Tramway SDK
ui.h
Go to the documentation of this file.
1// TRAMWAY DRIFT AND DUNGEON EXPLORATION SIMULATOR 2022
2// All rights reserved.
3
4#ifndef TRAM_SDK_FRAMEWORK_UI_H
5#define TRAM_SDK_FRAMEWORK_UI_H
6
7#include <render/render.h>
8
9namespace tram::UI {
10
11enum KeyboardKey : uint16_t {
12 // stutter keys
14
15 // number keys
17
18 // programming keys
20
21 // letter keys
24
25 // keys that you press by accident
27
28 // i have no idea what these are
30
31 // stutter keys
33
34 // arrow keys
36
37 // keys right above arrow keys
40
41 // function keys
48
49 // keyoad keys
52
53 // modfier keys
56
57 // i have no idea what this key is
59
60 // mouse keys
64
66};
67
68enum KeyboardAxis : uint16_t {
73};
74
76 STATE_DEFAULT, //< Normal input, events get generated, cursor disabled.
77 STATE_NO_INPUT, //< Inputs get ignored, no cursor.
78 STATE_FLYING, //< Events are skipped, inputs directly move view.
79 STATE_MENU_OPEN, //< Input gets registered, but no events are generated, cursor enabled.
80 STATE_CURSOR //< Normal input, events get generated, but cursor enabled.
81};
82
83typedef uint16_t keyboardaction_t;
84
101
107
108const float CAMERA_SENSITIVITY = 6.0f;
109const float CAMERA_SPEED = 6.0f;
110
111void Init();
112void Uninit();
113void Update();
114void EndFrame();
115
116float GetScreenWidth();
117float GetScreenHeight();
118
119void SetWindowTitle(const char* title);
120void SetWindowSize(int w, int h);
121
122void SetCursor(CursorType cursor);
123
124void SetWebMainLoop(void(*loop_function)(void));
125
127void BindKeyboardKey(KeyboardKey key, void (*action)());
128void BindKeyboardKey(KeyboardKey key, void (*action)(KeyboardKey));
129
133
134void SetInputState(InputState state);
136
137// maybe instead of each platform calling this? these could be fed as pointers
138// into the platform?
139// TODO: fix
140void KeyPress(KeyboardKey key);
141void KeyRelease(KeyboardKey key);
142void KeyCode(uint16_t code);
143void KeyMouse(float x_value, float y_value);
144void KeyScroll(float value);
145void ScreenResize(int w, int h);
146void ScreenClose();
147
149void SetAxisSensitivity(KeyboardAxis axis, float value);
150
154
155std::vector<std::pair<keyboardaction_t, std::vector<KeyboardKey>>> GetAllKeyboardKeyBindings();
156const char* GetKeyboardKeyName(KeyboardKey key);
157
158bool ShouldExit();
159
160}
161
162#endif // TRAM_SDK_FRAMEWORK_UI_H
Definition: ui.cpp:31
keyboardaction_t RegisterKeyboardAction(const char *name)
Definition: ui.cpp:361
keyboardaction_t GetKeyboardAction(name_t name)
Definition: ui.cpp:366
const float CAMERA_SENSITIVITY
Definition: ui.h:108
float GetAxisSensitivity(KeyboardAxis key)
Definition: ui.cpp:272
void EndFrame()
Definition: ui.cpp:164
void Init()
Definition: ui.cpp:107
float PollKeyboardAxis(KeyboardAxis key)
Checks the state of an axis for the current frame.
Definition: ui.cpp:262
void SetWindowTitle(const char *title)
Definition: ui.cpp:185
void SetWindowSize(int w, int h)
Definition: ui.cpp:190
void KeyRelease(KeyboardKey key)
Definition: ui.cpp:294
void Uninit()
Definition: ui.cpp:115
float PollKeyboardAxisDelta(KeyboardAxis key)
Checks the change of an axis for since the last frame.
Definition: ui.cpp:268
bool ShouldExit()
Definition: ui.cpp:337
KeyboardAction
Definition: ui.h:85
@ KEY_ACTION_RIGHT
Definition: ui.h:98
@ KEY_ACTION_ACTIVATE
Definition: ui.h:94
@ KEY_ACTION_UP
Definition: ui.h:95
@ KEY_ACTION_NONE
Definition: ui.h:86
@ KEY_ACTION_FORWARD
Definition: ui.h:87
@ KEY_ACTION_STRAFE_RIGHT
Definition: ui.h:90
@ KEY_ACTION_STRAFE_LEFT
Definition: ui.h:89
@ KEY_ACTION_DOWN
Definition: ui.h:96
@ KEY_ACTION_BACKWARD
Definition: ui.h:88
@ KEY_ACTION_SPRINT
Definition: ui.h:93
@ KEY_ACTION_CROUCH
Definition: ui.h:92
@ KEY_ACTION_JUMP
Definition: ui.h:91
@ KEY_ACTION_LAST
Definition: ui.h:99
@ KEY_ACTION_LEFT
Definition: ui.h:97
void SetWebMainLoop(void(*loop_function)(void))
Definition: ui.cpp:168
InputState GetInputState()
Definition: ui.cpp:250
CursorType
Definition: ui.h:102
@ CURSOR_TEXT
Definition: ui.h:104
@ CURSOR_CLICK
Definition: ui.h:105
@ CURSOR_DEFAULT
Definition: ui.h:103
void KeyScroll(float value)
Definition: ui.cpp:323
const char * GetKeyboardKeyName(KeyboardKey key)
Definition: ui.cpp:416
void SetCursor(CursorType cursor)
Definition: ui.cpp:194
uint16_t keyboardaction_t
Definition: ui.h:83
float GetScreenWidth()
Definition: ui.cpp:177
bool PollKeyboardKey(KeyboardKey key)
Checks the state of a key for the current frame.
Definition: ui.cpp:256
void ScreenResize(int width, int height)
Definition: ui.cpp:327
void Update()
Definition: ui.cpp:119
std::vector< std::pair< keyboardaction_t, std::vector< KeyboardKey > > > GetAllKeyboardKeyBindings()
Definition: ui.cpp:385
float GetScreenHeight()
Definition: ui.cpp:181
void KeyMouse(float xpos, float ypos)
Definition: ui.cpp:308
void BindKeyboardKey(KeyboardKey key, keyboardaction_t action)
Definition: ui.cpp:88
KeyboardAxis
Definition: ui.h:68
@ KEY_MOUSE_X
Definition: ui.h:69
@ KEY_MOUSE_SCROLL
Definition: ui.h:71
@ KEY_MOUSE_Y
Definition: ui.h:70
@ KEY_LASTAXIS
Definition: ui.h:72
void SetAxisSensitivity(KeyboardAxis key, float value)
Definition: ui.cpp:276
void SetInputState(InputState state)
Definition: ui.cpp:214
void KeyCode(uint16_t code)
Definition: ui.cpp:304
void ScreenClose()
Definition: ui.cpp:333
KeyboardKey
Definition: ui.h:11
@ KEY_LEFT_SUPER
Definition: ui.h:54
@ KEY_F14
Definition: ui.h:44
@ KEY_SPACE
Definition: ui.h:13
@ KEY_BACKSPACE
Definition: ui.h:32
@ KEY_5
Definition: ui.h:16
@ KEY_KP_6
Definition: ui.h:47
@ KEY_6
Definition: ui.h:16
@ KEY_F8
Definition: ui.h:43
@ KEY_RIGHT_SUPER
Definition: ui.h:55
@ KEY_KP_0
Definition: ui.h:46
@ KEY_LEFT_CONTROL
Definition: ui.h:54
@ KEY_P
Definition: ui.h:23
@ KEY_DELETE
Definition: ui.h:32
@ KEY_WORLD_2
Definition: ui.h:29
@ KEY_KP_MULTIPLY
Definition: ui.h:50
@ KEY_KP_4
Definition: ui.h:46
@ KEY_LEFT
Definition: ui.h:35
@ KEY_F19
Definition: ui.h:44
@ KEY_KP_5
Definition: ui.h:46
@ KEY_Q
Definition: ui.h:23
@ KEY_LEFT_ALT
Definition: ui.h:54
@ KEY_I
Definition: ui.h:22
@ KEY_F13
Definition: ui.h:43
@ KEY_PAGE_DOWN
Definition: ui.h:38
@ KEY_KP_3
Definition: ui.h:46
@ KEY_F9
Definition: ui.h:43
@ KEY_K
Definition: ui.h:22
@ KEY_F4
Definition: ui.h:42
@ KEY_V
Definition: ui.h:23
@ KEY_KP_1
Definition: ui.h:46
@ KEY_KP_2
Definition: ui.h:46
@ KEY_KP_DECIMAL
Definition: ui.h:50
@ KEY_HOME
Definition: ui.h:38
@ KEY_E
Definition: ui.h:22
@ KEY_END
Definition: ui.h:38
@ KEY_KP_ENTER
Definition: ui.h:51
@ KEY_L
Definition: ui.h:22
@ KEY_M
Definition: ui.h:22
@ KEY_DOWN
Definition: ui.h:35
@ KEY_F18
Definition: ui.h:44
@ KEY_KP_SUBTRACT
Definition: ui.h:50
@ KEY_9
Definition: ui.h:16
@ KEY_Z
Definition: ui.h:23
@ KEY_F5
Definition: ui.h:42
@ KEY_RIGHTMOUSE
Definition: ui.h:61
@ KEY_F2
Definition: ui.h:42
@ KEY_O
Definition: ui.h:23
@ KEY_0
Definition: ui.h:16
@ KEY_PRINT_SCREEN
Definition: ui.h:39
@ KEY_LEFT_SHIFT
Definition: ui.h:54
@ KEY_G
Definition: ui.h:22
@ KEY_A
Definition: ui.h:22
@ KEY_RIGHT_SHIFT
Definition: ui.h:55
@ KEY_S
Definition: ui.h:23
@ KEY_ENTER
Definition: ui.h:32
@ KEY_COMMA
Definition: ui.h:13
@ KEY_MINUS
Definition: ui.h:13
@ KEY_F6
Definition: ui.h:42
@ KEY_APOSTROPHE
Definition: ui.h:13
@ KEY_SEMICOLON
Definition: ui.h:19
@ KEY_KP_8
Definition: ui.h:47
@ KEY_7
Definition: ui.h:16
@ KEY_KP_DIVIDE
Definition: ui.h:50
@ KEY_F17
Definition: ui.h:44
@ KEY_F11
Definition: ui.h:43
@ KEY_KP_ADD
Definition: ui.h:50
@ KEY_NUM_LOCK
Definition: ui.h:39
@ KEY_WORLD_1
Definition: ui.h:29
@ KEY_F22
Definition: ui.h:45
@ KEY_SLASH
Definition: ui.h:13
@ KEY_TAB
Definition: ui.h:32
@ KEY_N
Definition: ui.h:23
@ KEY_F20
Definition: ui.h:45
@ KEY_F23
Definition: ui.h:45
@ KEY_X
Definition: ui.h:23
@ KEY_PAGE_UP
Definition: ui.h:38
@ KEY_F12
Definition: ui.h:43
@ KEY_INSERT
Definition: ui.h:32
@ KEY_RIGHT
Definition: ui.h:35
@ KEY_LEFTMOUSE
Definition: ui.h:62
@ KEY_2
Definition: ui.h:16
@ KEY_8
Definition: ui.h:16
@ KEY_4
Definition: ui.h:16
@ KEY_F24
Definition: ui.h:45
@ KEY_KP_EQUAL
Definition: ui.h:51
@ KEY_B
Definition: ui.h:22
@ KEY_SCROLL_LOCK
Definition: ui.h:39
@ KEY_J
Definition: ui.h:22
@ KEY_F16
Definition: ui.h:44
@ KEY_ESCAPE
Definition: ui.h:32
@ KEY_F25
Definition: ui.h:45
@ KEY_UP
Definition: ui.h:35
@ KEY_MENU
Definition: ui.h:58
@ KEY_GRAVE_ACCENT
Definition: ui.h:26
@ KEY_F21
Definition: ui.h:45
@ KEY_F3
Definition: ui.h:42
@ KEY_PERIOD
Definition: ui.h:13
@ KEY_Y
Definition: ui.h:23
@ KEY_F
Definition: ui.h:22
@ KEY_D
Definition: ui.h:22
@ KEY_3
Definition: ui.h:16
@ KEY_BACKSLASH
Definition: ui.h:26
@ KEY_C
Definition: ui.h:22
@ KEY_LEFT_BRACKET
Definition: ui.h:26
@ KEY_R
Definition: ui.h:23
@ KEY_T
Definition: ui.h:23
@ KEY_U
Definition: ui.h:23
@ KEY_KP_7
Definition: ui.h:47
@ KEY_F1
Definition: ui.h:42
@ KEY_CAPS_LOCK
Definition: ui.h:39
@ KEY_F7
Definition: ui.h:43
@ KEY_RIGHT_BRACKET
Definition: ui.h:26
@ KEY_KP_9
Definition: ui.h:47
@ KEY_1
Definition: ui.h:16
@ KEY_EQUAL
Definition: ui.h:19
@ KEY_RIGHT_CONTROL
Definition: ui.h:55
@ KEY_F15
Definition: ui.h:44
@ KEY_H
Definition: ui.h:22
@ KEY_PAUSE
Definition: ui.h:39
@ KEY_W
Definition: ui.h:23
@ KEY_LASTKEY
Definition: ui.h:65
@ KEY_MIDDLEMOUSE
Definition: ui.h:63
@ KEY_RIGHT_ALT
Definition: ui.h:55
@ KEY_F10
Definition: ui.h:43
const float CAMERA_SPEED
Definition: ui.h:109
void KeyPress(KeyboardKey key)
Definition: ui.cpp:280
name_t GetKeyboardActionName(keyboardaction_t type)
Definition: ui.cpp:381
InputState
Definition: ui.h:75
@ STATE_NO_INPUT
Definition: ui.h:77
@ STATE_CURSOR
Definition: ui.h:80
@ STATE_FLYING
Definition: ui.h:78
@ STATE_DEFAULT
Definition: ui.h:76
@ STATE_MENU_OPEN
Definition: ui.h:79
Definition: uid.h:11