[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] | 16 | using namespace std;
|
---|
| 17 |
|
---|
[e1f88a9] | 18 | // TODO: See if it makes sense to combine this with the files in the gui folder
|
---|
| 19 |
|
---|
[f6521fb] | 20 | enum 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] | 33 | union RawEvent {
|
---|
| 34 | SDL_Event sdl;
|
---|
[f6521fb] | 35 | };
|
---|
| 36 |
|
---|
| 37 | struct KeyEvent {
|
---|
| 38 | EventType type;
|
---|
| 39 | unsigned int keycode;
|
---|
[0ecab17] | 40 | bool repeat;
|
---|
[f6521fb] | 41 | };
|
---|
| 42 |
|
---|
| 43 | struct MouseEvent {
|
---|
| 44 | EventType type;
|
---|
[b8d4456] | 45 | int x;
|
---|
| 46 | int y;
|
---|
[a0da009] | 47 | /*
|
---|
| 48 | int button;
|
---|
| 49 | int action;
|
---|
| 50 | */
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[d8cf709] | 53 | struct WindowEvent {
|
---|
| 54 | EventType type;
|
---|
| 55 | };
|
---|
| 56 |
|
---|
[83b5b4b] | 57 | struct WindowResizeEvent {
|
---|
| 58 | EventType type;
|
---|
| 59 | int width;
|
---|
| 60 | int height;
|
---|
| 61 | };
|
---|
| 62 |
|
---|
[e1f88a9] | 63 | // TODO: Switch from union to std::variant
|
---|
| 64 |
|
---|
[d8cf709] | 65 | union GameEvent {
|
---|
[f6521fb] | 66 | EventType type;
|
---|
| 67 | WindowEvent window;
|
---|
| 68 | KeyEvent key;
|
---|
| 69 | MouseEvent mouse;
|
---|
[83b5b4b] | 70 | WindowResizeEvent windowResize;
|
---|
[f6521fb] | 71 | };
|
---|
| 72 |
|
---|
[d8cf709] | 73 | struct UIEvent {
|
---|
| 74 | RawEvent rawEvent;
|
---|
| 75 | GameEvent event;
|
---|
| 76 | };
|
---|
| 77 |
|
---|
[f898c5f] | 78 | class 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
|
---|