protected override void ApplyScale(Vector scale, Point center) { Rect elementBounds = this.EditingElementSet.ElementBounds; Matrix m = this.startSharedTransform; Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(m); Matrix matrix1 = new Matrix(); matrix1.Translate(-center.X, -center.Y); foreach (SceneElement element in this.EditingElementSet.Elements) { Matrix matrix2 = this.elementToElementsTransformDictionary[element] * matrix1; Point point1 = this.startCentersDictionary[element]; Matrix matrix3 = this.startTransformsDictionary[element]; Rect rect = this.startBoundsDictionary[element]; Point point2 = new Point(rect.X + rect.Width * point1.X, rect.Y + rect.Height * point1.Y); Point point3 = matrix2.Transform(point2); Vector vector = new Point(scale.X * point3.X, scale.Y * point3.Y) - point3; Matrix matrix4 = matrix3 * inverseMatrix; matrix4.ScaleAt(scale.X, scale.Y, matrix4.OffsetX, matrix4.OffsetY); matrix4.Translate(vector.X, vector.Y); CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * m); newTransform.ScaleX = RoundingHelper.RoundScale(newTransform.ScaleX); newTransform.ScaleY = RoundingHelper.RoundScale(newTransform.ScaleY); newTransform.SkewX = RoundingHelper.RoundAngle(newTransform.SkewX); newTransform.SkewY = RoundingHelper.RoundAngle(newTransform.SkewY); newTransform.RotationAngle = RoundingHelper.RoundAngle(newTransform.RotationAngle); newTransform.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX); newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY); AdornedToolBehavior.UpdateElementTransform(element, newTransform, AdornedToolBehavior.TransformPropertyFlags.All); } }
/// <summary> /// Gets all static fields for a Type. /// </summary> /// <param name="typeElement">Type element.</param> /// <returns>All static fields for the specified Type element.</returns> private FieldElement[] GetTypeStaticFields(TypeElement typeElement) { List <FieldElement> staticFields = new List <FieldElement>(); Action <ICodeElement> findStaticFields = delegate(ICodeElement codeElement) { FieldElement fieldElement = codeElement as FieldElement; if (fieldElement != null && fieldElement.MemberModifiers == MemberModifiers.Static) { bool isTypeChild = false; ICodeElement parentElement = codeElement.Parent; while (!isTypeChild && parentElement != null) { isTypeChild = parentElement == typeElement; if (!isTypeChild) { parentElement = parentElement.Parent; } } if (isTypeChild) { staticFields.Add(fieldElement); } } }; ElementUtilities.ProcessElementTree(typeElement, findStaticFields); return(staticFields.ToArray()); }
public RepeatDialog() { this.DialogContent = (UIElement)FileTable.GetElement("Resources\\Timeline\\RepeatDialog.xaml"); this.Title = StringTable.RepeatDialogTitle; this.SizeToContent = SizeToContent.WidthAndHeight; this.repeatCountNumberEditor = ElementUtilities.FindElement((FrameworkElement)this, "RepeatCount") as NumberEditor; }
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 object CreateTileBrush(BaseFrameworkElement element) { Visual visual1 = element.Visual != null ? element.Visual.PlatformSpecificObject as Visual : (Visual)null; if (visual1 == null) { return((object)null); } foreach (Visual visual2 in ElementUtilities.GetVisualTree(visual1)) { if (MakeDrawingBrushCommand.IsMediaElementInstance(visual2)) { this.showDrawingVideoWarning = true; break; } } Drawing drawing = MakeDrawingBrushCommand.SimplifyDrawing(MakeDrawingBrushCommand.CreateDrawing(visual1, false), Path.GetDirectoryName(this.SceneViewModel.ProjectContext.ProjectPath)); DrawingBrush drawingBrush = new DrawingBrush(); if (drawing != null) { drawingBrush.Drawing = drawing; UIElement uiElement = visual1 as UIElement; if (uiElement != null) { drawingBrush.Viewbox = new Rect(uiElement.RenderSize); drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; } } return((object)drawingBrush); }
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 HitTestResult HitTestCore(PointHitTestParameters hitTestParams) { Point hitPoint = hitTestParams.HitPoint; if (Tolerances.AreClose(hitPoint, this.lastPoint)) { return(base.HitTestCore(hitTestParams)); } this.lastPoint = hitPoint; double num; if (((LayoutBehavior)this.AdornerSet.Behavior).IsNewGridlineEnabled && Mouse.LeftButton != MouseButtonState.Pressed && Mouse.RightButton != MouseButtonState.Pressed) { Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(this.AdornerSet.Matrix); Point point = hitPoint * inverseMatrix; Point pointBegin; Point pointEnd; this.GetPoints(out pointBegin, out pointEnd, this.AdornerSet.Matrix); num = !new Rect(pointBegin, pointEnd).Contains(point) ? double.NaN : (!this.IsX ? point.Y : point.X); } else { num = double.NaN; } if (!this.position.Equals(num)) { this.position = num; if (this.isMouseOver) { this.InvalidateRender(); this.AdornerSet.Update(); } } return(base.HitTestCore(hitTestParams)); }
protected override bool OnButtonDown(Point pointerPosition) { this.isActive = false; Viewport3DElement firstHitViewport3D = this.ActiveView.GetFirstHitViewport3D(pointerPosition); if (firstHitViewport3D == null || firstHitViewport3D.ViewObject.PlatformSpecificObject == null) { return(false); } this.cameraElement = firstHitViewport3D.Camera; if (this.cameraElement == null || !this.cameraElement.IsSelectable) { return(false); } this.scale = Helper3D.UnitsPerPixel((Viewport3D)firstHitViewport3D.ViewObject.PlatformSpecificObject, new Point3D(0.0, 0.0, 0.0)); this.rootToViewport3DMatrix = ElementUtilities.GetComputedTransform(firstHitViewport3D.Visual != null ? firstHitViewport3D.Visual.PlatformSpecificObject as Visual : (Visual)null, (Visual)this.ActiveSceneViewModel.DefaultView.ViewRootContainer); this.pointerInViewportCoordinates = pointerPosition * this.rootToViewport3DMatrix; this.SetMovementMode(); this.cameraInitialUp = (Vector3D)this.cameraElement.GetComputedValue(ProjectionCameraElement.UpDirectionProperty); this.cameraInitialPosition = (Point3D)this.cameraElement.GetComputedValue(ProjectionCameraElement.PositionProperty); this.cameraInitialLookAt = this.cameraInitialPosition + (Vector3D)this.cameraElement.GetComputedValue(ProjectionCameraElement.LookDirectionProperty); this.totalAzimuthDelta = 0.0; this.totalElevationDelta = 0.0; this.lastPoint = this.pointerInViewportCoordinates; this.EnsureEditTransaction(); this.isActive = true; return(true); }
protected override Rect GetBoundingRectangleCore() { if (this._item.Parent == null && this._item != this._item.Root && this._item.Name != null) { ModelItem modelItem = this.ModelService.FromName(this.ModelService.Root, this._item.Name, StringComparison.OrdinalIgnoreCase); if (modelItem != null) { this._item = modelItem; } } PresentationSource presentationSource = PresentationSource.FromVisual((Visual)DesignerView.FromContext(this._item.Context)); if (presentationSource == null || presentationSource.RootVisual == null || !this.ViewItem.IsVisible) { return(new Rect()); } Rect selectionFrameBounds = ElementUtilities.GetSelectionFrameBounds(this.ViewItem); if (selectionFrameBounds.Location == new Point(0.0, 0.0) && selectionFrameBounds.Size == new Size(0.0, 0.0)) { return(new Rect()); } Rect rect1 = new Rect(selectionFrameBounds.Size); Rect rect2 = TransformUtil.GetSelectionFrameTransformToParentVisual(this.ViewItem, presentationSource.RootVisual).TransformBounds(rect1); return(new Rect(presentationSource.RootVisual.PointToScreen(rect2.Location), rect2.Size)); }
public void GetAttributeModifierTest() { FieldElement fieldElement = new FieldElement(); fieldElement.Name = "TestField"; fieldElement.Access = CodeAccess.Protected; fieldElement.Type = "int"; fieldElement.MemberModifiers = MemberModifiers.Static; string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Modifier, fieldElement); Assert.AreEqual("Static", attribute, "Unexpected attribute."); TypeElement typeElement = new TypeElement(); typeElement.TypeModifiers = TypeModifiers.Sealed; attribute = ElementUtilities.GetAttribute(ElementAttributeType.Modifier, typeElement); Assert.AreEqual("Sealed", attribute, "Unexpected attribute."); UsingElement usingElement = new UsingElement(); usingElement.Name = "System"; attribute = ElementUtilities.GetAttribute(ElementAttributeType.Modifier, usingElement); Assert.AreEqual(string.Empty, attribute, "Unexpected attribute."); }
private SnapDialog() { this.DialogContent = (UIElement)FileTable.GetElement("Resources\\Timeline\\SnapDialog.xaml"); this.Title = StringTable.SnapDialogTitle; this.SizeToContent = SizeToContent.WidthAndHeight; this.snapEntryNumberEditor = (NumberEditor)ElementUtilities.FindElement((FrameworkElement)this, "SnapResolution"); }
private void MovePathParts(PathPartSelectionSet pathPartSelectionSet, BaseFrameworkElement sceneElement, PathEditMode pathEditMode, Vector deltaOffset) { ICollection <PathPart> selectionByElement = pathPartSelectionSet.GetSelectionByElement((SceneElement)sceneElement, pathEditMode); Tool activeTool = this.ActiveSceneViewModel.DesignerContext.ToolManager.ActiveTool; if (selectionByElement.Count <= 0 || activeTool == null) { return; } PathEditorTarget pathEditorTarget = activeTool.GetPathEditorTarget((Base2DElement)sceneElement, pathEditMode); if (pathEditorTarget == null) { return; } this.EnsureEditTransaction(); pathEditorTarget.BeginEditing(); if (!this.pathEditorTargets.ContainsKey(pathEditorTarget)) { this.pathEditorTargets.Add(pathEditorTarget, true); } Matrix transformToAncestor = pathEditorTarget.GetTransformToAncestor((IViewObject)this.ActiveView.HitTestRoot); Vector correspondingVector = ElementUtilities.GetCorrespondingVector(deltaOffset, transformToAncestor); PathEditBehavior.TranslateSelection(pathEditorTarget, selectionByElement, correspondingVector); this.ActiveView.AdornerLayer.InvalidateAdornerVisuals((SceneElement)pathEditorTarget.EditingElement); }
public void Execute() { if (!this.IsEnabled) { return; } ResourceEntryItem resourceEntryItem = (ResourceEntryItem)this.resourceManager.SelectedItems.Selection[0]; SceneNode sceneNode = resourceEntryItem.Container.ViewModel.GetSceneNode(resourceEntryItem.Resource.ValueNode); ConvertibleDrawing convertibleDrawing = ConvertibleDrawing.CreateConvertibleDrawing((object)(Brush)this.designerContext.ActiveSceneViewModel.CreateInstance(sceneNode.DocumentNodePath), sceneNode.ProjectContext.ProjectPath); if (convertibleDrawing == null) { return; } DocumentCompositeNode documentCompositeNode = (DocumentCompositeNode)sceneNode.DocumentNode; string valueAsString = DocumentPrimitiveNode.GetValueAsString(resourceEntryItem.Resource.KeyNode); string documentUrl = documentCompositeNode.DocumentRoot.DocumentContext.DocumentUrl; SceneViewModel activeSceneViewModel = this.designerContext.ActiveSceneViewModel; using (SceneEditTransaction editTransaction = activeSceneViewModel.CreateEditTransaction(this.CommandName)) { BaseFrameworkElement child = (BaseFrameworkElement)activeSceneViewModel.CreateSceneNode((object)convertibleDrawing.Convert()); activeSceneViewModel.ActiveSceneInsertionPoint.Insert((SceneNode)child); child.SetLocalValue(DesignTimeProperties.BrushDocumentReferenceProperty, (object)documentUrl); child.SetLocalValue(DesignTimeProperties.BrushKeyProperty, (object)valueAsString); child.Name = valueAsString + "_1"; this.point *= ElementUtilities.GetInverseMatrix(activeSceneViewModel.DefaultView.GetComputedTransformToRoot(activeSceneViewModel.ActiveSceneInsertionPoint.SceneElement)); Rect rect = new Rect(this.point, new Size(child.Width, child.Height)); activeSceneViewModel.GetLayoutDesignerForChild((SceneElement)child, true).SetChildRect(child, rect, LayoutOverrides.None, LayoutOverrides.Width | LayoutOverrides.Height, LayoutOverrides.None); this.designerContext.SelectionManager.ElementSelectionSet.SetSelection((SceneElement)child); editTransaction.Commit(); } }
protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow) { dragCurrentPosition += this.adornerOffset; dragStartPosition += this.adornerOffset; if (this.UseSnappingEngine && !this.ToolBehaviorContext.SnappingEngine.IsStarted) { List <BaseFrameworkElement> list = new List <BaseFrameworkElement>(); foreach (SceneElement sceneElement in this.EditingElementSet.Elements) { if (this.EditingElement != sceneElement) { list.Add((BaseFrameworkElement)sceneElement); } } this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, this.BaseEditingElement, (IList <BaseFrameworkElement>)list); } Vector offset = dragCurrentPosition - dragStartPosition; SceneElement container = this.EditingElement.VisualElementAncestor ?? this.EditingElement; if (this.UseSnappingEngine) { Vector vector = this.ToolBehaviorContext.SnappingEngine.SnapRect(this.startBoundsInParent, container, offset, this.ActiveAdorner.EdgeFlags); dragCurrentPosition += vector; } this.currentPointerPosition = this.startPointerPosition + ElementUtilities.GetCorrespondingVector(dragCurrentPosition - dragStartPosition, this.elementToDocumentTransform); if (!this.ActiveSceneViewModel.AnimationEditor.IsRecording && !(this is DesignTimeSizeBehavior)) { this.ReplaceSubTransaction(); } this.UpdateScale(); this.UpdateEditTransaction(); this.ActiveView.UpdateLayout(); this.ActiveView.EnsureVisible((IAdorner)this.ActiveAdorner, scrollNow); return(true); }
protected override void OnDrag(MouseDevice mouseDevice, double zoom) { if (this.IsActive) { PathGeometryEditor pathGeometryEditor = this.BeginEditing(); PathFigureEditor pathFigureEditor = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path)); int figureIndex = this.PathEditContext.FigureIndex; int partIndex = this.PathEditContext.PartIndex; int ofUpstreamSegment = pathFigureEditor.GetFirstIndexOfUpstreamSegment(partIndex); if (!this.hasDragged) { Point point1 = pathFigureEditor.GetPoint(ofUpstreamSegment); Point point2 = pathFigureEditor.GetPoint(partIndex); if (VectorUtilities.ArePathPointsVeryClose(point2, pathFigureEditor.GetPoint(ofUpstreamSegment + 2)) && VectorUtilities.ArePathPointsVeryClose(point1, pathFigureEditor.GetPoint(ofUpstreamSegment + 1))) { pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 1, VectorUtilities.WeightedAverage(point1, point2, 1.0 / 3.0)); pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 2, VectorUtilities.WeightedAverage(point1, point2, 2.0 / 3.0)); this.initialFirstCubicHandle = pathFigureEditor.GetPoint(ofUpstreamSegment + 1); this.initialSecondCubicHandle = pathFigureEditor.GetPoint(ofUpstreamSegment + 2); } this.hasDragged = true; } Vector correspondingVector = ElementUtilities.GetCorrespondingVector((this.GetPointInViewRootCoordinates(mouseDevice, false) - this.initialPointerPosition) * this.damping, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null); Vector vector1 = correspondingVector * this.firstHandleCoef; Vector vector2 = correspondingVector * this.secondHandleCoef; pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 1, this.initialFirstCubicHandle + vector1); pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 2, this.initialSecondCubicHandle + vector2); } base.OnDrag(mouseDevice, zoom); }
protected override void OnDrag(MouseDevice mouseDevice, double zoom) { Point point = PathFigureUtilities.GetPoint(this.PathEditContext.GetPathFigure(this.Path), this.PathEditContext.PartIndex); Point point1 = this.geometryToDocument.Transform(point); Point viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, true); Vector vector = viewRootCoordinates - point1; Vector correspondingVector = ElementUtilities.GetCorrespondingVector(vector, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null); if (this.hasMoved || Tolerances.HaveMoved(point1, viewRootCoordinates, zoom)) { this.hasMoved = true; PathGeometry path = this.Path; int figureIndex = this.PathEditContext.FigureIndex; int partIndex = this.PathEditContext.PartIndex; PathGeometryEditor pathGeometryEditor = this.BeginEditing(); PathFigureEditor pathFigureEditor = new PathFigureEditor(path.Figures[figureIndex]); if (partIndex > 0 || PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure)) { pathGeometryEditor.SetPoint(figureIndex, partIndex - 1, point - correspondingVector); } if (pathFigureEditor.GetLastIndexOfDownstreamSegment(partIndex) != partIndex) { pathGeometryEditor.SetPoint(figureIndex, partIndex + 1, point + correspondingVector); } if (partIndex == PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - 1 && PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure)) { this.LastTangent = vector; } this.PathEditorTarget.AddCriticalEdit(); } base.OnDrag(mouseDevice, zoom); }
/// <summary> /// Gets the expression value. /// </summary> /// <param name="expression">The expression.</param> /// <param name="element">The element.</param> /// <returns>The expression value as text.</returns> private static string GetExpressionValue(IConditionExpression expression, ICodeElement element) { string value = string.Empty; if (expression != null && element != null) { StringExpression stringExpression = expression as StringExpression; if (stringExpression != null) { value = stringExpression.Text; } else { ElementAttributeExpression attributeExpression = expression as ElementAttributeExpression; if (attributeExpression.Scope == ElementAttributeScope.Parent) { element = element.Parent; } if (attributeExpression != null) { value = ElementUtilities.GetAttribute(attributeExpression.ElementAttribute, element); } } } return(value); }
public void FormatNullStringTest() { Assert.Throws <ArgumentNullException>( delegate { ElementUtilities.Format(null, new MethodElement()); }); }
public void FormatNullElementTest() { Assert.Throws <ArgumentNullException>( delegate { ElementUtilities.Format("$(Name)", null); }); }
public override Matrix GetComputedTransformToRoot(IViewObject element) { if (element == null) { return(Matrix.Identity); } return(ElementUtilities.GetComputedTransform((Visual)this.ViewRootContainer, element.PlatformSpecificObject as Visual)); }
protected override void OnDrag(MouseDevice mouseDevice, double zoom) { this.currentTangentPoint = this.GetPointInViewRootCoordinates(mouseDevice, true); Vector correspondingVector = ElementUtilities.GetCorrespondingVector(this.currentTangentPoint - this.currentNodePoint, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null); Vector lastTangent = this.LastTangent; this.LastTangent = correspondingVector; PathFigure pathFigure = this.PathEditContext.GetPathFigure(this.Path); PathFigureEditor pathFigureEditor = pathFigure == null ? (PathFigureEditor)null : new PathFigureEditor(pathFigure); if (pathFigureEditor != null && !PathFigureUtilities.IsIsolatedPoint(pathFigureEditor.PathFigure)) { PathGeometryEditor pathGeometryEditor = this.BeginEditing(); bool flag = PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure); int index = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - (flag ? 0 : 1); Point point1 = pathFigureEditor.GetPoint(index - 1); Point point2 = pathFigureEditor.GetPoint(index); if (pathFigureEditor.GetPointKind(index) == PathPointKind.Line) { pathGeometryEditor.RemoveLastSegmentOfFigure(this.PathEditContext.FigureIndex); if (flag) { pathGeometryEditor.CloseFigureWithCubicBezier(point1, point2, this.PathEditContext.FigureIndex); } else { pathGeometryEditor.AppendCubicBezier(point1, point2, point2, this.PathEditContext.FigureIndex); } pathFigureEditor = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path)); } if (!this.IsAltDown) { if (!this.areTangentsSymmetric) { double length = this.LastTangent.Length; if (length > 0.0) { int num1 = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure); double num2 = (pathFigureEditor.GetPoint(num1 - 1) - pathFigureEditor.GetPoint(num1 - 2)).Length / length; pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, num1 - 2, point2 - num2 * this.LastTangent); } } else { int pointIndex = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - (PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure) ? 1 : 2); pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, pointIndex, point2 - this.LastTangent); } } if (PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure) && pathFigureEditor.GetPointKind(3) == PathPointKind.Cubic && this.areTangentsSymmetric) { pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, 1, point2 + this.LastTangent); } this.PathEditorTarget.AddCriticalEdit(); } base.OnDrag(mouseDevice, zoom); }
public override Rect GetActualBoundsInParent(IViewObject element) { FrameworkElement element1 = element == null ? (FrameworkElement)null : element.PlatformSpecificObject as FrameworkElement; if (element1 == null) { return(new Rect()); } return(ElementUtilities.GetActualBoundsInParent(element1)); }
public void GetAttributeNoneTest() { FieldElement fieldElement = new FieldElement(); fieldElement.Name = "TestField"; string attribute = ElementUtilities.GetAttribute(ElementAttributeType.None, fieldElement); Assert.AreEqual(string.Empty, attribute, "Unexpected attribute."); }
protected void RecomputeTransform() { AdornerSet3DContainer adornerSet3Dcontainer = this.adornerSet3DContainer; Viewport3D viewport = (Viewport3D)this.Element.Viewport.ViewObject.PlatformSpecificObject; Matrix3D viewport3DtoElement = this.Element.GetComputedTransformFromViewport3DToElement(); Point3D point = new Point3D(); if (this.DoCenterOnSpecifiedCenter) { point = (CanonicalTransform3D)this.Element.Transform.Center; } Matrix3D source = viewport3DtoElement; source.TranslatePrepend((Vector3D)point); if (this.DoRemoveObjectScale) { Matrix3D rotation = new Matrix3D(); Vector3D scale = new Vector3D(); Matrix3DOperations.DecomposeIntoRotationAndScale(source, out rotation, out scale); rotation.OffsetX = source.OffsetX; rotation.OffsetY = source.OffsetY; rotation.OffsetZ = source.OffsetZ; source = rotation; } if (this.adornmentLayer == AdornerSet3D.Location.OrthographicLayer && adornerSet3Dcontainer.ShadowAdorningViewport3D.Camera is ProjectionCamera) { OrthographicCamera ortho = (OrthographicCamera)adornerSet3Dcontainer.OrthographicAdorningViewport3D.Camera; Point3D point3D = AdornedToolBehavior3D.ProjectionPoint3DTranslatedToMatchingOrthographicPosition(viewport, viewport3DtoElement, ortho, point); source.OffsetX = point3D.X; source.OffsetY = point3D.Y; source.OffsetZ = point3D.Z; } Point3D targetPoint = new Point3D(source.OffsetX, source.OffsetY, source.OffsetZ); if (this.DoScaleToScreen) { double num1 = this.adornmentLayer != AdornerSet3D.Location.OrthographicLayer || !(adornerSet3Dcontainer.ShadowAdorningViewport3D.Camera is ProjectionCamera) ? Helper3D.UnitsPerPixel(viewport, targetPoint) * AdornerSet3D.PixelsPerInch : 6.0 / (this.AdornerSet3DContainer.AdornedViewport.GetComputedTightBounds().Width / 96.0); Matrix rotation; Vector scale; Matrix3DOperations.DecomposeIntoRotationAndScale(ElementUtilities.GetComputedTransform((Visual)viewport, (Visual)(this.View.ViewModel.DefaultView.ViewRoot.PlatformSpecificObject as FrameworkElement)), out rotation, out scale); double x = scale.X; double zoom = this.View.Zoom; double num2 = num1 / zoom * x; double offsetX = -targetPoint.X * num2 + targetPoint.X; double offsetY = -targetPoint.Y * num2 + targetPoint.Y; double offsetZ = -targetPoint.Z * num2 + targetPoint.Z; Matrix3D matrix3D = new Matrix3D(num2, 0.0, 0.0, 0.0, 0.0, num2, 0.0, 0.0, 0.0, 0.0, num2, 0.0, offsetX, offsetY, offsetZ, 1.0); ((MatrixTransform3D)this.adornerSetVisual.Transform).Matrix = source * matrix3D; } else { ((MatrixTransform3D)this.adornerSetVisual.Transform).Matrix = source; } }
public void GetAttributeAccessTest() { FieldElement fieldElement = new FieldElement(); fieldElement.Name = "TestField"; fieldElement.Access = CodeAccess.Protected; string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Access, fieldElement); Assert.AreEqual("Protected", attribute, "Unexpected attribute."); }
public void FormatTest() { MethodElement methodElement = new MethodElement(); methodElement.Name = "Test"; string formatted = ElementUtilities.Format( "End $(ElementType) $(Name)", methodElement); Assert.AreEqual("End Method Test", formatted, "Unexpected formatted result."); }
protected override void OnInitialized(EventArgs e) { if (!this.initialized) { this.DataContext = (object)this.model; this.menuHost = ElementUtilities.FindElement((FrameworkElement)this, "AddDataSourceMenuClickControl"); this.model.AddDataSourceMenuHost = this.menuHost; this.SetValue(PaletteRegistry.PaletteHeaderContentProperty, this.Resources[(object)"PaletteHeaderContent"]); this.initialized = true; } base.OnInitialized(e); }
private void CreateInstance(Point dropPoint, ResourceEntryItem resource, IType type) { ISceneInsertionPoint pointFromPosition = this.ActiveSceneViewModel.GetActiveSceneInsertionPointFromPosition(new InsertionPointContext(dropPoint)); TypeAsset typeAsset = new TypeAsset(type); if (!typeAsset.CanCreateInstance(pointFromPosition)) { return; } this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, (BaseFrameworkElement)null, (IList <BaseFrameworkElement>)null); dropPoint = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dropPoint, EdgeFlags.All); this.ToolBehaviorContext.SnappingEngine.Stop(); Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(this.ActiveView.GetComputedTransformToRoot(pointFromPosition.SceneElement)); dropPoint *= inverseMatrix; using (SceneEditTransaction editTransaction = this.ActiveDocument.CreateEditTransaction(StringTable.CreateResourceViaToolUndoUnit)) { using (this.ActiveSceneViewModel.DesignerContext.AmbientPropertyManager.SuppressApplyAmbientProperties()) { typeAsset.CreateInstance(this.ActiveSceneViewModel.DesignerContext.LicenseManager, pointFromPosition, new Rect(dropPoint, new Size(double.PositiveInfinity, double.PositiveInfinity)), (OnCreateInstanceAction)(sceneNode => { SceneElement targetElement = sceneNode as SceneElement; if (targetElement == null) { return; } if (resource is StyleResourceItem) { this.ApplyResourceOnExistingElement(targetElement, BaseFrameworkElement.StyleProperty, resource); } else if (resource is ControlTemplateResourceItem) { this.ApplyResourceOnExistingElement(targetElement, ControlElement.TemplateProperty, resource); } else if (resource is DrawingImageResourceItem) { this.ApplyResourceOnExistingElement(targetElement, ImageElement.SourceProperty, resource); } else { if (!(resource is BrushResourceItem)) { return; } this.ApplyResourceOnExistingElement(targetElement, ShapeElement.FillProperty, resource); targetElement.SetValue(ShapeElement.StrokeProperty, (object)null); } })); editTransaction.Commit(); } } }
protected override void ApplyScale(Vector scale, Point center) { Dictionary <SceneElement, Size> dictionary = this.CalculateClampedSizes(ref scale); Vector vector1 = new Vector(scale.X < 0.0 ? -1.0 : 1.0, scale.Y < 0.0 ? -1.0 : 1.0); Matrix startSharedTransform = this.StartSharedTransform; Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(startSharedTransform); ILayoutDesigner designerForChild = this.ActiveSceneViewModel.GetLayoutDesignerForChild(this.EditingElementSet.PrimaryElement, true); foreach (SceneElement index in this.EditingElementSet.Elements) { double width = dictionary[index].Width; double height = dictionary[index].Height; Rect rect1 = this.StartBoundsDictionary[index]; Point renderTransformOrigin = ((Base2DElement)index).RenderTransformOrigin; Point point1 = new Point(rect1.X + rect1.Width * renderTransformOrigin.X, rect1.Y + rect1.Height * renderTransformOrigin.Y); Matrix matrix1 = this.ElementToElementsTransformDictionary[index]; Matrix matrix2 = new Matrix(); matrix2.Translate(-center.X, -center.Y); matrix1 *= matrix2; Point point2 = matrix1.Transform(point1); Vector vector2 = new Point(point2.X * scale.X, point2.Y * scale.Y) - point2; Vector vector3 = new Vector((width - rect1.Width) * renderTransformOrigin.X, (height - rect1.Height) * renderTransformOrigin.Y); Vector vector4 = vector2 * startSharedTransform - vector3; Matrix matrix3 = this.StartTransformsDictionary[index]; Matrix m = new Matrix(); m.Scale(scale.X, scale.Y); Matrix matrix4 = ElementUtilities.GetInverseMatrix(m) * matrix3 * inverseMatrix; Vector vector5 = new Vector(matrix3.OffsetX, matrix3.OffsetY) * inverseMatrix; matrix4.ScaleAt(scale.X, scale.Y, vector5.X, vector5.Y); CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * startSharedTransform); newTransform.ScaleX *= vector1.X; newTransform.ScaleY *= vector1.Y; newTransform.Translation += vector4; AdornedToolBehavior.UpdateElementTransform(index, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Skew | AdornedToolBehavior.TransformPropertyFlags.RotatationAngle); Rect rect2 = this.initialRects[index]; rect2.Offset(newTransform.TranslationX - this.initialTransforms[index].TranslationX, newTransform.TranslationY - this.initialTransforms[index].TranslationY); rect2.Width = width; rect2.Height = height; BaseFrameworkElement child = (BaseFrameworkElement)index; LayoutOverrides overridesToIgnore = (LayoutOverrides)(0 | (!object.Equals((object)width, (object)rect1.Width) ? 16 : 0) | (!object.Equals((object)height, (object)rect1.Height) ? 32 : 0)); designerForChild.SetChildRect(child, rect2, this.initialOverrides[index], overridesToIgnore, LayoutOverrides.None); if (!object.Equals((object)width, (object)rect1.Width) || !object.Equals((object)height, (object)rect1.Height)) { PathElement.EnsureStretchIsFill((SceneNode)index); } PathElement.PathTransformHelper pathTransformHelper; if (this.pathTransformHelpers.TryGetValue(index, out pathTransformHelper)) { pathTransformHelper.Update(scale.X * vector1.X, scale.Y * vector1.Y); } } }
protected override bool OnDrag(Point dragStartPosition, Point dragCurrentPosition, bool scrollNow) { Vector correspondingVector = ElementUtilities.GetCorrespondingVector(dragCurrentPosition - dragStartPosition, this.elementToDocumentTransform); Rect rect = this.startGeometry.Rect; rect.Offset(correspondingVector); RectangleGeometry rectangleGeometry = this.startGeometry.Clone(); rectangleGeometry.Rect = RoundingHelper.RoundRect(rect); this.EditingElement.SetLocalValueAsWpf(Base2DElement.ClipProperty, (object)rectangleGeometry); this.UpdateEditTransaction(); this.ActiveView.EnsureVisible(this.ActiveAdorner, scrollNow); return(true); }