@@ -13,12 +13,15 @@ var _pattern: Patterns.Pattern
13
13
var _tolerance := 0.003
14
14
var _fill_area : int = FillArea .AREA
15
15
var _fill_with : int = FillWith .COLOR
16
+ var _fill_merged_area := false ## Fill regions from the merging of all layers
16
17
var _offset_x := 0
17
18
var _offset_y := 0
18
19
## Working array used as buffer for segments while flooding
19
20
var _allegro_flood_segments : Array [Segment ]
20
21
## Results array per image while flooding
21
22
var _allegro_image_segments : Array [Segment ]
23
+ ## Used for _fill_merged_area = true
24
+ var _sample_masks : Dictionary [Frame , Image ] = {}
22
25
23
26
24
27
class Segment :
@@ -59,8 +62,15 @@ func _on_FillAreaOptions_item_selected(index: int) -> void:
59
62
save_config ()
60
63
61
64
65
+ func _on_merge_area_options_toggled (toggled_on : bool ) -> void :
66
+ _fill_merged_area = toggled_on
67
+ update_config ()
68
+ save_config ()
69
+
70
+
62
71
func _select_fill_area_optionbutton () -> void :
63
72
$ FillAreaOptions .selected = _fill_area
73
+ $ MergeAreaOptions .visible = _fill_area == FillArea .AREA
64
74
$ ToleranceSlider .visible = (_fill_area != FillArea .SELECTION )
65
75
66
76
@@ -103,10 +113,16 @@ func _on_PatternOffsetY_value_changed(value: float) -> void:
103
113
104
114
func get_config () -> Dictionary :
105
115
if ! _pattern :
106
- return {"fill_area" : _fill_area , "fill_with" : _fill_with , "tolerance" : _tolerance }
116
+ return {
117
+ "fill_area" : _fill_area ,
118
+ "fill_merged_area" : _fill_merged_area ,
119
+ "fill_with" : _fill_with ,
120
+ "tolerance" : _tolerance
121
+ }
107
122
return {
108
123
"pattern_index" : _pattern .index ,
109
124
"fill_area" : _fill_area ,
125
+ "fill_merged_area" : _fill_merged_area ,
110
126
"fill_with" : _fill_with ,
111
127
"tolerance" : _tolerance ,
112
128
"offset_x" : _offset_x ,
@@ -119,6 +135,7 @@ func set_config(config: Dictionary) -> void:
119
135
var index = config .get ("pattern_index" , _pattern .index )
120
136
_pattern = Global .patterns_popup .get_pattern (index )
121
137
_fill_area = config .get ("fill_area" , _fill_area )
138
+ _fill_merged_area = config .get ("fill_merged_area" , _fill_merged_area )
122
139
_fill_with = config .get ("fill_with" , _fill_with )
123
140
_tolerance = config .get ("tolerance" , _tolerance )
124
141
_offset_x = config .get ("offset_x" , _offset_x )
@@ -133,6 +150,7 @@ func update_config() -> void:
133
150
$ FillPattern .visible = _fill_with == FillWith .PATTERN
134
151
$ FillPattern/OffsetX .value = _offset_x
135
152
$ FillPattern/OffsetY .value = _offset_y
153
+ $ MergeAreaOptions .button_pressed = _fill_merged_area
136
154
137
155
138
156
func update_pattern () -> void :
@@ -163,6 +181,18 @@ func draw_start(pos: Vector2i) -> void:
163
181
return
164
182
if not Global .current_project .can_pixel_get_drawn (pos ):
165
183
return
184
+ if _fill_merged_area and _fill_area == FillArea .AREA :
185
+ var project := Global .current_project
186
+ for frame_layer : Array in project .selected_cels :
187
+ if project .frames [frame_layer [0 ]].cels [frame_layer [1 ]] is PixelCel :
188
+ var frame := project .frames [frame_layer [0 ]]
189
+ if not _sample_masks .has (frame ):
190
+ var mask := Image .create (
191
+ project .size .x , project .size .y , false , Image .FORMAT_RGBA8
192
+ )
193
+ mask .fill (Color (0 , 0 , 0 , 0 ))
194
+ DrawingAlgos .blend_layers (mask , frame )
195
+ _sample_masks [frame ] = mask
166
196
fill (pos )
167
197
168
198
@@ -183,6 +213,7 @@ func draw_end(pos: Vector2i) -> void:
183
213
super .draw_end (pos )
184
214
if _picking_color :
185
215
return
216
+ _sample_masks .clear ()
186
217
commit_undo ()
187
218
188
219
@@ -343,11 +374,14 @@ func _flood_fill(pos: Vector2i) -> void:
343
374
)
344
375
return
345
376
346
- var images := _get_selected_draw_images ()
347
- for image in images :
377
+ var cels = _get_selected_draw_cels ()
378
+ for cel : PixelCel in cels :
379
+ var image : ImageExtended = cel .image
348
380
if Tools .check_alpha_lock (image , pos ):
349
381
continue
350
382
var color : Color = image .get_pixelv (pos )
383
+ if _fill_merged_area :
384
+ color = _sample_masks .get (cel .get_frame (project ), cel .image ).get_pixelv (pos )
351
385
if _fill_with == FillWith .COLOR or _pattern == null :
352
386
# end early if we are filling with the same color
353
387
if tool_slot .color .is_equal_approx (color ):
@@ -360,7 +394,12 @@ func _flood_fill(pos: Vector2i) -> void:
360
394
# init flood data structures
361
395
_allegro_flood_segments = []
362
396
_allegro_image_segments = []
363
- _compute_segments_for_image (pos , project , image , color )
397
+ _compute_segments_for_image (
398
+ pos ,
399
+ project ,
400
+ image if ! _fill_merged_area else _sample_masks .get (cel .get_frame (project ), cel .image ),
401
+ color
402
+ )
364
403
# now actually color the image: since we have already checked a few things for the points
365
404
# we'll process here, we're going to skip a bunch of safety checks to speed things up.
366
405
_color_segments (image )
0 commit comments