Use touch events only from LVGL
This commit is contained in:
committed by
Raphael Coeffic
parent
197d177a6c
commit
b788bdb842
@@ -77,73 +77,6 @@ void MainWindow::setTouchEnabled(bool enable)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
|
||||||
bool getTouchOccured();
|
|
||||||
#endif
|
|
||||||
void MainWindow::checkEvents()
|
|
||||||
{
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
|
||||||
|
|
||||||
// if (touchPanelEventOccured()) {
|
|
||||||
if (getTouchOccured()) {
|
|
||||||
short lastDeltaX = touchState.lastDeltaX;
|
|
||||||
short lastDeltaY = touchState.lastDeltaY;;
|
|
||||||
TouchState newTouchState = touchPanelRead();
|
|
||||||
if(touchState.event != TE_SLIDE_END || newTouchState.event != TE_NONE)
|
|
||||||
touchState = newTouchState;
|
|
||||||
touchState.lastDeltaX = lastDeltaX;
|
|
||||||
touchState.lastDeltaY = lastDeltaY;
|
|
||||||
}
|
|
||||||
|
|
||||||
TouchEnableState currentState = touchEnableState;
|
|
||||||
|
|
||||||
switch(touchState.event)
|
|
||||||
{
|
|
||||||
case TE_DOWN:
|
|
||||||
case TE_SLIDE:
|
|
||||||
if(touchEnableState == TouchOn)
|
|
||||||
touchEnableState = TouchOn_Touching;
|
|
||||||
else if (touchEnableState == TouchOff)
|
|
||||||
touchEnableState = TouchOff_Touching;
|
|
||||||
break;
|
|
||||||
case TE_UP:
|
|
||||||
case TE_SLIDE_END:
|
|
||||||
if(touchEnableState == TouchOn_Touching)
|
|
||||||
touchEnableState = TouchOn;
|
|
||||||
else if (touchEnableState == TouchOff_Touching)
|
|
||||||
touchEnableState = TouchOff;
|
|
||||||
else if(touchEnableState == TouchOnToOff_Touching)
|
|
||||||
touchEnableState = TouchOff;
|
|
||||||
else if(touchEnableState == TouchOffToOn_Touching)
|
|
||||||
touchEnableState = TouchOn;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(touchState.event != TE_NONE)
|
|
||||||
_touchEventOccured = true;
|
|
||||||
|
|
||||||
if ( currentState == TouchOff
|
|
||||||
|| currentState == TouchOff_Touching
|
|
||||||
|| currentState == TouchOffToOn_Touching)
|
|
||||||
{
|
|
||||||
touchState.event = TE_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (touchState.event == TE_DOWN) {
|
|
||||||
onTouchStart(touchState.x + scrollPositionX, touchState.y + scrollPositionY);
|
|
||||||
slidingWindow = nullptr;
|
|
||||||
}
|
|
||||||
else if (touchState.event == TE_UP) {
|
|
||||||
touchState.event = TE_NONE;
|
|
||||||
onTouchEnd(touchState.startX + scrollPositionX, touchState.startY + scrollPositionY);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Window::checkEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::invalidate(const rect_t & rect)
|
void MainWindow::invalidate(const rect_t & rect)
|
||||||
{
|
{
|
||||||
if (invalidatedRect.w) {
|
if (invalidatedRect.w) {
|
||||||
|
|||||||
@@ -69,8 +69,6 @@ class MainWindow: public Window
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void checkEvents() override;
|
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
void setTouchEnabled(bool enable);
|
void setTouchEnabled(bool enable);
|
||||||
bool touchEventOccured() {
|
bool touchEventOccured() {
|
||||||
|
|||||||
+92
-38
@@ -26,6 +26,10 @@ Window * Window::slidingWindow = nullptr;
|
|||||||
Window * Window::capturedWindow = nullptr;
|
Window * Window::capturedWindow = nullptr;
|
||||||
std::list<Window *> Window::trash;
|
std::list<Window *> Window::trash;
|
||||||
|
|
||||||
|
extern lv_obj_t *virtual_kb;
|
||||||
|
|
||||||
|
static bool is_scrolling = false;
|
||||||
|
|
||||||
static void window_event_cb(lv_event_t * e)
|
static void window_event_cb(lv_event_t * e)
|
||||||
{
|
{
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
@@ -41,48 +45,98 @@ static void window_event_cb(lv_event_t * e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_obj_t *currentTarget = lv_event_get_current_target(e);
|
// If the event bubbled to the topmost window then
|
||||||
|
// hand it to libopenui MainWindow.
|
||||||
|
lv_obj_t *cur_target = lv_event_get_current_target(e);
|
||||||
|
if (MainWindow::isMainWindowCreated() &&
|
||||||
|
(lv_obj_get_parent(cur_target) == nullptr)) {
|
||||||
|
lv_obj_t *target = lv_event_get_target(e);
|
||||||
|
switch (code) {
|
||||||
|
case LV_EVENT_PRESSED:
|
||||||
|
case LV_EVENT_RELEASED: {
|
||||||
|
lv_indev_t* click_source = (lv_indev_t*)lv_event_get_param(e);
|
||||||
|
if(click_source == NULL || is_scrolling) return;
|
||||||
|
|
||||||
// if the event bubbled to the topmost window then hand it to libopenui MainWindow.
|
// Exclude keyboard ?
|
||||||
if (MainWindow::isMainWindowCreated()
|
// if(lv_indev_get_type(click_source) == LV_INDEV_TYPE_KEYPAD ||
|
||||||
&& (lv_obj_get_parent(currentTarget) == nullptr)) {
|
// lv_indev_get_type(click_source) == LV_INDEV_TYPE_ENCODER) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
lv_area_t obj_coords;
|
||||||
|
lv_obj_get_coords(target, &obj_coords);
|
||||||
|
|
||||||
switch(code) {
|
lv_point_t point_act;
|
||||||
case LV_EVENT_PRESSED:
|
lv_indev_get_point(click_source, &point_act);
|
||||||
case LV_EVENT_RELEASED:
|
|
||||||
case LV_EVENT_KEY:
|
// Ignore event from keypad
|
||||||
// do legacy processing
|
if(point_act.x < 0 || point_act.y < 0) return;
|
||||||
MainWindow::instance()->checkEvents();
|
|
||||||
break;
|
lv_point_t rel_pos;
|
||||||
case LV_EVENT_SCROLL: {
|
rel_pos.x = point_act.x - obj_coords.x1;
|
||||||
lv_obj_t* target = lv_event_get_target(e);
|
rel_pos.y = point_act.y - obj_coords.y1;
|
||||||
lv_coord_t scroll_y = lv_obj_get_scroll_y(target);
|
|
||||||
lv_coord_t scroll_x = lv_obj_get_scroll_x(target);
|
auto w = (Window*)lv_obj_get_user_data(target);
|
||||||
TRACE("SCROLL[x=%d;y=%d]", scroll_x, scroll_y);
|
if (!w) return;
|
||||||
Window* w = (Window*)lv_obj_get_user_data(target);
|
|
||||||
if (w) {
|
rel_pos.x += w->getScrollPositionX();
|
||||||
|
rel_pos.y += w->getScrollPositionY();
|
||||||
|
|
||||||
|
if (code == LV_EVENT_PRESSED) {
|
||||||
|
TRACE("PRESSED[%d|%d]", rel_pos.x, rel_pos.y);
|
||||||
|
w->onTouchStart(rel_pos.x, rel_pos.y);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
lv_point_t vect_act;
|
||||||
|
lv_indev_get_vect(click_source, &vect_act);
|
||||||
|
|
||||||
|
TRACE("RELEASED[%d|%d] vect[%d|%d]",
|
||||||
|
rel_pos.x, rel_pos.y,
|
||||||
|
vect_act.x, vect_act.y,
|
||||||
|
lv_indev_get_scroll_dir(click_source));
|
||||||
|
|
||||||
|
if (vect_act.x != 0 || vect_act.y != 0) return;
|
||||||
|
w->onTouchEnd(rel_pos.x, rel_pos.y);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case LV_EVENT_CLICKED:
|
||||||
|
TRACE("CLICKED");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LV_EVENT_KEY:
|
||||||
|
// do legacy processing
|
||||||
|
MainWindow::instance()->checkEvents();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LV_EVENT_SCROLL: {
|
||||||
|
lv_coord_t scroll_y = lv_obj_get_scroll_y(target);
|
||||||
|
lv_coord_t scroll_x = lv_obj_get_scroll_x(target);
|
||||||
|
TRACE("SCROLL[x=%d;y=%d]", scroll_x, scroll_y);
|
||||||
|
Window *w = (Window *)lv_obj_get_user_data(target);
|
||||||
|
if (w) {
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
TRACE("%s", w->getWindowDebugString().c_str());
|
TRACE("%s", w->getWindowDebugString().c_str());
|
||||||
#endif
|
#endif
|
||||||
w->setScrollPositionY(scroll_y);
|
w->setScrollPositionY(scroll_y);
|
||||||
w->setScrollPositionX(scroll_x);
|
w->setScrollPositionX(scroll_x);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case LV_EVENT_SCROLL_BEGIN:
|
case LV_EVENT_SCROLL_BEGIN:
|
||||||
TRACE("SCROLL_BEGIN");
|
TRACE("SCROLL_BEGIN");
|
||||||
break;
|
is_scrolling = true;
|
||||||
case LV_EVENT_SCROLL_END:
|
break;
|
||||||
TRACE("SCROLL_END");
|
case LV_EVENT_SCROLL_END:
|
||||||
break;
|
TRACE("SCROLL_END");
|
||||||
case LV_EVENT_FOCUSED: {
|
is_scrolling = false;
|
||||||
lv_obj_t* target = lv_event_get_target(e);
|
break;
|
||||||
bool lvgl_focused = lv_obj_has_state(target, LV_STATE_FOCUSED);
|
case LV_EVENT_FOCUSED: {
|
||||||
bool loiu_focused = ((Window*)target->user_data)->hasFocus();
|
bool lvgl_focused = lv_obj_has_state(target, LV_STATE_FOCUSED);
|
||||||
TRACE("FOCUSED[%d|%d]", lvgl_focused, loiu_focused);
|
bool loiu_focused = ((Window *)target->user_data)->hasFocus();
|
||||||
if (!loiu_focused) {
|
TRACE("FOCUSED[%d|%d]", lvgl_focused, loiu_focused);
|
||||||
((Window*)target->user_data)->setFocus();
|
if (!loiu_focused) {
|
||||||
}
|
((Window *)target->user_data)->setFocus();
|
||||||
} break;
|
}
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-6
@@ -404,6 +404,11 @@ class Window
|
|||||||
return _deleted;
|
return _deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HARDWARE_TOUCH)
|
||||||
|
virtual bool onTouchStart(coord_t x, coord_t y);
|
||||||
|
virtual bool onTouchEnd(coord_t x, coord_t y);
|
||||||
|
#endif
|
||||||
|
|
||||||
inline lv_obj_t *getLvObj() { return lvobj; }
|
inline lv_obj_t *getLvObj() { return lvobj; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -463,13 +468,11 @@ class Window
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HARDWARE_TOUCH)
|
#if defined(HARDWARE_TOUCH)
|
||||||
static coord_t getSnapStep(coord_t relativeScrollPosition, coord_t pageSize);
|
static coord_t getSnapStep(coord_t relativeScrollPosition,
|
||||||
|
coord_t pageSize);
|
||||||
|
|
||||||
virtual bool onTouchStart(coord_t x, coord_t y);
|
virtual bool onTouchSlide(coord_t x, coord_t y, coord_t startX,
|
||||||
|
coord_t startY, coord_t slideX, coord_t slideY);
|
||||||
virtual bool onTouchEnd(coord_t x, coord_t y);
|
|
||||||
|
|
||||||
virtual bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool forwardTouchEnd(coord_t x, coord_t y);
|
bool forwardTouchEnd(coord_t x, coord_t y);
|
||||||
|
|||||||
Reference in New Issue
Block a user