Skip to content

Commit

Permalink
currentState and previousState removed from WidgetCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Dec 4, 2021
1 parent aabbbb8 commit 6ea8724
Show file tree
Hide file tree
Showing 59 changed files with 448 additions and 449 deletions.
23 changes: 15 additions & 8 deletions src/bb3/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ void onKeyDown(uint16_t param) {
bool handled = false;

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

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

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

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

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

return false;
}

static bool findNextFocusCursor(const WidgetCursor &widgetCursor) {
if (isKeyboardEnabledForWidget(widgetCursor)) {
static bool findNextFocusCursor(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;
if (isKeyboardEnabledForWidget(widgetState)) {
if (g_findFocusCursorState == 0) {
g_focusWidgetCursorIter = widgetCursor;
g_findFocusCursorState = 1;
Expand Down Expand Up @@ -246,8 +252,9 @@ static void moveToNextFocusCursor() {
}
}

static bool findPreviousFocusCursor(const WidgetCursor &widgetCursor) {
if (isKeyboardEnabledForWidget(widgetCursor)) {
static bool findPreviousFocusCursor(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;
if (isKeyboardEnabledForWidget(widgetState)) {
if (g_findFocusCursorState == 0) {
g_focusWidgetCursorIter = widgetCursor;
g_findFocusCursorState = 1;
Expand Down
36 changes: 16 additions & 20 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) {
WidgetCursor toastPageWidgetCursor(widgetCursor.assets, appContext, &actionWidget, -1, nullptr, &actionWidgetState, nullptr, nullptr, actionWidget.x, actionWidget.y);
if (widgetCursor.previousState && actionWidgetIsActive == isActiveWidget(toastPageWidgetCursor)) {
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)) {
return;
}

Expand Down Expand Up @@ -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, -1, nullptr, nullptr, &actionWidgetState, nullptr, actionWidget.x, actionWidget.y);
return WidgetCursor(g_mainAssets, appContext, &actionWidget, actionWidget.x, actionWidget.y);
}
widget.action = ACTION_ID_INTERNAL_DIALOG_CLOSE;
return WidgetCursor(g_mainAssets, appContext, &widget, -1, nullptr, nullptr, &widgetState, nullptr, x, y);
return WidgetCursor(g_mainAssets, appContext, &widget, x, y);
}

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

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

Expand Down Expand Up @@ -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, -1, nullptr, nullptr, &widgetState, nullptr, x, y);
return WidgetCursor(g_mainAssets, appContext, &widget, x, y);
}
}
}
Expand Down Expand Up @@ -663,41 +663,39 @@ void MenuWithButtonsPage::init(AppContext *appContext, const char *message, cons

}

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

widgetCursor.appContext = m_appContext;
widgetCursor.previousState = widgetCursor2.previousState;
widgetCursor.currentState = widgetCursor2.currentState;

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

RectangleWidgetState rectangleWidgetState;
rectangleWidgetState.widgetCursor = widgetCursor;
rectangleWidgetState.draw();
rectangleWidgetState.draw(previousState);

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

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;
widgetCursor.currentState->flags.active = isActiveWidget(widgetCursor);
currentState->flags.active = isActiveWidget(widgetCursor);
TextWidgetState textWidgetState;
textWidgetState.widgetCursor = widgetCursor;
textWidgetState.draw();
textWidgetState.draw(previousState);
}
}

Expand All @@ -715,15 +713,13 @@ WidgetCursor MenuWithButtonsPage::findWidgetInternalPage(int x, int y, bool clic
x >= widgetCursor.x && x < widgetCursor.x + m_buttonTextWidgets[i].w &&
y >= widgetCursor.y && y < widgetCursor.y + m_buttonTextWidgets[i].h
) {
widgetCursor.currentState = &m_buttonTextWidgetStates[i];
return widgetCursor;
}
}

widgetCursor.widget = &m_containerRectangleWidget;
widgetCursor.x = this->x + m_containerRectangleWidget.x;
widgetCursor.y = this->y + m_containerRectangleWidget.y;
widgetCursor.currentState = &m_containerRectangleWidgetState;
return widgetCursor;
}

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

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

