protected override void OnPaint(PaintEventArgs pevent)
        {
            Brush bg;

            if (Checked)
            {
                bg = new SolidBrush(ColorManager.ui_hoveredLight);
            }
            else
            {
                bg = new SolidBrush(hover ? ColorManager.ui_hoveredDark : ColorManager.ui_bgDark);
            }

            pevent.Graphics.FillRectangle(bg, ClientRectangle);

            int bx = Width - 1;
            int by = Height - 1;

            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.White)), 0, 0, bx, 0);
            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.White)), 0, 1, 0, by);
            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.Black)), 0, by, bx, by);
            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.Black)), bx, 1, bx, by);

            string text     = DrawingUtils.clampText(pevent.Graphics, Text, Font, Width);
            SizeF  textSize = DrawingUtils.measureText(pevent.Graphics, text, Font);
            int    width    = (int)textSize.Width;
            int    x        = Math.Max(0, (Width / 2) - (width / 2));
            int    yText    = (Height / 2) - (int)(textSize.Height / 2);

            pevent.Graphics.DrawString(text, Font, new SolidBrush(Enabled ? ForeColor : Color.Silver), new Point(x, yText));
        }
Exemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            string text     = autoSize ? Text : DrawingUtils.clampText(e.Graphics, Text, Font, Width);
            SizeF  textSize = DrawingUtils.measureText(e.Graphics, text, Font);

            if (autoSize)
            {
                Size = new Size((int)textSize.Width, (int)textSize.Height);
            }
            int   x            = centered ? (Width / 2) - ((int)textSize.Width / 2) : 0;
            Point textLocation = new Point(x, (Height / 2) - ((int)textSize.Height / 2));

            e.Graphics.DrawString(text, Font, new SolidBrush(Enabled ? ForeColor : Color.Silver), textLocation);

            base.OnPaint(e);
        }
Exemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            Brush bg = new SolidBrush(hover ? ColorManager.ui_hoveredDark : ColorManager.ui_bgDark);

            pevent.Graphics.FillRectangle(bg, ClientRectangle);

            int bx = Width - 1;
            int by = Height - 1;

            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.White)), 0, 0, bx, 0);
            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.White)), 0, 1, 0, by);
            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.Black)), 0, by, bx, by);
            pevent.Graphics.DrawLine(new Pen(Color.FromArgb(64, Color.Black)), bx, 1, bx, by);

            string text = null;

            if (Text.Length > 0)
            {
                text = DrawingUtils.clampText(pevent.Graphics, Text, Font, Width - (img != null ? img.Width : 0) - 2);
            }
            SizeF textSize = DrawingUtils.measureText(pevent.Graphics, text, Font);
            int   width    = (int)textSize.Width;
            int   yImage   = 0;

            if (img != null)
            {
                width += img.Width;
                yImage = (Height / 2) - (img.Height / 2);
            }

            int   x         = centered ? (Width / 2) - (width / 2) : 0;
            int   yText     = (Height / 2) - (int)(textSize.Height / 2);
            Brush textBrush = new SolidBrush(Enabled ? ForeColor : Color.Silver);

            if (img != null)
            {
                pevent.Graphics.DrawImage(img, new Rectangle(x, yImage, img.Width, img.Height));
                pevent.Graphics.DrawString(text, Font, textBrush, new Point(x + img.Width, yText));
            }
            else
            {
                pevent.Graphics.DrawString(text, Font, textBrush, new Point(x, yText));
            }

            base.OnPaint(pevent);
        }
Exemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            int w = Resources.ui_icon_tick.Width;
            int h = Resources.ui_icon_tick.Height;

            //Draw box around
            Color lineColor = ForeColor;

            if (!Enabled)
            {
                lineColor = SystemColors.InactiveCaptionText;
            }
            e.Graphics.DrawLine(new Pen(lineColor), new Point(0, Height - 1), new Point(w - 1, Height - 1));
            e.Graphics.DrawLine(new Pen(lineColor), new Point(0, Height - 1), new Point(0, Height - 2));
            e.Graphics.DrawLine(new Pen(lineColor), new Point(w - 1, Height - 1), new Point(w - 1, Height - 2));

            //Ticked icon (if checked)
            Rectangle checkRect = new Rectangle(0, (Height / 2) - (h / 2), w, h);

            if (_checked)
            {
                e.Graphics.DrawImage(Resources.ui_icon_tick, checkRect);
            }

            //Draw text at the right of the box
            string text     = autoSize ? Text : DrawingUtils.clampText(e.Graphics, Text, Font, Width);
            SizeF  textSize = DrawingUtils.measureText(e.Graphics, text, Font);

            if (autoSize)
            {
                Size = new Size((int)textSize.Width + checkRect.Width, (int)textSize.Height);
            }
            Point textLocation = new Point(checkRect.Width, (Height / 2) - ((int)textSize.Height / 2));

            e.Graphics.DrawString(text, Font, new SolidBrush(Enabled ? ForeColor : Color.Silver), textLocation);

            base.OnPaint(e);
        }
