Skip to content

Commit

Permalink
Fixed Dark Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperHackio committed Nov 16, 2020
1 parent ec0ef07 commit 75b6940
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 103 deletions.
35 changes: 35 additions & 0 deletions WiiExplorer/Extra Controls/ColourToolStripComboBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WiiExplorer
{
public class ColourToolStripComboBox : ToolStripComboBox
{
public ColourToolStripComboBox()
{
base.ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
base.ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
base.ComboBox.DrawItem += (object sender, DrawItemEventArgs e) =>
{
e.DrawBackground();
if (e.State == DrawItemState.Focus)
e.DrawFocusRectangle();
var index = e.Index;
if (index < 0 || index >= Items.Count) return;
var item = Items[index];
string text = (item == null) ? "(null)" : item.ToString();
using (SolidBrush brush = new SolidBrush(e.ForeColor))
{
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
e.Graphics.DrawString(text, e.Font, brush, e.Bounds);
}
};
}

}
}
9 changes: 5 additions & 4 deletions WiiExplorer/FilePropertyForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ public FilePropertyForm(TreeView treeview, RARC archive)
IDNumericUpDown.Enabled = !Archive.KeepFileIDsSynced;
CenterToParent();


AutoDetectSettingsButton.BackColor = BackColor = NameTextBox.BackColor = IDNumericUpDown.BackColor = Program.ProgramColours.ControlBackColor;
AutoDetectSettingsButton.ForeColor = ForeColor = NameTextBox.ForeColor = IDNumericUpDown.ForeColor = Program.ProgramColours.TextColour;
NameTextBox.BorderColor = IDNumericUpDown.BorderColor = Program.ProgramColours.BorderColour;
for (int i = 0; i < Controls.Count; i++)
{
Controls[i].BackColor = Program.ProgramColours.ControlBackColor;
Controls[i].ForeColor = Program.ProgramColours.TextColour;
}
AutoDetectSettingsButton.BackColor = BackColor = Program.ProgramColours.ControlBackColor;
AutoDetectSettingsButton.ForeColor = ForeColor = NameTextBox.ForeColor = IDNumericUpDown.ForeColor = Program.ProgramColours.TextColour;
NameTextBox.BackColor = IDNumericUpDown.BackColor = Program.ProgramColours.WindowColour;
NameTextBox.BorderColor = IDNumericUpDown.BorderColor = Program.ProgramColours.BorderColour;
//FileSettingsGroupBox.BackColor = Program.ProgramColours.WindowColour;
}

private void FilePropertyForm_Load(object sender, EventArgs e)
Expand Down
23 changes: 11 additions & 12 deletions WiiExplorer/MainForm.Designer.cs

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

86 changes: 50 additions & 36 deletions WiiExplorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.WindowsAPICodePack.Dialogs;
using System.Diagnostics;
using WiiExplorer.Properties;
using System.Reflection;

namespace WiiExplorer
{
Expand All @@ -33,6 +34,7 @@ public MainForm(string Openwith)

RootNameTextBox.ContextMenu = new ContextMenu();
ReloadTheme();
Yaz0ToolStripComboBox.ComboBox.SetDoubleBuffered();
}

private void MainForm_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -88,8 +90,8 @@ private void DrawLeafTopPlaceholders(TreeNode NodeOver, TreeView Tree)
new Point(RightPos, NodeOver.Bounds.Top - 5)};


g.FillPolygon(System.Drawing.Brushes.Black, LeftTriangle);
g.FillPolygon(System.Drawing.Brushes.Black, RightTriangle);
g.FillPolygon(Brushes.Black, LeftTriangle);
g.FillPolygon(Brushes.Black, RightTriangle);
g.DrawLine(new System.Drawing.Pen(Color.Black, 2), new Point(LeftPos, NodeOver.Bounds.Top), new Point(RightPos, NodeOver.Bounds.Top));

}//eom
Expand Down Expand Up @@ -122,8 +124,8 @@ private void DrawLeafBottomPlaceholders(TreeNode NodeOver, TreeNode ParentDragDr
new Point(RightPos, NodeOver.Bounds.Bottom - 5)};


