source: opengl-game/game-gui.hpp

feature/imgui-sdl
Last change on this file was 429ac01, checked in by Dmitry Portnoy <dportnoy@…>, 3 years ago

Remove UnknownEvent since it doesn't add any new fields and add a UI_EVENT_UNHANDLED type to distinguish between UI events I haven't considered handling at all and ones I am aware of, but do not use right now

  • Property mode set to 100644
File size: 2.1 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,
[429ac01]29 UI_EVENT_UNHANDLED,
[a0da009]30 UI_EVENT_UNKNOWN
[f6521fb]31};
32
[d8cf709]33union RawEvent {
34 SDL_Event sdl;
[f6521fb]35};
36
37struct KeyEvent {
38 EventType type;
39 unsigned int keycode;
[0ecab17]40 bool repeat;
[f6521fb]41};
42
43struct MouseEvent {
44 EventType type;
[b8d4456]45 int x;
46 int y;
[a0da009]47 /*
48 int button;
49 int action;
50 */
51};
52
[d8cf709]53struct WindowEvent {
54 EventType type;
55};
56
[83b5b4b]57struct WindowResizeEvent {
58 EventType type;
59 int width;
60 int height;
61};
62
[e1f88a9]63// TODO: Switch from union to std::variant
64
[d8cf709]65union GameEvent {
[f6521fb]66 EventType type;
67 WindowEvent window;
68 KeyEvent key;
69 MouseEvent mouse;
[83b5b4b]70 WindowResizeEvent windowResize;
[f6521fb]71};
72
[d8cf709]73struct UIEvent {
74 RawEvent rawEvent;
75 GameEvent event;
76};
77
[f898c5f]78class GameGui {
79 public:
[98f3232]80 virtual ~GameGui() {};
81
[7fc5e27]82 virtual string& getError() = 0;
[d5f2b42]83
[7fc5e27]84 virtual bool init() = 0;
85 virtual void shutdown() = 0;
[0e6ecf3]86
[7fc5e27]87 virtual void* createWindow(const string& title, int width, int height, bool fullscreen) = 0;
88 virtual void destroyWindow() = 0;
[0e6ecf3]89
[f6521fb]90 virtual void processEvents() = 0;
[d8cf709]91 virtual int pollEvent(UIEvent* uiEvent) = 0;
[cd1cb0f]92 virtual bool keyPressed(unsigned int key) = 0;
[f6521fb]93
[a6f6833]94 virtual void refreshWindowSize() = 0;
95 virtual int getWindowWidth() = 0;
96 virtual int getWindowHeight() = 0;
[27c40ce]97
[4eb4d0a]98#ifdef GAMEGUI_INCLUDE_VULKAN
[7fc5e27]99 virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0;
100 virtual vector<const char*> getRequiredExtensions() = 0;
[a6f6833]101#endif
[0e6ecf3]102};
103
[27c40ce]104#endif // _GAME_GUI_H
Note: See TracBrowser for help on using the repository browser.