示例#1
0
        public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;

            Pen pen;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }
            GraphicsPath gp = new GraphicsPath();

            gp.AddLine(startPoint, endPoint);
            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            gp.Dispose();
            pen.Dispose();
        }
示例#2
0
        public override void Draw(Graphics g)
        {
            Pen   pen;
            Brush b = new SolidBrush(FillColor);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }
            GraphicsPath gp = new GraphicsPath();

            gp.AddEllipse(GetNormalizedRectangle(Rectangle));
            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            if (Filled)
            {
                g.FillPath(b, gp);
            }

            gp.Dispose();
            pen.Dispose();
            b.Dispose();
        }
示例#3
0
        public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Brush b = new SolidBrush(Color.Red);
            Pen   pen;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }
            GraphicsPath gp = new GraphicsPath();

            foreach (Point pt in pointList)
            {
                gp.AddEllipse(new Rectangle(pt, new Size(1, 1)));
            }
            g.DrawPath(pen, gp);
            g.FillPath(b, gp);
            gp.Dispose();
            b.Dispose();
            pen.Dispose();
        }
示例#4
0
        public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen = null;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = DrawPen.Clone() as Pen;
            }

            Point[] pts = new Point[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                Point px = (Point)pointArray[i];
                pts[i] = px;
            }
            byte[] types = new byte[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                types[i] = (byte)PathPointType.Line;
            }
            GraphicsPath gp = new GraphicsPath(pts, types);

            g.DrawPath(pen, gp);
            gp.Dispose();

            pen.Dispose();
        }
示例#5
0
        /// <summary>
        /// Draw rectangle
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            Pen   pen;
            Brush b = new SolidBrush(FillColor);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }

            GraphicsPath gp = new GraphicsPath();

            gp.AddRectangle(GetNormalizedRectangle(Rectangle));
            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }

            g.DrawPath(pen, gp);
            if (Filled)
            {
                g.FillPath(b, gp);
            }
            /////////////////////////////
            // Draw string for Name and Description
            /////////////////////////////


            Font       drawFont  = new Font("Arial", 10);
            SolidBrush drawBrush = new SolidBrush(Color.Black);

            // Set format of string.
            StringFormat drawFormat = new StringFormat();

            drawFormat.Alignment = StringAlignment.Center;

            // Draw string to screen.
            g.DrawString(FunctionName, drawFont, drawBrush, Rectangle, drawFormat);

            ///////////////////////////////////////
            // End of Drawing strings
            //////////////////////////////////////
            gp.Dispose();
            pen.Dispose();
            b.Dispose();
        }
示例#6
0
        public override void Draw(Graphics g)
        {
            Pen   pen;
            Brush b  = new SolidBrush(FillColor);
            Brush b1 = new LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 255));
            Brush b2 = new HatchBrush(HatchStyle.Cross, Color.Azure);
            Brush b3 = new TextureBrush(FillImage);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }

            GraphicsPath gp = new GraphicsPath();

            gp.AddRectangle(GetNormalizedRectangle(Rectangle));
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            if (Filled)
            {
                g.FillPath(b, gp);
            }
            if (Gradient)
            {
                g.FillPath(b1, gp);
            }
            if (Hatch)
            {
                g.FillPath(b2, gp);
            }
            if (Texture)
            {
                g.FillPath(b3, gp);
            }
            gp.Dispose();
            pen.Dispose();
            b.Dispose();
            b1.Dispose();
            b2.Dispose();
            b3.Dispose();
        }
示例#7
0
        public override void Draw(Graphics g)
        {
            if (pointArray.Count == 0)
            {
                return;
            }

            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = DrawPen.Clone() as Pen;
            }

            Point[] pts = new Point[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                Point px = (Point)pointArray[i];
                pts[i] = px;
            }
            byte[] types = new byte[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                types[i] = (byte)PathPointType.Line;
            }

            GraphicsPath gp = new GraphicsPath(pts, types);

            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            //g.DrawCurve(pen, pts);
            gp.Dispose();
            if (pen != null)
            {
                pen.Dispose();
            }
        }
示例#8
0
        public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;

            Pen pen = new Pen(Color.Black);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }

            g.DrawLine(pen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);

            pen.Dispose();
        }
示例#9
0
        public override void Draw(Graphics g)
        {
            Pen   pen = new Pen(Color.Black);
            Brush b   = new SolidBrush(FillColor);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }

            g.DrawEllipse(pen, DrawRectangle.GetNormalizedRectangle(Rectangle));
            if (Filled == true)
            {
                g.FillEllipse(b, DrawRectangle.GetNormalizedRectangle(Rectangle));
            }

            pen.Dispose();
            b.Dispose();
        }
示例#10
0
        /// <summary>
        /// Draw rectangle
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            Pen   pen = new Pen(Color.Black);
            Brush b   = new SolidBrush(FillColor);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }

            g.DrawRectangle(pen, DrawRectangle.GetNormalizedRectangle(Rectangle));
            if (Filled == true)
            {
                g.FillRectangle(b, DrawRectangle.GetNormalizedRectangle(Rectangle));
            }

            Console.WriteLine("Drew Rectangle at " + Rectangle.X + " " + Rectangle.Y);
            pen.Dispose();
            b.Dispose();
        }
示例#11
0
        public override void Draw(Graphics g)
        {
            //int x1 = 0, y1 = 0;     // previous point
            //int x2, y2;             // current point

            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen = null;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = DrawPen.Clone() as Pen;
            }

            // Convert the array of points to a GraphicsPath object so lines are mitered correctly at the intersections
            // (not to mention the object is drawn faster then drawing individual lines)
            Point[] pts = new Point[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                Point px = (Point)pointArray[i];
                pts[i] = px;
            }
            byte[] types = new byte[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                types[i] = (byte)PathPointType.Line;
            }
            GraphicsPath gp = new GraphicsPath(pts, types);

            g.DrawPath(pen, gp);
            gp.Dispose();
            pen.Dispose();
        }
示例#12
0
        public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = DrawPen.Clone() as Pen;
            }

            // Convert the array of points to a GraphicsPath object so lines are mitered correctly at the intersections
            // (not to mention the object is drawn faster then drawing individual lines)
            Point[] pts = new Point[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                Point px = (Point)pointArray[i];
                pts[i] = px;
            }
            byte[] types = new byte[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                types[i] = (byte)PathPointType.Line;
            }
            GraphicsPath gp = new GraphicsPath(pts, types);

            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            //g.DrawCurve(pen, pts);
            //
            //// For DrawBeziers() to work, the pts array must have a minimum of 4 points.
            //// The pts array may have more than 4 points, but if so, then after the first 4 points, remaining points must be in sets of 3 for the call to work.
            //// The following code will adjust the pts array to properly fit these requirements.
            //int numPoints = pts.Length;
            //if (numPoints - 4 <= 0)
            //{
            //    // Cannot call DrawBeziers() so return, drawing nothing.
            //    gp.Dispose();
            //    pen.Dispose();
            //    return;
            //}
            //while ((numPoints - 4) % 3 != 0 && numPoints - 4 > 0)
            //{
            //    // Chop off the last point from the pts array
            //    numPoints--;
            //    Array.Resize(ref pts, numPoints);
            //}
            //g.DrawBeziers(pen, pts);
            gp.Dispose();
            if (pen != null)
            {
                pen.Dispose();
            }
        }
