Beispiel #1
0
        private void ControllerConnected(Window owner, SDL2.SDL_Event ev)
        {
            var instance    = SDL2.SDL_GameControllerOpen(ev.cdevice.which);
            var joyInstance = SDL2.SDL_GameControllerGetJoystick(instance);
            var instanceId  = SDL2.SDL_JoystickInstanceID(joyInstance);

            var playerIndex = ControllerRegistry.Instance.GetFirstFreePlayerSlot();

            SDL2.SDL_GameControllerSetPlayerIndex(instance, playerIndex);

            var name        = SDL2.SDL_GameControllerName(instance);
            var productInfo = new ProductInfo(
                SDL2.SDL_GameControllerGetVendor(instance),
                SDL2.SDL_GameControllerGetProduct(instance)
                );

            var guid = SDL2.SDL_JoystickGetGUID(joyInstance);

            var controllerInfo = new ControllerInfo(instance, instanceId, guid, playerIndex, name, productInfo);

            ControllerRegistry.Instance.Register(instance, controllerInfo);

            owner.Game.OnControllerConnected(
                new ControllerEventArgs(controllerInfo)
                );
        }
Beispiel #2
0
 internal void DispatchEvent(SDL2.SDL_Event ev)
 {
     if (SdlEventHandlers.ContainsKey(ev.type))
     {
         SdlEventHandlers[ev.type]?.Invoke(Owner, ev);
     }
     else
     {
         Log.Debug($"Unsupported generic event: {ev.type}.");
     }
 }
Beispiel #3
0
        private void ControllerDisconnected(Window owner, SDL2.SDL_Event ev)
        {
            var instance       = SDL2.SDL_GameControllerFromInstanceID(ev.cdevice.which);
            var controllerInfo = ControllerRegistry.Instance.GetControllerInfoByPointer(instance);

            ControllerRegistry.Instance.Unregister(instance);

            owner.Game.OnControllerDisconnected(
                new ControllerEventArgs(controllerInfo)
                );
        }
Beispiel #4
0
 private void KeyPressed(Window owner, SDL2.SDL_Event ev)
 {
     Keyboard.OnKeyPressed(
         owner.Game,
         new KeyEventArgs(
             (ScanCode)ev.key.keysym.scancode,
             (KeyCode)ev.key.keysym.sym,
             (KeyModifiers)ev.key.keysym.mod,
             ev.key.repeat != 0
             )
         );
 }
Beispiel #5
0
        private void TextInput(Window owner, SDL2.SDL_Event ev)
        {
            string textInput;

            unsafe
            {
                textInput = Marshal.PtrToStringUTF8(
                    new IntPtr(ev.text.text)
                    );
            }

            owner.Game.OnTextInput(new TextInputEventArgs(textInput));
        }
Beispiel #6
0
        private void ControllerButtonReleased(Window owner, SDL2.SDL_Event ev)
        {
            var instance   = SDL2.SDL_GameControllerFromInstanceID(ev.cbutton.which);
            var controller = ControllerRegistry.Instance.GetControllerInfoByPointer(instance);

            var button = (ControllerButton)ev.cbutton.button;

            owner.Game.OnControllerButtonReleased(
                new ControllerButtonEventArgs(
                    controller,
                    button
                    )
                );
        }
Beispiel #7
0
        private void WheelMoved(Window owner, SDL2.SDL_Event ev)
        {
            if (ev.wheel.which == SDL2.SDL_TOUCH_MOUSEID)
            {
                return;
            }

            owner.Game.OnWheelMoved(
                new MouseWheelEventArgs(
                    new Vector2(ev.wheel.x, ev.wheel.y),
                    ev.wheel.direction
                    )
                );
        }
Beispiel #8
0
        internal void Dispatch(SDL2.SDL_Event ev)
        {
            if (DiscardedEventTypes.ContainsKey(ev.type))
            {
                return;
            }

            if (ev.type == SDL2.SDL_EventType.SDL_WINDOWEVENT)
            {
                DispatchWindowEvent(ev.window);
                return;
            }

            DispatchEvent(ev);
        }
Beispiel #9
0
        private void ControllerAxisMoved(Window owner, SDL2.SDL_Event ev)
        {
            var instance   = SDL2.SDL_GameControllerFromInstanceID(ev.caxis.which);
            var controller = ControllerRegistry.Instance.GetControllerInfoByPointer(instance);

            var axis = (ControllerAxis)ev.caxis.axis;

            owner.Game.OnControllerAxisMoved(
                new ControllerAxisEventArgs(
                    controller,
                    axis,
                    ev.caxis.axisValue
                    )
                );
        }
Beispiel #10
0
        private void MouseMoved(Window owner, SDL2.SDL_Event ev)
        {
            if (ev.motion.which == SDL2.SDL_TOUCH_MOUSEID)
            {
                return;
            }

            owner.Game.OnMouseMoved(
                new MouseMoveEventArgs(
                    new Vector2(ev.motion.x, ev.motion.y),
                    new Vector2(ev.motion.xrel, ev.motion.yrel),
                    new MouseButtonState(ev.motion.state)
                    )
                );
        }
Beispiel #11
0
        private void MouseReleased(Window owner, SDL2.SDL_Event ev)
        {
            if (ev.button.which == SDL2.SDL_TOUCH_MOUSEID)
            {
                return;
            }

            owner.Game.OnMouseReleased(
                new MouseButtonEventArgs(
                    new Vector2(
                        ev.button.x,
                        ev.button.y
                        ),
                    ev.button.state,
                    ev.button.button,
                    ev.button.clicks
                    )
                );
        }
Beispiel #12
0
 private void QuitRequested(Window owner, SDL2.SDL_Event ev)
 => owner.OnQuitRequested(new CancelEventArgs());
Beispiel #13
0
 private void AudioDeviceRemoved(Window owner, SDL2.SDL_Event ev)
 => owner.Game.Audio.OnDeviceRemoved(ev.adevice.which, ev.adevice.iscapture != 0);