mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-20 12:33:14 +00:00
"Fill inside" option in pencil tool (#489)
I modified some code from "EIRTeam/Pixelorama" and merged it with pencil tool.
This commit is contained in:
parent
1b286a95ab
commit
62dc608eea
2 changed files with 57 additions and 12 deletions
|
@ -4,13 +4,13 @@ extends "res://src/Tools/Draw.gd"
|
|||
var _last_position := Vector2.INF
|
||||
var _changed := false
|
||||
var _overwrite := false
|
||||
|
||||
var _fill_inside := false
|
||||
var _draw_points := Array()
|
||||
|
||||
class PencilOp extends Drawer.ColorOp:
|
||||
var changed := false
|
||||
var overwrite := false
|
||||
|
||||
|
||||
func process(src: Color, dst: Color) -> Color:
|
||||
changed = true
|
||||
src.a *= strength
|
||||
|
@ -29,20 +29,29 @@ func _on_Overwrite_toggled(button_pressed : bool):
|
|||
save_config()
|
||||
|
||||
|
||||
func _on_FillInside_toggled(button_pressed):
|
||||
_fill_inside = button_pressed
|
||||
update_config()
|
||||
save_config()
|
||||
|
||||
|
||||
func get_config() -> Dictionary:
|
||||
var config := .get_config()
|
||||
config["overwrite"] = _overwrite
|
||||
config["fill_inside"] = _fill_inside
|
||||
return config
|
||||
|
||||
|
||||
func set_config(config : Dictionary) -> void:
|
||||
.set_config(config)
|
||||
_overwrite = config.get("overwrite", _overwrite)
|
||||
_fill_inside = config.get("fill_inside", _fill_inside)
|
||||
|
||||
|
||||
func update_config() -> void:
|
||||
.update_config()
|
||||
$Overwrite.pressed = _overwrite
|
||||
$FillInside.pressed = _fill_inside
|
||||
|
||||
|
||||
func draw_start(position : Vector2) -> void:
|
||||
|
@ -51,6 +60,7 @@ func draw_start(position : Vector2) -> void:
|
|||
_changed = false
|
||||
_drawer.color_op.changed = false
|
||||
_drawer.color_op.overwrite = _overwrite
|
||||
_draw_points = Array()
|
||||
|
||||
prepare_undo()
|
||||
_drawer.reset()
|
||||
|
@ -61,6 +71,8 @@ func draw_start(position : Vector2) -> void:
|
|||
_line_end = position
|
||||
update_line_polylines(_line_start, _line_end)
|
||||
else:
|
||||
if _fill_inside:
|
||||
_draw_points.append(position)
|
||||
draw_tool(position)
|
||||
_last_position = position
|
||||
Global.canvas.sprite_changed_this_frame = true
|
||||
|
@ -78,6 +90,8 @@ func draw_move(position : Vector2) -> void:
|
|||
_last_position = position
|
||||
cursor_text = ""
|
||||
Global.canvas.sprite_changed_this_frame = true
|
||||
if _fill_inside:
|
||||
_draw_points.append(position)
|
||||
|
||||
|
||||
func draw_end(_position : Vector2) -> void:
|
||||
|
@ -85,6 +99,21 @@ func draw_end(_position : Vector2) -> void:
|
|||
draw_tool(_line_start)
|
||||
draw_fill_gap(_line_start, _line_end)
|
||||
_draw_line = false
|
||||
else:
|
||||
if _fill_inside:
|
||||
_draw_points.append(_position)
|
||||
if _draw_points.size() > 3:
|
||||
var image = _get_draw_image()
|
||||
var v = Vector2()
|
||||
var image_size = image.get_size()
|
||||
for x in image_size.x:
|
||||
v.x = x
|
||||
for y in image_size.y:
|
||||
v.y = y
|
||||
if Geometry.is_point_in_polygon(v, _draw_points):
|
||||
image.lock()
|
||||
draw_tool(v)
|
||||
image.unlock()
|
||||
if _changed or _drawer.color_op.changed:
|
||||
commit_undo("Draw")
|
||||
cursor_text = ""
|
||||
|
@ -97,3 +126,5 @@ func _draw_brush_image(image : Image, src_rect: Rect2, dst: Vector2) -> void:
|
|||
_get_draw_image().blit_rect(image, src_rect, dst)
|
||||
else:
|
||||
_get_draw_image().blend_rect(image, src_rect, dst)
|
||||
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@ margin_right = 128.0
|
|||
margin_right = 128.0
|
||||
|
||||
[node name="Type" parent="Brush" index="0"]
|
||||
margin_left = 7.0
|
||||
margin_right = 43.0
|
||||
margin_left = 9.0
|
||||
margin_right = 41.0
|
||||
|
||||
[node name="Size" parent="Brush" index="1"]
|
||||
margin_left = 47.0
|
||||
margin_right = 121.0
|
||||
margin_left = 45.0
|
||||
margin_right = 119.0
|
||||
|
||||
[node name="BrushSize" parent="." index="2"]
|
||||
margin_left = 18.0
|
||||
|
@ -45,15 +45,27 @@ margin_top = 102.0
|
|||
margin_right = 118.0
|
||||
margin_bottom = 126.0
|
||||
|
||||
[node name="EmptySpacer" parent="." index="6"]
|
||||
[node name="FillInside" type="CheckBox" parent="." index="5"]
|
||||
margin_left = 19.0
|
||||
margin_top = 130.0
|
||||
margin_right = 128.0
|
||||
margin_bottom = 142.0
|
||||
margin_right = 109.0
|
||||
margin_bottom = 154.0
|
||||
size_flags_horizontal = 4
|
||||
text = "Fill inside"
|
||||
align = 1
|
||||
__meta__ = {
|
||||
"_editor_description_": ""
|
||||
}
|
||||
|
||||
[node name="Mirror" parent="." index="7"]
|
||||
margin_top = 146.0
|
||||
[node name="EmptySpacer" parent="." index="7"]
|
||||
margin_top = 158.0
|
||||
margin_right = 128.0
|
||||
margin_bottom = 163.0
|
||||
margin_bottom = 170.0
|
||||
|
||||
[node name="Mirror" parent="." index="8"]
|
||||
margin_top = 174.0
|
||||
margin_right = 128.0
|
||||
margin_bottom = 191.0
|
||||
|
||||
[node name="Horizontal" parent="Mirror" index="0"]
|
||||
margin_left = 26.0
|
||||
|
@ -62,4 +74,6 @@ margin_right = 41.0
|
|||
[node name="Vertical" parent="Mirror" index="1"]
|
||||
margin_left = 85.0
|
||||
margin_right = 102.0
|
||||
|
||||
[connection signal="toggled" from="Overwrite" to="." method="_on_Overwrite_toggled"]
|
||||
[connection signal="toggled" from="FillInside" to="." method="_on_FillInside_toggled"]
|
||||
|
|
Loading…
Add table
Reference in a new issue