private void Render() { DeviceContext renderTarget = _deviceContext; renderTarget.BeginDraw(); List <Tuple <Geometry, Color> > copy = _task == null ? new List <Tuple <Geometry, Color> >() : _task.Result; _task = CreateGeometries(_time); if (_time == 0.1f) { renderTarget.Clear(Color.FromKnown(Colors.Black, 1f)); } renderTarget.FillRect(_brush, new RectF(0, 0, ClientSize.Width, ClientSize.Height)); for (int index = 0; index < copy.Count; ++index) { Tuple <Geometry, Color> tuple = copy[index]; using (Geometry geometry = tuple.Item1) { using (SolidColorBrush brush = renderTarget.CreateSolidColorBrush(tuple.Item2.AdjustContrast(1.5f))) { renderTarget.DrawGeometry(brush, 0.1f, geometry); } } } renderTarget.EndDraw(); _swapChain.Present(1, 0); _time += 0.002f; }
protected override void Render(DeviceContext target) { target.Clear(new RawColor4(1.0f, 1.0f, 1.0f, 1.0f)); var brush = rnd.Next(3) switch { 0 => ResourceCache["RedBrush".GetHashCode()] as Brush, 1 => ResourceCache["GreenBrush".GetHashCode()] as Brush, 2 => ResourceCache["BlueBrush".GetHashCode()] as Brush, _ => null }; target.DrawRectangle(new RawRectangleF(x, y, x + w, y + h), brush); x += dx; y += dy; if (x >= ActualWidth - w || x <= 0) { dx = -dx; } if (y >= ActualHeight - h || y <= 0) { dy = -dy; } } }
private void Render() { context.Clear(null); Matrix3x2 worldToFormTransform = GetWorldToFormTransform(); foreach (var bone in bones) { var transform = bone.GetChainedTransform(inputs) * worldToFormTransform; var formCenter = Matrix3x2.TransformPoint(transform, bone.Center); var formEnd = Matrix3x2.TransformPoint(transform, bone.End); context.DrawEllipse(new Ellipse(formCenter, 5, 5), whiteBrush, 2); context.DrawLine(formCenter, formEnd, whiteBrush, 2); } var formTarget = Matrix3x2.TransformPoint(worldToFormTransform, target); float crossSize = 5; context.DrawLine( formTarget + crossSize * new Vector2(-1, -1), formTarget + crossSize * new Vector2(+1, +1), redBrush, 2); context.DrawLine( formTarget + crossSize * new Vector2(-1, +1), formTarget + crossSize * new Vector2(+1, -1), redBrush, 2); }
public void Render() { if (_bitmap1 == null || _renderTarget2D == null) { return; } DeviceContext.Target = _bitmap1; using (DeviceContext.Target) { DeviceContext.BeginDraw(); if (this.needsClear) { DeviceContext.Clear(this.ClearColor); this.needsClear = false; } while (_queue.Count > 0) { CanvasObject o = _queue.Dequeue(); o.DoWork(DeviceContext); } DeviceContext.EndDraw(); } DeviceContext.Target = null; _spriteBatch.Begin(SpriteSortMode.Immediate, this._graphicsDeviceManager.GraphicsDevice.BlendStates.NonPremultiplied); _spriteBatch.Draw(_renderTarget2D, Vector2.Zero, Color.White); _spriteBatch.End(); }
public override void Render() { DeviceContext.Clear(Color.MediumPurple); DeviceContext.Transform = Matrix3x2.Rotation(position * 0.018f, new Vector2(position + 100, 200)); DeviceContext.DrawBitmap(Resource, "Image", new RawRectangleF(position, 100, position + 200, 300)); DeviceContext.Transform = Matrix3x2.Identity; }
public void Display(bool clear = false) { Device.Target = Device.BackBuffer; DeviceContext context = Device; context.BeginDraw(); if (clear) { context.Clear(Color.Transparent); } Render(); context.EndDraw(); }
public void PushRenderTarget(BitmapProxy target, bool clear) { if (targetStack.Count > 0) { DeviceContext.EndDraw(); } targetStack.Push(target); DeviceContext.Target = targetStack.Peek(); HasTarget = true; DeviceContext.BeginDraw(); if (clear) { DeviceContext.Clear(Color.Transparent); } }
public override void Render() { DeviceContext.Clear(Color.CornflowerBlue); DeviceContext.Transform = Matrix3x2.Rotation(position * 0.018f, new Vector2(position + 50, position + 150)); DeviceContext.DrawBitmap(Resource, "Image", new RawRectangleF(position, position + 100, position + 100, position + 200)); DeviceContext.Transform = Matrix3x2.Transformation(1, 1, 0, 10, 10); DeviceContext.DrawSprite(Resource, "Sprite"); DeviceContext.Transform = Matrix3x2.Identity; SpriteBatch.Begin(); SpriteBatch.Draw(Resource.Get <SpriteResource>("Saikoro"), new Vector2(position + 100, 150), position * 0.018f); SpriteBatch.End(); }
protected override void OnDxPaint(Dx11Component resource) { DeviceContext context = resource.D2D.Context; Size clientSize = GetClientSize(); if (frames % framesPerTick == 0) { for (int i = 0; i < ticksPerFrame; i++) { update |= circuitBoard.Update(); performanceMonitor.IncrementTicks(); } if (update) { circuitBoard.Image.CopyToBitmap(bitmap); update = false; } frames = 0; } frames++; context.BeginDraw(); context.Clear(clearColor); context.Transform = transformationMatrix; context.DrawBitmap(bitmap, CreateImageRect(bitmap.PixelSize, clientSize), 1f, BitmapInterpolationMode.NearestNeighbor); context.Transform = identityMatrix; if (performanceMonitor.TryCalculate()) { performaceText = $"{performanceMonitor.FramesPerSecond:F0} FPS | {performanceMonitor.TicksPerSecond:F0} TPS"; } context.DrawText(performaceText, textFormat, new RawRectangleF(0f, 0f, clientSize.Width, clientSize.Height), textBrush); context.EndDraw(); performanceMonitor.IncermentFrames(); }
public override void Render(DeviceContext target) { target.Clear(default(RawColor4)); if (_parent.LinksSource == null) { return; } var s = (float)_parent.Scale; var tx = (float)_parent.TranslateTransform.X; var ty = (float)_parent.TranslateTransform.Y; target.Transform = new RawMatrix3x2(s, 0, 0, s, tx, ty); var isDrawArrow = _parent.Scale > 0.125; var lineWidth = BaseLineWidth / s; DrawCurves(target, isDrawArrow, lineWidth); }
protected override void Render(DeviceContext target) { target.Clear(default(RawColor4)); if (_parent.LinksSource is null) { return; } var scale = (float)_parent.Scale; var tx = (float)_parent.TranslateTransform.X; var ty = (float)_parent.TranslateTransform.Y; target.Transform = new RawMatrix3x2(scale, 0f, 0f, scale, tx, ty); var isDrawArrow = scale > 0.085f; var lineWidth = BaseLineWidth / scale; DrawCurves(target, isDrawArrow, lineWidth); }
protected override void OnDraw(DeviceContext renderTarget) { base.OnDraw(renderTarget); renderTarget.Clear(ClearColor); renderTarget.Transform = GlobalTransform; foreach (var sprite in Sprites.Values) { sprite.Draw(renderTarget); } renderTarget.Transform = Matrix3x2.Identity; if (ShowFPS) { renderTarget.DrawText($"FPS: {RenderTimer.FramesPerSecond:F1}", XResource.TextFormats[12.0f], new RectangleF(0, 0, renderTarget.Size.Width, renderTarget.Size.Height), XResource.GetColor(Color.DimGray)); } }
private async Task Render() { DeviceContext renderTarget = _deviceContext; renderTarget.BeginDraw(); renderTarget.Clear(Color.FromKnown(Colors.Black, 1f)); for (int index = 0; index < PointCount; ++index) { for (int n = 0; n < NeighborCount; ++n) { renderTarget.DrawLine(_brush1, (NeighborCount - n) / (float)(10 * NeighborCount), _points[index], _points[_neighbors[index, n]]); } renderTarget.DrawEllipse(_brush, 0.5f, new Ellipse(_points[index], 1.5f, 1.5f)); } string text = "Press <Esc> to exit..."; using (TextFormat textFormat = _directWriteFactory.CreateTextFormat("Segoe UI", 13, FontWeight.Normal)) using (TextLayout textLayout = _directWriteFactory.CreateTextLayout(text, textFormat, float.MaxValue, float.MaxValue)) using (SolidColorBrush textBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.White, 1))) { renderTarget.DrawText( text, textFormat, new RectF(10, 10, ClientRectangle.Width, ClientRectangle.Height), textBrush, DrawTextOptions.None, MeasuringMode.Natural ); } renderTarget.EndDraw(); _swapChain.Present(1, 0); await MovePoints(); }
private void Render() { DeviceContext renderTarget = _deviceContext; renderTarget.BeginDraw(); renderTarget.Clear(Color.FromKnown(Colors.Black, 1f)); _random = new Random(19292); for (int index = 0; index < _brushes.Length; ++index) { float x = _random.Next(0, ClientRectangle.Width); float y = _random.Next(0, ClientRectangle.Height); Ellipse ellipse = new Ellipse(x, y, 50, 50); renderTarget.FillEllipse(_brushes[index], ellipse); renderTarget.DrawEllipse(_pens[index], 1, ellipse); } string text = "Press <Esc> to exit..."; using (TextFormat textFormat = _directWriteFactory.CreateTextFormat("Segoe UI", 13, FontWeight.Normal)) using (TextLayout textLayout = _directWriteFactory.CreateTextLayout(text, textFormat, float.MaxValue, float.MaxValue)) using (SolidColorBrush textBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.White, 1))) { renderTarget.DrawText( text, textFormat, new RectF(10, 10, ClientRectangle.Width, ClientRectangle.Height), textBrush, DrawTextOptions.None, MeasuringMode.Natural ); } renderTarget.EndDraw(); _swapChain.Present(1, 0); }
private void Render() { DeviceContext renderTarget = _deviceContext; renderTarget.BeginDraw(); renderTarget.Clear(Color.FromKnown(Colors.Black, 1f)); for (double re = 0.5; re <= 2; re += 0.1d) { for (double im = -2; im <= 2; im += 0.1d) { Complex s = new Complex(re, im); Complex z = AdvancedComplexMath.RiemannZeta(s); PointF rs = TranslateToScreen(s.Real, s.Imaginary); PointF rz = TranslateToScreen(z.Real, z.Imaginary); renderTarget.DrawLine(_brush1, 1, rs, rz); } } renderTarget.EndDraw(); _swapChain.Present(1, 0); }
/// <inheritdoc/> public void Clear(Color color) { _deviceContext.Clear(color.ToDirect2D()); }
private void RenderLoadingScreen() { DeviceContext.Clear(Color.Black); }
public System.Drawing.Bitmap TextToBitmap(string text, out Size2F size, RawColor4 bgcolor, d2.TextAntialiasMode aamode, int maxWidth = 1000, int maxHeight = 1000) { var sz = GetTextSize(text, maxWidth, maxHeight); int pixelWidth = (int)(sz.Width * 2); int pixelHeight = (int)(sz.Height * 2); var d2dRenderTarget = new Bitmap1(d2dContext, new Size2(pixelWidth, pixelHeight), d2dBitmapProps); if (d2dContext.Target != null) { d2dContext.Target.Dispose(); } d2dContext.Target = d2dRenderTarget; // associate bitmap with the d2d context // Draw Text TextLayout textLayout = new TextLayout(dwFactory, text, textFormat, pixelWidth, pixelHeight); //d2dContext.TextRenderingParams = new RenderingParams(dwFactory, 1, 0, 0, PixelGeometry.Flat, renderingMode); d2dContext.TextAntialiasMode = aamode; d2dContext.BeginDraw(); d2dContext.Clear(bgcolor); d2dContext.DrawTextLayout(new RawVector2(0, 0), textLayout, textBrush, DrawTextOptions.EnableColorFont); d2dContext.EndDraw(); size = new Size2F(textLayout.Metrics.Width, textLayout.Metrics.Height); textLayout.Dispose(); // Copy to MemoryStream var stream = new MemoryStream(); var encoder = new wic.PngBitmapEncoder(imagingFactory); encoder.Initialize(stream); var bitmapFrameEncode = new wic.BitmapFrameEncode(encoder); bitmapFrameEncode.Initialize(); bitmapFrameEncode.SetSize(pixelWidth, pixelHeight); bitmapFrameEncode.SetPixelFormat(ref wicPixelFormat); // this is the trick to write D2D1 bitmap to WIC var imageEncoder = new wic.ImageEncoder(imagingFactory, d2dDevice); var imageParam = new wic.ImageParameters(d2PixelFormat, dpi, dpi, 0, 0, pixelWidth, pixelHeight); imageEncoder.WriteFrame(d2dRenderTarget, bitmapFrameEncode, imageParam); bitmapFrameEncode.Commit(); encoder.Commit(); imageEncoder.Dispose(); encoder.Dispose(); bitmapFrameEncode.Dispose(); d2dRenderTarget.Dispose(); // Convert To Bitmap byte[] data = stream.ToArray(); stream.Seek(0, SeekOrigin.Begin); var bmp = new System.Drawing.Bitmap(stream); stream.Dispose(); return(bmp); }
public void TestDraw() { d2d1DC.BeginDraw(); d2d1DC.Clear(Color.Black); //============================= SolidColorBrush brush = new SolidColorBrush(d2d1DC, Color.Yellow); SolidColorBrush brush2 = new SolidColorBrush(d2d1DC, Color.YellowGreen); TextFormat textFormat = new TextFormat(DirectXFactory.DWFactory, PreferFont, FontSize); TextFormat textFormat2 = new TextFormat(DirectXFactory.DWFactory, PreferFont, FontSize); String msg = "正"; TextLayout textLayout = new TextLayout(DirectXFactory.DWFactory, msg, textFormat, textFormat.FontSize * 1.5f, textFormat.FontSize); Size2F s = new Size2F(textLayout.Metrics.Width, textLayout.Metrics.Height); float d = s.Width / 2.0f; RectangleF rect = new RectangleF(0, 0, d, s.Height); textFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading; textFormat2.TextAlignment = SharpDX.DirectWrite.TextAlignment.Trailing; textFormat.WordWrapping = WordWrapping.NoWrap; //遇到邊界時別下移 DrawTextOptions op = DrawTextOptions.Clip; //遇到邊界時裁切 float oy = (textLayout.Metrics.Height - textFormat.FontSize) / 2.0f; RectangleF rect1 = new RectangleF(0, oy, textLayout.Metrics.Width / 2.0f, textFormat.FontSize); RectangleF rect2 = new RectangleF(0, oy + textFormat.FontSize, textLayout.Metrics.Width / 2.0f, textFormat.FontSize); d2d1DC.FillRectangle(rect1, new SolidColorBrush(d2d1DC, Color.White)); d2d1DC.FillRectangle(rect2, new SolidColorBrush(d2d1DC, Color.Blue)); d2d1DC.DrawText("你", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("你", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("怎", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("怎", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("不", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("不", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("問", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("問", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("問", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("問", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("神", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("神", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("奇", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("奇", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("海", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("海", textFormat2, rect, brush2, op); rect.X += d; d2d1DC.DrawText("螺", textFormat, rect, brush, op); rect.X += d; d2d1DC.DrawText("螺", textFormat2, rect, brush2, op); //============================= d2d1DC.EndDraw(); swapChain.Present(1, PresentFlags.None); }