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 = 1,
46 BATTERY_HALF = 2,
47 BATTERY_HIGH = 3,
48 BATTERY_FULL = 4,
49
50 BATTERY_CHARGING = 8
51};
52
53struct GUIBackground {
54 void (*draw)(struct GUIBackground*, void* context);
55};
56
57struct GUIParams {
58 unsigned width;
59 unsigned height;
60 const struct GUIFont* font;
61 const char* basePath;
62
63 void (*drawStart)(void);
64 void (*drawEnd)(void);
65 uint32_t (*pollInput)(const struct mInputMap*);
66 enum GUICursorState (*pollCursor)(unsigned* x, unsigned* y);
67 int (*batteryState)(void);
68 void (*guiPrepare)(void);
69 void (*guiFinish)(void);
70
71 // State
72 struct mInputMap keyMap;
73 int inputHistory[GUI_INPUT_MAX];
74 enum GUICursorState cursorState;
75 int cx, cy;
76
77 // Directories
78 char currentPath[PATH_MAX];
79 size_t fileIndex;
80};
81
82void GUIInit(struct GUIParams* params);
83void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldInput);
84enum GUICursorState GUIPollCursor(struct GUIParams* params, unsigned* x, unsigned* y);
85void GUIInvalidateKeys(struct GUIParams* params);
86
87CXX_GUARD_END
88
89#endif