示例#1
0
        private void DrawLine(DXMediaBrush brush, double x1, double y1, double x2, double y2, float width, DashStyleHelper dashStyle)
        {
            SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();

            if (dashStyle == DashStyleHelper.Dash)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash;
            }
            if (dashStyle == DashStyleHelper.DashDot)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDot;
            }
            if (dashStyle == DashStyleHelper.DashDotDot)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDotDot;
            }
            if (dashStyle == DashStyleHelper.Dot)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot;
            }
            if (dashStyle == DashStyleHelper.Solid)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid;
            }

            SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(Core.Globals.D2DFactory, ssProps);

            SharpDX.Vector2 startPoint = new System.Windows.Point(x1, y1).ToVector2();
            SharpDX.Vector2 endPoint   = new System.Windows.Point(x2, y2).ToVector2();

            RenderTarget.DrawLine(startPoint, endPoint, brush.DxBrush, width, strokeStyle);

            strokeStyle.Dispose();
            strokeStyle = null;
        }
示例#2
0
        // Condense Line drawing code
        private void DrawLine(string brushName, double x1, double y1, double x2, double y2, float width, DashStyleHelper dashStyle)
        {
            // Create StrokeStyleProperties
            SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();

            // Set StrokeStyleProperties Dashstyle to that of the DashStyleHelper
            if (dashStyle == DashStyleHelper.Dash)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dash;
            }
            if (dashStyle == DashStyleHelper.DashDot)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDot;
            }
            if (dashStyle == DashStyleHelper.DashDotDot)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.DashDotDot;
            }
            if (dashStyle == DashStyleHelper.Dot)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Dot;
            }
            if (dashStyle == DashStyleHelper.Solid)
            {
                ssProps.DashStyle = SharpDX.Direct2D1.DashStyle.Solid;
            }

            // Create StrokeStyle from StrokeStyleProperties
            SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(Core.Globals.D2DFactory, ssProps);

            // Create Vector2 coordinates
            SharpDX.Vector2 startPoint = new System.Windows.Point(x1, y1).ToVector2();
            SharpDX.Vector2 endPoint   = new System.Windows.Point(x2, y2).ToVector2();

            // Draw the line
            RenderTarget.DrawLine(startPoint, endPoint, dxmBrushes[brushName].DxBrush, width, strokeStyle);

            // StrokeStyle is device-independant and does not need to be Disposed after each OnRender() or OnRenderTargetChanged() call, but is for good housekeeping,
            strokeStyle.Dispose();
        }