Optimization

This commit is contained in:
Bertrand Songis
2020-09-25 17:16:38 +02:00
parent 7c5aa513e5
commit ce74048a51
5 changed files with 24 additions and 13 deletions
+2
View File
@@ -95,6 +95,8 @@ bool MenuBody::onTouchEnd(coord_t /*x*/, coord_t y)
void MenuBody::paint(BitmapBuffer * dc) void MenuBody::paint(BitmapBuffer * dc)
{ {
dc->clear(MENU_BGCOLOR);
for (unsigned i = 0; i < lines.size(); i++) { for (unsigned i = 0; i < lines.size(); i++) {
auto & line = lines[i]; auto & line = lines[i];
LcdFlags flags = MENU_COLOR | MENU_FONT; LcdFlags flags = MENU_COLOR | MENU_FONT;
+6 -3
View File
@@ -85,12 +85,14 @@ void TextEdit::onEvent(event_t event)
value[length - 1] = '\0'; value[length - 1] = '\0';
--cursorPos; --cursorPos;
invalidate(); invalidate();
changed = true;
} }
} }
else if (cursorPos < length) { else if (cursorPos < length) {
memmove(value + cursorPos + 1, value + cursorPos, length - cursorPos - 1); memmove(value + cursorPos + 1, value + cursorPos, length - cursorPos - 1);
value[cursorPos++] = c; value[cursorPos++] = c;
invalidate(); invalidate();
changed = true;
} }
} }
#endif #endif
@@ -130,8 +132,10 @@ void TextEdit::onEvent(event_t event)
case EVT_KEY_BREAK(KEY_ENTER): case EVT_KEY_BREAK(KEY_ENTER):
if (cursorPos < length - 1) { if (cursorPos < length - 1) {
cursorPos++; cursorPos++;
if (value[cursorPos] == '\0') if (value[cursorPos] == '\0') {
value[cursorPos] = ' '; value[cursorPos] = ' ';
changed = true;
}
invalidate(); invalidate();
} }
else { else {
@@ -171,7 +175,7 @@ void TextEdit::onEvent(event_t event)
// TRACE("value[%d] = %d", cursorPos, v); // TRACE("value[%d] = %d", cursorPos, v);
value[cursorPos] = v; value[cursorPos] = v;
invalidate(); invalidate();
// TODO storageDirty(...); changed = true;
} }
} }
else { else {
@@ -216,6 +220,5 @@ void TextEdit::onFocusLost()
changeEnd(); changeEnd();
// TODO storageDirty(...);
FormField::onFocusLost(); FormField::onFocusLost();
} }
+7 -3
View File
@@ -67,6 +67,7 @@ class TextEdit : public FormField {
protected: protected:
char * value; char * value;
bool changed = false;
uint8_t length; uint8_t length;
uint8_t cursorPos = 0; uint8_t cursorPos = 0;
std::function<void()> changeHandler = nullptr; std::function<void()> changeHandler = nullptr;
@@ -76,9 +77,12 @@ class TextEdit : public FormField {
void changeEnd() void changeEnd()
{ {
cursorPos = 0; cursorPos = 0;
trim(); if (changed) {
if (changeHandler) changed = false;
changeHandler(); trim();
if (changeHandler)
changeHandler();
}
} }
static uint8_t getNextChar(uint8_t c) static uint8_t getNextChar(uint8_t c)
+8 -6
View File
@@ -205,17 +205,18 @@ void Window::scrollTo(const rect_t & rect)
} }
} }
bool Window::hasOpaqueRect(const rect_t & rect) const bool Window::hasOpaqueRect(const rect_t & testRect) const
{ {
if (!this->rect.contains(rect)) if (!rect.contains(testRect))
return false; return false;
if (windowFlags & OPAQUE) { if (windowFlags & OPAQUE) {
return true; return true;
} }
rect_t relativeRect = {testRect.x - rect.x, testRect.y - rect.y, testRect.w, testRect.h};
for (auto child: children) { for (auto child: children) {
if (child->hasOpaqueRect(rect)) if (child->hasOpaqueRect(relativeRect))
return true; return true;
} }
@@ -228,19 +229,20 @@ void Window::fullPaint(BitmapBuffer * dc)
coord_t xmin, xmax, ymin, ymax; coord_t xmin, xmax, ymin, ymax;
dc->getClippingRect(xmin, xmax, ymin, ymax); dc->getClippingRect(xmin, xmax, ymin, ymax);
coord_t x = dc->getOffsetX();
coord_t y = dc->getOffsetY();
auto firstChild = children.end(); auto firstChild = children.end();
rect_t relativeRect = {xmin - x, ymin - y, xmax - xmin, ymax - ymin};
while (firstChild != children.begin()) { while (firstChild != children.begin()) {
auto child = *(--firstChild); auto child = *(--firstChild);
if (child->hasOpaqueRect({xmin, ymin, xmax - xmin, ymax - ymin})) { if (child->hasOpaqueRect(relativeRect)) {
paintNeeded = false; paintNeeded = false;
break; break;
} }
} }
if (windowFlags & PAINT_CHILDREN_FIRST) { if (windowFlags & PAINT_CHILDREN_FIRST) {
coord_t x = dc->getOffsetX();
coord_t y = dc->getOffsetY();
paintChildren(dc, firstChild); paintChildren(dc, firstChild);
dc->setOffset(x, y); dc->setOffset(x, y);
dc->setClippingRect(xmin, xmax, ymin, ymax); dc->setClippingRect(xmin, xmax, ymin, ymax);
+1 -1
View File
@@ -416,7 +416,7 @@ class Window {
bool forwardTouchEnd(coord_t x, coord_t y); bool forwardTouchEnd(coord_t x, coord_t y);
bool hasOpaqueRect(const rect_t & rect) const; bool hasOpaqueRect(const rect_t & testRect) const;
}; };
#endif // _WINDOW_H_ #endif // _WINDOW_H_