diff --git a/.github/.build-all.sh b/.github/.build-all.sh index 6003fc521b63adcb0dc27583b13300f54b0071c2..8969dc4e1f3f8843290c80cdacbd5cae273ff246 100644 --- a/.github/.build-all.sh +++ b/.github/.build-all.sh @@ -10,6 +10,10 @@ cd ../.. for file in ./Hello* do echo -e "\e[44m $file building...\e[49m" + if [ "$file" == "./HelloAzureIoT" ]; then + echo "skip $file" + continue + fi cd $file cmake . make -j4 diff --git a/.github/.updateGuiLite.sh b/.github/.updateGuiLite.sh index be7c59c1af55005120c4a43d3ca000e6bcf28f83..793a2d77225cc0f764bdf877bd4a702ca3460fad 100644 --- a/.github/.updateGuiLite.sh +++ b/.github/.updateGuiLite.sh @@ -7,6 +7,10 @@ declare -i sum=0 for file in ./Hello* do echo -e "\e[44m $file sync up...\e[49m" + if [ "$file" == "./HelloAzureIoT" ]; then + echo "skip $file" + continue + fi cd $file cp $src/GuiLite.h UIcode/GuiLite.h cd .. diff --git a/Hello3D/UIcode/GuiLite.h b/Hello3D/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/Hello3D/UIcode/GuiLite.h +++ b/Hello3D/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/Hello3Ddonut/UIcode/GuiLite.h b/Hello3Ddonut/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/Hello3Ddonut/UIcode/GuiLite.h +++ b/Hello3Ddonut/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/Hello3Ddonut/UIcode/UIcode.cpp b/Hello3Ddonut/UIcode/UIcode.cpp index b15a4f848c81371f1bc7c02ed3305d407c7aa6c8..42c1dccc2856056dfbc951e63acf34c24afa66e5 100644 --- a/Hello3Ddonut/UIcode/UIcode.cpp +++ b/Hello3Ddonut/UIcode/UIcode.cpp @@ -63,7 +63,7 @@ void render_frame() } } -extern const FONT_INFO Consolas_13; +extern const LATTICE_FONT_INFO Consolas_13; // Demo void create_ui(void* phy_fb, int screen_width, int screen_height, int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) { if (phy_fb) diff --git a/Hello3Ddonut/UIcode/resource/Consolas_13.cpp b/Hello3Ddonut/UIcode/resource/Consolas_13.cpp index 3d7f27a88025e7fe2eaba5990e2012442c71635a..ab65592bf289ae1a46386b914610d734288e3427 100644 --- a/Hello3Ddonut/UIcode/resource/Consolas_13.cpp +++ b/Hello3Ddonut/UIcode/resource/Consolas_13.cpp @@ -41,8 +41,8 @@ static LATTICE lattice_array[] = { {64, 6, _64}, {126, 6, _126}, }; -extern const FONT_INFO Consolas_13; -const FONT_INFO Consolas_13 ={ +extern const LATTICE_FONT_INFO Consolas_13; +const LATTICE_FONT_INFO Consolas_13 ={ 13, 13, lattice_array diff --git a/Hello3Dwave/UIcode/GuiLite.h b/Hello3Dwave/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/Hello3Dwave/UIcode/GuiLite.h +++ b/Hello3Dwave/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloAnimation/UIcode/GuiLite.h b/HelloAnimation/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloAnimation/UIcode/GuiLite.h +++ b/HelloAnimation/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloAnimation/UIcode/UIcode.cpp b/HelloAnimation/UIcode/UIcode.cpp index bc4d33c673c2ff3208316bf4f3cb6f144b614fcb..8862642e55229373b3598dda7ca91583065ba373 100644 --- a/HelloAnimation/UIcode/UIcode.cpp +++ b/HelloAnimation/UIcode/UIcode.cpp @@ -56,7 +56,7 @@ static WND_TREE s_myUI_children[] = }; //////////////////////// start UI //////////////////////// -extern const FONT_INFO KaiTi_19; +extern const LATTICE_FONT_INFO KaiTi_19; static c_display* s_display; void load_resource() { diff --git a/HelloAnimation/UIcode/resource/KaiTi_19.cpp b/HelloAnimation/UIcode/resource/KaiTi_19.cpp index 9bf357eb7ae73be5b2f31bcdf0e1e16f4f021e7b..1619822ac3fe077af9c5fdd280ff973bd300ff7d 100644 --- a/HelloAnimation/UIcode/resource/KaiTi_19.cpp +++ b/HelloAnimation/UIcode/resource/KaiTi_19.cpp @@ -8,8 +8,8 @@ static LATTICE lattice_array[] = { {15044504, 20, _15044504}, {15056290, 20, _15056290}, }; -extern const FONT_INFO KaiTi_19; -const FONT_INFO KaiTi_19 ={ +extern const LATTICE_FONT_INFO KaiTi_19; +const LATTICE_FONT_INFO KaiTi_19 ={ 19, 2, lattice_array diff --git a/HelloCircle/UIcode/GuiLite.h b/HelloCircle/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloCircle/UIcode/GuiLite.h +++ b/HelloCircle/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloFFmpeg/UIcode/GuiLite.h b/HelloFFmpeg/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloFFmpeg/UIcode/GuiLite.h +++ b/HelloFFmpeg/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloFont/UIcode/GuiLite.h b/HelloFont/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloFont/UIcode/GuiLite.h +++ b/HelloFont/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloFont/UIcode/UIcode.cpp b/HelloFont/UIcode/UIcode.cpp index 5a8511f9075ea54fc70cc3a43e277c16b52f60bd..ebbf0096f9a8608e4581624e727f3fafde37ea98 100644 --- a/HelloFont/UIcode/UIcode.cpp +++ b/HelloFont/UIcode/UIcode.cpp @@ -70,7 +70,7 @@ static WND_TREE s_myUI_children[] = //////////////////////// start UI //////////////////////// extern const BITMAP_INFO background_bmp; -extern const FONT_INFO KaiTi_33B; +extern const LATTICE_FONT_INFO KaiTi_33B; static c_display* s_display; void load_resource() { diff --git a/HelloFont/UIcode/resource/KaiTi_33B.cpp b/HelloFont/UIcode/resource/KaiTi_33B.cpp index d79c36523cfd53a375f503e7ec18427778d41006..1e2095a3d11bc38bace455bedd519d526147ce6c 100644 --- a/HelloFont/UIcode/resource/KaiTi_33B.cpp +++ b/HelloFont/UIcode/resource/KaiTi_33B.cpp @@ -98,8 +98,8 @@ static LATTICE lattice_array[] = { {15308724, 33, _15308724}, {15309237, 33, _15309237}, }; -extern const FONT_INFO KaiTi_33B; -const FONT_INFO KaiTi_33B ={ +extern const LATTICE_FONT_INFO KaiTi_33B; +const LATTICE_FONT_INFO KaiTi_33B ={ 33, 32, lattice_array diff --git a/HelloFreetype/UIcode/GuiLite.h b/HelloFreetype/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloFreetype/UIcode/GuiLite.h +++ b/HelloFreetype/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloGuiLite/UIcode/GuiLite.h b/HelloGuiLite/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloGuiLite/UIcode/GuiLite.h +++ b/HelloGuiLite/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloLayers/UIcode/GuiLite.h b/HelloLayers/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloLayers/UIcode/GuiLite.h +++ b/HelloLayers/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloLayers/UIcode/UIcode.cpp b/HelloLayers/UIcode/UIcode.cpp index 264ce9bc3c91064599af6c831b2543b75b2cd459..46f629b011a93c31e8cc91015f2b855f75ef8aa2 100644 --- a/HelloLayers/UIcode/UIcode.cpp +++ b/HelloLayers/UIcode/UIcode.cpp @@ -56,7 +56,7 @@ void clear_layer_1() #endif } -extern const FONT_INFO Consolas_19; +extern const LATTICE_FONT_INFO Consolas_19; void load_resource() { c_theme::add_font(FONT_DEFAULT, &Consolas_19); diff --git a/HelloLayers/UIcode/resource/Consolas_19.cpp b/HelloLayers/UIcode/resource/Consolas_19.cpp index a7ab4ac3f149f15d0305bef051eb4af4e4ef2aa0..d52b3a7cdefd5d0e79b38d085e6fff5c5df07225 100644 --- a/HelloLayers/UIcode/resource/Consolas_19.cpp +++ b/HelloLayers/UIcode/resource/Consolas_19.cpp @@ -248,8 +248,8 @@ static LATTICE lattice_array[] = { {121, 9, _121}, {122, 9, _122}, }; -extern const FONT_INFO Consolas_19; -const FONT_INFO Consolas_19 ={ +extern const LATTICE_FONT_INFO Consolas_19; +const LATTICE_FONT_INFO Consolas_19 ={ 19, 82, lattice_array diff --git a/HelloMario/UIcode/GuiLite.h b/HelloMario/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloMario/UIcode/GuiLite.h +++ b/HelloMario/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloMolecule/UIcode/GuiLite.h b/HelloMolecule/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloMolecule/UIcode/GuiLite.h +++ b/HelloMolecule/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloNets/UIcode/GuiLite.h b/HelloNets/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloNets/UIcode/GuiLite.h +++ b/HelloNets/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloNoTouch/UIcode/GuiLite.h b/HelloNoTouch/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloNoTouch/UIcode/GuiLite.h +++ b/HelloNoTouch/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloNoTouch/UIcode/UIcode.cpp b/HelloNoTouch/UIcode/UIcode.cpp index a117ced15070dfbdd41af54a5cf2abcf56d7d758..b1ade2a20a81d92162a186bdd363cadd38700d61 100644 --- a/HelloNoTouch/UIcode/UIcode.cpp +++ b/HelloNoTouch/UIcode/UIcode.cpp @@ -72,7 +72,7 @@ static WND_TREE s_myUI_children[] = }; //////////////////////// start UI //////////////////////// -extern const FONT_INFO Consolas_28; +extern const LATTICE_FONT_INFO Consolas_28; void load_resource() { c_theme::add_font(FONT_DEFAULT, &Consolas_28); diff --git a/HelloNoTouch/UIcode/resource/Consolas_28.cpp b/HelloNoTouch/UIcode/resource/Consolas_28.cpp index 0d46893fb29282fa684f351ec7c9feccde226a16..14db9a36ca2eea208dc030eec6d313078cfac085 100644 --- a/HelloNoTouch/UIcode/resource/Consolas_28.cpp +++ b/HelloNoTouch/UIcode/resource/Consolas_28.cpp @@ -65,8 +65,8 @@ static LATTICE lattice_array[] = { {108, 13, _108}, {115, 13, _115}, }; -extern const FONT_INFO Consolas_28; -const FONT_INFO Consolas_28 ={ +extern const LATTICE_FONT_INFO Consolas_28; +const LATTICE_FONT_INFO Consolas_28 ={ 28, 21, lattice_array diff --git a/HelloParticle/UIcode/GuiLite.h b/HelloParticle/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloParticle/UIcode/GuiLite.h +++ b/HelloParticle/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloParticle/UIcode/UIcode.cpp b/HelloParticle/UIcode/UIcode.cpp index 57c9ff3c7f2085b903620dbd060619f4fb3bfb46..5f0aea572b08d9394926e60558f344468c2367f9 100644 --- a/HelloParticle/UIcode/UIcode.cpp +++ b/HelloParticle/UIcode/UIcode.cpp @@ -42,7 +42,7 @@ public: }; //////////////////////// start UI //////////////////////// -extern const FONT_INFO Microsoft_YaHei_28; +extern const LATTICE_FONT_INFO Microsoft_YaHei_28; void load_resource() { c_theme::add_font(FONT_DEFAULT, &Microsoft_YaHei_28); } diff --git a/HelloParticle/UIcode/resource/Microsoft_YaHei_28.cpp b/HelloParticle/UIcode/resource/Microsoft_YaHei_28.cpp index e7f197935bd65613e472b5ab11c8a9587f19da17..ff43b68d32f535aa375ff26951fe33626022389b 100644 --- a/HelloParticle/UIcode/resource/Microsoft_YaHei_28.cpp +++ b/HelloParticle/UIcode/resource/Microsoft_YaHei_28.cpp @@ -68,8 +68,8 @@ static LATTICE lattice_array[] = { {15711372, 21, _15711372}, {15711386, 21, _15711386}, }; -extern const FONT_INFO Microsoft_YaHei_28; -const FONT_INFO Microsoft_YaHei_28 ={ +extern const LATTICE_FONT_INFO Microsoft_YaHei_28; +const LATTICE_FONT_INFO Microsoft_YaHei_28 ={ 28, 22, lattice_array diff --git a/HelloPendulum/UIcode/GuiLite.h b/HelloPendulum/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloPendulum/UIcode/GuiLite.h +++ b/HelloPendulum/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloPendulum/UIcode/UIcode.cpp b/HelloPendulum/UIcode/UIcode.cpp index e7af5b003edd74692e3fb197803f4a42e639472d..57ab04ed942fa4a07d51d1b9df9578a5bbfbb752 100644 --- a/HelloPendulum/UIcode/UIcode.cpp +++ b/HelloPendulum/UIcode/UIcode.cpp @@ -55,8 +55,8 @@ namespace pendulum if (text1 && text2) { - c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text1, x1 + x - 14, y1 + y - 10, c_theme::get_font(FONT_DEFAULT), 0, 0, ALIGN_HCENTER); - c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text2, x2 + x - 18, y2 + y - 10, c_theme::get_font(FONT_DEFAULT), 0, 0, ALIGN_HCENTER); + c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text1, x1 + x - 14, y1 + y - 10, c_theme::get_font(FONT_DEFAULT), 0, 0); + c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text2, x2 + x - 18, y2 + y - 10, c_theme::get_font(FONT_DEFAULT), 0, 0); } else { @@ -74,8 +74,8 @@ namespace pendulum if (text1 && text2) { - c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text1, x1 + x - 14, y1 + y - 10, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), 0, ALIGN_HCENTER); - c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text2, x2 + x - 18, y2 + y - 10, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), 0, ALIGN_HCENTER); + c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text1, x1 + x - 14, y1 + y - 10, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), 0); + c_word::draw_string(s_surface, Z_ORDER_LEVEL_0, text2, x2 + x - 18, y2 + y - 10, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), 0); } else { @@ -85,7 +85,7 @@ namespace pendulum } } -extern const FONT_INFO Consolas_19; +extern const LATTICE_FONT_INFO Consolas_19; void load_resource() { c_theme::add_font(FONT_DEFAULT, &Consolas_19); diff --git a/HelloPendulum/UIcode/resource/Consolas_19.cpp b/HelloPendulum/UIcode/resource/Consolas_19.cpp index a7ab4ac3f149f15d0305bef051eb4af4e4ef2aa0..d52b3a7cdefd5d0e79b38d085e6fff5c5df07225 100644 --- a/HelloPendulum/UIcode/resource/Consolas_19.cpp +++ b/HelloPendulum/UIcode/resource/Consolas_19.cpp @@ -248,8 +248,8 @@ static LATTICE lattice_array[] = { {121, 9, _121}, {122, 9, _122}, }; -extern const FONT_INFO Consolas_19; -const FONT_INFO Consolas_19 ={ +extern const LATTICE_FONT_INFO Consolas_19; +const LATTICE_FONT_INFO Consolas_19 ={ 19, 82, lattice_array diff --git a/HelloScroll/UIcode/GuiLite.h b/HelloScroll/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloScroll/UIcode/GuiLite.h +++ b/HelloScroll/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloScroll/UIcode/UIcode.cpp b/HelloScroll/UIcode/UIcode.cpp index f2eaeb1fc7ef7e856b360fd587a3f93718630933..bcc98357a0827eca3ed276d24823662dba07acfd 100644 --- a/HelloScroll/UIcode/UIcode.cpp +++ b/HelloScroll/UIcode/UIcode.cpp @@ -118,7 +118,7 @@ WND_TREE s_main_widgets[] = }; // Create GUI -extern const FONT_INFO Consolas_24B; +extern const LATTICE_FONT_INFO Consolas_24B; void load_resource() { c_theme::add_font(FONT_DEFAULT, &Consolas_24B); diff --git a/HelloScroll/UIcode/resource/Consolas_24B.cpp b/HelloScroll/UIcode/resource/Consolas_24B.cpp index a1944d8b17d9d4dbfa2c0ff9531f3122e74a0a23..a7b22ef37299391af842085ea87637d0d0980334 100644 --- a/HelloScroll/UIcode/resource/Consolas_24B.cpp +++ b/HelloScroll/UIcode/resource/Consolas_24B.cpp @@ -254,8 +254,8 @@ static LATTICE lattice_array[] = { {14849714, 12, _14849714}, {14849724, 12, _14849724}, }; -extern const FONT_INFO Consolas_24B; -const FONT_INFO Consolas_24B ={ +extern const LATTICE_FONT_INFO Consolas_24B; +const LATTICE_FONT_INFO Consolas_24B ={ 24, 84, lattice_array diff --git a/HelloSlide/UIcode/GuiLite.h b/HelloSlide/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloSlide/UIcode/GuiLite.h +++ b/HelloSlide/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloStar/UIcode/GuiLite.h b/HelloStar/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloStar/UIcode/GuiLite.h +++ b/HelloStar/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloTimer/UIcode/GuiLite.h b/HelloTimer/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloTimer/UIcode/GuiLite.h +++ b/HelloTimer/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloTimer/UIcode/UIcode.cpp b/HelloTimer/UIcode/UIcode.cpp index bf4f037a294f3158086646eb2221cd0951343fd5..5b8e2eb9c1a01debf17b8df135384b487a89e3b6 100644 --- a/HelloTimer/UIcode/UIcode.cpp +++ b/HelloTimer/UIcode/UIcode.cpp @@ -6,8 +6,8 @@ const int UI_WIDTH = 240; const int UI_HEIGHT = 320; const int FRAME_COUNT = 32; -extern const FONT_INFO Consolas_19; -extern const FONT_INFO _DengXian_36B; +extern const LATTICE_FONT_INFO Consolas_19; +extern const LATTICE_FONT_INFO _DengXian_36B; extern const BITMAP_INFO humidity_bmp; extern const BITMAP_INFO temperature_bmp; extern const BITMAP_INFO weather_bmp; diff --git a/HelloTimer/UIcode/resource/Consolas_19.cpp b/HelloTimer/UIcode/resource/Consolas_19.cpp index 8ae19aafcf33a6435129cf360f5e2935e59b1bf5..e79d29ba6ae7dad9ea02f090e8b4eb50bf7b3095 100644 --- a/HelloTimer/UIcode/resource/Consolas_19.cpp +++ b/HelloTimer/UIcode/resource/Consolas_19.cpp @@ -8,8 +8,8 @@ static LATTICE lattice_array[] = { {48, 9, _48}, {49, 9, _49}, }; -extern const FONT_INFO Consolas_19; -const FONT_INFO Consolas_19 ={ +extern const LATTICE_FONT_INFO Consolas_19; +const LATTICE_FONT_INFO Consolas_19 ={ 19, 2, lattice_array diff --git a/HelloTimer/UIcode/resource/_DengXian_36B.cpp b/HelloTimer/UIcode/resource/_DengXian_36B.cpp index a5467646a0d74bc337eaec7e7fa1c3890ca26ce6..d3256765fc27f47a813c2a0c9765cc7bf42926e6 100644 --- a/HelloTimer/UIcode/resource/_DengXian_36B.cpp +++ b/HelloTimer/UIcode/resource/_DengXian_36B.cpp @@ -254,8 +254,8 @@ static LATTICE lattice_array[] = { {14849714, 35, _14849714}, {14849724, 35, _14849724}, }; -extern const FONT_INFO _DengXian_36B; -const FONT_INFO _DengXian_36B ={ +extern const LATTICE_FONT_INFO _DengXian_36B; +const LATTICE_FONT_INFO _DengXian_36B ={ 36, 84, lattice_array diff --git a/HelloTransparent/UIcode/GuiLite.h b/HelloTransparent/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloTransparent/UIcode/GuiLite.h +++ b/HelloTransparent/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloTransparent/UIcode/UIcode.cpp b/HelloTransparent/UIcode/UIcode.cpp index b72187be4f7fdb1c3908d3c7a1bd1151fb844aec..8e74313f97ff1b1d57347e68d81e702f8349030d 100644 --- a/HelloTransparent/UIcode/UIcode.cpp +++ b/HelloTransparent/UIcode/UIcode.cpp @@ -107,7 +107,7 @@ WND_TREE s_main_widgets[] = }; // Create GUI -extern const FONT_INFO Consolas_24B; +extern const LATTICE_FONT_INFO Consolas_24B; extern const BITMAP_INFO background_bmp; void load_resource() { diff --git a/HelloTransparent/UIcode/resource/Consolas_24B.cpp b/HelloTransparent/UIcode/resource/Consolas_24B.cpp index a1944d8b17d9d4dbfa2c0ff9531f3122e74a0a23..a7b22ef37299391af842085ea87637d0d0980334 100644 --- a/HelloTransparent/UIcode/resource/Consolas_24B.cpp +++ b/HelloTransparent/UIcode/resource/Consolas_24B.cpp @@ -254,8 +254,8 @@ static LATTICE lattice_array[] = { {14849714, 12, _14849714}, {14849724, 12, _14849724}, }; -extern const FONT_INFO Consolas_24B; -const FONT_INFO Consolas_24B ={ +extern const LATTICE_FONT_INFO Consolas_24B; +const LATTICE_FONT_INFO Consolas_24B ={ 24, 84, lattice_array diff --git a/HelloWave/UIcode/GuiLite.h b/HelloWave/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloWave/UIcode/GuiLite.h +++ b/HelloWave/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloWave/UIcode/UIcode.cpp b/HelloWave/UIcode/UIcode.cpp index 681e418f8868d499924be507406578fb8e788bd1..68e2aceac93d2955e6f9df36bbf26703b2972533 100644 --- a/HelloWave/UIcode/UIcode.cpp +++ b/HelloWave/UIcode/UIcode.cpp @@ -116,7 +116,7 @@ static WND_TREE s_myUI_children[] = }; //////////////////////// start UI //////////////////////// -extern const FONT_INFO Lucida_Console_27; +extern const LATTICE_FONT_INFO Lucida_Console_27; void load_resource() { c_theme::add_font(FONT_DEFAULT, &Lucida_Console_27); diff --git a/HelloWave/UIcode/resource/Lucida_Console_27.cpp b/HelloWave/UIcode/resource/Lucida_Console_27.cpp index 5dd088bae07f9bb52b8664d6419cc97fcee3fb6d..055aab2f4cd88e9c6ce50705d9228456e7d6ec99 100644 --- a/HelloWave/UIcode/resource/Lucida_Console_27.cpp +++ b/HelloWave/UIcode/resource/Lucida_Console_27.cpp @@ -32,8 +32,8 @@ static LATTICE lattice_array[] = { {15113402, 22, _15113402}, {15174023, 22, _15174023}, }; -extern const FONT_INFO Lucida_Console_27; -const FONT_INFO Lucida_Console_27 ={ +extern const LATTICE_FONT_INFO Lucida_Console_27; +const LATTICE_FONT_INFO Lucida_Console_27 ={ 27, 10, lattice_array diff --git a/HelloWidgets/UIcode/GuiLite.h b/HelloWidgets/UIcode/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HelloWidgets/UIcode/GuiLite.h +++ b/HelloWidgets/UIcode/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HelloWidgets/UIcode/UIcode.cpp b/HelloWidgets/UIcode/UIcode.cpp index e48aa75cc0ab2ce5d93b3952abaff4049578a278..11ce5b4d9823a1e15b559d92af9fc98d4e5c7d3d 100644 --- a/HelloWidgets/UIcode/UIcode.cpp +++ b/HelloWidgets/UIcode/UIcode.cpp @@ -142,7 +142,7 @@ WND_TREE s_main_widgets[] = }; // Create GUI -extern const FONT_INFO Consolas_24B; +extern const LATTICE_FONT_INFO Consolas_24B; void load_resource() { c_theme::add_font(FONT_DEFAULT, &Consolas_24B); diff --git a/HelloWidgets/UIcode/resource/Consolas_24B.cpp b/HelloWidgets/UIcode/resource/Consolas_24B.cpp index a1944d8b17d9d4dbfa2c0ff9531f3122e74a0a23..a7b22ef37299391af842085ea87637d0d0980334 100644 --- a/HelloWidgets/UIcode/resource/Consolas_24B.cpp +++ b/HelloWidgets/UIcode/resource/Consolas_24B.cpp @@ -254,8 +254,8 @@ static LATTICE lattice_array[] = { {14849714, 12, _14849714}, {14849724, 12, _14849724}, }; -extern const FONT_INFO Consolas_24B; -const FONT_INFO Consolas_24B ={ +extern const LATTICE_FONT_INFO Consolas_24B; +const LATTICE_FONT_INFO Consolas_24B ={ 24, 84, lattice_array diff --git a/HostMonitor/UIcode/include/GuiLite.h b/HostMonitor/UIcode/include/GuiLite.h index e397552be25d13e069dc7a89d75b1bb35f95a356..10036f61e00dcab41e7a4df2955bcde92a194624 100644 --- a/HostMonitor/UIcode/include/GuiLite.h +++ b/HostMonitor/UIcode/include/GuiLite.h @@ -115,19 +115,20 @@ typedef struct struct_lattice { unsigned int utf8_code; unsigned char width; - const unsigned char* pixel_gray_array; + const unsigned char* pixel_buffer; } LATTICE; -typedef struct struct_font_info +typedef struct struct_lattice_font_info { unsigned char height; unsigned int count; LATTICE* lattice_array; +} LATTICE_FONT_INFO; +typedef struct struct_font_info +{ + const void* font; //could be LATTICE_FONT_INFO or TTF } FONT_INFO; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; -typedef struct struct_bitmap_info BITMAP_INFO; //Rebuild gui library once you change this file -enum FONT_TYPE +enum FONT_LIST { FONT_NULL, FONT_DEFAULT, @@ -139,7 +140,7 @@ enum FONT_TYPE FONT_CUSTOM6, FONT_MAX }; -enum BITMAP_TYPE +enum BITMAP_LIST { BITMAP_CUSTOM1, BITMAP_CUSTOM2, @@ -149,7 +150,7 @@ enum BITMAP_TYPE BITMAP_CUSTOM6, BITMAP_MAX }; -enum COLOR_TYPE +enum COLOR_LIST { COLOR_WND_FONT, COLOR_WND_NORMAL, @@ -167,26 +168,26 @@ enum COLOR_TYPE class c_theme { public: - static int add_font(FONT_TYPE index, const FONT_INFO* font) + static int add_font(FONT_LIST index, const void* font) { if (index >= FONT_MAX) { ASSERT(false); return -1; } - s_font_map[index] = font; + s_font_map[index].font = font; return 0; } - static const FONT_INFO* get_font(FONT_TYPE index) + static const void* get_font(FONT_LIST index) { if (index >= FONT_MAX) { ASSERT(false); return 0; } - return s_font_map[index]; + return s_font_map[index].font; } - static int add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) + static int add_bitmap(BITMAP_LIST index, const BITMAP_INFO* bmp) { if (index >= BITMAP_MAX) { @@ -196,7 +197,7 @@ public: s_bmp_map[index] = bmp; return 0; } - static const BITMAP_INFO* get_bmp(BITMAP_TYPE index) + static const BITMAP_INFO* get_bmp(BITMAP_LIST index) { if (index >= BITMAP_MAX) { @@ -205,7 +206,7 @@ public: } return s_bmp_map[index]; } - static int add_color(COLOR_TYPE index, const unsigned int color) + static int add_color(COLOR_LIST index, const unsigned int color) { if (index >= COLOR_MAX) { @@ -215,7 +216,7 @@ public: s_color_map[index] = color; return 0; } - static const unsigned int get_color(COLOR_TYPE index) + static const unsigned int get_color(COLOR_LIST index) { if (index >= COLOR_MAX) { @@ -225,7 +226,7 @@ public: return s_color_map[index]; } private: - static const FONT_INFO* s_font_map[FONT_MAX]; + static FONT_INFO s_font_map[FONT_MAX]; static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; static unsigned int s_color_map[COLOR_MAX]; }; @@ -817,13 +818,23 @@ inline int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1 } #include #include -#define BUFFER_LEN 16 +#define VALUE_STR_LEN 16 class c_surface; -class c_word +class c_font_operator { public: - static void draw_string(c_surface* surface, int z_order, const char *s, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + virtual void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) = 0; + virtual void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) = 0; + virtual int get_str_size(const void* string, const void* font, int& width, int& height) = 0; +}; +class c_lattice_font_op: public c_font_operator +{ +public: + void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) { + const char* s = (const char*)string; if (0 == s) { return; @@ -833,32 +844,56 @@ public: while (*s) { s += get_utf8_code(s, utf8_code); - offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); + offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } } - static void draw_string_in_rect(c_surface* surface, int z_order, const char *s, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { + const char* s = (const char*)string; if (0 == s) { return; } int x, y; - get_string_pos(s, font, rect, align_type, x, y); - draw_string(surface, z_order, s, rect.m_left + x, rect.m_top + y, font, font_color, bg_color, ALIGN_LEFT); + get_string_pos(s, (const LATTICE_FONT_INFO*)font, rect, align_type, x, y); + draw_string(surface, z_order, string, rect.m_left + x, rect.m_top + y, font, font_color, bg_color); + } + void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string(surface, z_order, buf, x, y, (const LATTICE_FONT_INFO*)font, font_color, bg_color); } - static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string(surface, z_order, buf, x, y, font, font_color, bg_color, align_type); + char buf[VALUE_STR_LEN]; + value_2_string(value, dot_position, buf, VALUE_STR_LEN); + draw_string_in_rect(surface, z_order, buf, rect, (const LATTICE_FONT_INFO*)font, font_color, bg_color, align_type); } - static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + int get_str_size(const void *string, const void* font, int& width, int& height) { - char buf[BUFFER_LEN]; - value_2_string(value, dot_position, buf, BUFFER_LEN); - draw_string_in_rect(surface, z_order, buf, rect, font, font_color, bg_color, align_type); + const char* s = (const char*)string; + if (0 == s || 0 == font) + { + width = height = 0; + return -1; + } + int lattice_width = 0; + unsigned int utf8_code; + int utf8_bytes; + while (*s) + { + utf8_bytes = get_utf8_code(s, utf8_code); + const LATTICE* p_lattice = get_lattice((const LATTICE_FONT_INFO*)font, utf8_code); + lattice_width += p_lattice ? p_lattice->width : ((const LATTICE_FONT_INFO*)font)->height; + s += utf8_bytes; + } + width = lattice_width; + height = ((const LATTICE_FONT_INFO*)font)->height; + return 0; } - static void value_2_string(int value, int dot_position, char* buf, int len) +private: + void value_2_string(int value, int dot_position, char* buf, int len) { memset(buf, 0, len); switch (dot_position) @@ -880,29 +915,7 @@ public: break; } } - static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) - { - if (0 == s || 0 == font) - { - width = height = 0; - return -1; - } - int lattice_width = 0; - unsigned int utf8_code; - int utf8_bytes; - while (*s) - { - utf8_bytes = get_utf8_code(s, utf8_code); - const LATTICE* p_lattice = get_lattice(font, utf8_code); - lattice_width += p_lattice ? p_lattice->width : font->height; - s += utf8_bytes; - } - width = lattice_width; - height = font->height; - return 0; - } -private: - static int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const FONT_INFO* font, unsigned int font_color, unsigned int bg_color) + int draw_single_char(c_surface* surface, int z_order, unsigned int utf8_code, int x, int y, const LATTICE_FONT_INFO* font, unsigned int font_color, unsigned int bg_color) { unsigned int error_color = 0xFFFFFFFF; if (font) @@ -910,7 +923,7 @@ private: const LATTICE* p_lattice = get_lattice(font, utf8_code); if (p_lattice) { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_gray_array, font_color, bg_color); + draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->pixel_buffer, font_color, bg_color); return p_lattice->width; } } @@ -932,7 +945,7 @@ private: } return len; } - static void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) + void draw_lattice(c_surface* surface, int z_order, int x, int y, int width, int height, const unsigned char* p_data, unsigned int font_color, unsigned int bg_color) { unsigned int r, g, b, rgb; unsigned char blk_value = *p_data++; @@ -970,7 +983,7 @@ private: } } - static const LATTICE* get_lattice(const FONT_INFO* font, unsigned int utf8_code) + const LATTICE* get_lattice(const LATTICE_FONT_INFO* font, unsigned int utf8_code) { int first = 0; int last = font->count - 1; @@ -991,7 +1004,7 @@ private: } return 0; } - static void get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) + void get_string_pos(const char *s, const LATTICE_FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { int x_size, y_size; get_str_size(s, font, x_size, y_size); @@ -1089,6 +1102,32 @@ private: return utf8_bytes; } }; +class c_word +{ +public: + static void draw_string(c_surface* surface, int z_order, const void* string, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color)//string: char or wchar_t + { + fontOperator->draw_string(surface, z_order, string, x, y, font, font_color, bg_color); + } + static void draw_string_in_rect(c_surface* surface, int z_order, const void* string, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT)//string: char or wchar_t + { + fontOperator->draw_string_in_rect(surface, z_order, string, rect, font, font_color, bg_color, align_type); + } + static void draw_value_in_rect(c_surface* surface, int z_order, int value, int dot_position, c_rect rect, const void* font, unsigned int font_color, unsigned int bg_color, unsigned int align_type = ALIGN_LEFT) + { + fontOperator->draw_value_in_rect(surface, z_order, value, dot_position, rect, font, font_color, bg_color, align_type); + } + static void draw_value(c_surface* surface, int z_order, int value, int dot_position, int x, int y, const void* font, unsigned int font_color, unsigned int bg_color) + { + fontOperator->draw_value(surface, z_order, value, dot_position, x, y, font, font_color, bg_color); + } + + static int get_str_size(const void* string, const void* font, int& width, int& height) + { + return fontOperator->get_str_size(string, font, width, height); + } + static c_font_operator* fontOperator; +}; #define DEFAULT_MASK_COLOR 0xFF080408 class c_surface; class c_bitmap @@ -1173,8 +1212,6 @@ public: } } }; -typedef struct struct_font_info FONT_INFO; -typedef struct struct_color_rect COLOR_RECT; class c_wnd; class c_surface; typedef enum @@ -1325,8 +1362,8 @@ public: unsigned int get_font_color() { return m_font_color; } void set_bg_color(unsigned int color) { m_bg_color = color; } unsigned int get_bg_color() { return m_bg_color; } - void set_font_type(const FONT_INFO *font_type) { m_font_type = font_type; } - const FONT_INFO* get_font_type() { return m_font_type; } + void set_font_type(const LATTICE_FONT_INFO *font_type) { m_font = font_type; } + const void* get_font_type() { return m_font; } void set_wnd_pos(short x, short y, short width, short height) { m_wnd_rect.m_left = x; @@ -1612,11 +1649,11 @@ protected: c_wnd* m_next_sibling; //next brother c_wnd* m_focus_child; //current focused window const char* m_str; //caption - const FONT_INFO* m_font_type; - unsigned int m_font_color; - unsigned int m_bg_color; - int m_z_order; //the graphic level for rendering - c_surface* m_surface; + const void* m_font; //font face + unsigned int m_font_color; + unsigned int m_bg_color; + int m_z_order; //the graphic level for rendering + c_surface* m_surface; }; class c_button : public c_wnd { @@ -1633,14 +1670,14 @@ protected: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_FOCUSED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } break; case STATUS_PUSHED: @@ -1648,7 +1685,7 @@ protected: m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); if (m_str) { - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); } break; default: @@ -1670,7 +1707,7 @@ protected: { on_click = 0; m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_touch(int x, int y, TOUCH_ACTION action) @@ -1786,7 +1823,7 @@ protected: m_surface->fill_rect(rect, m_bg_color, m_z_order); if (m_str) { - c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_str, rect.m_left + 35, rect.m_top, c_theme::get_font(FONT_DEFAULT), GL_RGB(255, 255, 255), GL_ARGB(0, 0, 0, 0)); } } private: @@ -2004,31 +2041,31 @@ protected: } if (m_id == 0x14) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Caps", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x1B) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Esc", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == ' ') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Space", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '\n') { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Enter", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == '.') { - return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, ".", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x7F) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "Back", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } else if (m_id == 0x90) { - return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + return c_word::draw_string_in_rect(m_surface, m_z_order, "?123", rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } char letter[] = { 0, 0 }; if (m_id >= 'A' && m_id <= 'Z') @@ -2039,7 +2076,7 @@ protected: { letter[0] = (char)m_id; } - c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); + c_word::draw_string_in_rect(m_surface, m_z_order, letter, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_attr); } }; #include @@ -2064,7 +2101,7 @@ protected: { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); m_kb_style = STYLE_ALL_BOARD; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); memset(m_str_input, 0, sizeof(m_str_input)); memset(m_str, 0, sizeof(m_str)); @@ -2086,7 +2123,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2097,7 +2134,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: if (m_z_order == m_parent->get_z_order()) @@ -2108,8 +2145,8 @@ protected: } m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_PUSHED), m_parent->get_z_order()); m_surface->draw_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, c_theme::get_color(COLOR_WND_BORDER), m_parent->get_z_order(), 2); - strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : - c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); + strlen(m_str_input) ? c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str_input, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER) : + c_word::draw_string_in_rect(m_surface, m_parent->get_z_order(), m_str, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); break; default: ASSERT(false); @@ -2238,7 +2275,7 @@ public: if (m_str) { m_surface->fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font_type, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_str, rect, m_font, m_font_color, bg_color, ALIGN_LEFT | ALIGN_VCENTER); } } protected: @@ -2246,7 +2283,7 @@ protected: { m_attr = ATTR_VISIBLE; m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); } }; #include @@ -2290,7 +2327,7 @@ protected: memset(m_item_array, 0, sizeof(m_item_array)); m_item_total = 0; m_selected_item = 0; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } virtual void on_paint() @@ -2307,7 +2344,7 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_FOCUSED: if (m_z_order > m_parent->get_z_order()) @@ -2317,12 +2354,12 @@ protected: m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); } m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); break; case STATUS_PUSHED: m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_PUSHED), m_z_order); m_surface->draw_rect(rect, c_theme::get_color(COLOR_WND_BORDER), 2, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font_type, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[m_selected_item], rect, m_font, GL_RGB(2, 124, 165), GL_ARGB(0, 0, 0, 0), ALIGN_HCENTER | ALIGN_VCENTER); //draw list if (m_item_total > 0) { @@ -2400,12 +2437,12 @@ private: if (m_selected_item == i) { m_surface->fill_rect(tmp_rect, c_theme::get_color(COLOR_WND_FOCUS), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); } else { m_surface->fill_rect(tmp_rect, GL_RGB(17, 17, 17), m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font_type, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_string_in_rect(m_surface, m_z_order, m_item_array[i], tmp_rect, m_font, m_font_color, GL_RGB(17, 17, 17), ALIGN_HCENTER | ALIGN_VCENTER); } } } @@ -2837,12 +2874,12 @@ protected: get_screen_rect(rect); rect.m_right = rect.m_left + (rect.width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); - c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); + c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; @@ -2982,14 +3019,14 @@ protected: virtual void pre_create_wnd() { m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); } void draw_item(int row, int col, const char* str, unsigned int color) { c_rect rect = get_item_rect(row, col); m_surface->fill_rect(rect.m_left + 1, rect.m_top + 1, rect.m_right - 1, rect.m_bottom - 1, color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font_type, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); + c_word::draw_string_in_rect(m_surface, m_z_order, str, rect, m_font, m_font_color, GL_ARGB(0, 0, 0, 0), m_align_type); } unsigned int m_align_type; unsigned int m_row_num; @@ -3154,15 +3191,15 @@ public: get_screen_rect(rect); m_surface->fill_rect(rect, m_back_color, m_z_order); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } void set_wave_name(char* wave_name){ m_wave_name = wave_name;} void set_wave_unit(char* wave_unit){ m_wave_unit = wave_unit;} - void set_wave_name_font(const FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} - void set_wave_unit_font(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} + void set_wave_name_font(const LATTICE_FONT_INFO* wave_name_font_type){ m_wave_name_font = wave_name_font_type;} + void set_wave_unit_font(const LATTICE_FONT_INFO* wave_unit_font_type){ m_wave_unit_font = wave_unit_font_type;} void set_wave_name_color(unsigned int wave_name_color){ m_wave_name_color = wave_name_color;} void set_wave_unit_color(unsigned int wave_unit_color){ m_wave_unit_color = wave_unit_color;} void set_wave_color(unsigned int color){ m_wave_color = color;} @@ -3323,8 +3360,8 @@ protected: } char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font; - const FONT_INFO* m_wave_unit_font; + const LATTICE_FONT_INFO* m_wave_name_font; + const LATTICE_FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; unsigned int m_wave_color; @@ -3349,10 +3386,17 @@ private: #ifdef GUILITE_ON -const FONT_INFO* c_theme::s_font_map[FONT_MAX]; +FONT_INFO c_theme::s_font_map[FONT_MAX]; const BITMAP_INFO* c_theme::s_bmp_map[BITMAP_MAX]; unsigned int c_theme::s_color_map[COLOR_MAX]; +#endif + +#ifdef GUILITE_ON + +c_lattice_font_op the_lattice_font_op = c_lattice_font_op(); +c_font_operator* c_word::fontOperator = &the_lattice_font_op; + #endif #ifdef GUILITE_ON #if (defined __linux__) || (defined __APPLE__) diff --git a/HostMonitor/UIcode/source/manager/value_ctrl_manager.cpp b/HostMonitor/UIcode/source/manager/value_ctrl_manager.cpp index aa980dd118bf9282804eb50b5d7fdf18c04c97a8..33bf2475a90f5cf1a32e292683401847c1a86043 100644 --- a/HostMonitor/UIcode/source/manager/value_ctrl_manager.cpp +++ b/HostMonitor/UIcode/source/manager/value_ctrl_manager.cpp @@ -48,10 +48,10 @@ void c_value_ctrl_manage::config_param_ctrl_att(E_VALUE_TYPE value_id, c_value_c p_value_ctrl->set_high_limit(200, 0); p_value_ctrl->set_low_limit(0, 0); - p_value_ctrl->set_name_font_type(c_theme::get_font(p_cur_disc->name_font_type)); - p_value_ctrl->set_unit_font_type(c_theme::get_font(p_cur_disc->unit_font_type)); - p_value_ctrl->set_limit_font_type(c_theme::get_font(p_cur_disc->limit_font_type)); - p_value_ctrl->set_value_font_type(c_theme::get_font(p_cur_disc->value_font_type)); + p_value_ctrl->set_name_font_type((const LATTICE_FONT_INFO*)c_theme::get_font(p_cur_disc->name_font_type)); + p_value_ctrl->set_unit_font_type((const LATTICE_FONT_INFO*)c_theme::get_font(p_cur_disc->unit_font_type)); + p_value_ctrl->set_limit_font_type((const LATTICE_FONT_INFO*)c_theme::get_font(p_cur_disc->limit_font_type)); + p_value_ctrl->set_value_font_type((const LATTICE_FONT_INFO*)c_theme::get_font(p_cur_disc->value_font_type)); p_value_ctrl->set_name_color(p_cur_disc->name_color); p_value_ctrl->set_unit_color(p_cur_disc->unit_color); diff --git a/HostMonitor/UIcode/source/manager/wave_manager.cpp b/HostMonitor/UIcode/source/manager/wave_manager.cpp index cde0a43648b7eedfae51eda01ae86c4698ee7ad3..6638a9871c44c53012415ea88b3693c0ac5addd3 100644 --- a/HostMonitor/UIcode/source/manager/wave_manager.cpp +++ b/HostMonitor/UIcode/source/manager/wave_manager.cpp @@ -44,8 +44,8 @@ int c_wave_manage::register_wave_ctrl(WAVE_TYPE wave_type, c_wave_ctrl* p_wave) p_wave->set_max_min(p_disp[wave_type].max_data,p_disp[wave_type].min_data); p_wave->set_wave_name(p_disp[wave_type].wave_name); p_wave->set_wave_unit(p_disp[wave_type].wave_unit); - p_wave->set_wave_name_font(c_theme::get_font(p_disp[wave_type].wave_name_font_type)); - p_wave->set_wave_unit_font(c_theme::get_font(p_disp[wave_type].wave_unit_font_type)); + p_wave->set_wave_name_font((const LATTICE_FONT_INFO*)c_theme::get_font(p_disp[wave_type].wave_name_font_type)); + p_wave->set_wave_unit_font((const LATTICE_FONT_INFO*)c_theme::get_font(p_disp[wave_type].wave_unit_font_type)); p_wave->set_wave_name_color(p_disp[wave_type].wave_name_color); p_wave->set_wave_unit_color(p_disp[wave_type].wave_unit_color); p_wave->set_wave_color(p_disp[wave_type].wave_color); diff --git a/HostMonitor/UIcode/source/manager/wave_manager.h b/HostMonitor/UIcode/source/manager/wave_manager.h index 4e3c2e06cd2ddd49582b038f240a3abf1caea38c..55ae6ea7fef3b9faf28b4f580eee51db13202fff 100644 --- a/HostMonitor/UIcode/source/manager/wave_manager.h +++ b/HostMonitor/UIcode/source/manager/wave_manager.h @@ -23,16 +23,15 @@ typedef enum WAVE_TYPE_MAX }WAVE_TYPE; -typedef struct struct_font_info FONT_INFO; -typedef const FONT_INFO* (*PTR_FUNC_GET_FONT)(); +typedef const LATTICE_FONT_INFO* (*PTR_FUNC_GET_FONT)(); typedef struct struct_wave_ctrl_discpritor { unsigned char wave_id; char* wave_name; char* wave_unit; - FONT_TYPE wave_name_font_type; - FONT_TYPE wave_unit_font_type; + FONT_LIST wave_name_font_type; + FONT_LIST wave_unit_font_type; unsigned int wave_name_color; unsigned int wave_unit_color; diff --git a/HostMonitor/UIcode/source/resource/font/Arial_16B.cpp b/HostMonitor/UIcode/source/resource/font/Arial_16B.cpp index a8f9a8cc4a0b0350934c0a2eb4ed1484c8f4d287..4f3efc45f627bbb661227fd209619c9ccdf8facf 100644 --- a/HostMonitor/UIcode/source/resource/font/Arial_16B.cpp +++ b/HostMonitor/UIcode/source/resource/font/Arial_16B.cpp @@ -365,8 +365,8 @@ static LATTICE lattice_array[] = { {15182001, 16, _15182001}, {15500465, 11, _15500465}, }; -extern const FONT_INFO Arial_16B; -const FONT_INFO Arial_16B ={ +extern const LATTICE_FONT_INFO Arial_16B; +const LATTICE_FONT_INFO Arial_16B ={ 16, 121, lattice_array diff --git a/HostMonitor/UIcode/source/resource/font/Arial_32B.cpp b/HostMonitor/UIcode/source/resource/font/Arial_32B.cpp index 63526e8a81c061e46a14b5c53abb220130bb2d57..ab33e8889c2585f159178383f0fe70f429c91218 100644 --- a/HostMonitor/UIcode/source/resource/font/Arial_32B.cpp +++ b/HostMonitor/UIcode/source/resource/font/Arial_32B.cpp @@ -365,8 +365,8 @@ static LATTICE lattice_array[] = { {15182001, 29, _15182001}, {15500465, 22, _15500465}, }; -extern const FONT_INFO Arial_32B; -const FONT_INFO Arial_32B ={ +extern const LATTICE_FONT_INFO Arial_32B; +const LATTICE_FONT_INFO Arial_32B ={ 32, 121, lattice_array diff --git a/HostMonitor/UIcode/source/resource/font/Arial_56B.cpp b/HostMonitor/UIcode/source/resource/font/Arial_56B.cpp index a0cf42c4ed789ca2a1aa8e81f1686e260718bc5c..48c0c6eec1ddff29bd20624466c825df74c92cf6 100644 --- a/HostMonitor/UIcode/source/resource/font/Arial_56B.cpp +++ b/HostMonitor/UIcode/source/resource/font/Arial_56B.cpp @@ -59,8 +59,8 @@ static LATTICE lattice_array[] = { {63, 29, _63}, {95, 27, _95}, }; -extern const FONT_INFO Arial_56B; -const FONT_INFO Arial_56B ={ +extern const LATTICE_FONT_INFO Arial_56B; +const LATTICE_FONT_INFO Arial_56B ={ 56, 19, lattice_array diff --git a/HostMonitor/UIcode/source/resource/font/Arial_62B.cpp b/HostMonitor/UIcode/source/resource/font/Arial_62B.cpp index 1df41df416402959dfe7de3ad364f505d3fe8989..c96abce60b1ca4c2098936fd58cffb63a9f3f1bc 100644 --- a/HostMonitor/UIcode/source/resource/font/Arial_62B.cpp +++ b/HostMonitor/UIcode/source/resource/font/Arial_62B.cpp @@ -59,8 +59,8 @@ static LATTICE lattice_array[] = { {63, 32, _63}, {95, 29, _95}, }; -extern const FONT_INFO Arial_62B; -const FONT_INFO Arial_62B ={ +extern const LATTICE_FONT_INFO Arial_62B; +const LATTICE_FONT_INFO Arial_62B ={ 62, 19, lattice_array diff --git a/HostMonitor/UIcode/source/resource/resource.cpp b/HostMonitor/UIcode/source/resource/resource.cpp index 942273d960a0c1005adbf690d3475aff532b86ee..a35c75d9e3c7a5c9ef9c8f0979d27202838666f0 100644 --- a/HostMonitor/UIcode/source/resource/resource.cpp +++ b/HostMonitor/UIcode/source/resource/resource.cpp @@ -1,10 +1,10 @@ #include "../include/GuiLite.h" //fonts -extern const FONT_INFO Arial_16B; -extern const FONT_INFO Arial_32B; -extern const FONT_INFO Arial_56B; -extern const FONT_INFO Arial_62B; +extern const LATTICE_FONT_INFO Arial_16B; +extern const LATTICE_FONT_INFO Arial_32B; +extern const LATTICE_FONT_INFO Arial_56B; +extern const LATTICE_FONT_INFO Arial_62B; //icons extern const BITMAP_INFO bmspin_up_button_normal; @@ -14,16 +14,6 @@ extern const BITMAP_INFO bmspin_down_button_focus; extern const BITMAP_INFO wave_background_1_bmp; extern const BITMAP_INFO wave_background_2_bmp; -//shapes -extern COLOR_RECT shape_bt_normal[]; -extern COLOR_RECT shape_bt_focus[]; -extern COLOR_RECT shape_bt_push[]; -extern COLOR_RECT shape_listbox_select[]; -extern COLOR_RECT shape_listbox_push[]; -extern COLOR_RECT shape_listbox_extend[]; -extern COLOR_RECT shape_keyboard_bt_normal[]; -extern COLOR_RECT shape_keyboard_bt_push[]; - void load_theme(int index) { switch (index) diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp index 4edc2f8bf72f7314b7780b62b6187b9b4c08a23a..01d90a065a1d8476a8ef31777b4513145b244d27 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.cpp @@ -44,11 +44,11 @@ void c_time_bar::on_paint(void) void c_time_bar::set_time(long time) { - set_scale_bar_atrrs((time - ((TIME_MARK_CNT - 1) * 60)), time, GL_RGB(255, 255, 255), c_theme::get_font(FONT_DEFAULT)); + set_scale_bar_atrrs((time - ((TIME_MARK_CNT - 1) * 60)), time, GL_RGB(255, 255, 255), (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); draw_mark(); } -int c_time_bar::set_scale_bar_atrrs(long start_time, long end_time, unsigned int color, const FONT_INFO* font) +int c_time_bar::set_scale_bar_atrrs(long start_time, long end_time, unsigned int color, const LATTICE_FONT_INFO* font) { if ( !font || end_time <= start_time) { diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h index 0c0d3fccb430da7ca9926bb604f68365445b7bd1..836fc782dda8a62fe22430f439caa412613c248b 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/time_bar.h @@ -12,14 +12,14 @@ public: long get_start_time(){return m_start_seconds;} long get_end_time(){return m_end_seconds;} private: - int set_scale_bar_atrrs(long start_time, long end_time, unsigned int color, const FONT_INFO* font);//time unit: second + int set_scale_bar_atrrs(long start_time, long end_time, unsigned int color, const LATTICE_FONT_INFO* font);//time unit: second void draw_scale(); void draw_mark(); unsigned int time_2_pos_x(int time_minute); void on_btn_click(int ctrl_id, int param); private: unsigned int m_scale_color; - const FONT_INFO* m_mark_font; + const LATTICE_FONT_INFO* m_mark_font; long m_end_seconds; long m_start_seconds; diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/time_label.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/time_label.cpp index b1f68b66a534487589aacb7537a554bd91e1f2b5..d3c4a8197b94bf972ebe136302b2850942440d04 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/time_label.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/time_label.cpp @@ -5,7 +5,7 @@ void c_time_label::on_init_children(void) { - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); set_font_color(GL_RGB(255,255,255)); memset(&m_time, 0, sizeof(m_time)); } @@ -31,7 +31,7 @@ void c_time_label::on_paint(void) memset(tmp_str,0,sizeof(tmp_str)); sprintf(tmp_str, "%04d-%02d-%02d", cur_time.year, cur_time.month, cur_time.day); m_surface->fill_rect(temp_rect.m_left, temp_rect.m_top, temp_rect.m_right, temp_rect.m_bottom, m_bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, tmp_str, temp_rect, m_font_type, m_font_color, m_bg_color, ALIGN_LEFT); + c_word::draw_string_in_rect(m_surface, m_z_order, tmp_str, temp_rect, m_font, m_font_color, m_bg_color, ALIGN_LEFT); } temp_rect.m_left = rect.m_left;// + 25; @@ -41,6 +41,6 @@ void c_time_label::on_paint(void) memset(tmp_str,0,sizeof(tmp_str)); sprintf(tmp_str, "%02d:%02d:%02d", cur_time.hour, cur_time.minute, cur_time.second); m_surface->fill_rect(temp_rect.m_left, temp_rect.m_top, temp_rect.m_right, temp_rect.m_bottom, m_bg_color, m_z_order); - c_word::draw_string_in_rect(m_surface, m_z_order, tmp_str,temp_rect, m_font_type, m_font_color, m_bg_color, ALIGN_LEFT); + c_word::draw_string_in_rect(m_surface, m_z_order, tmp_str,temp_rect, m_font, m_font_color, m_bg_color, ALIGN_LEFT); m_time = cur_time; } diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.cpp index 6bbcc5de32ea853a12991270737eb0ed5d224d64..194f7be7bdda19e146089667b91315280baa3f39 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.cpp @@ -38,12 +38,12 @@ void c_trend_graph::on_init_children(void) m_v_axis_height = V_AXIS_HEIGHT; m_org_y_of_h_axis = (m_v_axis_height + 10); m_org_x_of_h_axis = X_ORG_OF_H_AXIS; - m_h_axis_mark_font = c_theme::get_font(FONT_DEFAULT); + m_h_axis_mark_font = (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT); for ( int i = 0; i < V_AXIS_CNT; i++ ) { m_v_axis_min[i] = m_v_axis_max[i] = m_v_scale_cnt[i] = 0; - m_v_axis_mark_font[i] = c_theme::get_font(FONT_DEFAULT); + m_v_axis_mark_font[i] = (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT); } memset(m_v_scale_value , 0 , sizeof( m_v_scale_value )); @@ -66,7 +66,7 @@ void c_trend_graph::set_v_axis_height(int height) m_org_y_of_h_axis = (m_v_axis_height + 10); } -void c_trend_graph::set_h_axis_atrrs(const FONT_INFO* font, long scale_value[], int scale_count) +void c_trend_graph::set_h_axis_atrrs(const LATTICE_FONT_INFO* font, long scale_value[], int scale_count) { if (!font || scale_count < 0 || scale_count > MAX_MARK_CNT) { @@ -85,7 +85,7 @@ void c_trend_graph::set_h_axis_atrrs(const FONT_INFO* font, long scale_value[], m_h_axis_max = scale_value[scale_count - 1]; } -void c_trend_graph::set_v_axis_atrrs(unsigned int v_axis_index, unsigned int color, const FONT_INFO* font, int value_scale[], int scale_count) +void c_trend_graph::set_v_axis_atrrs(unsigned int v_axis_index, unsigned int color, const LATTICE_FONT_INFO* font, int value_scale[], int scale_count) { if ( !font || scale_count <= 0 || scale_count > MAX_MARK_CNT || v_axis_index >= V_AXIS_CNT ) { @@ -218,7 +218,7 @@ void c_trend_graph::draw_line(unsigned int v_axis_index, unsigned int line_index draw_line_by_pixel(m_line_x_buf[line_index], m_line_y_buf[line_index], len, color); } -void c_trend_graph::draw_title(unsigned int row_index, char* str, unsigned int color, const FONT_INFO* font) +void c_trend_graph::draw_title(unsigned int row_index, char* str, unsigned int color, const LATTICE_FONT_INFO* font) { if (row_index >= MAX_TITLE_CNT || !font) { @@ -268,22 +268,22 @@ void c_trend_graph::on_paint(void) switch (m_type) { case TREND_TYPE_VITAL: - draw_title(0, "--Vitals", GL_RGB(255, 255, 255), c_theme::get_font(FONT_DEFAULT)); - draw_title(1, " -HR", HR_COLOR, c_theme::get_font(FONT_DEFAULT)); - draw_title(2, " -SPO2", SPO2_COLOR, c_theme::get_font(FONT_DEFAULT)); - draw_title(3, " -RR", RR_COLOR, c_theme::get_font(FONT_DEFAULT)); - set_v_axis_atrrs(0, HR_COLOR, c_theme::get_font(FONT_DEFAULT), hr_y_axis_scale, 5); - set_v_axis_atrrs(1, SPO2_COLOR, c_theme::get_font(FONT_DEFAULT), spo2_y_axis_scale, 7); - set_v_axis_atrrs(2, RR_COLOR, c_theme::get_font(FONT_DEFAULT), rr_y_axis_scale, 7); - set_h_axis_atrrs(c_theme::get_font(FONT_DEFAULT), x_axis_marks, m_h_scale_cnt); + draw_title(0, "--Vitals", GL_RGB(255, 255, 255), (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + draw_title(1, " -HR", HR_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + draw_title(2, " -SPO2", SPO2_COLOR, (const LATTICE_FONT_INFO*)(const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + draw_title(3, " -RR", RR_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + set_v_axis_atrrs(0, HR_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), hr_y_axis_scale, 5); + set_v_axis_atrrs(1, SPO2_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), spo2_y_axis_scale, 7); + set_v_axis_atrrs(2, RR_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), rr_y_axis_scale, 7); + set_h_axis_atrrs((const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), x_axis_marks, m_h_scale_cnt); break; case TREND_TYPE_NIBP: - draw_title(0, "--PRESSURES", GL_RGB(255, 255, 255), c_theme::get_font(FONT_DEFAULT)); - draw_title(1, "-NIBP(sys) mmHg", NIBP_COLOR, c_theme::get_font(FONT_DEFAULT)); - draw_title(2, "-NIBP(dia) mmHg", NIBP_COLOR, c_theme::get_font(FONT_DEFAULT)); - draw_title(3, "-NIBP(mean) mmHg", NIBP_COLOR, c_theme::get_font(FONT_DEFAULT)); - set_v_axis_atrrs(0, NIBP_COLOR, c_theme::get_font(FONT_DEFAULT), pressure_y_axis_scale, 5); - set_h_axis_atrrs(c_theme::get_font(FONT_DEFAULT), x_axis_marks, m_h_scale_cnt); + draw_title(0, "--PRESSURES", GL_RGB(255, 255, 255), (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + draw_title(1, "-NIBP(sys) mmHg", NIBP_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + draw_title(2, "-NIBP(dia) mmHg", NIBP_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + draw_title(3, "-NIBP(mean) mmHg", NIBP_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); + set_v_axis_atrrs(0, NIBP_COLOR, (const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), pressure_y_axis_scale, 5); + set_h_axis_atrrs((const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), x_axis_marks, m_h_scale_cnt); break; default: return; diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.h b/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.h index 90386754a20b567813d7cc4a7c3069c5498c29bb..dc5491a99c345f5e3298e6e261885a7182ef61e4 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.h +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/trend_graph.h @@ -22,13 +22,13 @@ public: void set_type(enum TREND_TYPE type) { m_type = type; } void set_v_axis_height(int height); - void set_h_axis_atrrs(const FONT_INFO* font, long scale_value[], int scale_count);//time in seconds. - void set_v_axis_atrrs(unsigned int v_axis_index, unsigned int color, const FONT_INFO* font, int scale_value[], int scale_count); + void set_h_axis_atrrs(const LATTICE_FONT_INFO* font, long scale_value[], int scale_count);//time in seconds. + void set_v_axis_atrrs(unsigned int v_axis_index, unsigned int color, const LATTICE_FONT_INFO* font, int scale_value[], int scale_count); void draw_line(unsigned int v_axis_index, unsigned int line_index, int data[], unsigned int len, unsigned int color); void draw_h_axis(void); private: void draw_line_by_pixel(int* line_x_buf, int* line_y_buf, int len, unsigned int color); - void draw_title(unsigned int row_index, char* str, unsigned int color, const FONT_INFO* font); + void draw_title(unsigned int row_index, char* str, unsigned int color, const LATTICE_FONT_INFO* font); void draw_v_axis(int index); void draw_v_axis(void); private: @@ -40,7 +40,7 @@ private: int m_h_scale_time_interval; int m_org_y_of_h_axis; int m_org_x_of_h_axis; - const FONT_INFO* m_h_axis_mark_font; + const LATTICE_FONT_INFO* m_h_axis_mark_font; int m_v_axis_height; int m_v_axis_min[V_AXIS_CNT]; @@ -49,7 +49,7 @@ private: int m_v_scale_cnt[V_AXIS_CNT]; int m_org_y_of_v_axis; int m_org_x_of_v_aixs[V_AXIS_CNT]; - const FONT_INFO* m_v_axis_mark_font[V_AXIS_CNT]; + const LATTICE_FONT_INFO* m_v_axis_mark_font[V_AXIS_CNT]; unsigned int m_v_axis_color[V_AXIS_CNT]; int m_line_x_buf[MAX_LINE_CNT][MAX_TREND_DATA_CNT]; diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/trend_table.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/trend_table.cpp index ab422a74803df833fec6573387d85b5a1201b924..0fb106b29fe1643af77fec2c73a16cf5b8c989fc 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/trend_table.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/trend_table.cpp @@ -9,7 +9,7 @@ void c_trend_table::on_init_children(void) m_bg_color = GL_RGB(80, 87, 104); m_align_type = ALIGN_LEFT | ALIGN_VCENTER; - m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font = c_theme::get_font(FONT_DEFAULT); set_col_num(9); set_row_num(9); diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.cpp index 23114aaff1ba11783ba68b4d8d51babbc84a3e82..4a622a135a71036814bce32ef9336331e07c7e68 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.cpp @@ -25,7 +25,7 @@ void c_value_ctrl::refresh_value(short value, unsigned short dot_position, bool c_word::draw_string_in_rect(m_surface, m_z_order, m_value_in_str, m_value_rect, m_value_font_type, m_bg_color, GL_ARGB(0, 0, 0, 0), m_value_align_type); memset(m_value_in_str, 0, sizeof(m_value_in_str)); - c_word::value_2_string(value, dot_position, m_value_in_str, sizeof(m_value_in_str)); + value_2_string(value, dot_position, m_value_in_str, sizeof(m_value_in_str)); if (flash_color) { c_word::draw_string_in_rect(m_surface, m_z_order, m_value_in_str, m_value_rect, m_value_font_type, m_bg_color, flash_color, m_value_align_type); @@ -43,7 +43,7 @@ void c_value_ctrl::refresh_value(short value, unsigned short dot_position, bool c_word::draw_string_in_rect(m_surface, m_z_order, m_value_in_str, m_value_rect, m_value_font_type, m_bg_color, GL_ARGB(0, 0, 0, 0), m_value_align_type); memset(m_value_in_str, 0, sizeof(m_value_in_str)); - c_word::value_2_string(value, dot_position, m_value_in_str, sizeof(m_value_in_str)); + value_2_string(value, dot_position, m_value_in_str, sizeof(m_value_in_str)); c_word::draw_string_in_rect(m_surface, m_z_order, m_value_in_str, m_value_rect, m_value_font_type, m_name_color, m_bg_color, m_value_align_type); } EXIT: @@ -94,7 +94,7 @@ void c_value_ctrl::on_paint(void) m_value_rect.m_left = rect.m_left + 50; m_value_rect.m_top = rect.m_top +(height - (m_value_font_type->height)) / 2; - c_word::value_2_string(m_value, m_limit_dot_position, m_value_in_str, sizeof(m_value_in_str)); + value_2_string(m_value, m_limit_dot_position, m_value_in_str, sizeof(m_value_in_str)); int strWidth, strHeight; c_word::get_str_size(m_value_in_str, m_value_font_type, strWidth, strHeight); @@ -103,3 +103,26 @@ void c_value_ctrl::on_paint(void) c_word::draw_string_in_rect(m_surface, m_z_order, m_value_in_str, m_value_rect, m_value_font_type, m_name_color, m_bg_color, m_value_align_type); } + +void c_value_ctrl::value_2_string(int value, int dot_position, char* buf, int len) +{ + memset(buf, 0, len); + switch (dot_position) + { + case 0: + sprintf(buf, "%d", value); + break; + case 1: + sprintf(buf, "%.1f", value * 1.0 / 10); + break; + case 2: + sprintf(buf, "%.2f", value * 1.0 / 100); + break; + case 3: + sprintf(buf, "%.3f", value * 1.0 / 1000); + break; + default: + ASSERT(false); + break; + } +} diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.h b/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.h index 6e047992c0ab2add1a912bd414f0b50b92ba58b0..64b76d6750038bcd14097221f45614ad2cc9aee4 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.h +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/value_ctrl.h @@ -11,10 +11,10 @@ typedef struct char* unit; unsigned short value_id; - FONT_TYPE name_font_type; - FONT_TYPE unit_font_type; - FONT_TYPE limit_font_type; - FONT_TYPE value_font_type; + FONT_LIST name_font_type; + FONT_LIST unit_font_type; + FONT_LIST limit_font_type; + FONT_LIST value_font_type; unsigned int name_color; unsigned int unit_color; @@ -36,15 +36,16 @@ public: void set_value_dot_position(unsigned short dot_position){m_value_dot_position = m_limit_dot_position = dot_position;} virtual void refresh_value(short value, unsigned short dot_position, bool flash_or_not, unsigned int flash_color); - void set_name_font_type(const FONT_INFO *name_font_type){m_name_font_type = name_font_type;} - void set_unit_font_type(const FONT_INFO *unit_font_type){m_unit_font_type = unit_font_type;} - void set_limit_font_type(const FONT_INFO *limit_font_type){m_limit_font_type = limit_font_type;} - void set_value_font_type(const FONT_INFO *value_font_type){m_value_font_type = value_font_type;} + void set_name_font_type(const LATTICE_FONT_INFO*name_font_type){m_name_font_type = (const LATTICE_FONT_INFO*)name_font_type;} + void set_unit_font_type(const LATTICE_FONT_INFO*unit_font_type){m_unit_font_type = (const LATTICE_FONT_INFO*)unit_font_type;} + void set_limit_font_type(const LATTICE_FONT_INFO*limit_font_type){m_limit_font_type = (const LATTICE_FONT_INFO*)limit_font_type;} + void set_value_font_type(const LATTICE_FONT_INFO*value_font_type){m_value_font_type = (const LATTICE_FONT_INFO*)value_font_type;} void set_name_color(unsigned int color){m_name_color = color;} void set_unit_color(unsigned int color){m_unit_color = color;} void set_limit_color(unsigned int color){m_limit_color = color;} protected: + void value_2_string(int value, int dot_position, char* buf, int len); virtual void on_paint(void); short m_value; @@ -64,10 +65,10 @@ protected: short m_limit_dot_position; c_rect m_limit_rect; - const FONT_INFO *m_value_font_type; - const FONT_INFO *m_name_font_type; - const FONT_INFO *m_unit_font_type; - const FONT_INFO *m_limit_font_type; + const LATTICE_FONT_INFO*m_value_font_type; + const LATTICE_FONT_INFO*m_name_font_type; + const LATTICE_FONT_INFO*m_unit_font_type; + const LATTICE_FONT_INFO*m_limit_font_type; unsigned int m_name_color; unsigned int m_unit_color; diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/value_sub_ctrl.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/value_sub_ctrl.cpp index a09ec4a844191ecae6860fc9e4f919a36ccbbf7c..fdf8ea788adb34e8d35acbef41d09669045e87bf 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/value_sub_ctrl.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/value_sub_ctrl.cpp @@ -22,7 +22,7 @@ void c_value_sub_ctrl::on_paint(void) } char buf[16]; - c_word::value_2_string(m_high_limit, m_limit_dot_position, buf, sizeof(buf)); + value_2_string(m_high_limit, m_limit_dot_position, buf, sizeof(buf)); int strWidth, strHeight; c_word::get_str_size(buf, m_value_font_type, strWidth, strHeight); m_value_rect.m_right = m_value_rect.m_left + strWidth; @@ -37,6 +37,6 @@ void c_value_sub_ctrl::on_paint(void) m_value_rect.m_bottom = rect.m_bottom - 2; } - c_word::value_2_string(m_value, m_limit_dot_position, m_value_in_str, sizeof(m_value_in_str)); + value_2_string(m_value, m_limit_dot_position, m_value_in_str, sizeof(m_value_in_str)); c_word::draw_string_in_rect(m_surface, m_z_order, m_value_in_str, m_value_rect, m_value_font_type, m_name_color, m_bg_color, m_value_align_type); } diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.cpp b/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.cpp index 82c87344fc23d9640a911b32d6aa1861df7d36e3..3ffa6a72d267192ed32d5439a4333b143cecaf9e 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.cpp +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.cpp @@ -73,9 +73,9 @@ void c_bitmap_wave_ctrl::on_paint() c_bitmap::draw_bitmap(m_surface, m_z_order, c_theme::get_bmp(m_bitmap_type), rect.m_left, rect.m_top); //show name - c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_name, m_wave_left + 10, rect.m_top, m_wave_name_font, m_wave_name_color, GL_ARGB(0, 0, 0, 0)); //show unit - c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0), ALIGN_LEFT); + c_word::draw_string(m_surface, m_z_order, m_wave_unit, m_wave_left + 60, rect.m_top, m_wave_unit_font, m_wave_unit_color, GL_ARGB(0, 0, 0, 0)); save_background(); } \ No newline at end of file diff --git a/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.h b/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.h index f2e12d2e9106b772e124931def3634f06c00a988..06d998a4d6ff3e0d984c5627da91160cc807cb83 100644 --- a/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.h +++ b/HostMonitor/UIcode/source/ui_ctrl_ex/wave_ctrl_ex.h @@ -14,11 +14,11 @@ protected: class c_bitmap_wave_ctrl : public c_wave_ctrl { public: - void set_bitmap(BITMAP_TYPE type) { m_bitmap_type = type; } + void set_bitmap(BITMAP_LIST type) { m_bitmap_type = type; } protected: virtual void on_paint(void); private: - BITMAP_TYPE m_bitmap_type; + BITMAP_LIST m_bitmap_type; }; #endif /* _WAVE_CTRL_EX_H_ */ diff --git a/HostMonitor/UIcode/source/ui_layout/View/nibp_list/nibp_list_view.cpp b/HostMonitor/UIcode/source/ui_layout/View/nibp_list/nibp_list_view.cpp index 4107914b48b71c698cbffa4bcbf874e10a7c9667..20225393737d4b3f86ebe6e9c4443a0541d54f2b 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/nibp_list/nibp_list_view.cpp +++ b/HostMonitor/UIcode/source/ui_layout/View/nibp_list/nibp_list_view.cpp @@ -24,7 +24,7 @@ void c_nibplist_view::on_init_children(void) m_table_colnum = 3; int col_width = total_width/(m_table_colnum+3); - p_table->set_font_type(c_theme::get_font(FONT_DEFAULT)); + p_table->set_font_type((const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); int row_height = 26; m_table_rownum = total_height / row_height; diff --git a/HostMonitor/UIcode/source/ui_layout/View/nibp_value/nibp_value_view.cpp b/HostMonitor/UIcode/source/ui_layout/View/nibp_value/nibp_value_view.cpp index 6e81a9a6cb6ad79006d3760e9335d055f1d80eee..b0264da21a5a18e3c07297e7c84c5479c85d9f27 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/nibp_value/nibp_value_view.cpp +++ b/HostMonitor/UIcode/source/ui_layout/View/nibp_value/nibp_value_view.cpp @@ -21,7 +21,7 @@ void c_nibp_value_view::on_init_children(void) return; } - p_name->set_font_type(c_theme::get_font(FONT_DEFAULT)); + p_name->set_font_type((const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT)); p_name->set_font_color(GL_RGB(255, 255, 255)); c_value_ctrl_manage::get_instance()->config_param_ctrl_att(VALUE_NIBP_SYS, p_sys_value); diff --git a/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp b/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp index 3fe047bc0b5d18c55fc995ba48b9467a0d1d3680..d9126d5f6652026ad3b90b5f42db586d5ae52938 100644 --- a/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp +++ b/HostMonitor/UIcode/source/ui_layout/View/trend/trend_view.cpp @@ -116,9 +116,9 @@ void c_trend_view::refresh_trend_graphic(long time) { x_axis_marks[(H_AXIS_MARK_CNT - 1) - i] = (time - (i * H_AXIS_MARK_INTERVAL)); } - p_vitals_trend_graph->set_h_axis_atrrs(c_theme::get_font(FONT_DEFAULT), x_axis_marks, H_AXIS_MARK_CNT); + p_vitals_trend_graph->set_h_axis_atrrs((const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), x_axis_marks, H_AXIS_MARK_CNT); p_vitals_trend_graph->draw_h_axis(); - p_nibp_trend->set_h_axis_atrrs(c_theme::get_font(FONT_DEFAULT), x_axis_marks, H_AXIS_MARK_CNT); + p_nibp_trend->set_h_axis_atrrs((const LATTICE_FONT_INFO*)c_theme::get_font(FONT_DEFAULT), x_axis_marks, H_AXIS_MARK_CNT); p_nibp_trend->draw_h_axis(); //update data