Пример #1
0
        public void Update(MouseComponent mouse, KeyboardComponent keyboard)
        {
            if (!mouse.IsMouseOwner(this))
            {
                return;
            }

            var deltaMouseX     = mouse.DeltaPosition().X;
            var deltaMouseY     = mouse.DeltaPosition().Y;
            var deltaMouseWheel = mouse.DeletaScrollWheel();

            if (keyboard.IsKeyReleased(Keys.F4))
            {
                Zoom    = 10;
                _lookAt = Vector3.Zero;
            }

            var ownsMouse = mouse.MouseOwner;

            if (keyboard.IsKeyDown(Keys.LeftAlt))
            {
                mouse.MouseOwner = this;
            }
            else
            {
                if (ownsMouse == this)
                {
                    mouse.MouseOwner = null;
                    mouse.ClearStates();
                    return;
                }
            }


            if (keyboard.IsKeyDown(Keys.LeftAlt))
            {
                mouse.MouseOwner = this;
                if (mouse.IsMouseButtonDown(MouseButton.Left))
                {
                    Yaw   += deltaMouseX * 0.01f;
                    Pitch += deltaMouseY * 0.01f;
                }
                if (mouse.IsMouseButtonDown(MouseButton.Right))
                {
                    MoveCameraRight(deltaMouseX * 0.01f * Zoom * .1f);
                    MoveCameraUp(-deltaMouseY * 0.01f * Zoom * .1f);
                }
                else if (deltaMouseWheel != 0)
                {
                    if (Math.Abs(deltaMouseWheel) > 250)   // Weird bug, sometimes this value is very large, probably related to state clearing. Temp fix
                    {
                        deltaMouseWheel = 250 * Math.Sign(deltaMouseWheel);
                    }

                    var oldZoom = (Zoom / 10);
                    Zoom += (deltaMouseWheel * 0.005f) * oldZoom;
                    //_logger.Here().Information($"Setting zoom {Zoom} - {deltaMouseWheel} - {oldZoom}");
                }
            }
        }
        public override void Update(GameTime gameTime)
        {
            if (!_mouseComponent.IsMouseOwner(this))
            {
                return;
            }

            ChangeSelectionMode();

            _currentMousePos = _mouseComponent.Position();

            if (_mouseComponent.IsMouseButtonPressed(MouseButton.Left))
            {
                _startDrag   = _mouseComponent.Position();
                _isMouseDown = true;

                if (_mouseComponent.MouseOwner != this)
                {
                    _mouseComponent.MouseOwner = this;
                }
            }

            if (_mouseComponent.IsMouseButtonReleased(MouseButton.Left))
            {
                if (_isMouseDown)
                {
                    var selectionRectangle = CreateSelectionRectangle(_startDrag, _currentMousePos);

                    var rectArea = RectArea(selectionRectangle);
                    if (rectArea > 8)
                    {
                        SelectFromRectangle(selectionRectangle, _keyboardComponent.IsKeyDown(Keys.LeftShift), _keyboardComponent.IsKeyDown(Keys.LeftControl));
                    }
                    else
                    {
                        SelectFromPoint(_currentMousePos, _keyboardComponent.IsKeyDown(Keys.LeftShift), _keyboardComponent.IsKeyDown(Keys.LeftControl));
                    }
                }
                else
                {
                    SelectFromPoint(_currentMousePos, _keyboardComponent.IsKeyDown(Keys.LeftShift), _keyboardComponent.IsKeyDown(Keys.LeftControl));
                }

                _isMouseDown = false;
            }


            if (!_isMouseDown)
            {
                if (_mouseComponent.MouseOwner == this)
                {
                    _mouseComponent.MouseOwner = null;
                    _mouseComponent.ClearStates();
                    return;
                }
            }
        }