DrawPath() public method

public DrawPath ( Pen pen, GraphicsPath path ) : void
pen Pen
path System.Drawing.Drawing2D.GraphicsPath
return void
Exemplo n.º 1
2
 public static void DrawRoundRectangle(Graphics g, Pen pen, Rectangle rect, int cornerRadius)
 {
     using (GraphicsPath path = CreateRoundedRectanglePath(rect, cornerRadius))
     {
         g.DrawPath(pen, path);
     }
 }
Exemplo n.º 2
1
        protected override void Draw(Graphics g)
        {
            if (points.Count > 2)
            {
                g.SmoothingMode = SmoothingMode.HighQuality;

                borderDotPen.DashOffset = (float)timer.Elapsed.TotalSeconds * 10;
                borderDotPen2.DashOffset = 5 + (float)timer.Elapsed.TotalSeconds * 10;

                using (Region region = new Region(regionFillPath))
                {
                    g.Clip = region;
                    g.FillRectangle(lightBackgroundBrush, ScreenRectangle0Based);
                    g.ResetClip();
                }

                g.DrawPath(borderDotPen, regionFillPath);
                g.DrawPath(borderDotPen2, regionFillPath);
                g.DrawLine(borderDotPen, points[points.Count - 1], points[0]);
                g.DrawLine(borderDotPen2, points[points.Count - 1], points[0]);
                g.DrawRectangleProper(borderPen, currentArea);
            }

            base.Draw(g);
        }
Exemplo n.º 3
1
        protected override void Draw(Graphics g)
        {
            if (points.Count > 2)
            {
                g.SmoothingMode = SmoothingMode.HighQuality;

                if (Config.UseDimming)
                {
                    using (Region region = new Region(regionFillPath))
                    {
                        g.Clip = region;
                        g.FillRectangle(lightBackgroundBrush, ScreenRectangle0Based);
                        g.ResetClip();
                    }
                }

                g.DrawPath(borderPen, regionFillPath);
                g.DrawPath(borderDotPen, regionFillPath);
                g.DrawLine(borderPen, points[points.Count - 1], points[0]);
                g.DrawLine(borderDotPen, points[points.Count - 1], points[0]);
                g.DrawRectangleProper(borderPen, currentArea);
            }

            base.Draw(g);
        }
Exemplo n.º 4
1
 // paramters:
 //      pen 绘制边框。可以为null,那样就整体一个填充色,没有边框
 //      brush   绘制填充色。可以为null,那样就只有边框
 public static void RoundRectangle(Graphics graphics,
     Pen pen,
     Brush brush,
     float x,
     float y,
     float width,
     float height,
     float radius)
 {
     using (GraphicsPath path = new GraphicsPath())
     {
         path.AddLine(x + radius, y, x + width - (radius * 2), y);
         path.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
         path.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
         path.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner
         path.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
         path.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
         path.AddLine(x, y + height - (radius * 2), x, y + radius);
         path.AddArc(x, y, radius * 2, radius * 2, 180, 90);
         path.CloseFigure();
         if (brush != null)
             graphics.FillPath(brush, path);
         if (pen != null)
             graphics.DrawPath(pen, path);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">Graphics reference</param>
        /// <param name="labelPoint">Label placement</param>
        /// <param name="offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text
            labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset
            if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// This routine draws the animated bomb
        /// using two toggling graphics paths
        /// giving the effect of a spinning bomb
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            UpdateBounds();
            Matrix m = new Matrix();

            m.Translate(MovingBounds.Left, MovingBounds.Top);
            // g.FillRectangle(Brushes.White , MovingBounds);
            if (_invert)
            {

                bombInTransformed = (GraphicsPath)bombIn.Clone();
                bombInTransformed.Transform(m);
                g.DrawPath(BombPen, bombInTransformed);
                bombInTransformed.Dispose();
            }
            else
            {
                bombOutTransformed = (GraphicsPath)bombOut.Clone();
                bombOutTransformed.Transform(m);
                g.DrawPath(BombPen, bombOutTransformed);
                bombOutTransformed.Dispose();
            }

              /*          Matrix flipMatrix = new Matrix();
            flipMatrix.Scale(-1.0f, 1.0f);

            m.Translate(MovingBounds.Left, MovingBounds.Top);

            if (_invert)
            {
                m.Scale(-1, 1);  // flip around the y axis
            }

            // g.FillRectangle(Brushes.White , MovingBounds);
                bombInTransformed = (GraphicsPath)bombIn.Clone();
                bombInTransformed.Transform(m);

                g.DrawPath(BombPen, bombInTransformed);
                bombInTransformed.Dispose();
            */

            _invert = !_invert;

            //            g.DrawPolygon(Pens.White, new PointF[]{new PointF(Position.X, Position.Y),
            //                                                   new PointF(Position.X + width, Position.Y + seg),
            //                                                   new PointF(Position.X, Position.Y + seg*2),
            //                                                    new PointF(Position.X + 3, Position.Y + seg*3)});

            Position.Y += TheBombInterval;
        }
Exemplo n.º 7
0
 private void DrawGlow(Graphics g)
 {
     GraphicsPath p = new GraphicsPath();
     Point [] border = {
                         new Point(0			, 0			),
                         new Point(Width-1	, 0			),
                         new Point(Width-1	, Height-1	),
                         new Point(0			, Height-1	)
                     };
     p.AddPolygon(border);
     g.SmoothingMode = SmoothingMode.AntiAlias;
     g.DrawPath(new Pen(Color.Gold, 3), p);
     g.DrawPath(new Pen(Color.FromArgb(200, Color.White), 1), p);
 }
 public virtual void Draw(Graphics g)
 {
     GraphicsPath usepath = new GraphicsPath();
     usepath.AddString(usecharacter.ToString(), useFont.FontFamily, (int)useFont.Style, useFont.Size, currentposition,StringFormat.GenericDefault);
     g.FillPath(fillbrush, usepath);
     g.DrawPath(strokepen, usepath);
 }
        public override void DrawRegionRepresentation(Graphics gc, Render.RenderParameter r, Render.IDrawVisitor drawMethods, PointD mousePosition)
        {
            if (m_Param.Path.PointCount > 0)
            {
                GraphicsPath fill = new GraphicsPath();
                RectangleF rect = m_Param.Path.GetBounds();
                PointD refPt = (PointD)rect.Location + ((PointD)rect.Size.ToPointF()) / 2;
                // this will draw beyond the shape's location
                for (double i = -rect.Height; i < rect.Height; i++)
                {
                    PointD pt1 = refPt + PointD.Orthogonal(m_Param.V) * i * drawMethods.Spacing(m_Param.C);
                    PointD pt2 = pt1 + m_Param.V * rect.Width * rect.Height;
                    PointD pt3 = pt1 - m_Param.V * rect.Width * rect.Height;

                    fill.StartFigure();
                    fill.AddLine((Point)pt2, (Point)pt3);

                }

                GraphicsContainer c = gc.BeginContainer();
                gc.SetClip((Tools.Model.VectorPath)m_Param.Path);
                gc.DrawPath(r.RegionGuides, fill);
                gc.EndContainer(c);

            }
        }
Exemplo n.º 10
0
        internal override void Draw(Graphics g)
        {
            IsInvalidated = false;

            Rectangle r = GetUnsignedRectangle();

            //Shadow
            GraphicsPath gp = CreatePath(r.X + 5, r.Y + 5, r.Width, r.Height, Radius);
            //g.FillPath(new SolidBrush(Color.FromArgb((int)(255.0f * (50 / 100.0f)), Color.LightGray)), gp);

            g.FillPath(new SolidBrush(Color.LightGray), gp);

            gp.Dispose();

            //Border
            gp = CreatePath(r.X, r.Y, r.Width, r.Height, Radius);

            Pen p = new Pen(borderColor, borderWidth);
            g.DrawPath(p, gp);            
            p.Dispose();

            //Color
            Brush b = this.GetBrush(r);
            g.FillPath(b, gp);
            gp.Dispose();

            b.Dispose();
        }
Exemplo n.º 11
0
        public static void DrawPolygon(Graphics graphics, Polygon pol, Brush brush, Pen pen, IViewport viewport)
        {
            if (pol.ExteriorRing == null) return;
            if (pol.ExteriorRing.Vertices.Count <= 2) return;

            //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
            var gp = new GraphicsPath();

            //Add the exterior polygon
            var points = GeometryRenderer.WorldToScreenGDI(pol.ExteriorRing, viewport);
            if (points.Length > 2)
                gp.AddPolygon(points);
            //Add the interior polygons (holes)
            foreach (LinearRing linearRing in pol.InteriorRings)
            {
                var interiorPoints = GeometryRenderer.WorldToScreenGDI(linearRing, viewport);
                if (interiorPoints.Length > 2)
                    gp.AddPolygon(interiorPoints);
            }

            if (gp.PointCount == 0) return;

            // Only render inside of polygon if the brush isn't null or isn't transparent
            if (brush != null && brush != Brushes.Transparent)
                graphics.FillPath(brush, gp);
            // Create an outline if a pen style is available
            if (pen != null)
                graphics.DrawPath(pen, gp);
        }
Exemplo n.º 12
0
        //------ End Constructors -----//
        public override void Paint(Graphics g, System.Drawing.Drawing2D.GraphicsPath gp, bool isSelected)
        {
            if (isSelected)
            {
                SolidBrush br = new SolidBrush(selectedBack);
                Pen pen = new Pen(selectedLine);
                g.FillPath(br, gp);
                g.DrawPath(pen, gp);
                br.Dispose();
                pen.Dispose();
            }
            else  //is not selected
            {
                if (_PaintBack)
                {
                    SolidBrush br = new SolidBrush(_BackColor);
                    g.FillPath(br,gp);
                    br.Dispose();
                }

                if (_PaintLine)
                {
                    Pen pen = new Pen(_LineColor);
                    g.DrawPath(pen, gp);
                    pen.Dispose();
                }
            }
        }
Exemplo n.º 13
0
        public static void DrawRoundedRectangle(Graphics newGraphics, Color boxColor, Color gradFillColor1, Color gradFillColor2, int xPosition, int yPosition,
                   int height, int width, int cornerRadius)
        {
            using (var boxPen = new Pen(boxColor))
            {
                using (var path = new GraphicsPath())
                {
                    path.AddLine(xPosition + cornerRadius, yPosition, xPosition + width - (cornerRadius * 2), yPosition);
                    path.AddArc(xPosition + width - (cornerRadius * 2), yPosition, cornerRadius * 2, cornerRadius * 2, 270, 90);
                    path.AddLine(xPosition + width, yPosition + cornerRadius, xPosition + width,
                                 yPosition + height - (cornerRadius * 2));
                    path.AddArc(xPosition + width - (cornerRadius * 2), yPosition + height - (cornerRadius * 2), cornerRadius * 2,
                                cornerRadius * 2, 0, 90);
                    path.AddLine(xPosition + width - (cornerRadius * 2), yPosition + height, xPosition + cornerRadius,
                                 yPosition + height);
                    path.AddArc(xPosition, yPosition + height - (cornerRadius * 2), cornerRadius * 2, cornerRadius * 2, 90, 90);
                    path.AddLine(xPosition, yPosition + height - (cornerRadius * 2), xPosition, yPosition + cornerRadius);
                    path.AddArc(xPosition, yPosition, cornerRadius * 2, cornerRadius * 2, 180, 90);
                    path.CloseFigure();
                    newGraphics.DrawPath(boxPen, path);

                    var b = new LinearGradientBrush(new Point(xPosition, yPosition),
                                                    new Point(xPosition + width, yPosition + height), gradFillColor1,
                                                    gradFillColor2);

                    newGraphics.FillPath(b, path);
                }
            }
        }
Exemplo n.º 14
0
 public override void Draw(Graphics g, RectangleD worldRect, Rectangle canvasRect)
 {
     base.Draw(g, worldRect, canvasRect);
     var pen = new Pen(UpLineColor, LineWidth);
     var path = new GraphicsPath();
     pen.DashStyle = (DashStyle)Enum.Parse(typeof(DashStyle), LineStyle.ToString());
     using (pen)
     {
         using (path)
         {
             for (int i = 1; i < Data.Count; i++)
             {
                 GetPriceByField(i);
                 var tf =
                     (PointF)
                     Conversion.WorldToScreen(
                         new PointD(i - 1, GetPriceByField(i - 1)), worldRect,
                         canvasRect);
                 var tf2 =
                     (PointF)
                     Conversion.WorldToScreen(new PointD(i, GetPriceByField(i)), worldRect,
                                              canvasRect);
                 path.AddLine(tf, tf2);
             }
             g.DrawPath(pen, path);
         }
     }
 }
Exemplo n.º 15
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();
        }
Exemplo n.º 16
0
        public override void DrawTab(Graphics gr, Rectangle borderrect, int index, bool selected, Color color1, Color color2, Color coloroutline, TabAlignment alignment)
        {
            GraphicsPath border = new GraphicsPath();
            GraphicsPath fill = new GraphicsPath();

            int xfar = borderrect.Right - 1;

            int ybot = (alignment == TabAlignment.Bottom) ? (borderrect.Y) : (borderrect.Bottom - 1);
            int ytop = (alignment == TabAlignment.Bottom) ? (borderrect.Bottom-1-((selected)?0:2)) : (borderrect.Y - ((selected) ? 2 : 0));

            border.AddLine(borderrect.X, ybot, borderrect.X + shift, ytop);
            border.AddLine(borderrect.X + shift, ytop, xfar, ytop);
            border.AddLine(xfar, ytop, xfar + shift, ybot);

            fill.AddLine(borderrect.X, ybot + 1, borderrect.X + shift, ytop);
            fill.AddLine(borderrect.X + shift, ytop, xfar, ytop);
            fill.AddLine(xfar, ytop, xfar + shift, ybot + 1);

            gr.SmoothingMode = SmoothingMode.Default;

            using (Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(borderrect, color1, color2, 90))
                gr.FillPath(b, fill);

            gr.SmoothingMode = SmoothingMode.AntiAlias;

            using (Pen p = new Pen(coloroutline, 1.0F))
                gr.DrawPath(p, border);
        }
