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