protected override bool OnButtonDown(Point pointerPosition) { this.initialElementToContextMatrix = this.ActiveView.GetComputedTransformToRoot(this.EditingElement); this.initialContextToElementMatrix = ElementUtilities.GetInverseMatrix(this.initialElementToContextMatrix); this.initialCenterInBrush = this.ActiveAdorner.BrushCenter; this.rootToBrushMatrix = this.initialContextToElementMatrix * this.ActiveAdorner.GetCompleteInverseBrushTransformMatrix(true); this.brushToRootMatrix = ElementUtilities.GetInverseMatrix(this.rootToBrushMatrix); this.initialCenterInDocument = this.ActiveAdorner.TransformPoint(this.initialCenterInBrush, true) * this.initialElementToContextMatrix; this.initialPointerPosition = pointerPosition; Point startPoint; Point endPoint; if (this.ActiveAdorner.GetBrushEndpoints(out startPoint, out endPoint)) { double offset = 1.0; if (this.ActiveAdorner.Kind == RadialGradientAdornerKind.GradientOriginPoint) { offset = 0.0; } Point S = startPoint * this.brushToRootMatrix; Point E = endPoint * this.brushToRootMatrix; Vector perpendicular; this.dragOffset = GradientStopBehavior.VectorProjection(S, E, pointerPosition, offset, out perpendicular); this.dragOffset = Math.Abs(this.dragOffset * (E - S).Length); } this.CancelEditTransaction(); return(true); }
protected override bool OnButtonDown(Point pointerPosition) { Matrix computedTransformToRoot = this.ActiveView.GetComputedTransformToRoot(this.EditingElement); this.rootToBrushMatrix = ElementUtilities.GetInverseMatrix(computedTransformToRoot); this.rootToBrushMatrix *= this.ActiveAdorner.GetCompleteInverseBrushTransformMatrix(true); this.brushToRootMatrix = ElementUtilities.GetInverseMatrix(this.rootToBrushMatrix); if (this.ActiveAdorner.Kind == LinearGradientAdornerKind.StartRotation || this.ActiveAdorner.Kind == LinearGradientAdornerKind.EndRotation) { Point startPoint = this.ActiveAdorner.StartPoint; Point endPoint = this.ActiveAdorner.EndPoint; Point point = startPoint * computedTransformToRoot; Vector vector = 0.5 * (endPoint * computedTransformToRoot - point); this.centerInRootCoordinates = point + vector; this.radiusInRootCoordinates = vector.Length; } else if (this.ActiveAdorner.GetBrushEndpoints(out this.initialStartPoint, out this.initialEndPoint)) { double offset = 0.0; if (this.ActiveAdorner.Kind == LinearGradientAdornerKind.EndPoint) { offset = 1.0; } Point S = this.initialStartPoint * this.brushToRootMatrix; Point E = this.initialEndPoint * this.brushToRootMatrix; Vector perpendicular; this.dragOffset = GradientStopBehavior.VectorProjection(S, E, pointerPosition, offset, out perpendicular); this.dragOffset = Math.Abs(this.dragOffset * (E - S).Length); } return(true); }
protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow) { switch (this.ActiveAdorner.Kind) { case RadialGradientAdornerKind.GradientOriginPoint: this.actionString = StringTable.UndoUnitRadialGradientOrigin; if (!this.HasMouseMovedAfterDown) { this.CopyPrimaryBrushToSelection(); } Point point = this.initialCenterInBrush; if (Tolerances.HaveMoved(dragCurrentPosition, this.initialCenterInDocument, this.ActiveView.Zoom)) { Point positionInBrush = this.ActiveAdorner.InverseTransformPoint(dragCurrentPosition * this.initialContextToElementMatrix, true) * this.brushToRootMatrix; BrushTransformBehavior.OffsetDragPoint(ref positionInBrush, this.initialCenterInBrush * this.brushToRootMatrix, this.dragOffset, 0.0); point = RoundingHelper.RoundPosition(positionInBrush * this.rootToBrushMatrix); } if (this.ActiveAdorner.GradientOriginPoint != point) { this.SetBrushValue(RadialGradientBrushNode.GradientOriginProperty, (object)point); this.UpdateEditTransaction(); break; } break; case RadialGradientAdornerKind.RadiusPoint: this.actionString = StringTable.UndoUnitScaleRadialGradient; if (!this.HasMouseMovedAfterDown) { this.CopyPrimaryBrushToSelection(); this.radiusX = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusXProperty); this.radiusY = (double)this.GetBrushValue(RadialGradientBrushNode.RadiusYProperty); if (Math.Abs(this.radiusX) < 0.01) { this.radiusX = 0.01; } if (Math.Abs(this.radiusY) < 0.01) { this.radiusY = 0.01; } } Vector perpendicular; double num1 = GradientStopBehavior.VectorProjection(this.ActiveAdorner.BrushCenter * this.brushToRootMatrix, this.initialPointerPosition, dragCurrentPosition, 0.0, out perpendicular); double num2 = RoundingHelper.RoundLength(this.radiusX * num1); double num3 = RoundingHelper.RoundLength(this.radiusY * num1); this.SetBrushValue(RadialGradientBrushNode.RadiusXProperty, (object)num2); this.SetBrushValue(RadialGradientBrushNode.RadiusYProperty, (object)num3); this.UpdateEditTransaction(); break; } this.ActiveView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow); return(true); }
private void UpdateTranslation() { SceneViewModel viewModel = this.ActiveView.ViewModel; PropertyReference propertyReference1 = this.GetBrushPropertyReference((SceneNode)this.EditingElement); if (propertyReference1 == null) { return; } Matrix matrixToAdornerLayer = this.ActiveAdorner.AdornerSet.GetTransformMatrixToAdornerLayer(); this.EnsureEditTransaction(); Point startPoint; Point endPoint; if (PlatformTypes.IsInstance(this.ActiveAdorner.PlatformBrush, PlatformTypes.GradientBrush, (ITypeResolver)this.EditingElement.ProjectContext) && this.ActiveAdorner.GetBrushEndpoints(out startPoint, out endPoint)) { if (!this.HasMouseMovedAfterDown) { this.CopyPrimaryBrushToSelection(); } PropertyReference propertyReference2 = propertyReference1.Append(GradientBrushNode.GradientStopsProperty); PropertyReference propertyReference3 = propertyReference2.Append((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)viewModel.ProjectContext.Platform.Metadata, PlatformTypes.GradientStopCollection, this.ActiveAdorner.Index)); PropertyReference propertyReference4 = propertyReference3.Append(GradientStopNode.OffsetProperty); PropertyReference propertyReference5 = propertyReference3.Append(GradientStopNode.ColorProperty); Matrix matrix = this.ActiveAdorner.GetCompleteBrushTransformMatrix(true) * this.ActiveView.GetComputedTransformToRoot(this.EditingElement); GradientStopCollection gradientStopCollection = (GradientStopCollection)this.EditingElement.GetComputedValueAsWpf(propertyReference2); GradientStop gradientStop = gradientStopCollection[this.ActiveAdorner.Index]; Vector perpendicular; double num1 = GradientStopBehavior.VectorProjection(startPoint * matrix, endPoint * matrix, this.dragCurrentPosition, gradientStop.Offset, out perpendicular); double length = (perpendicular * matrixToAdornerLayer).Length; int index = this.ActiveAdorner.Index + 1; if (index >= gradientStopCollection.Count) { index = this.ActiveAdorner.Index - 1; } if (length > 30.0 && !this.isDraggedOff && gradientStopCollection.Count > 2) { this.isDraggedOff = true; this.ActiveAdorner.Hidden = true; this.saveDraggedOffColor = gradientStop.Color; this.SetBrushValue(propertyReference5, (object)gradientStopCollection[index].Color); this.SetBrushValue(propertyReference4, (object)gradientStopCollection[index].Offset); this.Cursor = ToolCursors.MinusArrowCursor; } if (length <= 30.0 && this.isDraggedOff) { this.isDraggedOff = false; this.ActiveAdorner.Hidden = false; this.SetBrushValue(propertyReference5, (object)this.saveDraggedOffColor); this.Cursor = this.ActiveAdorner.AdornerSet.GetCursor((IAdorner)this.ActiveAdorner); } if (!this.isDraggedOff) { double num2 = RoundingHelper.RoundLength(gradientStop.Offset + num1); if (num2 > 1.0) { num2 = 1.0; } else if (num2 < 0.0) { num2 = 0.0; } this.SetBrushValue(propertyReference4, (object)num2); } else { this.SetBrushValue(propertyReference4, (object)gradientStopCollection[index].Offset); } } if (!this.HasMouseMovedAfterDown) { this.SetSelectedStopIndex(this.ActiveAdorner.Index); } this.UpdateEditTransaction(); }
protected override bool OnClickEnd(Point pointerPosition, int clickCount) { if (clickCount == 1 && this.ActiveAdorner != null && this.Tool is GradientBrushTool) { PropertyReference propertyReference1 = this.GetBrushPropertyReference((SceneNode)this.EditingElement); GradientStopCollection gradientStopCollection = (GradientStopCollection)this.ActiveAdorner.GetBrushPropertyAsWpf(GradientBrushNode.GradientStopsProperty); Matrix matrix = this.ActiveAdorner.GetCompleteBrushTransformMatrix(true) * this.ActiveView.GetComputedTransformToRoot(this.EditingElement); Point startPoint; Point endPoint; if (gradientStopCollection == null || !this.ActiveAdorner.GetBrushEndpoints(out startPoint, out endPoint)) { return(true); } Vector perpendicular; double offset = RoundingHelper.RoundLength(GradientStopBehavior.VectorProjection(startPoint * matrix, endPoint * matrix, this.dragStartPosition, 0.0, out perpendicular)); int index1 = 0; int index2 = 0; for (int index3 = 0; index3 < gradientStopCollection.Count; ++index3) { if (gradientStopCollection[index1].Offset > offset || gradientStopCollection[index3].Offset > gradientStopCollection[index1].Offset && gradientStopCollection[index3].Offset <= offset) { index1 = index3; } if (gradientStopCollection[index2].Offset < offset || gradientStopCollection[index3].Offset < gradientStopCollection[index2].Offset && gradientStopCollection[index3].Offset >= offset) { index2 = index3; } } GradientStop gradientStop; if (gradientStopCollection.Count == 0) { gradientStop = new GradientStop(Colors.White, offset); } else { double num = (offset - gradientStopCollection[index1].Offset) / (gradientStopCollection[index2].Offset - gradientStopCollection[index1].Offset); if (num > 1.0) { num = 1.0; } if (num < 0.0) { num = 0.0; } gradientStop = new GradientStop(Color.FromArgb((byte)((double)gradientStopCollection[index1].Color.A * (1.0 - num) + (double)gradientStopCollection[index2].Color.A * num), (byte)((double)gradientStopCollection[index1].Color.R * (1.0 - num) + (double)gradientStopCollection[index2].Color.R * num), (byte)((double)gradientStopCollection[index1].Color.G * (1.0 - num) + (double)gradientStopCollection[index2].Color.G * num), (byte)((double)gradientStopCollection[index1].Color.B * (1.0 - num) + (double)gradientStopCollection[index2].Color.B * num)), offset); } this.CopyPrimaryBrushToSelection(); PropertyReference propertyReference2 = propertyReference1.Append(GradientBrushNode.GradientStopsProperty); PropertyReference propertyReference3 = propertyReference2.Append(GradientStopCollectionNode.CountProperty); foreach (SceneElement sceneElement in this.ActiveView.ElementSelectionSet.Selection) { PropertyReference propertyReference4 = this.ActiveView.DesignerContext.PropertyManager.FilterProperty((SceneNode)sceneElement, propertyReference3); PropertyReference propertyReference5 = this.ActiveView.DesignerContext.PropertyManager.FilterProperty((SceneNode)sceneElement, propertyReference2); if (propertyReference4 != null && propertyReference5 != null) { int index3 = (int)sceneElement.GetComputedValue(propertyReference4); sceneElement.InsertValueAsWpf(propertyReference5, index3, (object)gradientStop); } } this.SetSelectedStopIndex(gradientStopCollection.Count); this.CommitEditTransaction(); } return(base.OnClickEnd(pointerPosition, clickCount)); }