mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Add overwrite option to pencil. (#282)
This commit is contained in:
parent
e04b79dd4b
commit
fd3afbfebc
|
@ -3,26 +3,53 @@ extends "res://src/Tools/Draw.gd"
|
|||
|
||||
var _last_position := Vector2.INF
|
||||
var _changed := false
|
||||
var _overwrite := false
|
||||
|
||||
|
||||
class AlphaBlendOp extends Drawer.ColorOp:
|
||||
class PencilOp extends Drawer.ColorOp:
|
||||
var changed := false
|
||||
var overwrite := false
|
||||
|
||||
|
||||
func process(src: Color, dst: Color) -> Color:
|
||||
changed = true
|
||||
src.a *= strength
|
||||
if overwrite:
|
||||
return src
|
||||
return dst.blend(src)
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_drawer.color_op = AlphaBlendOp.new()
|
||||
_drawer.color_op = PencilOp.new()
|
||||
|
||||
|
||||
func _on_Overwrite_toggled(button_pressed : bool):
|
||||
_overwrite = button_pressed
|
||||
update_config()
|
||||
save_config()
|
||||
|
||||
|
||||
func get_config() -> Dictionary:
|
||||
var config := .get_config()
|
||||
config["overwrite"] = _overwrite
|
||||
return config
|
||||
|
||||
|
||||
func set_config(config : Dictionary) -> void:
|
||||
.set_config(config)
|
||||
_overwrite = config.get("overwrite", _overwrite)
|
||||
|
||||
|
||||
func update_config() -> void:
|
||||
.update_config()
|
||||
$Overwrite.pressed = _overwrite
|
||||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
update_mask()
|
||||
_changed = false
|
||||
_drawer.color_op.changed = false
|
||||
_drawer.color_op.overwrite = _overwrite
|
||||
|
||||
prepare_undo()
|
||||
_drawer.reset()
|
||||
|
@ -65,4 +92,7 @@ func draw_end(_position : Vector2) -> void:
|
|||
|
||||
func _draw_brush_image(image : Image, src_rect: Rect2, dst: Vector2) -> void:
|
||||
_changed = true
|
||||
_get_draw_image().blend_rect(image, src_rect, dst)
|
||||
if _overwrite:
|
||||
_get_draw_image().blit_rect(image, src_rect, dst)
|
||||
else:
|
||||
_get_draw_image().blend_rect(image, src_rect, dst)
|
||||
|
|
|
@ -5,3 +5,31 @@
|
|||
|
||||
[node name="ToolOptions" instance=ExtResource( 1 )]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="Overwrite" type="CheckBox" parent="." index="3"]
|
||||
margin_left = 12.0
|
||||
margin_top = 74.0
|
||||
margin_right = 103.0
|
||||
margin_bottom = 98.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_default_cursor_shape = 2
|
||||
size_flags_horizontal = 4
|
||||
text = "Overwrite"
|
||||
align = 1
|
||||
__meta__ = {
|
||||
"_editor_description_": ""
|
||||
}
|
||||
|
||||
[node name="PixelPerfect" parent="." index="4"]
|
||||
margin_top = 102.0
|
||||
margin_bottom = 126.0
|
||||
|
||||
[node name="EmptySpacer" parent="." index="6"]
|
||||
margin_top = 130.0
|
||||
margin_bottom = 142.0
|
||||
|
||||
[node name="Mirror" parent="." index="7"]
|
||||
margin_top = 146.0
|
||||
margin_bottom = 163.0
|
||||
[connection signal="toggled" from="Overwrite" to="." method="_on_Overwrite_toggled"]
|
||||
|
|
Loading…
Reference in a new issue