Skip to content

Commit 2de205d

Browse files
committed
Improve alignment shortcuts
1 parent 0fe9935 commit 2de205d

7 files changed

Lines changed: 209 additions & 67 deletions

File tree

material_maker/doc/user_interface_main_menu.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ Edit menu
8080

8181
* *Select targets* selects all direct and indirect target nodes of the current selection
8282

83-
* *Align Start/Center/End* align selections horizontally
83+
* *Align Top* align selections vertically by their top edge
84+
85+
* *Align Start/End* align selections horizontally
86+
87+
* *Straighten Connections* straighens connection lines between two or more connected nodes.
8488

8589
* *Load Selection* Loads a graph selection previously saved into a file
8690

material_maker/main_window.gd

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ const MENU : Array[Dictionary] = [
8585
{ menu="Edit/Select Sources", command="edit_select_sources", shortcut="Control+L" },
8686
{ menu="Edit/Select Targets", command="edit_select_targets", shortcut="Control+Shift+L" },
8787
{ menu="Edit/-" },
88-
{ menu="Edit/Align Start", command="edit_align_start", shortcut="Control+BRACKETLEFT" },
89-
{ menu="Edit/Align Center", command="edit_align_center", shortcut="Control+BACKSLASH" },
90-
{ menu="Edit/Align End", command="edit_align_end", shortcut="Control+BRACKETRIGHT" },
88+
{ menu="Edit/Align Top", command="edit_align_top", shortcut="Shift+W" },
89+
{ menu="Edit/Align Start", command="edit_align_start", shortcut="Shift+A" },
90+
{ menu="Edit/Align End", command="edit_align_end", shortcut="Shift+D" },
91+
{ menu="Edit/Straighten Connections", command="edit_straighten_connections", shortcut="Q" },
9192
{ menu="Edit/-" },
9293
{ menu="Edit/Load Selection", command="edit_load_selection", not_in_ports=["HTML5"] },
9394
{ menu="Edit/Save Selection", command="edit_save_selection", not_in_ports=["HTML5"] },
@@ -991,33 +992,24 @@ func edit_preferences() -> void:
991992
dialog.edit_preferences(mm_globals.config)
992993

993994
func edit_align_start() -> void:
994-
var nodes : Array = get_current_graph_edit().get_selected_nodes()
995-
var min_offset : float = INF
996-
997-
for node : GraphElement in nodes:
998-
min_offset = min(min_offset, node.position_offset.x)
999-
for node : GraphElement in nodes:
1000-
node.position_offset.x = min_offset
1001-
1002-
func edit_align_center() -> void:
1003-
var nodes : Array = get_current_graph_edit().get_selected_nodes()
1004-
var min_offset : float = INF
1005-
var max_offset : float = -INF
1006-
1007-
for node : GraphElement in nodes:
1008-
max_offset = max(max_offset, node.position_offset.x + node.size.x)
1009-
min_offset = min(min_offset, node.position_offset.x)
1010-
for node : GraphElement in nodes:
1011-
node.position_offset.x = (max_offset + min_offset) * 0.5 - (node.size.x * 0.5)
995+
var graph_edit : MMGraphEdit = get_current_graph_edit()
996+
if graph_edit != null:
997+
graph_edit.align_start()
1012998

1013999
func edit_align_end() -> void:
1014-
var nodes : Array = get_current_graph_edit().get_selected_nodes()
1015-
var max_offset : float = -INF
1000+
var graph_edit : MMGraphEdit = get_current_graph_edit()
1001+
if graph_edit != null:
1002+
graph_edit.align_end()
1003+
1004+
func edit_align_top() -> void:
1005+
var graph_edit : MMGraphEdit = get_current_graph_edit()
1006+
if graph_edit != null:
1007+
graph_edit.align_top()
10161008

1017-
for node : GraphElement in nodes:
1018-
max_offset = max(max_offset, node.position_offset.x + node.size.x)
1019-
for node : GraphElement in nodes:
1020-
node.position_offset.x = max_offset - node.size.x
1009+
func edit_straighten_connections() -> void:
1010+
var graph_edit : MMGraphEdit = get_current_graph_edit()
1011+
if graph_edit != null:
1012+
graph_edit.straighten_connections()
10211013

10221014
func view_center() -> void:
10231015
var graph_edit : MMGraphEdit = get_current_graph_edit()

material_maker/panels/graph_edit/graph_align_menu.gd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ func _on_align_start_pressed() -> void:
55
mm_globals.main_window.edit_align_start()
66

77

8-
func _on_align_center_pressed() -> void:
9-
mm_globals.main_window.edit_align_center()
10-
11-
128
func _on_align_end_pressed() -> void:
139
mm_globals.main_window.edit_align_end()
10+
11+
12+
func _on_align_top_pressed() -> void:
13+
mm_globals.main_window.edit_align_top()
14+
15+
16+
func _on_straighten_pressed() -> void:
17+
mm_globals.main_window.edit_straighten_connections()

material_maker/panels/graph_edit/graph_edit.gd

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,6 @@ func _gui_input(event) -> void:
267267
minimize_selection()
268268
KEY_DELETE,KEY_BACKSPACE,KEY_X:
269269
remove_selection()
270-
KEY_C:
271-
if OS.get_name() == "macOS":
272-
center_view()
273-
KEY_MASK_ALT | KEY_S:
274-
if OS.get_name() == "macOS":
275-
swap_node_inputs()
276270
KEY_LEFT:
277271
scroll_offset.x -= 0.5*size.x
278272
accept_event()
@@ -292,6 +286,26 @@ func _gui_input(event) -> void:
292286
has_grab = true
293287
KEY_ESCAPE:
294288
has_grab = false
289+
290+
# macOS global menu does not support single-key accelerators
291+
# and they also require Cmd/Ctrl to be present in them to work
292+
# see https://github.com/godotengine/godot/issues/108622
293+
# As a workaround the menu items are invoked here
294+
if OS.get_name() == "macOS":
295+
match scancode_with_modifiers:
296+
KEY_C:
297+
center_view()
298+
KEY_MASK_ALT | KEY_S:
299+
swap_node_inputs()
300+
KEY_Q:
301+
straighten_connections()
302+
KEY_MASK_SHIFT | KEY_W:
303+
align_top()
304+
KEY_MASK_SHIFT | KEY_A:
305+
align_start()
306+
KEY_MASK_SHIFT | KEY_D:
307+
align_end()
308+
295309
match event.get_keycode():
296310
KEY_SHIFT, KEY_CTRL, KEY_ALT:
297311
var found_tip : bool = false
@@ -1811,3 +1825,53 @@ func _on_resized() -> void:
18111825
$GraphUI.size = Vector2.ZERO
18121826
$GraphUI.position = global_position
18131827
$GraphUI.position += Vector2(size.x - $GraphUI.size.x, 11)
1828+
1829+
func align_start() -> void:
1830+
var nodes : Array = get_selected_nodes()
1831+
var min_offset : float = INF
1832+
1833+
for node : GraphElement in nodes:
1834+
min_offset = min(min_offset, node.position_offset.x)
1835+
for node : GraphElement in nodes:
1836+
node.position_offset.x = min_offset
1837+
1838+
func align_end() -> void:
1839+
var nodes : Array = get_selected_nodes()
1840+
var max_offset : float = -INF
1841+
1842+
for node : GraphElement in nodes:
1843+
max_offset = max(max_offset, node.position_offset.x + node.size.x)
1844+
for node : GraphElement in nodes:
1845+
node.position_offset.x = max_offset - node.size.x
1846+
1847+
func align_top() -> void:
1848+
var nodes : Array = get_selected_nodes().filter(func(n): return n is GraphNode)
1849+
nodes.sort_custom(func(a: GraphNode, b: GraphNode):
1850+
return a.position_offset.x < b.position_offset.x)
1851+
for node in nodes:
1852+
node.position_offset.y = nodes[0].position_offset.y
1853+
1854+
func straighten_connections() -> void:
1855+
# basic connection straightening
1856+
# this expects selected nodes to be connected along a line
1857+
# and connections are made from left to right(in/out port position)
1858+
var nodes : Array = get_selected_nodes().filter(func(n): return n is GraphNode)
1859+
if nodes.size() < 2:
1860+
return
1861+
nodes.sort_custom(func(a, b) -> bool:
1862+
return a.position_offset.x < b.position_offset.x)
1863+
for i in nodes.size() - 1:
1864+
var from_node : MMGraphNodeMinimal = nodes[i]
1865+
var to_node : MMGraphNodeMinimal = nodes[i + 1]
1866+
var conns : Array[Dictionary]
1867+
for c in connections:
1868+
if c.to_node == to_node.name:
1869+
conns.append(c)
1870+
if conns.is_empty():
1871+
return
1872+
for conn in conns:
1873+
if conn.from_node == from_node.name:
1874+
var from_pos_y = from_node.get_output_port_position(conn.from_port).y + from_node.position_offset.y
1875+
var to_pos_y = to_node.get_input_port_position(conn.to_port).y + to_node.position_offset.y
1876+
var y_diff = to_pos_y - from_pos_y
1877+
to_node.position_offset.y -= y_diff

material_maker/projects_panel.tscn

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,15 @@ icon_alignment = 1
424424
script = ExtResource("7_qnupl")
425425
icon_name = "align_start"
426426

427-
[node name="AlignCenter" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
427+
[node name="AlignTop" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
428428
custom_minimum_size = Vector2(25, 25)
429429
layout_mode = 2
430-
tooltip_text = "Align Center"
430+
tooltip_text = "Align Top"
431431
shortcut = SubResource("Shortcut_7tisq")
432432
shortcut_in_tooltip = false
433433
icon_alignment = 1
434434
script = ExtResource("7_qnupl")
435-
icon_name = "align_center"
435+
icon_name = "align_top"
436436

437437
[node name="AlignEnd" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
438438
custom_minimum_size = Vector2(25, 25)
@@ -444,6 +444,16 @@ icon_alignment = 1
444444
script = ExtResource("7_qnupl")
445445
icon_name = "align_end"
446446

447+
[node name="Straighten" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
448+
custom_minimum_size = Vector2(25, 25)
449+
layout_mode = 2
450+
tooltip_text = "Straighten Connections"
451+
shortcut = SubResource("Shortcut_7tisq")
452+
shortcut_in_tooltip = false
453+
icon_alignment = 1
454+
script = ExtResource("7_qnupl")
455+
icon_name = "straighten_connections"
456+
447457
[node name="PreviewsMenu" type="PanelContainer" parent="MenuBar/HBox"]
448458
unique_name_in_owner = true
449459
layout_mode = 2
@@ -508,8 +518,9 @@ Scroll to zoom the 3D Preview."
508518
[connection signal="value_changed" from="MenuBar/HBox/MainGraphMenuBar/HBox/ViewMenu/ViewMenuPanel/VBoxContainer/VBoxContainer2/Curvature/LineCurvature" to="MenuBar/HBox/MainGraphMenuBar/HBox/ViewMenu" method="_on_line_curvature_value_changed"]
509519
[connection signal="value_changed" from="MenuBar/HBox/MainGraphMenuBar/HBox/ViewMenu/ViewMenuPanel/VBoxContainer/VBoxContainer2/Curvature/LineCurvature" to="MenuBar/HBox/MainGraphMenuBar/HBox/ViewMenu/ViewMenuPanel" method="_on_line_curvature_value_changed"]
510520
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignStart" to="MenuBar/HBox/AlignMenu" method="_on_align_start_pressed"]
511-
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignCenter" to="MenuBar/HBox/AlignMenu" method="_on_align_center_pressed"]
521+
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignTop" to="MenuBar/HBox/AlignMenu" method="_on_align_top_pressed"]
512522
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignEnd" to="MenuBar/HBox/AlignMenu" method="_on_align_end_pressed"]
523+
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/Straighten" to="MenuBar/HBox/AlignMenu" method="_on_straighten_pressed"]
513524
[connection signal="toggled" from="MenuBar/HBox/PreviewsMenu/HBox/2DPreview" to="." method="show_background_preview_2d"]
514525
[connection signal="toggled" from="MenuBar/HBox/PreviewsMenu/HBox/3DPreview" to="." method="show_background_preview_3d"]
515526
[connection signal="gui_input" from="MenuBar/HBox/PreviewsMenu/HBox/ControlView" to="BackgroundPreviews/Preview3D" method="on_gui_input"]

material_maker/theme/default.tres

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,6 @@ metadata/recolor = true
397397
atlas = ExtResource("1_s43fy")
398398
region = Rect2(32, 96, 16, 16)
399399

400-
[sub_resource type="AtlasTexture" id="AtlasTexture_khddu"]
401-
atlas = ExtResource("1_s43fy")
402-
region = Rect2(16, 208, 16, 16)
403-
404400
[sub_resource type="AtlasTexture" id="AtlasTexture_xbfay"]
405401
atlas = ExtResource("1_s43fy")
406402
region = Rect2(32, 208, 16, 16)
@@ -409,6 +405,10 @@ region = Rect2(32, 208, 16, 16)
409405
atlas = ExtResource("1_s43fy")
410406
region = Rect2(0, 208, 16, 16)
411407

408+
[sub_resource type="AtlasTexture" id="AtlasTexture_khddu"]
409+
atlas = ExtResource("1_s43fy")
410+
region = Rect2(16, 208, 16, 16)
411+
412412
[sub_resource type="AtlasTexture" id="AtlasTexture_60g77"]
413413
atlas = ExtResource("1_s43fy")
414414
region = Rect2(96, 144, 16, 16)
@@ -593,6 +593,13 @@ region = Rect2(96, 16, 16, 16)
593593
atlas = ExtResource("1_s43fy")
594594
region = Rect2(48, 16, 16, 16)
595595

596+
[sub_resource type="AtlasTexture" id="AtlasTexture_8xpdb"]
597+
atlas = ExtResource("1_s43fy")
598+
region = Rect2(48, 208, 15, 16)
599+
600+
[sub_resource type="AtlasTexture" id="AtlasTexture_a1e3v"]
601+
atlas = SubResource("AtlasTexture_8xpdb")
602+
596603
[sub_resource type="AtlasTexture" id="AtlasTexture_en6gw"]
597604
atlas = ExtResource("1_s43fy")
598605
region = Rect2(0, 0, 16, 16)
@@ -1258,9 +1265,9 @@ MM_Icons/icons/2D_preview = SubResource("AtlasTexture_1yu4y")
12581265
MM_Icons/icons/3D_preview = SubResource("AtlasTexture_ao7ds")
12591266
MM_Icons/icons/3D_preview_control = SubResource("AtlasTexture_hht3q")
12601267
MM_Icons/icons/add_image = SubResource("AtlasTexture_86qok")
1261-
MM_Icons/icons/align_center = SubResource("AtlasTexture_khddu")
12621268
MM_Icons/icons/align_end = SubResource("AtlasTexture_xbfay")
12631269
MM_Icons/icons/align_start = SubResource("AtlasTexture_nw6qx")
1270+
MM_Icons/icons/align_top = SubResource("AtlasTexture_khddu")
12641271
MM_Icons/icons/arrange_nodes = SubResource("AtlasTexture_60g77")
12651272
MM_Icons/icons/arrow_left = SubResource("AtlasTexture_q32qs")
12661273
MM_Icons/icons/arrow_right = SubResource("AtlasTexture_r3xak")
@@ -1305,6 +1312,7 @@ MM_Icons/icons/spline_link = SubResource("AtlasTexture_fs6qc")
13051312
MM_Icons/icons/spline_progressive = SubResource("AtlasTexture_70aex")
13061313
MM_Icons/icons/spline_reverse = SubResource("AtlasTexture_ahanl")
13071314
MM_Icons/icons/spline_unlink = SubResource("AtlasTexture_iofl8")
1315+
MM_Icons/icons/straighten_connections = SubResource("AtlasTexture_a1e3v")
13081316
MM_Icons/icons/view = SubResource("AtlasTexture_en6gw")
13091317
MM_Icons/icons/zoom = SubResource("AtlasTexture_iyaen")
13101318
MM_Icons/icons/zoom_in = SubResource("AtlasTexture_5k62t")

0 commit comments

Comments
 (0)