public void FillGradientEllipse(float x, float y, float width, float height, System.Drawing.Color[] colors) { // Create the radial gradient brush properties object SharpDX.Direct2D1.RadialGradientBrushProperties radProp = new SharpDX.Direct2D1.RadialGradientBrushProperties { RadiusX = width, RadiusY = height, Center = new SharpDX.Mathematics.Interop.RawVector2(x, y) }; // Create a list of gratiend stops List <SharpDX.Direct2D1.GradientStop> stops = new List <SharpDX.Direct2D1.GradientStop>(); // TODO: Create a color collection that also stores the color position // Auto calulate color position for (int i = 0; i < colors.Length; ++i) { SharpDX.Direct2D1.GradientStop stop = new SharpDX.Direct2D1.GradientStop { Color = ToColor(colors[i]), Position = (float)(1.0 / colors.Length) * (i + 1) }; stops.Add(stop); } SharpDX.Direct2D1.GradientStopCollection radStops = new SharpDX.Direct2D1.GradientStopCollection(d2dRenderTarget, stops.ToArray()); SharpDX.Direct2D1.RadialGradientBrush rgBrush = new SharpDX.Direct2D1.RadialGradientBrush(d2dRenderTarget, ref radProp, radStops); SharpDX.Mathematics.Interop.RawVector2 center = new SharpDX.Mathematics.Interop.RawVector2(x, y); SharpDX.Direct2D1.Ellipse ellipse = new SharpDX.Direct2D1.Ellipse(center, width, height); d2dRenderTarget.FillEllipse(ellipse, rgBrush); radStops.Dispose(); rgBrush.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); } }