From 144993f2d76dac296d4324450792e4b4863bd4d6 Mon Sep 17 00:00:00 2001 From: idea4good Date: Wed, 9 Jan 2019 11:23:42 +0800 Subject: [PATCH] !8 refactor wave_ctrl & support MCU basicly. Merge pull request !8 from idea4good/dev --- .gitignore | 7 +- GuiLite.uvprojx | 472 +++++++++++++++++++++++++++++++++ core/core_include/display.h | 1 + core/core_include/surface.h | 18 ++ core/core_include/wave_ctrl.h | 13 +- core/core_include/word.h | 2 +- core/src/adapter/api_none.cpp | 84 ++++++ core/src/adapter/msg_linux.cpp | 5 - core/src/adapter/msg_none.cpp | 56 ++++ core/src/adapter/msg_win.cpp | 3 - core/src/display.cpp | 9 + core/src/surface.cpp | 49 +++- core/src/wave_ctrl.cpp | 24 +- core/src/word.cpp | 56 ++-- gui/src/my_resource.cpp | 92 +++---- 15 files changed, 781 insertions(+), 110 deletions(-) create mode 100644 GuiLite.uvprojx create mode 100644 core/src/adapter/api_none.cpp create mode 100644 core/src/adapter/msg_none.cpp diff --git a/.gitignore b/.gitignore index 48f5e8e..33bd75c 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,9 @@ cmake_install.cmake Makefile libcore.a -libgui.a \ No newline at end of file +libgui.a + +# Keil +GuiLite.uvguix.* +GuiLite.uvoptx +Objects \ No newline at end of file diff --git a/GuiLite.uvprojx b/GuiLite.uvprojx new file mode 100644 index 0000000..1cdcad3 --- /dev/null +++ b/GuiLite.uvprojx @@ -0,0 +1,472 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + GuiLite + 0x4 + ARM-ADS + 5060750::V5.06 update 6 (build 750)::ARMCC + 0 + + + ARMCM3 + ARM + ARM.CMSIS.5.4.0 + http://www.keil.com/pack/ + IRAM(0x20000000,0x00020000) IROM(0x00000000,0x00040000) CPUTYPE("Cortex-M3") CLOCK(12000000) ESEL ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000) + 0 + $$Device:ARMCM3$Device\ARM\ARMCM3\Include\ARMCM3.h + + + + + + + + + + + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\Objects\ + GuiLite + 0 + 1 + 0 + 1 + 1 + .\Listings\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + 0 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 1 + + + SARMCM3.DLL + -MPU + DCM.DLL + -pCM3 + SARMCM3.DLL + -MPU + TCM.DLL + -pCM3 + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + -1 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M3" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 8 + 0 + 1 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x20000 + + + 1 + 0x0 + 0x40000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x40000 + + + 1 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x20000000 + 0x20000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 0 + 0 + 0 + + + + + .\core + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + 0 + 1 + 0 + 0x00000000 + 0x20000000 + + + + + + + + + + + + + core + + + bitmap.cpp + 8 + .\core\src\bitmap.cpp + + + cmd_target.cpp + 8 + .\core\src\cmd_target.cpp + + + display.cpp + 8 + .\core\src\display.cpp + + + rect.cpp + 8 + .\core\src\rect.cpp + + + surface.cpp + 8 + .\core\src\surface.cpp + + + wave_buffer.cpp + 8 + .\core\src\wave_buffer.cpp + + + wave_ctrl.cpp + 8 + .\core\src\wave_ctrl.cpp + + + wnd.cpp + 8 + .\core\src\wnd.cpp + + + word.cpp + 8 + .\core\src\word.cpp + + + api_none.cpp + 8 + .\core\src\adapter\api_none.cpp + + + msg_none.cpp + 8 + .\core\src\adapter\msg_none.cpp + + + + + gui + + + button.cpp + 8 + .\gui\src\button.cpp + + + label.cpp + 8 + .\gui\src\label.cpp + + + my_resource.cpp + 8 + .\gui\src\my_resource.cpp + + + + + + + + + + + + + +
diff --git a/core/core_include/display.h b/core/core_include/display.h index 2f8e108..bed3dd2 100644 --- a/core/core_include/display.h +++ b/core/core_include/display.h @@ -12,6 +12,7 @@ public: c_display(void* phy_fb, unsigned int display_width, unsigned int display_height, unsigned int surface_width, unsigned int surface_height, unsigned int color_bytes, unsigned int surface_cnt); + c_display(unsigned int display_width, unsigned int display_height, unsigned int color_bytes, EXTERNAL_GFX_OP* gfx_op); c_surface* alloc_surface(void* usr, Z_ORDER_LEVEL max_zorder); int merge_surface(c_surface* s1, c_surface* s2, int x0, int x1, int y0, int y2, int offset); unsigned int get_width() { return m_width; } diff --git a/core/core_include/surface.h b/core/core_include/surface.h index 12f0545..c49b0fb 100644 --- a/core/core_include/surface.h +++ b/core/core_include/surface.h @@ -70,4 +70,22 @@ class c_surface_16bits : public c_surface { protected: virtual void set_pixel(int x, int y, unsigned int rgb); }; + +struct EXTERNAL_GFX_OP +{ + void (*draw_pixel)(int x, int y, unsigned int rgb); + void (*fill_rect)(int x0, int y0, int x1, int y1, unsigned int rgb); +}; +class c_surface_mcu : public c_surface { + friend class c_display; + c_surface_mcu(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op); + virtual void draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order); + virtual void fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order); + virtual void fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb); + virtual unsigned int get_pixel(int x, int y, unsigned int z_order); +protected: + virtual void set_pixel(int x, int y, unsigned int rgb); +private: + struct EXTERNAL_GFX_OP* m_gfx_op; +}; #endif diff --git a/core/core_include/wave_ctrl.h b/core/core_include/wave_ctrl.h index c400feb..0ebb8c8 100644 --- a/core/core_include/wave_ctrl.h +++ b/core/core_include/wave_ctrl.h @@ -27,13 +27,13 @@ public: 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_type(const FONT_INFO* wave_name_font_type){ m_wave_name_font_type = wave_name_font_type;} - void set_wave_unit_font_type(const FONT_INFO* wave_unit_font_type){ m_wave_unit_font_type = wave_unit_font_type;} + 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_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;} - void set_wave_sample_rate(unsigned int rate);//speed = module sample rate + void set_wave_in_out_rate(unsigned int data_rate, unsigned int refresh_rate); void set_wave_speed(unsigned int speed); void set_max_min_base(short max_data, short min_data, short data_base); @@ -53,8 +53,8 @@ protected: char* m_wave_name; char* m_wave_unit; - const FONT_INFO* m_wave_name_font_type; - const FONT_INFO* m_wave_unit_font_type; + const FONT_INFO* m_wave_name_font; + const FONT_INFO* m_wave_unit_font; unsigned int m_wave_name_color; unsigned int m_wave_unit_color; @@ -77,7 +77,8 @@ private: unsigned int* m_bg_fb; //background frame buffer, could be used to draw scale line. int m_wave_cursor; int m_wave_speed; //pixels per refresh - int m_wave_sample_rate; + unsigned int m_wave_data_rate; //data sample rate + unsigned int m_wave_refresh_rate;//refresh cycle in millisecond unsigned char m_frame_len_map[64]; unsigned char m_frame_len_map_index; }; diff --git a/core/core_include/word.h b/core/core_include/word.h index e87eca6..41c58cb 100644 --- a/core/core_include/word.h +++ b/core/core_include/word.h @@ -11,7 +11,7 @@ public: 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); static void value_2_string(int value, int dot_position, char* buf, int len); - static int get_str_pixel_length(const char *s, const FONT_INFO* font); + static int get_str_size(const char *s, const FONT_INFO* font, int& width, int& height); 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); 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); diff --git a/core/src/adapter/api_none.cpp b/core/src/adapter/api_none.cpp new file mode 100644 index 0000000..3927af8 --- /dev/null +++ b/core/src/adapter/api_none.cpp @@ -0,0 +1,84 @@ +#include "../../core_include/api.h" +#include + +static void(*do_assert)(const char* file, int line); +static void(*do_log_out)(const char* log); +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)) +{ + do_assert = my_assert; + do_log_out = my_log_out; +} + +void _assert(const char* file, int line) +{ + if(do_assert) + { + do_assert(file, line); + } + else + { + printf("assert@ file:%s, line:%d\n", file, line); + } +} + +void log_out(const char* log) +{ + if (do_log_out) + { + do_log_out(log); + } + else + { + printf(log); + fflush(stdout); + } +} + +long get_time_in_second() +{ + return 0; +} + +T_TIME second_to_day(long second) +{ + T_TIME ret = {0}; + return ret; +} + +T_TIME get_time() +{ + T_TIME ret = {0}; + return ret; +} + +void start_real_timer(void (*func)(void* arg)) +{ + log_out("Not support now"); +} + +void register_timer(int milli_second, void func(void* ptmr, void* parg)) +{ + log_out("Not support now"); +} + +unsigned int get_cur_thread_id() +{ + log_out("Not support now"); + return 0; +} + +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg) +{ + log_out("Not support now"); +} + +void thread_sleep(unsigned int milli_seconds) +{ + log_out("Not support now"); +} + +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data) +{ + log_out("Not support now"); + return 0; +} diff --git a/core/src/adapter/msg_linux.cpp b/core/src/adapter/msg_linux.cpp index d6e3f02..2683b80 100644 --- a/core/src/adapter/msg_linux.cpp +++ b/core/src/adapter/msg_linux.cpp @@ -1,11 +1,6 @@ #include "../../core_include/api.h" -#include "../../core_include/rect.h" -#include "../../core_include/surface.h" -#include "../../core_include/display.h" #include "../../core_include/msg.h" #include -#include -#include #include #include diff --git a/core/src/adapter/msg_none.cpp b/core/src/adapter/msg_none.cpp new file mode 100644 index 0000000..da5560e --- /dev/null +++ b/core/src/adapter/msg_none.cpp @@ -0,0 +1,56 @@ +#include "../../core_include/api.h" +#include "../../core_include/msg.h" + + +c_fifo::c_fifo() +{ + m_head = m_tail = 0; + m_read_sem = m_write_mutex = NULL; +} + +int c_fifo::read(void* buf, int len) +{ + unsigned char* pbuf = (unsigned char*)buf; + int i = 0; + while(i < len) + { + if (m_tail == m_head) + {//empty + continue; + } + *pbuf++ = m_buf[m_head]; + m_head = (m_head + 1) % FIFO_BUFFER_LEN; + i++; + } + if(i != len) + { + ASSERT(FALSE); + } + return i; +} + +int c_fifo::write(void* buf, int len) +{ + unsigned char* pbuf = (unsigned char*)buf; + int i = 0; + int tail = m_tail; + + while(i < len) + { + if ((m_tail + 1) % FIFO_BUFFER_LEN == m_head) + {//full, clear data has been written; + m_tail = tail; + log_out("Warning: fifo full\n"); + return 0; + } + m_buf[m_tail] = *pbuf++; + m_tail = (m_tail + 1) % FIFO_BUFFER_LEN; + i++; + } + + if(i != len) + { + ASSERT(FALSE); + } + return i; +} diff --git a/core/src/adapter/msg_win.cpp b/core/src/adapter/msg_win.cpp index e2f6f5d..d3bfcbe 100644 --- a/core/src/adapter/msg_win.cpp +++ b/core/src/adapter/msg_win.cpp @@ -1,7 +1,4 @@ #include "../../core_include/api.h" -#include "../../core_include/rect.h" -#include "../../core_include/surface.h" -#include "../../core_include/display.h" #include "../../core_include/msg.h" #include diff --git a/core/src/display.cpp b/core/src/display.cpp index 311cab0..1afb363 100644 --- a/core/src/display.cpp +++ b/core/src/display.cpp @@ -37,6 +37,15 @@ c_display::c_display(void* phy_fb, unsigned int display_width, unsigned int disp } } +c_display::c_display(unsigned int display_width, unsigned int display_height, unsigned int color_bytes, EXTERNAL_GFX_OP* gfx_op) +{ + m_width = display_width; + m_height = display_height; + m_surface_cnt = 1; + m_phy_fb = NULL; + m_surface_group[0] = new c_surface_mcu(this, display_width, display_height, color_bytes, gfx_op); +} + c_surface* c_display::alloc_surface(void* usr, Z_ORDER_LEVEL max_zorder) { int i = 0; diff --git a/core/src/surface.cpp b/core/src/surface.cpp index c56cd5a..4918086 100644 --- a/core/src/surface.cpp +++ b/core/src/surface.cpp @@ -567,4 +567,51 @@ unsigned int c_surface_16bits::get_pixel(int x, int y, unsigned int z_order) } return GL_RGB_16_to_32(((unsigned short*)(m_frame_layers[z_order].fb))[y * m_width + x]); -} \ No newline at end of file +} + +////////////////////////////////////////////////////////////////////////////////////// +c_surface_mcu::c_surface_mcu(c_display* display, unsigned int width, unsigned int height, unsigned int color_bytes, struct EXTERNAL_GFX_OP* gfx_op) : + c_surface(display, width, height, color_bytes) +{ + m_gfx_op = gfx_op; +} + +void c_surface_mcu::draw_pixel(int x, int y, unsigned int rgb, unsigned int z_order) +{ + if (x >= m_width || y >= m_height || x < 0 || y < 0) + { + return; + } + if (m_gfx_op && m_gfx_op->draw_pixel) + { + m_gfx_op->draw_pixel(x, y, rgb); + } +} + +void c_surface_mcu::fill_rect(int x0, int y0, int x1, int y1, unsigned int rgb, unsigned int z_order) +{ + if (m_gfx_op && m_gfx_op->fill_rect) + { + return m_gfx_op->fill_rect(x0, y0, x1, y1, rgb); + } + + for (; y0 <= y1; y0++) + { + draw_hline(x0, x1, y0, rgb, z_order); + } +} + +void c_surface_mcu::fill_rect_on_fb(int x0, int y0, int x1, int y1, unsigned int rgb) +{//Not support + ASSERT(FALSE); +} + +unsigned int c_surface_mcu::get_pixel(int x, int y, unsigned int z_order) +{//Not support + return 0; +} + +void c_surface_mcu::set_pixel(int x, int y, unsigned int rgb) +{//Not support + ASSERT(FALSE); +} diff --git a/core/src/wave_ctrl.cpp b/core/src/wave_ctrl.cpp index 008b7f7..70b471c 100644 --- a/core/src/wave_ctrl.cpp +++ b/core/src/wave_ctrl.cpp @@ -23,13 +23,14 @@ c_wave_ctrl::c_wave_ctrl() { m_wave = NULL; m_bg_fb = NULL; - m_wave_name_font_type = m_wave_unit_font_type = NULL; + m_wave_name_font = m_wave_unit_font = NULL; m_wave_name = m_wave_unit = 0; m_max_data = 500; m_min_data = 0; m_pivot_data = 250; m_wave_speed = 4; - m_wave_sample_rate = 0; + m_wave_data_rate = 0; + m_wave_refresh_rate = 1000; m_gain = ZOOM_100; m_frame_len_map_index = 0; @@ -63,19 +64,16 @@ void c_wave_ctrl::set_wave_gain(E_WAVE_GAIN gain) m_gain = gain; } -void c_wave_ctrl::set_wave_sample_rate(unsigned int rate) +void c_wave_ctrl::set_wave_in_out_rate(unsigned int data_rate, unsigned int refresh_rate) { - if(rate > 500) - { - ASSERT(FALSE); - } - m_wave_sample_rate = rate; - int read_times_per_second = m_wave_speed * 1000 / REAL_TIME_TASK_CYCLE_MS; + m_wave_data_rate = data_rate; + m_wave_refresh_rate = refresh_rate; + int read_times_per_second = m_wave_speed * 1000 / m_wave_refresh_rate; memset(m_frame_len_map, 0, sizeof(m_frame_len_map)); for (unsigned int i = 1; i < sizeof(m_frame_len_map) + 1; i++) { - m_frame_len_map[i-1] = rate * i / read_times_per_second - rate * (i-1) / read_times_per_second; + m_frame_len_map[i-1] = data_rate * i / read_times_per_second - data_rate * (i-1) / read_times_per_second; } m_frame_len_map_index = 0; } @@ -94,7 +92,7 @@ void c_wave_ctrl::set_wave_speed(unsigned int speed) ASSERT(FALSE); break; } - set_wave_sample_rate(m_wave_sample_rate); + set_wave_in_out_rate(m_wave_data_rate, m_wave_refresh_rate); } void c_wave_ctrl::clear_data() @@ -234,9 +232,9 @@ void c_wave_ctrl::on_paint() fill_rect(rect.m_left, rect.m_top, rect.m_right, rect.m_bottom, m_back_color); //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_type, 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), ALIGN_LEFT); //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_type, 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), ALIGN_LEFT); save_background(); } diff --git a/core/src/word.cpp b/core/src/word.cpp index e162d57..4640f70 100644 --- a/core/src/word.cpp +++ b/core/src/word.cpp @@ -72,10 +72,6 @@ void c_word::draw_string_in_rect(c_surface* surface, int z_order, const char *s, { return; } - if (NULL == font) - { - ASSERT(FALSE); - } 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); @@ -87,21 +83,11 @@ void c_word::draw_string(c_surface* surface, int z_order, const char *s, int x, { return; } - if (NULL == font) - { - ASSERT(FALSE); - } int offset = 0; unsigned int utf8_code; while (*s) { - if (*s == '\n') - { - y += font->height; - offset = 0; - continue; - } s += get_utf8_code(s, utf8_code); offset += draw_single_char(surface, z_order, utf8_code, (x + offset), y, font, font_color, bg_color); } @@ -160,26 +146,29 @@ const LATTICE* c_word::get_lattice(const FONT_INFO* font, unsigned int utf8_code int c_word::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) { - if (NULL == font) + unsigned int error_color = 0xFFFFFFFF; + if (font) { - ASSERT(FALSE); - return 0; + 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->p_data, font_color, bg_color); + return p_lattice->width; + } } - - const LATTICE* p_lattice = get_lattice(font, utf8_code); - if (p_lattice) + else { - draw_lattice(surface, z_order, x, y, p_lattice->width, font->height, p_lattice->p_data, font_color, bg_color); - return p_lattice->width; + error_color = GL_RGB(255, 0, 0); } - int len = font->height; + //lattice/font not found, draw mosaic + int len = 16; for (int y_ = 0; y_ < len; y_++) { for (int x_ = 0; x_ < len; x_++) { ((y_ % 4) == 0) ? surface->draw_pixel((x + x_), (y + y_), 0, z_order) : - surface->draw_pixel((x + x_), (y + y_), 0xFFFFFFFF, z_order); + surface->draw_pixel((x + x_), (y + y_), error_color, z_order); } } return len; @@ -214,15 +203,12 @@ void c_word::draw_lattice(c_surface* surface, int z_order, int x, int y, int wid } } -int c_word::get_str_pixel_length(const char *s, const FONT_INFO* font) +int c_word::get_str_size(const char *s, const FONT_INFO* font, int& width, int& height) { - if(NULL == s) + if(NULL == s || NULL == font) { - return 0; - } - if (NULL == font) - { - ASSERT(FALSE); + width = height = 0; + return -1; } int lattice_width = 0; @@ -235,13 +221,15 @@ int c_word::get_str_pixel_length(const char *s, const FONT_INFO* font) lattice_width += p_lattice?p_lattice->width:font->height; s += utf8_bytes; } - return lattice_width; + width = lattice_width; + height = font->height; + return 0; } void c_word::get_string_pos(const char *s, const FONT_INFO* font, c_rect rect, unsigned int align_type, int &x, int &y) { - int x_size = get_str_pixel_length(s, font); - int y_size = font->height; + int x_size, y_size; + get_str_size(s, font, x_size, y_size); int height = rect.m_bottom - rect.m_top + 1; int width = rect.m_right - rect.m_left + 1; diff --git a/gui/src/my_resource.cpp b/gui/src/my_resource.cpp index ad66a25..3f82881 100644 --- a/gui/src/my_resource.cpp +++ b/gui/src/my_resource.cpp @@ -1,71 +1,71 @@ -#include "core_include/api.h" -#include "core_include/rect.h" -#include "core_include/resource.h" -#include "../gui_include/my_resource.h" - -static const FONT_INFO* s_font_map[FONT_MAX]; -static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; -static unsigned int s_color_map[COLOR_MAX]; - -int c_my_resource::add_font(FONT_TYPE index, const FONT_INFO* font) -{ +#include "core_include/api.h" +#include "core_include/rect.h" +#include "core_include/resource.h" +#include "../gui_include/my_resource.h" + +static const FONT_INFO* s_font_map[FONT_MAX]; +static const BITMAP_INFO* s_bmp_map[BITMAP_MAX]; +static unsigned int s_color_map[COLOR_MAX]; + +int c_my_resource::add_font(FONT_TYPE index, const FONT_INFO* font) +{ if (index >= FONT_MAX) { ASSERT(FALSE); return -1; - } - s_font_map[index] = font; - return 0; -} - -const FONT_INFO* c_my_resource::get_font(FONT_TYPE index) -{ + } + s_font_map[index] = font; + return 0; +} + +const FONT_INFO* c_my_resource::get_font(FONT_TYPE index) +{ if (index >= FONT_MAX) { ASSERT(FALSE); return NULL; - } - return s_font_map[index]; -} - -int c_my_resource::add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) -{ + } + return s_font_map[index]; +} + +int c_my_resource::add_bitmap(BITMAP_TYPE index, const BITMAP_INFO* bmp) +{ if (index >= BITMAP_MAX) { ASSERT(FALSE); return -1; - } - s_bmp_map[index] = bmp; - return 0; -} - -const BITMAP_INFO* c_my_resource::get_bmp(BITMAP_TYPE index) -{ + } + s_bmp_map[index] = bmp; + return 0; +} + +const BITMAP_INFO* c_my_resource::get_bmp(BITMAP_TYPE index) +{ if (index >= BITMAP_MAX) { ASSERT(FALSE); return NULL; - } - return s_bmp_map[index]; -} - -int c_my_resource::add_color(COLOR_TYPE index, const unsigned int color) -{ + } + return s_bmp_map[index]; +} + +int c_my_resource::add_color(COLOR_TYPE index, const unsigned int color) +{ if (index >= COLOR_MAX) { ASSERT(FALSE); return -1; - } - s_color_map[index] = color; - return 0; -} - -const unsigned int c_my_resource::get_color(COLOR_TYPE index) -{ + } + s_color_map[index] = color; + return 0; +} + +const unsigned int c_my_resource::get_color(COLOR_TYPE index) +{ if (index >= COLOR_MAX) { ASSERT(FALSE); return NULL; - } - return s_color_map[index]; + } + return s_color_map[index]; } \ No newline at end of file