From 3fc946eab50dc2277c0f9fd47c0a837dd3f03874 Mon Sep 17 00:00:00 2001 From: idea4good Date: Tue, 31 Dec 2019 16:23:19 +0800 Subject: [PATCH] remove clone function, support keyboard input --- GuiLite.cpp | 894 ++++++++++-------------- GuiLite.h | 238 +++---- documents/HowToWork-cn.md | 2 +- workspace/1h-1cpp.sh | 5 +- workspace/core/wnd.cpp | 211 ++---- workspace/core_include/wnd.h | 15 +- workspace/widgets/button.cpp | 18 +- workspace/widgets/dialog.cpp | 2 +- workspace/widgets/edit.cpp | 18 +- workspace/widgets/list_box.cpp | 30 +- workspace/widgets/slide_group.cpp | 50 +- workspace/widgets/spinbox.cpp | 169 +---- workspace/widgets/table.cpp | 8 + workspace/widgets_include/button.h | 6 +- workspace/widgets_include/edit.h | 4 +- workspace/widgets_include/keyboard.h | 2 - workspace/widgets_include/label.h | 2 - workspace/widgets_include/list_box.h | 4 +- workspace/widgets_include/slide_group.h | 8 +- workspace/widgets_include/spinbox.h | 60 +- workspace/widgets_include/table.h | 2 +- workspace/widgets_include/wave_ctrl.h | 1 - 22 files changed, 639 insertions(+), 1110 deletions(-) diff --git a/GuiLite.cpp b/GuiLite.cpp index 763c2fd..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) { @@ -960,71 +960,6 @@ int c_wnd::load_child_wnd(WND_TREE *p_child_tree) } return sum; } -c_wnd* c_wnd::connect_clone(c_wnd *parent, unsigned short resource_id, const char* str, - short x, short y, short width, short height, WND_TREE* p_child_tree ) -{ - if(0 == resource_id) - { - ASSERT(false); - return 0; - } - c_wnd* wnd = clone(); - wnd->m_id = resource_id; - wnd->set_str(str); - wnd->m_parent = parent; - wnd->m_status = STATUS_NORMAL; - if (parent) - { - wnd->m_z_order = parent->m_z_order; - wnd->m_surface = parent->m_surface; - } - else - { - wnd->m_surface = m_surface; - } - if(0 == wnd->m_surface) - { - ASSERT(false); - return 0; - } - /* (cs.x = x * 1024 / 768) for 1027*768=>800*600 quickly*/ - wnd->m_wnd_rect.m_left = x; - wnd->m_wnd_rect.m_top = y; - wnd->m_wnd_rect.m_right = (x + width - 1); - wnd->m_wnd_rect.m_bottom = (y + height - 1); - c_rect rect; - wnd->get_screen_rect(rect); - ASSERT(wnd->m_surface->is_valid(rect)); - wnd->pre_create_wnd(); - - if ( 0 != parent ) - { - parent->add_child_2_tail(wnd); - } - if (wnd->load_clone_child_wnd(p_child_tree) >= 0) - { - wnd->load_cmd_msg(); - wnd->on_init_children(); - } - return wnd; -} -int c_wnd::load_clone_child_wnd(WND_TREE *p_child_tree) -{ - if (0 == p_child_tree) - { - return 0; - } - int sum = 0; - WND_TREE* p_cur = p_child_tree; - while(p_cur->p_wnd) - { - p_cur->p_wnd->connect_clone(this, p_cur->resource_id, p_cur->str, - p_cur->x, p_cur->y, p_cur->width, p_cur->height,p_cur->p_child_tree); - p_cur++; - sum++; - } - return sum; -} void c_wnd::disconnect() { if (0 == m_id) @@ -1062,33 +997,9 @@ c_wnd* c_wnd::get_wnd_ptr(unsigned short id) const } return child; } -void c_wnd::set_attr(WND_ATTRIBUTION attr) -{ - m_attr = attr; - if ( ATTR_DISABLED == (attr & ATTR_DISABLED) ) - { - m_status = STATUS_DISABLED; - } - else - { - if (m_status == STATUS_DISABLED) - { - m_status = STATUS_NORMAL; - } - } -} bool c_wnd::is_focus_wnd() const { - if ( (m_attr & ATTR_VISIBLE) - && !(m_attr & ATTR_DISABLED) - && (m_attr & ATTR_FOCUS)) - { - return true; - } - else - { - return false; - } + return ((m_attr & ATTR_VISIBLE) && (m_attr & ATTR_FOCUS)) ? true : false; } void c_wnd::set_wnd_pos(short x, short y, short width, short height) { @@ -1143,10 +1054,6 @@ c_wnd* c_wnd::set_child_focus(c_wnd * focus_child) old_focus_child->on_kill_focus(); } m_focus_child = focus_child; - if (m_parent) - { - m_parent->set_child_focus(this); - } m_focus_child->on_focus(); } } @@ -1257,76 +1164,88 @@ void c_wnd::show_window() } } } -bool c_wnd::on_touch(int x, int y, TOUCH_ACTION action) +void c_wnd::on_touch(int x, int y, TOUCH_ACTION action) { - c_rect rect; + c_wnd* model_wnd = 0; + c_wnd* tmp_child = m_top_child; + while (tmp_child) + { + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) + { + model_wnd = tmp_child; + break; + } + tmp_child = tmp_child->m_next_sibling; + } + if (model_wnd) + { + return model_wnd->on_touch(x, y, action); + } x -= m_wnd_rect.m_left; y -= m_wnd_rect.m_top; c_wnd* child = m_top_child; - c_wnd* target_wnd = 0; - int target_z_order = Z_ORDER_LEVEL_0; while (child) { - if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE)) + if (child->is_focus_wnd()) { + c_rect rect; child->get_wnd_rect(rect); - if (true == rect.PtInRect(x, y) || child->m_attr & ATTR_MODAL) + if (true == rect.PtInRect(x, y)) { - if (true == child->is_focus_wnd()) - { - if (child->m_z_order >= target_z_order) - { - target_wnd = child; - target_z_order = child->m_z_order; - } - } + return child->on_touch(x, y, action); } } child = child->m_next_sibling; } - if (target_wnd == 0) - { - return false; - } - return target_wnd->on_touch(x, y, action); } -bool c_wnd::on_key(KEY_TYPE key) +void c_wnd::on_key(KEY_TYPE key) { - ASSERT(key == KEY_FORWARD || key == KEY_BACKWARD || key == KEY_ENTER); - // Find current focus wnd. - c_wnd* old_focus_wnd = m_focus_child; - while (m_focus_child && m_focus_child->m_focus_child) + c_wnd* model_wnd = 0; + c_wnd* tmp_child = m_top_child; + while (tmp_child) { - old_focus_wnd = m_focus_child->m_focus_child; + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) + { + model_wnd = tmp_child; + break; + } + tmp_child = tmp_child->m_next_sibling; } - if (old_focus_wnd && !old_focus_wnd->on_key(key)) + if (model_wnd) { - return true; + return model_wnd->on_key(key); } - // Default moving focus(Default handle KEY_FOWARD/KEY_BACKWARD) - if (key == KEY_ENTER) + if (!is_focus_wnd()) { - return true; + return; } + if (key != KEY_BACKWARD && key != KEY_FORWARD) + { + if (m_focus_child) + { + m_focus_child->on_key(key); + } + return; + } + // Move focus + c_wnd* old_focus_wnd = m_focus_child; + // No current focus wnd, new one. if (!old_focus_wnd) - {// No current focus wnd, new one. - c_wnd *child = m_top_child; - c_wnd *new_focus_wnd = 0; + { + c_wnd* child = m_top_child; + c_wnd* new_focus_wnd = 0; while (child) { - if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE)) + if (child->is_focus_wnd()) { - if (true == child->is_focus_wnd()) - { - new_focus_wnd = child; - new_focus_wnd->m_parent->set_child_focus(new_focus_wnd); - child = child->m_top_child; - continue; - } + new_focus_wnd = child; + new_focus_wnd->m_parent->set_child_focus(new_focus_wnd); + child = child->m_top_child; + continue; } child = child->m_next_sibling; } - return true; + return; } // Move focus from old wnd to next wnd c_wnd* next_focus_wnd = (key == KEY_FORWARD) ? old_focus_wnd->m_next_sibling : old_focus_wnd->m_prev_sibling; @@ -1346,7 +1265,6 @@ bool c_wnd::on_key(KEY_TYPE key) { next_focus_wnd->m_parent->set_child_focus(next_focus_wnd); } - return true; } void c_wnd::notify_parent(int msg_id, int param) { @@ -1976,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 @@ -2739,7 +2657,7 @@ void c_button::on_kill_focus() m_status = STATUS_NORMAL; on_paint(); } -bool c_button::on_touch(int x, int y, TOUCH_ACTION action) +void c_button::on_touch(int x, int y, TOUCH_ACTION action) { if (action == TOUCH_DOWN) { @@ -2753,16 +2671,20 @@ bool c_button::on_touch(int x, int y, TOUCH_ACTION action) on_paint(); notify_parent(GL_BN_CLICKED, 0); } - return true; } -bool c_button::on_key(KEY_TYPE key) +void c_button::on_key(KEY_TYPE key) { - if (key == KEY_ENTER) + switch (key) { - notify_parent(GL_BN_CLICKED, 0); - return false;// Do not handle KEY_ENTER by other wnd. + case KEY_ENTER: + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN); + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP); + break; + case KEY_FORWARD: + case KEY_BACKWARD: + break; } - return true;// Handle KEY_FOWARD/KEY_BACKWARD by parent wnd. + return c_wnd::on_key(key); } void c_button::on_paint() { @@ -2844,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; @@ -2918,10 +2840,21 @@ void c_edit::set_text(const char* str) strcpy(m_str, str); } } -bool c_edit::on_touch(int x, int y, TOUCH_ACTION action) +void c_edit::on_key(KEY_TYPE key) +{ + switch (key) + { + case KEY_ENTER: + (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : (on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN), on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP)); + return; + case KEY_BACKWARD: + case KEY_FORWARD: + return (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : c_wnd::on_key(key); + } +} +void c_edit::on_touch(int x, int y, TOUCH_ACTION action) { (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y); - return true; } void c_edit::on_touch_down(int x, int y) { @@ -3015,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()); @@ -3369,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) @@ -3577,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; @@ -3585,10 +3518,33 @@ void c_list_box::on_paint() ASSERT(false); } } -bool c_list_box::on_touch(int x, int y, TOUCH_ACTION action) +void c_list_box::on_key(KEY_TYPE key) +{ + switch (key) + { + case KEY_ENTER: + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN); + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP); + return; + case KEY_BACKWARD: + if (m_status != STATUS_PUSHED) + { + return c_wnd::on_key(key); + } + m_selected_item = (m_selected_item > 0) ? (m_selected_item - 1) : m_selected_item; + return show_list(); + case KEY_FORWARD: + if (m_status != STATUS_PUSHED) + { + return c_wnd::on_key(key); + } + m_selected_item = (m_selected_item < (m_item_total - 1)) ? (m_selected_item + 1) : m_selected_item; + return show_list(); + } +} +void c_list_box::on_touch(int x, int y, TOUCH_ACTION action) { (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y); - return true; } void c_list_box::on_touch_down(int x, int y) { @@ -3779,45 +3735,6 @@ int c_slide_group::add_slide(c_wnd* slide, unsigned short resource_id, short x, ASSERT(false); return -3; } -int c_slide_group::add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y, - short width, short height, WND_TREE* p_child_tree, Z_ORDER_LEVEL max_zorder) -{ - if(0 == slide) - { - return -1; - } - c_surface* old_surface = get_surface(); - c_surface* new_surface = old_surface->get_display()->alloc_surface(max_zorder); - new_surface->set_active(false); - set_surface(new_surface); - c_wnd* page_tmp = slide->connect_clone(this,resource_id,0,x,y,width,height,p_child_tree); - set_surface(old_surface); - int i = 0; - while(i < MAX_PAGES) - { - if(m_slides[i] == page_tmp) - {//slide has lived - ASSERT(false); - return -2; - } - i++; - } - //new slide - i = 0; - while(i < MAX_PAGES) - { - if(m_slides[i] == 0) - { - m_slides[i] = page_tmp; - page_tmp->show_window(); - return 0; - } - i++; - } - //no more slide can be add - ASSERT(false); - return -3; -} void c_slide_group::disabel_all_slide() { for(int i = 0; i < MAX_PAGES; i++) @@ -3828,7 +3745,7 @@ void c_slide_group::disabel_all_slide() } } } -bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) +void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) { x -= m_wnd_rect.m_left; y -= m_wnd_rect.m_top; @@ -3839,164 +3756,49 @@ bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) m_slides[m_active_slide_index]->on_touch(x, y, action); } } - return true; } -bool c_slide_group::on_key(KEY_TYPE key) +void c_slide_group::on_key(KEY_TYPE key) { if (m_slides[m_active_slide_index]) { m_slides[m_active_slide_index]->on_key(key); } - return true; } -#define ARROW_BT_HEIGHT 55 -#define ID_BT_ARROW_UP 1 -#define ID_BT_ARROW_DOWN 2 -GL_BEGIN_MESSAGE_MAP(c_spin_box) -ON_GL_BN_CLICKED(c_spin_box::on_arrow_bt_click) -GL_END_MESSAGE_MAP() +#define ARROW_BT_WIDTH 55 +#define ID_BT_ARROW_UP 0x1111 +#define ID_BT_ARROW_DOWN 0x2222 +void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) +{ + if (action == TOUCH_UP) + { + (m_id == ID_BT_ARROW_UP) ? m_spin_box->on_arrow_up_bt_click() : m_spin_box->on_arrow_down_bt_click(); + } + c_button::on_touch(x, y, action); +} void c_spin_box::pre_create_wnd() { - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); m_max = 6; m_min = 1; m_digit = 0; m_step = 1; - //set arrow button position. + //link arrow button position. c_rect rect; get_screen_rect(rect); - m_bt_up_rect.m_left = rect.m_left; - m_bt_up_rect.m_right = rect.m_left + rect.Width() / 2 - 1; - m_bt_up_rect.m_top = rect.m_bottom + 1; - m_bt_up_rect.m_bottom = m_bt_up_rect.m_top + ARROW_BT_HEIGHT; - m_bt_down_rect.m_left = rect.m_left + rect.Width() / 2; - m_bt_down_rect.m_right = rect.m_right; - m_bt_down_rect.m_top = rect.m_bottom + 1; - m_bt_down_rect.m_bottom = m_bt_down_rect.m_top + ARROW_BT_HEIGHT; -} -bool c_spin_box::on_touch(int x, int y, TOUCH_ACTION action) -{ - (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y); - return c_wnd::on_touch(x, y, action); -} -void c_spin_box::on_touch_down(int x, int y) -{ - if (false == m_wnd_rect.PtInRect(x, y)) - {//maybe click on up/down arrow button - return; - } - if (STATUS_NORMAL == m_status) - { - m_parent->set_child_focus(this); - } -} -void c_spin_box::on_touch_up(int x, int y) -{ - if (false == m_wnd_rect.PtInRect(x, y)) - {//maybe click on up/down arrow button - return; - } - if (STATUS_FOCUSED == m_status) - { - m_status = STATUS_PUSHED; - on_paint(); - } - else if (STATUS_PUSHED == m_status) - { - m_value = m_cur_value; - m_status = STATUS_FOCUSED; - on_paint(); - notify_parent(GL_SPIN_CONFIRM, m_value); - } -} -void c_spin_box::on_focus() -{ - m_status = STATUS_FOCUSED; - on_paint(); -} -void c_spin_box::on_kill_focus() -{ - m_cur_value = m_value; - m_status = STATUS_NORMAL; - on_paint(); -} -void c_spin_box::show_arrow_button() -{ - m_bt_up.connect(this, ID_BT_ARROW_UP, "\xe2\x96\xb2"/*unicode of up arrow*/, 0, m_wnd_rect.Height(), m_bt_up_rect.Width(),m_bt_up_rect.Height()); - m_bt_up.show_window(); - m_bt_down.connect(this, ID_BT_ARROW_DOWN, "\xe2\x96\xbc"/*unicode of down arrow*/, m_bt_up_rect.Width(), m_wnd_rect.Height(), m_bt_down_rect.Width(),m_bt_down_rect.Height()); - m_bt_down.show_window(); - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL); -} -void c_spin_box::hide_arrow_button() -{ - m_bt_up.disconnect(); - m_bt_down.disconnect(); - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); + m_bt_down.m_spin_box = m_bt_up.m_spin_box = this; + m_bt_down.connect(m_parent, ID_BT_ARROW_DOWN, "-", rect.m_left - ARROW_BT_WIDTH, rect.m_top, ARROW_BT_WIDTH, rect.Height()); + m_bt_up.connect(m_parent, ID_BT_ARROW_UP, "+", rect.m_right, rect.m_top, ARROW_BT_WIDTH, rect.Height()); } void c_spin_box::on_paint() { - c_rect rect, tmp_rect, empty_rect; + c_rect rect; get_screen_rect(rect); - tmp_rect.m_left = rect.m_left; - tmp_rect.m_right = rect.m_right; - switch(m_status) - { - case STATUS_NORMAL: - if (m_z_order > m_parent->get_z_order()) - { - hide_arrow_button(); - m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order); - m_z_order = m_parent->get_z_order(); - } - 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); - break; - case STATUS_FOCUSED: - if (m_z_order > m_parent->get_z_order()) - { - hide_arrow_button(); - m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order); - m_z_order = m_parent->get_z_order(); - } - m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), 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_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); - break; - case STATUS_PUSHED: - if (m_z_order == m_parent->get_z_order()) - { - m_z_order++; - } - tmp_rect.m_top = m_bt_down_rect.m_top; - tmp_rect.m_bottom = m_bt_down_rect.m_bottom; - m_surface->set_frame_layer_visible_rect(tmp_rect, m_z_order); - show_arrow_button(); - 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); - 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_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); - break; - default: - ASSERT(false); - } + 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); } -void c_spin_box::on_arrow_bt_click(int ctr_id, int param) -{ - switch (ctr_id) - { - case ID_BT_ARROW_UP: - on_arrow_up_bt_click(ctr_id, param); - break; - case ID_BT_ARROW_DOWN: - on_arrow_down_bt_click(ctr_id, param); - break; - default: - ASSERT(false); - break; - } -} -void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param) +void c_spin_box::on_arrow_up_bt_click() { if (m_cur_value + m_step > m_max) { @@ -4006,7 +3808,7 @@ void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param) notify_parent(GL_SPIN_CHANGE, m_cur_value); on_paint(); } -void c_spin_box::on_arrow_down_bt_click(int ctr_id, int param) +void c_spin_box::on_arrow_down_bt_click() { if (m_cur_value - m_step < m_min) { @@ -4016,6 +3818,12 @@ void c_spin_box::on_arrow_down_bt_click(int ctr_id, int param) notify_parent(GL_SPIN_CHANGE, m_cur_value); on_paint(); } +void c_table::pre_create_wnd() +{ + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); + m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font_color = c_theme::get_color(COLOR_WND_FONT); +} void c_table::set_item(int row, int col, char* str, unsigned int color) { draw_item( row, col, str, color); diff --git a/GuiLite.h b/GuiLite.h index 6d566d5..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; @@ -356,10 +356,9 @@ class c_wnd; class c_surface; typedef enum { - ATTR_VISIBLE = 0x80000000L, - ATTR_DISABLED = 0x40000000L, + 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 { @@ -398,10 +397,7 @@ class c_wnd : public c_cmd_target virtual ~c_wnd() {}; virtual int connect(c_wnd *parent, unsigned short resource_id, const char* str, short x, short y, short width, short height, WND_TREE* p_child_tree = 0); - virtual c_wnd* connect_clone(c_wnd *parent, unsigned short resource_id, const char* str, - short x, short y, short width, short height, WND_TREE* p_child_tree = 0); void disconnect(); - virtual c_wnd* clone() = 0; virtual void on_init_children() {} virtual void on_paint() {} virtual void show_window(); @@ -409,8 +405,8 @@ class c_wnd : public c_cmd_target int get_z_order() { return m_z_order; } c_wnd* get_wnd_ptr(unsigned short id) const; unsigned int get_attr() const { return m_attr; } - void set_attr(WND_ATTRIBUTION attr); void set_str(const char* str) { m_str = str; } + void set_attr(WND_ATTRIBUTION attr) { m_attr = attr; } bool is_focus_wnd() const; void set_font_color(unsigned int color) { m_font_color = color; } unsigned int get_font_color() { return m_font_color; } @@ -428,8 +424,8 @@ class c_wnd : public c_cmd_target c_wnd* get_prev_sibling() const { return m_prev_sibling; } c_wnd* get_next_sibling() const { return m_next_sibling; } void notify_parent(int msg_id, int param); - virtual bool on_touch(int x, int y, TOUCH_ACTION action);// return true: handled; false: not be handled. - virtual bool on_key(KEY_TYPE key);// return false: skip handling by parent; + virtual void on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); c_surface* get_surface() { return m_surface; } void set_surface(c_surface* surface) { m_surface = surface; } protected: @@ -438,7 +434,6 @@ class c_wnd : public c_cmd_target void wnd2screen(int &x, int &y) const; void wnd2screen(c_rect &rect) const; int load_child_wnd(WND_TREE *p_child_tree); - int load_clone_child_wnd(WND_TREE *p_child_tree); void set_active_child(c_wnd* child) { m_focus_child = child; } virtual void on_focus() {}; virtual void on_kill_focus() {}; @@ -487,15 +482,13 @@ class c_audio typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { -public: - virtual c_wnd* clone(){return new c_button();} protected: virtual void on_paint(); virtual void on_focus(); virtual void on_kill_focus(); virtual void pre_create_wnd(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); - virtual bool on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); }; #endif #ifndef GUILITE_WIDGETS_INCLUDE_DIALOG_H @@ -551,7 +544,6 @@ class c_keyboard: public c_wnd char* get_str() { return m_str; } protected: virtual void pre_create_wnd(); - virtual c_wnd* clone(){return new c_keyboard();} virtual void on_paint(); void on_key_clicked(int id, int param); void on_char_clicked(int id, int param); @@ -568,7 +560,6 @@ class c_keyboard: public c_wnd class c_keyboard_button : public c_button { protected: - virtual c_wnd* clone(){return new c_keyboard_button();} virtual void on_paint(); }; #endif /* KEYBOARD_H_ */ @@ -579,7 +570,6 @@ class c_edit : public c_wnd { friend class c_keyboard; public: - virtual c_wnd* clone(){return new c_edit();} const char* get_text(){return m_str;} void set_text(const char* str); void set_keyboard_style(KEYBOARD_STYLE kb_sytle) { m_kb_style = kb_sytle; } @@ -589,7 +579,8 @@ class c_edit : public c_wnd virtual void on_paint(); virtual void on_focus(); virtual void on_kill_focus(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); void on_key_board_click(int id, int param); GL_DECLARE_MESSAGE_MAP() @@ -633,11 +624,9 @@ class c_gesture{ class c_label : public c_wnd { public: - virtual c_wnd* clone(){return new c_label();} virtual void on_paint(); protected: virtual void pre_create_wnd(); -private: }; #endif #ifndef GUILITE_WIDGETS_INCLUDE_LIST_BOX_H @@ -655,12 +644,12 @@ class c_list_box : public c_wnd void select_item(short index); protected: - virtual c_wnd* clone(){return new c_list_box();} virtual void pre_create_wnd(); virtual void on_paint(); virtual void on_focus(); virtual void on_kill_focus(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); private: void update_list_size(); @@ -688,14 +677,10 @@ class c_slide_group : public c_wnd { int add_slide(c_wnd* slide, unsigned short resource_id, short x, short y, short width, short height, WND_TREE* p_child_tree = 0, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0); - int add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y, - short width, short height, WND_TREE* p_child_tree = 0, - Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0); void disabel_all_slide(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); - virtual bool on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); protected: - virtual c_wnd* clone(){return new c_slide_group();} c_wnd* m_slides[MAX_PAGES]; int m_active_slide_index; c_gesture* m_gesture; @@ -703,52 +688,42 @@ class c_slide_group : public c_wnd { #endif #ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H #define GUILITE_WIDGETS_INCLUDE_SPINBOX_H -#define GL_SPIN_CONFIRM 0x2222 #define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CONFIRM(func) \ -{MSG_TYPE_WND, GL_SPIN_CONFIRM, 0, msgCallback(&func)}, #define ON_SPIN_CHANGE(func) \ {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, +class c_spin_box; +class c_spin_button : public c_button +{ + friend class c_spin_box; + virtual void on_touch(int x, int y, TOUCH_ACTION action); + c_spin_box* m_spin_box; +}; class c_spin_box : public c_wnd { + friend class c_spin_button; public: - short get_value(){return m_value;} - void set_value(unsigned short value){m_value = m_cur_value = value;} - void set_max_min(short max, short min){m_max = max; m_min = min;} - void set_step(short step){m_step = step;} - short get_min(){return m_min;} - short get_max(){return m_max;} - short get_step(){return m_step;} - void set_value_digit(short digit){m_digit = digit;} - short get_value_digit(){return m_digit;} - + short get_value() { return m_value; } + void set_value(unsigned short value) { m_value = m_cur_value = value; } + void set_max_min(short max, short min) { m_max = max; m_min = min; } + void set_step(short step) { m_step = step; } + short get_min() { return m_min; } + short get_max() { return m_max; } + short get_step() { return m_step; } + void set_value_digit(short digit) { m_digit = digit; } + short get_value_digit() { return m_digit; } protected: - virtual c_wnd* clone(){return new c_spin_box();} virtual void on_paint(); - virtual void on_focus(); - virtual void on_kill_focus(); virtual void pre_create_wnd(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); - void on_arrow_bt_click(int ctr_id, int param); - void on_arrow_up_bt_click(int ctr_id, int param); - void on_arrow_down_bt_click(int ctr_id, int param); - GL_DECLARE_MESSAGE_MAP() -private: - void show_arrow_button(); - void hide_arrow_button(); - void on_touch_down(int x, int y); - void on_touch_up(int x, int y); -protected: + void on_arrow_up_bt_click(); + void on_arrow_down_bt_click(); short m_cur_value; short m_value; short m_step; short m_max; short m_min; short m_digit; - c_button m_bt_up; - c_button m_bt_down; - c_rect m_bt_up_rect; - c_rect m_bt_down_rect; + c_spin_button m_bt_up; + c_spin_button m_bt_down; }; #endif #ifndef GUILITE_WIDGETS_INCLUDE_TABLE_H @@ -758,7 +733,6 @@ class c_spin_box : public c_wnd class c_table: public c_wnd { public: - virtual c_wnd* clone(){return new c_table();} void set_sheet_align(unsigned int align_type){ m_align_type = align_type;} void set_row_num(unsigned int row_num){ m_row_num = row_num;} void set_col_num(unsigned int col_num){ m_col_num = col_num;} @@ -771,6 +745,7 @@ class c_table: public c_wnd unsigned int get_col_num(){ return m_col_num;} c_rect get_item_rect(int row, int col); protected: + virtual void pre_create_wnd(); void draw_item(int row, int col, const char* str, unsigned int color); unsigned int m_align_type; unsigned int m_row_num; @@ -823,7 +798,6 @@ class c_wave_ctrl : public c_wnd { public: c_wave_ctrl(); - virtual c_wnd* clone(){return new c_wave_ctrl();} virtual void on_init_children(); virtual void on_paint(); void set_wave_name(char* wave_name){ m_wave_name = wave_name;} diff --git a/documents/HowToWork-cn.md b/documents/HowToWork-cn.md index c76468c..9e5a63c 100644 --- a/documents/HowToWork-cn.md +++ b/documents/HowToWork-cn.md @@ -9,7 +9,7 @@ - [速成路线图](#速成路线图) *** ## 基本原理 -GuiLite只作两个工作:界面元素管理和图形绘制。 +GuiLite只做两个工作:界面元素管理和图形绘制。 界面管理包括: - 添加/删除界面元素(例如:按钮,标签,对话框等控件),设置对应的文字及位置信息 diff --git a/workspace/1h-1cpp.sh b/workspace/1h-1cpp.sh index 6e5a29f..bc48e23 100644 --- a/workspace/1h-1cpp.sh +++ b/workspace/1h-1cpp.sh @@ -1,6 +1,6 @@ ./.sync.sh 1h1cpp -echo "Flatten source code into: GuiLite.h/GuiLite.cpp" +echo "Merging all source code into: GuiLite.h/GuiLite.cpp" # build GuiLiteRaw.h cd core_include @@ -47,6 +47,7 @@ gcc -c GuiLite.cpp # clean rm GuiLiteRaw.h GuiLiteRaw.cpp GuiLiteNoInclude.cpp +mv GuiLite.h GuiLite.cpp ../ echo "Done!" -echo "You could find GuiLite.h/GuiLite.cpp in this folder" +echo "You could find GuiLite.h/GuiLite.cpp in root folder" diff --git a/workspace/core/wnd.cpp b/workspace/core/wnd.cpp index 3c386c1..a137d2d 100644 --- a/workspace/core/wnd.cpp +++ b/workspace/core/wnd.cpp @@ -89,80 +89,6 @@ int c_wnd::load_child_wnd(WND_TREE *p_child_tree) return sum; } -c_wnd* c_wnd::connect_clone(c_wnd *parent, unsigned short resource_id, const char* str, - short x, short y, short width, short height, WND_TREE* p_child_tree ) -{ - if(0 == resource_id) - { - ASSERT(false); - return 0; - } - - c_wnd* wnd = clone(); - wnd->m_id = resource_id; - wnd->set_str(str); - wnd->m_parent = parent; - wnd->m_status = STATUS_NORMAL; - - if (parent) - { - wnd->m_z_order = parent->m_z_order; - wnd->m_surface = parent->m_surface; - } - else - { - wnd->m_surface = m_surface; - } - if(0 == wnd->m_surface) - { - ASSERT(false); - return 0; - } - - /* (cs.x = x * 1024 / 768) for 1027*768=>800*600 quickly*/ - wnd->m_wnd_rect.m_left = x; - wnd->m_wnd_rect.m_top = y; - wnd->m_wnd_rect.m_right = (x + width - 1); - wnd->m_wnd_rect.m_bottom = (y + height - 1); - - c_rect rect; - wnd->get_screen_rect(rect); - ASSERT(wnd->m_surface->is_valid(rect)); - - wnd->pre_create_wnd(); - - if ( 0 != parent ) - { - parent->add_child_2_tail(wnd); - } - - if (wnd->load_clone_child_wnd(p_child_tree) >= 0) - { - wnd->load_cmd_msg(); - wnd->on_init_children(); - } - return wnd; -} - -int c_wnd::load_clone_child_wnd(WND_TREE *p_child_tree) -{ - if (0 == p_child_tree) - { - return 0; - } - int sum = 0; - - WND_TREE* p_cur = p_child_tree; - while(p_cur->p_wnd) - { - p_cur->p_wnd->connect_clone(this, p_cur->resource_id, p_cur->str, - p_cur->x, p_cur->y, p_cur->width, p_cur->height,p_cur->p_child_tree); - p_cur++; - sum++; - } - return sum; -} - void c_wnd::disconnect() { if (0 == m_id) @@ -208,35 +134,9 @@ c_wnd* c_wnd::get_wnd_ptr(unsigned short id) const return child; } -void c_wnd::set_attr(WND_ATTRIBUTION attr) -{ - m_attr = attr; - - if ( ATTR_DISABLED == (attr & ATTR_DISABLED) ) - { - m_status = STATUS_DISABLED; - } - else - { - if (m_status == STATUS_DISABLED) - { - m_status = STATUS_NORMAL; - } - } -} - bool c_wnd::is_focus_wnd() const { - if ( (m_attr & ATTR_VISIBLE) - && !(m_attr & ATTR_DISABLED) - && (m_attr & ATTR_FOCUS)) - { - return true; - } - else - { - return false; - } + return ((m_attr & ATTR_VISIBLE) && (m_attr & ATTR_FOCUS)) ? true : false; } void c_wnd::set_wnd_pos(short x, short y, short width, short height) @@ -302,11 +202,6 @@ c_wnd* c_wnd::set_child_focus(c_wnd * focus_child) old_focus_child->on_kill_focus(); } m_focus_child = focus_child; - - if (m_parent) - { - m_parent->set_child_focus(this); - } m_focus_child->on_focus(); } } @@ -434,84 +329,93 @@ void c_wnd::show_window() } } -bool c_wnd::on_touch(int x, int y, TOUCH_ACTION action) +void c_wnd::on_touch(int x, int y, TOUCH_ACTION action) { - c_rect rect; + c_wnd* model_wnd = 0; + c_wnd* tmp_child = m_top_child; + while (tmp_child) + { + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) + { + model_wnd = tmp_child; + break; + } + tmp_child = tmp_child->m_next_sibling; + } + if (model_wnd) + { + return model_wnd->on_touch(x, y, action); + } + x -= m_wnd_rect.m_left; y -= m_wnd_rect.m_top; c_wnd* child = m_top_child; - - c_wnd* target_wnd = 0; - int target_z_order = Z_ORDER_LEVEL_0; - while (child) { - if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE)) + if (child->is_focus_wnd()) { + c_rect rect; child->get_wnd_rect(rect); - if (true == rect.PtInRect(x, y) || child->m_attr & ATTR_MODAL) + if (true == rect.PtInRect(x, y)) { - if (true == child->is_focus_wnd()) - { - if (child->m_z_order >= target_z_order) - { - target_wnd = child; - target_z_order = child->m_z_order; - } - } + return child->on_touch(x, y, action); } } child = child->m_next_sibling; } - - if (target_wnd == 0) - { - return false; - } - return target_wnd->on_touch(x, y, action); } -bool c_wnd::on_key(KEY_TYPE key) +void c_wnd::on_key(KEY_TYPE key) { - ASSERT(key == KEY_FORWARD || key == KEY_BACKWARD || key == KEY_ENTER); - - // Find current focus wnd. - c_wnd* old_focus_wnd = m_focus_child; - while (m_focus_child && m_focus_child->m_focus_child) + c_wnd* model_wnd = 0; + c_wnd* tmp_child = m_top_child; + while (tmp_child) { - old_focus_wnd = m_focus_child->m_focus_child; + if ((tmp_child->m_attr & ATTR_PRIORITY) && (tmp_child->m_attr & ATTR_VISIBLE)) + { + model_wnd = tmp_child; + break; + } + tmp_child = tmp_child->m_next_sibling; } - if (old_focus_wnd && !old_focus_wnd->on_key(key)) + if (model_wnd) { - return true; + return model_wnd->on_key(key); } - // Default moving focus(Default handle KEY_FOWARD/KEY_BACKWARD) - if (key == KEY_ENTER) + if (!is_focus_wnd()) { - return true; + return; } + if (key != KEY_BACKWARD && key != KEY_FORWARD) + { + if (m_focus_child) + { + m_focus_child->on_key(key); + } + return; + } + + // Move focus + c_wnd* old_focus_wnd = m_focus_child; + // No current focus wnd, new one. if (!old_focus_wnd) - {// No current focus wnd, new one. - c_wnd *child = m_top_child; - c_wnd *new_focus_wnd = 0; + { + c_wnd* child = m_top_child; + c_wnd* new_focus_wnd = 0; while (child) { - if (ATTR_VISIBLE == (child->m_attr & ATTR_VISIBLE)) + if (child->is_focus_wnd()) { - if (true == child->is_focus_wnd()) - { - new_focus_wnd = child; - new_focus_wnd->m_parent->set_child_focus(new_focus_wnd); - child = child->m_top_child; - continue; - } + new_focus_wnd = child; + new_focus_wnd->m_parent->set_child_focus(new_focus_wnd); + child = child->m_top_child; + continue; } child = child->m_next_sibling; } - return true; + return; } - // Move focus from old wnd to next wnd c_wnd* next_focus_wnd = (key == KEY_FORWARD) ? old_focus_wnd->m_next_sibling : old_focus_wnd->m_prev_sibling; while (next_focus_wnd && (!next_focus_wnd->is_focus_wnd())) @@ -530,7 +434,6 @@ bool c_wnd::on_key(KEY_TYPE key) { next_focus_wnd->m_parent->set_child_focus(next_focus_wnd); } - return true; } void c_wnd::notify_parent(int msg_id, int param) diff --git a/workspace/core_include/wnd.h b/workspace/core_include/wnd.h index 171e9bc..d576054 100644 --- a/workspace/core_include/wnd.h +++ b/workspace/core_include/wnd.h @@ -9,10 +9,9 @@ class c_surface; typedef enum { - ATTR_VISIBLE = 0x80000000L, - ATTR_DISABLED = 0x40000000L, + 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 @@ -56,10 +55,7 @@ class c_wnd : public c_cmd_target virtual ~c_wnd() {}; virtual int connect(c_wnd *parent, unsigned short resource_id, const char* str, short x, short y, short width, short height, WND_TREE* p_child_tree = 0); - virtual c_wnd* connect_clone(c_wnd *parent, unsigned short resource_id, const char* str, - short x, short y, short width, short height, WND_TREE* p_child_tree = 0); void disconnect(); - virtual c_wnd* clone() = 0; virtual void on_init_children() {} virtual void on_paint() {} virtual void show_window(); @@ -68,9 +64,9 @@ class c_wnd : public c_cmd_target int get_z_order() { return m_z_order; } c_wnd* get_wnd_ptr(unsigned short id) const; unsigned int get_attr() const { return m_attr; } - void set_attr(WND_ATTRIBUTION attr); void set_str(const char* str) { m_str = str; } + void set_attr(WND_ATTRIBUTION attr) { m_attr = attr; } bool is_focus_wnd() const; void set_font_color(unsigned int color) { m_font_color = color; } @@ -94,8 +90,8 @@ class c_wnd : public c_cmd_target void notify_parent(int msg_id, int param); - virtual bool on_touch(int x, int y, TOUCH_ACTION action);// return true: handled; false: not be handled. - virtual bool on_key(KEY_TYPE key);// return false: skip handling by parent; + virtual void on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); c_surface* get_surface() { return m_surface; } void set_surface(c_surface* surface) { m_surface = surface; } @@ -107,7 +103,6 @@ class c_wnd : public c_cmd_target void wnd2screen(c_rect &rect) const; int load_child_wnd(WND_TREE *p_child_tree); - int load_clone_child_wnd(WND_TREE *p_child_tree); void set_active_child(c_wnd* child) { m_focus_child = child; } virtual void on_focus() {}; diff --git a/workspace/widgets/button.cpp b/workspace/widgets/button.cpp index 688d845..5cda563 100644 --- a/workspace/widgets/button.cpp +++ b/workspace/widgets/button.cpp @@ -28,7 +28,7 @@ void c_button::on_kill_focus() on_paint(); } -bool c_button::on_touch(int x, int y, TOUCH_ACTION action) +void c_button::on_touch(int x, int y, TOUCH_ACTION action) { if (action == TOUCH_DOWN) { @@ -42,17 +42,21 @@ bool c_button::on_touch(int x, int y, TOUCH_ACTION action) on_paint(); notify_parent(GL_BN_CLICKED, 0); } - return true; } -bool c_button::on_key(KEY_TYPE key) +void c_button::on_key(KEY_TYPE key) { - if (key == KEY_ENTER) + switch (key) { - notify_parent(GL_BN_CLICKED, 0); - return false;// Do not handle KEY_ENTER by other wnd. + case KEY_ENTER: + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN); + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP); + break; + case KEY_FORWARD: + case KEY_BACKWARD: + break; } - return true;// Handle KEY_FOWARD/KEY_BACKWARD by parent wnd. + return c_wnd::on_key(key); } void c_button::on_paint() 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 3f55c95..909fabb 100644 --- a/workspace/widgets/edit.cpp +++ b/workspace/widgets/edit.cpp @@ -41,10 +41,22 @@ void c_edit::set_text(const char* str) } } -bool c_edit::on_touch(int x, int y, TOUCH_ACTION action) +void c_edit::on_key(KEY_TYPE key) +{ + switch (key) + { + case KEY_ENTER: + (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : (on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN), on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP)); + return; + case KEY_BACKWARD: + case KEY_FORWARD: + return (m_status == STATUS_PUSHED) ? s_keyboard.on_key(key) : c_wnd::on_key(key); + } +} + +void c_edit::on_touch(int x, int y, TOUCH_ACTION action) { (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y); - return true; } void c_edit::on_touch_down(int x, int y) @@ -144,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 38933c4..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; @@ -84,10 +84,34 @@ void c_list_box::on_paint() } } -bool c_list_box::on_touch(int x, int y, TOUCH_ACTION action) +void c_list_box::on_key(KEY_TYPE key) +{ + switch (key) + { + case KEY_ENTER: + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_DOWN); + on_touch(m_wnd_rect.m_left, m_wnd_rect.m_top, TOUCH_UP); + return; + case KEY_BACKWARD: + if (m_status != STATUS_PUSHED) + { + return c_wnd::on_key(key); + } + m_selected_item = (m_selected_item > 0) ? (m_selected_item - 1) : m_selected_item; + return show_list(); + case KEY_FORWARD: + if (m_status != STATUS_PUSHED) + { + return c_wnd::on_key(key); + } + m_selected_item = (m_selected_item < (m_item_total - 1)) ? (m_selected_item + 1) : m_selected_item; + return show_list(); + } +} + +void c_list_box::on_touch(int x, int y, TOUCH_ACTION action) { (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y); - return true; } void c_list_box::on_touch_down(int x, int y) diff --git a/workspace/widgets/slide_group.cpp b/workspace/widgets/slide_group.cpp index d18e060..eb7f428 100644 --- a/workspace/widgets/slide_group.cpp +++ b/workspace/widgets/slide_group.cpp @@ -100,50 +100,6 @@ int c_slide_group::add_slide(c_wnd* slide, unsigned short resource_id, short x, return -3; } -int c_slide_group::add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y, - short width, short height, WND_TREE* p_child_tree, Z_ORDER_LEVEL max_zorder) -{ - if(0 == slide) - { - return -1; - } - - c_surface* old_surface = get_surface(); - c_surface* new_surface = old_surface->get_display()->alloc_surface(max_zorder); - new_surface->set_active(false); - set_surface(new_surface); - c_wnd* page_tmp = slide->connect_clone(this,resource_id,0,x,y,width,height,p_child_tree); - set_surface(old_surface); - - int i = 0; - while(i < MAX_PAGES) - { - if(m_slides[i] == page_tmp) - {//slide has lived - ASSERT(false); - return -2; - } - i++; - } - - //new slide - i = 0; - while(i < MAX_PAGES) - { - if(m_slides[i] == 0) - { - m_slides[i] = page_tmp; - page_tmp->show_window(); - return 0; - } - i++; - } - - //no more slide can be add - ASSERT(false); - return -3; -} - void c_slide_group::disabel_all_slide() { for(int i = 0; i < MAX_PAGES; i++) @@ -155,7 +111,7 @@ void c_slide_group::disabel_all_slide() } } -bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) +void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) { x -= m_wnd_rect.m_left; y -= m_wnd_rect.m_top; @@ -167,14 +123,12 @@ bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) m_slides[m_active_slide_index]->on_touch(x, y, action); } } - return true; } -bool c_slide_group::on_key(KEY_TYPE key) +void c_slide_group::on_key(KEY_TYPE key) { if (m_slides[m_active_slide_index]) { m_slides[m_active_slide_index]->on_key(key); } - return true; } diff --git a/workspace/widgets/spinbox.cpp b/workspace/widgets/spinbox.cpp index 172863a..754aea6 100644 --- a/workspace/widgets/spinbox.cpp +++ b/workspace/widgets/spinbox.cpp @@ -9,174 +9,47 @@ #include "../widgets_include/button.h" #include "../widgets_include/spinbox.h" -#define ARROW_BT_HEIGHT 55 -#define ID_BT_ARROW_UP 1 -#define ID_BT_ARROW_DOWN 2 +#define ARROW_BT_WIDTH 55 +#define ID_BT_ARROW_UP 0x1111 +#define ID_BT_ARROW_DOWN 0x2222 -GL_BEGIN_MESSAGE_MAP(c_spin_box) -ON_GL_BN_CLICKED(c_spin_box::on_arrow_bt_click) -GL_END_MESSAGE_MAP() +void c_spin_button::on_touch(int x, int y, TOUCH_ACTION action) +{ + if (action == TOUCH_UP) + { + (m_id == ID_BT_ARROW_UP) ? m_spin_box->on_arrow_up_bt_click() : m_spin_box->on_arrow_down_bt_click(); + } + c_button::on_touch(x, y, action); +} void c_spin_box::pre_create_wnd() { - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); m_font_type = c_theme::get_font(FONT_DEFAULT); m_font_color = c_theme::get_color(COLOR_WND_FONT); - m_max = 6; m_min = 1; m_digit = 0; m_step = 1; - //set arrow button position. + //link arrow button position. c_rect rect; get_screen_rect(rect); - - m_bt_up_rect.m_left = rect.m_left; - m_bt_up_rect.m_right = rect.m_left + rect.Width() / 2 - 1; - m_bt_up_rect.m_top = rect.m_bottom + 1; - m_bt_up_rect.m_bottom = m_bt_up_rect.m_top + ARROW_BT_HEIGHT; - - m_bt_down_rect.m_left = rect.m_left + rect.Width() / 2; - m_bt_down_rect.m_right = rect.m_right; - m_bt_down_rect.m_top = rect.m_bottom + 1; - m_bt_down_rect.m_bottom = m_bt_down_rect.m_top + ARROW_BT_HEIGHT; -} - -bool c_spin_box::on_touch(int x, int y, TOUCH_ACTION action) -{ - (action == TOUCH_DOWN) ? on_touch_down(x, y) : on_touch_up(x, y); - return c_wnd::on_touch(x, y, action); -} - -void c_spin_box::on_touch_down(int x, int y) -{ - if (false == m_wnd_rect.PtInRect(x, y)) - {//maybe click on up/down arrow button - return; - } - if (STATUS_NORMAL == m_status) - { - m_parent->set_child_focus(this); - } -} - -void c_spin_box::on_touch_up(int x, int y) -{ - if (false == m_wnd_rect.PtInRect(x, y)) - {//maybe click on up/down arrow button - return; - } - - if (STATUS_FOCUSED == m_status) - { - m_status = STATUS_PUSHED; - on_paint(); - } - else if (STATUS_PUSHED == m_status) - { - m_value = m_cur_value; - m_status = STATUS_FOCUSED; - on_paint(); - notify_parent(GL_SPIN_CONFIRM, m_value); - } -} - -void c_spin_box::on_focus() -{ - m_status = STATUS_FOCUSED; - on_paint(); -} - -void c_spin_box::on_kill_focus() -{ - m_cur_value = m_value; - m_status = STATUS_NORMAL; - on_paint(); -} - -void c_spin_box::show_arrow_button() -{ - m_bt_up.connect(this, ID_BT_ARROW_UP, "\xe2\x96\xb2"/*unicode of up arrow*/, 0, m_wnd_rect.Height(), m_bt_up_rect.Width(),m_bt_up_rect.Height()); - m_bt_up.show_window(); - m_bt_down.connect(this, ID_BT_ARROW_DOWN, "\xe2\x96\xbc"/*unicode of down arrow*/, m_bt_up_rect.Width(), m_wnd_rect.Height(), m_bt_down_rect.Width(),m_bt_down_rect.Height()); - m_bt_down.show_window(); - - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS | ATTR_MODAL); -} - -void c_spin_box::hide_arrow_button() -{ - m_bt_up.disconnect(); - m_bt_down.disconnect(); - m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE | ATTR_FOCUS); + m_bt_down.m_spin_box = m_bt_up.m_spin_box = this; + m_bt_down.connect(m_parent, ID_BT_ARROW_DOWN, "-", rect.m_left - ARROW_BT_WIDTH, rect.m_top, ARROW_BT_WIDTH, rect.Height()); + m_bt_up.connect(m_parent, ID_BT_ARROW_UP, "+", rect.m_right, rect.m_top, ARROW_BT_WIDTH, rect.Height()); } void c_spin_box::on_paint() { - c_rect rect, tmp_rect, empty_rect; + c_rect rect; get_screen_rect(rect); - tmp_rect.m_left = rect.m_left; - tmp_rect.m_right = rect.m_right; - - switch(m_status) - { - case STATUS_NORMAL: - if (m_z_order > m_parent->get_z_order()) - { - hide_arrow_button(); - m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order); - m_z_order = m_parent->get_z_order(); - } - 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); - break; - case STATUS_FOCUSED: - if (m_z_order > m_parent->get_z_order()) - { - hide_arrow_button(); - m_surface->set_frame_layer_visible_rect(empty_rect, m_z_order); - m_z_order = m_parent->get_z_order(); - } - m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_FOCUS), 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_FOCUS), ALIGN_HCENTER | ALIGN_VCENTER); - break; - case STATUS_PUSHED: - if (m_z_order == m_parent->get_z_order()) - { - m_z_order++; - } - tmp_rect.m_top = m_bt_down_rect.m_top; - tmp_rect.m_bottom = m_bt_down_rect.m_bottom; - m_surface->set_frame_layer_visible_rect(tmp_rect, m_z_order); - show_arrow_button(); - 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); - 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_PUSHED), ALIGN_HCENTER | ALIGN_VCENTER); - break; - default: - ASSERT(false); - } -} - -void c_spin_box::on_arrow_bt_click(int ctr_id, int param) -{ - switch (ctr_id) - { - case ID_BT_ARROW_UP: - on_arrow_up_bt_click(ctr_id, param); - break; - case ID_BT_ARROW_DOWN: - on_arrow_down_bt_click(ctr_id, param); - break; - default: - ASSERT(false); - break; - } + 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); } -void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param) +void c_spin_box::on_arrow_up_bt_click() { if (m_cur_value + m_step > m_max) { @@ -187,7 +60,7 @@ void c_spin_box::on_arrow_up_bt_click(int ctr_id, int param) on_paint(); } -void c_spin_box::on_arrow_down_bt_click(int ctr_id, int param) +void c_spin_box::on_arrow_down_bt_click() { if (m_cur_value - m_step < m_min) { diff --git a/workspace/widgets/table.cpp b/workspace/widgets/table.cpp index 006b983..ec12944 100644 --- a/workspace/widgets/table.cpp +++ b/workspace/widgets/table.cpp @@ -3,10 +3,18 @@ #include "../core_include/rect.h" #include "../core_include/word.h" #include "../core_include/surface.h" +#include "../core_include/theme.h" #include "../core_include/cmd_target.h" #include "../core_include/wnd.h" #include "../widgets_include/table.h" +void c_table::pre_create_wnd() +{ + m_attr = (WND_ATTRIBUTION)(ATTR_VISIBLE); + m_font_type = c_theme::get_font(FONT_DEFAULT); + m_font_color = c_theme::get_color(COLOR_WND_FONT); +} + void c_table::set_item(int row, int col, char* str, unsigned int color) { draw_item( row, col, str, color); diff --git a/workspace/widgets_include/button.h b/workspace/widgets_include/button.h index 27ae4ca..ee3cf41 100644 --- a/workspace/widgets_include/button.h +++ b/workspace/widgets_include/button.h @@ -8,16 +8,14 @@ typedef struct struct_bitmap_info BITMAP_INFO; class c_button : public c_wnd { -public: - virtual c_wnd* clone(){return new c_button();} protected: virtual void on_paint(); virtual void on_focus(); virtual void on_kill_focus(); virtual void pre_create_wnd(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); - virtual bool on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); }; #endif diff --git a/workspace/widgets_include/edit.h b/workspace/widgets_include/edit.h index b70a44b..8e26d76 100644 --- a/workspace/widgets_include/edit.h +++ b/workspace/widgets_include/edit.h @@ -7,7 +7,6 @@ class c_edit : public c_wnd { friend class c_keyboard; public: - virtual c_wnd* clone(){return new c_edit();} const char* get_text(){return m_str;} void set_text(const char* str); void set_keyboard_style(KEYBOARD_STYLE kb_sytle) { m_kb_style = kb_sytle; } @@ -17,7 +16,8 @@ class c_edit : public c_wnd virtual void on_paint(); virtual void on_focus(); virtual void on_kill_focus(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); void on_key_board_click(int id, int param); GL_DECLARE_MESSAGE_MAP() diff --git a/workspace/widgets_include/keyboard.h b/workspace/widgets_include/keyboard.h index 69e5680..04800b8 100644 --- a/workspace/widgets_include/keyboard.h +++ b/workspace/widgets_include/keyboard.h @@ -32,7 +32,6 @@ class c_keyboard: public c_wnd char* get_str() { return m_str; } protected: virtual void pre_create_wnd(); - virtual c_wnd* clone(){return new c_keyboard();} virtual void on_paint(); void on_key_clicked(int id, int param); @@ -52,7 +51,6 @@ class c_keyboard: public c_wnd class c_keyboard_button : public c_button { protected: - virtual c_wnd* clone(){return new c_keyboard_button();} virtual void on_paint(); }; diff --git a/workspace/widgets_include/label.h b/workspace/widgets_include/label.h index 71c48c1..e900117 100644 --- a/workspace/widgets_include/label.h +++ b/workspace/widgets_include/label.h @@ -4,11 +4,9 @@ class c_label : public c_wnd { public: - virtual c_wnd* clone(){return new c_label();} virtual void on_paint(); protected: virtual void pre_create_wnd(); -private: }; #endif diff --git a/workspace/widgets_include/list_box.h b/workspace/widgets_include/list_box.h index 2382ce2..8890643 100644 --- a/workspace/widgets_include/list_box.h +++ b/workspace/widgets_include/list_box.h @@ -16,12 +16,12 @@ class c_list_box : public c_wnd void select_item(short index); protected: - virtual c_wnd* clone(){return new c_list_box();} virtual void pre_create_wnd(); virtual void on_paint(); virtual void on_focus(); virtual void on_kill_focus(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); private: void update_list_size(); diff --git a/workspace/widgets_include/slide_group.h b/workspace/widgets_include/slide_group.h index da7be96..3334173 100644 --- a/workspace/widgets_include/slide_group.h +++ b/workspace/widgets_include/slide_group.h @@ -13,14 +13,10 @@ class c_slide_group : public c_wnd { int add_slide(c_wnd* slide, unsigned short resource_id, short x, short y, short width, short height, WND_TREE* p_child_tree = 0, Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0); - int add_clone_silde(c_wnd* slide, unsigned short resource_id, short x, short y, - short width, short height, WND_TREE* p_child_tree = 0, - Z_ORDER_LEVEL max_zorder = Z_ORDER_LEVEL_0); void disabel_all_slide(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); - virtual bool on_key(KEY_TYPE key); + virtual void on_touch(int x, int y, TOUCH_ACTION action); + virtual void on_key(KEY_TYPE key); protected: - virtual c_wnd* clone(){return new c_slide_group();} c_wnd* m_slides[MAX_PAGES]; int m_active_slide_index; c_gesture* m_gesture; diff --git a/workspace/widgets_include/spinbox.h b/workspace/widgets_include/spinbox.h index 74be52d..0428e3c 100644 --- a/workspace/widgets_include/spinbox.h +++ b/workspace/widgets_include/spinbox.h @@ -1,63 +1,47 @@ #ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H #define GUILITE_WIDGETS_INCLUDE_SPINBOX_H -#define GL_SPIN_CONFIRM 0x2222 #define GL_SPIN_CHANGE 0x3333 -#define ON_SPIN_CONFIRM(func) \ -{MSG_TYPE_WND, GL_SPIN_CONFIRM, 0, msgCallback(&func)}, - #define ON_SPIN_CHANGE(func) \ {MSG_TYPE_WND, GL_SPIN_CHANGE, 0, msgCallback(&func)}, +class c_spin_box; +class c_spin_button : public c_button +{ + friend class c_spin_box; + virtual void on_touch(int x, int y, TOUCH_ACTION action); + c_spin_box* m_spin_box; +}; + class c_spin_box : public c_wnd { + friend class c_spin_button; public: - short get_value(){return m_value;} - void set_value(unsigned short value){m_value = m_cur_value = value;} - - void set_max_min(short max, short min){m_max = max; m_min = min;} - void set_step(short step){m_step = step;} - - short get_min(){return m_min;} - short get_max(){return m_max;} - short get_step(){return m_step;} + short get_value() { return m_value; } + void set_value(unsigned short value) { m_value = m_cur_value = value; } + void set_max_min(short max, short min) { m_max = max; m_min = min; } + void set_step(short step) { m_step = step; } + short get_min() { return m_min; } + short get_max() { return m_max; } + short get_step() { return m_step; } + void set_value_digit(short digit) { m_digit = digit; } + short get_value_digit() { return m_digit; } - void set_value_digit(short digit){m_digit = digit;} - short get_value_digit(){return m_digit;} - protected: - virtual c_wnd* clone(){return new c_spin_box();} virtual void on_paint(); - virtual void on_focus(); - virtual void on_kill_focus(); virtual void pre_create_wnd(); - virtual bool on_touch(int x, int y, TOUCH_ACTION action); + void on_arrow_up_bt_click(); + void on_arrow_down_bt_click(); - void on_arrow_bt_click(int ctr_id, int param); - void on_arrow_up_bt_click(int ctr_id, int param); - void on_arrow_down_bt_click(int ctr_id, int param); - - GL_DECLARE_MESSAGE_MAP() - -private: - void show_arrow_button(); - void hide_arrow_button(); - void on_touch_down(int x, int y); - void on_touch_up(int x, int y); - -protected: short m_cur_value; short m_value; short m_step; short m_max; short m_min; short m_digit; - - c_button m_bt_up; - c_button m_bt_down; - c_rect m_bt_up_rect; - c_rect m_bt_down_rect; + c_spin_button m_bt_up; + c_spin_button m_bt_down; }; #endif diff --git a/workspace/widgets_include/table.h b/workspace/widgets_include/table.h index 065738f..59da5cf 100644 --- a/workspace/widgets_include/table.h +++ b/workspace/widgets_include/table.h @@ -7,7 +7,6 @@ class c_table: public c_wnd { public: - virtual c_wnd* clone(){return new c_table();} void set_sheet_align(unsigned int align_type){ m_align_type = align_type;} void set_row_num(unsigned int row_num){ m_row_num = row_num;} void set_col_num(unsigned int col_num){ m_col_num = col_num;} @@ -22,6 +21,7 @@ class c_table: public c_wnd unsigned int get_col_num(){ return m_col_num;} c_rect get_item_rect(int row, int col); protected: + virtual void pre_create_wnd(); void draw_item(int row, int col, const char* str, unsigned int color); unsigned int m_align_type; diff --git a/workspace/widgets_include/wave_ctrl.h b/workspace/widgets_include/wave_ctrl.h index 2d4c1a7..be0b47c 100644 --- a/workspace/widgets_include/wave_ctrl.h +++ b/workspace/widgets_include/wave_ctrl.h @@ -12,7 +12,6 @@ class c_wave_ctrl : public c_wnd { public: c_wave_ctrl(); - virtual c_wnd* clone(){return new c_wave_ctrl();} virtual void on_init_children(); virtual void on_paint();