Esempio n. 1
0
        public override Result DrawStrikethrough(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Strikethrough strikethrough, ComObject clientDrawingEffect)
        {
            PathGeometry pg   = new PathGeometry(this.factory);
            GeometrySink sink = pg.Open();

            Vector2 topLeft = new Vector2(0.0f, strikethrough.Offset);

            sink.BeginFigure(topLeft, FigureBegin.Filled);
            topLeft.X += strikethrough.Width;
            sink.AddLine(topLeft);
            topLeft.Y += strikethrough.Thickness;
            sink.AddLine(topLeft);
            topLeft.X -= strikethrough.Width;
            sink.AddLine(topLeft);
            sink.EndFigure(FigureEnd.Closed);
            sink.Close();


            TransformedGeometry tg = new TransformedGeometry(this.factory, pg, Matrix3x2.Translation(baselineOriginX, baselineOriginY) * Matrix3x2.Scaling(1.0f, -1.0f));

            pg.Dispose();
            sink.Dispose();

            this.AddGeometry(tg);
            return(Result.Ok);
        }
Esempio n. 2
0
        private void RenderingDrawMultiLine(List <float[]> points, int[] color, int thickness, bool drawWorldMap)
        {
            RawVector2[] pts = new RawVector2[points.Count + 1];

            for (int i = 0; i < points.Count; i++)
            {
                int[] screen;
                Helpers.ViewTransform.ToScreen.WorldToScreen(points[i], out screen, drawWorldMap);

                pts[i] = new RawVector2(screen[0], screen[1]);
            }

            pts[pts.Length - 1] = pts[0];

            pathGeometry = new PathGeometry(factory);
            geometrySink = pathGeometry.Open();

            geometrySink.BeginFigure(pts[0], new FigureBegin());
            geometrySink.AddLines(pts);
            geometrySink.EndFigure(new FigureEnd());
            geometrySink.Close();

            ChangeColor(color);

            device.DrawGeometry(pathGeometry, solidColorBrush);

            pathGeometry.Dispose();
            geometrySink.Dispose();
        }
Esempio n. 3
0
        protected override void SetSink(GeometrySink sink)
        {
            sink.SetFillMode(FillMode.Winding);

            sink.BeginFigure(new RawVector2(-35, 85), FigureBegin.Filled);
            sink.AddLine(new RawVector2(60, 85));
            sink.AddBezier(new BezierSegment {
                Point3 = new RawVector2(72, 58), Point1 = new RawVector2(80, 85), Point2 = new RawVector2(82, 58)
            });
            sink.AddBezier(new BezierSegment {
                Point3 = new RawVector2(85, 30), Point1 = new RawVector2(100, 58), Point2 = new RawVector2(95, 30)
            });
            sink.AddBezier(new BezierSegment {
                Point3 = new RawVector2(90, -5), Point1 = new RawVector2(115, 30), Point2 = new RawVector2(115, -5)
            });
            sink.AddBezier(new BezierSegment {
                Point3 = new RawVector2(85, -39), Point1 = new RawVector2(110, -5), Point2 = new RawVector2(105, -39)
            });
            sink.AddLine(new RawVector2(25, -39));
            sink.AddBezier(new BezierSegment {
                Point3 = new RawVector2(-10, -98), Point1 = new RawVector2(35, -105), Point2 = new RawVector2(0, -105)
            });
            sink.AddLine(new RawVector2(-10, -60));
            sink.AddLine(new RawVector2(-35, -16));
            sink.EndFigure(FigureEnd.Closed);

            sink.BeginFigure(new RawVector2(-90, 100), FigureBegin.Filled);
            sink.AddLine(new RawVector2(-48, 100));
            sink.AddLine(new RawVector2(-48, -20));
            sink.AddLine(new RawVector2(-90, -20));
            sink.EndFigure(FigureEnd.Closed);
        }
Esempio n. 4
0
        private void drawUGlyph(float wingLength, float x, float y, float lat, float lng, float width, Brush brush)
        {
            float rotationAngle = (float)Math.Atan((lng - lat) / width) * div;

            //rotationAngle += rotationAngle < 0 ? 90f : 45f;

            this.RenderTarget.Transform = Matrix3x2F.Rotation(rotationAngle, new D2D.Point2F(x, y));

            float hw = WINGLENGTH / 2;

            PathGeometry pLinesGeometry = this.Factory.CreatePathGeometry();
            GeometrySink gs             = pLinesGeometry.Open();

            gs.SetFillMode(FillMode.Winding);

            gs.BeginFigure(new D2D.Point2F(x, y), FigureBegin.Filled);
            gs.AddLine(new D2D.Point2F(x + hw, y + hw));
            gs.AddLine(new D2D.Point2F(x + hw, y - wingLength));
            gs.AddLine(new D2D.Point2F(x, y));
            gs.AddLine(new D2D.Point2F(x - hw, y + hw));
            gs.AddLine(new D2D.Point2F(x - hw, y - wingLength));
            gs.EndFigure(FigureEnd.Closed);

            gs.Close();

            brush.Opacity = 0.2f;
            this.RenderTarget.FillGeometry(pLinesGeometry, brush);

            brush.Opacity = 0.8f;
            this.RenderTarget.DrawGeometry(pLinesGeometry, brush, 0.8f);
            //this.RenderTarget.DrawRectangle(new D2D.RectF(x - RECTSIZE, y - RECTSIZE, x + RECTSIZE, y + RECTSIZE), brush, 0.8f);

            this.RenderTarget.Transform = Matrix3x2F.Identity;
        }
Esempio n. 5
0
        public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)
        {
            Bars bars = chartBars.Bars;

            if (chartBars.FromIndex > 0)
            {
                chartBars.FromIndex--;
            }

            SharpDX.Direct2D1.PathGeometry lineGeometry = new SharpDX.Direct2D1.PathGeometry(Core.Globals.D2DFactory);
            GeometrySink sink = lineGeometry.Open();

            sink.BeginFigure(new Vector2(chartControl.GetXByBarIndex(chartBars, chartBars.FromIndex > -1 ? chartBars.FromIndex : 0), chartScale.GetYByValue(bars.GetClose(chartBars.FromIndex > -1 ? chartBars.FromIndex : 0))), FigureBegin.Filled);

            for (int idx = chartBars.FromIndex + 1; idx <= chartBars.ToIndex; idx++)
            {
                double closeValue = bars.GetClose(idx);
                float  close      = chartScale.GetYByValue(closeValue);
                float  x          = chartControl.GetXByBarIndex(chartBars, idx);
                sink.AddLine(new Vector2(x, close));
            }

            sink.EndFigure(FigureEnd.Open);
            sink.Close();
            AntialiasMode oldAliasMode = RenderTarget.AntialiasMode;

            RenderTarget.AntialiasMode = AntialiasMode.PerPrimitive;
            RenderTarget.DrawGeometry(lineGeometry, UpBrushDX, (float)Math.Max(1, chartBars.Properties.ChartStyle.BarWidth));
            RenderTarget.AntialiasMode = oldAliasMode;
            lineGeometry.Dispose();
        }
