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
|
// Copyright (c) 2013-2020 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;
#if VKVG
using vkvg;
#else
using Crow.Cairo;
#endif
using Crow.DebugLogger;
using DebugLogAnalyzer;
namespace Crow
{
public class DbgEventView : TemplatedContainer {
DbgEvent evt;
public DbgEvent Event {
get => evt;
set {
if (evt == value)
return;
evt = value;
NotifyValueChangedAuto (evt);
}
}
}
public class DbgEventWidget : Widget
{
public DbgEventWidget (){}
DbgEvent evt, hoverEvt;
long ticksPerPixel;
double pixelPerTick;
public DbgEvent Event {
get => evt;
set {
if (evt == value)
return;
evt = value;
updatePixelPerTicks ();
NotifyValueChangedAuto (evt);
RegisterForRedraw ();
}
}
public DbgEvent HoverEvent {
get => hoverEvt;
private set {
if (hoverEvt == value)
return;
hoverEvt = value;
NotifyValueChangedAuto (hoverEvt);
}
}
[DefaultValue ("1000")]
public long TicksPerPixel {
get => ticksPerPixel;
set {
if (ticksPerPixel == value)
return;
ticksPerPixel = value;
NotifyValueChangedAuto (ticksPerPixel);
if (Width == Measure.Fit)
RegisterForLayouting (LayoutingType.Width);
}
}
public override int measureRawSize (LayoutingType lt)
{
updatePixelPerTicks ();
if (lt == LayoutingType.Width)
contentSize.Width = Event == null ? 0 : (int)Math.Max(pixelPerTick * Event.Duration, 2);
return base.measureRawSize (lt);
}
public override void OnLayoutChanges (LayoutingType layoutType)
{
if (layoutType == LayoutingType.Width)
updatePixelPerTicks ();
base.OnLayoutChanges (layoutType);
}
protected override void onDraw (Context gr)
{
if (Event == null) {
base.onDraw (gr);
return;
}
gr.LineWidth = 1;
gr.SetDash (new double [] { 1.0, 3.0 }, 0);
Rectangle cb = ClientRectangle;
if (Event.Duration == 0) {
gr.SetSource (Event.Color);
gr.Rectangle (cb);
gr.Fill ();
return;
}
drawEvent (gr, cb.Height, Event);
}
void drawEvent (Context ctx, int h, DbgEvent dbge)
{
double w = Math.Max(dbge.Duration * pixelPerTick, 2.0);
double x = (dbge.begin - Event.begin) * pixelPerTick;
ctx.Rectangle (x, 0, w, h);
ctx.SetSource (dbge.Color);
/*if (dbge.IsSelected) {
ctx.FillPreserve ();
ctx.SetSource (1, 1, 1);
ctx.Stroke ();
}else*/
ctx.Fill ();
if (dbge.Events == null)
return;
foreach (DbgEvent e in dbge.Events)
drawEvent (ctx, h, e);
}
public override void onMouseMove (object sender, MouseMoveEventArgs e)
{
if (Event != null) {
Point m = ScreenPointToLocal (e.Position);
long curTick = (long)(m.X / pixelPerTick) + Event.begin;
HoverEvent = hoverEvent (Event, curTick);
e.Handled = true;
}
base.onMouseMove (sender, e);
}
DbgEvent hoverEvent (DbgEvent hevt, long curTick){
if (hevt.Events != null) {
foreach (DbgEvent e in hevt.Events) {
if (curTick >= e.begin && curTick <= e.end)
return hoverEvent (e, curTick);
}
}
return hevt;
}
void updatePixelPerTicks ()
{
if (Width == Measure.Fit)
pixelPerTick = 1.0 / ticksPerPixel;
else
pixelPerTick = Event == null ? 0 : (double)ClientRectangle.Width / Event.Duration;
}
}
}
|