diff --git a/NAPS2.Lib/EtoForms/ColorScheme.cs b/NAPS2.Lib/EtoForms/ColorScheme.cs index b5b4539e9..909edf980 100644 --- a/NAPS2.Lib/EtoForms/ColorScheme.cs +++ b/NAPS2.Lib/EtoForms/ColorScheme.cs @@ -17,15 +17,21 @@ public class ColorScheme _darkModeProvider.DarkModeChanged += (_, _) => ColorSchemeChanged?.Invoke(this, EventArgs.Empty); } - public Color ForegroundColor => _darkModeProvider.IsDarkModeEnabled ? Colors.White : Colors.Black; + private bool DarkMode => _darkModeProvider.IsDarkModeEnabled; - public Color BackgroundColor => _darkModeProvider.IsDarkModeEnabled ? VeryDarkGray : Colors.White; + public Color ForegroundColor => DarkMode ? Colors.White : Colors.Black; - public Color SeparatorColor => _darkModeProvider.IsDarkModeEnabled ? MidGray : LightGray; + public Color BackgroundColor => DarkMode ? VeryDarkGray : Colors.White; - public Color BorderColor => _darkModeProvider.IsDarkModeEnabled ? LightGray : Colors.Black; + public Color SeparatorColor => DarkMode ? MidGray : LightGray; - public Color CropColor => _darkModeProvider.IsDarkModeEnabled ? HighlightBlue : Colors.Black; + public Color BorderColor => DarkMode ? LightGray : Colors.Black; + + public Color CropColor => DarkMode ? HighlightBlue : Colors.Black; + + public Color NotificationBackgroundColor => DarkMode ? Color.FromRgb(0x323232) : Color.FromRgb(0xf2f2f2); + + public Color NotificationBorderColor => DarkMode ? Color.FromRgb(0x606060) : Color.FromRgb(0xb2b2b2); public event EventHandler? ColorSchemeChanged; } \ No newline at end of file diff --git a/NAPS2.Lib/EtoForms/Notifications/CloseButton.cs b/NAPS2.Lib/EtoForms/Notifications/CloseButton.cs index ea1a413ed..cfeedc49c 100644 --- a/NAPS2.Lib/EtoForms/Notifications/CloseButton.cs +++ b/NAPS2.Lib/EtoForms/Notifications/CloseButton.cs @@ -6,16 +6,15 @@ namespace NAPS2.EtoForms.Notifications; public class CloseButton : Drawable { private const int CLOSE_BUTTON_PADDING = 5; - private static readonly Pen CloseButtonPen = new(new Color(0.7f, 0.7f, 0.7f), 3); - private static readonly Color DefaultBackground = new(0.95f, 0.95f, 0.95f); - private static readonly Color ActiveBackground = new(0.8f, 0.8f, 0.8f); - private static readonly Color HoverBackground = new(0.87f, 0.87f, 0.87f); + + private readonly ColorScheme _colorScheme; private bool _hover; private bool _active; - public CloseButton() + public CloseButton(ColorScheme colorScheme) { + _colorScheme = colorScheme; Cursor = Cursors.Pointer; Paint += OnPaint; MouseEnter += (_, _) => @@ -45,6 +44,17 @@ public class CloseButton : Drawable }; } + private Color PenColor => _colorScheme.NotificationBorderColor; + private Color DefaultBackground => _colorScheme.NotificationBackgroundColor; + private Color HoverBackground => Color.Blend( + _colorScheme.NotificationBackgroundColor, + _colorScheme.NotificationBorderColor, + 0.3f); + private Color ActiveBackground => Color.Blend( + _colorScheme.NotificationBackgroundColor, + _colorScheme.NotificationBorderColor, + 0.6f); + private void OnPaint(object? sender, PaintEventArgs e) { var clearColor = _active && _hover ? ActiveBackground : _hover ? HoverBackground : DefaultBackground; @@ -52,8 +62,9 @@ public class CloseButton : Drawable var w = e.ClipRectangle.Width; var h = e.ClipRectangle.Height; var p = CLOSE_BUTTON_PADDING; - e.Graphics.DrawLine(CloseButtonPen, p - 1, p - 1, w - p, h - p); - e.Graphics.DrawLine(CloseButtonPen, w - p, p - 1, p - 1, h - p); + var pen = new Pen(PenColor, 3); + e.Graphics.DrawLine(pen, p - 1, p - 1, w - p, h - p); + e.Graphics.DrawLine(pen, w - p, p - 1, p - 1, h - p); } public event EventHandler? Click; diff --git a/NAPS2.Lib/EtoForms/Notifications/LinkNotificationView.cs b/NAPS2.Lib/EtoForms/Notifications/LinkNotificationView.cs index d03659194..0b064badb 100644 --- a/NAPS2.Lib/EtoForms/Notifications/LinkNotificationView.cs +++ b/NAPS2.Lib/EtoForms/Notifications/LinkNotificationView.cs @@ -9,8 +9,8 @@ public class LinkNotificationView : NotificationView private readonly string? _linkTarget; private readonly string? _folderTarget; - private readonly Label _label = new() { BackgroundColor = BackgroundColor }; - private readonly LinkButton _link = new() { BackgroundColor = BackgroundColor }; + private readonly Label _label = new(); + private readonly LinkButton _link = new(); private readonly ContextMenu _contextMenu = new(); protected LinkNotificationView( @@ -38,6 +38,11 @@ public class LinkNotificationView : NotificationView }; } + protected override void BeforeCreateContent() + { + _label.BackgroundColor = _link.BackgroundColor = BackgroundColor; + } + protected override LayoutElement PrimaryContent => _label.DynamicWrap(180).MaxWidth(180).Scale(); protected override LayoutElement SecondaryContent => _link; diff --git a/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs b/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs index d7de47457..c1767e47f 100644 --- a/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs +++ b/NAPS2.Lib/EtoForms/Notifications/NotificationManager.cs @@ -2,7 +2,14 @@ namespace NAPS2.EtoForms.Notifications; public class NotificationManager { + public NotificationManager(ColorScheme colorScheme) + { + ColorScheme = colorScheme; + } + public List Notifications { get; } = new(); + + public ColorScheme ColorScheme { get; } public event EventHandler? Updated; diff --git a/NAPS2.Lib/EtoForms/Notifications/NotificationView.cs b/NAPS2.Lib/EtoForms/Notifications/NotificationView.cs index f8d4ad4fb..83b707fd4 100644 --- a/NAPS2.Lib/EtoForms/Notifications/NotificationView.cs +++ b/NAPS2.Lib/EtoForms/Notifications/NotificationView.cs @@ -7,9 +7,6 @@ namespace NAPS2.EtoForms.Notifications; public abstract class NotificationView : IDisposable { - // TODO: Get from color scheme - protected static readonly Color BackgroundColor = new(0.95f, 0.95f, 0.95f); - private static readonly Color BorderColor = new(0.7f, 0.7f, 0.7f); private const int BORDER_RADIUS = 7; private const int CLOSE_BUTTON_SIZE = 18; @@ -33,11 +30,16 @@ public abstract class NotificationView : IDisposable protected abstract LayoutElement SecondaryContent { get; } + protected Color BackgroundColor => Manager!.ColorScheme.NotificationBackgroundColor; + + protected Color BorderColor => Manager!.ColorScheme.NotificationBorderColor; + public LayoutElement CreateContent() { + BeforeCreateContent(); var drawable = new Drawable(); drawable.Paint += DrawableOnPaint; - var closeButton = new CloseButton(); + var closeButton = new CloseButton(Manager!.ColorScheme); closeButton.Click += (_, _) => Manager!.Hide(Model); drawable.MouseUp += (_, _) => NotificationClicked(); drawable.Load += (_, _) => SetUpHideTimeout(drawable); @@ -87,11 +89,15 @@ public abstract class NotificationView : IDisposable } } + protected virtual void BeforeCreateContent() + { + } + protected virtual void NotificationClicked() { } - private static void DrawableOnPaint(object? sender, PaintEventArgs e) + private void DrawableOnPaint(object? sender, PaintEventArgs e) { var w = e.ClipRectangle.Width; var h = e.ClipRectangle.Height; @@ -99,7 +105,7 @@ public abstract class NotificationView : IDisposable e.Graphics.DrawRectangle(BorderColor, 0, 0, w - 1, h - 1); } - private static void DrawWithRoundedCorners(PaintEventArgs e) + private void DrawWithRoundedCorners(PaintEventArgs e) { // TODO: We're not using this as the few pixels on the edges aren't transparent, which is a problem if there's // an image underneath. Not sure if there's a way to make that work but I don't care enough about rounded @@ -109,8 +115,7 @@ public abstract class NotificationView : IDisposable var r = BORDER_RADIUS; var d = r * 2; var q = r / 2; - // TODO: Color scheme background - e.Graphics.Clear(Colors.White); + e.Graphics.Clear(Manager!.ColorScheme.BackgroundColor); // Corners e.Graphics.FillEllipse(BackgroundColor, -1, -1, d, d); e.Graphics.FillEllipse(BackgroundColor, w - d, -1, d, d);