ShareX/ShareX.HelpersLib/ShareXResources.cs

182 lines
7.7 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; }
2019-06-25 06:36:16 +12:00
public static bool ExperimentalDarkTheme { 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;
2019-06-25 07:33:17 +12:00
public static int CheckerSize { get; } = 15;
public static Color DarkBackgroundColor { get; } = Color.FromArgb(42, 47, 56);
2019-06-25 09:49:34 +12:00
public static Color DarkBackgroundVariantColor { get; } = ColorHelpers.LighterColor(DarkBackgroundColor, 0.05f);
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-25 06:36:16 +12:00
public static Color DarkLinkColor { get; } = Color.FromArgb(166, 212, 255);
2019-06-25 06:36:16 +12:00
public static void ApplyTheme(Form form, bool setIcon = true)
{
2019-06-25 06:17:33 +12:00
if (setIcon)
{
form.Icon = Icon;
}
2019-06-25 06:36:16 +12:00
if (ExperimentalDarkTheme)
{
2019-06-25 06:36:16 +12:00
ApplyDarkThemeToControl(form);
if (form.IsHandleCreated)
{
2019-06-25 06:36:16 +12:00
NativeMethods.UseImmersiveDarkMode(form.Handle, true);
}
else
{
2019-06-25 06:36:16 +12:00
form.HandleCreated += (s, e) => NativeMethods.UseImmersiveDarkMode(form.Handle, true);
}
}
}
2019-06-25 06:36:16 +12:00
private static void ApplyDarkThemeToControl(Control control)
{
2019-06-25 07:33:17 +12:00
if (control.ContextMenuStrip != null)
{
control.ContextMenuStrip.Renderer = new ToolStripDarkRenderer();
}
if (control is MenuButton mb && mb.Menu != null)
{
mb.Menu.Renderer = new ToolStripDarkRenderer();
}
2019-06-23 23:26:53 +12:00
switch (control)
{
2019-06-23 23:26:53 +12:00
case Button btn:
2019-06-26 04:12:34 +12:00
btn.FlatStyle = FlatStyle.Flat;
btn.FlatAppearance.BorderColor = DarkBorderColor;
btn.ForeColor = DarkTextColor;
btn.BackColor = DarkBackgroundVariantColor;
return;
case CheckBox cb when cb.Appearance == Appearance.Button:
2019-06-24 03:56:19 +12:00
// Buttons looks better with system colors
2019-06-23 23:26:53 +12:00
control.ForeColor = SystemColors.ControlText;
2019-06-24 04:10:20 +12:00
return;
2019-06-25 09:49:34 +12:00
case TextBox tb:
tb.ForeColor = DarkTextColor;
tb.BackColor = DarkBackgroundVariantColor;
tb.BorderStyle = BorderStyle.FixedSingle;
return;
2019-06-23 23:26:53 +12:00
case SplitContainer sc:
2019-06-25 06:36:16 +12:00
sc.Panel1.BackColor = DarkBackgroundColor;
sc.Panel2.BackColor = DarkBackgroundColor;
2019-06-24 04:10:20 +12:00
break;
2019-06-24 01:03:25 +12:00
case PropertyGrid pg:
2019-06-25 06:36:16 +12:00
pg.CategoryForeColor = DarkTextColor;
2019-06-25 09:49:34 +12:00
pg.CategorySplitterColor = DarkBackgroundColor;
pg.LineColor = DarkBackgroundColor;
pg.SelectedItemWithFocusForeColor = DarkBackgroundColor;
2019-06-25 06:36:16 +12:00
pg.SelectedItemWithFocusBackColor = DarkTextColor;
2019-06-25 09:49:34 +12:00
pg.ViewForeColor = DarkTextColor;
pg.ViewBackColor = DarkBackgroundVariantColor;
pg.ViewBorderColor = DarkBorderColor;
pg.HelpForeColor = DarkTextColor;
pg.HelpBackColor = DarkBackgroundColor;
pg.HelpBorderColor = DarkBorderColor;
return;
2019-06-24 03:56:19 +12:00
case DataGridView dgv:
2019-06-25 09:49:34 +12:00
dgv.BackgroundColor = DarkBackgroundVariantColor;
2019-06-25 06:36:16 +12:00
dgv.GridColor = DarkBorderColor;
2019-06-25 09:49:34 +12:00
dgv.DefaultCellStyle.BackColor = DarkBackgroundVariantColor;
dgv.DefaultCellStyle.SelectionBackColor = DarkBackgroundVariantColor;
2019-06-25 06:36:16 +12:00
dgv.DefaultCellStyle.ForeColor = DarkTextColor;
dgv.DefaultCellStyle.SelectionForeColor = DarkTextColor;
2019-06-25 09:49:34 +12:00
dgv.ColumnHeadersDefaultCellStyle.BackColor = DarkBackgroundColor;
dgv.ColumnHeadersDefaultCellStyle.SelectionBackColor = DarkBackgroundColor;
2019-06-25 06:36:16 +12:00
dgv.ColumnHeadersDefaultCellStyle.ForeColor = DarkTextColor;
dgv.ColumnHeadersDefaultCellStyle.SelectionForeColor = DarkTextColor;
2019-06-24 03:56:19 +12:00
dgv.EnableHeadersVisualStyles = false;
2019-06-24 04:10:20 +12:00
break;
2019-06-25 05:59:48 +12:00
case ToolStrip ts:
ts.Renderer = new ToolStripDarkRenderer();
2019-06-25 06:36:16 +12:00
ApplyDarkThemeToToolStripItemCollection(ts.Items);
2019-06-25 05:59:48 +12:00
return;
2019-06-24 04:10:20 +12:00
case LinkLabel ll:
2019-06-25 06:36:16 +12:00
ll.LinkColor = DarkLinkColor;
2019-06-23 23:26:53 +12:00
break;
}
2019-06-25 06:36:16 +12:00
control.ForeColor = DarkTextColor;
control.BackColor = DarkBackgroundColor;
2019-06-24 04:10:20 +12:00
foreach (Control child in control.Controls)
{
2019-06-25 06:36:16 +12:00
ApplyDarkThemeToControl(child);
}
}
2019-06-25 05:59:48 +12:00
2019-06-25 06:36:16 +12:00
private static void ApplyDarkThemeToToolStripItemCollection(ToolStripItemCollection collection)
2019-06-25 05:59:48 +12:00
{
foreach (ToolStripItem tsi in collection)
{
switch (tsi)
{
case ToolStripControlHost tsch:
2019-06-25 06:36:16 +12:00
ApplyDarkThemeToControl(tsch.Control);
2019-06-25 05:59:48 +12:00
break;
case ToolStripDropDownItem tsddi:
2019-06-25 06:36:16 +12:00
ApplyDarkThemeToToolStripItemCollection(tsddi.DropDownItems);
2019-06-25 05:59:48 +12:00
break;
}
}
}
}
}