mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Fix palette swatch white border being shown on non-selected swatches, if the user has scrolled down
This commit is contained in:
parent
8c073dbe63
commit
14e73ae33b
|
@ -32,8 +32,7 @@ func set_palette(new_palette: Palette) -> void:
|
||||||
|
|
||||||
|
|
||||||
func setup_swatches() -> void:
|
func setup_swatches() -> void:
|
||||||
# Columns cannot be 0
|
columns = maxi(1, grid_size.x) # Columns cannot be 0
|
||||||
columns = 1 if grid_size.x == 0 else grid_size.x
|
|
||||||
if grid_size.x * grid_size.y > swatches.size():
|
if grid_size.x * grid_size.y > swatches.size():
|
||||||
for i in range(swatches.size(), grid_size.x * grid_size.y):
|
for i in range(swatches.size(), grid_size.x * grid_size.y):
|
||||||
var swatch := PALETTE_SWATCH_SCENE.instantiate() as PaletteSwatch
|
var swatch := PALETTE_SWATCH_SCENE.instantiate() as PaletteSwatch
|
||||||
|
@ -88,32 +87,30 @@ func scroll_palette(origin: Vector2i) -> void:
|
||||||
## Called when the color changes, either the left or the right, determined by [param mouse_button].
|
## 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.
|
## If current palette has [param target_color] as a [Color], then select it.
|
||||||
func find_and_select_color(target_color: Color, mouse_button: int) -> void:
|
func find_and_select_color(target_color: Color, mouse_button: int) -> void:
|
||||||
var found_color := false
|
|
||||||
var old_index := Palettes.current_palette_get_selected_color_index(mouse_button)
|
var old_index := Palettes.current_palette_get_selected_color_index(mouse_button)
|
||||||
for color_ind in swatches.size():
|
for color_ind in swatches.size():
|
||||||
if (
|
if (
|
||||||
target_color.is_equal_approx(swatches[color_ind].color)
|
target_color.is_equal_approx(swatches[color_ind].color)
|
||||||
or target_color.to_html() == swatches[color_ind].color.to_html()
|
or target_color.to_html() == swatches[color_ind].color.to_html()
|
||||||
):
|
):
|
||||||
select_swatch(mouse_button, color_ind, old_index)
|
var index := convert_grid_index_to_palette_index(color_ind)
|
||||||
|
select_swatch(mouse_button, index, old_index)
|
||||||
match mouse_button:
|
match mouse_button:
|
||||||
MOUSE_BUTTON_LEFT:
|
MOUSE_BUTTON_LEFT:
|
||||||
Palettes.left_selected_color = color_ind
|
Palettes.left_selected_color = index
|
||||||
MOUSE_BUTTON_RIGHT:
|
MOUSE_BUTTON_RIGHT:
|
||||||
Palettes.right_selected_color = color_ind
|
Palettes.right_selected_color = index
|
||||||
found_color = true
|
return
|
||||||
break
|
# Unselect swatches when tools color is changed
|
||||||
if not found_color:
|
var swatch_to_unselect := -1
|
||||||
# Unselect swatches when tools color is changed
|
if mouse_button == MOUSE_BUTTON_LEFT:
|
||||||
var swatch_to_unselect := -1
|
swatch_to_unselect = Palettes.left_selected_color
|
||||||
if mouse_button == MOUSE_BUTTON_LEFT:
|
Palettes.left_selected_color = -1
|
||||||
swatch_to_unselect = Palettes.left_selected_color
|
elif mouse_button == MOUSE_BUTTON_RIGHT:
|
||||||
Palettes.left_selected_color = -1
|
swatch_to_unselect = Palettes.right_selected_color
|
||||||
elif mouse_button == MOUSE_BUTTON_RIGHT:
|
Palettes.right_selected_color = -1
|
||||||
swatch_to_unselect = Palettes.right_selected_color
|
|
||||||
Palettes.right_selected_color = -1
|
|
||||||
|
|
||||||
unselect_swatch(mouse_button, swatch_to_unselect)
|
unselect_swatch(mouse_button, swatch_to_unselect)
|
||||||
|
|
||||||
|
|
||||||
## Displays a left/right highlight over a swatch
|
## Displays a left/right highlight over a swatch
|
||||||
|
@ -150,15 +147,15 @@ func get_swatch_color(palette_index: int) -> Color:
|
||||||
## Grid index adds grid window origin
|
## Grid index adds grid window origin
|
||||||
func convert_grid_index_to_palette_index(index: int) -> int:
|
func convert_grid_index_to_palette_index(index: int) -> int:
|
||||||
return (
|
return (
|
||||||
int(index / grid_size.x + grid_window_origin.y) * current_palette.width
|
(index / grid_size.x + grid_window_origin.y) * current_palette.width
|
||||||
+ (index % int(grid_size.x) + grid_window_origin.x)
|
+ (index % grid_size.x + grid_window_origin.x)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func convert_palette_index_to_grid_index(palette_index: int) -> int:
|
func convert_palette_index_to_grid_index(palette_index: int) -> int:
|
||||||
var x := palette_index % current_palette.width
|
var x := palette_index % current_palette.width
|
||||||
var y := palette_index / current_palette.width
|
var y := palette_index / current_palette.width
|
||||||
return int((x - grid_window_origin.x) + (y - grid_window_origin.y) * grid_size.x)
|
return (x - grid_window_origin.x) + (y - grid_window_origin.y) * grid_size.x
|
||||||
|
|
||||||
|
|
||||||
func resize_grid(new_rect_size: Vector2) -> void:
|
func resize_grid(new_rect_size: Vector2) -> void:
|
||||||
|
|
Loading…
Reference in a new issue