Exemplo n.º 17
0
 void paintshit(List<double> datta, int numPoints, double mulX, double mulY, int bw, int bh, Graphics g, LinearGradientBrush grad, Color cbase)
 {
     PointF[] points = new PointF[numPoints];
     lock (datta)
     {
         int s = 0;
         int samples = datta.Count;
         for (; s < (points.Length - 2) - samples; s++)
         {
             points[s + 1] = new PointF((float)(s * mulX), bh);
         }
         int ofs = (points.Length - 2) - samples;
         s = Math.Max(0, samples - (points.Length - 2));
         for (; s < samples; s++)
         {
             points[s + ofs + 1] = new PointF((float)((s + ofs) * mulX),
                 (float)(bh - datta[s] * mulY));
         }
         points[0] = new PointF(0f, bh);
         points[points.Length - 1] = new PointF(bw, bh);
     }
     GraphicsPath gp = new GraphicsPath();
     gp.AddLines(points);
     g.FillPath(grad, gp);
     g.DrawPath(new Pen(cbase, 2f), gp);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Draw Function.</summary>
        /// <param name="g">Graphics for Drawing</param>
        public void Draw(Graphics g, float rollAngle, float pitchAngle)
        {
            Matrix transformMatrix = new Matrix();
            transformMatrix.RotateAt(rollAngle, center);
            transformMatrix.Translate(0, pitchAngle * pixelPerDegree);

            // Previous major graduation value next to currentValue.
            int majorGraduationValue = ((int)(pitchAngle / 10) * 10);

            for (int degree = majorGraduationValue - 20; degree <= majorGraduationValue + 20; degree += 5)
            {
                if (degree == 0)
                    continue;

                int width = degree % 10 == 0 ? 60 : 30;

                GraphicsPath skyPath = new GraphicsPath();

                skyPath.AddLine(center.X - width, center.Y - degree * pixelPerDegree, center.X + width, center.Y - degree * pixelPerDegree);
                skyPath.Transform(transformMatrix);
                g.DrawPath(drawingPen, skyPath);

                //g.DrawString(degree.ToString(), SystemFonts.DefaultFont, Brushes.White, center.X - width - 15, center.Y - degree * 10);
            }
        }
Exemplo n.º 19
0
        public override void Draw(Graphics g)
        {
            System.Drawing.Size st = g.MeasureString(Marker.ToolTipText, Font).ToSize();
             System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height, st.Width + TextPadding.Width, st.Height + TextPadding.Height);
             rect.Offset(Offset.X, Offset.Y);

             using(GraphicsPath objGP = new GraphicsPath())
             {
            objGP.AddLine(rect.X + 2 * Radius, rect.Y + rect.Height, rect.X + Radius, rect.Y + rect.Height + Radius);
            objGP.AddLine(rect.X + Radius, rect.Y + rect.Height + Radius, rect.X + Radius, rect.Y + rect.Height);

            objGP.AddArc(rect.X, rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 90, 90);
            objGP.AddLine(rect.X, rect.Y + rect.Height - (Radius * 2), rect.X, rect.Y + Radius);
            objGP.AddArc(rect.X, rect.Y, Radius * 2, Radius * 2, 180, 90);
            objGP.AddLine(rect.X + Radius, rect.Y, rect.X + rect.Width - (Radius * 2), rect.Y);
            objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y, Radius * 2, Radius * 2, 270, 90);
            objGP.AddLine(rect.X + rect.Width, rect.Y + Radius, rect.X + rect.Width, rect.Y + rect.Height - (Radius * 2));
            objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 0, 90); // Corner

            objGP.CloseFigure();

            g.FillPath(Fill, objGP);
            g.DrawPath(Stroke, objGP);
             }

            #if !PocketPC
             g.DrawString(Marker.ToolTipText, Font, Brushes.Navy, rect, Format);
            #else
             g.DrawString(ToolTipText, ToolTipFont, TooltipForeground, rect, ToolTipFormat);
            #endif
        }
