Optimization
This commit is contained in:
+2
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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_
|
||||||
|
|||||||
Reference in New Issue
Block a user