protected override void Draw(D2D1.RenderTarget renderTarget) { renderTarget.Clear(_backgroundColor); if (_experimentStarted) { // Draw fixation SolidColorBrush.Color = _fixationColor; renderTarget.FillEllipse(_fixationPoint, SolidColorBrush); if (_trialStarted && _stimPos != 0) { SolidColorBrush.Color = _fontColor; foreach (var stimulusPoint in _stimulusPoints) { renderTarget.FillEllipse(stimulusPoint, SolidColorBrush); } } } else if (!string.IsNullOrWhiteSpace(_displayText)) // Draw text { SolidColorBrush.Color = _fontColor; renderTarget.DrawText(_displayText, _textFormat, new RawRectangleF(0, 0, Width, Height), SolidColorBrush, D2D1.DrawTextOptions.None); } }
internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Ellipse ellipse) { var rect = ellipse.GetBoundingRect(rootElement).ToSharpDX(); var d2dEllipse = new D2D.Ellipse( new Vector2( (float)((rect.Left + rect.Right) * 0.5), (float)((rect.Top + rect.Bottom) * 0.5)), (float)(0.5 * rect.Width), (float)(0.5 * rect.Height)); var fill = await ellipse.Fill.ToSharpDX(renderTarget, rect); var layer = ellipse.CreateAndPushLayerIfNecessary(renderTarget, rootElement); var stroke = await ellipse.Stroke.ToSharpDX(renderTarget, rect); if (ellipse.StrokeThickness > 0 && stroke != null) { var halfStrokeThickness = (float)(ellipse.StrokeThickness * 0.5); d2dEllipse.RadiusX -= halfStrokeThickness; d2dEllipse.RadiusY -= halfStrokeThickness; if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } renderTarget.DrawEllipse( d2dEllipse, stroke, (float)ellipse.StrokeThickness, ellipse.GetStrokeStyle(compositionEngine.D2DFactory)); } else if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } if (layer != null) { renderTarget.PopLayer(); layer.Dispose(); } }
internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Ellipse ellipse) { var rect = ellipse.GetBoundingRect(rootElement).ToSharpDX(); var d2dEllipse = new D2D.Ellipse( new DrawingPointF( (float)((rect.Left + rect.Right) * 0.5), (float)((rect.Top + rect.Bottom) * 0.5)), (float)(0.5 * rect.Width), (float)(0.5 * rect.Height)); var fill = await ellipse.Fill.ToSharpDX(renderTarget, rect); //var layer = new Layer(renderTarget); //var layerParameters = new LayerParameters(); //layerParameters.ContentBounds = rect; //renderTarget.PushLayer(ref layerParameters, layer); var stroke = await ellipse.Stroke.ToSharpDX(renderTarget, rect); if (ellipse.StrokeThickness > 0 && stroke != null) { var halfStrokeThickness = (float)(ellipse.StrokeThickness * 0.5); d2dEllipse.RadiusX -= halfStrokeThickness; d2dEllipse.RadiusY -= halfStrokeThickness; if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } renderTarget.DrawEllipse( d2dEllipse, stroke, (float)ellipse.StrokeThickness, ellipse.GetStrokeStyle(compositionEngine.D2DFactory)); } else if (fill != null) { renderTarget.FillEllipse(d2dEllipse, fill); } //renderTarget.PopLayer(); }
private void OnRender() { lock (_renderContextLock) { if (_renderTarget?.IsDisposed ?? true) { return; } _renderTarget.BeginDraw(); _renderTarget.Clear(_backgroundColor); if (_paradigmStarted) // Draw blocks { foreach (var block in _blocks) { if (block.BorderWidth > 0) { _solidColorBrush.Color = _blockBorderColor; _renderTarget.FillRectangle(block.BorderRect, _solidColorBrush); } if (_bitmap != null) { _solidColorBrush.Color = _blockNormalColor; _renderTarget.FillRectangle(block.ContentRect, _solidColorBrush); if (block.Actived) { _renderTarget.DrawBitmap(_bitmap, block.ContentRect, 1, D2D1.BitmapInterpolationMode.Linear); } } else { _solidColorBrush.Color = block.Actived ? _blockActivedColor : _blockNormalColor; _renderTarget.FillRectangle(block.ContentRect, _solidColorBrush); } if (block.Target) { _solidColorBrush.Color = _blockBorderColor; _renderTarget.FillEllipse(block.CenterPointEllipse, _solidColorBrush); } } } else if (!(_displayText?.IsBlank() ?? true)) // Draw text { _solidColorBrush.Color = _fontColor; _renderTarget.DrawText(_displayText, _textFormat, new RawRectangleF(0, 0, Width, Height), _solidColorBrush, D2D1.DrawTextOptions.None); } _renderTarget.EndDraw(); _swapChain.Present(1, DXGI.PresentFlags.None, _presentParameters); } }
public void Draw(ServiceResult serviceResult, float currentTime, float duration) { if (!uiInitialized) { return; } if (!redraw) { return; } redraw = false; target2d.BeginDraw(); target2d.Clear(new Color4(0, 0, 0, 0.7f)); target2d.DrawLine(new Vector2(0, 1), new Vector2(1024, 1), blueBrush, 2); target2d.DrawLine(new Vector2(0, 511), new Vector2(1024, 511), blueBrush, 2); textFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center; textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center; if (serviceResult.contentType == ServiceResult.ContentType.video) { target2d.DrawText("now playing:", textFormatSmall, new RectangleF(0, 0, 1024, 100), textBrush); target2d.DrawText(serviceResult.TitleWithFallback, textFormat, new RectangleF(0, 50, 1024, 100), textBrush); var barLength = 1024 - 265; var currentLength = barLength * (currentTime / duration); target2d.DrawLine(new Vector2(128, 384), new Vector2(1024 - 128, 384), textBrush, 6); target2d.DrawLine(new Vector2(128, 384), new Vector2(128 + currentLength, 384), blueBrush, 6); var ellipse = new DX2D.Ellipse(new Vector2(128 + currentLength + 3.5f, 384), 7, 7); target2d.FillEllipse(ellipse, blueBrush); target2d.DrawEllipse(new DX2D.Ellipse(new Vector2(512, 256), 48, 48), textBrush, 2); var dist = 8; var len = 10; target2d.DrawLine(new Vector2(512 - dist, 256 - len), new Vector2(512 - dist, 256 + len), textBrush, 2); target2d.DrawLine(new Vector2(512 + dist, 256 - len), new Vector2(512 + dist, 256 + len), textBrush, 2); textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Trailing; target2d.DrawText((new TimeSpan(0, 0, (int)Math.Floor(duration))).ToString(), textFormatSmall, new Rectangle(1024 - 128 - 150, 384, 150, 50), textBrush); int positionx = (int)(128 + currentLength - 74 / 2); positionx = MathUtil.Clamp(positionx, 128, 1024 - 128 - 74); textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center; target2d.DrawText((new TimeSpan(0, 0, (int)Math.Floor(currentTime))).ToString(), textFormatSmall, new Rectangle(positionx, 340, 74, 32), textBrush); } target2d.EndDraw(); }
protected override void Draw(D2D1.RenderTarget renderTarget) { /* Clear canvas */ renderTarget.Clear(_backgroundColor); /* Draw blocks */ if (_paradigmStarted) { var secsPassed = (CurrentTime - _stageUpdatedAt) / 1000.0; foreach (var block in _blocks) { /* Draw block border */ if (block.BorderRect != null) { SolidColorBrush.Color = _blockBorderColor; renderTarget.FillRectangle(block.BorderRect.Value, SolidColorBrush); } /* Fill block content */ if (!_trialStarted || block.Pattern == null) { SolidColorBrush.Color = _blockNormalColor; renderTarget.FillRectangle(block.ContentRect, SolidColorBrush); } else { _presenter.Present(renderTarget, block, secsPassed); } /* Draw block text */ if (block.Text != null) { SolidColorBrush.Color = _blockFontColor; renderTarget.DrawText(block.Text, _blockTextFormat, block.ContentRect, SolidColorBrush, D2D1.DrawTextOptions.None); } /* Draw block fixation */ if (block.FixationEllipse != null) { SolidColorBrush.Color = _blockFixationPointColor; renderTarget.FillEllipse(block.FixationEllipse.Value, SolidColorBrush); } } } else if (_displayText != null) // Draw text { SolidColorBrush.Color = _fontColor; renderTarget.DrawText(_displayText, _cueTextFormat, new RawRectangleF(0, 0, Width, Height), SolidColorBrush, D2D1.DrawTextOptions.None); } }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Рисование эллипса /// </summary> //--------------------------------------------------------------------------------------------------------- public override void Draw() { Direct2D.RenderTarget render_target = XDirect2DManager.D2DRenderTarget; if (mIsFilled) { render_target.FillEllipse(mD2DEllipse, mFill.D2DBrush); } if (mIsStroked) { render_target.DrawEllipse(mD2DEllipse, mStroke.Brush.D2DBrush, mStroke.Thickness, mStroke.mD2DStrokeStyle); } }
public void DrawEllipse(Rect frame, Pen pen = null, Brush brush = null) { var p = GetBrush(pen); var b = GetBrush(frame, brush); var c = frame.Center; var s = new D2D1.Ellipse(new Vector2((float)c.X, (float)c.Y), (float)(frame.Width / 2.0), (float)(frame.Height / 2.0)); if (b != null) { renderTarget.FillEllipse(s, b); } if (p != null) { renderTarget.DrawEllipse(s, p, (float)pen.Width, GetStrokeStyle(pen)); } }
public static void DrawPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IPoint point, D2D1.Brush b, float size, Vector2 offset, Map map) { if (point == null) { return; } var pp = TransformToImage(point.Coordinate, map); if (double.IsNaN(point.X)) { return; } pp += offset; var e = new D2D1.Ellipse(pp, size, size); renderTarget.FillEllipse(e, b); renderTarget.DrawEllipse(e, b); }
protected override void Draw(D2D1.RenderTarget renderTarget) { renderTarget.Clear(Color.Black); var screenRects = Screen.AllScreens.Select(screen => screen.Bounds) .Select(SharpDXUtils.ToRawRectangleF) .ToArray(); var displayBounds = screenRects.GetBounds(); var clientSize = ClientSize; var scale = Math.Min(clientSize.Width / displayBounds.Width(), clientSize.Height / displayBounds.Height()) * 0.9F; var pixelDrawingScale = 1 / scale; var lineThickness = pixelDrawingScale * 2; var pointSize = pixelDrawingScale * 5; renderTarget.Transform = ((RawMatrix3x2)SharpDX.Matrix3x2.Identity) .Translate(clientSize.Width / 2F, clientSize.Height / 2F) .Scale(scale).Translate(displayBounds.Center().Multiply(-1)); SolidColorBrush.Color = Color.White; foreach (var rect in screenRects) { renderTarget.DrawRectangle(rect, SolidColorBrush, lineThickness); } lock (_gazePoints) { var count = 0; foreach (var gazePoint in _gazePoints) { var alpha = 1 - (float)count++ / _historyCount; SolidColorBrush.Color = new RawColor4(1, 0, 0, alpha * alpha); renderTarget.FillEllipse(new D2D1.Ellipse(gazePoint, pointSize, pointSize), SolidColorBrush); } } }
public void Render(RenderTarget target) { InitializeResources(target); target.Transform = Matrix.Identity; target.FillEllipse(new Ellipse(new DrawingPointF(LeftPos.X,LeftPos.Y), 20, 20), Fill); target.DrawEllipse(new Ellipse(new DrawingPointF(LeftPos.X, LeftPos.Y), 20, 20), Stroke); target.FillEllipse(new Ellipse(new DrawingPointF(RightPos.X, RightPos.Y), 20, 20), Fill); target.DrawEllipse(new Ellipse(new DrawingPointF(RightPos.X, RightPos.Y), 20, 20), Stroke); }
public static void FillCircle(this SharpDX.Direct2D1.RenderTarget target, ID2DBrush brush, PointF center, float radius) { var w = radius + radius; target.FillEllipse(brush, center.X - radius, center.Y - radius, w, w); }
public static void FillCircle(this SharpDX.Direct2D1.RenderTarget target, ID2DBrush brush, float x, float y, float radius) { var w = radius + radius; target.FillEllipse(brush, x - radius, y - radius, w, w); }
public static void FillEllipse(this SharpDX.Direct2D1.RenderTarget target, ID2DBrush brush, float x, float y, float width, float height) { var ellipse = new Ellipse(new RawVector2(x + width / 2, y + height / 2), width / 2, height / 2); target.FillEllipse(ellipse, brush.NativeBrush); }
private void dxFillEllipse(SharpDX.Direct2D1.RenderTarget target, int x, int y, int w, int h, Brush brush) { Ellipse ell = new Ellipse(new RawVector2(x + w / 2, y + h / 2), w, h); target.FillEllipse(ell, brush); }