Expand All @@ -74,7 +74,6 @@ class ToastMessagePage : public InternalPage {
const char *actionLabel;

Widget actionWidget;
WidgetState actionWidgetState;
bool actionWidgetIsActive;
void (*action)(int param);
int actionParam;
Expand Down Expand Up @@ -109,7 +108,7 @@ class SelectFromEnumPage : public InternalPage {

void init();

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

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

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

static void executeAction();

private:
AppContext *m_appContext;
RectangleWidget m_containerRectangleWidget;
RectangleWidgetState m_containerRectangleWidgetState;
TextWidget m_messageTextWidget;
TextWidget m_buttonTextWidgets[MAX_MENU_ITEMS];
TextWidgetState m_buttonTextWidgetStates[MAX_MENU_ITEMS];
size_t m_numButtonTextWidgets;
void (*m_callback)(int);

Expand Down
13 changes: 8 additions & 5 deletions src/bb3/psu/gui/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,8 @@ bool PsuAppContext::canExecuteActionWhenTouchedOutsideOfActivePage(int pageId, i
return false;
}

void PsuAppContext::updatePage(int i, WidgetCursor &widgetCursor) {
AppContext::updatePage(i, widgetCursor);
void PsuAppContext::updatePage(int i, WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState) {
AppContext::updatePage(i, widgetCursor, currentState, previousState);

if (getActivePageId() == PAGE_ID_TOUCH_CALIBRATION_YES_NO || getActivePageId() == PAGE_ID_TOUCH_CALIBRATION_YES_NO_CANCEL) {
auto eventType = touch::getEventType();
Expand Down Expand Up @@ -1520,7 +1520,8 @@ static bool isEncoderEnabledForWidget(const WidgetCursor &widgetCursor) {
static bool g_focusCursorIsEnabled;
static int16_t g_focusCursorAction;

bool isEnabledFocusCursorStep(const WidgetCursor &widgetCursor) {
bool isEnabledFocusCursorStep(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;
if (isEncoderEnabledForWidget(widgetCursor)) {
if (g_focusCursor == widgetCursor && g_focusDataId == widgetCursor.widget->data) {
g_focusCursorIsEnabled = true;
Expand All @@ -1538,7 +1539,8 @@ bool isEnabledFocusCursor(const WidgetCursor& cursor, int16_t dataId) {
return g_focusCursorIsEnabled;
}

bool isEncoderEnabledInActivePageCheckWidget(const WidgetCursor &widgetCursor) {
bool isEncoderEnabledInActivePageCheckWidget(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;
if (widgetCursor.isPage()) {
g_isEncoderEnabledInActivePage = false;
} else if (isEncoderEnabledForWidget(widgetCursor)) {
Expand Down Expand Up @@ -1859,7 +1861,8 @@ static int g_findNextFocusCursorState = 0;
static WidgetCursor g_nextFocusCursor = 0;
static uint16_t g_nextFocusDataId = DATA_ID_CHANNEL_U_EDIT;

bool findNextFocusCursor(const WidgetCursor &widgetCursor) {
bool findNextFocusCursor(WidgetState *widgetState) {
const WidgetCursor &widgetCursor = widgetState->widgetCursor;
if (isEncoderEnabledForWidget(widgetCursor)) {
if (g_findNextFocusCursorState == 0) {
g_nextFocusCursor = widgetCursor;
Expand Down
2 changes: 1 addition & 1 deletion src/bb3/psu/gui/psu.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class PsuAppContext : public AppContext {
void onPageTouch(const WidgetCursor &foundWidget, Event &touchEvent) override;
bool testExecuteActionOnTouchDown(int action) override;
bool canExecuteActionWhenTouchedOutsideOfActivePage(int pageId, int action) override;
void updatePage(int i, WidgetCursor &widgetCursor) override;
void updatePage(int i, WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState) override;

private:
void doShowProgressPage();
Expand Down
37 changes: 9 additions & 28 deletions src/eez/gui/app_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ namespace gui {
////////////////////////////////////////////////////////////////////////////////

AppContext::AppContext() {
m_updatePageIndex = -1;
}

void AppContext::stateManagment() {
Expand Down Expand Up @@ -89,25 +88,6 @@ bool AppContext::isFocusWidget(const WidgetCursor &widgetCursor) {

////////////////////////////////////////////////////////////////////////////////

int AppContext::getActivePageStackPointer() {
return m_updatePageIndex != -1 ? m_updatePageIndex : m_pageNavigationStackPointer;
}

int AppContext::getActivePageId() {
return m_pageNavigationStack[getActivePageStackPointer()].pageId;
}

Page *AppContext::getActivePage() {
return m_pageNavigationStack[getActivePageStackPointer()].page;
}

int AppContext::getPreviousPageId() {
if (getActivePageStackPointer() == 0) {
return PAGE_ID_NONE;
}
return m_pageNavigationStack[getActivePageStackPointer() - 1].pageId;
}

void AppContext::onPageChanged(int previousPageId, int activePageId) {
display::turnOn();
hmi::noteActivity();
Expand Down Expand Up @@ -307,15 +287,16 @@ void AppContext::onPageTouch(const WidgetCursor &foundWidget, Event &touchEvent)

////////////////////////////////////////////////////////////////////////////////

void AppContext::updatePage(int i, WidgetCursor &widgetCursor) {
if (!widgetCursor.previousState || m_pageNavigationStack[i].displayBufferIndex == -1) {
void AppContext::updatePage(int i, WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState) {
if (!previousState || m_pageNavigationStack[i].displayBufferIndex == -1) {
m_pageNavigationStack[i].displayBufferIndex = display::allocBuffer();
widgetCursor.previousState = nullptr;
previousState = nullptr;
}

display::selectBuffer(m_pageNavigationStack[i].displayBufferIndex);

m_updatePageIndex = i;
auto savedPageNavigationStackPointer = m_pageNavigationStackPointer;
m_pageNavigationStackPointer = i;

int x;
int y;
Expand All @@ -332,9 +313,9 @@ void AppContext::updatePage(int i, WidgetCursor &widgetCursor) {
height = internalPage->height;
withShadow = true;

internalPage->updateInternalPage(widgetCursor);
internalPage->updateInternalPage(widgetCursor, currentState, previousState);

enumNoneWidget(widgetCursor);
enumNoneWidget(widgetCursor, currentState, previousState);
} else {
auto page = getPageAsset(m_pageNavigationStack[i].pageId, widgetCursor);

Expand All @@ -345,12 +326,12 @@ void AppContext::updatePage(int i, WidgetCursor &widgetCursor) {
withShadow = page->x > 0;

widgetCursor.widget = page;
enumWidget(widgetCursor);
enumWidget(widgetCursor, currentState, previousState);
}

display::setBufferBounds(m_pageNavigationStack[i].displayBufferIndex, x, y, width, height, withShadow, 255, 0, 0, withShadow && activePageHasBackdropHook() ? &rect : nullptr);

m_updatePageIndex = -1;
m_pageNavigationStackPointer = savedPageNavigationStackPointer;
}

bool isRect1FullyCoveredByRect2(int xRect1, int yRect1, int wRect1, int hRect1, int xRect2, int yRect2, int wRect2, int hRect2) {
Expand Down
18 changes: 11 additions & 7 deletions src/eez/gui/app_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ class AppContext {
void popPage();
void removePageFromStack(int pageId);

int getActivePageId();
Page *getActivePage();
int getActivePageId() {
return m_pageNavigationStack[m_pageNavigationStackPointer].pageId;
}

Page *getActivePage() {
return m_pageNavigationStack[m_pageNavigationStackPointer].page;
}

bool isActivePageInternal();

int getPreviousPageId();
int getPreviousPageId() {
return m_pageNavigationStackPointer == 0 ? PAGE_ID_NONE : m_pageNavigationStack[m_pageNavigationStackPointer - 1].pageId;
}

void replacePage(int pageId, Page *page = nullptr);

Expand Down Expand Up @@ -92,7 +99,6 @@ class AppContext {
PageOnStack m_pageNavigationStack[CONF_GUI_PAGE_NAVIGATION_STACK_SIZE];
int m_pageNavigationStackPointer = 0;
int m_activePageIndex;
int m_updatePageIndex;

uint32_t m_showPageTime;

Expand All @@ -102,9 +108,7 @@ class AppContext {
void doShowPage(int index, Page *page, int previousPageId);
void setPage(int pageId);

int getActivePageStackPointer();

virtual void updatePage(int i, WidgetCursor &widgetCursor);
virtual void updatePage(int i, WidgetCursor &widgetCursor, WidgetState *currentState, WidgetState *previousState);

bool isPageFullyCovered(int pageNavigationStackIndex);

Expand Down
Loading

0 comments on commit 6ea8724

Please sign in to comment.