indexing description: "[ Delegate of an EM_BUTTON. ]" date: "$Date$" revision: "$Revision$" class EM_ECLIPSE_BUTTON_DELEGATE inherit EM_WIDGET_DELEGATE redefine install, optimal_width, optimal_height, draw_body end feature -- Initialisation install (button: EM_BUTTON) is -- Install style on `button'. -- Set up all default values for background, border, font and colors. do Precursor {EM_WIDGET_DELEGATE} (button) button.set_foreground_color (theme_colors.button_text) button.set_background_color (theme_colors.button_background) create {EM_BEVEL_BORDER}normal_border.make_up create {EM_BEVEL_BORDER}hover_border.make_up create {EM_BEVEL_BORDER}pressed_border.make_down create {EM_COLOR_BACKGROUND}normal_background.make_from_color (create {EM_COLOR}.make_with_rgb (230, 230, 230)) create {EM_COLOR_BACKGROUND}hover_background.make_from_color (create {EM_COLOR}.make_with_rgb (247, 247, 247)) create {EM_COLOR_BACKGROUND}pressed_background.make_from_color (create {EM_COLOR}.make_with_rgb (180, 180, 180)) create {EM_COLOR_BACKGROUND}disabled_background.make_from_color (create {EM_COLOR}.make_with_rgb (210, 210, 210)) end feature -- Measurement optimal_width (button: EM_BUTTON): INTEGER is -- Optimal width of `button' do Result := button.border.left + button.border.right + 4 if button.text.count > 0 then Result := Result + button.font.string_width (button.text) + 6 end if button.image /= Void then Result := Result + button.image.width if button.text.count > 0 then Result := Result + 6 end end end optimal_height (button: EM_BUTTON): INTEGER is -- Optimal height of `button' do Result := button.border.top + button.border.bottom + 6 if button.text.count > 0 and button.image /= Void then Result := Result + button.font.string_height (button.text).max (button.image.height) elseif button.image /= Void then Result := Result + button.image.height else Result := Result + button.font.string_height (button.text) end end feature -- Drawing draw_body (button: EM_BUTTON) is -- Draw body of 'a_widget'. local x, y: INTEGER do if not button.is_enabled then disabled_background.draw_on (button) else if button.is_pressed then pressed_background.draw_on (button) elseif button.is_mouse_over then hover_background.draw_on (button) else -- Normal button state normal_background.draw_on (button) end end if button.image /= Void and button.text.is_empty then x := (button.width-button.optimal_width) // 2 + 3 y := (button.height-button.optimal_height) // 2 + 3 if not button.is_enabled and then button.disabled_image /= Void then button.surface.blit_surface (button.disabled_image, x, y) else button.surface.blit_surface (button.image, x, y) end elseif button.image = Void and button.text.count > 0 then x := (button.width-button.optimal_width) // 2 + 4 y := (button.height-button.optimal_height) // 2 + 2 button.surface.set_drawing_color (button.foreground_color) button.font.draw_string (button.text, button.surface, x, y) else x := (button.width-button.optimal_width) // 2 + 4 y := (button.inner_height-button.image.height) // 2 + button.border.top if not button.is_enabled and then button.disabled_image /= Void then button.surface.blit_surface (button.disabled_image, x, y) else button.surface.blit_surface (button.image, x, y) end x := x + button.image.width + 4 y := (button.inner_height - button.font.string_height (button.text)) // 2 + button.border.top button.surface.set_drawing_color (button.foreground_color) button.font.draw_string (button.text, button.surface, x, y) end if button.is_pressed then pressed_border.draw_on (button) elseif button.is_mouse_over then hover_border.draw_on (button) else -- Normal button state normal_border.draw_on (button) end end feature {NONE} -- Implementation normal_background: EM_BACKGROUND -- Background in normal state hover_background: EM_BACKGROUND -- Background in hover state pressed_background: EM_BACKGROUND -- Background in pressed state disabled_background: EM_BACKGROUND -- Background in disabled state normal_border: EM_BORDER -- Border in normal state hover_border: EM_BORDER -- Border in hover state pressed_border: EM_BORDER -- Border in pressed state end