DrawEllipse() 공개 메소드

Draws the outline of the specified ellipse using the specified stroke style.
The {{DrawEllipse}} method doesn't return an error code if it fails. To determine whether a drawing operation (such as DrawEllipse) failed, check the result returned by the M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@) or M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@) methods.
public DrawEllipse ( SharpDX.Direct2D1.Ellipse ellipse, Brush brush ) : void
ellipse SharpDX.Direct2D1.Ellipse The position and radius of the ellipse to draw, in device-independent pixels.
brush Brush The brush used to paint the ellipse's outline.
리턴 void
예제 #1
0
        public void Draw(ServiceResult serviceResult, float currentTime, float duration)
        {
            if (!uiInitialized)
            {
                return;
            }
            if (!redraw)
            {
                return;
            }
            redraw = false;

            target2d.BeginDraw();
            target2d.Clear(new Color4(0, 0, 0, 0.7f));

            target2d.DrawLine(new Vector2(0, 1), new Vector2(1024, 1), blueBrush, 2);
            target2d.DrawLine(new Vector2(0, 511), new Vector2(1024, 511), blueBrush, 2);

            textFormat.TextAlignment      = SharpDX.DirectWrite.TextAlignment.Center;
            textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;

            if (serviceResult.contentType == ServiceResult.ContentType.video)
            {
                target2d.DrawText("now playing:", textFormatSmall, new RectangleF(0, 0, 1024, 100), textBrush);
                target2d.DrawText(serviceResult.TitleWithFallback, textFormat, new RectangleF(0, 50, 1024, 100), textBrush);

                var barLength     = 1024 - 265;
                var currentLength = barLength * (currentTime / duration);

                target2d.DrawLine(new Vector2(128, 384), new Vector2(1024 - 128, 384), textBrush, 6);
                target2d.DrawLine(new Vector2(128, 384), new Vector2(128 + currentLength, 384), blueBrush, 6);
                var ellipse = new DX2D.Ellipse(new Vector2(128 + currentLength + 3.5f, 384), 7, 7);
                target2d.FillEllipse(ellipse, blueBrush);

                target2d.DrawEllipse(new DX2D.Ellipse(new Vector2(512, 256), 48, 48), textBrush, 2);
                var dist = 8;
                var len  = 10;
                target2d.DrawLine(new Vector2(512 - dist, 256 - len), new Vector2(512 - dist, 256 + len), textBrush, 2);
                target2d.DrawLine(new Vector2(512 + dist, 256 - len), new Vector2(512 + dist, 256 + len), textBrush, 2);

                textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Trailing;
                target2d.DrawText((new TimeSpan(0, 0, (int)Math.Floor(duration))).ToString(), textFormatSmall, new Rectangle(1024 - 128 - 150, 384, 150, 50), textBrush);


                int positionx = (int)(128 + currentLength - 74 / 2);
                positionx = MathUtil.Clamp(positionx, 128, 1024 - 128 - 74);
                textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
                target2d.DrawText((new TimeSpan(0, 0, (int)Math.Floor(currentTime))).ToString(), textFormatSmall, new Rectangle(positionx, 340, 74, 32), textBrush);
            }

            target2d.EndDraw();
        }
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Рисование эллипса
            /// </summary>
            //---------------------------------------------------------------------------------------------------------
            public override void Draw()
            {
                Direct2D.RenderTarget render_target = XDirect2DManager.D2DRenderTarget;

                if (mIsFilled)
                {
                    render_target.FillEllipse(mD2DEllipse, mFill.D2DBrush);
                }

                if (mIsStroked)
                {
                    render_target.DrawEllipse(mD2DEllipse, mStroke.Brush.D2DBrush, mStroke.Thickness, mStroke.mD2DStrokeStyle);
                }
            }
        public void DrawEllipse(Rect frame, Pen pen = null, Brush brush = null)
        {
            var p = GetBrush(pen);
            var b = GetBrush(frame, brush);
            var c = frame.Center;
            var s = new D2D1.Ellipse(new Vector2((float)c.X, (float)c.Y), (float)(frame.Width / 2.0), (float)(frame.Height / 2.0));

            if (b != null)
            {
                renderTarget.FillEllipse(s, b);
            }
            if (p != null)
            {
                renderTarget.DrawEllipse(s, p, (float)pen.Width, GetStrokeStyle(pen));
            }
        }
