Esempio n. 1
0
        void Render()
        {
            if (resized)
            {
                Resize();
                resized = false;
            }

            d2dDeviceContext.BeginDraw();
            d2dDeviceContext.Clear(Color4.White);

            d2dDeviceContext.PushAxisAlignedClip(new RectangleF(5, 5, Child.Width - 10, Child.Height - 10), AntialiasMode.Aliased);
            d2dDeviceContext.Transform = Matrix3x2.Translation(Child.Width / 2f / Scale + Translation.X, Child.Height / 2f / Scale + Translation.Y) * Matrix3x2.Scaling(Scale);

            d2dDeviceContext.AntialiasMode = AntialiasMode.Aliased;
            d2dDeviceContext.DrawLine(new Vector2(0, int.MinValue), new Vector2(0, int.MaxValue), RasterDrawBrush, 1 / Scale);
            d2dDeviceContext.DrawLine(new Vector2(int.MinValue, 0), new Vector2(int.MaxValue, 0), RasterDrawBrush, 1 / Scale);
            d2dDeviceContext.AntialiasMode = AntialiasMode.PerPrimitive;

            RenderGeometry();

            d2dDeviceContext.Transform = Matrix3x2.Identity;
            d2dDeviceContext.PopAxisAlignedClip();

            d2dDeviceContext.EndDraw();
            swapChain.Present(0, PresentFlags.None);
        }
Esempio n. 2
0
 protected override void OnDraw(SharpDX.Direct2D1.DeviceContext ctx)
 {
     ctx.Clear(Color.Transparent);
     foreach (var snow in _snows.Values)
     {
         snow.Draw(XResource.Bitmaps, ctx);
     }
     ctx.Transform = Matrix3x2.Identity;
 }
Esempio n. 3
0
        /// <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.
                d2dContext.BeginDraw();
                d2dContext.Clear(Color.CornflowerBlue);

                // Draw a block of text that will be clipped against the specified layout rectangle.
                d2dContext.FillRectangle(new RectangleF(50, 50, 200, 200), backgroundBrush);
                d2dContext.DrawText("This text is long enough to overflow the designed region but will be clipped to the containing rectangle. Lorem ipsum dolor sit amet, consectetur adipiscing elit. ", textFormat, new RectangleF(50, 50, 200, 200), textBrush, DrawTextOptions.Clip);

                // Draw a block of text that will overflow the specified layout rectangle.
                d2dContext.FillRectangle(new RectangleF(50, 300, 200, 200), backgroundBrush);
                d2dContext.DrawText("However, this other text isn't going to be clipped: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean gravida dui id accumsan dictum.", textFormat, new RectangleF(50, 300, 200, 200), textBrush, DrawTextOptions.None);

                // Draw three lines of text with different measuring modes.
                d2dContext.FillRectangle(new RectangleF(300, 50, 400, 200), backgroundBrush);
                d2dContext.DrawText("MeasuringMode: Natural", textFormat, new RectangleF(300, 50, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.Natural);
                d2dContext.DrawText("MeasuringMode: GDI classic", textFormat, new RectangleF(300, 80, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.GdiClassic);
                d2dContext.DrawText("MeasuringMode: GDI natural", textFormat, new RectangleF(300, 110, 400, 200), textBrush, DrawTextOptions.None, MeasuringMode.GdiNatural);

                float layoutYOffset = (float)Math.Cos(layoutY) * 50.0f;

                // Draw moving text.
                d2dContext.FillRectangle(new RectangleF(300, 300, 400, 200), backgroundBrush);
                d2dContext.DrawTextLayout(new Vector2(300, 350 + layoutYOffset), textLayout1, textBrush);

                // Draw moving text without pixel snapping, thus giving a smoother movement.
                d2dContext.FillRectangle(new RectangleF(750, 300, 400, 200), backgroundBrush);
                d2dContext.DrawTextLayout(new Vector2(750, 350 + layoutYOffset), textLayout2, textBrush, DrawTextOptions.NoSnap);

                d2dContext.EndDraw();
                layoutY += 1.0f / 60.0f;

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }
Esempio n. 4
0
        public void RenderFrame()
        {
            if (!_isDisposed)
            {
                _deviceContext.BeginDraw();
                _deviceContext.Clear(SharpDX.Color.White);

                foreach (var visual in _visuals)
                {
                    visual.Render(this);
                }

                _deviceContext.EndDraw();
                _swapChain.Present(1, PresentFlags.None);
            }
        }
Esempio n. 5
0
        /// <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);

                // Calculate the center of the screen
                int halfWidth  = this.swapChain.Description.ModeDescription.Width / 2;
                int halfHeight = this.swapChain.Description.ModeDescription.Height / 2;

                // Translate the origin of coordinates for drawing the bitmap filled rectangle
                d2dContext.Transform = Matrix3x2.Translation(halfWidth - 350, halfHeight);
                d2dContext.FillRectangle(new RectangleF(0, 0, 700, 70), terrainBrush);

                // Translate again for drawing the player bitmap
                d2dContext.Transform = Matrix3x2.Translation(halfWidth, halfHeight - playerBitmap.Size.Height);
                d2dContext.DrawBitmap(playerBitmap, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
                d2dContext.EndDraw();

                // Present the current buffer to the screen.
                swapChain.Present(1, PresentFlags.None);
            }
        }
