include/mgba-util/gui/menu.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef GUI_MENU_H
7#define GUI_MENU_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba-util/vector.h>
14
15#define GUI_V_V (struct GUIVariant) { .type = GUI_VARIANT_VOID }
16#define GUI_V_U(U) (struct GUIVariant) { .type = GUI_VARIANT_UNSIGNED, .v.u = (U) }
17#define GUI_V_I(I) (struct GUIVariant) { .type = GUI_VARIANT_INT, .v.i = (I) }
18#define GUI_V_F(F) (struct GUIVariant) { .type = GUI_VARIANT_FLOAT, .v.f = (F) }
19#define GUI_V_S(S) (struct GUIVariant) { .type = GUI_VARIANT_STRING, .v.s = (S) }
20
21enum GUIVariantType {
22 GUI_VARIANT_VOID = 0,
23 GUI_VARIANT_UNSIGNED,
24 GUI_VARIANT_INT,
25 GUI_VARIANT_FLOAT,
26 GUI_VARIANT_STRING
27};
28
29struct GUIVariant {
30 enum GUIVariantType type;
31 union {
32 unsigned u;
33 int i;
34 float f;
35 const char* s;
36 } v;
37};
38
39struct GUIMenu;
40struct GUIMenuItem {
41 const char* title;
42 void* data;
43 unsigned state;
44 const char* const* validStates;
45 const struct GUIVariant* stateMappings;
46 unsigned nStates;
47 struct GUIMenu* submenu;
48};
49
50DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem);
51
52struct GUIBackground;
53struct GUIMenu {
54 const char* title;
55 const char* subtitle;
56 struct GUIMenuItemList items;
57 size_t index;
58 struct GUIBackground* background;
59};
60
61enum GUIMenuExitReason {
62 GUI_MENU_EXIT_ACCEPT,
63 GUI_MENU_EXIT_BACK,
64 GUI_MENU_EXIT_CANCEL,
65};
66
67enum GUIMessageBoxButtons {
68 GUI_MESSAGE_BOX_OK = 1,
69 GUI_MESSAGE_BOX_CANCEL = 2
70};
71
72struct GUIParams;
73enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* menu, struct GUIMenuItem** item);
74
75ATTRIBUTE_FORMAT(printf, 4, 5)
76enum GUIMenuExitReason GUIShowMessageBox(struct GUIParams* params, int buttons, int frames, const char* format, ...);
77
78void GUIDrawBattery(struct GUIParams* params);
79void GUIDrawClock(struct GUIParams* params);
80
81CXX_GUARD_END
82
83#endif