Skip to content

Commit 14d1738

Browse files
committed
feat: improve stylus debugging dialog
1 parent bd82b59 commit 14d1738

File tree

2 files changed

+107
-25
lines changed

2 files changed

+107
-25
lines changed
Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Godot;
23
using GodotExt;
34
using JetBrains.Annotations;
@@ -7,18 +8,81 @@ namespace OpenScadGraphEditor.Widgets.StylusDebugDialog
78
[UsedImplicitly]
89
public class StylusDebugDialog : WindowDialog
910
{
10-
private Label _debugLabel;
11+
private TextEdit _debugEdit;
12+
private int _motionEventCount;
13+
private Vector2 _motionStart;
14+
private Vector2 _motionEnd;
1115

1216
public override void _Ready()
1317
{
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));
1531
}
1632

17-
public override void _GuiInput(InputEvent @event)
33+
private void OnGuiInput(InputEvent @event)
1834
{
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 = "";
2286
}
2387
}
2488
}

Widgets/StylusDebugDialog/StylusDebugDialog.tscn

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
[ext_resource path="res://Widgets/StylusDebugDialog/StylusDebugDialog.cs" type="Script" id=1]
44

55
[node name="StylusDebugDialog" type="WindowDialog"]
6+
visible = true
67
anchor_left = 0.5
78
anchor_top = 0.5
89
anchor_right = 0.5
910
anchor_bottom = 0.5
10-
margin_left = -398.0
11-
margin_top = -212.0
12-
margin_right = 398.0
13-
margin_bottom = 212.0
11+
margin_left = -602.0
12+
margin_top = -320.0
13+
margin_right = 672.0
14+
margin_bottom = 353.0
1415
window_title = "Stylus Debug"
1516
script = ExtResource( 1 )
1617

@@ -26,22 +27,39 @@ custom_constants/margin_bottom = 10
2627
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
2728
margin_left = 10.0
2829
margin_top = 10.0
29-
margin_right = 786.0
30-
margin_bottom = 414.0
30+
margin_right = 1264.0
31+
margin_bottom = 663.0
3132

3233
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
33-
margin_right = 776.0
34-
margin_bottom = 25.0
35-
text = "Test stylus below"
36-
37-
[node name="PanelContainer" type="PanelContainer" parent="MarginContainer/VBoxContainer"]
38-
margin_top = 33.0
39-
margin_right = 776.0
40-
margin_bottom = 371.0
41-
mouse_filter = 2
34+
margin_right = 1254.0
35+
margin_bottom = 20.0
36+
text = "Test the stylus at the blank area below, try clicking and dragging. "
37+
autowrap = true
38+
39+
[node name="TestContainer" type="PanelContainer" parent="MarginContainer/VBoxContainer"]
40+
margin_top = 28.0
41+
margin_right = 1254.0
42+
margin_bottom = 316.0
43+
size_flags_vertical = 3
44+
45+
[node name="DebugEdit" type="TextEdit" parent="MarginContainer/VBoxContainer"]
46+
margin_top = 324.0
47+
margin_right = 1254.0
48+
margin_bottom = 613.0
4249
size_flags_vertical = 3
4350

44-
[node name="DebugLabel" type="Label" parent="MarginContainer/VBoxContainer"]
45-
margin_top = 379.0
46-
margin_right = 776.0
47-
margin_bottom = 404.0
51+
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
52+
margin_top = 621.0
53+
margin_right = 1254.0
54+
margin_bottom = 653.0
55+
56+
[node name="CopyToClipboardButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
57+
margin_right = 178.0
58+
margin_bottom = 32.0
59+
text = "Copy text to clipboard"
60+
61+
[node name="ClearButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
62+
margin_left = 186.0
63+
margin_right = 247.0
64+
margin_bottom = 32.0
65+
text = "Clear"

0 commit comments

Comments
 (0)