indexing description: "[ Border which displays a title at the top. ]" date: "$Date$" revision: "$Revision$" class EM_NAMED_BORDER inherit EM_BORDER EM_SHARED_STANDARD_FONTS export {NONE} all end EM_SHARED_THEME export {NONE} all end create make_from_text feature {NONE} -- Initialisation make_from_text (a_text: like text) is -- Initialise border with `a_text'. require a_text_not_void: a_text /= Void do text := a_text set_font (Standard_ttf_fonts.bitstream_vera_sans (10)) -- TODO: refactor colors create text_color.make_black create outer_color.make_with_rgb (100, 100, 100) create inner_color.make_white ensure text_set: text = a_text end feature -- Access font: EM_FONT -- Text font text: STRING -- Text on border text_color: EM_COLOR -- Text color outer_color: EM_COLOR -- Color at top and left inner_color: EM_COLOR -- Color at bottom and right feature -- Element change set_text (a_text: like text) is -- Set `text' to `a_text'. require a_text_not_void: a_text /= Void do text := a_text set_font (font) ensure text_set: text = a_text end set_font (a_font: like font) is -- Set `font' to `a_font'. require a_font_not_void: a_font /= Void do font := a_font top := font.string_height (text) left := 2 right := 2 bottom := 2 ensure font_set: font = a_font end set_text_color (a_color: EM_COLOR) is -- Set `text_color' to `a_color'. require a_color_not_void: a_color /= Void do text_color := a_color ensure text_color_set: text_color = a_color end set_outer_color (a_color: EM_COLOR) is -- Set `outer_color' to `a_color'. require a_color_not_void: a_color /= Void do outer_color := a_color ensure outer_color_set: outer_color = a_color end set_inner_color (a_color: EM_COLOR) is -- Set `inner_color' to `a_color'. require a_color_not_void: a_color /= Void do inner_color := a_color ensure inner_color_set: inner_color = a_color end feature -- Drawing draw_on (widget: EM_WIDGET) is -- Draw border on `widget'. local left_x: INTEGER right_x: INTEGER top_y: INTEGER do left_x := 5 right_x := font.string_width (text)+left_x+2 top_y := font.string_height (text) // 2 widget.surface.put_line_segment (0, top_y, 0, widget.height-2, outer_color) widget.surface.put_line_segment (0, widget.height-2, widget.width-2, widget.height-2, outer_color) widget.surface.put_line_segment (widget.width-2, widget.height-2, widget.width-2, top_y, outer_color) widget.surface.put_line_segment (right_x, top_y, widget.width-2, top_y, outer_color) widget.surface.put_line_segment (0, top_y, left_x, top_y, outer_color) widget.surface.put_line_segment (1, top_y+1, 1, widget.height-3, inner_color) widget.surface.put_line_segment (0, widget.height-1, widget.width-1, widget.height-1, inner_color) widget.surface.put_line_segment (widget.width-1, widget.height-1, widget.width-1, top_y, inner_color) widget.surface.put_line_segment (right_x, top_y+1, widget.width-3, top_y+1, inner_color) widget.surface.put_line_segment (1, top_y+1, left_x, top_y+1, inner_color) widget.surface.set_drawing_color (text_color) font.draw_string (text, widget.surface, left_x+1, 0) end end