Esempio n. 6
0
        /// <summary>
        /// Draw polygon on layer with layerIndex Index.
        /// </summary>
        /// <param name="layerIndex"></param>
        /// <param name="points"></param>
        /// <param name="borderColor"></param>
        /// <param name="fillColor"></param>
        /// <param name="opacity"></param>
        /// <param name="fillPattern"></param>
        /// <param name="patternSize"></param>
        public void Draw(int layerIndex, System.Drawing.PointF[] points, System.Drawing.Color?borderColor, System.Drawing.Color?fillColor, float opacity, xPFT.Charting.Base.FillPattern fillPattern, float patternSize)
        {
            if (layerIndex < device.layers.Count)
            {
                var          tmpGeo       = new PathGeometry(device.factory);
                GeometrySink sink1        = tmpGeo.Open();
                Vector2[]    tmpPointList = DrawingBase.Convertor.ToVector2(points);
                sink1.BeginFigure(tmpPointList[0], new FigureBegin());
                sink1.AddLines(tmpPointList);
                sink1.EndFigure(new FigureEnd());
                sink1.Close();

                if (fillColor != null)
                {
                    if (device.renderTarget != prevRenderTarget || fillColor != prevFillColor || fillPattern != prevFillPattern || opacity != prevOpacity)
                    {
                        fillBrush        = BrushMaker.GetPatternBrush(device.renderTarget, (System.Drawing.Color)fillColor, opacity, fillPattern, patternSize);
                        prevFillColor    = (System.Drawing.Color)fillColor;
                        prevFillPattern  = fillPattern;
                        prevOpacity      = opacity;
                        prevRenderTarget = device.renderTarget;
                    }
                    device.layers[layerIndex].FillGeometry(tmpGeo, fillBrush);
                }
                if (borderColor != null)
                {
                    device.layers[layerIndex].DrawGeometry(tmpGeo, new SharpDX.Direct2D1.SolidColorBrush(device.renderTarget, xPFT.DrawingBase.Convertor.ColorConvertor((System.Drawing.Color)borderColor, opacity)), lineWidth);
                }
            }
        }
Esempio n. 7
0
        public override Result DrawUnderline(object clientDrawingContext, float baselineOriginX, float baselineOriginY, ref Underline underline, ComObject clientDrawingEffect)
        {
            using (PathGeometry pg = new PathGeometry(this.factory))
            {
                using (GeometrySink sink = pg.Open())
                {
                    Vector2 topLeft = new Vector2(0.0f, underline.Offset);
                    sink.BeginFigure(topLeft, FigureBegin.Filled);
                    topLeft.X += underline.Width;
                    sink.AddLine(topLeft);
                    topLeft.Y += underline.Thickness;
                    sink.AddLine(topLeft);
                    topLeft.X -= underline.Width;
                    sink.AddLine(topLeft);
                    sink.EndFigure(FigureEnd.Closed);
                    sink.Close();

                    Matrix3x2           mat = Matrix3x2.Translation(baselineOriginX, baselineOriginY) * Matrix3x2.Scaling(1.0f, -1.0f);
                    TransformedGeometry tg  = new TransformedGeometry(this.factory, pg, *(RawMat *)&mat);

                    this.AddGeometry(tg);
                    return(Result.Ok);
                }
            }
        }
Esempio n. 8
0
 private static void DrawRestDotPart(RenderTarget renderTarget, RawVector2 pos, Color color)
 {
     PointF[] pathPoints;
     using (GraphicsPath path = new GraphicsPath())
     {
         path.AddBezier(pos.X, pos.Y + 3f, pos.X - 2f, pos.Y + 6f, pos.X - 8f, pos.Y + 8f, pos.X - 12f, pos.Y + 2f);
         path.AddBezier((float)(pos.X - 12f), (float)(pos.Y + 2f), (float)(pos.X - 8f), (float)(pos.Y + 6.5f), (float)(pos.X - 2f), (float)(pos.Y + 5f), (float)(pos.X + 1f), (float)(pos.Y - 1f));
         path.Flatten();
         pathPoints = path.PathPoints;
         path.Dispose();
     }
     using (SharpDX.Direct2D1.Factory factory = renderTarget.Factory)
     {
         PathGeometry geometry = new PathGeometry(factory);
         if (pathPoints.Length > 1)
         {
             GeometrySink sink = geometry.Open();
             sink.SetSegmentFlags(PathSegment.ForceRoundLineJoin);
             sink.BeginFigure(new RawVector2(pathPoints[0].X, pathPoints[0].Y), FigureBegin.Filled);
             for (int i = 1; i < pathPoints.Length; i++)
             {
                 sink.AddLine(new RawVector2(pathPoints[i].X, pathPoints[i].Y));
             }
             sink.EndFigure(FigureEnd.Closed);
             sink.Close();
             sink.Dispose();
         }
         SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f));
         renderTarget.FillGeometry(geometry, brush);
         brush.Dispose();
         geometry.Dispose();
     }
     renderTarget.FillCircle(new RawVector2(pos.X - 8f, pos.Y + 2f), 3f, color);
 }
Esempio n. 9
0
        public PathGeometry ToDirect2DPathGeometry(Factory factory, System.Windows.Media.MatrixTransform graphToCanvas)
        {
            double xScale, xOffset, yScale, yOffset;

            xScale  = graphToCanvas.Matrix.M11;
            xOffset = graphToCanvas.Matrix.OffsetX;
            yScale  = graphToCanvas.Matrix.M22;
            yOffset = graphToCanvas.Matrix.OffsetY;

            PathGeometry geometry = new PathGeometry(factory);

            using (GeometrySink sink = geometry.Open())
            {
                float  xCanvas = (float)(xTransformed[0] * xScale + xOffset);
                float  yCanvas = (float)(yTransformed[0] * yScale + yOffset);
                PointF p0      = new PointF(xCanvas, yCanvas);

                sink.BeginFigure(p0, FigureBegin.Hollow);
                for (int i = 1; i < x.Length; ++i)
                {
                    if (includeLinePoint[i])
                    {
                        xCanvas = (float)(xTransformed[i] * xScale + xOffset);
                        yCanvas = (float)(yTransformed[i] * yScale + yOffset);
                        sink.AddLine(new PointF(xCanvas, yCanvas));
                    }
                }
                sink.EndFigure(FigureEnd.Open);
                sink.Close();
            }
            return(geometry);
        }
Esempio n. 10
0
        public void DrawGlyphRun(float baselineOriginX, float baselineOriginY, Graphics.Direct2D.MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ClientDrawingEffect clientDrawingEffect)
        {
            using (PathGeometry pathGeometry = _factory.CreatePathGeometry())
            {
                using (GeometrySink sink = pathGeometry.Open())
                {
                    glyphRun.FontFace.GetGlyphRunOutline(
                        glyphRun.EmSize,
                        glyphRun.GlyphIndices,
                        glyphRun.GlyphAdvances,
                        glyphRun.GlyphOffsets,
                        glyphRun.IsSideways,
                        glyphRun.BidiLevel != 0,
                        sink);
                    sink.Close();
                }

                CustomGeometrySink customSink = new CustomGeometrySink();
                pathGeometry.Stream(customSink);
                customSink.Close();
                System.Diagnostics.Debug.WriteLine(customSink.ToString());

                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(pathGeometry, matrix))
                {
                    _renderTarget.DrawGeometry(_outlineBrush, 5, transformedGeometry);
                    _renderTarget.FillGeometry(_fillBrush, transformedGeometry);
                }
            }
        }
Esempio n. 11
0
        protected void CalculateGeometry(Factory d2dFactory, System.Windows.Rect rect)
        {
            Func <bool, bool, System.Windows.Media.Color, GeometryGroup> buildGeometry = (isFilled, isOk, color) => {
                List <Geometry> geometry = new List <Geometry>();
                if (isOk && Points.Count > 0 && color != System.Windows.Media.Colors.Transparent)
                {
                    var childGeometry = new PathGeometry(d2dFactory);
                    using (GeometrySink ctx = childGeometry.Open()) {
                        for (int pointIndex = 0; pointIndex < Points.Count; pointIndex += 2)
                        {
                            ctx.BeginFigure(Points[pointIndex].ToD2D(), isFilled ? FigureBegin.Filled : FigureBegin.Hollow);
                            ctx.AddLine(Points[pointIndex + 1].ToD2D());
                            ctx.EndFigure(isFilled ? FigureEnd.Closed : FigureEnd.Open);
                        }
                        //  ctx.BeginFigure(Points.First().ToD2D(), isFilled ? FigureBegin.Filled : FigureBegin.Hollow);
                        //foreach (Point point in Points.Skip(1)) {
                        //  ctx.AddLine(point.ToD2D());
                        //}
                        //ctx.EndFigure(isFilled ? FigureEnd.Closed : FigureEnd.Open);
                        ctx.Close();
                    }
                    geometry.Add(childGeometry);
                    return(new GeometryGroup(d2dFactory, FillMode.Winding, geometry.ToArray()));
                }
                return(null);
            };

            _geometryByFactory[d2dFactory.NativePointer] = new GeometryAndFlag(
                buildGeometry(false, LineThickness > 0, LineColor),
                buildGeometry(true, true, LineColor), rect);
        }
