-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainForm.h
More file actions
660 lines (589 loc) · 24.8 KB
/
Copy pathMainForm.h
File metadata and controls
660 lines (589 loc) · 24.8 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
#pragma once
#include <Windows.h>
#include "ckLua.h"
#include <iostream>
#include <sstream>
#include <msclr\marshal_cppstd.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class MainForm : public System::Windows::Forms::Form
{
public:
MainForm(ckLua* lua, std::ostringstream* out) : minimizedFirstTime(true) {
InitializeComponent();
this->Show();
this->lua = lua;
this->out = out;
populateComboBoxes();
this->updateTimer->Start();
loadSelectedKeymap();
loadSelectedScript();
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MainForm::typeid));
this->Icon = gcnew System::Drawing::Icon(L"icon.ico");
this->minimizeIcon->Icon = gcnew System::Drawing::Icon(L"icon.ico");
}
private:
// When fully loaded
System::Void MainForm_Shown(System::Object^ sender, System::EventArgs^ e) {
changeInputDevice(false);
}
protected:
~MainForm(){
if (components){
delete components;
}
}
private: System::ComponentModel::IContainer^ components;
protected:
// Form components
private: System::Windows::Forms::RichTextBox^ txtOutput;
private: System::Windows::Forms::Label^ lblOutput;
private: System::Windows::Forms::Button^ btnClearConsole;
private: System::Windows::Forms::ComboBox^ cbScripts;
private: System::Windows::Forms::Label^ lblScript;
private: System::Windows::Forms::Button^ btnReloadScript;
private: System::Windows::Forms::Label^ lblKeyConfig;
private: System::Windows::Forms::ComboBox^ cbKeyConfig;
private: System::Windows::Forms::Button^ btnReloadConfig;
private: System::Windows::Forms::CheckBox^ chkPause;
private: System::Windows::Forms::ContextMenuStrip^ menuTray;
private: System::Windows::Forms::NotifyIcon^ minimizeIcon;
private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ restoreToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ notifyScriptMenu;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator1;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ fileToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ openToolStripMenuItem;
private: System::Windows::Forms::ToolStripSeparator^ toolStripSeparator3;
private: System::Windows::Forms::ToolStripMenuItem^ exitToolStripMenuItem1;
private: System::Windows::Forms::Button^ btnBrowseScript;
private: System::Windows::Forms::Button^ btnBrowseKeyconfig;
private: System::Windows::Forms::Label^ lblCustomScript;
private: System::Windows::Forms::Label^ lblCustomKeyConfig;
private: System::Windows::Forms::ToolStripMenuItem^ helpToolStripMenuItem;
private: System::Windows::Forms::ToolStripMenuItem^ luaCallbacksToolStripMenuItem;
private: System::Windows::Forms::Timer^ updateTimer;
// Initialize components
void InitializeComponent(void){
this->components = (gcnew System::ComponentModel::Container());
this->txtOutput = (gcnew System::Windows::Forms::RichTextBox());
this->lblOutput = (gcnew System::Windows::Forms::Label());
this->btnClearConsole = (gcnew System::Windows::Forms::Button());
this->cbScripts = (gcnew System::Windows::Forms::ComboBox());
this->lblScript = (gcnew System::Windows::Forms::Label());
this->btnReloadScript = (gcnew System::Windows::Forms::Button());
this->lblKeyConfig = (gcnew System::Windows::Forms::Label());
this->cbKeyConfig = (gcnew System::Windows::Forms::ComboBox());
this->btnReloadConfig = (gcnew System::Windows::Forms::Button());
this->updateTimer = (gcnew System::Windows::Forms::Timer(this->components));
this->chkPause = (gcnew System::Windows::Forms::CheckBox());
this->menuTray = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->restoreToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->notifyScriptMenu = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->exitToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->minimizeIcon = (gcnew System::Windows::Forms::NotifyIcon(this->components));
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->fileToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->openToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->toolStripSeparator3 = (gcnew System::Windows::Forms::ToolStripSeparator());
this->exitToolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->helpToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->luaCallbacksToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->btnBrowseScript = (gcnew System::Windows::Forms::Button());
this->btnBrowseKeyconfig = (gcnew System::Windows::Forms::Button());
this->lblCustomScript = (gcnew System::Windows::Forms::Label());
this->lblCustomKeyConfig = (gcnew System::Windows::Forms::Label());
this->menuTray->SuspendLayout();
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// txtOutput
//
this->txtOutput->BackColor = System::Drawing::SystemColors::Desktop;
this->txtOutput->Cursor = System::Windows::Forms::Cursors::Arrow;
this->txtOutput->ForeColor = System::Drawing::SystemColors::Window;
this->txtOutput->Location = System::Drawing::Point(15, 202);
this->txtOutput->Name = L"txtOutput";
this->txtOutput->ReadOnly = true;
this->txtOutput->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::ForcedVertical;
this->txtOutput->Size = System::Drawing::Size(382, 246);
this->txtOutput->TabIndex = 4;
this->txtOutput->Text = L"";
this->txtOutput->TextChanged += gcnew System::EventHandler(this, &MainForm::txtOutput_TextChanged);
//
// lblOutput
//
this->lblOutput->AutoSize = true;
this->lblOutput->BackColor = System::Drawing::SystemColors::Control;
this->lblOutput->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
this->lblOutput->Location = System::Drawing::Point(12, 186);
this->lblOutput->Name = L"lblOutput";
this->lblOutput->Size = System::Drawing::Size(42, 13);
this->lblOutput->TabIndex = 1;
this->lblOutput->Text = L"Output:";
//
// btnClearConsole
//
this->btnClearConsole->Location = System::Drawing::Point(306, 423);
this->btnClearConsole->Name = L"btnClearConsole";
this->btnClearConsole->Size = System::Drawing::Size(75, 23);
this->btnClearConsole->TabIndex = 2;
this->btnClearConsole->Text = L"Clear";
this->btnClearConsole->UseVisualStyleBackColor = true;
this->btnClearConsole->Click += gcnew System::EventHandler(this, &MainForm::btnClearConsole_Click);
//
// cbScripts
//
this->cbScripts->FormattingEnabled = true;
this->cbScripts->Location = System::Drawing::Point(15, 40);
this->cbScripts->Name = L"cbScripts";
this->cbScripts->Size = System::Drawing::Size(301, 21);
this->cbScripts->TabIndex = 5;
//
// lblScript
//
this->lblScript->AutoSize = true;
this->lblScript->Location = System::Drawing::Point(12, 24);
this->lblScript->Name = L"lblScript";
this->lblScript->Size = System::Drawing::Size(37, 13);
this->lblScript->TabIndex = 6;
this->lblScript->Text = L"Script:";
//
// btnReloadScript
//
this->btnReloadScript->Location = System::Drawing::Point(322, 38);
this->btnReloadScript->Name = L"btnReloadScript";
this->btnReloadScript->Size = System::Drawing::Size(75, 23);
this->btnReloadScript->TabIndex = 8;
this->btnReloadScript->Text = L"Load";
this->btnReloadScript->UseVisualStyleBackColor = true;
this->btnReloadScript->Click += gcnew System::EventHandler(this, &MainForm::btnReloadScript_Click);
//
// lblKeyConfig
//
this->lblKeyConfig->AutoSize = true;
this->lblKeyConfig->Location = System::Drawing::Point(12, 95);
this->lblKeyConfig->Name = L"lblKeyConfig";
this->lblKeyConfig->Size = System::Drawing::Size(61, 13);
this->lblKeyConfig->TabIndex = 9;
this->lblKeyConfig->Text = L"Key Config:";
//
// cbKeyConfig
//
this->cbKeyConfig->FormattingEnabled = true;
this->cbKeyConfig->Location = System::Drawing::Point(15, 116);
this->cbKeyConfig->Name = L"cbKeyConfig";
this->cbKeyConfig->Size = System::Drawing::Size(301, 21);
this->cbKeyConfig->TabIndex = 10;
//
// btnReloadConfig
//
this->btnReloadConfig->Location = System::Drawing::Point(322, 114);
this->btnReloadConfig->Name = L"btnReloadConfig";
this->btnReloadConfig->Size = System::Drawing::Size(75, 23);
this->btnReloadConfig->TabIndex = 12;
this->btnReloadConfig->Text = L"Load";
this->btnReloadConfig->UseVisualStyleBackColor = true;
this->btnReloadConfig->Click += gcnew System::EventHandler(this, &MainForm::btnReloadConfig_Click);
//
// updateTimer
//
this->updateTimer->Interval = 30;
this->updateTimer->Tick += gcnew System::EventHandler(this, &MainForm::updateTimer_Tick);
//
// chkPause
//
this->chkPause->AutoSize = true;
this->chkPause->Location = System::Drawing::Point(341, 185);
this->chkPause->Name = L"chkPause";
this->chkPause->Size = System::Drawing::Size(56, 17);
this->chkPause->TabIndex = 13;
this->chkPause->Text = L"Pause";
this->chkPause->UseVisualStyleBackColor = true;
//
// menuTray
//
this->menuTray->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(4) {
this->restoreToolStripMenuItem,
this->notifyScriptMenu, this->toolStripSeparator1, this->exitToolStripMenuItem
});
this->menuTray->Name = L"menuTray";
this->menuTray->Size = System::Drawing::Size(153, 98);
//
// restoreToolStripMenuItem
//
this->restoreToolStripMenuItem->Font = (gcnew System::Drawing::Font(L"Calibri", 8.25F, System::Drawing::FontStyle::Bold));
this->restoreToolStripMenuItem->Name = L"restoreToolStripMenuItem";
this->restoreToolStripMenuItem->Size = System::Drawing::Size(152, 22);
this->restoreToolStripMenuItem->Text = L"Show Window";
this->restoreToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::restoreToolStripMenuItem_Click);
//
// notifyScriptMenu
//
this->notifyScriptMenu->Name = L"notifyScriptMenu";
this->notifyScriptMenu->Size = System::Drawing::Size(152, 22);
this->notifyScriptMenu->Text = L"Change Script";
//
// toolStripSeparator1
//
this->toolStripSeparator1->Name = L"toolStripSeparator1";
this->toolStripSeparator1->Size = System::Drawing::Size(149, 6);
//
// exitToolStripMenuItem
//
this->exitToolStripMenuItem->Name = L"exitToolStripMenuItem";
this->exitToolStripMenuItem->Size = System::Drawing::Size(152, 22);
this->exitToolStripMenuItem->Text = L"Exit";
this->exitToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::exitEventHandler);
//
// minimizeIcon
//
this->minimizeIcon->ContextMenuStrip = this->menuTray;
this->minimizeIcon->Text = L"ckLua";
this->minimizeIcon->DoubleClick += gcnew System::EventHandler(this, &MainForm::minimizeIcon_DoubleClick);
this->minimizeIcon->MouseClick += gcnew System::Windows::Forms::MouseEventHandler(this, &MainForm::minimizeIcon_MouseClick);
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(2) {
this->fileToolStripMenuItem,
this->helpToolStripMenuItem
});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(412, 24);
this->menuStrip1->TabIndex = 14;
this->menuStrip1->Text = L"menuStrip1";
//
// fileToolStripMenuItem
//
this->fileToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
this->openToolStripMenuItem,
this->toolStripSeparator3, this->exitToolStripMenuItem1
});
this->fileToolStripMenuItem->Name = L"fileToolStripMenuItem";
this->fileToolStripMenuItem->Size = System::Drawing::Size(36, 20);
this->fileToolStripMenuItem->Text = L"&File";
//
// openToolStripMenuItem
//
this->openToolStripMenuItem->ImageTransparentColor = System::Drawing::Color::Magenta;
this->openToolStripMenuItem->Name = L"openToolStripMenuItem";
this->openToolStripMenuItem->ShortcutKeys = static_cast<System::Windows::Forms::Keys>((System::Windows::Forms::Keys::Control | System::Windows::Forms::Keys::O));
this->openToolStripMenuItem->Size = System::Drawing::Size(135, 22);
this->openToolStripMenuItem->Text = L"&Open";
this->openToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::fileOpenEventHandler);
//
// toolStripSeparator3
//
this->toolStripSeparator3->Name = L"toolStripSeparator3";
this->toolStripSeparator3->Size = System::Drawing::Size(132, 6);
//
// exitToolStripMenuItem1
//
this->exitToolStripMenuItem1->Name = L"exitToolStripMenuItem1";
this->exitToolStripMenuItem1->Size = System::Drawing::Size(135, 22);
this->exitToolStripMenuItem1->Text = L"E&xit";
this->exitToolStripMenuItem1->Click += gcnew System::EventHandler(this, &MainForm::exitEventHandler);
//
// helpToolStripMenuItem
//
this->helpToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->luaCallbacksToolStripMenuItem });
this->helpToolStripMenuItem->Name = L"helpToolStripMenuItem";
this->helpToolStripMenuItem->Size = System::Drawing::Size(41, 20);
this->helpToolStripMenuItem->Text = L"Help";
//
// luaCallbacksToolStripMenuItem
//
this->luaCallbacksToolStripMenuItem->Name = L"luaCallbacksToolStripMenuItem";
this->luaCallbacksToolStripMenuItem->Size = System::Drawing::Size(152, 22);
this->luaCallbacksToolStripMenuItem->Text = L"Lua callbacks";
this->luaCallbacksToolStripMenuItem->Click += gcnew System::EventHandler(this, &MainForm::luaCallbacksToolStripMenuItem_Click);
//
// btnBrowseScript
//
this->btnBrowseScript->Location = System::Drawing::Point(322, 67);
this->btnBrowseScript->Name = L"btnBrowseScript";
this->btnBrowseScript->Size = System::Drawing::Size(75, 23);
this->btnBrowseScript->TabIndex = 15;
this->btnBrowseScript->Text = L"Browse";
this->btnBrowseScript->UseVisualStyleBackColor = true;
this->btnBrowseScript->Click += gcnew System::EventHandler(this, &MainForm::scriptOpenEventHandler);
//
// btnBrowseKeyconfig
//
this->btnBrowseKeyconfig->Location = System::Drawing::Point(322, 143);
this->btnBrowseKeyconfig->Name = L"btnBrowseKeyconfig";
this->btnBrowseKeyconfig->Size = System::Drawing::Size(75, 23);
this->btnBrowseKeyconfig->TabIndex = 16;
this->btnBrowseKeyconfig->Text = L"Browse";
this->btnBrowseKeyconfig->UseVisualStyleBackColor = true;
this->btnBrowseKeyconfig->Click += gcnew System::EventHandler(this, &MainForm::keyConfigOpenEventHandler);
//
// lblCustomScript
//
this->lblCustomScript->AutoSize = true;
this->lblCustomScript->Location = System::Drawing::Point(12, 66);
this->lblCustomScript->Name = L"lblCustomScript";
this->lblCustomScript->Size = System::Drawing::Size(0, 13);
this->lblCustomScript->TabIndex = 17;
//
// lblCustomKeyConfig
//
this->lblCustomKeyConfig->AutoSize = true;
this->lblCustomKeyConfig->Location = System::Drawing::Point(12, 142);
this->lblCustomKeyConfig->Name = L"lblCustomKeyConfig";
this->lblCustomKeyConfig->Size = System::Drawing::Size(0, 13);
this->lblCustomKeyConfig->TabIndex = 18;
//
// MainForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(412, 460);
this->Controls->Add(this->lblCustomKeyConfig);
this->Controls->Add(this->lblCustomScript);
this->Controls->Add(this->btnBrowseKeyconfig);
this->Controls->Add(this->btnBrowseScript);
this->Controls->Add(this->menuStrip1);
this->Controls->Add(this->cbKeyConfig);
this->Controls->Add(this->cbScripts);
this->Controls->Add(this->btnReloadConfig);
this->Controls->Add(this->lblKeyConfig);
this->Controls->Add(this->btnReloadScript);
this->Controls->Add(this->lblScript);
this->Controls->Add(this->btnClearConsole);
this->Controls->Add(this->txtOutput);
this->Controls->Add(this->lblOutput);
this->Controls->Add(this->chkPause);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->MainMenuStrip = this->menuStrip1;
this->MaximizeBox = false;
this->Name = L"MainForm";
this->Text = L"CKLua";
this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &MainForm::formClosed);
this->Shown += gcnew System::EventHandler(this, &MainForm::MainForm_Shown);
this->SizeChanged += gcnew System::EventHandler(this, &MainForm::MainForm_SizeChanged);
this->menuTray->ResumeLayout(false);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
// Setup exit event
Application::ApplicationExit += gcnew EventHandler(this, &MainForm::onApplicationExit);
}
// Private members
ckLua* lua;
std::ostringstream* out;
bool minimizedFirstTime;
private:
// Finds files in folder and populates combo box
void populateComboBoxesHelper(ComboBox^ cb, LPCWSTR f, WIN32_FIND_DATA &data) {
HANDLE h = FindFirstFile(f, &data);
if (h != INVALID_HANDLE_VALUE)
{
do
{
char* nPtr = new char[lstrlen(data.cFileName) + 1];
for (int i = 0; i < lstrlen(data.cFileName); i++)
nPtr[i] = char(data.cFileName[i]);
nPtr[lstrlen(data.cFileName)] = '\0';
cb->Items->Add(gcnew String(nPtr));
delete nPtr;
} while (FindNextFile(h, &data));
}
else
std::cout << "Scripts not found" << std::endl;
FindClose(h);
}
// Load all scripts and keyconfigs
void populateComboBoxes() {
WIN32_FIND_DATA data;
populateComboBoxesHelper(this->cbScripts, L"scripts/*.lua", data);
for each (auto var in this->cbScripts->Items){
ToolStripMenuItem^ child = gcnew ToolStripMenuItem(var->ToString());
child->Click += gcnew EventHandler(this, &MainForm::scriptMenu_Click);
notifyScriptMenu->DropDownItems->Add(child);
}
if (cbScripts->Items->Count > 0) {
cbScripts->SelectedIndex = 0;
}
populateComboBoxesHelper(this->cbKeyConfig, L"keymaps/*.keyconf", data);
if (cbKeyConfig->Items->Count > 0)
cbKeyConfig->SelectedIndex = 0;
}
void loadSelectedScript(){
if (cbScripts->SelectedIndex == -1) return;
String^ fileName = "scripts/";
fileName = String::Concat(fileName, this->cbScripts->Items[this->cbScripts->SelectedIndex]->ToString());
lua->changeScript(msclr::interop::marshal_as<std::string>(fileName));
}
void loadSelectedKeymap(){
if (cbKeyConfig->SelectedIndex == -1) return;
// Convert from managed string to standard string and load keymap
String^ fileName = "keymaps/";
fileName = String::Concat(fileName, this->cbKeyConfig->Items[this->cbKeyConfig->SelectedIndex]->ToString());
lua->changeKeyConfig(msclr::interop::marshal_as<std::string>(fileName));
}
// When Application::Exit() is called
void onApplicationExit(Object^ sender, EventArgs^ e) {
lua->kill();
delete Icon;
delete minimizeIcon;
}
// When form is closed
System::Void formClosed(System::Object^ sender, System::Windows::Forms::FormClosedEventArgs^ e) {
Application::Exit();
}
// Handle events that want to exit program
System::Void exitEventHandler(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
// When pressing clear button
private: System::Void btnClearConsole_Click(System::Object^ sender, System::EventArgs^ e) {
txtOutput->Clear();
}
// Update console on set interval
System::Void updateTimer_Tick(System::Object^ sender, System::EventArgs^ e) {
if (out->str() == "") return;
// Silent?
if (!chkPause->Checked) {
txtOutput->AppendText(gcnew String(out->str().c_str()));
txtOutput->SelectionStart = txtOutput->Text->Length; //Set the current caret position at the end
txtOutput->ScrollToCaret(); //Now scroll it automatically
}
// Clear buffer
out->clear();
out->str("");
}
// Auto scroll text box
System::Void txtOutput_TextChanged(System::Object^ sender, System::EventArgs^ e) {
txtOutput->SelectionStart = txtOutput->TextLength;
}
// Actually, is load
System::Void btnReloadScript_Click(System::Object^ sender, System::EventArgs^ e) {
lblCustomScript->Text = "";
loadSelectedScript();
}
System::Void btnReloadConfig_Click(System::Object^ sender, System::EventArgs^ e) {
lblCustomKeyConfig->Text = "";
loadSelectedKeymap();
}
// Used for minimizing to tray
System::Void MainForm_SizeChanged(System::Object^ sender, System::EventArgs^ e) {
if (this->WindowState == FormWindowState::Minimized) {
this->minimizeIcon->Visible = true;
if (minimizedFirstTime) {
this->minimizeIcon->ShowBalloonTip(500, L"ckLua", L"Program is still running", ToolTipIcon::Info);
minimizedFirstTime = false;
}
this->ShowInTaskbar = false;
this->Hide();
changeInputDevice(true);
changeInputDevice(false);
}
else if (this->WindowState == FormWindowState::Normal) {
this->minimizeIcon->Visible = false;
this->ShowInTaskbar = true;
changeInputDevice(true);
changeInputDevice(false);
}
}
// Restore application when double clicking tray icon
System::Void minimizeIcon_DoubleClick(System::Object^ sender, System::EventArgs^ e) {
System::Windows::Forms::MouseEventArgs^ ee = (System::Windows::Forms::MouseEventArgs^)e;
switch (ee->Button)
{
case ::MouseButtons::Left:
this->Show();
this->WindowState = FormWindowState::Normal;
break;
}
}
// Restore application when clicking restore
System::Void restoreToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
this->Show();
this->WindowState = FormWindowState::Normal;
}
// Used to display context menu
System::Void minimizeIcon_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
switch (e->Button)
{
case ::MouseButtons::Right:
minimizeIcon->ContextMenuStrip->Show();
break;
}
}
// Change script from context menu
System::Void scriptMenu_Click(System::Object^ sender, System::EventArgs^ e) {
String^ fileName = "scripts/";
fileName = String::Concat(fileName, sender->ToString());
lua->changeScript(msclr::interop::marshal_as<std::string>(fileName));
}
// For opening different files
System::Void scriptOpenEventHandler(System::Object^ sender, System::EventArgs^ e) {
openFile(L"Lua Files (*.lua)|*.lua");
}
System::Void keyConfigOpenEventHandler(System::Object^ sender, System::EventArgs^ e) {
openFile(L"Keymap Files (*.keyconf)|*.keyconf");
}
System::Void fileOpenEventHandler(System::Object^ sender, System::EventArgs^ e) {
openFile(L"Lua Files (*.lua)|*.lua|Keymap Files (*.keyconf)|*.keyconf");
}
// Open file
void openFile(String^ filter) {
OpenFileDialog^ fileDialog = gcnew OpenFileDialog();
fileDialog->Filter = filter;
if (fileDialog->ShowDialog() == ::System::Windows::Forms::DialogResult::OK) {
std::string fileNameU = msclr::interop::marshal_as<std::string>(fileDialog->FileName->ToUpper());
std::string fileName = msclr::interop::marshal_as<std::string>(fileDialog->FileName);
if (fileNameU.find(".LUA") <= fileNameU.size()) {
String^ s = String::Concat(L"Custom: ", gcnew String(fileName.c_str()));
if (s->Length >= 40) {
s = s->Substring(s->Length - 40);
s = String::Concat("Custom: ...", s);
}
lblCustomScript->Text = s;
lua->changeScript(fileName);
}
else if (fileNameU.find(".KEYCONF") <= fileNameU.size()) {
String^ s = String::Concat(L"Custom: ", gcnew String(fileName.c_str()));
if (s->Length >= 40) {
s = s->Substring(s->Length - 40);
s = String::Concat("Custom: ...", s);
}
lblCustomKeyConfig->Text = s;
lua->changeKeyConfig(fileName);
}
}
}
// Registering raw input device for listening.
// Use this when minimizing and restoring to update device handle. This way, input is still being read when window state is changing
void changeInputDevice(bool remove) {
RAWINPUTDEVICE device;
device.usUsagePage = 0x01;
device.usUsage = 0x06;
if (remove)
device.dwFlags = RIDEV_REMOVE;
else
device.dwFlags = RIDEV_INPUTSINK;
device.hwndTarget = (HWND) this->Handle.ToPointer();
if (RegisterRawInputDevices(&device, 1, sizeof(device)) == FALSE){
//std::cout << GetLastError() << std::endl;
}
}
// Show information about lua
System::Void luaCallbacksToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show("Available callbacks in Lua scripts are:\
\nsetLed(key, r, g, b) - sets key with name <key> to color RGB\
\nsetLed(x, y, r, g, b) - sets key at x, y to color RGB\
\nloadKeymap(keymap) - loads keymap with name <keymap> (experimental)\
loadScript(script) - loads script with name <script> (experimental)", "Lua callbacks");
}
};