Beispiel #1
0
 public ScreenRenderer(IntPtr hostHandle, Size bufferSize)
 {
     _fontConsolas12           = new Font("Consolas", 12);
     FpsCounter                = new FpsCounter(new TimeSpan(0, 0, 0, 0, 1000));
     BackBuffer                = new DirectBitmap(bufferSize);
     RenderBitmaps             = new ConcurrentBag <Bitmap>();
     GraphicsHost              = Graphics.FromHwnd(hostHandle);
     GraphicsHostDeviceContext = GraphicsHost.GetHdc();
     BufferedGraphics          = BufferedGraphicsManager.Current.Allocate(GraphicsHostDeviceContext, new Rectangle(new Point(0, 0), bufferSize));
     HostHandle                = hostHandle;
     _bufferSize               = bufferSize;
 }
Beispiel #2
0
        public void Dispose()
        {
            lock (_updateLock)
            {
                HostHandle = default;

                GraphicsHost?.Dispose();
                GraphicsHost = default;

                FpsCounter?.Dispose();
                FpsCounter = default;

                RenderBitmaps.Clear();
                RenderBitmaps = default;

                _fontConsolas12?.Dispose();
                _fontConsolas12 = default;
            }
        }
Beispiel #3
0
        public void Render()
        {
            lock (_updateLock)
            {
                FpsCounter.StartFrame();
                Task.Delay(10).Wait();
                var t = DateTime.UtcNow.Millisecond / 1000.0;
                Color GetColor(int x, int y) => Color.FromArgb
                (
                    byte.MaxValue,
                    (byte)((double)x / _bufferSize.Width * byte.MaxValue),
                    (byte)((double)y / _bufferSize.Height * byte.MaxValue),
                    (byte)(Math.Sin(t * Math.PI) * byte.MaxValue)
                );

                Parallel.For(0, BackBuffer.Buffer.Length, index =>
                {
                    BackBuffer.GetXY(index, out var x, out var y);
                    BackBuffer.Buffer[index] = GetColor(x, y).ToArgb();
                });