Esempio n. 12
0
        /// <summary>
        /// Draws a Polygon.
        /// </summary>
        /// <param name="pen">The Pen.</param>
        /// <param name="polygon">The Polygon.</param>
        public void DrawPolygon(Pen pen, Polygon polygon)
        {
            var dxPen = pen.Instance as DirectXPen;

            if (dxPen == null)
            {
                throw new ArgumentException("DirectX10 expects a DirectXPen as resource.");
            }

            var geometry = new PathGeometry(DirectXHelper.Direct2DFactory);

            using (GeometrySink sink = geometry.Open())
            {
                sink.BeginFigure(DirectXHelper.ConvertVector(polygon.Points[0]), FigureBegin.Hollow);

                for (int i = 1; i < polygon.Points.Length; i++)
                {
                    sink.AddLine(DirectXHelper.ConvertVector(polygon.Points[i]));
                }

                sink.EndFigure(FigureEnd.Closed);
                sink.Close();

                _renderTarget.DrawGeometry(geometry, dxPen.GetPen(), dxPen.Width);
            }

            geometry.Dispose();
        }
Esempio n. 13
0
 public static void FillSector(this RenderTarget renderTarget, RawVector2 pos, float radius, Color color, float angleStart, float angleEnd)
 {
     PointF[] pathPoints;
     using (GraphicsPath path = new GraphicsPath())
     {
         radius *= 2f;
         path.AddPie(pos.X - (radius / 2f), pos.Y - (radius / 2f), radius, radius, angleStart, angleEnd);
         path.Flatten();
         pathPoints = path.PathPoints;
         path.Dispose();
     }
     using (SharpDX.Direct2D1.Factory factory = renderTarget.Factory)
     {
         PathGeometry geometry = new PathGeometry(factory);
         if (pathPoints.Length > 1)
         {
             GeometrySink sink = geometry.Open();
             sink.SetSegmentFlags(PathSegment.ForceRoundLineJoin);
             sink.BeginFigure(new RawVector2(pathPoints[0].X, pathPoints[0].Y), FigureBegin.Filled);
             for (int i = 1; i < pathPoints.Length; i++)
             {
                 sink.AddLine(new RawVector2(pathPoints[i].X, pathPoints[i].Y));
             }
             sink.EndFigure(FigureEnd.Closed);
             sink.Close();
             sink.Dispose();
         }
         SolidColorBrush brush = new SolidColorBrush(renderTarget, color.ToRawColor4(1f));
         renderTarget.FillGeometry(geometry, brush);
         brush.Dispose();
         geometry.Dispose();
     }
 }
Esempio n. 14
0
        private static void DrawArrow(
            GeometrySink sink,
            ReadOnlySpan <ImmutableVec2_float> bezier,
            float arrowSize)
        {
            var b1X = BiaNodeEditorHelper.Bezier(bezier[0].X, bezier[1].X, bezier[2].X, bezier[3].X, 0.5001f);
            var b1Y = BiaNodeEditorHelper.Bezier(bezier[0].Y, bezier[1].Y, bezier[2].Y, bezier[3].Y, 0.5001f);
            var b2X = BiaNodeEditorHelper.Bezier(bezier[0].X, bezier[1].X, bezier[2].X, bezier[3].X, 0.5f);
            var b2Y = BiaNodeEditorHelper.Bezier(bezier[0].Y, bezier[1].Y, bezier[2].Y, bezier[3].Y, 0.5f);

            var sx = b1X - b2X;
            var sy = b1Y - b2Y;
            var r  = MathF.Atan2(sy, sx) + MathF.PI * 0.5f;
            var m  = (MathF.Sin(r), MathF.Cos(r));

            var l1 = new ImmutableVec2_float(arrowSize / 1.732f, arrowSize / 1.732f * 2.0f);
            var l2 = new ImmutableVec2_float(-arrowSize / 1.732f, arrowSize / 1.732f * 2.0f);

            var t1X = (bezier[0].X + bezier[3].X) * 0.5f;
            var t1Y = (bezier[0].Y + bezier[3].Y) * 0.5f;

            var t2 = Rotate(m, l1);
            var t3 = Rotate(m, l2);

            sink.BeginFigure(new RawVector2(t1X, t1Y), FigureBegin.Filled);
            sink.AddLine(new RawVector2(t2.X + t1X, t2.Y + t1Y));
            sink.AddLine(new RawVector2(t3.X + t1X, t3.Y + t1Y));
            sink.EndFigure(FigureEnd.Closed);
        }
Esempio n. 15
0
        /// <summary>
        /// In a derived class, implements logic to initialize the sample.
        /// </summary>
        protected override void OnInitialize()
        {
            DeviceSettings2D settings = new DeviceSettings2D {
                Width  = WindowWidth,
                Height = WindowHeight
            };

            InitializeDevice(settings);
            geometry = new PathGeometry(Context2D.RenderTarget.Factory);
            using (GeometrySink sink = geometry.Open()) {
                PointF p0 = new PointF(0.50f * WindowWidth, 0.25f * WindowHeight);
                PointF p1 = new PointF(0.75f * WindowWidth, 0.75f * WindowHeight);
                PointF p2 = new PointF(0.25f * WindowWidth, 0.75f * WindowHeight);

                sink.BeginFigure(p0, FigureBegin.Filled);
                sink.AddLine(p1);
                sink.AddLine(p2);
                sink.EndFigure(FigureEnd.Closed);

                // Note that Close() and Dispose() are not equivalent like they are for
                // some other IDisposable() objects.
                sink.Close();
            }

            brush = new SolidColorBrush(Context2D.RenderTarget, new Color4(0.93f, 0.40f, 0.08f));
        }
Esempio n. 16
0
        static void addClockwise(RectangleF r, double start, double stop, GeometrySink sink)
        {
            var rx    = r.Width / 2;
            var ry    = r.Height / 2;
            var angle = start;

            // the quality of Direct2D arcs are lousy, so we render them in 16 segments per circle

            const int    MaxSegments  = 16;
            const double SegmentAngle = Math.PI * 2 / MaxSegments;

            for (var segment = 0; angle < stop && segment != MaxSegments; ++segment)
            {
                var angleLeft = stop - angle;
                var angleNow  = Math.Min(SegmentAngle, angleLeft);
                var nextAngle = angle + angleNow;
                var nextPoint = pointOn(r, nextAngle);

                sink.AddArc(new ArcSegment
                {
                    ArcSize        = ArcSize.Small,
                    Size           = new DrawingSizeF(rx, ry),
                    Point          = nextPoint,
                    RotationAngle  = angleNow.import(),
                    SweepDirection = SweepDirection.Clockwise
                });

                angle = nextAngle;
            }
        }
        /// <summary>
        /// Does a one off calculation of the geometry to be rendered
        /// </summary>
        protected void CalculateGeometry(Factory d2dFactory, System.Windows.Rect rect)
        {
            Func <bool, int, PathGeometry> buildGeometry = (bool isFilled, int pointIndex) => {
                PathGeometry childGeometry = new PathGeometry(d2dFactory);
                using (GeometrySink ctx = childGeometry.Open()) {
                    // Break up into groups of 4
                    ctx.BeginFigure(Points[pointIndex].ToD2D(), isFilled ? FigureBegin.Filled : FigureBegin.Hollow);
                    for (int j = 1; j < 4; ++j)
                    {
                        ctx.AddLine(Points[pointIndex + j].ToD2D());
                    }
                    ctx.AddLine(Points[pointIndex].ToD2D());
                    ctx.EndFigure(isFilled ? FigureEnd.Closed : FigureEnd.Open);
                    ctx.Close();
                }
                return(childGeometry);
            };

            List <Geometry> filledGeometry   = new List <Geometry>();
            List <Geometry> unfilledGeometry = new List <Geometry>();

            if (Points.Count > 0)
            {
                for (int pointIndex = 0, colorIndex = 0; pointIndex < (Points.Count - 3); pointIndex += 4, colorIndex += 1)
                {
                    unfilledGeometry.Add(buildGeometry(false, pointIndex));
                    filledGeometry.Add(buildGeometry(true, pointIndex));
                }
            }
            _geometryByFactory[d2dFactory.NativePointer] = new GeometryAndFlag(unfilledGeometry, filledGeometry, rect);
        }
        protected GeometrySink CreateSectionSweepGeometry()
        {
            //扇形的X轴Y轴半径是矩形框width的一半
            SizeF size = new SizeF(displayer.coordinateSystem.CoordinateArea.Width / 2, height: displayer.coordinateSystem.CoordinateArea.Height / 2);

            _pie = displayer.Factory.CreatePathGeometry();   //扇形区域

            //开始合成扇形
            GeometrySink gs = _pie.Open();

            gs.BeginFigure(displayer.coordinateSystem.OriginalPoint, FigureBegin.Filled);

            //添加第一条线
            gs.AddLine(BeginLinePoint);   //原始代码

            //添加弧线
            ArcSegment arc = new ArcSegment(EndLinePoint, size, 0, SweepDirection.Clockwise, ArcSize.Small);

            gs.AddArc(arc);

            //添加第二条线
            gs.AddLine(displayer.coordinateSystem.OriginalPoint);
            gs.EndFigure(FigureEnd.Closed);
            gs.Close();

            return(gs);
        }
