Inheritance: INativeWindow, IInputDriver
Beispiel #1
0
        static void ProcessKeyEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
        {
            bool key_pressed = ev.key.state == SDL.SDL_PRESSED;
            var  key         = ev.key.keysym;

            window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
        }
Beispiel #2
0
        private static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev)
        {
            // Calculate the length of the typed text string
            int length;

            for (length = 0; length < TextInputEvent.TextSize && ev.Text[length] != '\0'; length++)
            {
                ;
            }

            // Make sure we have enough space to decode this string
            int decoded_length = Encoding.UTF8.GetCharCount(ev.Text, length);

            if (window.DecodeTextBuffer.Length < decoded_length)
            {
                Array.Resize(
                    ref window.DecodeTextBuffer,
                    2 * Math.Max(decoded_length, window.DecodeTextBuffer.Length));
            }

            // Decode the string from UTF8 to .Net UTF16
            fixed(char *pBuffer = window.DecodeTextBuffer)
            {
                decoded_length = System.Text.Encoding.UTF8.GetChars(
                    ev.Text,
                    length,
                    pBuffer,
                    window.DecodeTextBuffer.Length);
            }

            for (int i = 0; i < decoded_length; i++)
            {
                window.OnKeyPress(window.DecodeTextBuffer[i]);
            }
        }
Beispiel #3
0
        static void ProcessButtonEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
        {
            bool button_pressed = ev.button.state == SDL.SDL_PRESSED;

            // We need MouseUp events to be reported even if they occur
            // outside the window. SetWindowGrab ensures we get them.
            if (window.CursorVisible)
            {
                SDL.SDL_SetWindowGrab(window.window.Handle,
                                      button_pressed ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
            }

            switch (ev.button.button)
            {
            case (byte)SDL.SDL_BUTTON_LEFT:
                window.mouse[MouseButton.Left] = button_pressed;
                break;

            case (byte)SDL.SDL_BUTTON_MIDDLE:
                window.mouse[MouseButton.Middle] = button_pressed;
                break;

            case (byte)SDL.SDL_BUTTON_RIGHT:
                window.mouse[MouseButton.Right] = button_pressed;
                break;

            case (byte)SDL.SDL_BUTTON_X1:
                window.mouse[MouseButton.Button1] = button_pressed;
                break;

            case (byte)SDL.SDL_BUTTON_X2:
                window.mouse[MouseButton.Button2] = button_pressed;
                break;
            }
        }
Beispiel #4
0
        static void ProcessMouseMotionEvent(Sdl2NativeWindow window, MouseMotionEvent ev)
        {
            float scale = window.ClientSize.Width / (float)window.Size.Width;

            window.OnMouseMove(
                (int)Math.Round(ev.X * scale),
                (int)Math.Round(ev.Y * scale));
        }
Beispiel #5
0
        static void ProcessButtonEvent(Sdl2NativeWindow window, Event ev)
        {
            bool button_pressed = ev.Button.State == State.Pressed;

            // We need MouseUp events to be reported even if they occur
            // outside the window. SetWindowGrab ensures we get them.
            if (window.CursorVisible)
            {
                SDL.SetWindowGrab(window.window.Handle,
                                  button_pressed ? true : false);
            }
        }
Beispiel #6
0
        private static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
        {
            bool key_pressed = ev.Key.State == State.Pressed;
            Key  key         = TranslateKey(ev.Key.Keysym.Scancode);

            if (key_pressed)
            {
                window.OnKeyDown(key, ev.Key.Repeat > 0);
            }
            else
            {
                window.OnKeyUp(key);
            }
        }
Beispiel #7
0
        static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
        {
            bool key_pressed = ev.Key.State == State.Pressed;
            var  key         = ev.Key.Keysym;

            window.key_args.Key      = TranslateKey(key.Scancode);
            window.key_args.ScanCode = (uint)key.Scancode;
            if (key_pressed)
            {
                window.KeyDown(window, window.key_args);
            }
            else
            {
                window.KeyUp(window, window.key_args);
            }
            //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
        }
Beispiel #8
0
        private static void ProcessMouseButtonEvent(Sdl2NativeWindow window, MouseButtonEvent ev)
        {
            bool button_pressed = ev.State == State.Pressed;

            // We need MouseUp events to be reported even if they occur
            // outside the window. SetWindowGrab ensures we get them.
            if (window.CursorVisible)
            {
                SDL.SetWindowGrab(window.window.Handle,
                                  button_pressed ? true : false);
            }

            MouseButton button = Sdl2Mouse.TranslateButton(ev.Button);

            if (button_pressed)
            {
                window.OnMouseDown(button);
            }
            else
            {
                window.OnMouseUp(button);
            }
        }
        static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev)
        {
            var keyPress = window.KeyPress;

            if (keyPress != null)
            {
                var   length = 0;
                byte *pText  = ev.Text;
                while (*pText != 0)
                {
                    length++;
                    pText++;
                }
                using (var stream = new System.IO.UnmanagedMemoryStream(ev.Text, length))
                    using (var reader = new System.IO.StreamReader(stream, Encoding.UTF8))
                    {
                        var text = reader.ReadToEnd();
                        foreach (var c in text)
                        {
                            keyPress(window, new KeyPressEventArgs(c));
                        }
                    }
            }
        }
 static void ProcessMouseMotionEvent(Sdl2NativeWindow window, MouseMotionEvent ev)
 {
     float scale = window.ClientSize.Width / (float)window.Size.Width;
     window.OnMouseMove(
         (int)Math.Round(ev.X * scale),
         (int)Math.Round(ev.Y * scale));
 }
 static void ProcessMouseWheelEvent(Sdl2NativeWindow window, MouseWheelEvent ev)
 {
     window.OnMouseWheel(ev.X, ev.Y);
 }
