Пример #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            ControlRenderer.DrawStringLine(e.Graphics,
                                           "Width:",
                                           SystemFonts.DefaultFont,
                                           this.rectLabelWidth,
                                           !this.Enabled ? ControlRenderer.ColorGrayText : ControlRenderer.ColorText);
            ControlRenderer.DrawStringLine(e.Graphics,
                                           "Height:",
                                           SystemFonts.DefaultFont,
                                           this.rectLabelHeight,
                                           !this.Enabled ? ControlRenderer.ColorGrayText : ControlRenderer.ColorText);
            ControlRenderer.DrawStringLine(e.Graphics,
                                           this.value != null ? this.value.Width.ToString() : " - ",
                                           SystemFonts.DefaultFont,
                                           this.rectLabelWidthVal,
                                           !this.Enabled ? ControlRenderer.ColorGrayText : ControlRenderer.ColorText);
            ControlRenderer.DrawStringLine(e.Graphics,
                                           this.value != null ? this.value.Height.ToString() : " - ",
                                           SystemFonts.DefaultFont,
                                           this.rectLabelHeightVal,
                                           !this.Enabled ? ControlRenderer.ColorGrayText : ControlRenderer.ColorText);

            if (this.PreviewFrameCount == 0)
            {
                ControlRenderer.DrawStringLine(e.Graphics,
                                               this.value != null ? this.value.Name : " - ",
                                               SystemFonts.DefaultFont,
                                               this.rectLabelName,
                                               !this.Enabled ? ControlRenderer.ColorGrayText : ControlRenderer.ColorText,
                                               StringAlignment.Far);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Rectangle rectImage     = new Rectangle(this.rectPreview.X + 1, this.rectPreview.Y + 1, this.rectPreview.Width - 2, this.rectPreview.Height - 2);
            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);
            Bitmap    img           = this.GetPreviewFrame((int)this.subImageSelector.Value);

            e.Graphics.FillRectangle(new HatchBrush(HatchStyle.LargeCheckerBoard, brightChecker, darkChecker), rectImage);
            if (img != null)
            {
                Size  imgSize        = img.Size;
                float widthForHeight = (float)imgSize.Width / (float)imgSize.Height;
                if (widthForHeight * (imgSize.Height - rectImage.Height) > imgSize.Width - rectImage.Width)
                {
                    imgSize.Height = Math.Min(rectImage.Height, imgSize.Height);
                    imgSize.Width  = MathF.RoundToInt(widthForHeight * imgSize.Height);
                }
                else
                {
                    imgSize.Width  = Math.Min(rectImage.Width, imgSize.Width);
                    imgSize.Height = MathF.RoundToInt(imgSize.Width / widthForHeight);
                }
                e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                e.Graphics.DrawImage(img,
                                     rectImage.X + rectImage.Width / 2 - imgSize.Width / 2,
                                     rectImage.Y + rectImage.Height / 2 - imgSize.Height / 2,
                                     imgSize.Width,
                                     imgSize.Height);
                e.Graphics.InterpolationMode = InterpolationMode.Default;
            }

            ControlRenderer.DrawBorder(e.Graphics,
                                       this.rectPreview,
                                       BorderStyle.Simple,
                                       !this.Enabled ? BorderState.Disabled : BorderState.Normal);

            bool focusBg = this.Focused || (this is IPopupControlHost && (this as IPopupControlHost).IsDropDownOpened);

            ControlRenderer.DrawGroupHeaderBackground(
                e.Graphics,
                this.rectHeader,
                focusBg ? ControlRenderer.ColorBackground.ScaleBrightness(0.85f) : ControlRenderer.ColorBackground,
                GroupHeaderStyle.SmoothSunken);

            if (this.subImageSelector.Rect.Width > 0)
            {
                ControlRenderer.DrawStringLine(e.Graphics,
                                               "Frame Index",
                                               SystemFonts.DefaultFont,
                                               this.rectLabelName,
                                               !this.Enabled ? ControlRenderer.ColorGrayText : ControlRenderer.ColorText,
                                               StringAlignment.Far);
                this.subImageSelector.OnPaint(e, this.Enabled && !this.subImageSelector.ReadOnly, false);
            }
        }
Пример #3
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");
        }