g.FillPolygon(System.Drawing.Brushes.Black, LeftTriangle);
g.FillPolygon(System.Drawing.Brushes.Black, RightTriangle);
g.FillPolygon(Brushes.Black, LeftTriangle);
g.FillPolygon(Brushes.Black, RightTriangle);
g.DrawLine(new System.Drawing.Pen(Color.Black, 2), new Point(LeftPos, NodeOver.Bounds.Bottom), new Point(RightPos, NodeOver.Bounds.Bottom));
}//eom

Expand Down Expand Up @@ -151,8 +153,8 @@ private void DrawFolderTopPlaceholders(TreeNode NodeOver, TreeView Tree)
new Point(RightPos, NodeOver.Bounds.Top - 5)};


g.FillPolygon(System.Drawing.Brushes.Black, LeftTriangle);
g.FillPolygon(System.Drawing.Brushes.Black, RightTriangle);
g.FillPolygon(Brushes.Black, LeftTriangle);
g.FillPolygon(Brushes.Black, RightTriangle);
g.DrawLine(new System.Drawing.Pen(Color.Black, 2), new Point(LeftPos, NodeOver.Bounds.Top), new Point(RightPos, NodeOver.Bounds.Top));

}//eom
Expand All @@ -168,7 +170,7 @@ private void DrawAddToFolderPlaceholder(TreeNode NodeOver, TreeView Tree)
new Point(RightPos, NodeOver.Bounds.Y + (NodeOver.Bounds.Height / 2) - 5)};

this.Refresh();
g.FillPolygon(System.Drawing.Brushes.Black, RightTriangle);
g.FillPolygon(Brushes.Black, RightTriangle);
}//eom

private void SetNewNodeMap(TreeNode tnNode, bool boolBelowNode)
Expand Down Expand Up @@ -517,8 +519,8 @@ private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!(Edited && MessageBox.Show("You have unsaved changes.\nAre you sure you want to open another file?", "Unsaved Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No))
{
ofd.InitialDirectory = Properties.Settings.Default.PreviousOpenArchivePath;
string tmp = Properties.Settings.Default.PreviousOpenArchivePath;
ofd.InitialDirectory = Settings.Default.PreviousOpenArchivePath;
string tmp = Settings.Default.PreviousOpenArchivePath;
if (ofd.ShowDialog() == DialogResult.OK && ofd.FileName != "")
OpenArchive(ofd.FileName);
}
Expand All @@ -539,15 +541,15 @@ private void OpenArchive(string Filename)
MainToolStripProgressBar.Value = 100;
MainToolStripStatusLabel.Text = $"Archive loaded successfully!";
Text = $"WiiExplorer {Application.ProductVersion} - {new FileInfo(Filename).Name}";
Properties.Settings.Default.PreviousOpenArchivePath = new FileInfo(Filename).DirectoryName;
Properties.Settings.Default.Save();
Settings.Default.PreviousOpenArchivePath = new FileInfo(Filename).DirectoryName;
Settings.Default.Save();
}

private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Archive.FileName is null)
{
sfd.InitialDirectory = Properties.Settings.Default.PreviousSaveArchivePath;
sfd.InitialDirectory = Settings.Default.PreviousSaveArchivePath;
if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != "")
SaveArchive(sfd.FileName);
else
Expand All @@ -559,7 +561,7 @@ private void SaveToolStripMenuItem_Click(object sender, EventArgs e)

