/// <summary>
        /// Draw this item on the given graphics.
        /// The graphics is transformed such that this item can draw starting at (0, 0).
        /// </summary>
        protected override void DrawItem(ItemPaintEventArgs e, Size sz)
        {
            var roundSize  = Math.Min(sz.Width, sz.Height) / 2;
            var offsetLeft = sz.Width / 4;

            using (var path = GraphicsUtil.CreateRoundedRectangle(new Size(sz.Width - offsetLeft, sz.Height), roundSize))
            {
                var offsetTx = new Matrix();
                offsetTx.Translate(offsetLeft, 0);
                path.Transform(offsetTx);
                using (var brush = new SolidBrush(Color.FromArgb(192, BackgroundColor)))
                {
                    e.Graphics.FillPath(brush, path);
                }
                var borderColor = BorderColor;
                using (var pen = new Pen(borderColor))
                {
                    e.Graphics.DrawPath(pen, path);
                    var m = sz.Height / 2;
                    e.Graphics.DrawLine(pen, 0, m, offsetLeft, m);
                    e.Graphics.DrawLine(pen, 0, 0, 0, sz.Height);
                }
            }
            if (Context.ShowDescriptions)
            {
                using (var brush = new SolidBrush(TextColor))
                {
                    var font   = SystemFonts.DefaultFont;
                    var text   = Text;
                    var bounds = e.Graphics.GetTextBounds(font, text, new PointF(sz.Width / 2.0F, sz.Height),
                                                          ContentAlignment.TopCenter);
                    e.Graphics.DrawString(Text, font, brush, bounds);
                }
            }
        }
 /// <summary>
 /// Draw this item on the given graphics.
 /// The graphics is transformed such that this item can draw starting at (0, 0).
 /// </summary>
 protected override void DrawItem(ItemPaintEventArgs e, Size sz)
 {
     using (var path = GraphicsUtil.CreateRoundedRectangle(sz, 1))
     {
         using (var brush = new SolidBrush(Color.FromArgb(192, BackgroundColor)))
         {
             e.Graphics.FillPath(brush, path);
         }
         using (var pen = new Pen(BorderColor))
         {
             e.Graphics.DrawPath(pen, path);
         }
     }
     if (Context.ShowDescriptions)
     {
         using (var brush = new SolidBrush(TextColor))
         {
             var font   = SystemFonts.DefaultFont;
             var text   = Text;
             var bounds = e.Graphics.GetTextBounds(font, text, new PointF(sz.Width / 2.0F, sz.Height),
                                                   ContentAlignment.TopCenter);
             e.Graphics.DrawString(Text, font, brush, bounds);
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Draw this item on the given graphics.
        /// The graphics is transformed such that this item can draw starting at (0, 0).
        /// </summary>
        protected override void DrawItem(ItemPaintEventArgs e, Size sz)
        {
            var roundSize = Math.Min(sz.Width, sz.Height) / 3;
            var reverse   = Entity.ReverseSides;

            using (var path = GraphicsUtil.CreateRoundedRectangle(sz, roundSize))
            {
                var rect       = new Rectangle(Point.Empty, sz);
                var colors     = BackgroundColors;
                var colorFront = Color.FromArgb(192, colors.Item1);
                var colorBack  = Color.FromArgb(192, colors.Item2);
                if (reverse)
                {
                    var tmp = colorBack;
                    colorBack  = colorFront;
                    colorFront = tmp;
                }
                using (var brush = new LinearGradientBrush(rect, colorBack, colorFront, 0.0f))
                {
                    e.Graphics.FillPath(brush, path);
                }
                {
                    // Draw front marker
                    var curClip = e.Graphics.Clip;
                    var w       = (Math.Min(sz.Width, sz.Height) * 0.5f);
                    e.Graphics.Clip = new Region(new RectangleF(reverse ? 0 : sz.Width - w, 0, w, sz.Height));
                    e.Graphics.FillPath(Brushes.Aqua, path);
                    e.Graphics.Clip = curClip;
                }
                e.Graphics.DrawPath(Entity.IsStation ? Pens.DarkRed : Pens.Blue, path);
            }
            // Draw "front" marker

            /*using (var path = new GraphicsPath())
             * {
             *  var radius = (Math.Min(sz.Width, sz.Height) * 0.5f);
             *  var xOffset = radius * 1.3f;
             *  var p1 = new PointF(reverse ? xOffset : sz.Width - xOffset, (sz.Height - radius)/2.0f);
             *  var p2 = new PointF(reverse ? p1.X - radius : p1.X + radius, sz.Height / 2.0f);
             *  var p3 = new PointF(p1.X, p1.Y + radius);
             *  path.AddLines(new[] { p1, p2, p3 });
             *  path.CloseFigure();
             *  e.Graphics.FillPath(Brushes.Green, path);
             *  e.Graphics.DrawPath(Pens.Yellow, path);
             * }*/
            using (var brush = new SolidBrush(TextColor))
            {
                var format = new StringFormat();
                format.LineAlignment = StringAlignment.Center;
                format.Alignment     = StringAlignment.Center;
                format.FormatFlags   = StringFormatFlags.NoWrap;
                e.Graphics.DrawString(Text, SystemFonts.DefaultFont, brush,
                                      new RectangleF(0, 0, sz.Width, sz.Height), format);
            }
        }
예제 #4
0
        /// <summary>
        /// Draw this item on the given graphics.
        /// The graphics is transformed such that this item can draw starting at (0, 0).
        /// </summary>
        protected override void DrawItem(ItemPaintEventArgs e, Size sz)
        {
            // Draw background
            var roundSize = Math.Min(sz.Width, sz.Height) / 4;

            using (var path = GraphicsUtil.CreateRoundedRectangle(sz, roundSize))
            {
                using (var brush = new SolidBrush(Color.FromArgb(192, BackgroundColor)))
                {
                    e.Graphics.FillPath(brush, path);
                }
                e.Graphics.DrawPath(Pens.Silver, path);

                // Draw text);
                if (Context.ShowDescriptions)
                {
                    using (var brush = new SolidBrush(TextColor))
                    {
                        var font   = SystemFonts.DefaultFont;
                        var text   = Text;
                        var bounds = e.Graphics.GetTextBounds(font, text, new PointF(sz.Width / 2.0F, sz.Height),
                                                              ContentAlignment.TopCenter);
                        e.Graphics.DrawString(Text, font, brush, bounds);
                    }
                }

                // Clip to rounded rectangle
                e.Graphics.SetClip(path);

                // Draw state
                if (Direction == SwitchDirection.Straight)
                {
                    using (var pen = new Pen(Color.Green, 3.0f))
                    {
                        e.Graphics.DrawLine(pen, 0, sz.Height / 2.0f, sz.Width, sz.Height / 2.0f);
                    }
                }
                else
                {
                    using (var pen = new Pen(Color.Red, 3.0f))
                    {
                        e.Graphics.DrawLine(pen, 0, 0, sz.Width, sz.Height);
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Draw this label
        /// </summary>
        /// <param name="e"></param>
        public override void Draw(ItemPaintEventArgs e)
        {
            Size          sz = this.Size;
            Graphics      g  = e.Graphics;
            SmoothingMode oldSmoothingMode = g.SmoothingMode;

            try
            {
                g.SmoothingMode = SmoothingMode.HighQuality;

                using (GraphicsPath path = GraphicsUtil.CreateRoundedRectangle(sz, 3))
                {
                    // Draw background
                    painter.DrawBackground(this, e, path);

                    if (image != null)
                    {
                        Point     pt        = new Point(1 + (sz.Width - image.Width) / 2, 1 + (sz.Height - image.Height) / 2);
                        Rectangle imgBounds = new Rectangle(pt, image.Size);
                        painter.DrawImage(this, e, imgBounds);
                    }

                    if (!string.IsNullOrEmpty(Text))
                    {
                        // Calculate rectangle
                        Rectangle rect = new Rectangle(Point.Empty, sz);
                        painter.DrawText(this, e, rect);
                    }

                    if (IsMouseOver)
                    {
                        painter.DrawMouseOver(this, e, path);
                    }
                }
            }
            finally
            {
                g.SmoothingMode = oldSmoothingMode;
            }

            base.Draw(e);
        }
예제 #6
0
        /// <summary>
        /// Create a graphics path to draw the entity shape.
        /// </summary>
        protected GraphicsPath CreateShape(Size sz)
        {
            var roundSize = Math.Min(sz.Width, sz.Height) / 2;

            switch (Entity.Shape)
            {
            case Shapes.Circle:
                return(GraphicsUtil.CreateRoundedRectangle(sz, roundSize));

            case Shapes.Diamond:
                return(GraphicsUtil.CreateDiamond(sz));

            case Shapes.Square:
                return(GraphicsUtil.CreateSquare(sz));

            case Shapes.Triangle:
                return(GraphicsUtil.CreateTriangle(sz));

            default:
                throw new ArgumentException("Unknown shape: " + (int)Entity.Shape);
            }
        }
        /// <summary>
        /// Draw the zoom control
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnPostPaint(VCItem sender, ItemPaintEventArgs e)
        {
            float[]       steps            = ZoomSteps;
            int           count            = steps.Length;
            int           current          = (count - 1) - CurrentZoomStep;
            Graphics      g                = e.Graphics;
            SmoothingMode oldSmoothingMode = g.SmoothingMode;

            try
            {
                g.SmoothingMode = SmoothingMode.HighQuality;

                Color c = containsMouse ? Color.Gray : ControlPaint.Light(Color.Gray);
                using (GraphicsPath path = GraphicsUtil.CreateRoundedRectangle(20, 10, 3))
                    using (GraphicsPath smallPath = GraphicsUtil.CreateRoundedRectangle(16, 8, 3))
                    {
                        int    x  = ZoomLayer.AvailableSize.Width - 40;
                        int    y  = 20;
                        Matrix tx = new Matrix();
                        tx.Translate(x, y);
                        path.Transform(tx);
                        tx = new Matrix();
                        tx.Translate(x + 2, y + 1);
                        smallPath.Transform(tx);

                        tx = new Matrix();
                        tx.Translate(0, 20);

                        zoomArea = new Rectangle(x, 20, 20, (steps.Length - 1) * 20 + 10);
                        using (Pen pen = new Pen(c))
                        {
                            var pt1 = new PointF((zoomArea.Left + zoomArea.Right) / 2, zoomArea.Top + 2);
                            var pt2 = new PointF(pt1.X, zoomArea.Bottom - 2);
                            g.DrawLine(pen, pt1, pt2);
                        }

                        for (int i = 0; i < count; i++)
                        {
                            if (current == i)
                            {
                                using (SolidBrush brush = new SolidBrush(c))
                                {
                                    g.FillPath(brush, path);
                                }
                            }
                            else if (containsMouse)
                            {
                                using (SolidBrush brush = new SolidBrush(ControlPaint.LightLight(c)))
                                {
                                    g.FillPath(brush, smallPath);
                                }
                                //g.DrawPath(pen, path);
                            }
                            path.Transform(tx);
                            smallPath.Transform(tx);
                        }

                        if (containsMouse)
                        {
                            var rect   = new RectangleF((zoomArea.Left + zoomArea.Right) / 2 - 20, zoomArea.Bottom + 2, 40, 20);
                            var text   = string.Format("{0}%", Math.Round((ZoomLayer.ZoomFactor * 100.0f)));
                            var format = new StringFormat();
                            format.Alignment = StringAlignment.Center;

                            using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f))
                                using (SolidBrush brush = new SolidBrush(c))
                                {
                                    g.DrawString(text, font, brush, rect, format);
                                }
                        }
                    }
            }
            finally
            {
                g.SmoothingMode = oldSmoothingMode;
            }
            base.OnPostPaint(sender, e);
        }