private void UpdateTouches()
 {
     try {
         var pssTouches = Touch.GetData(0);
         foreach (var touch in pssTouches)
         {
             Vector2 position = new Vector2((touch.X + 0.5f) * _frameBufferWidth, (touch.Y + 0.5f) * _frameBufferHeight);
             if (touch.Status == TouchStatus.Down)
             {
                 TouchPanel.AddEvent(touch.ID, TouchLocationState.Pressed, position);
             }
             else if (touch.Status == TouchStatus.Move)
             {
                 TouchPanel.AddEvent(touch.ID, TouchLocationState.Moved, position);
             }
             else
             {
                 TouchPanel.AddEvent(touch.ID, TouchLocationState.Released, position);
             }
         }
     } catch (Sce.PlayStation.Core.InputSystemException exc) {
         if (exc.Message.ToLowerInvariant().Trim() == "native function returned error.")
         {
             throw new InvalidOperationException("Touch must be listed in your features list in app.xml in order to use the TouchPanel API on PlayStation Mobile.", exc);
         }
         else
         {
             throw;
         }
     }
 }
        protected override void WndProc(ref Message m)
        {
            var state = TouchLocationState.Invalid;

            if (m.Msg == WM_POINTERUP)
            {
                state = TouchLocationState.Released;
            }
            else if (m.Msg == WM_POINTERDOWN)
            {
                state = TouchLocationState.Pressed;
            }
            else if (m.Msg == WM_POINTERUPDATE)
            {
                state = TouchLocationState.Moved;
            }

            if (state != TouchLocationState.Invalid)
            {
                var id = m.GetPointerId();

                var position = m.GetPointerLocation();
                position = PointToClient(position);
                var vec = new Vector2(position.X, position.Y);

                TouchPanel.AddEvent(id, state, vec, false);
            }

            base.WndProc(ref m);
        }
Esempio n. 3
0
        private void OnMouseState(object sender, MouseEventArgs mouseEventArgs)
        {
            var previousState = Mouse.State.LeftButton;

            Mouse.State.X                 = mouseEventArgs.X;
            Mouse.State.Y                 = mouseEventArgs.Y;
            Mouse.State.LeftButton        = (mouseEventArgs.Button & MouseButtons.Left) == MouseButtons.Left ? ButtonState.Pressed : ButtonState.Released;
            Mouse.State.MiddleButton      = (mouseEventArgs.Button & MouseButtons.Middle) == MouseButtons.Middle ? ButtonState.Pressed : ButtonState.Released;
            Mouse.State.RightButton       = (mouseEventArgs.Button & MouseButtons.Right) == MouseButtons.Right ? ButtonState.Pressed : ButtonState.Released;
            Mouse.State.ScrollWheelValue += mouseEventArgs.Delta;

            TouchLocationState?touchState = null;

            if (Mouse.State.LeftButton == ButtonState.Pressed)
            {
                if (previousState == ButtonState.Released)
                {
                    touchState = TouchLocationState.Pressed;
                }
                else
                {
                    touchState = TouchLocationState.Moved;
                }
            }
            else if (previousState == ButtonState.Pressed)
            {
                touchState = TouchLocationState.Released;
            }

            if (touchState.HasValue)
            {
                TouchPanel.AddEvent(0, touchState.Value, new Vector2(Mouse.State.X, Mouse.State.Y), true);
            }
        }
