mgba/include/mgba-util/gui/menu.h

124 lines
3.3 KiB
C
Raw Normal View History

2015-08-30 20:14:29 +00:00
/* Copyright (c) 2013-2015 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GUI_MENU_H
#define GUI_MENU_H
#include <mgba-util/common.h>
2016-12-27 05:01:55 +00:00
CXX_GUARD_START
#include <mgba-util/gui.h>
#include <mgba-util/vector.h>
2015-08-30 20:14:29 +00:00
2018-09-29 18:09:16 +00:00
#define GUI_V_V (struct GUIVariant) { .type = GUI_VARIANT_VOID }
#define GUI_V_U(U) (struct GUIVariant) { .type = GUI_VARIANT_UNSIGNED, .v.u = (U) }
#define GUI_V_I(I) (struct GUIVariant) { .type = GUI_VARIANT_INT, .v.i = (I) }
#define GUI_V_F(F) (struct GUIVariant) { .type = GUI_VARIANT_FLOAT, .v.f = (F) }
#define GUI_V_S(S) (struct GUIVariant) { .type = GUI_VARIANT_STRING, .v.s = (S) }
2021-06-29 04:13:05 +00:00
#define GUI_V_P(P) (struct GUIVariant) { .type = GUI_VARIANT_POINTER, .v.p = (P) }
#define GUIVariantIs(V, T) ((V).type == GUI_VARIANT_##T)
#define GUIVariantIsVoid(V) GUIVariantIs(V, VOID)
#define GUIVariantIsUInt(V) GUIVariantIs(V, UNSIGNED)
#define GUIVariantIsInt(V) GUIVariantIs(V, INT)
#define GUIVariantIsFloat(V) GUIVariantIs(V, FLOAT)
#define GUIVariantIsString(V) GUIVariantIs(V, STRING)
#define GUIVariantIsPointer(V) GUIVariantIs(V, POINTER)
#define GUIVariantCompareUInt(V, X) (GUIVariantIsUInt(V) && (V).v.u == (X))
#define GUIVariantCompareInt(V, X) (GUIVariantIsInt(V) && (V).v.i == (X))
#define GUIVariantCompareString(V, X) (GUIVariantIsString(V) && strcmp((V).v.s, (X)) == 0)
2018-09-29 18:09:16 +00:00
enum GUIVariantType {
GUI_VARIANT_VOID = 0,
GUI_VARIANT_UNSIGNED,
GUI_VARIANT_INT,
GUI_VARIANT_FLOAT,
2021-06-29 04:13:05 +00:00
GUI_VARIANT_STRING,
GUI_VARIANT_POINTER,
2018-09-29 18:09:16 +00:00
};
struct GUIVariant {
enum GUIVariantType type;
union {
unsigned u;
int i;
float f;
const char* s;
2021-06-29 04:13:05 +00:00
void* p;
2018-09-29 18:09:16 +00:00
} v;
};
2015-09-02 05:09:12 +00:00
struct GUIMenu;
2015-08-30 20:14:29 +00:00
struct GUIMenuItem {
const char* title;
2021-06-29 04:13:05 +00:00
struct GUIVariant data;
2015-09-18 02:53:27 +00:00
unsigned state;
2016-01-08 07:52:55 +00:00
const char* const* validStates;
2018-09-29 18:09:16 +00:00
const struct GUIVariant* stateMappings;
2016-01-08 07:52:55 +00:00
unsigned nStates;
2015-09-02 05:09:12 +00:00
struct GUIMenu* submenu;
2022-01-09 23:05:57 +00:00
bool readonly;
2015-08-30 20:14:29 +00:00
};
DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem);
2015-09-02 04:51:14 +00:00
struct GUIBackground;
2015-08-30 20:14:29 +00:00
struct GUIMenu {
const char* title;
const char* subtitle;
2015-08-30 20:14:29 +00:00
struct GUIMenuItemList items;
size_t index;
2015-09-02 04:51:14 +00:00
struct GUIBackground* background;
2015-08-30 20:14:29 +00:00
};
struct GUIMenuSavedState {
struct GUIMenu* menu;
size_t start;
};
DECLARE_VECTOR(GUIMenuSavedList, struct GUIMenuSavedState);
struct GUIMenuState {
size_t start;
int cursorOverItem;
enum GUICursorState cursor;
unsigned cx, cy;
struct GUIMenuSavedList stack;
struct GUIMenuItem* resultItem;
};
2015-08-30 20:14:29 +00:00
enum GUIMenuExitReason {
GUI_MENU_CONTINUE = 0,
2015-08-30 20:14:29 +00:00
GUI_MENU_EXIT_ACCEPT,
GUI_MENU_EXIT_BACK,
GUI_MENU_EXIT_CANCEL,
GUI_MENU_ENTER,
2015-08-30 20:14:29 +00:00
};
2016-08-23 00:30:56 +00:00
enum GUIMessageBoxButtons {
GUI_MESSAGE_BOX_OK = 1,
GUI_MESSAGE_BOX_CANCEL = 2
};
2015-08-30 20:14:29 +00:00
struct GUIParams;
void GUIMenuStateInit(struct GUIMenuState*);
void GUIMenuStateDeinit(struct GUIMenuState*);
2015-09-18 02:53:27 +00:00
enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* menu, struct GUIMenuItem** item);
enum GUIMenuExitReason GUIMenuRun(struct GUIParams* params, struct GUIMenu* menu, struct GUIMenuState* state);
2015-08-30 20:14:29 +00:00
2016-08-23 00:30:56 +00:00
ATTRIBUTE_FORMAT(printf, 4, 5)
enum GUIMenuExitReason GUIShowMessageBox(struct GUIParams* params, int buttons, int frames, const char* format, ...);
void GUIDrawBattery(struct GUIParams* params);
void GUIDrawClock(struct GUIParams* params);
2016-12-27 05:01:55 +00:00
CXX_GUARD_END
2015-08-30 20:14:29 +00:00
#endif