ModalWindow layer added

This commit is contained in:
Bertrand Songis
2019-11-29 14:18:29 +01:00
parent 1311885c3b
commit 5de2d9c03e
3 changed files with 89 additions and 51 deletions
+1 -25
View File
@@ -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
+2 -26
View File
@@ -23,7 +23,7 @@
#include <vector>
#include <functional>
#include <utility>
#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();
+86
View File
@@ -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 <vector>
#include <functional>
#include <utility>
#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_