Esempio n. 1
0
 private void OnKeyDown(ref SDL.SDL_Event Event)
 {
     if (KeyDown != null)
     {
         KeyDown(this, ref Event);
     }
 }
Esempio n. 2
0
 private void OnLastEvent(ref SDL.SDL_Event Event)
 {
     if (LastEvent != null)
     {
         LastEvent(this, ref Event);
     }
 }
Esempio n. 3
0
 private void OnJoyButtonDown(ref SDL.SDL_Event Event)
 {
     if (JoyButtonDown != null)
     {
         JoyButtonDown(this, ref Event);
     }
 }
Esempio n. 4
0
 private void OnJoyDeviceRemoved(ref SDL.SDL_Event Event)
 {
     if (JoyDeviceRemoved != null)
     {
         JoyDeviceRemoved(this, ref Event);
     }
 }
Esempio n. 5
0
 private void OnDropFile(ref SDL.SDL_Event Event)
 {
     if (DropFile != null)
     {
         DropFile(this, ref Event);
     }
 }
Esempio n. 6
0
 private void OnFingerUp(ref SDL.SDL_Event Event)
 {
     if (FingerUp != null)
     {
         FingerUp(this, ref Event);
     }
 }
        public MouseMotionEventArgs(SDL.SDL_Event rawEvent)
            : base(rawEvent)
        {
            RawTimeStamp               = rawEvent.motion.timestamp;
            WindowID                   = rawEvent.motion.windowID;
            MouseDeviceID              = rawEvent.motion.which;
            RelativeToWindowX          = rawEvent.motion.x;
            RelativeToWindowY          = rawEvent.motion.y;
            RelativeToLastMotionEventX = rawEvent.motion.xrel;
            RelativeToLastMotionEventY = rawEvent.motion.yrel;

            List <MouseButtonCode> buttonsPressed = new List <MouseButtonCode>();

            if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_LEFT)
            {
                buttonsPressed.Add(MouseButtonCode.Left);
            }
            if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_MIDDLE)
            {
                buttonsPressed.Add(MouseButtonCode.Middle);
            }
            if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_RIGHT)
            {
                buttonsPressed.Add(MouseButtonCode.Right);
            }
            if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_X1)
            {
                buttonsPressed.Add(MouseButtonCode.X1);
            }
            if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_X2)
            {
                buttonsPressed.Add(MouseButtonCode.X2);
            }
            MouseButtonsPressed = buttonsPressed;
        }
Esempio n. 8
0
 private void OnDollarGesture(ref SDL.SDL_Event Event)
 {
     if (DollarGesture != null)
     {
         DollarGesture(this, ref Event);
     }
 }
Esempio n. 9
0
        private void HandleMouseButtonEvent(SDL.SDL_Event e)
        {
            bool         isDown = false;
            eMouseButton button = eMouseButton.Any;

            if (e.type == SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN)
            {
                isDown = true;
            }

            if (e.button.button == SDL.SDL_BUTTON_LEFT)
            {
                button = eMouseButton.Left;
            }
            else if (e.button.button == SDL.SDL_BUTTON_MIDDLE)
            {
                button = eMouseButton.Middle;
            }
            else if (e.button.button == SDL.SDL_BUTTON_RIGHT)
            {
                button = eMouseButton.Right;
            }

            _input.MouseBindings.UpdateAndDispatchMouseButton(button, isDown);
        }
Esempio n. 10
0
 public virtual void HandleEvent(SDL.SDL_Event e)
 {
     if (e.type == SDL.SDL_EventType.SDL_QUIT)
     {
         IsAlive = false;
     }
 }
Esempio n. 11
0
        public static void HandleEvent(SDL.SDL_Event inputEvent)
        {
            _mouseMotionEvent    = new SDL.SDL_MouseMotionEvent();
            _mouseWheelDirection = 0;

            switch (inputEvent.type)
            {
            case SDL.SDL_EventType.SDL_KEYDOWN:
                _keysDown.Add(inputEvent.key.keysym.sym);
                break;

            case SDL.SDL_EventType.SDL_KEYUP:
                RemoveKey(inputEvent.key.keysym.sym);
                break;

            case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                _mouseButtonsDown.Add(inputEvent.button.button);
                break;

            case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
                RemoveMouseButton(inputEvent.button.button);
                break;

            case SDL.SDL_EventType.SDL_MOUSEMOTION:
                _mouseMotionEvent = inputEvent.motion;
                break;

            case SDL.SDL_EventType.SDL_MOUSEWHEEL:
                _mouseWheelDirection = (int)inputEvent.wheel.direction;
                break;
            }
        }
