Skip to content
Open
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
22 changes: 18 additions & 4 deletions material_maker/panels/graph_edit/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var need_save_crash_recovery : bool = false
var top_generator = null
var generator = null

var grab_accumulation : Dictionary[String, Vector2]
@onready var grab_icon := preload("res://material_maker/icons/grab.svg")
var has_grab : bool = false:
set(v):
Expand All @@ -34,6 +35,7 @@ var has_grab : bool = false:
grab_icon.get_size() * 0.5)
else:
Input.set_custom_mouse_cursor(null)
grab_accumulation.clear()

const PREVIEW_COUNT = 2
var current_preview : Array = [ null, null ]
Expand Down Expand Up @@ -134,16 +136,29 @@ func process_port_click(pressed : bool):
port_click_port_index = -1
return


func _input(event: InputEvent) -> void:
# Handle node grab
if has_grab:
var selected_nodes := get_selected_nodes()
if event is InputEventMouseMotion:
for node in selected_nodes:
for node : GraphElement in selected_nodes:
if node is not MMGraphComment:
node.move_to_front()
node.position_offset += event.relative / zoom

if snapping_enabled != event.is_command_or_control_pressed():
if not grab_accumulation.has(node.name):
grab_accumulation[node.name] = Vector2.ZERO
grab_accumulation[node.name] += event.relative / zoom

var step : Vector2 = (grab_accumulation[node.name] / snapping_distance
+ Vector2(0.5, 0.5)).floor()
if not step.is_zero_approx():
node.position_offset = node.position_offset.snappedf(snapping_distance)
node.position_offset += step * snapping_distance
grab_accumulation[node.name] -= step * snapping_distance
else:
node.position_offset += event.relative / zoom

elif (event is InputEventMouseButton
and event.button_index == MOUSE_BUTTON_LEFT):
accept_event()
Expand All @@ -156,7 +171,6 @@ func _input(event: InputEvent) -> void:
if get_nodes_under_mouse().is_empty():
node.set_deferred("selected", true)


func _gui_input(event) -> void:
if (
event.is_action_pressed("ui_library_popup")
Expand Down