Changeset d8cf709 in opengl-game
- Timestamp:
- Feb 13, 2021, 11:41:39 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- c6f0793
- Parents:
- 8b823e7
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-glfw.cpp
r8b823e7 rd8cf709 79 79 if (glfwWindowShouldClose(window)) { 80 80 UIEvent e; 81 e. type = UI_EVENT_QUIT;81 e.event.type = UI_EVENT_QUIT; 82 82 83 83 s_events.push(e); … … 147 147 void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { 148 148 UIEvent e; 149 e. type = action == GLFW_RELEASE ? UI_EVENT_KEYUP : UI_EVENT_KEYDOWN;150 e. key.keycode = key;149 e.event.type = action == GLFW_RELEASE ? UI_EVENT_KEYUP : UI_EVENT_KEYDOWN; 150 e.event.key.keycode = key; 151 151 152 152 GameGui_GLFW::s_events.push(e); … … 155 155 void glfw_window_size_callback(GLFWwindow* window, int width, int height) { 156 156 UIEvent e; 157 e. type = UI_EVENT_WINDOWRESIZE;158 e. windowResize.width = width;159 e. windowResize.height = height;157 e.event.type = UI_EVENT_WINDOWRESIZE; 158 e.event.windowResize.width = width; 159 e.event.windowResize.height = height; 160 160 161 161 GameGui_GLFW::s_events.push(e); -
game-gui-sdl.cpp
r8b823e7 rd8cf709 79 79 } 80 80 81 int GameGui_SDL::pollEvent(UIEvent* event) {81 int GameGui_SDL::pollEvent(UIEvent* uiEvent) { 82 82 SDL_Event e; 83 83 … … 87 87 88 88 if (SDL_PollEvent(&e)) { 89 uiEvent->rawEvent.sdl = e; 90 91 GameEvent* event = &uiEvent->event; 92 89 93 switch(e.type) { 90 94 case SDL_QUIT: … … 93 97 case SDL_WINDOWEVENT: 94 98 if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED || 95 e.window.event == SDL_WINDOWEVENT_MINIMIZED ||96 e.window.event == SDL_WINDOWEVENT_MAXIMIZED) {99 e.window.event == SDL_WINDOWEVENT_MINIMIZED || 100 e.window.event == SDL_WINDOWEVENT_MAXIMIZED) { 97 101 event->type = UI_EVENT_WINDOWRESIZE; 102 } else if (e.window.event == SDL_WINDOWEVENT_CLOSE && 103 e.window.windowID == SDL_GetWindowID(window)) { 104 event->type = UI_EVENT_QUIT; 98 105 } else { 99 106 event->type = UI_EVENT_WINDOW; … … 122 129 event->mouse.y = e.motion.y; 123 130 case SDL_FINGERMOTION: 131 // TODO: Get coordinates for finger events 124 132 event->type = UI_EVENT_MOUSEMOTION; 125 133 break; 126 // Ignore the following events134 // The following events are not currently supported 127 135 case SDL_AUDIODEVICEADDED: 128 136 case SDL_AUDIODEVICEREMOVED: 129 137 case SDL_TEXTINPUT: 130 138 case SDL_TEXTEDITING: 139 case SDL_MOUSEWHEEL: 131 140 event->type = UI_EVENT_UNKNOWN; 132 event->unknown.eventType = e.type;133 141 break; 134 142 default: 135 143 event->type = UI_EVENT_UNKNOWN; 136 event->unknown.eventType = 0;137 144 } 138 145 139 146 return 1; 147 } else { 148 return 0; 140 149 } 141 142 event = nullptr;143 return 0;144 150 } 145 151 -
game-gui-sdl.hpp
r8b823e7 rd8cf709 23 23 24 24 void processEvents(); 25 int pollEvent(UIEvent* event);25 int pollEvent(UIEvent* uiEvent); 26 26 bool keyPressed(unsigned int key); 27 27 -
game-gui.hpp
r8b823e7 rd8cf709 8 8 #include <vulkan/vulkan.h> 9 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> 10 15 11 16 using namespace std; … … 25 30 }; 26 31 27 struct WindowEvent {28 EventType type;32 union RawEvent { 33 SDL_Event sdl; 29 34 }; 30 35 … … 45 50 }; 46 51 52 struct WindowEvent { 53 EventType type; 54 }; 55 47 56 struct WindowResizeEvent { 48 57 EventType type; … … 53 62 struct UnknownEvent { 54 63 EventType type; 55 unsigned int eventType;56 64 }; 57 65 58 66 // TODO: Switch from union to std::variant 59 67 60 union UIEvent {68 union GameEvent { 61 69 EventType type; 62 70 WindowEvent window; … … 65 73 WindowResizeEvent windowResize; 66 74 UnknownEvent unknown; 75 }; 76 77 struct UIEvent { 78 RawEvent rawEvent; 79 GameEvent event; 67 80 }; 68 81 … … 80 93 81 94 virtual void processEvents() = 0; 82 virtual int pollEvent(UIEvent* event) = 0;95 virtual int pollEvent(UIEvent* uiEvent) = 0; 83 96 virtual bool keyPressed(unsigned int key) = 0; 84 97 -
gui/button.cpp
r8b823e7 rd8cf709 87 87 } 88 88 89 void Button::handleEvent( UIEvent& e) {89 void Button::handleEvent(GameEvent& e) { 90 90 switch(e.type) { 91 91 case UI_EVENT_MOUSEMOTION: -
gui/button.hpp
r8b823e7 rd8cf709 21 21 void init() override; 22 22 void render(int x, int y) override; 23 void handleEvent( UIEvent& e) override;23 void handleEvent(GameEvent& e) override; 24 24 25 25 private: -
gui/game-screen.cpp
r8b823e7 rd8cf709 49 49 } 50 50 51 void GameScreen::handleEvent( UIEvent& e) {51 void GameScreen::handleEvent(GameEvent& e) { 52 52 Screen::handleEvent(e); 53 53 } -
gui/game-screen.hpp
r8b823e7 rd8cf709 13 13 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage) override; 14 14 15 void handleEvent( UIEvent& e) override;15 void handleEvent(GameEvent& e) override; 16 16 }; 17 17 -
gui/main-screen.cpp
r8b823e7 rd8cf709 21 21 } 22 22 23 void MainScreen::handleEvent( UIEvent& e) {23 void MainScreen::handleEvent(GameEvent& e) { 24 24 Screen::handleEvent(e); 25 25 } -
gui/main-screen.hpp
r8b823e7 rd8cf709 13 13 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage) override; 14 14 15 void handleEvent( UIEvent& e) override;15 void handleEvent(GameEvent& e) override; 16 16 }; 17 17 -
gui/panel.cpp
r8b823e7 rd8cf709 72 72 } 73 73 74 void Panel::handleEvent( UIEvent& e) {74 void Panel::handleEvent(GameEvent& e) { 75 75 for (UIElement*& uiElement : this->uiElements) { 76 76 uiElement->handleEvent(e); -
gui/panel.hpp
r8b823e7 rd8cf709 19 19 20 20 void render(int x, int y) override; 21 void handleEvent( UIEvent& e) override;21 void handleEvent(GameEvent& e) override; 22 22 23 23 private: -
gui/screen.cpp
r8b823e7 rd8cf709 29 29 } 30 30 31 void Screen::handleEvent( UIEvent& e) {31 void Screen::handleEvent(GameEvent& e) { 32 32 for (UIElement*& uiElement : this->uiElements) { 33 33 uiElement->handleEvent(e); -
gui/screen.hpp
r8b823e7 rd8cf709 17 17 class VulkanGame; 18 18 19 template<class Type>20 struct ValueReference {21 22 };23 24 19 // TODO: Add a function to create an SDL_Color from a uint32_t 25 20 … … 34 29 35 30 virtual void renderUI(); 36 virtual void handleEvent( UIEvent& e);31 virtual void handleEvent(GameEvent& e); 37 32 void addUIElement(UIElement* element); 38 33 -
gui/ui-element.cpp
r8b823e7 rd8cf709 21 21 } 22 22 23 void UIElement::handleEvent( UIEvent& e) {23 void UIElement::handleEvent(GameEvent& e) { 24 24 } -
gui/ui-element.hpp
r8b823e7 rd8cf709 18 18 virtual void init(); 19 19 virtual void render(int x, int y) = 0; 20 virtual void handleEvent( UIEvent& e);20 virtual void handleEvent(GameEvent& e); 21 21 22 22 protected: -
main-vulkan.cpp
r8b823e7 rd8cf709 4 4 #include "crash-logger.hpp" 5 5 6 //#include "vulkan-game.hpp"7 #include "sdl-game.hpp"6 #include "vulkan-game.hpp" 7 //#include "sdl-game.hpp" 8 8 9 9 using namespace std; … … 24 24 25 25 try { 26 //game.run(800, 600, 0);26 game.run(800, 600, 0); 27 27 //game.run(800, 600, GUI_FLAGS_WINDOW_FULLSCREEN); 28 game.run(1280, 720, 0);29 28 } catch (const exception& e) { 30 29 cerr << e.what() << endl; -
opengl-game.cpp
r8b823e7 rd8cf709 160 160 161 161 void OpenGLGame::mainLoop() { 162 UIEvent e;162 UIEvent uiEvent; 163 163 bool quit = false; 164 164 … … 166 166 gui->processEvents(); 167 167 168 while (gui->pollEvent(&e)) { 168 while (gui->pollEvent(&uiEvent)) { 169 GameEvent& e = uiEvent.event; 170 169 171 switch (e.type) { 170 172 case UI_EVENT_QUIT: -
opengl-game.hpp
r8b823e7 rd8cf709 4 4 #include <glm/glm.hpp> 5 5 6 // TODO: Rewrite this to work with the new version of IMGUI 6 7 #include "IMGUI/imgui.h" 7 8 #include "imgui_impl_glfw_gl3.h" -
vulkan-game.cpp
r8b823e7 rd8cf709 771 771 772 772 void VulkanGame::mainLoop() { 773 UIEvent e;774 773 this->quit = false; 775 774 … … 799 798 gui->processEvents(); 800 799 801 while (gui->pollEvent(&e)) { 800 UIEvent uiEvent; 801 while (gui->pollEvent(&uiEvent)) { 802 GameEvent& e = uiEvent.event; 803 802 804 switch(e.type) { 803 805 case UI_EVENT_QUIT:
Note:
See TracChangeset
for help on using the changeset viewer.