Esempio n. 6
0
        public DXBitmapExportContext(int width, int height, float displayScale = 1, int dpi = 72, bool disposeBitmap = true)
            : base(width, height, dpi)
        {
            _disposeBitmap = disposeBitmap;

            if (_default3DDevice == null)
            {
                _default3DDevice = new d3d.Device(DriverType.Hardware, d3d.DeviceCreationFlags.VideoSupport | d3d.DeviceCreationFlags.BgraSupport);
                // default3DDevice = new d3d.Device(DriverType.Warp,  d3d.DeviceCreationFlags.BgraSupport);

                _default3DDevice1 = _default3DDevice.QueryInterface <d3d.Device1>();
                _dxgiDevice       = _default3DDevice1.QueryInterface <dxgi.Device>(); // get a reference to DXGI device

                _device2D = new d2.Device(_dxgiDevice);

                // initialize the DeviceContext - it will be the D2D render target
                _deviceContext = new d2.DeviceContext(_device2D, d2.DeviceContextOptions.None);
            }

            // specify a pixel format that is supported by both and WIC
            _pixelFormat = new d2.PixelFormat(dxgi.Format.B8G8R8A8_UNorm, d2.AlphaMode.Premultiplied);

            // create the d2d bitmap description using default flags
            var bitmapProps = new d2.BitmapProperties1(_pixelFormat, Dpi, Dpi,
                                                       d2.BitmapOptions.Target | d2.BitmapOptions.CannotDraw);

            // create our d2d bitmap where all drawing will happen
            _bitmap = new d2.Bitmap1(_deviceContext, new Size2(width, height), bitmapProps);

            // associate bitmap with the d2d context
            _deviceContext.Target = _bitmap;
            _deviceContext.BeginDraw();
            _deviceContext.Clear(new Color4 {
                Alpha = 0, Blue = 0, Green = 0, Red = 0
            });

            _canvas = new DXCanvas(_deviceContext)
            {
                DisplayScale = displayScale
            };
        }
Esempio n. 7
0
        /// <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 void ClearScreen()
 {
     d2dContext.BeginDraw();
     d2dContext.Clear(Color.White);
     d2dContext.EndDraw();
 }
Esempio n. 9
0
 public void Clear(Windows.UI.Color color)
 {
     d2dContext.Clear(ConvertToColorF(color));
 }
Esempio n. 10
0
 public void Clear(Color color)
 {
     _d2D1DeviceContext.Clear(color.ToRawColor4());
 }
Esempio n. 11
0
 protected override void OnDraw(SharpDX.Direct2D1.DeviceContext ctx)
 {
     ctx.Clear(Color.Transparent);
     ctx.DrawBitmap(XResource.Bitmaps[CurrentMc], 1.0f, InterpolationMode.Linear);
 }