Exemple #1
0
        private void DoRegion()
        {
            Region r = new Region(Rectangle.FromLTRB(0, 0, this.ClientSize.Width, this.ClientSize.Height));

            //r.Exclude(Rectangle.FromLTRB(10,10,50,50));

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            //gp.AddRectangle(Rectangle.FromLTRB(15,15,this.ClientSize.Width - 15,this.ClientSize.Height - 15));
            gp.StartFigure();
            gp.AddLine(0, 0, 15, 0);
            gp.AddLine(0, 0, 0, 15);
            gp.AddArc(0, 0, 31, 31, 180, 90);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(0, this.ClientSize.Height - 30, 31, 31, 90, 90);
            gp.AddLine(0, this.ClientSize.Height, 0, this.ClientSize.Height - 15);
            gp.AddLine(0, this.ClientSize.Height, 15, this.ClientSize.Height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(this.ClientSize.Width - 30, this.ClientSize.Height - 30, 30, 30, 0, 90);
            gp.AddLine(this.ClientSize.Width, this.ClientSize.Height, this.ClientSize.Width, this.ClientSize.Height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(this.ClientSize.Width - 30, 0, 30, 30, 270, 90);
            gp.AddLine(this.ClientSize.Width, 0, this.ClientSize.Width, 0);
            gp.CloseFigure();

            r.Exclude(gp);

            this.Region = r;
        }
Exemple #2
0
        public static Region DoRegion(int width, int height)
        {
            Region r = new Region(Rectangle.FromLTRB(0, 0, width, height));

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.StartFigure();
            gp.AddLine(0, 0, 15, 0);
            gp.AddLine(0, 0, 0, 15);
            gp.AddArc(0, 0, 31, 31, 180, 90);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(0, height - 30, 31, 31, 90, 90);
            gp.AddLine(0, height, 0, height - 15);
            gp.AddLine(0, height, 15, height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(width - 30, height - 30, 30, 30, 0, 90);
            gp.AddLine(width, height, width, height);
            gp.CloseFigure();

            gp.StartFigure();
            gp.AddArc(width - 30, 0, 30, 30, 270, 90);
            gp.AddLine(width, 0, width, 0);
            gp.CloseFigure();

            r.Exclude(gp);

            return(r);
        }
Exemple #3
0
            public void set_inner_surfaces(List <surface_store> i_inner_surfaces)
            {
                // add inner surface one after another
                for (int i = 0; i < i_inner_surfaces.Count; i++)
                {
                    if (i_inner_surfaces[i].SignedPolygonArea() > 0) // check whether the inner surface is oriented clockwise (positive area = anti-clockwise)
                    {
                        // anti-clockwise orientation detected so reverse the orientation to be clockwise
                        i_inner_surfaces[i].reverse_surface_orinetation();
                    }
                    inner_surfaces.Add(i_inner_surfaces[i]); // inner surface is clockwise
                }
                //inner_surfaces.AddRange(i_inner_surfaces);

                foreach (surface_store surf in inner_surfaces) // cycle through all the inner surfaces
                {
                    // Set the path of inner surface
                    List <PointF> temp_sur_pts = new List <PointF>();
                    foreach (edge2d ed in surf.surface_edges)
                    {
                        temp_sur_pts.Add(ed.end_pt.get_point());
                    }

                    System.Drawing.Drawing2D.GraphicsPath inner_surface = new System.Drawing.Drawing2D.GraphicsPath();
                    inner_surface.StartFigure();
                    inner_surface.AddPolygon(temp_sur_pts.ToArray());
                    inner_surface.CloseFigure();


                    // set region
                    surface_region.Exclude(inner_surface); // exclude the inner surface region
                }
            }
        private void DrawTextBox(ref Bitmap bmp)
        {
            Graphics g = Graphics.FromImage(bmp);

            int       cRadius   = bmp.Width * 5 / 400;
            int       boxWidth  = bmp.Width;
            int       boxHeight = bmp.Height / 6;
            Rectangle rect      = new Rectangle(cRadius / 2, cRadius / 2, boxWidth - cRadius, boxHeight - cRadius);

            // 指定图形路径, 有一系列 直线/曲线 组成
            System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();
            myPath.StartFigure();
            myPath.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 180, 90);
            myPath.AddLine(new Point(rect.X + cRadius, rect.Y), new Point(rect.Right - cRadius, rect.Y));
            myPath.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 270, 90);
            myPath.AddLine(new Point(rect.Right, rect.Y + cRadius), new Point(rect.Right, rect.Bottom - cRadius));
            myPath.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 0, 90);
            myPath.AddLine(new Point(rect.Right - cRadius, rect.Bottom), new Point(rect.X + cRadius, rect.Bottom));
            myPath.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 90, 90);
            myPath.AddLine(new Point(rect.X, rect.Bottom - cRadius), new Point(rect.X, rect.Y + cRadius));
            myPath.CloseFigure();

            int opacity = 50;
            int alpha   = (opacity * 255) / 100;

            g.FillPath(new SolidBrush(Color.FromArgb(alpha, Color.AliceBlue)), myPath);

            float fontSize = boxHeight * 25 / 80;
            int   stringX  = bmp.Width * 5 / 400;
            int   stringY  = (int)((boxHeight - fontSize / 72 * 96) / 3);

            g.DrawString(DateTime.Now.ToString("hh:mm:ss"), new Font("Segoe UI", fontSize),
                         new SolidBrush(Color.Green), stringX, stringY);
        }
Exemple #5
0
        /// <summary>
        /// 划圆角边框
        /// </summary>
        /// <param name="g">绘制的图形</param>
        /// <param name="p">颜色和粗细</param>
        /// <param name="X">绘制图形的初始X</param>
        /// <param name="Y">绘制图形的初始Y</param>
        /// <param name="width">绘制图形的宽度</param>
        /// <param name="height">绘制图形的高度</param>
        /// <param name="radius">绘制图形的弧度</param>
        public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);

            gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);

            gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));

            gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);

            gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);

            gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);

            gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);

            gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);

            gp.CloseFigure();

            g.DrawPath(p, gp);

            gp.Dispose();
        }
