From 53a86127a035d491f1e9b8194cd27a2f586e30e6 Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 12:26:48 +0500 Subject: [PATCH 1/8] add a way to see indices --- project.godot | 4 +++ src/Autoload/Global.gd | 8 +++++ src/Classes/Project.gd | 1 + src/Main.gd | 1 + src/UI/Canvas/Canvas.gd | 2 ++ src/UI/Canvas/Canvas.tscn | 12 ++++++- src/UI/Canvas/color_index.gd | 37 +++++++++++++++++++++ src/UI/TopMenuContainer/TopMenuContainer.gd | 13 ++++++++ 8 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/UI/Canvas/color_index.gd diff --git a/project.godot b/project.godot index 4e8a3fed5..2f12d7a98 100644 --- a/project.godot +++ b/project.godot @@ -921,6 +921,10 @@ right_text_tool={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":true,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) ] } +show_color_indices={ +"deadzone": 0.5, +"events": [] +} [input_devices] diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 01c288bba..19448dbc2 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -38,6 +38,7 @@ enum ViewMenu { SHOW_RULERS, SHOW_GUIDES, SHOW_MOUSE_GUIDES, + SHOW_COLOR_INDICES, DISPLAY_LAYER_EFFECTS, SNAP_TO, } @@ -555,6 +556,12 @@ var show_rulers := true: var show_guides := true ## If [code]true[/code], the mouse guides are visible. var show_mouse_guides := false +## If [code]true[/code], the indices of color are shown. +var show_color_indices := false: + set(value): + show_color_indices = value + if is_instance_valid(canvas.color_index): + canvas.color_index.enabled = value var display_layer_effects := true: set(value): if value == display_layer_effects: @@ -749,6 +756,7 @@ func _ready() -> void: Global.use_native_file_dialogs = true await get_tree().process_frame project_switched.emit() + canvas.color_index.enabled = show_color_indices # Initialize color index preview func update_grids(grids_data: Dictionary): diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 19f41db8d..30baf79a1 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -34,6 +34,7 @@ var color_mode: int = Image.FORMAT_RGBA8: image.resize_indices() image.select_palette("", false) image.convert_rgb_to_indexed() + Global.canvas.color_index.queue_redraw() var fill_color := Color(0) var has_changed := false: set(value): diff --git a/src/Main.gd b/src/Main.gd index a933597ae..bef51b382 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -604,6 +604,7 @@ func _exit_tree() -> void: Global.config_cache.set_value("view_menu", "show_rulers", Global.show_rulers) Global.config_cache.set_value("view_menu", "show_guides", Global.show_guides) Global.config_cache.set_value("view_menu", "show_mouse_guides", Global.show_mouse_guides) + Global.config_cache.set_value("view_menu", "show_color_indices", Global.show_color_indices) Global.config_cache.set_value( "view_menu", "display_layer_effects", Global.display_layer_effects ) diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index f97e3ff15..62518ffd5 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -15,6 +15,7 @@ var layer_metadata_texture := ImageTexture.new() @onready var currently_visible_frame := $CurrentlyVisibleFrame as SubViewport @onready var current_frame_drawer := $CurrentlyVisibleFrame/CurrentFrameDrawer as Node2D @onready var tile_mode := $TileMode as Node2D +@onready var color_index := $ColorIndex as Node2D @onready var pixel_grid := $PixelGrid as Node2D @onready var grid := $Grid as Node2D @onready var selection := $Selection as SelectionNode @@ -67,6 +68,7 @@ func _draw() -> void: current_frame_drawer.queue_redraw() tile_mode.queue_redraw() draw_set_transform(position, rotation, scale) + color_index.queue_redraw() func _input(event: InputEvent) -> void: diff --git a/src/UI/Canvas/Canvas.tscn b/src/UI/Canvas/Canvas.tscn index 9078617b4..339f87727 100644 --- a/src/UI/Canvas/Canvas.tscn +++ b/src/UI/Canvas/Canvas.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=3 uid="uid://ba24iuv55m4l3"] +[gd_scene load_steps=24 format=3 uid="uid://ba24iuv55m4l3"] [ext_resource type="Script" path="res://src/UI/Canvas/Canvas.gd" id="1"] [ext_resource type="Shader" path="res://src/Shaders/BlendLayers.gdshader" id="1_253dh"] @@ -17,6 +17,7 @@ [ext_resource type="Script" path="res://src/UI/Canvas/Measurements.gd" id="16_nxilb"] [ext_resource type="Shader" path="res://src/Shaders/AutoInvertColors.gdshader" id="17_lowhf"] [ext_resource type="Script" path="res://src/UI/Canvas/ReferenceImages.gd" id="17_qfjb4"] +[ext_resource type="Script" path="res://src/UI/Canvas/color_index.gd" id="18_o3xx2"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_6b0ox"] shader = ExtResource("1_253dh") @@ -26,6 +27,11 @@ shader_parameter/origin_y_positive = true [sub_resource type="CanvasItemMaterial" id="1"] blend_mode = 4 +[sub_resource type="ShaderMaterial" id="ShaderMaterial_ascg6"] +shader = ExtResource("17_lowhf") +shader_parameter/width = 0.05 +shader_parameter/hollow_shapes = false + [sub_resource type="ShaderMaterial" id="2"] shader = ExtResource("9") shader_parameter/width = 0.05 @@ -59,6 +65,10 @@ show_behind_parent = true material = SubResource("1") script = ExtResource("4") +[node name="ColorIndex" type="Node2D" parent="."] +material = SubResource("ShaderMaterial_ascg6") +script = ExtResource("18_o3xx2") + [node name="PixelGrid" type="Node2D" parent="."] script = ExtResource("6") diff --git a/src/UI/Canvas/color_index.gd b/src/UI/Canvas/color_index.gd new file mode 100644 index 000000000..1f6571273 --- /dev/null +++ b/src/UI/Canvas/color_index.gd @@ -0,0 +1,37 @@ +extends Node2D + +const FONT_SIZE = 16 + +var users := 1 +var enabled: bool = false: + set(value): + enabled = value + queue_redraw() + + +func _draw() -> void: + if not enabled: + return + var project = ExtensionsApi.project.current_project + var size: Vector2i = project.size + var cel: BaseCel = project.frames[project.current_frame].cels[project.current_layer] + if not cel is PixelCel: + return + var index_image: Image = cel.image.indices_image + if index_image.get_size() != size: + return + + var font: Font = ExtensionsApi.theme.get_theme().default_font + draw_set_transform(position, rotation, Vector2(0.05, 0.05)) + for x in range(size.x): + for y in range(size.y): + var index := index_image.get_pixel(x, y).r8 + draw_string( + font, + Vector2(x, y) * 20 + Vector2.DOWN * 16, + str(index), + HORIZONTAL_ALIGNMENT_LEFT, + -1, + FONT_SIZE if (index < 100) else int(FONT_SIZE / 1.5) + ) + draw_set_transform(position, rotation, scale) diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index c7d88d4c5..04d5d6fc4 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -235,6 +235,7 @@ func _setup_view_menu() -> void: "Show Rulers": "show_rulers", "Show Guides": "show_guides", "Show Mouse Guides": "", + "Show Color Indices": "show_color_indices", "Display Layer Effects": &"display_layer_effects", "Snap To": "", } @@ -270,6 +271,9 @@ func _setup_view_menu() -> void: var show_mouse_guides: bool = Global.config_cache.get_value( "view_menu", "show_mouse_guides", Global.show_mouse_guides ) + var show_color_indices: bool = Global.config_cache.get_value( + "view_menu", "show_color_indices", Global.show_color_indices + ) var display_layer_effects: bool = Global.config_cache.get_value( "view_menu", "display_layer_effects", Global.display_layer_effects ) @@ -295,6 +299,8 @@ func _setup_view_menu() -> void: _toggle_show_guides() if show_mouse_guides != Global.show_mouse_guides: _toggle_show_mouse_guides() + if show_color_indices != Global.show_color_indices: + _toggle_show_color_indices() if display_layer_effects != Global.display_layer_effects: Global.display_layer_effects = display_layer_effects if snap_to_rectangular_grid_boundary != Global.snap_to_rectangular_grid_boundary: @@ -666,6 +672,8 @@ func view_menu_id_pressed(id: int) -> void: _toggle_show_guides() Global.ViewMenu.SHOW_MOUSE_GUIDES: _toggle_show_mouse_guides() + Global.ViewMenu.SHOW_COLOR_INDICES: + _toggle_show_color_indices() Global.ViewMenu.DISPLAY_LAYER_EFFECTS: Global.display_layer_effects = not Global.display_layer_effects _: @@ -851,6 +859,11 @@ func _toggle_show_mouse_guides() -> void: Global.canvas.mouse_guide_container.get_child(1).queue_redraw() +func _toggle_show_color_indices() -> void: + Global.show_color_indices = !Global.show_color_indices + view_menu.set_item_checked(Global.ViewMenu.SHOW_COLOR_INDICES, Global.show_color_indices) + + func _toggle_zen_mode() -> void: for i in ui_elements.size(): if ui_elements[i].name == "Main Canvas": From adbeec12f88a4e94ba4855cc5f2281ea5f9eabe0 Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 12:52:43 +0500 Subject: [PATCH 2/8] fix some things --- project.godot | 2 +- src/Autoload/Global.gd | 8 +++---- src/Main.gd | 2 +- src/UI/Canvas/color_index.gd | 12 +++++++++- src/UI/TopMenuContainer/TopMenuContainer.gd | 26 ++++++++++----------- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/project.godot b/project.godot index 2f12d7a98..6c4397d44 100644 --- a/project.godot +++ b/project.godot @@ -921,7 +921,7 @@ right_text_tool={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":true,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) ] } -show_color_indices={ +show_pixel_indices={ "deadzone": 0.5, "events": [] } diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 19448dbc2..bae48c0bc 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -35,10 +35,10 @@ enum ViewMenu { MIRROR_VIEW, SHOW_GRID, SHOW_PIXEL_GRID, + SHOW_PIXEL_INDICES, SHOW_RULERS, SHOW_GUIDES, SHOW_MOUSE_GUIDES, - SHOW_COLOR_INDICES, DISPLAY_LAYER_EFFECTS, SNAP_TO, } @@ -557,9 +557,9 @@ var show_guides := true ## If [code]true[/code], the mouse guides are visible. var show_mouse_guides := false ## If [code]true[/code], the indices of color are shown. -var show_color_indices := false: +var show_pixel_indices := false: set(value): - show_color_indices = value + show_pixel_indices = value if is_instance_valid(canvas.color_index): canvas.color_index.enabled = value var display_layer_effects := true: @@ -756,7 +756,7 @@ func _ready() -> void: Global.use_native_file_dialogs = true await get_tree().process_frame project_switched.emit() - canvas.color_index.enabled = show_color_indices # Initialize color index preview + canvas.color_index.enabled = show_pixel_indices # Initialize color index preview func update_grids(grids_data: Dictionary): diff --git a/src/Main.gd b/src/Main.gd index bef51b382..d253ce221 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -601,10 +601,10 @@ func _exit_tree() -> void: Global.config_cache.set_value("window", "size", get_window().size) Global.config_cache.set_value("view_menu", "draw_grid", Global.draw_grid) Global.config_cache.set_value("view_menu", "draw_pixel_grid", Global.draw_pixel_grid) + Global.config_cache.set_value("view_menu", "show_pixel_indices", Global.show_pixel_indices) Global.config_cache.set_value("view_menu", "show_rulers", Global.show_rulers) Global.config_cache.set_value("view_menu", "show_guides", Global.show_guides) Global.config_cache.set_value("view_menu", "show_mouse_guides", Global.show_mouse_guides) - Global.config_cache.set_value("view_menu", "show_color_indices", Global.show_color_indices) Global.config_cache.set_value( "view_menu", "display_layer_effects", Global.display_layer_effects ) diff --git a/src/UI/Canvas/color_index.gd b/src/UI/Canvas/color_index.gd index 1f6571273..e1708bd42 100644 --- a/src/UI/Canvas/color_index.gd +++ b/src/UI/Canvas/color_index.gd @@ -9,16 +9,26 @@ var enabled: bool = false: queue_redraw() +func _ready() -> void: + Global.camera.zoom_changed.connect(queue_redraw) + + func _draw() -> void: if not enabled: return + # when we zoom out there is a visual issue that inverts the text + # (kind of how you look through a magnifying glass) + # so we should restrict the rendering distance of this preview. + var zoom_percentage := 100.0 * Global.camera.zoom.x + if zoom_percentage < Global.pixel_grid_show_at_zoom: + return var project = ExtensionsApi.project.current_project var size: Vector2i = project.size var cel: BaseCel = project.frames[project.current_frame].cels[project.current_layer] if not cel is PixelCel: return var index_image: Image = cel.image.indices_image - if index_image.get_size() != size: + if index_image.get_size() != size or not cel.image.is_indexed: return var font: Font = ExtensionsApi.theme.get_theme().default_font diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index 04d5d6fc4..de29ebf89 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -232,10 +232,10 @@ func _setup_view_menu() -> void: "Mirror View": "mirror_view", "Show Grid": "show_grid", "Show Pixel Grid": "show_pixel_grid", + "Show Pixel Indices": "show_pixel_indices", "Show Rulers": "show_rulers", "Show Guides": "show_guides", "Show Mouse Guides": "", - "Show Color Indices": "show_color_indices", "Display Layer Effects": &"display_layer_effects", "Snap To": "", } @@ -262,6 +262,9 @@ func _setup_view_menu() -> void: var draw_pixel_grid: bool = Global.config_cache.get_value( "view_menu", "draw_pixel_grid", Global.draw_pixel_grid ) + var show_pixel_indices: bool = Global.config_cache.get_value( + "view_menu", "show_pixel_indices", Global.show_pixel_indices + ) var show_rulers: bool = Global.config_cache.get_value( "view_menu", "show_rulers", Global.show_rulers ) @@ -271,9 +274,6 @@ func _setup_view_menu() -> void: var show_mouse_guides: bool = Global.config_cache.get_value( "view_menu", "show_mouse_guides", Global.show_mouse_guides ) - var show_color_indices: bool = Global.config_cache.get_value( - "view_menu", "show_color_indices", Global.show_color_indices - ) var display_layer_effects: bool = Global.config_cache.get_value( "view_menu", "display_layer_effects", Global.display_layer_effects ) @@ -299,8 +299,8 @@ func _setup_view_menu() -> void: _toggle_show_guides() if show_mouse_guides != Global.show_mouse_guides: _toggle_show_mouse_guides() - if show_color_indices != Global.show_color_indices: - _toggle_show_color_indices() + if show_pixel_indices != Global.show_pixel_indices: + _toggle_show_pixel_indices() if display_layer_effects != Global.display_layer_effects: Global.display_layer_effects = display_layer_effects if snap_to_rectangular_grid_boundary != Global.snap_to_rectangular_grid_boundary: @@ -672,8 +672,8 @@ func view_menu_id_pressed(id: int) -> void: _toggle_show_guides() Global.ViewMenu.SHOW_MOUSE_GUIDES: _toggle_show_mouse_guides() - Global.ViewMenu.SHOW_COLOR_INDICES: - _toggle_show_color_indices() + Global.ViewMenu.SHOW_PIXEL_INDICES: + _toggle_show_pixel_indices() Global.ViewMenu.DISPLAY_LAYER_EFFECTS: Global.display_layer_effects = not Global.display_layer_effects _: @@ -828,6 +828,11 @@ func _toggle_show_pixel_grid() -> void: view_menu.set_item_checked(Global.ViewMenu.SHOW_PIXEL_GRID, Global.draw_pixel_grid) +func _toggle_show_pixel_indices() -> void: + Global.show_pixel_indices = !Global.show_pixel_indices + view_menu.set_item_checked(Global.ViewMenu.SHOW_PIXEL_INDICES, Global.show_pixel_indices) + + func _toggle_show_rulers() -> void: Global.show_rulers = !Global.show_rulers view_menu.set_item_checked(Global.ViewMenu.SHOW_RULERS, Global.show_rulers) @@ -859,11 +864,6 @@ func _toggle_show_mouse_guides() -> void: Global.canvas.mouse_guide_container.get_child(1).queue_redraw() -func _toggle_show_color_indices() -> void: - Global.show_color_indices = !Global.show_color_indices - view_menu.set_item_checked(Global.ViewMenu.SHOW_COLOR_INDICES, Global.show_color_indices) - - func _toggle_zen_mode() -> void: for i in ui_elements.size(): if ui_elements[i].name == "Main Canvas": From b8c04e83c95050330a1ea917074524132896f987 Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 14:47:59 +0500 Subject: [PATCH 3/8] Fixed more than one swatch selected if there is the same color available in an earlier swatch --- src/Autoload/Global.gd | 2 +- src/Autoload/Palettes.gd | 3 ++- src/Palette/PaletteGrid.gd | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index bae48c0bc..fbdb41f9a 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -756,7 +756,7 @@ func _ready() -> void: Global.use_native_file_dialogs = true await get_tree().process_frame project_switched.emit() - canvas.color_index.enabled = show_pixel_indices # Initialize color index preview + canvas.color_index.enabled = show_pixel_indices # Initialize color index preview func update_grids(grids_data: Dictionary): diff --git a/src/Autoload/Palettes.gd b/src/Autoload/Palettes.gd index eef4abab6..a472e30db 100644 --- a/src/Autoload/Palettes.gd +++ b/src/Autoload/Palettes.gd @@ -296,13 +296,14 @@ func current_palette_select_color(mouse_button: int, index: int) -> void: if color == null: return + _select_color(mouse_button, index) + match mouse_button: MOUSE_BUTTON_LEFT: Tools.assign_color(color, mouse_button) MOUSE_BUTTON_RIGHT: Tools.assign_color(color, mouse_button) - _select_color(mouse_button, index) func _select_color(mouse_button: int, index: int) -> void: diff --git a/src/Palette/PaletteGrid.gd b/src/Palette/PaletteGrid.gd index 66bb92c46..abe894482 100644 --- a/src/Palette/PaletteGrid.gd +++ b/src/Palette/PaletteGrid.gd @@ -82,17 +82,20 @@ func scroll_palette(origin: Vector2i) -> void: ## Called when the color changes, either the left or the right, determined by [param mouse_button]. ## If current palette has [param target_color] as a [Color], then select it. +## This is helpful when we select color indirectly (e.g through colorpicker) func find_and_select_color(target_color: Color, mouse_button: int) -> void: if not is_instance_valid(current_palette): return - var old_index := Palettes.current_palette_get_selected_color_index(mouse_button) + var selected_index := Palettes.current_palette_get_selected_color_index(mouse_button) + if get_swatch_color(selected_index) == target_color: # Color already selected + return for color_ind in swatches.size(): if ( target_color.is_equal_approx(swatches[color_ind].color) or target_color.to_html() == swatches[color_ind].color.to_html() ): var index := convert_grid_index_to_palette_index(color_ind) - select_swatch(mouse_button, index, old_index) + select_swatch(mouse_button, index, selected_index) match mouse_button: MOUSE_BUTTON_LEFT: Palettes.left_selected_color = index From dcf26084df85bbe9c564bb76fb09af880dff89ef Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 15:35:20 +0500 Subject: [PATCH 4/8] fixed wrong index drawn when moved to an smpty swatch --- src/Classes/ImageExtended.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Classes/ImageExtended.gd b/src/Classes/ImageExtended.gd index 4b5ef9ea5..93b7e8de1 100644 --- a/src/Classes/ImageExtended.gd +++ b/src/Classes/ImageExtended.gd @@ -78,7 +78,7 @@ func update_palette() -> void: return if palette.size() != current_palette.colors_max: palette.resize(current_palette.colors_max) - palette.fill(TRANSPARENT) + palette.fill(TRANSPARENT) for i in current_palette.colors: palette[i] = current_palette.colors[i].color From dc000f7267ac89e4b904853caccae5ad213008ec Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 16:13:14 +0500 Subject: [PATCH 5/8] make active_button public --- src/Autoload/Palettes.gd | 1 - src/Autoload/Tools.gd | 34 +++++++++++++++++----------------- src/Classes/ImageExtended.gd | 7 +++++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Autoload/Palettes.gd b/src/Autoload/Palettes.gd index a472e30db..9e3a1ad9c 100644 --- a/src/Autoload/Palettes.gd +++ b/src/Autoload/Palettes.gd @@ -305,7 +305,6 @@ func current_palette_select_color(mouse_button: int, index: int) -> void: Tools.assign_color(color, mouse_button) - func _select_color(mouse_button: int, index: int) -> void: match mouse_button: MOUSE_BUTTON_LEFT: diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index f1cd0bb08..5cff9e158 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -12,6 +12,7 @@ enum Dynamics { NONE, PRESSURE, VELOCITY } const XY_LINE := Vector2(-0.707107, 0.707107) const X_MINUS_Y_LINE := Vector2(0.707107, 0.707107) +var active_button := -1 var picking_color_for := MOUSE_BUTTON_LEFT var horizontal_mirror := false var vertical_mirror := false @@ -238,7 +239,6 @@ var _right_tools_per_layer_type := { Global.LayerTypes.THREE_D: "Pan", } var _tool_buttons: Node -var _active_button := -1 var _last_position := Vector2i(Vector2.INF) @@ -627,32 +627,32 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void: change_layer_automatically(draw_pos) return - if event.is_action_pressed(&"activate_left_tool") and _active_button == -1 and not pen_inverted: - _active_button = MOUSE_BUTTON_LEFT - _slots[_active_button].tool_node.draw_start(draw_pos) - elif event.is_action_released(&"activate_left_tool") and _active_button == MOUSE_BUTTON_LEFT: - _slots[_active_button].tool_node.draw_end(draw_pos) - _active_button = -1 + if event.is_action_pressed(&"activate_left_tool") and active_button == -1 and not pen_inverted: + active_button = MOUSE_BUTTON_LEFT + _slots[active_button].tool_node.draw_start(draw_pos) + elif event.is_action_released(&"activate_left_tool") and active_button == MOUSE_BUTTON_LEFT: + _slots[active_button].tool_node.draw_end(draw_pos) + active_button = -1 elif ( ( event.is_action_pressed(&"activate_right_tool") - and _active_button == -1 + and active_button == -1 and not pen_inverted ) or ( - event.is_action_pressed(&"activate_left_tool") and _active_button == -1 and pen_inverted + event.is_action_pressed(&"activate_left_tool") and active_button == -1 and pen_inverted ) ): - _active_button = MOUSE_BUTTON_RIGHT - _slots[_active_button].tool_node.draw_start(draw_pos) + active_button = MOUSE_BUTTON_RIGHT + _slots[active_button].tool_node.draw_start(draw_pos) elif ( - (event.is_action_released(&"activate_right_tool") and _active_button == MOUSE_BUTTON_RIGHT) + (event.is_action_released(&"activate_right_tool") and active_button == MOUSE_BUTTON_RIGHT) or ( - event.is_action_released(&"activate_left_tool") and _active_button == MOUSE_BUTTON_RIGHT + event.is_action_released(&"activate_left_tool") and active_button == MOUSE_BUTTON_RIGHT ) ): - _slots[_active_button].tool_node.draw_end(draw_pos) - _active_button = -1 + _slots[active_button].tool_node.draw_end(draw_pos) + active_button = -1 if event is InputEventMouseMotion: pen_pressure = event.pressure @@ -683,8 +683,8 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void: _last_position = position _slots[MOUSE_BUTTON_LEFT].tool_node.cursor_move(position) _slots[MOUSE_BUTTON_RIGHT].tool_node.cursor_move(position) - if _active_button != -1: - _slots[_active_button].tool_node.draw_move(draw_pos) + if active_button != -1: + _slots[active_button].tool_node.draw_move(draw_pos) var project := Global.current_project var text := "[%s×%s]" % [project.size.x, project.size.y] diff --git a/src/Classes/ImageExtended.gd b/src/Classes/ImageExtended.gd index 93b7e8de1..c1fd655d6 100644 --- a/src/Classes/ImageExtended.gd +++ b/src/Classes/ImageExtended.gd @@ -142,6 +142,13 @@ func set_pixelv_custom(point: Vector2i, color: Color) -> void: if not color.is_equal_approx(TRANSPARENT): if palette.has(color): color_index = palette.find(color) + ## If the color selected in the palette is the same then it should take prioity. + #var selected_index = Palettes.current_palette_get_selected_color_index( + #Tools.active_button + #) + #if selected_index != -1: + #if Palettes.current_palette_get_color(selected_index) == color: + #color_index = selected_index else: # Find the most similar color var smaller_distance := color_distance(color, palette[0]) for i in palette.size(): From 1b8301ae728cb3ad69db7463d32e5fe4af2f99ce Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 16:33:14 +0500 Subject: [PATCH 6/8] fixed wrong color getting stored in array (similar fix to #1108.) --- src/Classes/ImageExtended.gd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Classes/ImageExtended.gd b/src/Classes/ImageExtended.gd index c1fd655d6..b2eec5861 100644 --- a/src/Classes/ImageExtended.gd +++ b/src/Classes/ImageExtended.gd @@ -80,7 +80,12 @@ func update_palette() -> void: palette.resize(current_palette.colors_max) palette.fill(TRANSPARENT) for i in current_palette.colors: - palette[i] = current_palette.colors[i].color + # Due to the decimal nature of the color values, some values get rounded off + # unintentionally. + # Even though the decimal values change, the HTML code remains the same after the change. + # So we're using this trick to convert the values back to how they are shown in + # the palette. + palette[i] = Color(current_palette.colors[i].color.to_html()) ## Displays the actual RGBA values of each pixel in the image from indexed mode. From 7b6530021fecd2cb8efa38e192de07c49fe7f04a Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 16:48:05 +0500 Subject: [PATCH 7/8] If the color selected in the palette is the same then it should take prioity. --- src/Classes/ImageExtended.gd | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Classes/ImageExtended.gd b/src/Classes/ImageExtended.gd index b2eec5861..b3d8c8d59 100644 --- a/src/Classes/ImageExtended.gd +++ b/src/Classes/ImageExtended.gd @@ -147,13 +147,13 @@ func set_pixelv_custom(point: Vector2i, color: Color) -> void: if not color.is_equal_approx(TRANSPARENT): if palette.has(color): color_index = palette.find(color) - ## If the color selected in the palette is the same then it should take prioity. - #var selected_index = Palettes.current_palette_get_selected_color_index( - #Tools.active_button - #) - #if selected_index != -1: - #if Palettes.current_palette_get_color(selected_index) == color: - #color_index = selected_index + # If the color selected in the palette is the same then it should take prioity. + var selected_index = Palettes.current_palette_get_selected_color_index( + Tools.active_button + ) + if selected_index != -1: + if palette[selected_index].is_equal_approx(color): + color_index = selected_index else: # Find the most similar color var smaller_distance := color_distance(color, palette[0]) for i in palette.size(): From c6b3adceb48a786d49c08ea3e5a76665f12fd0fe Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 17:13:19 +0500 Subject: [PATCH 8/8] formatting --- src/Autoload/Tools.gd | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index 5cff9e158..48a0c3170 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -639,17 +639,13 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void: and active_button == -1 and not pen_inverted ) - or ( - event.is_action_pressed(&"activate_left_tool") and active_button == -1 and pen_inverted - ) + or event.is_action_pressed(&"activate_left_tool") and active_button == -1 and pen_inverted ): active_button = MOUSE_BUTTON_RIGHT _slots[active_button].tool_node.draw_start(draw_pos) elif ( (event.is_action_released(&"activate_right_tool") and active_button == MOUSE_BUTTON_RIGHT) - or ( - event.is_action_released(&"activate_left_tool") and active_button == MOUSE_BUTTON_RIGHT - ) + or event.is_action_released(&"activate_left_tool") and active_button == MOUSE_BUTTON_RIGHT ): _slots[active_button].tool_node.draw_end(draw_pos) active_button = -1