Beispiel #12
0
 static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev)
 {
     var keyPress = window.KeyPress;
     if (keyPress != null)
     {
         var length = 0;
         byte* pText = ev.Text;
         while (*pText != 0)
         {
             length++;
             pText++;
         }
         using (var stream = new System.IO.UnmanagedMemoryStream(ev.Text, length))
         using (var reader = new System.IO.StreamReader(stream, Encoding.UTF8))
         {
             var text = reader.ReadToEnd();
             foreach (var c in text)
             {
                 keyPress(window, new KeyPressEventArgs(c));
             }
         }
     }
 }
        static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev)
        {
            // Calculate the length of the typed text string
            int length;
            for (length = 0; length < TextInputEvent.TextSize && ev.Text[length] != '\0'; length++)
                ;

            // Make sure we have enough space to decode this string
            int decoded_length = Encoding.UTF8.GetCharCount(ev.Text, length);
            if (window.DecodeTextBuffer.Length < decoded_length)
            {
                Array.Resize(
                    ref window.DecodeTextBuffer,
                    2 * Math.Max(decoded_length, window.DecodeTextBuffer.Length));
            }

            // Decode the string from UTF8 to .Net UTF16
            fixed (char* pBuffer = window.DecodeTextBuffer)
            {
                decoded_length = System.Text.Encoding.UTF8.GetChars(
                    ev.Text,
                    length,
                    pBuffer,
                    window.DecodeTextBuffer.Length);
            }

            for (int i = 0; i < decoded_length; i++)
            {
                window.OnKeyPress(window.DecodeTextBuffer[i]);
            }
        }
Beispiel #14
0
 static void ProcessWheelEvent(Sdl2NativeWindow window, Event ev)
 {
     //window.mouse.Wheel += ev.wheel.y;
 }
Beispiel #15
0
 static void ProcessKeyEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
 {
     bool key_pressed = ev.key.state == SDL.SDL_PRESSED;
     var key = ev.key.keysym;
     window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
 }
Beispiel #16
0
 static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
 {
     bool key_pressed = ev.Key.State == State.Pressed;
     var key = ev.Key.Keysym;
     //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
 }
Beispiel #17
0
 static void ProcessMotionEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
 {
         window.mouse.Position = new Point(ev.motion.x, ev.motion.y);
 }
Beispiel #18
0
 static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
 {
     bool key_pressed = ev.Key.State == State.Pressed;
     var key = ev.Key.Keysym;
     var args = new KeyboardKeyEventArgs() 
     { 
         Key = TranslateKey(key.Scancode),
         ScanCode = (uint)key.Scancode
     };
     if (key_pressed)
         window.KeyDown(window, args);
     else
         window.KeyUp(window, args);
     //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
 }
Beispiel #19
0
        static void ProcessButtonEvent(Sdl2NativeWindow window, Event ev)
        {
            bool button_pressed = ev.Button.State == State.Pressed;

            // We need MouseUp events to be reported even if they occur
            // outside the window. SetWindowGrab ensures we get them.
            if (window.CursorVisible)
            {
                SDL.SetWindowGrab(window.window.Handle,
                    button_pressed ? true : false);
            }
        }
