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
|
extends ScrollContainer
class_name Stage
signal save # (database_entry: Dictionary)
signal discard # ()
const POINTER_VELOCITY_DECAYING_FACTOR: float = 2.5
var is_pointer_dragging := false
var pointer_drag_velocity := 0.0
onready var process_id: LineEdit = get_node("controls/process_id")
onready var surgery_id: LineEdit = get_node("controls/surgery_id")
onready var date: DatePicker = get_node("controls/date_picker")
onready var place: LineEdit = get_node("controls/place")
onready var anesthetic: LineEdit = get_node("controls/anesthetic")
onready var first_assistant: LineEdit = get_node("controls/first_assistant")
onready var type: LineEdit = get_node("controls/type")
onready var sub_type: LineEdit = get_node("controls/sub_type")
onready var sub_sub_type: LineEdit = get_node("controls/sub_sub_type")
onready var pathology: LineEdit = get_node("controls/pathology")
onready var intervention: LineEdit = get_node("controls/intervention")
onready var is_urgency: Button = get_node("controls/is_urgency")
onready var notes: LineEdit = get_node("controls/notes")
onready var save_button: Button = get_node("controls/save")
onready var discard_button: Button = get_node("controls/discard")
onready var v_scroll_bar: VScrollBar = get_v_scrollbar()
func _ready():
save_button.connect("pressed", self, "save_action")
discard_button.connect("pressed", self, "discard_action")
for it in get_node("controls").get_children():
it = it as Control
match it.name:
"date_picker", "save", "discard":
pass
_:
var drag_sensor = PointerInputSensor.new()
it.add_child(drag_sensor)
drag_sensor.name = "drag_sensor"
drag_sensor.anchor_right = 1.0
drag_sensor.anchor_bottom = 1.0
drag_sensor.connect("on_press", self, "pointer_input_handler")
drag_sensor.connect("on_drag", self, "pointer_input_handler")
drag_sensor.connect("on_end_drag", self, "pointer_input_handler")
drag_sensor.connect("on_click", self, "pointer_input_handler")
it.connect("focus_entered", drag_sensor, "set_mouse_filter", [Control.MOUSE_FILTER_IGNORE])
it.connect("focus_entered", drag_sensor, "mouse_default_cursor_shape", [Control.CURSOR_IBEAM])
it.connect("focus_exited", drag_sensor, "set_mouse_filter", [Control.MOUSE_FILTER_STOP])
it.connect("focus_exited", drag_sensor, "mouse_default_cursor_shape", [Control.CURSOR_ARROW])
if it is LineEdit:
it.connect("focus_exited", it, "deselect")
func _process(delta: float):
# Apply drag movement inertia.
if is_pointer_dragging == false && abs(pointer_drag_velocity) > 0.5:
pointer_drag_velocity *= clamp((1.0 - POINTER_VELOCITY_DECAYING_FACTOR * delta), 0.0, 1.0)
v_scroll_bar.value -= pointer_drag_velocity * delta
func save_action():
self.visible = false
emit_signal("save", get_stage())
func discard_action():
self.visible = false
emit_signal("discard")
func set_stage(entry: Dictionary):
process_id.text = entry.process_id
surgery_id.text = entry.surgery_id
date.set_date(entry.date_year, entry.date_month, entry.date_day)
place.text = entry.place
anesthetic.text = entry.anesthetic
first_assistant.text = entry.first_assistant
type.text = entry.type
sub_type.text = entry.sub_type
sub_sub_type.text = entry.sub_sub_type
pathology.text = entry.pathology
intervention.text = entry.intervention
is_urgency.pressed = entry.is_urgency
notes.text = entry.notes
self.scroll_vertical = 0 # @DAM TODO
func get_stage() -> Dictionary:
# @DAM Simplify all this... avoid creating multiple entries/dictionaries.
var entry: Dictionary = {
"process_id": process_id.text,
"surgery_id": surgery_id.text,
"date_year": date.get_year(),
"date_month": date.get_month(),
"date_day": date.get_day(),
"place": place.text,
"anesthetic": anesthetic.text,
"first_assistant": first_assistant.text,
"type": type.text,
"sub_type": sub_type.text,
"sub_sub_type": sub_sub_type.text,
"pathology": pathology.text,
"intervention": intervention.text,
"is_urgency": is_urgency.pressed,
"notes": notes.text,
}
return entry
func _notification(what: int):
if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
discard_action()
func pointer_input_handler(pointer: PointerInputSensor.PointerInputData):
match pointer.action:
PointerInputSensor.PointerInputAction.ON_PRESS:
is_pointer_dragging = true
PointerInputSensor.PointerInputAction.ON_DRAG:
is_pointer_dragging = true
pointer_drag_velocity = pointer.velocity.y
v_scroll_bar.value -= pointer.relative_position.y
PointerInputSensor.PointerInputAction.ON_END_DRAG:
is_pointer_dragging = false
PointerInputSensor.PointerInputAction.ON_CLICK:
var target: Control = pointer.target.get_parent()
var position := target.get_global_mouse_position() - target.rect_global_position
var event_touch := InputEventScreenTouch.new()
event_touch.index = 0
event_touch.position = position
var event_mouse := InputEventMouseButton.new()
event_mouse.button_index = BUTTON_LEFT
event_mouse.button_mask = BUTTON_MASK_LEFT
event_mouse.position = position
event_mouse.pressed = true
event_touch.pressed = true
target._gui_input(event_mouse)
target._gui_input(event_touch)
target.grab_focus()
event_mouse.pressed = false
event_touch.pressed = false
target._gui_input(event_mouse)
target._gui_input(event_touch)
|