indexing description: "[ An EM_BMP_FONT expect a EM_DRAWABLE that contains all the 256 ASCII characters It is a matrix of size 16x16. Every entry contains one character. The character with the ASCII number 0 is at the top left, the character with the number 255 is at the bottom right. You can build such matrixes with the help of www.lmnopc.com/bitmapfontbuilder/ ]" date: "$Date$" revision: "$Revision$" class EM_BMP_FONT inherit EM_FONT create make feature -- Initialization make (a_drawable: EM_DRAWABLE) is -- Create an EM_BMP_FONT out of `a_drawable' that contains the font data. require a_drawable_not_void: a_drawable/=void do font := a_drawable end feature -- Measurement width (a_character: CHARACTER): INTEGER is -- Width of `a_character'. All characters have same width. do Result := font.width // 16 end height (a_character: CHARACTER): INTEGER is -- Height of `a_character'. All characters have same height. do Result := font.height // 16 end string_width (a_string: STRING): INTEGER is -- Width of `a_string'. do Result := a_string.count * (font.width // 16) end string_height (a_string: STRING): INTEGER is -- Height of `a_string'. All strings have same height. do Result := font.height // 16 end feature -- Drawing draw_string (a_string: STRING; a_surface: EM_SURFACE; x: INTEGER; y: INTEGER) is -- Draw `a_string' to `a_screen' to position `x' `y'. local i: INTEGER ascii_nr: INTEGER fx,fy: INTEGER do font.set_y (y) from i:=1 until i>a_string.count loop ascii_nr := (a_string @ (i)).code fx:=ascii_nr\\16 fy:=ascii_nr//16 font.set_x (x+(i-1)*font.width//16) part_rect.set_x (fx*(font.width//16)) part_rect.set_y (fy*(font.height//16)) part_rect.set_width (font.width//16) part_rect.set_height (font.height//16) font.draw_part (part_rect, a_surface) i:=i+1 end end draw (a_character: CHARACTER; a_surface: EM_SURFACE; x: INTEGER; y: INTEGER) is -- Draw `a_character' to `a_surface' to position `x' `y'. local fx, fy: INTEGER do fx:=a_character.code\\16 fy:=a_character.code//16 font.set_x (x) font.set_y (y) part_rect.set_x (fx*(font.width//16)) part_rect.set_y (fy*(font.height//16)) part_rect.set_width (font.width//16) part_rect.set_height (font.height//16) font.draw_part (part_rect, a_surface) 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 fx,fy: INTEGER do fx:=a_character.code\\16 fy:=a_character.code//16 font.set_x (x) font.set_y (y) part_rect.set_x (fx*(font.width//16) + rect.x) part_rect.set_y (fy*(font.height//16) + rect.y) part_rect.set_width (rect.width) part_rect.set_height (rect.height) font.draw_part (part_rect, a_surface) end feature {NONE} -- Implementation font: EM_DRAWABLE -- Bitmap containing the font data part_rect: EM_BLITTING_RECTANGLE is -- Rectangular part in `font' to be drawn once create result.make (0, 0, 0, 0) end end