Example #1
0
        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);
            }
            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 buttonState = ButtonState.Disabled;

            if (!this.ReadOnly && this.Enabled)
            {
                if (this.buttonPressed)
                {
                    buttonState = ButtonState.Pressed;
                }
                else if (this.buttonHovered || this.Focused)
                {
                    buttonState = ButtonState.Hot;
                }
                else
                {
                    buttonState = ButtonState.Normal;
                }
            }
            ControlRenderer.DrawButton(
                e.Graphics,
                this.rectButton,
                buttonState,
                null,
                EditorRes.GeneralResCache.ColorWheel);
        }
Example #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Color headerBgColorUpper = ControlRenderer.ColorBackground;
            Color headerBgColorLower = headerBgColorUpper.ScaleBrightness(0.95f);

            GroupedPropertyEditor.DrawGroupHeaderBackground(e.Graphics, this.rectHeader, headerBgColorUpper, GroupedPropertyEditor.GroupHeaderStyle.Emboss);
            GroupedPropertyEditor.DrawGroupHeaderBackground(e.Graphics, this.rectPrefab, headerBgColorLower, GroupedPropertyEditor.GroupHeaderStyle.SmoothSunken);
            if (this.Focused)
            {
                ControlRenderer.DrawBorder(e.Graphics, this.ClientRectangle, AdamsLair.WinForms.Drawing.BorderStyle.Simple, BorderState.Normal);
            }

            CheckBoxState activeState = CheckBoxState.UncheckedDisabled;

            if (!this.ReadOnly && this.Enabled)
            {
                if (!this.active.HasValue)
                {
                    if (this.activeCheckPressed)
                    {
                        activeState = CheckBoxState.MixedPressed;
                    }
                    else if (this.activeCheckHovered)
                    {
                        activeState = CheckBoxState.MixedHot;
                    }
                    else
                    {
                        activeState = CheckBoxState.MixedNormal;
                    }
                }
                else if (this.active.Value)
                {
                    if (this.activeCheckPressed)
                    {
                        activeState = CheckBoxState.CheckedPressed;
                    }
                    else if (this.activeCheckHovered)
                    {
                        activeState = CheckBoxState.CheckedHot;
                    }
                    else
                    {
                        activeState = CheckBoxState.CheckedNormal;
                    }
                }
                else
                {
                    if (this.activeCheckPressed)
                    {
                        activeState = CheckBoxState.UncheckedPressed;
                    }
                    else if (this.activeCheckHovered)
                    {
                        activeState = CheckBoxState.UncheckedHot;
                    }
                    else
                    {
                        activeState = CheckBoxState.UncheckedNormal;
                    }
                }
            }
            else
            {
                if (!this.active.HasValue)
                {
                    activeState = CheckBoxState.MixedDisabled;
                }
                else if (this.active.Value)
                {
                    activeState = CheckBoxState.CheckedDisabled;
                }
                else
                {
                    activeState = CheckBoxState.UncheckedDisabled;
                }
            }
            ControlRenderer.DrawCheckBox(e.Graphics, this.rectCheckActive.Location, activeState);

            Region[] nameLabelRegion = ControlRenderer.MeasureStringLine(e.Graphics, this.displayedName, new[] { new CharacterRange(0, this.displayedName.Length) }, headerNameFont, this.rectLabelName);
            ControlRenderer.DrawStringLine(e.Graphics, this.displayedName, headerNameFont, this.rectLabelName, SystemColors.ControlText);

            if (nameLabelRegion.Length > 0)
            {
                SizeF     nameLabelSize = nameLabelRegion[0].GetBounds(e.Graphics).Size;
                Rectangle extLabelRect  = new Rectangle(
                    this.rectLabelName.X + (int)nameLabelSize.Width,
                    this.rectLabelName.Y,
                    this.rectLabelName.Width - (int)nameLabelSize.Width,
                    this.rectLabelName.Height);
                ControlRenderer.DrawStringLine(e.Graphics, this.displayedNameExt, headerNameExtFont, extLabelRect, SystemColors.ControlText);
            }

            ButtonState buttonStateAdd        = ButtonState.Normal;
            ButtonState buttonStateDefaultAdd = ButtonState.Normal;

            if (this.curButtonPressed)
            {
                buttonStateAdd = ButtonState.Pressed;
            }
            else if (this.curButtonHovered)
            {
                buttonStateAdd = ButtonState.Hot;
            }
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonAddComponent, this.curButton == 4 ? buttonStateAdd : buttonStateDefaultAdd, "+");

            ControlRenderer.DrawStringLine(e.Graphics, "PrefabLink", headerPrefabFont, this.rectLabelPrefab, !this.prefabLinked ? SystemColors.GrayText : (this.prefabLinkAvailable ? Color.Blue : Color.DarkRed));

            ButtonState buttonState             = ButtonState.Disabled;
            ButtonState buttonStateDefault      = ButtonState.Disabled;
            ButtonState buttonStateDefaultBreak = ButtonState.Disabled;

            if (!this.ReadOnly && this.Enabled && this.prefabLinked)
            {
                if (this.prefabLinkAvailable)
                {
                    buttonState        = ButtonState.Normal;
                    buttonStateDefault = ButtonState.Normal;
                }
                buttonStateDefaultBreak = ButtonState.Normal;
            }

            if (this.curButtonPressed)
            {
                buttonState = ButtonState.Pressed;
            }
            else if (this.curButtonHovered)
            {
                buttonState = ButtonState.Hot;
            }

            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabShow, this.curButton == 0 ? buttonState : buttonStateDefault, "Show");
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabRevert, this.curButton == 1 ? buttonState : buttonStateDefault, "Revert");
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabApply, this.curButton == 2 ? buttonState : buttonStateDefault, "Apply");
            ControlRenderer.DrawButton(e.Graphics, this.rectButtonPrefabBreak, this.curButton == 3 ? buttonState : buttonStateDefaultBreak, "Break");
        }
