public void Visit() { var rotate = _rotate; if (!_isDown || rotate == null) { return; } var handle = _handle; if (handle == null) { return; } if (!_input.LeftMouseButtonDown) { _isDown = false; handle.TextConfig = _idleConfig; return; } float offsetX = _input.MousePosition.XMainViewport - _xOnDown; float offsetY = _input.MousePosition.YMainViewport - _yOnDown; if (MathUtils.FloatEquals(offsetX, 0f) || MathUtils.FloatEquals(offsetY, 0f)) { return; } (offsetX, offsetY) = _editor.ToGameSize(offsetX, offsetY); float angle = (float)MathHelper.RadiansToDegrees(-Math.Atan2(offsetX, offsetY)) + 90f; if (_input.IsKeyDown(Key.AltLeft) || _input.IsKeyDown(Key.AltRight)) { float clamp = AGSDraggableComponent.ClampingToWhenAlt; angle = (float)Math.Round(angle / clamp) * clamp; } PropertyInfo prop = rotate.GetType().GetProperty(nameof(IRotateComponent.Angle)); PropertyAction action = new PropertyAction(new InspectorProperty(rotate, null, nameof(IRotate.Angle), prop), angle, _editor.Project.Model); _actions.RecordAction(action); }
private void scale(float width, float height) { var handle = _handle; if (handle == null) { return; } (width, height) = _editor.ToGameSize(width, height); float w = _widthOnDown + width; float h = _heightOnDown + height; if (_input.IsKeyDown(Key.AltLeft) || _input.IsKeyDown(Key.AltRight)) { float clamp = AGSDraggableComponent.ClampingToWhenAlt; w = (float)Math.Round(w / clamp) * clamp; h = (float)Math.Round(h / clamp) * clamp; } if (_input.IsKeyDown(Key.ControlLeft) || _input.IsKeyDown(Key.ControlRight)) { float targetAspectRatio = _widthOnDown / _heightOnDown; float heightCandidate = w / targetAspectRatio; float widthCandidate = h * targetAspectRatio; if (Math.Abs(heightCandidate - _heightOnDown) < Math.Abs(widthCandidate - _widthOnDown)) { w = widthCandidate; } else { h = heightCandidate; } } PropertyInfo prop = _scale.GetType().GetProperty(nameof(IScaleComponent.Scale)); PointF toScale = (w / _scale.BaseSize.Width, h / _scale.BaseSize.Height); PropertyAction action = new PropertyAction(new InspectorProperty(_scale, null, nameof(IScale.Scale), prop), toScale, _editor.Project.Model); _actions.RecordAction(action); }
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); }