Exemple #6
0
        private static void CropEllipse(string pathSource, string pathTarget, int x, int y, int radiusWidth, int radiusHeight)
        {
            if (System.IO.File.Exists(pathSource))
            {
                if (System.IO.File.Exists(pathTarget))
                {
                    System.IO.File.Delete(pathTarget);
                }

                System.Drawing.Image     imgSource = System.Drawing.Image.FromFile(pathSource);
                System.Drawing.Rectangle cropArea  = new System.Drawing.Rectangle(x, y, radiusWidth * 2, radiusHeight * 2);
                System.Drawing.Bitmap    imgTarget = new System.Drawing.Bitmap(radiusWidth * 2, radiusHeight * 2);

                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(imgTarget))
                {
                    var path = new System.Drawing.Drawing2D.GraphicsPath();
                    path.AddEllipse(0, 0, radiusWidth * 2, radiusHeight * 2);
                    path.CloseFigure();

                    g.SetClip(path, System.Drawing.Drawing2D.CombineMode.Replace);
                    g.DrawImage(imgSource, new System.Drawing.Rectangle(0, 0, imgTarget.Width, imgTarget.Height), cropArea, System.Drawing.GraphicsUnit.Pixel);
                    imgTarget.Save(pathTarget, System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// 角の丸い枠線を表すGraphicsPathを取得します
 /// </summary>
 /// <returns></returns>
 private System.Drawing.Drawing2D.GraphicsPath getGraphicsPath()
 {
     if (graphicsPath == null)
     {
         graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
         graphicsPath.StartFigure();
         int w = base.Width - 1;
         int h = base.Height - 1;
         // 上の横線
         graphicsPath.AddLine(RADIUS, 0, w - RADIUS, 0);
         // 右上の角
         graphicsPath.AddArc(w - DIAMETER, 0, DIAMETER, DIAMETER, 270, 90);
         // 右の縦線
         graphicsPath.AddLine(w, RADIUS, w, h - RADIUS);
         // 右下の角
         graphicsPath.AddArc(w - DIAMETER, h - DIAMETER, DIAMETER, DIAMETER, 0, 90);
         // 下の横線
         graphicsPath.AddLine(w - RADIUS, h, RADIUS, h);
         // 左下の角
         graphicsPath.AddArc(0, h - DIAMETER, DIAMETER, DIAMETER, 90, 90);
         // 左の縦線
         graphicsPath.AddLine(0, h - RADIUS, 0, RADIUS);
         // 左上の角
         graphicsPath.AddArc(0, 0, DIAMETER, DIAMETER, 180, 90);
         graphicsPath.CloseFigure();
     }
     return(graphicsPath);
 }
Exemple #8
0
        protected void UpdatePath()
        {
            // After deserialization _points array will be null.
            if (_points == null)
            {
                return;
            }

            if (_path != null)
            {
                _path.Dispose();
            }

            System.Drawing.RectangleF bounds = VObjectsUtils.GetBoundingRectangle(_points);
            if (bounds.Width < VObject.Eps)
            {
                _points[0].X += 0.05f;
            }
            if (bounds.Height < VObject.Eps)
            {
                _points[0].Y += 0.05f;
            }

            _path = new System.Drawing.Drawing2D.GraphicsPath();
            _path.AddLines(_points);
            if (_closePath)
            {
                _path.CloseFigure();
            }
        }
Exemple #9
0
        /// <summary>
        /// 绘制圆角
        /// </summary>
        /// <param name="g"></param>
        /// <param name="p"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="radius"></param>
        public static void DrawRoundRect(Graphics g, Pen p, Brush brush,float X, float Y, float width, float height, float radius)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddLine(X + radius, Y, X + width - (radius * 2), Y);

            gp.AddArc(X + width - (radius * 2), Y, radius * 2, radius * 2, 270, 90);

            gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius * 2));

            gp.AddArc(X + width - (radius * 2), Y + height - (radius * 2), radius * 2, radius * 2, 0, 90);

            gp.AddLine(X + width - (radius * 2), Y + height, X + radius, Y + height);

            gp.AddArc(X, Y + height - (radius * 2), radius * 2, radius * 2, 90, 90);

            gp.AddLine(X, Y + height - (radius * 2), X, Y + radius);

            gp.AddArc(X, Y, radius * 2, radius * 2, 180, 90);

            gp.CloseFigure();

            g.DrawPath(p, gp);

            g.FillPath(brush, gp);

            gp.Dispose();
        }
        public override void AddToPath(System.Drawing.Drawing2D.GraphicsPath graphicsPath)
        {
            var pathData = graphicsPath.PathData;

            if (pathData.Points.Length > 0)
            {
                // Important for custom line caps.  Force the path the close with an explicit line, not just an implicit close of the figure.

                if (!pathData.Points[0].Equals(pathData.Points[pathData.Points.Length - 1]))
                {
                    int i = pathData.Points.Length - 1;
                    while (i >= 0 && pathData.Types[i] > 0)
                    {
                        i--;
                    }
                    if (i < 0)
                    {
                        i = 0;
                    }
                    graphicsPath.AddLine(pathData.Points[pathData.Points.Length - 1], pathData.Points[i]);
                }

                graphicsPath.CloseFigure();
            }
        }
Exemple #11
0
        private void roundObject(Form obj)
        {
            System.Drawing.Drawing2D.GraphicsPath DGP = new System.Drawing.Drawing2D.GraphicsPath();
            DGP.StartFigure();
            //'top left corner
            DGP.AddArc(new Rectangle(0, 0, 40, 40), 180, 90);
            DGP.AddLine(40, 0, obj.Width - 40, 0);


            //'top right corner
            DGP.AddArc(new Rectangle(obj.Width - 40, 0, 40, 40), -90, 90);
            DGP.AddLine(obj.Width, 40, obj.Width, obj.Height - 40);


            //'buttom right corner
            DGP.AddArc(new Rectangle(obj.Width - 40, obj.Height - 40, 40, 40), 0, 90);
            DGP.AddLine(obj.Width - 40, obj.Height, 40, obj.Height);


            //'buttom left corner
            DGP.AddArc(new Rectangle(0, obj.Height - 40, 40, 40), 90, 90);
            DGP.CloseFigure();

            obj.Region = new Region(DGP);
        }
Exemple #12
0
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, IPolygon polygon, IAreaStyle style)
        {
            if (polygon == null || style == null)
            {
                return;
            }

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddPolygon(RenderUtil.CoordToPoint(polygon.Shell.Coordinates));
            foreach (ILinearRing l in polygon.Holes)
            {
                gp.AddPolygon(RenderUtil.CoordToPoint(l.Coordinates));
            }
            gp.CloseFigure();

            if (style.Fill != null)
            {
                RenderUtil.RenderFill(engine, graphics, gp, style.Fill);
            }

            if (style.Outline != null)
            {
                RenderUtil.RenderOutline(engine, graphics, gp, style.Outline);
            }
        }
Exemple #13
0
        private System.Drawing.Drawing2D.GraphicsPath RoundRegion(Rectangle r)
        {
            //Scale the radius if it's too large to fit.
            int radius = CornerRadius;

            if (radius > (r.Width))
            {
                radius = r.Width;
            }
            if (radius > (r.Height))
            {
                radius = r.Height;
            }

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            if (radius <= 0)
            {
                path.AddRectangle(r);
            }
            else
            {
                path.AddArc(r.Left, r.Top, radius, radius, 180, 90);
                path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90);
                path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom);
                path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom);
                path.CloseFigure();
            }

            return(path);
        }
Exemple #14
0
        private System.Drawing.Drawing2D.GraphicsPath RoundedRect(Vector2 p1, Vector2 p2, float radius)
        {
            float diameter = radius * 2;

            System.Drawing.SizeF                  size = new System.Drawing.SizeF(diameter, diameter);
            System.Drawing.RectangleF             arc  = new System.Drawing.RectangleF(new System.Drawing.PointF(p1.x, p1.y), size);
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            /*if (radius == 0)
             * {
             *  path.AddRectangle(bounds);
             *  return path;
             * }*/

            // top left arc
            path.AddArc(arc, 180, 90);

            // top right arc
            arc.X = p2.x - diameter;
            path.AddArc(arc, 270, 90);

            // bottom right arc
            arc.Y = p2.y - diameter;
            path.AddArc(arc, 0, 90);

            // bottom left arc
            arc.X = p1.x;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return(path);
        }
