introduce theme files and handle in notification popup

This commit is contained in:
mshafer1
2024-12-21 09:39:43 -06:00
parent 7a5d067343
commit f187cd8ea6
4 changed files with 77 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ using System.Windows.Forms;
using System.ComponentModel;
using Microsoft.Win32;
using System.Diagnostics;
using ntfysh_client.Themes;
namespace ntfysh_client
@@ -21,6 +22,10 @@ namespace ntfysh_client
private System.Windows.Forms.Timer? _updateTimer = null;
private Stopwatch? _shownStopwatch = null;
private BaseTheme _darkModeTheme = new DarkModeTheme();
private BaseTheme _defaultTheme = new DefaultTheme();
private BaseTheme? _theme = null;
public NotificationDialog()
{
ShowInTaskbar = false;
@@ -38,6 +43,17 @@ namespace ntfysh_client
HandleTimeout(null, null);
}
if(showInDarkMode)
{
_theme = _darkModeTheme;
}
else
{
_theme = _defaultTheme;
}
ApplyTheme();
// setup data
IconBox.Image = (icon is null) ? null : ConvertToolTipIconToImage(icon.Value);
@@ -95,6 +111,31 @@ namespace ntfysh_client
SetWindowPosition();
}
private void ApplyTheme()
{
if (_theme is null) _theme = _defaultTheme;
// back colors
BackColor = _theme.BackgroundColor;
TxBTitle.BackColor = _theme.BackgroundColor;
TxBMessage.BackColor = _theme.BackgroundColor;
LblTimeout.BackColor = _theme.BackgroundColor;
ProgressBar1.BackColor = _theme.BackgroundColor;
// this one is not "hiding"
ButtonClose.BackColor = _theme.ControlBackGroundColor;
// handle mouse over
ButtonClose.FlatAppearance.MouseOverBackColor = _theme.ControlMouseOverBackgroundColor;
// fore colors
ForeColor = _theme.ForegroundColor;
TxBTitle.ForeColor = _theme.ForegroundColor;
TxBMessage.ForeColor = _theme.ForegroundColor;
LblTimeout.ForeColor = _theme.ForegroundColor;
ProgressBar1.ForeColor = _theme.ForegroundColor;
ButtonClose.ForeColor = _theme.ForegroundColor;
}
private void UpdateProgress(object? sender, EventArgs e)
{
if (_shownStopwatch is null) return;

View File

@@ -0,0 +1,12 @@
using System.Drawing;
namespace ntfysh_client.Themes
{
internal abstract class BaseTheme
{
public abstract Color BackgroundColor {get; }
public abstract Color ControlBackGroundColor {get; }
public abstract Color ControlMouseOverBackgroundColor { get; }
public abstract Color ForegroundColor { get; }
}
}

View File

@@ -0,0 +1,12 @@
using System.Drawing;
namespace ntfysh_client.Themes
{
internal class DarkModeTheme: BaseTheme
{
public override Color BackgroundColor { get => SystemColors.ControlDark; }
public override Color ControlBackGroundColor { get => Color.Black; }
public override Color ControlMouseOverBackgroundColor { get => Color.Silver; }
public override Color ForegroundColor { get => SystemColors.ControlLight; }
}
}

View File

@@ -0,0 +1,12 @@
using System.Drawing;
namespace ntfysh_client.Themes
{
internal class DefaultTheme: BaseTheme
{
public override Color BackgroundColor { get => Color.White; }
public override Color ControlBackGroundColor { get => SystemColors.ControlDark; }
public override Color ControlMouseOverBackgroundColor { get => Color.LightSkyBlue; }
public override Color ForegroundColor { get => SystemColors.WindowText; }
}
}