Esempio n. 12
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);
        }
Esempio n. 13
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;
            }
        }
Esempio n. 14
0
        internal static void ProcessKeyBoardEvents(ref Params gVar, SDL.SDL_Event e)
        {
            bool quit       = false;
            var  playerBody = gVar.Entity[0].Body;

            //var playerVel = entity[0].Body.GetLinearVelocityFromWorldPoint(entity[0].Body.GetWorldCenter());

            switch (e.type)
            {
            case SDL.SDL_EventType.SDL_QUIT:
                quit = true;
                break;

            case SDL.SDL_EventType.SDL_KEYDOWN:
                switch (e.key.keysym.sym)
                {
                case SDL.SDL_Keycode.SDLK_LEFT:
                    // increase left velocity
                    playerBody.SetLinearVelocity(new Vector2(-29.0f, 0.0f));
                    break;

                case SDL.SDL_Keycode.SDLK_RIGHT:
                    playerBody.SetLinearVelocity(new Vector2(+29.0f, 0.0f));
                    break;

                case SDL.SDL_Keycode.SDLK_q:
                    quit = true;
                    break;
                }
                break;

            case SDL.SDL_EventType.SDL_KEYUP:
                switch (e.key.keysym.sym)
                {
                case SDL.SDL_Keycode.SDLK_LEFT:
                    // increase left velocity
                    playerBody.SetLinearVelocity(new Vector2(0.0f, 0.0f));
                    break;

                case SDL.SDL_Keycode.SDLK_RIGHT:
                    playerBody.SetLinearVelocity(new Vector2(0.0f, 0.0f));
                    break;

                case SDL.SDL_Keycode.SDLK_SPACE:
                    Vector2 bulletPos = new Vector2();
                    bulletPos   = playerBody.GetWorldCenter();
                    bulletPos.Y = bulletPos.Y + 1.0f;
                    CreateEntity(ref gVar, bulletPos, 0.1f, 0.1f, Behavior.Bullet);
                    gVar.BulletCount++;
                    gVar.Entity[gVar.Entity.Count - 1].Body.SetLinearVelocity(new Vector2(0.0f, 35.0f));
                    break;
                }
                break;
            }

            if (quit == true)
            {
                CleanUp(ref gVar);
            }
        }
Esempio n. 15
0
        static uint SetupTimerCallback(UInt32 interval, IntPtr?param)
        {
            var      managedMethod        = new ManagedTypeSignature(CallBack);
            Delegate untypedManagedMethod = (Delegate)managedMethod;
            IntPtr   intPtr = Marshal.GetFunctionPointerForDelegate(untypedManagedMethod);

            SDL.SDL_Event     @event    = new SDL.SDL_Event();
            SDL.SDL_UserEvent userevent = new SDL.SDL_UserEvent
            {
                /* In this example, our callback pushes a function
                 * into the queue, and causes our callback to be called again at the
                 * same interval: */

                type  = (uint)SDL.SDL_EventType.SDL_USEREVENT,
                code  = 0,
                data1 = intPtr
            };
            if (param.HasValue)
            {
                userevent.data2 = param.Value;
            }

            @event.type = SDL.SDL_EventType.SDL_USEREVENT;
            @event.user = userevent;

            SDL.SDL_PushEvent(ref @event);
            return(interval);
        }
Esempio n. 16
0
 private void OnControllerDeviceMoved(ref SDL.SDL_Event Event)
 {
     if (ControllerDeviceMoved != null)
     {
         ControllerDeviceMoved(this, ref Event);
     }
 }
Esempio n. 17
0
 public static void HandleKeyUp(SDL.SDL_Event event_)
 {
     if (event_.key.repeat == 0)
     {
         scancodesReleased[(int)event_.key.keysym.scancode] = true;
     }
 }
Esempio n. 18
0
 private void OnDollarRecord(ref SDL.SDL_Event Event)
 {
     if (DollarRecord != null)
     {
         DollarRecord(this, ref Event);
     }
 }
Esempio n. 19
0
 private void HandleEvent(SDL.SDL_Event e, bool down)
 {
     if (controller == null)
     {
         return;
     }
     if (e.cdevice.which != controller.Index &&
         e.jdevice.which != controller.Index)
     {
         return;
     }
     if (controller.IsGameController)
     {
         var button = SDL.SDL_GameControllerGetBindForButton(controller.game_controller, (SDL.SDL_GameControllerButton)index).button;
         if (e.cbutton.button == button)
         {
             pressed   = this.down != down && down;
             released  = this.down != down && !down;
             this.down = down;
         }
     }
     else
     {
         if (e.jbutton.button == index)
         {
             pressed   = this.down != down && down;
             released  = this.down != down && !down;
             this.down = down;
         }
     }
 }
