/// <summary> /// Process a single event and dispatch it to the right window. /// </summary> public static void ProcessEvent(SDL.SDL_Event e) { Window ctrl = null; // Code below is to extract the associated `Window' instance and to find out the window // with focus. In the future, we could even add events handled at the application level. switch (e.type) { case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN: case SDL.SDL_EventType.SDL_MOUSEBUTTONUP: ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.button.windowID)); break; case SDL.SDL_EventType.SDL_MOUSEMOTION: ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.motion.windowID)); break; case SDL.SDL_EventType.SDL_MOUSEWHEEL: ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.wheel.windowID)); break; case SDL.SDL_EventType.SDL_KEYDOWN: case SDL.SDL_EventType.SDL_KEYUP: ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.key.windowID)); break; case SDL.SDL_EventType.SDL_TEXTEDITING: ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.edit.windowID)); break; case SDL.SDL_EventType.SDL_TEXTINPUT: ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.text.windowID)); break; case SDL.SDL_EventType.SDL_FINGERMOTION: case SDL.SDL_EventType.SDL_FINGERDOWN: case SDL.SDL_EventType.SDL_FINGERUP: ctrl = WindowWithFocus; break; case SDL.SDL_EventType.SDL_WINDOWEVENT: { ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.window.windowID)); switch (e.window.windowEvent) { case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: WindowWithFocus = ctrl; break; case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: WindowWithFocus = null; break; } break; } case SDL.SDL_EventType.SDL_JOYDEVICEADDED: case SDL.SDL_EventType.SDL_JOYDEVICEREMOVED: // Send these events to all the windows Windows.ForEach(x => x.ProcessEvent(e)); break; case SDL.SDL_EventType.SDL_DROPTEXT: case SDL.SDL_EventType.SDL_DROPFILE: ctrl = WindowFromSdlHandle(SDL.SDL_GetWindowFromID(e.drop.windowID)); break; } ctrl?.ProcessEvent(e); }
/// <summary> /// Process a single event and dispatch it to the right window. /// </summary> public static void ProcessEvent(Event e) { Window ctrl = null; // Code below is to extract the associated `Window' instance and to find out the window // with focus. In the future, we could even add events handled at the application level. switch ((EventType)e.Type) { case EventType.Mousebuttondown: case EventType.Mousebuttonup: ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Button.WindowID)); break; case EventType.Mousemotion: ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Motion.WindowID)); break; case EventType.Mousewheel: ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Wheel.WindowID)); break; case EventType.Keydown: case EventType.Keyup: ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Key.WindowID)); break; case EventType.Textediting: ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Edit.WindowID)); break; case EventType.Textinput: ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Text.WindowID)); break; case EventType.Fingermotion: case EventType.Fingerdown: case EventType.Fingerup: ctrl = WindowWithFocus; break; case EventType.Windowevent: { ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Window.WindowID)); switch ((WindowEventID)e.Window.Event) { case WindowEventID.WindoweventFocusGained: WindowWithFocus = ctrl; break; case WindowEventID.WindoweventFocusLost: WindowWithFocus = null; break; } break; } case EventType.Joydeviceadded: case EventType.Joydeviceremoved: // Send these events to all the windows Windows.ForEach(x => x.ProcessEvent(e)); break; case EventType.Droptext: case EventType.Dropfile: ctrl = WindowFromSdlHandle(SDL.GetWindowFromID(e.Drop.WindowID)); break; } ctrl?.ProcessEvent(e); }