MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / HandleEvent

Method HandleEvent

Source/Engine/Platform/SDL/SDLInput.cpp:524–696  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

522}
523
524bool SDLInput::HandleEvent(SDLWindow* window, SDL_Event& event)
525{
526 switch (event.type)
527 {
528 case SDL_EVENT_MOUSE_MOTION:
529 {
530 if (Input::Mouse->IsRelative())
531 {
532 const Float2 mouseDelta(event.motion.xrel, event.motion.yrel);
533 Input::Mouse->OnMouseMoveRelative(mouseDelta, window);
534 }
535 else
536 {
537 const Float2 mousePos = window->ClientToScreen({ event.motion.x, event.motion.y });
538 Input::Mouse->OnMouseMove(mousePos, window);
539 }
540 return true;
541 }
542 case SDL_EVENT_WINDOW_MOUSE_LEAVE:
543 {
544 Input::Mouse->OnMouseLeave(window);
545 return true;
546 }
547 case SDL_EVENT_MOUSE_BUTTON_DOWN:
548 case SDL_EVENT_MOUSE_BUTTON_UP:
549 {
550 Float2 mousePos = window->ClientToScreen({ event.button.x, event.button.y });
551
552 // In case of activating the window from non-focused state, we might not have received the motion event yet
553 if (!Input::Mouse->IsRelative() && event.button.down)
554 Input::Mouse->OnMouseMove(mousePos, window);
555
556 MouseButton button = MouseButton::None;
557 if (event.button.button == SDL_BUTTON_LEFT)
558 button = MouseButton::Left;
559 else if (event.button.button == SDL_BUTTON_RIGHT)
560 button = MouseButton::Right;
561 else if (event.button.button == SDL_BUTTON_MIDDLE)
562 button = MouseButton::Middle;
563 else if (event.button.button == SDL_BUTTON_X1)
564 button = MouseButton::Extended1;
565 else if (event.button.button == SDL_BUTTON_X2)
566 button = MouseButton::Extended2;
567
568 if (Input::Mouse->IsRelative())
569 {
570 // Use the previous visible mouse position here, the event or global
571 // mouse position would cause input to trigger in other editor windows.
572 mousePos = SDLInputImpl::Mouse->GetOldMousePosition();
573 }
574
575 if (!event.button.down)
576 Input::Mouse->OnMouseUp(mousePos, button, window);
577 // Prevent sending multiple mouse down event when double-clicking UI elements
578 else if (event.button.clicks % 2 == 1)
579 Input::Mouse->OnMouseDown(mousePos, button, window);
580 else
581 Input::Mouse->OnMouseDoubleClick(mousePos, button, window);

Callers 5

EventFilterCallbackMethod · 0.45
PostHandleEventsMethod · 0.45
EventFilterCallbackMethod · 0.45
PostHandleEventsMethod · 0.45
PostHandleEventsMethod · 0.45

Calls 15

GetOldMousePositionMethod · 0.80
OnAxisMotionMethod · 0.80
OnButtonStateMethod · 0.80
GetJoystickInstanceIdMethod · 0.80
DeleteObjectMethod · 0.80
RemoveAtKeepOrderMethod · 0.80
IsRelativeMethod · 0.45
OnMouseMoveRelativeMethod · 0.45
ClientToScreenMethod · 0.45
OnMouseMoveMethod · 0.45
OnMouseLeaveMethod · 0.45
OnMouseUpMethod · 0.45

Tested by

no test coverage detected