Esempio n. 1
0
        private bool isRecent(MovePivotAction followingAction)
        {
            var timeDelta = followingAction._timestamp.Subtract(_timestamp);

            return(timeDelta.Seconds < 2);
        }
Esempio n. 2
0
            public void Visit()
            {
                if (!_isDown)
                {
                    return;
                }

                var handle = _handle;

                if (handle == null)
                {
                    return;
                }

                if (!_input.LeftMouseButtonDown)
                {
                    _isDown           = false;
                    handle.TextConfig = _idleConfig;
                    return;
                }

                var boundingBox = _boundingBox;

                if (boundingBox == null)
                {
                    return;
                }

                float xDiff = _input.MousePosition.XMainViewport - _xOnDown;
                float yDiff = _input.MousePosition.YMainViewport - _yOnDown;

                (xDiff, yDiff) = _editor.ToGameSize(xDiff, yDiff);
                float pivotXOffset           = xDiff / boundingBox.WorldBoundingBox.Width;
                float pivotYOffset           = yDiff / boundingBox.WorldBoundingBox.Height;
                float toPivotX               = _pivotOnDown.X + pivotXOffset;
                float toPivotY               = _pivotOnDown.Y + pivotYOffset;
                bool  shouldRecalculateDiffs = false;

                if (_input.IsKeyDown(Key.AltLeft) || _input.IsKeyDown(Key.AltRight))
                {
                    shouldRecalculateDiffs = true;
                    toPivotX = (float)Math.Round(toPivotX, 1);
                    toPivotY = (float)Math.Round(toPivotY, 1);
                }
                if (_input.IsKeyDown(Key.ControlLeft) || _input.IsKeyDown(Key.ControlRight))
                {
                    shouldRecalculateDiffs = true;
                    toPivotX = MathUtils.Clamp(toPivotX, 0f, 1f);
                    toPivotY = MathUtils.Clamp(toPivotY, 0f, 1f);
                }
                if (shouldRecalculateDiffs)
                {
                    xDiff = boundingBox.WorldBoundingBox.Width * (toPivotX - _pivotOnDown.X);
                    yDiff = boundingBox.WorldBoundingBox.Height * (toPivotY - _pivotOnDown.Y);
                }
                float           toX    = _translateXOnDown + xDiff;
                float           toY    = _translateYOnDown + yDiff;
                MovePivotAction action = new MovePivotAction(handle.GetFriendlyName(), _image, _translate,
                                                             toPivotX, toPivotY, toX, toY, _editor.Project.Model);

                _actions.RecordAction(action);
            }