Exemple #1
0
        private void Flattener_Paint(object sender, PaintEventArgs e)
        {
            GraphicsPath path = Samples.Common.Shapes.GetShape(shapeComboBox.SelectedIndex);

            if (path == null)
            {
                return;
            }

            e.Graphics.DrawPath(default_pen, path);
            int pcount = path.PointCount;

            if ((translateX != 0f) || (translateY != 0f))
            {
                Matrix translateMatrix = new Matrix();
                translateMatrix.Translate(translateX, translateY);
                path.Flatten(translateMatrix, flat);
            }
            else
            {
                path.Flatten(null, flat);
            }
            e.Graphics.DrawPath(flat_pen, path);

            int fcount = path.PointCount;

            path.Dispose();

            infoLabel.Text = System.String.Format("Path Points: {0}, Flat Points: {1}", pcount, fcount);
        }
Exemple #2
0
        public List <Point> ToPolyline()
        {
            var temp = new List <Point>();

            gp.Flatten(null, 0.1f);

            for (int i = 0; i < this.Count; i++)
            {
                temp.Add(this[i].Coord);
            }

            return(temp);
        }
Exemple #3
0
        public static RectangleF GetBounds(GraphicsPath path, Matrix matrix)
        {
            GraphicsPath path1 = (GraphicsPath)path.Clone();

            path1.Flatten(matrix, 0.5f);
            return(path1.GetBounds());
        }
Exemple #4
0
        private static BitmapSource Create()
        {
            BitmapSource image;

            using (Bitmap bitmap = new Bitmap(10, 10))
            {
                using (Graphics graphics = Graphics.FromImage(bitmap))
                {
                    Rectangle    rect       = new Rectangle(0, 0, 10, 10);
                    GraphicsPath wheel_path = new GraphicsPath();
                    wheel_path.AddEllipse(rect);
                    wheel_path.Flatten();

                    using (PathGradientBrush path_brush = new PathGradientBrush(wheel_path))
                    {
                        using (Pen pen = new Pen(path_brush, 3))
                        {
                            graphics.DrawPath(pen, wheel_path);
                        }
                    }
                    image = CreateBitmapSourceFromGdiBitmap(bitmap);
                }
                return(image);
            }
        }
 /// <summary>
 /// Creates a new instance of a Distortion Service
 /// </summary>
 /// <param name="distortion">The distortion to be performed</param>
 /// <param name="source">The graphics path to be distorted</param>
 /// <param name="flatness">The precision of the flattening operation (smaller = more points = slower)</param>
 public DistortionService(IDistortion distortion, GraphicsPath source, float flatness = .2f)
 {
     _distortion = distortion;
     _source     = source;
     _flatness   = flatness;
     _source.Flatten(null, flatness);
 }
Exemple #6
0
        public Rectangle Draw(char c)
        {
            var text = c.ToString();
            var path = new GraphicsPath();

            path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new Point(0, 0), StringFormat.GenericTypographic);
            path.Flatten();

            var contures     = getContures(path).ToList();
            var measuredSize = new SizeF(
                this.fakeCanvas.MeasureString(text, this.font, int.MaxValue, StringFormat.GenericTypographic).Width + Padding * 2,
                TextRenderer.MeasureText(this.fakeCanvas, text, this.font, new Size(int.MaxValue, int.MaxValue)).Height + Padding * 2
                );
            var rect = this.atlas.Add(measuredSize);

            int width     = rect.Size.Width;
            int height    = rect.Size.Height;
            var distField = genSdf(contures, width, height);

            for (int y = 0; y < height; y++)
            {
                var rgbValues = new byte[4 * width];
                for (int x = 0; x < width; x++)
                {
                    rgbValues[4 * x]     = (byte)(distField[y, x] * 255);
                    rgbValues[4 * x + 1] = rgbValues[4 * x];
                    rgbValues[4 * x + 2] = rgbValues[4 * x];
                    rgbValues[4 * x + 3] = rgbValues[4 * x];
                }

                Marshal.Copy(rgbValues, 0, this.bmpPtr + (rect.Y + y) * bmpData.Stride + rect.X * 4, rgbValues.Length);
            }

            return(new Rectangle(rect.X + Padding, rect.Y + Padding, width - 2 * Padding, height - 2 * Padding));
        }