Exemplo n.º 20
0
        public static void RenderBorder(Graphics g, Rectangle rect, Color borderColor,
            ButtonBorderType borderType, int radius, RoundStyle roundType)
        {
            rect.Width--;
            rect.Height--;

            bool simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2));
            SmoothingMode newMode = simpleRect ? SmoothingMode.HighSpeed : SmoothingMode.AntiAlias;

            using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode))
            {
                using (Pen p = new Pen(borderColor))
                {
                    if (simpleRect)
                    {
                        g.DrawRectangle(p, rect);
                    }
                    else if (borderType == ButtonBorderType.Ellipse)
                    {
                        g.DrawEllipse(p, rect);
                    }
                    else
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false))
                        {
                            g.DrawPath(p, path);
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
			/// <summary>Draws the grip in the graphics context.</summary>
			/// <param name="g">Graphics context.</param>
			/// <param name="pageScale">Current zoom factor that can be used to calculate pen width etc. for displaying the handle. Attention: this factor must not be used to transform the path of the handle.</param>
			public void Show(Graphics g, double pageScale)
			{
				using (var pen = new Pen(Color.Blue, (float)(1 / pageScale)))
				{
					g.DrawPath(pen, _displayPath);
				}
			}
Exemplo n.º 22
0
 private void paint(Graphics g, GraphicsPath path, bool edge, Color edgeColour, int edgeWidth, bool fill, Color fillColour)
 {
     if (edge)
         g.DrawPath(new Pen(edgeColour, edgeWidth), path);
     if (fill)
         g.FillPath(new SolidBrush(fillColour), path);
 }
Exemplo n.º 23
0
        public void DrawRoundRect(Graphics g, Pen p, float X, float Y, float width, float height, float radius)
        {
            try
            {
                p.Width = 6;
                Rectangle r = this.ClientRectangle;
                // r.Width--; r.Height--;
                using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
                {
                    using (System.Drawing.Drawing2D.LinearGradientBrush gradBrush = new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 90, false))
                    {

                        ColorBlend cb = new ColorBlend();
                        cb.Positions = new[] { 0, 1f };
                        cb.Colors = new[] { Color.Transparent, Color.Transparent };
                        gradBrush.InterpolationColors = cb;
                        // rotate
                        gradBrush.RotateTransform(0);
                        // paint
                        //g.FillPath(gradBrush, rr);
                        g.DrawPath(p, rr);
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 24
0
		public override void Draw(Graphics graphics)
		{
			if (graphics == null) {
				throw new ArgumentNullException("graphics");
			}
			
			Rectangle rect = new Rectangle(this.ClientRectangle.Left,this.ClientRectangle.Top,
			                               this.ClientRectangle.Right -1,
			                               this.ClientRectangle.Bottom -1);
//			backgroundShape.FillShape(graphics,
//			                new SolidFillPattern(this.BackColor),
//			                rect);
			
			Border b = new Border(new BaseLine (this.ForeColor,System.Drawing.Drawing2D.DashStyle.Solid,1));
//			DrawFrame(graphics,b);
			BaseLine line = new BaseLine(base.ForeColor,DashStyle,Thickness,LineCap.Round,LineCap.Round,DashCap.Round);
			using (Pen pen = line.CreatePen(line.Thickness)){
				shape.CornerRadius = this.CornerRadius;
				GraphicsPath path1 = shape.CreatePath(rect);
				graphics.DrawPath(pen, path1);
				
			}
			
//			shape.DrawShape (graphics,
//			                 this.Baseline(),
//			                 rect);
			
		}
Exemplo n.º 25
0
 public override void Draw(Graphics g)
 {
     if (m_blVisible == false)
         return;
     SetPath();
     g.DrawPath(new Pen(m_clrPenColor, m_ftPenwidth), m_grpShapePath);          //Draw the path between two points
 }
Exemplo n.º 26
0
 public void Draw(Pen pen, Graphics g)
 {
     gp.Widen(pen); //To coś daje
     gp.Flatten(); //To też :)
     g.DrawPath(pen, gp);
     gp.Reset();
 }
Exemplo n.º 27
0
 protected override void DrawDisabled(Graphics g, ArrowDirection direction)
 {
     g.DrawEllipse(_disabledPen, _circleRect);
     if (direction == ArrowDirection.Right)
         g.MultiplyTransform(new Matrix(-1, 0, 0, 1, 23, 0));
     g.DrawPath(_disabledArrowPen, _arrowPath);
 }
 private void DrawButton(Graphics graphics, ScrollButton scrollButton)
 {
     Rectangle buttonBounds = base.GetButtonBounds(scrollButton);
     if (base.Orientation == Orientation.Horizontal)
     {
         buttonBounds.Inflate(-base.itemStrip.ItemSize.Width / 6, -base.itemStrip.ItemSize.Height / 4);
     }
     else
     {
         buttonBounds.Inflate(-base.itemStrip.ItemSize.Width / 4, -base.itemStrip.ItemSize.Height / 6);
     }
     if (base.ActiveButton == scrollButton)
     {
         buttonBounds.Offset(1, 1);
         Size size = (base.Orientation == Orientation.Horizontal) ? new Size(0, 2) : new Size(2, 0);
         buttonBounds.Inflate(size.Width, size.Height);
         graphics.FillRectangle(SelectionBrush, buttonBounds);
         graphics.DrawRectangle(Pens.Black, buttonBounds);
         buttonBounds.Inflate(-size.Width, -size.Height);
     }
     using (GraphicsPath path = ActivityDesignerPaint.GetScrollIndicatorPath(buttonBounds, scrollButton))
     {
         graphics.FillPath(Brushes.Black, path);
         graphics.DrawPath(Pens.Black, path);
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Draw an outlined text on a graphic.
        /// Draw a text using an outline in it, from custom CardGraphicComponent values. These are used to get position of text and destination picture/graphic.
        /// </summary>
        /// <param name="g">Graphic to draw the text</param>
        /// <param name="text">Text to draw</param>
        /// <param name="canvas">Values for position, font, etc. of the text</param>
        /// <param name="parent">If canvas has a parent, use it for relative position of the text</param>
        /// <param name="centered">If text must be drawn centered or not</param>
        public static void drawOutlineText(Graphics g, string text, CardGraphicComponent canvas, CardGraphicComponent parent, bool centered=false)
        {
            // Check parent to get proper offsets
            var offsetTop  = 0;
            var offsetLeft = 0;
            if (parent != null)
            {
                offsetLeft = parent.Left;
                offsetTop  = parent.Top;
            }
            // set atialiasing for drawing
            g.SmoothingMode     = SmoothingMode.HighQuality; // AntiAlias
            g.InterpolationMode = InterpolationMode.HighQualityBicubic; // High
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            // Create GraphicsPath to draw text
            using (GraphicsPath path = new GraphicsPath())
            {
                // Calculate position in case text must be draw centered or not
                float txtWidth = 0;
                if (centered)
                    txtWidth = getStringWidth(g, text, new Font(canvas.font.FontFamily, canvas.font.Size, canvas.font.Style, GraphicsUnit.Point, ((byte)(0)))) / 2;
                // Add string to path
                path.AddString(text, canvas.font.FontFamily, (int)canvas.font.Style, canvas.font.Size, new Point(canvas.Left + offsetLeft - (int)txtWidth, canvas.Top + offsetTop), StringFormat.GenericTypographic);
                // Draw text using this pen. This does the trick (with the path) to draw the outline
                using (Pen pen = new Pen(canvas.borderColor, canvas.Outline))
                {
                    pen.LineJoin = LineJoin.Round;

                    g.DrawPath(pen, path);
                    g.FillPath(canvas.textColor, path);
                }
            }
        }
Exemplo n.º 30
0
        public override void DrawTab(Graphics gr, Rectangle borderrect, int index, bool selected, Color color1, Color color2, Color coloroutline)
        {
            int additional = 0;                             // extra depth for fill

            if (selected)
            {
                additional = 1;
                borderrect.Height += borderrect.Y;          // this one uses any height to get it bigger
                borderrect.Y = 0;
            }

            int xfar = borderrect.Right - 1;
            int yfar = borderrect.Bottom - 1;

            GraphicsPath border = new GraphicsPath();
            border.AddLine(borderrect.X, yfar + additional, borderrect.X + shift, borderrect.Y);
            border.AddLine(borderrect.X + shift, borderrect.Y, xfar, borderrect.Y);
            border.AddLine(xfar, borderrect.Y, xfar + shift, yfar + additional);

            GraphicsPath fill = new GraphicsPath();
            fill.AddLine(borderrect.X, yfar + additional + 1, borderrect.X + shift, borderrect.Y);
            fill.AddLine(borderrect.X + shift, borderrect.Y, xfar, borderrect.Y);
            fill.AddLine(xfar, borderrect.Y, xfar + shift, yfar + additional + 1);

            gr.SmoothingMode = SmoothingMode.Default;

            using (Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(borderrect, color1, color2, 90))
                gr.FillPath(b, fill);

            gr.SmoothingMode = SmoothingMode.AntiAlias;

            using (Pen p = new Pen(coloroutline, 1.0F))
                gr.DrawPath(p, border);
        }
Exemplo n.º 31
0
    public virtual void  drawPolygon(System.Drawing.Point[] points, int color)
    {
        System.Drawing.Graphics g2d = System.Drawing.Graphics.FromImage(image);
        //UPGRADE_TODO: Constructor 'java.awt.Color.Color' was converted to 'System.Drawing.Color.FromArgb' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtColorColor_int'"
        SupportClass.GraphicsManager.manager.SetColor(g2d, System.Drawing.Color.FromArgb(color));
        int numPoints = points.Length;

        int[] polygonX = new int[numPoints];
        int[] polygonY = new int[numPoints];
        for (int i = 0; i < numPoints; i++)
        {
            //UPGRADE_TODO: Method 'java.awt.Point.getX' was converted to 'System.Drawing.Point.X' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtPointgetX'"
            polygonX[i] = (int)(points[i].X);
            //UPGRADE_TODO: Method 'java.awt.Point.getY' was converted to 'System.Drawing.Point.Y' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtPointgetY'"
            polygonY[i] = (int)(points[i].Y);
        }
        g2d.DrawPath(SupportClass.GraphicsManager.manager.GetPen(g2d), SupportClass.CreateGraphicsPath(polygonX, polygonY, numPoints));
        //UPGRADE_TODO: Method 'java.awt.Component.repaint' was converted to 'System.Windows.Forms.Control.Refresh' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtComponentrepaint'"
        Refresh();
    }
Exemplo n.º 32
0
        protected void PaintXErrorBars(System.Drawing.Graphics g, IPlotArea layer, Altaxo.Graph.Gdi.Plot.Data.Processed2DPlotData pdata)
        {
            // Plot error bars for the independent variable (x)
            PlotRangeList rangeList = pdata.RangeList;

            PointF[]       ptArray   = pdata.PlotPointsInAbsoluteLayerCoordinates;
            INumericColumn posErrCol = _positiveErrorColumn.Document;
            INumericColumn negErrCol = _negativeErrorColumn.Document;

            if (posErrCol == null && negErrCol == null)
            {
                return; // nothing to do if both error columns are null
            }
            System.Drawing.Drawing2D.GraphicsPath errorBarPath = new System.Drawing.Drawing2D.GraphicsPath();

            Region oldClippingRegion = g.Clip;
            Region newClip           = (Region)oldClippingRegion.Clone();

            foreach (PlotRange r in rangeList)
            {
                int lower  = r.LowerBound;
                int upper  = r.UpperBound;
                int offset = r.OffsetToOriginal;
                for (int j = lower; j < upper; j++)
                {
                    AltaxoVariant x  = pdata.GetXPhysical(j + offset);
                    Logical3D     lm = layer.GetLogical3D(pdata, j + offset);
                    lm.RX += _cachedLogicalShiftOfIndependent;
                    if (lm.IsNaN)
                    {
                        continue;
                    }

                    Logical3D lh      = lm;
                    Logical3D ll      = lm;
                    bool      lhvalid = false;
                    bool      llvalid = false;
                    if (posErrCol != null)
                    {
                        lh.RX   = layer.XAxis.PhysicalVariantToNormal(x + Math.Abs(posErrCol[j + offset]));
                        lhvalid = !lh.IsNaN;
                    }
                    if (negErrCol != null)
                    {
                        ll.RX   = layer.XAxis.PhysicalVariantToNormal(x - Math.Abs(negErrCol[j + offset]));
                        llvalid = !ll.IsNaN;
                    }
                    if (!(lhvalid || llvalid))
                    {
                        continue; // nothing to do for this point if both pos and neg logical point are invalid.
                    }
                    // now paint the error bar
                    if (_symbolGap) // if symbol gap, then clip the painting, exclude a rectangle of size symbolSize x symbolSize
                    {
                        double xlm, ylm;
                        layer.CoordinateSystem.LogicalToLayerCoordinates(lm, out xlm, out ylm);
                        newClip.Union(oldClippingRegion);
                        newClip.Exclude(new RectangleF((float)(xlm - _symbolSize / 2), (float)(ylm - _symbolSize / 2), _symbolSize, _symbolSize));
                        g.Clip = newClip;
                    }

                    if (lhvalid && llvalid)
                    {
                        errorBarPath.Reset();
                        layer.CoordinateSystem.GetIsoline(errorBarPath, ll, lm);
                        layer.CoordinateSystem.GetIsoline(errorBarPath, lm, lh);
                        g.DrawPath(_strokePen, errorBarPath);
                    }
                    else if (llvalid)
                    {
                        layer.CoordinateSystem.DrawIsoline(g, _strokePen, ll, lm);
                    }
                    else if (lhvalid)
                    {
                        layer.CoordinateSystem.DrawIsoline(g, _strokePen, lm, lh);
                    }


                    // now the end bars
                    if (_showEndBars)
                    {
                        if (lhvalid)
                        {
                            PointF outDir;
                            layer.CoordinateSystem.GetNormalizedDirection(lm, lh, 1, new Logical3D(0, 1), out outDir);
                            outDir.X *= _symbolSize / 2;
                            outDir.Y *= _symbolSize / 2;
                            double xlay, ylay;
                            layer.CoordinateSystem.LogicalToLayerCoordinates(lh, out xlay, out ylay);
                            // Draw a line from x,y to
                            g.DrawLine(_strokePen, (float)(xlay - outDir.X), (float)(ylay - outDir.Y), (float)(xlay + outDir.X), (float)(ylay + outDir.Y));
                        }

                        if (llvalid)
                        {
                            PointF outDir;
                            layer.CoordinateSystem.GetNormalizedDirection(lm, ll, 1, new Logical3D(0, 1), out outDir);
                            outDir.X *= _symbolSize / 2;
                            outDir.Y *= _symbolSize / 2;
                            double xlay, ylay;
                            layer.CoordinateSystem.LogicalToLayerCoordinates(ll, out xlay, out ylay);
                            // Draw a line from x,y to
                            g.DrawLine(_strokePen, (float)(xlay - outDir.X), (float)(ylay - outDir.Y), (float)(xlay + outDir.X), (float)(ylay + outDir.Y));
                        }
                    }
                }
            }

            g.Clip = oldClippingRegion;
        }
Exemplo n.º 33
0
        public static void DrawBackground(
            System.Drawing.Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color innerBorderColor,
            RoundStyle style,
            int roundWidth,
            float basePosition,
            bool ifDrawBorder,
            bool ifDrawGlass,
            LinearGradientMode mode)
        {
            if (ifDrawBorder)
            {
                rect.Width--;
                rect.Height--;
            }

            using (LinearGradientBrush brush = new LinearGradientBrush(
                       rect, Color.Transparent, Color.Transparent, mode))
            {
                Color[] colors = new Color[4];
                colors[0] = GetColor(baseColor, 0, 35, 24, 9);
                colors[1] = GetColor(baseColor, 0, 13, 8, 3);
                colors[2] = baseColor;
                colors[3] = GetColor(baseColor, 0, 35, 24, 9);

                ColorBlend blend = new ColorBlend();
                blend.Positions           = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
                blend.Colors              = colors;
                brush.InterpolationColors = blend;
                if (style != RoundStyle.None)
                {
                    using (GraphicsPath path =
                               GraphicsHelper.CreatePath(rect, roundWidth, style, false))
                    {
                        g.FillPath(brush, path);
                    }

                    if (baseColor.A > 80)
                    {
                        Rectangle rectTop = rect;

                        if (mode == LinearGradientMode.Vertical)
                        {
                            rectTop.Height = (int)(rectTop.Height * basePosition);
                        }
                        else
                        {
                            rectTop.Width = (int)(rect.Width * basePosition);
                        }
                        using (GraphicsPath pathTop = GraphicsHelper.CreatePath(
                                   rectTop, roundWidth, RoundStyle.Top, false))
                        {
                            using (SolidBrush brushAlpha =
                                       new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                            {
                                g.FillPath(brushAlpha, pathTop);
                            }
                        }
                    }

                    if (ifDrawGlass)
                    {
                        RectangleF glassRect = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = rect.Y + rect.Height * basePosition;
                            glassRect.Height = (rect.Height - rect.Height * basePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = rect.X + rect.Width * basePosition;
                            glassRect.Width = (rect.Width - rect.Width * basePosition) * 2;
                        }
                        GraphicsHelper.DrawGlass(g, glassRect, 170, 0);
                    }

                    if (ifDrawBorder)
                    {
                        using (GraphicsPath path =
                                   GraphicsHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            using (Pen pen = new Pen(borderColor))
                            {
                                g.DrawPath(pen, path);
                            }
                        }

                        rect.Inflate(-1, -1);
                        using (GraphicsPath path =
                                   GraphicsHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            using (Pen pen = new Pen(innerBorderColor))
                            {
                                g.DrawPath(pen, path);
                            }
                        }
                    }
                }
                else
                {
                    g.FillRectangle(brush, rect);
                    if (baseColor.A > 80)
                    {
                        Rectangle rectTop = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            rectTop.Height = (int)(rectTop.Height * basePosition);
                        }
                        else
                        {
                            rectTop.Width = (int)(rect.Width * basePosition);
                        }
                        using (SolidBrush brushAlpha =
                                   new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                        {
                            g.FillRectangle(brushAlpha, rectTop);
                        }
                    }

                    if (ifDrawGlass)
                    {
                        RectangleF glassRect = rect;
                        if (mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = rect.Y + rect.Height * basePosition;
                            glassRect.Height = (rect.Height - rect.Height * basePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = rect.X + rect.Width * basePosition;
                            glassRect.Width = (rect.Width - rect.Width * basePosition) * 2;
                        }
                        GraphicsHelper.DrawGlass(g, glassRect, 200, 0);
                    }

                    if (ifDrawBorder)
                    {
                        using (Pen pen = new Pen(borderColor))
                        {
                            g.DrawRectangle(pen, rect);
                        }

                        rect.Inflate(-1, -1);
                        using (Pen pen = new Pen(innerBorderColor))
                        {
                            g.DrawRectangle(pen, rect);
                        }
                    }
                }
            }
        }
Exemplo n.º 34
0
        void DrawTab(System.Drawing.Graphics g, TabVS2005 tab)
        {
            var rectTabOrigin = GetTabRectangle(tab);

            if (rectTabOrigin.IsEmpty)
            {
                return;
            }

            var dockState = tab.Content.DockHandler.DockState;
            var content   = tab.Content;

            var path = GetTabOutline(tab, false, true);

            var startColor   = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor;
            var endColor     = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor;
            var gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode;

            g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path);
            g.DrawPath(PenTabBorder, path);

            // Set no rotate for drawing icon and text
            var matrixRotate = g.Transform;

            g.Transform = MatrixIdentity;

            // Draw the icon
            var rectImage = rectTabOrigin;

            rectImage.X += ImageGapLeft;
            rectImage.Y += ImageGapTop;
            var imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom;
            var imageWidth  = ImageWidth;

            if (imageHeight > ImageHeight)
            {
                imageWidth = ImageWidth * (imageHeight / ImageHeight);
            }
            rectImage.Height = imageHeight;
            rectImage.Width  = imageWidth;
            rectImage        = GetTransformedRectangle(dockState, rectImage);
            g.DrawIcon(((Form)content).Icon, RtlTransform(rectImage, dockState));

            // Draw the text
            var rectText = rectTabOrigin;

            rectText.X     += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
            rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
            rectText        = RtlTransform(GetTransformedRectangle(dockState, rectText), dockState);

            var textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor;

            if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
            {
                g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabVertical);
            }
            else
            {
                g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabHorizontal);
            }

            // Set rotate back
            g.Transform = matrixRotate;
        }
Exemplo n.º 35
0
        /// <summary>
        /// Paints the shape on the canvas
        /// </summary>
        /// <param name="g"></param>
        ///

        public override void Paint(System.Drawing.Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle toggleNode = Rectangle.Empty;             //the [+] [-]

            Point[] pts = new Point[12]
            {
                new Point(rectangle.X, rectangle.Y),                        //0
                new Point(rectangle.X + bshift, rectangle.Y),               //1
                new Point(rectangle.Right - bshift, rectangle.Y),           //2
                new Point(rectangle.Right, rectangle.Y),                    //3
                new Point(rectangle.Right, rectangle.Y + bshift),           //4
                new Point(rectangle.Right, rectangle.Bottom - bshift),      //5
                new Point(rectangle.Right, rectangle.Bottom),               //6
                new Point(rectangle.Right - bshift, rectangle.Bottom),      //7
                new Point(rectangle.X + bshift, rectangle.Bottom),          //8
                new Point(rectangle.X, rectangle.Bottom),                   //9
                new Point(rectangle.X, rectangle.Bottom - bshift),          //10
                new Point(rectangle.X, rectangle.Y + bshift),               //11
            };
            path = new GraphicsPath();
            path.AddBezier(pts[11], pts[0], pts[0], pts[1]);
            path.AddLine(pts[1], pts[2]);
            path.AddBezier(pts[2], pts[3], pts[3], pts[4]);
            path.AddLine(pts[4], pts[5]);
            path.AddBezier(pts[5], pts[6], pts[6], pts[7]);
            path.AddLine(pts[7], pts[8]);
            path.AddBezier(pts[8], pts[9], pts[9], pts[10]);
            path.AddLine(pts[10], pts[11]);
            path.CloseFigure();
            region = new Region(path);

            shapeBrush = new LinearGradientBrush(rectangle, this.shapeColor, Color.WhiteSmoke, 0f);

            // start Draw Shadow
            shadow = region.Clone();
            shadow.Translate(5, 5);


            //add the amount of children
            if (childNodes.Count > 0)
            {
                plus = " [" + childNodes.Count + "]";
            }
            else
            {
                plus = "";
            }

            g.FillRegion(new SolidBrush(Color.Gainsboro), shadow);
            //g.DrawPath(new Pen(Color.Gainsboro,1), shadow);
            //End Draw Shadow

            g.FillRegion(shapeBrush, region);



            if (hovered || isSelected)
            {
                pen = thickPen;
            }
            else
            {
                pen = blackPen;
            }

            g.DrawPath(pen, path);

            if (text != string.Empty)
            {
                g.DrawString(text + plus, font, Brushes.Black, rectangle.X + 5, rectangle.Y + 5);
            }



            //draw the [+] expansion shape
            if (childNodes.Count > 0)
            {
                switch (site.LayoutDirection)
                {
                case TreeDirection.Vertical:
                    toggleNode = new Rectangle(Left + this.Width / 2 - 5, Bottom, 10, 10);
                    break;

                case TreeDirection.Horizontal:
                    toggleNode = new Rectangle(Right, Top + Height / 2 - 5, 10, 10);
                    break;
                }


                //Draw [ ]
                g.FillRectangle(new SolidBrush(Color.White), toggleNode);
                g.DrawRectangle(blackPen, toggleNode);

                //Draw -
                g.DrawLine(blackPen, (toggleNode.X + 2), (toggleNode.Y + (toggleNode.Height / 2)), (toggleNode.X + (toggleNode.Width - 2)), (toggleNode.Y + (toggleNode.Height / 2)));

                if (!this.Expanded)
                {
                    //Draw |
                    g.DrawLine(blackPen, (toggleNode.X + (toggleNode.Width / 2)), (toggleNode.Y + 2), (toggleNode.X + (toggleNode.Width / 2)), (toggleNode.Y + (toggleNode.Height - 2)));
                }
            }
        }
Exemplo n.º 36
0
        void VistaStyleTreeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            System.Drawing.Graphics g = e.Graphics;
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

            TreeView tv = (TreeView)sender;

            if (e.Node.IsVisible == false)
            {
                return;
            }

            int indent        = tv.Indent;
            int depth         = e.Node.Level + 1;
            int selectedDepth = 1;

            if (e.Node.TreeView.SelectedNode != null)
            {
                selectedDepth = e.Node.TreeView.SelectedNode.Level + 1;
            }

            int nodeIndent = indent * depth;

            Font font = tv.Font;

            if (e.Node.NodeFont != null)
            {
                font = e.Node.NodeFont;
            }

            Brush fgBrush = Brushes.Black;
            Brush bgBrush = Brushes.White;

            //if (e.State == TreeNodeStates.Selected)
            //{
            //    fgBrush = SystemBrushes.HighlightText;
            //}

            g.FillRectangle(bgBrush, e.Bounds);
            int imageWidth = 0;

            if (tv.ImageList != null)
            {
                imageWidth = tv.ImageList.ImageSize.Width;
            }

            if (e.Node.IsSelected || e.State == TreeNodeStates.Marked)
            {
                SizeF      size = g.MeasureString(e.Node.Text, font);
                RectangleF rect = new RectangleF(e.Bounds.X, e.Bounds.Y + 1, e.Bounds.Width - 1, e.Bounds.Height - 2); //new RectangleF(e.Bounds.Left + nodeIndent + imageWidth, e.Bounds.Top, size.Width, size.Height);
                using (System.Drawing.Drawing2D.GraphicsPath path = this.GetRoundedRect(rect, 3f))
                    using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
                               rect, Color.FromArgb(234, 243, 252), Color.FromArgb(206, 228, 254), 90f))
                        using (Pen pen = new Pen(Color.FromArgb(148, 183, 226)))
                        {
                            g.FillPath(brush, path);
                            g.DrawPath(pen, path);
                        }
            }
            else if (e.State == TreeNodeStates.Hot ||
                     e.State == TreeNodeStates.Selected)
            {
                SizeF      size = g.MeasureString(e.Node.Text, font);
                RectangleF rect = new RectangleF(e.Bounds.X, e.Bounds.Y + 1, e.Bounds.Width - 1, e.Bounds.Height - 2); //new RectangleF(e.Bounds.Left + nodeIndent + imageWidth, e.Bounds.Top, size.Width, size.Height);
                using (System.Drawing.Drawing2D.GraphicsPath path = this.GetRoundedRect(rect, 3f))
                    using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
                               rect, Color.FromArgb(254, 254, 254), Color.FromArgb(235, 243, 253), 90f))
                        using (Pen pen = new Pen(Color.FromArgb(201, 224, 252)))
                        {
                            g.FillPath(brush, path);
                            g.DrawPath(pen, path);
                        }
            }

            g.DrawString(e.Node.Text, font, fgBrush, e.Bounds.Left + nodeIndent + imageWidth, e.Bounds.Top + 1);

            int expanderSize = 9;

            Rectangle expanderBounds = new Rectangle(e.Bounds.Left + nodeIndent - indent / 2 - expanderSize / 2, e.Bounds.Top + tv.ItemHeight / 2 - expanderSize / 2, expanderSize, expanderSize);

            if (e.Node.Nodes.Count > 0)
            {
                if (e.Node.IsExpanded)
                {
                    g.DrawImage(gView.Win.Sys.UI.Properties.Resources.tree_minus, expanderBounds, new Rectangle(0, 0, 9, 9), GraphicsUnit.Pixel);
                }
                else
                {
                    g.DrawImage(gView.Win.Sys.UI.Properties.Resources.tree_plus, expanderBounds, new Rectangle(0, 0, 9, 9), GraphicsUnit.Pixel);
                }
            }

            if (this.UIImageList != null)
            {
                Image img        = null;
                int   imageIndex = tv.ImageIndex;
                if (e.Node.ImageIndex != -1)
                {
                    imageIndex = e.Node.ImageIndex;
                }

                img = this.UIImageList[imageIndex];
                g.DrawImageUnscaled(img, e.Bounds.Left + nodeIndent, e.Bounds.Top + e.Bounds.Height / 2 - img.Height / 2);
            }
        }
