Example #1
0
        public static void VisualizeAtlas(Bitmap bitmap, List <Rect> atlas)
        {
            ColorRgba avgColor   = bitmap.GetAverageColor();
            ColorRgba atlasColor = avgColor.GetLuminance() < 0.5f ? new ColorRgba(128, 0, 0, 164) : new ColorRgba(255, 128, 128, 164);

            // Draw atlas rects
            if (atlas != null)
            {
                Pen atlasPen = new Pen(Color.FromArgb(atlasColor.A, atlasColor.R, atlasColor.G, atlasColor.B));
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    foreach (Rect r in atlas)
                    {
                        g.DrawRectangle(atlasPen, r.X, r.Y, r.W, r.H);
                    }
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Color brightChecker = Color.FromArgb(224, 224, 224);
            Color darkChecker   = Color.FromArgb(192, 192, 192);

            e.Graphics.FillRectangle(new HatchBrush(HatchStyle.LargeCheckerBoard, brightChecker, darkChecker), this.rectPanel);
            if (this.value != null)
            {
                Color val      = Color.FromArgb(this.value.ToIntArgb());
                Color valSolid = Color.FromArgb(255, val);
                e.Graphics.FillRectangle(
                    new SolidBrush(val),
                    this.rectPanel.X,
                    this.rectPanel.Y,
                    this.rectPanel.Width / 2,
                    this.rectPanel.Height);
                e.Graphics.FillRectangle(
                    new SolidBrush(valSolid),
                    this.rectPanel.X + this.rectPanel.Width / 2,
                    this.rectPanel.Y,
                    this.rectPanel.Width / 2,
                    this.rectPanel.Height);

                ColorRgba    rgba      = this.value.ConvertTo <ColorRgba>();
                Color        textColor = rgba.GetLuminance() > 0.5f ? Color.Black : Color.White;
                StringFormat format    = StringFormat.GenericDefault;
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                format.Trimming      = StringTrimming.EllipsisCharacter;
                e.Graphics.DrawString(
                    string.Format("{0}, {1}, {2}, {3}", rgba.R, rgba.G, rgba.B, rgba.A),
                    this.ControlRenderer.FontRegular,
                    new SolidBrush(Color.FromArgb(128, textColor)),
                    this.rectPanel,
                    format);
            }
            e.Graphics.DrawRectangle(SystemPens.ControlLightLight,
                                     this.rectPanel.X + 1,
                                     this.rectPanel.Y + 1,
                                     this.rectPanel.Width - 2,
                                     this.rectPanel.Height - 2);
            e.Graphics.DrawRectangle(SystemPens.ControlDark, this.rectPanel);

            ButtonState buttonCDiagState = ButtonState.Disabled;

            if (!this.ReadOnly && this.Enabled)
            {
                if (this.buttonCDiagPressed)
                {
                    buttonCDiagState = ButtonState.Pressed;
                }
                else if (this.buttonCDiagHovered)
                {
                    buttonCDiagState = ButtonState.Hot;
                }
                else
                {
                    buttonCDiagState = ButtonState.Normal;
                }
            }
            ControlRenderer.DrawButton(
                e.Graphics,
                this.rectCDiagButton,
                buttonCDiagState,
                null,
                Properties.GeneralResCache.ColorWheel);

            ButtonState buttonCPickState = ButtonState.Disabled;

            if (!this.ReadOnly && this.Enabled)
            {
                if (this.buttonCPickPressed)
                {
                    buttonCPickState = ButtonState.Pressed;
                }
                else if (this.buttonCPickHovered)
                {
                    buttonCPickState = ButtonState.Hot;
                }
                else
                {
                    buttonCPickState = ButtonState.Normal;
                }
            }
            ControlRenderer.DrawButton(
                e.Graphics,
                this.rectCPickButton,
                buttonCPickState,
                null,
                Properties.GeneralResCache.ColorPick);
        }