Skip to content

Commit 88fbd4c

Browse files
committed
Improve alignment shortcuts
1 parent aa4fe74 commit 88fbd4c

File tree

8 files changed

+224
-87
lines changed

8 files changed

+224
-87
lines changed

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* straighten connection lines along 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"] },
@@ -1000,33 +1001,24 @@ func edit_preferences() -> void:
10001001
dialog.edit_preferences(mm_globals.config)
10011002

10021003
func edit_align_start() -> void:
1003-
var nodes : Array = get_current_graph_edit().get_selected_nodes()
1004-
var min_offset : float = INF
1005-
1006-
for node : GraphElement in nodes:
1007-
min_offset = min(min_offset, node.position_offset.x)
1008-
for node : GraphElement in nodes:
1009-
node.position_offset.x = min_offset
1010-
1011-
func edit_align_center() -> void:
1012-
var nodes : Array = get_current_graph_edit().get_selected_nodes()
1013-
var min_offset : float = INF
1014-
var max_offset : float = -INF
1015-
1016-
for node : GraphElement in nodes:
1017-
max_offset = max(max_offset, node.position_offset.x + node.size.x)
1018-
min_offset = min(min_offset, node.position_offset.x)
1019-
for node : GraphElement in nodes:
1020-
node.position_offset.x = (max_offset + min_offset) * 0.5 - (node.size.x * 0.5)
1004+
var graph_edit : MMGraphEdit = get_current_graph_edit()
1005+
if graph_edit != null:
1006+
graph_edit.align_start()
10211007

10221008
func edit_align_end() -> void:
1023-
var nodes : Array = get_current_graph_edit().get_selected_nodes()
1024-
var max_offset : float = -INF
1009+
var graph_edit : MMGraphEdit = get_current_graph_edit()
1010+
if graph_edit != null:
1011+
graph_edit.align_end()
1012+
1013+
func edit_align_top() -> void:
1014+
var graph_edit : MMGraphEdit = get_current_graph_edit()
1015+
if graph_edit != null:
1016+
graph_edit.align_top()
10251017

1026-
for node : GraphElement in nodes:
1027-
max_offset = max(max_offset, node.position_offset.x + node.size.x)
1028-
for node : GraphElement in nodes:
1029-
node.position_offset.x = max_offset - node.size.x
1018+
func edit_straighten_connections() -> void:
1019+
var graph_edit : MMGraphEdit = get_current_graph_edit()
1020+
if graph_edit != null:
1021+
graph_edit.straighten_connections()
10301022

