Skip to content
Snippets Groups Projects
Commit 1d50d95e authored by DamianKomdeur's avatar DamianKomdeur
Browse files

Merge branch 'MainForm'

Merge main menu and settings menu
parent fba44f8f
No related branches found
No related tags found
No related merge requests found
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using static System.Windows.Forms.DataFormats;
namespace PuzzlePlayer_Namespace namespace PuzzlePlayer_Namespace
{ {
...@@ -9,7 +11,7 @@ namespace PuzzlePlayer_Namespace ...@@ -9,7 +11,7 @@ namespace PuzzlePlayer_Namespace
{ {
internal static void Main(string[] args) internal static void Main(string[] args)
{ {
Application.Run(new PuzzleForm(new Binary(6))); Application.Run(new MainForm());
} }
} }
...@@ -17,33 +19,123 @@ namespace PuzzlePlayer_Namespace ...@@ -17,33 +19,123 @@ namespace PuzzlePlayer_Namespace
{ {
List<PuzzleForm> puzzleForms = new List<PuzzleForm>(); List<PuzzleForm> puzzleForms = new List<PuzzleForm>();
public Panel buttonsPanel;
public Button[] buttons;
public MainForm() public MainForm()
{ {
this.ClientSize = new Size(1000, 500);
SetUpPuzzleForms(); SetUpPuzzleForms();
SetUpUI(); SetUpUI();
} }
private void SetUpPuzzleForms() private void SetUpPuzzleForms()
{ {
puzzleForms.Add(new PuzzleForm(new Binary())); for (int i = 0; i < 5; i++)
{
puzzleForms.Add(new PuzzleForm(new Binair()));
}
puzzleForms.Add(new PuzzleForm(new Binair()));
} }
private void SetUpUI() private void SetUpUI()
{ {
buttons = new Button[puzzleForms.Count]; // -- List<RoundedButton> buttons = new List<RoundedButton>();
//binair. this.ClientSize = new Size(1115, 755);
this.BackColor = SettingForm.primaryColor;
this.Text = "PuzzlePlayer";
MenuStrip menuStrip = new MenuStrip
{
BackColor = SettingForm.secondaryColor,
ForeColor = SettingForm.secondaryColor,
Name = "Main menu",
Text = "Main Menu",
Dock = DockStyle.Top,
Font = SettingForm.mainFont,
};
ToolStripMenuItem menuSettings = new ToolStripMenuItem
{
BackColor = Color.FromArgb(54, 57, 62),
ForeColor = Color.Black,
Text = "Settings",
TextAlign = ContentAlignment.BottomRight,
Font = SettingForm.mainFont,
};
menuSettings.Click += (object o, EventArgs e) =>
{
this.Hide();
SettingForm settingForm = new SettingForm();
settingForm.FormClosed += (object s, FormClosedEventArgs args) =>
{
this.BackColor = SettingForm.primaryColor;
this.ForeColor = SettingForm.tertiaryColor;
foreach (Control control in this.Controls)
{
SettingForm.UpdateSettings(control);
}
this.Show();
};
settingForm.Show();
};
// Create a flow layout panel that automatically sorts the buttons when the window is resized
FlowLayoutPanel buttonsPanel = new FlowLayoutPanel
{
Location = new Point(0, menuStrip.Height),
Size = new Size(ClientSize.Width, ClientSize.Height - menuStrip.Height),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom,
FlowDirection = FlowDirection.LeftToRight,
// Add another row if there are more buttons than that fit in the window horizontally
WrapContents = true,
// Add a scroll bar in case the buttons don't fit on the window vertically
AutoScroll = true,
};
// Add a button for each puzzle type
for (int i = 0; i < puzzleForms.Count; i++)
{
string image = "../../..//Resources/" + $"{puzzleForms[i].puzzleType}";
// Set the name of the button
RoundedButton button = new RoundedButton
{
Text = puzzleForms[i].puzzleType,
Margin = new Padding(10),
Height = 345,
Width = 345,
Image = Image.FromFile(image + ".jpg"),
FlatStyle = FlatStyle.Flat,
Font = SettingForm.mainFont,
};
button.MouseEnter += (object o, EventArgs e) =>
{
button.Image = Image.FromFile(image + "Gray.jpg");
};
button.MouseLeave += (object o, EventArgs e) =>
{
button.Image = Image.FromFile(image + ".jpg");
};
buttonsPanel.Controls.Add(button);
// -- buttons.Add(button);
if (i == 0)
{
this.MinimumSize = new Size(button.Width + 56, button.Height + 83);
}
}
this.Controls.Add(menuStrip);
this.Controls.Add(buttonsPanel);
menuStrip.Items.Add(menuSettings);
menuStrip.BringToFront();
} }
} }
} }
...@@ -5,5 +5,11 @@ ...@@ -5,5 +5,11 @@
<Compile Update="PuzzleForm.cs"> <Compile Update="PuzzleForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Update="RoundedButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Update="SettingForm.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
PuzzlePlayer/Resources/Binair.jpg

36.3 KiB

PuzzlePlayer/Resources/BinairGray.jpg

34.7 KiB