Esempio n. 4
0
        protected override void WndProc(ref Message m)
        {
            var state = TouchLocationState.Invalid;

            switch (m.Msg)
            {
            case WM_TABLET_QUERYSYSTEMGESTURESTA:
            {
                // This disables the windows touch helpers, popups, and
                // guides that get in the way of touch gameplay.
                const int flags = 0x00000001 |        // TABLET_DISABLE_PRESSANDHOLD
                                  0x00000008 |        // TABLET_DISABLE_PENTAPFEEDBACK
                                  0x00000010 |        // TABLET_DISABLE_PENBARRELFEEDBACK
                                  0x00000100 |        // TABLET_DISABLE_TOUCHUIFORCEON
                                  0x00000200 |        // TABLET_DISABLE_TOUCHUIFORCEOFF
                                  0x00008000 |        // TABLET_DISABLE_TOUCHSWITCH
                                  0x00010000 |        // TABLET_DISABLE_FLICKS
                                  0x00080000 |        // TABLET_DISABLE_SMOOTHSCROLLING
                                  0x00100000;         // TABLET_DISABLE_FLICKFALLBACKKEYS
                m.Result = new IntPtr(flags);
                return;
            }

            case WM_SYSCOMMAND:
                // Disable the system menu from being toggled by
                // keyboard input so we can own the ALT key.
                if (m.WParam.ToInt32() == 0xF100)     // SC_KEYMENU
                {
                    m.Result = IntPtr.Zero;
                    return;
                }
                break;

            case WM_POINTERUP:
                state = TouchLocationState.Released;
                break;

            case WM_POINTERDOWN:
                state = TouchLocationState.Pressed;
                break;

            case WM_POINTERUPDATE:
                state = TouchLocationState.Moved;
                break;
            }

            if (state != TouchLocationState.Invalid)
            {
                var id = m.GetPointerId();

                var position = m.GetPointerLocation();
                position = PointToClient(position);
                var vec = new Vector2(position.X, position.Y);

                TouchPanel.AddEvent(id, state, vec, false);
            }

            base.WndProc(ref m);
        }
Esempio n. 5
0
            private static void OnPointerReleased(DrawingSurfaceManipulationHost sender, PointerEventArgs args)
            {
                var pointerPoint = args.CurrentPoint;

                // To convert from DIPs (device independent pixels) to screen resolution pixels.
                var dipFactor = DisplayProperties.LogicalDpi / 96.0f;
                var pos       = new Vector2((float)pointerPoint.Position.X, (float)pointerPoint.Position.Y) * dipFactor;

                TouchPanel.AddEvent((int)pointerPoint.PointerId, TouchLocationState.Released, pos);
            }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="evt"></param>
        public void OnTouchEvent(MotionEvent evt)
        {
            if (!Enabled)
            {
                return;
            }

            Vector2 position = Vector2.Zero;

            position.X = evt.GetX(evt.ActionIndex);
            position.Y = evt.GetY(evt.ActionIndex);
            UpdateTouchPosition(ref position);
            int id = evt.GetPointerId(evt.ActionIndex);

            switch (evt.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                TouchPanel.AddEvent(id, TouchLocationState.Pressed, position);
                break;

            case MotionEventActions.Up:
            case MotionEventActions.PointerUp:
                TouchPanel.AddEvent(id, TouchLocationState.Released, position);
                break;

            case MotionEventActions.Move:
                for (int i = 0; i < evt.PointerCount; i++)
                {
                    id         = evt.GetPointerId(i);
                    position.X = evt.GetX(i);
                    position.Y = evt.GetY(i);
                    UpdateTouchPosition(ref position);
                    TouchPanel.AddEvent(id, TouchLocationState.Moved, position);
                }
                break;

            case MotionEventActions.Cancel:
            case MotionEventActions.Outside:
                for (int i = 0; i < evt.PointerCount; i++)
                {
                    id = evt.GetPointerId(i);
                    TouchPanel.AddEvent(id, TouchLocationState.Released, position);
                }
                break;
            }
        }
Esempio n. 7
0
        private void UpdateInput()
        {
            if (UnityEngine.Input.mousePresent)
            {
                bool mouseIsDown = UnityEngine.Input.GetMouseButton(0);
                if (!_mouseIsDown && mouseIsDown)
                {
                    TouchPanel.AddEvent(MouseId, TouchLocationState.Pressed, ToMonoGame(UnityEngine.Input.mousePosition));
                }
                else if (_mouseIsDown && !mouseIsDown)
                {
                    TouchPanel.AddEvent(MouseId, TouchLocationState.Released, ToMonoGame(UnityEngine.Input.mousePosition));
                }
                else if (_mouseIsDown)
                {
                    TouchPanel.AddEvent(MouseId, TouchLocationState.Moved, ToMonoGame(UnityEngine.Input.mousePosition));
                }
                _mouseIsDown = mouseIsDown;
            }

            for (var i = 0; i < UnityEngine.Input.touchCount; i++)
            {
                var touch = UnityEngine.Input.touches[i];
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    TouchPanel.AddEvent(touch.fingerId, TouchLocationState.Pressed, ToMonoGame(touch.position));
                    break;

                case TouchPhase.Moved:
                    TouchPanel.AddEvent(touch.fingerId, TouchLocationState.Moved, ToMonoGame(touch.position));
                    break;

                case TouchPhase.Canceled:
                case TouchPhase.Ended:
                    TouchPanel.AddEvent(touch.fingerId, TouchLocationState.Released, ToMonoGame(touch.position));
                    break;

                case TouchPhase.Stationary:
                    //do nothing
                    break;
                }
            }
        }
