Mercurial > fife-parpg
comparison engine/core/eventchannel/eventmanager.cpp @ 111:abfe54ebae15
fix key event, patch by yonibear
author | spq@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 26 Jul 2008 17:35:02 +0000 |
parents | c512dff398c2 |
children | bb9902910067 |
comparison
equal
deleted
inserted
replaced
110:68534083e1a1 | 111:abfe54ebae15 |
---|---|
110 } else if (sdlevt.type == SDL_KEYUP) { | 110 } else if (sdlevt.type == SDL_KEYUP) { |
111 keyevt.setType(KeyEvent::RELEASED); | 111 keyevt.setType(KeyEvent::RELEASED); |
112 } else { | 112 } else { |
113 throw EventException("Invalid event type in fillKeyEvent"); | 113 throw EventException("Invalid event type in fillKeyEvent"); |
114 } | 114 } |
115 keyevt.setShiftPressed(sdlevt.key.keysym.mod & KMOD_SHIFT); | |
116 keyevt.setControlPressed(sdlevt.key.keysym.mod & KMOD_CTRL); | |
117 keyevt.setAltPressed(sdlevt.key.keysym.mod & KMOD_ALT); | |
118 keyevt.setMetaPressed(sdlevt.key.keysym.mod & KMOD_META); | |
119 keyevt.setNumericPad(sdlevt.key.keysym.sym >= SDLK_KP0 | |
120 && sdlevt.key.keysym.sym <= SDLK_KP_EQUALS); | |
121 | |
122 SDL_keysym keysym = sdlevt.key.keysym; | 115 SDL_keysym keysym = sdlevt.key.keysym; |
123 Key::KeyType value = Key::INVALID_KEY; | 116 |
124 std::string repr(""); | 117 keyevt.setShiftPressed(keysym.mod & KMOD_SHIFT); |
125 | 118 keyevt.setControlPressed(keysym.mod & KMOD_CTRL); |
126 if (keysym.unicode < 255) { | 119 keyevt.setAltPressed(keysym.mod & KMOD_ALT); |
127 value = static_cast<Key::KeyType>(keysym.unicode); | 120 keyevt.setMetaPressed(keysym.mod & KMOD_META); |
128 repr.push_back(value); | 121 keyevt.setNumericPad(keysym.sym >= SDLK_KP0 && keysym.sym <= SDLK_KP_EQUALS); |
129 } | 122 keyevt.setKey(Key(static_cast<Key::KeyType>(keysym.sym), keysym.unicode)); |
130 | |
131 #define MAP_KEY(_orig, _new) case _orig: value = _new; repr = #_new; break; | |
132 switch (keysym.sym) { | |
133 MAP_KEY(SDLK_TAB, Key::TAB); | |
134 MAP_KEY(SDLK_LALT, Key::LEFT_ALT); | |
135 MAP_KEY(SDLK_RALT, Key::RIGHT_ALT); | |
136 MAP_KEY(SDLK_LSHIFT, Key::LEFT_SHIFT); | |
137 MAP_KEY(SDLK_RSHIFT, Key::RIGHT_SHIFT); | |
138 MAP_KEY(SDLK_LCTRL, Key::LEFT_CONTROL); | |
139 MAP_KEY(SDLK_RCTRL, Key::RIGHT_CONTROL); | |
140 MAP_KEY(SDLK_BACKSPACE, Key::BACKSPACE); | |
141 MAP_KEY(SDLK_PAUSE, Key::PAUSE); | |
142 MAP_KEY(SDLK_ESCAPE, Key::ESCAPE); | |
143 MAP_KEY(SDLK_DELETE, Key::DELETE_KEY); | |
144 MAP_KEY(SDLK_INSERT, Key::INSERT); | |
145 MAP_KEY(SDLK_HOME, Key::HOME); | |
146 MAP_KEY(SDLK_END, Key::END); | |
147 MAP_KEY(SDLK_PAGEUP, Key::PAGE_UP); | |
148 MAP_KEY(SDLK_PRINT, Key::PRINT_SCREEN); | |
149 MAP_KEY(SDLK_PAGEDOWN, Key::PAGE_DOWN); | |
150 MAP_KEY(SDLK_F1, Key::F1); | |
151 MAP_KEY(SDLK_F2, Key::F2); | |
152 MAP_KEY(SDLK_F3, Key::F3); | |
153 MAP_KEY(SDLK_F4, Key::F4); | |
154 MAP_KEY(SDLK_F5, Key::F5); | |
155 MAP_KEY(SDLK_F6, Key::F6); | |
156 MAP_KEY(SDLK_F7, Key::F7); | |
157 MAP_KEY(SDLK_F8, Key::F8); | |
158 MAP_KEY(SDLK_F9, Key::F9); | |
159 MAP_KEY(SDLK_F10, Key::F10); | |
160 MAP_KEY(SDLK_F11, Key::F11); | |
161 MAP_KEY(SDLK_F12, Key::F12); | |
162 MAP_KEY(SDLK_F13, Key::F13); | |
163 MAP_KEY(SDLK_F14, Key::F14); | |
164 MAP_KEY(SDLK_F15, Key::F15); | |
165 MAP_KEY(SDLK_NUMLOCK, Key::NUM_LOCK); | |
166 MAP_KEY(SDLK_CAPSLOCK, Key::CAPS_LOCK); | |
167 MAP_KEY(SDLK_SCROLLOCK, Key::SCROLL_LOCK); | |
168 MAP_KEY(SDLK_RMETA, Key::RIGHT_META); | |
169 MAP_KEY(SDLK_LMETA, Key::LEFT_META); | |
170 MAP_KEY(SDLK_LSUPER, Key::LEFT_SUPER); | |
171 MAP_KEY(SDLK_RSUPER, Key::RIGHT_SUPER); | |
172 MAP_KEY(SDLK_MODE, Key::ALT_GR); | |
173 MAP_KEY(SDLK_UP, Key::UP); | |
174 MAP_KEY(SDLK_DOWN, Key::DOWN); | |
175 MAP_KEY(SDLK_LEFT, Key::LEFT); | |
176 MAP_KEY(SDLK_RIGHT, Key::RIGHT); | |
177 MAP_KEY(SDLK_RETURN, Key::ENTER); | |
178 MAP_KEY(SDLK_KP_ENTER, Key::ENTER); | |
179 case SDLK_SPACE: | |
180 // Special characters like ~ (tilde) ends up with the keysym.sym SDLK_SPACE which | |
181 // without this check would be lost. The check is only valid on key down events in SDL. | |
182 if (sdlevt.type == SDL_KEYUP || keysym.unicode == ' ') { | |
183 value = Key::SPACE; | |
184 } | |
185 break; | |
186 default: | |
187 break; | |
188 } | |
189 | |
190 if (!(keysym.mod & KMOD_NUM)) { | |
191 switch (keysym.sym) { | |
192 MAP_KEY(SDLK_KP0, Key::INSERT); | |
193 MAP_KEY(SDLK_KP1, Key::END); | |
194 MAP_KEY(SDLK_KP2, Key::DOWN); | |
195 MAP_KEY(SDLK_KP3, Key::PAGE_DOWN); | |
196 MAP_KEY(SDLK_KP4, Key::LEFT); | |
197 MAP_KEY(SDLK_KP5, Key::INVALID_KEY); | |
198 MAP_KEY(SDLK_KP6, Key::RIGHT); | |
199 MAP_KEY(SDLK_KP7, Key::HOME); | |
200 MAP_KEY(SDLK_KP8, Key::UP); | |
201 MAP_KEY(SDLK_KP9, Key::PAGE_UP); | |
202 default: | |
203 break; | |
204 } | |
205 } | |
206 | |
207 keyevt.setKey(Key(value, repr)); | |
208 } | 123 } |
209 | 124 |
210 template<typename T> | 125 template<typename T> |
211 void removeListener(std::vector<T>& vec, T& listener) { | 126 void removeListener(std::vector<T>& vec, T& listener) { |
212 vec.push_back(listener); | 127 vec.push_back(listener); |