diff --git a/src/Tools/Pencil.gd b/src/Tools/Pencil.gd index 4b0cde1a0..c139a06cc 100644 --- a/src/Tools/Pencil.gd +++ b/src/Tools/Pencil.gd @@ -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) diff --git a/src/Tools/Pencil.tscn b/src/Tools/Pencil.tscn index 8a1c113b6..24045c273 100644 --- a/src/Tools/Pencil.tscn +++ b/src/Tools/Pencil.tscn @@ -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"]