public void DrawText(String message, String fontFamily, float fontSize, System.Drawing.Color clr, System.Drawing.Rectangle area) { SharpDX.DirectWrite.TextFormat fmt = new SharpDX.DirectWrite.TextFormat(dwFactory, fontFamily, fontSize); SharpDX.Mathematics.Interop.RawRectangleF rect = ToRectangle(area); SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush(d2dRenderTarget, ToColor(clr)); d2dRenderTarget.DrawText(message, fmt, rect, brush); fmt.Dispose(); brush.Dispose(); }
private void OnRender() { lock (_renderContextLock) { if (_renderTarget?.IsDisposed ?? true) { return; } _renderTarget.BeginDraw(); _renderTarget.Clear(_backgroundColor); if (_experimentStarted) // Draw blocks { var secsPassed = (CurrentTime - _stageUpdatedAt) / 1000.0; switch (_paradigm) { case SsvepExperiment.Configuration.TestConfig.StimulationParadigm.Flicker: foreach (var block in _blocks) { if (block.BorderWidth > 0) { _solidColorBrush.Color = _blockBorderColor; _renderTarget.FillRectangle(block.BorderRect, _solidColorBrush); } if (!_trialStarted || block.Patterns == null) { _solidColorBrush.Color = _blockNormalColor; } else { _solidColorBrush.Color = Color.SmoothStep(_blockNormalColor, _blockFlashingColor, (float)ConvertCosineValueToGrayScale(block.Patterns[0].Sample(secsPassed))); } _renderTarget.FillRectangle(block.ContentRect, _solidColorBrush); if (block.FixationPointSize > 0) { _solidColorBrush.Color = _blockFixationPointColor; _renderTarget.FillEllipse(block.CenterPointEllipse, _solidColorBrush); } } break; case SsvepExperiment.Configuration.TestConfig.StimulationParadigm.DualFlickers: foreach (var block in _blocks) { if (block.BorderWidth > 0) { _solidColorBrush.Color = _blockBorderColor; _renderTarget.FillRectangle(block.BorderRect, _solidColorBrush); } for (var i = 0; i < block.DualFlickerRects.Length; i++) { if (!_trialStarted || block.Patterns == null) { _solidColorBrush.Color = _blockNormalColor; } else { _solidColorBrush.Color = Color.SmoothStep(_blockNormalColor, _blockFlashingColor, (float)ConvertCosineValueToGrayScale(block.Patterns[i].Sample(secsPassed))); } _renderTarget.FillRectangle(block.DualFlickerRects[i], _solidColorBrush); } if (block.FixationPointSize > 0) { _solidColorBrush.Color = _blockFixationPointColor; _renderTarget.FillEllipse(block.CenterPointEllipse, _solidColorBrush); } } break; } } else if (!(_displayText?.IsBlank() ?? true)) // Draw text { _solidColorBrush.Color = _fontColor; _renderTarget.DrawText(_displayText, _textFormat, new RawRectangleF(0, 0, Width, Height), _solidColorBrush, SharpDX.Direct2D1.DrawTextOptions.None); } _renderTarget.EndDraw(); _swapChain.Present(1, SharpDX.DXGI.PresentFlags.None, _presentParameters); } }