1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Add an opacity option for the Eraser's tool options

This lets the user change the strength of the tool. When it has an opacity of 255, the eraser will completely delete the underlying pixels. If it has less than 255, it will simply subtruct that value from the underlying pixel's alpha.
This commit is contained in:
Manolis Papadeas 2021-10-12 23:12:05 +03:00
parent a5e3afa7e2
commit cdb7ff1004
2 changed files with 75 additions and 5 deletions

View file

@ -9,12 +9,12 @@ var _changed := false
class EraseOp extends Drawer.ColorOp:
var changed := false
func process(_src: Color, _dst: Color) -> Color:
func process(_src: Color, dst: Color) -> Color:
changed = true
# dst.a -= src.a * strength
# return dst
return Color(0, 0, 0, 0)
dst.a -= strength
if dst.a <= 0:
dst = Color(0, 0, 0, 0)
return dst
func _init() -> void:
@ -23,6 +23,17 @@ func _init() -> void:
_clear_image.fill(Color(0, 0, 0, 0))
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)
func draw_start(position : Vector2) -> void:
Global.canvas.selection.transform_content_confirm()
update_mask()
@ -77,3 +88,15 @@ func _draw_brush_image(image : Image, src_rect: Rect2, dst: Vector2) -> void:
var images := _get_selected_draw_images()
for draw_image in images:
draw_image.blit_rect_mask(_clear_image, image, src_rect, dst)
func _on_Opacity_value_changed(value: float) -> void:
_strength = value / 255
update_config()
save_config()
func update_config() -> void:
.update_config()
$OpacitySpinBox.value = _strength * 255
$OpacitySlider.value = _strength * 255

View file

@ -5,3 +5,50 @@
[node name="ToolOptions" instance=ExtResource( 1 )]
script = ExtResource( 2 )
[node name="OpacityLabel" type="Label" parent="." index="3"]
margin_top = 74.0
margin_right = 116.0
margin_bottom = 88.0
text = "Opacity:"
align = 1
[node name="OpacitySpinBox" type="SpinBox" parent="." index="4"]
margin_left = 21.0
margin_top = 92.0
margin_right = 95.0
margin_bottom = 116.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 4
max_value = 255.0
value = 255.0
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="OpacitySlider" type="HSlider" parent="." index="5"]
margin_left = 12.0
margin_top = 120.0
margin_right = 104.0
margin_bottom = 136.0
rect_min_size = Vector2( 92, 0 )
mouse_default_cursor_shape = 2
size_flags_horizontal = 4
max_value = 255.0
value = 255.0
[node name="PixelPerfect" parent="." index="6"]
margin_top = 140.0
margin_bottom = 164.0
[node name="EmptySpacer" parent="." index="8"]
margin_top = 168.0
margin_bottom = 180.0
[node name="Mirror" parent="." index="9"]
margin_top = 184.0
margin_bottom = 201.0
[connection signal="value_changed" from="OpacitySpinBox" to="." method="_on_Opacity_value_changed"]
[connection signal="value_changed" from="OpacitySlider" to="." method="_on_Opacity_value_changed"]