From 4931e502133410f5ba5cd2dfbda7336c1b5c721c Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 22 Nov 2021 18:43:06 +0200 Subject: [PATCH] Move cursot tool icon visibility to ViewportContainer I have no idea what I was thinking when I put that code inside Canvas' _input() --- src/UI/Canvas/Canvas.gd | 14 -------------- src/UI/ViewportContainer.gd | 8 +++++++- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index a4d5b3b82..c63335931 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -5,7 +5,6 @@ extends Node2D var fill_color := Color(0, 0, 0, 0) var current_pixel := Vector2.ZERO var can_undo := true -var cursor_image_has_changed := false var sprite_changed_this_frame := false # for optimization purposes var move_preview_location := Vector2.ZERO @@ -78,19 +77,6 @@ func _input(event : InputEvent) -> void: sprite_changed_this_frame = false - if Global.has_focus: - if !cursor_image_has_changed: - cursor_image_has_changed = true - if Global.show_left_tool_icon: - Global.left_cursor.visible = true - if Global.show_right_tool_icon: - Global.right_cursor.visible = true - else: - if cursor_image_has_changed: - cursor_image_has_changed = false - Global.left_cursor.visible = false - Global.right_cursor.visible = false - Tools.handle_draw(current_pixel.floor(), event) if sprite_changed_this_frame: diff --git a/src/UI/ViewportContainer.gd b/src/UI/ViewportContainer.gd index 7b2e1a8e0..d2bba42f5 100644 --- a/src/UI/ViewportContainer.gd +++ b/src/UI/ViewportContainer.gd @@ -1,12 +1,18 @@ extends ViewportContainer -func _ready(): + +func _ready() -> void: material = CanvasItemMaterial.new() material.blend_mode = CanvasItemMaterial.BLEND_MODE_PREMULT_ALPHA + func _on_ViewportContainer_mouse_entered() -> void: Global.has_focus = true + Global.left_cursor.visible = true + Global.right_cursor.visible = true func _on_ViewportContainer_mouse_exited() -> void: Global.has_focus = false + Global.left_cursor.visible = false + Global.right_cursor.visible = false