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