diff --git a/1h-1cpp.sh b/1h-1cpp.sh index 9705305..ab7e441 100644 --- a/1h-1cpp.sh +++ b/1h-1cpp.sh @@ -11,7 +11,7 @@ read -p "Please input:[1-3]:" input # build GuiLite.h cd core_include -cat api.h cmd_target.h rect.h msg.h resource.h theme.h surface.h display.h word.h bitmap.h wnd.h audio.h > core.h +cat api.h cmd_target.h rect.h resource.h theme.h surface.h display.h word.h bitmap.h wnd.h audio.h > core.h mv core.h ../ cd ../widgets_include diff --git a/CMakeLists.txt b/CMakeLists.txt index 1afb164..4b56569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}) # core FILE(GLOB CORE_SRC core/*.cpp) FILE(GLOB CORE_ADAPTER core/adapter/api_linux.cpp - core/adapter/audio_linux.cpp - core/adapter/msg_linux.cpp) + core/adapter/audio_linux.cpp) # gui FILE(GLOB WIDGETS_SRC widgets/*.cpp) diff --git a/GuiLite.uvprojx b/GuiLite.uvprojx index f26d0e7..8fc7a69 100644 --- a/GuiLite.uvprojx +++ b/GuiLite.uvprojx @@ -427,11 +427,6 @@ 8 .\core\adapter\api_unknow.cpp - - msg_unknow.cpp - 8 - .\core\adapter\msg_unknow.cpp - diff --git a/GuiLite.vcxproj b/GuiLite.vcxproj index 00e41e1..0968458 100644 --- a/GuiLite.vcxproj +++ b/GuiLite.vcxproj @@ -36,7 +36,7 @@ {DF7A4FAD-A68D-3E43-9C4B-7DE4EE77F732} - 10.0.16299.0 + 10.0 Win32Proj Win32 GuiLite @@ -46,12 +46,12 @@ StaticLibrary Unicode - v141 + v142 StaticLibrary Unicode - v141 + v142 StaticLibrary @@ -390,7 +390,6 @@ - diff --git a/GuiLite.vcxproj.filters b/GuiLite.vcxproj.filters index 9a0f08d..ca7a913 100644 --- a/GuiLite.vcxproj.filters +++ b/GuiLite.vcxproj.filters @@ -67,9 +67,6 @@ core\adapter - - core\adapter - diff --git a/README.md b/README.md index 2c2e246..37f86a4 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ GuiLite is the smallest GUI library with 5000 lines of code, could run on **all ### IoT Solution & Code Telemetry - Report build activities to cloud:
![BuildInfo](doc/BuildInfo.png) - Sync running data to cloud:
![DataOnCloud](doc/data_on_cloud.png) +- ⚠️To stop telemetry, remove script files(e,g: sync_build.bat .sync.sh .sync_build.sh) *** ### Support Docker We build GuiLite demo as docker image, you can update/deploy/run the latest GuiLite demo on your device with single command below: diff --git a/core/adapter/api_linux.cpp b/core/adapter/api_linux.cpp index 77bca59..f709bb6 100644 --- a/core/adapter/api_linux.cpp +++ b/core/adapter/api_linux.cpp @@ -1,5 +1,4 @@ #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #define MAX_TIMER_CNT 10 #define TIMER_UNIT 50//ms @@ -318,3 +318,68 @@ int build_bmp(const char *filename, unsigned int width, unsigned int height, uns fclose(fp); return 0; } + +c_fifo::c_fifo() +{ + m_head = m_tail = 0; + m_read_sem = malloc(sizeof(sem_t)); + m_write_mutex = malloc(sizeof(pthread_mutex_t)); + + sem_init((sem_t*)m_read_sem, 0, 0); + pthread_mutex_init((pthread_mutex_t*)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 + sem_wait((sem_t*)m_read_sem); + 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; + + pthread_mutex_lock((pthread_mutex_t*)m_write_mutex); + 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"); + pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex); + return 0; + } + m_buf[m_tail] = *pbuf++; + m_tail = (m_tail + 1) % FIFO_BUFFER_LEN; + i++; + } + pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex); + + if(i != len) + { + ASSERT(false); + } + else + { + sem_post((sem_t*)m_read_sem); + } + return i; +} diff --git a/core/adapter/api_unknow.cpp b/core/adapter/api_unknow.cpp index 040d795..3c0ccd6 100644 --- a/core/adapter/api_unknow.cpp +++ b/core/adapter/api_unknow.cpp @@ -75,3 +75,56 @@ int build_bmp(const char *filename, unsigned int width, unsigned int height, uns 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; +} diff --git a/core/adapter/api_win.cpp b/core/adapter/api_win.cpp index 5247b30..8731eaa 100644 --- a/core/adapter/api_win.cpp +++ b/core/adapter/api_win.cpp @@ -1,5 +1,4 @@ #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include #include #include @@ -325,3 +324,68 @@ int build_bmp(const char *filename, unsigned int width, unsigned int height, uns fclose(fp); return 0; } + +c_fifo::c_fifo() +{ + m_head = m_tail = 0; + m_read_sem = CreateSemaphore(0, // default security attributes + 0, // initial count + 1, // maximum count + 0); // unnamed semaphore + m_write_mutex = CreateMutex(0, false, 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 + WaitForSingleObject(m_read_sem, INFINITE); + 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; + + WaitForSingleObject(m_write_mutex, INFINITE); + 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"); + ReleaseMutex(m_write_mutex); + return 0; + } + m_buf[m_tail] = *pbuf++; + m_tail = (m_tail + 1) % FIFO_BUFFER_LEN; + i++; + } + ReleaseMutex(m_write_mutex); + + if (i != len) + { + ASSERT(false); + } + else + { + ReleaseSemaphore(m_read_sem, 1, 0); + } + return i; +} diff --git a/core/adapter/audio_linux.cpp b/core/adapter/audio_linux.cpp index 3998e8c..eca574a 100644 --- a/core/adapter/audio_linux.cpp +++ b/core/adapter/audio_linux.cpp @@ -1,5 +1,4 @@ #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include "../../core_include/audio.h" #include #include diff --git a/core/adapter/audio_win.cpp b/core/adapter/audio_win.cpp index 77c4945..bb89b89 100644 --- a/core/adapter/audio_win.cpp +++ b/core/adapter/audio_win.cpp @@ -3,7 +3,6 @@ #include #include "../../core_include/api.h" -#include "../../core_include/msg.h" #include "../../core_include/audio.h" #ifndef AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM diff --git a/core/adapter/msg_linux.cpp b/core/adapter/msg_linux.cpp deleted file mode 100644 index c02c34c..0000000 --- a/core/adapter/msg_linux.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "../../core_include/api.h" -#include "../../core_include/msg.h" -#include -#include -#include - -c_fifo::c_fifo() -{ - m_head = m_tail = 0; - m_read_sem = malloc(sizeof(sem_t)); - m_write_mutex = malloc(sizeof(pthread_mutex_t)); - - sem_init((sem_t*)m_read_sem, 0, 0); - pthread_mutex_init((pthread_mutex_t*)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 - sem_wait((sem_t*)m_read_sem); - 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; - - pthread_mutex_lock((pthread_mutex_t*)m_write_mutex); - 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"); - pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex); - return 0; - } - m_buf[m_tail] = *pbuf++; - m_tail = (m_tail + 1) % FIFO_BUFFER_LEN; - i++; - } - pthread_mutex_unlock((pthread_mutex_t*)m_write_mutex); - - if(i != len) - { - ASSERT(false); - } - else - { - sem_post((sem_t*)m_read_sem); - } - return i; -} diff --git a/core/adapter/msg_unknow.cpp b/core/adapter/msg_unknow.cpp deleted file mode 100644 index e47db0f..0000000 --- a/core/adapter/msg_unknow.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "../../core_include/api.h" -#include "../../core_include/msg.h" - -c_fifo::c_fifo() -{ - m_head = m_tail = 0; - m_read_sem = m_write_mutex = 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; -} diff --git a/core/adapter/msg_win.cpp b/core/adapter/msg_win.cpp deleted file mode 100644 index 59598a8..0000000 --- a/core/adapter/msg_win.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "../../core_include/api.h" -#include "../../core_include/msg.h" -#include - -c_fifo::c_fifo() -{ - m_head = m_tail = 0; - m_read_sem = CreateSemaphore(0, // default security attributes - 0, // initial count - 1, // maximum count - 0); // unnamed semaphore - m_write_mutex = CreateMutex(0, false, 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 - WaitForSingleObject(m_read_sem, INFINITE); - 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; - - WaitForSingleObject(m_write_mutex, INFINITE); - 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"); - ReleaseMutex(m_write_mutex); - return 0; - } - m_buf[m_tail] = *pbuf++; - m_tail = (m_tail + 1) % FIFO_BUFFER_LEN; - i++; - } - ReleaseMutex(m_write_mutex); - - if(i != len) - { - ASSERT(false); - } - else - { - ReleaseSemaphore(m_read_sem, 1, 0); - } - return i; -} diff --git a/core/display.cpp b/core/display.cpp index 33132f2..dd219c1 100644 --- a/core/display.cpp +++ b/core/display.cpp @@ -1,7 +1,6 @@ #include "../core_include/api.h" #include "../core_include/rect.h" #include "../core_include/cmd_target.h" -#include "../core_include/msg.h" #include "../core_include/surface.h" #include "../core_include/display.h" @@ -46,7 +45,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/api.h b/core_include/api.h index c68f3f4..53cf5c6 100644 --- a/core_include/api.h +++ b/core_include/api.h @@ -53,4 +53,19 @@ 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 diff --git a/core_include/display.h b/core_include/display.h index 8db60fb..847e7a3 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* s0, c_surface* s1, 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/core_include/msg.h b/core_include/msg.h deleted file mode 100644 index 1230637..0000000 --- a/core_include/msg.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef GUILITE_CORE_INCLUDE_MSG_H -#define GUILITE_CORE_INCLUDE_MSG_H - -typedef struct -{ - unsigned int dwMsgId; - unsigned int dwParam1; - unsigned int dwParam2; -}MSG_INFO; - -#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 diff --git a/widgets/gesture.cpp b/widgets/gesture.cpp index 1899274..73e08de 100644 --- a/widgets/gesture.cpp +++ b/widgets/gesture.cpp @@ -1,5 +1,4 @@ #include "../core_include/api.h" -#include "../core_include/msg.h" #include "../core_include/rect.h" #include "../core_include/surface.h" #include "../core_include/display.h" @@ -9,46 +8,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 +34,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 +74,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 +90,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 +107,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 +132,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 +167,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 +192,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 +211,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..d18e060 100644 --- a/widgets/slide_group.cpp +++ b/widgets/slide_group.cpp @@ -6,10 +6,12 @@ #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() { + m_gesture = new c_gesture(this); for(int i = 0; i < MAX_PAGES; i++) { m_slides[i] = 0; @@ -157,9 +159,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..da7be96 100644 --- a/widgets_include/slide_group.h +++ b/widgets_include/slide_group.h @@ -2,7 +2,7 @@ #define GUILITE_WIDGETS_INCLUDE_SLIDE_GROUP_H #define MAX_PAGES 5 - +class c_gesture; class c_slide_group : public c_wnd { public: c_slide_group(); @@ -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 diff --git a/widgets_include/table.h b/widgets_include/table.h index 2613178..065738f 100644 --- a/widgets_include/table.h +++ b/widgets_include/table.h @@ -22,7 +22,7 @@ public: unsigned int get_col_num(){ return m_col_num;} c_rect get_item_rect(int row, int col); protected: - void draw_item(int col, int row, const char* str, unsigned int color); + void draw_item(int row, int col, const char* str, unsigned int color); unsigned int m_align_type; unsigned int m_row_num;