예제 #4
0
        internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Ellipse ellipse)
        {
            var rect = ellipse.GetBoundingRect(rootElement).ToSharpDX();

            var d2dEllipse = new D2D.Ellipse(
                new Vector2(
                    (float)((rect.Left + rect.Right) * 0.5),
                    (float)((rect.Top + rect.Bottom) * 0.5)),
                (float)(0.5 * rect.Width),
                (float)(0.5 * rect.Height));
            var fill = await ellipse.Fill.ToSharpDX(renderTarget, rect);

            var layer = ellipse.CreateAndPushLayerIfNecessary(renderTarget, rootElement);

            var stroke = await ellipse.Stroke.ToSharpDX(renderTarget, rect);

            if (ellipse.StrokeThickness > 0 &&
                stroke != null)
            {
                var halfStrokeThickness = (float)(ellipse.StrokeThickness * 0.5);
                d2dEllipse.RadiusX -= halfStrokeThickness;
                d2dEllipse.RadiusY -= halfStrokeThickness;

                if (fill != null)
                {
                    renderTarget.FillEllipse(d2dEllipse, fill);
                }

                renderTarget.DrawEllipse(
                    d2dEllipse,
                    stroke,
                    (float)ellipse.StrokeThickness,
                    ellipse.GetStrokeStyle(compositionEngine.D2DFactory));
            }
            else if (fill != null)
            {
                renderTarget.FillEllipse(d2dEllipse, fill);
            }

            if (layer != null)
            {
                renderTarget.PopLayer();
                layer.Dispose();
            }
        }
예제 #5
0
        internal static async Task Render(CompositionEngine compositionEngine, SharpDX.Direct2D1.RenderTarget renderTarget, FrameworkElement rootElement, Ellipse ellipse)
        {
            var rect = ellipse.GetBoundingRect(rootElement).ToSharpDX();

            var d2dEllipse = new D2D.Ellipse(
                new DrawingPointF(
                    (float)((rect.Left + rect.Right) * 0.5),
                    (float)((rect.Top + rect.Bottom) * 0.5)),
                (float)(0.5 * rect.Width),
                (float)(0.5 * rect.Height));
            var fill = await ellipse.Fill.ToSharpDX(renderTarget, rect);

            //var layer = new Layer(renderTarget);
            //var layerParameters = new LayerParameters();
            //layerParameters.ContentBounds = rect;
            //renderTarget.PushLayer(ref layerParameters, layer);

            var stroke = await ellipse.Stroke.ToSharpDX(renderTarget, rect);

            if (ellipse.StrokeThickness > 0 &&
                stroke != null)
            {
                var halfStrokeThickness = (float)(ellipse.StrokeThickness * 0.5);
                d2dEllipse.RadiusX -= halfStrokeThickness;
                d2dEllipse.RadiusY -= halfStrokeThickness;

                if (fill != null)
                {
                    renderTarget.FillEllipse(d2dEllipse, fill);
                }

                renderTarget.DrawEllipse(
                    d2dEllipse,
                    stroke,
                    (float)ellipse.StrokeThickness,
                    ellipse.GetStrokeStyle(compositionEngine.D2DFactory));
            }
            else if (fill != null)
            {
                renderTarget.FillEllipse(d2dEllipse, fill);
            }

            //renderTarget.PopLayer();
        }
예제 #6
0
        public static void DrawPoint(D2D1.RenderTarget renderTarget, D2D1.Factory factory, IPoint point, D2D1.Brush b, float size, Vector2 offset, Map map)
        {
            if (point == null)
            {
                return;
            }

            var pp = TransformToImage(point.Coordinate, map);

            if (double.IsNaN(point.X))
            {
                return;
            }

            pp += offset;

            var e = new D2D1.Ellipse(pp, size, size);

            renderTarget.FillEllipse(e, b);
            renderTarget.DrawEllipse(e, b);
        }
