source: opengl-game/game-gui.hpp@ ea2b4dc

feature/imgui-sdl
Last change on this file since ea2b4dc was d8cf709, checked in by Dmitry Portnoy <dportnoy@…>, 4 years ago

Change UIEvent to also include the original event from the UI library the game gui is currently using, such as SDL or GLFW.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#ifndef _GAME_GUI_H
2#define _GAME_GUI_H
3
4#include <string>
5#include <vector>
6
7#ifdef GAMEGUI_INCLUDE_VULKAN
8 #include <vulkan/vulkan.h>
9#endif
10
11// These are included here so I can implement the RawEvent union, which requires knowledge
12// of the ui event types of all ui libraries I might use for any of the GameGui clases
13// GLFW does not have its own event type though, so SDL is currently the only library this is done for
14#include <SDL2/SDL.h>
15
16using namespace std;
17
18// TODO: See if it makes sense to combine this with the files in the gui folder
19
20enum EventType {
21 UI_EVENT_QUIT,
22 UI_EVENT_WINDOW,
23 UI_EVENT_WINDOWRESIZE,
24 UI_EVENT_KEYDOWN,
25 UI_EVENT_KEYUP,
26 UI_EVENT_MOUSEBUTTONDOWN,
27 UI_EVENT_MOUSEBUTTONUP,
28 UI_EVENT_MOUSEMOTION,
29 UI_EVENT_UNKNOWN
30};
31
32union RawEvent {
33 SDL_Event sdl;
34};
35
36struct KeyEvent {
37 EventType type;
38 unsigned int keycode;
39 bool repeat;
40};
41
42struct MouseEvent {
43 EventType type;
44 int x;
45 int y;
46 /*
47 int button;
48 int action;
49 */
50};
51
52struct WindowEvent {
53 EventType type;
54};
55
56struct WindowResizeEvent {
57 EventType type;
58 int width;
59 int height;
60};
61
62struct UnknownEvent {
63 EventType type;
64};
65
66// TODO: Switch from union to std::variant
67
68union GameEvent {
69 EventType type;
70 WindowEvent window;
71 KeyEvent key;
72 MouseEvent mouse;
73 WindowResizeEvent windowResize;
74 UnknownEvent unknown;
75};
76
77struct UIEvent {
78 RawEvent rawEvent;
79 GameEvent event;
80};
81
82class GameGui {
83 public:
84 virtual ~GameGui() {};
85
86 virtual string& getError() = 0;
87
88 virtual bool init() = 0;
89 virtual void shutdown() = 0;
90
91 virtual void* createWindow(const string& title, int width, int height, bool fullscreen) = 0;
92 virtual void destroyWindow() = 0;
93
94 virtual void processEvents() = 0;
95 virtual int pollEvent(UIEvent* uiEvent) = 0;
96 virtual bool keyPressed(unsigned int key) = 0;
97
98 virtual void refreshWindowSize() = 0;
99 virtual int getWindowWidth() = 0;
100 virtual int getWindowHeight() = 0;
101
102#ifdef GAMEGUI_INCLUDE_VULKAN
103 virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0;
104 virtual vector<const char*> getRequiredExtensions() = 0;
105#endif
106};
107
108#endif // _GAME_GUI_H
Note: See TracBrowser for help on using the repository browser.