-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisplayForm.cs
843 lines (721 loc) · 32.1 KB
/
DisplayForm.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
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
/*****************************************************************************/
/* Project : LedMatrix */
/* File : DisplayForm.cs */
/* Version : 1 */
/* Language : C# */
/* Summary : Implementation of the demonstration interface */
/* Creation : 23/02/2010 */
/* Autor : Guillaume CHOUTEAU */
/* History : */
/*****************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using LedMatrixControlNamespace;
using LST_Busline.Settings;
using Newtonsoft.Json;
using NonInvasiveKeyboardHookLibrary;
using UpdaterService.Diagnostics.Update;
namespace LSTBusline
{
/// <summary>
/// Definition of the demonstration interface
/// </summary>
public partial class DisplayForm : Form
{
#region Thread-Safe Status + Progressbar
private delegate void SafeSetTextBoxText(string text);
private delegate void SafeSetProgressBarValue(int value);
private void SplitAndUpdateStatusTextAndProgressbar(string InputText)
{
String[] SplitUp = InputText.Split('#');
if (SplitUp.Length > 1)
{
WriteTextSafe(SplitUp[0]);
SetProgressBarValueSafe(Convert.ToInt16(SplitUp[1]));
}
}
private void WriteTextSafe(string text)
{
if (UpdateStatusTextbox.InvokeRequired)
{
var d = new SafeSetTextBoxText(WriteTextSafe);
UpdateStatusTextbox.Invoke(d, new object[] { text });
}
else
{
UpdateStatusTextbox.Text = text;
}
}
private void SetProgressBarValueSafe(int value)
{
/*if (SplashProgressBar.InvokeRequired)
{
var d = new SafeSetProgressBarValue(SetProgressBarValueSafe);
SplashProgressBar.Invoke(d, new object[] { value });
}
else
{
SplashProgressBar.Value = value;
}*/
}
#endregion
private readonly object lockObject = new object();
int idText_Line1;
int idText_Line2;
int idLogo;
int idCurrentTime;
int idNextStopTime;
bool even_or_uneven = false; // Hilfsvariable um regelmässig zwischen zwei Zuständen hin und her zu schalten
DateTime lastrun = DateTime.Now;
bool m_bIsOn;
bool m_bIsHide;
KeyboardHookManager _kManager;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Timer timer3;
private System.Windows.Forms.Timer timer4;
String BusLine = "###############";
String NextStop = "###############";
int MaxLineCharacters = 20;
int currentMode = 0; // aktueller Modus
int currentLine = 0; // aktuelle Linie im aktuellen Modus
int currentStop = 0; // aktueller Halt der aktuellen Linie im aktuellen Modus
int savedStatisticMode = int.MaxValue;
int savedStatisticLine = int.MaxValue;
int savedStatisticStop = int.MaxValue;
DateTime savedStatisticStopTime = DateTime.MinValue;
bool invalidated = false;
SettingsRoot Konfiguration;
//-------------------------------//
// CONSTRUCTOR //
//-------------------------------//
#region Constuctor
/// <summary>
/// Class constructor
/// </summary>
public DisplayForm()
{
InitializeComponent();
SplitAndUpdateStatusTextAndProgressbar("Starte...#0");
Log.Event += (sender, e) => SplitAndUpdateStatusTextAndProgressbar(e.Message);
#region read configuration
Konfiguration = ReadConfiguration();
WriteConfiguration(Konfiguration);
#endregion
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
versionlabel.Text = String.Format("{0}", version);
ledMatrixControl.LedOnColor = Color.FromArgb(Konfiguration?.settings?.style?.led_on_color ?? -256);
ledMatrixControl.LedOffColor = Color.FromArgb(Konfiguration?.settings?.style?.led_off_color ?? -12566464);
ledMatrixControl.SizeCoeff = (double)Konfiguration.settings.style.led_size_coefficient;
HotkeysActive.Checked = true;
invertLogoCheckbox.Checked = Konfiguration.settings.style.logoinverted;
currentTimeStopOnLineChange.Checked = Konfiguration.settings.autosuggeststoponlinechange;
autoSwitchAfterFirst.Checked = Konfiguration.settings.autoforwardlineafterfirst;
if (autoSwitchAfterFirst.Checked)
LinienAbbruchZeitUpDownControl.Enabled = false;
else
LinienAbbruchZeitUpDownControl.Enabled = true;
if (Konfiguration.settings.style?.ledtype == 0)
{
ledMatrixControl.SetLedStyle(LedSyle.Round);
cbxDisplayLedStyle.SelectedIndex = 0;
}
else
{
ledMatrixControl.SetLedStyle(LedSyle.Square);
cbxDisplayLedStyle.SelectedIndex = 1;
}
// Get the color from the control
pbtDisplayLedOn.BackColor = ledMatrixControl.LedOnColor;
pbtDisplayLedOff.BackColor = ledMatrixControl.LedOffColor;
// Get the size from the control
ledMatrixControl.SetMatrixSize(Konfiguration.settings?.style?.lines ?? 200, Konfiguration.settings?.style?.rows ?? 17);
nudLedSize.Value = (decimal)ledMatrixControl.SizeCoeff;
// Set the font collection
ledMatrixControl.LoadFontCollectionFromResource("LST-Busline-Font.xml");
// Add the text item to the conrol
//idLogo = ledMatrixControl.AddTextItem(tbxTx1.Text, new Point(0, 0), ItemDirection.Right, ItemSpeed.Idle);
idCurrentTime = ledMatrixControl.AddTextItem(GenerateCurrentTimeString(), new Point(165, 0), ItemDirection.Right, ItemSpeed.Idle);
idNextStopTime = ledMatrixControl.AddTextItem(GenerateNextSelectedStopTime(), new Point(165, 8), ItemDirection.Right, ItemSpeed.Idle);
idLogo = ledMatrixControl.AddTextItem(GenerateLogo(), new Point(0, 0), ItemDirection.Right, ItemSpeed.Idle);
idText_Line1 = ledMatrixControl.AddTextItem(GenerateLine1(), new Point(25, 0), ItemDirection.Right, ItemSpeed.Idle);
idText_Line2 = ledMatrixControl.AddTextItem(GenerateLine2(), new Point(25, 8), ItemDirection.Right, ItemSpeed.Idle);
// Line Abort Window
LinienAbbruchZeitUpDownControl.Value = Konfiguration.settings.lineabortwindow;
// Init the flags
m_bIsOn = false;
m_bIsHide = false;
// Register Hotkeys
_kManager = new KeyboardHookManager();
_kManager.Start();
RegisterHotkeys(_kManager);
invalidated = true;
InitTimer();
var updater = new UpdaterService.Diagnostics.Update.Updater(StartUpAndUpdate.ReadResourceHelper.ReadResource("update.xml"));
updater.StartMonitoring();
HandleHotKey_Reset();
}
#region Konfiguration
public SettingsRoot ReadConfiguration()
{
return JsonConvert.DeserializeObject<SettingsRoot>(File.ReadAllText("LST-Busline-Konfiguration.json")) ?? new SettingsRoot();
}
public void WriteConfiguration(SettingsRoot Konfiguration)
{
// write it
File.WriteAllText("LST-Busline-Konfiguration.json", JsonConvert.SerializeObject(Konfiguration, Formatting.Indented));
}
#endregion
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Fensterposition wiederherstellen
Location = new Point(Konfiguration.settings.style.windowposition_x, Konfiguration.settings.style.windowposition_y);
Size = new Size(Konfiguration.settings.style.windowwidth, Konfiguration.settings.style.windowheight);
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
// Fensterposition speichern...
Konfiguration.settings.style.windowposition_x = Location.X;
Konfiguration.settings.style.windowposition_y = Location.Y;
Konfiguration.settings.style.windowheight = Size.Height;
Konfiguration.settings.style.windowwidth = Size.Width;
WriteConfiguration(Konfiguration);
}
public void RegisterHotkeys(KeyboardHookManager kManager)
{
#region register hotkeys
//Boolean NextStop = RegisterHotKey(this.Handle, 1, 0x0000, Konfiguration.settings.hotkeys.nextstop);
// if (!NextStop) { MessageBox.Show("Nächster Halt Hotkey konnte nicht aktiviert werden!"); }
//Boolean PreviousStop = RegisterHotKey(this.Handle, 2, 0x0000, Konfiguration.settings.hotkeys.previousstop);
// if (!PreviousStop) { MessageBox.Show("Vorheriger Halt Hotkey konnte nicht aktiviert werden!"); }
//Boolean ResetLine = RegisterHotKey(this.Handle, 3, 0x0000, Konfiguration.settings.hotkeys.resetline);
// if (!ResetLine) { MessageBox.Show("Reset Hotkey konnte nicht aktiviert werden!"); }
//Boolean SwitchLine = RegisterHotKey(this.Handle, 4, 0x0000, Konfiguration.settings.hotkeys.switchline);
// if (!SwitchLine) { MessageBox.Show("Linienwechsel Hotkey konnte nicht aktiviert werden!"); }
//Boolean SwitchMode = RegisterHotKey(this.Handle, 5, 0x0000, Konfiguration.settings.hotkeys.switchmode);
// if (!SwitchMode) { MessageBox.Show("Moduswechsel Hotkey konnte nicht aktiviert werden!"); }
kManager.Stop();
kManager.Start();
kManager.UnregisterAll();
// Nächster Halt
kManager.RegisterHotkey(Konfiguration.settings.hotkeys?.nextstop ?? (int)Keys.D9, () =>
{
HandleHotKey_NextStop();
});
// Vorheriger Halt
kManager.RegisterHotkey(Konfiguration.settings.hotkeys?.previousstop ?? (int)Keys.D8, () =>
{
HandleHotKey_PreviousStop();
});
// Reset
kManager.RegisterHotkey(Konfiguration.settings.hotkeys?.resetline ?? (int)Keys.D7, () =>
{
HandleHotKey_Reset();
});
// Linienwechsel
kManager.RegisterHotkey(Konfiguration.settings.hotkeys?.switchline ?? (int)Keys.D6, () =>
{
HandleHotKey_LineChange();
});
// Moduswechsel
kManager.RegisterHotkey(Konfiguration.settings.hotkeys?.switchmode ?? (int)Keys.D5, () =>
{
HandleHotKey_ModeChange();
});
#endregion
}
#endregion
#region Hotkeys behandeln und reagieren
protected void HandleHotKey_NextStop()
{
Debug.WriteLine("Nächster Halt");
lock (lockObject)
{
if ((currentStop + 1) > Konfiguration.modes[currentMode].lines[currentLine].stops.Count() - 1)
{
// hochzählen geht nicht, wir fangen bei 0 an
currentStop = 0;
}
else
{
// eins hochzählen
currentStop += 1;
}
}
invalidated = true;
}
protected void HandleHotKey_PreviousStop()
{
Debug.WriteLine("Vorheriger Halt");
lock (lockObject)
{
if ((currentStop - 1) < 0)
{
// runterzählen geht nicht, wir schalten auf den letzten Stop
currentStop = Konfiguration.modes[currentMode].lines[currentLine].stops.Count() - 1;
}
else
{
// eins runterzählen
currentStop -= 1;
}
}
invalidated = true;
}
protected void HandleHotKey_Reset()
{
Debug.WriteLine("Reset");
invalidated = true;
lock (lockObject)
{
currentLine = Konfiguration.modes[currentMode].lines.Count() - 1;
currentMode = 0;
currentStop = 0;
}
HandleHotKey_LineChange();
invalidated = true;
}
protected void HandleHotKey_LineChange()
{
Debug.WriteLine("Linienwechsel");
lock (lockObject)
{
if ((currentLine + 1) > Konfiguration.modes[currentMode].lines.Count() - 1)
{
// hochzählen geht nicht, wir fangen bei 0 an
currentLine = 0;
}
else
{
// eins hochzählen
currentLine += 1;
}
if (!Konfiguration.settings.autosuggeststoponlinechange)
{
// reset der Stops - wir starten beim ersten Stop
currentStop = 0;
}
else
{
// den richtigen Stop vorauswählen - das ist der nächstmögliche entsprechend der aktuellen Uhrzeit
for (int i = 0; i <= Konfiguration.modes[currentMode].lines[currentLine].stops.Count() - 1; i++)
{
DateTime stoptime = GenerateNextStopTime(currentMode, currentLine, i,false);
if (stoptime <= DateTime.Now)
{
//do something
//Debug.WriteLine(Konfiguration.modes[currentMode].lines[currentLine].stops[i].name);
//Debug.WriteLine(stoptime);
currentStop = i;
}
}
}
}
invalidated = true;
}
protected void HandleHotKey_ModeChange()
{
Debug.WriteLine("Moduswechsel");
lock (lockObject)
{
if ((currentMode + 1) > Konfiguration.modes.Count() - 1)
{
// hochzählen geht nicht, wir fangen bei 0 an
currentMode = 0;
}
else
{
// eins hochzählen
currentMode += 1;
}
// reset der anderen Werte
currentLine = 0;
currentStop = 0;
}
invalidated = true;
}
#endregion
#region Timer Display Update
public void InitTimer()
{
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(UpdateDisplayCycle);
timer1.Interval = 200; // in miliseconds
timer1.Start();
timer2 = new System.Windows.Forms.Timer();
timer2.Tick += new EventHandler(ReRegisterHotkeys);
timer2.Interval = 10000;
timer2.Start();
timer3 = new System.Windows.Forms.Timer();
timer3.Tick += new EventHandler(AutoForward);
timer3.Interval = 1000;
timer3.Start();
timer4 = new System.Windows.Forms.Timer();
timer4.Tick += new EventHandler(UpdateStatistics);
timer4.Interval = 1000;
timer4.Start();
}
private void UpdateStatistics(object sender, EventArgs e)
{
if ( (savedStatisticMode != currentMode) || (savedStatisticLine != currentLine) || (savedStatisticStop != currentStop) )
{
// es wurde umgeschaltet
// hole nächste Stop Zeit
savedStatisticStopTime = GenerateNextStopTime(currentMode, currentLine, currentStop, false);
}
if (savedStatisticStopTime != DateTime.MinValue)
{
String prefix = "";
String suffix = "";
if (savedStatisticStopTime >= DateTime.Now)
{
//Debug.WriteLine("early");
prefix = "-";
suffix = "früh";
}
else
{
if ((DateTime.Now - savedStatisticStopTime).TotalMinutes <= 1)
{
//Debug.WriteLine("ontime");
prefix = "";
suffix = "pünktlich";
}
else
{
//Debug.WriteLine("late");
prefix = "+";
suffix = "verspätet";
}
}
//tooLateTime.Text = ;
timeToNextStop.Text = prefix + (savedStatisticStopTime - DateTime.Now).ToString(@"mm\:ss")+ " - "+ suffix;
//Debug.WriteLine(stopTime);
}
}
private bool IsCurrentlineLineInformationOnly()
{
/*int stoptime = int.MinValue;
// Prüft ob alle Halts in der Linie identische Zeiten haben
// alle stops
for (int stop=0;stop <= Konfiguration.modes[currentMode].lines[currentLine].stops.Count() -1; stop++)
{
// alle haltezeiten dieses stops
foreach (int thisstoptime in Konfiguration.modes[currentMode].lines[currentLine].stops[stop].leavetimes_hourly)
{
if (stoptime == int.MinValue)
stoptime = thisstoptime;
if (stoptime != thisstoptime)
return false;
}
}
return true;*/
return Konfiguration.modes[currentMode].lines[currentLine].isInformationOnly;
}
private void AutoForward(object sender, EventArgs e)
{
if ((Konfiguration.settings.autoforwardlineafterfirst) && currentStop > 0 && !IsCurrentlineLineInformationOnly())
{
//Debug.WriteLine("AutoForward");
// auto forward...
int tempstop = 0;
//Debug.WriteLine("-----");
// den nächsten Stop vorauswählen - das ist der nächstmögliche entsprechend der aktuellen Uhrzeit
lock (lockObject)
{
for (int i = 0; i <= Konfiguration.modes[currentMode].lines[currentLine].stops.Count() - 1; i++)
{
//Debug.WriteLine(Konfiguration.modes[currentMode].lines[currentLine].stops[i].name + " - " + GenerateNextStopTime(currentMode, currentLine, i, false));
DateTime stoptime = GenerateNextStopTime(currentMode, currentLine, i, false);
if (stoptime < DateTime.Now)
{
//do something
tempstop = i;
}
}
if (tempstop > currentStop)
{
currentStop = tempstop;
invalidated = true;
}
}
}
}
private void ReRegisterHotkeys(object sender, EventArgs e)
{
//Debug.WriteLine("Hotkeys re-register");
if (HotkeysActive.Checked)
RegisterHotkeys(_kManager);
}
/// <summary>
/// wird regelmässig aufgerufen um das Display zu aktualisieren
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UpdateDisplayCycle(object sender, EventArgs e)
{
//Debug.WriteLine("Tick Tock");
// Update Uhrzeit
ledMatrixControl.SetItemText(idCurrentTime,GenerateCurrentTimeString());
// nur updaten wenn wir müssen
if (invalidated)
{
// Update Line1
ledMatrixControl.SetItemText(idText_Line1, GenerateLine1());
// Update Line2
ledMatrixControl.SetItemText(idText_Line2, GenerateLine2());
// Update Nächster Halt
ledMatrixControl.SetItemText(idNextStopTime, GenerateNextSelectedStopTime());
// stop updating
invalidated = false;
}
//Debug.WriteLine("Mode: " + currentMode + " Line: " + currentLine + " Stop:" + currentStop);
}
#endregion
#region Dynamische Anzeigen Erzeugung
public String GenerateCurrentTimeString()
{
// umschalten...
if ((DateTime.Now - lastrun).TotalSeconds >= 1)
{
lastrun = DateTime.Now;
even_or_uneven = !even_or_uneven;
}
if (even_or_uneven)
return "¥" + DateTime.Now.ToString("HH:mm");
else
return "¥" + DateTime.Now.ToString("HH¦mm");
}
public DateTime GetNearestTimeInTheFutureForMinute(int MinuteInput,bool ignoreAbortWindow)
{
int Minute = MinuteInput + Konfiguration.settings.lineabortwindow;
if (ignoreAbortWindow) Minute = MinuteInput;
if (Minute > 60) { Minute = 60 - Minute; }
DateTime output = new DateTime(DateTime.Now.Year, DateTime.Now.Month,DateTime.Now.Day, DateTime.Now.Hour, MinuteInput, 0);
if (DateTime.Now.Minute > Minute)
output = output.AddHours(1);
return output;
}
public String GenerateNextSelectedStopTime()
{
if (IsCurrentlineLineInformationOnly())
return "";
else
return "¦¦¦ :" + GenerateNextStopTime(currentMode, currentLine, currentStop, false).Minute.ToString("D2");
}
public DateTime GenerateNextStopTime(int mode, int line, int stop, bool ignoreAbortWindow)
{
TimeSpan TimeDistance = TimeSpan.MaxValue;
DateTime Abfahrtzeit = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
lock (lockObject)
{
foreach (int Abfahrtszeit in Konfiguration.modes[mode].lines[line].stops[stop].leavetimes_hourly)
{
DateTime nearestTimeForAbfahrzeit = GetNearestTimeInTheFutureForMinute(Abfahrtszeit, ignoreAbortWindow);
// qualifiziert weil in der Zukunft?
if (TimeDistance == TimeSpan.MaxValue)
TimeDistance = nearestTimeForAbfahrzeit - DateTime.Now;
if (TimeDistance < nearestTimeForAbfahrzeit - DateTime.Now)
{
TimeDistance = nearestTimeForAbfahrzeit - DateTime.Now;
}
else
{
TimeDistance = nearestTimeForAbfahrzeit - DateTime.Now;
Abfahrtzeit = nearestTimeForAbfahrzeit;
}
}
}
return new DateTime(Abfahrtzeit.Year,Abfahrtzeit.Month,Abfahrtzeit.Day,Abfahrtzeit.Hour,Abfahrtzeit.Minute,0);
}
public String GenerateLogo()
{
if (Konfiguration.settings.style.logoinverted)
return "£";
else
return "¢";
}
public String GenerateLine1()
{
String currentLineName = "###############"; // Standardwert wenn Fehler
// aktuellen Modus hernehmen und die daraus selektierte Linienbezeichnung anzeigen
try
{
lock(lockObject)
currentLineName = Konfiguration.modes[currentMode].lines[currentLine].name;
} catch(Exception)
{
}
return PadCenter(currentLineName, MaxLineCharacters);
}
public String GenerateLine2()
{
String nextStopName = "###############"; // Standardwert wenn Fehler
// aktuellen Modus hernehmen und die daraus selektierte Linienbezeichnung anzeigen
try
{
lock(lockObject)
nextStopName = Konfiguration.modes[currentMode].lines[currentLine].stops[currentStop].name;
}
catch (Exception)
{
}
return PadCenter(nextStopName, MaxLineCharacters);
}
#endregion
#region String helper
static string PadCenter(string text, int newWidth)
{
const char filler = '¡';
int length = text.Length;
int charactersToPad = newWidth - length;
if (charactersToPad < 0) return text;// throw new ArgumentException("New width must be greater than string length.", "newWidth");
int padLeft = charactersToPad / 2 + charactersToPad % 2;
//add a space to the left if the string is an odd number
int padRight = charactersToPad / 2;
StringBuilder resultBuilder = new StringBuilder(newWidth);
for (int i = 0; i < padLeft; i++) resultBuilder.Insert(i, filler);
for (int i = 0; i < length; i++) resultBuilder.Insert(i + padLeft, text[i]);
for (int i = newWidth - padRight; i < newWidth; i++) resultBuilder.Insert(i, filler);
return resultBuilder.ToString();
}
#endregion
//-------------------------------//
// Display properties events //00
//-------------------------------//
#region Display
private void cbxDisplayLedStyle_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbxDisplayLedStyle.SelectedIndex == 0)
{
ledMatrixControl.SetLedStyle(LedSyle.Round);
}
else if (cbxDisplayLedStyle.SelectedIndex == 1)
{
ledMatrixControl.SetLedStyle(LedSyle.Square);
}
Konfiguration.settings.style.ledtype = cbxDisplayLedStyle.SelectedIndex;
WriteConfiguration(Konfiguration);
}
private void pbtDisplayLedOn_Click(object sender, EventArgs e)
{
ColorDialog cdLedOnColorDlg = new ColorDialog();
if (cdLedOnColorDlg.ShowDialog() == DialogResult.OK)
{
pbtDisplayLedOn.BackColor = cdLedOnColorDlg.Color;
ledMatrixControl.LedOnColor = cdLedOnColorDlg.Color;
}
Konfiguration.settings.style.led_on_color = cdLedOnColorDlg.Color.ToArgb();
WriteConfiguration(Konfiguration);
}
private void pbtDisplayLedOff_Click(object sender, EventArgs e)
{
ColorDialog cdLedOffColorDlg = new ColorDialog();
if (cdLedOffColorDlg.ShowDialog() == DialogResult.OK)
{
pbtDisplayLedOff.BackColor = cdLedOffColorDlg.Color;
ledMatrixControl.LedOffColor = cdLedOffColorDlg.Color;
}
Konfiguration.settings.style.led_off_color = cdLedOffColorDlg.Color.ToArgb();
WriteConfiguration(Konfiguration);
}
private void bptHide_Click(object sender, EventArgs e)
{
if (m_bIsHide == false)
{
groupBox3.Visible = false;
groupBox2.Visible = false;
groupBox1.Visible = false;
pbtHide.Text = "Ausklappen";
panel1.Height = 35;
m_bIsHide = true;
}
else
{
groupBox3.Visible = true;
groupBox2.Visible = true;
groupBox1.Visible = true;
pbtHide.Text = "Einklappen";
panel1.Height = 170;
m_bIsHide = false;
}
}
private void nudLedSize_ValueChanged(object sender, EventArgs e)
{
ledMatrixControl.SizeCoeff = (double)nudLedSize.Value;
Konfiguration.settings.style.led_size_coefficient = (double)nudLedSize.Value;
WriteConfiguration(Konfiguration);
}
#endregion
#region Kurzwahltasten
private void button_switchmode_Click(object sender, EventArgs e)
{
HandleHotKey_ModeChange();
}
private void button_switchline_Click(object sender, EventArgs e)
{
HandleHotKey_LineChange();
}
private void button_previousstop_Click(object sender, EventArgs e)
{
HandleHotKey_PreviousStop();
}
private void button_nextstop_Click(object sender, EventArgs e)
{
HandleHotKey_NextStop();
}
private void button_reset_Click(object sender, EventArgs e)
{
HandleHotKey_Reset();
}
private void Lizenzen_Click(object sender, EventArgs e)
{
var myForm = new ReleaseNotesCopyrightsAndLicenses();
myForm.Show();
}
#endregion
#region Einstellungen
private void LinienAbbruchZeitUpDownControl_ValueChanged(object sender, EventArgs e)
{
Konfiguration.settings.lineabortwindow = Convert.ToInt32(LinienAbbruchZeitUpDownControl.Value);
WriteConfiguration(Konfiguration);
}
private void currentTimeStopOnLineChange_CheckedChanged(object sender, EventArgs e)
{
Konfiguration.settings.autosuggeststoponlinechange = currentTimeStopOnLineChange.Checked;
WriteConfiguration(Konfiguration);
}
private void autoSwitchAfterFirst_CheckedChanged(object sender, EventArgs e)
{
Konfiguration.settings.autoforwardlineafterfirst = autoSwitchAfterFirst.Checked;
if (autoSwitchAfterFirst.Checked)
LinienAbbruchZeitUpDownControl.Enabled = false;
else
LinienAbbruchZeitUpDownControl.Enabled = true;
WriteConfiguration(Konfiguration);
}
private void invertLogoCheckbox_CheckedChanged(object sender, EventArgs e)
{
Konfiguration.settings.style.logoinverted = invertLogoCheckbox.Checked;
ledMatrixControl.SetItemText(idLogo, GenerateLogo());
WriteConfiguration(Konfiguration);
}
#endregion
private void HotkeysActive_CheckedChanged(object sender, EventArgs e)
{
if (!HotkeysActive.Checked)
{
_kManager.UnregisterAll();
}
}
}
}