Esempio n. 19
0
            public override Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
            {
                using (PathGeometry path = new PathGeometry(renderer.factory2d))
                {
                    using (GeometrySink sink = path.Open())
                    {
                        glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.Advances.Length, glyphRun.IsSideways, (glyphRun.BidiLevel % 2) > 0, sink);
                        sink.Close();
                    }

                    var matrix = new Matrix3x2()
                    {
                        M11 = 1,
                        M12 = 0,
                        M21 = 0,
                        M22 = 1,
                        M31 = baselineOriginX,
                        M32 = baselineOriginY
                    };

                    TransformedGeometry transformedGeometry = new TransformedGeometry(renderer.factory2d, path, matrix);
                    renderer.rtv2d.DrawGeometry(transformedGeometry, renderer.brush2dOutline);
                    Utilities.Dispose(ref transformedGeometry);
                }

                return(new Result());
            }
Esempio n. 20
0
        Geometry CreateCheckGeometry0(D2DGraphics g)
        {
            RectangleF rect = new RectangleF(0, Height, Width, Height);
            float      w    = rect.Width / 2;
            float      h    = rect.Height / 4;

            PathGeometry pathGeometry = new PathGeometry(D2DGraphics.d2dFactory);

            GeometrySink pSink = null;

            pSink = pathGeometry.Open();
            pSink.SetFillMode(SharpDX.Direct2D1.FillMode.Winding);

            pSink.BeginFigure(new RawVector2(rect.Left, rect.Top), FigureBegin.Filled);



            RawVector2[] points =
            {
                new RawVector2(rect.Left + w,  rect.Top + h * 2),
                new RawVector2(rect.Right + w, rect.Top - h * 2),
                new RawVector2(rect.Left + w,  rect.Bottom),
            };

            pSink.AddLines(points);
            pSink.EndFigure(FigureEnd.Closed);
            pSink.Close();
            pSink.Dispose();

            return(pathGeometry);
        }
Esempio n. 21
0
        Geometry CreateCheckGeometry1(D2DGraphics g)
        {
            RectangleF rect = new RectangleF(FillMargin.left, FillMargin.top, Width - FillMargin.right - FillMargin.left, Height - FillMargin.bottom - FillMargin.top);

            float w  = rect.Width / 2;
            float h2 = rect.Height / 2;
            float h4 = rect.Height / 4f;

            PathGeometry pathGeometry = new PathGeometry(D2DGraphics.d2dFactory);

            GeometrySink pSink = null;

            pSink = pathGeometry.Open();
            pSink.SetFillMode(SharpDX.Direct2D1.FillMode.Winding);

            pSink.BeginFigure(new RawVector2(rect.Left, rect.Top + h2), FigureBegin.Filled);



            RawVector2[] points =
            {
                new RawVector2(rect.Left + w - w / 10, rect.Top + h4 * 2.7f),
                new RawVector2(rect.Right,             rect.Top),
                new RawVector2(rect.Left + w,          rect.Bottom),
            };

            pSink.AddLines(points);
            pSink.EndFigure(FigureEnd.Closed);
            pSink.Close();
            pSink.Dispose();

            return(pathGeometry);
        }
Esempio n. 22
0
        public void DrawShip(RenderTarget D2DRT, SolidColorBrush scb, Factory d2dFactory)
        {
            PathGeometry shape = new PathGeometry(d2dFactory);
            GeometrySink sink  = shape.Open();

            //Ship Front
            sink.BeginFigure(new Vector2((float)X + direction.X * 20, (float)Y - direction.Y * 20), FigureBegin.Hollow);

            //Calculating Ship Right Wing by rotating unit vector 90 degrees
            float rwX = (float)(direction.X * 0 - direction.Y * -1);
            float rwY = (float)(direction.X * 1 + direction.Y * 0);

            sink.AddLine(new Vector2(X + rwX * 7, Y + rwY * 7));

            //Calculating Ship Left Wing by rotating unit vector 270 degrees
            float lwX = (float)(direction.X * 0 - direction.Y * 1);
            float lwY = (float)(direction.X * -1 + direction.Y * 0);

            sink.AddLine(new Vector2(X + lwX * 7, Y - rwY * 7));

            sink.EndFigure(FigureEnd.Closed);
            sink.Close();
            D2DRT.DrawGeometry(shape, scb, 1f);

            //draw a line that is 10 times the length of the unit vector ship.direction
            D2DRT.DrawLine(new Vector2(X, Y), new Vector2(X + direction.X * 10, Y - direction.Y * 10), scb);
            edgePoints = new List <Vector2>();
            edgePoints.Add(new Vector2((float)X + direction.X * 20, (float)(Y - direction.Y * 20)));
            edgePoints.Add(new Vector2(X + lwX * 7, Y - rwY * 7));
            edgePoints.Add(new Vector2(X + lwX * 7, Y - rwY * 7));

            shape.Dispose();
            sink.Dispose();
        }
        /// <summary>
        /// 根据当前的路径生成几何组。
        /// </summary>
        /// <param name="factory">Direct2D 工厂。</param>
        /// <returns>生成的几何组。</returns>
        public GeometryGroup GetGeometryGroup(Factory factory)
        {
            Geometry[]   geometries = new Geometry[this.figureCount];
            PathGeometry path       = new PathGeometry(factory);
            GeometrySink sink       = path.Open();

            sink.SetFillMode(FillMode.Winding);
            sink.BeginFigure(this.StartPoint, FigureBegin.Filled);
            int cnt = this.Count;
            int idx = 0;

            for (int i = 0; i < cnt; i++)
            {
                EndFigureSegment end = this[i] as EndFigureSegment;
                if (end == null)
                {
                    this[i].FillGeometry(sink);
                }
                else
                {
                    sink.EndFigure(FigureEnd.Closed);
                    sink.Close();
                    geometries[idx++] = path;
                    path = new PathGeometry(factory);
                    sink = path.Open();
                    sink.SetFillMode(FillMode.Winding);
                    sink.BeginFigure(end.EndPoint, FigureBegin.Filled);
                }
            }
            sink.EndFigure(FigureEnd.Closed);
            sink.Close();
            geometries[idx++] = path;
            return(new GeometryGroup(factory, FillMode.Winding, geometries));
        }
