2021-02-02 17:48:17 +02:00
|
|
|
extends BaseTool
|
2020-07-09 20:22:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
var _color_slot := 0
|
|
|
|
|
|
|
|
|
2021-02-02 17:48:17 +02:00
|
|
|
func _on_Options_item_selected(id : int) -> void:
|
2020-07-09 20:22:17 +08:00
|
|
|
_color_slot = id
|
|
|
|
update_config()
|
|
|
|
save_config()
|
|
|
|
|
|
|
|
|
|
|
|
func get_config() -> Dictionary:
|
|
|
|
return {
|
|
|
|
"color_slot" : _color_slot,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func set_config(config : Dictionary) -> void:
|
|
|
|
_color_slot = config.get("color_slot", _color_slot)
|
|
|
|
|
|
|
|
|
|
|
|
func update_config() -> void:
|
|
|
|
$ColorPicker/Options.selected = _color_slot
|
|
|
|
|
|
|
|
|
|
|
|
func draw_start(position : Vector2) -> void:
|
|
|
|
_pick_color(position)
|
|
|
|
|
|
|
|
|
|
|
|
func draw_move(position : Vector2) -> void:
|
|
|
|
_pick_color(position)
|
|
|
|
|
|
|
|
|
|
|
|
func draw_end(_position : Vector2) -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func _pick_color(position : Vector2) -> void:
|
2020-08-06 06:13:45 -03:00
|
|
|
if position.x < 0 or position.y < 0:
|
|
|
|
return
|
|
|
|
|
2020-07-09 20:22:17 +08:00
|
|
|
var image := Image.new()
|
|
|
|
image.copy_from(_get_draw_image())
|
2020-08-06 06:13:45 -03:00
|
|
|
if position.x > image.get_width() - 1 or position.y > image.get_height() - 1:
|
|
|
|
return
|
|
|
|
|
2020-07-09 20:22:17 +08:00
|
|
|
image.lock()
|
|
|
|
var color := image.get_pixelv(position)
|
|
|
|
var button := BUTTON_LEFT if _color_slot == 0 else BUTTON_RIGHT
|
2020-10-23 20:18:39 +03:00
|
|
|
Tools.assign_color(color, button, false)
|