Esempio n. 20
0
 private void OnFingerMotion(ref SDL.SDL_Event Event)
 {
     if (FingerMotion != null)
     {
         FingerMotion(this, ref Event);
     }
 }
Esempio n. 21
0
        //Takes key presses and adjusts the dot's velocity
        public void handleEvent(SDL.SDL_Event e)
        {
            //If a key was pressed
            if (e.type == SDL.SDL_EventType.SDL_KEYDOWN && e.key.repeat == 0)
            {
                //Adjust the velocity
                switch (e.key.keysym.sym)
                {
                case SDL.SDL_Keycode.SDLK_UP: mVelY -= DOT_VEL; break;

                case SDL.SDL_Keycode.SDLK_DOWN: mVelY += DOT_VEL; break;

                case SDL.SDL_Keycode.SDLK_LEFT: mVelX -= DOT_VEL; break;

                case SDL.SDL_Keycode.SDLK_RIGHT: mVelX += DOT_VEL; break;
                }
            }
            //If a key was released
            else if (e.type == SDL.SDL_EventType.SDL_KEYUP && e.key.repeat == 0)
            {
                //Adjust the velocity
                switch (e.key.keysym.sym)
                {
                case SDL.SDL_Keycode.SDLK_UP: mVelY += DOT_VEL; break;

                case SDL.SDL_Keycode.SDLK_DOWN: mVelY -= DOT_VEL; break;

                case SDL.SDL_Keycode.SDLK_LEFT: mVelX += DOT_VEL; break;

                case SDL.SDL_Keycode.SDLK_RIGHT: mVelX -= DOT_VEL; break;
                }
            }
        }
Esempio n. 22
0
 private void OnFirstEvent(ref SDL.SDL_Event Event)
 {
     if (FirstEvent != null)
     {
         FirstEvent(this, ref Event);
     }
 }
Esempio n. 23
0
        /// <summary>Raises an event handler with arguments parsed from the SDL event parameter.
        /// This method does nothing if there are no event subscribers.
        /// </summary>
        /// <param name="eventHandler"></param>
        /// <param name="rawEvent"></param>
        /// <typeparam name="T"></typeparam>
        private void RaiseEvent <T>(EventHandler <T> eventHandler, SDL.SDL_Event rawEvent)
            where T : EventArgs
        {
            var eventArgs = CreateEventArgs <T>(rawEvent);

            RaiseEvent(eventHandler, eventArgs);
        }
Esempio n. 24
0
 private void OnJoyButtonUp(ref SDL.SDL_Event Event)
 {
     if (JoyButtonUp != null)
     {
         JoyButtonUp(this, ref Event);
     }
 }
Esempio n. 25
0
 private void OnClipBoardUpdate(ref SDL.SDL_Event Event)
 {
     if (ClipBoardUpdate != null)
     {
         ClipBoardUpdate(this, ref Event);
     }
 }
Esempio n. 26
0
 private void OnJoyHatMotion(ref SDL.SDL_Event Event)
 {
     if (JoyHatMotion != null)
     {
         JoyHatMotion(this, ref Event);
     }
 }
Esempio n. 27
0
 private void OnControllerAxisMotion(ref SDL.SDL_Event Event)
 {
     if (ControllerAxisMotion != null)
     {
         ControllerAxisMotion(this, ref Event);
     }
 }
Esempio n. 28
0
 private void OnKeyUp(ref SDL.SDL_Event Event)
 {
     if (KeyUp != null)
     {
         KeyUp(this, ref Event);
     }
 }
Esempio n. 29
0
 private void OnControllerButtonUp(ref SDL.SDL_Event Event)
 {
     if (ControllerButtonUp != null)
     {
         ControllerButtonUp(this, ref Event);
     }
 }
Esempio n. 30
0
 private void OnMouseButtonUp(ref SDL.SDL_Event Event)
 {
     if (MouseButtonUp != null)
     {
         MouseButtonUp(this, ref Event);
     }
 }
Esempio n. 31
0
        public void Close()
        {
            lock (sync)
            {
                if (Exists)
                {
                    Debug.Print("SDL2 destroying window {0}", window.Handle);

                    SDL.SDL_Event e = new SDL.SDL_Event();
                    e.type = SDL.SDL_EventType.SDL_WINDOWEVENT;
                    e.window.windowEvent = SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE;
                    e.window.windowID = window_id;
                    lock (SDL.Sync)
                    {
                        SDL.SDL_PushEvent(ref e);
                    }
                }
            }
        }