indexing description: "[ EM_STRING contains a string and an EM_FONT used draw that string. ]" date: "$Date$" revision: "$Revision$" class EM_STRING inherit EM_DRAWABLE create make feature -- Initialisation make (a_string: STRING; a_font: EM_FONT) is -- Create an EM_STRING with `a_string' drawn using `a_font'. require a_string_not_void: a_string /= void a_font_not_void: a_font/=void do create character_container.make font := a_font set_value (a_string) set_visible (True) ensure value_set: value.is_equal (a_string) font_set: font = a_font is_visible: is_visible end feature -- Measurement width:INTEGER is -- Width of `Current' do result := character_container.width end height: INTEGER is -- Height of `Current' do result := character_container.height end feature -- Access value: STRING -- String to draw font: EM_FONT -- Font used to draw `value' feature -- Element change set_value (a_string: like value) is -- Set `value' to `a_string'. require a_string_not_void: a_string /= void local i: INTEGER chr: EM_CHARACTER pos: INTEGER do create value.make_from_string (a_string) character_container.wipe_out from i := 1 until i > a_string.count loop create chr.make (a_string.item (i), font) chr.set_x (pos) pos := pos + chr.width character_container.extend ( chr ) i := i + 1 end ensure value_equal_a_string: value.is_equal (a_string) end set_font (a_font: like font) is -- Set `font' to `a_font'. require a_font_not_void: a_font /= void local cursor: DS_LINKED_LIST_CURSOR [EM_CHARACTER] do if character_container = Void then create character_container.make end font := a_font from cursor := character_container.new_cursor cursor.start until cursor.off loop cursor.item.set_font (font) cursor.forth end ensure font_equal_a_font: a_font = font end feature -- Drawing draw (a_surface: EM_SURFACE) is -- Draws `Current' to `a_surface'. local ttf: EM_TTF_FONT do if is_visible then character_container.set_x_y (x, y) ttf ?= font if ttf /= Void then ttf.draw_string (value, a_surface, x, y) else character_container.draw (a_surface) end end end feature {NONE} -- Implementation character_container: EM_DRAWABLE_CONTAINER [EM_CHARACTER] -- The `character_container' contains all characters of the string invariant a_value_not_void: value /= void a_font_not_void: font /= void end