diff --git a/GuiLite.cpp b/GuiLite.cpp index 7ccee4c..9833968 100644 --- a/GuiLite.cpp +++ b/GuiLite.cpp @@ -821,73 +821,73 @@ void c_surface_no_fb::draw_pixel_on_fb(int x, int y, unsigned int rgb) ((unsigned short*)m_fb)[y * m_width + x] = GL_RGB_32_to_16(rgb); } } - -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_theme::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_theme::get_font(FONT_TYPE index) -{ - if (index >= FONT_MAX) - { - ASSERT(false); - return 0; - } - return s_font_map[index]; -} - -int c_theme::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_theme::get_bmp(BITMAP_TYPE index) -{ - if (index >= BITMAP_MAX) - { - ASSERT(false); - return 0; - } - return s_bmp_map[index]; -} - -int c_theme::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_theme::get_color(COLOR_TYPE index) -{ - if (index >= COLOR_MAX) - { - ASSERT(false); - return 0; - } - return s_color_map[index]; -} + +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_theme::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_theme::get_font(FONT_TYPE index) +{ + if (index >= FONT_MAX) + { + ASSERT(false); + return 0; + } + return s_font_map[index]; +} + +int c_theme::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_theme::get_bmp(BITMAP_TYPE index) +{ + if (index >= BITMAP_MAX) + { + ASSERT(false); + return 0; + } + return s_bmp_map[index]; +} + +int c_theme::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_theme::get_color(COLOR_TYPE index) +{ + if (index >= COLOR_MAX) + { + ASSERT(false); + return 0; + } + return s_color_map[index]; +} c_wnd::c_wnd(): m_status(STATUS_NORMAL), m_attr(ATTR_VISIBLE), m_parent(0), m_top_child(0), m_prev_sibling(0), m_next_sibling(0), m_str(0), m_font_color(0), m_bg_color(0), m_id(0), m_z_order(Z_ORDER_LEVEL_0), m_focus_child(0), m_surface(0) { @@ -1170,7 +1170,7 @@ void c_wnd::on_touch(int x, int y, TOUCH_ACTION action) c_wnd* tmp_child = m_top_child; while (tmp_child) { - if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE)) + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) { model_wnd = tmp_child; break; @@ -1204,7 +1204,7 @@ void c_wnd::on_key(KEY_TYPE key) c_wnd* tmp_child = m_top_child; while (tmp_child) { - if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE)) + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) { model_wnd = tmp_child; break; @@ -1894,139 +1894,139 @@ int c_fifo::write(void* buf, int len) return i; } #endif -#if (!defined _WIN32) && (!defined WIN32) && (!defined _WIN64) && (!defined WIN64) && (!defined __linux__) && (!defined __APPLE__) - -#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); - } - while(1); -} - -void log_out(const char* log) -{ - if (do_log_out) - { - do_log_out(log); - } -} - -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"); -} - -extern "C" void delay_ms(unsigned short nms); -void thread_sleep(unsigned int milli_seconds) -{//MCU alway implemnet driver code in APP. - delay_ms(milli_seconds); -} - -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data) -{ - log_out("Not support now"); - return 0; -} - -c_fifo::c_fifo() -{ - m_head = m_tail = 0; - m_read_sem = m_write_mutex = 0; -} - -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; -} - -#endif +#if (!defined _WIN32) && (!defined WIN32) && (!defined _WIN64) && (!defined WIN64) && (!defined __linux__) && (!defined __APPLE__) + +#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); + } + while(1); +} + +void log_out(const char* log) +{ + if (do_log_out) + { + do_log_out(log); + } +} + +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"); +} + +extern "C" void delay_ms(unsigned short nms); +void thread_sleep(unsigned int milli_seconds) +{//MCU alway implemnet driver code in APP. + delay_ms(milli_seconds); +} + +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data) +{ + log_out("Not support now"); + return 0; +} + +c_fifo::c_fifo() +{ + m_head = m_tail = 0; + m_read_sem = m_write_mutex = 0; +} + +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; +} + +#endif #if (defined _WIN32) || (defined WIN32) || (defined _WIN64) || (defined WIN64) #include #include @@ -2766,7 +2766,7 @@ int c_dialog::open_dialog(c_dialog* p_dlg, bool modal_mode) c_rect rc; p_dlg->get_screen_rect(rc); p_dlg->get_surface()->set_frame_layer_visible_rect(rc, Z_ORDER_LEVEL_1); - p_dlg->set_attr(modal_mode ? (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL) : (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS)); + p_dlg->set_attr(modal_mode ? (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_PRIORITY) : (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS)); p_dlg->show_window(); p_dlg->set_me_the_dialog(); return 1; @@ -2948,7 +2948,7 @@ void c_edit::on_paint() if (m_z_order == m_parent->get_z_order()) { m_z_order++; - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL); + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_PRIORITY); show_keyboard(); } 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()); @@ -3302,23 +3302,23 @@ void c_keyboard::pre_create_wnd() } void c_keyboard::on_key_clicked(int id, int param) { - switch (id) - { - case 0x14: - on_caps_clicked(id, param); - break; - case '\n': - on_enter_clicked(id, param); - break; - case 0x1B: - on_esc_clicked(id, param); - break; - case 0x7F: - on_del_clicked(id, param); - break; + switch (id) + { + case 0x14: + on_caps_clicked(id, param); + break; + case '\n': + on_enter_clicked(id, param); + break; + case 0x1B: + on_esc_clicked(id, param); + break; + case 0x7F: + on_del_clicked(id, param); + break; default: on_char_clicked(id, param); - break; + break; } } void c_keyboard::on_caps_clicked(int id, int parm) @@ -3510,7 +3510,7 @@ void c_list_box::on_paint() m_z_order++; } m_surface->set_frame_layer_visible_rect(m_list_screen_rect, m_z_order); - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL); + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_PRIORITY); show_list(); } break; diff --git a/GuiLite.h b/GuiLite.h index 4f73f42..362e7b5 100644 --- a/GuiLite.h +++ b/GuiLite.h @@ -1,74 +1,74 @@ -#ifndef GUILITE_CORE_INCLUDE_API_H -#define GUILITE_CORE_INCLUDE_API_H - -#define REAL_TIME_TASK_CYCLE_MS 50 - -#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) - -#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) -#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) -#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) -#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) -#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) -#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) - -#define ALIGN_HCENTER 0x00000000L -#define ALIGN_LEFT 0x01000000L -#define ALIGN_RIGHT 0x02000000L -#define ALIGN_HMASK 0x03000000L - -#define ALIGN_VCENTER 0x00000000L -#define ALIGN_TOP 0x00100000L -#define ALIGN_BOTTOM 0x00200000L -#define ALIGN_VMASK 0x00300000L - -typedef struct -{ - unsigned short year; - unsigned short month; - unsigned short date; - unsigned short day; - unsigned short hour; - unsigned short minute; - unsigned short second; -}T_TIME; - -void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); -void _assert(const char* file, int line); -#define ASSERT(condition) \ - do{ \ - if(!(condition))_assert(__FILE__, __LINE__);\ - }while(0) -void log_out(const char* log); - -long get_time_in_second(); -T_TIME second_to_day(long second); -T_TIME get_time(); - -void start_real_timer(void (*func)(void* arg)); -void register_timer(int milli_second, void func(void* ptmr, void* parg)); - -unsigned int get_cur_thread_id(); -void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); -void thread_sleep(unsigned int milli_seconds); -int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); - -#define FIFO_BUFFER_LEN 1024 -class c_fifo -{ -public: - c_fifo(); - int read(void* buf, int len); - int write(void* buf, int len); -private: - unsigned char m_buf[FIFO_BUFFER_LEN]; - int m_head; - int m_tail; - void* m_read_sem; - void* m_write_mutex; -}; -#endif +#ifndef GUILITE_CORE_INCLUDE_API_H +#define GUILITE_CORE_INCLUDE_API_H + +#define REAL_TIME_TASK_CYCLE_MS 50 + +#define GL_ARGB(a, r, g, b) ((((unsigned int)(a)) << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_ARGB_A(rgb) ((((unsigned int)(rgb)) >> 24) & 0xFF) + +#define GL_RGB(r, g, b) ((0xFF << 24) | (((unsigned int)(r)) << 16) | (((unsigned int)(g)) << 8) | ((unsigned int)(b))) +#define GL_RGB_R(rgb) ((((unsigned int)(rgb)) >> 16) & 0xFF) +#define GL_RGB_G(rgb) ((((unsigned int)(rgb)) >> 8) & 0xFF) +#define GL_RGB_B(rgb) (((unsigned int)(rgb)) & 0xFF) +#define GL_RGB_32_to_16(rgb) (((((unsigned int)(rgb)) & 0xFF) >> 3) | ((((unsigned int)(rgb)) & 0xFC00) >> 5) | ((((unsigned int)(rgb)) & 0xF80000) >> 8)) +#define GL_RGB_16_to_32(rgb) ((0xFF << 24) | ((((unsigned int)(rgb)) & 0x1F) << 3) | ((((unsigned int)(rgb)) & 0x7E0) << 5) | ((((unsigned int)(rgb)) & 0xF800) << 8)) + +#define ALIGN_HCENTER 0x00000000L +#define ALIGN_LEFT 0x01000000L +#define ALIGN_RIGHT 0x02000000L +#define ALIGN_HMASK 0x03000000L + +#define ALIGN_VCENTER 0x00000000L +#define ALIGN_TOP 0x00100000L +#define ALIGN_BOTTOM 0x00200000L +#define ALIGN_VMASK 0x00300000L + +typedef struct +{ + unsigned short year; + unsigned short month; + unsigned short date; + unsigned short day; + unsigned short hour; + unsigned short minute; + unsigned short second; +}T_TIME; + +void register_debug_function(void(*my_assert)(const char* file, int line), void(*my_log_out)(const char* log)); +void _assert(const char* file, int line); +#define ASSERT(condition) \ + do{ \ + if(!(condition))_assert(__FILE__, __LINE__);\ + }while(0) +void log_out(const char* log); + +long get_time_in_second(); +T_TIME second_to_day(long second); +T_TIME get_time(); + +void start_real_timer(void (*func)(void* arg)); +void register_timer(int milli_second, void func(void* ptmr, void* parg)); + +unsigned int get_cur_thread_id(); +void create_thread(unsigned long* thread_id, void* attr, void *(*start_routine) (void *), void* arg); +void thread_sleep(unsigned int milli_seconds); +int build_bmp(const char *filename, unsigned int width, unsigned int height, unsigned char *data); + +#define FIFO_BUFFER_LEN 1024 +class c_fifo +{ +public: + c_fifo(); + int read(void* buf, int len); + int write(void* buf, int len); +private: + unsigned char m_buf[FIFO_BUFFER_LEN]; + int m_head; + int m_tail; + void* m_read_sem; + void* m_write_mutex; +}; +#endif #ifndef GUILITE_CORE_INCLUDE_CMD_TARGET_H #define GUILITE_CORE_INCLUDE_CMD_TARGET_H class c_cmd_target; @@ -358,7 +358,7 @@ typedef enum { ATTR_VISIBLE = 0x40000000L, ATTR_FOCUS = 0x20000000L, - ATTR_MODAL = 0x10000000L// Handle touch action at high priority + ATTR_PRIORITY = 0x10000000L// Handle touch action at high priority }WND_ATTRIBUTION; typedef enum { diff --git a/workspace/core/wnd.cpp b/workspace/core/wnd.cpp index 6dc7f60..a137d2d 100644 --- a/workspace/core/wnd.cpp +++ b/workspace/core/wnd.cpp @@ -335,7 +335,7 @@ void c_wnd::on_touch(int x, int y, TOUCH_ACTION action) c_wnd* tmp_child = m_top_child; while (tmp_child) { - if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE)) + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) { model_wnd = tmp_child; break; @@ -371,7 +371,7 @@ void c_wnd::on_key(KEY_TYPE key) c_wnd* tmp_child = m_top_child; while (tmp_child) { - if ((tmp_child->m_attr & ATTR_MODAL) && (tmp_child->m_attr & ATTR_VISIBLE)) + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) { model_wnd = tmp_child; break; diff --git a/workspace/core_include/wnd.h b/workspace/core_include/wnd.h index ecdd962..d576054 100644 --- a/workspace/core_include/wnd.h +++ b/workspace/core_include/wnd.h @@ -11,7 +11,7 @@ typedef enum { ATTR_VISIBLE = 0x40000000L, ATTR_FOCUS = 0x20000000L, - ATTR_MODAL = 0x10000000L// Handle touch action at high priority + ATTR_PRIORITY = 0x10000000L// Handle touch action at high priority }WND_ATTRIBUTION; typedef enum diff --git a/workspace/widgets/dialog.cpp b/workspace/widgets/dialog.cpp index 8fba397..895fb75 100644 --- a/workspace/widgets/dialog.cpp +++ b/workspace/widgets/dialog.cpp @@ -63,7 +63,7 @@ int c_dialog::open_dialog(c_dialog* p_dlg, bool modal_mode) p_dlg->get_screen_rect(rc); p_dlg->get_surface()->set_frame_layer_visible_rect(rc, Z_ORDER_LEVEL_1); - p_dlg->set_attr(modal_mode ? (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL) : (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS)); + p_dlg->set_attr(modal_mode ? (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_PRIORITY) : (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS)); p_dlg->show_window(); p_dlg->set_me_the_dialog(); return 1; diff --git a/workspace/widgets/edit.cpp b/workspace/widgets/edit.cpp index eb193d6..909fabb 100644 --- a/workspace/widgets/edit.cpp +++ b/workspace/widgets/edit.cpp @@ -156,7 +156,7 @@ void c_edit::on_paint() if (m_z_order == m_parent->get_z_order()) { m_z_order++; - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL); + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_PRIORITY); show_keyboard(); } 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()); diff --git a/workspace/widgets/list_box.cpp b/workspace/widgets/list_box.cpp index e696042..160365b 100644 --- a/workspace/widgets/list_box.cpp +++ b/workspace/widgets/list_box.cpp @@ -75,7 +75,7 @@ void c_list_box::on_paint() m_z_order++; } m_surface->set_frame_layer_visible_rect(m_list_screen_rect, m_z_order); - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL); + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_PRIORITY); show_list(); } break;