private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
sfd.InitialDirectory = Properties.Settings.Default.PreviousSaveArchivePath;
sfd.InitialDirectory = Settings.Default.PreviousSaveArchivePath;
if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != "")
SaveArchive(sfd.FileName);
}
Expand Down Expand Up @@ -588,8 +590,8 @@ private void SaveArchive(string Filename)
MainToolStripStatusLabel.Text = $"Archive saved successfully!{(Program.Yaz0Mode != 0 ? $" ({timer.Elapsed.ToString("mm\\:ss")} Elapsed)":"")}";
SetControlsEnabled(affectall:true);
Text = $"WiiExplorer {Application.ProductVersion} - {new FileInfo(Filename).Name}";
Properties.Settings.Default.PreviousSaveArchivePath = new FileInfo(Filename).DirectoryName;
Properties.Settings.Default.Save();
Settings.Default.PreviousSaveArchivePath = new FileInfo(Filename).DirectoryName;
Settings.Default.Save();
}

private void AddFileToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -713,8 +715,8 @@ private void ExportAllToolStripMenuItem_Click(object sender, EventArgs e)
Archive.Export(new DirectoryInfo(Exportsfd.FileName).Parent.FullName, true);
MainToolStripProgressBar.Value = 100;
MainToolStripStatusLabel.Text = $"Full Archive \"{Archive.Root.Name}\" has been saved!";
Properties.Settings.Default.PreviousExportPath = new DirectoryInfo(Exportsfd.FileName).Parent.FullName;
Properties.Settings.Default.Save();
Settings.Default.PreviousExportPath = new DirectoryInfo(Exportsfd.FileName).Parent.FullName;
Settings.Default.Save();
}
}

