comparison engine/core/gui/guimanager.cpp @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents 09f40db3f10c
children b84dbc4665b0
comparison
equal deleted inserted replaced
254:10b5f7f36dd4 255:51cc05d862f2
23 #include <iostream> 23 #include <iostream>
24 24
25 // 3rd party library includes 25 // 3rd party library includes
26 #include <boost/filesystem/convenience.hpp> 26 #include <boost/filesystem/convenience.hpp>
27 #include <guichan/sdl/sdlinput.hpp> 27 #include <guichan/sdl/sdlinput.hpp>
28 #include <guichan/key.hpp>
28 #include <guichan/focushandler.hpp> 29 #include <guichan/focushandler.hpp>
29 #include <guichan.hpp> 30 #include <guichan.hpp>
30 31
31 // FIFE includes 32 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line 33 // These includes are split up in two parts, separated by one empty line
39 #include "gui/base/gui_font.h" 40 #include "gui/base/gui_font.h"
40 #include "gui/console/console.h" 41 #include "gui/console/console.h"
41 #include "video/fonts/fontbase.h" 42 #include "video/fonts/fontbase.h"
42 #include "video/fonts/truetypefont.h" 43 #include "video/fonts/truetypefont.h"
43 #include "video/fonts/subimagefont.h" 44 #include "video/fonts/subimagefont.h"
45 #include "eventchannel/key/ec_key.h"
44 #include "eventchannel/key/ec_keyevent.h" 46 #include "eventchannel/key/ec_keyevent.h"
45 #include "eventchannel/mouse/ec_mouseevent.h" 47 #include "eventchannel/mouse/ec_mouseevent.h"
46 48
47 #include "guimanager.h" 49 #include "guimanager.h"
48 50
236 keyevt.setShiftPressed(gcnevt.isShiftPressed()); 238 keyevt.setShiftPressed(gcnevt.isShiftPressed());
237 keyevt.setControlPressed(gcnevt.isControlPressed()); 239 keyevt.setControlPressed(gcnevt.isControlPressed());
238 keyevt.setAltPressed(gcnevt.isAltPressed()); 240 keyevt.setAltPressed(gcnevt.isAltPressed());
239 keyevt.setMetaPressed(gcnevt.isMetaPressed()); 241 keyevt.setMetaPressed(gcnevt.isMetaPressed());
240 keyevt.setNumericPad(gcnevt.isNumericPad()); 242 keyevt.setNumericPad(gcnevt.isNumericPad());
241 keyevt.setKey(Key(static_cast<Key::KeyType>(gcnevt.getKey().getValue()), gcnevt.getKey().getValue())); 243
244 // Convert from guichan keyval to FIFE keyval
245 int keyval = gcnevt.getKey().getValue();
246 keyval = convertGuichanKeyToFifeKey(keyval);
247
248 keyevt.setKey(Key(static_cast<Key::KeyType>(keyval), keyval));
249
242 return keyevt; 250 return keyevt;
243 } 251 }
244 252
245 MouseEvent GUIManager::translateMouseEvent(const gcn::MouseEvent& gcnevt) { 253 MouseEvent GUIManager::translateMouseEvent(const gcn::MouseEvent& gcnevt) {
246 MouseEvent mouseevt; 254 MouseEvent mouseevt;
298 break; 306 break;
299 } 307 }
300 return mouseevt; 308 return mouseevt;
301 } 309 }
302 310
311
312 int GUIManager::convertGuichanKeyToFifeKey(int value) {
313
314 switch (value) {
315 case gcn::Key::TAB:
316 value = Key::TAB;
317 break;
318 case gcn::Key::LEFT_ALT:
319 value = Key::LEFT_ALT;
320 break;
321 case gcn::Key::RIGHT_ALT:
322 value = Key::RIGHT_ALT;
323 break;
324 case gcn::Key::LEFT_SHIFT:
325 value = Key::LEFT_SHIFT;
326 break;
327 case gcn::Key::RIGHT_SHIFT:
328 value = Key::RIGHT_SHIFT;
329 break;
330 case gcn::Key::LEFT_CONTROL:
331 value = Key::LEFT_CONTROL;
332 break;
333 case gcn::Key::RIGHT_CONTROL:
334 value = Key::RIGHT_CONTROL;
335 break;
336 case gcn::Key::BACKSPACE:
337 value = Key::BACKSPACE;
338 break;
339 case gcn::Key::PAUSE:
340 value = Key::PAUSE;
341 break;
342 case gcn::Key::SPACE:
343 value = Key::SPACE;
344 break;
345 case gcn::Key::ESCAPE:
346 value = Key::ESCAPE;
347 break;
348 case gcn::Key::DELETE:
349 value = Key::DELETE;
350 break;
351 case gcn::Key::INSERT:
352 value = Key::INSERT;
353 break;
354 case gcn::Key::HOME:
355 value = Key::HOME;
356 break;
357 case gcn::Key::END:
358 value = Key::END;
359 break;
360 case gcn::Key::PAGE_UP:
361 value = Key::PAGE_UP;
362 break;
363 case gcn::Key::PRINT_SCREEN:
364 value = Key::PRINT_SCREEN;
365 break;
366 case gcn::Key::PAGE_DOWN:
367 value = Key::PAGE_DOWN;
368 break;
369 case gcn::Key::F1:
370 value = Key::F1;
371 break;
372 case gcn::Key::F2:
373 value = Key::F2;
374 break;
375 case gcn::Key::F3:
376 value = Key::F3;
377 break;
378 case gcn::Key::F4:
379 value = Key::F4;
380 break;
381 case gcn::Key::F5:
382 value = Key::F5;
383 break;
384 case gcn::Key::F6:
385 value = Key::F6;
386 break;
387 case gcn::Key::F7:
388 value = Key::F7;
389 break;
390 case gcn::Key::F8:
391 value = Key::F8;
392 break;
393 case gcn::Key::F9:
394 value = Key::F9;
395 break;
396 case gcn::Key::F10:
397 value = Key::F10;
398 break;
399 case gcn::Key::F11:
400 value = Key::F11;
401 break;
402 case gcn::Key::F12:
403 value = Key::F12;
404 break;
405 case gcn::Key::F13:
406 value = Key::F13;
407 break;
408 case gcn::Key::F14:
409 value = Key::F14;
410 break;
411 case gcn::Key::F15:
412 value = Key::F15;
413 break;
414 case gcn::Key::NUM_LOCK:
415 value = Key::NUM_LOCK;
416 break;
417 case gcn::Key::CAPS_LOCK:
418 value = Key::CAPS_LOCK;
419 break;
420 case gcn::Key::SCROLL_LOCK:
421 value = Key::SCROLL_LOCK;
422 break;
423 case gcn::Key::RIGHT_META:
424 value = Key::RIGHT_META;
425 break;
426 case gcn::Key::LEFT_META:
427 value = Key::LEFT_META;
428 break;
429 case gcn::Key::LEFT_SUPER:
430 value = Key::LEFT_SUPER;
431 break;
432 case gcn::Key::RIGHT_SUPER:
433 value = Key::RIGHT_SUPER;
434 break;
435 case gcn::Key::ALT_GR:
436 value = Key::ALT_GR;
437 break;
438 case gcn::Key::UP:
439 value = Key::UP;
440 break;
441 case gcn::Key::DOWN:
442 value = Key::DOWN;
443 break;
444 case gcn::Key::LEFT:
445 value = Key::LEFT;
446 break;
447 case gcn::Key::RIGHT:
448 value = Key::RIGHT;
449 break;
450 case gcn::Key::ENTER:
451 value = Key::ENTER;
452 break;
453
454 default:
455 // Convert from unicode to lowercase letters
456 if (value >= 1 && value <= 26) {
457 // Control characters
458 value = value - 1 + 'a';
459 } else if (value >= 'A' && value <= 'Z') {
460 value = value - 'A' + 'a';
461 }
462
463 // FIXME: Accented characters (á) will not get converted properly.
464 break;
465 }
466
467 return value;
468 }
303 } 469 }