public void SetColor(System.Drawing.Color color) { if (textBrush != null) { textBrush.Dispose(); } textBrush = new SolidColorBrush(d2dContext, new RawColor4(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255)); }
public override void Draw(RenderTarget target) { if (this.points.Count >= 4) { SolidColorBrush curveBrush = new SolidColorBrush(target, this.LineColor); PathGeometry geometry = new PathGeometry(target.Factory); GeometrySink gs = geometry.Open(); gs.BeginFigure(this.points[0], FigureBegin.Filled); for (int i = 0; i < this.points.Count - 3; i += 2) { float a = 0; float b = 1; float h = (b - a) / this.resolution; float t = a; RawVector2 P0, P1; P0 = MathHelper.Interpolate(t, this.points[i], this.points[i + 1], this.points[i + 2], this.points[i + 3]); while (t < b) { t += h; P1 = MathHelper.Interpolate(t, this.points[i], this.points[i + 1], this.points[i + 2], this.points[i + 3]); // target.DrawLine(P0, P1, curveBrush); gs.AddLine(P0); gs.AddLine(P1); P0 = P1; } } if (this.Closed) { this.Close(target, gs); gs.EndFigure(FigureEnd.Closed); gs.Close(); if (this.Filled) { SolidColorBrush fillBrush = new SolidColorBrush(target, this.FillColor); target.FillGeometry(geometry, fillBrush); fillBrush.Dispose(); } } else { gs.EndFigure(FigureEnd.Open); gs.Close(); } target.DrawGeometry(geometry, curveBrush, this.LineThickness); gs.Dispose(); geometry.Dispose(); curveBrush.Dispose(); } base.Draw(target); }
public void Dispose() { if (ColorConverter.IsValueCreated) { ColorConverter.Value.Dispose(); } _solidColorBrush?.Dispose(); _solidColorBrush = null; RenderTarget.Dispose(); RenderTarget = null; _factory.Dispose(); _factory = null; _writeFactory?.Dispose(); _writeFactory = null; _imagingFactory?.Dispose(); _imagingFactory = null; PreviewTexture.Dispose(); PreviewTexture = null; DesktopTexture.Dispose(); DesktopTexture = null; StagingTexture.Dispose(); StagingTexture = null; Device.Dispose(); Device = null; }
public override void Draw(GameTime gameTime) { //this.RenderTarget.FillRectangle(new RectangleF(0, 0, GameWindow.Width, GameWindow.Height), backgroundBrush); this.RenderTarget.FillRectangle( new RectangleF(0, 0, GraphicsRenderer.Width, GraphicsRenderer.Height), brushWhite ); if (alphaTeuz > 0) { this.RenderTarget.DrawBitmap(bitmapTeuz, rectangleTeuz, alphaTeuz, BitmapInterpolationMode.Linear); } if (alphaBackground > 0) { brushBlack.Dispose(); this.RenderTarget.FillRectangle( new RectangleF(0, 0, GraphicsRenderer.Width, GraphicsRenderer.Height), brushBlack = new SolidColorBrush(RenderTarget, new Color4(0f, 0f, 0f, alphaBackground)) ); } if (alphaTowerDefence > 0) { this.RenderTarget.DrawBitmap(bitmapTowerDefence, rectangleTowerDefence, alphaTowerDefence, BitmapInterpolationMode.Linear); } }
private void ReleaseResources() { ReleaseD2DObjects(); ReleaseRenderingObjects(); void ReleaseD2DObjects() { renderTarget2d?.Dispose(); surface?.Dispose(); renderView?.Dispose(); backBuffer?.Dispose(); swapChain?.Dispose(); device?.Dispose(); factoryWrite?.Dispose(); factory2d?.Dispose(); factory?.Dispose(); } void ReleaseRenderingObjects() { foreach (var cell in cells) { cell.Dispose(); } textFormat?.Dispose(); sColorBrush?.Dispose(); } }
private void DrawLine(Vector3 w2s, Vector3 _w2s, Color color) { var solidColorBrush = new SolidColorBrush(this.device, new Color4(color.R, color.G, color.B, color.A)); device.DrawLine(new Vector2(w2s.X, w2s.Y), new Vector2(_w2s.X, _w2s.Y), solidColorBrush); solidColorBrush.Dispose(); }
public override void Draw(RenderTarget rt) { var b = new SolidColorBrush(rt, Color_Line); base.Draw(rt); rt.FillRectangle(ContentView.Scaled(ContentBounds), new SolidColorBrush(rt, new Color4(0.3f, 0.3f, 0.3f, 0.5f))); { float unit = 0.3f; float height = 0.6f; float ny = Position.Y + height / 2f; float x0 = Position.X + 0.1f; x0 -= Width / 2; float x = x0; x += unit; Vector2 last = new Vector2(x0, ny); for (int i = 0; i < 6; i++) { Vector2 a = new Vector2(x0, ny - (i % 2) * height); rt.DrawLine(ContentView.Scaled(last), ContentView.Scaled(a), b, ContentView.Scaled(0.1f)); last = new Vector2(x, ny - (i % 2) * height); rt.DrawLine(ContentView.Scaled(a), ContentView.Scaled(last), b, ContentView.Scaled(0.1f)); x0 += unit; x += unit; } } b.Dispose(); }
public virtual void OnD2DPaint(ScGraphics g) { D2DGraphics d2dGraph = (D2DGraphics)g; if (d2dGraph == null) { return; } if (BackgroundColor != null && BackgroundColor.Value.A != 0) { if (BackgroundColor.Value.A == 255) { RawColor4 color = GDIDataD2DUtils.TransToRawColor4(Color.FromArgb(BackgroundColor.Value.ToArgb())); d2dGraph.RenderTarget.Clear(color); } else { d2dGraph.RenderTarget.AntialiasMode = AntialiasMode.Aliased; RawRectangleF rect = new RawRectangleF(0, 0, Width, Height); RawColor4 rawColor = GDIDataD2DUtils.TransToRawColor4(BackgroundColor.Value); SolidColorBrush brush = new SolidColorBrush(d2dGraph.RenderTarget, rawColor); d2dGraph.RenderTarget.FillRectangle(rect, brush); brush.Dispose(); } } if (D2DPaint != null) { D2DPaint(d2dGraph); } }
public override void Draw(RenderTarget rt) { base.Draw(rt); var brush = new SolidColorBrush(rt, Signed ? ContentView.CableColor_Signed : ContentView.CableColor); var brush_node = new SolidColorBrush(rt, Signed ? ContentView.CableColor_Node_Signed : ContentView.CableColor_Node); rt.FillEllipse(new Ellipse(ContentView.Scaled(P1.RingPosition), ContentView.Scaled(0.15f), ContentView.Scaled(0.15f)), brush_node); rt.FillEllipse(new Ellipse(ContentView.Scaled(P2.RingPosition), ContentView.Scaled(0.15f), ContentView.Scaled(0.15f)), brush_node); if (Path.Count == 0) { rt.DrawLine(ContentView.Scaled(P1.RingPosition), ContentView.Scaled(P2.RingPosition), brush, ContentView.Scaled(0.1f)); } else { rt.DrawLine(ContentView.Scaled(P1.RingPosition), ContentView.Scaled(Path[0]), brush, ContentView.Scaled(0.1f)); int i = 1; for (; i < Path.Count; i++) { rt.DrawLine(ContentView.Scaled(Path[i - 1]), ContentView.Scaled(Path[i]), brush, ContentView.Scaled(0.1f)); } rt.DrawLine(ContentView.Scaled(Path[i - 1]), ContentView.Scaled(P2.RingPosition), brush, ContentView.Scaled(0.1f)); } brush.Dispose(); brush_node.Dispose(); }
private static void DrawRestDotPart(RenderTarget renderTarget, RawVector2 pos, Color color) { PointF[] pathPoints; using (GraphicsPath path = new GraphicsPath()) { path.AddBezier(pos.X, pos.Y + 3f, pos.X - 2f, pos.Y + 6f, pos.X - 8f, pos.Y + 8f, pos.X - 12f, pos.Y + 2f); path.AddBezier((float)(pos.X - 12f), (float)(pos.Y + 2f), (float)(pos.X - 8f), (float)(pos.Y + 6.5f), (float)(pos.X - 2f), (float)(pos.Y + 5f), (float)(pos.X + 1f), (float)(pos.Y - 1f)); path.Flatten(); pathPoints = path.PathPoints; path.Dispose(); } using (SharpDX.Direct2D1.Factory factory = renderTarget.Factory) { PathGeometry geometry = new PathGeometry(factory); if (pathPoints.Length > 1) { GeometrySink sink = geometry.Open(); sink.SetSegmentFlags(PathSegment.ForceRoundLineJoin); sink.BeginFigure(new RawVector2(pathPoints[0].X, pathPoints[0].Y), FigureBegin.Filled); for (int i = 1; i < pathPoints.Length; i++) { sink.AddLine(new RawVector2(pathPoints[i].X, pathPoints[i].Y)); } sink.EndFigure(FigureEnd.Closed); sink.Close(); sink.Dispose(); } SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.FillGeometry(geometry, brush); brush.Dispose(); geometry.Dispose(); } renderTarget.FillCircle(new RawVector2(pos.X - 8f, pos.Y + 2f), 3f, color); }
protected override void OnCleanUpDeviceResources() { base.OnCleanUpDeviceResources(); _radialGradientBrush.Dispose(); _sceneBrush.Dispose(); _gridPatternBrush.Dispose(); }
public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect) { var rect = new SharpDX.RectangleF(0, underline.Offset, underline.Width, underline.Offset + underline.Thickness); var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect); RawMatrix3x2 matrix = new RawMatrix3x2( 1.0f, 0.0f, 0.0f, 1.0f, baselineOriginX, baselineOriginY ); var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix); var brushColor = (Color4)Color.Black; if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect) { brushColor = (Color4)(clientDrawingEffect as ColorDrawingEffect).Color; } var brush = new SolidColorBrush(_renderTarget, brushColor); _renderTarget.DrawGeometry(transformedGeometry, brush); _renderTarget.FillGeometry(transformedGeometry, brush); rectangleGeometry.Dispose(); transformedGeometry.Dispose(); brush.Dispose(); return(SharpDX.Result.Ok); }
public void DrawUnderline(float baselineOriginX, float baselineOriginY, Underline underline, ClientDrawingEffect clientDrawingEffect) { RectF rect = new RectF(0, underline.Offset, underline.Width, underline.Thickness); using (RectangleGeometry rectangleGeometry = _factory.CreateRectangleGeometry(rect)) { SolidColorBrush brush = null; if (clientDrawingEffect != null) { ColorDrawingEffect drawingEffect = clientDrawingEffect as ColorDrawingEffect; if (drawingEffect != null) { brush = _renderTarget.CreateSolidColorBrush(drawingEffect.Color); } } Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY); using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(rectangleGeometry, matrix)) { _renderTarget.FillGeometry(brush == null ? _defaultBrush : brush, transformedGeometry); } if (brush != null) { brush.Dispose(); } } }
public Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect) { var rect = new SharpDX.RectangleF(0, underline.Offset, underline.Width, underline.Offset + underline.Thickness); var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect); var matrix = new Matrix3x2() { M11 = 1, M12 = 0, M21 = 0, M22 = 1, M31 = baselineOriginX, M32 = baselineOriginY }; var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix); var brushColor = new Color4(1, 0, 0, 0); if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect) { brushColor = (clientDrawingEffect as ColorDrawingEffect).Color; } var brush = new SolidColorBrush(_renderTarget, brushColor); _renderTarget.DrawGeometry(transformedGeometry, brush); _renderTarget.FillGeometry(transformedGeometry, brush); rectangleGeometry.Dispose(); transformedGeometry.Dispose(); brush.Dispose(); return(SharpDX.Result.Ok); }
protected override void OnCleanUpDeviceResources() { base.OnCleanUpDeviceResources(); _bitmap.Dispose(); _brush.Dispose(); _gridPatternBrush.Dispose(); }
public override void Draw(RenderTarget rt) { base.Draw(rt); var b = new SolidColorBrush(rt, new Color4(0.2f, 0.2f, 0.2f, 1f)); var b2 = new SolidColorBrush(rt, new Color4(0f, 0f, 1f, 1f)); var b3 = new SolidColorBrush(rt, new Color4(0.3f, 0.3f, 0.3f, 1f)); var b4 = new SolidColorBrush(rt, new Color4(1f, 0.2f, 0.1f, 1f)); rt.DrawLine(ContentView.Scaled(Position), ContentView.Scaled(Pin.Position), b, ContentView.Scaled(0.1f)); rt.FillEllipse(new Ellipse(ContentView.Scaled(Position), ContentView.Scaled(0.5f), ContentView.Scaled(0.5f)), b3); rt.FillEllipse(new Ellipse(ContentView.Scaled(Position), ContentView.Scaled(0.1f), ContentView.Scaled(0.1f)), b2); var DWFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared); SharpDX.DirectWrite.TextFormat tf = new SharpDX.DirectWrite.TextFormat(DWFactory, "Arial", ContentView.Scaled(0.5f)); var tg = ContentView.Scaled(AreaBounds); tg.Left += ContentView.Scaled(Direction == Direction.Left ? 1.5f : 1f); tg.Top -= 1; rt.DrawText(Name, tf, tg, b4); tf.Dispose(); DWFactory.Dispose(); b.Dispose(); b2.Dispose(); b3.Dispose(); b4.Dispose(); }
void PaintState2(D2DGraphics g) { g.RenderTarget.AntialiasMode = AntialiasMode.Aliased; RawRectangleF rect = new RawRectangleF(1, 1, Width - 1, Height - 1); int a = Math.Min(BoxColor.A + 100, 255); int R = Math.Max(BoxColor.R - 130, 0); int G = Math.Max(BoxColor.G - 130, 0); int B = Math.Max(BoxColor.B - 130, 0); RawColor4 rawColor = GDIDataD2DUtils.TransToRawColor4(Color.FromArgb(a, R, G, B)); SolidColorBrush brush = new SolidColorBrush(g.RenderTarget, rawColor); g.RenderTarget.DrawRectangle(rect, brush, boxSideWidth); brush.Dispose(); R = Math.Max(FillInBoxColor.R - 50, 0); G = Math.Max(FillInBoxColor.G - 50, 0); B = Math.Max(FillInBoxColor.B - 50, 0); if (IsUseInFill) { FillIn(g, Color.FromArgb(FillInBoxColor.A, R, G, B)); } if (IsUseInFill2) { FillIn2(g, Color.FromArgb(FillInBoxColor.A, R, G, B)); } }
public void Dispose() { _solidColorBrush?.Dispose(); _solidColorBrush = null; RenderTarget.Dispose(); RenderTarget = null; _factory.Dispose(); _factory = null; _writeFactory?.Dispose(); _writeFactory = null; _imagingFactory?.Dispose(); _imagingFactory = null; PreviewTexture.Dispose(); PreviewTexture = null; DesktopTexture.Dispose(); DesktopTexture = null; StagingTexture.Dispose(); StagingTexture = null; Device.Dispose(); Device = null; }
public override void Draw(RenderTarget target) { SolidColorBrush brush = new SolidColorBrush(target, Color.RawColor); var pathGeometry = new PathGeometry(target.Factory); var geometrySink = pathGeometry.Open(); if (_points.Count > 0) { geometrySink.BeginFigure(_points.First(), FigureBegin.Filled); for (int i = 1; i < _points.Count && i < _framePoint; i++) { geometrySink.AddLine(_points[i]); } geometrySink.EndFigure(FigureEnd.Open); } geometrySink.Close(); // target.DrawGeometry(pathGeometry, brush); target.DrawGeometry(new GeometryNode().PathGeometry, brush); // important. turn pathGeometry into nodes // pathGeometry.Combine pathGeometry.Dispose(); brush.Dispose(); _frameDelayCounter++; if (_frameDelayCounter >= FrameDelay) { _framePoint++; _frameDelayCounter = 0; } }
public static void DrawEllipse(this RenderTarget renderTarget, Ellipse ellipse, Color color, float strokeWidth) { SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.DrawEllipse(ellipse, brush, strokeWidth); brush.Dispose(); }
public override void Dispose() { base.Dispose(); RodBrush.Dispose(); RingBrush.Dispose(); RingBrush_Pointed.Dispose(); }
public static void DrawLine(this RenderTarget renderTarget, RawVector2 p1, RawVector2 p2, Color color, float strokeWidth) { SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.DrawLine(p1, p2, brush, strokeWidth); brush.Dispose(); }
public void DrawFillRect(int X, int Y, int W, int H, Color color) { var bursh = new SolidColorBrush(this.device, new Color4(color.R, color.G, color.B, (float)color.A / 255.0f)); device.FillRectangle(new RectangleF((float)X, (float)Y, (float)W, (float)H), bursh); bursh.Dispose(); }
public static void FillEllipse(this RenderTarget renderTarget, Ellipse ellipse, Color color) { SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.FillEllipse(ellipse, brush); brush.Dispose(); }
public Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect) { var rect = new SharpDX.RectangleF(0, strikethrough.Offset, strikethrough.Width, strikethrough.Offset + strikethrough.Thickness); var rectangleGeometry = new RectangleGeometry(_d2DFactory, rect); var matrix = new Matrix3x2() { M11 = 1, M12 = 0, M21 = 0, M22 = 1, M31 = baselineOriginX, M32 = baselineOriginY }; var transformedGeometry = new TransformedGeometry(_d2DFactory, rectangleGeometry, matrix); var brushColor = (Color4)Color.Black; if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect) { brushColor = (Color4)(clientDrawingEffect as ColorDrawingEffect).Color; } var brush = new SolidColorBrush(_renderTarget, brushColor); _renderTarget.DrawGeometry(transformedGeometry, brush); _renderTarget.FillGeometry(transformedGeometry, brush); rectangleGeometry.Dispose(); transformedGeometry.Dispose(); brush.Dispose(); return(Result.Ok); }
public static void FillRectangle(this RenderTarget renderTarget, RawRectangleF rectF, Color color) { SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.FillRectangle(rectF, brush); brush.Dispose(); }
public static void DrawText(string text, int x, int y) { SolidColorBrush dBrushBack = new SolidColorBrush(Device, Color.FromArgb(1, 1, 1).toRawColor4()); SolidColorBrush dBrush = new SolidColorBrush(Device, Settings.userSettings.VisualColors.World_Text.toRawColor4()); if (text == "Darc Euphoria") { if (_RED_TO_GREEN > 510) { dBrush.Color = Color.FromArgb(_RED_TO_GREEN - 510, 255 - (_RED_TO_GREEN - 510), 0).toRawColor4(); } else if (_RED_TO_GREEN > 255) { dBrush.Color = Color.FromArgb(0, _RED_TO_GREEN - 255, 255 - (_RED_TO_GREEN - 255)).toRawColor4(); } else { dBrush.Color = Color.FromArgb(255 - _RED_TO_GREEN, 0, _RED_TO_GREEN).toRawColor4(); } } else { Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x - 1, y), dBrushBack); Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x + 1, y), dBrushBack); Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x, y - 1), dBrushBack); Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x, y + 1), dBrushBack); } Device.DrawText(text, gvar.textFormat, MathFuncs.StringSize(text, x, y), dBrush); dBrushBack.Dispose(); dBrush.Dispose(); }
public static void FillSector(this RenderTarget renderTarget, RawVector2 pos, float radius, Color color, float angleStart, float angleEnd) { PointF[] pathPoints; using (GraphicsPath path = new GraphicsPath()) { radius *= 2f; path.AddPie(pos.X - (radius / 2f), pos.Y - (radius / 2f), radius, radius, angleStart, angleEnd); path.Flatten(); pathPoints = path.PathPoints; path.Dispose(); } using (SharpDX.Direct2D1.Factory factory = renderTarget.Factory) { PathGeometry geometry = new PathGeometry(factory); if (pathPoints.Length > 1) { GeometrySink sink = geometry.Open(); sink.SetSegmentFlags(PathSegment.ForceRoundLineJoin); sink.BeginFigure(new RawVector2(pathPoints[0].X, pathPoints[0].Y), FigureBegin.Filled); for (int i = 1; i < pathPoints.Length; i++) { sink.AddLine(new RawVector2(pathPoints[i].X, pathPoints[i].Y)); } sink.EndFigure(FigureEnd.Closed); sink.Close(); sink.Dispose(); } SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f)); renderTarget.FillGeometry(geometry, brush); brush.Dispose(); geometry.Dispose(); } }
//Dispose of resources. public void Dispose() { textSceneColorBrush.Dispose(); textFormatTitle.Dispose(); textFormatHorizontal.Dispose(); textFormatVertical.Dispose(); }
private void Close(RenderTarget target, GeometrySink gs) { float a = 0; float b = 1; float h = (b - a) / this.resolution; float t = a; RawVector2 P0, P1; SolidColorBrush curveBrush = new SolidColorBrush(target, this.LineColor); P0 = MathHelper.Interpolate(t, this.points[this.points.Count - 2], this.points[this.points.Count - 1], this.points[0], this.points[1]); while (t < b) { t += h; P1 = MathHelper.Interpolate(t, this.points[this.points.Count - 2], this.points[this.points.Count - 1], this.points[0], this.points[1]); gs.AddLine(P0); gs.AddLine(P1); P0 = P1; } curveBrush.Dispose(); }