mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Make the color picker pick any visible color on the canvas, regardless of layer (#816)
* Pick top color by default * revert accidental commit * Pick top color by default * formatting * formatting
This commit is contained in:
parent
0a615298f5
commit
ef6ae86c8d
|
@ -1,7 +1,10 @@
|
|||
extends BaseTool
|
||||
|
||||
enum { TOP_COLOR, CURRENT_LAYER }
|
||||
|
||||
var _prev_mode := 0
|
||||
var _color_slot := 0
|
||||
var _mode := 0
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
@ -23,18 +26,24 @@ func _on_Options_item_selected(id: int) -> void:
|
|||
save_config()
|
||||
|
||||
|
||||
func _on_ExtractFrom_item_selected(index):
|
||||
_mode = index
|
||||
update_config()
|
||||
save_config()
|
||||
|
||||
|
||||
func get_config() -> Dictionary:
|
||||
return {
|
||||
"color_slot": _color_slot,
|
||||
}
|
||||
return {"color_slot": _color_slot, "mode": _mode}
|
||||
|
||||
|
||||
func set_config(config: Dictionary) -> void:
|
||||
_color_slot = config.get("color_slot", _color_slot)
|
||||
_mode = config.get("mode", _mode)
|
||||
|
||||
|
||||
func update_config() -> void:
|
||||
$ColorPicker/Options.selected = _color_slot
|
||||
$ColorPicker/ExtractFrom.selected = _mode
|
||||
|
||||
|
||||
func draw_start(position: Vector2) -> void:
|
||||
|
@ -58,13 +67,26 @@ func _pick_color(position: Vector2) -> void:
|
|||
if position.x < 0 or position.y < 0:
|
||||
return
|
||||
|
||||
var color := Color(0, 0, 0, 0)
|
||||
var image := Image.new()
|
||||
image.copy_from(_get_draw_image())
|
||||
if position.x > image.get_width() - 1 or position.y > image.get_height() - 1:
|
||||
return
|
||||
|
||||
image.lock()
|
||||
var color := image.get_pixelv(position)
|
||||
image.unlock()
|
||||
match _mode:
|
||||
TOP_COLOR:
|
||||
var curr_frame: Frame = project.frames[project.current_frame]
|
||||
for layer in project.layers.size():
|
||||
var idx = (project.layers.size() - 1) - layer
|
||||
if project.layers[idx].can_layer_get_drawn():
|
||||
image = curr_frame.cels[idx].get_image()
|
||||
image.lock()
|
||||
color = image.get_pixelv(position)
|
||||
image.unlock()
|
||||
if color != Color(0, 0, 0, 0):
|
||||
break
|
||||
CURRENT_LAYER:
|
||||
image.lock()
|
||||
color = image.get_pixelv(position)
|
||||
image.unlock()
|
||||
var button := BUTTON_LEFT if _color_slot == 0 else BUTTON_RIGHT
|
||||
Tools.assign_color(color, button, false)
|
||||
|
|
|
@ -9,7 +9,7 @@ script = ExtResource( 2 )
|
|||
[node name="ColorPicker" type="VBoxContainer" parent="." index="2"]
|
||||
margin_top = 26.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 64.0
|
||||
margin_bottom = 106.0
|
||||
|
||||
[node name="Label" type="Label" parent="ColorPicker" index="0"]
|
||||
margin_right = 116.0
|
||||
|
@ -27,4 +27,22 @@ text = "Left Color"
|
|||
items = [ "Left Color", null, false, 0, null, "Right Color", null, false, 1, null ]
|
||||
selected = 0
|
||||
|
||||
[node name="Label2" type="Label" parent="ColorPicker" index="2"]
|
||||
margin_top = 42.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 56.0
|
||||
mouse_default_cursor_shape = 2
|
||||
size_flags_vertical = 1
|
||||
text = "Pick mode:"
|
||||
|
||||
[node name="ExtractFrom" type="OptionButton" parent="ColorPicker" index="3"]
|
||||
margin_top = 60.0
|
||||
margin_right = 116.0
|
||||
margin_bottom = 80.0
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Top Color"
|
||||
items = [ "Top Color", null, false, 0, null, "Current Layer", null, false, 1, null ]
|
||||
selected = 0
|
||||
|
||||
[connection signal="item_selected" from="ColorPicker/Options" to="." method="_on_Options_item_selected"]
|
||||
[connection signal="item_selected" from="ColorPicker/ExtractFrom" to="." method="_on_ExtractFrom_item_selected"]
|
||||
|
|
|
@ -601,8 +601,16 @@ func _pick_color(position: Vector2) -> void:
|
|||
if position.x > image.get_width() - 1 or position.y > image.get_height() - 1:
|
||||
return
|
||||
|
||||
image.lock()
|
||||
var color := image.get_pixelv(position)
|
||||
image.unlock()
|
||||
var color := Color(0, 0, 0, 0)
|
||||
var curr_frame: Frame = project.frames[project.current_frame]
|
||||
for layer in project.layers.size():
|
||||
var idx = (project.layers.size() - 1) - layer
|
||||
if project.layers[idx].can_layer_get_drawn():
|
||||
image = curr_frame.cels[idx].get_image()
|
||||
image.lock()
|
||||
color = image.get_pixelv(position)
|
||||
image.unlock()
|
||||
if color != Color(0, 0, 0, 0):
|
||||
break
|
||||
var button := BUTTON_LEFT if Tools._slots[BUTTON_LEFT].tool_node == self else BUTTON_RIGHT
|
||||
Tools.assign_color(color, button, false)
|
||||
|
|
Loading…
Reference in a new issue