Exemple #7
0
        public MapArea(string toolTip, string url, string attributes, string postBackValue, GraphicsPath path, object tag)
            : base()
        {
            if (path.PointCount == 0)
            {
                throw new ArgumentException(SR.ExceptionImageMapPolygonShapeInvalid);
            }

            // Flatten all curved lines
            path.Flatten();

            // Allocate array of floats
            PointF[] pathPoints = path.PathPoints;
            float[]  coord      = new float[pathPoints.Length * 2];

            // Transfer path points
            int index = 0;

            foreach (PointF point in pathPoints)
            {
                coord[index++] = point.X;
                coord[index++] = point.Y;
            }

            // Initiazize area
            Initialize(MapAreaShape.Polygon, toolTip, url, attributes, postBackValue, coord, tag);
        }
 private void InsertSubpath(int index, string toolTip, string href, string attr, GraphicsPath path, bool absCoordinates, ChartGraphics graph)
 {
     if (path.PointCount > 0)
     {
         path.Flatten();
         PointF[] pathPoints = path.PathPoints;
         float[]  array      = new float[pathPoints.Length * 2];
         if (absCoordinates)
         {
             for (int i = 0; i < pathPoints.Length; i++)
             {
                 pathPoints[i] = graph.GetRelativePoint(pathPoints[i]);
             }
         }
         int      num    = 0;
         PointF[] array2 = pathPoints;
         for (int j = 0; j < array2.Length; j++)
         {
             PointF pointF = array2[j];
             array[num++] = pointF.X;
             array[num++] = pointF.Y;
         }
         this.Insert(index, MapAreaShape.Polygon, toolTip, href, attr, array, null);
     }
 }
Exemple #9
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);
 }
Exemple #10
0
        /// <summary>
        /// ћетод, позвол¤ющий перемещать указатель мыши
        /// по заданной траектории (например, вдоль окружности)
        /// </summary>
        /// <param name="times"> оличество повторов</param>
        public void MoveMouse(int times)
        {
            GraphicsPath gp = new GraphicsPath();
            // –азмеры экрана
            Rectangle screensize = Screen.GetBounds(new Point(0, 0));
            // ¬ыберем произвольный пр¤моугольник в области экрана
            Rectangle rect = new Rectangle((int)screensize.Width / 2 - 100,
                                           (int)screensize.Height / 2 - 100, 200, 200);

            // ƒобавим в траекторию окружность
            gp.AddEllipse(rect);
            // –азобьем окружность на серию линий
            gp.Flatten();

            // цикл повторений движени¤ указател¤ мыши
            for (int repeat = 0; repeat <= times - 1; repeat++)
            {
                // проходим через все точки траектории
                for (int i = 0; i <= gp.PathData.Points.Length - 1; i++)
                {
                    // организуем небольшую задержку
                    System.Threading.Thread.Sleep(10);
                    // выводим в заголовке формы число витков
                    this.Text = (repeat + 1).ToString();
                    // перемещаем указатель мыши
                    Cursor.Position = new Point((int)gp.PathData.Points[i].X, (int)gp.PathData.Points[i].Y);
                }
            }
            gp.Dispose();
        }
