protected override void Draw() { RenderTarget.BeginDraw(); RenderTarget.Transform = Matrix3x2.Identity; Random random = new Random(); RenderTarget.Clear(new Color4(0.5f, 0.5f, 0.5f, 0.0f)); RenderTarget.AntialiasMode = AntialiasMode.Aliased; StrokeStyleProperties properties = new StrokeStyleProperties(); properties.LineJoin = LineJoin.MiterOrBevel; StrokeStyle strokeStyle = new StrokeStyle(RenderTarget.Factory, properties); foreach (DirectPath path in paths) { if (path.Geometry != null && path.Brush != null) { if (path is DirectPathScatter) { (path as DirectPathScatter).RenderScatterGeometry(RenderTarget); } else { if (path.QuickStrokeDash != QuickStrokeDash.None) { RenderTarget.DrawGeometry(path.Geometry, path.Brush, (float)path.StrokeThickness, strokeStyle); } } } } RenderTarget.EndDraw(); graphicsDeviceService10.CopyTextureAcross(); graphicsDeviceService10.Device.Flush(); }
public void RenderScatterGeometry(RenderTarget renderTarget) { double[] x = curve.X; double[] y = curve.Y; int length = x.Length; double xScale, xOffset, yScale, yOffset; xScale = graphToCanvas.Matrix.M11; xOffset = graphToCanvas.Matrix.OffsetX - this.xOffsetMarker; yScale = graphToCanvas.Matrix.M22; yOffset = graphToCanvas.Matrix.OffsetY - this.yOffsetMarker; bool[] include = curve.includeMarker; StrokeStyleProperties properties = new StrokeStyleProperties(); properties.LineJoin = LineJoin.MiterOrBevel; StrokeStyle strokeStyle = new StrokeStyle(renderTarget.Factory, properties); for (int i = 0; i < length; ++i) { if (include[i]) { renderTarget.Transform = (Matrix3x2)Matrix.Translation((float)(x[i] * xScale + xOffset), (float)(y[i] * yScale + yOffset), 0); renderTarget.FillGeometry(Geometry, FillBrush); renderTarget.DrawGeometry(Geometry, Brush, (float)StrokeThickness, strokeStyle); } } renderTarget.Transform = Matrix3x2.Identity; }
void MainWindow_Load(object sender, EventArgs e) { this._factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None); StrokeStyleProperties ssp = new StrokeStyleProperties(LineCapStyle.Round, LineCapStyle.Round, LineCapStyle.Round, LineJoin.Round, 10, DashStyle.Solid, 0); this._strokeStyle = this._factory.CreateStrokeStyle(ssp, null); this._renderTarget = this._factory.CreateWindowRenderTarget(this); this.Resize += new EventHandler(MainWindow_Resize); }
public virtual void Initialize(DeviceManager deviceManager) { TouchCapabilities = new Windows.Devices.Input.TouchCapabilities(); // Initialize a TextFormat textFormat = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }; textFormat2 = new TextFormat(deviceManager.FactoryDirectWrite, "Calibri", 20) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Center }; sceneColorBrush = new SolidColorBrush(deviceManager.ContextDirect2D, Color.Tomato); strokeProperties = new StrokeStyleProperties(); strokeProperties.StartCap = CapStyle.Round; strokeProperties.EndCap = CapStyle.Round; strokeProperties.LineJoin = LineJoin.Round; strokeStyle = new StrokeStyle(deviceManager.FactoryDirect2D, strokeProperties); }
/// <summary> /// Converts a pen to a Direct2D stroke style. /// </summary> /// <param name="pen">The pen to convert.</param> /// <param name="target">The render target.</param> /// <returns>The Direct2D brush.</returns> public static StrokeStyle ToDirect2DStrokeStyle(this Perspex.Media.Pen pen, SharpDX.Direct2D1.RenderTarget target) { var properties = new StrokeStyleProperties { DashStyle = DashStyle.Solid, MiterLimit = (float)pen.MiterLimit, LineJoin = pen.LineJoin.ToDirect2D(), StartCap = pen.StartLineCap.ToDirect2D(), EndCap = pen.EndLineCap.ToDirect2D(), DashCap = pen.DashCap.ToDirect2D() }; var dashes = new float[0]; if (pen.DashStyle?.Dashes != null && pen.DashStyle.Dashes.Count > 0) { properties.DashStyle = DashStyle.Custom; properties.DashOffset = (float)pen.DashStyle.Offset; dashes = pen.DashStyle?.Dashes.Select(x => (float)x).ToArray(); } return new StrokeStyle(target.Factory, properties, dashes); }
public static StrokeStyle ToSharpDXStrokeStyle(Factory factory, System.Drawing.Pen pen) { var sp = new StrokeStyleProperties { DashCap = (CapStyle) pen.DashCap, DashOffset = pen.DashOffset, DashStyle = (DashStyle) pen.DashStyle, StartCap = (CapStyle)pen.StartCap, EndCap = (CapStyle)pen.EndCap, LineJoin = (LineJoin)pen.LineJoin, MiterLimit = pen.MiterLimit, }; if (pen.DashStyle == System.Drawing.Drawing2D.DashStyle.Custom) return new StrokeStyle(factory, sp, pen.DashPattern); return new StrokeStyle(factory, sp); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.StrokeStyle"/> that describes start cap, dash pattern, and other features of a stroke. /// </summary> /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory" /></param> /// <param name="properties">A structure that describes the stroke's line cap, dash offset, and other details of a stroke.</param> /// <param name="dashes">An array whose elements are set to the length of each dash and space in the dash pattern. The first element sets the length of a dash, the second element sets the length of a space, the third element sets the length of a dash, and so on. The length of each dash and space in the dash pattern is the product of the element value in the array and the stroke width. </param> public StrokeStyle(Factory factory, StrokeStyleProperties properties, float[] dashes) : base(IntPtr.Zero) { factory.CreateStrokeStyle(ref properties, dashes, dashes.Length, this); }
/// <summary> /// Creates an <see cref="SharpDX.Direct2D1.StrokeStyle"/> that describes start cap, dash pattern, and other features of a stroke. /// </summary> /// <param name="factory">an instance of <see cref = "SharpDX.Direct2D1.Factory" /></param> /// <param name="properties">a definition for this render target</param> public StrokeStyle(Factory factory, StrokeStyleProperties properties) : base(IntPtr.Zero) { factory.CreateStrokeStyle(ref properties, null, 0, this); }
/// <summary> /// Converts a pen to a Direct2D stroke style. /// </summary> /// <param name="pen">The pen to convert.</param> /// <param name="target">The render target.</param> /// <returns>The Direct2D brush.</returns> public static StrokeStyle ToDirect2DStrokeStyle(this Perspex.Media.Pen pen, RenderTarget target) { if (pen.DashArray != null && pen.DashArray.Count > 0) { var properties = new StrokeStyleProperties { DashStyle = DashStyle.Custom, }; return new StrokeStyle(target.Factory, properties, pen.DashArray.Select(x => (float)x).ToArray()); } else { return null; } }
private void ReconfigureStrokeStyle() { _StrokeStyle.SafeDispose(); StrokeStyleProperties newStyle = new StrokeStyleProperties { LineJoin = ActiveStrokeJoin.ToDirectWrite(), MiterLimit = ActiveMiterLimit, DashCap = ActiveDashCap.ToDirectWrite(), EndCap = ActiveStrokeCap.ToDirectWrite(), StartCap = ActiveStrokeCap.ToDirectWrite(), DashStyle = ActiveLineStyle.ToDirectWrite() }; _StrokeStyle = new StrokeStyle(_Factory2D, newStyle, new float[0]); }
/// <summary> /// Converts a pen to a Direct2D stroke style. /// </summary> /// <param name="pen">The pen to convert.</param> /// <param name="target">The render target.</param> /// <returns>The Direct2D brush.</returns> public static StrokeStyle ToDirect2DStrokeStyle(this Perspex.Media.Pen pen, RenderTarget target) { if (pen.DashStyle != null) { if (pen.DashStyle.Dashes != null && pen.DashStyle.Dashes.Count > 0) { var properties = new StrokeStyleProperties { DashStyle = DashStyle.Custom, DashOffset = (float)pen.DashStyle.Offset, MiterLimit = (float)pen.MiterLimit, LineJoin = pen.LineJoin.ToDirect2D(), StartCap = pen.StartLineCap.ToDirect2D(), EndCap = pen.EndLineCap.ToDirect2D(), DashCap = pen.DashCap.ToDirect2D() }; return new StrokeStyle(target.Factory, properties, pen.DashStyle?.Dashes.Select(x => (float)x).ToArray()); } } return null; }
protected internal StrokeStyle RandomStrokeStyle() { var strokeStyleProperties = new StrokeStyleProperties( RandomCapStyle(), RandomCapStyle(), RandomCapStyle(), RandomLineJoin(), 1.0f + 2.0f * (float)Random.NextDouble(), RandomDashStyle(), 5.0f * (float)Random.NextDouble()); if (strokeStyleProperties.DashStyle == DashStyle.Custom) return d2DFactory.CreateStrokeStyle(strokeStyleProperties, RandomDashes()); else return d2DFactory.CreateStrokeStyle(strokeStyleProperties); }