Exemple #15
0
        public void fillShapes(short[] xy, int pointCnt)
        {
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);

            System.Drawing.Drawing2D.SmoothingMode oldSmoothMode = mGraphics.SmoothingMode;
            mGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            if (pointCnt > xy.Length / 2)
            {
                pointCnt = xy.Length / 2;
            }

            int i = 0;
            int x0, y0, x, y;

            path.StartFigure();
            x0 = xy[0];
            y0 = xy[1];
            for (i = 1; i < pointCnt; i++)
            {
                x = xy[2 * i];
                y = xy[2 * i + 1];
                path.AddLine(x0, y0, x, y);
                x0 = x;
                y0 = y;
            }
            path.CloseFigure();
            mGraphics.FillPath(mPen.Brush, path);

            mGraphics.SmoothingMode = oldSmoothMode;
        }
        public static System.Drawing.Drawing2D.GraphicsPath CreateRoundedRectPath(float x, float y, float width, float height, float radius)
        {
            var xw   = x + width;
            var yh   = y + height;
            var xwr  = xw - radius;
            var yhr  = yh - radius;
            var xr   = x + radius;
            var yr   = y + radius;
            var r2   = radius * 2;
            var xwr2 = xw - r2;
            var yhr2 = yh - r2;

            var p = new System.Drawing.Drawing2D.GraphicsPath();

            p.StartFigure();

            p.AddArc(x, y, r2, r2, 180, 90);

            p.AddLine(xr, y, xwr, y);

            p.AddArc(xwr2, y, r2, r2, 270, 90);

            p.AddLine(xw, yr, xw, yhr);

            p.AddArc(xwr2, yhr2, r2, r2, 0, 90);

            p.AddLine(xwr, yh, xr, yh);

            p.AddArc(x, yhr2, r2, r2, 90, 90);
            p.AddLine(x, yhr, x, yr);

            p.CloseFigure();
            return(p);
        }
Exemple #17
0
        /// <summary>
        /// Render plot view region of line chart component.
        /// </summary>
        /// <param name="dc">Platform no-associated drawing context.</param>
        protected override void OnPaint(DrawingContext dc)
        {
            var axisChart = base.Chart as AxisChart;

            if (axisChart == null)
            {
                return;
            }

            var ds = Chart.DataSource;

            var g          = dc.Graphics;
            var clientRect = this.ClientBounds;


            var path = new System.Drawing.Drawing2D.GraphicsPath();

            for (int r = 0; r < ds.SerialCount; r++)
            {
                var style     = axisChart.DataSerialStyles[r];
                var lastPoint = new System.Drawing.PointF(axisChart.PlotColumnPoints[0], axisChart.ZeroHeight);

                for (int c = 0; c < ds.CategoryCount; c++)
                {
                    var pt = axisChart.PlotDataPoints[r][c];

                    System.Drawing.PointF point;

                    if (pt.hasValue)
                    {
                        point = new System.Drawing.PointF(axisChart.PlotColumnPoints[c], axisChart.ZeroHeight - pt.value);
                    }
                    else
                    {
                        point = new System.Drawing.PointF(axisChart.PlotColumnPoints[c], axisChart.ZeroHeight);
                    }

                    path.AddLine(lastPoint, point);
                    lastPoint = point;
                }

                var endPoint = new System.Drawing.PointF(axisChart.PlotColumnPoints[ds.CategoryCount - 1], axisChart.ZeroHeight);

                if (lastPoint != endPoint)
                {
                    path.AddLine(lastPoint, endPoint);
                }

                path.CloseFigure();

                g.FillPath(style.FillColor, path);

                path.Reset();
            }

            path.Dispose();
        }
Exemple #18
0
        /// <summary>
        /// takes in a parsed path and returns a list of points that can be used to draw the path
        /// </summary>
        /// <returns>The drawing points.</returns>
        /// <param name="segments">Segments.</param>
        public Vector2[] GetDrawingPoints(List <SvgPathSegment> segments, float flatness = 3)
        {
            var path = new System.Drawing.Drawing2D.GraphicsPath();

            for (var j = 0; j < segments.Count; j++)
            {
                var segment = segments[j];
                if (segment is SvgMoveToSegment)
                {
                    path.StartFigure();
                }
                else if (segment is SvgCubicCurveSegment)
                {
                    var cubicSegment = segment as SvgCubicCurveSegment;
                    path.AddBezier(ToDrawPoint(segment.Start), ToDrawPoint(cubicSegment.FirstCtrlPoint),
                                   ToDrawPoint(cubicSegment.SecondCtrlPoint), ToDrawPoint(segment.End));
                }
                else if (segment is SvgClosePathSegment)
                {
                    // important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
                    if (path.PointCount > 0 && !path.PathPoints[0].Equals(path.PathPoints[path.PathPoints.Length - 1]))
                    {
                        var i = path.PathTypes.Length - 1;
                        while (i >= 0 && path.PathTypes[i] > 0)
                        {
                            i--;
                        }
                        if (i < 0)
                        {
                            i = 0;
                        }
                        path.AddLine(path.PathPoints[path.PathPoints.Length - 1], path.PathPoints[i]);
                    }

                    path.CloseFigure();
                }
                else if (segment is SvgLineSegment)
                {
                    path.AddLine(ToDrawPoint(segment.Start), ToDrawPoint(segment.End));
                }
                else if (segment is SvgQuadraticCurveSegment)
                {
                    var quadSegment = segment as SvgQuadraticCurveSegment;
                    path.AddBezier(ToDrawPoint(segment.Start), ToDrawPoint(quadSegment.FirstCtrlPoint),
                                   ToDrawPoint(quadSegment.SecondCtrlPoint), ToDrawPoint(segment.End));
                }
                else
                {
                    Debug.Warn("unknown type in getDrawingPoints");
                }
            }

            path.Flatten(new System.Drawing.Drawing2D.Matrix(), flatness);

            return(System.Array.ConvertAll(path.PathPoints, i => new Vector2(i.X, i.Y)));
        }
        private DialogResult PopupInput(ListViewItem.ListViewSubItem pSelectedSubItems, int border, int length, ref string output)
        {
            System.Drawing.Point ctrlpt = pSelectedSubItems.Bounds.Location;
            ctrlpt = this.PointToScreen(pSelectedSubItems.Bounds.Location);
            //ctrlpt.Y += grbSave.Location.Y + 10;
            //ctrlpt.X += grbSave.Location.X + (length / 2);
            ctrlpt.Y += 251;
            ctrlpt.X += 328 + (length / 2);
            TextBox input = new TextBox {
                Height = 20, Width = length, Top = border / 2, Left = border / 2
            };

            input.BorderStyle = BorderStyle.FixedSingle;
            input.Text        = output;

            //######## SetColor to your preference
            input.BackColor = Color.Azure;

            Button btnok = new Button {
                DialogResult = System.Windows.Forms.DialogResult.OK, Top = 25
            };
            Button btncn = new Button {
                DialogResult = System.Windows.Forms.DialogResult.Cancel, Top = 25
            };

            Form frm = new Form {
                ControlBox = false, AcceptButton = btnok, CancelButton = btncn, StartPosition = FormStartPosition.Manual, Location = ctrlpt
            };

            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            //######## SetColor to your preference
            frm.BackColor = Color.Black;

            RectangleF rec = new RectangleF(0, 0, (length + border), (20 + border));

            System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath(); //GetRoundedRect(rec, 4.0F);
            float      diameter = 8.0F;
            SizeF      sizef    = new SizeF(diameter, diameter);
            RectangleF arc      = new RectangleF(rec.Location, sizef);

            GP.AddArc(arc, 180, 90);
            arc.X = rec.Right - diameter;
            GP.AddArc(arc, 270, 90);
            arc.Y = rec.Bottom - diameter;
            GP.AddArc(arc, 0, 90);
            arc.X = rec.Left;
            GP.AddArc(arc, 90, 90);
            GP.CloseFigure();

            frm.Region = new Region(GP);
            frm.Controls.AddRange(new Control[] { input, btncn, btnok });
            DialogResult rst = frm.ShowDialog();

            output = input.Text;
            return(rst);
        }
