diff --git a/core/display.cpp b/core/display.cpp index 33132f2..81238ed 100644 --- a/core/display.cpp +++ b/core/display.cpp @@ -46,7 +46,7 @@ c_surface* c_display::alloc_surface(Z_ORDER_LEVEL max_zorder) return m_surface_group[i]; } -int c_display::merge_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) +int c_display::swipe_surface(c_surface* s0, c_surface* s1, int x0, int x1, int y0, int y1, int offset) { int surface_width = s0->get_width(); int surface_height = s0->get_height(); diff --git a/core_include/display.h b/core_include/display.h index 8db60fb..b3afbe2 100644 --- a/core_include/display.h +++ b/core_include/display.h @@ -13,7 +13,7 @@ public: unsigned int surface_width, unsigned int surface_height, unsigned int color_bytes, unsigned int surface_cnt, EXTERNAL_GFX_OP* gfx_op = 0); c_surface* alloc_surface(Z_ORDER_LEVEL max_zorder); - int merge_surface(c_surface* s1, c_surface* s2, int x0, int x1, int y0, int y2, int offset); + int swipe_surface(c_surface* s1, c_surface* s2, int x0, int x1, int y0, int y2, int offset); unsigned int get_width() { return m_width; } unsigned int get_height() { return m_height; } diff --git a/widgets/gesture.cpp b/widgets/gesture.cpp index 1899274..e1ce8fe 100644 --- a/widgets/gesture.cpp +++ b/widgets/gesture.cpp @@ -9,46 +9,24 @@ #include "../widgets_include/slide_group.h" #include -//#define FLIP_STEP 300//for arm -#define FLIP_STEP 10//for PC & ANDROID +//#define SWIPE_STEP 300//for arm +#define SWIPE_STEP 10//for PC & ANDROID #define MOVE_THRESHOLD 10 -void* c_gesture::task_handle_msg(void* param) +c_gesture::c_gesture(c_slide_group* group) { - c_gesture* This = (c_gesture*)param; - MSG_INFO msg; - while(1) - { - This->m_hid_fifo->read(&msg, sizeof(msg)); - if(This->handle_flip(msg)) - { - This->handle_hid_msg(msg); - } - } - return 0; -} - -c_gesture::c_gesture(c_wnd* root, c_slide_group* group, c_fifo* hid_fifo) -{ - m_root = root; m_slide_group = group; - m_hid_fifo = hid_fifo; - m_action = TOUCH_IDLE; + m_state = TOUCH_IDLE; m_down_x = m_down_y = m_move_x = m_move_y = 0; - - unsigned long pid; - create_thread(&pid, 0, task_handle_msg, this); } -bool c_gesture::handle_flip(MSG_INFO &msg) +bool c_gesture::handle_swipe(int x, int y, TOUCH_ACTION action) { - int x = msg.dwParam1; - - if(msg.dwMsgId == 0x4700)//MOUSE_LBUTTONDOWN + if(action == TOUCH_DOWN)//MOUSE_LBUTTONDOWN { - if(m_action == TOUCH_IDLE) + if(m_state == TOUCH_IDLE) { - m_action = TOUCH_MOVE; + m_state = TOUCH_MOVE; m_move_x = m_down_x = x; return true; } @@ -57,12 +35,12 @@ bool c_gesture::handle_flip(MSG_INFO &msg) return on_move(x); } } - else if(msg.dwMsgId == 0x4600)//MOUSE_LBUTTONUP + else if(action == TOUCH_UP)//MOUSE_LBUTTONUP { - if(m_action == TOUCH_MOVE) + if(m_state == TOUCH_MOVE) { - m_action = TOUCH_IDLE; - return on_flip(x); + m_state = TOUCH_IDLE; + return on_swipe(x); } else { @@ -97,7 +75,7 @@ bool c_gesture::on_move(int x) return false; } -bool c_gesture::on_flip(int x) +bool c_gesture::on_swipe(int x) { if (m_slide_group == 0) { @@ -113,11 +91,11 @@ bool c_gesture::on_flip(int x) m_move_x = x; if ((m_move_x - m_down_x) > 0) { - page = flip_right(); + page = swipe_right(); } else { - page = flip_left(); + page = swipe_left(); } if (page >= 0) { @@ -130,7 +108,7 @@ bool c_gesture::on_flip(int x) return false; } -int c_gesture::flip_left() +int c_gesture::swipe_left() { if (m_slide_group == 0) { @@ -155,17 +133,17 @@ int c_gesture::flip_left() m_slide_group->get_screen_rect(rc); while(step < rc.Width()) { - s1->get_display()->merge_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step); - step += FLIP_STEP; + s1->get_display()->swipe_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step); + step += SWIPE_STEP; } if (step != rc.Width()) { - s1->get_display()->merge_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, rc.Width()); + s1->get_display()->swipe_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, rc.Width()); } return (index + 1); } -int c_gesture::flip_right() +int c_gesture::swipe_right() { if (m_slide_group == 0) { @@ -190,12 +168,12 @@ int c_gesture::flip_right() int step = rc.Width() - (m_move_x - m_down_x); while(step > 0) { - s1->get_display()->merge_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step); - step -= FLIP_STEP; + s1->get_display()->swipe_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, step); + step -= SWIPE_STEP; } if (step != 0) { - s1->get_display()->merge_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, 0); + s1->get_display()->swipe_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, 0); } return (index - 1); } @@ -215,7 +193,7 @@ void c_gesture::move_left() m_slide_group->get_screen_rect(rc); if(s1->get_display() == s2->get_display()) { - s1->get_display()->merge_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, (m_down_x - m_move_x)); + s1->get_display()->swipe_surface(s2, s1, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, (m_down_x - m_move_x)); } } @@ -234,19 +212,6 @@ void c_gesture::move_right() m_slide_group->get_screen_rect(rc); if(s1->get_display() == s2->get_display()) { - s1->get_display()->merge_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, (rc.Width() - (m_move_x - m_down_x))); - } -} - -void c_gesture::handle_hid_msg(MSG_INFO &msg) -{ - switch(msg.dwMsgId) - { - case 0x4700://MOUSE_LBUTTONDOWN - m_root->on_touch(msg.dwParam1, msg.dwParam2, TOUCH_DOWN); - break; - case 0x4600://MOUSE_LBUTTONUP - m_root->on_touch(msg.dwParam1, msg.dwParam2, TOUCH_UP); - break; + s1->get_display()->swipe_surface(s1, s2, rc.m_left, rc.m_right, rc.m_top, rc.m_bottom, (rc.Width() - (m_move_x - m_down_x))); } } diff --git a/widgets/slide_group.cpp b/widgets/slide_group.cpp index f1117e7..f58cf06 100644 --- a/widgets/slide_group.cpp +++ b/widgets/slide_group.cpp @@ -6,9 +6,10 @@ #include "../core_include/wnd.h" #include "../core_include/surface.h" #include "../widgets_include/dialog.h" +#include "../widgets_include/gesture.h" #include "../widgets_include/slide_group.h" -c_slide_group::c_slide_group() +c_slide_group::c_slide_group() : m_gesture(this) { for(int i = 0; i < MAX_PAGES; i++) { @@ -157,9 +158,13 @@ bool c_slide_group::on_touch(int x, int y, TOUCH_ACTION action) { x -= m_wnd_rect.m_left; y -= m_wnd_rect.m_top; - if (m_slides[m_active_slide_index]) + + if (m_gesture.handle_swipe(x, y, action)) { - m_slides[m_active_slide_index]->on_touch(x, y, action); + if (m_slides[m_active_slide_index]) + { + m_slides[m_active_slide_index]->on_touch(x, y, action); + } } return true; } diff --git a/widgets_include/gesture.h b/widgets_include/gesture.h index f563f62..082a19f 100644 --- a/widgets_include/gesture.h +++ b/widgets_include/gesture.h @@ -4,35 +4,27 @@ typedef enum{ TOUCH_MOVE, TOUCH_IDLE -}ACTION; +}TOUCH_STATE; class c_slide_group; class c_gesture{ public: - c_gesture(c_wnd* root, c_slide_group* group, c_fifo* hid_fifo); - void set_page_group(c_slide_group* group){m_slide_group = group;} -protected: - bool handle_flip(MSG_INFO &msg); - bool on_move(int x); - bool on_flip(int x); + c_gesture(c_slide_group* group); + bool handle_swipe(int x, int y, TOUCH_ACTION action); private: - int flip_left(); - int flip_right(); + bool on_move(int x); + bool on_swipe(int x); + int swipe_left(); + int swipe_right(); void move_left(); void move_right(); - void handle_hid_msg(MSG_INFO &msg); int m_down_x; int m_down_y; int m_move_x; int m_move_y; - ACTION m_action; - + TOUCH_STATE m_state; c_slide_group* m_slide_group; - c_wnd* m_root; - c_fifo* m_hid_fifo; - - static void* task_handle_msg(void* param); }; #endif diff --git a/widgets_include/slide_group.h b/widgets_include/slide_group.h index dad1fea..75eb271 100644 --- a/widgets_include/slide_group.h +++ b/widgets_include/slide_group.h @@ -23,6 +23,7 @@ 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; }; #endif