-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
179 lines (152 loc) · 5.26 KB
/
MainWindow.xaml.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
using Note.Views;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using static Note.App;
namespace Note
{
public partial class MainWindow : Window
{
bool isDraging = false;
public static Page backTo = null;
static DockPanel controls;
static Button backControl;
static Label usernameLabel;
static StackPanel menuBar;
static Grid mainGrid;
static Frame main;
public MainWindow()
{
InitializeComponent();
Main.Content = new StartPage();
controls = LoggedinControls;
backControl = BackControl;
usernameLabel = UsernameLabel;
menuBar = MenuBar;
mainGrid = MainGrid;
main = Main;
}
public static void LoggedInUI(bool show)
{
if (show == false)
{
//dont show//
controls.Visibility = Visibility.Collapsed;
menuBar.Visibility = Visibility.Collapsed;
Grid.SetColumn(main, 0);
Grid.SetColumnSpan(main, 2);
if (user == null)
{
usernameLabel.Visibility = Visibility.Collapsed;
}
}
else
{
//show//
controls.Visibility = Visibility.Visible;
menuBar.Visibility = Visibility.Visible;
Grid.SetColumn(main, 1);
Grid.SetColumnSpan(main, 1);
if (user != null)
{
usernameLabel.Visibility = Visibility.Visible;
usernameLabel.Content = $"User: {user.username}";
}
}
}
public static void GoBackUI(bool show)
{
if (show == false)
{
//dont display//
backControl.Visibility = Visibility.Collapsed;
}
else
{
//display//
backControl.Visibility = Visibility.Visible;
}
}
#region window control
private void SwitchState()
{
switch(WindowState)
{
case WindowState.Normal:
WindowState = WindowState.Maximized;
break;
case WindowState.Maximized:
WindowState = WindowState.Normal;
break;
}
}
private void MinimizeWindowButton_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void ResizeWindowButton_Click(object sender, RoutedEventArgs e)
{
SwitchState();
}
private void ExitWindowButton_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void DockPanel_MouseMove(object sender, MouseEventArgs e)
{
if(isDraging == true)
{
isDraging = false;
double percentHorizontal = e.GetPosition(this).X / ActualWidth;
double targetHorizontal = RestoreBounds.Width * percentHorizontal;
double percentVertical = e.GetPosition(this).Y / ActualHeight;
double targetVertical = RestoreBounds.Height * percentVertical;
WindowState = WindowState.Normal;
System.Drawing.Point lMousePosition = System.Windows.Forms.Cursor.Position;
Left = lMousePosition.X - targetHorizontal;
Top = lMousePosition.Y - targetVertical;
DragMove();
}
}
private void DockPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
isDraging = false;
}
private void DockPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2) SwitchState();
else isDraging = true;
}
#endregion
private void AddNoteButton_Click(object sender, RoutedEventArgs e)
{
Page page;
if (Main.Content.GetType() == typeof(MainPage)) page = new NoteAddPage();
else page = new Views.Accounts.AccountAddPage();
Main.Content = page;
}
private void SettingsButton_Click(object sender, RoutedEventArgs e)
{
Main.Content = new SettingsPage();
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
Main.Content = backTo;
}
private void NotesButton_Click(object sender, RoutedEventArgs e)
{
Main.Content = new MainPage();
NotesMenuButton.Background = new SolidColorBrush(Color.FromRgb(66, 66, 66));
AccountsMenuButton.Background = Brushes.Transparent;
}
private void AccountsButton_Click(object sender, RoutedEventArgs e)
{
Main.Content = new Views.Accounts.MainPage();
NotesMenuButton.Background = Brushes.Transparent;
AccountsMenuButton.Background = new SolidColorBrush(Color.FromRgb(66, 66, 66));
}
}
}