Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions material_maker/doc/user_interface_main_menu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ View menu

* *Reset zoom* Resets the zoom level of the current material graph view

* *Frame selected nodes* Zoom in/out to selected nodes so that they fit the graph view

* *Frame all nodes* Zoom in/out to all nodes to fit the graph view

* *Show/Hide side panels* (or the *Control+SpaceBar* keyboard shortcut) can
be used to hide the side panels so the space available for the main panel
is maximized (which can be useful on smaller displays).
Expand Down
4 changes: 4 additions & 0 deletions material_maker/doc/user_interface_shortcuts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ Graph Editor
+-------------------------------------------------------+----------------------------------------------------+
| :kbd:`Ctrl/Cmd-Shift-Z` | Redo |
+-------------------------------------------------------+----------------------------------------------------+
| :kbd:`.` | Frame selected nodes |
+-------------------------------------------------------+----------------------------------------------------+
| :kbd:`Home` | Frame all nodes |
+-------------------------------------------------------+----------------------------------------------------+

Nodes
+++++
Expand Down
10 changes: 10 additions & 0 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const MENU : Array[Dictionary] = [

{ menu="View/Center view", command="view_center", shortcut="C" },
{ menu="View/Reset zoom", command="view_reset_zoom", shortcut="Control+0" },
{ menu="View/Frame selected nodes", command="view_frame_all", shortcut="PERIOD"},
{ menu="View/Frame all", command="view_frame_all", shortcut="HOME"},
{ menu="View/-" },
# { menu="View/Show or Hide side panels", command="toggle_side_panels", shortcut="Control+Space" },
{ menu="View/Panels", submenu="show_panels" },
Expand Down Expand Up @@ -1036,6 +1038,14 @@ func view_reset_zoom() -> void:
var graph_edit : MMGraphEdit = get_current_graph_edit()
graph_edit.zoom = 1

func view_frame_selected() -> void:
var graph_edit : MMGraphEdit = get_current_graph_edit()
graph_edit.frame_nodes(true)

func view_frame_all() -> void:
var graph_edit : MMGraphEdit = get_current_graph_edit()
graph_edit.frame_nodes()

func toggle_side_panels() -> void:
$VBoxContainer/Layout.toggle_side_panels()

Expand Down
25 changes: 25 additions & 0 deletions material_maker/panels/graph_edit/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func _gui_input(event) -> void:
KEY_MASK_ALT | KEY_S:
if OS.get_name() == "macOS":
swap_node_inputs()
KEY_PERIOD:
if OS.get_name() == "macOS":
frame_nodes(true)
KEY_LEFT:
scroll_offset.x -= 0.5*size.x
accept_event()
Expand Down Expand Up @@ -615,6 +618,28 @@ func center_view() -> void:
center /= node_count
scroll_offset = center * zoom - 0.5*size

func frame_nodes(frame_selected : bool = false) -> void:
var nodes := get_children().filter(func(c): return c is GraphElement)
if frame_selected:
nodes = get_selected_nodes()
if nodes.is_empty():
return
var count := 0
var bbox : Rect2

for c in nodes:
count += 1
if count == 1:
bbox.position = c.position_offset + 0.5 * c.size
else:
bbox = bbox.expand(c.position_offset + 0.5 * c.size)
bbox = bbox.grow(160.0).grow_individual(0.0, 20.0, 0.0, 20.0)
var sc = size / bbox.size
var _zoom := minf(minf(sc.x, sc.y), 1.5)
var tween := get_tree().create_tween()
tween.parallel().tween_property(self, "zoom", _zoom, 0.3).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC)
tween.parallel().tween_property(self, "scroll_offset", bbox.get_center() * _zoom - 0.5 * size, 0.3).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC)

func update_view(g) -> void:
if generator != null and is_instance_valid(generator):
generator.disconnect("connections_changed", Callable(self, "on_connections_changed"))
Expand Down