mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 09:09:47 +00:00
Fix two bugs with palettes, see description
1) `Palettes`'s `reindex_colors_on_width_increase()` was not changing the `index` of `PaletteColors`, thus resulting in the opened palette itself and the saved file having different indices, which could've caused conflicts with multiple colors sharing the same index, if the user re-arranged the palette after resizing it. 2) If the width was increased but the height increased, the positions of the colors remained the same, which resulted in the colors being in the columns that were removed, to be removed themselves. Now, the colors are taking advantage of the empty space, in order to remove as less as colors as possible. No colors will be removed if the width times the height is equal to or greater than it was before.
This commit is contained in:
parent
f7296efbc5
commit
b6583e4133
|
@ -56,6 +56,7 @@ func _init(
|
|||
|
||||
func edit(new_name: String, new_width: int, new_height: int, new_comment: String) -> void:
|
||||
var old_width := width
|
||||
var old_height := height
|
||||
width = new_width
|
||||
height = new_height
|
||||
name = new_name
|
||||
|
@ -68,7 +69,7 @@ func edit(new_name: String, new_width: int, new_height: int, new_comment: String
|
|||
# If size was reduced colors must be reindexed to fit into new smaller size
|
||||
reindex_colors_on_size_reduce(true)
|
||||
|
||||
if old_width < new_width and colors_max > old_colors_max:
|
||||
if old_width < new_width and height >= old_height:
|
||||
# If width increases colors have to be reindexed so they keep same grid positions
|
||||
# unless the height has become smaller and we have to re-position the colors
|
||||
# so that they won't get erased
|
||||
|
@ -158,12 +159,13 @@ func reindex_colors_on_size_reduce(remove_trailing: bool) -> void:
|
|||
## Adds difference of old and new width to color indexes
|
||||
## so they remain on the same position as before resize
|
||||
func reindex_colors_on_width_increase(old_width: int) -> void:
|
||||
var sorted_colors_indexes := colors.keys()
|
||||
sorted_colors_indexes.sort()
|
||||
var sorted_colors_indices := colors.keys()
|
||||
sorted_colors_indices.sort()
|
||||
var new_colors := {}
|
||||
for old_index: int in sorted_colors_indexes:
|
||||
for old_index: int in sorted_colors_indices:
|
||||
var new_index := old_index + (width - old_width) * (old_index / old_width)
|
||||
new_colors[new_index] = colors[old_index]
|
||||
new_colors[new_index].index = new_index
|
||||
|
||||
colors = new_colors
|
||||
|
||||
|
|
Loading…
Reference in a new issue