Exemple #20
0
 public static System.Drawing.Drawing2D.GraphicsPath  RoundRectangle(Rectangle R, int Curve)
 {
     System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding);
     GP.AddArc(R.X, R.Y, Curve, Curve, 180.0F, 90.0F);
     GP.AddArc(R.Right - Curve, R.Y, Curve, Curve, 270.0F, 90.0F);
     GP.AddArc(R.Right - Curve, R.Bottom - Curve, Curve, Curve, 0.0F, 90.0F);
     GP.AddArc(R.X, R.Bottom - Curve, Curve, Curve, 90.0F, 90.0F);
     GP.CloseFigure();
     return(GP);
 }
Exemple #21
0
        public static System.Drawing.Drawing2D.GraphicsPath DrawEllipse(int x, int y, int height, int width)
        {
            var result = new System.Drawing.Drawing2D.GraphicsPath();

            result.AddEllipse(x, y, width * 2, height * 2);

            result.CloseFigure();

            return(result);
        }
        public void DrawMarkings(Graphics graphics)
        {
            // Create the pen for drawing the field lines with
            using (Pen linePen = new Pen(Color.Brown, linePenWidth)) {
                using (Brush courtBrush = new SolidBrush(Color.LightGray)) {
                    #region Draw the court surface
                    using (var path = new System.Drawing.Drawing2D.GraphicsPath()) {
                        float pos_frame_rad = 2.0F;
                        path.AddArc(new RectangleF(0.0F, 0.0F, (pos_frame_rad * 2), (pos_frame_rad * 2)), -180.0F, 90.0F);
                        path.AddArc(new RectangleF(Length - (pos_frame_rad * 2), 0.0F, (pos_frame_rad * 2), (pos_frame_rad * 2)), 270.0F, 90.0F);
                        path.AddArc(new RectangleF(Length - (pos_frame_rad * 2), Width - (pos_frame_rad * 2), (pos_frame_rad * 2), (pos_frame_rad * 2)), 0.0F, 90.0F);
                        path.AddArc(new RectangleF(0.0F, Width - (pos_frame_rad * 2), (pos_frame_rad * 2), (pos_frame_rad * 2)), 90.0F, 90.0F);
                        path.CloseFigure();
                        linePen.Width *= 2.0F;
                        graphics.DrawPath(linePen, path);
                        linePen.Width /= 2.0F;
                    }
                    #endregion

                    #region Draw central line
                    PointF fieldCenter      = new PointF(Length / 2, Width / 2);
                    PointF centerLineTop    = new PointF(fieldCenter.X, 0.0F);
                    PointF centerLineBottom = new PointF(fieldCenter.X, Width);
                    PointF leftLineTop      = new PointF(2.5F, 0.0F);
                    PointF leftLineBottom   = new PointF(2.5F, Width);
                    PointF rightLineTop     = new PointF(Length - 2.5F, 0.0F);
                    PointF rightLineBottom  = new PointF(Length - 2.5F, Width);

                    graphics.DrawLine(linePen, centerLineTop, centerLineBottom);
                    graphics.DrawLine(linePen, leftLineTop, leftLineBottom);
                    graphics.DrawLine(linePen, rightLineTop, rightLineBottom);
                    #endregion

                    #region Draw goal lines
                    DrawGoal(graphics, linePen, 3.0F - 0.5F, Width / 2.0F, true);
                    DrawGoal(graphics, linePen, Length - 3.0F + 0.5F, Width / 2.0F, !true);
                    #endregion Draw goal lines

                    #region Draw bully line
                    using (Pen bullyPen = new Pen(Color.Black, 0.09F)) {
                        DrawingCross(graphics, bullyPen, Length / 2.0F, 1.0F);
                        DrawingCross(graphics, bullyPen, HalfLength, HalfWidth);
                        DrawingCross(graphics, bullyPen, Length / 2.0F, Width - 1.0F);

                        DrawingCross(graphics, bullyPen, 2.5F, 1.0F);
                        DrawingCross(graphics, bullyPen, 2.5F, Width - 1.0F);

                        DrawingCross(graphics, bullyPen, Length - 2.5F, 1.0F);
                        DrawingCross(graphics, bullyPen, Length - 2.5F, Width - 1.0F);
                    }
                    #endregion Draw bully line
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// Creates a path based on a polygon.
        /// </summary>
        private System.Drawing.Drawing2D.GraphicsPath CreatePath(C2DPolyBase Poly)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();


            if (Poly.Lines.Count == 0)
            {
                return(gp);
            }

            for (int i = 0; i < Poly.Lines.Count; i++)
            {
                if (Poly.Lines[i] is C2DLine)
                {
                    C2DPoint ptFrom = Poly.Lines[i].GetPointFrom();
                    C2DPoint ptTo   = Poly.Lines[i].GetPointTo();
                    ScaleAndOffSet(ptFrom);
                    ScaleAndOffSet(ptTo);
                    gp.AddLine((int)ptFrom.x, (int)ptFrom.y, (int)ptTo.x, (int)ptTo.y);
                }
                else if (Poly.Lines[i] is C2DArc)
                {
                    C2DRect Rect        = new C2DRect();
                    int     nStartAngle = 0;
                    int     nSweepAngle = 0;

                    GetArcParameters(Poly.Lines[i] as C2DArc, Rect, ref nStartAngle, ref nSweepAngle);

                    if (nSweepAngle == 0)
                    {
                        nSweepAngle = 1;
                    }

                    int Width = (int)Rect.Width();
                    if (Width == 0)
                    {
                        Width = 1;
                    }
                    int Height = (int)Rect.Height();
                    if (Height == 0)
                    {
                        Height = 1;
                    }

                    gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                              Width, Height, nStartAngle, nSweepAngle);
                }
            }

            gp.CloseFigure();

            return(gp);
        }
 static void DrawRoundedRectangle(Graphics g, Pen p, int x, int y, int w, int h, int rx, int ry)
 {
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     path.AddArc(x, y, rx + rx, ry + ry, 180, 90);
     path.AddLine(x + rx, y, x + w - rx, y);
     path.AddArc(x + w - 2 * rx, y, 2 * rx, 2 * ry, 270, 90);
     path.AddLine(x + w, y + ry, x + w, y + h - ry);
     path.AddArc(x + w - 2 * rx, y + h - 2 * ry, rx + rx, ry + ry, 0, 91);
     path.AddLine(x + rx, y + h, x + w - rx, y + h);
     path.AddArc(x, y + h - 2 * ry, 2 * rx, 2 * ry, 90, 91);
     path.CloseFigure();
     g.DrawPath(p, path);
 }
        /// <summary>
        /// 未知方法,(现已废弃,替代方法 PointInPolygon)
        /// </summary>
        /// <param name="point"></param>
        /// <param name="pointColl"></param>
        /// <returns></returns>
        public static bool IsVisible_GraphicsPath(Point point, List <Point> pointColl)
        {
            System.Drawing.Drawing2D.GraphicsPath path       = new System.Drawing.Drawing2D.GraphicsPath();
            List <System.Drawing.Point>           pathPoints = new List <System.Drawing.Point>();

            foreach (var pathPoint in pointColl)
            {
                pathPoints.Add(new System.Drawing.Point((int)Math.Round(pathPoint.X), (int)Math.Round(pathPoint.Y)));
            }
            path.AddPolygon(pathPoints.ToArray());
            path.CloseFigure();
            return(path.IsVisible(new System.Drawing.Point((int)Math.Round(point.X), (int)Math.Round(point.Y))));
        }
Exemple #26
0
 void DrawRoundRect(Graphics g, Brush b, int x, int y, int w, int h, int r)
 {
     System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
     path.AddArc(x, y, r + r, r + r, 180, 90);
     path.AddLine(x + r, y, x + w - r, y);
     path.AddArc(x + w - 2 * r, y, 2 * r, 2 * r, 270, 90);
     path.AddLine(x + w, y + r, x + w, y + h - r);
     path.AddArc(x + w - 2 * r, y + h - 2 * r, r + r, r + r, 0, 91);
     path.AddLine(x + r, y + h, x + w - r, y + h);
     path.AddArc(x, y + h - 2 * r, 2 * r, 2 * r, 90, 91);
     path.CloseFigure();
     g.FillPath(b, path);
 }
Exemple #27
0
        private void FrmPolygonShape2_Paint(object sender, PaintEventArgs e)
        {
            /// zoom and shift the output
            Form   f = (Form)sender;
            double d = f.ClientSize.Width / (double)f.ClientSize.Height;

            _shiftX = pt.Min(a => a.X);
            _shiftY = pt.Min(a => a.Y);
            float  distX  = Math.Abs(pt.Max(a => a.X) - _shiftX);
            float  distY  = Math.Abs(pt.Max(a => a.Y) - _shiftY);
            double factor = distX / distY;

            _zoom = 1.0f;
            _zoom = factor >= d ? (float)(f.ClientSize.Width / distX) : (float)(f.ClientSize.Height / distY);

            e.Graphics.ScaleTransform(_zoom, _zoom);
            e.Graphics.TranslateTransform(-_shiftX * _zoom, -_shiftY * _zoom, System.Drawing.Drawing2D.MatrixOrder.Append);

            /// make nicer look
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            /// setup the path and test for being inside
            using (System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath())
            {
                myPath.AddLines(pt);
                myPath.CloseFigure();

                using (Pen pen = new Pen(Color.Blue, 4))
                    e.Graphics.DrawPath(pen, myPath);

                using (Pen pen = new Pen(Color.Blue))
                {
                    /// IsoutlineVisible is not needed normally
                    if (myPath.IsVisible(ptCheck) || myPath.IsOutlineVisible(ptCheck, pen))
                    {
                        this.Text = "inside - Origin at " + new PointF(_shiftX, _shiftY).ToString() + "; ZoomFacotr: ";// + _zoom.ToString();
                    }
                    else
                    {
                        this.Text = "outside - Origin at " + new PointF(_shiftX, _shiftY).ToString() + "; ZoomFacotr: ";// + _zoom.ToString();
                    }
                }
            }

            /// draw the testpoint as a small cross
            using (Pen pen = new Pen(Color.Red, 4))
            {
                e.Graphics.DrawLine(pen, ptCheck.X - 5 / _zoom, ptCheck.Y, ptCheck.X + 5 / _zoom, ptCheck.Y);
                e.Graphics.DrawLine(pen, ptCheck.X, ptCheck.Y - 5 / _zoom, ptCheck.X, ptCheck.Y + 5 / _zoom);
            }
        }
 /// <summary>
 /// Method to curve our form border
 /// </summary>
 void curve_border()
 {
     System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath();
     p.StartFigure();
     p.AddArc(new System.Drawing.RectangleF(0, 0, 40, 40), 180, 90);
     p.AddLine(40, 0, this.Width - 40, 0);
     p.AddArc(new RectangleF(this.Width - 40, 0, 40, 40), -90, 90);
     p.AddLine(this.Width, 40, this.Width, this.Height - 40);
     p.AddArc(new RectangleF(this.Width - 40, this.Height - 40, 40, 40), 0, 90);
     p.AddLine(this.Width - 40, this.Height, 40, this.Height);
     p.AddArc(new Rectangle(0, this.Height - 40, 40, 40), 90, 90);
     p.CloseFigure();
     this.Region = new Region(p);
 }
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, IPolygon polygon, IAreaStyle style)
        {
            if (polygon == null || style == null) return;

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddPolygon(RenderUtil.CoordToPoint(polygon.Shell.Coordinates));
            foreach (ILinearRing l in polygon.Holes)
                gp.AddPolygon(RenderUtil.CoordToPoint(l.Coordinates));
            gp.CloseFigure();

            if (style.Fill != null) RenderUtil.RenderFill(engine, graphics, gp, style.Fill);

            if (style.Outline != null) RenderUtil.RenderOutline(engine, graphics, gp, style.Outline);
        }
