| 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 |
|
|---|
| 16 | using namespace std;
|
|---|
| 17 |
|
|---|
| 18 | // TODO: See if it makes sense to combine this with the files in the gui folder
|
|---|
| 19 |
|
|---|
| 20 | enum 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_UNHANDLED,
|
|---|
| 30 | UI_EVENT_UNKNOWN
|
|---|
| 31 | };
|
|---|
| 32 |
|
|---|
| 33 | union RawEvent {
|
|---|
| 34 | SDL_Event sdl;
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | struct KeyEvent {
|
|---|
| 38 | EventType type;
|
|---|
| 39 | unsigned int keycode;
|
|---|
| 40 | bool repeat;
|
|---|
| 41 | };
|
|---|
| 42 |
|
|---|
| 43 | struct MouseEvent {
|
|---|
| 44 | EventType type;
|
|---|
| 45 | int x;
|
|---|
| 46 | int y;
|
|---|
| 47 | /*
|
|---|
| 48 | int button;
|
|---|
| 49 | int action;
|
|---|
| 50 | */
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | struct WindowEvent {
|
|---|
| 54 | EventType type;
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | struct WindowResizeEvent {
|
|---|
| 58 | EventType type;
|
|---|
| 59 | int width;
|
|---|
| 60 | int height;
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | // TODO: Switch from union to std::variant
|
|---|
| 64 |
|
|---|
| 65 | union GameEvent {
|
|---|
| 66 | EventType type;
|
|---|
| 67 | WindowEvent window;
|
|---|
| 68 | KeyEvent key;
|
|---|
| 69 | MouseEvent mouse;
|
|---|
| 70 | WindowResizeEvent windowResize;
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | struct UIEvent {
|
|---|
| 74 | RawEvent rawEvent;
|
|---|
| 75 | GameEvent event;
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | class GameGui {
|
|---|
| 79 | public:
|
|---|
| 80 | virtual ~GameGui() {};
|
|---|
| 81 |
|
|---|
| 82 | virtual string& getError() = 0;
|
|---|
| 83 |
|
|---|
| 84 | virtual bool init() = 0;
|
|---|
| 85 | virtual void shutdown() = 0;
|
|---|
| 86 |
|
|---|
| 87 | virtual void* createWindow(const string& title, int width, int height, bool fullscreen) = 0;
|
|---|
| 88 | virtual void destroyWindow() = 0;
|
|---|
| 89 |
|
|---|
| 90 | virtual void processEvents() = 0;
|
|---|
| 91 | virtual int pollEvent(UIEvent* uiEvent) = 0;
|
|---|
| 92 | virtual bool keyPressed(unsigned int key) = 0;
|
|---|
| 93 |
|
|---|
| 94 | virtual void refreshWindowSize() = 0;
|
|---|
| 95 | virtual int getWindowWidth() = 0;
|
|---|
| 96 | virtual int getWindowHeight() = 0;
|
|---|
| 97 |
|
|---|
| 98 | #ifdef GAMEGUI_INCLUDE_VULKAN
|
|---|
| 99 | virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0;
|
|---|
| 100 | virtual vector<const char*> getRequiredExtensions() = 0;
|
|---|
| 101 | #endif
|
|---|
| 102 | };
|
|---|
| 103 |
|
|---|
| 104 | #endif // _GAME_GUI_H
|
|---|