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;
}
}
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 buttonStateSet = ButtonState.Disabled;
if(!this.ReadOnly && this.Enabled)
{
if (this.buttonSetPressed) buttonStateSet = ButtonState.Pressed;
else if (this.buttonSetHovered) buttonStateSet = ButtonState.Hot;
else buttonStateSet = ButtonState.Normal;
}
ControlRenderer.DrawButton(
e.Graphics,
this.rectButtonSet,
buttonStateSet,
null,
iconSet);
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);
}