public static void DrawGroupHeaderBackground(Graphics g, Rectangle rect, Color baseColor, GroupHeaderStyle style) { if (rect.Height == 0 || rect.Width == 0) { return; } Color lightColor = baseColor.ScaleBrightness(style == GroupHeaderStyle.SmoothSunken ? 0.85f : 1.1f); Color darkColor = baseColor.ScaleBrightness(style == GroupHeaderStyle.SmoothSunken ? 0.95f : 0.85f); LinearGradientBrush gradientBrush = new LinearGradientBrush(rect, lightColor, darkColor, 90.0f); if (style != GroupHeaderStyle.Simple && style != GroupHeaderStyle.Flat) { g.FillRectangle(gradientBrush, rect); } else { g.FillRectangle(new SolidBrush(baseColor), rect); } if (style == GroupHeaderStyle.Flat) { return; } g.DrawLine(new Pen(Color.FromArgb(128, Color.White)), rect.Left, rect.Top, rect.Right, rect.Top); g.DrawLine(new Pen(Color.FromArgb(64, Color.Black)), rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1); g.DrawLine(new Pen(Color.FromArgb(64, Color.White)), rect.Left, rect.Top, rect.Left, rect.Bottom - 1); g.DrawLine(new Pen(Color.FromArgb(32, Color.Black)), rect.Right, rect.Top, rect.Right, rect.Bottom - 1); }
public static Color MixWith(this Color c, Color other, float ratio, bool lockBrightness = false) { float myRatio = 1.0f - ratio; if (lockBrightness) { int oldBrightness = Math.Max(c.R, Math.Max(c.G, c.B)); int newBrightness = Math.Max(other.R, Math.Max(other.G, other.B)); other = other.ScaleBrightness((float)oldBrightness / (float)newBrightness); } return Color.FromArgb(c.A, (byte)Math.Min(Math.Max((float)c.R * myRatio + (float)other.R * ratio, 0.0f), 255.0f), (byte)Math.Min(Math.Max((float)c.G * myRatio + (float)other.G * ratio, 0.0f), 255.0f), (byte)Math.Min(Math.Max((float)c.B * myRatio + (float)other.B * ratio, 0.0f), 255.0f)); }
public static Color MixWith(this Color c, Color other, float ratio, bool lockBrightness = false) { float myRatio = 1.0f - ratio; if (lockBrightness) { int oldBrightness = Math.Max(c.R, Math.Max(c.G, c.B)); int newBrightness = Math.Max(other.R, Math.Max(other.G, other.B)); other = other.ScaleBrightness((float)oldBrightness / (float)newBrightness); } return(Color.FromArgb(c.A, (byte)Math.Min(Math.Max((float)c.R * myRatio + (float)other.R * ratio, 0.0f), 255.0f), (byte)Math.Min(Math.Max((float)c.G * myRatio + (float)other.G * ratio, 0.0f), 255.0f), (byte)Math.Min(Math.Max((float)c.B * myRatio + (float)other.B * ratio, 0.0f), 255.0f))); }
public Color GetBackgroundColor(Color baseColor, bool focus, int indent) { float brightnessScale = 1.0f; if (focus) { brightnessScale *= this.FocusBrightnessScale; } brightnessScale *= (float)Math.Pow(this.NestedBrightnessScale, Math.Max((indent - this.NestedBrightnessOffset) / PropertyEditing.GroupedPropertyEditor.DefaultIndent, 0)); if (brightnessScale != 1.0f) { baseColor = baseColor.ScaleBrightness(brightnessScale); } return(baseColor); }
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"); }
public void DrawGroupHeaderBackground(Graphics g, Rectangle rect, Color baseColor, GroupHeaderStyle style) { if (rect.Height == 0 || rect.Width == 0) return; Color lightColor = baseColor.ScaleBrightness(style == GroupHeaderStyle.SmoothSunken ? 0.85f : 1.1f); Color darkColor = baseColor.ScaleBrightness(style == GroupHeaderStyle.SmoothSunken ? 0.95f : 0.85f); LinearGradientBrush gradientBrush = new LinearGradientBrush(rect, lightColor, darkColor, 90.0f); if (style != GroupHeaderStyle.Simple && style != GroupHeaderStyle.Flat) g.FillRectangle(gradientBrush, rect); else g.FillRectangle(new SolidBrush(baseColor), rect); if (style == GroupHeaderStyle.Flat) return; g.DrawLine(new Pen(Color.FromArgb(128, Color.White)), rect.Left, rect.Top, rect.Right, rect.Top); g.DrawLine(new Pen(Color.FromArgb(64, Color.Black)), rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1); g.DrawLine(new Pen(Color.FromArgb(64, Color.White)), rect.Left, rect.Top, rect.Left, rect.Bottom - 1); g.DrawLine(new Pen(Color.FromArgb(32, Color.Black)), rect.Right, rect.Top, rect.Right, rect.Bottom - 1); }
public Color GetBackgroundColor(Color baseColor, bool focus, int indent) { float brightnessScale = 1.0f; if (focus) brightnessScale *= this.FocusBrightnessScale; brightnessScale *= (float)Math.Pow(this.NestedBrightnessScale, Math.Max((indent - this.NestedBrightnessOffset) / PropertyEditing.GroupedPropertyEditor.DefaultIndent, 0)); if (brightnessScale != 1.0f) baseColor = baseColor.ScaleBrightness(brightnessScale); return baseColor; }
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); Color headerBgColor = this.ControlRenderer.ColorBackground; if (focusBg) { headerBgColor = headerBgColor.ScaleBrightness(this.ControlRenderer.FocusBrightnessScale); } GroupedPropertyEditor.DrawGroupHeaderBackground( e.Graphics, this.rectHeader, headerBgColor, GroupedPropertyEditor.GroupHeaderStyle.SmoothSunken); if (this.subImageSelector.Rect.Width > 0) { this.ControlRenderer.DrawStringLine(e.Graphics, "Frame Index", SystemFonts.DefaultFont, this.rectLabelName, !this.Enabled ? this.ControlRenderer.ColorGrayText : this.ControlRenderer.ColorText, StringAlignment.Far); this.subImageSelector.OnPaint(e, this.Enabled && !this.subImageSelector.ReadOnly, false); } }