Skip to content

Commit c900fad

Browse files
committed
[GraphNode] Fix slot focus rect draw, make slot focus mode configurable.
1 parent d7bdc0b commit c900fad

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

doc/classes/GraphNode.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@
272272
If [code]true[/code], you can connect ports with different types, even if the connection was not explicitly allowed in the parent [GraphEdit].
273273
</member>
274274
<member name="mouse_filter" type="int" setter="set_mouse_filter" getter="get_mouse_filter" overrides="Control" enum="Control.MouseFilter" default="0" />
275+
<member name="slots_focus_mode" type="int" setter="set_slots_focus_mode" getter="get_slots_focus_mode" enum="Control.FocusMode" default="3">
276+
Determines how connection slots can be focused.
277+
- If set to [constant Control.FOCUS_CLICK], connections can only be made with the mouse.
278+
- If set to [constant Control.FOCUS_ALL], slots can also be focused using the [member ProjectSettings.input/ui_up] and [member ProjectSettings.input/ui_down] and connected using [member ProjectSettings.input/ui_left] and [member ProjectSettings.input/ui_right] input actions.
279+
- If set to [constant Control.FOCUS_ACCESSIBILITY], slot input actions are only enabled when the screen reader is active.
280+
</member>
275281
<member name="title" type="String" setter="set_title" getter="get_title" default="&quot;&quot;">
276282
The text displayed in the GraphNode's title bar.
277283
</member>

scene/gui/graph_node.cpp

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -407,21 +407,25 @@ void GraphNode::gui_input(const Ref<InputEvent> &p_event) {
407407
}
408408

