Changeset f6521fb in opengl-game for game-gui-sdl.cpp
- Timestamp:
- Sep 13, 2019, 1:30:24 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- c61323a
- Parents:
- 203ab1b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-sdl.cpp
r203ab1b rf6521fb 5 5 6 6 #include "consts.hpp" 7 8 map<unsigned int, unsigned char> s_keyState;9 map<unsigned int, bool> s_keyDown;10 7 11 8 using namespace std; … … 81 78 } 82 79 83 /*84 80 void GameGui_SDL::processEvents() { 81 } 82 83 int GameGui_SDL::pollEvent(UIEvent* event) { 85 84 SDL_Event e; 86 85 87 s_keyState.clear(); 88 while (SDL_PollEvent(&e)) { 89 if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP) { 90 if (e.type == SDL_KEYDOWN && !e.key.repeat) { 91 s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_PRESSED; 92 } else if (e.type == SDL_KEYUP) { 93 s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_RELEASED; 94 } else { 95 s_keyState.erase(e.key.keysym.sym); 96 } 86 /* The trackpad on OSX triggers both SDL_MOUSE and SDL_FINGER events, so just treat them both 87 * as mouse events since this game isn't targeting mobile devices 88 */ 97 89 98 s_keyDown[e.key.keysym.sym] = e.type == SDL_KEYDOWN; 99 } else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) { 100 MouseEvent mouseEvent { 0, 0, e.button.x, e.button.y }; 90 if (SDL_PollEvent(&e)) { 91 switch(e.type) { 92 case SDL_QUIT: 93 event->type = UI_EVENT_QUIT; 94 break; 95 case SDL_WINDOWEVENT: 96 event->type = UI_EVENT_WINDOW; 97 break; 98 case SDL_KEYUP: 99 case SDL_KEYDOWN: 100 event->type = UI_EVENT_KEY; 101 event->key.keycode = e.key.keysym.scancode; 102 break; 103 case SDL_MOUSEBUTTONDOWN: 104 case SDL_FINGERDOWN: 105 event->type = UI_EVENT_MOUSEBUTTONDOWN; 106 break; 107 case SDL_MOUSEBUTTONUP: 108 case SDL_FINGERUP: 109 event->type = UI_EVENT_MOUSEBUTTONUP; 110 break; 111 case SDL_MOUSEMOTION: 112 case SDL_FINGERMOTION: 113 event->type = UI_EVENT_MOUSEMOTION; 114 break; 115 // Ignore the following events 116 case SDL_AUDIODEVICEADDED: 117 case SDL_AUDIODEVICEREMOVED: 118 event = nullptr; 119 return 0; 120 break; 121 default: 122 cout << "Unknown event type: 0x" << hex << e.type << dec << endl; 123 event = nullptr; 124 return 0; 125 } 101 126 102 mouseEvents.push(mouseEvent); 103 } else { 104 events.push(e); 105 } 106 } 107 } 108 109 int GameGui_SDL::pollMouseEvent(MouseEvent* event) { 110 if (mouseEvents.empty()) { 111 return 0; 127 return 1; 112 128 } 113 129 114 *event = mouseEvents.front(); 115 mouseEvents.pop(); 116 117 return 1; 130 event = nullptr; 131 return 0; 118 132 } 119 120 unsigned char GameGui_SDL::getKeyEvent(unsigned int key) {121 if (s_keyDown.count(key)) {122 return s_keyState[key];123 } else {124 return RTWO_KEY_EVENT_NONE;125 }126 }127 128 bool GameGui_SDL::isKeyPressed(unsigned int key) {129 if (s_keyDown.count(key)) {130 return s_keyDown[key];131 } else {132 return false;133 }134 }135 136 int GameGui_SDL::pollEvent(SDL_Event* event) {137 if (events.empty()) {138 return 0;139 }140 141 *event = events.front();142 events.pop();143 144 return 1;145 }146 */147 133 148 134 #ifdef GAMEGUI_INCLUDE_VULKAN
Note:
See TracChangeset
for help on using the changeset viewer.