Exemplo n.º 37
0
        public System.Drawing.Image getImageFromShape(Shape shape, float ZoomFactor)
        {
            System.Drawing.Image img = null;



            double ll = Math.Truncate(ZoomFactor * 100000);
            float  tt = (float)(100000 / ll);

            bool   selected      = shape.Selected;
            bool   locked        = shape.Locked;
            PointF ShapeLocation = shape.Location;

            shape.Selected = true;
            shape.Locked   = false;

            shape.Location = new PointF(0, 0);


            try
            {
                shape.Transformer.Scale(tt, tt);
            }
            catch
            {
            }



            Pen pen = new Pen(shape.Appearance.ActivePen.Color, shape.Appearance.BorderWidth * tt);

            pen.MiterLimit = 1;
            pen.EndCap     = System.Drawing.Drawing2D.LineCap.Round;
            pen.StartCap   = System.Drawing.Drawing2D.LineCap.Round;

            Bitmap bmp = new Bitmap((int)(shape.Dimension.Width + 1), (int)(shape.Dimension.Height + 1));

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

            g.Clear(Color.White);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            g.DrawPath(pen, shape.Geometric);
            long i = 0;


            if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.Text)
            {
                //Sbn.AdvancedControls.Imaging.SbnPaint.Text ttext = new Text();
                //ttext = (Sbn.AdvancedControls.Imaging.SbnPaint.Text)shape;
                //Brush bb = new System.Drawing.SolidBrush(ttext.Appearance.MarkerColor);


                //StringFormat m_Formatdd = new StringFormat();
                //m_Formatdd.Alignment = StringAlignment.Near;
                //m_Formatdd.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.DirectionRightToLeft;
                //m_Formatdd.LineAlignment = StringAlignment.Near;

                //Rectangle WFTitle = new Rectangle(0, 0, bmp.Width, bmp.Height);

                //// using (Font fntDayDate = new Font("Tahoma", 10, FontStyle.Regular))
                //g.DrawString(ttext.DisplayedText, ttext.Font, SystemBrushes.WindowText, WFTitle, m_Formatdd);



                // g.DrawString(ttext.DisplayedText, ttext.Font, bb, new PointF(0, 0) , sf);
            }

            if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.RectangleBody)
            {
                //Pen pen = new Pen(shape.Appearance.ActivePen.Color, shape.Appearance.BorderWidth * tt);

                //pen.MiterLimit = 1;
                //pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
                //pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;

                g.DrawRectangle(pen, 0, 0, shape.Dimension.Width, shape.Dimension.Height);
            }


            //if (shape is pActiveAnnotation)
            //{

            //    g.DrawImage(((pActiveAnnotation)shape).Bitmap, 0, 0, shape.Dimension.Width, shape.Dimension.Height);
            //}

            g.Dispose();

            bmp.MakeTransparent(Color.White);

            Bitmap bmpp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format4bppIndexed);

            bmp.Palette = bmpp.Palette;
            // bmp.Save("c:\\www2.png");
            pen.Dispose();
            shape.Location = ShapeLocation;
            shape.Selected = selected;
            shape.Locked   = locked;

            // Image img2 = (System.Drawing.Image)bmp;
            bmp.MakeTransparent(Color.White);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            return((System.Drawing.Image)bmp);
        }
Exemplo n.º 38
0
        private void DrawBackground(System.Drawing.Graphics g)
        {
            //Graphics g = bg.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            int ArcWidth  = this.C_RoundCorners * 2;
            int ArcHeight = this.C_RoundCorners * 2;
            int ArcX1     = 0;
            int ArcX2     = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1);
            int ArcY1     = 0;
            int ArcY2     = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush           = new SolidBrush(_colorFrame);        //this.BorderColor
            System.Drawing.Pen   BorderPen             = new Pen(BorderBrush, _frameBorder); //this.BorderThickness
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush                  BackgroundBrush = new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush             ShadowBrush     = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath      = null;

            //画出阴影效果
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath  = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle); //顶端的左角
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle); //顶端右角
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle); //底部右角
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle);  //底部左角
                ShadowPath.CloseAllFigures();

                g.FillPath(ShadowBrush, ShadowPath);
            }

            //画出图形
            path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle);
            path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle);
            path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle);
            path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle);
            path.CloseAllFigures();

            if (this.C_BackgroundGradientMode == DutBoxGradientMode.None)
            {
                g.FillPath(BackgroundBrush, path);
            }
            else
            {
                BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                g.FillPath(BackgroundGradientBrush, path);
            }
            //画对号
            if (IsActivedDut && ManualChecked)
            {
                //g.DrawLine(BorderPen, 10, 10, 20, 20);
                int x = Width - 30;
                int y = 12;

                /*
                 * x--; y++;
                 * g.DrawLine(pen, x, y, x, y + 4);
                 * x--; y++;
                 * g.DrawLine(pen, x, y, x, y + 2);
                 * x--; y++;
                 * x = Width - 30;
                 * y = 12;
                 * */
                for (int i = 0; i < 6; i++)
                {
                    g.DrawLine(CheckedPen, x, y, x, y + 6);
                    x++; y++;
                }
                for (int i = 0; i < 12; i++)
                {
                    g.DrawLine(CheckedPen, x, y, x, y + 6);
                    x++; y--;
                }

                /*
                 * g.DrawLine(pen, x, y + 2, x, y + 6);
                 * x++; y++;
                 * g.DrawLine(pen, x, y + 2, x, y + 4);
                 * x++; y++;
                 * */
            }
            //画边框
            if (IsActivedDut)
            {
                g.DrawPath(BorderPen, path);
            }
            else
            {
                System.Drawing.Brush defaultBrush = new SolidBrush(this.BorderColor);
                System.Drawing.Pen   defaultPen   = new Pen(defaultBrush, this.BorderThickness);
                g.DrawPath(defaultPen, path);
            }
            //销毁Graphic 对象
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderPen.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }

            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
        }
Exemplo n.º 39
0
        /// <summary>This method will paint the group title.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintGroupText(System.Drawing.Graphics g)
        {
            //Check if string has something-------------
            if (this.GroupTitle == string.Empty)
            {
                return;
            }
            //------------------------------------------

            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            SizeF stringSize  = g.MeasureString(this.GroupTitle, this.Font);
            Size  stringSize2 = stringSize.ToSize();


            if (this.GroupImage != null)
            {
                stringSize2.Width += 18;
            }
            //int ArcWidth = this.RoundCorners;
            //int ArcHeight = this.RoundCorners;
            int arcWidth  = this.HeaderRoundCorners;
            int arcHeight = this.HeaderRoundCorners;
            //int intX1 = 0;
            //int intX2 = 0;

            //int ArcX1 = 10;
            //int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1);
            int ArcX1 = 20;
            int ArcX2 = (stringSize2.Width + 34) - (arcWidth + 1);
            int ArcY1 = 2;
            int ArcY2 = 22 - (arcHeight + 1);

            //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===Start
            int intMidX           = this.Size.Width / 2;
            int intMidX1          = (ArcX2 - ArcX1) / 2;
            int CustomStringWidth = (this.GroupImage != null) ? 44 : 28;

            _vXTrans = intMidX - intMidX1 - ArcX1;//X坐标平移距离
            int intTitleTextSpace = CustomStringWidth - ArcX1;

            //中间对齐
            if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Center)
            {
                ArcX1             = intMidX - intMidX1;
                ArcX2             = intMidX + intMidX1;
                CustomStringWidth = ArcX1 + intTitleTextSpace;
            }
            else if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Right)
            {
                ArcX1             = intMidX + intMidX - ArcX2;
                ArcX2             = ArcX1 + intMidX1 + intMidX1;
                CustomStringWidth = ArcX1 + intTitleTextSpace;
            }
            //标题与左边线距离
            ArcX1 -= this.TitleLeftSpace;
            ArcX2 -= this.TitleLeftSpace;

            //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===End
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush           = new SolidBrush(this.BorderColor);
            System.Drawing.Pen   BorderPen             = new Pen(BorderBrush, this.BorderThickness);
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush                  BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush             TextColorBrush  = new SolidBrush(this.ForeColor);
            System.Drawing.SolidBrush             ShadowBrush     = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath      = null;
            //-----------------------------------

            //Check if shadow is needed----------
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath  = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(new SolidBrush(Color.Transparent), ShadowPath);
                //g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------
            //Edit BY WZW 2008-12-16
            //是否显示标题边框------
            if (this._vShowTileRectangle)
            {
                //创建title边框路径
                path.AddArc(ArcX1, ArcY1, arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left
                path.AddArc(ArcX2, ArcY1, arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right
                path.AddArc(ArcX2, ArcY2, arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
                path.AddArc(ArcX1, ArcY2, arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
                path.CloseAllFigures();
                //画Title边框
                g.DrawPath(BorderPen, path);
            }

            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (this.PaintGroupBox)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                if (this.BackgroundGradientMode == GroupBoxGradientMode.None)
                {
                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundBrush, path);
                    //-----------------------------------
                }
                else
                {
                    BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundGradientBrush, path);
                    //-----------------------------------
                }
            }
            //-----------------------------------

            //绘制title文字-------------------------
            //int CustomStringWidth = (this.GroupImage != null) ? 44 : 28;
            //if(this.GroupImage!=null)
            //{
            //    CustomStringWidth += 2;
            //}

            //g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 5);

            // g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth-this.TitleLeftSpace-2, 5);
            g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth - this.TitleLeftSpace, 5);
            //-----------------------------------

            //Draw GroupImage if there is one----
            if (this.GroupImage != null)
            {
                //因增加了标题对齐功能,需修改X坐标值 By  WZW 2008-12-17
                g.DrawImage(this.GroupImage, ArcX1 + 5, 4, 16, 16);
            }

            //释放资源------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (TextColorBrush != null)
            {
                TextColorBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
        }
Exemplo n.º 40
0
        protected override void OnRenderButtonBackground(System.Windows.Forms.ToolStripItemRenderEventArgs e)
        {
            System.Drawing.Rectangle rectangle1;

            System.Drawing.Graphics graphics1 = e.Graphics;
            Oranikle.Studio.Controls.CtrlTabStrip       ctrlTabStrip       = e.ToolStrip as Oranikle.Studio.Controls.CtrlTabStrip;
            Oranikle.Studio.Controls.CtrlTabStripButton ctrlTabStripButton = e.Item as Oranikle.Studio.Controls.CtrlTabStripButton;
            if ((ctrlTabStrip == null) || (ctrlTabStripButton == null))
            {
                if (currentRenderer != null)
                {
                    currentRenderer.DrawButtonBackground(e);
                    return;
                }
                base.OnRenderButtonBackground(e);
                return;
            }
            bool flag1 = ctrlTabStripButton.Checked;
            bool flag2 = ctrlTabStripButton.Selected;
            int  i1 = 0, i2 = 0;

            System.Drawing.Rectangle rectangle3 = ctrlTabStripButton.Bounds;
            int i3 = rectangle3.Width - 1;

            System.Drawing.Rectangle rectangle4 = ctrlTabStripButton.Bounds;
            int i4 = rectangle4.Height - 1;

            if (UseVS)
            {
                if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal)
                {
                    if (!flag1)
                    {
                        i1 = 2;
                        i4--;
                    }
                    else
                    {
                        i1 = 1;
                    }
                    rectangle1 = new System.Drawing.Rectangle(0, 0, i3, i4);
                }
                else
                {
                    if (!flag1)
                    {
                        i2 = 2;
                        i3--;
                    }
                    else
                    {
                        i2 = 1;
                    }
                    rectangle1 = new System.Drawing.Rectangle(0, 0, i4, i3);
                }
                using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(rectangle1.Width, rectangle1.Height))
                {
                    System.Windows.Forms.VisualStyles.VisualStyleElement visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Normal;
                    if (flag1)
                    {
                        visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Pressed;
                    }
                    if (flag2)
                    {
                        visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Hot;
                    }
                    if (!ctrlTabStripButton.Enabled)
                    {
                        visualStyleElement = System.Windows.Forms.VisualStyles.VisualStyleElement.Tab.TabItem.Disabled;
                    }
                    if (!flag1 || flag2)
                    {
                        rectangle1.Width++;
                    }
                    else
                    {
                        rectangle1.Height++;
                    }
                    using (System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap))
                    {
                        System.Windows.Forms.VisualStyles.VisualStyleRenderer visualStyleRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(visualStyleElement);
                        visualStyleRenderer.DrawBackground(graphics2, rectangle1);
                        if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Vertical)
                        {
                            if (Mirrored)
                            {
                                bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                            }
                            else
                            {
                                bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                            }
                        }
                        else if (Mirrored)
                        {
                            bitmap.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
                        }
                        if (Mirrored)
                        {
                            System.Drawing.Rectangle rectangle5 = ctrlTabStripButton.Bounds;
                            i2 = rectangle5.Width - bitmap.Width - i2;
                            System.Drawing.Rectangle rectangle6 = ctrlTabStripButton.Bounds;
                            i1 = rectangle6.Height - bitmap.Height - i1;
                        }
                        graphics1.DrawImage(bitmap, i2, i1);
                    }
                    return;
                }
            }
            if (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal)
            {
                if (!flag1)
                {
                    i1  = ctrlTabStripButton.VerticalOffsetInactive;
                    i4 -= ctrlTabStripButton.VerticalOffsetInactive - 1;
                }
                else
                {
                    i1 = ctrlTabStripButton.VerticalOffset;
                }
                if (Mirrored)
                {
                    i2 = 1;
                    i1 = 0;
                }
                else
                {
                    i1++;
                }
                i3--;
            }
            else
            {
                if (!flag1)
                {
                    i2 = 2;
                    i3--;
                }
                else
                {
                    i2 = 1;
                }
                if (Mirrored)
                {
                    i2 = 0;
                    i1 = 1;
                }
            }
            i4--;
            rectangle1 = new System.Drawing.Rectangle(i2, i1, i3, i4);
            using (System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath())
            {
                if (Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal))
                {
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Top, rectangle1.Left, rectangle1.Bottom - 2);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Bottom - 3, 2, 2, 90.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left + 2, rectangle1.Bottom, rectangle1.Right - 2, rectangle1.Bottom);
                    graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Bottom - 3, 2, 2, 0.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right, rectangle1.Bottom - 2, rectangle1.Right, rectangle1.Top);
                }
                else if (!Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Horizontal))
                {
                    int i5 = 1, i6 = 3;
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Bottom, rectangle1.Left, rectangle1.Top + i6);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Top + i6 - 1, i6, i6, 180.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left + i6, rectangle1.Top, rectangle1.Right - i6 - i5, rectangle1.Top);
                    graphicsPath.AddArc(rectangle1.Right - i6 - i5, rectangle1.Top + i6 - 1, i6, i6, 270.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right - i5, rectangle1.Top + i6, rectangle1.Right - i5, rectangle1.Bottom);
                }
                else if (Mirrored && (ctrlTabStrip.Orientation == System.Windows.Forms.Orientation.Vertical))
                {
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Top, rectangle1.Right - 2, rectangle1.Top);
                    graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Top + 1, 2, 2, 270.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right, rectangle1.Top + 2, rectangle1.Right, rectangle1.Bottom - 2);
                    graphicsPath.AddArc(rectangle1.Right - 2, rectangle1.Bottom - 3, 2, 2, 0.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Right - 2, rectangle1.Bottom, rectangle1.Left, rectangle1.Bottom);
                }
                else
                {
                    graphicsPath.AddLine(rectangle1.Right, rectangle1.Top, rectangle1.Left + 2, rectangle1.Top);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Top + 1, 2, 2, 180.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left, rectangle1.Top + 2, rectangle1.Left, rectangle1.Bottom - 2);
                    graphicsPath.AddArc(rectangle1.Left, rectangle1.Bottom - 3, 2, 2, 90.0F, 90.0F);
                    graphicsPath.AddLine(rectangle1.Left + 2, rectangle1.Bottom, rectangle1.Right, rectangle1.Bottom);
                }
                System.Drawing.Color color1 = ctrlTabStripButton.BackColorInactive;
                if (flag1)
                {
                    color1 = ctrlTabStripButton.BackColor;
                }
                else if (flag2)
                {
                    color1 = ctrlTabStripButton.BackColorHot;
                }
                System.Drawing.Color color2 = ctrlTabStripButton.BackColor2Inactive;
                if (flag1)
                {
                    color2 = ctrlTabStripButton.BackColor2;
                }
                else if (flag2)
                {
                    color2 = ctrlTabStripButton.BackColor2Hot;
                }
                if (renderMode == System.Windows.Forms.ToolStripRenderMode.Professional)
                {
                    color1 = flag2 ? System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientBegin : System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientEnd;
                    using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush1 = new System.Drawing.Drawing2D.LinearGradientBrush(ctrlTabStripButton.ContentRectangle, color1, System.Windows.Forms.ProfessionalColors.ButtonCheckedGradientMiddle, System.Drawing.Drawing2D.LinearGradientMode.Vertical))
                    {
                        graphics1.FillPath(linearGradientBrush1, graphicsPath);
                        goto label_1;
                    }
                }
                using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush2 = new System.Drawing.Drawing2D.LinearGradientBrush(ctrlTabStripButton.ContentRectangle, color1, color2, System.Drawing.Drawing2D.LinearGradientMode.Vertical))
                {
                    graphics1.FillPath(linearGradientBrush2, graphicsPath);
                }
