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
|
// Copyright (c) 2013-2025 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Drawing2D;
using Crow.DebugLogger;
using System.Diagnostics;
namespace Crow
{
public class DbgLogViewer : Widget
{
public static Dictionary<DbgEvtType, Color> colors;
#region CTOR
protected DbgLogViewer () : base(){}
public DbgLogViewer (Interface iface, string style = null) : base(iface, style){}
#endregion
FontExtents fe;
double xScale = 1.0/1024.0, yScale = 1.0, leftMargin, topMargin = 0.0;
DbgWidgetRecord curWidget, hoverWidget;
DbgEvent curEvent, hoverEvent;
IList<DbgEvent> events = new List<DbgEvent> ();
IList<DbgWidgetRecord> widgets = new List<DbgWidgetRecord> ();
public DbgEvtType Filter {
get => Configuration.Global.Get<DbgEvtType> ("DbgLogViewFilter");
set {
if (Filter == value)
return;
Configuration.Global.Set ("DbgLogViewFilter", value);
NotifyValueChangedAuto(Filter);
RegisterForGraphicUpdate();
}
}
public IList<DbgEvent> Events {
get => events;
set {
if (events == value)
return;
events = value;
NotifyValueChanged (nameof (Events), events);
maxTicks = minTicks = 0;
if (events != null && events.Count > 0) {
minTicks = long.MaxValue;
foreach (DbgEvent e in events) {
if (e.begin < minTicks)
minTicks = e.begin;
if (e.end > maxTicks)
maxTicks = e.end;
}
visibleTicks = maxTicks - minTicks;
XScale = (ClientRectangle.Width - leftMargin)/visibleTicks;
ScrollX = 0;
ScrollY = 0;
} else {
maxTicks = 1;
XScale = 1.0/1024.0;
}
RegisterForGraphicUpdate ();
}
}
public IList<DbgWidgetRecord> Widgets {
get => widgets;
set {
if (widgets == value)
return;
widgets = value;
NotifyValueChanged (nameof (Widgets), widgets);
updateMargins ();
updateMaxScrollX ();
updateMaxScrollY ();
}
}
public DbgWidgetRecord CurrentWidget {
get => curWidget;
set {
if (curWidget == value)
return;
curWidget = value;
NotifyValueChanged (nameof (CurrentWidget), curWidget);
if (CurrentWidget == null)
return;
if (CurrentWidget.listIndex < scrollY || CurrentWidget.listIndex > scrollY + visibleLines)
ScrollY = CurrentWidget.listIndex - (visibleLines / 2);
currentLine = CurrentWidget.listIndex;
RegisterForRedraw();
}
}
public DbgEvent CurrentEvent {
get => curEvent;
set {
if (curEvent == value)
return;
/*if (curEvent != null)
curEvent.IsSelected = false;*/
curEvent = value;
if (curEvent != null) {
//curEvent.IsSelected = true;
if (curEvent is DbgWidgetEvent we) {
//CurrentWidget = Widgets [we.InstanceIndex];
hoverLine = we.InstanceIndex;
}
currentTick = curEvent.begin;
if (curEvent.begin > minTicks + ScrollX + visibleTicks ||
curEvent.end < minTicks + ScrollX)
ScrollX = curEvent.begin - minTicks - visibleTicks / 2;
}
NotifyValueChanged (nameof (CurrentEvent), curEvent);
RegisterForRedraw ();
}
}
public DbgWidgetRecord HoverWidget {
get => hoverWidget;
internal set {
if (hoverWidget == value)
return;
hoverWidget = value;
NotifyValueChanged (nameof (HoverWidget), hoverWidget);
}
}
public DbgEvent HoverEvent {
get => hoverEvent;
set {
if (hoverEvent == value)
return;
hoverEvent = value;
NotifyValueChanged (nameof (HoverEvent), hoverEvent);
RegisterForRepaint ();
}
}
long hoverTick = 0, currentTick, selStart = -1, selEnd = -1, minTicks = 0, maxTicks = 0, visibleTicks = 0;
int hoverLine = -1, currentLine = -1;
int visibleLines = 1;
Point mousePos;
public double XScale {
get => xScale;
set {
if (xScale == value)
return;
xScale = value;
NotifyValueChanged ("XScale", xScale);
updateVisibleTicks ();
RegisterForGraphicUpdate ();
}
}
public double YScale {
get => yScale;
set {
if (yScale == value)
return;
yScale = value;
NotifyValueChanged ("YScale", yScale);
RegisterForGraphicUpdate ();
}
}
public override Font Font {
get { return base.Font; }
set {
base.Font = value;
using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) {
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
fe = gr.FontExtents;
}
updateMargins ();
}
}
RectangleD getWidgetEvtBounds (DbgEvent evt, ref Rectangle cb, double penY) {
double x = xScale * (evt.begin - minTicks - ScrollX);
double w = Math.Max (Math.Max (2.0, 2.0 * xScale), (double)(evt.end - evt.begin) * xScale);
if (x < 0.0) {
w += x;
x = 0.0;
}
x += leftMargin + cb.Left;
double rightDiff = x + w - cb.Right;
if (rightDiff > 0)
w -= rightDiff;
return new RectangleD(x, penY, w, fe.Height);
}
void drawEvents (IContext ctx, IList<DbgEvent> evts)
{
if (evts == null || evts.Count == 0)
return;
Rectangle cb = ClientRectangle;
foreach (DbgEvent evt in evts) {
if ((evt.Category & currentFilter) == currentFilter) {
if (evt.end - minTicks <= ScrollX)
continue;
if (evt.begin - minTicks > ScrollX + visibleTicks)
break;
double penY = topMargin + ClientRectangle.Top;
if (evt.type.HasFlag (DbgEvtType.Widget)) {
DbgWidgetEvent eW = evt as DbgWidgetEvent;
int lIdx = eW.InstanceIndex - ScrollY;
if (lIdx >= 0 && lIdx <= visibleLines) {
penY += (lIdx) * fe.Height;
ctx.SetSource (evt.Color);
RectangleD r = getWidgetEvtBounds (evt, ref cb, penY);
if (r.Width > 0){
ctx.Rectangle (r.X,r.Y,r.Width,r.Height);
ctx.Fill ();
}
}
} else if (evt.type.HasFlag (DbgEvtType.IFace)) {
double x = xScale * (evt.begin - minTicks - ScrollX);
double w = Math.Max (Math.Max (2.0, 2.0 * xScale), (double)(evt.end - evt.begin) * xScale);
if (x < 0.0) {
w += x;
x = 0.0;
}
x += leftMargin + cb.Left;
double rightDiff = x + w - cb.Right;
if (rightDiff > 0)
w -= rightDiff;
//ctx.SetSource (0.9,0.9,0.0,0.1);
ctx.SetSource (evt.Color.AdjustAlpha(0.13));
ctx.Rectangle (x, cb.Top + topMargin, w, cb.Height);
ctx.Fill ();
}
}
drawEvents (ctx, evt.Events);
}
}
DbgEvtType currentFilter;
protected override void onDraw (IContext gr)
{
base.onDraw (gr);
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
if (widgets == null)
return;
gr.LineWidth = 1.0;
Rectangle cb = ClientRectangle;
double penY = topMargin + ClientRectangle.Top;
for (int i = 0; i < visibleLines; i++) {
if (i + ScrollY >= widgets.Count)
break;
int gIdx = i + ScrollY;
DbgWidgetRecord g = widgets [gIdx];
penY += fe.Height;
gr.SetSource (Colors.Jet);
gr.MoveTo (cb.X, penY - 0.5);
gr.LineTo (cb.Right, penY - 0.5);
gr.Stroke ();
double penX = 5.0 * g.xLevel + cb.Left;
if (g.xLevel == 0)
gr.SetSource (Colors.LightSalmon);
else if (currentLine == g.listIndex)
gr.SetSource(Colors.RoyalBlue);
else
Foreground.SetAsSource (IFace, gr);
gr.MoveTo (penX, penY - gr.FontExtents.Descent);
gr.ShowText (g.name + gIdx);
}
currentFilter = Filter;
drawEvents (gr, events);
gr.MoveTo (cb.Left, topMargin - 0.5 + cb.Top);
gr.LineTo (cb.Right, topMargin - 0.5 + cb.Top);
gr.MoveTo (leftMargin + cb.Left, cb.Top);
gr.LineTo (leftMargin + cb.Left, cb.Bottom);
gr.SetSource (Colors.Grey);
penY = topMargin + ClientRectangle.Top;
//graduation
long largeGrad = long.Parse ("1" + new string ('0', visibleTicks.ToString ().Length - 1));
long smallGrad = Math.Max (1, largeGrad / 10);
long firstVisibleTicks = minTicks + ScrollX;
long curGrad = firstVisibleTicks - firstVisibleTicks % smallGrad + smallGrad;
long gg = curGrad - ScrollX - minTicks;
while (gg < visibleTicks ) {
double x = (double)gg * xScale + leftMargin + cb.Left;
gr.MoveTo (x, penY - 0.5);
if (curGrad % largeGrad == 0) {
gr.LineTo (x, penY - 8.5);
string str = ticksToMS(curGrad);
TextExtents te = gr.TextExtents (str);
gr.RelMoveTo (-0.5 * te.Width, -2.0);
gr.ShowText (str);
}else
gr.LineTo (x, penY - 2.5);
curGrad += smallGrad;
gg = curGrad - ScrollX - minTicks;
}
gr.Stroke ();
}
string ticksToMS(long ticks) => Math.Round ((double)ticks / Stopwatch.Frequency * 1000.0, 2).ToString();
public override bool Paint (IContext ctx)
{
base.Paint (ctx);
Rectangle r = new Rectangle(mousePos.X, 0, 1, Slot.Height);
Rectangle ctxR = ContextCoordinates (r);
Rectangle cb = ClientRectangle;
ctx.LineWidth = 1.0;
if (hoverTick >= 0) {
double x = xScale * (hoverTick - minTicks - ScrollX) + leftMargin;
if (x - Math.Truncate (x) > 0.5)
x = Math.Truncate (x) + 0.5;
else
x = Math.Truncate (x) - 0.5;
ctx.MoveTo (x, cb.Top + topMargin - 4.0);
ctx.LineTo (x, cb.Bottom);
ctx.SetSource (0.7,0.7,0.7,0.5);
ctx.Stroke();
}
if (currentTick >= 0) {
double x = xScale * (currentTick - minTicks - ScrollX) + leftMargin;
if (x > leftMargin && x < cb.Right) {
if (x - Math.Truncate (x) > 0.5)
x = Math.Truncate (x) + 0.5;
else
x = Math.Truncate (x) - 0.5;
ctx.MoveTo (x, cb.Top);
ctx.LineTo (x, cb.Bottom);
ctx.SetSource (0.2,0.7,1.0,0.6);
ctx.Stroke();
}
}
ctx.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
ctx.SetFontSize (Font.Size);
string str = ticksToMS(hoverTick);
ctx.MoveTo (ctxR.X - ctx.TextExtents (str).Width / 2, ctxR.Y + fe.Height);
ctx.ShowText (str);
ctx.Operator = Operator.Add;
if (hoverLine >= 0) {
double y = fe.Height * (hoverLine - ScrollY) + topMargin + cb.Top;
r = new Rectangle (cb.Left, (int)y, cb.Width, (int)fe.Height);
ctx.SetSource (0.1, 0.1, 0.1, 0.4);
ctx.Rectangle (ContextCoordinates (r));
ctx.Fill ();
if (hoverEvent is DbgWidgetEvent wevt) {
ctx.SetSource (1.0,1.0,1.0,0.7);
ctx.SetDash (new double[] {1, 2});
ctx.Rectangle ((Rectangle)getWidgetEvtBounds (wevt, ref cb, y).Inflated (1), 1);
}
}
if (currentLine >= ScrollY && currentLine < scrollY + visibleLines) {
double y = fe.Height * (currentLine - ScrollY) + topMargin + cb.Top;
r = new Rectangle (cb.Left, (int)y, cb.Width, (int)fe.Height);
ctx.SetSource (0.1, 0.1, 0.7, 0.2);
ctx.Rectangle (ContextCoordinates (r));
ctx.Fill ();
}
if (selStart < 0 || selEnd < 0) {
ctx.Operator = Operator.Over;
return true;
}
double selStartX = (double)(selStart - ScrollX - minTicks) * xScale + leftMargin + cb.Left;
double selEndX = (double)(selEnd - ScrollX - minTicks) * xScale + leftMargin + cb.Left;
if (selStartX < selEndX) {
ctxR.X = (int)selStartX;
ctxR.Width = (int)(selEndX - selStartX);
} else {
ctxR.X = (int)selEndX;
ctxR.Width = (int)(selStartX - selEndX);
}
ctxR.Width = Math.Max (1, ctxR.Width);
ctx.Rectangle (ctxR);
ctx.SetSource (0.0,0.2,0.8,0.15);
//ctx.SetSource (Colors.Jet);
ctx.Fill();
ctx.Operator = Operator.Over;
str = $"{ticksToMS(Math.Abs (selEnd - selStart))} (ms)";
ctx.MoveTo (ctxR.Center.X - ctx.TextExtents (str).Width / 2, ctxR.Y + fe.Height);
ctx.SetSource (Colors.Black);
ctx.ShowText (str);
return true;
}
public override void OnLayoutChanges (LayoutingType layoutType)
{
base.OnLayoutChanges (layoutType);
switch (layoutType) {
case LayoutingType.Width:
if (xScale < 0) {
visibleTicks = maxTicks - minTicks;
XScale = (ClientRectangle.Width - leftMargin) / visibleTicks;
}
updateVisibleTicks ();
break;
case LayoutingType.Height:
updateVisibleLines ();
break;
}
}
public override void onMouseLeave (object sender, MouseMoveEventArgs e)
{
base.onMouseLeave (sender, e);
hoverLine = -1;
hoverTick = 0;
}
public override void onMouseMove (object sender, MouseMoveEventArgs e)
{
long lastTick = hoverTick;
int lastLine = hoverLine;
updateMouseLocalPos (e.Position);
if ((IFace.IsDown (Glfw.MouseButton.Left) || IFace.IsDown (Glfw.MouseButton.Middle)) && selStart >= 0)
selEnd = hoverTick;
else if (IFace.IsDown(Glfw.MouseButton.Right)) {
if (lastTick >= 0 && hoverTick >= 0)
ScrollX += lastTick - hoverTick;
if (lastLine >= 0 && hoverLine >= 0)
ScrollY += lastLine - hoverLine;
updateMouseLocalPos (e.Position);
} else if (widgets != null) {
HoverWidget = (hoverLine < 0 || hoverLine >= widgets.Count) ? null : widgets [hoverLine];
//HoverEvent = hoverWidget?.Events.FirstOrDefault (ev => ev.begin <= hoverTick && ev.end >= hoverTick);
double tickPerPixel = (double)visibleTicks / ClientRectangle.Width;
//Console.WriteLine ($"ticks per pixel: {tickPerPixel}");
Task.Run (() => findHoverEvent (hoverWidget, hoverTick, (int)tickPerPixel));
}
RegisterForRepaint();
e.Handled = true;
base.onMouseMove (sender, e);
}
void findHoverEvent (DbgWidgetRecord widget, long tick, long precision = 0) {
DbgEvent tmp = widget?.Events.FirstOrDefault (ev => ev.begin - precision <= tick && ev.end + precision >= tick);
if (tmp == null) {
tmp = Events.Where(e=>e.type.HasFlag(DbgEvtType.IFace)).Where (ev => ev.begin - precision <= tick && ev.end + precision >= tick).FirstOrDefault();
while(tmp != null) {
DbgEvent che = tmp.Events?.Where(e=>e.type.HasFlag(DbgEvtType.IFace)).Where (ev => ev.begin - precision <= tick && ev.end + precision >= tick).FirstOrDefault();
if (che == null)
break;
tmp = che;
}
} else {
while(tmp != null) {
DbgEvent che = tmp.Events?.OfType<DbgWidgetEvent>()?.Where(ev=>ev.InstanceIndex == widget.listIndex && ev.begin - precision <= tick && ev.end + precision >= tick).FirstOrDefault();
if (che == null)
break;
tmp = che;
}
}
HoverEvent = tmp;
}
public override void onMouseClick(object sender, MouseButtonEventArgs e)
{
if (e.Button == Glfw.MouseButton.Left) {
if (selEnd < 0) {
currentTick = hoverTick;
currentLine = hoverLine;
CurrentWidget = hoverWidget;
CurrentEvent = hoverEvent;
}
selStart = -1;
selEnd = -1;
}
e.Handled = true;
base.onMouseClick(sender, e);
}
public override void onMouseDown (object sender, MouseButtonEventArgs e)
{
if (e.Button == Glfw.MouseButton.Left || e.Button == Glfw.MouseButton.Middle) {
selStart = hoverTick;
selEnd = -1;
}
RegisterForRedraw ();
e.Handled = true;
base.onMouseDown (sender, e);
}
public override void onMouseUp (object sender, MouseButtonEventArgs e)
{
if (e.Button == Glfw.MouseButton.Left && selEnd > 0 && selEnd != selStart) {
long scrX = 0;
if (selStart < selEnd) {
visibleTicks = selEnd - selStart;
scrX = selStart - minTicks;
} else {
visibleTicks = selStart - selEnd;
scrX = selEnd - minTicks;
}
XScale = (ClientRectangle.Width - leftMargin) / visibleTicks;
ScrollX = scrX;
}
RegisterForRedraw ();
e.Handled = true;
base.onMouseUp (sender, e);
}
/// <summary> Process scrolling vertically, or if shift is down, vertically </summary>
public override void onMouseWheel (object sender, MouseWheelEventArgs e)
{
//base.onMouseWheel (sender, e);
if (IFace.Shift)
ScrollX -= (int)((double)(e.Delta * MouseWheelSpeed) / xScale);
else if (IFace.Ctrl)
ScrollY -= e.Delta * MouseWheelSpeed;
else {
if (e.Delta > 0) {
XScale *= 2.0;
} else {
if (MaxScrollX > 0)
XScale *= 0.5;
}
ScrollX = (long)(hoverTick - (long)((double)Math.Max(0, mousePos.X - (long)leftMargin) / xScale) - minTicks);
}
}
public override void onKeyDown (object sender, KeyEventArgs e)
{
base.onKeyDown (sender, e);
if (e.Key == Glfw.Key.F3) {
if (selEnd < 0)
return;
if (selEnd < selStart)
zoom (selEnd, selStart);
else
zoom (selStart, selEnd);
selEnd = selStart = -1;
}
}
void updateMargins ()
{
leftMargin = topMargin = 0.0;
if (widgets == null)
return;
using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) {
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
double maxNameWidth = 0.0;
foreach (DbgWidgetRecord o in widgets) {
double nameWidth = gr.TextExtents (o.name).Width + 5.0 * o.xLevel;
if (nameWidth > maxNameWidth)
maxNameWidth = nameWidth;
}
leftMargin = 10.5 + maxNameWidth;
topMargin = 2.0 * fe.Height;
RegisterForGraphicUpdate ();
}
}
void updateVisibleLines ()
{
visibleLines = fe.Height < 1 ? 1 : (int)Math.Ceiling (((double)ClientRectangle.Height - topMargin) / fe.Height);
NotifyValueChanged ("VisibleLines", visibleLines);
updateMaxScrollY ();
}
void updateVisibleTicks ()
{
visibleTicks = Math.Max (0, (long)((double)(ClientRectangle.Width - leftMargin) / XScale));
NotifyValueChanged ("VisibleTicks", visibleTicks);
updateMaxScrollX ();
}
void updateMaxScrollX ()
{
if (widgets == null) {
MaxScrollX = 0;
} else {
long tot = maxTicks - minTicks;
MaxScrollX = Math.Max (0L, tot - visibleTicks);
NotifyValueChanged ("ChildWidthRatio", (double)visibleTicks / tot);
}
}
void updateMaxScrollY ()
{
if (widgets == null)
MaxScrollY = 0;
else {
MaxScrollY = Math.Max (0, widgets.Count + 1 - visibleLines);
NotifyValueChanged ("ChildHeightRatio", (double)visibleLines / (widgets.Count + 1));
}
}
void updateMouseLocalPos (Point mPos)
{
Rectangle r = ScreenCoordinates (Slot);
Rectangle cb = ClientRectangle;
cb.Left += (int)leftMargin;
cb.Width -= (int)leftMargin;
cb.Y += (int)topMargin;
cb.Height -= (int)topMargin;
mousePos = mPos - r.Position;
mousePos.X = Math.Max (cb.X, mousePos.X);
mousePos.X = Math.Min (cb.Right, mousePos.X);
if (mousePos.Y < cb.Top || mousePos.Y > cb.Bottom)
hoverLine = -1;
else
hoverLine = (int)((double)(mousePos.Y - cb.Top) / fe.Height) + ScrollY;
NotifyValueChanged ("CurrentLine", hoverLine);
mousePos.Y = Math.Max (cb.Y, mousePos.Y);
mousePos.Y = Math.Min (cb.Bottom, mousePos.Y);
hoverTick = (long)((double)(mousePos.X - cb.X) / xScale) + minTicks + ScrollX;
RegisterForRedraw ();
}
void zoom (long start, long end) {
//Rectangle cb = ClientRectangle;
//cb.X += (int)leftMargin;
XScale = ((double)ClientRectangle.Width - leftMargin)/(end - start);
ScrollX = (int)(start - minTicks);
}
long scrollX, maxScrollX;
int scrollY, maxScrollY, mouseWheelSpeed;
/// <summary>
/// if true, key stroke are handled in derrived class
/// </summary>
protected bool KeyEventsOverrides = false;
/// <summary> Horizontal Scrolling Position </summary>
[DefaultValue(0)]
public virtual long ScrollX {
get => scrollX;
set {
if (scrollX == value)
return;
long newS = value;
if (newS < 0)
newS = 0;
else if (newS > maxScrollX)
newS = maxScrollX;
if (newS == scrollX)
return;
scrollX = newS;
NotifyValueChangedAuto (scrollX);
RegisterForGraphicUpdate ();
}
}
/// <summary> Vertical Scrolling Position </summary>
[DefaultValue(0)]
public virtual int ScrollY {
get => scrollY;
set {
if (scrollY == value)
return;
int newS = value;
if (newS < 0)
newS = 0;
else if (newS > maxScrollY)
newS = maxScrollY;
if (newS == scrollY)
return;
scrollY = newS;
NotifyValueChangedAuto (scrollY);
RegisterForGraphicUpdate ();
if (widgets == null)
return;
Rectangle cb = ClientRectangle;
cb.Left += (int)leftMargin;
cb.Width -= (int)leftMargin;
cb.Y += (int)topMargin;
cb.Height -= (int)topMargin;
if (mousePos.Y < cb.Top || mousePos.Y > cb.Bottom)
hoverLine = -1;
else
hoverLine = (int)((double)(mousePos.Y - cb.Top) / fe.Height) + ScrollY;
NotifyValueChanged ("CurrentLine", hoverLine);
}
}
/// <summary> Horizontal Scrolling maximum value </summary>
[DefaultValue(0)]
public virtual long MaxScrollX {
get => maxScrollX;
set {
if (maxScrollX == value)
return;
maxScrollX = Math.Max(0, value);
if (scrollX > maxScrollX)
ScrollX = maxScrollX;
NotifyValueChangedAuto (maxScrollX);
RegisterForGraphicUpdate ();
}
}
/// <summary> Vertical Scrolling maximum value </summary>
[DefaultValue(0)]
public virtual int MaxScrollY {
get => maxScrollY;
set {
if (maxScrollY == value)
return;
maxScrollY = Math.Max (0, value);
if (scrollY > maxScrollY)
ScrollY = maxScrollY;
NotifyValueChangedAuto (maxScrollY);
RegisterForGraphicUpdate ();
}
}
/// <summary> Mouse Wheel Scrolling multiplier </summary>
[DefaultValue(1)]
public virtual int MouseWheelSpeed {
get => mouseWheelSpeed;
set {
if (mouseWheelSpeed == value)
return;
mouseWheelSpeed = value;
NotifyValueChangedAuto (mouseWheelSpeed);
}
}
}
}
|