Exemplo n.º 5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            int totalSize = (list.Count * tileSize) + (showHeader ? headerSize : 0);
            int startY    = 0;

            if (totalSize > Height)
            {
                startY = -ListScroll.Value;
            }
            int index = 0;

            //Renderiza a parte do Header
            int i = 0;

            if (showHeader)
            {
                int columnX = 0;

                foreach (columnHeader header in columns)
                {
                    int columnWidth;
                    if (i == columns.Count - 1)
                    {
                        columnWidth = Width - columnX;
                    }
                    else
                    {
                        columnWidth = header.width;
                    }
                    if (columnWidth < 2)
                    {
                        break;
                    }

                    Rectangle rect = new Rectangle(columnX, startY, columnWidth - 1, headerSize);
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0x1f, Color.White)), rect);

                    Font   font         = new Font(Font.FontFamily, Font.Size, FontStyle.Bold);
                    int    textHeight   = (int)e.Graphics.MeasureString(header.text, font).Height;
                    string text         = DrawingUtils.clampText(e.Graphics, header.text, font, columnWidth);
                    Point  textLocation = new Point(columnX, startY + ((headerSize / 2) - (textHeight / 2)));
                    e.Graphics.DrawString(text, font, new SolidBrush(ForeColor), textLocation);
                    font.Dispose();

                    columnX += columnWidth;
                    i++;
                }

                startY += headerSize;
            }

            //Renderiza os itens da lista
            for (int j = 0; j < list.Count; j++)
            {
                listItemGroup item = list[j];

                if (startY >= -tileSize)
                {
                    if (startY > Height)
                    {
                        break;
                    }

                    Rectangle itemRect = new Rectangle(0, startY, Width, tileSize);

                    //Selecionado
                    if (clicked)
                    {
                        if (itemRect.Contains(mousePosition))
                        {
                            e.Graphics.FillRectangle(new SolidBrush(selectedColor), itemRect);
                            selectedIndex = index;
                            if (selectedIndex != oldIndex && SelectedIndexChanged != null)
                            {
                                SelectedIndexChanged(this, EventArgs.Empty);
                            }
                            oldIndex = selectedIndex;
                            clicked  = false;
                        }
                    }
                    else
                    {
                        if (index == selectedIndex)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(selectedColor), itemRect);
                        }
                    }

                    //Textos e afins
                    i = 0;
                    int x = 0;
                    foreach (listItem subItem in item.columns)
                    {
                        int columnWidth;
                        if (i == columns.Count - 1 || columns.Count == 0)
                        {
                            columnWidth = Width - x;
                        }
                        else
                        {
                            columnWidth = columns[i].width;
                        }

                        if (columnWidth < 1)
                        {
                            break;
                        }

                        if (subItem.thumbnail != null)
                        {
                            float     ar = (float)subItem.thumbnail.Width / subItem.thumbnail.Height;
                            int       w  = (int)(tileSize * ar);
                            int       h  = (int)(columnWidth / ar);
                            Rectangle dst;
                            if (w > columnWidth)
                            {
                                dst = new Rectangle(x, startY + ((tileSize / 2) - (h / 2)), columnWidth, h);
                            }
                            else
                            {
                                dst = new Rectangle(x + ((columnWidth / 2) - (w / 2)), startY, w, tileSize);
                            }

                            Rectangle src = new Rectangle(0, 0, subItem.thumbnail.Width, subItem.thumbnail.Height);
                            e.Graphics.DrawImage(subItem.thumbnail, dst, src, GraphicsUnit.Pixel);
                        }

                        int    textHeight   = (int)e.Graphics.MeasureString(subItem.text, Font).Height;
                        string text         = DrawingUtils.clampText(e.Graphics, subItem.text, Font, columnWidth);
                        Point  textLocation = new Point(x, startY + ((tileSize / 2) - (textHeight / 2)));
                        e.Graphics.DrawString(text, Font, new SolidBrush(ForeColor), textLocation);

                        x += columnWidth;
                        i++;
                    }
                }

                startY += tileSize;
                index++;
            }

            if (clicked)
            {
                selectedIndex = -1;
                if (selectedIndex != oldIndex && SelectedIndexChanged != null)
                {
                    SelectedIndexChanged(this, EventArgs.Empty);
                }
                oldIndex = selectedIndex;
            }
            clicked = false;

            base.OnPaint(e);
        }