indexing description: "[ Basic delegate of an EM_BUTTON. ]" date: "$Date$" revision: "$Revision$" class EM_BASIC_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) 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) + 4 end if button.image /= Void then Result := Result + button.image.width if button.text.count > 0 then Result := Result + 4 end end end optimal_height (button: EM_BUTTON): INTEGER is -- Optimal height of `button' do Result := button.border.top + button.border.bottom + 4 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 `button'. local x, y: INTEGER do if button.is_pressed then internal_color.set_red (theme_colors.button_background.red // 4 * 3) internal_color.set_green (theme_colors.button_background.green // 4 * 3) internal_color.set_blue (theme_colors.button_background.blue // 4 * 3) elseif button.is_mouse_over then internal_color.set_red (theme_colors.button_background.red + (255 - theme_colors.button_background.red) // 2) internal_color.set_green (theme_colors.button_background.green + (255 - theme_colors.button_background.green) // 2) internal_color.set_blue (theme_colors.button_background.blue + (255 - theme_colors.button_background.blue) // 2) else -- Normal button state internal_color.set_red (theme_colors.button_background.red) internal_color.set_green (theme_colors.button_background.green) internal_color.set_blue (theme_colors.button_background.blue) end button.surface.fill (internal_color) if button.image /= Void and button.text.is_empty then x := (button.width-button.optimal_width) // 2 + 2 y := (button.height-button.optimal_height) // 2 + 2 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 not button.text.is_empty 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 internal_border.set_color (theme_colors.button_border) internal_border.draw_on (button) end feature {NONE} -- Implementation internal_color: EM_COLOR is -- Color used internally once create Result.make_black end internal_border: EM_LINE_BORDER is -- Border used internally once create Result.make (create {EM_COLOR}.make_black, 1) end end