diff --git a/radio/src/thirdparty/libopenui/src/CMakeLists.txt b/radio/src/thirdparty/libopenui/src/CMakeLists.txt index f3b9ef290..082eb2f3f 100644 --- a/radio/src/thirdparty/libopenui/src/CMakeLists.txt +++ b/radio/src/thirdparty/libopenui/src/CMakeLists.txt @@ -30,6 +30,7 @@ set(LIBOPENUI_SRC coloredit.cpp progress.cpp table.cpp + modal_window.cpp dialog.cpp message_dialog.cpp ) diff --git a/radio/src/thirdparty/libopenui/src/dialog.cpp b/radio/src/thirdparty/libopenui/src/dialog.cpp index 751f7b285..46b863579 100644 --- a/radio/src/thirdparty/libopenui/src/dialog.cpp +++ b/radio/src/thirdparty/libopenui/src/dialog.cpp @@ -21,27 +21,11 @@ #include "mainwindow.h" Dialog::Dialog(std::string title, const rect_t & rect): - FormGroup(&mainWindow, rect, OPAQUE), - title(std::move(title)), - previousFocus(focusWindow) + ModalWindow(), + content(this, rect), + form(&content, {0, 0, rect.w, rect.h}, FORM_NO_BORDER) { bringToTop(); - setFocus(); -} - -void Dialog::paint(BitmapBuffer * dc) -{ - dc->drawRect(0, 0, width() - 1, height() - 1, 1, SOLID, DEFAULT_COLOR); - dc->drawSolidFilledRect(1, 1, width() - 3, PAGE_LINE_HEIGHT, FOCUS_BGCOLOR); - dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, title.c_str(), FOCUS_COLOR); - dc->drawSolidFilledRect(1, PAGE_LINE_HEIGHT + 1, width() - 3, height() - PAGE_LINE_HEIGHT - 3, DEFAULT_BGCOLOR); -} - -void Dialog::deleteLater() -{ - if (previousFocus) { - previousFocus->setFocus(); - } - - Window::deleteLater(); + content.setTitle(title); + form.setFocus(); } diff --git a/radio/src/thirdparty/libopenui/src/dialog.h b/radio/src/thirdparty/libopenui/src/dialog.h index 0827f21f5..7ab4f8a83 100644 --- a/radio/src/thirdparty/libopenui/src/dialog.h +++ b/radio/src/thirdparty/libopenui/src/dialog.h @@ -20,19 +20,22 @@ #ifndef _DIALOG_H_ #define _DIALOG_H_ +#include "modal_window.h" #include "form.h" -class Dialog: public FormGroup { +class Dialog: public ModalWindow { public: Dialog(std::string title, const rect_t & rect); - void paint(BitmapBuffer * dc) override; - - void deleteLater(); + ~Dialog() override + { + form.detach(); + content.detach(); + } protected: - std::string title; - Window * previousFocus; + ModalWindowContent content; + FormGroup form; }; -#endif // _CONFIRMATION_H_ +#endif // _DIALOG_H_ diff --git a/radio/src/thirdparty/libopenui/src/form.cpp b/radio/src/thirdparty/libopenui/src/form.cpp index ffdd5b744..91ccdf40b 100644 --- a/radio/src/thirdparty/libopenui/src/form.cpp +++ b/radio/src/thirdparty/libopenui/src/form.cpp @@ -69,7 +69,7 @@ void FormField::paint(BitmapBuffer * dc) else if (hasFocus()) { dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR); } - else if (!(windowFlags & BORDER_FOCUS_ONLY)) { + else if (!(windowFlags & FORM_BORDER_FOCUS_ONLY)) { dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR); } } @@ -155,11 +155,11 @@ void FormGroup::onEvent(event_t event) void FormGroup::paint(BitmapBuffer * dc) { - if (!(windowFlags & FORM_FORWARD_FOCUS)) { + if (!(windowFlags & (FORM_NO_BORDER | FORM_FORWARD_FOCUS))) { if (!editMode && hasFocus()) { dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR); } - else if (!(windowFlags & BORDER_FOCUS_ONLY)) { + else if (!(windowFlags & FORM_BORDER_FOCUS_ONLY)) { dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR); } } diff --git a/radio/src/thirdparty/libopenui/src/form.h b/radio/src/thirdparty/libopenui/src/form.h index 7afd60ba1..ec37a6d64 100644 --- a/radio/src/thirdparty/libopenui/src/form.h +++ b/radio/src/thirdparty/libopenui/src/form.h @@ -24,7 +24,9 @@ constexpr WindowFlags FORM_FORWARD_FOCUS = WINDOW_FLAGS_LAST << 1; constexpr WindowFlags FORM_DETACHED = WINDOW_FLAGS_LAST << 2; -constexpr WindowFlags FORM_FLAGS_LAST = FORM_DETACHED; +constexpr WindowFlags FORM_BORDER_FOCUS_ONLY = WINDOW_FLAGS_LAST << 3; +constexpr WindowFlags FORM_NO_BORDER = WINDOW_FLAGS_LAST << 4; +constexpr WindowFlags FORM_FLAGS_LAST = FORM_NO_BORDER; class FormField: public Window { public: diff --git a/radio/src/thirdparty/libopenui/src/gridlayout.h b/radio/src/thirdparty/libopenui/src/gridlayout.h index 9134b7c72..9d3b9111a 100644 --- a/radio/src/thirdparty/libopenui/src/gridlayout.h +++ b/radio/src/thirdparty/libopenui/src/gridlayout.h @@ -117,7 +117,7 @@ class FormGridLayout: public GridLayout { protected: coord_t labelWidth = PAGE_LABEL_WIDTH; coord_t lineMarginLeft = PAGE_PADDING; - coord_t lineMarginRight = 10; + coord_t lineMarginRight = PAGE_PADDING; }; #endif diff --git a/radio/src/thirdparty/libopenui/src/menu.cpp b/radio/src/thirdparty/libopenui/src/menu.cpp index a5629a1ed..84dc6412f 100644 --- a/radio/src/thirdparty/libopenui/src/menu.cpp +++ b/radio/src/thirdparty/libopenui/src/menu.cpp @@ -21,13 +21,6 @@ #include "font.h" #include "theme.h" -MenuWindow::MenuWindow(Menu * parent): - Window(parent, {(LCD_W - MENUS_WIDTH) / 2, (LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}, OPAQUE), - body(this, {0, 0, width(), height()}) -{ - body.setFocus(); -} - void MenuBody::select(int index) { selectedIndex = index; @@ -95,7 +88,14 @@ void MenuBody::paint(BitmapBuffer * dc) } } -void MenuWindow::paint(BitmapBuffer * dc) +MenuWindowContent::MenuWindowContent(Menu * parent): + ModalWindowContent(parent, {(LCD_W - MENUS_WIDTH) / 2, (LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}), + body(this, {0, 0, width(), height()}) +{ + body.setFocus(); +} + +void MenuWindowContent::paint(BitmapBuffer * dc) { // the background dc->clear(MENU_BGCOLOR); @@ -109,7 +109,7 @@ void MenuWindow::paint(BitmapBuffer * dc) Menu::Menu(): ModalWindow(), - menuWindow(createMenuWindow(this)) + content(createMenuWindow(this)) { } @@ -117,37 +117,37 @@ void Menu::updatePosition() { if (!toolbar) { // there is no navigation bar at the left, we may center the window on screen - auto headerHeight = menuWindow->title.empty() ? 0 : MENUS_HEADER_HEIGHT; - auto bodyHeight = limit(MENUS_MIN_HEIGHT, menuWindow->body.lines.size() * MENUS_LINE_HEIGHT - 1, MENUS_MAX_HEIGHT); - menuWindow->setTop((LCD_H - headerHeight - bodyHeight) / 2 + MENUS_OFFSET_TOP); - menuWindow->setHeight(headerHeight + bodyHeight); - menuWindow->body.setTop(headerHeight); - menuWindow->body.setHeight(bodyHeight); + auto headerHeight = content->title.empty() ? 0 : MENUS_HEADER_HEIGHT; + auto bodyHeight = limit(MENUS_MIN_HEIGHT, content->body.lines.size() * MENUS_LINE_HEIGHT - 1, MENUS_MAX_HEIGHT); + content->setTop((LCD_H - headerHeight - bodyHeight) / 2 + MENUS_OFFSET_TOP); + content->setHeight(headerHeight + bodyHeight); + content->body.setTop(headerHeight); + content->body.setHeight(bodyHeight); } - menuWindow->body.setInnerHeight(menuWindow->body.lines.size() * MENUS_LINE_HEIGHT - 1); + content->body.setInnerHeight(content->body.lines.size() * MENUS_LINE_HEIGHT - 1); } void Menu::setTitle(const std::string text) { - menuWindow->setTitle(text); + content->setTitle(text); updatePosition(); } void Menu::addLine(const std::string & text, std::function onPress) { - menuWindow->body.addLine(text, std::move(onPress)); + content->body.addLine(text, std::move(onPress)); updatePosition(); } void Menu::addCustomLine(std::function drawLine, std::function onPress) { - menuWindow->body.addCustomLine(drawLine, std::move(onPress)); + content->body.addCustomLine(drawLine, std::move(onPress)); updatePosition(); } void Menu::removeLines() { - menuWindow->body.removeLines(); + content->body.removeLines(); updatePosition(); } diff --git a/radio/src/thirdparty/libopenui/src/menu.h b/radio/src/thirdparty/libopenui/src/menu.h index 278d0bb69..b7cdac108 100644 --- a/radio/src/thirdparty/libopenui/src/menu.h +++ b/radio/src/thirdparty/libopenui/src/menu.h @@ -26,10 +26,10 @@ #include "modal_window.h" class Menu; -class MenuWindow; +class MenuWindowContent; class MenuBody: public Window { - friend class MenuWindow; + friend class MenuWindowContent; friend class Menu; class MenuLine { @@ -110,13 +110,13 @@ class MenuBody: public Window { std::function onCancel; }; -class MenuWindow: public Window { +class MenuWindowContent: public ModalWindowContent { friend class Menu; public: - explicit MenuWindow(Menu * parent); + explicit MenuWindowContent(Menu * parent); - ~MenuWindow() override + ~MenuWindowContent() override { body.detach(); } @@ -124,20 +124,14 @@ class MenuWindow: public Window { #if defined(DEBUG_WINDOWS) std::string getName() override { - return "MenuWindow"; + return "MenuWindow::"; } #endif - void setTitle(const std::string text) - { - title = std::move(text); - } - void paint(BitmapBuffer * dc) override; protected: MenuBody body; - std::string title; }; class Menu: public ModalWindow { @@ -146,7 +140,7 @@ class Menu: public ModalWindow { void setCancelHandler(std::function handler) { - menuWindow->body.setCancelHandler(handler); + content->body.setCancelHandler(handler); } #if defined(DEBUG_WINDOWS) @@ -159,9 +153,9 @@ class Menu: public ModalWindow { void setToolbar(Window * window) { toolbar = window; - menuWindow->setLeft(toolbar->right()); - menuWindow->setTop(toolbar->top()); - menuWindow->setHeight(toolbar->height()); + content->setLeft(toolbar->right()); + content->setTop(toolbar->top()); + content->setHeight(toolbar->height()); } void setTitle(const std::string text); @@ -174,7 +168,7 @@ class Menu: public ModalWindow { inline void select(int index) { - menuWindow->body.select(index); + content->body.select(index); } #if defined(HARDWARE_KEYS) @@ -182,7 +176,7 @@ class Menu: public ModalWindow { #endif protected: - MenuWindow * menuWindow; + MenuWindowContent * content; Window * toolbar = nullptr; void updatePosition(); }; diff --git a/radio/src/thirdparty/libopenui/src/modal_window.cpp b/radio/src/thirdparty/libopenui/src/modal_window.cpp new file mode 100644 index 000000000..09c54e210 --- /dev/null +++ b/radio/src/thirdparty/libopenui/src/modal_window.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + + +#include "modal_window.h" +#include "mainwindow.h" +#include "font.h" + +ModalWindow::ModalWindow(): + Window(&mainWindow, {0, 0, LCD_W, LCD_H}) +#if !defined(HARDWARE_TOUCH) + , previousFocus(focusWindow) +#endif +{ +} + +void ModalWindow::paint(BitmapBuffer * dc) +{ + dc->drawFilledRect(0, 0, width(), height(), SOLID, OVERLAY_COLOR | OPACITY(5)); +} + +void ModalWindowContent::paint(BitmapBuffer * dc) +{ + dc->drawSolidFilledRect(0, 0, width(), PAGE_LINE_HEIGHT, FOCUS_BGCOLOR); + dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, title.c_str(), FOCUS_COLOR); + dc->drawSolidFilledRect(0, PAGE_LINE_HEIGHT, width(), height() - PAGE_LINE_HEIGHT, DEFAULT_BGCOLOR); + +/* + // the background + dc->clear(MENU_BGCOLOR); + + // the title + if (!title.empty()) { + dc->drawText(MENUS_WIDTH / 2, (MENUS_HEADER_HEIGHT - getFontHeight(MENU_HEADER_FONT)) / 2, title.c_str(), CENTERED | MENU_HEADER_FONT); + dc->drawSolidHorizontalLine(0, MENUS_HEADER_HEIGHT - 1, MENUS_WIDTH, MENU_LINE_COLOR); + }*/ +} diff --git a/radio/src/thirdparty/libopenui/src/modal_window.h b/radio/src/thirdparty/libopenui/src/modal_window.h index b04d12aaf..9faa6143c 100644 --- a/radio/src/thirdparty/libopenui/src/modal_window.h +++ b/radio/src/thirdparty/libopenui/src/modal_window.h @@ -20,21 +20,12 @@ #ifndef _MODAL_WINDOW_H_ #define _MODAL_WINDOW_H_ -#include -#include -#include -#include "mainwindow.h" +#include "window.h" class ModalWindow: public Window { public: - ModalWindow(): - Window(&mainWindow, {0, 0, LCD_W, LCD_H}) -#if !defined(HARDWARE_TOUCH) - , previousFocus(focusWindow) -#endif - { - } + ModalWindow(); #if defined(DEBUG_WINDOWS) std::string getName() override @@ -53,10 +44,7 @@ class ModalWindow: public Window Window::deleteLater(); } - void paint(BitmapBuffer * dc) override - { - dc->drawFilledRect(0, 0, width(), height(), SOLID, OVERLAY_COLOR | OPACITY(5)); - } + void paint(BitmapBuffer * dc) override; #if defined(HARDWARE_TOUCH) bool onTouchStart(coord_t x, coord_t y) override @@ -80,7 +68,34 @@ class ModalWindow: public Window #endif protected: +#if !defined(HARDWARE_TOUCH) Window * previousFocus = nullptr; +#endif +}; + +class ModalWindowContent: public Window { + public: + explicit ModalWindowContent(ModalWindow * parent, const rect_t & rect): + Window(parent, rect, OPAQUE) + { + } + +#if defined(DEBUG_WINDOWS) + std::string getName() override + { + return "ModalWindowContent"; + } +#endif + + void setTitle(std::string text) + { + title = std::move(text); + } + + void paint(BitmapBuffer * dc) override; + + protected: + std::string title; }; #endif // _MODAL_WINDOW_H_ diff --git a/radio/src/thirdparty/libopenui/src/theme.h b/radio/src/thirdparty/libopenui/src/theme.h index c06d2b868..4dafc524c 100644 --- a/radio/src/thirdparty/libopenui/src/theme.h +++ b/radio/src/thirdparty/libopenui/src/theme.h @@ -24,7 +24,7 @@ #include "checkbox.h" class Menu; -class MenuWindow; +class MenuWindowContent; class ChoiceBase; enum IconState { @@ -52,6 +52,6 @@ class Theme { extern Theme * theme; -MenuWindow * createMenuWindow(Menu * menu); +MenuWindowContent * createMenuWindow(Menu * menu); #endif // _THEME_H_ diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index 9bf4b000b..b1b6e892f 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -38,14 +38,13 @@ typedef uint32_t WindowFlags; #undef TRANSPARENT #endif -constexpr WindowFlags OPAQUE = 1 << 0; -constexpr WindowFlags TRANSPARENT = 1 << 1; -constexpr WindowFlags NO_SCROLLBAR = 1 << 2; -constexpr WindowFlags NO_FOCUS = 1 << 3; -constexpr WindowFlags FORWARD_SCROLL = 1 << 4; -constexpr WindowFlags REFRESH_ALWAYS = 1 << 5; -constexpr WindowFlags BORDER_FOCUS_ONLY = 1 << 6; -constexpr WindowFlags PAINT_CHILDREN_FIRST = 1 << 7; +constexpr WindowFlags OPAQUE = 1u << 0; +constexpr WindowFlags TRANSPARENT = 1u << 1; +constexpr WindowFlags NO_SCROLLBAR = 1u << 2; +constexpr WindowFlags NO_FOCUS = 1u << 3; +constexpr WindowFlags FORWARD_SCROLL = 1u << 4; +constexpr WindowFlags REFRESH_ALWAYS = 1u << 5; +constexpr WindowFlags PAINT_CHILDREN_FIRST = 1u << 6; constexpr WindowFlags WINDOW_FLAGS_LAST = PAINT_CHILDREN_FIRST; enum SetFocusFlag {