Exemple #30
0
		/// <summary>
		/// takes in a parsed path and returns a list of points that can be used to draw the path
		/// </summary>
		/// <returns>The drawing points.</returns>
		/// <param name="segments">Segments.</param>
		public Vector2[] getDrawingPoints( List<SvgPathSegment> segments, float flatness = 3 )
		{
			var path = new System.Drawing.Drawing2D.GraphicsPath();
			for( var j = 0; j < segments.Count; j++ )
			{
				var segment = segments[j];
				if( segment is SvgMoveToSegment )
				{
					path.StartFigure();
				}
				else if( segment is SvgCubicCurveSegment )
				{
					var cubicSegment = segment as SvgCubicCurveSegment;
					path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( cubicSegment.firstCtrlPoint ), toDrawPoint( cubicSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
				}
				else if( segment is SvgClosePathSegment )
				{
					// important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
					if( path.PointCount > 0 && !path.PathPoints[0].Equals( path.PathPoints[path.PathPoints.Length - 1] ) )
					{
						var i = path.PathTypes.Length - 1;
						while( i >= 0 && path.PathTypes[i] > 0 )
							i--;
						if( i < 0 )
							i = 0;
						path.AddLine( path.PathPoints[path.PathPoints.Length - 1], path.PathPoints[i] );
					}
					path.CloseFigure();
				}
				else if( segment is SvgLineSegment )
				{
					path.AddLine( toDrawPoint( segment.start ), toDrawPoint( segment.end ) );
				}
				else if( segment is SvgQuadraticCurveSegment )
				{
					var quadSegment = segment as SvgQuadraticCurveSegment;
					path.AddBezier( toDrawPoint( segment.start ), toDrawPoint( quadSegment.firstCtrlPoint ), toDrawPoint( quadSegment.secondCtrlPoint ), toDrawPoint( segment.end ) );
				}
				else
				{
					Debug.warn( "unknown type in getDrawingPoints" );
				}
			}

			path.Flatten( new System.Drawing.Drawing2D.Matrix(), flatness );

			return System.Array.ConvertAll( path.PathPoints, i => new Vector2( i.X, i.Y ) );
		}
Exemple #31
0
        private System.Drawing.Drawing2D.GraphicsPath GetRoundedRP(Rectangle rect, int a)
        {
            int       diameter = a;
            Rectangle arcRect  = new Rectangle(rect.Location, new Size(diameter, diameter));

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddArc(arcRect, 180, 90);
            arcRect.X = rect.Right - diameter;
            gp.AddArc(arcRect, 270, 90);
            arcRect.Y = rect.Bottom - diameter;
            gp.AddArc(arcRect, 0, 90);
            arcRect.X = rect.Left;
            gp.AddArc(arcRect, 90, 90);
            gp.CloseFigure();
            return(gp);
        }
Exemple #32
0
        private System.Drawing.Drawing2D.GraphicsPath GetRoundedRect(RectangleF baseRect,
                                                                     float radius)
        {
            // if corner radius is less than or equal to zero,
            // return the original rectangle
            if (radius <= 0.0F)
            {
                System.Drawing.Drawing2D.GraphicsPath mPath = new System.Drawing.Drawing2D.GraphicsPath();
                mPath.AddRectangle(baseRect);
                mPath.CloseFigure();
                return(mPath);
            }

            // if the corner radius is greater than or equal to
            // half the width, or height (whichever is shorter)
            // then return a capsule instead of a lozenge
            if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0)
            {
                return(GetCapsule(baseRect));
            }

            // create the arc for the rectangle sides and declare
            // a graphics path object for the drawing
            float      diameter = radius * 2.0F;
            SizeF      sizeF    = new SizeF(diameter, diameter);
            RectangleF arc      = new RectangleF(baseRect.Location, sizeF);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            // top left arc
            path.AddArc(arc, 180, 90);

            // top right arc
            arc.X = baseRect.Right - diameter;
            path.AddArc(arc, 270, 90);

            // bottom right arc
            arc.Y = baseRect.Bottom - diameter;
            path.AddArc(arc, 0, 90);

            // bottom left arc
            arc.X = baseRect.Left;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return(path);
        }
