Changeset c61323a in opengl-game for game-gui-glfw.cpp
- Timestamp:
- Sep 13, 2019, 2:51:30 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1fcca9e
- Parents:
- f6521fb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-glfw.cpp
rf6521fb rc61323a 1 1 #include "game-gui-glfw.hpp" 2 3 #include <queue>4 2 5 3 #include "compiler.hpp" 6 4 #include "consts.hpp" 7 5 8 int GameGui_GLFW::s_keyState[GLFW_KEY_LAST]; 9 bool GameGui_GLFW::s_keyDown[GLFW_KEY_LAST]; 10 11 // queue<MouseEvent> mouseEvents; 12 6 queue<UIEvent> GameGui_GLFW::s_events; 13 7 string GameGui_GLFW::s_errorMessage; 14 8 … … 32 26 33 27 void* GameGui_GLFW::createWindow(const string& title, int width, int height, bool fullscreen) { 34 GLFWwindow* window = nullptr;35 28 GLFWmonitor* mon = nullptr; 36 29 … … 62 55 63 56 window = glfwCreateWindow(windowWidth, windowHeight, title.c_str(), mon, nullptr); 64 //glfwMakeContextCurrent(window);65 57 66 58 glfwSetMouseButtonCallback(window, glfw_mouse_button_callback); 67 59 glfwSetKeyCallback(window, glfw_key_callback); 68 69 // fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);70 // fill(s_keyDown, s_keyDown + GLFW_KEY_LAST, false);71 60 72 61 return window; … … 78 67 } 79 68 80 /*81 69 void GameGui_GLFW::processEvents() { 82 fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);70 glfwPollEvents(); 83 71 84 glfwPollEvents(); 72 if (glfwWindowShouldClose(window)) { 73 UIEvent e; 74 e.type = UI_EVENT_QUIT; 75 76 s_events.push(e); 77 } 85 78 } 86 79 87 unsigned char GameGui_GLFW::getKeyEvent(unsigned int key) { 88 return s_keyState[key]; 89 } 90 91 bool GameGui_GLFW::isKeyPressed(unsigned int key) { 92 return s_keyDown[key]; 93 } 94 95 int GameGui_GLFW::pollMouseEvent(MouseEvent* event) { 96 if (mouseEvents.empty()) { 80 int GameGui_GLFW::pollEvent(UIEvent* event) { 81 if (s_events.empty()) { 97 82 return 0; 98 83 } 99 84 100 *event = mouseEvents.front();101 mouseEvents.pop();85 *event = s_events.front(); 86 s_events.pop(); 102 87 103 88 return 1; 104 89 } 105 */106 90 107 91 #ifdef GAMEGUI_INCLUDE_VULKAN … … 149 133 150 134 void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { 151 GameGui_GLFW::s_keyState[key] = action; 152 /* 153 switch(action) { 154 case GLFW_PRESS: 155 s_keyState[key] = RTWO_KEY_EVENT_PRESSED; 156 break; 157 case GLFW_RELEASE: 158 s_keyState[key] = RTWO_KEY_EVENT_RELEASED; 159 break; 160 default: 161 s_keyState[key] = RTWO_KEY_EVENT_NONE; 162 break; 163 } 135 UIEvent e; 136 e.type = UI_EVENT_KEY; 137 e.key.keycode = key; 164 138 165 // should be true for GLFW_PRESS and GLFW_REPEAT 166 GameGui_GLFW::s_keyDown[key] = (action != GLFW_RELEASE); 167 */ 139 GameGui_GLFW::s_events.push(e); 168 140 }
Note:
See TracChangeset
for help on using the changeset viewer.