Touch events again and some clean-up
This commit is contained in:
committed by
Raphael Coeffic
parent
81366e5ae6
commit
681c161dd3
@@ -22,10 +22,10 @@
|
||||
#include "opentx.h"
|
||||
|
||||
#include "LvglWrapper.h"
|
||||
#include "view_main.h"
|
||||
|
||||
LvglWrapper* LvglWrapper::_instance = nullptr;
|
||||
|
||||
static lv_disp_drv_t disp_drv; /*A variable to hold the drivers. Must be static or global.*/
|
||||
lv_disp_t * disp;
|
||||
static lv_disp_draw_buf_t disp_buf;
|
||||
|
||||
@@ -130,9 +130,11 @@ BitmapBuffer canBuf(BMP_RGB565, LCD_W, LCD_H, (uint16_t *)cbuf);
|
||||
|
||||
extern BitmapBuffer * lcdFront;
|
||||
extern BitmapBuffer * lcd;
|
||||
LvglWrapper::LvglWrapper()
|
||||
|
||||
static lv_disp_drv_t disp_drv;
|
||||
|
||||
static lv_disp_drv_t* init_disp_drv()
|
||||
{
|
||||
lv_init();
|
||||
lv_disp_draw_buf_init(&disp_buf, lcdFront->getData(), lcd->getData(), LCD_W*LCD_H);
|
||||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
||||
disp_drv.draw_buf = &disp_buf; /*Set an initialized buffer*/
|
||||
@@ -146,15 +148,15 @@ LvglWrapper::LvglWrapper()
|
||||
#endif
|
||||
disp_drv.sw_rotate = 1;
|
||||
|
||||
/*Register the driver in LVGL and save the created input device object*/
|
||||
return &disp_drv;
|
||||
}
|
||||
|
||||
static void init_lvgl_drivers()
|
||||
{
|
||||
// Register the driver and save the created display objects
|
||||
disp = lv_disp_drv_register(init_disp_drv());
|
||||
|
||||
disp = lv_disp_drv_register(&disp_drv); /*Register the driver and save the created display objects*/
|
||||
|
||||
// create a canvas as the drawing target for libopenui as a hack. This is going to be removed
|
||||
canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, LCD_W, LCD_H, LV_IMG_CF_TRUE_COLOR);
|
||||
|
||||
// Register the driver in LVGL and save the created input device object
|
||||
lv_indev_drv_init(&touchDriver); /*Basic initialization*/
|
||||
touchDriver.type = LV_INDEV_TYPE_POINTER; /*See below.*/
|
||||
touchDriver.read_cb = touchDriverRead; /*See below.*/
|
||||
@@ -166,6 +168,25 @@ LvglWrapper::LvglWrapper()
|
||||
lv_indev_drv_register(&keyboard_drv);
|
||||
}
|
||||
|
||||
LvglWrapper::LvglWrapper()
|
||||
{
|
||||
lv_init();
|
||||
init_lvgl_drivers();
|
||||
|
||||
// Create a canvas as the drawing target for libopenui as a hack.
|
||||
// This is going to be removed
|
||||
//
|
||||
canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, LCD_W, LCD_H, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_obj_set_style_bg_opa(canvas, LV_OPA_MAX, LV_PART_MAIN);
|
||||
|
||||
auto window = MainWindow::instance();
|
||||
lv_obj_set_parent(canvas, window->getLvObj());
|
||||
lv_obj_move_background(canvas);
|
||||
lv_scr_load(window->getLvObj());
|
||||
lv_obj_invalidate(canvas);
|
||||
}
|
||||
|
||||
void LvglWrapper::run()
|
||||
{
|
||||
tmr10ms_t tick = get_tmr10ms();
|
||||
|
||||
@@ -114,11 +114,9 @@ bool BindRxChoiceMenu::onTouchEnd(coord_t x, coord_t y)
|
||||
// Note: onCancel() is not called when the menu is discarded
|
||||
// by clicking outside the menu window and the onCancel
|
||||
// handler is not accessible from here
|
||||
if (!Window::onTouchEnd(x, y)) {
|
||||
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
|
||||
onKeyPress();
|
||||
deleteLater();
|
||||
}
|
||||
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
|
||||
onKeyPress();
|
||||
deleteLater();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,7 @@ class RadioGhostModuleConfig: public Page
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onEvent(event_t event) override;
|
||||
void checkEvents();
|
||||
void checkEvents() override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -51,6 +51,8 @@ ViewMain::ViewMain():
|
||||
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||
lv_obj_set_user_data(tile_view, this);
|
||||
|
||||
lv_obj_set_style_bg_opa(tile_view, LV_OPA_TRANSP, LV_PART_MAIN);
|
||||
|
||||
lv_obj_move_foreground(topbar->getLvObj());
|
||||
}
|
||||
|
||||
@@ -62,6 +64,7 @@ ViewMain::~ViewMain()
|
||||
void ViewMain::addMainView(Window* view, uint32_t viewId)
|
||||
{
|
||||
auto tile = lv_tileview_add_tile(tile_view, viewId, 0, LV_DIR_LEFT | LV_DIR_RIGHT);
|
||||
lv_obj_add_flag(tile, LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||
lv_obj_set_user_data(tile, view);
|
||||
|
||||
view->setLeft(lv_obj_get_x(tile));
|
||||
@@ -203,18 +206,16 @@ void ViewMain::setScrollPositionY(coord_t value)
|
||||
|
||||
bool ViewMain::onTouchEnd(coord_t x, coord_t y)
|
||||
{
|
||||
if (Window::onTouchEnd(x,y)) return true;
|
||||
if (!hasFocus()) {
|
||||
setFocus();
|
||||
}
|
||||
else {
|
||||
openMenu();
|
||||
int x1 = x;
|
||||
int w1 = getParent()->width();
|
||||
while (x1 > w1) x1 -= w1;
|
||||
if (x1 > w1 / 2)
|
||||
pushEvent(EVT_ROTARY_LEFT);
|
||||
}
|
||||
openMenu();
|
||||
|
||||
// TODO: remove this hack to preset
|
||||
// the scrolling on the main menu
|
||||
int x1 = x;
|
||||
int w1 = getParent()->width();
|
||||
while (x1 > w1) x1 -= w1;
|
||||
if (x1 > w1 / 2)
|
||||
pushEvent(EVT_ROTARY_LEFT);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -34,9 +34,7 @@
|
||||
#include "view_text.h"
|
||||
|
||||
|
||||
LvglWidgetFactory viewMainFactory = LvglWidgetFactory([] (lv_obj_t *parent) {
|
||||
return lv_obj_create(nullptr);
|
||||
});
|
||||
static LvglWidgetFactory viewMainFactory = {lv_obj_create, nullptr};
|
||||
|
||||
ViewMainMenu::ViewMainMenu(Window* parent) :
|
||||
Window(parent->getFullScreenWindow(), {}, 0, 0, &viewMainFactory)
|
||||
|
||||
@@ -34,10 +34,8 @@ public:
|
||||
bool onTouchStart(coord_t /*x*/, coord_t /*y*/) override { return true; }
|
||||
bool onTouchEnd(coord_t x, coord_t y) override
|
||||
{
|
||||
if (!Window::onTouchEnd(x, y)) {
|
||||
onKeyPress();
|
||||
deleteLater();
|
||||
}
|
||||
onKeyPress();
|
||||
deleteLater();
|
||||
return true;
|
||||
}
|
||||
bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY,
|
||||
|
||||
@@ -76,16 +76,10 @@ bool Widget::onTouchEnd(coord_t x, coord_t y)
|
||||
TRACE_WINDOWS("Widget received touch end (%d) x=%d;y=%d",
|
||||
hasFocus(), x, y);
|
||||
|
||||
if (fullscreen) {
|
||||
//TODO: forward to widget (lua for instance)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Window::onTouchEnd(x, y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hasFocus()) {
|
||||
|
||||
// TODO: find a better way
|
||||
if (touchState.tapCount == 0)
|
||||
onPress();
|
||||
else if (touchState.tapCount > 1)
|
||||
@@ -94,6 +88,7 @@ bool Widget::onTouchEnd(coord_t x, coord_t y)
|
||||
else {
|
||||
setFocus();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
Submodule radio/src/thirdparty/libopenui updated: af50430828...fef30535c6
Reference in New Issue
Block a user