Changeset 7bf5433 in opengl-game for game-gui-glfw.cpp
- Timestamp:
- Sep 12, 2019, 5:23:28 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- d2f607c
- Parents:
- 27c40ce
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-glfw.cpp
r27c40ce r7bf5433 1 1 #include "game-gui-glfw.hpp" 2 3 #include <queue> 2 4 3 5 #include "compiler.hpp" 4 6 #include "consts.hpp" 5 7 6 const int KEY_STATE_UNCHANGED = -1; 8 int GameGui_GLFW::s_keyState[GLFW_KEY_LAST]; 9 bool GameGui_GLFW::s_keyDown[GLFW_KEY_LAST]; 10 11 // queue<MouseEvent> mouseEvents; 7 12 8 13 string GameGui_GLFW::s_errorMessage; 9 10 int GameGui_GLFW::s_keyState[NUM_KEYS];11 bool GameGui_GLFW::s_keyDown[NUM_KEYS];12 14 13 15 string& GameGui_GLFW::getError() { … … 62 64 //glfwMakeContextCurrent(window); 63 65 64 //glfwSetMouseButtonCallback(window,mouse_button_callback);66 glfwSetMouseButtonCallback(window, glfw_mouse_button_callback); 65 67 glfwSetKeyCallback(window, glfw_key_callback); 66 68 67 fill(GameGui_GLFW::s_keyState, GameGui_GLFW::s_keyState + NUM_KEYS, KEY_STATE_UNCHANGED); 69 // fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE); 70 // fill(s_keyDown, s_keyDown + GLFW_KEY_LAST, false); 68 71 69 72 return window; … … 74 77 glfwDestroyWindow(window); 75 78 } 79 80 /* 81 void GameGui_GLFW::processEvents() { 82 fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE); 83 84 glfwPollEvents(); 85 } 86 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()) { 97 return 0; 98 } 99 100 *event = mouseEvents.front(); 101 mouseEvents.pop(); 102 103 return 1; 104 } 105 */ 76 106 77 107 #ifdef GAMEGUI_INCLUDE_VULKAN … … 107 137 } 108 138 139 void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { 140 double x, y; 141 glfwGetCursorPos(window, &x, &y); 142 143 /* 144 MouseEvent e { button, action, (int)x, (int)y }; 145 146 mouseEvents.push(e); 147 */ 148 } 149 109 150 void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { 110 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 } 111 164 112 165 // should be true for GLFW_PRESS and GLFW_REPEAT 113 166 GameGui_GLFW::s_keyDown[key] = (action != GLFW_RELEASE); 167 */ 114 168 }
Note:
See TracChangeset
for help on using the changeset viewer.