From 7c63b86cfef10c2eff0af02092593f2ef6526b09 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 24 Apr 2022 14:03:39 +0200 Subject: [PATCH] split SetupWidgetsPage --- radio/src/gui/colorlcd/CMakeLists.txt | 1 + radio/src/gui/colorlcd/screen_setup.cpp | 145 +-------------------- radio/src/gui/colorlcd/screen_setup.h | 8 -- radio/src/gui/colorlcd/topbar.cpp | 3 +- radio/src/gui/colorlcd/widgets_setup.cpp | 157 +++++++++++++++++++++++ radio/src/gui/colorlcd/widgets_setup.h | 67 ++++++++++ radio/src/telemetry/telemetry.h | 1 + 7 files changed, 229 insertions(+), 153 deletions(-) create mode 100644 radio/src/gui/colorlcd/widgets_setup.cpp create mode 100644 radio/src/gui/colorlcd/widgets_setup.h diff --git a/radio/src/gui/colorlcd/CMakeLists.txt b/radio/src/gui/colorlcd/CMakeLists.txt index e1426717d..41e3088cb 100644 --- a/radio/src/gui/colorlcd/CMakeLists.txt +++ b/radio/src/gui/colorlcd/CMakeLists.txt @@ -87,6 +87,7 @@ set(GUI_SRC view_text.cpp menu_screen.cpp screen_user_interface.cpp + widgets_setup.cpp screen_setup.cpp switch_warn_dialog.cpp LvglWrapper.cpp diff --git a/radio/src/gui/colorlcd/screen_setup.cpp b/radio/src/gui/colorlcd/screen_setup.cpp index cde9a556f..b7bf8cccd 100644 --- a/radio/src/gui/colorlcd/screen_setup.cpp +++ b/radio/src/gui/colorlcd/screen_setup.cpp @@ -26,12 +26,12 @@ #include "topbar.h" #include "libopenui.h" #include "layouts/layout_factory_impl.h" +#include "widgets_setup.h" #define SET_DIRTY() storageDirty(EE_MODEL) #define BUTTON_HEIGHT 30 #define BUTTON_WIDTH 75 - class LayoutChoice: public FormField { public: @@ -109,149 +109,6 @@ class LayoutChoice: public FormField std::function setValue; }; -SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainer* container, uint8_t slotIndex): - Button(parent, rect) -{ - setPressHandler([parent, container, slotIndex]() -> uint8_t { - - Menu * menu = new Menu(parent); - menu->addLine(TR_SELECT_WIDGET, [=]() { - Menu * menu = new Menu(parent); - for (auto factory: getRegisteredWidgets()) { - menu->addLine(factory->getDisplayName(), [=]() { - container->createWidget(slotIndex, factory); - auto widget = container->getWidget(slotIndex); - if(widget->getOptions() && widget->getOptions()->name) - new WidgetSettings(parent, widget); - }); - } - }); - - if (container->getWidget(slotIndex)) { - auto widget = container->getWidget(slotIndex); - if(widget->getOptions() && widget->getOptions()->name) - menu->addLine(TR_WIDGET_SETTINGS, [=]() { - new WidgetSettings(parent, widget); - }); - menu->addLine(STR_REMOVE_WIDGET, [=]() { - container->removeWidget(slotIndex); - }); - } - - return 0; - }); -} - -void SetupWidgetsPageSlot::paint(BitmapBuffer * dc) -{ - if (hasFocus()) { - dc->drawRect(0, 0, width()-1, height()-1, 2, STASHED, COLOR_THEME_FOCUS); - } - else { - dc->drawSolidRect(0, 0, width()-1, height()-1, 2, COLOR_THEME_PRIMARY3); - } -} - -class SetupWidgetsPage: public FormWindow -{ - public: - SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx): - FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS), - menu(menu), - customScreenIdx(customScreenIdx) - { - Layer::push(this); - - // attach this custom screen here so we can display it - auto screen = customScreens[customScreenIdx]; - if (screen) { - setRect(screen->getRect()); - auto viewMain = ViewMain::instance(); - savedView = viewMain->getCurrentMainView(); - viewMain->setCurrentMainView(customScreenIdx); - viewMain->bringToTop(); - } - - for (unsigned i = 0; i < screen->getZonesCount(); i++) { - auto rect = screen->getZone(i); - auto widget = new SetupWidgetsPageSlot(this, rect, customScreens[customScreenIdx], i); - if (i == 0) widget->setFocus(); - } - -#if defined(HARDWARE_TOUCH) - new Button( - this, {0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT}, - [this]() -> uint8_t { - this->deleteLater(); - return 1; - }, - NO_FOCUS | FORM_NO_BORDER); -#endif - } - -#if defined(DEBUG_WINDOWS) - std::string getName() const override - { - return "SetupWidgetsPage(idx=" + std::to_string(customScreenIdx) + ")"; - } -#endif - - void deleteLater(bool detach = true, bool trash = true) override - { -#if defined(HARDWARE_TOUCH) - Keyboard::hide(); -#endif - auto screen = customScreens[customScreenIdx]; - if (screen) { - auto viewMain = ViewMain::instance(); - viewMain->setCurrentMainView(savedView); - } - FormWindow::deleteLater(detach, trash); - - // restore screen setting tab on top - menu->bringToTop(); - Layer::pop(this); - } - -#if defined(HARDWARE_TOUCH) - bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, - coord_t slideX, coord_t slideY) override - { - FormWindow::onTouchSlide(x, y, startX, startY, slideX, slideY); - return true; - } - - bool onTouchEnd(coord_t x, coord_t y) override - { - FormWindow::onTouchEnd(x, y); - return true; - } -#endif - -#if defined(HARDWARE_KEYS) - void onEvent(event_t event) override - { - TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); - - if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) { - killEvents(event); - deleteLater(); - } - } -#endif - - protected: - ScreenMenu* menu; - uint8_t customScreenIdx; - unsigned savedView = 0; - - // void paint(BitmapBuffer * dc) override - // { - // //ViewMain::instance()->fullPaint(dc); - // //dc->clear(COLOR_THEME_SECONDARY3); - // } -}; - ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex): PageTab(), menu(menu), diff --git a/radio/src/gui/colorlcd/screen_setup.h b/radio/src/gui/colorlcd/screen_setup.h index 7aec7e8c2..18b08763d 100644 --- a/radio/src/gui/colorlcd/screen_setup.h +++ b/radio/src/gui/colorlcd/screen_setup.h @@ -47,11 +47,3 @@ class ScreenSetupPage: public PageTab { unsigned pageIndex; unsigned customScreenIndex; }; - -class SetupWidgetsPageSlot: public Button -{ - public: - SetupWidgetsPageSlot(FormGroup * parent, const rect_t & rect, WidgetsContainer* container, uint8_t slotIndex); - - void paint(BitmapBuffer * dc) override; -}; diff --git a/radio/src/gui/colorlcd/topbar.cpp b/radio/src/gui/colorlcd/topbar.cpp index 63497bc53..3b90bbd87 100644 --- a/radio/src/gui/colorlcd/topbar.cpp +++ b/radio/src/gui/colorlcd/topbar.cpp @@ -22,10 +22,11 @@ #include "opentx.h" #include "layer.h" #include "view_main.h" -#include "screen_setup.h" #include "storage/storage.h" #include "topbar.h" #include "topbar_impl.h" +#include "menu_screen.h" +#include "widgets_setup.h" Topbar * TopbarFactory::create(Window * parent) diff --git a/radio/src/gui/colorlcd/widgets_setup.cpp b/radio/src/gui/colorlcd/widgets_setup.cpp new file mode 100644 index 000000000..b21e9d2a1 --- /dev/null +++ b/radio/src/gui/colorlcd/widgets_setup.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "widgets_setup.h" +#include "menu_screen.h" +#include "view_main.h" +#include "widget_settings.h" +#include "widget.h" + +#include "layer.h" +#include "menu.h" + +#include "gui.h" +#include "translations.h" + +SetupWidgetsPageSlot::SetupWidgetsPageSlot(FormGroup* parent, + const rect_t& rect, + WidgetsContainer* container, + uint8_t slotIndex) : + Button(parent, rect) +{ + setPressHandler([parent, container, slotIndex]() -> uint8_t { + Menu* menu = new Menu(parent); + menu->addLine(STR_SELECT_WIDGET, [=]() { + Menu* menu = new Menu(parent); + for (auto factory : getRegisteredWidgets()) { + menu->addLine(factory->getDisplayName(), [=]() { + container->createWidget(slotIndex, factory); + auto widget = container->getWidget(slotIndex); + if (widget->getOptions() && widget->getOptions()->name) + new WidgetSettings(parent, widget); + }); + } + }); + + if (container->getWidget(slotIndex)) { + auto widget = container->getWidget(slotIndex); + if (widget->getOptions() && widget->getOptions()->name) + menu->addLine(STR_WIDGET_SETTINGS, + [=]() { new WidgetSettings(parent, widget); }); + menu->addLine(STR_REMOVE_WIDGET, + [=]() { container->removeWidget(slotIndex); }); + } + + return 0; + }); +} + +void SetupWidgetsPageSlot::paint(BitmapBuffer* dc) +{ + if (hasFocus()) { + dc->drawRect(0, 0, width() - 1, height() - 1, 2, STASHED, + COLOR_THEME_FOCUS); + } else { + dc->drawSolidRect(0, 0, width() - 1, height() - 1, 2, COLOR_THEME_PRIMARY3); + } +} + +SetupWidgetsPage::SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx) : + FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS), + menu(menu), + customScreenIdx(customScreenIdx) +{ + Layer::push(this); + + // attach this custom screen here so we can display it + auto screen = customScreens[customScreenIdx]; + if (screen) { + setRect(screen->getRect()); + auto viewMain = ViewMain::instance(); + savedView = viewMain->getCurrentMainView(); + viewMain->setCurrentMainView(customScreenIdx); + viewMain->bringToTop(); + } + + for (unsigned i = 0; i < screen->getZonesCount(); i++) { + auto rect = screen->getZone(i); + auto widget = + new SetupWidgetsPageSlot(this, rect, customScreens[customScreenIdx], i); + if (i == 0) widget->setFocus(); + } + +#if defined(HARDWARE_TOUCH) + new Button( + this, + {0, 0, MENU_HEADER_BACK_BUTTON_WIDTH, MENU_HEADER_BACK_BUTTON_HEIGHT}, + [this]() -> uint8_t { + this->deleteLater(); + return 1; + }, + NO_FOCUS | FORM_NO_BORDER); +#endif +} + +void SetupWidgetsPage::deleteLater(bool detach, bool trash) +{ +#if defined(HARDWARE_TOUCH) + Keyboard::hide(); +#endif + auto screen = customScreens[customScreenIdx]; + if (screen) { + auto viewMain = ViewMain::instance(); + viewMain->setCurrentMainView(savedView); + } + FormWindow::deleteLater(detach, trash); + + // restore screen setting tab on top + menu->bringToTop(); + Layer::pop(this); +} + +#if defined(HARDWARE_TOUCH) +bool SetupWidgetsPage::onTouchSlide(coord_t x, coord_t y, coord_t startX, + coord_t startY, coord_t slideX, + coord_t slideY) +{ + FormWindow::onTouchSlide(x, y, startX, startY, slideX, slideY); + return true; +} + +bool SetupWidgetsPage::onTouchEnd(coord_t x, coord_t y) +{ + FormWindow::onTouchEnd(x, y); + return true; +} +#endif + +#if defined(HARDWARE_KEYS) +void SetupWidgetsPage::onEvent(event_t event) +{ + TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), + event); + + if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) { + killEvents(event); + deleteLater(); + } +} +#endif diff --git a/radio/src/gui/colorlcd/widgets_setup.h b/radio/src/gui/colorlcd/widgets_setup.h new file mode 100644 index 000000000..a958518e7 --- /dev/null +++ b/radio/src/gui/colorlcd/widgets_setup.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include "form.h" +#include "button.h" + +class ScreenMenu; +class WidgetsContainer; + +class SetupWidgetsPage : public FormWindow +{ + public: + SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx); + +#if defined(DEBUG_WINDOWS) + std::string getName() const override + { + return "SetupWidgetsPage(idx=" + std::to_string(customScreenIdx) + ")"; + } +#endif + + void deleteLater(bool detach = true, bool trash = true) override; + +#if defined(HARDWARE_TOUCH) + bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, + coord_t slideX, coord_t slideY) override; + bool onTouchEnd(coord_t x, coord_t y) override; +#endif + +#if defined(HARDWARE_KEYS) + void onEvent(event_t event) override; +#endif + + protected: + ScreenMenu* menu; + uint8_t customScreenIdx; + unsigned savedView = 0; +}; + +class SetupWidgetsPageSlot : public Button +{ + public: + SetupWidgetsPageSlot(FormGroup* parent, const rect_t& rect, + WidgetsContainer* container, uint8_t slotIndex); + + void paint(BitmapBuffer* dc) override; +}; diff --git a/radio/src/telemetry/telemetry.h b/radio/src/telemetry/telemetry.h index cdbc27cd3..5de3a658a 100644 --- a/radio/src/telemetry/telemetry.h +++ b/radio/src/telemetry/telemetry.h @@ -22,6 +22,7 @@ #ifndef _TELEMETRY_H_ #define _TELEMETRY_H_ +#include "dataconstants.h" #include "frsky.h" #include "io/frsky_sport.h" #include "crossfire.h"