Beispiel #20
0
        unsafe static int FilterEvents(IntPtr user_data, IntPtr e)
        {
            bool processed = false;

            try
            {
                Sdl2NativeWindow window = null;
                Event            ev     = *(Event *)e;

                switch (ev.Type)
                {
                case EventType.WINDOWEVENT:
                    if (windows.TryGetValue(ev.Window.WindowID, out window))
                    {
                        ProcessWindowEvent(window, ev.Window);
                        processed = true;
                    }
                    break;

                case EventType.TEXTINPUT:
                    if (windows.TryGetValue(ev.Text.WindowID, out window))
                    {
                        ProcessTextInputEvent(window, ev.Text);
                        processed = true;
                    }
                    break;

                case EventType.KEYDOWN:
                case EventType.KEYUP:
                    if (windows.TryGetValue(ev.Key.WindowID, out window))
                    {
                        ProcessKeyEvent(window, ev);
                        processed = true;
                    }
                    break;

                case EventType.MOUSEBUTTONDOWN:
                case EventType.MOUSEBUTTONUP:
                    if (windows.TryGetValue(ev.Button.WindowID, out window))
                    {
                        ProcessButtonEvent(window, ev);
                        processed = true;
                    }
                    break;

                case EventType.MOUSEMOTION:
                    if (windows.TryGetValue(ev.Motion.WindowID, out window))
                    {
                        ProcessMotionEvent(window, ev);
                        processed = true;
                    }
                    break;

                case EventType.MOUSEWHEEL:
                    if (windows.TryGetValue(ev.Wheel.WindowID, out window))
                    {
                        ProcessWheelEvent(window, ev);
                        processed = true;
                    }
                    break;

                case EventType.QUIT:
                    Debug.WriteLine("Sdl2 application quit");
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
            }

            return(processed ? 0 : 1);
        }
Beispiel #21
0
        static void ProcessWindowEvent(Sdl2NativeWindow window, SDL.SDL_WindowEvent e)
        {
            switch (e.windowEvent)
            {
            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE:
                var close_args = new System.ComponentModel.CancelEventArgs();
                window.Closing(window, close_args);
                if (!close_args.Cancel)
                {
                    window.Closed(window, EventArgs.Empty);
                    //window.DestroyWindow();
                }
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER:
                window.MouseEnter(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE:
                window.MouseLeave(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED:
                // do nothing
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
                window.is_focused = true;
                window.FocusedChanged(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
                window.is_focused = false;
                window.FocusedChanged(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN:
                window.is_visible = false;
                window.VisibleChanged(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN:
                window.is_visible = true;
                window.VisibleChanged(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED:
                window.previous_window_state = window.window_state;
                window.window_state          = OpenTK.WindowState.Maximized;
                window.WindowStateChanged(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED:
                window.previous_window_state = window.window_state;
                window.window_state          = OpenTK.WindowState.Minimized;
                window.WindowStateChanged(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED:
                window.window_state = window.previous_window_state;
                window.WindowStateChanged(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED:
                window.Move(window, EventArgs.Empty);
                break;

            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED:
            case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
                window.Resize(window, EventArgs.Empty);
                break;

            default:
                Debug.Print("SDL2 unhandled event: {0}", e.type);
                break;
            }
        }
Beispiel #22
0
 static void ProcessMotionEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
 {
     window.mouse.Position = new Point(ev.motion.x, ev.motion.y);
 }
        static void ProcessWindowEvent(Sdl2NativeWindow window, WindowEvent e)
        {
            switch (e.Event)
            {
                case WindowEventID.CLOSE:
                    var close_args = new System.ComponentModel.CancelEventArgs();
                    try
                    {
                        window.is_in_closing_event = true;
                        window.OnClosing(close_args);
                    }
                    finally
                    {
                        window.is_in_closing_event = false;
                    }

                    if (!close_args.Cancel)
                    {
                        window.OnClosed(EventArgs.Empty);
                        window.must_destroy = true;
                    }
                    break;

                case WindowEventID.ENTER:
                    window.OnMouseEnter(EventArgs.Empty);
                    break;

                case WindowEventID.LEAVE:
                    window.OnMouseLeave(EventArgs.Empty);
                    break;

                case WindowEventID.EXPOSED:
                    // do nothing
                    break;

                case WindowEventID.FOCUS_GAINED:
                    window.is_focused = true;
                    window.OnFocusedChanged(EventArgs.Empty);
                    break;

                case WindowEventID.FOCUS_LOST:
                    window.is_focused = false;
                    window.OnFocusedChanged(EventArgs.Empty);
                    break;

                case WindowEventID.HIDDEN:
                    window.is_visible = false;
                    window.OnVisibleChanged(EventArgs.Empty);
                    break;

                case WindowEventID.SHOWN:
                    window.is_visible = true;
                    window.OnVisibleChanged(EventArgs.Empty);
                    break;

                case WindowEventID.MAXIMIZED:
                    window.window_state = WindowState.Maximized;
                    window.OnWindowStateChanged(EventArgs.Empty);
                    break;

                case WindowEventID.MINIMIZED:
                    window.previous_window_state = window.window_state;
                    window.window_state = WindowState.Minimized;
                    window.OnWindowStateChanged(EventArgs.Empty);
                    break;

                case WindowEventID.RESTORED:
                    window.window_state = window.previous_window_state;
                    window.OnWindowStateChanged(EventArgs.Empty);
                    break;

                case WindowEventID.MOVED:
                    window.OnMove(EventArgs.Empty);
                    break;

                case WindowEventID.RESIZED:
                case WindowEventID.SIZE_CHANGED:
                    window.OnResize(EventArgs.Empty);
                    break;

                default:
                    Debug.Print("SDL2 unhandled event: {0}", e.Type);
                    break;
            }
        }
Beispiel #24
0
        private static unsafe void ProcessDropEvent(Sdl2NativeWindow window, DropEvent ev)
        {
            string dropString = Marshal.PtrToStringAuto(ev.File);

            window.OnFileDrop(dropString);
        }
Beispiel #25
0
        static void ProcessWindowEvent(Sdl2NativeWindow window, SDL.SDL_WindowEvent e)
        {
            switch (e.windowEvent)
            {
                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE:
                    var close_args = new System.ComponentModel.CancelEventArgs();
                    window.Closing(window, close_args);
                    if (!close_args.Cancel)
                    {
                        window.Closed(window, EventArgs.Empty);
                        //window.DestroyWindow();
                    }
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER:
                    window.MouseEnter(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE:
                    window.MouseLeave(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_EXPOSED:
                    // do nothing
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED:
                    window.is_focused = true;
                    window.FocusedChanged(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST:
                    window.is_focused = false;
                    window.FocusedChanged(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_HIDDEN:
                    window.is_visible = false;
                    window.VisibleChanged(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SHOWN:
                    window.is_visible = true;
                    window.VisibleChanged(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MAXIMIZED:
                    window.previous_window_state = window.window_state;
                    window.window_state = OpenTK.WindowState.Maximized;
                    window.WindowStateChanged(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MINIMIZED:
                    window.previous_window_state = window.window_state;
                    window.window_state = OpenTK.WindowState.Minimized;
                    window.WindowStateChanged(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESTORED:
                    window.window_state = window.previous_window_state;
                    window.WindowStateChanged(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED:
                    window.Move(window, EventArgs.Empty);
                    break;

                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED:
                case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
                    window.Resize(window, EventArgs.Empty);
                    break;

                default:
                    Debug.Print("SDL2 unhandled event: {0}", e.type);
                    break;
            }
        }
Beispiel #26
0
        static void ProcessButtonEvent(Sdl2NativeWindow window, SDL.SDL_Event ev)
        {
            bool button_pressed = ev.button.state == SDL.SDL_PRESSED;

            // We need MouseUp events to be reported even if they occur
            // outside the window. SetWindowGrab ensures we get them.
            if (window.CursorVisible)
            {
                SDL.SDL_SetWindowGrab(window.window.Handle,
                    button_pressed ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
            }

            switch (ev.button.button)
            {
                case (byte)SDL.SDL_BUTTON_LEFT:
                    window.mouse[MouseButton.Left] = button_pressed;
                    break;

                case (byte)SDL.SDL_BUTTON_MIDDLE:
                    window.mouse[MouseButton.Middle] = button_pressed;
                    break;
                
                case (byte)SDL.SDL_BUTTON_RIGHT:
                    window.mouse[MouseButton.Right] = button_pressed;
                    break;
                
                case (byte)SDL.SDL_BUTTON_X1:
                    window.mouse[MouseButton.Button1] = button_pressed;
                    break;
                
                case (byte)SDL.SDL_BUTTON_X2:
                    window.mouse[MouseButton.Button2] = button_pressed;
                    break;
            }
        }
Beispiel #27
0
 static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev)
 {
     float scale = window.ClientSize.Width / (float)window.Size.Width;
     //window.mouse.Position = new Point(
     //    (int)(ev.motion.x * scale), (int)(ev.motion.y * scale));
 }
        static void ProcessMouseButtonEvent(Sdl2NativeWindow window, MouseButtonEvent ev)
        {
            bool button_pressed = ev.State == State.Pressed;

            // We need MouseUp events to be reported even if they occur
            // outside the window. SetWindowGrab ensures we get them.
            if (window.CursorVisible)
            {
                SDL.SetWindowGrab(window.window.Handle,
                    button_pressed ? true : false);
            }

            MouseButton button = Sdl2Mouse.TranslateButton(ev.Button);
            if (button_pressed)
            {
                window.OnMouseDown(button);
            }
            else
            {
                window.OnMouseUp(button);
            }
        }
Beispiel #29
0
        private int ProcessEvent(ref Event ev)
        {
            bool processed = false;

            try
            {
                Sdl2NativeWindow window = null;

                switch (ev.Type)
                {
                case EventType.WINDOWEVENT:
                    if (windows.TryGetValue(ev.Window.WindowID, out window))
                    {
                        ProcessWindowEvent(window, ev.Window);
                        processed = true;
                    }
                    break;

                case EventType.TEXTINPUT:
                    if (windows.TryGetValue(ev.Text.WindowID, out window))
                    {
                        ProcessTextInputEvent(window, ev.Text);
                        processed = true;
                    }
                    break;

                case EventType.KEYDOWN:
                case EventType.KEYUP:
                    if (windows.TryGetValue(ev.Key.WindowID, out window))
                    {
                        ProcessKeyEvent(window, ev);
                        processed = true;
                    }
                    break;

                case EventType.MOUSEBUTTONDOWN:
                case EventType.MOUSEBUTTONUP:
                    if (windows.TryGetValue(ev.Button.WindowID, out window))
                    {
                        ProcessMouseButtonEvent(window, ev.Button);
                        processed = true;
                    }
                    break;

                case EventType.MOUSEMOTION:
                    if (windows.TryGetValue(ev.Motion.WindowID, out window))
                    {
                        ProcessMouseMotionEvent(window, ev.Motion);
                        processed = true;
                    }
                    break;

                case EventType.MOUSEWHEEL:
                    if (windows.TryGetValue(ev.Wheel.WindowID, out window))
                    {
                        ProcessMouseWheelEvent(window, ev.Wheel);
                        processed = true;
                    }
                    break;

                case EventType.DROPFILE:
                    if (windows.TryGetValue(ev.Drop.WindowID, out window))
                    {
                        ProcessDropEvent(window, ev.Drop);
                        SDL.Free(ev.Drop.File);
                        processed = true;
                    }
                    break;

                case EventType.QUIT:
                    Debug.WriteLine("Sdl2 application quit");
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
            }

            return(processed ? 0 : 1);
        }
 static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
 {
     bool key_pressed = ev.Key.State == State.Pressed;
     Key key = TranslateKey(ev.Key.Keysym.Scancode);
     if (key_pressed)
     {
         window.OnKeyDown(key, ev.Key.Repeat > 0);
     }
     else
     {
         window.OnKeyUp(key);
     }
 }
Beispiel #31
0
 static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
 {
     bool key_pressed = ev.Key.State == State.Pressed;
     var key = ev.Key.Keysym;
     window.key_args.Key = TranslateKey(key.Scancode);
     window.key_args.ScanCode = (uint)key.Scancode;
     window.key_args.Modifiers = window.input_driver.Keyboard[0].GetModifiers();
     if (key_pressed)
     {
         window.KeyDown(window, window.key_args);
     }
     else
     {
         window.KeyUp(window, window.key_args);
     }
     //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed);
 }
Beispiel #32
0
        unsafe static int FilterEvents(IntPtr user_data, IntPtr e)
        {
            bool processed = false;

            try
            {
                Sdl2NativeWindow window = null;
                SDL.SDL_Event    ev     = *(SDL.SDL_Event *)e;

                switch (ev.type)
                {
                case SDL.SDL_EventType.SDL_WINDOWEVENT:
                    if (windows.TryGetValue(ev.window.windowID, out window))
                    {
                        ProcessWindowEvent(window, ev.window);
                        processed = true;
                    }
                    break;

                case SDL.SDL_EventType.SDL_KEYDOWN:
                case SDL.SDL_EventType.SDL_KEYUP:
                    if (windows.TryGetValue(ev.key.windowID, out window))
                    {
                        ProcessKeyEvent(window, ev);
                        processed = true;
                    }
                    break;

                case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
                    if (windows.TryGetValue(ev.button.windowID, out window))
                    {
                        ProcessButtonEvent(window, ev);
                        processed = true;
                    }
                    break;

                case SDL.SDL_EventType.SDL_MOUSEMOTION:
                    if (windows.TryGetValue(ev.motion.windowID, out window))
                    {
                        ProcessMotionEvent(window, ev);
                        processed = true;
                    }
                    break;

                case SDL.SDL_EventType.SDL_MOUSEWHEEL:
                    if (windows.TryGetValue(ev.wheel.windowID, out window))
                    {
                        ProcessWheelEvent(window, ev);
                        processed = true;
                    }
                    break;

                case SDL.SDL_EventType.SDL_QUIT:
                    Debug.WriteLine("Sdl2 application quit");
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
            }

            return(processed ? 0 : 1);
        }
Beispiel #33
0
 private static void ProcessMouseWheelEvent(Sdl2NativeWindow window, MouseWheelEvent ev)
 {
     window.OnMouseWheel(ev.X, ev.Y);
 }
Beispiel #34
0
 static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev)
 {
     float scale = window.ClientSize.Width / (float)window.Size.Width;
     //window.mouse.Position = new Point(
     //    (int)(ev.motion.x * scale), (int)(ev.motion.y * scale));
 }
Beispiel #35
0
        private static void ProcessWindowEvent(Sdl2NativeWindow window, WindowEvent e)
        {
            switch (e.Event)
            {
            case WindowEventID.CLOSE:
                var close_args = new System.ComponentModel.CancelEventArgs();
                try
                {
                    window.is_in_closing_event = true;
                    window.OnClosing(close_args);
                }
                finally
                {
                    window.is_in_closing_event = false;
                }

                if (!close_args.Cancel)
                {
                    window.OnClosed(EventArgs.Empty);
                    window.must_destroy = true;
                }
                break;

            case WindowEventID.ENTER:
                window.OnMouseEnter(EventArgs.Empty);
                break;

            case WindowEventID.LEAVE:
                window.OnMouseLeave(EventArgs.Empty);
                break;

            case WindowEventID.EXPOSED:
                // do nothing
                break;

            case WindowEventID.FOCUS_GAINED:
                window.is_focused = true;
                window.OnFocusedChanged(EventArgs.Empty);
                break;

            case WindowEventID.FOCUS_LOST:
                window.is_focused = false;
                window.OnFocusedChanged(EventArgs.Empty);
                break;

            case WindowEventID.HIDDEN:
                window.is_visible = false;
                window.OnVisibleChanged(EventArgs.Empty);
                break;

            case WindowEventID.SHOWN:
                window.is_visible = true;
                window.OnVisibleChanged(EventArgs.Empty);
                break;

            case WindowEventID.MAXIMIZED:
                window.window_state = WindowState.Maximized;
                window.OnWindowStateChanged(EventArgs.Empty);
                break;

            case WindowEventID.MINIMIZED:
                window.previous_window_state = window.window_state;
                window.window_state          = WindowState.Minimized;
                window.OnWindowStateChanged(EventArgs.Empty);
                break;

            case WindowEventID.RESTORED:
                window.window_state = window.previous_window_state;
                window.OnWindowStateChanged(EventArgs.Empty);
                break;

            case WindowEventID.MOVED:
                window.OnMove(EventArgs.Empty);
                break;

            case WindowEventID.RESIZED:
            case WindowEventID.SIZE_CHANGED:
                window.OnResize(EventArgs.Empty);
                break;

            default:
                Debug.Print("SDL2 unhandled event: {0}", e.Type);
                break;
            }
        }
Beispiel #36
0
 static void ProcessWheelEvent(Sdl2NativeWindow window, Event ev)
 {
     //window.mouse.Wheel += ev.wheel.y;
 }