indexing description: "[ A color background which interpolates the background color between a left and a right colors. ]" date: "$Date$" revision: "$Revision$" class EM_HORIZONTAL_GRADIENT_BACKGROUND inherit EM_BACKGROUND create make_from_colors feature {NONE} -- Initialisation make_from_colors (a_left_color: like left_color; a_right_color: like right_color) is -- Initialise background with `a_left_color' and `a_right_color'. require a_left_color: a_left_color /= Void a_right_color_not_void: a_right_color /= Void do left_color := a_left_color right_color := a_right_color ensure left_color_set: left_color = a_left_color right_color_set: right_color = a_right_color end feature -- Access left_color: EM_COLOR -- Left color right_color: EM_COLOR -- Right color feature -- Element change set_left_color (a_color: like left_color) is -- Set `left_color' to `a_color'. require a_color_not_void: a_color /= Void do left_color := a_color ensure left_color_set: left_color = a_color end set_right_color (a_color: like right_color) is -- Set `right_color' to `a_color'. require a_color_not_void: a_color /= Void do right_color := a_color ensure right_color_set: right_color = a_color end feature -- Drawing draw_on (widget: EM_WIDGET) is -- Draw background on `widget'. local x, y_end: INTEGER color: EM_COLOR dred, dgreen, dblue: DOUBLE do y_end := widget.height-1 create color.make_black dred := (right_color.red-left_color.red) / (widget.width-1) dgreen := (right_color.green-left_color.green) / (widget.width-1) dblue := (right_color.blue-left_color.blue) / (widget.width-1) from x := 0 until x = widget.width loop color.set_red (left_color.red+(x*dred).floor) color.set_green (left_color.green+(x*dgreen).floor) color.set_blue (left_color.blue+(x*dblue).floor) widget.surface.put_line_segment (x, 0, x, y_end, color) x := x + 1 end end invariant left_color_not_void: left_color /= Void right_color_not_void: right_color /= Void end