Example #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            bool linkBroken = this.ReferenceBroken;

            Color bgColorBright = Color.White;

            if (this.dragHover)
            {
                bgColorBright = bgColorBright.MixWith(Color.FromArgb(192, 255, 0), 0.4f);
            }
            else if (this.multiple)
            {
                bgColorBright = Color.Bisque;
            }
            else if (linkBroken)
            {
                bgColorBright = Color.FromArgb(255, 128, 128);
            }

            bool      darkBg    = false;
            Rectangle rectImage = new Rectangle(this.rectPanel.X + 2, this.rectPanel.Y + 2, this.rectPanel.Width - 4, this.rectPanel.Height - 4);

            if (this.prevImage == null)
            {
                if (this.ReadOnly || !this.Enabled)
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(64, bgColorBright)), rectImage);
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(bgColorBright), rectImage);
                }
            }
            else
            {
                Color brightChecker = this.prevImageLum > 0.5f ? Color.FromArgb(48, 48, 48) : Color.FromArgb(224, 224, 224);
                Color darkChecker   = this.prevImageLum > 0.5f ? Color.FromArgb(32, 32, 32) : Color.FromArgb(192, 192, 192);

                if (this.dragHover)
                {
                    brightChecker = brightChecker.MixWith(Color.FromArgb(192, 255, 0), 0.4f);
                    darkChecker   = darkChecker.MixWith(Color.FromArgb(192, 255, 0), 0.4f);
                }
                else if (this.multiple)
                {
                    brightChecker = brightChecker.MixWith(Color.FromArgb(255, 200, 128), 0.4f);
                    darkChecker   = darkChecker.MixWith(Color.FromArgb(255, 200, 128), 0.4f);
                }
                else if (linkBroken)
                {
                    brightChecker = brightChecker.MixWith(Color.FromArgb(255, 128, 128), 0.4f);
                    darkChecker   = darkChecker.MixWith(Color.FromArgb(255, 128, 128), 0.4f);
                }

                e.Graphics.FillRectangle(new HatchBrush(HatchStyle.LargeCheckerBoard, brightChecker, darkChecker), rectImage);

                TextureBrush bgImageBrush = new TextureBrush(this.prevImage);
                bgImageBrush.ResetTransform();
                bgImageBrush.TranslateTransform(rectImage.X, rectImage.Y);
                e.Graphics.FillRectangle(bgImageBrush, rectImage);

                darkBg = this.prevImageLum > 0.5f;
                if (this.ReadOnly || !this.Enabled)
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(128, SystemColors.Control)), rectImage);
                    darkBg = (this.prevImageLum + SystemColors.Control.GetLuminance()) * 0.5f < 0.5f;
                }
            }

            if (this.prevSound != null)
            {
                if (this.prevSoundInst != null)
                {
                    e.Graphics.DrawImage(darkBg ? EditorBaseResCache.IconSpeakerWhite : EditorBaseResCache.IconSpeakerBlack,
                                         this.rectPrevSound.X,
                                         this.rectPrevSound.Y);
                }
                else
                {
                    e.Graphics.DrawImageAlpha(darkBg ? EditorBaseResCache.IconSpeakerWhite : EditorBaseResCache.IconSpeakerBlack,
                                              0.5f,
                                              this.rectPrevSound.X,
                                              this.rectPrevSound.Y);
                }
            }

            StringFormat format = StringFormat.GenericDefault;

            format.Alignment     = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            format.Trimming      = StringTrimming.EllipsisPath;
            SizeF textSize = e.Graphics.MeasureString(
                this.ReferenceName ?? "null",
                SystemFonts.DefaultFont,
                new SizeF(this.rectPanel.Width, this.rectPanel.Height),
                format);

            Rectangle rectText;

            if (this.prevImage == null)
            {
                rectText = this.rectPanel;
            }
            else
            {
                rectText = new Rectangle(
                    this.rectPanel.X, this.rectPanel.Bottom - (int)textSize.Height - 2, this.rectPanel.Width, (int)textSize.Height);
            }

            if (this.prevImage != null)
            {
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(192, bgColorBright)),
                                         rectText.X + rectText.Width / 2 - textSize.Width / 2 - 1,
                                         rectText.Y + rectText.Height / 2 - textSize.Height / 2 - 2,
                                         textSize.Width + 1,
                                         textSize.Height + 2);
            }
            e.Graphics.DrawString(
                this.ReferenceName ?? "null",
                SystemFonts.DefaultFont,
                new SolidBrush(this.Enabled ? SystemColors.ControlText : SystemColors.GrayText),
                rectText,
                format);

            ControlRenderer.DrawBorder(e.Graphics,
                                       this.rectPanel,
                                       BorderStyle.ContentBox,
                                       (this.ReadOnly || !this.Enabled) ? BorderState.Disabled : BorderState.Normal);

            ButtonState buttonStateReset = ButtonState.Disabled;

            if (!this.ReadOnly && this.Enabled && this.ReferenceName != null)
            {
                if (this.buttonResetPressed)
                {
                    buttonStateReset = ButtonState.Pressed;
                }
                else if (this.buttonResetHovered)
                {
                    buttonStateReset = ButtonState.Hot;
                }
                else
                {
                    buttonStateReset = ButtonState.Normal;
                }
            }
            ControlRenderer.DrawButton(
                e.Graphics,
                this.rectButtonReset,
                buttonStateReset,
                null,
                iconReset);

            ButtonState buttonStateShow = ButtonState.Disabled;

            if (this.Enabled && this.ReferenceName != null)
            {
                if (this.buttonShowPressed)
                {
                    buttonStateShow = ButtonState.Pressed;
                }
                else if (this.buttonShowHovered || this.Focused)
                {
                    buttonStateShow = ButtonState.Hot;
                }
                else
                {
                    buttonStateShow = ButtonState.Normal;
                }
            }
            ControlRenderer.DrawButton(
                e.Graphics,
                this.rectButtonShow,
                buttonStateShow,
                null,
                iconShow);
        }
        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);
        }