/// <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);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Draw this label
        /// </summary>
        /// <param name="e"></param>
        public override void Draw(ItemPaintEventArgs e)
        {
            Graphics      g = e.Graphics;
            SmoothingMode oldSmoothingMode = g.SmoothingMode;

            try
            {
                g.SmoothingMode = SmoothingMode.HighQuality;

                // Calculate formatting
                StringFormat format = new StringFormat();
                format.Alignment     = Alignment;
                format.LineAlignment = LineAlignment;

                // Calculate rectangle
                RectangleF rect = new RectangleF(PointF.Empty, Size);

                // Draw text
                using (Brush brush = new SolidBrush(TextColor))
                {
                    g.DrawString(Text, TextFont, brush, rect, format);
                }
            }
            finally
            {
                g.SmoothingMode = oldSmoothingMode;
            }
            base.Draw(e);
        }
        /// <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);
                }
            }
        }
        private void PaintColumnExtender(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
        {
            var bounds = paintEventArgs.Bounds;

            if (column.Extender != null && bounds.Width > CustomListBoxColumn.ExtenderButtonWidth)
            {
                var graphics = paintEventArgs.Graphics;
                using (var brush = new SolidBrush(ColorTable.Background))
                {
                    graphics.FillRectangle(brush,
                                           bounds.Right - CustomListBoxColumn.ExtenderButtonWidth - 0.5f, bounds.Y,
                                           1, bounds.Height);
                }
                var foregroundColor = paintEventArgs.HoveredPart == ColumnHitTestResults.Extender ?
                                      ColorTable.HoverExtenderForeground : ColorTable.ExtenderForeground;
                using (var brush = new SolidBrush(foregroundColor))
                {
                    const int ArrowSize = 4;
                    var       p1        = new Point(
                        bounds.Right - CustomListBoxColumn.ExtenderButtonWidth + CustomListBoxColumn.ExtenderButtonWidth / 2,
                        bounds.Y + bounds.Height - (bounds.Height - ArrowSize) / 2);
                    var p2 = new Point(p1.X + ArrowSize, p1.Y - ArrowSize);
                    var p3 = new Point(p1.X - ArrowSize + 1, p1.Y - ArrowSize);
                    _triangle[0] = p1;
                    _triangle[1] = p2;
                    _triangle[2] = p3;
                    graphics.FillPolygon(brush, _triangle);
                }
            }
        }
        /// <summary>
        /// Draw resize handles on the given placement
        /// </summary>
        /// <param name="e"></param>
        /// <param name="placement"></param>
        private void DrawResizeHandles(ItemPaintEventArgs e, VCItemPlacement placement)
        {
            if ((placement == activePlacement) && CanResize(placement))
            {
                Graphics g = e.Graphics;
                handleSize = (int)(DEFAULT_HANDLE_SIZE / e.ZoomFactor);
                int  d  = -handleSize / 2;
                int  s  = handleSize;
                Size sz = placement.Item.Size;

                Brush brush = Brushes.Red;

                // Top-left
                g.FillRectangle(brush, d, d, s, s);
                // Top-right
                g.FillRectangle(brush, sz.Width + d, d, s, s);
                // Bottom-left
                g.FillRectangle(brush, d, sz.Height + d, s, s);
                // Bottom-right
                g.FillRectangle(brush, sz.Width + d, sz.Height + d, s, s);

                // Top-center
                g.FillRectangle(brush, (sz.Width / 2) + d, d, s, s);
                // Bottom-center
                g.FillRectangle(brush, (sz.Width / 2) + d, sz.Height + d, s, s);
                // Left-middle
                g.FillRectangle(brush, d, (sz.Height / 2) + d, s, s);
                // Right-middle
                g.FillRectangle(brush, sz.Width + d, (sz.Height / 2) + d, s, s);
            }
        }
Esempio n. 6
0
 void OnIconPaint(object sender, ItemPaintEventArgs e)
 {
     if (content.Image != null)
     {
         e.Graphics.DrawImageUnscaled(content.Image, e.ClipRectangle);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Draw this item and all child items
        /// </summary>
        public override void Draw(ItemPaintEventArgs e)
        {
            base.Draw(e);

            // Draw module connections
            if (railway.ModuleConnections.Count > 0)
            {
                var oldMode = e.Graphics.SmoothingMode;
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                using (var pen = new Pen(Color.DarkBlue, 2))
                {
                    foreach (var connection in railway.ModuleConnections)
                    {
                        var edgeA = GetModuleItem(connection.EdgeA);
                        var edgeB = GetModuleItem(connection.EdgeB);

                        if ((edgeA == null) || (edgeB == null))
                        {
                            continue;
                        }

                        // Find position of edges center in my coordinate space
                        var ptA = Control2Local(edgeA.Local2Control(Center(connection.EdgeA)));
                        var ptB = Control2Local(edgeB.Local2Control(Center(connection.EdgeB)));

                        e.Graphics.DrawLine(pen, ptA, ptB);
                    }
                }
                e.Graphics.SmoothingMode = oldMode;
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Mouse handlers can draw over an already drawn item.
 /// </summary>
 /// <param name="e"></param>
 public virtual void OnPostPaint(VCItem sender, ItemPaintEventArgs e)
 {
     if (next != null)
     {
         next.OnPostPaint(sender, e);
     }
 }
Esempio n. 9
0
            /// <summary>
            /// Draw the image of the button
            /// </summary>
            /// <param name="e"></param>
            /// <param name="bounds"></param>
            public virtual void DrawImage(VCButtonItem button, ItemPaintEventArgs e, Rectangle imgBounds)
            {
                Image image = button.Image;

                if (button.Enabled)
                {
                    e.Graphics.DrawImage(image, imgBounds);
                }
                else
                {
                    float[][] array = new float[5][];
                    array[0] = new float[5] {
                        0.2125f, 0.2125f, 0.2125f, 0, 0
                    };
                    array[1] = new float[5] {
                        0.5f, 0.5f, 0.5f, 0, 0
                    };
                    array[2] = new float[5] {
                        0.0361f, 0.0361f, 0.0361f, 0, 0
                    };
                    array[3] = new float[5] {
                        0, 0, 0, 1, 0
                    };
                    array[4] = new float[5] {
                        0.2f, 0.2f, 0.2f, 0, 1
                    };
                    ColorMatrix     grayMatrix = new ColorMatrix(array);
                    ImageAttributes att        = new ImageAttributes();
                    att.SetColorMatrix(grayMatrix);
                    e.Graphics.DrawImage(image, imgBounds, 0, 0, imgBounds.Width, imgBounds.Height, GraphicsUnit.Pixel, att);
                }
            }
Esempio n. 10
0
        public override void OnPaintColumnContent(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
        {
            var graphics = paintEventArgs.Graphics;
            var rect = paintEventArgs.Bounds;
            var font = column.HeaderFont;

            ItemPaintEventArgs.PrepareContentRectangle(ref rect);
            paintEventArgs.PrepareTextRectangle(font, font, ref rect);
            if(column.Extender != null && ((paintEventArgs.State & (ItemState.Hovered | ItemState.Pressed)) != ItemState.None))
            {
                rect.Width -= CustomListBoxColumn.ExtenderButtonWidth;
                if(rect.Width <= 0) return;
            }
            StringFormat format;
            switch(column.HeaderAlignment)
            {
                case StringAlignment.Near:
                    format = GitterApplication.TextRenderer.LeftAlign;
                    break;
                case StringAlignment.Far:
                    format = GitterApplication.TextRenderer.RightAlign;
                    break;
                case StringAlignment.Center:
                    format = GitterApplication.TextRenderer.CenterAlign;
                    break;
                default:
                    format = GitterApplication.TextRenderer.LeftAlign;
                    break;
            }
            GitterApplication.TextRenderer.DrawText(graphics, column.Name, font, column.HeaderBrush, rect, format);
        }
Esempio n. 11
0
 /// <summary>
 /// Draw moving boxes
 /// </summary>
 public override void OnPostPaint(VCItem sender, ItemPaintEventArgs e)
 {
     if ((movingPlacements != null) && (!moveContents))
     {
         container.DrawContainer(e, DrawMovingBoxes);
     }
     base.OnPostPaint(sender, e);
 }
Esempio n. 12
0
        /// <summary>
        /// Draw the current time in the clock
        /// </summary>
        protected virtual void DrawTime(ItemPaintEventArgs e, Size sz)
        {
            var g          = e.Graphics;
            var halfWidth  = sz.Width / 2.0f;
            var halfHeight = sz.Height / 2.0f;

            g.DrawLine(Pens.Black, halfWidth, sz.Height / 8.0f, halfWidth, halfHeight);
            g.DrawLine(Pens.Black, halfWidth, halfHeight, halfWidth + sz.Width / 4.0f, halfHeight);
        }
Esempio n. 13
0
        /// <summary>
        /// Draw this label
        /// </summary>
        /// <param name="e"></param>
        public override void Draw(ItemPaintEventArgs e)
        {
            if (image != null)
            {
                Rectangle imgBounds = new Rectangle(Point.Empty, image.Size);
                e.Graphics.DrawImage(image, imgBounds);
            }

            base.Draw(e);
        }
Esempio n. 14
0
 /// <summary>
 /// Draw the background of the button
 /// </summary>
 /// <param name="e"></param>
 /// <param name="bounds"></param>
 public virtual void DrawBackground(VCButtonItem button, ItemPaintEventArgs e, GraphicsPath bounds)
 {
     if (button.IsMouseDown)
     {
         using (Brush brush = new SolidBrush(Color.Yellow))
         {
             e.Graphics.FillPath(brush, bounds);
         }
     }
 }
Esempio n. 15
0
 /// <summary>
 /// Mouse handlers can draw over an already drawn item.
 /// </summary>
 public override void OnPostPaint(VCItem sender, ItemPaintEventArgs e)
 {
     if (mouseIsOver)
     {
         var sz     = edgeItem.Size;
         var bounds = new Rectangle(sz.Width / -2, sz.Height / -2, sz.Width * 2, sz.Height * 2);
         e.Graphics.FillRectangle(Brushes.Red, bounds);
     }
     base.OnPostPaint(sender, e);
 }
Esempio n. 16
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);
            }
        }
Esempio n. 17
0
 private void drawLocDirectionMarker(ItemPaintEventArgs e, Size sz, bool reverse, ILocState loc)
 {
     using (var path = new GraphicsPath())
     {
         var radius  = (Math.Min(sz.Width, sz.Height) * 1.0f);
         var xOffset = 0.0f;// radius * 0.5f;
         var p1      = new PointF(reverse ? -xOffset : sz.Width + xOffset, sz.Height / 2.0f);
         var brush   = loc.PossibleDeadlock.Actual ? Brushes.Orange : Brushes.White;
         e.Graphics.FillEllipse(brush, new RectangleF(new PointF(p1.X - (radius / 4.0f), p1.Y - (radius / 4.0f)), new SizeF(radius / 2.0f, radius / 2.0f)));
     }
 }
        private static void RenderColumnNormalBackground(ItemPaintEventArgs paintEventArgs)
        {
            var graphics = paintEventArgs.Graphics;
            var bounds   = paintEventArgs.Bounds;
            var c1       = Color.FromArgb(63, 63, 70);

            using (var pen = new Pen(c1))
            {
                graphics.DrawLine(pen, bounds.Right - 1, 0, bounds.Right - 1, bounds.Bottom - 1);
                graphics.DrawLine(pen, bounds.X, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
            }
        }
Esempio n. 19
0
 public override void OnPostPaint(VCItem sender, ItemPaintEventArgs e)
 {
     base.OnPostPaint(sender, e);
     if (canAccept)
     {
         using (Pen pen = new Pen(Color.Black))
         {
             pen.DashStyle = DashStyle.Dot;
             e.Graphics.DrawRectangle(pen, new Rectangle(Point.Empty, sender.Size));
         }
     }
 }
Esempio n. 20
0
        /// <summary>
        /// Draw boxes on the new location of the moving placements.
        /// </summary>
        /// <param name="e"></param>
        private void DrawMovingBoxes(ItemPaintEventArgs e)
        {
            using (var pen = new Pen(Color.Black, 2.0f / e.ZoomFactor))
            {
                pen.DashStyle = DashStyle.Dot;
                var g = e.Graphics;

                foreach (var mPlacement in movingPlacements)
                {
                    g.DrawRectangle(pen, mPlacement.GetNewBounds(this));
                }
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Draw this item
 /// </summary>
 /// <param name="e"></param>
 public override void Draw(ItemPaintEventArgs e)
 {
     if (IsMouseOver)
     {
         using (drawFont = new Font(this.Font, FontStyle.Underline))
         {
             base.Draw(e);
         }
     }
     else
     {
         drawFont = this.Font;
         base.Draw(e);
     }
 }
Esempio n. 22
0
 public override void OnPaintColumnBackground(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
 {
     switch(paintEventArgs.State)
     {
         case ItemState.None:
             RenderColumnNormalBackground(paintEventArgs);
             break;
         case ItemState.Pressed:
             RenderColumnPressedBackground(column, paintEventArgs);
             break;
         default:
             RenderColumnHoverBackground(column, paintEventArgs);
             break;
     }
 }
Esempio n. 23
0
            /// <summary>
            /// Draw the text of the button
            /// </summary>
            /// <param name="e"></param>
            /// <param name="bounds"></param>
            public virtual void DrawText(VCButtonItem button, ItemPaintEventArgs e, Rectangle textBounds)
            {
                // Calculate formatting
                StringFormat format = new StringFormat();

                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;

                // Draw text
                Color c = button.Enabled ? button.TextColor : ControlPaint.Light(button.TextColor);

                using (Brush brush = new SolidBrush(c))
                {
                    e.Graphics.DrawString(button.Text, button.Font, brush, textBounds, format);
                }
            }
Esempio n. 24
0
        /// <summary>
        /// Draw this item.
        /// Setup orientation and call DrawItem
        /// </summary>
        public sealed override void Draw(ItemPaintEventArgs e)
        {
            var w     = Entity.Width;
            var h     = Entity.Height;
            var state = e.Graphics.Save();

            try
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                base.Draw(e);
                DrawItem(e, new Size(w, h));
            }
            finally
            {
                e.Graphics.Restore(state);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Draw selection
        /// </summary>
        /// <param name="e"></param>
        public override void OnPostPaint(VCItem sender, ItemPaintEventArgs e)
        {
            if (IsSelecting)
            {
                var rect = SelectionBounds;
                if (!rect.IsEmpty)
                {
                    using (Pen pen = new Pen(Color.Black))
                    {
                        pen.DashStyle = DashStyle.Dot;
                        e.Graphics.DrawRectangle(pen, SelectionBounds.Round());
                    }
                }
            }

            base.OnPostPaint(sender, e);
        }
Esempio n. 26
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);
                    }
                }
            }
        }
        public override void OnPaintColumnBackground(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
        {
            switch (paintEventArgs.State)
            {
            case ItemState.None:
                RenderColumnNormalBackground(paintEventArgs);
                break;

            case ItemState.Pressed:
                RenderColumnPressedBackground(column, paintEventArgs);
                break;

            default:
                RenderColumnHoverBackground(column, paintEventArgs);
                break;
            }
        }
Esempio n. 28
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);
        }
Esempio n. 29
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.CreateCircle(Math.Min(sz.Width, sz.Height)))
            {
                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
                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(Position.ToString(), SystemFonts.DefaultFont, brush,
                                          new RectangleF(0, 0, sz.Width, sz.Height), format);
                }
            }
        }
        private void RenderColumnHoverBackground(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
        {
            var graphics = paintEventArgs.Graphics;
            var bounds   = paintEventArgs.Bounds;
            var c1       = Color.FromArgb(63, 63, 70);
            var c2       = Color.FromArgb(62, 62, 64);

            using (var pen = new Pen(c1))
            {
                graphics.DrawLine(pen, bounds.Right - 1, 0, bounds.Right - 1, bounds.Bottom - 1);
                graphics.DrawLine(pen, bounds.X, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
            }
            using (var brush = new SolidBrush(c2))
            {
                var rc = bounds;
                rc.Width  -= 1;
                rc.Height -= 1;
                graphics.FillRectangle(brush, rc);
            }
            PaintColumnExtender(column, paintEventArgs);
        }
Esempio n. 31
0
        public override void Draw(ItemPaintEventArgs e)
        {
            var rect = new Rectangle(Point.Empty, Size);

            if (!contentsEditable)
            {
                e.Graphics.DrawRectangle(Pens.Gray, rect);
            }
            base.Draw(e);
            if (railwayEditable)
            {
                using (var brush = new SolidBrush(Color.FromArgb(128, Color.White)))
                {
                    e.Graphics.FillRectangle(brush, rect);
                }
                var format = new StringFormat();
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                e.Graphics.DrawString(Entity.Description, new Font(FontFamily.GenericSansSerif, 20), SystemBrushes.ControlText, rect, format);
            }
        }
Esempio n. 32
0
        /// <summary>
        /// Draw this block
        /// </summary>
        protected override void DrawItem(ItemPaintEventArgs e, Size sz)
        {
            base.DrawItem(e, sz);

            var blockState = state.State;
            var loc        = state.LockedBy;
            var reverse    = Entity.ReverseSides;

            switch (blockState)
            {
            case BlockState.Occupied:
                if ((loc != null) && (loc.CurrentBlock.Actual == state))
                {
                    if (loc.CurrentBlockEnterSide.Actual == BlockSide.Front)
                    {
                        // If loc entered block at front, we go towards back.
                        reverse = !reverse;
                    }
                    // Draw "loc direction" marker
                    drawLocDirectionMarker(e, sz, reverse, loc);
                }
                break;

            case BlockState.Entering:
            case BlockState.Destination:
                if ((loc != null) && (loc.CurrentRoute.Actual != null))
                {
                    if (loc.CurrentRoute.Actual.Route.ToBlockSide == BlockSide.Front)
                    {
                        // If loc will block at front, we go towards back.
                        reverse = !reverse;
                    }
                    // Draw "loc direction" marker
                    drawLocDirectionMarker(e, sz, reverse, loc);
                }
                break;
            }
        }
Esempio n. 33
0
        public override void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs)
        {
            var state = paintEventArgs.State;

            if(state == ItemState.None) return;

            bool hovered = (state & ItemState.Hovered) == ItemState.Hovered;
            bool selected = (state & ItemState.Selected) == ItemState.Selected;
            bool focused = (state & ItemState.Focused) == ItemState.Focused;
            IBackgroundStyle background = null;
            if(selected)
            {
                if(paintEventArgs.IsHostControlFocused)
                {
                    if(hovered)
                    {
                        background = BackgroundStyle.SelectedFocused;
                    }
                    else if(focused)
                    {
                        background = BackgroundStyle.SelectedFocused;
                    }
                    else
                    {
                        background = BackgroundStyle.Selected;
                    }
                }
                else
                {
                    if(hovered)
                    {
                        background = BackgroundStyle.SelectedFocused;
                    }
                    else
                    {
                        background = BackgroundStyle.SelectedNoFocus;
                    }
                }
            }
            else
            {
                if(hovered)
                {
                    if(focused && paintEventArgs.IsHostControlFocused)
                    {
                        background = BackgroundStyle.HoveredFocused;
                    }
                    else
                    {
                        background = BackgroundStyle.Hovered;
                    }
                }
                else if(focused)
                {
                    if(paintEventArgs.IsHostControlFocused)
                    {
                        background = BackgroundStyle.Focused;
                    }
                }
            }
            if(background != null)
            {
                background.Draw(paintEventArgs.Graphics, paintEventArgs.Bounds);
            }
        }
Esempio n. 34
0
 private static void RenderColumnHoverBackground(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
 {
     var graphics = paintEventArgs.Graphics;
     var rect = paintEventArgs.Bounds;
     var c1 = Color.FromArgb(227, 232, 238);
     var c2 = Color.FromArgb(241, 245, 251);
     using(var p = new Pen(c1))
     {
         var rc = rect;
         rc.Y -= 1;
         rc.Width -= 1;
         graphics.DrawRectangle(p, rc);
     }
     using(var b = new SolidBrush(c2))
     {
         var rc = rect;
         rc.X += 2;
         rc.Y += 1;
         rc.Width -= 4;
         rc.Height -= 3;
         graphics.FillRectangle(b, rc);
     }
     if(column.Extender != null)
     {
         if(rect.Width > CustomListBoxColumn.ExtenderButtonWidth)
         {
             if(paintEventArgs.HoveredPart == ColumnHitTestResults.Extender)
             {
                 graphics.FillRectangle(ExtenderHoveredBrush,
                     rect.Right - CustomListBoxColumn.ExtenderButtonWidth + 1.5f, rect.Y + 1.5f,
                     CustomListBoxColumn.ExtenderButtonWidth - 4, rect.Height - 4);
                 graphics.DrawRectangle(ExtenderBorderPenHovered,
                     rect.Right - CustomListBoxColumn.ExtenderButtonWidth, 0,
                     CustomListBoxColumn.ExtenderButtonWidth - 1, rect.Height - 1);
             }
             else
             {
                 graphics.FillRectangle(ExtenderBorderBrush,
                     rect.Right - CustomListBoxColumn.ExtenderButtonWidth - 0.5f, rect.Y,
                     1, rect.Height);
             }
             graphics.DrawImage(ImgColumnExtender,
                 rect.Right - CustomListBoxColumn.ExtenderButtonWidth + 4, rect.Y + 9,
                 7, 4);
         }
     }
 }
Esempio n. 35
0
 private static void RenderColumnNormalBackground(ItemPaintEventArgs paintEventArgs)
 {
     var graphics = paintEventArgs.Graphics;
     var rect = paintEventArgs.Bounds;
     var c1 = Color.FromArgb(223, 234, 247);
     var c2 = Color.FromArgb(255, 255, 255);
     var rc = new Rectangle(rect.Right - 1, 0, 1, rect.Height);
     using(var brush = new LinearGradientBrush(
         rc, c1, c2, LinearGradientMode.Vertical))
     {
         graphics.FillRectangle(brush, rc);
     }
 }
Esempio n. 36
0
 private static void RenderColumnPressedBackground(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
 {
     var graphics = paintEventArgs.Graphics;
     var rect = paintEventArgs.Bounds;
     var c1 = Color.FromArgb(192, 203, 217);
     var c2 = Color.FromArgb(246, 247, 248);
     var c3 = Color.FromArgb(193, 204, 218);
     var c4 = Color.FromArgb(215, 222, 231);
     var c5 = Color.FromArgb(235, 238, 242);
     using(var p = new Pen(c1))
     {
         var rc = rect;
         rc.Y -= 1;
         rc.X += 1;
         rc.Width -= 2;
         graphics.DrawRectangle(p, rc);
     }
     using(var b = new SolidBrush(c2))
     {
         var rc = rect;
         rc.Y += 3;
         rc.X += 2;
         rc.Width -= 4;
         rc.Height -= 4;
         graphics.FillRectangle(b, rc);
     }
     using(var p = new Pen(c3))
     {
         var rc = rect;
         graphics.DrawLine(p, rc.X + 1, rc.Y + 0, rc.Right - 2, rc.Y + 0);
     }
     using(var p = new Pen(c4))
     {
         var rc = rect;
         graphics.DrawLine(p, rc.X + 1, rc.Y + 1, rc.Right - 2, rc.Y + 1);
     }
     using(var p = new Pen(c5))
     {
         var rc = rect;
         graphics.DrawLine(p, rc.X + 1, rc.Y + 2, rc.Right - 2, rc.Y + 2);
     }
     if(column.Extender != null)
     {
         if(rect.Width > CustomListBoxColumn.ExtenderButtonWidth)
         {
             graphics.FillRectangle(ExtenderBorderBrush, rect.Right - CustomListBoxColumn.ExtenderButtonWidth - 0.5f, rect.Y, 1, rect.Height - 1);
             graphics.DrawImage(ImgColumnExtender, rect.Right - CustomListBoxColumn.ExtenderButtonWidth + 4, rect.Y + 9, 7, 4);
         }
     }
 }
Esempio n. 37
0
        public override void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs)
        {
            var state = paintEventArgs.State;

            if(state == ItemState.None) return;

            bool isHovered	= (state & ItemState.Hovered) == ItemState.Hovered;
            bool isSelected	= (state & ItemState.Selected) == ItemState.Selected;
            bool isFocused	= (state & ItemState.Focused) == ItemState.Focused;
            Brush brush = null;
            Pen pen = null;
            if(isSelected)
            {
                if(paintEventArgs.IsHostControlFocused)
                {
                    if(isHovered)
                    {
                        brush = new SolidBrush(ColorTable.SelectionBackground);
                    }
                    else if(isFocused)
                    {
                        brush = new SolidBrush(ColorTable.SelectionBackground);
                    }
                    else
                    {
                        brush = new SolidBrush(ColorTable.SelectionBackground);
                    }
                }
                else
                {
                    if(isHovered)
                    {
                        brush = new SolidBrush(ColorTable.SelectionBackgroundNoFocus);
                    }
                    else
                    {
                        brush = new SolidBrush(ColorTable.SelectionBackgroundNoFocus);
                    }
                }
            }
            else
            {
                if(isHovered)
                {
                    if(isFocused && paintEventArgs.IsHostControlFocused)
                    {
                        brush = new SolidBrush(ColorTable.HoverBackground);
                        pen = new Pen(ColorTable.FocusBorder);
                    }
                    else
                    {
                        brush = new SolidBrush(ColorTable.HoverBackground);
                    }
                }
                else if(isFocused)
                {
                    if(paintEventArgs.IsHostControlFocused)
                    {
                        pen = new Pen(ColorTable.FocusBorder);
                    }
                }
            }
            if(brush != null)
            {
                var itemBounds = Rectangle.Intersect(paintEventArgs.ClipRectangle, paintEventArgs.Bounds);
                if(itemBounds.Width > 0 && itemBounds.Height > 0)
                {
                    paintEventArgs.Graphics.FillRectangle(brush, itemBounds);
                }
                brush.Dispose();
            }
            if(pen != null)
            {
                var rect = paintEventArgs.Bounds;
                rect.Width -= 1;
                rect.Height -= 1;
                paintEventArgs.Graphics.DrawRectangle(pen, rect);
                pen.Dispose();
            }
        }
Esempio n. 38
0
 public abstract void OnPaintItemBackground(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs);
Esempio n. 39
0
 /// <summary>Paints item background.</summary>
 /// <param name="paintEventArgs">Painting options.</param>
 protected override void OnPaintBackground(ItemPaintEventArgs paintEventArgs)
 {
     ListBox.Renderer.OnPaintItemBackground(this, paintEventArgs);
 }
Esempio n. 40
0
 protected override void OnPaintContent(ItemPaintEventArgs paintEventArgs)
 {
 }
Esempio n. 41
0
 private void PaintColumnExtender(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
 {
     var bounds = paintEventArgs.Bounds;
     if(column.Extender != null && bounds.Width > CustomListBoxColumn.ExtenderButtonWidth)
     {
         var graphics = paintEventArgs.Graphics;
         using(var brush = new SolidBrush(ColorTable.Background))
         {
             graphics.FillRectangle(brush,
                 bounds.Right - CustomListBoxColumn.ExtenderButtonWidth - 0.5f, bounds.Y,
                 1, bounds.Height);
         }
         var foregroundColor = paintEventArgs.HoveredPart == ColumnHitTestResults.Extender ?
             ColorTable.HoverExtenderForeground : ColorTable.ExtenderForeground;
         using(var brush = new SolidBrush(foregroundColor))
         {
             const int ArrowSize = 4;
             var p1 = new Point(
                 bounds.Right - CustomListBoxColumn.ExtenderButtonWidth + CustomListBoxColumn.ExtenderButtonWidth / 2,
                 bounds.Y + bounds.Height - (bounds.Height - ArrowSize) / 2);
             var p2 = new Point(p1.X + ArrowSize, p1.Y - ArrowSize);
             var p3 = new Point(p1.X - ArrowSize + 1, p1.Y - ArrowSize);
             _triangle[0] = p1;
             _triangle[1] = p2;
             _triangle[2] = p3;
             graphics.FillPolygon(brush, _triangle);
         }
     }
 }
Esempio n. 42
0
 private void RenderColumnPressedBackground(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs)
 {
     var graphics = paintEventArgs.Graphics;
     var bounds = paintEventArgs.Bounds;
     var c1 = Color.FromArgb(63, 63, 70);
     var c2 = Color.FromArgb(0, 122, 204);
     using(var pen = new Pen(c1))
     {
         graphics.DrawLine(pen, bounds.Right - 1, 0, bounds.Right - 1, bounds.Bottom - 1);
         graphics.DrawLine(pen, bounds.X, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
     }
     using(var brush = new SolidBrush(c2))
     {
         var rc = bounds;
         rc.Width -= 1;
         rc.Height -= 1;
         graphics.FillRectangle(brush, rc);
     }
     PaintColumnExtender(column, paintEventArgs);
 }
Esempio n. 43
0
 public abstract void OnPaintColumnBackground(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs);
Esempio n. 44
0
 public abstract void OnPaintItemContent(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs);
Esempio n. 45
0
 /// <summary>Paint item content.</summary>
 /// <param name="paintEventArgs">Painting options.</param>
 protected override void OnPaintContent(ItemPaintEventArgs paintEventArgs)
 {
     ListBox.Renderer.OnPaintItemContent(this, paintEventArgs);
 }
Esempio n. 46
0
 public abstract void OnPaintColumnContent(CustomListBoxColumn column, ItemPaintEventArgs paintEventArgs);
Esempio n. 47
0
        public override void OnPaintItemContent(CustomListBoxItem item, ItemPaintEventArgs paintEventArgs)
        {
            var graphics = paintEventArgs.Graphics;
            var rect = paintEventArgs.Bounds;

            #region clip invisible subitems

            var clip = paintEventArgs.ClipRectangle;
            var clipX1 = clip.X;
            var clipX2 = clip.Right;
            var columns = item.ListBox.Columns;
            int columnsCount = columns.Count;
            int x = rect.X;

            int firstColumnId;
            int startColumnId;
            int endColumnId;
            int startX;

            if(clipX1 <= rect.X && clipX2 >= rect.Right)
            {
                // all subitems should be painted
                startColumnId = 0;
                firstColumnId = 0;
                endColumnId = columnsCount - 1;
                startX = x;
            }
            else
            {
                firstColumnId = -1;
                startColumnId = -1;
                endColumnId = -1;
                startX = -1;
                // skip clipped subitems
                int prev = -1;
                for(int i = 0; i < columnsCount; ++i)
                {
                    var column = columns[i];
                    if(column.IsVisible)
                    {
                        if(firstColumnId == -1)
                        {
                            firstColumnId = i;
                        }

                        int x2 = x + column.Width;

                        if(startColumnId == -1 && x2 > clipX1)
                        {
                            if(prev != -1 && columns[prev].ExtendsToRight)
                            {
                                startColumnId = prev;
                                startX = x - columns[prev].Width;
                            }
                            else
                            {
                                startColumnId = i;
                                startX = x;
                            }
                        }

                        if(startColumnId != -1 && endColumnId == -1 && x2 >= clipX2)
                        {
                            endColumnId = i++;
                            for(; i < columnsCount; ++i)
                            {
                                if(columns[i].IsVisible)
                                {
                                    if(columns[i].ExtendsToLeft)
                                    {
                                        endColumnId = i;
                                    }
                                    break;
                                }
                            }
                            break;
                        }

                        x = x2;
                        prev = i;
                    }
                }
                // no visible columns found
                if(startColumnId == -1) return;
                if(endColumnId == -1) endColumnId = prev;
            }

            #endregion

            x = startX;
            bool first = startColumnId == firstColumnId;
            var subrect = new Rectangle(0, rect.Y, 0, rect.Height);

            int hoveredPart = paintEventArgs.HoveredPart;

            for(int i = startColumnId; i <= endColumnId; ++i)
            {
                var column = columns[i];
                if(column.IsVisible)
                {
                    int columnWidth = column.Width;

                    if(first)
                    {
                        first = false;
                        var level = item.Level;
                        var listBox = item.ListBox;
                        int offset = level * ListBoxConstants.LevelMargin + ListBoxConstants.RootMargin;
                        int w2 = columnWidth - offset;

                        #region paint plus/minus

                        if(listBox.ShowTreeLines)
                        {
                            if(!listBox.ShowRootTreeLines)
                            {
                                if(level != 0)
                                {
                                    offset -= ListBoxConstants.LevelMargin;
                                    w2 += ListBoxConstants.LevelMargin;
                                }
                            }
                            if(level != 0 || listBox.ShowRootTreeLines)
                            {
                                if(w2 > ListBoxConstants.SpaceBeforePlusMinus && item.Items.Count != 0)
                                {
                                    RenderPlusMinus(
                                        graphics,
                                        x + offset, subrect.Y + (subrect.Height - ListBoxConstants.PlusMinusImageWidth) / 2,
                                        item.IsExpanded,
                                        (paintEventArgs.State & ItemState.Selected) == ItemState.Selected,
                                        hoveredPart == ItemHitTestResults.PlusMinus,
                                        paintEventArgs.IsHostControlFocused);
                                }
                                offset += ListBoxConstants.PlusMinusAreaWidth;
                                w2 -= ListBoxConstants.PlusMinusAreaWidth;
                            }
                        }

                        #endregion

                        #region paint checkbox

                        if(listBox.ShowCheckBoxes && item.CheckedState != CheckedState.Unavailable)
                        {
                            Bitmap checkedStateImage = null;
                            if(hoveredPart == ItemHitTestResults.CheckBox)
                            {
                                ImgCheckedStateHovered.TryGetValue(item.CheckedState, out checkedStateImage);
                            }
                            else
                            {
                                ImgCheckedState.TryGetValue(item.CheckedState, out checkedStateImage);
                            }
                            if(checkedStateImage != null && w2 > ListBoxConstants.SpaceBeforeCheckbox)
                            {
                                Rectangle destRect, srcRect;
                                if(w2 < ListBoxConstants.CheckboxImageWidth + ListBoxConstants.SpaceBeforeCheckbox)
                                {
                                    destRect = new Rectangle(
                                        x + offset + ListBoxConstants.SpaceBeforeCheckbox,
                                        rect.Y + (rect.Height - ListBoxConstants.CheckboxImageWidth) / 2,
                                        w2 - ListBoxConstants.SpaceBeforeCheckbox,
                                        ListBoxConstants.CheckboxImageWidth);
                                    srcRect = new Rectangle(
                                        0, 0,
                                        w2 - ListBoxConstants.SpaceBeforeCheckbox,
                                        ListBoxConstants.CheckboxImageWidth);
                                }
                                else
                                {
                                    destRect = new Rectangle(
                                        x + offset + ListBoxConstants.SpaceBeforeCheckbox,
                                        rect.Y + (rect.Height - ListBoxConstants.CheckboxImageWidth) / 2,
                                        ListBoxConstants.CheckboxImageWidth,
                                        ListBoxConstants.CheckboxImageWidth);
                                    srcRect = new Rectangle(
                                        0, 0,
                                        ListBoxConstants.CheckboxImageWidth,
                                        ListBoxConstants.CheckboxImageWidth);
                                }
                                graphics.DrawImage(checkedStateImage, destRect, srcRect, GraphicsUnit.Pixel);
                            }
                            offset += ListBoxConstants.CheckBoxAreaWidth;
                            w2 -= ListBoxConstants.CheckBoxAreaWidth;
                        }

                        #endregion

                        subrect.X = x + offset;
                        subrect.Width = w2;
                        x += columnWidth;
                        if(w2 <= 0) continue;
                    }
                    else
                    {
                        subrect.X = x;
                        subrect.Width = columnWidth;
                        x += columnWidth;
                    }

                    item.PaintSubItem(new SubItemPaintEventArgs(paintEventArgs.Graphics, clip, subrect, paintEventArgs.Index,
                        paintEventArgs.State, hoveredPart, paintEventArgs.IsHostControlFocused, i, column));
                }
            }
        }
Esempio n. 48
0
 private static void RenderColumnNormalBackground(ItemPaintEventArgs paintEventArgs)
 {
     var graphics = paintEventArgs.Graphics;
     var bounds = paintEventArgs.Bounds;
     var c1 = Color.FromArgb(63, 63, 70);
     using(var pen = new Pen(c1))
     {
         graphics.DrawLine(pen, bounds.Right - 1, 0, bounds.Right - 1, bounds.Bottom - 1);
         graphics.DrawLine(pen, bounds.X, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
     }
 }