Menu black overlay fix (need to give the pointer of the current window)
This commit is contained in:
+9
-14
@@ -17,7 +17,6 @@
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "bitmapbuffer.h"
|
||||
#include "libopenui_depends.h"
|
||||
#include "libopenui_globals.h"
|
||||
@@ -190,13 +189,11 @@ void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, ui
|
||||
if (x + w > xmax)
|
||||
w = xmax - x;
|
||||
|
||||
for (coord_t i=y; i<y+h; i++) {
|
||||
if ((att & ROUND) && (i==y || i==y+h-1))
|
||||
drawHorizontalLine(x+1, i, w-2, pat, att);
|
||||
else
|
||||
drawHorizontalLine(x, i, w, pat, att);
|
||||
for (coord_t i = y; i < y + h; i++) {
|
||||
drawHorizontalLine(x, i, w, pat, att);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//void BitmapBuffer::invertRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags att)
|
||||
//{
|
||||
@@ -309,9 +306,8 @@ void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, ui
|
||||
|
||||
void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, LcdFlags flags, coord_t offset, coord_t width)
|
||||
{
|
||||
if (mask == nullptr) {
|
||||
if (!mask)
|
||||
return;
|
||||
}
|
||||
|
||||
APPLY_OFFSET();
|
||||
|
||||
@@ -326,15 +322,14 @@ void BitmapBuffer::drawMask(coord_t x, coord_t y, const BitmapBuffer * mask, Lcd
|
||||
width = xmax - x;
|
||||
}
|
||||
|
||||
if (x < 0) {
|
||||
width += x;
|
||||
offset -= x;
|
||||
x = 0;
|
||||
if (x < xmin) {
|
||||
width += x - xmin;
|
||||
offset -= x + xmin;
|
||||
x = xmin;
|
||||
}
|
||||
|
||||
if (y >= ymax || x >= xmax || width <= 0 || x + width < xmin || y + height < ymin) {
|
||||
if (y >= ymax || x >= xmax || width <= 0 || x + width < xmin || y + height < ymin)
|
||||
return;
|
||||
}
|
||||
|
||||
pixel_t color = lcdColorTable[COLOR_IDX(flags)];
|
||||
|
||||
|
||||
+8
-8
@@ -390,12 +390,12 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
||||
template<class T>
|
||||
void drawBitmap(coord_t x, coord_t y, const T * bmp, coord_t srcx=0, coord_t srcy=0, coord_t w=0, coord_t h=0, float scale=0)
|
||||
{
|
||||
if (!data || !bmp)
|
||||
return;
|
||||
|
||||
APPLY_OFFSET();
|
||||
|
||||
if (x >= xmax) return;
|
||||
if (y >= ymax) return;
|
||||
|
||||
if (!data || !bmp)
|
||||
if (x >= xmax || y >= ymax)
|
||||
return;
|
||||
|
||||
coord_t srcw = bmp->width();
|
||||
@@ -411,14 +411,14 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
||||
h = srch - srcy;
|
||||
|
||||
if (x < xmin) {
|
||||
w += x-xmin;
|
||||
srcx -= x-xmin;
|
||||
w += x - xmin;
|
||||
srcx -= x - xmin;
|
||||
x = xmin;
|
||||
}
|
||||
|
||||
if (y < ymin) {
|
||||
h += y-ymin;
|
||||
srcy -= y-ymin;
|
||||
h += y - ymin;
|
||||
srcy -= y - ymin;
|
||||
y = ymin;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ void Choice::onEvent(event_t event)
|
||||
|
||||
void Choice::openMenu()
|
||||
{
|
||||
auto menu = new Menu();
|
||||
auto menu = new Menu(this);
|
||||
if (!menuTitle.empty())
|
||||
menu->setTitle(menuTitle);
|
||||
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ DialogWindowContent::DialogWindowContent(Dialog * parent, const rect_t & rect):
|
||||
}
|
||||
|
||||
|
||||
Dialog::Dialog(std::string title, const rect_t & rect):
|
||||
ModalWindow(),
|
||||
Dialog::Dialog(Window * parent, std::string title, const rect_t & rect):
|
||||
ModalWindow(parent),
|
||||
content(createDialogWindow(this, rect))
|
||||
{
|
||||
bringToTop();
|
||||
|
||||
+1
-8
@@ -49,14 +49,7 @@ class DialogWindowContent: public ModalWindowContent {
|
||||
|
||||
class Dialog: public ModalWindow {
|
||||
public:
|
||||
Dialog(std::string title, const rect_t & rect);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "Dialog";
|
||||
}
|
||||
#endif
|
||||
Dialog(Window * parent, std::string title, const rect_t & rect);
|
||||
|
||||
protected:
|
||||
DialogWindowContent * content;
|
||||
|
||||
+2
-2
@@ -87,7 +87,7 @@ bool FileChoice::openMenu()
|
||||
|
||||
files.push_front("");
|
||||
|
||||
auto menu = new Menu();
|
||||
auto menu = new Menu(this);
|
||||
int count = 0;
|
||||
int current = -1;
|
||||
std::string value = getValue();
|
||||
@@ -116,7 +116,7 @@ bool FileChoice::openMenu()
|
||||
}
|
||||
}
|
||||
|
||||
new MessageDialog(STR_SDCARD, STR_NO_FILES_ON_SD);
|
||||
new MessageDialog(this, STR_SDCARD, STR_NO_FILES_ON_SD);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,9 +38,6 @@
|
||||
#define PREC2 0x30
|
||||
#define MODE(flags) ((((int8_t)(flags) & 0x30) - 0x10) >> 4)
|
||||
|
||||
/* rect, square flags */
|
||||
#define ROUND 0x04
|
||||
|
||||
/* telemetry flags */
|
||||
#define NO_UNIT 0x40
|
||||
|
||||
|
||||
+4
-4
@@ -108,8 +108,8 @@ void MenuWindowContent::paint(BitmapBuffer * dc)
|
||||
}
|
||||
}
|
||||
|
||||
Menu::Menu():
|
||||
ModalWindow(),
|
||||
Menu::Menu(Window * parent):
|
||||
ModalWindow(parent),
|
||||
content(createMenuWindow(this))
|
||||
{
|
||||
}
|
||||
@@ -128,9 +128,9 @@ void Menu::updatePosition()
|
||||
content->body.setInnerHeight(content->body.lines.size() * MENUS_LINE_HEIGHT - 1);
|
||||
}
|
||||
|
||||
void Menu::setTitle(const std::string text)
|
||||
void Menu::setTitle(std::string text)
|
||||
{
|
||||
content->setTitle(text);
|
||||
content->setTitle(std::move(text));
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
|
||||
+2
-9
@@ -136,20 +136,13 @@ class MenuWindowContent: public ModalWindowContent {
|
||||
|
||||
class Menu: public ModalWindow {
|
||||
public:
|
||||
Menu();
|
||||
explicit Menu(Window * parent);
|
||||
|
||||
void setCancelHandler(std::function<void()> handler)
|
||||
{
|
||||
content->body.setCancelHandler(handler);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "Menu";
|
||||
}
|
||||
#endif
|
||||
|
||||
void setToolbar(Window * window)
|
||||
{
|
||||
toolbar = window;
|
||||
@@ -158,7 +151,7 @@ class Menu: public ModalWindow {
|
||||
content->setHeight(toolbar->height());
|
||||
}
|
||||
|
||||
void setTitle(const std::string text);
|
||||
void setTitle(std::string text);
|
||||
|
||||
void addLine(const std::string & text, std::function<void()> onPress);
|
||||
|
||||
|
||||
+2
-2
@@ -138,7 +138,7 @@ class MenuToolbar: public FormGroup {
|
||||
std::list<Window *>::iterator current = children.end();
|
||||
T * choice;
|
||||
Menu * menu;
|
||||
coord_t y = 0; // TODO NV14 was 5;
|
||||
coord_t y = 0;
|
||||
|
||||
void addButton(char picto, int16_t filtermin, int16_t filtermax)
|
||||
{
|
||||
@@ -164,7 +164,7 @@ class MenuToolbar: public FormGroup {
|
||||
return 1;
|
||||
});
|
||||
|
||||
y += 30;
|
||||
y += MENUS_TOOLBAR_BUTTON_WIDTH;
|
||||
|
||||
setInnerHeight(y);
|
||||
}
|
||||
|
||||
+2
-13
@@ -19,11 +19,10 @@
|
||||
|
||||
|
||||
#include "modal_window.h"
|
||||
#include "mainwindow.h"
|
||||
#include "font.h"
|
||||
|
||||
ModalWindow::ModalWindow():
|
||||
Window(&mainWindow, {0, 0, LCD_W, LCD_H})
|
||||
ModalWindow::ModalWindow(Window * parent):
|
||||
Window(parent->getFullScreenWindow(), {0, 0, LCD_W, LCD_H})
|
||||
#if !defined(HARDWARE_TOUCH)
|
||||
, previousFocus(focusWindow)
|
||||
#endif
|
||||
@@ -40,14 +39,4 @@ void ModalWindowContent::paint(BitmapBuffer * dc)
|
||||
dc->drawSolidFilledRect(0, 0, width(), POPUP_HEADER_HEIGHT, FOCUS_BGCOLOR);
|
||||
dc->drawText(FIELD_PADDING_LEFT, (POPUP_HEADER_HEIGHT - getFontHeight(FONT(STD))) / 2, title.c_str(), FOCUS_COLOR);
|
||||
dc->drawSolidFilledRect(0, POPUP_HEADER_HEIGHT, width(), height() - POPUP_HEADER_HEIGHT, DEFAULT_BGCOLOR);
|
||||
|
||||
/*
|
||||
// the background
|
||||
dc->clear(MENU_BGCOLOR);
|
||||
|
||||
// the title
|
||||
if (!title.empty()) {
|
||||
dc->drawText(MENUS_WIDTH / 2, (POPUP_HEADER_HEIGHT - getFontHeight(MENU_HEADER_FONT)) / 2, title.c_str(), CENTERED | MENU_HEADER_FONT);
|
||||
dc->drawSolidHorizontalLine(0, POPUP_HEADER_HEIGHT - 1, MENUS_WIDTH, MENU_LINE_COLOR);
|
||||
}*/
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
class ModalWindow: public Window
|
||||
{
|
||||
public:
|
||||
ModalWindow();
|
||||
explicit ModalWindow(Window * parent);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
|
||||
+2
-2
@@ -121,7 +121,7 @@ class Table: public Window {
|
||||
body.invalidate();
|
||||
}
|
||||
|
||||
void setHeader(const char * values[])
|
||||
void setHeader(const char * const values[])
|
||||
{
|
||||
Line line;
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
@@ -130,7 +130,7 @@ class Table: public Window {
|
||||
header.setLine(line);
|
||||
}
|
||||
|
||||
void addLine(const char * values[], std::function<void()> onPress = nullptr)
|
||||
void addLine(const char * const values[], std::function<void()> onPress = nullptr)
|
||||
{
|
||||
Line line;
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
|
||||
+3
-3
@@ -33,10 +33,10 @@ void TextEdit::paint(BitmapBuffer * dc)
|
||||
dc->drawSizedText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, length, FOCUS_COLOR);
|
||||
coord_t left = (cursorPos == 0 ? 0 : getTextWidth(value, cursorPos));
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
dc->drawSolidFilledRect(left + 2, FIELD_PADDING_TOP + 1, 2, 20, FOCUS_COLOR);
|
||||
dc->drawSolidFilledRect(left + 2, 2, 2, height() - 4, FOCUS_COLOR);
|
||||
#else
|
||||
char s[] = { value[cursorPos], '\0' };
|
||||
dc->drawSolidFilledRect(FIELD_PADDING_LEFT + left - 1, FIELD_PADDING_TOP + 1, getTextWidth(s, 1) + 1, height() - 2, FOCUS_COLOR);
|
||||
dc->drawSolidFilledRect(FIELD_PADDING_LEFT + left - 1, FIELD_PADDING_TOP - 1, getTextWidth(s, 1) + 1, height() - 2, FOCUS_COLOR);
|
||||
dc->drawText(FIELD_PADDING_LEFT + left, FIELD_PADDING_TOP, s, DEFAULT_COLOR);
|
||||
#endif
|
||||
}
|
||||
@@ -193,7 +193,7 @@ bool TextEdit::onTouchEnd(coord_t x, coord_t y)
|
||||
char c = value[cursorPos];
|
||||
if (c == '\0')
|
||||
break;
|
||||
uint8_t w = getCharWidth(c, fontspecsTable[0]);
|
||||
uint8_t w = getCharWidth(c, fontspecsTable[0]) + 1;
|
||||
if (rest < w)
|
||||
break;
|
||||
rest -= w;
|
||||
|
||||
+20
-14
@@ -187,26 +187,41 @@ void Window::scrollTo(Window * child)
|
||||
|
||||
void Window::fullPaint(BitmapBuffer * dc)
|
||||
{
|
||||
TRACE_WINDOWS("%s", getWindowDebugString().c_str());
|
||||
bool paintNeeded = true;
|
||||
|
||||
auto firstChild = children.end();
|
||||
while (firstChild != children.begin()) {
|
||||
auto child = *(--firstChild);
|
||||
if ((child->windowFlags & OPAQUE) && isChildFullSize(child)) {
|
||||
paintNeeded = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (windowFlags & PAINT_CHILDREN_FIRST) {
|
||||
coord_t xmin, xmax, ymin, ymax;
|
||||
coord_t x = dc->getOffsetX();
|
||||
coord_t y = dc->getOffsetY();
|
||||
dc->getClippingRect(xmin, xmax, ymin, ymax);
|
||||
paintChildren(dc);
|
||||
paintChildren(dc, firstChild);
|
||||
dc->setOffset(x, y);
|
||||
dc->setClippingRect(xmin, xmax, ymin, ymax);
|
||||
}
|
||||
|
||||
paint(dc);
|
||||
if (paintNeeded) {
|
||||
TRACE_WINDOWS("%s", getWindowDebugString().c_str());
|
||||
paint(dc);
|
||||
}
|
||||
else {
|
||||
TRACE_WINDOWS("%s (skipped)", getWindowDebugString().c_str());
|
||||
}
|
||||
|
||||
if (!(windowFlags & NO_SCROLLBAR)) {
|
||||
drawVerticalScrollbar(dc);
|
||||
}
|
||||
|
||||
if (!(windowFlags & PAINT_CHILDREN_FIRST)) {
|
||||
paintChildren(dc);
|
||||
paintChildren(dc, firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,22 +244,13 @@ bool Window::isChildVisible(Window * window)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Window::paintChildren(BitmapBuffer * dc)
|
||||
void Window::paintChildren(BitmapBuffer * dc, std::list<Window *>::iterator it)
|
||||
{
|
||||
coord_t x = dc->getOffsetX();
|
||||
coord_t y = dc->getOffsetY();
|
||||
coord_t xmin, xmax, ymin, ymax;
|
||||
dc->getClippingRect(xmin, xmax, ymin, ymax);
|
||||
|
||||
auto it = children.end();
|
||||
|
||||
while(it != children.begin()) {
|
||||
auto child = *(--it);
|
||||
if ((child->windowFlags & OPAQUE) && isChildFullSize(child)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (; it != children.end(); it++) {
|
||||
auto child = *it;
|
||||
|
||||
|
||||
+27
-22
@@ -97,6 +97,11 @@ class Window {
|
||||
return parent;
|
||||
}
|
||||
|
||||
Window * getFullScreenWindow()
|
||||
{
|
||||
return (width() == LCD_W && height() == LCD_H) ? this : parent->getFullScreenWindow();
|
||||
}
|
||||
|
||||
WindowFlags getWindowFlags() const
|
||||
{
|
||||
return windowFlags;
|
||||
@@ -287,37 +292,15 @@ class Window {
|
||||
return parent && parent->isChildVisible(this);
|
||||
}
|
||||
|
||||
virtual void paint(BitmapBuffer * dc)
|
||||
{
|
||||
}
|
||||
|
||||
void drawVerticalScrollbar(BitmapBuffer * dc);
|
||||
|
||||
void paintChildren(BitmapBuffer * dc);
|
||||
|
||||
void fullPaint(BitmapBuffer * dc);
|
||||
|
||||
static bool pointInRect(coord_t x, coord_t y, rect_t & rect)
|
||||
{
|
||||
return (x >= rect.x && x < rect.x + rect.w && y >= rect.y && y < rect.y + rect.h);
|
||||
}
|
||||
|
||||
virtual void onFocusLost()
|
||||
{
|
||||
TRACE_WINDOWS("%s onFocusLost()", getWindowDebugString().c_str());
|
||||
invalidate();
|
||||
};
|
||||
|
||||
virtual void onEvent(event_t event);
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
virtual bool onTouchStart(coord_t x, coord_t y);
|
||||
|
||||
virtual bool onTouchEnd(coord_t x, coord_t y);
|
||||
|
||||
virtual bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY);
|
||||
#endif
|
||||
|
||||
void adjustInnerHeight();
|
||||
|
||||
coord_t adjustHeight();
|
||||
@@ -371,6 +354,28 @@ class Window {
|
||||
}
|
||||
|
||||
virtual void invalidate(const rect_t & rect);
|
||||
|
||||
void paintChildren(BitmapBuffer * dc, std::list<Window *>::iterator it);
|
||||
|
||||
void fullPaint(BitmapBuffer * dc);
|
||||
|
||||
virtual void paint(BitmapBuffer * dc)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void onFocusLost()
|
||||
{
|
||||
TRACE_WINDOWS("%s onFocusLost()", getWindowDebugString().c_str());
|
||||
invalidate();
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
virtual bool onTouchStart(coord_t x, coord_t y);
|
||||
|
||||
virtual bool onTouchEnd(coord_t x, coord_t y);
|
||||
|
||||
virtual bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _WINDOW_H_
|
||||
|
||||
Reference in New Issue
Block a user