Exemple #11
0
    public static GraphicsPath Shrink(this GraphicsPath originalPath, float width)
    {
        originalPath.CloseAllFigures();
        originalPath.Flatten();
        var parts       = originalPath.SplitFigures();
        var shrunkPaths = new List <GraphicsPath>();

        foreach (var part in parts)
        {
            using (var widePath = new GraphicsPath(part.PathPoints, part.PathTypes))
            {
                // widen the figure
                widePath.Widen(new Pen(Color.Black, width * 2));

                // pick the inner edge
                var innerEdge = widePath.SplitFigures()[1];
                var fixedPath = CleanPath(innerEdge, part, width);
                if (fixedPath.PointCount > 0)
                {
                    shrunkPaths.Add(fixedPath);
                }
            }
        }
        // build the result
        originalPath.Reset();
        foreach (var p in shrunkPaths)
        {
            originalPath.AddPath(p, false);
        }
        return(originalPath);
    }
        // Draw some text along a GraphicsPath.
        private void DrawTextOnPath(Graphics gr, Brush brush, Font font,
                                    string txt, GraphicsPath path, ContentAlignment alignment, GraphicsPath resultPath = null)
        {
            if (resultPath != null)
            {
                resultPath.Reset();
            }

            // Make a copy so we don't mess up the original.
            path = (GraphicsPath)path.Clone();

            // Flatten the path into segments.
            path.Flatten(new Matrix(), 0.005f);

            var points = path.PathPoints;

            gr.Transform.TransformPoints(points);

            // Draw characters.
            int    start_ch    = 0;
            PointF start_point = points[0];

            for (int i = 1; i < points.Length; i++)
            {
                PointF end_point = points[i];
                DrawTextOnSegment(gr, brush, font, txt, ref start_ch, ref start_point, end_point, alignment, resultPath);
                if (start_ch >= txt.Length)
                {
                    break;
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Repaints the form with cool background and stuff.
        /// </summary>
        /// <param name="graph">The graphics object to paint to, the element will be drawn to 0, 0.</param>
        public override void Paint(Graphics graph)
        {
            // Draws Rectangular Shapes
            if (Shape == ModelShape.Arrow)
            {
                _arrowPath = new GraphicsPath();

                // Draws the basic shape
                Pen arrowPen = Highlight < 1 ? new Pen(Color.Cyan, 3F) : new Pen(Color.Black, 3F);

                // Draws the curved arrow
                Point[] lineArray = new Point[4];
                lineArray[0] = new Point(StartPoint.X, StartPoint.Y);
                lineArray[1] = new Point(StartPoint.X - ((StartPoint.X - StopPoint.X) / 3), StartPoint.Y);
                lineArray[2] = new Point(StopPoint.X - ((StopPoint.X - StartPoint.X) / 3), StopPoint.Y);
                lineArray[3] = new Point(StopPoint.X, StopPoint.Y);
                graph.DrawBeziers(arrowPen, lineArray);
                _arrowPath.AddBeziers(lineArray);
                _arrowPath.Flatten();

                // Draws the arrow head
                Point[] arrowArray = new Point[3];
                arrowArray[0] = StopPoint;
                arrowArray[1] = new Point(StopPoint.X - (5 * Math.Sign(StopPoint.X - StartPoint.X)), StopPoint.Y - 2);
                arrowArray[2] = new Point(StopPoint.X - (5 * Math.Sign(StopPoint.X - StartPoint.X)), StopPoint.Y + 2);
                graph.DrawPolygon(arrowPen, arrowArray);

                // Garbage collection
                arrowPen.Dispose();
            }
        }
Exemple #14
0
        /// <summary>
        /// Tesselate and cache the contours of the path.
        /// </summary>
        protected virtual void CacheStroke()
        {
            // Tesselate stroke.
            TEMP_PATH.Reset();
            TEMP_PATH.AddPath(path, false);
            Tesselate(TEMP_PATH, pen.Color.ToArgb(), true, false);

            // Set the start index of the flattened path
            this.flattenedStartIndex = renderListTypes.Count;

            // Add flattened path.
            TEMP_PATH.Reset();
            TEMP_PATH.AddPath(path, false);
            TEMP_PATH.Flatten(new Matrix(), this.flatness);
            CacheFlatPath(TEMP_PATH);
        }
Exemple #15
0
        private void DrawColorWheel(Graphics gr, Color outline_color, int xmin, int ymin, int wid, int hgt)
        {
            GraphicsPath RoundPath = new GraphicsPath();

            RoundPath.AddEllipse(new Rectangle(xmin, ymin, wid, hgt));
            RoundPath.Flatten(new Matrix(), 0.1f);
            float num_pts = (RoundPath.PointCount - 1) / 6;

            Color[] surround_colors = new Color[RoundPath.PointCount];
            int     index           = 0;

            InterpolateColors(surround_colors, ref index, 1 * num_pts, 255, 255, 0, 0, 255, 255, 0, 255);
            InterpolateColors(surround_colors, ref index, 2 * num_pts, 255, 255, 0, 255, 255, 0, 0, 255);
            InterpolateColors(surround_colors, ref index, 3 * num_pts, 255, 0, 0, 255, 255, 0, 255, 255);
            InterpolateColors(surround_colors, ref index, 4 * num_pts, 255, 0, 255, 255, 255, 0, 255, 0);
            InterpolateColors(surround_colors, ref index, 5 * num_pts, 255, 0, 255, 0, 255, 255, 255, 0);
            InterpolateColors(surround_colors, ref index, RoundPath.PointCount, 255, 255, 255, 0, 255, 255, 0, 0);
            using (PathGradientBrush path_brush = new PathGradientBrush(RoundPath))
            {
                path_brush.CenterColor    = Color.White;
                path_brush.SurroundColors = surround_colors;
                gr.FillPath(path_brush, RoundPath);
                using (Pen thick_pen = new Pen(outline_color, 2)) gr.DrawPath(thick_pen, RoundPath);
            }
        }
        public Analyzer(double meanX, double meanY, GraphicsPath path)
        {
            Counters = new RunningCount[Enum.GetValues(typeof(AnalysisMetric)).Length];

            foreach (AnalysisMetric metric in Enum.GetValues(typeof(AnalysisMetric)))
            {
                Counters[(int)metric] = new RunningCount(metric);
            }


            MeanX = meanX;
            MeanY = meanY;


            path.Flatten();

            using (GraphicsPathIterator PathIterator = new GraphicsPathIterator(path))
            {
                using (GraphicsPath Subpath = new GraphicsPath())
                {
                    Paths = new List <PointF[]>();

                    bool Closed;

                    while (PathIterator.NextSubpath(Subpath, out Closed) > 0)
                    {
                        Paths.Add(Subpath.PathPoints);
                        Subpath.Reset();
                    }
                }
            }
        }
Exemple #17
0
        public static GraphicsPath BuildPathPoints(Track track)
        {
            var path = new GraphicsPath();

            if (track.ControlPoints.Count < 2)
            {
                return(path);
            }

            var points = track.ControlPoints.Select(cp => cp.Point.ToPointF()).ToArray();

            path.AddCurve(points, Tension);
            path.Flatten(new Matrix(), Flatness);
            points = path.PathPoints;

            track.Points.Clear();
            for (var i = 0; i < points.Length; i++)
            {
                var p = points[i];
                track.Points.Add(new PathPoint {
                    Point = p, Width = 1
                });
            }

            return(path);
        }
Exemple #18
0
        /// <summary>
        /// Get the desired Rounded Rectangle path.
        /// </summary>
        private GraphicsPath GetLine(RectangleF baseRect)
        {
            float x1 = (float)X1;
            float y1 = (float)Y1;
            float x2 = (float)X2;
            float y2 = (float)Y2;

            float w = (float)Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

            float ang = (y2 - y1) / (x2 - x1);

            ang  = (float)Math.Atan(ang);
            ang *= (float)(180.0f / Math.PI);
            GraphicsPath mPath = new GraphicsPath();

            System.Drawing.Rectangle r = new System.Drawing.Rectangle((int)x1, (int)y1, (int)w, (int)StrokeThickness);
            mPath.AddRectangle(r);
            mPath.CloseFigure();

            using (Matrix matrix = new Matrix())
            {
                matrix.RotateAt(ang, new PointF(x1, y1), MatrixOrder.Append);
                matrix.Translate(baseRect.X, baseRect.Y, MatrixOrder.Append);
                RectangleF bounds = mPath.GetBounds(matrix);
                matrix.Scale(baseRect.Width / bounds.Width, baseRect.Height / bounds.Height);
                mPath.Transform(matrix);
            }
            mPath.Flatten();

            return(mPath);
        }
Exemple #19
0
 private PathGradientBrush GetSpecialCapBrush(GaugeGraphics g, GraphicsPath path, PointF pointOrigin, float angle, Color fillColor, GradientType fillGradientType, Color fillGradientEndColor, GaugeHatchStyle fillHatchStyle)
 {
     using (GraphicsPath graphicsPath = (GraphicsPath)path.Clone())
     {
         graphicsPath.Flatten(null, 0.3f);
         graphicsPath.Reset();
         RectangleF bounds = path.GetBounds();
         bounds.Inflate(-20f, -20f);
         PointF[] points = new PointF[4]
         {
             new PointF(bounds.Left, bounds.Top),
             new PointF(bounds.Right, bounds.Top),
             new PointF(bounds.Right, bounds.Bottom),
             new PointF(bounds.Left, bounds.Bottom)
         };
         graphicsPath.AddLines(points);
         PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath);
         pathGradientBrush.SurroundColors = new Color[4]
         {
             Color.Red,
             Color.Green,
             Color.Blue,
             Color.Green
         };
         pathGradientBrush.CenterColor = Color.Transparent;
         pathGradientBrush.CenterPoint = new PointF(bounds.Left, bounds.Top);
         pathGradientBrush.RotateTransform(angle, MatrixOrder.Append);
         pathGradientBrush.TranslateTransform(pointOrigin.X, pointOrigin.Y, MatrixOrder.Append);
         return(pathGradientBrush);
     }
 }
        public static void DrawString(this WavefrontFormat wf,
                                      string color,
                                      Point2d pt,
                                      FontFamily family, FontStyle style, float sizeInPoints,
                                      string text)
        {
            float dpiY   = 1;
            float emSize = dpiY * sizeInPoints / 72;

            using (GraphicsPath path = new GraphicsPath())
            {
                //float dpiY = 1;
                path.AddString(text,
                               family, (int)style, emSize,
                               new PointF(0, 0),
                               StringFormat.GenericTypographic);

                float pathheight = path.GetBounds().Height;
                path.Transform(new Matrix(1, 0, 0, -1, 0, pathheight));
                path.Transform(new Matrix(1, 0, 0, 1, (float)pt.X, (float)pt.Y));

                path.Flatten(new Matrix(), 0.01f);

                DrawPath(wf, path);
            }
        }
Exemple #21
0
        public void Round(System.Drawing.Region region)
        {
            GraphicsPath gPath = new GraphicsPath();
            int          x = 2, y = 2;
            int          thisWidth  = this.Width;
            int          thisHeight = this.Height;

            if (radius)
            {
                //var g=CreateGraphics();
                //var pen = new System.Drawing.Pen(System.Drawing.Color.Black,10);
                //g.SmoothingMode = SmoothingMode.AntiAlias;
                //g.DrawEllipse(pen,x,y,this.Width,this.Height);
                //g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                gPath.AddEllipse(x, y, this.Width - 3f, this.Height - 3f);
                gPath.Flatten();
                gPath.ClearMarkers();
                gPath.CloseAllFigures();
                Region = new System.Drawing.Region(gPath);
            }
            else
            {
                gPath.AddLine(x, y, thisWidth, y);
                gPath.AddLine(thisWidth, y, thisWidth, thisHeight);
                gPath.AddLine(thisWidth, thisHeight, x, thisHeight);
                gPath.AddLine(x, y, x, thisHeight);
                Region = new System.Drawing.Region(gPath);
            }
        }
Exemple #22
0
        public virtual RectangleF GetBounds()
        {
            GraphicsPath path1 = (GraphicsPath)this.GPath.Clone();

            path1.Flatten();
            return(path1.GetBounds());
        }
        static void Main(string[] args)
        {
            /* some test data */
            var pointss = new Point[]
            {
                new Point(5, 20),
                new Point(17, 63),
                new Point(2, 9)
            };

            /* instead of to the picture box, draw to a path */
            using (var path = new GraphicsPath())
            {
                path.AddCurve(pointss, 1.0F);
                /* use a unit matrix to get points per pixel */
                using (var mx = new Matrix(1, 0, 0, 1, 0, 0))
                {
                    path.Flatten(mx, 0.1f);
                }
                /* store points in a list */
                var list_of_points = new List <PointF>(path.PathPoints);
                /* show them */
                int i = 0;
                foreach (var point in list_of_points)
                {
                    Debug.WriteLine($"Point #{ ++i }: X={ point.X }, Y={point.Y}");
                }
            }
        }
        private void BuildDistortion(GraphicsPath source)
        {
            _sourceBounds = source.GetBounds();

            _distortionPath = new GraphicsPath(source.FillMode);

            _lowerLeft  = new PointF(_sourceBounds.Left, _sourceBounds.Bottom);
            _lowerRight = new PointF(_sourceBounds.Right, _sourceBounds.Bottom);
            _upperLeft  = new PointF(_sourceBounds.Left, _sourceBounds.Top);
            _upperRight = new PointF(_sourceBounds.Right, _sourceBounds.Top);

            _distortionPath.AddLine(_lowerLeft, _upperLeft);

            _distortionPath.AddBezier(_upperLeft,
                                      new PointF(_sourceBounds.Left, _sourceBounds.Top + ((_sourceBounds.Height * (float)Intensity)) * -1),
                                      new PointF(_sourceBounds.Right, _sourceBounds.Top + ((_sourceBounds.Height * (float)Intensity)) * -1),
                                      _upperRight);

            _distortionPath.AddLine(_upperRight, _lowerRight);

            _distortionPath.AddBezier(_lowerRight,
                                      new PointF(_sourceBounds.Right, _sourceBounds.Bottom + (_sourceBounds.Height * (float)Intensity)),
                                      new PointF(_sourceBounds.Left, _sourceBounds.Bottom + (_sourceBounds.Height * (float)Intensity)),
                                      _lowerLeft);

            _distortionPath.Flatten();
            _distortionPoints = ClipperUtility.ConvertToClipperPolygons(_distortionPath);
            _distortionBounds = _distortionPath.GetBounds();
        }
 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();
     }
 }
