MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / translateSdlEvents

Method translateSdlEvents

framework/framework.cpp:511–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

509void Framework::pushEvent(Event *e) { this->pushEvent(up<Event>(e)); }
510
511void Framework::translateSdlEvents()
512{
513 SDL_Event e;
514 Event *fwE;
515 bool touch_events_enabled = Options::optionEnableTouchEvents.get();
516
517 // FIXME: That's not the right way to figure out the primary finger!
518 int primaryFingerID = -1;
519 if (SDL_GetNumTouchDevices())
520 {
521 SDL_Finger *primaryFinger = SDL_GetTouchFinger(SDL_GetTouchDevice(0), 0);
522 if (primaryFinger)
523 {
524 primaryFingerID = primaryFinger->id;
525 }
526 }
527
528 while (SDL_PollEvent(&e))
529 {
530 switch (e.type)
531 {
532 case SDL_QUIT:
533 fwE = new DisplayEvent(EVENT_WINDOW_CLOSED);
534 pushEvent(up<Event>(fwE));
535 break;
536 case SDL_JOYDEVICEADDED:
537 case SDL_JOYDEVICEREMOVED:
538 // FIXME: Do nothing?
539 break;
540 case SDL_KEYDOWN:
541 fwE = new KeyboardEvent(EVENT_KEY_DOWN);
542 fwE->keyboard().KeyCode = e.key.keysym.sym;
543 fwE->keyboard().ScanCode = e.key.keysym.scancode;
544 fwE->keyboard().Modifiers = e.key.keysym.mod;
545 pushEvent(up<Event>(fwE));
546 break;
547 case SDL_KEYUP:
548 fwE = new KeyboardEvent(EVENT_KEY_UP);
549 fwE->keyboard().KeyCode = e.key.keysym.sym;
550 fwE->keyboard().ScanCode = e.key.keysym.scancode;
551 fwE->keyboard().Modifiers = e.key.keysym.mod;
552 pushEvent(up<Event>(fwE));
553 break;
554 case SDL_TEXTINPUT:
555 fwE = new TextEvent();
556 fwE->text().Input = e.text.text;
557 pushEvent(up<Event>(fwE));
558 break;
559 case SDL_TEXTEDITING:
560 // FIXME: Do nothing?
561 break;
562 case SDL_MOUSEMOTION:
563 fwE = new MouseEvent(EVENT_MOUSE_MOVE);
564 fwE->mouse().X = coordWindowToDisplayX(e.motion.x);
565 fwE->mouse().Y = coordWindowToDisplayY(e.motion.y);
566 fwE->mouse().DeltaX = e.motion.xrel;
567 fwE->mouse().DeltaY = e.motion.yrel;
568 fwE->mouse().WheelVertical = 0; // These should be handled

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
displayMethod · 0.45

Tested by

no test coverage detected