From add08fdd8c3e00e4d372e1e5e7c55ed8fd64708b Mon Sep 17 00:00:00 2001 From: idea4good Date: Sat, 14 Mar 2020 18:21:37 +0800 Subject: [PATCH] fix touch issue, update spinbox appearance --- GuiLite.h | 28 ++++++++++++++-------------- workspace/core_include/wnd.h | 22 ++++++++++++---------- workspace/widgets_include/spinbox.h | 8 ++++---- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/GuiLite.h b/GuiLite.h index b15d69e..75f14a1 100644 --- a/GuiLite.h +++ b/GuiLite.h @@ -1681,23 +1681,23 @@ public: } virtual void on_touch(int x, int y, TOUCH_ACTION action) { - c_wnd* model_wnd = 0; + x -= m_wnd_rect.m_left; + y -= m_wnd_rect.m_top; + c_wnd* priority_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; + priority_wnd = tmp_child; break; } tmp_child = tmp_child->m_next_sibling; } - if (model_wnd) + if (priority_wnd) { - return model_wnd->on_touch(x, y, action); + return priority_wnd->on_touch(x, y, action); } - x -= m_wnd_rect.m_left; - y -= m_wnd_rect.m_top; c_wnd* child = m_top_child; while (child) { @@ -1715,20 +1715,20 @@ public: } virtual void on_key(KEY_TYPE key) { - c_wnd* model_wnd = 0; + c_wnd* priority_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; + priority_wnd = tmp_child; break; } tmp_child = tmp_child->m_next_sibling; } - if (model_wnd) + if (priority_wnd) { - return model_wnd->on_key(key); + return priority_wnd->on_key(key); } if (!is_focus_wnd()) { @@ -3092,7 +3092,6 @@ inline void c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) #endif #ifndef GUILITE_WIDGETS_INCLUDE_SPINBOX_H #define GUILITE_WIDGETS_INCLUDE_SPINBOX_H -#define ARROW_BT_WIDTH 55 #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 #define GL_SPIN_CHANGE 0x3333 @@ -3123,6 +3122,7 @@ protected: { c_rect rect; get_screen_rect(rect); + rect.m_right = rect.m_left + (rect.Width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); } @@ -3137,10 +3137,10 @@ protected: m_step = 1; //link arrow button position. c_rect rect; - get_screen_rect(rect); + get_wnd_rect(rect); 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()); + m_bt_up.connect(m_parent, ID_BT_ARROW_UP, "+", (rect.m_left + rect.Width() * 2 / 3), rect.m_top, (rect.Width() / 3), (rect.Height() / 2)); + m_bt_down.connect(m_parent, ID_BT_ARROW_DOWN, "-", (rect.m_left + rect.Width() * 2 / 3), (rect.m_top + rect.Height() / 2), (rect.Width() / 3), (rect.Height() / 2)); } void on_arrow_up_bt_click() { diff --git a/workspace/core_include/wnd.h b/workspace/core_include/wnd.h index 9a6027c..8da4a9e 100644 --- a/workspace/core_include/wnd.h +++ b/workspace/core_include/wnd.h @@ -319,24 +319,25 @@ public: virtual void on_touch(int x, int y, TOUCH_ACTION action) { - c_wnd* model_wnd = 0; + x -= m_wnd_rect.m_left; + y -= m_wnd_rect.m_top; + + c_wnd* priority_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; + priority_wnd = tmp_child; break; } tmp_child = tmp_child->m_next_sibling; } - if (model_wnd) + if (priority_wnd) { - return model_wnd->on_touch(x, y, action); + return priority_wnd->on_touch(x, y, action); } - x -= m_wnd_rect.m_left; - y -= m_wnd_rect.m_top; c_wnd* child = m_top_child; while (child) { @@ -354,20 +355,20 @@ public: } virtual void on_key(KEY_TYPE key) { - c_wnd* model_wnd = 0; + c_wnd* priority_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; + priority_wnd = tmp_child; break; } tmp_child = tmp_child->m_next_sibling; } - if (model_wnd) + if (priority_wnd) { - return model_wnd->on_key(key); + return priority_wnd->on_key(key); } if (!is_focus_wnd()) @@ -468,6 +469,7 @@ protected: parent = parent->m_parent; } } + void wnd2screen(c_rect &rect) const { int l = rect.m_left; diff --git a/workspace/widgets_include/spinbox.h b/workspace/widgets_include/spinbox.h index 2fbe81f..755ab48 100644 --- a/workspace/widgets_include/spinbox.h +++ b/workspace/widgets_include/spinbox.h @@ -11,7 +11,6 @@ #include "../core_include/theme.h" #include "../widgets_include/button.h" -#define ARROW_BT_WIDTH 55 #define ID_BT_ARROW_UP 0x1111 #define ID_BT_ARROW_DOWN 0x2222 #define GL_SPIN_CHANGE 0x3333 @@ -46,6 +45,7 @@ protected: { c_rect rect; get_screen_rect(rect); + rect.m_right = rect.m_left + (rect.Width() * 2 / 3); m_surface->fill_rect(rect, c_theme::get_color(COLOR_WND_NORMAL), m_z_order); c_word::draw_value_in_rect(m_surface, m_parent->get_z_order(), m_cur_value, m_digit, rect, m_font_type, m_font_color, c_theme::get_color(COLOR_WND_NORMAL), ALIGN_HCENTER | ALIGN_VCENTER); @@ -62,10 +62,10 @@ protected: //link arrow button position. c_rect rect; - get_screen_rect(rect); + get_wnd_rect(rect); 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()); + m_bt_up.connect(m_parent, ID_BT_ARROW_UP, "+", (rect.m_left + rect.Width() * 2 / 3), rect.m_top, (rect.Width() / 3), (rect.Height() / 2)); + m_bt_down.connect(m_parent, ID_BT_ARROW_DOWN, "-", (rect.m_left + rect.Width() * 2 / 3), (rect.m_top + rect.Height() / 2), (rect.Width() / 3), (rect.Height() / 2)); } void on_arrow_up_bt_click() {