label_1:
                if (flag1)
                {
                    using (System.Drawing.Pen pen1 = new System.Drawing.Pen(ctrlTabStripButton.BorderColor))
                    {
                        graphics1.DrawPath(pen1, graphicsPath);
                        goto label_2;
                    }
                }
                if (flag2)
                {
                    using (System.Drawing.Pen pen2 = new System.Drawing.Pen(ctrlTabStripButton.BorderColorHot))
                    {
                        graphics1.DrawPath(pen2, graphicsPath);
                        goto label_2;
                    }
                }
                using (System.Drawing.Pen pen3 = new System.Drawing.Pen(ctrlTabStripButton.BorderColorInactive))
                {
                    graphics1.DrawPath(pen3, graphicsPath);
                }
label_2:
                if (ctrlTabStripButton.ShowCloseButton)
                {
                    System.Drawing.Image image = Oranikle.Studio.Controls.Properties.Resources.Icon_Close_Disabled_16;
                    if (flag2)
                    {
                        image = Oranikle.Studio.Controls.Properties.Resources.Icon_Close_16;
                    }
                    System.Drawing.Rectangle rectangle2 = new System.Drawing.Rectangle(i2 + i3 - ctrlTabStripButton.CloseButtonHorizontalOffset, ctrlTabStripButton.CloseButtonVerticalOffset, 8, 8);
                    graphics1.DrawImage(image, rectangle2);
                }
            }
        }
Exemplo n.º 41
0
        //public  System.Drawing.Image getImageFromShape(Shape shape, float ZoomFactor)
        //{
        //    System.Drawing.Image img = null;



        //    double ll = Math.Truncate(ZoomFactor * 100000);
        //    float tt = (float)(100000 / ll);

        //    bool selected = shape.Selected;
        //    bool locked = shape.Locked;
        //    PointF ShapeLocation = shape.Location;

        //    shape.Selected = true;
        //    shape.Locked = false;

        //    shape.Location = new PointF(2, 2);


        //    try
        //    {
        //        shape.Transformer.Scale(tt, tt);
        //    }
        //    catch
        //    {
        //    }



        //    Pen pen = new Pen(shape.Appearance.ActivePen.Color, shape.Appearance.BorderWidth * tt);

        //    pen.MiterLimit = 1;
        //    pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
        //    pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;

        //    Bitmap bmp = new Bitmap((int)(shape.Dimension.Width + 5), (int)(shape.Dimension.Height + 5));
        //    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

        //    g.Clear(Color.White);

        //    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

        //    g.DrawPath(pen, shape.Geometric);
        //    long i = 0;


        //    if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.Text)
        //    {
        //        Sbn.AdvancedControls.Imaging.SbnPaint.Text ttext = new Text();
        //        ttext = (Sbn.AdvancedControls.Imaging.SbnPaint.Text)shape;
        //        Brush bb = new System.Drawing.SolidBrush(ttext.Appearance.MarkerColor);


        //        StringFormat m_Formatdd = new StringFormat();
        //        m_Formatdd.Alignment = StringAlignment.Near;
        //        m_Formatdd.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.DirectionRightToLeft;
        //        m_Formatdd.LineAlignment = StringAlignment.Near;

        //        Rectangle WFTitle = new Rectangle(0, 0, bmp.Width, bmp.Height);

        //        // using (Font fntDayDate = new Font("Tahoma", 10, FontStyle.Regular))
        //        g.DrawString(ttext.DisplayedText, ttext.Font, SystemBrushes.WindowText, WFTitle, m_Formatdd);



        //        // g.DrawString(ttext.DisplayedText, ttext.Font, bb, new PointF(0, 0) , sf);
        //    }

        //    if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.RectangleBody)
        //    {
        //        //Pen pen = new Pen(shape.Appearance.ActivePen.Color, shape.Appearance.BorderWidth * tt);

        //        //pen.MiterLimit = 1;
        //        //pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
        //        //pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;

        //        g.DrawRectangle(pen, 0, 0, shape.Dimension.Width, shape.Dimension.Height);
        //    }

        //    g.Dispose();

        //    bmp.MakeTransparent(Color.White);

        //    Bitmap bmpp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format4bppIndexed);

        //    bmp.Palette = bmpp.Palette;
        //    bmp.Save("c:\\www2.jpg");
        //    pen.Dispose();
        //    shape.Location = ShapeLocation;
        //    shape.Selected = selected;
        //    shape.Locked = locked;


        //    //bmp.MakeTransparent(Color.White);
        //    //System.IO.MemoryStream ms = new System.IO.MemoryStream();
        //    //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

        //    return (System.Drawing.Image)bmp;

        //}


        public System.Drawing.Image getImageFromShapeOld(Shape shape, float ZoomFactor)
        {
            System.Drawing.Image img = null;



            double ll = Math.Truncate(ZoomFactor * 100000);
            float  tt = (float)(100000 / ll);

            bool selected = shape.Selected;
            bool locked   = shape.Locked;

            shape.Selected = true;
            shape.Locked   = false;

            try
            {
                shape.Transformer.Scale(tt, tt);
            }
            catch
            {
            }

            shape.Selected = selected;
            shape.Locked   = locked;

            Bitmap bmp = new Bitmap((int)(shape.Dimension.Width + 5), (int)(shape.Dimension.Height + 5));

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

            g.Clear(Color.White);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            long i = 0;

            if (shape is Sbn.FramWork.Drawing.CompositeShape)
            {
                foreach (Shape sh in ((Sbn.FramWork.Drawing.CompositeShape)shape).Shapes)
                {
                    PointF[] pf = new PointF[sh.Geometric.PathPoints.Length];

                    long j = 0;
                    foreach (PointF point in sh.Geometric.PathPoints)
                    {
                        if (i < shape.Geometric.PathPoints.Length)
                        {
                            pf[j].X = shape.Geometric.PathPoints[i].X - shape.Location.X + 2;
                            pf[j].Y = shape.Geometric.PathPoints[i].Y - shape.Location.Y + 2;
                            i++;
                            if (j == sh.Geometric.PointCount - 1)
                            {
                                break;
                            }
                            j++;
                        }
                    }

                    Pen pen = new Pen(sh.Appearance.ActivePen.Color, sh.Appearance.BorderWidth * tt);

                    pen.MiterLimit = 1;
                    pen.EndCap     = System.Drawing.Drawing2D.LineCap.Round;
                    pen.StartCap   = System.Drawing.Drawing2D.LineCap.Round;

                    System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(pf, sh.Geometric.PathTypes);


                    g.DrawPath(pen, gp);

                    pen.Dispose();
                }
            }


            if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.Text)
            {
                Sbn.AdvancedControls.Imaging.SbnPaint.Text ttext = new Text();
                ttext = (Sbn.AdvancedControls.Imaging.SbnPaint.Text)shape;
                Brush bb = new System.Drawing.SolidBrush(ttext.Appearance.MarkerColor);


                StringFormat m_Formatdd = new StringFormat();
                m_Formatdd.Alignment     = StringAlignment.Near;
                m_Formatdd.FormatFlags   = StringFormatFlags.NoWrap | StringFormatFlags.DirectionRightToLeft;
                m_Formatdd.LineAlignment = StringAlignment.Near;

                Rectangle WFTitle = new Rectangle(0, 0, bmp.Width, bmp.Height);

                // using (Font fntDayDate = new Font("Tahoma", 10, FontStyle.Regular))
                g.DrawString(ttext.DisplayedText, ttext.Font, SystemBrushes.WindowText, WFTitle, m_Formatdd);



                // g.DrawString(ttext.DisplayedText, ttext.Font, bb, new PointF(0, 0) , sf);
            }

            if (shape is Sbn.AdvancedControls.Imaging.SbnPaint.RectangleBody)
            {
                Pen pen = new Pen(shape.Appearance.ActivePen.Color, shape.Appearance.BorderWidth * tt);

                pen.MiterLimit = 1;
                pen.EndCap     = System.Drawing.Drawing2D.LineCap.Round;
                pen.StartCap   = System.Drawing.Drawing2D.LineCap.Round;

                g.DrawRectangle(pen, 0, 0, shape.Dimension.Width, shape.Dimension.Height);
            }

            g.Dispose();

            bmp.MakeTransparent(Color.White);

            Bitmap bmpp = new Bitmap(bmp.Width, bmp.Height, System.Drawing.Imaging.PixelFormat.Format4bppIndexed);

            bmp.Palette = bmpp.Palette;
            bmp.Save("c:\\www.jpg");

            return((System.Drawing.Image)bmp);
        }
Exemplo n.º 42
0
        /// <summary>
        /// Source: http://www.extensionmethod.net/csharp/draw/fill-draw-roundedrectangle
        /// </summary>
        /// <param name="g"></param>
        /// <param name="pen">Passing null will disable edge drawing.</param>
        /// <param name="brush">Passing null will disable filling enterior or rectngle.</param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="radius"></param>
        /// <param name="roundTopLeft"></param>
        /// <param name="roundTopRight"></param>
        /// <param name="roundBottomLeft"></param>
        /// <param name="roundBottomRight"></param>
        public static void DrawOrFillRoundedRectangle(this System.Drawing.Graphics g, Pen pen, Brush brush, int x, int y, int width, int height, int radius, bool roundTopLeft = true, bool roundTopRight = true, bool roundBottomLeft = true, bool roundBottomRight = true, Color?backgroundForCorners = null)
        {
            int shortestSide = Math.Min(width, height);

            if (radius >= shortestSide)
            {
                radius = shortestSide - 1;
            }
            if (radius <= 0)
            {
                radius = 1;
            }

            float?originalPenWidth = null;

            if (pen != null)
            {
                if (pen.Width * 2 + 3 >= shortestSide)
                {
                    originalPenWidth = pen.Width;
                    pen.Width        = (float)Math.Floor((float)shortestSide / 2) - 3;
                }

                //Below id fixed with g.Clip(...)
                //if (pen.Width * 2 >= radius)
                //{
                //	pen.Width = (float)Math.Floor((float)radius / 2) - 1;
                //}
            }


            float penWidth = pen == null ? 0 : pen.Width;
            int   lineAndArcAndPenWidthJunctionFix = (int)Math.Round(penWidth * 1.9);

            var originalGClip = g.Clip;

            g.Clip = new Region(new Rectangle((int)Math.Round(x - penWidth / 2), (int)Math.Round(y - penWidth / 2), (int)Math.Round(width + penWidth), (int)Math.Round(height + penWidth)));

            Rectangle corner = new Rectangle(x, y, radius, radius);

            using (GraphicsPath path = new GraphicsPath())
            {
                Pen   bp = null;
                Brush bb = null;
                try
                {
                    if (backgroundForCorners != null)
                    {
                        bp = new Pen(backgroundForCorners.Value, penWidth);
                        bb = new SolidBrush(backgroundForCorners.Value);
                    }

                    if (!roundTopLeft)
                    {
                        path.AddLine(new Point(corner.X, corner.Y), new Point(corner.X, corner.Y));
                    }
                    else
                    {
                        path.AddArc(corner, 180, 90);
                        if (backgroundForCorners != null)
                        {
                            using (GraphicsPath path2 = new GraphicsPath())
                            {
                                path2.AddArc(corner, 180, 90 - lineAndArcAndPenWidthJunctionFix);
                                path2.AddLine(corner.X + corner.Width / 2 - penWidth, corner.Y, corner.X, corner.Y);
                                path2.AddLine(corner.X, corner.Y, corner.X, corner.Y + corner.Height / 2);
                                g.FillPath(bb, path2);
                                g.DrawLine(bp, corner.X + corner.Width / 2 + penWidth / 2, corner.Y, corner.X, corner.Y);
                                g.DrawPath(bp, path2);
                            }
                        }
                    }

                    corner.X = x + width - radius;
                    if (!roundTopRight)
                    {
                        path.AddLine(new Point(corner.X + corner.Width, corner.Y), new Point(corner.X + corner.Width, corner.Y));
                    }
                    else
                    {
                        path.AddArc(corner, 270, 90);
                        if (backgroundForCorners != null)
                        {
                            using (GraphicsPath path2 = new GraphicsPath())
                            {
                                path2.AddArc(corner, 270, 90 - lineAndArcAndPenWidthJunctionFix);
                                path2.AddLine(corner.Right, corner.Bottom - (corner.Height / 2) - penWidth, corner.Right, corner.Y);
                                path2.AddLine(corner.Right, corner.Y, corner.Right - (corner.Width / 2), corner.Y);
                                g.FillPath(bb, path2);
                                g.DrawLine(bp, corner.Right, corner.Bottom - (corner.Height / 2) + penWidth / 2, corner.Right, corner.Y);
                                g.DrawPath(bp, path2);
                            }
                        }
                    }

                    corner.Y = y + height - radius;
                    if (!roundBottomRight)
                    {
                        path.AddLine(new Point(corner.X + corner.Width, corner.Y + corner.Height), new Point(corner.X + corner.Width, corner.Y + corner.Height));
                    }
                    else
                    {
                        path.AddArc(corner, 0, 90);
                        if (backgroundForCorners != null)
                        {
                            using (GraphicsPath path2 = new GraphicsPath())
                            {
                                path2.AddArc(corner, 0, 90 - lineAndArcAndPenWidthJunctionFix);
                                path2.AddLine(corner.Right - (corner.Width / 2) + penWidth, corner.Bottom, corner.Right, corner.Bottom);
                                path2.AddLine(corner.Right, corner.Bottom, corner.Right, corner.Bottom - (corner.Height / 2));
                                g.FillPath(bb, path2);
                                g.DrawLine(bp, corner.Right - (corner.Width / 2) - penWidth / 2, corner.Bottom, corner.Right, corner.Bottom);
                                g.DrawPath(bp, path2);
                            }
                        }
                    }

                    corner.X = x;
                    if (!roundBottomLeft)
                    {
                        path.AddLine(new Point(corner.X, corner.Y + corner.Height), new Point(corner.X, corner.Y + corner.Height));
                    }
                    else
                    {
                        path.AddArc(corner, 90, 90);
                        if (backgroundForCorners != null)
                        {
                            using (GraphicsPath path2 = new GraphicsPath())
                            {
                                path2.AddArc(corner, 90, 90 - lineAndArcAndPenWidthJunctionFix);
                                path2.AddLine(corner.Left, corner.Bottom - corner.Height / 2 + penWidth, corner.Left, corner.Bottom);
                                path2.AddLine(corner.Left, corner.Bottom, corner.Left + (corner.Width / 2), corner.Bottom);
                                g.FillPath(bb, path2);
                                g.DrawLine(bp, corner.Left, corner.Bottom - corner.Height / 2 - penWidth / 2, corner.Left, corner.Bottom);
                                g.DrawPath(bp, path2);
                            }
                        }
                    }
                }
                finally
                {
                    if (backgroundForCorners != null)
                    {
                        bb.Dispose();
                        bp.Dispose();
                    }
                }

                path.CloseFigure();

                if (brush != null)
                {
                    g.FillPath(brush, path);
                }

                if (pen != null)
                {
                    g.DrawPath(pen, path);
                }
            }

            g.Clip = originalGClip;

            if (originalPenWidth != null)
            {
                pen.Width = originalPenWidth.Value;
            }
        }