Exemple #26
0
        public GraphicsPath GetTempPath(IGraph graph, PointF offset)
        {
            GraphicsPath path = base.graphPath.Clone() as GraphicsPath;

            if (path.PointCount == 0)
            {
                return(path);
            }
            GraphicsPath path2 = new GraphicsPath();

            path.Flatten(base.GraphTransform.Matrix);
            PointF[] points = new PointF[] { offset };
            graph.GraphTransform.Matrix.TransformVectors(points);
            offset = points[0];

            if (graph == startGraph)
            {
                path2.AddLine(new PointF(path.PathPoints[0].X + offset.X, path.PathPoints[0].Y + offset.Y), path.PathPoints[path.PointCount - 1]);
            }
            else
            {
                path2.AddLine(path.PathPoints[0], new PointF(path.PathPoints[path.PointCount - 1].X + offset.X, path.PathPoints[path.PointCount - 1].Y + offset.Y));
            }
            return(path2);
        }
Exemple #27
0
        protected GraphicsPath CalculateTransformedPath(GraphicsPath path, SharpDX.RectangleF baseRect)
        {
            GraphicsPath result = path;

            using (Matrix m = new Matrix())
            {
                RectangleF bounds = result.GetBounds();
                _fillDisabled = bounds.Width < StrokeThickness || bounds.Height < StrokeThickness;
                if (Width > 0)
                {
                    baseRect.Width = (float)Width;
                }
                if (Height > 0)
                {
                    baseRect.Height = (float)Height;
                }
                float scaleW;
                float scaleH;
                if (Stretch == Stretch.Fill)
                {
                    scaleW = baseRect.Width / bounds.Width;
                    scaleH = baseRect.Height / bounds.Height;
                    m.Translate(-bounds.X, -bounds.Y, MatrixOrder.Append);
                }
                else if (Stretch == Stretch.Uniform)
                {
                    scaleW = Math.Min(baseRect.Width / bounds.Width, baseRect.Height / bounds.Height);
                    scaleH = scaleW;
                    m.Translate(-bounds.X, -bounds.Y, MatrixOrder.Append);
                }
                else if (Stretch == Stretch.UniformToFill)
                {
                    scaleW = Math.Max(baseRect.Width / bounds.Width, baseRect.Height / bounds.Height);
                    scaleH = scaleW;
                    m.Translate(-bounds.X, -bounds.Y, MatrixOrder.Append);
                }
                else
                {
                    // Stretch == Stretch.None
                    scaleW = 1;
                    scaleH = 1;
                }
                // In case bounds.Width or bounds.Height or baseRect.Width or baseRect.Height were 0
                if (scaleW == 0 || float.IsNaN(scaleW) || float.IsInfinity(scaleW))
                {
                    scaleW = 1;
                }
                if (scaleH == 0 || float.IsNaN(scaleH) || float.IsInfinity(scaleH))
                {
                    scaleH = 1;
                }
                m.Scale(scaleW, scaleH, MatrixOrder.Append);

                m.Translate(baseRect.X, baseRect.Y, MatrixOrder.Append);
                result.Transform(m);
                result.Flatten();
            }
            return(result);
        }