Esempio n. 24
0
        protected override void SetSink(GeometrySink sink)
        {
            sink.SetFillMode(FillMode.Winding);

            sink.BeginFigure(new RawVector2(0, 100), FigureBegin.Filled);
            sink.AddBeziers(new[] {
                new BezierSegment {
                    Point3 = new RawVector2(100, -40), Point1 = new RawVector2(0, 100), Point2 = new RawVector2(100, 20)
                },
                new BezierSegment {
                    Point3 = new RawVector2(50, -100), Point1 = new RawVector2(100, -75), Point2 = new RawVector2(75, -100)
                },
                new BezierSegment {
                    Point3 = new RawVector2(0, -50), Point1 = new RawVector2(25, -100), Point2 = new RawVector2(0, -75)
                },
                new BezierSegment {
                    Point3 = new RawVector2(-50, -100), Point1 = new RawVector2(0, -75), Point2 = new RawVector2(-25, -100)
                },
                new BezierSegment {
                    Point3 = new RawVector2(-100, -40), Point1 = new RawVector2(-75, -100), Point2 = new RawVector2(-100, -75)
                },
                new BezierSegment {
                    Point3 = new RawVector2(0, 100), Point1 = new RawVector2(-100, 20), Point2 = new RawVector2(0, 100)
                }
            });
            sink.EndFigure(FigureEnd.Closed);
        }
Esempio n. 25
0
        protected override Geometry CreateHitGeometryByD2D(D2DGraphics g)
        {
            RectangleF rect = new RectangleF(0, 0, Width, Height);

            PathGeometry pathGeometry = new PathGeometry(D2DGraphics.d2dFactory);

            GeometrySink pSink = null;

            pSink = pathGeometry.Open();
            pSink.SetFillMode(SharpDX.Direct2D1.FillMode.Winding);

            pSink.BeginFigure(new RawVector2(rect.Left, rect.Bottom), FigureBegin.Filled);

            float len = gradientSize;

            RawVector2[] points =
            {
                new RawVector2(rect.Left + len,  rect.Top),
                new RawVector2(rect.Right - len, rect.Top),
                new RawVector2(rect.Right,       rect.Bottom),
            };

            pSink.AddLines(points);
            pSink.EndFigure(FigureEnd.Closed);
            pSink.Close();
            pSink.Dispose();

            return(pathGeometry);
        }
Esempio n. 26
0
        void FillItemGeometry(D2DGraphics g)
        {
            RectangleF rect = new RectangleF(0, 0, Width, Height);

            PathGeometry pathGeometry = new PathGeometry(D2DGraphics.d2dFactory);

            GeometrySink pSink = null;

            pSink = pathGeometry.Open();
            pSink.SetFillMode(SharpDX.Direct2D1.FillMode.Winding);

            pSink.BeginFigure(new RawVector2(rect.Left, rect.Bottom), FigureBegin.Filled);

            float len = gradientSize;

            RawVector2[] points =
            {
                new RawVector2(rect.Left + len,  rect.Top),
                new RawVector2(rect.Right - len, rect.Top),
                new RawVector2(rect.Right,       rect.Bottom),
            };

            pSink.AddLines(points);
            pSink.EndFigure(FigureEnd.Closed);
            pSink.Close();
            pSink.Dispose();

            RawColor4       rawColor = GDIDataD2DUtils.TransToRawColor4(color);
            SolidColorBrush brush    = new SolidColorBrush(g.RenderTarget, rawColor);

            g.RenderTarget.FillGeometry(pathGeometry, brush);
        }
Esempio n. 27
0
        public override Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect)
        {
            using (PathGeometry path = new PathGeometry(_factory))
                using (GeometrySink sink = path.Open())
                {
                    glyphRun.FontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, false, sink);
                    sink.Close();

                    var translation = Matrix3x2.Translation(baselineOriginX, baselineOriginY);
                    var outline     = new TransformedGeometry(_factory, path, translation);
                    using (var strokeStyle = new StrokeStyle(_factory, new StrokeStyleProperties {
                        LineJoin = LineJoin.Round
                    }))
                    {
                        for (int i = 1; i < 8; i++)
                        {
                            var color = Color.White;
                            color.A /= (byte)Math.Ceiling(i / 1.5);
                            using (var brush = new SolidColorBrush(_surface, color))
                            {
                                _surface.DrawGeometry(outline, brush, i, strokeStyle);
                            }
                        }
                    }
                }

            return(new Result());
        }
Esempio n. 28
0
        private void DrawFDEBBeziers(float width, float height)
        {
            float[] t;
            for (int i = 0, j = _pt.GetLength(1); i < _pt.GetLength(0); i++)
            {
                PathGeometry pLinesGeometry = this.Factory.CreatePathGeometry();
                GeometrySink gs             = pLinesGeometry.Open();
                gs.SetFillMode(FillMode.Winding);

                gs.BeginFigure(new D2D.Point2F(_pt[i, 0, 0], _pt[i, 0, 1]), FigureBegin.Hollow);
                gs.AddBezier(
                    new BezierSegment(
                        new Point2F(_pt[i, (int)((j - 1) * 0.33), 0], _pt[i, (int)((j - 1) * .33), 1]),
                        new Point2F(_pt[i, (int)((j - 1) * 0.66), 0], _pt[i, (int)((j - 1) * .66), 1]),
                        new Point2F(_pt[i, (int)(j - 1), 0], _pt[i, (int)(j - 1), 1])
                        )
                    );
                gs.EndFigure(FigureEnd.Open);
                gs.Close();
                this.RenderTarget.DrawGeometry(pLinesGeometry, neutralBrush, 1f);

                foreach (Story s in _st)
                {
                    t = s.GetLocationLines();
                    if ((int)_pt[i, 0, 1] == (int)t[0] && (int)_pt[i, (int)(j - 1), 1] == (int)t[1])
                    {
                        PointAndTangent   pt = pLinesGeometry.ComputePointAtLength(s.GetEventLocation()[0]);
                        RectangleGeometry pEventsGeometry = this.Factory.CreateRectangleGeometry(
                            new D2D.RectF(pt.Point.X - RECTSIZE, pt.Point.Y - RECTSIZE, pt.Point.X + RECTSIZE, pt.Point.Y + RECTSIZE)
                            );
                        this.RenderTarget.DrawGeometry(pEventsGeometry, brushes[s.GetLabel()], 0.8f);
                    }
                }
            }
        }
        protected void CalculateGeometry(Factory d2dFactory, System.Windows.Rect rect)
        {
            if (_strokeStyle == null)
            {
                StrokeStyleProperties porps = new StrokeStyleProperties();
                porps.LineJoin = LineJoin.Bevel;
                _strokeStyle   = new StrokeStyle(d2dFactory, porps);
            }

            Func <bool, bool, System.Windows.Media.Color, GeometryGroup> buildGeometry = (isFilled, isOk, color) => {
                List <Geometry> geometry = new List <Geometry>();
                if (isOk && Points.Count > 0 && color != System.Windows.Media.Colors.Transparent)
                {
                    var childGeometry = new PathGeometry(d2dFactory);
                    using (GeometrySink ctx = childGeometry.Open()) {
                        ctx.BeginFigure(Points.First().ToD2D(), isFilled ? FigureBegin.Filled : FigureBegin.Hollow);
                        foreach (Point point in Points.Skip(1))
                        {
                            ctx.AddLine(point.ToD2D());
                        }
                        ctx.EndFigure(isFilled ? FigureEnd.Closed : FigureEnd.Open);
                        ctx.Close();
                    }
                    geometry.Add(childGeometry);
                    return(new GeometryGroup(d2dFactory, FillMode.Winding, geometry.ToArray()));
                }
                return(null);
            };

            _geometryByFactory[d2dFactory.NativePointer] = new GeometryAndFlag(
                buildGeometry(false, LineThickness > 0, LineColor),
                buildGeometry(true, true, FillColor), rect);
        }
