From 605bff732440bb6d19e8ef733ff3171a1959653a Mon Sep 17 00:00:00 2001
From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com>
Date: Sun, 15 Dec 2024 00:13:59 +0200
Subject: [PATCH] Show the index of the palette swatches when color indices are
 visible on the canvas

---
 src/Palette/PaletteGrid.gd   |  1 +
 src/Palette/PaletteSwatch.gd | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/src/Palette/PaletteGrid.gd b/src/Palette/PaletteGrid.gd
index 89b4633fb..bcb767a78 100644
--- a/src/Palette/PaletteGrid.gd
+++ b/src/Palette/PaletteGrid.gd
@@ -64,6 +64,7 @@ func draw_palette() -> void:
 			var grid_index := i + grid_size.x * j
 			var index := convert_grid_index_to_palette_index(grid_index)
 			var swatch := swatches[grid_index]
+			swatch.color_index = index
 			swatch.show_left_highlight = Palettes.left_selected_color == index
 			swatch.show_right_highlight = Palettes.right_selected_color == index
 			var color = current_palette.get_color(index)
diff --git a/src/Palette/PaletteSwatch.gd b/src/Palette/PaletteSwatch.gd
index bcb6937e2..5259eb157 100644
--- a/src/Palette/PaletteSwatch.gd
+++ b/src/Palette/PaletteSwatch.gd
@@ -8,6 +8,7 @@ signal dropped(source_index: int, new_index: int)
 const DEFAULT_COLOR := Color(0.0, 0.0, 0.0, 0.0)
 
 var index := -1
+var color_index := -1
 var show_left_highlight := false
 var show_right_highlight := false
 var empty := true:
@@ -48,6 +49,23 @@ func _draw() -> void:
 		draw_rect(
 			Rect2(margin - Vector2.ONE, size - margin * 2 + Vector2(2, 2)), Color.WHITE, false, 1
 		)
+	if Global.show_pixel_indices:
+		var font := Themes.get_font()
+		var str_pos := Vector2(size.x / 2, size.y - 2)
+		var text_color := Global.control.theme.get_color(&"font_color", &"Label")
+		draw_string_outline(
+			font,
+			str_pos,
+			str(color_index),
+			HORIZONTAL_ALIGNMENT_RIGHT,
+			-1,
+			size.x / 2,
+			1,
+			text_color.inverted()
+		)
+		draw_string(
+			font, str_pos, str(color_index), HORIZONTAL_ALIGNMENT_RIGHT, -1, size.x / 2, text_color
+		)
 
 
 ## Enables drawing of highlights which indicate selected swatches