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

feature/imgui-sdl
Last change on this file since d8cf709 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
RevLine 
[0e6ecf3]1#ifndef _GAME_GUI_H
2#define _GAME_GUI_H
3
[9546928]4#include <string>
5#include <vector>
6
[4eb4d0a]7#ifdef GAMEGUI_INCLUDE_VULKAN
8 #include <vulkan/vulkan.h>
9#endif
[0e6ecf3]10
[d8cf709]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
[0e6ecf3]16using namespace std;
17
[e1f88a9]18// TODO: See if it makes sense to combine this with the files in the gui folder
19
[f6521fb]20enum EventType {
21 UI_EVENT_QUIT,
22 UI_EVENT_WINDOW,
[0e09340]23 UI_EVENT_WINDOWRESIZE,
[5a23277]24 UI_EVENT_KEYDOWN,
25 UI_EVENT_KEYUP,
[f6521fb]26 UI_EVENT_MOUSEBUTTONDOWN,
27 UI_EVENT_MOUSEBUTTONUP,
[a0da009]28 UI_EVENT_MOUSEMOTION,
29 UI_EVENT_UNKNOWN
[f6521fb]30};
31
[d8cf709]32union RawEvent {
33 SDL_Event sdl;
[f6521fb]34};
35
36struct KeyEvent {
37 EventType type;
38 unsigned int keycode;
[0ecab17]39 bool repeat;
[f6521fb]40};
41
42struct MouseEvent {
43 EventType type;
[b8d4456]44 int x;
45 int y;
[a0da009]46 /*
47 int button;
48 int action;
49 */
50};
51
[d8cf709]52struct WindowEvent {
53 EventType type;
54};
55
[83b5b4b]56struct WindowResizeEvent {
57 EventType type;
58 int width;
59 int height;
60};
61
[a0da009]62struct UnknownEvent {
63 EventType type;
[f6521fb]64};
65
[e1f88a9]66// TODO: Switch from union to std::variant
67
[d8cf709]68union GameEvent {
[f6521fb]69 EventType type;
70 WindowEvent window;
71 KeyEvent key;
72 MouseEvent mouse;
[83b5b4b]73 WindowResizeEvent windowResize;
[a0da009]74 UnknownEvent unknown;
[f6521fb]75};
76
[d8cf709]77struct UIEvent {
78 RawEvent rawEvent;
79 GameEvent event;
80};
81
[f898c5f]82class GameGui {
83 public:
[98f3232]84 virtual ~GameGui() {};
85
[7fc5e27]86 virtual string& getError() = 0;
[d5f2b42]87
[7fc5e27]88 virtual bool init() = 0;
89 virtual void shutdown() = 0;
[0e6ecf3]90
[7fc5e27]91 virtual void* createWindow(const string& title, int width, int height, bool fullscreen) = 0;
92 virtual void destroyWindow() = 0;
[0e6ecf3]93
[f6521fb]94 virtual void processEvents() = 0;
[d8cf709]95 virtual int pollEvent(UIEvent* uiEvent) = 0;
[cd1cb0f]96 virtual bool keyPressed(unsigned int key) = 0;
[f6521fb]97
[a6f6833]98 virtual void refreshWindowSize() = 0;
99 virtual int getWindowWidth() = 0;
100 virtual int getWindowHeight() = 0;
[27c40ce]101
[4eb4d0a]102#ifdef GAMEGUI_INCLUDE_VULKAN
[7fc5e27]103 virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0;
104 virtual vector<const char*> getRequiredExtensions() = 0;
[a6f6833]105#endif
[0e6ecf3]106};
107
[27c40ce]108#endif // _GAME_GUI_H
Note: See TracBrowser for help on using the repository browser.