private void moveEntity(IEntity entity, float xOffset, float yOffset) { var translate = entity.GetComponent <ITranslateComponent>(); if (translate == null) { return; } if (_input.IsKeyDown(Key.AltLeft) || _input.IsKeyDown(Key.AltRight)) { xOffset /= 10f; yOffset /= 10f; } if (!MathUtils.FloatEquals(xOffset, 0f)) { PropertyInfo prop = translate.GetType().GetProperty(nameof(ITranslateComponent.X)); PropertyAction action = new PropertyAction(new InspectorProperty(translate, nameof(ITranslateComponent.X), prop), translate.X + xOffset, _editor.Project.Model); _actions.RecordAction(action); } if (!MathUtils.FloatEquals(yOffset, 0f)) { PropertyInfo prop = translate.GetType().GetProperty(nameof(ITranslateComponent.Y)); PropertyAction action = new PropertyAction(new InspectorProperty(translate, nameof(ITranslateComponent.Y), prop), translate.Y + yOffset, _editor.Project.Model); _actions.RecordAction(action); } }
private void scaleEntity(IEntity entity, float scaleOffset) { var scale = entity.GetComponent <IScaleComponent>(); if (scale == null) { return; } if (_input.IsKeyDown(Key.AltLeft) || _input.IsKeyDown(Key.AltRight)) { scaleOffset /= 10f; } PropertyInfo prop = scale.GetType().GetProperty(nameof(IScaleComponent.Scale)); PropertyAction action = new PropertyAction(new InspectorProperty(scale, nameof(IScaleComponent.Scale), prop), new PointF(scale.ScaleX + scaleOffset, scale.ScaleY + scaleOffset), _editor.Project.Model); _actions.RecordAction(action); }
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 rotateEntity(IEntity entity, float angleOffset) { var rotate = entity.GetComponent <IRotateComponent>(); if (rotate == null) { return; } if (_input.IsKeyDown(Key.AltLeft) || _input.IsKeyDown(Key.AltRight)) { angleOffset /= 10f; } if (MathUtils.FloatEquals(angleOffset, 0f)) { return; } PropertyInfo prop = rotate.GetType().GetProperty(nameof(IRotateComponent.Angle)); PropertyAction action = new PropertyAction(new InspectorProperty(rotate, nameof(IRotateComponent.Angle), prop), rotate.Angle + angleOffset, _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); }
private bool isRecent(PropertyAction followingAction) { var timeDelta = followingAction._timestamp.Subtract(_timestamp); return(timeDelta.Seconds < 2); }