Beispiel #1
0
        internal unsafe MouseState(IMouse mouse)
        {
            Name        = mouse.Name;
            Index       = mouse.Index;
            IsConnected = mouse.IsConnected;
            var buttons = mouse.SupportedButtons;

            _buttonCount        = buttons.Count;
            _buttons            = (MouseButton *)Marshal.AllocHGlobal(_buttonCount * sizeof(MouseButton));
            _pressedButtons     = (MouseButton *)Marshal.AllocHGlobal(_buttonCount * sizeof(MouseButton));
            _pressedButtonCount = 0;
            for (var i = 0; i < _buttonCount; i++)
            {
                _buttons[i] = buttons[i];
                if (mouse.IsButtonPressed(_buttons[i]))
                {
                    _pressedButtons[_pressedButtonCount++] = _buttons[i];
                }
            }

            _pressedButtons = (MouseButton *)Marshal.ReAllocHGlobal
                                  ((IntPtr)_pressedButtons, (IntPtr)(_pressedButtonCount * sizeof(MouseButton)));
            var wheels = mouse.ScrollWheels;

            _scrollWheelCount = wheels.Count;
            _scrollWheels     = (ScrollWheel *)Marshal.AllocHGlobal(_scrollWheelCount * sizeof(ScrollWheel));
            for (var i = 0; i < _scrollWheelCount; i++)
            {
                _scrollWheels[i] = wheels[i];
            }

            Position = mouse.Position;
        }
Beispiel #2
0
 protected override void OnMouseMove(IMouse sender, Vector2 position)
 {
     if (sender.IsButtonPressed(MouseButton.Left))
     {
         offset.X    += (lastMousePos.X - position.X) * mouseMoveScale * scale;
         offset.Y    += (position.Y - lastMousePos.Y) * mouseMoveScale * scale;
         lastMousePos = position;
         UpdateTransformMatrix();
     }
 }
Beispiel #3
0
        internal unsafe MouseState(IMouse mouse, MemoryPool <byte> pool)
        {
            // Set properties
            Name        = mouse.Name;
            Index       = mouse.Index;
            IsConnected = mouse.IsConnected;

            // Initial rentals
            var srcButtons = mouse.SupportedButtons;                      // get the source's supported buttons

            _buttonCount = srcButtons.Count;                              // assign the button count
            _buttons     = pool.Rent(_buttonCount * sizeof(MouseButton)); // do a full rental of all supported buttons
            // we don't know how many buttons are pressed, do a full rental
            _pressedButtons     = pool.Rent(_buttonCount * sizeof(MouseButton));
            _pressedButtonCount = _buttonCount;         // set the pressed button count to span the entire initial rental
            var buttons        = GetSupportedButtons(); // get the span over the supported buttons
            var pressedButtons = GetPressedButtons();   // get the full span of the initial rental of the pressed buttons

            _pressedButtonCount = 0;                    // set the pressed button count to zero to actually count how many are pressed
            for (var i = 0; i < _buttonCount; i++)
            {
                buttons[i] = srcButtons[i];
                if (mouse.IsButtonPressed(buttons[i]))
                {
                    pressedButtons[_pressedButtonCount++] = buttons[i];
                }
            }

            // Trim the pressed button rental
            using var wip = _pressedButtons;                                        // get the original rental, and dispose of it when we're done
            var wipSpan = GetPressedButtons();                                      // get the trimmed span over the full initial rental

            _pressedButtons = pool.Rent(_pressedButtonCount * sizeof(MouseButton)); // create the trimmed rental
            pressedButtons  = GetPressedButtons();                                  // get the span over the trimmed rental
            wipSpan.CopyTo(pressedButtons);                                         // copy the trimmed span over the full rental to the trimmed rental

            // Scroll wheels
            var srcWheels = mouse.ScrollWheels;

            _scrollWheelCount = srcWheels.Count;
            _scrollWheels     = pool.Rent(_scrollWheelCount * sizeof(ScrollWheel));
            var dstWheels = GetScrollWheels();

            for (var i = 0; i < _scrollWheelCount; i++)
            {
                dstWheels[i] = srcWheels[i];
            }

            Position = mouse.Position;
        }
Beispiel #4
0
        protected override void OnMouseMove(IMouse sender, PointF position)
        {
            if (Window.IsClosing)
            {
                return;
            }

            if (sender.IsButtonPressed(MouseButton.Left))
            {
                offset.X    += (position.X - lastMousePos.X) * mouseMoveScale / scale;
                offset.Y    += (lastMousePos.Y - position.Y) * mouseMoveScale / scale;
                lastMousePos = position;
                UpdateTransformMatrix();
            }
        }