From 1bd8ec4ae0514f3efae3dfa45b92a8fadae816d7 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 10 Dec 2019 19:56:16 +0200 Subject: [PATCH] Added 2 small sprites below the cursor for the selected tools Instead of having a tool icon as a cursor for the left tool only --- Assets/Graphics/Cursor.png | Bin 0 -> 667 bytes Assets/Graphics/Cursor.png.import | 34 ++++++++++++++++++ .../Graphics/Tools/Bucket_Cursor.png.import | 29 +++------------ .../Tools/ColorPicker_Cursor.png.import | 29 +++------------ .../Graphics/Tools/Eraser_Cursor.png.import | 29 +++------------ .../Tools/LightenDarken_Cursor.png.import | 29 +++------------ .../Graphics/Tools/Pencil_Cursor.png.import | 29 +++------------ .../Tools/RectSelect_Cursor.png.import | 29 +++------------ Main.tscn | 7 ++-- Prefabs/FrameButton.tscn | 14 ++++---- Prefabs/LayerContainer.tscn | 2 +- Scripts/Canvas.gd | 6 +++- Scripts/Global.gd | 10 ++++++ Scripts/Main.gd | 11 ++++-- 14 files changed, 94 insertions(+), 164 deletions(-) create mode 100644 Assets/Graphics/Cursor.png create mode 100644 Assets/Graphics/Cursor.png.import diff --git a/Assets/Graphics/Cursor.png b/Assets/Graphics/Cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..e032de831982ed3b67f84eb8bb19b159612f2f0e GIT binary patch literal 667 zcmV;M0%ZM(P)EX>4Tx04R}tkv&MmKpe$iQ>9WW3U&~2$WWauh>AE$D;B{*X)CnqU~=gfG-*gu zTpR`0f`cE6RRjdyW16NwdUuyz$pQJZB zTI2{A*aj}HJDR))TeSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{0047IL_t(Y$L*KF4!|G?LtFp void: Global.cursor_position_label.text = "[%s×%s] %s, %s" % [size.x, size.y, mouse_pos_floored.x, mouse_pos_floored.y] if !cursor_inside_canvas: cursor_inside_canvas = true - Input.set_custom_mouse_cursor(load("res://Assets/Graphics/Tools/%s_Cursor.png" % Global.current_left_tool), 0, Vector2(3, 24)) + Input.set_custom_mouse_cursor(load("res://Assets/Graphics/Cursor.png"), 0, Vector2(15, 15)) + Global.left_cursor.visible = true + Global.right_cursor.visible = true else: if !Input.is_mouse_button_pressed(BUTTON_LEFT) && !Input.is_mouse_button_pressed(BUTTON_RIGHT): if mouse_inside_canvas: @@ -121,6 +123,8 @@ func _process(delta : float) -> void: Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y] if cursor_inside_canvas: cursor_inside_canvas = false + Global.left_cursor.visible = false + Global.right_cursor.visible = false Input.set_custom_mouse_cursor(null) #Handle Undo/Redo diff --git a/Scripts/Global.gd b/Scripts/Global.gd index 842353534..1d0f7fb12 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -12,6 +12,8 @@ var has_focus := false var canvases := [] # warning-ignore:unused_class_variable var hidden_canvases := [] +var left_cursor_tool_texture : ImageTexture +var right_cursor_tool_texture : ImageTexture # warning-ignore:unused_class_variable var selected_pixels := [] var image_clipboard : Image @@ -103,6 +105,8 @@ var custom_right_brush_texture := ImageTexture.new() #Nodes var control : Node +var left_cursor : Sprite +var right_cursor : Sprite var canvas : Canvas var canvas_parent : Node var main_viewport : ViewportContainer @@ -178,8 +182,14 @@ func _ready() -> void: var root = get_tree().get_root() control = find_node_by_name(root, "Control") + left_cursor = find_node_by_name(root, "LeftCursor") + right_cursor = find_node_by_name(root, "RightCursor") canvas = find_node_by_name(root, "Canvas") canvases.append(canvas) + left_cursor_tool_texture = ImageTexture.new() + left_cursor_tool_texture.create_from_image(preload("res://Assets/Graphics/Tools/Pencil_Cursor.png")) + right_cursor_tool_texture = ImageTexture.new() + right_cursor_tool_texture.create_from_image(preload("res://Assets/Graphics/Tools/Eraser_Cursor.png")) canvas_parent = canvas.get_parent() main_viewport = find_node_by_name(root, "ViewportContainer") second_viewport = find_node_by_name(root, "ViewportContainer2") diff --git a/Scripts/Main.gd b/Scripts/Main.gd index 2b84e5592..c5bfe91da 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -164,6 +164,10 @@ func _ready() -> void: Global.brushes_from_files = Global.custom_brushes.size() func _input(event : InputEvent) -> void: + Global.left_cursor.position = get_global_mouse_position() + Vector2(-20, 20) + Global.left_cursor.texture = Global.left_cursor_tool_texture + Global.right_cursor.position = get_global_mouse_position() + Vector2(20, 20) + Global.right_cursor.texture = Global.right_cursor_tool_texture if event.is_action_pressed("toggle_fullscreen"): OS.window_fullscreen = !OS.window_fullscreen @@ -319,8 +323,8 @@ func _on_CreateNewImage_confirmed() -> void: Global.canvas = load("res://Prefabs/Canvas.tscn").instance() Global.canvas.size = Vector2(width, height).floor() - Global.canvas_parent.add_child(Global.canvas) Global.canvases.append(Global.canvas) + Global.canvas_parent.add_child(Global.canvas) Global.current_frame = 0 if fill_color.a > 0: Global.canvas.layers[0][0].fill(fill_color) @@ -497,8 +501,8 @@ func _on_ImportSprites_files_selected(paths) -> void: #Store [Image, ImageTexture, Layer Name, Visibity boolean] canvas.layers.append([image, tex, "Layer 0", true]) canvas.frame = i - Global.canvas_parent.add_child(canvas) Global.canvases.append(canvas) + Global.canvas_parent.add_child(canvas) canvas.visible = false if path == paths[0]: #If it's the first file max_size = canvas.size @@ -712,6 +716,9 @@ func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_le else: t[0].texture_normal = load("res://Assets/Graphics/Tools/%s.png" % tool_name) + Global.left_cursor_tool_texture.create_from_image(load("res://Assets/Graphics/Tools/%s_Cursor.png" % Global.current_left_tool)) + Global.right_cursor_tool_texture.create_from_image(load("res://Assets/Graphics/Tools/%s_Cursor.png" % Global.current_right_tool)) + func _on_LeftIndicatorCheckbox_toggled(button_pressed) -> void: Global.left_square_indicator_visible = button_pressed