2 #include "sdl_events.h"
5 #include <CEGUI/RendererModules/OpenGLGUIRenderer/openglrenderer.h>
7 // FIXME temporary fix for enum
8 #include "projection.h"
18 // Library for window switching (-> nGhost)
19 #include "wmcontrol.h"
22 struct sdl_destination{
25 int town_street_assoc;
30 static struct search_param {
33 struct search_list *sl;
38 void route_to(int x,int y){
42 /* FIXME: Get projection from list like x,y or use pcoord from search directly */
43 pos.pro = projection_mg;
44 using namespace CEGUI;
45 extern struct navit *sdl_gui_navit;
48 WindowManager::getSingleton().getWindow("AdressSearchWindow")->hide();
49 WindowManager::getSingleton().getWindow("Navit/Routing/Tips")->show();
51 // WindowManager::getSingleton().getWindow("Navit/ProgressWindow")->show();
52 // route_set_destination(co->route, &pos);
53 // I could have been using search->nav instead of sdl_gui_navit. is it better this way?
55 // WindowManager::getSingleton().getWindow("Navit/ProgressWindow")->hide();
56 // WindowManager::getSingleton().getWindow("OSD/RoadbookButton")->show();
57 // WindowManager::getSingleton().getWindow("OSD/ETA")->show();
59 catch (CEGUI::Exception& e)
61 fprintf(stderr,"CEGUI Exception occured: \n%s\n", e.getMessage().c_str());
62 printf("Missing control!...\n");
64 navit_set_destination(sdl_gui_navit, &pos, "FIXME");
68 bool Handle_Virtual_Key_Down(const CEGUI::EventArgs& event){
70 using namespace CEGUI;
72 const WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(event);
73 String senderID = we.window->getName();
75 Window* editbox = WindowManager::getSingleton().getWindow("Navit/Keyboard/Input");
76 String content=editbox->getText();
80 WindowManager::getSingleton().getWindow("Navit/Keyboard")->hide();
82 } else if(senderID=="BACK"){
83 content=content.substr(0, content.length()-1);
84 editbox->setText(content);
87 editbox->setText(content);
90 Window* country_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/CountryEditbox"));
91 Window* town_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/TownEditbox"));
92 Window* street_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/StreetEditbox"));
94 switch (SDL_dest.current_search) {
96 country_edit->setText(content);
99 town_edit->setText(content);
102 street_edit->setText(content);
105 handle_destination_change();
108 bool handleItemSelect(int r)
110 using namespace CEGUI;
112 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("AdressSearch/Listbox"));
114 ListboxItem * item = mcl->getItemAtGridReference(MCLGridRef(r,0));
115 ListboxItem * itemid = mcl->getItemAtGridReference(MCLGridRef(r,1));
116 ListboxItem * item_assoc = mcl->getItemAtGridReference(MCLGridRef(r,2));
119 Window* country_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/CountryEditbox"));
120 Window* twn_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/TownEditbox"));
121 Window* street_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/StreetEditbox"));
123 if(SDL_dest.current_search==SRCH_COUNTRY){
124 country_edit->setText(item->getText());
125 twn_edit->activate();
126 SDL_dest.current_search=SRCH_TOWN;
127 WindowManager::getSingleton().getWindow("Navit/Keyboard/Input")->setText("");
129 } else if(SDL_dest.current_search==SRCH_TOWN){
130 twn_edit->setText(item->getText());
132 ListboxItem * itemx = mcl->getItemAtGridReference(MCLGridRef(r,3));
133 ListboxItem * itemy = mcl->getItemAtGridReference(MCLGridRef(r,4));
135 Window* Dest_x = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/Dest_x"));
136 Dest_x->setText(itemx->getText().c_str());
138 Window* Dest_y = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/Dest_y"));
139 Dest_y->setText(itemy->getText().c_str());
143 SDL_dest.current_search=SRCH_STREET;
144 street_edit->activate();
145 WindowManager::getSingleton().getWindow("Navit/Keyboard/Input")->setText("");
147 } else if(SDL_dest.current_search==SRCH_STREET){
148 street_edit->setText(item->getText());
150 WindowManager::getSingleton().getWindow("Navit/Keyboard")->hide();
152 ListboxItem * itemx = mcl->getItemAtGridReference(MCLGridRef(r,3));
153 ListboxItem * itemy = mcl->getItemAtGridReference(MCLGridRef(r,4));
155 Window* Dest_x = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/Dest_x"));
156 Dest_x->setText(itemx->getText().c_str());
158 Window* Dest_y = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/Dest_y"));
159 Dest_y->setText(itemy->getText().c_str());
163 SDL_dest.current_search=SRCH_STREET;
165 WindowManager::getSingleton().getWindow("Navit/Keyboard/Input")->setText("");
168 } else if (SDL_dest.current_search==SRCH_NUMBER){
171 ListboxItem * itemx = mcl->getItemAtGridReference(MCLGridRef(r,3));
172 ListboxItem * itemy = mcl->getItemAtGridReference(MCLGridRef(r,4));
174 pos.x=atoi(itemx->getText().c_str());
175 pos.y=atoi(itemy->getText().c_str());
177 route_to(pos.x,pos.y);
183 bool route_clear(const CEGUI::EventArgs& event)
185 // navit_set_destination(gui->nav, NULL, NULL);
188 bool ItemSelect(const CEGUI::EventArgs& event)
190 //FIXME maybe merge with handleItemSelect
191 using namespace CEGUI;
193 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("AdressSearch/Listbox"));
194 ListboxItem * item = mcl->getFirstSelectedItem();
195 handleItemSelect(mcl->getItemRowIndex(item));
198 bool BookmarkSelect(const CEGUI::EventArgs& event)
200 using namespace CEGUI;
202 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("Bookmarks/Listbox"));
204 ListboxItem * item = mcl->getFirstSelectedItem();
206 dbg(0,"item %s is at row %i\n",item->getText().c_str(),mcl->getItemRowIndex(item));
207 BookmarkGo(item->getText().c_str());
209 WindowManager::getSingleton().getWindow("BookmarkSelection")->hide();
212 bool FormerDestSelect(const CEGUI::EventArgs& event)
214 using namespace CEGUI;
216 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("FormerDests/Listbox"));
218 ListboxItem * item = mcl->getFirstSelectedItem();
220 dbg(0,"item %s is at row %i\n",item->getText().c_str(),mcl->getItemRowIndex(item));
221 FormerDestGo(item->getText().c_str());
223 WindowManager::getSingleton().getWindow("FormerDestSelection")->hide();
227 bool handleMouseEnters(const CEGUI::EventArgs& event)
229 // FIXME this whole function could maybe be removed
230 const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(event);
232 // FIXME theses variables should be shared
233 extern CEGUI::OpenGLRenderer* renderer;
235 using namespace CEGUI;
236 WindowManager::getSingleton().getWindow("Navit/Keyboard/Input")->setText("");
237 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("AdressSearch/Listbox"));
239 String senderID = we.window->getName();
241 if (senderID == "AdressSearch/CountryEditbox"){
242 // First, clean off the Street and Town Editbox
243 Window* town_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/TownEditbox"));
244 town_edit->setText("");
245 Window* street_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/StreetEditbox"));
246 street_edit->setText("");
247 SDL_dest.current_search=SRCH_COUNTRY;
249 } else if (senderID == "AdressSearch/TownEditbox"){
250 // First, clean off the Street Editbox
251 Window* street_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/StreetEditbox"));
252 street_edit->setText("");
253 SDL_dest.current_search=SRCH_TOWN;
255 } else if (senderID == "AdressSearch/StreetEditbox"){
256 // First, make sure the user selected an entry in the town choice. If he hadn't, select the first for him.
257 if(SDL_dest.current_search==SRCH_TOWN){
258 if (mcl->getRowCount()>0)
263 SDL_dest.current_search=SRCH_STREET;
269 void handle_destination_change(){
271 using namespace CEGUI;
273 struct search_param *search=&search_param;
274 struct search_list_result *res;
276 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("AdressSearch/Listbox"));
279 if (SDL_dest.current_search==SRCH_COUNTRY)
281 Editbox* country_edit = static_cast<Editbox*>(WindowManager::getSingleton().getWindow("AdressSearch/CountryEditbox"));
282 String content=country_edit->getText();
285 dbg(0,"Starting a country search : %s\n",content.c_str());
287 search->attr.type=attr_country_all;
289 // FIXME the following codeblock could be shared between country, town and street search
290 search->attr.u.str=(char *)content.c_str();
292 search_list_search(search->sl, &search->attr, 1);
293 while((res=search_list_get_result(search->sl))) {
294 ListboxTextItem* itemListbox = new ListboxTextItem((CEGUI::utf8*)(res->country->name));
295 itemListbox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
297 mcl->addRow(itemListbox,0);
300 } else if (SDL_dest.current_search==SRCH_TOWN)
303 Editbox* town_edit = static_cast<Editbox*>(WindowManager::getSingleton().getWindow("AdressSearch/TownEditbox"));
304 String content=town_edit->getText();
309 if(strlen(content.c_str())<4){
312 dbg(0,"town searching for %s\n",content.c_str());
313 search->attr.type=attr_town_name;
314 search->attr.u.str=(char *)content.c_str();
316 search_list_search(search->sl, &search->attr, 1);
317 while((res=search_list_get_result(search->sl))) {
318 ListboxTextItem* itemListbox = new ListboxTextItem((CEGUI::utf8*)(res->town->name));
319 itemListbox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
321 mcl->addRow(itemListbox,0);
324 sprintf(x,"%li",res->c->x);
325 ListboxTextItem* xitem = new ListboxTextItem(x);
328 sprintf(y,"%li",res->c->y);
330 ListboxTextItem* yitem = new ListboxTextItem(y);
334 mcl->setItem(xitem, 3, mcl->getRowCount()-1);
335 mcl->setItem(yitem, 4, mcl->getRowCount()-1);
337 // something went wrong, so cleanup the ListboxTextItem.
338 catch (InvalidRequestException)
348 } else if (SDL_dest.current_search==SRCH_STREET)
350 Editbox* street_edit = static_cast<Editbox*>(WindowManager::getSingleton().getWindow("AdressSearch/StreetEditbox"));
352 String content=street_edit->getText();
353 if(strlen(content.c_str())<1){
356 // dbg(1,"street searching for %s\n",content.c_str());
357 search->attr.type=attr_street_name;
358 search->attr.u.str=(char *)content.c_str();
362 search_list_search(search->sl, &search->attr, 1);
363 while((res=search_list_get_result(search->sl))) {
364 ListboxTextItem* itemListbox = new ListboxTextItem((CEGUI::utf8*)(res->street->name));
365 itemListbox->setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush");
367 mcl->addRow(itemListbox,0);
370 sprintf(x,"%li",res->c->x);
371 ListboxTextItem* xitem = new ListboxTextItem(x);
374 sprintf(y,"%li",res->c->y);
376 ListboxTextItem* yitem = new ListboxTextItem(y);
380 mcl->setItem(xitem, 3, mcl->getRowCount()-1);
381 mcl->setItem(yitem, 4, mcl->getRowCount()-1);
383 // something went wrong, so cleanup the ListboxTextItem.
384 catch (InvalidRequestException)
397 bool DestinationEntryChange(const CEGUI::EventArgs& event)
399 handleMouseEnters(event);
400 handle_destination_change();
405 bool DestinationWindowSwitch(const CEGUI::EventArgs& event)
407 using namespace CEGUI;
409 WindowManager::getSingleton().getWindow("AdressSearchWindow")->hide();
410 WindowManager::getSingleton().getWindow("BookmarkSelection")->hide();
411 WindowManager::getSingleton().getWindow("FormerDestSelection")->hide();
413 if(WindowManager::getSingleton().getWindow("DestinationChoose")->isVisible()){
414 WindowManager::getSingleton().getWindow("DestinationChoose")->hide();
416 WindowManager::getSingleton().getWindow("DestinationChoose")->show();
420 bool BookmarkSelectionSwitch(const CEGUI::EventArgs& event)
422 using namespace CEGUI;
423 if(WindowManager::getSingleton().getWindow("BookmarkSelection")->isVisible()){
424 WindowManager::getSingleton().getWindow("BookmarkSelection")->hide();
426 WindowManager::getSingleton().getWindow("DestinationChoose")->hide();
427 WindowManager::getSingleton().getWindow("BookmarkSelection")->show();
431 bool FormerDestSelectionSwitch(const CEGUI::EventArgs& event)
433 using namespace CEGUI;
434 if(WindowManager::getSingleton().getWindow("FormerDestSelection")->isVisible()){
435 WindowManager::getSingleton().getWindow("FormerDestSelection")->hide();
437 WindowManager::getSingleton().getWindow("DestinationChoose")->hide();
438 WindowManager::getSingleton().getWindow("FormerDestSelection")->show();
442 bool AddressSearchSwitch(const CEGUI::EventArgs& event)
444 using namespace CEGUI;
445 WindowManager::getSingleton().getWindow("DestinationChoose")->hide();
446 WindowManager::getSingleton().getWindow("AdressSearchWindow")->show();
451 dbg(0,"*** Invalid navit instance in sdl_events\n");
453 struct search_param *search=&search_param;
454 struct search_list_result *res;
456 // dbg(1,"search->nav=sdl_gui_navit;\n");
457 search->nav=sdl_gui_navit;
458 // dbg(1,"search->ms=navit_get_mapset(sdl_gui_navit);\n");
459 search->ms=navit_get_mapset(sdl_gui_navit);
460 // dbg(1,"search->sl=search_list_new(search->ms);\n");
461 search->sl=search_list_new(search->ms);
464 const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(event);
466 Window* town_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/TownEditbox"));
467 town_edit->setText("");
468 Window* street_edit = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/StreetEditbox"));
469 street_edit->setText("");
470 town_edit->activate();
472 SDL_dest.current_search=SRCH_COUNTRY;
473 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("AdressSearch/Listbox"));
477 // Code to get the current country and set it by default for the search
478 struct attr search_attr, country_name, *country_attr;
479 struct tracking *tracking;
480 struct country_search *cs;
484 Editbox* country_edit = static_cast<Editbox*>(WindowManager::getSingleton().getWindow("AdressSearch/CountryEditbox"));
486 country_attr=country_default();
487 tracking=navit_get_tracking(sdl_gui_navit);
488 if (tracking && tracking_get_current_attr(tracking, attr_country_id, &search_attr))
489 country_attr=&search_attr;
490 cs=country_search_new(country_attr, 0);
491 item=country_search_get_item(cs);
492 if (item && item_attr_get(item, attr_country_name, &country_name)){
493 country_edit->setText(country_name.u.str);
494 handle_destination_change();
496 country_search_destroy(cs);
498 SDL_dest.current_search=SRCH_TOWN;
503 bool Switch_to_nGhost(const CEGUI::EventArgs& event)
505 extern char media_window_title[255], media_cmd[255];
506 dbg(0,"trying to switch to %s (%s)\n",media_window_title,media_cmd);
507 if (window_switch(media_window_title)==EXIT_FAILURE)
509 popen(media_cmd,"r");
515 bool RoadBookSwitch(const CEGUI::EventArgs& event)
517 using namespace CEGUI;
519 // const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(event);
520 if(WindowManager::getSingleton().getWindow("Navit/RoadBook")->isVisible()){
521 WindowManager::getSingleton().getWindow("Navit/RoadBook")->hide();
522 WindowManager::getSingleton().getWindow("OSD/RoadbookButton")->show();
524 WindowManager::getSingleton().getWindow("Navit/RoadBook")->show();
525 WindowManager::getSingleton().getWindow("OSD/RoadbookButton")->hide();
530 bool ButtonGo(const CEGUI::EventArgs& event)
532 using namespace CEGUI;
534 MultiColumnList* mcl = static_cast<MultiColumnList*>(WindowManager::getSingleton().getWindow("AdressSearch/Listbox"));
535 // First, make sure the user selected an entry in the town choice. If he hadn't, select the first for him.
536 if(SDL_dest.current_search==SRCH_TOWN){
537 if (mcl->getRowCount()>0)
544 Window* Dest_x = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/Dest_x"));
545 Window* Dest_y = static_cast<Window*>(WindowManager::getSingleton().getWindow("AdressSearch/Dest_y"));
547 extern struct navit *sdl_gui_navit;
548 route_to(atoi(Dest_x->getText().c_str()),atoi(Dest_y->getText().c_str()));
554 bool ZoomIn(const CEGUI::EventArgs& event)
556 extern struct navit *sdl_gui_navit;
557 navit_zoom_in(sdl_gui_navit, 2, NULL);
561 bool ZoomOut(const CEGUI::EventArgs& event)
563 extern struct navit *sdl_gui_navit;
564 navit_zoom_out(sdl_gui_navit, 2, NULL);
567 bool ButtonQuit(const CEGUI::EventArgs& event)
575 // Nothing really interesting below.
577 void handle_mouse_down(Uint8 button)
581 // handle real mouse buttons
582 case SDL_BUTTON_LEFT:
583 CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
585 case SDL_BUTTON_MIDDLE:
586 CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton);
588 case SDL_BUTTON_RIGHT:
589 CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
592 // handle the mouse wheel
593 case SDL_BUTTON_WHEELDOWN:
594 CEGUI::System::getSingleton().injectMouseWheelChange( -1 );
596 case SDL_BUTTON_WHEELUP:
597 CEGUI::System::getSingleton().injectMouseWheelChange( +1 );
603 void handle_mouse_up(Uint8 button)
607 case SDL_BUTTON_LEFT:
608 CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
610 case SDL_BUTTON_MIDDLE:
611 CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton);
613 case SDL_BUTTON_RIGHT:
614 CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
619 void inject_time_pulse(double& last_time_pulse)
621 // get current "run-time" in seconds
622 double t = 0.001*SDL_GetTicks();
624 // inject the time that passed since the last call
625 CEGUI::System::getSingleton().injectTimePulse( float(t-last_time_pulse) );
627 // store the new time as the last time
631 CEGUI::uint SDLKeyToCEGUIKey(SDLKey key)
633 using namespace CEGUI;
636 case SDLK_BACKSPACE: return Key::Backspace;
637 case SDLK_TAB: return Key::Tab;
638 case SDLK_RETURN: return Key::Return;
639 case SDLK_PAUSE: return Key::Pause;
640 case SDLK_ESCAPE: return Key::Escape;
641 case SDLK_SPACE: return Key::Space;
642 case SDLK_COMMA: return Key::Comma;
643 case SDLK_MINUS: return Key::Minus;
644 case SDLK_PERIOD: return Key::Period;
645 case SDLK_SLASH: return Key::Slash;
646 case SDLK_0: return Key::Zero;
647 case SDLK_1: return Key::One;
648 case SDLK_2: return Key::Two;
649 case SDLK_3: return Key::Three;
650 case SDLK_4: return Key::Four;
651 case SDLK_5: return Key::Five;
652 case SDLK_6: return Key::Six;
653 case SDLK_7: return Key::Seven;
654 case SDLK_8: return Key::Eight;
655 case SDLK_9: return Key::Nine;
656 case SDLK_COLON: return Key::Colon;
657 case SDLK_SEMICOLON: return Key::Semicolon;
658 case SDLK_EQUALS: return Key::Equals;
659 case SDLK_LEFTBRACKET: return Key::LeftBracket;
660 case SDLK_BACKSLASH: return Key::Backslash;
661 case SDLK_RIGHTBRACKET: return Key::RightBracket;
662 case SDLK_a: return Key::A;
663 case SDLK_b: return Key::B;
664 case SDLK_c: return Key::C;
665 case SDLK_d: return Key::D;
666 case SDLK_e: return Key::E;
667 case SDLK_f: return Key::F;
668 case SDLK_g: return Key::G;
669 case SDLK_h: return Key::H;
670 case SDLK_i: return Key::I;
671 case SDLK_j: return Key::J;
672 case SDLK_k: return Key::K;
673 case SDLK_l: return Key::L;
674 case SDLK_m: return Key::M;
675 case SDLK_n: return Key::N;
676 case SDLK_o: return Key::O;
677 case SDLK_p: return Key::P;
678 case SDLK_q: return Key::Q;
679 case SDLK_r: return Key::R;
680 case SDLK_s: return Key::S;
681 case SDLK_t: return Key::T;
682 case SDLK_u: return Key::U;
683 case SDLK_v: return Key::V;
684 case SDLK_w: return Key::W;
685 case SDLK_x: return Key::X;
686 case SDLK_y: return Key::Y;
687 case SDLK_z: return Key::Z;
688 case SDLK_DELETE: return Key::Delete;
689 case SDLK_KP0: return Key::Numpad0;
690 case SDLK_KP1: return Key::Numpad1;
691 case SDLK_KP2: return Key::Numpad2;
692 case SDLK_KP3: return Key::Numpad3;
693 case SDLK_KP4: return Key::Numpad4;
694 case SDLK_KP5: return Key::Numpad5;
695 case SDLK_KP6: return Key::Numpad6;
696 case SDLK_KP7: return Key::Numpad7;
697 case SDLK_KP8: return Key::Numpad8;
698 case SDLK_KP9: return Key::Numpad9;
699 case SDLK_KP_PERIOD: return Key::Decimal;
700 case SDLK_KP_DIVIDE: return Key::Divide;
701 case SDLK_KP_MULTIPLY: return Key::Multiply;
702 case SDLK_KP_MINUS: return Key::Subtract;
703 case SDLK_KP_PLUS: return Key::Add;
704 case SDLK_KP_ENTER: return Key::NumpadEnter;
705 case SDLK_KP_EQUALS: return Key::NumpadEquals;
706 case SDLK_UP: return Key::ArrowUp;
707 case SDLK_DOWN: return Key::ArrowDown;
708 case SDLK_RIGHT: return Key::ArrowRight;
709 case SDLK_LEFT: return Key::ArrowLeft;
710 case SDLK_INSERT: return Key::Insert;
711 case SDLK_HOME: return Key::Home;
712 case SDLK_END: return Key::End;
713 case SDLK_PAGEUP: return Key::PageUp;
714 case SDLK_PAGEDOWN: return Key::PageDown;
715 case SDLK_F1: return Key::F1;
716 case SDLK_F2: return Key::F2;
717 case SDLK_F3: return Key::F3;
718 case SDLK_F4: return Key::F4;
719 case SDLK_F5: return Key::F5;
720 case SDLK_F6: return Key::F6;
721 case SDLK_F7: return Key::F7;
722 case SDLK_F8: return Key::F8;
723 case SDLK_F9: return Key::F9;
724 case SDLK_F10: return Key::F10;
725 case SDLK_F11: return Key::F11;
726 case SDLK_F12: return Key::F12;
727 case SDLK_F13: return Key::F13;
728 case SDLK_F14: return Key::F14;
729 case SDLK_F15: return Key::F15;
730 case SDLK_NUMLOCK: return Key::NumLock;
731 case SDLK_SCROLLOCK: return Key::ScrollLock;
732 case SDLK_RSHIFT: return Key::RightShift;
733 case SDLK_LSHIFT: return Key::LeftShift;
734 case SDLK_RCTRL: return Key::RightControl;
735 case SDLK_LCTRL: return Key::LeftControl;
736 case SDLK_RALT: return Key::RightAlt;
737 case SDLK_LALT: return Key::LeftAlt;
738 case SDLK_LSUPER: return Key::LeftWindows;
739 case SDLK_RSUPER: return Key::RightWindows;
740 case SDLK_SYSREQ: return Key::SysRq;
741 case SDLK_MENU: return Key::AppMenu;
742 case SDLK_POWER: return Key::Power;
749 void inject_input(bool& must_quit)
753 // go through all available events
754 while (SDL_PollEvent(&e))
756 // we use a switch to determine the event type
759 // mouse motion handler
760 case SDL_MOUSEMOTION:
761 // we inject the mouse position directly.
762 CEGUI::System::getSingleton().injectMousePosition(
763 static_cast<float>(e.motion.x),
764 static_cast<float>(e.motion.y)
768 // mouse down handler
769 case SDL_MOUSEBUTTONDOWN:
770 // let a special function handle the mouse button down event
771 handle_mouse_down(e.button.button);
775 case SDL_MOUSEBUTTONUP:
776 // let a special function handle the mouse button up event
777 handle_mouse_up(e.button.button);
783 // to tell CEGUI that a key was pressed, we inject the scancode, translated from SDL
784 CEGUI::System::getSingleton().injectKeyDown(SDLKeyToCEGUIKey(e.key.keysym.sym));
786 // as for the character it's a litte more complicated. we'll use for translated unicode value.
787 // this is described in more detail below.
788 if ((e.key.keysym.unicode & 0xFF80) == 0)
790 CEGUI::System::getSingleton().injectChar(e.key.keysym.unicode & 0x7F);
796 // like before we inject the scancode translated from SDL.
797 CEGUI::System::getSingleton().injectKeyUp(SDLKeyToCEGUIKey(e.key.keysym.sym));
801 // WM quit event occured