Esempio n. 8
0
        // TODO: Review FillTouchCollection
        private void FillTouchCollection(NSSet touches)
        {
            if (touches.Count == 0)
            {
                return;
            }

            var touchesArray = touches.ToArray <UITouch> ();

            for (int i = 0; i < touchesArray.Length; ++i)
            {
                var touch = touchesArray [i];

                //Get position touch
                var location = touch.LocationInView(touch.View);
                var position = GetOffsetPosition(new Vector2(location.X, location.Y), true);
                var id       = touch.Handle.ToInt32();

                switch (touch.Phase)
                {
                //case UITouchPhase.Stationary:
                case UITouchPhase.Moved:
                    TouchPanel.AddEvent(id, TouchLocationState.Moved, position);
                    break;

                case UITouchPhase.Began:
                    TouchPanel.AddEvent(id, TouchLocationState.Pressed, position);
                    break;

                case UITouchPhase.Ended:
                    TouchPanel.AddEvent(id, TouchLocationState.Released, position);
                    break;

                case UITouchPhase.Cancelled:
                    TouchPanel.AddEvent(id, TouchLocationState.Released, position);
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 9
0
        private void PointerMoved(PointerPoint pointerPoint)
        {
            // To convert from DIPs (device independent pixels) to actual screen resolution pixels.
            var dipFactor = DisplayProperties.LogicalDpi / 96.0f;
            var pos       = new Vector2((float)pointerPoint.Position.X, (float)pointerPoint.Position.Y) * dipFactor;

            var isTouch     = pointerPoint.PointerDevice.PointerDeviceType == PointerDeviceType.Touch;
            var touchIsDown = pointerPoint.IsInContact;

            if (touchIsDown)
            {
                TouchPanel.AddEvent((int)pointerPoint.PointerId, TouchLocationState.Moved, pos, !isTouch);
            }

            if (!isTouch)
            {
                // Mouse or stylus event.
                UpdateMouse(pointerPoint);
            }
        }
        private void UpdateTouches()
        {
            var pssTouches = Touch.GetData(0);

            foreach (var touch in pssTouches)
            {
                Vector2 position = new Vector2((touch.X + 0.5f) * _frameBufferWidth, (touch.Y + 0.5f) * _frameBufferHeight);
                if (touch.Status == TouchStatus.Down)
                {
                    TouchPanel.AddEvent(touch.ID, TouchLocationState.Pressed, position);
                }
                else if (touch.Status == TouchStatus.Move)
                {
                    TouchPanel.AddEvent(touch.ID, TouchLocationState.Moved, position);
                }
                else
                {
                    TouchPanel.AddEvent(touch.ID, TouchLocationState.Released, position);
                }
            }
        }
Esempio n. 11
0
        private void PointerReleased(PointerPoint pointerPoint, UIElement target, Pointer pointer)
        {
            // To convert from DIPs (device independent pixels) to screen resolution pixels.
            var dipFactor = DisplayProperties.LogicalDpi / 96.0f;
            var pos       = new Vector2((float)pointerPoint.Position.X, (float)pointerPoint.Position.Y) * dipFactor;

            var isTouch = pointerPoint.PointerDevice.PointerDeviceType == PointerDeviceType.Touch;

            TouchPanel.AddEvent((int)pointerPoint.PointerId, TouchLocationState.Released, pos, !isTouch);

            if (!isTouch)
            {
                // Mouse or stylus event.
                UpdateMouse(pointerPoint);

                // Release the captured pointer.
                if (target != null)
                {
                    target.ReleasePointerCapture(pointer);
                }
            }
        }
Esempio n. 12
0
        public override void RunLoop()
        {
            SDL.SDL_ShowWindow(Window.Handle);

            SDL.SDL_Event evt;

            while (INTERNAL_runApplication)
            {
#if !THREADED_GL
                Threading.Run();
#endif
                while (SDL.SDL_PollEvent(out evt) == 1)
                {
                    // Keyboard
                    if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN)
                    {
                        Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode);
                        if (!keys.Contains(key))
                        {
                            keys.Add(key);
                            INTERNAL_TextInputIn(key);
                        }
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_KEYUP)
                    {
                        Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode);
                        if (keys.Remove(key))
                        {
                            INTERNAL_TextInputOut(key);
                        }
                    }

                    // Mouse Input
                    else if (evt.type == SDL.SDL_EventType.SDL_MOUSEMOTION)
                    {
                        Mouse.INTERNAL_IsWarped = false;
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_MOUSEWHEEL)
                    {
                        // 120 units per notch. Because reasons.
                        Mouse.INTERNAL_MouseWheel += evt.wheel.y * 120;
                    }

                    // Touch Input
                    else if (evt.type == SDL.SDL_EventType.SDL_FINGERDOWN)
                    {
                        TouchPanel.AddEvent(
                            (int)evt.tfinger.touchId,
                            TouchLocationState.Pressed,
                            new Vector2(
                                evt.tfinger.x,
                                evt.tfinger.y
                                )
                            );
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_FINGERUP)
                    {
                        TouchPanel.AddEvent(
                            (int)evt.tfinger.touchId,
                            TouchLocationState.Released,
                            new Vector2(
                                evt.tfinger.x,
                                evt.tfinger.y
                                )
                            );
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_FINGERMOTION)
                    {
                        TouchPanel.AddEvent(
                            (int)evt.tfinger.touchId,
                            TouchLocationState.Moved,
                            new Vector2(
                                evt.tfinger.x,
                                evt.tfinger.y
                                )
                            );
                    }

                    // Various Window Events...
                    else if (evt.type == SDL.SDL_EventType.SDL_WINDOWEVENT)
                    {
                        // Window Focus
                        if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED)
                        {
                            IsActive = true;

                            if (!INTERNAL_useFullscreenSpaces)
                            {
                                // If we alt-tab away, we lose the 'fullscreen desktop' flag on some WMs
                                SDL.SDL_SetWindowFullscreen(
                                    Window.Handle,
                                    Game.GraphicsDevice.PresentationParameters.IsFullScreen ?
                                    (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP :
                                    0
                                    );
                            }

                            // Disable the screensaver when we're back.
                            SDL.SDL_DisableScreenSaver();
                        }
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST)
                        {
                            IsActive = false;

                            if (!INTERNAL_useFullscreenSpaces)
                            {
                                SDL.SDL_SetWindowFullscreen(Window.Handle, 0);
                            }

                            // Give the screensaver back, we're not that important now.
                            SDL.SDL_EnableScreenSaver();
                        }

                        // Window Resize
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED)
                        {
                            Mouse.INTERNAL_WindowWidth  = evt.window.data1;
                            Mouse.INTERNAL_WindowHeight = evt.window.data2;

                            // Should be called on user resize only, NOT ApplyChanges!
                            ((SDL2_GameWindow)Window).INTERNAL_ClientSizeChanged();
                        }
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED)
                        {
                            Mouse.INTERNAL_WindowWidth  = evt.window.data1;
                            Mouse.INTERNAL_WindowHeight = evt.window.data2;

                            // Need to reset the graphics device any time the window size changes
                            if (Game.graphicsDeviceManager.IsFullScreen)
                            {
                                GraphicsDevice device = Game.GraphicsDevice;
                                Game.graphicsDeviceManager.INTERNAL_ResizeGraphicsDevice(
                                    device.GLDevice.Backbuffer.Width,
                                    device.GLDevice.Backbuffer.Height
                                    );
                            }
                            else
                            {
                                Game.graphicsDeviceManager.INTERNAL_ResizeGraphicsDevice(
                                    evt.window.data1,
                                    evt.window.data2
                                    );
                            }
                        }

                        // Window Move
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED)
                        {
                            /* Apparently if you move the window to a new
                             * display, a GraphicsDevice Reset occurs.
                             * -flibit
                             */
                            int newIndex = SDL.SDL_GetWindowDisplayIndex(
                                Window.Handle
                                );
                            if (newIndex != displayIndex)
                            {
                                displayIndex = newIndex;
                                INTERNAL_GenerateDisplayModes();
                                Game.GraphicsDevice.Reset();
                            }
                        }

                        // Mouse Focus
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER)
                        {
                            SDL.SDL_DisableScreenSaver();
                        }
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE)
                        {
                            SDL.SDL_EnableScreenSaver();
                        }
                    }

                    // Controller device management
                    else if (evt.type == SDL.SDL_EventType.SDL_JOYDEVICEADDED)
                    {
                        GamePad.INTERNAL_AddInstance(evt.jdevice.which);
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_JOYDEVICEREMOVED)
                    {
                        GamePad.INTERNAL_RemoveInstance(evt.jdevice.which);
                    }

                    // Text Input
                    else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT && !INTERNAL_TextInputSuppress)
                    {
                        string text;
                        unsafe { text = new string((char *)evt.text.text); }
                        if (text.Length > 0)
                        {
                            TextInputEXT.OnTextInput(text[0]);
                        }
                    }

                    // Quit
                    else if (evt.type == SDL.SDL_EventType.SDL_QUIT)
                    {
                        INTERNAL_runApplication = false;
                        break;
                    }
                }
                // Text Input Controls Key Handling
                INTERNAL_TextInputUpdate();

                Keyboard.SetKeys(keys);
                Game.Tick();
            }

            // We out.
            Game.Exit();
        }