Exemple #28
0
        /// <summary>
        /// Method to draw the text on the <see cref="GraphicsPath"/>
        /// </summary>
        /// <returns>The area covered by the rendering process</returns>
        public RectangleF DrawTextOnPathEx()
        {
            var affectedArea = new RectangleF();

            var points = new PointF[25001];
            var count  = 0;
            var gp     = new GraphicsPath(_pathdata.Points, _pathdata.Types)
            {
                FillMode = FillMode.Winding
            };

            _regionList.Clear();
            _angles.Clear();
            _pointText.Clear();
            _pointTextUp.Clear();
            gp.Flatten(null, 1);
            try
            {
                var      tmpPoint = gp.PathPoints[0];
                int      i;
                PointF[] tmpPoints;
                for (i = 0; i <= gp.PathPoints.Length - 2; i++)
                {
                    if (gp.PathTypes[i + 1] == (byte)PathPointType.Start | (gp.PathTypes[i] & (byte)PathPointType.CloseSubpath) == (byte)PathPointType.CloseSubpath)
                    {
                        tmpPoints = GetLinePoints(gp.PathPoints[i], tmpPoint, 1);
                        Array.ConstrainedCopy(tmpPoints, 0, points, count, tmpPoints.Length);
                        count   += 1;
                        tmpPoint = gp.PathPoints[i + 1];
                    }
                    else
                    {
                        tmpPoints = GetLinePoints(gp.PathPoints[i], gp.PathPoints[i + 1], 1);
                        Array.ConstrainedCopy(tmpPoints, 0, points, count, tmpPoints.Length);
                        count += tmpPoints.Length - 1;
                    }
                }
                tmpPoints = new PointF[count];
                Array.Copy(points, tmpPoints, count);
                points = CleanPoints(tmpPoints);

                count = points.Length - 1;
                if (IsVisible(points, count))
                {
                    // if can show all letter
                    DrawText(Graphics, points, count);
                }

                affectedArea = gp.GetBounds();
                gp.Dispose();
                //DrawText(points, count);
            }
            catch (Exception ex)
            {
                LastError = ex;
            }

            return(affectedArea);
        }