409409
if (p_event->is_pressed() && slot_count > 0) {
410-
if (p_event->is_action("ui_up", true)) {
411-
selected_slot--;
412-
if (selected_slot < 0) {
413-
selected_slot = -1;
414-
} else {
415-
accept_event();
416-
}
417-
} else if (p_event->is_action("ui_down", true)) {
418-
selected_slot++;
419-
if (selected_slot >= slot_count) {
420-
selected_slot = -1;
421-
} else {
422-
accept_event();
410+
bool ac_enabled = get_tree() && get_tree()->is_accessibility_enabled();
411+
if (((ac_enabled && slots_focus_mode == Control::FOCUS_ACCESSIBILITY) || slots_focus_mode == Control::FOCUS_ALL)) {
412+
if (p_event->is_action("ui_up", true)) {
413+
selected_slot--;
414+
if (selected_slot < 0) {
415+
selected_slot = -1;
416+
} else {
417+
accept_event();
418+
}
419+
} else if (p_event->is_action("ui_down", true)) {
420+
selected_slot++;
421+
if (selected_slot >= slot_count) {
422+
selected_slot = -1;
423+
} else {
424+
accept_event();
425+
}
423426
}
424-
} else if (p_event->is_action("ui_cancel", true)) {
427+
}
428+
if (p_event->is_action("ui_cancel", true)) {
425429
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
426430
if (graph && graph->is_keyboard_connecting()) {
427431
graph->force_connection_drag_end();
@@ -664,9 +668,18 @@ void GraphNode::_notification(int p_what) {
664668
}
665669

666670
if (slot_index == selected_slot) {
667-
Size2i port_sz = theme_cache.port->get_size();
668-
draw_style_box(sb_slot_selected, Rect2i(port_h_offset - port_sz.x, slot_y_cache[E.key] + sb_panel->get_margin(SIDE_TOP) - port_sz.y, port_sz.x * 2, port_sz.y * 2));
669-
draw_style_box(sb_slot_selected, Rect2i(get_size().x - port_h_offset - port_sz.x, slot_y_cache[E.key] + sb_panel->get_margin(SIDE_TOP) - port_sz.y, port_sz.x * 2, port_sz.y * 2));
671+
Ref<Texture2D> port_icon = slot.custom_port_icon_left;
672+
if (port_icon.is_null()) {
673+
port_icon = theme_cache.port;
674+
}
675+
Size2i port_sz = port_icon->get_size() + sb_slot_selected->get_minimum_size();
676+
draw_style_box(sb_slot_selected, Rect2i(port_h_offset - port_sz.x * 0.5, slot_y_cache[E.key] - port_sz.y * 0.5, port_sz.x, port_sz.y));
677+
port_icon = slot.custom_port_icon_right;
678+
if (port_icon.is_null()) {
679+
port_icon = theme_cache.port;
680+
}
681+
port_sz = port_icon->get_size() + sb_slot_selected->get_minimum_size();
682+
draw_style_box(sb_slot_selected, Rect2i(get_size().x - port_h_offset - port_sz.x * 0.5, slot_y_cache[E.key] - port_sz.y * 0.5, port_sz.x, port_sz.y));
670683
}
671684

672685
// Draw slot stylebox.
@@ -1180,6 +1193,23 @@ Vector<int> GraphNode::get_allowed_size_flags_vertical() const {
11801193
return flags;
11811194
}
11821195

1196+
void GraphNode::set_slots_focus_mode(Control::FocusMode p_focus_mode) {
1197+
if (slots_focus_mode == p_focus_mode) {
1198+
return;
1199+
}
1200+
ERR_FAIL_COND((int)p_focus_mode < 1 || (int)p_focus_mode > 3);
1201+
1202+
slots_focus_mode = p_focus_mode;
1203+
if (slots_focus_mode == Control::FOCUS_CLICK && selected_slot > -1) {
1204+
selected_slot = -1;
1205+
queue_redraw();
1206+
}
1207+
}
1208+
1209+
Control::FocusMode GraphNode::get_slots_focus_mode() const {
1210+
return slots_focus_mode;
1211+
}
1212+
11831213
void GraphNode::_bind_methods() {
11841214
ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
11851215
ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
@@ -1220,6 +1250,9 @@ void GraphNode::_bind_methods() {
12201250
ClassDB::bind_method(D_METHOD("set_ignore_invalid_connection_type", "ignore"), &GraphNode::set_ignore_invalid_connection_type);
12211251
ClassDB::bind_method(D_METHOD("is_ignoring_valid_connection_type"), &GraphNode::is_ignoring_valid_connection_type);
12221252

1253+
ClassDB::bind_method(D_METHOD("set_slots_focus_mode", "focus_mode"), &GraphNode::set_slots_focus_mode);
1254+
ClassDB::bind_method(D_METHOD("get_slots_focus_mode"), &GraphNode::get_slots_focus_mode);
1255+
12231256
ClassDB::bind_method(D_METHOD("get_input_port_count"), &GraphNode::get_input_port_count);
12241257
ClassDB::bind_method(D_METHOD("get_input_port_position", "port_idx"), &GraphNode::get_input_port_position);
12251258
ClassDB::bind_method(D_METHOD("get_input_port_type", "port_idx"), &GraphNode::get_input_port_type);
@@ -1236,6 +1269,7 @@ void GraphNode::_bind_methods() {
12361269

12371270
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
12381271
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_invalid_connection_type"), "set_ignore_invalid_connection_type", "is_ignoring_valid_connection_type");
1272+
ADD_PROPERTY(PropertyInfo(Variant::INT, "slots_focus_mode", PROPERTY_HINT_ENUM, "Click:1,All:2,Accessibility:3"), "set_slots_focus_mode", "get_slots_focus_mode");
12391273

12401274
ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "slot_index")));
12411275
ADD_SIGNAL(MethodInfo("slot_sizes_changed"));

scene/gui/graph_node.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class GraphNode : public GraphElement {
8585
HashMap<int, Slot> slot_table;
8686
Vector<int> slot_y_cache;
8787

88+
Control::FocusMode slots_focus_mode = Control::FOCUS_ACCESSIBILITY;
8889
int slot_count = 0;
8990
int selected_slot = -1;
9091

@@ -179,6 +180,9 @@ class GraphNode : public GraphElement {
179180
Color get_output_port_color(int p_port_idx);
180181
int get_output_port_slot(int p_port_idx);
181182

183+
void set_slots_focus_mode(Control::FocusMode p_focus_mode);
184+
Control::FocusMode get_slots_focus_mode() const;
185+
182186
virtual Size2 get_minimum_size() const override;
183187

184188
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;

0 commit comments

Comments
 (0)