include/mgba-util/gui.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_H
7#define GUI_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13// TODO: Fix layering violation
14#include <mgba/core/input.h>
15#include <mgba-util/vector.h>
16
17struct GUIFont;
18
19enum GUIInput {
20 GUI_INPUT_NONE = -1,
21 GUI_INPUT_SELECT = 0,
22 GUI_INPUT_BACK,
23 GUI_INPUT_CANCEL,
24
25 GUI_INPUT_UP,
26 GUI_INPUT_DOWN,
27 GUI_INPUT_LEFT,
28 GUI_INPUT_RIGHT,
29
30 GUI_INPUT_USER_START = 0x8,
31
32 GUI_INPUT_MAX = 0x20
33};
34
35enum GUICursorState {
36 GUI_CURSOR_NOT_PRESENT = 0,
37 GUI_CURSOR_UP,
38 GUI_CURSOR_DOWN,
39 GUI_CURSOR_CLICKED,
40 GUI_CURSOR_DRAGGING
41};
42
43enum {
44 BATTERY_EMPTY = 0,
45 BATTERY_LOW = 25,
46 BATTERY_HALF = 50,
47 BATTERY_HIGH = 75,
48 BATTERY_FULL = 100,
49 BATTERY_VALUE = 0x7F,
50 BATTERY_PERCENTAGE_VALID = 0x80,
51
52 BATTERY_CHARGING = 0x100,
53 BATTERY_NOT_PRESENT = 0x200,
54};
55
56struct GUIBackground {
57 void (*draw)(struct GUIBackground*, void* context);
58};
59
60struct GUIParams {
61 unsigned width;
62 unsigned height;
63 const struct GUIFont* font;
64 const char* basePath;
65
66 void (*drawStart)(void);
67 void (*drawEnd)(void);
68 uint32_t (*pollInput)(const struct mInputMap*);
69 enum GUICursorState (*pollCursor)(unsigned* x, unsigned* y);
70 int (*batteryState)(void);
71 void (*guiPrepare)(void);
72 void (*guiFinish)(void);
73
74 // State
75 struct mInputMap keyMap;
76 int inputHistory[GUI_INPUT_MAX];
77 enum GUICursorState cursorState;
78 int cx, cy;
79
80 // Directories
81 char currentPath[PATH_MAX];
82 size_t fileIndex;
83};
84
85void GUIInit(struct GUIParams* params);
86void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldInput);
87enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y);
88void GUIInvalidateKeys(struct GUIParams* params);
89
90CXX_GUARD_END
91
92#endif