tool

extends Panel

export var title = "Unnamed panel" setget set_title

var dragging = false
var resizing = false
var last_origin = Vector2.ZERO
var last_mouse = Vector2.ZERO

func _handle_drag(event):
	if event is InputEventMouseButton:
		dragging = event.pressed
		last_origin = rect_position
		last_mouse = event.global_position
	if dragging and event is InputEventMouseMotion:
		rect_position = last_origin + (event.global_position - last_mouse)

func _handle_resize(event):
	if event is InputEventMouseButton:
		resizing = event.pressed
		last_origin = rect_size
		last_mouse = event.global_position
	if resizing and event is InputEventMouseMotion:
		rect_size = last_origin + (event.global_position - last_mouse)

func _input(event):
	if event is InputEventMouseButton:
		if dragging and not event.pressed:
			dragging = false
		if resizing and not event.pressed:
			resizing = false

func set_title(val):
	title = val
	$DragHandle/Label.text = title