示例#13
0
        public override void Draw(Graphics g)
        {
            Pen          pen;
            GraphicsPath gp = new GraphicsPath();
            Brush        b  = new SolidBrush(FillColor);
            Brush        b1 = new LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 255));
            Brush        b2 = new HatchBrush(HatchStyle.Cross, Color.Azure);
            Brush        b3 = new TextureBrush(FillImage);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }

            Rectangle rect = DrawRectangle.GetNormalizedRectangle(Rectangle);

            if (ShapeName == SpecialShape.ShapeName.Triangle)
            {
                PointF[] ListPoint =
                {
                    new PointF(rect.X + rect.Width / 2, rect.Y),
                    new PointF(rect.X + rect.Width,     rect.Y + rect.Height),
                    new PointF(rect.X,                  rect.Y + rect.Height),
                    new PointF(rect.X + rect.Width / 2, rect.Y)
                };
                gp.AddLines(ListPoint);
            }
            else if (ShapeName == SpecialShape.ShapeName.RightTriangle)
            {
                PointF[] ListPoint =
                {
                    new PointF(rect.X,              rect.Y),
                    new PointF(rect.X + rect.Width, rect.Y + rect.Height),
                    new PointF(rect.X,              rect.Y + rect.Height),
                    new PointF(rect.X,              rect.Y)
                };
                gp.AddLines(ListPoint);
            }
            else if (ShapeName == SpecialShape.ShapeName.RoundedRectangle)
            {
                int rad = 60;
                gp.AddArc(rect.X, rect.Y, rad, rad, 180, 90);
                gp.AddArc(rect.X + rect.Width - rad, rect.Y, rad, rad, 270, 90);
                gp.AddArc(rect.X + rect.Width - rad, rect.Y + rect.Height - rad, rad, rad, 0, 90);
                gp.AddArc(rect.X, rect.Y + rect.Height - rad, rad, rad, 90, 90);
                gp.AddLine(rect.X, rect.Y + rect.Height - rad, rect.X, rect.Y + rad / 2);
            }
            else if (ShapeName == SpecialShape.ShapeName.Arrow)
            {
                PointF[] ListPoint =
                {
                    new PointF(rect.X + rect.Width / 2, rect.Y),
                    new PointF(rect.X + rect.Width,     rect.Y + rect.Height / 2),
                    new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height),
                    new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height * 3 / 4),
                    new PointF(rect.X,                  rect.Y + rect.Height * 3 / 4),
                    new PointF(rect.X,                  rect.Y + rect.Height / 4),
                    new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 4),
                    new PointF(rect.X + rect.Width / 2, rect.Y)
                };
                gp.AddLines(ListPoint);
            }
            else if (ShapeName == SpecialShape.ShapeName.Star)
            {
                PointF[] ListPoint =
                {
                    new PointF(rect.X + rect.Width / 2,        rect.Y),
                    new PointF(rect.X + rect.Width * 6 / 10,   rect.Y + rect.Height * 4 / 10),
                    new PointF(rect.X + rect.Width,            rect.Y + rect.Height * 4 / 10),
                    new PointF(rect.X + rect.Width * 65 / 100, rect.Y + rect.Height * 65 / 100),
                    new PointF(rect.X + rect.Width * 3 / 4,    rect.Y + rect.Height),
                    new PointF(rect.X + rect.Width / 2,        rect.Y + rect.Height * 78 / 100),
                    new PointF(rect.X + rect.Width / 4,        rect.Y + rect.Height),
                    new PointF(rect.X + rect.Width * 35 / 100, rect.Y + rect.Height * 65 / 100),
                    new PointF(rect.X,                         rect.Y + rect.Height * 4 / 10),
                    new PointF(rect.X + rect.Width * 4 / 10,   rect.Y + rect.Height * 4 / 10),
                    new PointF(rect.X + rect.Width / 2,        rect.Y)
                };
                gp.AddLines(ListPoint);
            }
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            if (Filled)
            {
                g.FillPath(b, gp);
            }
            if (Gradient)
            {
                g.FillPath(b1, gp);
            }
            if (Hatch)
            {
                g.FillPath(b2, gp);
            }
            if (Texture)
            {
                g.FillPath(b3, gp);
            }
            gp.Dispose();
            pen.Dispose();
            b.Dispose();
            b1.Dispose();
            b2.Dispose();
            b3.Dispose();
        }
示例#14
0
        public void CreateBitmap(int w, int h, uint argb, int lineW, string fname)
        {
            DrawContext dc = Controller.DC;

            CadObjectDB db = Controller.DB;

            List <uint> idlist = Controller.DB.GetSelectedFigIDList();

            var figList = new List <CadFigure>();

            idlist.ForEach(id =>
            {
                figList.Add(db.GetFigure(id));
            });

            CadRect r = CadUtil.GetContainsRectScrn(dc, figList);

            CadRect wr = default(CadRect);

            wr.p0 = dc.DevPointToWorldPoint(r.p0);
            wr.p1 = dc.DevPointToWorldPoint(r.p1);

            DrawContextGDIBmp tdc = new DrawContextGDIBmp();

            tdc.WorldScale = dc.WorldScale;

            tdc.SetCamera(dc.Eye, dc.LookAt, dc.UpVector);
            tdc.CalcProjectionMatrix();

            tdc.SetViewSize(w, h);

            tdc.SetViewOrg(new Vector3d(w / 2, h / 2, 0));

            tdc.SetupTools(DrawTools.DrawMode.DARK);

            Pen pen = new Pen(Color.FromArgb((int)argb), lineW);

            DrawPen drawPen = new DrawPen(pen);

            double sw = r.p1.X - r.p0.X;
            double sh = r.p1.Y - r.p0.Y;

            double a = Math.Min(w, h) / (Math.Max(sw, sh) + lineW);

            tdc.DeviceScaleX *= a;
            tdc.DeviceScaleY *= a;

            CadRect tr = CadUtil.GetContainsRectScrn(tdc, figList);

            Vector3d trcp = (Vector3d)((tr.p1 - tr.p0) / 2 + tr.p0);

            Vector3d d = trcp - tdc.ViewOrg;

            tdc.SetViewOrg(tdc.ViewOrg - d);

            DrawParams dp = default;

            dp.LinePen = drawPen;
            dp.EdgePen = drawPen;

            Env.RunOnMainThread((Action)(() =>
            {
                tdc.Drawing.Clear(dc.GetBrush(DrawTools.BRUSH_TRANSPARENT));

                tdc.GdiGraphics.SmoothingMode = SmoothingMode.AntiAlias;

                foreach (CadFigure fig in figList)
                {
                    fig.Draw(tdc, dp);
                }

                if (fname.Length > 0)
                {
                    tdc.Image.Save(fname);
                }
                else
                {
                    BitmapUtil.BitmapToClipboardAsPNG(tdc.Image);
                }

                tdc.Dispose();
                drawPen.Dispose();
            }));
        }