Пример #4
0
        protected void PaintHeader(Graphics g)
        {
            if (this.headerHeight == 0)
            {
                return;
            }
            Rectangle buttonRect = this.ButtonRectangle;

            CheckBoxState activeState  = CheckBoxState.UncheckedDisabled;
            CheckBoxState expandState  = CheckBoxState.UncheckedDisabled;
            bool          parentExpand = this.ParentUseIndentChildExpand;

            if (!parentExpand && (this.Hints & HintFlags.HasExpandCheck) != HintFlags.None)
            {
                if (this.Enabled && this.CanExpand && (this.Hints & HintFlags.ExpandEnabled) != HintFlags.None)
                {
                    if (!this.Expanded)
                    {
                        if (this.expandCheckPressed)
                        {
                            expandState = CheckBoxState.PlusPressed;
                        }
                        else if (this.expandCheckHovered)
                        {
                            expandState = CheckBoxState.PlusHot;
                        }
                        else
                        {
                            expandState = CheckBoxState.PlusNormal;
                        }
                    }
                    else
                    {
                        if (this.expandCheckPressed)
                        {
                            expandState = CheckBoxState.MinusPressed;
                        }
                        else if (this.expandCheckHovered)
                        {
                            expandState = CheckBoxState.MinusHot;
                        }
                        else
                        {
                            expandState = CheckBoxState.MinusNormal;
                        }
                    }
                }
                else
                {
                    if (this.Expanded)
                    {
                        expandState = CheckBoxState.PlusDisabled;
                    }
                    else
                    {
                        expandState = CheckBoxState.MinusDisabled;
                    }
                }
            }
            if ((this.Hints & HintFlags.HasActiveCheck) != HintFlags.None)
            {
                if (this.Enabled && !this.ReadOnly && (this.Hints & HintFlags.ActiveEnabled) != HintFlags.None)
                {
                    if (this.Active)
                    {
                        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)
                    {
                        activeState = CheckBoxState.CheckedDisabled;
                    }
                    else
                    {
                        activeState = CheckBoxState.UncheckedDisabled;
                    }
                }
            }

            Rectangle iconRect;

            if (this.headerIcon != null)
            {
                iconRect = new Rectangle(
                    this.activeCheckRect.Right + 2,
                    this.headerRect.Y + this.headerRect.Height / 2 - this.headerIcon.Height / 2,
                    this.headerIcon.Width,
                    this.headerIcon.Height);
            }
            else
            {
                iconRect = new Rectangle(this.activeCheckRect.Right, this.headerRect.Y, 0, 0);
            }
            Rectangle textRect = new Rectangle(
                iconRect.Right,
                this.headerRect.Y,
                this.headerRect.Width - buttonRect.Width - iconRect.Width - this.expandCheckRect.Width - this.activeCheckRect.Width - 2,
                this.headerRect.Height);
            Rectangle nameTextRect;
            Rectangle valueTextRect;

            if (!string.IsNullOrEmpty(this.PropertyName) && !string.IsNullOrEmpty(this.headerValueText))
            {
                int nameWidth;
                nameWidth     = this.NameLabelWidth - textRect.X;
                nameTextRect  = new Rectangle(textRect.X, textRect.Y, nameWidth, textRect.Height);
                valueTextRect = new Rectangle(textRect.X + nameWidth, textRect.Y, textRect.Width - nameWidth, textRect.Height);
            }
            else if (!string.IsNullOrEmpty(this.headerValueText))
            {
                nameTextRect  = new Rectangle(textRect.X, textRect.Y, 0, 0);
                valueTextRect = textRect;
            }
            else
            {
                nameTextRect  = textRect;
                valueTextRect = new Rectangle(textRect.X, textRect.Y, 0, 0);
            }


            bool focusBg      = this.Focused || (this is IPopupControlHost && (this as IPopupControlHost).IsDropDownOpened);
            bool focusBgColor = this.headerStyle == GroupHeaderStyle.Flat || this.headerStyle == GroupHeaderStyle.Simple;

            ControlRenderer.DrawGroupHeaderBackground(g, this.headerRect, focusBg && focusBgColor ? this.headerColor.Value.ScaleBrightness(0.85f) : this.headerColor.Value, this.headerStyle);
            if (focusBg && !focusBgColor)
            {
                ControlRenderer.DrawBorder(g, this.headerRect, Renderer.BorderStyle.Simple, BorderState.Normal);
            }

            if (!parentExpand && (this.Hints & HintFlags.HasExpandCheck) != HintFlags.None)
            {
                ControlRenderer.DrawCheckBox(g, this.expandCheckRect.Location, expandState);
            }
            if ((this.Hints & HintFlags.HasActiveCheck) != HintFlags.None)
            {
                ControlRenderer.DrawCheckBox(g, this.activeCheckRect.Location, activeState);
            }

            if (this.headerIcon != null)
            {
                g.DrawImage(this.Enabled ? this.headerIcon.Normal : this.headerIcon.Disabled, iconRect);
            }

            ControlRenderer.DrawStringLine(g,
                                           this.PropertyName,
                                           this.ValueModified ? ControlRenderer.DefaultFontBold : ControlRenderer.DefaultFont,
                                           nameTextRect,
                                           this.Enabled && !this.NonPublic ? ControlRenderer.ColorText : ControlRenderer.ColorGrayText);
            ControlRenderer.DrawStringLine(g,
                                           this.headerValueText,
                                           this.ValueModified ? ControlRenderer.DefaultFontBold : ControlRenderer.DefaultFont,
                                           valueTextRect,
                                           this.Enabled ? ControlRenderer.ColorText : ControlRenderer.ColorGrayText);
        }