From 0d5284038a44f8847be451d8844506078a5ba39c Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 1 Jun 2019 22:15:51 +0300 Subject: [PATCH] Support dark theme in notification form --- ShareX.HelpersLib/Helpers/ImageHelpers.cs | 1 - ShareX/Forms/NotificationForm.cs | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs index fa35982bc..e5673e0b4 100644 --- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs +++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs @@ -690,7 +690,6 @@ public static Bitmap FillBackground(Image img, Brush brush) using (img) { g.FillRectangle(brush, 0, 0, result.Width, result.Height); - g.SetHighQuality(); g.DrawImage(img, 0, 0, result.Width, result.Height); } diff --git a/ShareX/Forms/NotificationForm.cs b/ShareX/Forms/NotificationForm.cs index 48e32688c..74b1c303f 100644 --- a/ShareX/Forms/NotificationForm.cs +++ b/ShareX/Forms/NotificationForm.cs @@ -75,12 +75,13 @@ public NotificationForm(int duration, int fadeDuration, ContentAlignment placeme if (config.Image != null) { config.Image = ImageHelpers.ResizeImageLimit(config.Image, size); - config.Image = ImageHelpers.DrawCheckers(config.Image); + Color backgroundColor = ShareXResources.UseDarkTheme ? ShareXResources.DarkBackgroundColor : SystemColors.Window; + config.Image = ImageHelpers.FillBackground(config.Image, backgroundColor); size = new Size(config.Image.Width + 2, config.Image.Height + 2); } else if (!string.IsNullOrEmpty(config.Text)) { - textRenderSize = TextRenderer.MeasureText(config.Text, textFont, size.Offset(-textPadding * 2), TextFormatFlags.Left); + textRenderSize = TextRenderer.MeasureText(config.Text, textFont, size.Offset(-textPadding * 2), TextFormatFlags.Left | TextFormatFlags.EndEllipsis); size = new Size(textRenderSize.Width + (textPadding * 2), textRenderSize.Height + (textPadding * 2) + 2); } @@ -161,7 +162,7 @@ protected override void OnPaint(PaintEventArgs e) g.FillRectangle(brush, textRect); } - TextRenderer.DrawText(g, ToastConfig.URL, textFont, textRect.Offset(-urlPadding), Color.White, TextFormatFlags.Left); + TextRenderer.DrawText(g, ToastConfig.URL, textFont, textRect.Offset(-urlPadding), Color.White, TextFormatFlags.Left | TextFormatFlags.EndEllipsis); } } else if (!string.IsNullOrEmpty(ToastConfig.Text)) @@ -172,11 +173,15 @@ protected override void OnPaint(PaintEventArgs e) } Rectangle textRect = new Rectangle(textPadding, textPadding, textRenderSize.Width + 2, textRenderSize.Height + 2); - TextRenderer.DrawText(g, ToastConfig.Text, textFont, textRect, Color.Black, TextFormatFlags.Left); - TextRenderer.DrawText(g, ToastConfig.Text, textFont, textRect.LocationOffset(1), Color.White, TextFormatFlags.Left); + TextRenderer.DrawText(g, ToastConfig.Text, textFont, textRect, Color.Black, TextFormatFlags.Left | TextFormatFlags.EndEllipsis); + TextRenderer.DrawText(g, ToastConfig.Text, textFont, textRect.LocationOffset(1), Color.White, TextFormatFlags.Left | TextFormatFlags.EndEllipsis); } - g.DrawRectangleProper(Pens.Black, rect); + Color borderColor = ShareXResources.UseDarkTheme ? ShareXResources.DarkBorderColor : SystemColors.WindowText; + using (Pen borderPen = new Pen(borderColor)) + { + g.DrawRectangleProper(borderPen, rect); + } } public static void Show(int duration, int fadeDuration, ContentAlignment placement, Size size, NotificationFormConfig config)