예제 #7
0
        public void Run()
        {
            var form = new RenderForm("2d and 3d combined...it's like magic");
            form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) form.Close(); };

            // DirectX DXGI 1.1 factory
            var factory1 = new Factory1();

            // The 1st graphics adapter
            var adapter1 = factory1.GetAdapter1(0);

            // ---------------------------------------------------------------------------------------------
            // Setup direct 3d version 11. It's context will be used to combine the two elements
            // ---------------------------------------------------------------------------------------------

            var description = new SwapChainDescription
                {
                    BufferCount = 1,
                    ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                    IsWindowed = true,
                    OutputHandle = form.Handle,
                    SampleDescription = new SampleDescription(1, 0),
                    SwapEffect = SwapEffect.Discard,
                    Usage = Usage.RenderTargetOutput,
                    Flags = SwapChainFlags.AllowModeSwitch
                };

            Device11 device11;
            SwapChain swapChain;

            Device11.CreateWithSwapChain(adapter1, DeviceCreationFlags.None, description, out device11, out swapChain);

            // create a view of our render target, which is the backbuffer of the swap chain we just created
            RenderTargetView renderTargetView;
            using (var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0))
                renderTargetView = new RenderTargetView(device11, resource);

            // setting a viewport is required if you want to actually see anything
            var context = device11.ImmediateContext;

            var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
            context.OutputMerger.SetTargets(renderTargetView);
            context.Rasterizer.SetViewports(viewport);

            //
            // Create the DirectX11 texture2D. This texture will be shared with the DirectX10 device.
            //
            // The DirectX10 device will be used to render text onto this texture.
            // DirectX11 will then draw this texture (blended) onto the screen.
            // The KeyedMutex flag is required in order to share this resource between the two devices.
            var textureD3D11 = new Texture2D(device11, new Texture2DDescription
            {
                Width = form.ClientSize.Width,
                Height = form.ClientSize.Height,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.B8G8R8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.SharedKeyedmutex
            });

            // ---------------------------------------------------------------------------------------------
            // Setup a direct 3d version 10.1 adapter
            // ---------------------------------------------------------------------------------------------
            var device10 = new Device10(adapter1, SharpDX.Direct3D10.DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);

            // ---------------------------------------------------------------------------------------------
            // Setup Direct 2d
            // ---------------------------------------------------------------------------------------------

            // Direct2D Factory
            var factory2D = new SharpDX.Direct2D1.Factory(FactoryType.SingleThreaded, DebugLevel.Information);

            // Here we bind the texture we've created on our direct3d11 device through the direct3d10
            // to the direct 2d render target....
            var sharedResource = textureD3D11.QueryInterface<SharpDX.DXGI.Resource>();
            var textureD3D10 = device10.OpenSharedResource<SharpDX.Direct3D10.Texture2D>(sharedResource.SharedHandle);

            var surface = textureD3D10.AsSurface();
            var rtp = new RenderTargetProperties
                {
                    MinLevel = SharpDX.Direct2D1.FeatureLevel.Level_10,
                    Type = RenderTargetType.Hardware,
                    PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
                };

            var renderTarget2D = new RenderTarget(factory2D, surface, rtp);
            var solidColorBrush = new SolidColorBrush(renderTarget2D, Colors.Red);

            // ---------------------------------------------------------------------------------------------------
            // Setup the rendering data
            // ---------------------------------------------------------------------------------------------------

            // Load Effect. This includes both the vertex and pixel shaders.
            // Also can include more than one technique.
            ShaderBytecode shaderByteCode = ShaderBytecode.CompileFromFile(
                "effectDx11.fx",
                "fx_5_0",
                ShaderFlags.EnableStrictness);

            var effect = new Effect(device11, shaderByteCode);

            // create triangle vertex data, making sure to rewind the stream afterward
            var verticesTriangle = new DataStream(VertexPositionColor.SizeInBytes * 3, true, true);
            verticesTriangle.Write(new VertexPositionColor(new Vector3(0.0f, 0.5f, 0.5f),new Color4(1.0f, 0.0f, 0.0f, 1.0f)));
            verticesTriangle.Write(new VertexPositionColor(new Vector3(0.5f, -0.5f, 0.5f),new Color4(0.0f, 1.0f, 0.0f, 1.0f)));
            verticesTriangle.Write(new VertexPositionColor(new Vector3(-0.5f, -0.5f, 0.5f),new Color4(0.0f, 0.0f, 1.0f, 1.0f)));

            verticesTriangle.Position = 0;

            // create the triangle vertex layout and buffer
            var layoutColor = new InputLayout(device11, effect.GetTechniqueByName("Color").GetPassByIndex(0).Description.Signature, VertexPositionColor.inputElements);
            var vertexBufferColor = new Buffer(device11, verticesTriangle, (int)verticesTriangle.Length, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            verticesTriangle.Close();

            // create overlay vertex data, making sure to rewind the stream afterward
            // Top Left of screen is -1, +1
            // Bottom Right of screen is +1, -1
            var verticesText = new DataStream(VertexPositionTexture.SizeInBytes * 4, true, true);
            verticesText.Write(new VertexPositionTexture(new Vector3(-1, 1, 0),new Vector2(0, 0f)));
            verticesText.Write(new VertexPositionTexture(new Vector3(1, 1, 0),new Vector2(1, 0)));
            verticesText.Write(new VertexPositionTexture(new Vector3(-1, -1, 0),new Vector2(0, 1)));
            verticesText.Write(new VertexPositionTexture(new Vector3(1, -1, 0),new Vector2(1, 1)));

            verticesText.Position = 0;

            // create the overlay vertex layout and buffer
            var layoutOverlay = new InputLayout(device11, effect.GetTechniqueByName("Overlay").GetPassByIndex(0).Description.Signature, VertexPositionTexture.inputElements);
            var vertexBufferOverlay = new Buffer(device11, verticesText, (int)verticesText.Length, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            verticesText.Close();

            // Think of the shared textureD3D10 as an overlay.
            // The overlay needs to show the 2d content but let the underlying triangle (or whatever)
            // show thru, which is accomplished by blending.
            var bsd = new BlendStateDescription();
            bsd.RenderTarget[0].IsBlendEnabled = true;
            bsd.RenderTarget[0].SourceBlend = BlendOption.SourceColor;
            bsd.RenderTarget[0].DestinationBlend = BlendOption.BlendFactor;
            bsd.RenderTarget[0].BlendOperation = BlendOperation.Add;
            bsd.RenderTarget[0].SourceAlphaBlend = BlendOption.One;
            bsd.RenderTarget[0].DestinationAlphaBlend = BlendOption.Zero;
            bsd.RenderTarget[0].AlphaBlendOperation = BlendOperation.Add;
            bsd.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;

            var blendStateTransparent = new BlendState(device11, bsd);

            // ---------------------------------------------------------------------------------------------------
            // Create and tesselate an ellipse
            // ---------------------------------------------------------------------------------------------------
            var center = new DrawingPointF(form.ClientSize.Width/2.0f, form.ClientSize.Height/2.0f);
            var ellipse = new EllipseGeometry(factory2D, new Ellipse(center, form.ClientSize.Width / 2.0f, form.ClientSize.Height / 2.0f));

            // Populate a PathGeometry from Ellipse tessellation
            var tesselatedGeometry = new PathGeometry(factory2D);
            _geometrySink = tesselatedGeometry.Open();

            // Force RoundLineJoin otherwise the tesselated looks buggy at line joins
            _geometrySink.SetSegmentFlags(PathSegment.ForceRoundLineJoin);

            // Tesselate the ellipse to our TessellationSink
            ellipse.Tessellate(1, this);

            _geometrySink.Close();

            // ---------------------------------------------------------------------------------------------------
            // Acquire the mutexes. These are needed to assure the device in use has exclusive access to the surface
            // ---------------------------------------------------------------------------------------------------

            var device10Mutex = textureD3D10.QueryInterface<KeyedMutex>();
            var device11Mutex = textureD3D11.QueryInterface<KeyedMutex>();

            // ---------------------------------------------------------------------------------------------------
            // Main rendering loop
            // ---------------------------------------------------------------------------------------------------

            bool first = true;

            RenderLoop
                .Run(form,
                     () =>
                         {
                             if(first)
                             {
                                 form.Activate();
                                 first = false;
                             }

                             // clear the render target to black
                             context.ClearRenderTargetView(renderTargetView, Colors.DarkSlateGray);

                             // Draw the triangle
                             context.InputAssembler.InputLayout = layoutColor;
                             context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                             context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferColor, VertexPositionColor.SizeInBytes, 0));
                             context.OutputMerger.BlendState = null;
                             var currentTechnique = effect.GetTechniqueByName("Color");
                             for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
                             {
                                 using (var effectPass = currentTechnique.GetPassByIndex(pass))
                                 {
                                     System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
                                     effectPass.Apply(context);
                                 }
                                 context.Draw(3, 0);
                             };

                             // Draw Ellipse on the shared Texture2D
                             device10Mutex.Acquire(0, 100);
                             renderTarget2D.BeginDraw();
                             renderTarget2D.Clear(Colors.Black);
                             renderTarget2D.DrawGeometry(tesselatedGeometry, solidColorBrush);
                             renderTarget2D.DrawEllipse(new Ellipse(center, 200, 200), solidColorBrush, 20, null);
                             renderTarget2D.EndDraw();
                             device10Mutex.Release(0);

                             // Draw the shared texture2D onto the screen, blending the 2d content in
                             device11Mutex.Acquire(0, 100);
                             var srv = new ShaderResourceView(device11, textureD3D11);
                             effect.GetVariableByName("g_Overlay").AsShaderResource().SetResource(srv);
                             context.InputAssembler.InputLayout = layoutOverlay;
                             context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
                             context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBufferOverlay, VertexPositionTexture.SizeInBytes, 0));
                             context.OutputMerger.BlendState = blendStateTransparent;
                             currentTechnique = effect.GetTechniqueByName("Overlay");

                             for (var pass = 0; pass < currentTechnique.Description.PassCount; ++pass)
                             {
                                 using (var effectPass = currentTechnique.GetPassByIndex(pass))
                                 {
                                     System.Diagnostics.Debug.Assert(effectPass.IsValid, "Invalid EffectPass");
                                     effectPass.Apply(context);
                                 }
                                 context.Draw(4, 0);
                             }
                             srv.Dispose();
                             device11Mutex.Release(0);

                             swapChain.Present(0, PresentFlags.None);
                         });

            // dispose everything
            vertexBufferColor.Dispose();
            vertexBufferOverlay.Dispose();
            layoutColor.Dispose();
            layoutOverlay.Dispose();
            effect.Dispose();
            shaderByteCode.Dispose();
            renderTarget2D.Dispose();
            swapChain.Dispose();
            device11.Dispose();
            device10.Dispose();
            textureD3D10.Dispose();
            textureD3D11.Dispose();
            factory1.Dispose();
            adapter1.Dispose();
            sharedResource.Dispose();
            factory2D.Dispose();
            surface.Dispose();
            solidColorBrush.Dispose();
            blendStateTransparent.Dispose();

            device10Mutex.Dispose();
            device11Mutex.Dispose();
        }
