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":