Esempio n. 30
0
        static void AddRect(GeometrySink pSink, RawRectangleF rect, float r)
        {
            ArcSegment arcSeg = new ArcSegment();

            arcSeg.ArcSize        = ArcSize.Small;
            arcSeg.Point          = new RawVector2(rect.Left + r, rect.Top);
            arcSeg.RotationAngle  = 90;
            arcSeg.Size           = new Size2F(r, r);
            arcSeg.SweepDirection = SweepDirection.Clockwise;
            pSink.AddArc(arcSeg);

            pSink.AddLine(new RawVector2(rect.Right - r, rect.Top));

            //
            arcSeg.Point = new RawVector2(rect.Right, rect.Top + r);
            pSink.AddArc(arcSeg);
            pSink.AddLine(new RawVector2(rect.Right, rect.Bottom - r));


            //
            arcSeg.Point = new RawVector2(rect.Right - r, rect.Bottom);
            pSink.AddArc(arcSeg);
            pSink.AddLine(new RawVector2(rect.Left + r, rect.Bottom));

            arcSeg.Point = new RawVector2(rect.Left, rect.Bottom - r);
            pSink.AddArc(arcSeg);
            pSink.AddLine(new RawVector2(rect.Left, rect.Top + r));
        }
Esempio n. 31
0
        public void BeginModify(FillMode fillmode)
        {
            if(m_geometryFilled)
                CreatePathGeometry();

            m_geometrySink = m_pathGeometry.Open();
            m_geometrySink.SetFillMode((SlimDX.Direct2D.FillMode)fillmode);
        }
Esempio n. 32
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && m_sink != null)
     {
         m_sink.Dispose();
         m_sink = null;
     }
     base.Dispose(disposing);
 }
		/// <summary>
		/// 使用当前的路径填充指定的路径几何。
		/// </summary>
		/// <param name="sink">要填充的路径几何。</param>
		public override void FillGeometry(GeometrySink sink)
		{
			D2D1.BezierSegment bezier = new D2D1.BezierSegment()
			{
				Point1 = this.Point1,
				Point2 = this.Point2,
				Point3 = this.EndPoint
			};
			sink.AddBezier(bezier);
		}
Esempio n. 34
0
		/// <summary>
		/// 使用当前的路径填充指定的路径几何。
		/// </summary>
		/// <param name="sink">要填充的路径几何。</param>
		public override void FillGeometry(GeometrySink sink)
		{
			D2D1.ArcSegment arc = new D2D1.ArcSegment()
			{
				Point = EndPoint,
				Size = Size,
				RotationAngle = RotationAngle,
				SweepDirection = SweepDirection,
				ArcSize = ArcSize
			};
			sink.AddArc(arc);
		}
Esempio n. 35
0
        public void Build(Shape shape, out DxGeometry result)
        {
            Contract.Requires(shape != null);
            Contract.Ensures(Contract.ValueAtReturn(out result) != null);

            try
            {
                shape.ExtractTo(this);
            }
            finally
            {
                result = _Path;

                _PathSink = null;
                _Path = null;
            }
        }
Esempio n. 36
0
        protected override void Initialize(DemoConfiguration demoConfiguration)
        {
            base.Initialize(demoConfiguration);

            // Create an ellipse
            Ellipse = new EllipseGeometry(Factory2D,
                                          new Ellipse(new Vector2(demoConfiguration.Width/2, demoConfiguration.Height/2), demoConfiguration.Width/2 - 100,
                                                      demoConfiguration.Height/2 - 100));

            // Populate a PathGeometry from Ellipse tessellation 
            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);

            // Close the GeometrySink
            GeometrySink.Close();
        }
		/// <summary>
		/// 使用当前的路径填充指定的路径几何。
		/// </summary>
		/// <param name="sink">要填充的路径几何。</param>
		public override void FillGeometry(GeometrySink sink)
		{
			sink.EndFigure(FigureEnd.Closed);
			sink.BeginFigure(EndPoint, FigureBegin.Filled);
		}
        char _token;             // Non whitespace character returned by ReadToken




        public PathGeometry parse(string path, Factory1 d2dfactory)
        {
            _factory = d2dfactory;

            _pathGeometry = new PathGeometry(d2dfactory);
            _figure = _pathGeometry.Open();
            //GeometrySink _sink  = _pathGeometry.Open();

            _formatProvider = CultureInfo.InvariantCulture;
            _pathString = path;
            _pathLength = path.Length;
            _curIndex = 0;

            _secondLastPoint = new Point(0, 0);
            _lastPoint = new Point(0, 0);
            _lastStart = new Point(0, 0);

            _figureStarted = false;

            bool first = true;

            char last_cmd = ' ';

            while (ReadToken()) // Empty path is allowed in XAML
            {
                char cmd = _token;

                if (first)
                {
                    if ((cmd != 'M') && (cmd != 'm'))  // Path starts with M|m 
                    {
                        ThrowBadToken();
                    }

                    first = false;
                }

                switch (cmd)
                {
                    case 'm':
                    case 'M':
                        // XAML allows multiple points after M/m
                        _lastPoint = ReadPoint(cmd, !AllowComma);


                        _figure.BeginFigure(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y), IsFilled ? FigureBegin.Filled : FigureBegin.Hollow);
                        //_figure.StartPoint = _lastPoint;
                        //_figure.IsFilled = IsFilled;
                        //if (!IsClosed) _figure.Close();
                        //_figure.IsClosed = !IsClosed;
                        //context.BeginFigure(_lastPoint, IsFilled, !IsClosed);
                        _figureStarted = true;
                        _lastStart = _lastPoint;
                        last_cmd = 'M';

                        while (IsNumber(AllowComma))
                        {
                            _lastPoint = ReadPoint(cmd, !AllowComma);

                            //LineSegment _lineSegment = new LineSegment();
                            //_lineSegment.Point = _lastPoint;
                            _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y));
                            //_figure.Segments.Add(_lineSegment);
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                            last_cmd = 'L';
                        }
                        break;

                    case 'l':
                    case 'L':
                    case 'h':
                    case 'H':
                    case 'v':
                    case 'V':
                        EnsureFigure();

                        do
                        {
                            switch (cmd)
                            {
                                case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'h': _lastPoint.X += ReadNumber(!AllowComma); break;
                                case 'H': _lastPoint.X = ReadNumber(!AllowComma); break;
                                case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break;
                                case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break;
                            }

                            //LineSegment _lineSegment = new LineSegment();
                            //_lineSegment.Point = _lastPoint;
                            //_figure.Segments.Add(_lineSegment);
                            _figure.AddLine(new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y));
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                        }
                        while (IsNumber(AllowComma));

                        last_cmd = 'L';
                        break;

                    case 'c':
                    case 'C': // cubic Bezier 
                    case 's':
                    case 'S': // smooth cublic Bezier
                        EnsureFigure();

                        do
                        {
                            Point p;

                            if ((cmd == 's') || (cmd == 'S'))
                            {
                                if (last_cmd == 'C')
                                {
                                    p = Reflect();
                                }
                                else
                                {
                                    p = _lastPoint;
                                }

                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                p = ReadPoint(cmd, !AllowComma);

                                _secondLastPoint = ReadPoint(cmd, AllowComma);
                            }

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            //BezierSegment _bizierSegment = new BezierSegment();
                            //_bizierSegment.Point1 = p;
                            //_bizierSegment.Point2 = _secondLastPoint;
                            //_bizierSegment.Point3 = _lastPoint;
                            //_figure.Segments.Add(_bizierSegment);
                            _figure.AddBezier(new BezierSegment()
                            {
                                Point1 = new SharpDX.Vector2((float)p.X, (float)p.Y),
                                Point2 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y),
                                Point3 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)
                            });
                            //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            last_cmd = 'C';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'q':
                    case 'Q': // quadratic Bezier 
                    case 't':
                    case 'T': // smooth quadratic Bezier
                        EnsureFigure();

                        do
                        {
                            if ((cmd == 't') || (cmd == 'T'))
                            {
                                if (last_cmd == 'Q')
                                {
                                    _secondLastPoint = Reflect();
                                }
                                else
                                {
                                    _secondLastPoint = _lastPoint;
                                }

                                _lastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                                _lastPoint = ReadPoint(cmd, AllowComma);
                            }

                            //QuadraticBezierSegment _quadraticBezierSegment = new QuadraticBezierSegment();
                            //_quadraticBezierSegment.Point1 = _secondLastPoint;
                            //_quadraticBezierSegment.Point2 = _lastPoint;
                            //_figure.Segments.Add(_quadraticBezierSegment);
                            _figure.AddQuadraticBezier(new QuadraticBezierSegment()
                            {
                                Point1 = new SharpDX.Vector2((float)_secondLastPoint.X, (float)_secondLastPoint.Y),
                                Point2 = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y)
                            });
                            //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            last_cmd = 'Q';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'a':
                    case 'A':
                        EnsureFigure();

                        do
                        {
                            // A 3,4 5, 0, 0, 6,7
                            double w = ReadNumber(!AllowComma);
                            double h = ReadNumber(AllowComma);
                            double rotation = ReadNumber(AllowComma);
                            bool large = ReadBool();
                            bool sweep = ReadBool();

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            //ArcSegment _arcSegment = new ArcSegment();
                            //_arcSegment.Point = _lastPoint;
                            //_arcSegment.Size = new Size(w, h);
                            //_arcSegment.RotationAngle = rotation;
                            //_arcSegment.IsLargeArc = large;
                            //_arcSegment.SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                            //_figure.Segments.Add(_arcSegment);

                            _figure.AddArc(new ArcSegment()
                            {
                                Point = new SharpDX.Vector2((float)_lastPoint.X, (float)_lastPoint.Y),
                                Size = new SharpDX.Size2F((float)w, (float)h),
                                RotationAngle = (float)rotation,
                                ArcSize = large ? ArcSize.Large : ArcSize.Small,
                                SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.CounterClockwise
                            });
                            //context.ArcTo(
                            //    _lastPoint,
                            //    new Size(w, h),
                            //    rotation,
                            //    large,
                            //    sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise,
                            //    IsStroked,
                            //    !IsSmoothJoin
                            //    );
                        }
                        while (IsNumber(AllowComma));

                        last_cmd = 'A';
                        break;

                    case 'z':
                    case 'Z':
                        EnsureFigure();



                        //_figure.IsClosed = IsClosed;
                        //context.SetClosedState(IsClosed);
                        _figure.EndFigure(IsClosed ? FigureEnd.Closed : FigureEnd.Open);
                        _figureStarted = false;
                        last_cmd = 'Z';

                        _lastPoint = _lastStart; // Set reference point to be first point of current figure
                        break;

                    default:
                        ThrowBadToken();
                        break;
                }
            }

            //if (null != _figure)
            //{
            //    _pathGeometry = new PathGeometry(d2dfactory);
            //    _pathGeometry.Figures.Add(_figure);

            //}

            _figure.Close();
            //_sink.Close();


            return _pathGeometry;
        }
 public GeometrySinkFigureTarget(GeometrySink sink)
 {
     _sink = sink;
 }
