/// <summary> /// Draws a tree-control style expander, which looks like a square with /// a dash (expanded) or a cross (unexpanded).</summary> /// <param name="x">X coordinate of expander top right corner</param> /// <param name="y">Y coordinate of expander top right corner</param> /// <param name="pen">Pen, should be 1 pixel wide</param> /// <param name="size">Size of pin, in pixels</param> /// <param name="pinned">Whether or not expander should appear "expanded"</param> /// <param name="g">Graphics object</param> public static void DrawRightPin(int x, int y, int size, D2dBrush pen, bool pinned, D2dGraphics g) { //g.DrawRectangle(pen, x - size, y, size, size); int rectWidth = size / 4; int rectHeight = 2 * size / 3; int center = size / 2; if (pinned) { g.DrawLine(x + center - size, y + rectHeight, x + center - size, y + size, pen); //lower center-vertical line g.DrawLine(x - size, y + rectHeight, x, y + rectHeight, pen); // middle-horizontal line g.DrawRectangle(new RectangleF(x + rectWidth - size, y, 2 * rectWidth, rectHeight), pen); //g.DrawLine(pen, x + 3 * rectWidth - 1, y, x + 3 * rectWidth - 1, y + rectHeight); // a vertial line next to the right side of the rect g.DrawLine(x + 3 * rectWidth - 1 - size, y, x + 3 * rectWidth - 1 - size, y + rectHeight, pen); // a vertial line next to the right side of the rect } else { g.DrawLine(x, y + center, x - size + rectHeight, y + center, pen); //left center-horizontal line g.DrawLine(x - size + rectHeight, y, x - size + rectHeight, y + size, pen); // middle-vertical line g.DrawRectangle(new RectangleF(x - size, y + (size - rectWidth) / 2 - 1, rectHeight, 2 * rectWidth), pen); g.DrawLine(x - size + rectHeight, y + (size - rectWidth) / 2 + 2 * rectWidth - 2, x - size, y + (size - rectWidth) / 2 + 2 * rectWidth - 2, pen); // a horizontal line next to the bottom side of the rect } }
/// <summary> /// Draws grid lines corresponding to a vertical scale</summary> /// <param name="g">The Direct2D graphics object</param> /// <param name="transform">Graph (world) to window's client (screen) transform</param> /// <param name="graphRect">Graph rectangle</param> /// <param name="majorSpacing">Scale's major spacing</param> /// <param name="lineBrush">Grid line brush</param> public static void DrawVerticalScaleGrid( this D2dGraphics g, Matrix transform, RectangleF graphRect, int majorSpacing, D2dBrush lineBrush) { double xScale = transform.Elements[0]; RectangleF clientRect = Transform(transform, graphRect); double min = Math.Min(graphRect.Left, graphRect.Right); double max = Math.Max(graphRect.Left, graphRect.Right); double tickAnchor = CalculateTickAnchor(min, max); double step = CalculateStep(min, max, Math.Abs(clientRect.Right - clientRect.Left), majorSpacing, 0.0); if (step > 0) { double offset = tickAnchor - min; offset = offset - MathUtil.Remainder(offset, step) + step; for (double x = tickAnchor - offset; x <= max; x += step) { double cx = (x - graphRect.Left) * xScale + clientRect.Left; g.DrawLine((float)cx, clientRect.Top, (float)cx, clientRect.Bottom, lineBrush); } } }
/// <summary> /// Draws a pin button, which looks like a square with /// a dash (expanded) or a cross (unexpanded).</summary> /// <param name="x">X coordinate of pin top left corner</param> /// <param name="y">Y coordinate of pin top left corner</param> /// <param name="pinned">Whether or not pin should appear "pinned"</param> /// <param name="toLeft">Whether pin points left or right</param> /// <param name="pen">Pen, should be 1 pixel wide</param> /// <param name="g">Graphics object</param> public static void DrawPin(int x, int y, bool pinned, bool toLeft, D2dBrush pen, D2dGraphics g) { if (toLeft) { DrawLeftPin(x, y, ThumbtackSize, pen, pinned, g); } else { DrawRightPin(x, y, ThumbtackSize, pen, pinned, g); } }
/// <summary> /// Draws a tree-control style expander, which looks like a square with /// a dash (expanded) or a cross (unexpanded)</summary> /// <param name="g">The Direct2D graphics object</param> /// <param name="x">X coordinate of expander top left corner</param> /// <param name="y">Y coordinate of expander top left corner</param> /// <param name="size">Size of expander, in pixels</param> /// <param name="brush">Brush</param> /// <param name="expanded">Whether or not expander should appear "expanded"</param> public static void DrawExpander(this D2dGraphics g, float x, float y, float size, D2dBrush brush, bool expanded) { s_expanderPoints[0] = new PointF(x, y + size); if (expanded) { s_expanderPoints[1] = new PointF(x + size, y + size); s_expanderPoints[2] = new PointF(x + size, y); g.FillPolygon(s_expanderPoints, brush); } else { s_expanderPoints[1] = new PointF(x + size, y + size / 2); s_expanderPoints[2] = new PointF(x, y); g.DrawPolygon(s_expanderPoints, brush, 1.0f); } }
/// <summary> /// Draws the eye icon</summary> /// <param name="g">The D2dGraphics graphics object</param> /// <param name="rect">The rectangle to fit the eye icon in</param> /// <param name="pen">The pen used to draw the icon</param> /// <param name="strokeWidth">Width of the stroke</param> public static void DrawEyeIcon(this D2dGraphics g, RectangleF rect, D2dBrush pen, float strokeWidth) { float delta = rect.Width / 3; var p1 = new PointF(rect.X, rect.Y + rect.Height / 2); var p2 = new PointF(p1.X + delta, rect.Y); var p3 = new PointF(p1.X + 2 * delta, rect.Y); var p4 = new PointF(rect.X + rect.Width, rect.Y + rect.Height / 2); g.DrawBezier(p1, p2, p3, p4, pen, strokeWidth);// top lid p2 = new PointF(p2.X, rect.Y + rect.Height); p3 = new PointF(p3.X, rect.Y + rect.Height); g.DrawBezier(p1, p2, p3, p4, pen, strokeWidth); //bottom lid var irisCenter = new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); float irisRadius = 0.2f * Math.Min(rect.Width, rect.Height); var irisRect = new RectangleF(irisCenter.X - irisRadius, irisCenter.Y - irisRadius, 2 * irisRadius, 2 * irisRadius); g.DrawEllipse(irisRect, pen, strokeWidth * 1.8f); }
/// <summary> /// Draws a tree-control style expander, which looks like a square with /// a dash (expanded) or a cross (unexpanded)</summary> /// <param name="g">The Direct2D graphics object</param> /// <param name="x">X coordinate of expander top left corner</param> /// <param name="y">Y coordinate of expander top left corner</param> /// <param name="size">Size of expander, in pixels</param> /// <param name="brush">Brush</param> /// <param name="expanded">Whether or not expander should appear "expanded"</param> public static void DrawExpander(this D2dGraphics g, float x, float y, float size, D2dBrush brush, bool expanded) { s_expanderPoints[0] = new PointF(x, y + size); if (expanded) { s_expanderPoints[1] = new PointF(x + size, y + size); s_expanderPoints[2] = new PointF(x + size, y); g.FillPolygon(s_expanderPoints, brush); } else { s_expanderPoints[1] = new PointF(x + size, y + size / 2); s_expanderPoints[2] = new PointF(x, y); g.DrawPolygon(s_expanderPoints, brush, 1.0f); } //g.DrawRectangle(new RectangleF(x, y, size, size), brush); //float lineLength = size - 4; //float center = size / 2; //g.DrawLine(x + 2, y + center, x + 2 + lineLength, y + center, brush); //if (!expanded) // g.DrawLine(x + center, y + 2, x + center, y + 2 + lineLength, brush); }
/// <summary> /// Paints the interior of the specified ellipse</summary> /// <param name="rect">The rectangle, in pixels, that encloses the ellipse to paint</param> /// <param name="brush">The brush used to paint the interior of the ellipse</param> public void FillEllipse(RectangleF rect, D2dBrush brush) { var tmpEllipse = new Ellipse { RadiusX = rect.Width * 0.5f, RadiusY = rect.Height * 0.5f }; tmpEllipse.Point = new Vector2(rect.X + tmpEllipse.RadiusX, rect.Y + tmpEllipse.RadiusY); m_renderTarget.FillEllipse(tmpEllipse, brush.NativeBrush); }
/// <summary> /// Draws a geometry previosly defined</summary> /// <param name="geometry">The geometry to draw</param> /// <param name="brush">The brush used to paint the geometry's stroke</param> /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param> /// <param name="strokeStyle">The style of the geometry's stroke, or null to paint a solid stroke</param> public void DrawGeometry(D2dGeometry geometry, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { m_renderTarget.DrawGeometry(geometry.NativeGeometry, brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); }
/// <summary> /// Draws the formatted text described by the specified D2dTextLayout</summary> /// <param name="origin">The point, described in pixels, at which the upper-left /// corner of the text described by textLayout is drawn</param> /// <param name="textLayout">The formatted text to draw</param> /// <param name="brush">The brush used to paint any text in textLayout /// that does not already have a brush associated with it as a drawing effect</param> public void DrawTextLayout(PointF origin, D2dTextLayout textLayout, D2dBrush brush) { m_renderTarget.DrawTextLayout( origin.ToSharpDX(), textLayout.NativeTextLayout, brush.NativeBrush, (DrawTextOptions)textLayout.DrawTextOptions); }
/// <summary> /// Draws a horizontal chart scale</summary> /// <param name="g">The Direct2D graphics object</param> /// <param name="transform">Graph (world) to window's client (screen) transform</param> /// <param name="graphRect">Graph rectangle</param> /// <param name="top">Whether or not the scale should be aligned along the top of the rectangle</param> /// <param name="majorSpacing">Spacing, in pixels, between major tick marks</param> /// <param name="minimumGraphStep">Minimum spacing, in graph (world) space, between ticks. /// For example, 1.0 would limit ticks to being drawn on whole integers.</param> /// <param name="lineBrush">Scale line pen</param> /// <param name="textFormat">Text format</param> /// <param name="textBrush">Text brush</param> public static void DrawHorizontalScale( this D2dGraphics g, Matrix transform, RectangleF graphRect, bool top, int majorSpacing, float minimumGraphStep, D2dBrush lineBrush, D2dTextFormat textFormat, D2dBrush textBrush) { double xScale = transform.Elements[0]; RectangleF clientRect = Transform(transform, graphRect); double tickEnd, majorTickStart, minorTickStart, textStart; if (top) { tickEnd = clientRect.Top + 1; majorTickStart = tickEnd + 12; minorTickStart = tickEnd + 6; textStart = tickEnd + 8; } else { tickEnd = clientRect.Bottom - 1; majorTickStart = tickEnd - 12; minorTickStart = tickEnd - 6; textStart = tickEnd - 19; } double min = Math.Min(graphRect.Left, graphRect.Right); double max = Math.Max(graphRect.Left, graphRect.Right); double tickAnchor = CalculateTickAnchor(min, max); double majorGraphStep = CalculateStep( min, max, Math.Abs(clientRect.Right - clientRect.Left), majorSpacing, minimumGraphStep); int numMinorTicks = CalculateNumMinorTicks(majorGraphStep, minimumGraphStep, 5); double cMinorStep = (majorGraphStep / numMinorTicks) * xScale; if (majorGraphStep > 0) { double offset = tickAnchor - min; offset = offset - MathUtil.Remainder(offset, majorGraphStep); // draw leading minor ticks double cmx; cmx = ((tickAnchor - (offset + majorGraphStep)) - min) * xScale + clientRect.Left + cMinorStep; for (int i = 0; i < numMinorTicks - 1 && cmx < clientRect.Right; i++) { // cull minor ticks outside of the view if (cmx > clientRect.Left) { g.DrawLine((float)cmx, (float)minorTickStart, (float)cmx, (float)tickEnd, lineBrush); } cmx += cMinorStep; } for (double x = tickAnchor - offset; x < max; x += majorGraphStep) { double cx = (x - min) * xScale + clientRect.Left; g.DrawLine((float)cx, (float)majorTickStart, (float)cx, (float)tickEnd, lineBrush); string xString = String.Format("{0:G8}", Math.Round(x, 6)); SizeF textSize = g.MeasureText(xString, textFormat); var textRect = new RectangleF(new PointF((float)cx + 1, (float)textStart), textSize); g.DrawText(xString, textFormat, textRect, textBrush); // draw minor ticks cmx = cx + cMinorStep; for (int i = 0; i < numMinorTicks - 1 && cmx < clientRect.Right; i++) { g.DrawLine((float)cmx, (float)minorTickStart, (float)cmx, (float)tickEnd, lineBrush); cmx += cMinorStep; } } } }
/// <summary> /// Fills the interior of a polygon defined by given points</summary> /// <param name="points">Array of PointF structures that represent the vertices of /// the polygon to fill</param> /// <param name="brush">Brush that determines the characteristics of the fill</param> public void FillPolygon(IEnumerable<PointF> points, D2dBrush brush) { var iter = points.GetEnumerator(); if (!iter.MoveNext()) return; using (var geom = new PathGeometry(D2dFactory.NativeFactory)) { var sink = geom.Open(); var pt1 = iter.Current; sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Filled); while (iter.MoveNext()) { sink.AddLine(iter.Current.ToSharpDX()); } sink.EndFigure(FigureEnd.Closed); sink.Close(); sink.Dispose(); m_renderTarget.FillGeometry(geom, brush.NativeBrush); } }
/// <summary> /// Paints the interior of the specified rounded rectangle</summary> /// <param name="roundedRect">The dimensions of the rounded rectangle to paint, in pixels</param> /// <param name="brush">The brush used to paint the interior of the rounded rectangle</param> public void FillRoundedRectangle(D2dRoundedRect roundedRect, D2dBrush brush) { var tmp = roundedRect.ToSharpDX(); m_renderTarget.FillRoundedRectangle(ref tmp, brush.NativeBrush); }
/// <summary> /// Draws a line between the specified points</summary> /// <param name="pt1X">The starting x-coordinate of the line, in pixels</param> /// <param name="pt1Y">The starting y-coordinate of the line, in pixels</param> /// <param name="pt2X">The ending x-coordinate of the line, in pixels</param> /// <param name="pt2Y">The ending y-coordinate of the line, in pixels</param> /// <param name="brush">The brush used to paint the line's stroke</param> /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param> /// <param name="strokeStyle">The style of stroke to paint, or null to paint a solid line</param> public void DrawLine(float pt1X, float pt1Y, float pt2X, float pt2Y, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { m_renderTarget.DrawLine( new Vector2(pt1X, pt1Y), new Vector2(pt2X, pt2Y), brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); }
/// <summary> /// Draws a line between the specified points</summary> /// <param name="pt1">The start point of the line, in pixels</param> /// <param name="pt2">The end point of the line, in pixels</param> /// <param name="brush">The brush used to paint the line's stroke</param> /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param> /// <param name="strokeStyle">The style of stroke to paint, or NULL to paint a solid line</param> public void DrawLine(PointF pt1, PointF pt2, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { m_renderTarget.DrawLine(pt1.ToSharpDX(), pt2.ToSharpDX(), brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); }
/// <summary> /// Draws the outline of the specified ellipse</summary> /// <param name="rect">The rectangle, in pixels, that encloses the ellipse to paint</param> /// <param name="brush">The brush used to paint the ellipse's outline</param> /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline.</param> /// <param name="strokeStyle">The style of stroke to apply to the ellipse's outline or null to draw a solid line</param> public void DrawEllipse(RectangleF rect, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { var tmpEllipse = new Ellipse(); tmpEllipse.RadiusX = rect.Width * 0.5f; tmpEllipse.RadiusY = rect.Height * 0.5f; tmpEllipse.Point = new Vector2(rect.X + tmpEllipse.RadiusX, rect.Y + tmpEllipse.RadiusY); m_renderTarget.DrawEllipse(tmpEllipse, brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); }
/// <summary> /// Draws the outline of the specified ellipse using the specified stroke style</summary> /// <param name="ellipse">Position and radius of the ellipse to draw in pixels</param> /// <param name="brush">The brush used to paint the ellipse's outline</param> /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline.</param> /// <param name="strokeStyle">The style of stroke to apply to the ellipse's outline or null to draw a solid line</param> public void DrawEllipse(D2dEllipse ellipse, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { m_renderTarget.DrawEllipse(ellipse.ToSharpDX(), brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); }
/// <summary> /// Draws a Bézier spline defined by four System.Drawing.PointF structures</summary> /// <param name="pt1">Represents the starting point of the curve</param> /// <param name="pt2">Represents the first control point for the curve</param> /// <param name="pt3">Represents the second control point for the curve</param> /// <param name="pt4">Represents the ending point of the curve</param> /// <param name="brush">The brush used to paint the curve's stroke</param> /// <param name="strokeWidth">The thickness of the geometry's stroke. The stroke is centered on the geometry's outline.</param> /// <param name="strokeStyle">The style of stroke to apply to the geometry's outline or null to draw a solid line</param> public void DrawBezier(PointF pt1, PointF pt2, PointF pt3, PointF pt4, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { using (var geom = new PathGeometry(D2dFactory.NativeFactory)) { var sink = geom.Open(); sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Hollow); var seg = new BezierSegment { Point1 = pt2.ToSharpDX(), Point2 = pt3.ToSharpDX(), Point3 = pt4.ToSharpDX() }; sink.AddBezier(seg); sink.EndFigure(FigureEnd.Open); sink.Close(); sink.Dispose(); var stroke = strokeStyle == null ? null : strokeStyle.NativeStrokeStyle; m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth, stroke); } }
/// <summary> /// Draws an arc representing a portion of an ellipse specified by a D2dEllipse</summary> /// <param name="ellipse">Ellipse to draw</param> /// <param name="brush">The brush used to paint the arc's outline</param> /// <param name="startAngle">Starting angle in degrees measured clockwise from the x-axis /// to the starting point of the arc</param> /// <param name="sweepAngle">Sweep angle in degrees measured clockwise from the startAngle /// parameter to ending point of the arc</param> /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered /// on the ellipse's outline.</param> /// <param name="strokeStyle">The style of stroke to apply to the arc's outline or null to draw a solid line</param> public void DrawArc(D2dEllipse ellipse, D2dBrush brush, float startAngle, float sweepAngle, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { // compute steps float step = Tessellation / m_scale.X; float angle1 = startAngle * ToRadian; float angle2 = (startAngle + sweepAngle) * ToRadian; if (angle1 > angle2) { float temp = angle1; angle1 = angle2; angle2 = temp; } float cx = ellipse.Center.X; float cy = ellipse.Center.Y; var v1 = new Vec2F(); v1.X = ellipse.RadiusX * (float)Math.Cos(angle1); v1.Y = ellipse.RadiusY * (float)Math.Sin(angle1); var v2 = new Vec2F(); v2.X = ellipse.RadiusX * (float)Math.Cos(angle2); v2.Y = ellipse.RadiusY * (float)Math.Sin(angle2); float arcLen = (v2 - v1).Length; // approx arc len. float numSegs = arcLen / step; float dtheta = (angle2 - angle1) / numSegs; m_tempPoints.Clear(); for (float theta = angle1; theta < angle2; theta += dtheta) { var pt = new PointF(); pt.X = cx + ellipse.RadiusX * (float)Math.Cos(theta); pt.Y = cy + ellipse.RadiusY * (float)Math.Sin(theta); m_tempPoints.Add(pt); } DrawLines(m_tempPoints, brush, strokeWidth, strokeStyle); }
/// <summary> /// Draws a geometry previosly defined</summary> /// <param name="geometry">The geometry to draw</param> /// <param name="brush">The brush used to fill.</param> public void FillGeometry(D2dGeometry geometry, D2dBrush brush) { m_renderTarget.FillGeometry(geometry.NativeGeometry, brush.NativeBrush); }
/// <summary> /// Paints the interior of the specified ellipse</summary> /// <param name="ellipse">The position and radius, in pixels, of the ellipse to paint</param> /// <param name="brush">The brush used to paint the interior of the ellipse</param> public void FillEllipse(D2dEllipse ellipse, D2dBrush brush) { m_renderTarget.FillEllipse(ellipse.ToSharpDX(), brush.NativeBrush); }
/// <summary> /// Draws a pin button, which looks like a square with /// a dash (expanded) or a cross (unexpanded).</summary> /// <param name="x">X coordinate of pin top left corner</param> /// <param name="y">Y coordinate of pin top left corner</param> /// <param name="pinned">Whether or not pin should appear "pinned"</param> /// <param name="toLeft">Whether pin points left or right</param> /// <param name="pen">Pen, should be 1 pixel wide</param> /// <param name="g">Graphics object</param> public static void DrawPin(int x, int y, bool pinned, bool toLeft, D2dBrush pen, D2dGraphics g) { if (toLeft) DrawLeftPin(x, y, ThumbtackSize, pen, pinned, g); else DrawRightPin(x, y, ThumbtackSize, pen, pinned, g); }
/// <summary> /// Draws a solid rectangle with the specified brush while using the alpha channel of the given /// bitmap to control the opacity of each pixel.</summary> /// <param name="opacityMask">The opacity mask to apply to the brush. The alpha value of /// each pixel in the region specified by sourceRectangle is multiplied with the alpha value /// of the brush after the brush has been mapped to the area defined by destinationRectangle.</param> /// <param name="brush">The brush used to paint the region of the render target specified by destinationRectangle.</param> /// <param name="destRect">The region of the render target to paint, in device-independent pixels.</param> /// <param name="sourceRect">The region of the bitmap to use as the opacity mask, in device-independent pixels.</param> public void FillOpacityMask(D2dBitmap opacityMask, D2dBrush brush, RectangleF destRect, RectangleF sourceRect) { m_renderTarget.FillOpacityMask(opacityMask.NativeBitmap, brush.NativeBrush, OpacityMaskContent.Graphics, destRect.ToSharpDX(), sourceRect.ToSharpDX()); }
/// <summary> /// Draws an icon that indicates a linked (referenced) item</summary> /// <param name="g">The Direct2D graphics object</param> /// <param name="x">X coordinate of icon top left corner</param> /// <param name="y">Y coordinate of icon top left corner</param> /// <param name="size">Size of expander, in pixels</param> /// <param name="brush">Brush</param> public static void DrawLink(this D2dGraphics g, float x, float y, float size, D2dBrush brush) { var path = new EdgeStyleData[5]; var pathData = new PointF[16]; for (int i = 0; i < 16; ++i) { pathData[i] = new PointF(s_unitCurvedArrowData[i].X * size + x, s_unitCurvedArrowData[i].Y * size + y); } var edgeData = new EdgeStyleData { ShapeType = EdgeStyleData.EdgeShape.Line, EdgeData = new PointF[] { pathData[0], pathData[1], pathData[2], pathData[3] } }; path[0] = edgeData; edgeData = new EdgeStyleData { ShapeType = EdgeStyleData.EdgeShape.Bezier, EdgeData = new BezierCurve2F(pathData[3], pathData[4], pathData[5], pathData[6]) }; path[1] = edgeData; edgeData = new EdgeStyleData { ShapeType = EdgeStyleData.EdgeShape.Bezier, EdgeData = new BezierCurve2F(pathData[6], pathData[7], pathData[8], pathData[9]) }; path[2] = edgeData; edgeData = new EdgeStyleData { ShapeType = EdgeStyleData.EdgeShape.Bezier, EdgeData = new BezierCurve2F(pathData[9], pathData[10], pathData[11], pathData[12]) }; path[3] = edgeData; edgeData = new EdgeStyleData { ShapeType = EdgeStyleData.EdgeShape.Bezier, EdgeData = new BezierCurve2F(pathData[12], pathData[13], pathData[14], pathData[15]) }; path[4] = edgeData; g.FillPath(path, brush); }
/// <summary> /// Paints the interior of the specified rectangle</summary> /// <param name="rect">Rectangle to paint, in pixels</param> /// <param name="brush">The brush used to paint the rectangle's interior</param> public void FillRectangle(RectangleF rect, D2dBrush brush) { m_renderTarget.FillRectangle(rect.ToSharpDX(), brush.NativeBrush); }
/// <summary> /// Paints the interior of the specified rounded rectangle</summary> /// <param name="roundedRect">The dimensions of the rounded rectangle to paint, in pixels</param> /// <param name="brush">The brush used to paint the interior of the rounded rectangle</param> public void FillRoundedRectangle(D2dRoundedRect roundedRect, D2dBrush brush) { var tmp = new RoundedRectangle(); tmp.RadiusX = roundedRect.RadiusX; tmp.RadiusY = roundedRect.RadiusY; var r = new SharpDX.RectangleF( roundedRect.Rect.Left, roundedRect.Rect.Top, roundedRect.Rect.Right, roundedRect.Rect.Bottom); tmp.Rect = r; m_renderTarget.FillRoundedRectangle(ref tmp, brush.NativeBrush); }
/// <summary> /// Draws a path defined by an enumeration of EdgeStyleData structures</summary> /// <param name="path">The enumeration of drawing primitives that describes the contents of the path</param> /// <param name="brush">The brush used to paint the path's stroke</param> /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param> /// <remarks>Assume the end point of one primitive be coincident with the start point of the following primitive in a path</remarks> /// <param name="strokeStyle">The style of the rounded rectangle's stroke, or null to paint a solid stroke</param> public void DrawPath(IEnumerable<EdgeStyleData> path, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { using (var geom = new PathGeometry(D2dFactory.NativeFactory)) { var sink = geom.Open(); var firstPoint = true; foreach (var edge in path) { if (edge.ShapeType == EdgeStyleData.EdgeShape.Line) { var line = edge.EdgeData.As<PointF[]>(); if (firstPoint) { sink.BeginFigure(line[0].ToSharpDX(), FigureBegin.Hollow); firstPoint = false; } for (var i = 1; i < line.Length; ++i) sink.AddLine(line[i].ToSharpDX()); } else if (edge.ShapeType == EdgeStyleData.EdgeShape.Bezier) { var curve = edge.EdgeData.As<BezierCurve2F>(); if (firstPoint) { sink.BeginFigure(curve.P1.ToSharpDX(), FigureBegin.Hollow); firstPoint = false; } var seg = new BezierSegment { Point1 = curve.P2.ToSharpDX(), Point2 = curve.P3.ToSharpDX(), Point3 = curve.P4.ToSharpDX() }; sink.AddBezier(seg); } } sink.EndFigure(FigureEnd.Open); sink.Close(); sink.Dispose(); m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); } }
/// <summary> /// Draws the specified text using the format information provided at the specified location</summary> /// <param name="text">The text string to draw</param> /// <param name="textFormat">The text format object to use</param> /// <param name="upperLeft">Upper left corner of the text</param> /// <param name="brush">The brush to use to draw the text</param> public void DrawText(string text, D2dTextFormat textFormat, PointF upperLeft, D2dBrush brush) { var rtsize = Size; using (var layout = new SharpDX.DirectWrite.TextLayout(D2dFactory.NativeDwFactory, text, textFormat.NativeTextFormat, rtsize.Width, rtsize.Height)) { layout.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading; layout.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near; if (textFormat.Underlined) layout.SetUnderline(true,new SharpDX.DirectWrite.TextRange(0, text.Length)); if (textFormat.Strikeout) layout.SetStrikethrough(true,new SharpDX.DirectWrite.TextRange(0, text.Length)); m_renderTarget.DrawTextLayout(upperLeft.ToSharpDX(), layout, brush.NativeBrush, (DrawTextOptions)textFormat.DrawTextOptions); } }
/// <summary> /// Draws the specified text using the format information provided by an SharpDX.DirectWrite.TextFormat object</summary> /// <param name="text">A string to draw</param> /// <param name="textFormat">An object that describes formatting details of the text to draw, such as /// the font, the font size, and flow direction</param> /// <param name="layoutRect">The size and position of the area in which the text is drawn</param> /// <param name="brush">The brush used to paint the text</param> public void DrawText(string text, D2dTextFormat textFormat, RectangleF layoutRect, D2dBrush brush) { using (var layout = new SharpDX.DirectWrite.TextLayout(D2dFactory.NativeDwFactory, text, textFormat.NativeTextFormat, layoutRect.Width, layoutRect.Height)) { if (textFormat.Underlined) layout.SetUnderline(true, new SharpDX.DirectWrite.TextRange(0, text.Length)); if (textFormat.Strikeout) layout.SetStrikethrough(true, new SharpDX.DirectWrite.TextRange(0, text.Length)); m_renderTarget.DrawTextLayout( layoutRect.Location.ToSharpDX(), layout, brush.NativeBrush, (DrawTextOptions)textFormat.DrawTextOptions); } }
/// <summary> /// Draws a series of line segments that connect an array of System.Drawing.PointF</summary> /// <param name="points">Array of PointF that represent the points to connect</param> /// <param name="brush">The brush used to paint the line's stroke</param> /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param> /// <param name="strokeStyle">The style of stroke to paint, or NULL to paint a solid line</param> public void DrawLines(IEnumerable<PointF> points, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { var iter = points.GetEnumerator(); if (!iter.MoveNext()) return; var transparent = brush.Opacity < 1.0f; if (!transparent) { var sbrush = brush as D2dSolidColorBrush; if (sbrush != null) transparent = sbrush.Color.A < 255; } var nstroke = (strokeStyle ?? s_strokeStyle).NativeStrokeStyle; if (transparent) { using (var geom = new PathGeometry(D2dFactory.NativeFactory)) { var sink = geom.Open(); var pt1 = iter.Current; sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Hollow); while (iter.MoveNext()) { sink.AddLine(iter.Current.ToSharpDX()); } sink.EndFigure(FigureEnd.Open); sink.Close(); sink.Dispose(); m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth, nstroke); } } else { var nbrush = brush.NativeBrush; var pt1 = iter.Current; while (iter.MoveNext()) { var pt2 = iter.Current; m_renderTarget.DrawLine(pt1.ToSharpDX(), pt2.ToSharpDX(), nbrush, strokeWidth, nstroke); pt1 = pt2; } } }
/// <summary> /// Draws a polygon defined by an array of PointF structures</summary> /// <param name="points">Array of System.Drawing.PointF structures /// that represent the vertices of the polygon</param> /// <param name="brush">The brush used to paint the polygon's stroke</param> /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param> /// <param name="strokeStyle">The style of stroke to paint, or NULL to paint a solid line</param> public void DrawPolygon(IEnumerable<PointF> points, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { var iter = points.GetEnumerator(); if (!iter.MoveNext()) return; using (var geom = new PathGeometry(D2dFactory.NativeFactory)) { var sink = geom.Open(); var pt1 = iter.Current; sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Hollow); while (iter.MoveNext()) { sink.AddLine(iter.Current.ToSharpDX()); } sink.EndFigure(FigureEnd.Closed); sink.Close(); sink.Dispose(); m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); } }
/// <summary> /// Draws the outline of the specified rounded rectangle</summary> /// <param name="roundedRect">The dimensions of the rounded rectangle to draw, in pixels</param> /// <param name="brush">The brush used to paint the rounded rectangle's outline</param> /// <param name="strokeWidth">The width of the rounded rectangle's stroke. The stroke is centered on the /// rounded rectangle's outline.</param> /// <param name="strokeStyle">The style of the rounded rectangle's stroke, or null to paint a solid stroke</param> public void DrawRoundedRectangle(D2dRoundedRect roundedRect, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { m_renderTarget.DrawRoundedRectangle(roundedRect.ToSharpDX(), brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); }