indexing description: "[ An EM_COLOR_TTF_FONT is created from a true type font file or another EM_TTF_FONT. The color of the font can be set using `set_color'. ]" date: "$Date$" revision: "$Revision$" class EM_COLOR_TTF_FONT inherit EM_TTF_FONT redefine make_from_ttf_file, draw, draw_part, draw_string, free_font end create make_from_ttf_file, make_from_ttf_font, make_from_ttf_file_color, make_from_ttf_font_color feature {NONE} -- Initialisation make_from_ttf_file (a_ttf_file: STRING; a_point_size: INTEGER) is -- Initialise true type font from `a_ttf_file' with `a_point_size' size. do Precursor {EM_TTF_FONT} (a_ttf_file, a_point_size) set_color (create {EM_COLOR}.make_white) end make_from_ttf_file_color (a_ttf_file: STRING; a_point_size: INTEGER; a_color: like color) is -- Initialise true type font from `a_ttf_file' with `a_point_size' size and `a_color'. require a_ttf_file_not_void: a_ttf_file /= Void a_color_not_void: a_color /= Void do make_from_ttf_file (a_ttf_file, a_point_size) set_color (a_color) end make_from_ttf_font (a_ttf_font: EM_TTF_FONT) is -- Initialise true type font from `a_ttf_font'. require a_ttf_font_not_void: a_ttf_font /= Void do ttf_font := a_ttf_font font := a_ttf_font.font set_color (create {EM_COLOR}.make_white) end make_from_ttf_font_color (a_ttf_font: EM_TTF_FONT; a_color: like color) is -- Initialise true type font from `a_ttf_font'. require a_ttf_font_not_void: a_ttf_font /= Void do ttf_font := a_ttf_font font := a_ttf_font.font set_color (a_color) end feature -- Access color: EM_COLOR -- Color of font feature -- Element change set_color (a_color: like color) is -- Set `color' to `a_color'. require a_color_not_void: a_color /= Void do color := a_color ensure a_color_set: color = a_color end feature -- Drawing draw (a_character: CHARACTER; a_surface: EM_SURFACE; x: INTEGER; y:INTEGER) is -- Draw `a_character' to `a_surface' to position `x' `y' local surface: EM_TTF_SURFACE dest_box: EM_RECTANGLE do create surface.make_from_ttf_pointer (ttf_render_glyph_blended_external (font.item, a_character.code, color.sdl_pointer)) create dest_box.make_from_coordinates (x, y, x+surface.width, y+surface.height) a_surface.draw_surface_stretched (surface, dest_box) end draw_part (rect: EM_BLITTING_RECTANGLE; a_character: CHARACTER; a_surface: EM_SURFACE; x: INTEGER; y: INTEGER) is -- Draw `rect' part of `a_character' to `a_surface' to position `x' `y' local surface: EM_TTF_SURFACE dest_box: EM_RECTANGLE do create surface.make_from_ttf_pointer (ttf_render_glyph_blended_external (font.item, a_character.code, color.sdl_pointer)) create dest_box.make_from_coordinates (x, y, x+surface.width, y+surface.height) a_surface.draw_surface_stretched (surface, dest_box) end draw_string (a_string: STRING; a_surface: EM_SURFACE; x: INTEGER; y: INTEGER) is -- Draw `a_string' to `a_screen' to position `x' ,`y' in the surface's drawing_color require else a_string_not_void: a_string /= Void a_string_not_empty: not a_string.is_empty local surface: EM_TTF_SURFACE dest_box: EM_RECTANGLE text_c_string: EWG_ZERO_TERMINATED_STRING do create text_c_string.make_unshared_from_string (a_string) create surface.make_from_ttf_pointer (ttf_render_text_blended_external (font.item, text_c_string.item, color.sdl_pointer)) create dest_box.make_from_coordinates (x, y, x+surface.width, y+surface.height) a_surface.draw_surface_stretched (surface, dest_box) end feature {NONE} -- Implementation ttf_font: EM_TTF_FONT -- TTF Font from which color font was created. -- Void if color font was created from a file. free_font is -- Only free the font if it is not managed by a non-color font object already. do if ttf_font = Void then Precursor end end end