Esempio n. 40
0
 /// <summary>	
 /// Combines this geometry with the specified geometry and stores the result in an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/>.  	
 /// </summary>	
 /// <param name="inputGeometry">The geometry to combine with this instance.</param>
 /// <param name="combineMode">The type of combine operation to perform.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometries. Smaller values produce more accurate results but cause slower execution. </param>
 /// <param name="geometrySink">The result of the combine operation.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT CombineWithGeometry([In] ID2D1Geometry* inputGeometry,[None] D2D1_COMBINE_MODE combineMode,[In, Optional] const D2D1_MATRIX_3X2_F* inputGeometryTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Combine(SharpDX.Direct2D1.Geometry inputGeometry, SharpDX.Direct2D1.CombineMode combineMode, float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Combine(inputGeometry, combineMode, null, flatteningTolerance, geometrySink);
 }
Esempio n. 41
0
 /// <summary>	
 /// Widens the geometry by the specified stroke and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> after it has been transformed by the specified matrix and flattened using the specified tolerance.	
 /// </summary>	
 /// <param name="strokeWidth">The amount by which to widen the geometry.</param>
 /// <param name="strokeStyle">The style of stroke to apply to the geometry, or NULL.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution.</param>
 /// <param name="geometrySink">The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the widened geometry is appended.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Widen([None] FLOAT strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Widen(float strokeWidth, SharpDX.Direct2D1.StrokeStyle strokeStyle, float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Widen(strokeWidth, strokeStyle, null, flatteningTolerance, geometrySink);
 }
Esempio n. 42
0
 /// <summary>	
 /// Computes the outline of the geometry and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/>.	
 /// </summary>	
 /// <remarks>	
 /// The {{Outline}} method allows the caller to produce a geometry with an equivalent fill to the input geometry, with the following additional properties: The output geometry contains no transverse intersections; that is, segments may touch, but they never cross.The outermost figures in the output geometry are all oriented counterclockwise. The output geometry is fill-mode invariant; that is, the fill of the geometry does not depend on the choice of the fill mode. For more information about the fill mode, see <see cref="SharpDX.Direct2D1.FillMode"/>.Additionally, the  {{Outline}} method can be useful in removing redundant portions of said geometries to simplify complex geometries. It can also be useful in combination with <see cref="SharpDX.Direct2D1.GeometryGroup"/> to create unions among several geometries simultaneously.	
 /// </remarks>	
 /// <param name="worldTransform">The transform to apply to the geometry outline, or NULL.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. </param>
 /// <param name="geometrySink">The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the geometry's transformed outline is appended. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Outline([In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Outline(RawMatrix3x2? worldTransform, float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Outline_(worldTransform, flatteningTolerance, GeometrySinkShadow.ToIntPtr(geometrySink));
 }
Esempio n. 43
0
 /// <summary>	
 /// Computes the outline of the geometry and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/>.	
 /// </summary>	
 /// <remarks>	
 /// The {{Outline}} method allows the caller to produce a geometry with an equivalent fill to the input geometry, with the following additional properties: The output geometry contains no transverse intersections; that is, segments may touch, but they never cross.The outermost figures in the output geometry are all oriented counterclockwise. The output geometry is fill-mode invariant; that is, the fill of the geometry does not depend on the choice of the fill mode. For more information about the fill mode, see <see cref="SharpDX.Direct2D1.FillMode"/>.Additionally, the  {{Outline}} method can be useful in removing redundant portions of said geometries to simplify complex geometries. It can also be useful in combination with <see cref="SharpDX.Direct2D1.GeometryGroup"/> to create unions among several geometries simultaneously.	
 /// </remarks>	
 /// <param name="geometrySink">The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the geometry's transformed outline is appended. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Outline([In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Outline(GeometrySink geometrySink)
 {
     this.Outline(null, FlatteningTolerance, geometrySink);
 }
        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();
        }
Esempio n. 45
0
 /// <summary>
 /// Get a native callback pointer from a managed callback.
 /// </summary>
 /// <param name="geometrySink">The geometry sink.</param>
 /// <returns>A pointer to the unmanaged geometry sink counterpart</returns>
 public static IntPtr ToIntPtr(GeometrySink geometrySink)
 {
     return ToCallbackPtr<GeometrySink>(geometrySink);
 }
Esempio n. 46
0
 /// <summary>	
 /// Copies the contents of the path geometry to the specified <see cref="SharpDX.Direct2D1.GeometrySink"/>.	
 /// </summary>	
 /// <param name="geometrySink">The sink to which the path geometry's contents are copied. Modifying this sink does not change the contents of this path geometry.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Stream([In] ID2D1GeometrySink* geometrySink)</unmanaged>
 public void Stream(GeometrySink geometrySink)
 {
     this.Stream_(GeometrySinkShadow.ToIntPtr(geometrySink));
 }
