editor_test.gd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. extends Control
  2. # Called when the node enters the scene tree for the first time.
  3. func _ready() -> void:
  4. pass # Replace with function body.
  5. get_tree().get_root().files_dropped.connect(_on_files_dropped)
  6. # Called every frame. 'delta' is the elapsed time since the previous frame.
  7. func _process(delta: float) -> void:
  8. pass
  9. func _on_button_pressed() -> void:
  10. $FileDialog.popup()
  11. func _on_file_dialog_files_selected(paths: PackedStringArray) -> void:
  12. var image = Image.new()
  13. image.load(paths[0])
  14. var image_texture = ImageTexture.new()
  15. image_texture.set_image(image)
  16. $TextureRect.texture = image_texture
  17. func _on_files_dropped(files):
  18. if not mouse_over_control($TextureRect):
  19. return
  20. var path = files[0]
  21. var image = Image.new()
  22. image.load(path)
  23. var image_texture = ImageTexture.new()
  24. image_texture.set_image(image)
  25. $TextureRect.texture = image_texture
  26. func mouse_over_control(node: Control):
  27. var rect = node.get_rect()
  28. var mouse = get_global_mouse_position()
  29. return rect.has_point(mouse)