Esempio n. 13
0
        public override void RunLoop()
        {
            SDL.SDL_ShowWindow(Window.Handle);
            if (Window.IsBorderlessEXT)
            {
                /* FIXME: SDL2/X11 bug!
                 * See SDL2_GameWindow.IsBorderlessEXT.
                 * -flibit
                 */
                SDL.SDL_SetWindowBordered(
                    Window.Handle,
                    SDL.SDL_bool.SDL_FALSE
                    );
            }

            SDL.SDL_Event evt;

            while (INTERNAL_runApplication)
            {
                while (SDL.SDL_PollEvent(out evt) == 1)
                {
                    // Keyboard
                    if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN)
                    {
#if USE_SCANCODES
                        Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode);
#else
                        Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym);
#endif
                        if (!keys.Contains(key))
                        {
                            keys.Add(key);
                            INTERNAL_TextInputIn(key);
                        }
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_KEYUP)
                    {
#if USE_SCANCODES
                        Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode);
#else
                        Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym);
#endif
                        if (keys.Remove(key))
                        {
                            INTERNAL_TextInputOut(key);
                        }
                    }

                    // Mouse Input
                    else if (evt.type == SDL.SDL_EventType.SDL_MOUSEMOTION)
                    {
                        Mouse.INTERNAL_IsWarped = false;
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_MOUSEWHEEL)
                    {
                        // 120 units per notch. Because reasons.
                        Mouse.INTERNAL_MouseWheel += evt.wheel.y * 120;
                    }

                    // Touch Input
                    else if (evt.type == SDL.SDL_EventType.SDL_FINGERDOWN)
                    {
                        TouchPanel.AddEvent(
                            (int)evt.tfinger.touchId,
                            TouchLocationState.Pressed,
                            new Vector2(
                                evt.tfinger.x,
                                evt.tfinger.y
                                )
                            );
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_FINGERUP)
                    {
                        TouchPanel.AddEvent(
                            (int)evt.tfinger.touchId,
                            TouchLocationState.Released,
                            new Vector2(
                                evt.tfinger.x,
                                evt.tfinger.y
                                )
                            );
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_FINGERMOTION)
                    {
                        TouchPanel.AddEvent(
                            (int)evt.tfinger.touchId,
                            TouchLocationState.Moved,
                            new Vector2(
                                evt.tfinger.x,
                                evt.tfinger.y
                                )
                            );
                    }

                    // Various Window Events...
                    else if (evt.type == SDL.SDL_EventType.SDL_WINDOWEVENT)
                    {
                        // Window Focus
                        if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED)
                        {
                            IsActive = true;

                            if (!INTERNAL_useFullscreenSpaces)
                            {
                                // If we alt-tab away, we lose the 'fullscreen desktop' flag on some WMs
                                SDL.SDL_SetWindowFullscreen(
                                    Window.Handle,
                                    Game.GraphicsDevice.PresentationParameters.IsFullScreen ?
                                    (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP :
                                    0
                                    );
                            }

                            // Disable the screensaver when we're back.
                            SDL.SDL_DisableScreenSaver();
                        }
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST)
                        {
                            IsActive = false;

                            if (!INTERNAL_useFullscreenSpaces)
                            {
                                SDL.SDL_SetWindowFullscreen(Window.Handle, 0);
                            }

                            // Give the screensaver back, we're not that important now.
                            SDL.SDL_EnableScreenSaver();
                        }

                        // Window Resize
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED)
                        {
                            Mouse.INTERNAL_WindowWidth  = evt.window.data1;
                            Mouse.INTERNAL_WindowHeight = evt.window.data2;

                            // Should be called on user resize only, NOT ApplyChanges!
                            ((SDL2_GameWindow)Window).INTERNAL_ClientSizeChanged();
                        }
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED)
                        {
                            Mouse.INTERNAL_WindowWidth  = evt.window.data1;
                            Mouse.INTERNAL_WindowHeight = evt.window.data2;

                            // Need to reset the graphics device any time the window size changes
                            GraphicsDeviceManager gdm = Game.Services.GetService(
                                typeof(IGraphicsDeviceService)
                                ) as GraphicsDeviceManager;
                            // FIXME: gdm == null? -flibit
                            if (gdm.IsFullScreen)
                            {
                                GraphicsDevice device = Game.GraphicsDevice;
                                gdm.INTERNAL_ResizeGraphicsDevice(
                                    device.GLDevice.Backbuffer.Width,
                                    device.GLDevice.Backbuffer.Height
                                    );
                            }
                            else
                            {
                                gdm.INTERNAL_ResizeGraphicsDevice(
                                    evt.window.data1,
                                    evt.window.data2
                                    );
                            }
                        }

                        // Window Move
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED)
                        {
                            /* Apparently if you move the window to a new
                             * display, a GraphicsDevice Reset occurs.
                             * -flibit
                             */
                            int newIndex = SDL.SDL_GetWindowDisplayIndex(
                                Window.Handle
                                );
                            if (newIndex != displayIndex)
                            {
                                displayIndex = newIndex;
                                INTERNAL_GenerateDisplayModes();
                                Game.GraphicsDevice.Reset();
                            }
                        }

                        // Mouse Focus
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER)
                        {
                            SDL.SDL_DisableScreenSaver();
                        }
                        else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE)
                        {
                            SDL.SDL_EnableScreenSaver();
                        }
                    }

                    // Controller device management
                    else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED)
                    {
                        GamePad.INTERNAL_AddInstance(evt.cdevice.which);
                    }
                    else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED)
                    {
                        GamePad.INTERNAL_RemoveInstance(evt.cdevice.which);
                    }

                    // Text Input
                    else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT && !INTERNAL_TextInputSuppress)
                    {
                        string text;

                        // Based on the SDL2# LPUtf8StrMarshaler
                        unsafe
                        {
                            byte *endPtr = evt.text.text;
                            while (*endPtr != 0)
                            {
                                endPtr++;
                            }
                            byte[] bytes = new byte[endPtr - evt.text.text];
                            Marshal.Copy((IntPtr)evt.text.text, bytes, 0, bytes.Length);
                            text = System.Text.Encoding.UTF8.GetString(bytes);
                        }

                        if (text.Length > 0)
                        {
                            TextInputEXT.OnTextInput(text[0]);
                        }
                    }

                    // Quit
                    else if (evt.type == SDL.SDL_EventType.SDL_QUIT)
                    {
                        INTERNAL_runApplication = false;
                        break;
                    }
                }
                // Text Input Controls Key Handling
                INTERNAL_TextInputUpdate();

                Keyboard.SetKeys(keys);
                Game.Tick();
            }

            // We out.
            Game.Exit();
        }