32 lines
648 B
GDScript
32 lines
648 B
GDScript
extends Control
|
|
class_name DraggableWindow
|
|
|
|
|
|
var dragging: bool = false
|
|
var dragging_start_position: Vector2i = Vector2i()
|
|
|
|
signal on_drag(offset: Vector2i)
|
|
signal on_drop()
|
|
|
|
|
|
func _ready() -> void:
|
|
set_process_input(true)
|
|
|
|
|
|
func _gui_input(event: InputEvent) -> void:
|
|
if event is not InputEventMouseButton:
|
|
return
|
|
if event.button_index != MOUSE_BUTTON_LEFT:
|
|
return
|
|
|
|
if event.pressed:
|
|
dragging = true
|
|
dragging_start_position = Vector2i(get_global_mouse_position())
|
|
else:
|
|
dragging = false
|
|
on_drop.emit()
|
|
|
|
|
|
func _process(_delta) -> void:
|
|
if dragging:
|
|
on_drag.emit(Vector2i(get_global_mouse_position()) - dragging_start_position)
|