/// <summary> /// convert D2dRoundedRect to SharpDX.RoundedRectangle.</summary> internal static RoundedRectangle ToSharpDX(this D2dRoundedRect rec) { return(new RoundedRectangle { RadiusX = rec.RadiusX, RadiusY = rec.RadiusY, Rect = rec.Rect.ToSharpDX() }); }
/// <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="color">The color used to paint the interior of the rounded rectangle</param> public void FillRoundedRectangle(D2dRoundedRect roundedRect, Color color) { m_solidColorBrush.Color = color; FillRoundedRectangle(roundedRect, m_solidColorBrush); }
/// <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 the outline of the specified rounded rectangle</summary> /// <param name="roundedRect">The dimensions of the rounded rectangle to draw, in pixels</param> /// <param name="color">The color used to paint the rounded rectangle's stroke</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, Color color, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null) { m_solidColorBrush.Color = color; DrawRoundedRectangle(roundedRect, m_solidColorBrush, strokeWidth, strokeStyle); }
/// <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); }
private void GenPrimitives() { SizeF csize = m_d2dGraphics.Size; Random r = new Random(7737); int w = (int)csize.Width; int h = (int)csize.Height; if (m_sampleDrawing == SampleDrawings.DrawFewStates) { m_drawInfo = "draw few states"; } else if (m_sampleDrawing == SampleDrawings.FillSolidRects || m_sampleDrawing == SampleDrawings.FillGradientRects1 || m_sampleDrawing == SampleDrawings.FillGradientRects2 || m_sampleDrawing == SampleDrawings.FillGradientRects3 || m_sampleDrawing == SampleDrawings.DrawRects || m_sampleDrawing == SampleDrawings.DrawRectsWithBitmapMasks || m_sampleDrawing == SampleDrawings.FillBmpRects) { int itemCount = 500; m_rects.Clear(); for (int i = 0; i < itemCount; i++) { float cx = r.Next(-40, w); float cy = r.Next(-40, h); float width = r.Next(20, 140); float height = r.Next(20, 140); RectangleF rect = new RectangleF(cx, cy, width, height); m_rects.Add(rect); } if (m_sampleDrawing == SampleDrawings.FillSolidRects) m_drawInfo = string.Format("Fill {0} solid rectangles", itemCount); else if (m_sampleDrawing == SampleDrawings.FillGradientRects1 || m_sampleDrawing == SampleDrawings.FillGradientRects2 || m_sampleDrawing == SampleDrawings.FillGradientRects3) m_drawInfo = string.Format("Fill {0} gradient rectangles", itemCount); else if (m_sampleDrawing == SampleDrawings.FillBmpRects) m_drawInfo = string.Format("Fill {0} rectangles using bitmap brush", itemCount); else if (m_sampleDrawing == SampleDrawings.DrawRectsWithBitmapMasks) m_drawInfo = string.Format("Fill {0} rectangles using bitmap's alpha blending", itemCount); else m_drawInfo = string.Format("Draw {0} rectangles", itemCount); } else if (m_sampleDrawing == SampleDrawings.FillSolidRoundedRects || m_sampleDrawing == SampleDrawings.DrawRoundedRects) { int itemCount = 300; m_roundedRects.Clear(); for (int i = 0; i < itemCount; i++) { float cx = r.Next(-40, w); float cy = r.Next(-40, h); float width = r.Next(20, 140); float height = r.Next(20, 140); D2dRoundedRect roundRect = new D2dRoundedRect(); roundRect.Rect = new RectangleF(cx, cy, width, height); roundRect.RadiusX = 12; roundRect.RadiusY = 12; m_roundedRects.Add(roundRect); } if (m_sampleDrawing == SampleDrawings.FillSolidRoundedRects) m_drawInfo = string.Format("Fill {0} solid rounded rectangles", itemCount); else m_drawInfo = string.Format("Draw {0} rounded rectangles", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawRandomLines1 || m_sampleDrawing == SampleDrawings.DrawRandomLines2) { int itemCount = 2000; m_lines.Clear(); for (int i = 0; i < itemCount; i++) { PointF pt1 = new PointF(r.Next(w), r.Next(h)); //PointF pt2 = new PointF(pt1.X + r.Next(-20, 20), pt1.Y+r.Next(-20, 20)); PointF pt2 = new PointF(r.Next(w), r.Next(h)); m_lines.Add(new Line(pt1, pt2)); } if (m_sampleDrawing == SampleDrawings.DrawRandomLines1) m_drawInfo = string.Format("Draw {0} lines width = 1", itemCount); else m_drawInfo = string.Format("Draw {0} lines width = 2", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawConnectedLines) { int itemCount = 200; m_connectedLines.Clear(); for (int i = 0; i < itemCount; i++) { PointF pt = new PointF(r.Next(w), r.Next(h)); m_connectedLines.Add(pt); } m_drawInfo = string.Format("Draw {0} connected lines width = 2", itemCount - 1); } else if (m_sampleDrawing == SampleDrawings.FillSolidEllipse) { int itemCount = 300; m_ellipses.Clear(); for (int i = 0; i < itemCount; i++) { D2dEllipse elp = new D2dEllipse(); elp.Center = new PointF(r.Next(w), r.Next(h)); elp.RadiusX = r.Next(20, 120); elp.RadiusY = r.Next(20, 120); m_ellipses.Add(elp); } m_drawInfo = string.Format("Fill {0} solid ellipses", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawOrbs) { int itemCount = 60; m_ellipses.Clear(); for (int i = 0; i < itemCount; i++) { D2dEllipse elp = new D2dEllipse(); elp.Center = new PointF(r.Next(w), r.Next(h)); float rad = r.Next(60,120); elp.RadiusX = rad; elp.RadiusY = rad; m_ellipses.Add(elp); } m_drawInfo = string.Format("Render {0} Glass balls", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawEllipse) { int itemCount = 200; m_ellipses.Clear(); for (int i = 0; i < itemCount; i++) { int k = i + 10; D2dEllipse elp = new D2dEllipse(); elp.Center = new PointF(k + k / 2, k + k / 2); elp.RadiusX = k / 2; elp.RadiusY = k / 2; m_ellipses.Add(elp); } m_drawInfo = string.Format("Draw {0} ellipses", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawBeziers) { r = new Random(7737); int itemCount = 200; Bezier bz = new Bezier(); bz.P1 = new PointF(0, 0); bz.P2 = new PointF(20f, 25f); bz.P3 = new PointF(40f, -25f); bz.P4 = new PointF(60f, 25f); m_beziers.Clear(); for (int i = 0; i < itemCount; i++) { Bezier b = new Bezier(); SizeF sz = new SizeF(); sz.Width = r.Next(w); sz.Height = r.Next(h); b.P1 = bz.P1 + sz; b.P2 = bz.P2 + sz; b.P3 = bz.P3 + sz; b.P4 = bz.P4 + sz; m_beziers.Add(b); } m_drawInfo = string.Format("Draw {0} beziers", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawCachedBitmap) { m_drawInfo = "Draw of screen buffer (bitmap)"; } else if (m_sampleDrawing == SampleDrawings.DrawText) { r = new Random(7737); int itemCount = 200; m_texts.Clear(); for (int i = 0; i < itemCount; i++) { PointF pt = new PointF(r.Next(w), r.Next(h)); m_texts.Add(pt); } m_drawInfo = string.Format("Draw {0} text", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawTextLayout) { foreach (D2dTextLayout txtlayout in m_textLayouts) txtlayout.Dispose(); r = new Random(7737); int itemCount = 200; m_texts.Clear(); m_textLayouts.Clear(); for (int i = 0; i < itemCount; i++) { PointF pt = new PointF(r.Next(w), r.Next(h)); m_texts.Add(pt); D2dTextLayout txtLayout = D2dFactory.CreateTextLayout("Draw Text " + i, m_generalTextFormat); m_textLayouts.Add(txtLayout); } m_drawInfo = string.Format("Draw {0} text layout", itemCount); } else if (m_sampleDrawing == SampleDrawings.DrawBitmaps) { m_drawInfo = "Draw overlapping transparent bitmaps"; } else if (m_sampleDrawing == SampleDrawings.GdiInterOp) { m_drawInfo = "Gdi interop"; } else if (m_sampleDrawing == SampleDrawings.DrawTriangle) { m_drawInfo = "Fill and draw a triangle"; } m_fps = 0.0f; UpdateInfo(); }
/// <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 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) { var roundrect = new RoundedRectangle(); roundrect.RadiusX = roundedRect.RadiusX; roundrect.RadiusY = roundedRect.RadiusY; roundrect.Rect.Top = roundedRect.Rect.Top; roundrect.Rect.Left = roundedRect.Rect.Left; roundrect.Rect.Right = roundedRect.Rect.Right; roundrect.Rect.Bottom = roundedRect.Rect.Bottom; m_renderTarget.DrawRoundedRectangle(roundrect, brush.NativeBrush, strokeWidth, strokeStyle != null ? strokeStyle.NativeStrokeStyle : null); }