-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
154 lines (134 loc) · 4.52 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
using Gma.System.MouseKeyHook;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Timers;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using Timer = System.Timers.Timer;
namespace RngHelper
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
private IKeyboardMouseEvents m_GlobalHook;
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
this.DragMove();
AutoUpdate = Properties.Settings.Default.AutoUpdate;
if (Properties.Settings.Default.GlobalClickEvent)
{
// Note: for the application hook, use the Hook.AppEvents() instead
m_GlobalHook = Hook.GlobalEvents();
m_GlobalHook.MouseDownExt += GlobalHookMouseDownExt;
}
else
{
RngWindow.MouseLeftButtonDown += RngWindow_MouseLeftButtonDown;
}
// Init colors
try
{
color1 = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Color1_25);
color2 = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Color26_50);
color3 = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Color51_75);
color4 = (Color)ColorConverter.ConvertFromString(Properties.Settings.Default.Color76_100);
}
catch (Exception)
{
// Default colours
color1 = (Color)ColorConverter.ConvertFromString("#fdfd00");
color2 = (Color)ColorConverter.ConvertFromString("#ff8000");
color3 = (Color)ColorConverter.ConvertFromString("#ff0000");
color4 = (Color)ColorConverter.ConvertFromString("#7e00fc");
}
timer = new Timer();
timer.Elapsed += new ElapsedEventHandler(UpdateNumber);
timer.Interval = 5000;
timer.Start();
}
private void RngWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
setRandom();
}
private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
{
if (e.Button == MouseButtons.Left)
{
setRandom();
}
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
private Timer timer;
private Random rng = new Random();
private void UpdateNumber(object source, ElapsedEventArgs e)
{
if (AutoUpdate)
setRandom();
}
private int? random;
public int? Random
{
get { return random; }
set
{
random = value;
OnPropertyChanged("Random");
OnPropertyChanged("BackgroundColor");
}
}
private bool autoUpdate;
public bool AutoUpdate {
get
{
return autoUpdate;
}
set
{
autoUpdate = value;
Properties.Settings.Default.AutoUpdate = value;
Properties.Settings.Default.Save();
}
}
private Color color1;
private Color color2;
private Color color3;
private Color color4;
public Brush BackgroundColor
{
get
{
if (Random > 75)
return new SolidColorBrush(color4);
if (Random > 50)
return new SolidColorBrush(color3);
if (Random > 25)
return new SolidColorBrush(color2);
else if (Random > 0)
return new SolidColorBrush(color1);
return new SolidColorBrush();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
private void setRandom()
{
Random = rng.Next(1, 101);
}
}
}