Exemplo n.º 43
0
 /// <summary>
 /// Draws the outline of a rounded rectangle.
 /// </summary>
 /// <param name="graphics">The graphics to draw on.</param>
 /// <param name="pen">The pen to use to draw the rectangle.</param>
 /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to draw.</param>
 /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to draw.</param>
 /// <param name="width">Width of the rectangle to draw.</param>
 /// <param name="height">Height of the rectangle to draw.</param>
 /// <param name="radius">The radius of rounded corners.</param>
 public static void DrawRoundedRectangle(System.Drawing.Graphics graphics, Pen pen, int x, int y, int width, int height, int radius)
 {
     using (GraphicsPath path = GetRoundedRectanglePath(x, y, width, height, radius)) {
         graphics.DrawPath(pen, path);
     }
 }
Exemplo n.º 44
0
        public CGlyph(char chr, float MaxHigh)
        {
            _SIZEh = MaxHigh;

            float           outline = CFonts.Outline;
            TextFormatFlags flags   = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix;

            float factor = GetFactor(chr, flags);

            CFonts.Height = SIZEh * factor;
            Bitmap bmp = new Bitmap(10, 10);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

            Font fo    = CFonts.GetFont();
            Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);

            SizeF size = g.MeasureString(chr.ToString(), fo);

            g.Dispose();
            bmp.Dispose();

            bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height);
            g   = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.Transparent);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            CFonts.Height       = SIZEh;
            fo = CFonts.GetFont();

            PointF point = new PointF(
                outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + SIZEh / 5f,
                (sizeB.Height - size.Height - (size.Height + SIZEh / 4f) * (1f - factor)) / 2f);

            GraphicsPath path = new GraphicsPath();

            path.AddString(
                chr.ToString(),
                fo.FontFamily,
                (int)fo.Style,
                SIZEh,
                point,
                new StringFormat());

            Pen pen = new Pen(
                Color.FromArgb(
                    (int)CFonts.OutlineColor.A * 255,
                    (int)CFonts.OutlineColor.R * 255,
                    (int)CFonts.OutlineColor.G * 255,
                    (int)CFonts.OutlineColor.B * 255),
                SIZEh * outline);

            pen.LineJoin = LineJoin.Round;
            g.DrawPath(pen, path);
            g.FillPath(Brushes.White, path);

            /*
             * g.DrawString(
             *  chr.ToString(),
             *  fo,
             *  Brushes.White,
             *  point);
             * */

            Texture = CDraw.AddTexture(bmp);
            //bmp.Save("test.png", ImageFormat.Png);
            Chr   = chr;
            width = (int)((1f + outline / 2f) * sizeB.Width * Texture.width / factor / bmp.Width);

            bmp.Dispose();
            g.Dispose();
            fo.Dispose();
        }
        protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel)
        {
            base.Render(canvas, graphics, channel);

            if (channel == GH_CanvasChannel.Objects)
            {
                Pen spacer = new Pen(UI.Colour.SpacerColour);

                Font font = GH_FontServer.Standard;
                // adjust fontsize to high resolution displays
                font = new Font(font.FontFamily, font.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular);

                Font sml = GH_FontServer.Small;
                // adjust fontsize to high resolution displays
                sml = new Font(sml.FontFamily, sml.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular);

                //Draw divider line
                if (SpacerTxt != "")
                {
                    graphics.DrawString(SpacerTxt, sml, UI.Colour.AnnotationTextDark, SpacerBounds, GH_TextRenderingConstants.CenterCenter);
                    graphics.DrawLine(spacer, SpacerBounds.X, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 - 4, SpacerBounds.Y + SpacerBounds.Height / 2);
                    graphics.DrawLine(spacer, SpacerBounds.X + (SpacerBounds.Width - GH_FontServer.StringWidth(SpacerTxt, sml)) / 2 + GH_FontServer.StringWidth(SpacerTxt, sml) + 4, SpacerBounds.Y + SpacerBounds.Height / 2, SpacerBounds.X + SpacerBounds.Width, SpacerBounds.Y + SpacerBounds.Height / 2);
                }

                // ### button 1 ###
                // Draw button box
                System.Drawing.Drawing2D.GraphicsPath button1 = UI.ButtonsUI.Button.RoundedRect(Button1Bounds, 2);

                Brush normal_colour1  = UI.Colour.ButtonColour;
                Brush hover_colour1   = UI.Colour.HoverButtonColour;
                Brush clicked_colour1 = UI.Colour.ClickedButtonColour;

                Brush butCol1 = (mouseOver1) ? hover_colour1 : normal_colour1;
                graphics.FillPath(mouseDown1 ? clicked_colour1 : butCol1, button1);

                // draw button edge
                Color edgeColor1 = UI.Colour.ButtonBorderColour;
                Color edgeHover1 = UI.Colour.HoverBorderColour;
                Color edgeClick1 = UI.Colour.ClickedBorderColour;
                Color edgeCol1   = (mouseOver1) ? edgeHover1 : edgeColor1;
                Pen   pen1       = new Pen(mouseDown1 ? edgeClick1 : edgeCol1)
                {
                    Width = (mouseDown1) ? 0.8f : 0.5f
                };
                graphics.DrawPath(pen1, button1);

                // draw button text
                graphics.DrawString(button1Text, font, UI.Colour.AnnotationTextBright, Button1Bounds, GH_TextRenderingConstants.CenterCenter);


                // ### button 2 ###
                // Draw button box
                System.Drawing.Drawing2D.GraphicsPath button2 = UI.ButtonsUI.Button.RoundedRect(Button2Bounds, 2);

                Brush normal_colour2  = UI.Colour.ButtonColour;
                Brush hover_colour2   = UI.Colour.HoverButtonColour;
                Brush clicked_colour2 = UI.Colour.ClickedButtonColour;

                Brush butCol2 = (mouseOver2) ? hover_colour2 : normal_colour2;
                graphics.FillPath(mouseDown2 ? clicked_colour2 : butCol2, button2);

                // draw button edge
                Color edgeColor2 = UI.Colour.ButtonBorderColour;
                Color edgeHover2 = UI.Colour.HoverBorderColour;
                Color edgeClick2 = UI.Colour.ClickedBorderColour;
                Color edgeCol2   = (mouseOver2) ? edgeHover2 : edgeColor2;
                Pen   pen2       = new Pen(mouseDown2 ? edgeClick2 : edgeCol2)
                {
                    Width = (mouseDown2) ? 0.8f : 0.5f
                };
                graphics.DrawPath(pen2, button2);

                // draw button text
                graphics.DrawString(button2Text, font, UI.Colour.AnnotationTextBright, Button2Bounds, GH_TextRenderingConstants.CenterCenter);

                // ### button 3 ###
                // Draw button box
                System.Drawing.Drawing2D.GraphicsPath button3 = UI.ButtonsUI.Button.RoundedRect(Button3Bounds, 2);

                Brush normal_colour3  = UI.Colour.ButtonColour;
                Brush hover_colour3   = UI.Colour.HoverButtonColour;
                Brush clicked_colour3 = UI.Colour.ClickedButtonColour;

                Brush butCol3 = (mouseOver3) ? hover_colour3 : normal_colour3;
                graphics.FillPath(mouseDown3 ? clicked_colour3 : butCol3, button3);

                // draw button edge
                Color edgeColor3 = UI.Colour.ButtonBorderColour;
                Color edgeHover3 = UI.Colour.HoverBorderColour;
                Color edgeClick3 = UI.Colour.ClickedBorderColour;
                Color edgeCol3   = (mouseOver3) ? edgeHover3 : edgeColor3;
                Pen   pen3       = new Pen(mouseDown3 ? edgeClick3 : edgeCol3)
                {
                    Width = (mouseDown3) ? 0.8f : 0.5f
                };
                graphics.DrawPath(pen3, button3);

                // draw button text
                graphics.DrawString(button3Text, font, UI.Colour.AnnotationTextBright, Button3Bounds, GH_TextRenderingConstants.CenterCenter);
            }
        }
Exemplo n.º 46
0
        /// <summary>This method will paint the control.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintBack(System.Drawing.Graphics g)
        {
            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            int ArcWidth  = this.RoundCorners * 2;
            int ArcHeight = this.RoundCorners * 2;
            int ArcX1     = 0;
            int ArcX2     = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1);
            int ArcY1     = 10;

            //Check if string has something-------------
            if (this.GroupTitle == string.Empty)
            {
                ArcY1 = 0;
            }
            //------------------------------------------
            int ArcY2 = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush           = new SolidBrush(this.BorderColor);
            System.Drawing.Pen   BorderPen             = new Pen(BorderBrush, this.BorderThickness);
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush                  BackgroundBrush = new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush             ShadowBrush     = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath      = null;
            //-----------------------------------

            //Check if shadow is needed----------
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath  = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle);            // Top Left
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle);            //Top Right
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle);            //Bottom Right
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle);             //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------

            //Create Rounded Rectangle Path------
            path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle);            // Top Left
            path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle);            //Top Right
            path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle);            //Bottom Right
            path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle);             //Bottom Left
            path.CloseAllFigures();
            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (this.BackgroundGradientMode == GroupBoxGradientMode.None)
            {
                //Paint Rounded Rectangle------------

                if (this.GroupBoxDrawStyle == GroupBoxDrawType.SingleLine)
                {
                    g.FillPath(BackgroundBrush, path);
                }
                else
                {
                    Brush brush1 = null;
                    Brush brush2 = null;
                    if (this.GroupBoxDrawStyle == GroupBoxDrawType.TwoLine)
                    {
                        brush1 = BackgroundBrush;
                        brush2 = new SolidBrush(BackgroundColor2);
                    }
                    else if (this.GroupBoxDrawStyle == GroupBoxDrawType.TwoLineReversed)
                    {
                        brush1 = new SolidBrush(BackgroundColor2);
                        brush2 = BackgroundBrush;
                    }

                    int          dis         = ArcY2 - ArcY1;
                    int          num         = dis / TwoLineDistance;
                    int          curY        = TwoLineStartOffset;
                    GraphicsPath twoLinePath = new GraphicsPath();

                    for (int i = 0; i < num; ++i)
                    {
                        if (i % 2 == 0)
                        {
                            g.FillRectangle(brush1, ArcX1 + 1, curY, ArcX2 + 2, TwoLineDistance);
                        }
                        else if (i % 2 == 1)
                        {
                            g.FillRectangle(brush2, ArcX1 + 1, curY, ArcX2 + 2, TwoLineDistance);
                        }

                        curY += TwoLineDistance;
                    }
                }

                //-----------------------------------
            }
            else
            {
                BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundGradientBrush, path);
                //-----------------------------------
            }
            //-----------------------------------

            //Paint Borded-----------------------
            g.DrawPath(BorderPen, path);
            //-----------------------------------

            //Destroy Graphic Objects------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
            //-----------------------------------
        }
Exemplo n.º 47
0
 partial void DrawRoundRectangleImp(Pen pen, RectangleF rect, float radius)
 {
     using (var gp = RoundRect(rect, radius))
         g.DrawPath(pen.pen, gp);
 }
Exemplo n.º 48
0
        /// <summary>This method will paint the control.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintBack(System.Drawing.Graphics g)
        {
            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            int ArcWidth  = this.RoundCorners * 2;
            int ArcHeight = this.RoundCorners * 2;
            int ArcX1     = 0;
            int ArcX2     = (this.ShadowControl) ? (this.Width - (ArcWidth + 1)) - this.ShadowThickness : this.Width - (ArcWidth + 1);
            int ArcY1     = 10;
            int ArcY2     = (this.ShadowControl) ? (this.Height - (ArcHeight + 1)) - this.ShadowThickness : this.Height - (ArcHeight + 1);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush           = new SolidBrush(this.BorderColor);
            System.Drawing.Pen   BorderPen             = new Pen(BorderBrush, this.BorderThickness);
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush                  BackgroundBrush = new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush             ShadowBrush     = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath      = null;
            //-----------------------------------

            //Check if shadow is needed----------
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath  = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 180, SweepAngle);            // Top Left
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY1 + this.ShadowThickness, ArcWidth, ArcHeight, 270, SweepAngle);            //Top Right
                ShadowPath.AddArc(ArcX2 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 360, SweepAngle);            //Bottom Right
                ShadowPath.AddArc(ArcX1 + this.ShadowThickness, ArcY2 + this.ShadowThickness, ArcWidth, ArcHeight, 90, SweepAngle);             //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------

            //Create Rounded Rectangle Path------
            path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle);            // Top Left
            path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle);            //Top Right
            path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle);            //Bottom Right
            path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle);             //Bottom Left
            path.CloseAllFigures();
            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (this.BackgroundGradientMode == GroupBoxGradientMode.None)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundGradientBrush, path);
                //-----------------------------------
            }
            //-----------------------------------

            //Paint Borded-----------------------
            g.DrawPath(BorderPen, path);
            //-----------------------------------

            //Destroy Graphic Objects------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
            //-----------------------------------
        }
