Skip to content

Commit

Permalink
Implemented dark theme (#5)
Browse files Browse the repository at this point in the history
Not really perfect, the tabs look quite ugly and the scrollbars still write, but 95% of the controls are dark. I will probably try to add custom tabcontrol and scrollbars. Why not :D
  • Loading branch information
AndnixSH committed May 9, 2023
1 parent ab629c2 commit ee0fa89
Show file tree
Hide file tree
Showing 19 changed files with 524 additions and 91 deletions.
11 changes: 9 additions & 2 deletions APKToolGUI/APKToolGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
<HintPath>..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll</HintPath>
</Reference>
<Reference Include="CustomMarshalers" />
<Reference Include="DarkNet, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DarkNet.2.2.0\lib\net452\DarkNet.dll</HintPath>
</Reference>
<Reference Include="DotNetZip, Version=1.16.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll</HintPath>
</Reference>
Expand All @@ -101,6 +104,9 @@
<Reference Include="Ookii.Dialogs.WinForms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=66aa232afad40158, processorArchitecture=MSIL">
<HintPath>..\packages\Ookii.Dialogs.WinForms.4.0.0\lib\net462\Ookii.Dialogs.WinForms.dll</HintPath>
</Reference>
<Reference Include="OSVersionExt, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OSVersionExt.2.0.0\lib\net462\OSVersionExt.dll</HintPath>
</Reference>
<Reference Include="PortableSettingsProvider, Version=0.2.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\PortableSettingsProvider.0.2.4\lib\net45\PortableSettingsProvider.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -317,6 +323,7 @@
<Compile Include="Handlers\SignControlEventHandlers.cs" />
<Compile Include="Handlers\SmaliControlEventHandlers.cs" />
<Compile Include="Handlers\ZipalignControlEventHandlers.cs" />
<Compile Include="Controls\DarkTheme.cs" />
<Compile Include="Utils\AdminUtils.cs" />
<Compile Include="Utils\BitmapUtils.cs" />
<Compile Include="Utils\CMD.cs" />
Expand Down Expand Up @@ -455,16 +462,16 @@
<Error Condition="!Exists('..\packages\Costura.Fody.5.7.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.5.7.0\build\Costura.Fody.props'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets'))" />
<Error Condition="!Exists('..\packages\Fody.6.6.4\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.6.4\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Resource.Embedder.2.2.0\build\Resource.Embedder.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Resource.Embedder.2.2.0\build\Resource.Embedder.props'))" />
<Error Condition="!Exists('..\packages\Fody.6.7.0\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.7.0\build\Fody.targets'))" />
</Target>
<Import Project="..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.5.7.0\build\Costura.Fody.targets')" />
<Import Project="..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
<Import Project="..\packages\Fody.6.6.4\build\Fody.targets" Condition="Exists('..\packages\Fody.6.6.4\build\Fody.targets')" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="..\packages\Fody.6.7.0\build\Fody.targets" Condition="Exists('..\packages\Fody.6.7.0\build\Fody.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
224 changes: 224 additions & 0 deletions APKToolGUI/Controls/DarkTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;

namespace APKToolGUI.Controls
{
internal class DarkTheme
{
static Color bgColor = Color.FromArgb(32, 32, 32);
static Color txtBoxColor = Color.FromArgb(64, 64, 64);
static Color btnColor = Color.FromArgb(51, 51, 51);
static Color btnBorderColor = Color.FromArgb(155, 155, 155);
static Color tabBorderColor = Color.FromArgb(45, 45, 45);
static Color menuItemHoverColor = Color.FromArgb(51, 51, 51);
static Color menuItemSelectedColor = Color.FromArgb(41, 41, 41);

public static void SetTheme(Control.ControlCollection container, Form form)
{
form.BackColor = bgColor;
form.ForeColor = Color.White;

foreach (Control component in container)
{
Debug.WriteLine(component.GetType());
component.BackColor = bgColor;
component.ForeColor = Color.White;

SetThemeTabControl(component);
}
}

public static void SetThemeTabControl(Control component)
{
if (component is TabControl)
{
((TabControl)component).DrawMode = TabDrawMode.OwnerDrawFixed;

foreach (Control tabControl in component.Controls)
{
SetThemeTabControl(tabControl);

Debug.WriteLine("tabPage " + tabControl.GetType());

((TabControl)component).DrawItem += (sender, e) =>
{
// Set Border header
e.Graphics.FillRectangle(new SolidBrush(tabBorderColor), e.Bounds);
Rectangle paddedBounds = e.Bounds;

paddedBounds.Inflate(0, 0);

// Set the rectangle for the tab button
Rectangle tabRect = ((TabControl)component).GetTabRect(e.Index);

// Draw the border color
using (Pen borderPen = new Pen(tabBorderColor, 7))
{
e.Graphics.DrawRectangle(borderPen, tabRect);
}

StringFormat stringFlags = new StringFormat();
stringFlags.Alignment = StringAlignment.Center;
stringFlags.LineAlignment = StringAlignment.Center;

e.Graphics.DrawString(((TabControl)component).TabPages[e.Index].Text, FormMain.Instance.Font, SystemBrushes.HighlightText, tabRect, stringFlags);

//set Tabcontrol border
Graphics g = e.Graphics;
Pen p = new Pen(tabBorderColor, 8);
g.DrawRectangle(p, tabControl.Bounds.X, tabControl.Bounds.Y, tabControl.Bounds.Width, tabControl.Bounds.Height);

SolidBrush fillbrush = new SolidBrush(bgColor);

//draw rectangle behind the tabs
Rectangle lasttabrect = ((TabControl)component).GetTabRect(((TabControl)component).TabPages.Count - 1);
Rectangle background = new Rectangle();
background.Location = new Point(lasttabrect.Right, 0);

//pad the rectangle to cover the 1 pixel line between the top of the tabpage and the start of the tabs
background.Size = new Size(((TabControl)component).Right - background.Left, lasttabrect.Height + 1);
e.Graphics.FillRectangle(fillbrush, background);
};

foreach (Control tabPage in tabControl.Controls)
{
SetThemeTabControl(tabPage);
}
}
}
else if (component is Panel)
{
foreach (Control control in component.Controls)
{
SetThemeTabControl(control);
}
component.BackColor = bgColor;
component.ForeColor = Color.White;
}
if (component is MenuStrip menuStrip)
{
((MenuStrip)component).Renderer = new ToolStripProfessionalRenderer(new MenuItemColorTable());

foreach (ToolStripItem item in menuStrip.Items)
{
if (item is ToolStripMenuItem toolStripMenuItem)
{
foreach (ToolStripMenuItem dditem in toolStripMenuItem.DropDownItems)
{
dditem.BackColor = bgColor;
dditem.ForeColor = Color.White;
Debug.WriteLine(dditem.Text);
}

toolStripMenuItem.BackColor = bgColor;
toolStripMenuItem.ForeColor = Color.White;
}
}
}
else if (component is GroupBox)
{
foreach (Control control in component.Controls)
{
SetThemeTabControl(control);
}
component.BackColor = bgColor;
component.ForeColor = Color.White;
}
else if (component is ComboBox)
{
component.BackColor = bgColor;
component.ForeColor = Color.White;
((ComboBox)component).FlatStyle = FlatStyle.Flat;
}
else if (component is Button)
{
component.BackColor = btnColor;
component.ForeColor = Color.White;
((Button)component).FlatStyle = FlatStyle.Flat;
((Button)component).FlatAppearance.BorderColor = btnBorderColor;

}
else if (component is TextBox)
{
foreach (Control panel in component.Controls)
{
SetThemeTabControl(panel);
}
component.BackColor = txtBoxColor;
component.ForeColor = Color.White;
((TextBox)component).BorderStyle = BorderStyle.FixedSingle;
}
else if (component is RichTextBox)
{
((RichTextBox)component).BorderStyle = BorderStyle.None;
component.BackColor = bgColor;
component.ForeColor = Color.White;
}
else
{
component.BackColor = bgColor;
component.ForeColor = Color.White;
}
}

public class MenuItemColorTable : ProfessionalColorTable
{
public override Color ImageMarginGradientBegin
{
get { return bgColor; }
}

public override Color ImageMarginGradientEnd
{
get { return bgColor; }
}

public override Color ToolStripDropDownBackground
{
get { return bgColor; }
}

public override Color MenuItemSelected
{
get { return menuItemHoverColor; }
}

public override Color MenuBorder
{
get { return menuItemHoverColor; }
}

public override Color MenuItemBorder
{
get { return menuItemHoverColor; }
}

public override Color MenuItemSelectedGradientBegin
{
get { return menuItemSelectedColor; }
}

public override Color MenuItemSelectedGradientEnd
{
get { return menuItemSelectedColor; }
}
public override Color MenuItemPressedGradientBegin
{
get { return menuItemSelectedColor; }
}

public override Color MenuItemPressedGradientEnd
{
get { return menuItemSelectedColor; }
}
}
}
}
1 change: 1 addition & 0 deletions APKToolGUI/Forms/FormAboutBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion APKToolGUI/Forms/FormAboutBox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using APKToolGUI.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
Expand All @@ -13,6 +14,10 @@ partial class FormAboutBox : Form
public FormAboutBox()
{
InitializeComponent();

if (Program.IsDarkTheme())
DarkTheme.SetTheme(Controls, this);

this.Text = String.Format("{0} {1}", this.Text, AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("{0} {1}", labelVersion.Text, AssemblyVersion);
Expand Down
20 changes: 10 additions & 10 deletions APKToolGUI/Forms/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ee0fa89

Please sign in to comment.