예제 #8
0
        public void Render(RenderTarget target)
        {
            InitializeResources(target);
            target.Transform = Matrix.Identity;

            target.FillEllipse(new Ellipse(new DrawingPointF(LeftPos.X,LeftPos.Y), 20, 20), Fill);
            target.DrawEllipse(new Ellipse(new DrawingPointF(LeftPos.X, LeftPos.Y), 20, 20), Stroke);

            target.FillEllipse(new Ellipse(new DrawingPointF(RightPos.X, RightPos.Y), 20, 20), Fill);
            target.DrawEllipse(new Ellipse(new DrawingPointF(RightPos.X, RightPos.Y), 20, 20), Stroke);
        }
예제 #9
0
        public static void DrawCircle(this SharpDX.Direct2D1.RenderTarget target, ID2DPen pen, PointF center, float radius)
        {
            var w = radius + radius;

            target.DrawEllipse(pen, center.X - radius, center.Y - radius, w, w);
        }
예제 #10
0
        public static void DrawCircle(this SharpDX.Direct2D1.RenderTarget target, ID2DPen pen, float x, float y, float radius)
        {
            var w = radius + radius;

            target.DrawEllipse(pen, x - radius, y - radius, w, w);
        }
예제 #11
0
        public static void DrawEllipse(this SharpDX.Direct2D1.RenderTarget target, ID2DPen pen, float x, float y, float width, float height)
        {
            var ellipse = new Ellipse(new RawVector2(x + width / 2, y + height / 2), width / 2, height / 2);

            target.DrawEllipse(ellipse, pen.Brush.NativeBrush, pen.StrokeWidth, pen.StrokeStyle);
        }
예제 #12
0
파일: Circle.cs 프로젝트: fxbit/FxMath
        /// <summary>
        /// render the circle to specific render target of Direct2D1
        /// </summary>
        /// <param name="renderTarget"></param>
        public void Render2D( RenderTarget renderTarget , Brush brush)
        {
            // if the brush is dirty renew it
            if ( m_isLineColorBrushDirty ) {
                // clean the color brush
                if ( m_lineColorBrush != null )
                    m_lineColorBrush.Dispose();

                // allocate a new one
                m_lineColorBrush = new SolidColorBrush( renderTarget, m_circleColor );

                // clean the flag
                m_isLineColorBrushDirty = false;
            }

            // check if we use other color
            if ( m_useDefaultColor || m_lineColorBrush == null) {
                renderTarget.DrawEllipse(m_Ellipse, brush);
            } else {
                // draw
                renderTarget.DrawEllipse(m_Ellipse, m_lineColorBrush, m_lineWidth);
            }
        }