all repos — mgba @ d746cb16d6350c587a4bca70e80be6aaae8c659b

mGBA Game Boy Advance Emulator

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