using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Windows.Forms;
namespace PuzzlePlayer_Namespace
{
class RoundedButton : Button
{
GraphicsPath GetRoundPath(RectangleF Rect, int radius)
{
float r2 = radius / 2f;
GraphicsPath GraphPath = new GraphicsPath();
GraphPath.AddArc(Rect.X, Rect.Y, radius, radius, 180, 90);
GraphPath.AddLine(Rect.X + r2, Rect.Y, Rect.Width - r2, Rect.Y);
GraphPath.AddArc(Rect.X + Rect.Width - radius, Rect.Y, radius, radius, 270, 90);
GraphPath.AddLine(Rect.Width, Rect.Y + r2, Rect.Width, Rect.Height - r2);
GraphPath.AddArc(Rect.X + Rect.Width - radius,
Rect.Y + Rect.Height - radius, radius, radius, 0, 90);
GraphPath.AddLine(Rect.Width - r2, Rect.Height, Rect.X + r2, Rect.Height);
GraphPath.AddArc(Rect.X, Rect.Y + Rect.Height - radius, radius, radius, 90, 90);
GraphPath.AddLine(Rect.X, Rect.Height - r2, Rect.X, Rect.Y + r2);
GraphPath.CloseFigure();
return GraphPath;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
RectangleF Rect = new RectangleF(0, 0, this.Width, this.Height);
using (GraphicsPath GraphPath = GetRoundPath(Rect, 50))
{
this.Region = new Region(GraphPath);
using (Pen pen = new Pen(Color.Black, 1.75f))
{
pen.Alignment = PenAlignment.Inset;
e.Graphics.DrawPath(pen, GraphPath);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace PuzzlePlayer_Namespace
{
internal class SettingForm : Form
{
// Public variables for all settings
public static Color primaryColor = Color.FromArgb(66, 69, 73);
public static Color secondaryColor = Color.FromArgb(54, 57, 62);
public static Color tertiaryColor = Color.FromArgb(66, 69, 73);
public static int fontSize = 16;
public static Font mainFont = new Font("Gotham", fontSize);
public SettingForm()
{
SetUpUi();
this.BackColor = primaryColor;
foreach (Control control in Controls)
{
UpdateSettings(control);
}
Invalidate();
}
private void SetUpUi()
{
this.ClientSize = new Size(1115, 755);
this.BackColor = SettingForm.primaryColor;
this.Text = "PuzzlePlayer";
MenuStrip menuStrip = new MenuStrip
{
BackColor = secondaryColor,
ForeColor = secondaryColor,
Name = "Main menu",
Text = "Main Menu",
Dock = DockStyle.Top
};
ToolStripMenuItem menuBack = new ToolStripMenuItem
{
BackColor = secondaryColor,
ForeColor = Color.Black,
Text = "Back",
TextAlign = ContentAlignment.BottomRight
};
menuBack.Click += (object o, EventArgs e) =>
{
this.Close();
};
//
ComboBox themeSelector = new ComboBox
{
Text = "Theme",
Name = "Theme",
Height = 25,
Width = 250,
BackColor = SettingForm.secondaryColor,
ForeColor = Color.Black,
Margin = new Padding(20)
};
themeSelector.Items.Add("Dark");
themeSelector.Items.Add("Light");
themeSelector.SelectedIndexChanged += (object o, EventArgs e) =>
{
switch (themeSelector.Text)
{
case "Dark":
SettingForm.primaryColor = Color.FromArgb(66, 69, 73);
SettingForm.secondaryColor = Color.FromArgb(54, 57, 62);
SettingForm.tertiaryColor = Color.FromArgb(0, 0, 0);
break;
case "Light":
SettingForm.primaryColor = Color.FromArgb(228, 229, 241);
SettingForm.secondaryColor = Color.FromArgb(210, 211, 219);
SettingForm.tertiaryColor = Color.FromArgb(72, 75, 106);
break;
}
};
ComboBox sizeSelector = new ComboBox
{
Text = "Size",
Name = "Size",
Height = 25,
Width = 250,
BackColor = SettingForm.secondaryColor,
ForeColor = Color.Black,
Margin = new Padding(20)
};
sizeSelector.Items.Add("Small");
sizeSelector.Items.Add("Medium");
sizeSelector.Items.Add("Large");
sizeSelector.SelectedIndexChanged += (object o, EventArgs e) =>
{
switch (sizeSelector.Text)
{
case "Small":
fontSize = 8;
break;
case "Medium":
fontSize = 16;
break;
case "Large":
fontSize = 24;
break;
}
mainFont = new Font("Gotham", fontSize);
};
FlowLayoutPanel settingsPanel = new FlowLayoutPanel
{
Location = new Point(0, menuStrip.Height),
Size = new Size(ClientSize.Width, ClientSize.Height - menuStrip.Height - 100),
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom,
FlowDirection = FlowDirection.TopDown,
WrapContents = true,
AutoScroll = true,
};
//
RoundedButton saveButton = new RoundedButton
{
Text = "Save",
Name = "Save",
Height = 100,
Width = 350,
BackColor = SettingForm.secondaryColor,
ForeColor = Color.Black,
Location = new Point(10, ClientSize.Height - 110),
Anchor = AnchorStyles.Left | AnchorStyles.Bottom,
FlatStyle = FlatStyle.Flat,
Margin = new Padding(10)
};
saveButton.Click += (object o, EventArgs e) =>
{
this.BackColor = primaryColor;
foreach (Control control in Controls)
{
UpdateSettings(control);
}
settingsPanel.BackColor = primaryColor;
Invalidate();
};
//
this.Controls.Add(menuStrip);
this.Controls.Add(settingsPanel);
this.Controls.Add(saveButton);
settingsPanel.Controls.Add(themeSelector);
settingsPanel.Controls.Add(sizeSelector);
menuStrip.Items.Add(menuBack);
menuStrip.BringToFront();
themeSelector.BringToFront();
saveButton.BringToFront();
}
public static void UpdateSettings(Control control)
{
if (control is not FlowLayoutPanel)
{
control.BackColor = secondaryColor;
control.ForeColor = tertiaryColor;
}
else
{
control.BackColor = primaryColor;
}
try
{
control.Font = mainFont;
}
catch (Exception ex) { }
foreach (Control childControl in control.Controls)
{
UpdateSettings(childControl);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment