public static bool DrawInscribedRoundedRect(DrawingContext drawingContext, Brush fill, Pen stroke, Rect outerBounds, double cornerRadius) { Point spineLeftTop = new Point(outerBounds.Left, outerBounds.Top); Point spineRightBottom = new Point(outerBounds.Right, outerBounds.Bottom); bool drewSomething = false; if (stroke != null && !Tolerances.NearZero(stroke.Thickness)) { double halfThickness = stroke.Thickness / 2d; spineLeftTop.X += halfThickness; spineLeftTop.Y += halfThickness; spineRightBottom.X -= halfThickness; spineRightBottom.Y -= halfThickness; } Rect spineRect = new Rect(spineLeftTop, spineRightBottom); if (!Tolerances.NearZero(spineRect.Width) && !Tolerances.NearZero(spineRect.Height)) { drawingContext.DrawRoundedRectangle(fill, stroke, spineRect, cornerRadius, cornerRadius); drewSomething = true; } return(drewSomething); }
private PathGeometry GetEllipseGeometry(Point left, Point top, Point right, Point bottom, double horizontalScale, double verticalScale) { Vector vector1 = right - left; if (!Tolerances.NearZero(vector1.Length)) { vector1.Normalize(); vector1 *= horizontalScale; } Vector vector2 = top - bottom; if (!Tolerances.NearZero(vector2.Length)) { vector2.Normalize(); vector2 *= verticalScale; } PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = left; pathFigure.Segments.Add((PathSegment) new BezierSegment(left + vector2, top - vector1, top, true)); pathFigure.Segments.Add((PathSegment) new BezierSegment(top + vector1, right + vector2, right, true)); pathFigure.Segments.Add((PathSegment) new BezierSegment(right - vector2, bottom + vector1, bottom, true)); pathFigure.Segments.Add((PathSegment) new BezierSegment(bottom - vector1, left - vector2, left, true)); pathFigure.IsClosed = true; pathFigure.Freeze(); PathGeometry pathGeometry = new PathGeometry((IEnumerable <PathFigure>) new PathFigure[1] { pathFigure }); pathGeometry.Freeze(); return(pathGeometry); }
public static Rect CalculateInnerRect(Rect outerBounds, double strokeThickness) { if (!Tolerances.NearZero(strokeThickness)) { return(new Rect(new Point(outerBounds.Left + strokeThickness, outerBounds.Top + strokeThickness), new Point(outerBounds.Right - strokeThickness, outerBounds.Bottom - strokeThickness))); } return(outerBounds); }
public void ApplyScale(Vector scale, Point origin, Point fixedPoint) { this.Translation += new Vector((1.0 - scale.X) * (fixedPoint.X - origin.X), (1.0 - scale.Y) * (fixedPoint.Y - origin.Y)) * this.Value; double num1 = Tolerances.NearZero(this.ScaleX) ? 0.001 : this.ScaleX; double num2 = Tolerances.NearZero(this.ScaleY) ? 0.001 : this.ScaleY; this.Scale = new Vector(num1 * scale.X, num2 * scale.Y); }
internal Radii(CornerRadius radii, Thickness borders, bool outer) { double num1 = 0.5 * borders.Left; double num2 = 0.5 * borders.Top; double num3 = 0.5 * borders.Right; double num4 = 0.5 * borders.Bottom; if (outer) { if (Tolerances.NearZero(radii.TopLeft)) { this.LeftTop = this.TopLeft = 0.0; } else { this.LeftTop = radii.TopLeft + num1; this.TopLeft = radii.TopLeft + num2; } if (Tolerances.NearZero(radii.TopRight)) { this.TopRight = this.RightTop = 0.0; } else { this.TopRight = radii.TopRight + num2; this.RightTop = radii.TopRight + num3; } if (Tolerances.NearZero(radii.BottomRight)) { this.RightBottom = this.BottomRight = 0.0; } else { this.RightBottom = radii.BottomRight + num3; this.BottomRight = radii.BottomRight + num4; } if (Tolerances.NearZero(radii.BottomLeft)) { this.BottomLeft = this.LeftBottom = 0.0; } else { this.BottomLeft = radii.BottomLeft + num4; this.LeftBottom = radii.BottomLeft + num1; } } else { this.LeftTop = Math.Max(0.0, radii.TopLeft - num1); this.TopLeft = Math.Max(0.0, radii.TopLeft - num2); this.TopRight = Math.Max(0.0, radii.TopRight - num2); this.RightTop = Math.Max(0.0, radii.TopRight - num3); this.RightBottom = Math.Max(0.0, radii.BottomRight - num3); this.BottomRight = Math.Max(0.0, radii.BottomRight - num4); this.BottomLeft = Math.Max(0.0, radii.BottomLeft - num4); this.LeftBottom = Math.Max(0.0, radii.BottomLeft - num1); } }
public void Render(DrawingContext dc, Rect renderRect, Brush brush, CornerRadius cornerRadius) { if (brush == null || Tolerances.NearZero(renderRect.Width) || Tolerances.NearZero(renderRect.Height)) { return; } this.ValidateGeometry(renderRect, cornerRadius); dc.DrawGeometry(brush, (Pen)null, (Geometry)this.geometry); }
private void SetRotationFromPointer() { Vector vector = Mouse.GetPosition((IInputElement)this) - new Point(this.RenderSize.Width / 2.0, this.RenderSize.Height / 2.0); if (Tolerances.NearZero(vector) || !this.IsEnabled) { return; } double num = Math.Atan2(vector.Y, vector.X) * 180.0 / Math.PI; this.RotationAngle = this.ClosestAngleTo(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ? Math.Round(num / 15.0) * 15.0 : RoundingHelper.RoundAngle(num)); }
private void SetOrientationFromPointer() { Vector3D positionFromPointer = this.GetPositionFromPointer(); Vector3D axisOfRotation = Vector3D.CrossProduct(this.initialPosition, positionFromPointer); if (!this.IsEnabled || Tolerances.NearZero(axisOfRotation.Length)) { return; } axisOfRotation.Normalize(); Quaternion quaternion = new Quaternion(axisOfRotation, Math.Acos(Vector3D.DotProduct(this.initialPosition, positionFromPointer)) * 57.2957795130823) * this.initialOrientation; this.Orientation = (Rotation3D) new AxisAngleRotation3D(quaternion.Axis, quaternion.Angle); }
private static bool ComputeLineTriangleIntersection(Ray3D line, Point3D[] triangle, out Point hitBarycentric) { hitBarycentric = new Point(double.NaN, double.NaN); Vector3D vector3D1 = triangle[1] - triangle[0]; Vector3D vector3D2 = triangle[2] - triangle[0]; if (Tolerances.NearZero(Vector3D.CrossProduct(vector3D1, vector3D2).LengthSquared)) { return(false); } Vector3D vector3D3 = line.Origin - triangle[0]; Vector3D vector2_1 = Vector3D.CrossProduct(line.Direction, vector3D2); double d = Vector3D.DotProduct(vector3D1, vector2_1); if (Tolerances.NearZero(d)) { return(false); } Vector3D vector1; if (d > 0.0) { vector1 = line.Origin - triangle[0]; } else { vector1 = triangle[0] - line.Origin; d = -d; } double num1 = 1.0 / d; double num2 = Vector3D.DotProduct(vector1, vector2_1); if (num2 < 0.0 || d < num2) { return(false); } Vector3D vector2_2 = Vector3D.CrossProduct(vector1, vector3D1); double num3 = Vector3D.DotProduct(line.Direction, vector2_2); if (num3 < 0.0 || d < num2 + num3) { return(false); } double num4 = Vector3D.DotProduct(vector3D2, vector2_2) * num1; double x = num2 * num1; double y = num3 * num1; hitBarycentric = new Point(x, y); return(true); }
private void GetArcGeometry(Vector3D axis1, Vector3D axis2, Vector3D normal, out PathGeometry frontGeometry, out PathGeometry backGeometry) { Vector3D vector3D = Vector3D.CrossProduct(normal, new Vector3D(0.0, 0.0, 1.0)); if (Tolerances.NearZero(vector3D.Length)) { Point point = new Point(this.ActualWidth / 2.0, this.ActualHeight / 2.0); double num = this.ActualWidth / 2.0; Vector vector1 = new Vector(1.0, 0.0); Vector vector2 = new Vector(0.0, -1.0); Point top = point + vector2 * num; Point bottom = point - vector2 * num; Point left = point - vector1 * num; Point right = point + vector1 * num; double horizontalScale = num * ArcBallPresenter.tangentSize; double verticalScale = num * ArcBallPresenter.tangentSize; frontGeometry = this.GetEllipseGeometry(left, top, right, bottom, horizontalScale, verticalScale); backGeometry = new PathGeometry(); } else { vector3D.Normalize(); axis1 = vector3D; axis2 = Vector3D.CrossProduct(normal, axis1); if (axis2.Z < 0.0) { axis2 = -axis2; } Vector vector1 = new Vector(axis1.X, -axis1.Y); Vector vector2 = new Vector(axis2.X, -axis2.Y); Point center = new Point(this.ActualWidth / 2.0, this.ActualHeight / 2.0); double num = this.ActualWidth / 2.0; Point top1 = center + vector2 * num; Point top2 = center - vector2 * num; Point point1 = center + vector1 * num; Point point2 = center - vector1 * num; double horizontalScale = vector1.Length * num * ArcBallPresenter.tangentSize; double verticalScale = vector2.Length * num * ArcBallPresenter.tangentSize; frontGeometry = this.GetSemiEllipseGeometry(point1, top1, point2, center, horizontalScale, verticalScale); backGeometry = this.GetSemiEllipseGeometry(point2, top2, point1, center, horizontalScale, verticalScale); } }
protected void GetBrushOffsetEndpoints(out Point startPoint, out Point endPoint, double startOffset, double endOffset, Matrix matrix) { this.GetBrushEndpoints(out startPoint, out endPoint); Matrix matrix1 = this.GetCompleteBrushTransformMatrix(true) * matrix; startPoint *= matrix1; endPoint *= matrix1; Vector vector = startPoint - endPoint; if (Tolerances.NearZero(vector.LengthSquared)) { vector = new Vector(1.0, 0.0); } else { vector.Normalize(); } startPoint += startOffset * vector; endPoint -= endOffset * vector; }
public override void Draw(DrawingContext context, Matrix matrix) { Point position; double length; Orientation orientation; if (this.baseFlowInsertionPoint.IsEmpty || MoveStrategy.GetContainerHost((SceneElement)this.baseFlowInsertionPoint.Element) == null || !this.GetInsertionInfo((SceneElement)this.baseFlowInsertionPoint.Element, this.baseFlowInsertionPoint.Index, this.baseFlowInsertionPoint.IsCursorAtEnd, out position, out length, out orientation)) { return; } Point point1 = position; Point point2 = position; switch (orientation) { case Orientation.Horizontal: point2.Y += length; break; case Orientation.Vertical: point2.X += length; break; } Brush activeBrush = FeedbackHelper.GetActiveBrush(AdornerType.Default); Pen thinPen = FeedbackHelper.GetThinPen(AdornerType.Default); Point point0 = this.TransformPoint(point1); Point point1_1 = this.TransformPoint(point2); Vector vector = point1_1 - point0; if (!Tolerances.NearZero(vector)) { vector.Normalize(); context.PushTransform((Transform) new MatrixTransform(new Matrix(vector.X, vector.Y, -vector.Y, -vector.X, point0.X, point0.Y))); context.DrawGeometry(activeBrush, thinPen, BaseFlowInsertionPointAdorner.ArrowGeometry); context.Pop(); context.PushTransform((Transform) new MatrixTransform(new Matrix(-vector.X, -vector.Y, vector.Y, -vector.X, point1_1.X, point1_1.Y))); context.DrawGeometry(activeBrush, thinPen, BaseFlowInsertionPointAdorner.ArrowGeometry); context.Pop(); } context.DrawLine(thinPen, point0, point1_1); }
public static bool DrawInscribedRoundedRect(DrawingContext drawingContext, Brush fill, Pen stroke, Rect outerBounds, double cornerRadius) { Point point1 = new Point(outerBounds.Left, outerBounds.Top); Point point2 = new Point(outerBounds.Right, outerBounds.Bottom); bool flag = false; if (stroke != null && !Tolerances.NearZero(stroke.Thickness)) { double num = stroke.Thickness / 2.0; point1.X += num; point1.Y += num; point2.X -= num; point2.Y -= num; } Rect rectangle = new Rect(point1, point2); if (!Tolerances.NearZero(rectangle.Width) && !Tolerances.NearZero(rectangle.Height)) { drawingContext.DrawRoundedRectangle(fill, stroke, rectangle, cornerRadius, cornerRadius); flag = true; } return(flag); }
public void Update(Rect rect, Thickness margin, Matrix4x4 transformToRoot, double density) { double unitsPerPixel = 1 / density; boundingBox = DpiHelper.RoundToPixel(rect, unitsPerPixel); marginZones.Clear(); if (margin == new Thickness()) { return; } // If transform to root is more than just an offset (i.e. element or // some of its ancestors are scaled/rotated/etc.) then no margins to // render. This matches WPF, UWP and WinUI adorners. if (!Tolerances.AreClose(transformToRoot.M11, 1) || !Tolerances.AreClose(transformToRoot.M22, 1) || !Tolerances.AreClose(transformToRoot.M12, 0) || !Tolerances.AreClose(transformToRoot.M21, 0)) { return; } // Create up to 4 rectangles for margins. Keep in mind that some of // margin values can be negative, e.g. Margin="-10, 20, 30, -40". // Left if (!Tolerances.NearZero(margin.Left)) { Rect rc = new Rect(); rc.Left = Math.Min(rect.Left - margin.Left, rect.Left); rc.Width = Math.Abs(margin.Left); rc.Top = rect.Top; rc.Bottom = rect.Bottom; TryAddMarginZone(rc, unitsPerPixel); } // Right if (!Tolerances.NearZero(margin.Right)) { Rect rc = new Rect(); rc.Left = Math.Min(rect.Right, rect.Right + margin.Right); rc.Width = Math.Abs(margin.Right); rc.Top = rect.Top; rc.Bottom = rect.Bottom; TryAddMarginZone(rc, unitsPerPixel); } // Top if (!Tolerances.NearZero(margin.Top)) { Rect rc = new Rect(); rc.Left = rect.Left - Math.Max(0, margin.Left); rc.Right = rect.Right + Math.Max(0, margin.Right); rc.Top = Math.Min(rect.Top - margin.Top, rect.Top); rc.Height = Math.Abs(margin.Top); TryAddMarginZone(rc, unitsPerPixel); } // Bottom if (!Tolerances.NearZero(margin.Bottom)) { Rect rc = new Rect(); rc.Left = rect.Left - Math.Max(0, margin.Left); rc.Right = rect.Right + Math.Max(0, margin.Right); rc.Top = Math.Min(rect.Bottom + margin.Bottom, rect.Bottom); rc.Height = Math.Abs(margin.Bottom); TryAddMarginZone(rc, unitsPerPixel); } }
private static void GenerateGeometry(StreamGeometryContext ctx, Rect rect, SuperRoundedRectRenderer.Radii radii) { Point point1 = new Point(radii.LeftTop, 0.0); Point point2 = new Point(rect.Width - radii.RightTop, 0.0); Point point3 = new Point(rect.Width, radii.TopRight); Point point4 = new Point(rect.Width, rect.Height - radii.BottomRight); Point point5 = new Point(rect.Width - radii.RightBottom, rect.Height); Point point6 = new Point(radii.LeftBottom, rect.Height); Point point7 = new Point(0.0, rect.Height - radii.BottomLeft); Point point8 = new Point(0.0, radii.TopLeft); if (point1.X > point2.X) { double num = radii.LeftTop / (radii.LeftTop + radii.RightTop) * rect.Width; point1.X = num; point2.X = num; } if (point3.Y > point4.Y) { double num = radii.TopRight / (radii.TopRight + radii.BottomRight) * rect.Height; point3.Y = num; point4.Y = num; } if (point5.X < point6.X) { double num = radii.LeftBottom / (radii.LeftBottom + radii.RightBottom) * rect.Width; point5.X = num; point6.X = num; } if (point7.Y < point8.Y) { double num = radii.TopLeft / (radii.TopLeft + radii.BottomLeft) * rect.Height; point7.Y = num; point8.Y = num; } Vector vector = new Vector(rect.TopLeft.X, rect.TopLeft.Y); point1 += vector; point2 += vector; point3 += vector; point4 += vector; point5 += vector; point6 += vector; point7 += vector; point8 += vector; ctx.BeginFigure(point1, true, true); ctx.LineTo(point2, true, false); double num1 = rect.TopRight.X - point2.X; double num2 = point3.Y - rect.TopRight.Y; if (!Tolerances.NearZero(num1) || !Tolerances.NearZero(num2)) { ctx.ArcTo(point3, new Size(num1, num2), 0.0, false, SweepDirection.Clockwise, true, false); } ctx.LineTo(point4, true, false); double num3 = rect.BottomRight.X - point5.X; double num4 = rect.BottomRight.Y - point4.Y; if (!Tolerances.NearZero(num3) || !Tolerances.NearZero(num4)) { ctx.ArcTo(point5, new Size(num3, num4), 0.0, false, SweepDirection.Clockwise, true, false); } ctx.LineTo(point6, true, false); double num5 = point6.X - rect.BottomLeft.X; double num6 = rect.BottomLeft.Y - point7.Y; if (!Tolerances.NearZero(num5) || !Tolerances.NearZero(num6)) { ctx.ArcTo(point7, new Size(num5, num6), 0.0, false, SweepDirection.Clockwise, true, false); } ctx.LineTo(point8, true, false); double num7 = point1.X - rect.TopLeft.X; double num8 = point8.Y - rect.TopLeft.Y; if (Tolerances.NearZero(num7) && Tolerances.NearZero(num8)) { return; } ctx.ArcTo(point1, new Size(num7, num8), 0.0, false, SweepDirection.Clockwise, true, false); }
private RegistrationPointFlags FindRegistrationPointForElement(BaseFrameworkElement element) { if (!element.IsViewObjectValid) { return(RegistrationPointFlags.None); } Point elementCoordinates = element.RenderTransformOriginInElementCoordinates; Point point1 = elementCoordinates; if (this.IsRenderTransform) { Rect computedTightBounds = element.GetComputedTightBounds(); point1 = new Point(elementCoordinates.X - computedTightBounds.Left, elementCoordinates.Y - computedTightBounds.Top); Point point2 = (Point)element.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty); Point point3 = new Point(); bool flag = false; if (!Tolerances.NearZero(computedTightBounds.Width)) { point1.X /= computedTightBounds.Width; } else if (!Tolerances.NearZero(point1.X)) { point1.X = -1.0; } if (!Tolerances.NearZero(computedTightBounds.Height)) { point1.Y /= computedTightBounds.Height; } else if (!Tolerances.NearZero(point1.Y)) { point1.Y = -1.0; } if (!double.IsNaN(point2.X) && !double.IsNaN(point2.Y)) { point3.X = point2.X; point3.Y = point2.Y; flag = true; } if ((Tolerances.NearZero(computedTightBounds.Width) || Tolerances.NearZero(computedTightBounds.Height)) && flag) { if (!Tolerances.NearZero(computedTightBounds.Width) && Tolerances.AreClose(point1.X, point3.X) && Tolerances.NearZero(point1.Y)) { point1 = point3; } else if (!Tolerances.NearZero(computedTightBounds.Height) && Tolerances.AreClose(point1.Y, point3.Y) && Tolerances.NearZero(point1.X)) { point1 = point3; } else if (Tolerances.NearZero(computedTightBounds.Width) && Tolerances.NearZero(computedTightBounds.Height) && Tolerances.NearZero(point1)) { point1 = point3; } } } foreach (RegistrationPointFlags registrationPoint in Enum.GetValues(typeof(RegistrationPointFlags))) { if ((this.CenterFromRegistrationPoint(registrationPoint) - point1).LengthSquared <= RegistrationPointModel.RegistrationPointTolerance) { return(registrationPoint); } } return(RegistrationPointFlags.None); }