From 4dc55e538e86a25a73d2b041d45f56165c2d070d Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 17 Oct 2024 02:34:27 +0300 Subject: [PATCH] Fix issues when picking color with the bucket tool 1) The bucket tool now picks colors from the top-most layer, like the rest of the drawing tools. 2) Using the tool while moving the cursor and also holding the color picker shortcut (Alt by default), now picks colors instead of using the bucket tool. --- src/Tools/BaseDraw.gd | 29 ----------------------------- src/Tools/BaseTool.gd | 24 ++++++++++++++++++++++++ src/Tools/DesignTools/Bucket.gd | 30 +++++++++--------------------- 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/Tools/BaseDraw.gd b/src/Tools/BaseDraw.gd index be429d31a..5544679a4 100644 --- a/src/Tools/BaseDraw.gd +++ b/src/Tools/BaseDraw.gd @@ -720,35 +720,6 @@ func _get_undo_data() -> Dictionary: return data -func _pick_color(pos: Vector2i) -> void: - var project := Global.current_project - pos = project.tiles.get_canon_position(pos) - - if pos.x < 0 or pos.y < 0: - return - - var image := Image.new() - image.copy_from(_get_draw_image()) - if pos.x > image.get_width() - 1 or pos.y > image.get_height() - 1: - return - - var color := Color(0, 0, 0, 0) - var curr_frame: Frame = project.frames[project.current_frame] - for layer in project.layers.size(): - var idx := (project.layers.size() - 1) - layer - if project.layers[idx].is_visible_in_hierarchy(): - image = curr_frame.cels[idx].get_image() - color = image.get_pixelv(pos) - if not is_zero_approx(color.a): - break - var button := ( - MOUSE_BUTTON_LEFT - if Tools._slots[MOUSE_BUTTON_LEFT].tool_node == self - else MOUSE_BUTTON_RIGHT - ) - Tools.assign_color(color, button, false) - - func _on_flip_x_toggled(button_pressed: bool) -> void: _brush_flip_x = button_pressed update_brush() diff --git a/src/Tools/BaseTool.gd b/src/Tools/BaseTool.gd index 23326db37..c3d43aabb 100644 --- a/src/Tools/BaseTool.gd +++ b/src/Tools/BaseTool.gd @@ -315,6 +315,30 @@ func _get_selected_draw_images() -> Array[Image]: return images +func _pick_color(pos: Vector2i) -> void: + var project := Global.current_project + pos = project.tiles.get_canon_position(pos) + + if pos.x < 0 or pos.y < 0: + return + + var image := Image.new() + image.copy_from(_get_draw_image()) + if pos.x > image.get_width() - 1 or pos.y > image.get_height() - 1: + return + + var color := Color(0, 0, 0, 0) + var curr_frame: Frame = project.frames[project.current_frame] + for layer in project.layers.size(): + var idx := (project.layers.size() - 1) - layer + if project.layers[idx].is_visible_in_hierarchy(): + image = curr_frame.cels[idx].get_image() + color = image.get_pixelv(pos) + if not is_zero_approx(color.a): + break + Tools.assign_color(color, tool_slot.button, false) + + func _flip_rect(rect: Rect2, rect_size: Vector2, horiz: bool, vert: bool) -> Rect2: var result := rect if horiz: diff --git a/src/Tools/DesignTools/Bucket.gd b/src/Tools/DesignTools/Bucket.gd index 794ed5422..2635ab356 100644 --- a/src/Tools/DesignTools/Bucket.gd +++ b/src/Tools/DesignTools/Bucket.gd @@ -7,6 +7,7 @@ const COLOR_REPLACE_SHADER := preload("res://src/Shaders/ColorReplace.gdshader") const PATTERN_FILL_SHADER := preload("res://src/Shaders/PatternFill.gdshader") var _undo_data := {} +var _picking_color := false var _prev_mode := 0 var _pattern: Patterns.Pattern var _tolerance := 0.003 @@ -152,8 +153,10 @@ func update_pattern() -> void: func draw_start(pos: Vector2i) -> void: super.draw_start(pos) if Input.is_action_pressed(&"draw_color_picker", true): + _picking_color = true _pick_color(pos) return + _picking_color = false _undo_data = _get_undo_data() if !Global.current_project.layers[Global.current_project.current_layer].can_layer_get_drawn(): return @@ -164,6 +167,10 @@ func draw_start(pos: Vector2i) -> void: func draw_move(pos: Vector2i) -> void: super.draw_move(pos) + if _picking_color: # Still return even if we released Alt + if Input.is_action_pressed(&"draw_color_picker", true): + _pick_color(pos) + return Global.canvas.selection.transform_content_confirm() if !Global.current_project.layers[Global.current_project.current_layer].can_layer_get_drawn(): return @@ -174,6 +181,8 @@ func draw_move(pos: Vector2i) -> void: func draw_end(pos: Vector2i) -> void: super.draw_end(pos) + if _picking_color: + return commit_undo() @@ -514,24 +523,3 @@ func _get_undo_data() -> Dictionary: var image := cel.get_image() data[image] = image.data return data - - -func _pick_color(pos: Vector2i) -> void: - var project := Global.current_project - pos = project.tiles.get_canon_position(pos) - - if pos.x < 0 or pos.y < 0: - return - - var image := Image.new() - image.copy_from(_get_draw_image()) - if pos.x > image.get_width() - 1 or pos.y > image.get_height() - 1: - return - - var color := image.get_pixelv(pos) - var button := ( - MOUSE_BUTTON_LEFT - if Tools._slots[MOUSE_BUTTON_LEFT].tool_node == self - else MOUSE_BUTTON_RIGHT - ) - Tools.assign_color(color, button, false)