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
39struct GUIBackground {
40 void (*draw)(struct GUIBackground*, void* context);
41};
42
43struct GUIParams {
44 unsigned width;
45 unsigned height;
46 const struct GUIFont* font;
47 const char* basePath;
48
49 void (*drawStart)(void);
50 void (*drawEnd)(void);
51 uint32_t (*pollInput)(void);
52 enum GUICursorState (*pollCursor)(int* x, int* y);
53 void (*guiPrepare)(void);
54 void (*guiFinish)(void);
55
56 // State
57 int inputHistory[GUI_INPUT_MAX];
58 enum GUICursorState cursorState;
59 int cx, cy;
60
61 // Directories
62 char currentPath[PATH_MAX];
63 size_t fileIndex;
64};
65
66#define GUI_PARAMS_TRAIL {}, GUI_CURSOR_NOT_PRESENT, 0, 0, "", 0
67
68void GUIInit(struct GUIParams* params);
69void GUIPollInput(struct GUIParams* params, uint32_t* newInput, uint32_t* heldInput);
70enum GUICursorState GUIPollCursor(struct GUIParams* params, int* x, int* y);
71void GUIInvalidateKeys(struct GUIParams* params);
72
73#endif