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)
{
dc->clear(MENU_BGCOLOR);
for (unsigned i = 0; i < lines.size(); i++) {
auto & line = lines[i];
LcdFlags flags = MENU_COLOR | MENU_FONT;
+6 -3
View File
@@ -85,12 +85,14 @@ void TextEdit::onEvent(event_t event)
value[length - 1] = '\0';
--cursorPos;
invalidate();
changed = true;
}
}
else if (cursorPos < length) {
memmove(value + cursorPos + 1, value + cursorPos, length - cursorPos - 1);
value[cursorPos++] = c;
invalidate();
changed = true;
}
}
#endif
@@ -130,8 +132,10 @@ void TextEdit::onEvent(event_t event)
case EVT_KEY_BREAK(KEY_ENTER):
if (cursorPos < length - 1) {
cursorPos++;
if (value[cursorPos] == '\0')
if (value[cursorPos] == '\0') {
value[cursorPos] = ' ';
changed = true;
}
invalidate();
}
else {
@@ -171,7 +175,7 @@ void TextEdit::onEvent(event_t event)
// TRACE("value[%d] = %d", cursorPos, v);
value[cursorPos] = v;
invalidate();
// TODO storageDirty(...);
changed = true;
}
}
else {
@@ -216,6 +220,5 @@ void TextEdit::onFocusLost()
changeEnd();
// TODO storageDirty(...);
FormField::onFocusLost();
}
+7 -3
View File
@@ -67,6 +67,7 @@ class TextEdit : public FormField {
protected:
char * value;
bool changed = false;
uint8_t length;
uint8_t cursorPos = 0;
std::function<void()> changeHandler = nullptr;
@@ -76,9 +77,12 @@ class TextEdit : public FormField {
void changeEnd()
{
cursorPos = 0;
trim();
if (changeHandler)
changeHandler();
if (changed) {
changed = false;
trim();
if (changeHandler)
changeHandler();
}
}
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;
if (windowFlags & OPAQUE) {
return true;
}
rect_t relativeRect = {testRect.x - rect.x, testRect.y - rect.y, testRect.w, testRect.h};
for (auto child: children) {
if (child->hasOpaqueRect(rect))
if (child->hasOpaqueRect(relativeRect))
return true;
}
@@ -228,19 +229,20 @@ void Window::fullPaint(BitmapBuffer * dc)
coord_t xmin, xmax, ymin, ymax;
dc->getClippingRect(xmin, xmax, ymin, ymax);
coord_t x = dc->getOffsetX();
coord_t y = dc->getOffsetY();
auto firstChild = children.end();
rect_t relativeRect = {xmin - x, ymin - y, xmax - xmin, ymax - ymin};
while (firstChild != children.begin()) {
auto child = *(--firstChild);
if (child->hasOpaqueRect({xmin, ymin, xmax - xmin, ymax - ymin})) {
if (child->hasOpaqueRect(relativeRect)) {
paintNeeded = false;
break;
}
}
if (windowFlags & PAINT_CHILDREN_FIRST) {
coord_t x = dc->getOffsetX();
coord_t y = dc->getOffsetY();
paintChildren(dc, firstChild);
dc->setOffset(x, y);
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 hasOpaqueRect(const rect_t & rect) const;
bool hasOpaqueRect(const rect_t & testRect) const;
};
#endif // _WINDOW_H_