ShareX/ShareX.HelpersLib/ShareXResources.cs

118 lines
4.6 KiB
C#
Raw Normal View History

#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2019-01-02 20:43:52 +13:00
Copyright (c) 2007-2019 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
2014-12-11 09:25:20 +13:00
using ShareX.HelpersLib.Properties;
2018-11-06 12:40:05 +13:00
using System;
using System.Drawing;
2018-11-06 12:40:05 +13:00
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
namespace ShareX.HelpersLib
{
public static class ShareXResources
{
2018-11-06 12:40:05 +13:00
public static string UserAgent
{
get
{
Version version = Version.Parse(Application.ProductVersion);
return $"ShareX/{version.Major}.{version.Minor}.{version.Build}";
}
}
public static bool UseDarkTheme { get; set; }
public static bool UseWhiteIcon { get; set; }
public static bool ApplyTheme { get; set; } = true;
public static Icon Icon => UseWhiteIcon ? Resources.ShareX_Icon_White : Resources.ShareX_Icon;
public static Image Logo => Resources.ShareX_Logo;
public static Image LogoBlack => Resources.ShareX_Logo_Black;
public static Color BackgroundColor => UseDarkTheme ? DarkBackgroundColor : SystemColors.Window;
public static Color TextColor => UseDarkTheme ? DarkTextColor : SystemColors.ControlText;
public static Color BorderColor => UseDarkTheme ? DarkBorderColor : ProfessionalColors.SeparatorDark;
public static Color CheckerColor1 => UseDarkTheme ? DarkCheckerColor1 : SystemColors.ControlLightLight;
public static Color CheckerColor2 => UseDarkTheme ? DarkCheckerColor2 : SystemColors.ControlLight;
public static Color DarkBackgroundColor { get; } = Color.FromArgb(42, 47, 56);
public static Color DarkTextColor { get; } = Color.FromArgb(235, 235, 235);
public static Color DarkBorderColor { get; } = Color.FromArgb(28, 32, 38);
public static Color DarkCheckerColor1 { get; } = Color.FromArgb(60, 60, 60);
public static Color DarkCheckerColor2 { get; } = Color.FromArgb(50, 50, 50);
2019-06-03 07:45:15 +12:00
public static int CheckerSize { get; } = 15;
public static void ApplyThemeToForm(Form form)
{
form.Icon = Icon;
if (ApplyTheme)
{
ApplyThemeToControl(form);
if (form.IsHandleCreated)
{
NativeMethods.UseImmersiveDarkMode(form.Handle, UseDarkTheme);
}
else
{
form.HandleCreated += (s, e) => NativeMethods.UseImmersiveDarkMode(form.Handle, UseDarkTheme);
}
}
}
private static void ApplyThemeToControl(Control control)
{
2019-06-23 23:26:53 +12:00
switch (control)
{
2019-06-23 23:26:53 +12:00
case Button btn:
case CheckBox cb when cb.Appearance == Appearance.Button:
2019-06-23 23:26:53 +12:00
// Button looks better with system colors
control.ForeColor = SystemColors.ControlText;
break;
case SplitContainer sc:
sc.Panel1.BackColor = BackgroundColor;
sc.Panel2.BackColor = BackgroundColor;
goto default;
2019-06-24 01:03:25 +12:00
case PropertyGrid pg:
pg.CategoryForeColor = TextColor;
pg.CategorySplitterColor = BorderColor;
pg.LineColor = BorderColor;
pg.SelectedItemWithFocusForeColor = BorderColor;
pg.SelectedItemWithFocusBackColor = TextColor;
goto default;
2019-06-23 23:26:53 +12:00
default:
control.ForeColor = TextColor;
control.BackColor = BackgroundColor;
break;
}
foreach (Control child in control.Controls)
{
ApplyThemeToControl(child);
}
}
}
}