Skip to content

Commit

Permalink
single widget state buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 6, 2021
1 parent 6c3b15f commit 5ecb53e
Show file tree
Hide file tree
Showing 72 changed files with 1,907 additions and 2,054 deletions.
31 changes: 10 additions & 21 deletions src/bb3/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ void onKeyDown(uint16_t param) {
bool handled = false;

if (g_focusWidgetCursor) {
auto widgetState = getWidgetState(g_focusWidgetCursor);
if (widgetState) {
handled = widgetState->onKeyboard(key, mod);
}
handled = g_focusWidgetCursor.currentState->onKeyboard(g_focusWidgetCursor, key, mod);
}

if (!handled) {
Expand Down Expand Up @@ -198,9 +195,7 @@ void onKeyboardEvent(SDL_KeyboardEvent *key) {
static int g_findFocusCursorState;
static WidgetCursor g_focusWidgetCursorIter;

static bool isKeyboardEnabledForWidget(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;

static bool isKeyboardEnabledForWidget(const WidgetCursor& widgetCursor) {
Overlay *overlay = getOverlay(widgetCursor);
if (overlay && !overlay->state) {
return false;
Expand All @@ -211,16 +206,15 @@ static bool isKeyboardEnabledForWidget(WidgetState *widgetState) {
return true;
}

if (widgetState->hasOnKeyboard()) {
if (widgetCursor.currentState->hasOnKeyboard()) {
return true;
}

return false;
}

static bool findNextFocusCursor(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;
if (isKeyboardEnabledForWidget(widgetState)) {
static void findNextFocusCursor(const WidgetCursor& widgetCursor) {
if (isKeyboardEnabledForWidget(widgetCursor)) {
if (g_findFocusCursorState == 0) {
g_focusWidgetCursorIter = widgetCursor;
g_findFocusCursorState = 1;
Expand All @@ -235,15 +229,13 @@ static bool findNextFocusCursor(WidgetState *widgetState) {
g_findFocusCursorState = 3;
}
}

return true;
}

static void moveToNextFocusCursor() {
g_findFocusCursorState = 0;
g_focusWidgetCursorIter = 0;

forEachWidget(&getRootAppContext(), findNextFocusCursor);
forEachWidget(findNextFocusCursor);

if (g_findFocusCursorState > 0) {
g_focusWidgetCursor = g_focusWidgetCursorIter;
Expand All @@ -252,9 +244,8 @@ static void moveToNextFocusCursor() {
}
}

static bool findPreviousFocusCursor(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;
if (isKeyboardEnabledForWidget(widgetState)) {
static void findPreviousFocusCursor(const WidgetCursor& widgetCursor) {
if (isKeyboardEnabledForWidget(widgetCursor)) {
if (g_findFocusCursorState == 0) {
g_focusWidgetCursorIter = widgetCursor;
g_findFocusCursorState = 1;
Expand All @@ -266,15 +257,13 @@ static bool findPreviousFocusCursor(WidgetState *widgetState) {
}
}
}

return true;
}

static void moveToPreviousFocusCursor() {
g_findFocusCursorState = 0;
g_focusWidgetCursorIter = 0;
forEachWidget(&getRootAppContext(), findPreviousFocusCursor);

forEachWidget(findPreviousFocusCursor);

if (g_findFocusCursorState > 0) {
g_focusWidgetCursor = g_focusWidgetCursorIter;
Expand Down
18 changes: 8 additions & 10 deletions src/bb3/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ static int g_mouseWasCursorX;
static int g_mouseWasCursorY;

static WidgetCursor g_foundWidgetAtMouse;
static OnTouchFunctionType g_onTouchFunctionAtMouse;

static bool g_lastMouseCursorVisible;
static int g_lastMouseCursorX;
static int g_lastMouseCursorY;
static WidgetCursor g_lastFoundWidgetAtMouse;
static OnTouchFunctionType g_lastOnTouchFunctionAtMouse;

MouseInfo g_mouseInfo;

Expand Down Expand Up @@ -89,8 +87,12 @@ void getEvent(bool &mouseCursorVisible, EventType &mouseEventType, int &mouseX,
g_mouseWasCursorX = g_mouseCursorX;
g_mouseWasCursorY = g_mouseCursorY;

g_foundWidgetAtMouse = findWidget(&getRootAppContext(), g_mouseCursorX, g_mouseCursorY, false);
g_onTouchFunctionAtMouse = getWidgetTouchFunction(g_foundWidgetAtMouse);
auto foundWidgetAtMouse = findWidget(g_mouseCursorX, g_mouseCursorY, false);
if (getWidgetTouchFunction(foundWidgetAtMouse)) {
g_foundWidgetAtMouse = foundWidgetAtMouse;
} else {
g_foundWidgetAtMouse = 0;
}

mouseCursorVisible = true;
mouseX = g_mouseCursorX;
Expand All @@ -101,7 +103,6 @@ void getEvent(bool &mouseCursorVisible, EventType &mouseEventType, int &mouseX,
g_mouseWasCursorY = 0;

g_foundWidgetAtMouse = 0;
g_onTouchFunctionAtMouse = 0;

mouseCursorVisible = false;
mouseX = 0;
Expand All @@ -114,14 +115,12 @@ bool isDisplayDirty() {
g_lastMouseCursorVisible != g_mouseCursorVisible ||
g_lastMouseCursorX != g_mouseCursorX ||
g_lastMouseCursorY != g_mouseCursorY ||
g_lastFoundWidgetAtMouse != g_foundWidgetAtMouse ||
g_lastOnTouchFunctionAtMouse != g_onTouchFunctionAtMouse
g_lastFoundWidgetAtMouse != g_foundWidgetAtMouse
) {
g_lastMouseCursorVisible = g_mouseCursorVisible;
g_lastMouseCursorX = g_mouseCursorX;
g_lastMouseCursorY = g_mouseCursorY;
g_lastFoundWidgetAtMouse = g_foundWidgetAtMouse;
g_lastOnTouchFunctionAtMouse = g_onTouchFunctionAtMouse;

return true;
}
Expand Down Expand Up @@ -153,7 +152,7 @@ void updateDisplay() {
image.height = getDisplayHeight() - g_lastMouseCursorY;
}

if (g_foundWidgetAtMouse && g_onTouchFunctionAtMouse) {
if (g_foundWidgetAtMouse) {
int16_t w;
int16_t h;

Expand All @@ -176,7 +175,6 @@ void updateDisplay() {

void onPageChanged() {
g_foundWidgetAtMouse = 0;
g_onTouchFunctionAtMouse = 0;
}

void onMouseXMove(int x) {
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/psu/dlog_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#endif

#include <eez/gui/gui.h>
#include <eez/gui/widgets/container.h>
#include <eez/gui/widgets/containers/container.h>

#include <bb3/fs/fs.h>

Expand Down
2 changes: 1 addition & 1 deletion src/bb3/psu/event_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#if OPTION_DISPLAY
#include <eez/gui/gui.h>
#include <eez/gui/widgets/container.h>
#include <eez/gui/widgets/containers/container.h>

#include <bb3/psu/gui/psu.h>
#include <bb3/psu/gui/animations.h>
Expand Down
12 changes: 7 additions & 5 deletions src/bb3/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,10 @@ void data_no_channel_index(int slotIndex, DataOperationEnum operation, const Wid
}

void data_slot_channel_index(int slotIndex, Channel *channel, DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
auto testResult = g_slots[slotIndex]->getTestResult();
// TODO trtMrt
if (slotIndex == -1) return;

auto testResult = g_slots[slotIndex]->getTestResult();
if (channel && g_slots[slotIndex]->enabled && (testResult == TEST_OK || testResult == TEST_SKIPPED)) {
data_channel_index(*channel, operation, widgetCursor, value);
} else {
Expand Down Expand Up @@ -4119,15 +4122,14 @@ void data_ethernet_dhcp(DataOperationEnum operation, const WidgetCursor &widgetC

void data_ethernet_mac(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
#if OPTION_ETHERNET
static uint8_t s_macAddressData[2][6];
static uint8_t g_macAddressData[6];

if (operation == DATA_OPERATION_GET) {
SysSettingsEthernetPage *page =
(SysSettingsEthernetPage *)getPage(PAGE_ID_SYS_SETTINGS_ETHERNET);
if (page) {
uint8_t *macAddress = &s_macAddressData[getCurrentStateBufferIndex()][0];
memcpy(macAddress, page->m_macAddress, 6);
value = MakeMacAddressValue(macAddress);
memcpy(g_macAddressData, page->m_macAddress, 6);
value = MakeMacAddressValue(g_macAddressData);
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/psu/gui/file_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <bb3/fs_driver.h>

#include <eez/gui/gui.h>
#include <eez/gui/widgets/container.h>
#include <eez/gui/widgets/containers/container.h>

#include <bb3/psu/psu.h>
#include <bb3/psu/serial_psu.h>
Expand Down
6 changes: 3 additions & 3 deletions src/bb3/psu/gui/keypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ void Keypad::init(AppContext *appContext, const char *label_) {
}

Value Keypad::getKeypadTextValue() {
char *text = &m_stateText[getCurrentStateBufferIndex()][0];
getKeypadText(text, sizeof(m_stateText[0]));
return Value(text);
char text[MAX_KEYPAD_TEXT_LENGTH + 2];
getKeypadText(text, sizeof(text));
return Value::makeStringRef(text, strlen(text), 0x893cbf99);
}

void Keypad::getKeypadText(char *text, size_t count) {
Expand Down
1 change: 0 additions & 1 deletion src/bb3/psu/gui/keypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class Keypad : public Page {
protected:
AppContext *m_appContext;

char m_stateText[2][MAX_KEYPAD_TEXT_LENGTH + 2];
char m_label[MAX_KEYPAD_LABEL_LENGTH + 1];
char m_keypadText[MAX_KEYPAD_TEXT_LENGTH + 2];
int m_cursorPosition;
Expand Down
47 changes: 23 additions & 24 deletions src/bb3/psu/gui/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ void ToastMessagePage::onEncoderClicked() {
}
}

void ToastMessagePage::updateInternalPage(const WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState) {
WidgetCursor toastPageWidgetCursor(widgetCursor.assets, appContext, &actionWidget, actionWidget.x, actionWidget.y);
if (previousState && actionWidgetIsActive == isActiveWidget(toastPageWidgetCursor)) {
void ToastMessagePage::updateInternalPage(const WidgetCursor &widgetCursor) {
WidgetCursor toastPageWidgetCursor(widgetCursor.assets, appContext, &actionWidget, actionWidget.x, actionWidget.y, widgetCursor.currentState, widgetCursor.hasPreviousState);
if (widgetCursor.hasPreviousState && actionWidgetIsActive == isActiveWidget(toastPageWidgetCursor)) {
return;
}

Expand Down Expand Up @@ -284,7 +284,7 @@ void ToastMessagePage::updateInternalPage(const WidgetCursor &widgetCursor, Widg
}
}

WidgetCursor ToastMessagePage::findWidgetInternalPage(int x, int y, bool clicked) {
WidgetCursor ToastMessagePage::findWidgetInternalPage(const WidgetCursor &widgetCursor, int x, int y, bool clicked) {
if (x >= this->x && x < this->x + width && y >= this->y && y < this->y + height) {
const Style *style = getStyle(type == INFO_TOAST ? STYLE_ID_INFO_ALERT : STYLE_ID_ERROR_ALERT);
font::Font font = styleGetFont(style);
Expand All @@ -296,10 +296,10 @@ WidgetCursor ToastMessagePage::findWidgetInternalPage(int x, int y, bool clicked
y >= (actionWidget.y - textHeight / 4) &&
y < (actionWidget.y + actionWidget.h - 1 + textHeight / 4)
) {
return WidgetCursor(g_mainAssets, appContext, &actionWidget, actionWidget.x, actionWidget.y);
return WidgetCursor(g_mainAssets, appContext, &actionWidget, actionWidget.x, actionWidget.y, widgetCursor.currentState, widgetCursor.hasPreviousState);
}
widget.action = ACTION_ID_INTERNAL_DIALOG_CLOSE;
return WidgetCursor(g_mainAssets, appContext, &widget, x, y);
return WidgetCursor(g_mainAssets, appContext, &widget, x, y, widgetCursor.currentState, widgetCursor.hasPreviousState);
}

return WidgetCursor();
Expand Down Expand Up @@ -486,8 +486,8 @@ void SelectFromEnumPage::findPagePosition() {
}
}

void SelectFromEnumPage::updateInternalPage(const WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState) {
if (previousState && !dirty) {
void SelectFromEnumPage::updateInternalPage(const WidgetCursor &widgetCursor) {
if (widgetCursor.hasPreviousState && !dirty) {
return;
}

Expand All @@ -512,7 +512,7 @@ void SelectFromEnumPage::updateInternalPage(const WidgetCursor &widgetCursor, Wi
dirty = false;
}

WidgetCursor SelectFromEnumPage::findWidgetInternalPage(int x, int y, bool clicked) {
WidgetCursor SelectFromEnumPage::findWidgetInternalPage(const WidgetCursor &widgetCursor, int x, int y, bool clicked) {
for (int i = 0; i < numItems; ++i) {
int xItem, yItem;
getItemPosition(i, xItem, yItem);
Expand All @@ -527,7 +527,7 @@ WidgetCursor SelectFromEnumPage::findWidgetInternalPage(int x, int y, bool click

widget.action = ACTION_ID_INTERNAL_SELECT_ENUM_ITEM;
widget.data = (uint16_t)i;
return WidgetCursor(g_mainAssets, appContext, &widget, x, y);
return WidgetCursor(g_mainAssets, appContext, &widget, x, y, widgetCursor.currentState, widgetCursor.hasPreviousState);
}
}
}
Expand Down Expand Up @@ -663,41 +663,40 @@ void MenuWithButtonsPage::init(AppContext *appContext, const char *message, cons

}

void MenuWithButtonsPage::updateInternalPage(const WidgetCursor &widgetCursor2, WidgetState *currentState, WidgetState *previousState) {
void MenuWithButtonsPage::updateInternalPage(const WidgetCursor &widgetCursor2) {
WidgetCursor widgetCursor;

widgetCursor.appContext = m_appContext;

if (!previousState) {
if (!widgetCursor2.hasPreviousState) {
widgetCursor.widget = &m_containerRectangleWidget;
widgetCursor.x = x + m_containerRectangleWidget.x;
widgetCursor.y = y + m_containerRectangleWidget.y;
currentState->flags.active = 0;

RectangleWidgetState rectangleWidgetState(widgetCursor);
rectangleWidgetState.draw(previousState);
RectangleWidgetState rectangleWidgetState;
rectangleWidgetState.flags.active = 0;
rectangleWidgetState.render(widgetCursor);

widgetCursor.widget = &m_messageTextWidget;
widgetCursor.x = x + m_messageTextWidget.x;
widgetCursor.y = y + m_messageTextWidget.y;
currentState->flags.active = 0;
TextWidgetState textWidgetState(widgetCursor);
textWidgetState.draw(previousState);
TextWidgetState textWidgetState;
textWidgetState.flags.active = 0;
textWidgetState.render(widgetCursor);
}

for (size_t i = 0; i < m_numButtonTextWidgets; i++) {
widgetCursor.widget = &m_buttonTextWidgets[i];
widgetCursor.x = x + m_buttonTextWidgets[i].x;
widgetCursor.y = y + m_buttonTextWidgets[i].y;
widgetCursor.cursor = i;
currentState->flags.active = isActiveWidget(widgetCursor);
TextWidgetState textWidgetState(widgetCursor);
textWidgetState.draw(previousState);
TextWidgetState textWidgetState;
textWidgetState.flags.active = isActiveWidget(widgetCursor);
textWidgetState.render(widgetCursor);
}
}

WidgetCursor MenuWithButtonsPage::findWidgetInternalPage(int x, int y, bool clicked) {
WidgetCursor widgetCursor;
WidgetCursor MenuWithButtonsPage::findWidgetInternalPage(const WidgetCursor &widgetCursor2, int x, int y, bool clicked) {
WidgetCursor widgetCursor = widgetCursor2;

widgetCursor.appContext = m_appContext;

Expand Down
12 changes: 6 additions & 6 deletions src/bb3/psu/gui/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class ToastMessagePage : public InternalPage {
void onEncoder(int counter);
void onEncoderClicked();

void updateInternalPage(const WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState);
WidgetCursor findWidgetInternalPage(int x, int y, bool clicked);
void updateInternalPage(const WidgetCursor &widgetCursor);
WidgetCursor findWidgetInternalPage(const WidgetCursor &widgetCursor, int x, int y, bool clicked);
bool canClickPassThrough();

bool hasAction() {
Expand Down Expand Up @@ -108,8 +108,8 @@ class SelectFromEnumPage : public InternalPage {

void init();

void updateInternalPage(const WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState);
WidgetCursor findWidgetInternalPage(int x, int y, bool clicked);
void updateInternalPage(const WidgetCursor &widgetCursor);
WidgetCursor findWidgetInternalPage(const WidgetCursor &widgetCursor, int x, int y, bool clicked);

void selectEnumItem();

Expand Down Expand Up @@ -165,8 +165,8 @@ class MenuWithButtonsPage : public InternalPage {
public:
static MenuWithButtonsPage *create(AppContext *appContext, const char *message, const char **menuItems, void (*callback)(int));

void updateInternalPage(const WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState);
WidgetCursor findWidgetInternalPage(int x, int y, bool clicked);
void updateInternalPage(const WidgetCursor &widgetCursor);
WidgetCursor findWidgetInternalPage(const WidgetCursor &widgetCursor, int x, int y, bool clicked);

static void executeAction();

Expand Down
Loading

0 comments on commit 5ecb53e

Please sign in to comment.