Esempio n. 47
0
        public override void Load( CanvasRenderArguments args )
        {
            // dispose the prev geometry
            if ( meshGeo != null )
                meshGeo.Dispose();
            if (meshGeo_Color != null)
                meshGeo_Color.Dispose();
            if (lineBrush_Color != null)
                lineBrush_Color.Dispose();
            if (lineBrush != null)
                lineBrush.Dispose();

            // init the lines brushs
            lineBrush = new SolidColorBrush(args.renderTarget, LineColor);

            // init the lines brushs
            lineBrush_Color = new SolidColorBrush(args.renderTarget, new Color4(0.98f, 0.99f, 0.09f, 1.0f));

            // init the geometryes
            meshGeo = new PathGeometry( args.factory );

            // fill the mesh geo
            meshGeo_Sink = meshGeo.Open();

            // init the geometryes
            meshGeo_Color = new PathGeometry(args.factory);

            // fill the mesh geo
            meshGeo_Sink_Color = meshGeo_Color.Open();

            // draw all the faces
            mesh.FaceFunctionExec(new FaceFunction(DrawFace));

            // close the geo
            meshGeo_Sink.Close();

            // free the memory for the sink
            meshGeo_Sink.Dispose();

            // close the geo
            meshGeo_Sink_Color.Close();

            // free the memory for the sink
            meshGeo_Sink_Color.Dispose();

            IsGeomrtryDirty = false;
        }
Esempio n. 48
0
 internal D2dGeometrySink(GeometrySink sink)
 {
     m_sink = sink;
 }
Esempio n. 49
0
		/// <summary>
		/// 使用当前的路径填充指定的路径几何。
		/// </summary>
		/// <param name="sink">要填充的路径几何。</param>
		public abstract void FillGeometry(GeometrySink sink);
Esempio n. 50
0
 /// <summary>	
 /// Creates a simplified version of the geometry that contains only lines and (optionally) cubic Bezier curves and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/>.	
 /// </summary>	
 /// <param name="simplificationOption">A value that specifies whether the simplified geometry should contain curves.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. </param>
 /// <param name="geometrySink"> The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the simplified geometry is appended. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Simplify([None] D2D1_GEOMETRY_SIMPLIFICATION_OPTION simplificationOption,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Simplify(SharpDX.Direct2D1.GeometrySimplificationOption simplificationOption, float flatteningTolerance, GeometrySink geometrySink)
 {
     Simplify(simplificationOption, null, flatteningTolerance, geometrySink);
 }
Esempio n. 51
0
 /// <summary>	
 /// Creates a simplified version of the geometry that contains only lines and (optionally) cubic Bezier curves and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/>.	
 /// </summary>	
 /// <param name="simplificationOption">A value that specifies whether the simplified geometry should contain curves.</param>
 /// <param name="worldTransform">The transform to apply to the simplified geometry, or NULL.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. </param>
 /// <param name="geometrySink"> The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the simplified geometry is appended. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Simplify([None] D2D1_GEOMETRY_SIMPLIFICATION_OPTION simplificationOption,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Simplify(SharpDX.Direct2D1.GeometrySimplificationOption simplificationOption, SharpDX.Matrix3x2? worldTransform, float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Simplify_(simplificationOption, worldTransform, flatteningTolerance, GeometrySinkShadow.ToIntPtr(geometrySink));
 }
Esempio n. 52
0
        void IGeometrySink.Begin()
        {
            Contract.Assert(_Path == null);

            _Path = new PathGeometry(_Factory2D);

            _IsSinkInFigure = false;

            Contract.Assert(_PathSink == null);

            _PathSink = _Path.Open();
        }
Esempio n. 53
0
 /// <summary>	
 /// Computes the outline of the geometry and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/>.	
 /// </summary>	
 /// <remarks>	
 /// The {{Outline}} method allows the caller to produce a geometry with an equivalent fill to the input geometry, with the following additional properties: The output geometry contains no transverse intersections; that is, segments may touch, but they never cross.The outermost figures in the output geometry are all oriented counterclockwise. The output geometry is fill-mode invariant; that is, the fill of the geometry does not depend on the choice of the fill mode. For more information about the fill mode, see <see cref="SharpDX.Direct2D1.FillMode"/>.Additionally, the  {{Outline}} method can be useful in removing redundant portions of said geometries to simplify complex geometries. It can also be useful in combination with <see cref="SharpDX.Direct2D1.GeometryGroup"/> to create unions among several geometries simultaneously.	
 /// </remarks>	
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution. </param>
 /// <param name="geometrySink">The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the geometry's transformed outline is appended. </param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Outline([In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Outline(float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Outline(null, flatteningTolerance, geometrySink);
 }
 public Direct2D1StreamGeometryContext(GeometrySink geometrySink)
 {
     this.sink = geometrySink;
 }
Esempio n. 55
0
 /// <summary>	
 /// Widens the geometry by the specified stroke and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> after it has been transformed by the specified matrix and flattened using the specified tolerance.	
 /// </summary>	
 /// <param name="strokeWidth">The amount by which to widen the geometry.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution.</param>
 /// <param name="geometrySink">The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the widened geometry is appended.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Widen([None] FLOAT strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Widen(float strokeWidth, float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Widen(strokeWidth, null, null, flatteningTolerance, geometrySink);
 }
        private void EnsureFigure()
        {
            if (!_figureStarted)
            {
                _figure = _pathGeometry.Open();
                //_figure = new PathFigure();
                //_figure.StartPoint = _lastStart;
                _figure.BeginFigure(new SharpDX.Vector2((float)_lastStart.X, (float)_lastStart.Y), FigureBegin.Hollow);

                //_context.BeginFigure(_lastStart, IsFilled, !IsClosed);
                _figureStarted = true;
            }
        }
Esempio n. 57
0
 /// <summary>	
 /// Widens the geometry by the specified stroke and writes the result to an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> after it has been transformed by the specified matrix and flattened using the specified tolerance.	
 /// </summary>	
 /// <param name="strokeWidth">The amount by which to widen the geometry.</param>
 /// <param name="strokeStyle">The style of stroke to apply to the geometry, or NULL.</param>
 /// <param name="worldTransform">The transform to apply to the geometry after widening it, or NULL.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution.</param>
 /// <param name="geometrySink">The <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/> to which the widened geometry is appended.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT Widen([None] FLOAT strokeWidth,[In, Optional] ID2D1StrokeStyle* strokeStyle,[In, Optional] const D2D1_MATRIX_3X2_F* worldTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Widen(float strokeWidth, SharpDX.Direct2D1.StrokeStyle strokeStyle, RawMatrix3x2? worldTransform, float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Widen_(strokeWidth, strokeStyle, worldTransform, flatteningTolerance, GeometrySinkShadow.ToIntPtr(geometrySink));
 }
Esempio n. 58
0
 public StreamGeometryContextImpl(GeometrySink sink)
 {
     _sink = sink;
 }
Esempio n. 59
0
 /// <summary>	
 /// Combines this geometry with the specified geometry and stores the result in an <see cref="SharpDX.Direct2D1.SimplifiedGeometrySink"/>.  	
 /// </summary>	
 /// <param name="inputGeometry">The geometry to combine with this instance.</param>
 /// <param name="combineMode">The type of combine operation to perform.</param>
 /// <param name="inputGeometryTransform">The transform to apply to inputGeometry before combining, or NULL.</param>
 /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometries. Smaller values produce more accurate results but cause slower execution. </param>
 /// <param name="geometrySink">The result of the combine operation.</param>
 /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
 /// <unmanaged>HRESULT CombineWithGeometry([In] ID2D1Geometry* inputGeometry,[None] D2D1_COMBINE_MODE combineMode,[In, Optional] const D2D1_MATRIX_3X2_F* inputGeometryTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged>
 public void Combine(SharpDX.Direct2D1.Geometry inputGeometry, SharpDX.Direct2D1.CombineMode combineMode, RawMatrix3x2? inputGeometryTransform, float flatteningTolerance, GeometrySink geometrySink)
 {
     this.Combine_(inputGeometry, combineMode, inputGeometryTransform, flatteningTolerance, GeometrySinkShadow.ToIntPtr(geometrySink));
 }
Esempio n. 60
0
 public GeometryTarget(Factory factory, GeometrySink sink)
 {
     _factory = factory;
     _sink = sink;
 }