1
+ using System ;
1
2
using Godot ;
2
3
using GodotExt ;
3
4
using JetBrains . Annotations ;
@@ -7,18 +8,81 @@ namespace OpenScadGraphEditor.Widgets.StylusDebugDialog
7
8
[ UsedImplicitly ]
8
9
public class StylusDebugDialog : WindowDialog
9
10
{
10
- private Label _debugLabel ;
11
+ private TextEdit _debugEdit ;
12
+ private int _motionEventCount ;
13
+ private Vector2 _motionStart ;
14
+ private Vector2 _motionEnd ;
11
15
12
16
public override void _Ready ( )
13
17
{
14
- _debugLabel = this . WithName < Label > ( "DebugLabel" ) ;
18
+ _debugEdit = this . WithName < TextEdit > ( "DebugEdit" ) ;
19
+
20
+ this . WithName < Control > ( "TestContainer" )
21
+ . Connect ( "gui_input" )
22
+ . To ( this , nameof ( OnGuiInput ) ) ;
23
+
24
+ this . WithName < Button > ( "CopyToClipboardButton" )
25
+ . Connect ( "pressed" )
26
+ . To ( this , nameof ( OnCopyToClipboardPressed ) ) ;
27
+
28
+ this . WithName < Button > ( "ClearButton" )
29
+ . Connect ( "pressed" )
30
+ . To ( this , nameof ( OnClearButtonPressed ) ) ;
15
31
}
16
32
17
- public override void _GuiInput ( InputEvent @event )
33
+ private void OnGuiInput ( InputEvent @event )
18
34
{
19
-
20
- var type = @event . GetType ( ) . Name ;
21
- _debugLabel . Text = type ;
35
+ // count motion events and compress them into a single output line
36
+ if ( @event is InputEventMouseMotion motionEvent )
37
+ {
38
+ if ( _motionEventCount == 0 )
39
+ {
40
+ _motionStart = motionEvent . Position ;
41
+ AddToDebugEdit ( "Mouse Motion begin at: " + _motionStart + "\n " ) ;
42
+ }
43
+ _motionEnd = motionEvent . Position ;
44
+ _motionEventCount ++ ;
45
+ return ;
46
+ }
47
+
48
+ // if we have pending motion events, output them now
49
+ if ( _motionEventCount > 0 )
50
+ {
51
+ AddToDebugEdit ( $ "Mouse Motion ends ({ _motionEventCount } motion events suppressed) at: { _motionEnd } \n ") ;
52
+ _motionEventCount = 0 ;
53
+ }
54
+
55
+ if ( @event is InputEventMouseButton buttonEvent )
56
+ {
57
+ AddToDebugEdit ( $ "Button { buttonEvent . ButtonIndex } pressed: { buttonEvent . Pressed } \n ") ;
58
+ return ;
59
+ }
60
+
61
+ if ( @event is InputEventKey keyEvent )
62
+ {
63
+ AddToDebugEdit ( $ "Key { keyEvent . Scancode } pressed: { keyEvent . Pressed } \n ") ;
64
+ return ;
65
+ }
66
+
67
+ // other events, just print their type
68
+ AddToDebugEdit ( "{@event.GetType().Name}\n " ) ;
69
+ }
70
+
71
+ private void AddToDebugEdit ( string text )
72
+ {
73
+ _debugEdit . Text += text ;
74
+ _debugEdit . ScrollVertical = double . MaxValue ;
75
+ }
76
+
77
+ private void OnCopyToClipboardPressed ( )
78
+ {
79
+ OS . Clipboard = _debugEdit . Text ;
80
+ }
81
+
82
+
83
+ private void OnClearButtonPressed ( )
84
+ {
85
+ _debugEdit . Text = "" ;
22
86
}
23
87
}
24
88
}
0 commit comments