void RenderGeometry() { var ellipse = new Ellipse(new Vector2(100, 100), 3, 3); d2dDeviceContext.FillEllipse(ellipse, VertexFillBrush); d2dDeviceContext.DrawEllipse(ellipse, VertexDrawBrush, 0.5f); }
public bool SendFrame(TimeSpan elapsedTime, int frameIndex) { var a = Math.PI * elapsedTime.TotalSeconds; var h = VideoFrameHeight - _ballEllipse.RadiusY; var y = (float)(VideoFrameHeight - Math.Abs(Math.Sin(a) * h)); var pos = new RawVector2(VideoFrameWidth * 0.5f, y); using (var df = TakeNextFrameForSending()) { if (!df.TryGetFrame(out FrameD3D11 frame)) { return(false); } // TODO: Draw bouncing ball. _context2D.Target = frame.Bitmap; _context2D.BeginDraw(); _context2D.Transform = Matrix3x2.Identity; _context2D.DrawBitmap(_backgroundBitmap, new RawRectangleF(0, 0, VideoFrameWidth, VideoFrameHeight), 1, D2D1.BitmapInterpolationMode.NearestNeighbor); _context2D.Transform = BallPosition.HasValue ? Matrix3x2.Translation(BallPosition.Value * new Vector2(VideoFrameWidth, VideoFrameHeight)) : Matrix3x2.Translation(pos); _context2D.FillEllipse(_ballEllipse, _ballBrush); _context2D.EndDraw(); _context2D.Target = null; return(true); } }
/// <summary> /// Run our application until the user quits. /// </summary> public void Run() { // Make window active and hide mouse cursor. window.PointerCursor = null; window.Activate(); // Infinite loop to prevent the application from exiting. while (true) { // Dispatch all pending events in the queue. window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent); // Quit if the users presses Escape key. if (window.GetAsyncKeyState(VirtualKey.Escape) == CoreVirtualKeyStates.Down) { return; } // Set the Direct2D drawing target. d2dContext.Target = d2dTarget; // Clear the target and draw some geometry with the brushes we created. d2dContext.BeginDraw(); d2dContext.Clear(Color.CornflowerBlue); d2dContext.FillRectangle(new RectangleF(50, 50, 450, 150), solidBrush); d2dContext.FillRoundedRectangle(new RoundedRectangle() { Rect = new RectangleF(50, 250, 450, 150), RadiusX = 10, RadiusY = 10 }, linearGradientBrush); d2dContext.FillEllipse(new Ellipse(new Vector2(250, 525), 100, 100), radialGradientBrush); d2dContext.EndDraw(); // Present the current buffer to the screen. swapChain.Present(1, PresentFlags.None); } }
public bool SendFrame(TimeSpan elapsedTime) { using (var df = TakeNextFrameForSending()) { if (!df.TryGetFrame(out BitmapFrameD2D1 frame)) { return(false); } _context2D.Target = frame.Bitmap; _context2D.BeginDraw(); _context2D.Transform = Matrix3x2.Identity; _context2D.DrawBitmap(_backgroundBitmap, new RawRectangleF(0, 0, VideoFrameWidth, VideoFrameHeight), 1, D2D1.BitmapInterpolationMode.NearestNeighbor); // Draw many balls to simulate high motion for (int i = 0; i < BallCount; ++i) { var a = 2 * Math.PI * elapsedTime.TotalSeconds + i * Math.PI / BallCount; var h = VideoFrameHeight - _ballEllipse.RadiusY; var s = (float)VideoFrameWidth / (BallCount + 1); var y = (float)(VideoFrameHeight - Math.Abs(Math.Sin(a) * h)); var pos = new RawVector2((i + 1) * s, y); // - _ballEllipse.RadiusX, y); _context2D.Transform = MousePosition.HasValue ? Matrix3x2.Translation(MousePosition.Value * new Vector2(VideoFrameWidth, VideoFrameHeight)) : Matrix3x2.Translation(pos); _context2D.FillEllipse(_ballEllipse, _ballBrush); } if (_rulerOptions != null) { _context2D.Transform = Matrix3x2.Identity; // Draw the time markers and current time to measure latency int markerCount = _rulerOptions.MarkerCount; int markerWidth = _rulerOptions.MarkerWidth; int markerHeight = _rulerOptions.MarkerHeight; int markerOffset = markerWidth / 2; var y = VideoFrameHeight - markerHeight; _context2D.FillRectangle(new RectangleF(0, y, VideoFrameWidth, markerHeight), _timeRulerBrush); for (int i = 0; i < markerCount; ++i) { var x = markerOffset + i * (VideoFrameWidth - markerWidth) / markerCount; var b = i % 10 == 0 ? _timeMarkerBrush2 : _timeMarkerBrush1; var r = new RectangleF(x - markerOffset, y, markerWidth, markerHeight); _context2D.FillRectangle(r, b); } // Draw current time { var duration = _rulerOptions.Duration.TotalMilliseconds; var t = elapsedTime.TotalMilliseconds % duration; var i = (float)(t * markerCount / duration); var x = markerOffset + i * (VideoFrameWidth - markerWidth) / markerCount; var r = new RectangleF(x - markerOffset, y, markerWidth, markerHeight); _context2D.FillRectangle(r, _currentTimeBrush); } } _context2D.EndDraw(); _context2D.Target = null; return(true); } }
public void FillEllipse(Ellipse ellipse, Brush brush) { deviceContext.FillEllipse(ellipse, brush); }