diff --git a/radio/src/gui/128x64/gui.h b/radio/src/gui/128x64/gui.h index dc4872d85..5f95b5ac5 100644 --- a/radio/src/gui/128x64/gui.h +++ b/radio/src/gui/128x64/gui.h @@ -235,12 +235,6 @@ void editSingleName(coord_t x, coord_t y, const char * label, char * name, uint8 uint8_t editDelay(coord_t y, event_t event, uint8_t attr, const char * str, uint8_t delay); #define EDIT_DELAY(x, y, event, attr, str, delay) editDelay(y, event, attr, str, delay) -enum { - WARNING_TYPE_ASTERISK, - WARNING_TYPE_CONFIRM, - WARNING_TYPE_INFO, -}; - #define COPY_MODE 1 #define MOVE_MODE 2 extern uint8_t s_copyMode; diff --git a/radio/src/gui/128x64/popups.h b/radio/src/gui/128x64/popups.h index 73edb0a84..e5d483e0b 100644 --- a/radio/src/gui/128x64/popups.h +++ b/radio/src/gui/128x64/popups.h @@ -35,37 +35,10 @@ #define WARNING_LINE_X 16 #define WARNING_LINE_Y 3*FH -#if !defined(GUI) - #define DISPLAY_WARNING(...) - #define POPUP_WARNING(...) - #define POPUP_CONFIRMATION(...) - #define POPUP_INPUT(...) - #define WARNING_INFO_FLAGS 0 - #define SET_WARNING_INFO(...) -#else - #define DISPLAY_WARNING (*popupFunc) - #define POPUP_INFORMATION(s) (warningText = s, warningType = WARNING_TYPE_INFO, warningInfoText = nullptr, popupFunc = runPopupWarning) - #define POPUP_WARNING(s) (warningText = s, warningInfoText = 0, popupFunc = runPopupWarning) - #define POPUP_CONFIRMATION(s, func) (warningText = s, warningType = WARNING_TYPE_CONFIRM, warningInfoText = nullptr, popupFunc = runPopupWarning, popupMenuHandler = func) - #define POPUP_INPUT(s, func) (warningText = s, popupFunc = func) - #define WARNING_INFO_FLAGS warningInfoFlags - #define SET_WARNING_INFO(info, len, flags) (warningInfoText = info, warningInfoLength = len, warningInfoFlags = flags) -#endif - -#if defined(SDCARD) - #define POPUP_MENU_ADD_SD_ITEM(s) POPUP_MENU_ADD_ITEM(s) -#else - #define POPUP_MENU_ADD_SD_ITEM(s) -#endif - -#define POPUP_MENU_ADD_ITEM(s) do { popupMenuOffsetType = MENU_OFFSET_INTERNAL; if (popupMenuItemsCount < POPUP_MENU_MAX_LINES) popupMenuItems[popupMenuItemsCount++] = s; } while (0) -#define POPUP_MENU_SELECT_ITEM(s) s_menu_item = (s > 0 ? (s < popupMenuItemsCount ? s : popupMenuItemsCount) : 0) -#define POPUP_MENU_START(func) do { popupMenuHandler = (func); AUDIO_KEY_PRESS(); } while (0) #define POPUP_MENU_MAX_LINES 12 #define MENU_MAX_DISPLAY_LINES 6 #define MENU_LINE_LENGTH (LEN_MODEL_NAME+12) -#define POPUP_MENU_SET_BSS_FLAG() -#define POPUP_MENU_UNSET_BSS_FLAG() + enum { MENU_OFFSET_INTERNAL, MENU_OFFSET_EXTERNAL diff --git a/radio/src/gui/212x64/gui.h b/radio/src/gui/212x64/gui.h index 3b4fb1e8b..af294a58e 100644 --- a/radio/src/gui/212x64/gui.h +++ b/radio/src/gui/212x64/gui.h @@ -247,11 +247,6 @@ void editSingleName(coord_t x, coord_t y, const char * label, char * name, uint8 uint8_t editDelay(coord_t y, event_t event, uint8_t attr, const char * str, uint8_t delay); #define EDIT_DELAY(y, event, attr, str, delay) editDelay(y, event, attr, str, delay) -#define WARNING_TYPE_ASTERISK 0 -#define WARNING_TYPE_CONFIRM 1 -#define WARNING_TYPE_INPUT 2 -#define WARNING_TYPE_INFO 4 - void copySelection(char * dst, const char * src, uint8_t size); #define COPY_MODE 1 diff --git a/radio/src/gui/212x64/popups.h b/radio/src/gui/212x64/popups.h index 295419096..377d0e8e6 100644 --- a/radio/src/gui/212x64/popups.h +++ b/radio/src/gui/212x64/popups.h @@ -33,22 +33,9 @@ #define WARNING_LINE_X 16 #define WARNING_LINE_Y 3*FH -#define DISPLAY_WARNING (*popupFunc) -#define POPUP_INFORMATION(s) (warningText = s, warningType = WARNING_TYPE_INFO, warningInfoText = 0, popupFunc = runPopupWarning) -#define POPUP_WARNING(s) (warningText = s, warningInfoText = 0, popupFunc = runPopupWarning) -#define POPUP_CONFIRMATION(s, func) (warningText = s, warningType = WARNING_TYPE_CONFIRM, warningInfoText = 0, popupFunc = runPopupWarning, popupMenuHandler = func) -#define POPUP_INPUT(s, func) (warningText = s, popupFunc = func) -#define WARNING_INFO_FLAGS warningInfoFlags -#define SET_WARNING_INFO(info, len, flags) (warningInfoText = info, warningInfoLength = len, warningInfoFlags = flags) - -#define POPUP_MENU_ADD_ITEM(s) do { popupMenuOffsetType = MENU_OFFSET_INTERNAL; if (popupMenuItemsCount < POPUP_MENU_MAX_LINES) popupMenuItems[popupMenuItemsCount++] = s; } while (0) -#define POPUP_MENU_SELECT_ITEM(s) s_menu_item = (s > 0 ? (s < popupMenuItemsCount ? s : popupMenuItemsCount) : 0) -#define POPUP_MENU_START(func) do { popupMenuHandler = (func); AUDIO_KEY_PRESS(); } while (0) #define POPUP_MENU_MAX_LINES 12 #define MENU_MAX_DISPLAY_LINES 6 -#define POPUP_MENU_ADD_SD_ITEM(s) POPUP_MENU_ADD_ITEM(s) #define MENU_LINE_LENGTH (LEN_MODEL_NAME+12) -#define POPUP_MENU_SET_BSS_FLAG() enum { MENU_OFFSET_INTERNAL, diff --git a/radio/src/gui/480x272/menus.h b/radio/src/gui/480x272/menus.h index 4246a84bc..8cd2ac31d 100644 --- a/radio/src/gui/480x272/menus.h +++ b/radio/src/gui/480x272/menus.h @@ -493,7 +493,6 @@ extern uint8_t warningInfoFlags; #define POPUP_INFORMATION(s) (warningText = s, warningType = WARNING_TYPE_INFO, warningInfoText = 0, popupFunc = runPopupWarning) #define POPUP_WARNING(s) (warningType = WARNING_TYPE_ASTERISK, warningText = s, warningInfoText = 0, popupFunc = runPopupWarning) #define POPUP_INPUT(s, func) (warningText = s, popupFunc = func) -#define WARNING_INFO_FLAGS warningInfoFlags #define SET_WARNING_INFO(info, len, flags) (warningInfoText = info, warningInfoLength = len, warningInfoFlags = flags) #define POPUP_MENU_ADD_ITEM(s) do { popupMenuOffsetType = MENU_OFFSET_INTERNAL; if (popupMenuItemsCount < POPUP_MENU_MAX_LINES) popupMenuItems[popupMenuItemsCount++] = s; } while (0) diff --git a/radio/src/gui/common/stdlcd/popups.cpp b/radio/src/gui/common/stdlcd/popups.cpp index a8b3bd493..722626a62 100644 --- a/radio/src/gui/common/stdlcd/popups.cpp +++ b/radio/src/gui/common/stdlcd/popups.cpp @@ -171,10 +171,13 @@ void runPopupWarning(event_t event) drawMessageBox(warningText); if (warningInfoText) { - lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, WARNING_INFO_FLAGS); + lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, warningInfoFlags); } switch (warningType) { + case WARNING_TYPE_WAIT: + return; + case WARNING_TYPE_INFO: lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+2*FH+2, STR_OK); break; diff --git a/radio/src/gui/common/stdlcd/popups.h b/radio/src/gui/common/stdlcd/popups.h index 17806561c..b6e1c9de0 100644 --- a/radio/src/gui/common/stdlcd/popups.h +++ b/radio/src/gui/common/stdlcd/popups.h @@ -21,6 +21,9 @@ #ifndef _STDLCD_POPUPS_H_ #define _STDLCD_POPUPS_H_ +#include +#include "audio.h" + extern const char * warningText; extern const char * warningInfoText; extern uint8_t warningInfoLength; @@ -28,13 +31,15 @@ extern uint8_t warningResult; extern uint8_t warningType; extern uint8_t warningInfoFlags; -extern void (* popupFunc)(event_t event); +typedef void (* PopupFunc)(event_t event); +extern PopupFunc popupFunc; extern uint8_t popupMenuOffsetType; extern uint16_t popupMenuOffset; extern const char * popupMenuItems[POPUP_MENU_MAX_LINES]; extern uint16_t popupMenuItemsCount; -extern void (* popupMenuHandler)(const char * result); +typedef void (* PopupMenuHandler)(const char * result); +extern PopupMenuHandler popupMenuHandler; extern const char * popupMenuTitle; extern uint8_t s_menu_item; @@ -53,4 +58,106 @@ void showAlertBox(const char * title, const char * text, const char * action , u // Full screen with 2 lines and a progress bar void drawProgressScreen(const char * title, const char * message, int num, int den); +enum +{ + WARNING_TYPE_WAIT, + WARNING_TYPE_INFO, + WARNING_TYPE_ASTERISK, + WARNING_TYPE_CONFIRM, + WARNING_TYPE_INPUT +}; + +#if !defined(GUI) + #define DISPLAY_WARNING(...) + inline void POPUP_WAIT(const char * s) { } + inline void POPUP_WARNING(const char * s) { } + inline void POPUP_CONFIRMATION(const char * s, PopupMenuHandler handler) { } + inline void POPUP_INPUT(const char * s, PopupFunc func) { } + inline void SET_WARNING_INFO(const char * info, uint8_t length, uint8_t flags) { } +#else + #define DISPLAY_WARNING (*popupFunc) + inline void POPUP_WAIT(const char * s) + { + warningText = s; + warningInfoText = nullptr; + warningType = WARNING_TYPE_WAIT; + popupFunc = runPopupWarning; + } + + inline void POPUP_INFORMATION(const char * s) + { + warningText = s; + warningInfoText = nullptr; + warningType = WARNING_TYPE_INFO; + popupFunc = runPopupWarning; + } + + inline void POPUP_WARNING(const char * s) + { + warningText = s; + warningInfoText = nullptr; + warningType = WARNING_TYPE_ASTERISK; + popupFunc = runPopupWarning; + } + + inline void POPUP_CONFIRMATION(const char * s, PopupMenuHandler handler) + { + warningText = s; + warningInfoText = nullptr; + warningType = WARNING_TYPE_CONFIRM; + popupFunc = runPopupWarning; + popupMenuHandler = handler; + } + + inline void POPUP_INPUT(const char * s, PopupFunc func) + { + warningText = s; + warningInfoText = nullptr; + warningType = WARNING_TYPE_INPUT; + popupFunc = func; + } + + inline void SET_WARNING_INFO(const char * info, uint8_t length, uint8_t flags) + { + warningInfoText = info; + warningInfoLength = length; + warningInfoFlags = flags; + } + + inline bool isEventCaughtByPopup() + { + if (warningText && warningType != WARNING_TYPE_WAIT) + return true; + + if (popupMenuItemsCount > 0) + return true; + + return false; + } +#endif + +inline void POPUP_MENU_ADD_ITEM(const char * s) +{ + popupMenuOffsetType = MENU_OFFSET_INTERNAL; + if (popupMenuItemsCount < POPUP_MENU_MAX_LINES) + popupMenuItems[popupMenuItemsCount++] = s; +} + +#if defined(SDCARD) + #define POPUP_MENU_ADD_SD_ITEM(s) POPUP_MENU_ADD_ITEM(s) +#else + #define POPUP_MENU_ADD_SD_ITEM(s) +#endif + +inline void POPUP_MENU_SELECT_ITEM(uint8_t index) +{ + s_menu_item = (index > 0 ? (index < popupMenuItemsCount ? index : popupMenuItemsCount) : 0); +} + +inline void POPUP_MENU_START(PopupMenuHandler handler) +{ + popupMenuHandler = handler; + AUDIO_KEY_PRESS(); +} + #endif // _STDLCD_POPUPS_H_ diff --git a/radio/src/main.cpp b/radio/src/main.cpp index b2989b722..3887a678d 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -438,24 +438,20 @@ void guiMain(event_t evt) menuEvent = 0; } + handleGui(isEventCaughtByPopup() ? 0 : evt); + if (warningText) { // show warning on top of the normal menus - handleGui(0); // suppress events, they are handled by the warning DISPLAY_WARNING(evt); } else if (popupMenuItemsCount > 0) { - // popup menu is active display it on top of normal menus - handleGui(0); // suppress events, they are handled by the popup + // show popup menu on top of the normal menus const char * result = runPopupMenu(evt); if (result) { TRACE("popupMenuHandler(%s)", result); popupMenuHandler(result); } } - else { - // normal menus - handleGui(evt); - } lcdRefresh(); }