Exemple #29
0
        public RectangleF GetRectangle()
        {
            GraphicsPath path1 = (GraphicsPath)this.GPath.Clone();

            //path1.Transform(Transform.Matrix);
            path1.Flatten(new Matrix(), 0.5f);
            return(path1.GetBounds());
        }
        private static void DrawTie(this RenderTarget renderTarget, SharpDX.DirectWrite.Factory writeFactory, RawVector2 startPos, RawVector2 endPos, Color color, bool flipVertical = false, bool isTriplet = false)
        {
            PointF[]   pathPoints;
            RawVector2 vector;
            RawVector2 vector2;

            using (GraphicsPath path = new GraphicsPath())
            {
                float num  = 45f;
                float num2 = 0.3f;
                float num3 = startPos.GetDistanceByRawVector2(endPos).Clamp(64f, 256f);
                float num4 = startPos.GetAngleByRawVector2(endPos);
                float num5 = endPos.GetAngleByRawVector2(startPos);
                if (flipVertical)
                {
                    vector  = startPos.GetRawVector2ByPolarCoordinates(num4 + num, num3 * num2);
                    vector2 = endPos.GetRawVector2ByPolarCoordinates(num5 - num, num3 * num2);
                    path.AddBezier(startPos.X, startPos.Y, vector.X, vector.Y, vector2.X, vector2.Y, endPos.X, endPos.Y);
                    path.AddBezier(endPos.X, endPos.Y + 1f, vector2.X, vector2.Y + 2f, vector.X, vector.Y + 2f, startPos.X, startPos.Y + 1f);
                }
                else
                {
                    vector  = startPos.GetRawVector2ByPolarCoordinates(num4 - num, num3 * num2);
                    vector2 = endPos.GetRawVector2ByPolarCoordinates(num5 + num, num3 * num2);
                    path.AddBezier(startPos.X, startPos.Y, vector.X, vector.Y, vector2.X, vector2.Y, endPos.X, endPos.Y);
                    path.AddBezier(endPos.X, endPos.Y - 1f, vector2.X, vector2.Y - 2f, vector.X, vector.Y - 2f, startPos.X, startPos.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();
                if (isTriplet)
                {
                    RawVector2 pos = new RawVector2(vector.X + ((vector2.X - vector.X) / 2f), vector.Y + ((vector2.Y - vector.Y) / 2f));
                    renderTarget.DrawTextLayout(writeFactory, "3", pos, "Consolas", 16f, Color.FromArgb((int)(color.A * 0.75f), color), TextAlignment.Center, ParagraphAlignment.Center, SharpDX.DirectWrite.FontStyle.Normal, FontWeight.ExtraBlack);
                }
            }
        }
Exemple #31
0
    public static List<PointF> GetArrowLinePoints(float x1, float y1, float x2, float y2, float extra_thickness = 0)
    {
        var widthX	= (x2 - x1);
        var lengthX = Math.Max(60, Math.Abs(widthX / 2))
            //+ Math.Max(0, -widthX / 2)
            ;
        var lengthY = 0;// Math.Max(-170, Math.Min(-120.0f, widthX - 120.0f)) + 120.0f;
        if (widthX < 120)
            lengthX = 60;
        var yB = ((y1 + y2) / 2) + lengthY;// (y2 + ((y1 - y2) / 2) * 0.75f) + lengthY;
        var yC = y2 + yB;
        var xC = (x1 + x2) / 2;
        var xA = x1 + lengthX;
        var xB = x2 - lengthX;

        /*
            if (widthX >= 120)
            {
                xA = xB = xC = x2 - 60;
            }
            //*/

        var points = new List<PointF>
        {
            new PointF(x1, y1),
            new PointF(xA, y1),
            new PointF(xB, y2),
            new PointF(x2 - GraphConstants.ConnectorSize - extra_thickness, y2)
        };

        var t  = 1.0f;//Math.Min(1, Math.Max(0, (widthX - 30) / 60.0f));
        var yA = (yB * t) + (yC * (1 - t));

        if (widthX <= 120)
        {
            points.Insert(2, new PointF(xB, yA));
            points.Insert(2, new PointF(xC, yA));
            points.Insert(2, new PointF(xA, yA));
        }
        //*
        using (var tempPath = new GraphicsPath())
        {
            tempPath.AddBeziers(points.ToArray());
            tempPath.Flatten();
            points = tempPath.PathPoints.ToList();
        }
        return points;
    }