2020-07-09 12:22:17 +00:00
|
|
|
extends "res://src/Tools/Draw.gd"
|
|
|
|
|
|
|
|
|
|
|
|
var _last_position := Vector2.INF
|
|
|
|
var _clear_image := Image.new()
|
|
|
|
var _changed := false
|
|
|
|
|
|
|
|
|
|
|
|
class EraseOp extends Drawer.ColorOp:
|
|
|
|
var changed := false
|
|
|
|
|
2021-10-12 20:12:05 +00:00
|
|
|
func process(_src: Color, dst: Color) -> Color:
|
2020-07-09 12:22:17 +00:00
|
|
|
changed = true
|
2021-10-12 20:12:05 +00:00
|
|
|
dst.a -= strength
|
|
|
|
if dst.a <= 0:
|
|
|
|
dst = Color(0, 0, 0, 0)
|
|
|
|
return dst
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
_drawer.color_op = EraseOp.new()
|
|
|
|
_clear_image.create(1, 1, false, Image.FORMAT_RGBA8)
|
|
|
|
_clear_image.fill(Color(0, 0, 0, 0))
|
|
|
|
|
|
|
|
|
2021-10-12 20:12:05 +00:00
|
|
|
func get_config() -> Dictionary:
|
|
|
|
var config := .get_config()
|
|
|
|
config["strength"] = _strength
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
func set_config(config : Dictionary) -> void:
|
|
|
|
.set_config(config)
|
|
|
|
_strength = config.get("strength", _strength)
|
|
|
|
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
func draw_start(position : Vector2) -> void:
|
2021-11-14 01:30:00 +00:00
|
|
|
if Input.is_action_pressed("alt"):
|
|
|
|
_picking_color = true
|
|
|
|
_pick_color(position)
|
|
|
|
return
|
|
|
|
_picking_color = false
|
|
|
|
|
2021-04-23 20:37:07 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2021-11-08 17:26:00 +00:00
|
|
|
update_mask(_strength == 1)
|
2020-07-09 12:22:17 +00:00
|
|
|
_changed = false
|
|
|
|
_drawer.color_op.changed = false
|
|
|
|
|
|
|
|
prepare_undo()
|
|
|
|
_drawer.reset()
|
|
|
|
|
|
|
|
_draw_line = Tools.shift
|
|
|
|
if _draw_line:
|
|
|
|
_line_start = position
|
|
|
|
_line_end = position
|
|
|
|
update_line_polylines(_line_start, _line_end)
|
|
|
|
else:
|
|
|
|
draw_tool(position)
|
|
|
|
_last_position = position
|
|
|
|
Global.canvas.sprite_changed_this_frame = true
|
|
|
|
cursor_text = ""
|
|
|
|
|
|
|
|
|
|
|
|
func draw_move(position : Vector2) -> void:
|
2021-11-14 01:30:00 +00:00
|
|
|
if _picking_color: # Still return even if we released Alt
|
|
|
|
if Input.is_action_pressed("alt"):
|
|
|
|
_pick_color(position)
|
|
|
|
return
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
if _draw_line:
|
|
|
|
var d = _line_angle_constraint(_line_start, position)
|
|
|
|
_line_end = d.position
|
|
|
|
cursor_text = d.text
|
|
|
|
update_line_polylines(_line_start, _line_end)
|
|
|
|
else:
|
|
|
|
draw_fill_gap(_last_position, position)
|
|
|
|
_last_position = position
|
|
|
|
cursor_text = ""
|
|
|
|
Global.canvas.sprite_changed_this_frame = true
|
|
|
|
|
|
|
|
|
|
|
|
func draw_end(_position : Vector2) -> void:
|
2021-11-14 01:30:00 +00:00
|
|
|
if _picking_color:
|
|
|
|
return
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
if _draw_line:
|
|
|
|
draw_tool(_line_start)
|
|
|
|
draw_fill_gap(_line_start, _line_end)
|
|
|
|
_draw_line = false
|
|
|
|
if _changed or _drawer.color_op.changed:
|
|
|
|
commit_undo("Draw")
|
|
|
|
cursor_text = ""
|
|
|
|
update_random_image()
|
|
|
|
|
|
|
|
|
2021-07-20 23:19:46 +00:00
|
|
|
func _draw_brush_image(image : Image, src_rect: Rect2, dst: Vector2) -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
_changed = true
|
2021-11-14 14:19:38 +00:00
|
|
|
if _strength == 1:
|
|
|
|
var size := image.get_size()
|
|
|
|
if _clear_image.get_size() != size:
|
|
|
|
_clear_image.resize(size.x, size.y, Image.INTERPOLATE_NEAREST)
|
|
|
|
|
|
|
|
var images := _get_selected_draw_images()
|
|
|
|
for draw_image in images:
|
|
|
|
draw_image.blit_rect_mask(_clear_image, image, src_rect, dst)
|
|
|
|
else:
|
|
|
|
image.lock()
|
|
|
|
for xx in image.get_size().x:
|
|
|
|
for yy in image.get_size().y:
|
|
|
|
if image.get_pixel(xx, yy).a > 0:
|
|
|
|
var pos := Vector2(xx, yy) + dst - src_rect.position
|
|
|
|
_set_pixel(pos, true)
|
|
|
|
image.unlock()
|
2021-10-12 20:12:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_Opacity_value_changed(value: float) -> void:
|
|
|
|
_strength = value / 255
|
|
|
|
update_config()
|
|
|
|
save_config()
|
|
|
|
|
|
|
|
|
|
|
|
func update_config() -> void:
|
|
|
|
.update_config()
|
2021-10-15 13:31:24 +00:00
|
|
|
$Opacity/OpacitySpinBox.value = _strength * 255
|
|
|
|
$Opacity/OpacitySlider.value = _strength * 255
|
2021-11-15 00:03:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
func update_brush() -> void:
|
|
|
|
.update_brush()
|
|
|
|
$ColorInterpolation.visible = false
|