Expand Down Expand Up @@ -824,8 +826,8 @@ private void ExportArchiveFile(dynamic Item)
Directory.CreateDirectory(Exportsfd.FileName);
Item.Export(Exportsfd.FileName);
MainToolStripStatusLabel.Text = $"\"{Item.Name}\" has been saved!";
Properties.Settings.Default.PreviousExportPath = new DirectoryInfo(Exportsfd.FileName).Parent.FullName;
Properties.Settings.Default.Save();
Settings.Default.PreviousExportPath = new DirectoryInfo(Exportsfd.FileName).Parent.FullName;
Settings.Default.Save();
}
}
else
Expand All @@ -841,14 +843,14 @@ private void ExportArchiveFile(dynamic Item)
}
}
Exportsfd.Filter = ext;
Exportsfd.InitialDirectory = Properties.Settings.Default.PreviousExportPath;
Exportsfd.InitialDirectory = Settings.Default.PreviousExportPath;
if (Exportsfd.ShowDialog() == DialogResult.OK && Exportsfd.FileName != "")
{
Item.Save(Exportsfd.FileName);
MainToolStripStatusLabel.Text = $"\"{Item.Name}\" has been saved!";

Properties.Settings.Default.PreviousExportPath = new FileInfo(Exportsfd.FileName).DirectoryName;
Properties.Settings.Default.Save();
Settings.Default.PreviousExportPath = new FileInfo(Exportsfd.FileName).DirectoryName;
Settings.Default.Save();
}
}
}
Expand Down Expand Up @@ -915,7 +917,7 @@ private void NewFromFolderToolStripMenuItem_Click(object sender, EventArgs e)
if (Edited && MessageBox.Show("You have unsaved changes.\nAre you sure you want to start a new file?", "Unsaved Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
return;

CommonOpenFileDialog BFB = new CommonOpenFileDialog() { InitialDirectory = Properties.Settings.Default.PreviousAddFilePath, Multiselect = false, IsFolderPicker = true };
CommonOpenFileDialog BFB = new CommonOpenFileDialog() { InitialDirectory = Settings.Default.PreviousAddFilePath, Multiselect = false, IsFolderPicker = true };
if (BFB.ShowDialog() == CommonFileDialogResult.Ok && !BFB.FileName.Equals(""))
{
Archive = new RARC();
Expand All @@ -924,8 +926,8 @@ private void NewFromFolderToolStripMenuItem_Click(object sender, EventArgs e)
RootNameTextBox.Text = Archive.Root.Name;
KeepIDsSyncedCheckBox.Checked = Archive.KeepFileIDsSynced;
ArchiveTreeView.Nodes.AddRange(Archive.ToTreeNode(0, ArchiveImageList));
Properties.Settings.Default.PreviousAddFilePath = new DirectoryInfo(BFB.FileName).Parent.FullName;
Properties.Settings.Default.Save();
Settings.Default.PreviousAddFilePath = new DirectoryInfo(BFB.FileName).Parent.FullName;
Settings.Default.Save();

Edited = true;
SetControlsEnabled();
Expand Down Expand Up @@ -987,6 +989,11 @@ private void SwitchThemeToolStripMenuItem_Click(object sender, EventArgs e)

private void ReloadTheme()
{
for (int i = 0; i < Controls.Count; i++)
{
Controls[i].BackColor = Program.ProgramColours.ControlBackColor;
Controls[i].ForeColor = Program.ProgramColours.TextColour;
}
ForeColor = Program.ProgramColours.TextColour;
BackColor = Program.ProgramColours.ControlBackColor;
MainFormMenuStrip.Renderer = Settings.Default.IsDarkMode ? new MyRenderer() : default;
Expand All @@ -1006,16 +1013,9 @@ private void ReloadTheme()
ArchiveContextMenuStrip.Items[i].BackColor = Program.ProgramColours.WindowColour;
ArchiveContextMenuStrip.Items[i].ForeColor = Program.ProgramColours.TextColour;
}
Yaz0ToolStripComboBox.BackColor = Program.ProgramColours.WindowColour;
Yaz0ToolStripComboBox.ForeColor = Program.ProgramColours.TextColour;
RootNameTextBox.BackColor = RootNameTextBox.BorderColor = Program.ProgramColours.ControlBackColor;
RootNameTextBox.ForeColor = KeepIDsSyncedCheckBox.ForeColor = Program.ProgramColours.TextColour;
for (int i = 0; i < Controls.Count; i++)
{
Controls[i].BackColor = Program.ProgramColours.ControlBackColor;
Controls[i].ForeColor = Program.ProgramColours.TextColour;
}
MainToolStripProgressBar.BackColor = Program.ProgramColours.WindowColour;
MainToolStripProgressBar.BackColor = RootNameTextBox.BackColor = Yaz0ToolStripComboBox.BackColor = ArchiveTreeView.BackColor = Program.ProgramColours.WindowColour;
RootNameTextBox.BorderColor = Program.ProgramColours.BorderColour;
Yaz0ToolStripComboBox.ForeColor = RootNameTextBox.ForeColor = KeepIDsSyncedCheckBox.ForeColor = Program.ProgramColours.TextColour;
}

#region MenuStrip Managers
Expand Down Expand Up @@ -1160,9 +1160,11 @@ private void MainFormMenuStrip_Paint(object sender, PaintEventArgs e)
cb.ComboBox.Size.Height + 1);

Pen cbBorderPen = new Pen(Program.ProgramColours.BorderColour);
e.Graphics.FillRectangle(cbBorderPen.Brush, r);
e.Graphics.DrawRectangle(cbBorderPen, r);
}
}
if (!Yaz0ToolStripComboBox.ComboBox.DroppedDown)
RootNameLabel.Focus();
}

private void MainForm_KeyDown(object sender, KeyEventArgs e)
Expand All @@ -1176,4 +1178,16 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e)
}
}
}

public static class ControlEx
{
[DebuggerStepThrough]
public static void SetDoubleBuffered(this Control control)
{
// set instance non-public property with name "DoubleBuffered" to true
typeof(Control).InvokeMember("DoubleBuffered",
BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, control, new object[] { true });
}
}
}
Loading

0 comments on commit 75b6940

Please sign in to comment.