1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 12:33:14 +00:00

Fixed issues where fully transparent color could not be picked

More specifically, the color picked sometimes failed to pick transparent color (and picked black instead), swapping between colors when one of them is fully transparent made it fully opaque, and also when picking a color from a palette which was fully transparent made it fully opaque.

Closes #364
This commit is contained in:
Manolis Papadeas 2020-10-23 20:18:39 +03:00
parent df7a650137
commit 96fc2aa12d
3 changed files with 11 additions and 10 deletions

View file

@ -59,7 +59,7 @@ var shift := false
var alt := false
func _ready():
func _ready() -> void:
yield(get_tree(), "idle_frame")
_slots[BUTTON_LEFT] = Slot.new("Left tool")
_slots[BUTTON_RIGHT] = Slot.new("Right tool")
@ -72,9 +72,9 @@ func _ready():
value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "tool", "Eraser")
set_tool(value, BUTTON_RIGHT)
value = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "color", Color.black)
assign_color(value, BUTTON_LEFT)
assign_color(value, BUTTON_LEFT, false)
value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "color", Color.white)
assign_color(value, BUTTON_RIGHT)
assign_color(value, BUTTON_RIGHT, false)
update_tool_buttons()
update_tool_cursors()
@ -115,13 +115,14 @@ func default_color() -> void:
func swap_color() -> void:
var left = _slots[BUTTON_LEFT].color
var right = _slots[BUTTON_RIGHT].color
assign_color(right, BUTTON_LEFT)
assign_color(left, BUTTON_RIGHT)
assign_color(right, BUTTON_LEFT, false)
assign_color(left, BUTTON_RIGHT, false)
func assign_color(color : Color, button : int) -> void:
func assign_color(color : Color, button : int, change_alpha := true) -> void:
var c : Color = _slots[button].color
if color.a == 0:
# This was requested by Issue #54 on GitHub
if color.a == 0 and change_alpha:
if color.r != c.r or color.g != c.g or color.b != c.b:
color.a = 1
_slots[button].color = color

View file

@ -268,9 +268,9 @@ func on_color_select(index : int) -> void:
var color : Color = Global.palettes[current_palette].get_color(index)
if Input.is_action_just_pressed("left_mouse"):
Tools.assign_color(color, BUTTON_LEFT)
Tools.assign_color(color, BUTTON_LEFT, false)
elif Input.is_action_just_pressed("right_mouse"):
Tools.assign_color(color, BUTTON_RIGHT)
Tools.assign_color(color, BUTTON_RIGHT, false)
func _load_palettes() -> void:

View file

@ -48,4 +48,4 @@ func _pick_color(position : Vector2) -> void:
image.lock()
var color := image.get_pixelv(position)
var button := BUTTON_LEFT if _color_slot == 0 else BUTTON_RIGHT
Tools.assign_color(color, button)
Tools.assign_color(color, button, false)