UIElement createCoil(float vx1, float vy1, float vx2, float vy2, float vw, bool dirDown, Brush stroke, float vthick, Brush fill) { Path path = new Path(); float thick = vthick * (float)Math.Sqrt(w * h); float rad = (float)convVSizeX(vw / 2); float y1 = (float)convVY(vy1) + rad; float y2 = (float)convVY(vy2) - rad; if (stroke != null) { path.Stroke = stroke; } path.Fill = fill; path.StrokeThickness = thick; StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(new Point(convVX(vx1), y1), true, false); ctx.LineTo(new Point(convVX(vx2), y2), true, true); ctx.ArcTo(new Point(convVX(vx2 + vw), y2), new Size(rad, rad), 0, true, SweepDirection.Counterclockwise, true, true); ctx.LineTo(new Point(convVX(vx1 + vw), y1), true, true); ctx.ArcTo(new Point(convVX(vx1), y1), new Size(rad, rad), 0, true, SweepDirection.Counterclockwise, true, true); } geometry.Freeze(); path.Data = geometry; return(path); }
UIElement createTestTube(float vx, float vy, float vw, float vh, Brush stroke, float vthick, Brush fill) { Path path = new Path(); float thick = vthick * (float)Math.Sqrt(w * h); float rad = (float)convVSizeX(vw / 2); if (stroke != null) { path.Stroke = stroke; } path.Fill = fill; path.StrokeThickness = thick; StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(new Point(convVX(vx), convVY(vy)), true, false); ctx.LineTo(new Point(convVX(vx), convVY(vy + vh) - rad), true, true); ctx.ArcTo(new Point(convVX(vx + vw), convVY(vy + vh) - rad), new Size(rad, rad), 0, true, SweepDirection.Counterclockwise, true, true); ctx.LineTo(new Point(convVX(vx + vw), convVY(vy)), true, true); } geometry.Freeze(); path.Data = geometry; return(path); }
private void InternalDrawArrowGeometry(StreamGeometryContext context) { double theta = Math.Atan2(Y1 - Y2, X1 - X2); double sint = Math.Sin(theta); double cost = Math.Cos(theta); Point pt1 = new Point(X1, this.Y1); Point pt2 = new Point(X2, this.Y2); context.BeginFigure(pt1, true, false); context.LineTo(pt2, true, true); if (IsDirected) { double mid_X = (X2 + X1) / 2; double mid_Y = (Y2 + Y1) / 2; Point mid_point = new Point(mid_X, mid_Y); Point pt3 = new Point( mid_X + (HeadWidth * cost - HeadHeight * sint), mid_Y + (HeadWidth * sint + HeadHeight * cost)); Point pt4 = new Point( mid_X + (HeadWidth * cost + HeadHeight * sint), mid_Y - (HeadHeight * cost - HeadWidth * sint)); context.LineTo(mid_point, true, true); context.LineTo(pt3, true, true); context.LineTo(mid_point, true, true); context.LineTo(pt4, true, true); } }
internal static void DrawTriangle(this StreamGeometryContext ctx, Point pos1, Point pos2, Point pos3, bool isStroked, bool isClosed) { ctx.BeginFigure(pos1, true, isClosed); ctx.LineTo(pos2, isStroked, false); ctx.LineTo(pos3, isStroked, false); }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Создание геометрии стрелки /// </summary> /// <param name="start">Начало</param> /// <param name="end">Конец</param> /// <param name="head_width">Ширина</param> /// <param name="head_height">Высота</param> /// <param name="freeze">Следует ли заморозить геометрию</param> /// <returns>Геометрия</returns> //--------------------------------------------------------------------------------------------------------- public static Geometry CreateGeometryArrow(Point start, Point end, Double head_width, Double head_height, Boolean freeze) { Double theta = Math.Atan2(start.Y - end.Y, start.X - end.X); Double sint = Math.Sin(theta); Double cost = Math.Cos(theta); Point pt3 = new Point( end.X + (head_width * cost - head_height * sint), end.Y + (head_width * sint + head_height * cost)); Point pt4 = new Point( end.X + (head_width * cost + head_height * sint), end.Y - (head_height * cost - head_width * sint)); Geometry geometry = new StreamGeometry(); using (StreamGeometryContext ctx = ((StreamGeometry)geometry).Open()) { ctx.BeginFigure(start, true, false); ctx.LineTo(end, true, true); ctx.LineTo(pt3, true, true); ctx.LineTo(end, true, true); ctx.LineTo(pt4, true, true); } // Freeze the geometry (make it unmodifiable) // for additional performance benefits. if (freeze) { geometry.Freeze(); } return(geometry); }
/// <summary> /// Draw a rectangle /// </summary> /// <param name="context"></param> private void InternalDrawNodeGeometry(StreamGeometryContext context) { context.BeginFigure(new Point(0, 0), true, true); context.LineTo(new Point(Width, 0), true, false); context.LineTo(new Point(Width, Height), true, false); context.LineTo(new Point(0, Height), true, false); }
/// <summary> /// Defines the three parallel lines of a Triple bond. /// </summary> /// <param name="startPoint">Where the bond starts</param> /// <param name="endPoint">Where it ends</param> /// <param name="enclosingPoly"></param> /// <returns></returns> public static System.Windows.Media.Geometry TripleBondGeometry(Point startPoint, Point endPoint, ref List <Point> enclosingPoly) { Vector v = endPoint - startPoint; Vector normal = v.Perpendicular(); normal.Normalize(); double distance = Globals.Offset; Point point1 = startPoint + normal * distance; Point point2 = point1 + v; Point point3 = startPoint - normal * distance; Point point4 = point3 + v; enclosingPoly = new List <Point>() { point1, point2, point4, point3 }; StreamGeometry sg = new StreamGeometry(); using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(startPoint, false, false); sgc.LineTo(endPoint, true, false); sgc.BeginFigure(point1, false, false); sgc.LineTo(point2, true, false); sgc.BeginFigure(point3, false, false); sgc.LineTo(point4, true, false); sgc.Close(); } sg.Freeze(); return(sg); }
/// <summary> /// draws the two parallel lines of a double bond /// These bonds can either straddle the atom-atom line or fall to one or other side of it /// </summary> /// <param name="startPoint"></param> /// <param name="endPoint"></param> /// <param name="doubleBondPlacement"></param> /// <param name="ringCentroid"></param> /// <param name="enclosingPoly"></param> /// <returns></returns> public static System.Windows.Media.Geometry DoubleBondGeometry(Point startPoint, Point endPoint, BondDirection doubleBondPlacement, ref List <Point> enclosingPoly, Point?ringCentroid = null) { Point point1; Point point2; Point point3; Point point4; enclosingPoly = GetDoubleBondPoints(startPoint, endPoint, doubleBondPlacement, ringCentroid, out point1, out point2, out point3, out point4); ; StreamGeometry sg = new StreamGeometry(); using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(point1, false, false); sgc.LineTo(point2, true, false); sgc.BeginFigure(point3, false, false); sgc.LineTo(point4, true, false); sgc.Close(); } sg.Freeze(); return(sg); }
private static void DrawArrow(StreamGeometryContext streamGeometryContext, Point[] points, Vector sizeOffset, double thickness) { double headWidth = thickness; double headHeight = thickness * 0.8; Point pt1 = Point.Add(points[points.Length - 2], sizeOffset); Point pt2 = Point.Add(points[points.Length - 1], sizeOffset); double theta = Math.Atan2(pt1.Y - pt2.Y, pt1.X - pt2.X); double sint = Math.Sin(theta); double cost = Math.Cos(theta); Point pt3 = new Point( pt2.X + (headWidth * cost - headHeight * sint), pt2.Y + (headWidth * sint + headHeight * cost)); Point pt4 = new Point( pt2.X + (headWidth * cost + headHeight * sint), pt2.Y - (headHeight * cost - headWidth * sint)); streamGeometryContext.BeginFigure(pt1, true, false); streamGeometryContext.LineTo(pt2, true, true); streamGeometryContext.LineTo(pt3, true, true); streamGeometryContext.LineTo(pt2, true, true); streamGeometryContext.LineTo(pt4, true, true); }
private void DrawGeometry(StreamGeometryContext context) { bool large = Math.Abs(EndAngle - StartAngle) > 180.0; Point innerArcStartPoint = ToPoint(Center, InnerRadius, StartAngle); Point innerArcMiddlePoint = ToPoint(Center, InnerRadius, (StartAngle + EndAngle) / 2); Point innerArcEndPoint = ToPoint(Center, InnerRadius, EndAngle); Point outerArcStartPoint = ToPoint(Center, OuterRadius, StartAngle); Point outerArcMiddlePoint = ToPoint(Center, OuterRadius, (StartAngle + EndAngle) / 2); Point outerArcEndPoint = ToPoint(Center, OuterRadius, EndAngle); var outerArcSize = new Size(OuterRadius, OuterRadius); var innerArcSize = new Size(InnerRadius, InnerRadius); context.BeginFigure(innerArcStartPoint, true, true); context.LineTo(outerArcStartPoint, true, true); if (large) { context.ArcTo(outerArcMiddlePoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true); } context.ArcTo(outerArcEndPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true); context.LineTo(innerArcEndPoint, true, true); if (large) { context.ArcTo(innerArcMiddlePoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true); } context.ArcTo(innerArcStartPoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true); }
/// <summary> /// Draws the join with given context. /// </summary> /// <param name="points">The points of join.</param> /// <param name="context">The context of geometry.</param> private static void drawJoin(Point[] points, StreamGeometryContext context) { context.BeginFigure(points[0], true, false); var from = new Point(); var to = new Point(); // Get Bezier Spline Control Points. Point[] controlPoints1, controlPoints2; BezierSpline.GetCurveControlPoints(points, out controlPoints1, out controlPoints2); for (var i = 0; i < controlPoints1.Length; ++i) { from = points[i]; to = points[i + 1]; var controlPoint1 = controlPoints1[i]; var controlPoint2 = controlPoints2[i]; //context.BezierTo(controlPoint1, controlPoint2, to, true, true); context.LineTo(to, true, true); } Point arm1; Point arm2; computeArms(ref from, ref to, out arm1, out arm2); context.LineTo(arm1, true, true); context.LineTo(to, false, false); context.LineTo(arm2, true, true); }
UIElement createHArrow(float vx, float vy, float vw, float vh, Brush stroke, float vthick) { Path path = new Path(); float vhy = vy + vh / 2; float thick = vthick * (float)Math.Sqrt(w * h); if (stroke != null) { path.Stroke = stroke; } path.StrokeThickness = thick; StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(new Point(convVX(vx), convVY(vhy)), true, false); ctx.LineTo(new Point(convVX(vx + vw), convVY(vhy)), true, true); ctx.LineTo(new Point(convVX(vx + 0.75f * vw), convVY(vy)), true, true); ctx.BeginFigure(new Point(convVX(vx + vw), convVY(vhy)), true, false); ctx.LineTo(new Point(convVX(vx + 0.75f * vw), convVY(vy + vh)), true, true); } geometry.Freeze(); path.Data = geometry; return(path); }
private void DrawGeometry(StreamGeometryContext context) { Point startPoint = new Point(CentreX, CentreY); Point innerArcStartPoint = ComputeCartesianCoordinate(RotationAngle, InnerRadius); innerArcStartPoint.Offset(CentreX, CentreY); var innerArcEndPoint = ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius); innerArcEndPoint.Offset(CentreX, CentreY); Point outerArcStartPoint = ComputeCartesianCoordinate(RotationAngle, Radius); outerArcStartPoint.Offset(CentreX, CentreY); Point outerArcEndPoint = ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius); outerArcEndPoint.Offset(CentreX, CentreY); bool largeArc = WedgeAngle > 180.0; Size outerArcSize = new Size(Radius, Radius); Size innerArcSize = new Size(InnerRadius, InnerRadius); context.BeginFigure(innerArcStartPoint, true, true); context.LineTo(outerArcStartPoint, true, true); context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true); context.LineTo(innerArcEndPoint, true, true); context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true); }
public void Draw(TextView textView, DrawingContext drawingContext) { foreach (TextSegment current in this.SearchHitsSegments) { foreach (Rect current2 in BackgroundGeometryBuilder.GetRectsForSegment(textView, current)) { Point bottomLeft = current2.BottomLeft; Point bottomRight = current2.BottomRight; Pen pen = new Pen(new SolidColorBrush(Colors.OrangeRed), 1); pen.Freeze(); double num = 2.5; int count = System.Math.Max((int)((bottomRight.X - bottomLeft.X) / num) + 1, 4); StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext streamGeometryContext = streamGeometry.Open()) { streamGeometryContext.BeginFigure(bottomLeft, true, true); streamGeometryContext.LineTo(current2.TopLeft, true, false); streamGeometryContext.LineTo(current2.TopRight, true, false); streamGeometryContext.LineTo(current2.BottomRight, true, false); } streamGeometry.Freeze(); drawingContext.DrawGeometry(Brushes.Transparent, pen, streamGeometry); } } }
private void method_18(StreamGeometryContext streamGeometryContext_0) { Point point = new Point(this.method_10(), this.method_12()); Point point2 = Utils.ComputeCartesianCoordinate(this.method_8(), this.method_4()); point2.Offset(this.method_10(), this.method_12()); Point point3 = Utils.ComputeCartesianCoordinate(this.method_8() + this.method_6(), this.method_4()); point3.Offset(this.method_10(), this.method_12()); Point point4 = Utils.ComputeCartesianCoordinate(this.method_8(), this.method_0()); point4.Offset(this.method_10(), this.method_12()); Point point5 = Utils.ComputeCartesianCoordinate(this.method_8() + this.method_6(), this.method_0()); point5.Offset(this.method_10(), this.method_12()); bool isLargeArc = this.method_6() > 180.0; if (this.method_2() > 0.0) { Point point6 = Utils.ComputeCartesianCoordinate(this.method_8() + this.method_6() / 2.0, this.method_2()); point2.Offset(point6.X, point6.Y); point3.Offset(point6.X, point6.Y); point4.Offset(point6.X, point6.Y); point5.Offset(point6.X, point6.Y); } Size size = new Size(this.method_0(), this.method_0()); Size size2 = new Size(this.method_4(), this.method_4()); streamGeometryContext_0.BeginFigure(point2, true, true); streamGeometryContext_0.LineTo(point4, true, true); streamGeometryContext_0.ArcTo(point5, size, 0.0, isLargeArc, SweepDirection.Clockwise, true, true); streamGeometryContext_0.LineTo(point3, true, true); streamGeometryContext_0.ArcTo(point2, size2, 0.0, isLargeArc, SweepDirection.Counterclockwise, true, true); }
protected override void DrawGeometry(StreamGeometryContext context) { context.BeginFigure(new Point(Position.X + 5, Position.Y), true, true); context.LineTo(new Point(Position.X, Position.Y + 5), true, true); context.LineTo(new Point(Position.X - 5, Position.Y), true, true); context.LineTo(new Point(Position.X, Position.Y - 5), true, true); }
private void CreateArea(List <Point> viewPoints, double height) { using (StreamGeometryContext ctx = _area.Open()) { List <Point> .Enumerator it = viewPoints.GetEnumerator(); if (it.MoveNext()) { ctx.BeginFigure(new Point(it.Current.X, height), true, // IS filled true); // IS closed ctx.LineTo(it.Current, false, // is NOT stroked false); // is not smoothly joined w/other segments var point = new Point(); while (it.MoveNext()) { point = it.Current; ctx.LineTo( point, false, // is NOT stroked false); // is not smoothly joined w/other segments } if (point != new Point()) { ctx.LineTo(new Point(point.X, height), false, // is NOT stroked false); // is not smoothly joined w/other segments } } } }
private Geometry GenerateMyWeirdGeometry() { // Setup the Center Point & Radius StreamGeometry geom = new StreamGeometry(); using (StreamGeometryContext context = geom.Open()) { Point c = new Point(ActualWidth / 2, ActualHeight / 2); double rOutterX = ActualWidth / 2; double rOutterY = ActualHeight / 2; double rInnerX = rOutterX - inner_width; double rInnerY = rOutterY - inner_width; double theta = 0; bool hasBegun = false; double x; double y; Point currentPoint; // Draw the Outside Edge for (theta = start_angle; theta <= stop_angle; theta++) { x = c.X + rOutterX * Math.Cos(GetRadian(theta)); y = c.Y + rOutterY * Math.Sin(GetRadian(theta)); currentPoint = new Point(x, y); if (!hasBegun) { context.BeginFigure(currentPoint, true, true); hasBegun = true; } context.LineTo(currentPoint, true, true); } // Connect the Outside Edge to the Inner Edge x = c.X + rInnerX * Math.Cos(GetRadian(stop_angle)); y = c.Y + rInnerY * Math.Sin(GetRadian(stop_angle)); currentPoint = new Point(x, y); context.LineTo(currentPoint, true, true); // Draw the Inner Edge for (theta = stop_angle; theta >= start_angle; theta--) { x = c.X + rInnerX * Math.Cos(GetRadian(theta)); y = c.Y + rInnerY * Math.Sin(GetRadian(theta)); currentPoint = new Point(x, y); context.LineTo(currentPoint, true, true); } // Connect the Inner Edge to the Outside Edge x = c.X + rOutterX * Math.Cos(GetRadian(start_angle)); y = c.Y + rOutterY * Math.Sin(GetRadian(start_angle)); currentPoint = new Point(x, y); context.LineTo(currentPoint, true, true); //context.Close(); } return(geom); }
private void DrawGeometry(StreamGeometryContext context) { Radius = Math.Abs(Radius); InnerRadius = Math.Abs(InnerRadius); Point innerArcStartPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle, InnerRadius); innerArcStartPoint.Offset(CenterX, CenterY); Point innerArcEndPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius); innerArcEndPoint.Offset(CenterX, CenterY); Point outerArcStartPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle, Radius); outerArcStartPoint.Offset(CenterX, CenterY); Point outerArcEndPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius); outerArcEndPoint.Offset(CenterX, CenterY); if (PushOut > 0 && WedgeAngle < 360.0) { Point offset = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, PushOut); innerArcStartPoint.Offset(offset.X, offset.Y); innerArcEndPoint.Offset(offset.X, offset.Y); outerArcStartPoint.Offset(offset.X, offset.Y); outerArcEndPoint.Offset(offset.X, offset.Y); } bool largeArc = WedgeAngle > 180.0; Size outerArcSize = new Size(Radius, Radius); Size innerArcSize = new Size(InnerRadius, InnerRadius); if (WedgeAngle >= 360.0) { Point internalOuterPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, Radius); internalOuterPoint.Offset(CenterX, CenterY); Point internalInnerPoint = CalculationUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, InnerRadius); internalInnerPoint.Offset(CenterX, CenterY); context.BeginFigure(innerArcStartPoint, true, true); context.LineTo(outerArcStartPoint, true, true); context.ArcTo(internalOuterPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true); context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true); context.LineTo(innerArcEndPoint, true, true); context.ArcTo(internalInnerPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true); context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true); } else { context.BeginFigure(innerArcStartPoint, true, true); context.LineTo(outerArcStartPoint, true, true); context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true); context.LineTo(innerArcEndPoint, true, true); context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true); } }
public static Canvas GetArc() { Canvas canvas = new Canvas(); canvas.Height = 200; canvas.Width = 200; Path pathArc = new Path(); PathGeometry pathGeometry = new PathGeometry(); ArcSegment arc = new ArcSegment(new Point(0, 50), new Size(50, 50), 0, false, SweepDirection.Clockwise, true); PathFigure figureArc = new PathFigure(); figureArc.StartPoint = new Point(50, 0); figureArc.Segments.Add(arc); LineSegment line1 = new LineSegment(new Point(50, 0), true); LineSegment line2 = new LineSegment(new Point(0, 50), true); PathFigure figureLine = new PathFigure(); figureLine.StartPoint = new Point(50, 50); figureLine.Segments.Add(line1); figureLine.Segments.Add(line2); pathGeometry.Figures.Add(figureArc); pathGeometry.Figures.Add(figureLine); pathArc.Data = pathGeometry; pathArc.Fill = new SolidColorBrush(Colors.LightGray); canvas.Children.Add(pathArc); Path pathLine1 = new Path(); StreamGeometry streamGeomety1 = new StreamGeometry(); StreamGeometryContext sgc1 = streamGeomety1.Open(); sgc1.BeginFigure(new Point(0, 50), true, true); sgc1.LineTo(new Point(50, 50), true, true); sgc1.LineTo(new Point(0, 200), true, true); sgc1.Close(); pathLine1.Data = streamGeomety1; pathLine1.Fill = new SolidColorBrush(Colors.LightGray); canvas.Children.Add(pathLine1); Path pathLine2 = new Path(); StreamGeometry streamGeomety2 = new StreamGeometry(); StreamGeometryContext sgc2 = streamGeomety2.Open(); sgc2.BeginFigure(new Point(50, 0), true, true); sgc2.LineTo(new Point(50, 50), true, true); sgc2.LineTo(new Point(200, 0), true, true); sgc2.Close(); pathLine2.Data = streamGeomety2; pathLine2.Fill = new SolidColorBrush(Colors.LightGray); canvas.Children.Add(pathLine2); return(canvas); }
/// <summary> /// Draws the pie piece /// </summary> private void DrawGeometry(StreamGeometryContext context) { var innerArcStartPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle, InnerRadius); innerArcStartPoint.Offset(CentreX, CentreY); var innerArcEndPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius); innerArcEndPoint.Offset(CentreX, CentreY); var outerArcStartPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle, Radius); outerArcStartPoint.Offset(CentreX, CentreY); var outerArcEndPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius); outerArcEndPoint.Offset(CentreX, CentreY); var innerArcMidPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle * .5, InnerRadius); innerArcMidPoint.Offset(CentreX, CentreY); var outerArcMidPoint = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle * .5, Radius); outerArcMidPoint.Offset(CentreX, CentreY); var largeArc = WedgeAngle > 180.0d; var requiresMidPoint = Math.Abs(WedgeAngle - 360) < 0.01; if (PushOut > 0 && !requiresMidPoint) { var offset = PieUtils.ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, PushOut); innerArcStartPoint.Offset(offset.X, offset.Y); innerArcEndPoint.Offset(offset.X, offset.Y); outerArcStartPoint.Offset(offset.X, offset.Y); outerArcEndPoint.Offset(offset.X, offset.Y); } var outerArcSize = new Size(Radius, Radius); var innerArcSize = new Size(InnerRadius, InnerRadius); if (requiresMidPoint) { context.BeginFigure(innerArcStartPoint, true, true); context.LineTo(outerArcStartPoint, true, true); context.ArcTo(outerArcMidPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true); context.ArcTo(outerArcEndPoint, outerArcSize, 0, false, SweepDirection.Clockwise, true, true); context.LineTo(innerArcEndPoint, true, true); context.ArcTo(innerArcMidPoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true); context.ArcTo(innerArcStartPoint, innerArcSize, 0, false, SweepDirection.Counterclockwise, true, true); return; } context.BeginFigure(innerArcStartPoint, true, true); context.LineTo(outerArcStartPoint, true, true); context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true); context.LineTo(innerArcEndPoint, true, true); context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true); }
private void DrawGeometry(StreamGeometryContext context) { context.BeginFigure(new Point(Position.X, 0), false, false); context.LineTo(new Point(Position.X, (double)Parent.GetValue(ActualHeightProperty)), true, true); context.BeginFigure(new Point(0, Position.Y), false, false); context.LineTo(new Point((double)Parent.GetValue(ActualWidthProperty), Position.Y), true, true); }
UIElement createGear(float vx, float vy, float vw, float vh, Brush fill) { Path path = new Path(); float thick = 0.005f * (float)Math.Sqrt(w * h); float rad = (float)convVSizeX(vw / 2); float irad = 0.75f * rad; float srad = 0.5f * irad; double x1, y1, x2, y2; bool inward = true; int gears = 8; double gearstep = 2 * Math.PI / (gears * 2); double aoffset = gearstep / 2; path.Fill = fill; path.Stroke = fill; if (thick > 0) { path.StrokeThickness = thick; } StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(new Point(convVX(vx + vw), convVY(vy + vh / 2)), true, true); for (double a = 0; a < 2 * Math.PI; a += gearstep) { x1 = convVX(vx) + rad * (1 + Math.Cos(a + aoffset)); y1 = convVY(vy) + rad * (1 + Math.Sin(a + aoffset)); x2 = convVX(vx) + (rad - irad) + irad * (1 + Math.Cos(a + aoffset)); y2 = convVY(vy) + (rad - irad) + irad * (1 + Math.Sin(a + aoffset)); if (inward) { ctx.LineTo(new Point(x1, y1), true, true); ctx.LineTo(new Point(x2, y2), true, true); } else { ctx.LineTo(new Point(x2, y2), true, true); ctx.LineTo(new Point(x1, y1), true, true); } inward = !inward; } } geometry.Freeze(); EllipseGeometry circleGeometry = new EllipseGeometry(new Point(convVX(vx + vw / 2), convVY(vy + vh / 2)), srad, srad); GeometryGroup geometryGroup = new GeometryGroup(); geometryGroup.Children.Add(geometry); geometryGroup.Children.Add(circleGeometry); path.Data = geometryGroup; return(path); }
protected override void DrawGeometry(StreamGeometryContext context) { double lHeight = (double)Parent.GetValue(ActualHeightProperty); context.BeginFigure(Position, true, true); context.LineTo(new Point(Position.X, lHeight), true, true); context.LineTo(new Point(Position.X - ColumnWidth, lHeight), true, true); context.LineTo(new Point(Position.X - ColumnWidth, Position.Y), true, true); }
/// <summary> /// Draws the Triangle-Control /// </summary> /// <param name="context"></param> protected void InternalDrawTriangleGeometry(StreamGeometryContext context) { Point pt1 = new Point(Width / 2, 0); Point pt2 = new Point(Width, Height); Point pt3 = new Point(0, Height); context.BeginFigure(pt1, true, true); context.LineTo(pt2, true, false); context.LineTo(pt3, true, false); }
private void InternalDrawArrowGeometry(StreamGeometryContext context) { Point ptCenter = new Point(this.Width / 2, this.Height / 2); double radius = this.Width / 2; Point[] pts = new Point[10]; pts[0] = new Point(ptCenter.X, (int)(ptCenter.Y - radius)); for (int i = 1; i < 5; i++) { pts[2 * i] = RotateTheta(pts[2 * (i - 1)], ptCenter, 72.0); pts[2 * i].X = (int)(ptCenter.X + (pts[2 * i].X - ptCenter.X)); pts[2 * i].Y = (int)(ptCenter.Y + (pts[2 * i].Y - ptCenter.Y)); } //通过直线求交点的方式来取得1,3,5,7,9点坐标 pts[1] = Intersection(pts[0], pts[4], pts[2], pts[8]); pts[3] = Intersection(pts[0], pts[4], pts[2], pts[6]); pts[5] = Intersection(pts[2], pts[6], pts[4], pts[8]); pts[7] = Intersection(pts[0], pts[6], pts[4], pts[8]); pts[9] = Intersection(pts[0], pts[6], pts[2], pts[8]); context.BeginFigure(pts[0], true, true); context.LineTo(pts[1], true, true); context.LineTo(pts[2], true, true); context.LineTo(pts[3], true, true); context.LineTo(pts[4], true, true); context.LineTo(pts[5], true, true); context.LineTo(pts[6], true, true); context.LineTo(pts[7], true, true); context.LineTo(pts[8], true, true); context.LineTo(pts[9], true, true); }
// 在此覆写方法中实现图形 protected override Geometry CreateDefiningGeometry() { StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext context = streamGeometry.Open()) { double X1 = StartPoint.X; double X2 = EndPoint.X; double Y1 = StartPoint.Y; double Y2 = EndPoint.Y; // 往右走一部分的点 double X1Right = X1 + rightBias; double X2Right = X2 + rightBias; //(X1,Y1)--------(X1Right,Y1) // | // | // | //(X2,Y2)<-------(X2Right,Y2) // 这里要计算的角就是下侧的边了 double theta = Math.Atan2(Y2 - Y2, X2Right - X2); double sint = Math.Sin(theta); double cost = Math.Cos(theta); Point pt1 = new Point(X1, Y1); Point pt2 = new Point(X1Right, Y1); Point pt3 = new Point(X2Right, Y2); Point pt4 = new Point(X2, Y2); double HeadWidth = this.HeadWidth; double HeadHeight = this.HeadHeight; // 箭帽的两个点 Point pt5 = new Point( X2 + (HeadWidth * cost - HeadHeight * sint), Y2 + (HeadWidth * sint + HeadHeight * cost)); Point pt6 = new Point( X2 + (HeadWidth * cost + HeadHeight * sint), Y2 - (HeadHeight * cost - HeadWidth * sint)); context.BeginFigure(pt1, false); context.LineTo(pt2); context.LineTo(pt3); context.LineTo(pt4); context.EndFigure(false); context.BeginFigure(pt5, false); context.LineTo(pt4); context.LineTo(pt6); context.EndFigure(false); } return(streamGeometry); }
internal override void RenderAxis() { XAxisPosition position = (XAxisPosition)GetValue(XAxisPositionProperty); Point tickPosition; StreamGeometryContext lineContext = axisLineGeometry.Open(); if (!IsInnermost) { Point axisStart = new Point(MinTransformed * Scale - Offset - axisLine.StrokeThickness / 2, yPosition); lineContext.BeginFigure(axisStart, false, false); lineContext.LineTo(new Point(MaxTransformed * Scale - Offset + axisLine.StrokeThickness / 2, yPosition), true, false); } lineContext.Close(); StreamGeometryContext ticksContext = axisTicksGeometry.Open(); if (TicksVisible) { for (int i = 0; i < TicksTransformed.Length; ++i) { tickPosition = TickStartPosition(i); ticksContext.BeginFigure(tickPosition, false, false); if (position == XAxisPosition.Bottom) { tickPosition.Y = tickPosition.Y + TickLength; } if (position == XAxisPosition.Top) { tickPosition.Y = tickPosition.Y - TickLength; } ticksContext.LineTo(tickPosition, true, false); ticksContext.BeginFigure(tickPosition, false, false); tickPosition.Y = tickPosition.Y; ticksContext.LineTo(tickPosition, true, false); } } ticksContext.Close(); interactionPad.Width = Math.Max(AxisTotalLength - AxisPadding.Total(), 1); interactionPad.Height = AxisThickness; if (position == XAxisPosition.Bottom) { interactionPad.SetValue(Canvas.TopProperty, yPosition); } else { interactionPad.SetValue(Canvas.TopProperty, yPosition - AxisThickness); } double xPosition = Scale * MinTransformed - Offset; interactionPad.SetValue(Canvas.LeftProperty, xPosition); base.RenderAxis(); }
private static void DefineRectangle(StreamGeometryContext context, Thickness th, CornerRadiusExt r, double w, double h) { context.BeginFigure(new Point(th.Left, th.Top + r.TopLeftLeft), true, true); context.QuadraticBezierTo(new Point(th.Left, th.Top), new Point(th.Left + r.TopLeftTop, th.Top), false, false); context.LineTo(new Point(w - th.Right - r.TopRightTop, th.Top), false, false); context.QuadraticBezierTo(new Point(w - th.Right, th.Top), new Point(w - th.Right, th.Top + r.TopRightRight), false, false); context.LineTo(new Point(w - th.Right, h - th.Bottom - r.BottomRightRight), false, false); context.QuadraticBezierTo(new Point(w - th.Right, h - th.Bottom), new Point(w - th.Right - r.BottomRightBottom, h - th.Bottom), false, false); context.LineTo(new Point(th.Left + r.BottomLeftBottom, h - th.Bottom), false, false); context.QuadraticBezierTo(new Point(th.Left, h - th.Bottom), new Point(th.Left, h - th.Bottom - r.BottomLeftLeft), false, false); }
public static void DrawTriangle(StreamGeometryContext context, Vector mainLine, Vector mainPerpendicularLine, Point point1, int size, bool isFilled) { int halfSize = size / 2; context.BeginFigure(point1, isFilled, true); var point2 = point1 + (mainPerpendicularLine * halfSize) + (mainLine * size); var point3 = point1 - (mainPerpendicularLine * halfSize) + (mainLine * size); context.LineTo(point2, true, true); context.LineTo(point3, true, true); }
protected internal override void ApplyTo(StreamGeometryContext ctx) { ctx.LineTo(Point); }
private static void DeserializeLineTo(BinaryReader br, Byte firstByte, StreamGeometryContext sc) { Point point; bool isStroked; bool isSmoothJoin; DeserializePointAndTwoBools(br, firstByte, out point, out isStroked, out isSmoothJoin); sc.LineTo(point, isStroked, isSmoothJoin); }