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