10311023
func view_center() -> void:
10321024
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
@@ -274,12 +274,6 @@ func _gui_input(event) -> void:
274274
minimize_selection()
275275
KEY_DELETE,KEY_BACKSPACE,KEY_X:
276276
remove_selection()
277-
KEY_C:
278-
if OS.get_name() == "macOS":
279-
center_view()
280-
KEY_MASK_ALT | KEY_S:
281-
if OS.get_name() == "macOS":
282-
swap_node_inputs()
283277
KEY_LEFT:
284278
scroll_offset.x -= 0.5*size.x
285279
accept_event()
@@ -299,6 +293,26 @@ func _gui_input(event) -> void:
299293
has_grab = true
300294
KEY_ESCAPE:
301295
has_grab = false
296+
297+
# macOS global menu does not support single-key accelerators
298+
# and they also require Cmd/Ctrl to be present in them to work
299+
# see https://github.com/godotengine/godot/issues/108622
300+
# As a workaround the menu items are invoked here
301+
if OS.get_name() == "macOS":
302+
match scancode_with_modifiers:
303+
KEY_C:
304+
center_view()
305+
KEY_MASK_ALT | KEY_S:
306+
swap_node_inputs()
307+
KEY_Q:
308+
straighten_connections()
309+
KEY_MASK_SHIFT | KEY_W:
310+
align_top()
311+
KEY_MASK_SHIFT | KEY_A:
312+
align_start()
313+
KEY_MASK_SHIFT | KEY_D:
314+
align_end()
315+
302316
match event.get_keycode():
303317
KEY_SHIFT, KEY_CTRL, KEY_ALT:
304318
var found_tip : bool = false
@@ -1924,3 +1938,53 @@ func _on_connection_drag_started(_from_node : StringName, _from_port : int, _is_
19241938

19251939
func _on_connection_drag_ended() -> void:
19261940
is_dragging_connection = false
1941+
1942+
func align_start() -> void:
1943+
var nodes : Array = get_selected_nodes()
1944+
var min_offset : float = INF
1945+
1946+
for node : GraphElement in nodes:
1947+
min_offset = min(min_offset, node.position_offset.x)
1948+
for node : GraphElement in nodes:
1949+
node.position_offset.x = min_offset
1950+
1951+
func align_end() -> void:
1952+
var nodes : Array = get_selected_nodes()
1953+
var max_offset : float = -INF
1954+
1955+
for node : GraphElement in nodes:
1956+
max_offset = max(max_offset, node.position_offset.x + node.size.x)
1957+
for node : GraphElement in nodes:
1958+
node.position_offset.x = max_offset - node.size.x
1959+
1960+
func align_top() -> void:
1961+
var nodes : Array = get_selected_nodes().filter(func(n): return n is GraphNode)
1962+
nodes.sort_custom(func(a: GraphNode, b: GraphNode):
1963+
return a.position_offset.x < b.position_offset.x)
1964+
for node in nodes:
1965+
node.position_offset.y = nodes[0].position_offset.y
1966+
1967+
func straighten_connections() -> void:
1968+
# basic connection straightening
1969+
# expects selected nodes to be connected along a line
1970+
# and connections are made from left to right(in/out port position)
1971+
var nodes : Array = get_selected_nodes().filter(func(n): return n is GraphNode)
1972+
if nodes.size() < 2:
1973+
return
1974+
nodes.sort_custom(func(a, b) -> bool:
1975+
return a.position_offset.x < b.position_offset.x)
1976+
for i in nodes.size() - 1:
1977+
var from_node : MMGraphNodeMinimal = nodes[i]
1978+
var to_node : MMGraphNodeMinimal = nodes[i + 1]
1979+
var conns : Array[Dictionary]
1980+
for c in connections:
1981+
if c.to_node == to_node.name:
1982+
conns.append(c)
1983+
if conns.is_empty():
1984+
return
1985+
for conn in conns:
1986+
if conn.from_node == from_node.name:
1987+
var from_pos_y = from_node.get_output_port_position(conn.from_port).y + from_node.position_offset.y
1988+
var to_pos_y = to_node.get_input_port_position(conn.to_port).y + to_node.position_offset.y
1989+
var y_diff = to_pos_y - from_pos_y
1990+
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
@@ -439,15 +439,15 @@ icon_alignment = 1
439439
script = ExtResource("7_qnupl")
440440
icon_name = "align_start"
441441

442-
[node name="AlignCenter" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
442+
[node name="AlignTop" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
443443
custom_minimum_size = Vector2(25, 25)
444444
layout_mode = 2
445-
tooltip_text = "Align Center"
445+
tooltip_text = "Align Top"
446446
shortcut = SubResource("Shortcut_7tisq")
447447
shortcut_in_tooltip = false
448448
icon_alignment = 1
449449
script = ExtResource("7_qnupl")
450-
icon_name = "align_center"
450+
icon_name = "align_top"
451451

452452
[node name="AlignEnd" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
453453
custom_minimum_size = Vector2(25, 25)
@@ -459,6 +459,16 @@ icon_alignment = 1
459459
script = ExtResource("7_qnupl")
460460
icon_name = "align_end"
461461

462+
[node name="Straighten" type="Button" parent="MenuBar/HBox/AlignMenu/HBox"]
463+
custom_minimum_size = Vector2(25, 25)
464+
layout_mode = 2
465+
tooltip_text = "Straighten Connections"
466+
shortcut = SubResource("Shortcut_7tisq")
467+
shortcut_in_tooltip = false
468+
icon_alignment = 1
469+
script = ExtResource("7_qnupl")
470+
icon_name = "straighten_connections"
471+
462472
[node name="PreviewsMenu" type="PanelContainer" parent="MenuBar/HBox"]
463473
unique_name_in_owner = true
464474
layout_mode = 2
@@ -523,8 +533,9 @@ Scroll to zoom the 3D Preview."
523533
[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"]
524534
[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"]
525535
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignStart" to="MenuBar/HBox/AlignMenu" method="_on_align_start_pressed"]
526-
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignCenter" to="MenuBar/HBox/AlignMenu" method="_on_align_center_pressed"]
536+
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignTop" to="MenuBar/HBox/AlignMenu" method="_on_align_top_pressed"]
527537
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/AlignEnd" to="MenuBar/HBox/AlignMenu" method="_on_align_end_pressed"]
538+
[connection signal="pressed" from="MenuBar/HBox/AlignMenu/HBox/Straighten" to="MenuBar/HBox/AlignMenu" method="_on_straighten_pressed"]
528539
[connection signal="toggled" from="MenuBar/HBox/PreviewsMenu/HBox/2DPreview" to="." method="show_background_preview_2d"]
529540
[connection signal="toggled" from="MenuBar/HBox/PreviewsMenu/HBox/3DPreview" to="." method="show_background_preview_3d"]
530541
[connection signal="gui_input" from="MenuBar/HBox/PreviewsMenu/HBox/ControlView" to="BackgroundPreviews/Preview3D" method="on_gui_input"]

material_maker/theme/classic_base.tres

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ border_color = Color(1, 0.560784, 0.560784, 1)
291291
[sub_resource type="AtlasTexture" id="AtlasTexture_nmkov"]
292292
atlas = ExtResource("1_fw8f4")
293293
region = Rect2(16, 224, 16, 16)
294-
metadata/recolor = false
294+
metadata/recolor = true
295295

296296
[sub_resource type="AtlasTexture" id="AtlasTexture_ppdpb"]
297297
atlas = ExtResource("1_fw8f4")
@@ -301,7 +301,7 @@ metadata/recolor = true
301301
[sub_resource type="AtlasTexture" id="AtlasTexture_btb0w"]
302302
atlas = ExtResource("1_fw8f4")
303303
region = Rect2(96, 208, 16, 16)
304-
metadata/recolor = false
304+
metadata/recolor = true
305305

306306
[sub_resource type="AtlasTexture" id="AtlasTexture_1207d"]
307307
atlas = ExtResource("1_fw8f4")
@@ -315,7 +315,7 @@ metadata/recolor = true
315315

316316
[sub_resource type="AtlasTexture" id="AtlasTexture_a74kv"]
317317
atlas = ExtResource("1_fw8f4")
318-
region = Rect2(48, 208, 16, 16)
318+
region = Rect2(32, 224, 16, 16)
319319
metadata/recolor = true
320320

321321
[sub_resource type="AtlasTexture" id="AtlasTexture_wbe58"]

material_maker/theme/default.tres

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ atlas = ExtResource("1_s43fy")
365365
region = Rect2(64, 208, 16, 16)
366366
metadata/recolor = true
367367

368-
[sub_resource type="AtlasTexture" id="AtlasTexture_8xpdb"]
368+
[sub_resource type="AtlasTexture" id="AtlasTexture_a74kv"]
369369
atlas = ExtResource("1_s43fy")
370-
region = Rect2(48, 208, 16, 16)
370+
region = Rect2(32, 224, 16, 16)
371371
metadata/recolor = true
372372

373373
[sub_resource type="AtlasTexture" id="AtlasTexture_5aawx"]
@@ -431,10 +431,6 @@ metadata/recolor = true
431431
atlas = ExtResource("1_s43fy")
432432
region = Rect2(32, 96, 16, 16)
433433

434-
[sub_resource type="AtlasTexture" id="AtlasTexture_khddu"]
435-
atlas = ExtResource("1_s43fy")
436-
region = Rect2(16, 208, 16, 16)
437-
438434
[sub_resource type="AtlasTexture" id="AtlasTexture_xbfay"]
439435
atlas = ExtResource("1_s43fy")
440436
region = Rect2(32, 208, 16, 16)
@@ -443,6 +439,10 @@ region = Rect2(32, 208, 16, 16)
443439
atlas = ExtResource("1_s43fy")
444440
region = Rect2(0, 208, 16, 16)
445441

442+
[sub_resource type="AtlasTexture" id="AtlasTexture_khddu"]
443+
atlas = ExtResource("1_s43fy")
444+
region = Rect2(16, 208, 16, 16)
445+
446446
[sub_resource type="AtlasTexture" id="AtlasTexture_60g77"]
447447
atlas = ExtResource("1_s43fy")
448448
region = Rect2(96, 144, 16, 16)
@@ -627,6 +627,10 @@ region = Rect2(96, 16, 16, 16)
627627
atlas = ExtResource("1_s43fy")
628628
region = Rect2(48, 16, 16, 16)
629629

630+
[sub_resource type="AtlasTexture" id="AtlasTexture_8xpdb"]
631+
atlas = ExtResource("1_s43fy")
632+
region = Rect2(48, 208, 16, 16)
633+
630634
[sub_resource type="AtlasTexture" id="AtlasTexture_en6gw"]
631635
atlas = ExtResource("1_s43fy")
632636
region = Rect2(0, 0, 16, 16)
@@ -1309,7 +1313,7 @@ MM_CurveIcons/icons/bounce = SubResource("AtlasTexture_skutf")
13091313
MM_CurveIcons/icons/easein = SubResource("AtlasTexture_tqdx4")
13101314
MM_CurveIcons/icons/easeinout = SubResource("AtlasTexture_1okio")
13111315
MM_CurveIcons/icons/easeout = SubResource("AtlasTexture_a1e3v")
1312-
MM_CurveIcons/icons/linear = SubResource("AtlasTexture_8xpdb")
1316+
MM_CurveIcons/icons/linear = SubResource("AtlasTexture_a74kv")
13131317
MM_CurveIcons/icons/sawtooth = SubResource("AtlasTexture_5aawx")
13141318
MM_FilterLineEdit/base_type = &"LineEdit"
13151319
MM_FilterLineEdit/styles/focus = SubResource("StyleBoxFlat_dyhk7")
@@ -1322,9 +1326,9 @@ MM_Icons/icons/2D_preview = SubResource("AtlasTexture_1yu4y")
13221326
MM_Icons/icons/3D_preview = SubResource("AtlasTexture_ao7ds")
13231327
MM_Icons/icons/3D_preview_control = SubResource("AtlasTexture_hht3q")
13241328
MM_Icons/icons/add_image = SubResource("AtlasTexture_86qok")
1325-
MM_Icons/icons/align_center = SubResource("AtlasTexture_khddu")
13261329
MM_Icons/icons/align_end = SubResource("AtlasTexture_xbfay")
13271330
MM_Icons/icons/align_start = SubResource("AtlasTexture_nw6qx")
1331+
MM_Icons/icons/align_top = SubResource("AtlasTexture_khddu")
13281332
MM_Icons/icons/arrange_nodes = SubResource("AtlasTexture_60g77")
13291333
MM_Icons/icons/arrow_left = SubResource("AtlasTexture_q32qs")
13301334
MM_Icons/icons/arrow_right = SubResource("AtlasTexture_r3xak")
@@ -1369,6 +1373,7 @@ MM_Icons/icons/spline_link = SubResource("AtlasTexture_fs6qc")
13691373
MM_Icons/icons/spline_progressive = SubResource("AtlasTexture_70aex")
13701374
MM_Icons/icons/spline_reverse = SubResource("AtlasTexture_ahanl")
13711375
MM_Icons/icons/spline_unlink = SubResource("AtlasTexture_iofl8")
1376+
MM_Icons/icons/straighten_connections = SubResource("AtlasTexture_8xpdb")
13721377
MM_Icons/icons/view = SubResource("AtlasTexture_en6gw")
13731378
MM_Icons/icons/zoom = SubResource("AtlasTexture_iyaen")
13741379
MM_Icons/icons/zoom_in = SubResource("AtlasTexture_5k62t")

0 commit comments

Comments
 (0)