@@ -253,90 +253,57 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
253
253
}
254
254
}
255
255
256
- void common_hal_bitmaptools_paint_fill (displayio_bitmap_t * destination ,
256
+ void common_hal_bitmaptools_boundary_fill (displayio_bitmap_t * destination ,
257
257
int16_t x , int16_t y ,
258
258
uint32_t value , uint32_t background_value ) {
259
259
260
- /*def _boundaryFill4(self, px, py, fc, bc): # px & py = x, y coord to start fill, fc = fill color, bc = background color
261
- fillArea = [[px, py]]
262
-
263
- while len(fillArea) > 0:
264
- x, y = fillArea.pop()
265
-
266
- if self._bitmap[x, y] != bc:
267
- continue
268
- self._bitmap[x, y] = fc
269
- fillArea.append((x + 1, y))
270
- fillArea.append((x - 1, y))
271
- fillArea.append((x, y + 1))
272
- fillArea.append((x, y - 1))*/
273
-
260
+ // the list of points that we'll check
274
261
mp_obj_t fill_area = mp_obj_new_list (0 , NULL );
262
+
263
+ // first point is the one user passed in
275
264
mp_obj_t point [] = { mp_obj_new_int (x ), mp_obj_new_int (y ) };
276
265
mp_obj_list_append (
277
266
fill_area ,
278
267
mp_obj_new_tuple (2 , point )
279
268
);
280
- //mp_obj_list_t *point;
281
- //mp_obj_list_append(point, x);
282
- //mp_obj_list_append(point, y);
283
-
284
269
285
270
mp_obj_t * fill_points ;
286
271
size_t list_length = 0 ;
287
272
mp_obj_list_get (fill_area , & list_length , & fill_points );
288
- //mp_printf(&mp_plat_print, "\nLen bfore loop: %d", list_length);
273
+
289
274
mp_obj_t current_point ;
290
275
uint32_t current_point_color_value ;
291
276
292
277
size_t tuple_len = 0 ;
293
278
mp_obj_t * tuple_items ;
294
279
295
-
280
+ // while there are still points to check
296
281
while (list_length > 0 ){
297
282
mp_obj_list_get (fill_area , & list_length , & fill_points );
298
- //mp_printf(&mp_plat_print, "\nLen begin loop: %d\n", list_length);
299
283
current_point = mp_obj_list_pop (fill_area , 0 );
300
-
301
-
302
- //mp_obj_print(current_point, PRINT_STR);
303
284
mp_obj_tuple_get (current_point , & tuple_len , & tuple_items );
304
285
current_point_color_value = common_hal_displayio_bitmap_get_pixel (
305
286
destination ,
306
287
mp_obj_get_int (tuple_items [0 ]),
307
288
mp_obj_get_int (tuple_items [1 ]));
308
289
309
- //mp_printf(&mp_plat_print, "%d\n", current_point_color_value);
310
-
290
+ // if the current point is not background color ignore it
311
291
if (current_point_color_value != background_value ){
312
292
mp_obj_list_get (fill_area , & list_length , & fill_points );
313
293
continue ;
314
294
}
315
295
316
-
317
-
296
+ // fill the current point with fill color
318
297
displayio_bitmap_write_pixel (
319
298
destination ,
320
299
mp_obj_get_int (tuple_items [0 ]),
321
300
mp_obj_get_int (tuple_items [1 ]),
322
301
value );
323
302
324
-
325
- //mp_obj_t above_point[] = { mp_obj_new_int(tuple_items[0]), mp_obj_new_int(tuple_items[1])-1 };
326
- //mp_printf(&mp_plat_print,"math:\n");
327
- //mp_printf(&mp_plat_print, "%d\n", mp_obj_get_int(tuple_items[0]));
328
- //mp_printf(&mp_plat_print, "%d\n", mp_obj_get_int(tuple_items[0])+1);
329
- //int16_t above_int = mp_obj_get_int(tuple_items[0])+1;
330
- //mp_printf(&mp_plat_print, "%d\n", above_int);
331
- //int16_t *above = &above_int;
332
- //mp_printf(&mp_plat_print, "%d\n", above);
333
-
303
+ // add all 4 surrounding points to the list to check
334
304
mp_obj_t above_point [] = {
335
305
tuple_items [0 ],
336
306
MP_OBJ_NEW_SMALL_INT (mp_obj_int_get_checked (tuple_items [1 ])- 1 )};
337
-
338
- //mp_printf(&mp_plat_print,"above_point:\n");
339
- //mp_obj_print(above_point, PRINT_STR);
340
307
mp_obj_list_append (
341
308
fill_area ,
342
309
mp_obj_new_tuple (2 , above_point ));
@@ -363,26 +330,12 @@ void common_hal_bitmaptools_paint_fill(displayio_bitmap_t *destination,
363
330
mp_obj_new_tuple (2 , below_point ));
364
331
365
332
mp_obj_list_get (fill_area , & list_length , & fill_points );
366
- //mp_printf(&mp_plat_print, "\nLen end loop: %d\n", list_length);
367
333
}
368
334
335
+ // set dirty the area so displayio will draw
369
336
displayio_area_t area = { 0 , 0 , destination -> width , destination -> height };
370
337
displayio_bitmap_set_dirty_area (destination , & area );
371
338
372
- //mp_obj_print(fill_area, PRINT_STR);
373
- //mp_obj_print(current_point[0], PRINT_STR);
374
-
375
- /*
376
- mp_printf(&mp_plat_print, "\nLen: %d", list_length);
377
- size_t tuple_len = 0;
378
- mp_obj_t *tuple_items;
379
- mp_obj_tuple_get(current_point[0], &tuple_len, &tuple_items);
380
-
381
- //mp_obj_print(mp_obj_get_int(tuple_items[0])+1, PRINT_STR);
382
-
383
- mp_printf(&mp_plat_print, "\n%d", mp_obj_get_int(tuple_items[0])+1);
384
- */
385
-
386
339
}
387
340
388
341
void common_hal_bitmaptools_draw_line (displayio_bitmap_t * destination ,
0 commit comments