Exemplo n.º 49
0
        public override System.Drawing.Image GetImage(float ZoomFactor)
        {
            //  return base.GetImage(ZoomFactor);


            float tt = (1 / ZoomFactor);

            Text TempImage = this.Clone() as Text;

            if (TempImage != null)
            {
                TempImage.Selected = true;
                TempImage.Locked   = false;


                TempImage.Transformer.Scale(tt, tt);
                TempImage.Transformer.Translate(-TempImage.Location.X, -TempImage.Location.Y);
                Bitmap bmpResult = new Bitmap((int)(TempImage.Dimension.Width), (int)(TempImage.Dimension.Height));  //,  System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                System.Drawing.Graphics gg = System.Drawing.Graphics.FromImage(bmpResult);
                gg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                gg.DrawPath(new Pen(Color), TempImage.Geometric);
                //this.Geometric.FillMode = System.Drawing.Drawing2D.FillMode.Winding;

                gg.FillPath(Brushes.Black, TempImage.Geometric);
                gg.Save();



                gg.Dispose();

                //try
                //{



                //    bmpResult.Save(@"D:\1.Png");
                //}
                //catch (Exception)
                //{


                //}



                return(bmpResult);
            }



            bool   selected      = this.Selected;
            bool   locked        = this.Locked;
            PointF ShapeLocation = this.Location;


            this.Selected = true;
            this.Locked   = false;

            this.Location = new PointF(0, 0);


            try
            {
                this.Transformer.Scale(tt, tt);
            }
            catch
            {
            }



            Bitmap bmp = new Bitmap((int)(this.Dimension.Width + 2), (int)(this.Dimension.Height + 2));//,  System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;


            //Brush bb = new System.Drawing.SolidBrush(this.Appearance.MarkerColor);

            //StringFormat m_Formatdd = new StringFormat();
            //m_Formatdd.Alignment = StringAlignment.Near;
            //m_Formatdd.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.DirectionRightToLeft;
            //m_Formatdd.LineAlignment = StringAlignment.Near;

            //Rectangle WFTitle = new Rectangle(0, 0, bmp.Width, bmp.Height);
            //Size ss = System.Windows.Forms.TextRenderer.MeasureText(this.DisplayedText, this.Font);

            //   g.DrawString(this.DisplayedText, this.Font, SystemBrushes.WindowText, WFTitle, this.StringFormat);// m_Formatdd);

            Transformer.Translate(-this.Location.X, -this.Location.Y);

            Pen pn = new Pen(Brushes.Black, 1);

            this.Appearance.ActivePen = pn;



            g.DrawPath(this.Appearance.ActivePen, this.Geometric);
            //this.Geometric.FillMode = System.Drawing.Drawing2D.FillMode.Winding;
            g.FillPath(Brushes.Black, this.Geometric);
            g.Dispose();
            //   bmp.Save("c:\\kkk.jpg");
            this.Location = ShapeLocation;
            this.Selected = selected;
            this.Locked   = locked;
            return(bmp);
        }
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);
            System.Drawing.Graphics G = e.Graphics;

            G.SmoothingMode = SmoothingMode.HighQuality;
            //G.Clear(Parent.BackColor);
            _Width  = Width - 1;
            _Height = Height - 1;

            GraphicsPath GP        = default(GraphicsPath);
            GraphicsPath GP2       = new GraphicsPath();
            Rectangle    BaseRect  = new Rectangle(0, 0, _Width, _Height);
            Rectangle    ThumbRect = new Rectangle(_Width / 2, 0, 38, _Height);

            G.SmoothingMode     = (System.Drawing.Drawing2D.SmoothingMode) 2;
            G.PixelOffsetMode   = (System.Drawing.Drawing2D.PixelOffsetMode) 2;
            G.TextRenderingHint = (System.Drawing.Text.TextRenderingHint) 5;
            //G.Clear(BackColor);

            GP        = RoundRectangle.RoundRect(BaseRect, 4);
            ThumbRect = new Rectangle(4, 4, 36, _Height - 8);
            GP2       = RoundRectangle.RoundRect(ThumbRect, 4);
            G.FillPath(new SolidBrush(bigBackgroundColor), GP);
            G.FillPath(new SolidBrush(smallBackgroundColor), GP2);
            G.DrawPath(new Pen(bigBackgroundBorderColor), GP);
            G.DrawPath(new Pen(smallBackgroundBorderColor), GP2);


            if (_Toggled)
            {
                GP        = RoundRectangle.RoundRect(BaseRect, 4);
                ThumbRect = new Rectangle((_Width / 2) - 2, 4, 36, _Height - 8);
                GP2       = RoundRectangle.RoundRect(ThumbRect, 4);
                G.FillPath(new SolidBrush(bigBackgroundToggledColor), GP);
                G.FillPath(new SolidBrush(smallBackgroundToggledColor), GP2);
                G.DrawPath(new Pen(bigBackgroundBorderColor), GP);
                G.DrawPath(new Pen(smallBackgroundBorderColor), GP2);
            }

            // Draw string
            switch (ToggleType)
            {
            case TypeOfToggle.CheckMark:
                if (Toggled)
                {
                    G.DrawString("ü", new Font("Wingdings", 18, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 19, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("r", new Font("Marlett", 14, FontStyle.Regular), Brushes.DimGray, Bar.X + 59, Bar.Y + 18, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case TypeOfToggle.OnOff:
                if (Toggled)
                {
                    G.DrawString("ON", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("OFF", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case TypeOfToggle.YesNo:
                if (Toggled)
                {
                    G.DrawString("YES", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 19, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("NO", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 56, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;

            case TypeOfToggle.IO:
                if (Toggled)
                {
                    G.DrawString("I", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                else
                {
                    G.DrawString("O", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 57, Bar.Y + 16, new StringFormat()
                    {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    });
                }
                break;
            }
        }
Exemplo n.º 51
0
        /// <summary>This method will paint the group title.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintGroupText(System.Drawing.Graphics g)
        {
            //Check if string has something-------------
            if (this.GroupTitle == string.Empty)
            {
                return;
            }
            //------------------------------------------

            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            SizeF StringSize  = g.MeasureString(this.GroupTitle, this.Font);
            Size  StringSize2 = StringSize.ToSize();

            if (this.GroupImage != null)
            {
                StringSize2.Width += 18;
            }
            int ArcWidth  = this.RoundCorners;
            int ArcHeight = this.RoundCorners;
            int ArcX1     = 20;
            int ArcX2     = (StringSize2.Width + 34) - (ArcWidth + 1);
            int ArcY1     = 0;
            int ArcY2     = 24 - (ArcHeight + 1);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush           = new SolidBrush(this.BorderColor);
            System.Drawing.Pen   BorderPen             = new Pen(BorderBrush, this.BorderThickness);
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush                  BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush             TextColorBrush  = new SolidBrush(this.ForeColor);
            System.Drawing.SolidBrush             ShadowBrush     = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath      = null;
            //-----------------------------------

            //Check if shadow is needed----------
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath  = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 180, SweepAngle);        // Top Left
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 270, SweepAngle);        //Top Right
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 360, SweepAngle);        //Bottom Right
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), ArcWidth, ArcHeight, 90, SweepAngle);         //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------

            //Create Rounded Rectangle Path------
            path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, SweepAngle);            // Top Left
            path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, SweepAngle);            //Top Right
            path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, SweepAngle);            //Bottom Right
            path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, SweepAngle);             //Bottom Left
            path.CloseAllFigures();
            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (this.PaintGroupBox)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                if (this.BackgroundGradientMode == GroupBoxGradientMode.None)
                {
                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundBrush, path);
                    //-----------------------------------
                }
                else
                {
                    BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundGradientBrush, path);
                    //-----------------------------------
                }
            }
            //-----------------------------------

            //Paint Borded-----------------------
            g.DrawPath(BorderPen, path);
            //-----------------------------------

            //Paint Text-------------------------
            int CustomStringWidth = (this.GroupImage != null) ? 44 : 28;

            g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 5);
            //-----------------------------------

            //Draw GroupImage if there is one----
            if (this.GroupImage != null)
            {
                g.DrawImage(this.GroupImage, 28, 4, 16, 16);
            }
            //-----------------------------------

            //Destroy Graphic Objects------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (TextColorBrush != null)
            {
                TextColorBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
            //-----------------------------------
        }
Exemplo n.º 52
0
 public static bool DrawRectangle(
     System.Drawing.Graphics g,
     System.Drawing.Pen BorderPen,
     System.Drawing.Brush FillBrush,
     System.Drawing.Rectangle Bounds,
     int roundRadio,
     System.Drawing.Rectangle ClipRectangle,
     bool ForceDrawBorder)
 {
     System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty;
     if (ClipRectangle.IsEmpty)
     {
         rect = Bounds;
     }
     else
     {
         rect = System.Drawing.Rectangle.Intersect(Bounds, ClipRectangle);
     }
     if (rect.IsEmpty)
     {
         return(false);
     }
     if (roundRadio <= 0)
     {
         if (FillBrush != null)
         {
             g.FillRectangle(FillBrush, rect);
         }
         if (BorderPen != null)
         {
             rect = new System.Drawing.Rectangle(
                 Bounds.Left,
                 Bounds.Top,
                 Bounds.Width - (int)Math.Ceiling(BorderPen.Width / 2.0),
                 Bounds.Height - (int)Math.Ceiling(BorderPen.Width / 2.0));
             if (ForceDrawBorder || ClipRectangle.IsEmpty)
             {
                 g.DrawRectangle(BorderPen, rect);
             }
             else
             {
                 if (rect.IntersectsWith(ClipRectangle))
                 {
                     g.DrawRectangle(BorderPen, rect);
                 }
             }
         }
     }
     else
     {
         if (FillBrush != null)
         {
             int fix = 0;
             if (BorderPen != null)
             {
                 fix = (int)Math.Ceiling(BorderPen.Width / 2.0);
             }
             using (GraphicsPath path = ShapeDrawer.CreateRoundRectanglePath(
                        new RectangleF(Bounds.Left, Bounds.Top, Bounds.Width - fix, Bounds.Height - fix),
                        roundRadio))
             {
                 g.FillPath(FillBrush, path);
             }
         }
         if (BorderPen != null)
         {
             using (GraphicsPath path = ShapeDrawer.CreateRoundRectanglePath(
                        new RectangleF(
                            Bounds.Left,
                            Bounds.Top,
                            Bounds.Width - ( int )Math.Ceiling(BorderPen.Width / 2.0),
                            Bounds.Height - ( int)Math.Ceiling(BorderPen.Width / 2.0)),
                        roundRadio))
             {
                 if (ForceDrawBorder || ClipRectangle.IsEmpty)
                 {
                     g.DrawPath(BorderPen, path);
                 }
                 else
                 {
                     if (rect.IntersectsWith(ClipRectangle))
                     {
                         g.DrawPath(BorderPen, path);
                     }
                 }
             }
         }
     }
     return(true);
 }
Exemplo n.º 53
0
 static void drawRoundedRectangle(System.Drawing.Graphics graphics, Rectangle rectangle, Pen pen, Vector4 corners)
 {
     using (GraphicsPath path = roundedPath(rectangle, corners))
         graphics.DrawPath(pen, path);
 }
