diff --git a/radio/src/thirdparty/libopenui/src/menu.cpp b/radio/src/thirdparty/libopenui/src/menu.cpp index ca8c91553..a5629a1ed 100644 --- a/radio/src/thirdparty/libopenui/src/menu.cpp +++ b/radio/src/thirdparty/libopenui/src/menu.cpp @@ -108,10 +108,7 @@ void MenuWindow::paint(BitmapBuffer * dc) } Menu::Menu(): - Window(&mainWindow, {0, 0, LCD_W, LCD_H}), -#if !defined(HARDWARE_TOUCH) - previousFocus(focusWindow), -#endif + ModalWindow(), menuWindow(createMenuWindow(this)) { } @@ -154,11 +151,6 @@ void Menu::removeLines() updatePosition(); } -void Menu::paint(BitmapBuffer * dc) -{ - dc->drawFilledRect(0, 0, width(), height(), SOLID, OVERLAY_COLOR | OPACITY(5)); -} - #if defined(HARDWARE_KEYS) void Menu::onEvent(event_t event) { @@ -170,19 +162,3 @@ void Menu::onEvent(event_t event) } } #endif - -#if defined(HARDWARE_TOUCH) -bool Menu::onTouchEnd(coord_t x, coord_t y) -{ - if (!Window::onTouchEnd(x, y)) { - deleteLater(); - } - return true; -} - -bool Menu::onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) -{ - Window::onTouchSlide(x, y, startX, startY, slideX, slideY); - return true; -} -#endif diff --git a/radio/src/thirdparty/libopenui/src/menu.h b/radio/src/thirdparty/libopenui/src/menu.h index 0affe1363..278d0bb69 100644 --- a/radio/src/thirdparty/libopenui/src/menu.h +++ b/radio/src/thirdparty/libopenui/src/menu.h @@ -23,7 +23,7 @@ #include #include #include -#include "mainwindow.h" +#include "modal_window.h" class Menu; class MenuWindow; @@ -140,7 +140,7 @@ class MenuWindow: public Window { std::string title; }; -class Menu: public Window { +class Menu: public ModalWindow { public: Menu(); @@ -149,16 +149,6 @@ class Menu: public Window { menuWindow->body.setCancelHandler(handler); } - void deleteLater() - { -#if !defined(HARDWARE_TOUCH) - if (previousFocus) { - previousFocus->setFocus(); - } -#endif - Window::deleteLater(); - } - #if defined(DEBUG_WINDOWS) std::string getName() override { @@ -187,25 +177,11 @@ class Menu: public Window { menuWindow->body.select(index); } - void paint(BitmapBuffer * dc) override; - #if defined(HARDWARE_KEYS) void onEvent(event_t event) override; #endif -#if defined(HARDWARE_TOUCH) - bool onTouchStart(coord_t x, coord_t y) override - { - return true; - } - - bool onTouchEnd(coord_t x, coord_t y) override; - - bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) override; -#endif - protected: - Window * previousFocus = nullptr; MenuWindow * menuWindow; Window * toolbar = nullptr; void updatePosition(); diff --git a/radio/src/thirdparty/libopenui/src/modal_window.h b/radio/src/thirdparty/libopenui/src/modal_window.h new file mode 100644 index 000000000..b04d12aaf --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/modal_window.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) OpenTX + * + * Source: + * https://github.com/opentx/libopenui + * + * This file is a part of libopenui library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + */ + +#ifndef _MODAL_WINDOW_H_ +#define _MODAL_WINDOW_H_ + +#include +#include +#include +#include "mainwindow.h" + +class ModalWindow: public Window +{ + public: + ModalWindow(): + Window(&mainWindow, {0, 0, LCD_W, LCD_H}) +#if !defined(HARDWARE_TOUCH) + , previousFocus(focusWindow) +#endif + { + } + +#if defined(DEBUG_WINDOWS) + std::string getName() override + { + return "ModalWindow"; + } +#endif + + void deleteLater() + { +#if !defined(HARDWARE_TOUCH) + if (previousFocus) { + previousFocus->setFocus(); + } +#endif + Window::deleteLater(); + } + + void paint(BitmapBuffer * dc) override + { + dc->drawFilledRect(0, 0, width(), height(), SOLID, OVERLAY_COLOR | OPACITY(5)); + } + +#if defined(HARDWARE_TOUCH) + bool onTouchStart(coord_t x, coord_t y) override + { + return true; + } + + bool onTouchEnd(coord_t x, coord_t y) + { + if (!Window::onTouchEnd(x, y)) { + deleteLater(); + } + return true; + } + + bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY) + { + Window::onTouchSlide(x, y, startX, startY, slideX, slideY); + return true; + } +#endif + + protected: + Window * previousFocus = nullptr; +}; + +#endif // _MODAL_WINDOW_H_