-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
337 lines (296 loc) · 11.2 KB
/
Form1.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;
namespace SightByte
{
public partial class Form1 : Form
{
Knob knobby;
Hotkey_Configuration keyConfig;
int _gammaLvl;
public static int _MAXGAMMA = 256;
public bool editing;
public Keys keyPreset0;
public Form1.KeyModifier preset0Mod;
public Keys keyPreset1;
public Form1.KeyModifier preset1Mod;
public static int preset1Value;
public Keys keyPreset2;
public Form1.KeyModifier preset2Mod;
public static int preset2Value;
public Keys keyPreset3;
public Form1.KeyModifier preset3Mod;
public static int preset3Value;
public int gammaLvl { get { return _gammaLvl; } set { _gammaLvl = value; } }
public static RAMP ramp = new RAMP();
public static RAMP r = new RAMP();
public static RAMP preset1 = new RAMP();
public static RAMP preset2 = new RAMP();
public static RAMP preset3 = new RAMP();
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
public enum KeyModifier
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
WinKey = 8
}
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("gdi32.dll")]
public static extern int GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
[DllImport("gdi32.dll")]
public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct RAMP
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Red;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Green;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public UInt16[] Blue;
}
public Form1()
{
InitializeComponent();
comboBox1.SelectedIndex = 0;
trackBar1.Value = _MAXGAMMA / 2;
StoreGamma();
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x0312)
{
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
int id = m.WParam.ToInt32();
if(!editing)
{
switch (id)
{
case (0):
{
trackBar1.Value = _MAXGAMMA / 2;
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r);
break;
}
case (1):
{
trackBar1.Value = preset1Value;
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset1);
break;
}
case (2):
{
trackBar1.Value = preset2Value;
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset2);
break;
}
case (3):
{
trackBar1.Value = preset3Value;
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset3);
break;
}
default:
break;
}
}
}
}
public static void SetGamma(int gamma)
{
if (gamma <= 256 && gamma >= 1)
{
RAMP ramp = new RAMP();
ramp.Red = new ushort[256];
ramp.Green = new ushort[256];
ramp.Blue = new ushort[256];
for (int i = 1; i < 256; i++)
{
int iArrayValue = i * (gamma + 128);
if (iArrayValue > 65535)
iArrayValue = 65535;
ramp.Red[i] = ramp.Blue[i] = ramp.Green[i] = (ushort)iArrayValue;
}
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
}
}
public static int GetGamma()
{
return GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
}
public static void StoreGamma()
{
GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r);
GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset1);
preset1Value = _MAXGAMMA / 2;
GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset2);
preset2Value = _MAXGAMMA / 2;
GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset3);
preset3Value = _MAXGAMMA / 2;
}
private void Form1_Resize(object sender, EventArgs e)
{
if(WindowState == FormWindowState.Minimized)
{
Hide();
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
if(knobby == null || !knobby.IsHandleCreated)
knobby = new Knob(this);
knobby.Show();
knobby.TopMost = true;
}
// Revert
private void button3_Click(object sender, EventArgs e)
{
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r);
trackBar1.Value = _MAXGAMMA / 2;
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
gammaLvl = trackBar1.Value;
SetGamma(trackBar1.Value);
toolTip1.SetToolTip(trackBar1, trackBar1.Value.ToString());
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r);
UnregisterHotKey(this.Handle, 0);
UnregisterHotKey(this.Handle, 1);
UnregisterHotKey(this.Handle, 2);
UnregisterHotKey(this.Handle, 3);
}
public void setGammaValue(int value)
{
SetGamma(value);
}
//Preset 1
private void button1_Click(object sender, EventArgs e)
{
trackBar1.Value = preset1Value;
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset1);
}
//Preset 2
private void button2_Click(object sender, EventArgs e)
{
trackBar1.Value = preset2Value;
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset2);
}
//Preset 3
private void button4_Click(object sender, EventArgs e)
{
trackBar1.Value = preset3Value;
SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset3);
}
//Save preset
private void button5_Click(object sender, EventArgs e)
{
if(comboBox1.SelectedIndex == 0)
{
saveLabel.ForeColor = Color.Black;
preset1Value = trackBar1.Value;
saveLabel.Text = "Preset 1 Saved!";
GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset1);
timer1.Start();
}
if (comboBox1.SelectedIndex == 1)
{
saveLabel.ForeColor = Color.Black;
preset2Value = trackBar1.Value;
saveLabel.Text = "Preset 2 Saved!";
GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset2);
timer1.Start();
}
if (comboBox1.SelectedIndex == 2)
{
saveLabel.ForeColor = Color.Black;
preset3Value = trackBar1.Value;
saveLabel.Text = "Preset 3 Saved!";
GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref preset3);
timer1.Start();
}
}
private void donateToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=NV98CPXKF2MP2&lc=US&item_name=Gray%20Glove%20Studio¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted");
}
private void setHotkeyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (keyConfig == null || !keyConfig.IsHandleCreated)
keyConfig = new Hotkey_Configuration(this);
keyConfig.ShowDialog();
keyConfig.TopMost = true;
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutApp aApp = new AboutApp();
aApp.ShowDialog();
}
private void timer1_Tick(object sender, EventArgs e)
{
int fadingSpeed = 10;
saveLabel.ForeColor = Color.FromArgb(saveLabel.ForeColor.R + fadingSpeed, saveLabel.ForeColor.G + fadingSpeed, saveLabel.ForeColor.B + fadingSpeed);
if (saveLabel.ForeColor.R >= this.BackColor.R)
{
timer1.Stop();
saveLabel.ForeColor = this.BackColor;
}
}
public void changeHotKey(int value, KeyEventArgs e, KeyModifier mod)
{
UnregisterHotKey(this.Handle, value);
if (value == 0)
keyPreset0 = e.KeyCode;
if (value == 1)
keyPreset1 = e.KeyCode;
if (value == 2)
keyPreset2 = e.KeyCode;
if (value == 3)
keyPreset3 = e.KeyCode;
RegisterHotKey(this.Handle, value, (int)mod, e.KeyCode.GetHashCode());
}
private void Form1_Load(object sender, EventArgs e)
{
int id = 0;
keyPreset0 = Keys.NumPad0;
preset0Mod = (int)KeyModifier.None;
RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.NumPad0.GetHashCode());
id = 1;
keyPreset1 = Keys.NumPad1;
preset1Mod = (int)KeyModifier.None;
RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.NumPad1.GetHashCode());
id = 2;
keyPreset2 = Keys.NumPad2;
preset2Mod = (int)KeyModifier.None;
RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.NumPad2.GetHashCode());
id = 3;
keyPreset3 = Keys.NumPad3;
preset3Mod = (int)KeyModifier.None;
RegisterHotKey(this.Handle, id, (int)KeyModifier.None, Keys.NumPad3.GetHashCode());
}
}
}