Exemplo n.º 54
0
        /// <summary>
        /// 绘制
        /// </summary>
        /// <param name="g"></param>
        /// <param name="center"></param>
        /// <param name="zoom"></param>
        /// <param name="screen_size"></param>
        public override void Draw(System.Drawing.Graphics g, LatLngPoint center, int zoom, System.Drawing.Size screen_size)
        {
            //不同路线绘制不一样 数据源结构也不一样
            if (DataSource != null)
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //质量优先

                LatLngPoint first, second;
                Point       s_first = new Point(), s_second = new Point();
                if (Type == RouteType.Transit)                                  //公交
                {
                    using (Pen p = new Pen(Color.FromArgb(250, Color.Blue), 6)) //蓝色
                    {
                        p.StartCap = System.Drawing.Drawing2D.LineCap.Round;    //连接圆滑
                        p.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                        p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        JToken route = DataSource["scheme"][0];
                        foreach (JArray array in route["steps"])
                        {
                            if ((string)array[0]["type"] == "5") //步行
                            {
                                using (Pen p2 = new Pen(Color.FromArgb(250, Color.Gray), 6))
                                {
                                    p2.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                                    p2.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                                    p2.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;

                                    string[] points = ((string)array[0]["path"]).Split(';'); //每一步骤中的点

                                    for (int i = points.Length - 1; i > 0; --i)
                                    {
                                        first    = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                        second   = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                        s_first  = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                        s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                        if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                        {
                                            g.DrawLine(p2, s_first, s_second);
                                        }
                                    }
                                }
                            }
                            else //公交 地铁
                            {
                                string transits   = "";
                                double duration   = 0;
                                int    type       = 0; //公交 还是 地铁
                                string start_name = "";
                                duration   = double.Parse((string)array[0]["duration"]);
                                type       = int.Parse((string)array[0]["vehicle"]["type"]);
                                start_name = (string)array[0]["vehicle"]["start_name"];
                                foreach (JObject jo in array) //多种方案
                                {
                                    transits += ((string)jo["vehicle"]["name"] + "/");
                                }
                                transits = transits.TrimEnd(new char[] { '/' });
                                //只绘制一个方案即可

                                string[] points = ((string)array[0]["path"]).Split(';'); //每一步骤中的点

                                for (int i = points.Length - 1; i > 0; --i)
                                {
                                    first    = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                    second   = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_first  = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                    {
                                        g.DrawLine(p, s_first, s_second);
                                    }

                                    if (i == 1) //起点
                                    {
                                        using (Font f = new Font("微软雅黑", 8))
                                        {
                                            string info      = start_name + " 上车\n乘坐" + transits + " \n车程约" + Math.Round(duration / 60, 0) + "分钟";
                                            Size   info_size = TextRenderer.MeasureText(info, f);

                                            GraphicsPath pt = new GraphicsPath();

                                            pt.AddPolygon(new Point[] { new Point(s_first.X - info_size.Width / 2 - 5, s_first.Y - 25),
                                                                        new Point(s_first.X - info_size.Width / 2 - 5, s_first.Y - 25 - info_size.Height - 10),
                                                                        new Point(s_first.X + info_size.Width / 2 + 5, s_first.Y - 25 - info_size.Height - 10),
                                                                        new Point(s_first.X + info_size.Width / 2 + 5, s_first.Y - 25),
                                                                        new Point(s_first.X + 8, s_first.Y - 25),
                                                                        new Point(s_first.X, s_first.Y - 15),
                                                                        new Point(s_first.X - 8, s_first.Y - 25) });
                                            g.FillPath(Brushes.Wheat, pt);
                                            g.DrawPath(Pens.LightGray, pt);
                                            g.DrawString(info, new Font("微软雅黑", 9), Brushes.Black, new PointF(s_first.X - info_size.Width / 2, s_first.Y - info_size.Height - 25 - 5));

                                            Bitmap b = type == 0 ? Properties.BMap.ico_bybus : Properties.BMap.ico_bysubway; //0公交 1地铁轻轨

                                            g.DrawImage(b, new Rectangle(s_first.X - b.Width / 2, s_first.Y - b.Height / 2, b.Width, b.Height));
                                        }
                                    }
                                    if (i == points.Length - 1)                                                          //终点
                                    {
                                        Bitmap b = type == 0 ? Properties.BMap.ico_bybus : Properties.BMap.ico_bysubway; //0公交 1地铁轻轨

                                        g.DrawImage(b, new Rectangle(s_second.X - b.Width / 2, s_second.Y - b.Height / 2, b.Width, b.Height));
                                    }
                                }
                            }
                        }
                    }
                }
                else if (Type == RouteType.Driving)                              //驾车
                {
                    using (Pen p = new Pen(Color.FromArgb(250, Color.Green), 6)) //绿色
                    {
                        p.StartCap = System.Drawing.Drawing2D.LineCap.Round;     //连接圆滑
                        p.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                        p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        foreach (JObject step in DataSource["steps"])
                        {
                            first   = new LatLngPoint(double.Parse((string)step["stepOriginLocation"]["lng"]), double.Parse((string)step["stepOriginLocation"]["lat"]));
                            s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size); //第一点

                            string[] points = ((string)step["path"]).Split(';');                             //每一步骤中的点
                            for (int i = 0; i < points.Length; ++i)
                            {
                                if (i == 0) //与前一点连接
                                {
                                    second   = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                    {
                                        g.DrawLine(p, s_first, s_second);
                                    }
                                }
                                else
                                {
                                    first    = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                    second   = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_first  = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                    {
                                        g.DrawLine(p, s_first, s_second);
                                    }
                                }
                            }
                            s_first = s_second;

                            second   = new LatLngPoint(double.Parse((string)step["stepDestinationLocation"]["lng"]), double.Parse((string)step["stepDestinationLocation"]["lat"]));
                            s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                            if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                            {
                                g.DrawLine(p, s_first, s_second);                                                                                                //最后一点
                            }
                        }
                    }
                }
                else //步行
                {
                    using (Pen p = new Pen(Color.FromArgb(250, Color.Gray), 6)) //灰色
                    {
                        p.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                        p.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                        p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        foreach (JObject step in DataSource["steps"])
                        {
                            first   = new LatLngPoint(double.Parse((string)step["stepOriginLocation"]["lng"]), double.Parse((string)step["stepOriginLocation"]["lat"]));
                            s_first = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size); //第一点

                            string[] points = ((string)step["path"]).Split(';');                             //每一步骤中的点
                            for (int i = 0; i < points.Length; ++i)
                            {
                                if (i == 0) //与前一点连接
                                {
                                    second   = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                    {
                                        g.DrawLine(p, s_first, s_second);
                                    }
                                }
                                else
                                {
                                    first    = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                                    second   = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                                    s_first  = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                                    s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                                    if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                                    {
                                        g.DrawLine(p, s_first, s_second);
                                    }
                                }
                            }
                            s_first = s_second;

                            second   = new LatLngPoint(double.Parse((string)step["stepDestinationLocation"]["lng"]), double.Parse((string)step["stepDestinationLocation"]["lat"]));
                            s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                            if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                            {
                                g.DrawLine(p, s_first, s_second);                                                                                                //最后一点
                            }
                        }
                    }
                }

                if (HighlightPath != null)
                {
                    using (Pen p3 = new Pen(Color.FromArgb(250, Color.Red), 6))
                    {
                        p3.StartCap = System.Drawing.Drawing2D.LineCap.Round; //连接圆滑
                        p3.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                        p3.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                        string[] points = HighlightPath.Split(';'); //高亮部分中的点
                        for (int i = points.Length - 1; i > 0; --i)
                        {
                            first    = new LatLngPoint(double.Parse(points[i - 1].Split(',')[0]), double.Parse(points[i - 1].Split(',')[1]));
                            second   = new LatLngPoint(double.Parse(points[i].Split(',')[0]), double.Parse(points[i].Split(',')[1]));
                            s_first  = MapHelper.GetScreenLocationByLatLng(first, center, zoom, screen_size);
                            s_second = MapHelper.GetScreenLocationByLatLng(second, center, zoom, screen_size);
                            if (new Rectangle(new Point(0, 0), screen_size).Contains(s_first) || new Rectangle(new Point(0, 0), screen_size).Contains(s_second)) //在屏幕范围内
                            {
                                g.DrawLine(p3, s_first, s_second);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 55
0
        /// <summary>
        /// NS, 2013-12-02, draw circle inside polygon
        /// </summary>
        /// <param name="g"></param>
        /// <param name="pol"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        /// <param name="clip"></param>
        /// <param name="map"></param>
        /// <param name="circleline"></param>
        /// <param name="drawcircle"></param>
        /// <param name="radius"></param>
        public static void DrawPolygonWithCircle(System.Drawing.Graphics g, IPolygon pol, System.Drawing.Brush brush,
                                                 System.Drawing.Pen pen, bool clip, SharpMap.Map map, System.Drawing.Pen circleline, bool drawcircle, int radius)
        {
            try
            {
                if (pol.Shell == null)
                {
                    return;
                }
                if (pol.Shell.Coordinates.Length > 2)
                {
                    if (drawcircle)
                    {
                        System.Drawing.PointF pp = SharpMap.Utilities.Transform.WorldtoMap(pol.Centroid.Coordinate, map);
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.DrawEllipse(circleline, (pp.X - radius), (pp.Y - radius), radius * 2f, radius * 2f);
                    }

                    //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
                    System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

                    //Add the exterior polygon
                    if (!clip)
                    {
                        gp.AddPolygon(Transform.TransformToImage(pol.Shell, map));
                    }
                    //gp.AddPolygon(LimitValues(Transform.TransformToImage(pol.Shell, map), extremeValueLimit));
                    else
                    {
                        gp.AddPolygon(clipPolygon(Transform.TransformToImage(pol.Shell, map), map.Size.Width, map.Size.Height));
                    }

                    //Add the interior polygons (holes)
                    for (int i = 0; i < pol.Holes.Length; i++)
                    {
                        if (!clip)
                        {
                            gp.AddPolygon(Transform.TransformToImage(pol.Holes[i], map));
                        }
                        //gp.AddPolygon(LimitValues(Transform.TransformToImage(pol.Holes[i], map), extremeValueLimit));
                        else
                        {
                            gp.AddPolygon(clipPolygon(Transform.TransformToImage(pol.Holes[i], map), map.Size.Width, map.Size.Height));
                        }
                    }

                    // Only render inside of polygon if the brush isn't null or isn't transparent
                    if (brush != null && brush != System.Drawing.Brushes.Transparent)
                    {
                        g.FillPath(brush, gp);
                    }
                    // Create an outline if a pen style is available
                    if (pen != null)
                    {
                        g.DrawPath(pen, gp);
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                log.WarnFormat("Error during rendering", e);
            }
            catch (OverflowException e)
            {
                log.WarnFormat("Error during rendering", e);
            }
        }
Exemplo n.º 56
0
        public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect, bool enableShadows, bool useroundedCorners)
        {
            if (appointment == null)
            {
                throw new ArgumentNullException("appointment");
            }

            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            if (rect.Width == 0 || rect.Height == 0)
            {
                return;
            }

            float _ShadowDistance = 6f;

            #region " Adjust Appointment Rectangle based on the Size of the Grip Rectangle "
            rect.X     += gripRect.Width;
            rect.Width -= gripRect.Width;
            gripRect.X += gripRect.Width;
            #endregion

            #region " Gradient Colors "
            Color start = InterpolateColors(appointment.Color, Color.White, 0.4f);
            Color end   = InterpolateColors(appointment.Color, Color.FromArgb(191, 210, 234), 0.7f);
            //start = Color.FromArgb(230, start);
            //end = Color.FromArgb(180, end);
            #endregion

            GraphicsPath gp = null;
            try
            {
                #region " Create Graphics Path "
                if (useroundedCorners)
                {
                    gp = CreateRoundRectangle(rect);
                }
                else
                {
                    gp = new GraphicsPath();
                    gp.AddRectangle(rect);
                }
                #endregion

                #region " Shadows "
                if (enableShadows)
                {
                    Matrix _Matrix = new Matrix();
                    _Matrix.Translate(_ShadowDistance, _ShadowDistance);
                    gp.Transform(_Matrix);
                    using (PathGradientBrush _Brush = new PathGradientBrush(gp))
                    {
                        // set the wrapmode so that the colors will layer themselves
                        // from the outer edge in
                        _Brush.WrapMode = WrapMode.Clamp;

                        // Create a color blend to manage our colors and positions and
                        // since we need 3 colors set the default length to 3
                        ColorBlend _ColorBlend = new ColorBlend(3);

                        // here is the important part of the shadow making process, remember
                        // the clamp mode on the colorblend object layers the colors from
                        // the outside to the center so we want our transparent color first
                        // followed by the actual shadow color. Set the shadow color to a
                        // slightly transparent DimGray, I find that it works best.
                        _ColorBlend.Colors = new Color[] { Color.Transparent, Color.FromArgb(180, Color.DimGray), Color.FromArgb(180, Color.DimGray) };

                        // our color blend will control the distance of each color layer
                        // we want to set our transparent color to 0 indicating that the
                        // transparent color should be the outer most color drawn, then
                        // our Dimgray color at about 10% of the distance from the edge
                        _ColorBlend.Positions = new float[] { 0f, .1f, 1f };

                        // assign the color blend to the pathgradientbrush
                        _Brush.InterpolationColors = _ColorBlend;

                        // fill the shadow with our pathgradientbrush
                        g.FillPath(_Brush, gp);
                    }

                    // Draw shadow lines
                    //int xLeft = rect.X + 6;
                    //int xRight = rect.Right + 1;
                    //int yTop = rect.Y + 1;
                    //int yButton = rect.Bottom + 1;

                    //for (int i = 0; i < 5; i++)
                    //{
                    //    using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
                    //    {
                    //        g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
                    //        g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i); //vertical
                    //    }
                    //}

                    //Move the GraphicsPath Back to the original Location
                    _Matrix.Translate(_ShadowDistance * -2, _ShadowDistance * -2);
                    gp.Transform(_Matrix);
                }
                #endregion

                #region " Draw Background "
                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillPath(aGB, gp);
                #endregion

                #region " Selection Border "
                if (isSelected)
                {
                    using (Pen m_Pen = new Pen(appointment.BorderColor, 2))
                        g.DrawPath(m_Pen, gp);
                }
                #endregion

                #region " Appointment Grip "
                gripRect.Width += 1;

                GraphicsPath grippath = null;
                try
                {
                    if (useroundedCorners)
                    {
                        grippath = CreateGripRectangle(gripRect);
                    }
                    else
                    {
                        grippath = new GraphicsPath();
                        grippath.AddRectangle(gripRect);
                    }
                    using (SolidBrush aGB = new SolidBrush(appointment.BorderColor))
                        g.FillPath(aGB, grippath);
                }
                finally
                {
                    grippath.Dispose();
                }

                #endregion

                #region " Appointment Border
                if (appointment.DrawBorder)
                {
                    using (Pen m_Pen = new Pen(appointment.BorderColor, 1))
                        g.DrawPath(m_Pen, gp);
                }
                #endregion

                #region " Draw Recurring Icon "
                if (appointment.Recurring || appointment.Locked)
                {
                    Rectangle iconrec = rect;
                    iconrec.Width  = 16;
                    iconrec.Height = 16;

                    iconrec.X = rect.Right - 18;
                    iconrec.Y = rect.Bottom - 18;
                    Image icon = (appointment.Locked) ? Properties.CalendarResources.LockedAppointment : Properties.CalendarResources.recurring;
                    g.DrawImage(icon, iconrec);
                    icon.Dispose();
                }
                #endregion
            }
            finally
            {
                gp.Dispose();
            }

            #region " Draw Text "
            using (StringFormat format = new StringFormat())
            {
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Near;
                // draw appointment text

                rect.X += gripRect.Width;
                g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format);
                g.TextRenderingHint = TextRenderingHint.SystemDefault;
            }
            #endregion
        }
 /// <summary>
 ///   Draws the <c>Quadrilateral</c> with <c>Graphics</c> provided.
 /// </summary>
 /// <param name="graphics">
 ///   <c>Graphics</c> used to draw.
 /// </param>
 /// <param name="pen">
 ///   <c>Pen</c> used to draw outline.
 /// </param>
 /// <param name="brush">
 ///   <c>Brush</c> used to fill the inside.
 /// </param>
 public void Draw(Graphics graphics, Pen pen, Brush brush)
 {
     graphics.FillPath(brush, m_path);
     graphics.DrawPath(pen, m_path);
 }
Exemplo n.º 58
0
        public void Paint(System.Drawing.Graphics g, IPlotArea layer, Processed2DPlotData pdata)
        {
            PlotRangeList rangeList = pdata.RangeList;

            System.Drawing.PointF[] ptArray = pdata.PlotPointsInAbsoluteLayerCoordinates;

            // paint the drop style


            double xleft, xright, ytop, ybottom;

            layer.CoordinateSystem.LogicalToLayerCoordinates(new Logical3D(0, 0), out xleft, out ybottom);
            layer.CoordinateSystem.LogicalToLayerCoordinates(new Logical3D(1, 1), out xright, out ytop);
            float xe = (float)xright;
            float ye = (float)ybottom;

            GraphicsPath path = new GraphicsPath();

            double globalBaseValue;

            if (_usePhysicalBaseValue)
            {
                globalBaseValue = layer.YAxis.PhysicalVariantToNormal(_baseValue);
                if (double.IsNaN(globalBaseValue))
                {
                    globalBaseValue = 0;
                }
            }
            else
            {
                globalBaseValue = _baseValue.ToDouble();
            }


            int j = -1;

            foreach (int originalRowIndex in pdata.RangeList.OriginalRowIndices())
            {
                j++;

                double xcn = layer.XAxis.PhysicalVariantToNormal(pdata.GetXPhysical(originalRowIndex));
                double xln = xcn + _position;
                double xrn = xln + _width;

                double ycn    = layer.YAxis.PhysicalVariantToNormal(pdata.GetYPhysical(originalRowIndex));
                double ynbase = globalBaseValue;

                if (_startAtPreviousItem && pdata.PreviousItemData != null)
                {
                    double prevstart = layer.YAxis.PhysicalVariantToNormal(pdata.PreviousItemData.GetYPhysical(originalRowIndex));
                    if (!double.IsNaN(prevstart))
                    {
                        ynbase  = prevstart;
                        ynbase += Math.Sign(ynbase - globalBaseValue) * _previousItemYGap;
                    }
                }


                path.Reset();
                layer.CoordinateSystem.GetIsoline(path, new Logical3D(xln, ynbase), new Logical3D(xln, ycn));
                layer.CoordinateSystem.GetIsoline(path, new Logical3D(xln, ycn), new Logical3D(xrn, ycn));
                layer.CoordinateSystem.GetIsoline(path, new Logical3D(xrn, ycn), new Logical3D(xrn, ynbase));
                layer.CoordinateSystem.GetIsoline(path, new Logical3D(xrn, ynbase), new Logical3D(xln, ynbase));
                path.CloseFigure();

                _fillBrush.Rectangle = path.GetBounds();
                g.FillPath(_fillBrush, path);

                if (_framePen != null)
                {
                    _framePen.BrushRectangle = path.GetBounds();
                    g.DrawPath(_framePen, path);
                }
            }
        }