extends Control


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.
	get_tree().get_root().files_dropped.connect(_on_files_dropped)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass


func _on_button_pressed() -> void:
	$FileDialog.popup()


func _on_file_dialog_files_selected(paths: PackedStringArray) -> void:
	var image = Image.new()
	image.load(paths[0])
	
	var image_texture = ImageTexture.new()
	image_texture.set_image(image)
	
	$TextureRect.texture = image_texture

func _on_files_dropped(files):
	if not mouse_over_control($TextureRect):
		return
	
	var path = files[0]
	
	var image = Image.new()
	image.load(path)
	
	var image_texture = ImageTexture.new()
	image_texture.set_image(image)
	
	$TextureRect.texture = image_texture

func mouse_over_control(node: Control):
	var rect = node.get_rect()
	var mouse = get_global_mouse_position()
	return rect.has_point(mouse)
