indexing description: "[ A color background which interpolates the background color between a top and a bottom colors. ]" date: "$Date$" revision: "$Revision$" class EM_VERTICAL_GRADIENT_BACKGROUND inherit EM_BACKGROUND create make_from_colors feature {NONE} -- Initialisation make_from_colors (a_top_color: like top_color; a_bottom_color: like bottom_color) is -- Initialise background with `a_top_color' and `a_bottom_color'. require a_top_color_not_void: a_top_color /= Void a_bottom_color_not_void: a_bottom_color /= Void do top_color := a_top_color bottom_color := a_bottom_color ensure top_color_set: top_color = a_top_color bottom_color_set: bottom_color = a_bottom_color end feature -- Access top_color: EM_COLOR -- Top color bottom_color: EM_COLOR -- Bottom color feature -- Element change set_top_color (a_color: like top_color) is -- Set `top_color' to `a_color'. require a_color_not_void: a_color /= Void do top_color := a_color ensure top_color_set: top_color = a_color end set_bottom_color (a_color: like bottom_color) is -- Set `bottom_color' to `a_color'. require a_color_not_void: a_color /= Void do bottom_color := a_color ensure bottom_color_set: bottom_color = a_color end feature -- Drawing draw_on (widget: EM_WIDGET) is -- Draw background on `widget'. local y: INTEGER x_end: INTEGER color: EM_COLOR dred, dgreen, dblue: DOUBLE do x_end := widget.width-1 create color.make_black dred := (bottom_color.red-top_color.red) / (widget.height-1) dgreen := (bottom_color.green-top_color.green) / (widget.height-1) dblue := (bottom_color.blue-top_color.blue) / (widget.height-1) from y := 0 until y = widget.height loop color.set_red (top_color.red+(y*dred).floor) color.set_green (top_color.green+(y*dgreen).floor) color.set_blue (top_color.blue+(y*dblue).floor) widget.surface.put_line_segment (0, y, x_end, y, color) y := y + 1 end end invariant top_color_not_void: top_color /= Void bottom_color_not_void: bottom_color /= Void end