-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cs
200 lines (166 loc) · 6.66 KB
/
MainWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using YeelightAPI;
namespace light_controller_app
{
public partial class LightController : Form
{
//Device device = new Device(DeviceLocator.DiscoverAsync().Result.ToString()); //test this feature
public LightController()
{
InitializeComponent();
}
private void circularButton_Paint(object sender, PaintEventArgs e)
{
Button button = (Button)sender;
using (GraphicsPath circularPath = new GraphicsPath())
{
circularPath.AddEllipse(0, 0, button.Width - 1, button.Height - 1);
button.Region = new Region(circularPath);
}
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnMin_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
// WinAPI constants
private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HT_CAPTION = 0x2;
// WinAPI functions
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern bool ReleaseCapture();
private void pnlMenuBar_MouseDown(object sender, MouseEventArgs e)
{
pnlMenuBar.MouseDown += customPanel_MouseDown;
}
private void lblCurrentMenu_MouseDown(object sender, MouseEventArgs e)
{
lblCurrentMenu.MouseDown += customPanel_MouseDown;
}
private void customPanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void LogoClicked(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/barandev");
}
private void pbLogo_Click(object sender, EventArgs e)
{
pbLogo.Click += LogoClicked;
}
private void NavButtonClicked(Button button,String formToAdd)
{
switch (formToAdd)
{
case "dashboard":
{
if (pnlContent.Controls.Count == 0 || pnlContent.Controls[0].GetType() != typeof(Dashboard))
{
lblCurrentMenu.Text = "Dashboard";
pnlContent.Controls.Clear();
Dashboard dashboard = new Dashboard();
dashboard.TopLevel = false;
dashboard.FormBorderStyle = FormBorderStyle.None;
dashboard.Dock = DockStyle.Fill;
pnlContent.Controls.Add(dashboard);
pnlContent.Tag = dashboard;
dashboard.BringToFront();
dashboard.Show();
}
else
ResetContentPanel();
break;
}
case "rooms":
{
if (pnlContent.Controls.Count == 0 || pnlContent.Controls[0].GetType() != typeof(Rooms))
{
lblCurrentMenu.Text = "Rooms";
pnlContent.Controls.Clear();
Rooms rooms = new Rooms();
rooms.TopLevel = false;
rooms.FormBorderStyle = FormBorderStyle.None;
rooms.Dock = DockStyle.Fill;
pnlContent.Controls.Add(rooms);
pnlContent.Tag = rooms;
rooms.BringToFront();
rooms.Show();
}
else
ResetContentPanel();
break;
}
case "devices":
{
if (pnlContent.Controls.Count == 0 || pnlContent.Controls[0].GetType() != typeof(Devices))
{
lblCurrentMenu.Text = "Devices";
pnlContent.Controls.Clear();
Devices devices = new Devices();
devices.TopLevel = false;
devices.FormBorderStyle = FormBorderStyle.None;
devices.Dock = DockStyle.Fill;
pnlContent.Controls.Add(devices);
pnlContent.Tag = devices;
devices.BringToFront();
devices.Show();
}
else
ResetContentPanel();
break;
}
}
// Reset the color of all buttons to the original color (27, 22, 40)
foreach (Button btn in pnlNav.Controls.OfType<Button>())
{
btn.BackColor = Color.FromArgb(27, 22, 40);
}
// Change the color of the clicked button to the desired color (47, 42, 60)
button.BackColor = Color.FromArgb(47, 42, 60);
// Move pnlCurrentMenuIndicator to the bottom of the clicked button
pnlCurrentMenuIndicator.Width = button.Width;
pnlCurrentMenuIndicator.Location = new Point(button.Location.X, button.Location.Y + button.Height - pnlCurrentMenuIndicator.MaximumSize.Height);
}
private void ResetContentPanel()
{
pnlContent.Controls.Clear();
pnlContent.Controls.Add(pbRobotGif);
lblCurrentMenu.Text = "Main Menu";
}
private void btnHome_Click(object sender, EventArgs e)
{
NavButtonClicked(btnHome, "dashboard");
}
private void btnDevices_Click(object sender, EventArgs e)
{
NavButtonClicked(btnDevices, "devices");
}
private void btnRooms_Click(object sender, EventArgs e)
{
NavButtonClicked(btnRooms, "rooms");
}
private void LightController_Load(object sender, EventArgs e)
{
}
}
}