Exemple #33
0
 public static void DrawRoundedRectangleOutlined(Graphics gfxObj, Pen penObj, float X, float Y, float RectWidth, float RectHeight, float CornerRadius)
 {
     RectWidth--;
     RectHeight--;
     System.Drawing.Drawing2D.GraphicsPath gfxPath = new System.Drawing.Drawing2D.GraphicsPath();
     gfxPath.AddLine(X + CornerRadius, Y, X + RectWidth - (CornerRadius * 2), Y);
     gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y, CornerRadius * 2, CornerRadius * 2, 270, 90);
     gfxPath.AddLine(X + RectWidth, Y + CornerRadius, X + RectWidth, Y + RectHeight - (CornerRadius * 2));
     gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 0, 90);
     gfxPath.AddLine(X + RectWidth - (CornerRadius * 2), Y + RectHeight, X + CornerRadius, Y + RectHeight);
     gfxPath.AddArc(X, Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 90, 90);
     gfxPath.AddLine(X, Y + RectHeight - (CornerRadius * 2), X, Y + CornerRadius);
     gfxPath.AddArc(X, Y, CornerRadius * 2, CornerRadius * 2, 180, 90);
     gfxPath.CloseFigure();
     gfxObj.DrawPath(penObj, gfxPath);
     gfxPath.Dispose();
 }
        /// <summary>
        /// Creates a rounded corner rectangle from a regular rectangel
        /// </summary>
        /// <param name="baseRect"></param>
        /// <param name="radius"></param>
        /// <returns></returns>
        private System.Drawing.Drawing2D.GraphicsPath GetRoundedRect(RectangleF baseRect, float radius)
        {
            if ((radius <= 0.0F) || radius >= ((Math.Min(baseRect.Width, baseRect.Height)) / 2.0))
            {
                System.Drawing.Drawing2D.GraphicsPath mPath = new System.Drawing.Drawing2D.GraphicsPath();
                mPath.AddRectangle(baseRect);
                mPath.CloseFigure();
                return mPath;
            }

            float diameter = radius * 2.0F;
            SizeF sizeF = new SizeF(diameter, diameter);
            RectangleF arc = new RectangleF(baseRect.Location, sizeF);
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            // top left arc 
            path.AddArc(arc, 180, 90);

            // top right arc 
            arc.X = baseRect.Right - diameter;
            path.AddArc(arc, 270, 90);

            // bottom right arc 
            arc.Y = baseRect.Bottom - diameter;
            path.AddArc(arc, 0, 90);

            // bottom left arc
            arc.X = baseRect.Left;
            path.AddArc(arc, 90, 90);

            path.CloseFigure();
            return path;
        }
        /// <summary>
        /// Creates a path based on a polygon.
        /// </summary>
        private System.Drawing.Drawing2D.GraphicsPath CreatePath( C2DPolyBase Poly)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            if (Poly.Lines.Count == 0)
                return gp;

            for (int i = 0; i < Poly.Lines.Count; i++)
            {
                if (Poly.Lines[i] is C2DLine)
                {
                    C2DPoint ptFrom = Poly.Lines[i].GetPointFrom();
                    C2DPoint ptTo = Poly.Lines[i].GetPointTo();
                    ScaleAndOffSet(ptFrom);
                    ScaleAndOffSet(ptTo);
                    gp.AddLine((int)ptFrom.x, (int)ptFrom.y, (int)ptTo.x, (int)ptTo.y);
                }
                else if (Poly.Lines[i] is C2DArc)
                {

                    C2DRect Rect = new C2DRect();
                    int nStartAngle = 0;
                    int nSweepAngle = 0;

                    GetArcParameters(Poly.Lines[i] as C2DArc, Rect, ref nStartAngle, ref nSweepAngle);

                    if (nSweepAngle == 0)
                        nSweepAngle = 1;

                    int Width = (int)Rect.Width();
                    if (Width == 0)
                        Width = 1;
                    int Height = (int)Rect.Height();
                    if (Height == 0)
                        Height = 1;

                    gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                        Width, Height, nStartAngle, nSweepAngle);

                }
            }

            gp.CloseFigure();

            return gp;
        }
Exemple #36
0
		protected System.Drawing.Drawing2D.GraphicsPath GetPath()
		{
			System.Drawing.Drawing2D.GraphicsPath graphPath = new System.Drawing.Drawing2D.GraphicsPath();
			if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) 
			{
				graphPath.AddRectangle(this.ClientRectangle);
			} 
			else 
			{
				try 
				{
					int curve = 0;
					System.Drawing.Rectangle rect = this.ClientRectangle;
					int offset = 0;
					if (this._BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle) 
					{
						if (this._BorderWidth > 1) 
						{
							offset = DoubleToInt(this.BorderWidth / 2);
						}
						curve = this.adjustedCurve;
					} 
					else if (this._BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D) 
					{
					} 
					else if (this._BorderStyle == System.Windows.Forms.BorderStyle.None) 
					{
						curve = this.adjustedCurve;
					}
					if (curve == 0) 
					{
						graphPath.AddRectangle(System.Drawing.Rectangle.Inflate(rect, -offset, -offset));
					} 
					else 
					{
						int rectWidth = rect.Width - 1 - offset;
						int rectHeight = rect.Height - 1 - offset;
						int curveWidth = 1;
						if ((this._CurveMode & CornerCurveMode.TopRight) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90);
						if ((this._CurveMode & CornerCurveMode.BottomRight) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90);
						if ((this._CurveMode & CornerCurveMode.BottomLeft) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90);
						if ((this._CurveMode & CornerCurveMode.TopLeft) != 0) 
						{
							curveWidth = (curve * 2);
						} 
						else 
						{
							curveWidth = 1;
						}
						graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90);
						graphPath.CloseFigure();
					}
				} 
				catch (System.Exception) 
				{
					graphPath.AddRectangle(this.ClientRectangle);
				}
			}
			return graphPath;
		}
        // Zeichnet das Rechteck mit abgerundeten Ecken der Termindetails
        public void DrawRoundRect(Graphics g, Pen p, float x, float y, float width, float height, float radius)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddLine(x + radius, y, x + width - (radius * 2), y); // Line
            gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); // Corner
            gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); // Line
            gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
            gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); // Line
            gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner
            gp.AddLine(x, y + height - (radius * 2), x, y + radius); // Line
            gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); // Corner
            gp.CloseFigure();

            g.DrawPath(p, gp);
            gp.Dispose();
        }
            /// <summary>
            /// Creates a GraphicsPath object and adds an arc to it with the specified arc values and closure type.
            /// </summary>
            /// <param name="ellipseBounds">A RectangleF structure that represents the rectangular bounds of the ellipse from which the arc is taken.</param>
            /// <param name="start">The starting angle of the arc measured in degrees.</param>
            /// <param name="extent">The angular extent of the arc measured in degrees.</param>
            /// <param name="arcType">The closure type for the arc.</param>
            /// <returns>Returns a new GraphicsPath object that contains the arc path.</returns>
            public static System.Drawing.Drawing2D.GraphicsPath CreateArc2D(System.Drawing.RectangleF ellipseBounds, float start, float extent, int arcType)
            {
                System.Drawing.Drawing2D.GraphicsPath arc2DPath = new System.Drawing.Drawing2D.GraphicsPath();
                switch (arcType)
                {
                    case OPEN:
                        arc2DPath.AddArc(ellipseBounds, start * -1, extent * -1);
                        break;
                    case CLOSED:
                        arc2DPath.AddArc(ellipseBounds, start * -1, extent * -1);
                        arc2DPath.CloseFigure();
                        break;
                    case PIE:
                        arc2DPath.AddPie(ellipseBounds.X, ellipseBounds.Y, ellipseBounds.Width, ellipseBounds.Height, start * -1, extent * -1);
                        break;
                    default:
                        break;
                }

                return arc2DPath;
            }
 /// <summary>
 /// Creates a GraphicsPath object and adds an arc to it with the specified arc values and closure type.
 /// </summary>
 /// <param name="x">The x coordinate of the upper-left corner of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="y">The y coordinate of the upper-left corner of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="height">The height of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="width">The width of the rectangular region that defines the ellipse from which the arc is drawn.</param>
 /// <param name="start">The starting angle of the arc measured in degrees.</param>
 /// <param name="extent">The angular extent of the arc measured in degrees.</param>
 /// <param name="arcType">The closure type for the arc.</param>
 /// <returns>Returns a new GraphicsPath object that contains the arc path.</returns>
 public static System.Drawing.Drawing2D.GraphicsPath CreateArc2D(float x, float y, float height, float width, float start, float extent, int arcType)
 {
     System.Drawing.Drawing2D.GraphicsPath arc2DPath = new System.Drawing.Drawing2D.GraphicsPath();
     switch (arcType)
     {
         case OPEN:
             arc2DPath.AddArc(x, y, height, width, start * -1, extent * -1);
             break;
         case CLOSED:
             arc2DPath.AddArc(x, y, height, width, start * -1, extent * -1);
             arc2DPath.CloseFigure();
             break;
         case PIE:
             arc2DPath.AddPie(x, y, height, width, start * -1, extent * -1);
             break;
         default:
             break;
     }
     return arc2DPath;
 }
        public void Render(LittleSharpRenderEngine engine, Graphics graphics, IPoint point, IPointStyle style)
        {
            if (point == null || style == null)
                return;

            if (style.Type == global::LittleSharpRenderEngine.Style.Point.PointType.Symbol)
            {
                return;
            }
            else
            {
                int w = style.Size.Width / 2;
                int h = style.Size.Height / 2;
                System.Drawing.Point[] points;

                switch (style.Type)
                {
                    case global::LittleSharpRenderEngine.Style.Point.PointType.Circle:
                        int pc = (int)Math.Max(8, Math.Log10(Math.Max(w, h)));
                        points = new System.Drawing.Point[pc + 1];

                        double fr = (2*Math.PI) / pc;

                        for (int i = 0; i < pc; i++)
                            points[i] = new System.Drawing.Point((int)(Math.Cos(fr * i) * w + point.X), (int)(Math.Sin(fr * i) * h + point.Y));
                        points[pc] = points[0];
                        break;
                    case global::LittleSharpRenderEngine.Style.Point.PointType.Square:
                        points = new System.Drawing.Point[] 
                                {
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y - h),
                                    new System.Drawing.Point((int)point.X + w, (int)point.Y - h),
                                    new System.Drawing.Point((int)point.X + w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y - h),
                                };
                        break;
                    case global::LittleSharpRenderEngine.Style.Point.PointType.Triangle:
                        points = new System.Drawing.Point[] 
                                {
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X, (int)point.Y - h),
                                    new System.Drawing.Point((int)point.X + w, (int)point.Y + h),
                                    new System.Drawing.Point((int)point.X - w, (int)point.Y + h),
                                };
                        break;
                    default:
                        return;
                }

                //TODO: Apply rotation
                if (style.Type != global::LittleSharpRenderEngine.Style.Point.PointType.Circle)
                {
                }

                //Apply offset
                for (int i = 0; i < points.Length; i++)
                {
                    points[i].X += (w - style.Center.X);
                    points[i].Y += (h - style.Center.Y);
                }

                System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
                gp.AddPolygon(points);
                gp.CloseFigure();

                if (style.Fill != null)
                    RenderUtil.RenderFill(engine, graphics, gp, style.Fill);

                if (style.Outline != null)
                    RenderUtil.RenderOutline(engine, graphics, gp, style.Outline);
            }
        }
Exemple #41
0
        /// <summary>角の丸い矩形のGraphicsPathを生成する</summary>
        public static System.Drawing.Drawing2D.GraphicsPath CreateRoundedGraphicsPath(RectangleF bounds, float xRadius, float yRadius) {
            float left = bounds.X;
            float top = bounds.Y;
            float right = bounds.Right;
            float bottom = bounds.Bottom;

            var path = new System.Drawing.Drawing2D.GraphicsPath();
            path.StartFigure();
            path.AddArc(left, top, xRadius * 2, yRadius * 2, 180, 90);
            path.AddArc(right - xRadius * 2, top, xRadius * 2, yRadius * 2, 270, 90);
            path.AddArc(right - xRadius * 2, bottom - yRadius * 2, xRadius * 2, yRadius * 2, 0, 90);
            path.AddArc(left, bottom - yRadius * 2, xRadius * 2, xRadius * 2, 90, 90);
            path.CloseFigure();

            return path;
        }
Exemple #42
0
        private System.Drawing.Drawing2D.GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
        {
            int diameter = radius;
            Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            // 左上角
            path.AddArc(arcRect, 180, 90);

            // 右上角
            arcRect.X = rect.Right - diameter;
            path.AddArc(arcRect, 270, 90);

            // 右下角
            arcRect.Y = rect.Bottom - diameter;
            path.AddArc(arcRect, 0, 90);

            // 左下角
            arcRect.X = rect.Left;
            path.AddArc(arcRect, 90, 90);
            path.CloseFigure();//闭合曲线
            return path;
        }
Exemple #43
0
 public static void DrawRoundedRectangleOutlined(Graphics gfxObj, Pen penObj, float X, float Y, float RectWidth, float RectHeight, float CornerRadius)
 {
     RectWidth--;
     RectHeight--;
     System.Drawing.Drawing2D.GraphicsPath gfxPath = new System.Drawing.Drawing2D.GraphicsPath();
     gfxPath.AddLine(X + CornerRadius, Y, X + RectWidth - (CornerRadius * 2), Y);
     gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y, CornerRadius * 2, CornerRadius * 2, 270, 90);
     gfxPath.AddLine(X + RectWidth, Y + CornerRadius, X + RectWidth, Y + RectHeight - (CornerRadius * 2));
     gfxPath.AddArc(X + RectWidth - (CornerRadius * 2), Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 0, 90);
     gfxPath.AddLine(X + RectWidth - (CornerRadius * 2), Y + RectHeight, X + CornerRadius, Y + RectHeight);
     gfxPath.AddArc(X, Y + RectHeight - (CornerRadius * 2), CornerRadius * 2, CornerRadius * 2, 90, 90);
     gfxPath.AddLine(X, Y + RectHeight - (CornerRadius * 2), X, Y + CornerRadius);
     gfxPath.AddArc(X, Y, CornerRadius * 2, CornerRadius * 2, 180, 90);
     gfxPath.CloseFigure();
     gfxObj.DrawPath(penObj, gfxPath);
     gfxPath.Dispose();
 }
        private System.Drawing.Drawing2D.GraphicsPath RoundRectangle(Rectangle r, int radius, Corners corners)
        {
            //Make sure the Path fits inside the rectangle
            r.Width -= 1;
            r.Height -= 1;

            //Scale the radius if it's too large to fit.
            if (radius > (r.Width))
                radius = r.Width;
            if (radius > (r.Height))
                radius = r.Height;

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

            if (radius <= 0)
                path.AddRectangle(r);
            else
                if ((corners & Corners.TopLeft) == Corners.TopLeft)
                    path.AddArc(r.Left, r.Top, radius, radius, 180, 90);
                else
                    path.AddLine(r.Left, r.Top, r.Left, r.Top);

            if ((corners & Corners.TopRight) == Corners.TopRight)
                path.AddArc(r.Right - radius, r.Top, radius, radius, 270, 90);
            else
                path.AddLine(r.Right, r.Top, r.Right, r.Top);

            if ((corners & Corners.BottomRight) == Corners.BottomRight)
                path.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, 0, 90);
            else
                path.AddLine(r.Right, r.Bottom, r.Right, r.Bottom);

            if ((corners & Corners.BottomLeft) == Corners.BottomLeft)
                path.AddArc(r.Left, r.Bottom - radius, radius, radius, 90, 90);
            else
                path.AddLine(r.Left, r.Bottom, r.Left, r.Bottom);

            path.CloseFigure();

            return path;
        }
Exemple #45
0
        private void Carte_Paint(object sender, PaintEventArgs e)
        {
            int i;
            double w, h;
            //projet = ((Musliw.MusliW)(this.MdiParent)).projet;
            Graphics page = e.Graphics;

            //page.Clear(this.BackColor);

            w = this.Width;
            h = this.Height;

            Pen stylo = new Pen(fen.stylo_couleur, (int)fen.epaisseur);
            Font fonte = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold);
            this.ForeColor = Color.Black;
            Brush brosse =new SolidBrush(fen.brosse_couleur);
            Brush brosse_texte = new SolidBrush(fen.couleur_texte);
            double dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
            double dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
            double deltax,deltay,voldeltax,voldeltay;
            double cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
            double cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);

            //MessageBox.Show(xl.ToString() + " " + yu.ToString());
            PointF p1=new PointF();
            PointF p2 = new PointF();
            PointF p3 = new PointF();
            PointF p4 = new PointF();
            PointF p5 = new PointF();

            PointF[] points = new PointF[4] ;
               double angle=0,norme=0;
            double sinx = 0, cosx = 1;
            if (fen.volume_echelle < 1e-6f)
            {
                fen.volume_echelle = 1e-6f;
            }
            for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
            {
                norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
                {

                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                cosx = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
                sinx = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);

                    voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    page.DrawLine(stylo, (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay), (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax),(float) (((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay),(float) (((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax));

                    p1.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay);
                    p1.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax);
                    p2.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay);
                    p2.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax);
                    p3.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay);
                    p3.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax);
                    p4.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay);
                    p4.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);

                    System.Drawing.Drawing2D.GraphicsPath epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    epaisseur.StartFigure();
                    points[0] = p1;
                    points[1] = p2;
                    points[2] = p3;
                    points[3] = p4;

                    epaisseur.AddPolygon(points);
                    epaisseur.CloseFigure();
                    //page.FillPath(brosse, epaisseur);
                    //page.FillPolygon(brosse, points);
                    //page.DrawPolygon(stylo,points);
                    epaisseur.Reset();
                    texte_epaisseur.StartFigure();
                    p5.X = 0.5f * (p3.X + p2.X);
                    p5.Y = 0.5f * (p3.Y + p2.Y);
                    texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, (float)fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
                    RectangleF encombrement = texte_epaisseur.GetBounds();
                    // texte_epaisseur.AddRectangle(encombrement);
                    //texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);

                    page.FillPolygon(brosse, points);
                    page.DrawPolygon(stylo, points);

                    if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
                    {
                        System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();

                        if (cosx >= 0 && sinx <= 0)
                        {
                            angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();
                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx <= 0 && sinx >= 0)
                        {
                            angle = 180f - 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx >= 0 && sinx >= 0)
                        {
                            angle = -180f * (float)Math.Acos(cosx) / (float)Math.PI;
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx <= 0)
                        {
                            angle = 180 + 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }

                    }
                    epaisseur.Dispose();
                    texte_epaisseur.Dispose();
                }

            }
            /*        for (i = 0; i < projet.reseaux[nproj].nodes.Count; i++)
            {
                if (projet.reseaux[nproj].nodes[i].i != 0)
                {
                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                    page.FillRectangle(brosse, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawRectangle(stylo, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawString(res.nodes[i].i.ToString(), fonte, Brushes.Black, new RectangleF((res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f));
                }
            }*/
        }
        static System.Drawing.Drawing2D.GraphicsPath ResolveGraphicsPath(GraphicsPath path)
        {
            //convert from graphics path to internal presentation
            System.Drawing.Drawing2D.GraphicsPath innerPath = path.InnerPath as System.Drawing.Drawing2D.GraphicsPath;
            if (innerPath != null)
            {
                return innerPath;
            }
            //--------
            innerPath = new System.Drawing.Drawing2D.GraphicsPath();
            path.InnerPath = innerPath;
            List<float> points;
            List<PathCommand> cmds;
            GraphicsPath.GetPathData(path, out points, out cmds);
            int j = cmds.Count;
            int p_index = 0;
            for (int i = 0; i < j; ++i)
            {
                PathCommand cmd = cmds[i];
                switch (cmd)
                {
                    default:
                        throw new NotSupportedException();
                    case PathCommand.Arc:
                        innerPath.AddArc(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3],
                            points[p_index + 4],
                            points[p_index + 5]);
                        p_index += 6;
                        break;
                    case PathCommand.Bezier:
                        innerPath.AddBezier(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3],
                            points[p_index + 4],
                            points[p_index + 5],
                            points[p_index + 6],
                            points[p_index + 7]);
                        p_index += 8;
                        break;
                    case PathCommand.CloseFigure:
                        innerPath.CloseFigure();
                        break;
                    case PathCommand.Ellipse:
                        innerPath.AddEllipse(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]);
                        p_index += 4;
                        break;
                    case PathCommand.Line:
                        innerPath.AddLine(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]);
                        p_index += 4;
                        break;
                    case PathCommand.Rect:
                        innerPath.AddRectangle(
                           new System.Drawing.RectangleF(
                          points[p_index],
                          points[p_index + 1],
                          points[p_index + 2],
                          points[p_index + 3]));
                        p_index += 4;
                        break;
                    case PathCommand.StartFigure:
                        break;
                }
            }


            return innerPath;
        }
Exemple #47
0
 private void DrawRoundRect(Graphics g, float x, float y, float width, float height, float radius, Color color)
 {
     System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
     gp.AddLine(x + radius, y, x + width - (radius * 2), y); //追加线段
     gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);  //追加椭圆弧
     gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
     gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
     gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
     gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
     gp.AddLine(x, y + height - (radius * 2), x, y + radius);
     gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
     gp.CloseFigure();
     Pen pen = new System.Drawing.Pen(ColorTranslator.FromHtml("#CCCCCC"), 1);
     g.DrawPath(pen, gp);
     Rectangle rec = new Rectangle((int)x, (int)y, (int)width, (int)height);
     Brush brush = new System.Drawing.SolidBrush(color);
     g.FillPath(brush, gp);
     gp.Dispose();
 }