1 #define __SP_FLOOD_CONTEXT_C__
3 /** \file
4 * Bucket fill drawing context, works by bitmap filling an area on a rendered version of the current display and then tracing the result using potrace.
5 *
6 * Author:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
9 * John Bintz <jcoswell@coswellproductions.org>
10 *
11 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
12 * Copyright (C) 2000-2005 authors
13 * Copyright (C) 2000-2001 Ximian, Inc.
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
18 #include "config.h"
20 #include <gdk/gdkkeysyms.h>
21 #include <queue>
22 #include <deque>
24 #include "macros.h"
25 #include "display/sp-canvas.h"
26 #include "document.h"
27 #include "sp-namedview.h"
28 #include "sp-object.h"
29 #include "sp-rect.h"
30 #include "selection.h"
31 #include "desktop-handles.h"
32 #include "desktop.h"
33 #include "desktop-style.h"
34 #include "message-stack.h"
35 #include "message-context.h"
36 #include "pixmaps/cursor-paintbucket.xpm"
37 #include "flood-context.h"
38 #include "sp-metrics.h"
39 #include <glibmm/i18n.h>
40 #include "object-edit.h"
41 #include "xml/repr.h"
42 #include "xml/node-event-vector.h"
43 #include "prefs-utils.h"
44 #include "context-fns.h"
45 #include "rubberband.h"
47 #include "display/nr-arena-item.h"
48 #include "display/nr-arena.h"
49 #include "display/nr-arena-image.h"
50 #include "display/canvas-arena.h"
51 #include "libnr/nr-pixops.h"
52 #include "libnr/nr-matrix-translate-ops.h"
53 #include "libnr/nr-scale-ops.h"
54 #include "libnr/nr-scale-translate-ops.h"
55 #include "libnr/nr-translate-matrix-ops.h"
56 #include "libnr/nr-translate-scale-ops.h"
57 #include "libnr/nr-matrix-ops.h"
58 #include "sp-item.h"
59 #include "sp-root.h"
60 #include "sp-defs.h"
61 #include "sp-path.h"
62 #include "splivarot.h"
63 #include "livarot/Path.h"
64 #include "livarot/Shape.h"
65 #include "libnr/n-art-bpath.h"
66 #include "svg/svg.h"
67 #include "color.h"
69 #include "trace/trace.h"
70 #include "trace/imagemap.h"
71 #include "trace/potrace/inkscape-potrace.h"
73 static void sp_flood_context_class_init(SPFloodContextClass *klass);
74 static void sp_flood_context_init(SPFloodContext *flood_context);
75 static void sp_flood_context_dispose(GObject *object);
77 static void sp_flood_context_setup(SPEventContext *ec);
79 static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event);
80 static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
82 static void sp_flood_finish(SPFloodContext *rc);
84 static SPEventContextClass *parent_class;
87 GtkType sp_flood_context_get_type()
88 {
89 static GType type = 0;
90 if (!type) {
91 GTypeInfo info = {
92 sizeof(SPFloodContextClass),
93 NULL, NULL,
94 (GClassInitFunc) sp_flood_context_class_init,
95 NULL, NULL,
96 sizeof(SPFloodContext),
97 4,
98 (GInstanceInitFunc) sp_flood_context_init,
99 NULL, /* value_table */
100 };
101 type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPFloodContext", &info, (GTypeFlags) 0);
102 }
103 return type;
104 }
106 static void sp_flood_context_class_init(SPFloodContextClass *klass)
107 {
108 GObjectClass *object_class = (GObjectClass *) klass;
109 SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
111 parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass);
113 object_class->dispose = sp_flood_context_dispose;
115 event_context_class->setup = sp_flood_context_setup;
116 event_context_class->root_handler = sp_flood_context_root_handler;
117 event_context_class->item_handler = sp_flood_context_item_handler;
118 }
120 static void sp_flood_context_init(SPFloodContext *flood_context)
121 {
122 SPEventContext *event_context = SP_EVENT_CONTEXT(flood_context);
124 event_context->cursor_shape = cursor_paintbucket_xpm;
125 event_context->hot_x = 11;
126 event_context->hot_y = 30;
127 event_context->xp = 0;
128 event_context->yp = 0;
129 event_context->tolerance = 4;
130 event_context->within_tolerance = false;
131 event_context->item_to_select = NULL;
133 event_context->shape_repr = NULL;
134 event_context->shape_knot_holder = NULL;
136 flood_context->item = NULL;
138 new (&flood_context->sel_changed_connection) sigc::connection();
139 }
141 static void sp_flood_context_dispose(GObject *object)
142 {
143 SPFloodContext *rc = SP_FLOOD_CONTEXT(object);
144 SPEventContext *ec = SP_EVENT_CONTEXT(object);
146 rc->sel_changed_connection.disconnect();
147 rc->sel_changed_connection.~connection();
149 /* fixme: This is necessary because we do not grab */
150 if (rc->item) {
151 sp_flood_finish(rc);
152 }
154 if (ec->shape_repr) { // remove old listener
155 sp_repr_remove_listener_by_data(ec->shape_repr, ec);
156 Inkscape::GC::release(ec->shape_repr);
157 ec->shape_repr = 0;
158 }
160 if (rc->_message_context) {
161 delete rc->_message_context;
162 }
164 G_OBJECT_CLASS(parent_class)->dispose(object);
165 }
167 static Inkscape::XML::NodeEventVector ec_shape_repr_events = {
168 NULL, /* child_added */
169 NULL, /* child_removed */
170 ec_shape_event_attr_changed,
171 NULL, /* content_changed */
172 NULL /* order_changed */
173 };
175 /**
176 \brief Callback that processes the "changed" signal on the selection;
177 destroys old and creates new knotholder
178 */
179 void sp_flood_context_selection_changed(Inkscape::Selection *selection, gpointer data)
180 {
181 SPFloodContext *rc = SP_FLOOD_CONTEXT(data);
182 SPEventContext *ec = SP_EVENT_CONTEXT(rc);
184 if (ec->shape_repr) { // remove old listener
185 sp_repr_remove_listener_by_data(ec->shape_repr, ec);
186 Inkscape::GC::release(ec->shape_repr);
187 ec->shape_repr = 0;
188 }
190 SPItem *item = selection->singleItem();
191 if (item) {
192 Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
193 if (shape_repr) {
194 ec->shape_repr = shape_repr;
195 Inkscape::GC::anchor(shape_repr);
196 sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
197 }
198 }
199 }
201 static void sp_flood_context_setup(SPEventContext *ec)
202 {
203 SPFloodContext *rc = SP_FLOOD_CONTEXT(ec);
205 if (((SPEventContextClass *) parent_class)->setup) {
206 ((SPEventContextClass *) parent_class)->setup(ec);
207 }
209 SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
210 if (item) {
211 Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
212 if (shape_repr) {
213 ec->shape_repr = shape_repr;
214 Inkscape::GC::anchor(shape_repr);
215 sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
216 }
217 }
219 rc->sel_changed_connection.disconnect();
220 rc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
221 sigc::bind(sigc::ptr_fun(&sp_flood_context_selection_changed), (gpointer)rc)
222 );
224 rc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
226 if (prefs_get_int_attribute("tools.paintbucket", "selcue", 0) != 0) {
227 rc->enableSelectionCue();
228 }
229 }
231 /**
232 * \brief Merge a pixel with the background color.
233 * \param orig The pixel to merge with the background.
234 * \param bg The background color.
235 * \param base The pixel to merge the original and background into.
236 */
237 inline static void
238 merge_pixel_with_background (unsigned char *orig, unsigned char *bg,
239 unsigned char *base)
240 {
241 int precalc_bg_alpha = (255 * (255 - bg[3])) / 255;
243 for (int i = 0; i < 3; i++) {
244 base[i] = precalc_bg_alpha + (bg[i] * bg[3]) / 255;
245 base[i] = (base[i] * (255 - orig[3])) / 255 + (orig[i] * orig[3]) / 255;
246 }
247 }
249 /**
250 * \brief Get the pointer to a pixel in a pixel buffer.
251 * \param px The pixel buffer.
252 * \param x The X coordinate.
253 * \param y The Y coordinate.
254 * \param width The width of the pixel buffer.
255 */
256 inline unsigned char * get_pixel(guchar *px, int x, int y, int width) {
257 return px + (x + y * width) * 4;
258 }
260 inline unsigned char * get_trace_pixel(guchar *trace_px, int x, int y, int width) {
261 return trace_px + (x + y * width);
262 }
264 /**
265 * \brief Generate the list of trace channel selection entries.
266 */
267 GList * flood_channels_dropdown_items_list() {
268 GList *glist = NULL;
270 glist = g_list_append (glist, _("Visible Colors"));
271 glist = g_list_append (glist, _("Red"));
272 glist = g_list_append (glist, _("Green"));
273 glist = g_list_append (glist, _("Blue"));
274 glist = g_list_append (glist, _("Hue"));
275 glist = g_list_append (glist, _("Saturation"));
276 glist = g_list_append (glist, _("Lightness"));
277 glist = g_list_append (glist, _("Alpha"));
279 return glist;
280 }
282 /**
283 * \brief Generate the list of autogap selection entries.
284 */
285 GList * flood_autogap_dropdown_items_list() {
286 GList *glist = NULL;
288 glist = g_list_append (glist, _("None"));
289 glist = g_list_append (glist, _("Small"));
290 glist = g_list_append (glist, _("Medium"));
291 glist = g_list_append (glist, _("Large"));
293 return glist;
294 }
296 /**
297 * \brief Compare a pixel in a pixel buffer with another pixel to determine if a point should be included in the fill operation.
298 * \param check The pixel in the pixel buffer to check.
299 * \param orig The original selected pixel to use as the fill target color.
300 * \param merged_orig_pixel The original pixel merged with the background.
301 * \param dtc The desktop background color.
302 * \param threshold The fill threshold.
303 * \param method The fill method to use as defined in PaintBucketChannels.
304 */
305 static bool compare_pixels(unsigned char *check, unsigned char *orig, unsigned char *merged_orig_pixel, unsigned char *dtc, int threshold, PaintBucketChannels method) {
306 int diff = 0;
307 float hsl_check[3], hsl_orig[3];
309 if ((method == FLOOD_CHANNELS_H) ||
310 (method == FLOOD_CHANNELS_S) ||
311 (method == FLOOD_CHANNELS_L)) {
312 sp_color_rgb_to_hsl_floatv(hsl_check, check[0] / 255.0, check[1] / 255.0, check[2] / 255.0);
313 sp_color_rgb_to_hsl_floatv(hsl_orig, orig[0] / 255.0, orig[1] / 255.0, orig[2] / 255.0);
314 }
316 switch (method) {
317 case FLOOD_CHANNELS_ALPHA:
318 return ((int)abs(check[3] - orig[3]) <= threshold);
319 case FLOOD_CHANNELS_R:
320 return ((int)abs(check[0] - orig[0]) <= threshold);
321 case FLOOD_CHANNELS_G:
322 return ((int)abs(check[1] - orig[1]) <= threshold);
323 case FLOOD_CHANNELS_B:
324 return ((int)abs(check[2] - orig[2]) <= threshold);
325 case FLOOD_CHANNELS_RGB:
326 unsigned char merged_check[3];
328 merge_pixel_with_background(check, dtc, merged_check);
330 for (int i = 0; i < 3; i++) {
331 diff += (int)abs(merged_check[i] - merged_orig_pixel[i]);
332 }
333 return ((diff / 3) <= ((threshold * 3) / 4));
335 case FLOOD_CHANNELS_H:
336 return ((int)(fabs(hsl_check[0] - hsl_orig[0]) * 100.0) <= threshold);
337 case FLOOD_CHANNELS_S:
338 return ((int)(fabs(hsl_check[1] - hsl_orig[1]) * 100.0) <= threshold);
339 case FLOOD_CHANNELS_L:
340 return ((int)(fabs(hsl_check[2] - hsl_orig[2]) * 100.0) <= threshold);
341 }
343 return false;
344 }
346 enum {
347 PIXEL_CHECKED = 1,
348 PIXEL_QUEUED = 2,
349 PIXEL_PAINTABLE = 4,
350 PIXEL_NOT_PAINTABLE = 8,
351 PIXEL_COLORED = 16
352 };
354 static inline bool is_pixel_checked(unsigned char *t) { return (*t & PIXEL_CHECKED) == PIXEL_CHECKED; }
355 static inline bool is_pixel_queued(unsigned char *t) { return (*t & PIXEL_QUEUED) == PIXEL_QUEUED; }
356 static inline bool is_pixel_paintability_checked(unsigned char *t) {
357 return !((*t & PIXEL_PAINTABLE) == 0) && ((*t & PIXEL_NOT_PAINTABLE) == 0);
358 }
359 static inline bool is_pixel_paintable(unsigned char *t) { return (*t & PIXEL_PAINTABLE) == PIXEL_PAINTABLE; }
360 static inline bool is_pixel_colored(unsigned char *t) { return (*t & PIXEL_COLORED) == PIXEL_COLORED; }
362 static inline void mark_pixel_checked(unsigned char *t) { *t |= PIXEL_CHECKED; }
363 static inline void mark_pixel_unchecked(unsigned char *t) { *t ^= PIXEL_CHECKED; }
364 static inline void mark_pixel_queued(unsigned char *t) { *t |= PIXEL_QUEUED; }
365 static inline void mark_pixel_paintable(unsigned char *t) { *t |= PIXEL_PAINTABLE; *t ^= PIXEL_NOT_PAINTABLE; }
366 static inline void mark_pixel_not_paintable(unsigned char *t) { *t |= PIXEL_NOT_PAINTABLE; *t ^= PIXEL_PAINTABLE; }
367 static inline void mark_pixel_colored(unsigned char *t) { *t |= PIXEL_COLORED; }
369 static inline void clear_pixel_paintability(unsigned char *t) { *t ^= PIXEL_PAINTABLE; *t ^= PIXEL_NOT_PAINTABLE; }
371 struct bitmap_coords_info {
372 bool is_left;
373 unsigned int x;
374 unsigned int y;
375 int y_limit;
376 unsigned int width;
377 unsigned int height;
378 unsigned int threshold;
379 unsigned int radius;
380 PaintBucketChannels method;
381 unsigned char *dtc;
382 unsigned char *merged_orig_pixel;
383 NR::Rect bbox;
384 NR::Rect screen;
385 unsigned int max_queue_size;
386 unsigned int current_step;
387 };
389 /**
390 * \brief Check if a pixel can be included in the fill.
391 * \param px The rendered pixel buffer to check.
392 * \param trace_t The pixel in the trace pixel buffer to check or mark.
393 * \param x The X coordinate.
394 * \param y The y coordinate.
395 * \param orig_color The original selected pixel to use as the fill target color.
396 * \param bci The bitmap_coords_info structure.
397 */
398 inline static bool check_if_pixel_is_paintable(guchar *px, unsigned char *trace_t, int x, int y, unsigned char *orig_color, bitmap_coords_info bci) {
399 if (is_pixel_paintability_checked(trace_t)) {
400 return is_pixel_paintable(trace_t);
401 } else {
402 unsigned char *t = get_pixel(px, x, y, bci.width);
403 if (compare_pixels(t, orig_color, bci.merged_orig_pixel, bci.dtc, bci.threshold, bci.method)) {
404 mark_pixel_paintable(trace_t);
405 return true;
406 } else {
407 mark_pixel_not_paintable(trace_t);
408 return false;
409 }
410 }
411 }
413 /**
414 * \brief Perform the bitmap-to-vector tracing and place the traced path onto the document.
415 * \param px The trace pixel buffer to trace to SVG.
416 * \param desktop The desktop on which to place the final SVG path.
417 * \param transform The transform to apply to the final SVG path.
418 * \param union_with_selection If true, merge the final SVG path with the current selection.
419 */
420 static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *desktop, NR::Matrix transform, bool union_with_selection) {
421 SPDocument *document = sp_desktop_document(desktop);
423 unsigned char *trace_t;
425 GrayMap *gray_map = GrayMapCreate(bci.width, bci.height);
426 for (unsigned int y = 0; y < bci.height ; y++) {
427 unsigned long *gray_map_t = gray_map->rows[y];
429 trace_t = get_trace_pixel(trace_px, 0, y, bci.width);
430 for (unsigned int x = 0; x < bci.width ; x++) {
431 *gray_map_t = is_pixel_colored(trace_t) ? GRAYMAP_BLACK : GRAYMAP_WHITE;
432 gray_map_t++;
433 trace_t++;
434 }
435 }
437 Inkscape::Trace::Potrace::PotraceTracingEngine pte;
438 std::vector<Inkscape::Trace::TracingEngineResult> results = pte.traceGrayMap(gray_map);
439 gray_map->destroy(gray_map);
441 Inkscape::XML::Node *layer_repr = SP_GROUP(desktop->currentLayer())->repr;
442 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
444 long totalNodeCount = 0L;
446 double offset = prefs_get_double_attribute("tools.paintbucket", "offset", 0.0);
448 for (unsigned int i=0 ; i<results.size() ; i++) {
449 Inkscape::Trace::TracingEngineResult result = results[i];
450 totalNodeCount += result.getNodeCount();
452 Inkscape::XML::Node *pathRepr = xml_doc->createElement("svg:path");
453 /* Set style */
454 sp_desktop_apply_style_tool (desktop, pathRepr, "tools.paintbucket", false);
456 NArtBpath *bpath = sp_svg_read_path(result.getPathData().c_str());
457 Path *path = bpath_to_Path(bpath);
458 g_free(bpath);
460 if (offset != 0) {
462 Shape *path_shape = new Shape();
464 path->ConvertWithBackData(0.03);
465 path->Fill(path_shape, 0);
466 delete path;
468 Shape *expanded_path_shape = new Shape();
470 expanded_path_shape->ConvertToShape(path_shape, fill_nonZero);
471 path_shape->MakeOffset(expanded_path_shape, offset * desktop->current_zoom(), join_round, 4);
472 expanded_path_shape->ConvertToShape(path_shape, fill_positive);
474 Path *expanded_path = new Path();
476 expanded_path->Reset();
477 expanded_path_shape->ConvertToForme(expanded_path);
478 expanded_path->ConvertEvenLines(1.0);
479 expanded_path->Simplify(1.0);
481 delete path_shape;
482 delete expanded_path_shape;
484 gchar *str = expanded_path->svg_dump_path();
485 if (str && *str) {
486 pathRepr->setAttribute("d", str);
487 g_free(str);
488 } else {
489 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Too much inset</b>, the result is empty."));
490 Inkscape::GC::release(pathRepr);
491 g_free(str);
492 return;
493 }
495 delete expanded_path;
497 } else {
498 gchar *str = path->svg_dump_path();
499 delete path;
500 pathRepr->setAttribute("d", str);
501 g_free(str);
502 }
504 layer_repr->addChild(pathRepr, NULL);
506 SPObject *reprobj = document->getObjectByRepr(pathRepr);
507 if (reprobj) {
508 sp_item_write_transform(SP_ITEM(reprobj), pathRepr, transform, NULL);
510 // premultiply the item transform by the accumulated parent transform in the paste layer
511 NR::Matrix local = sp_item_i2doc_affine(SP_GROUP(desktop->currentLayer()));
512 if (!local.test_identity()) {
513 gchar const *t_str = pathRepr->attribute("transform");
514 NR::Matrix item_t (NR::identity());
515 if (t_str)
516 sp_svg_transform_read(t_str, &item_t);
517 item_t *= local.inverse();
518 // (we're dealing with unattached repr, so we write to its attr instead of using sp_item_set_transform)
519 gchar *affinestr=sp_svg_transform_write(item_t);
520 pathRepr->setAttribute("transform", affinestr);
521 g_free(affinestr);
522 }
524 Inkscape::Selection *selection = sp_desktop_selection(desktop);
526 pathRepr->setPosition(-1);
528 if (union_with_selection) {
529 desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, ngettext("Area filled, path with <b>%d</b> node created and unioned with selection.","Area filled, path with <b>%d</b> nodes created and unioned with selection.",sp_nodes_in_path(SP_PATH(reprobj))), sp_nodes_in_path(SP_PATH(reprobj)));
530 selection->add(reprobj);
531 sp_selected_path_union_skip_undo();
532 } else {
533 desktop->messageStack()->flashF(Inkscape::WARNING_MESSAGE, ngettext("Area filled, path with <b>%d</b> node created.","Area filled, path with <b>%d</b> nodes created.",sp_nodes_in_path(SP_PATH(reprobj))), sp_nodes_in_path(SP_PATH(reprobj)));
534 selection->set(reprobj);
535 }
537 }
539 Inkscape::GC::release(pathRepr);
541 }
542 }
544 /**
545 * \brief The possible return states of perform_bitmap_scanline_check()
546 */
547 enum ScanlineCheckResult {
548 SCANLINE_CHECK_OK,
549 SCANLINE_CHECK_ABORTED,
550 SCANLINE_CHECK_BOUNDARY
551 };
553 /**
554 * \brief Determine if the provided coordinates are within the pixel buffer limits.
555 * \param x The X coordinate.
556 * \param y The Y coordinate.
557 * \param bci The bitmap_coords_info structure.
558 */
559 inline static bool coords_in_range(unsigned int x, unsigned int y, bitmap_coords_info bci) {
560 return (x < bci.width) &&
561 (y < bci.height);
562 }
564 #define PAINT_DIRECTION_LEFT 1
565 #define PAINT_DIRECTION_RIGHT 2
566 #define PAINT_DIRECTION_UP 4
567 #define PAINT_DIRECTION_DOWN 8
568 #define PAINT_DIRECTION_ALL 15
570 /**
571 * \brief Paint a pixel or a square (if autogap is enabled) on the trace pixel buffer
572 * \param px The rendered pixel buffer to check.
573 * \param trace_px The trace pixel buffer.
574 * \param orig_color The original selected pixel to use as the fill target color.
575 * \param bci The bitmap_coords_info structure.
576 * \param original_point_trace_t The original pixel in the trace pixel buffer to check.
577 */
578 inline static unsigned int paint_pixel(guchar *px, guchar *trace_px, unsigned char *orig_color, bitmap_coords_info bci, unsigned char *original_point_trace_t) {
579 if (bci.radius == 0) {
580 mark_pixel_colored(original_point_trace_t);
581 return PAINT_DIRECTION_ALL;
582 } else {
583 unsigned char *trace_t;
585 bool can_paint_up = true;
586 bool can_paint_down = true;
587 bool can_paint_left = true;
588 bool can_paint_right = true;
590 for (unsigned int ty = bci.y - bci.radius; ty <= bci.y + bci.radius; ty++) {
591 for (unsigned int tx = bci.x - bci.radius; tx <= bci.x + bci.radius; tx++) {
592 if (coords_in_range(tx, ty, bci)) {
593 trace_t = get_trace_pixel(trace_px, tx, ty, bci.width);
594 if (!is_pixel_colored(trace_t)) {
595 if (check_if_pixel_is_paintable(px, trace_t, tx, ty, orig_color, bci)) {
596 mark_pixel_colored(trace_t);
597 } else {
598 if (tx < bci.x) { can_paint_left = false; }
599 if (tx > bci.x) { can_paint_right = false; }
600 if (ty < bci.y) { can_paint_up = false; }
601 if (ty > bci.y) { can_paint_down = false; }
602 }
603 }
604 }
605 }
606 }
608 unsigned int paint_directions = 0;
609 if (can_paint_left) { paint_directions += PAINT_DIRECTION_LEFT; }
610 if (can_paint_right) { paint_directions += PAINT_DIRECTION_RIGHT; }
611 if (can_paint_up) { paint_directions += PAINT_DIRECTION_UP; }
612 if (can_paint_down) { paint_directions += PAINT_DIRECTION_DOWN; }
614 return paint_directions;
615 }
616 }
618 /**
619 * \brief Push a point to be checked onto the bottom of the rendered pixel buffer check queue.
620 * \param fill_queue The fill queue to add the point to.
621 * \param max_queue_size The maximum size of the fill queue.
622 * \param trace_t The trace pixel buffer pixel.
623 * \param x The X coordinate.
624 * \param y The Y coordinate.
625 */
626 static void push_point_onto_queue(std::deque<NR::Point> *fill_queue, unsigned int max_queue_size, unsigned char *trace_t, unsigned int x, unsigned int y) {
627 if (!is_pixel_queued(trace_t)) {
628 if ((fill_queue->size() < max_queue_size)) {
629 fill_queue->push_back(NR::Point(x, y));
630 mark_pixel_queued(trace_t);
631 }
632 }
633 }
635 /**
636 * \brief Shift a point to be checked onto the top of the rendered pixel buffer check queue.
637 * \param fill_queue The fill queue to add the point to.
638 * \param max_queue_size The maximum size of the fill queue.
639 * \param trace_t The trace pixel buffer pixel.
640 * \param x The X coordinate.
641 * \param y The Y coordinate.
642 */
643 static void shift_point_onto_queue(std::deque<NR::Point> *fill_queue, unsigned int max_queue_size, unsigned char *trace_t, unsigned int x, unsigned int y) {
644 if (!is_pixel_queued(trace_t)) {
645 if ((fill_queue->size() < max_queue_size)) {
646 fill_queue->push_front(NR::Point(x, y));
647 mark_pixel_queued(trace_t);
648 }
649 }
650 }
652 /**
653 * \brief Scan a row in the rendered pixel buffer and add points to the fill queue as necessary.
654 * \param fill_queue The fill queue to add the point to.
655 * \param px The rendered pixel buffer.
656 * \param trace_px The trace pixel buffer.
657 * \param orig_color The original selected pixel to use as the fill target color.
658 * \param bci The bitmap_coords_info structure.
659 */
660 static ScanlineCheckResult perform_bitmap_scanline_check(std::deque<NR::Point> *fill_queue, guchar *px, guchar *trace_px, unsigned char *orig_color, bitmap_coords_info bci) {
661 bool aborted = false;
662 bool reached_screen_boundary = false;
663 bool ok;
665 bool keep_tracing;
666 bool initial_paint = true;
668 unsigned char *current_trace_t = get_trace_pixel(trace_px, bci.x, bci.y, bci.width);
669 unsigned int paint_directions;
671 bool currently_painting_top = false;
672 bool currently_painting_bottom = false;
674 unsigned int top_ty = bci.y - 1;
675 unsigned int bottom_ty = bci.y + 1;
677 bool can_paint_top = (top_ty > 0);
678 bool can_paint_bottom = (bottom_ty < bci.height);
680 NR::Point t = fill_queue->front();
682 do {
683 ok = false;
684 if (bci.is_left) {
685 keep_tracing = (bci.x != 0);
686 } else {
687 keep_tracing = (bci.x < bci.width);
688 }
690 if (keep_tracing) {
691 if (check_if_pixel_is_paintable(px, current_trace_t, bci.x, bci.y, orig_color, bci)) {
692 paint_directions = paint_pixel(px, trace_px, orig_color, bci, current_trace_t);
693 if (bci.radius == 0) {
694 mark_pixel_checked(current_trace_t);
695 if ((t[NR::X] == bci.x) && (t[NR::Y] == bci.y)) {
696 fill_queue->pop_front(); t = fill_queue->front();
697 }
698 }
700 if (can_paint_top) {
701 if (paint_directions & PAINT_DIRECTION_UP) {
702 unsigned char *trace_t = current_trace_t - bci.width;
703 if (!is_pixel_queued(trace_t)) {
704 bool ok_to_paint = check_if_pixel_is_paintable(px, trace_t, bci.x, top_ty, orig_color, bci);
706 if (initial_paint) { currently_painting_top = !ok_to_paint; }
708 if (ok_to_paint && (!currently_painting_top)) {
709 currently_painting_top = true;
710 push_point_onto_queue(fill_queue, bci.max_queue_size, trace_t, bci.x, top_ty);
711 }
712 if ((!ok_to_paint) && currently_painting_top) {
713 currently_painting_top = false;
714 }
715 }
716 }
717 }
719 if (can_paint_bottom) {
720 if (paint_directions & PAINT_DIRECTION_DOWN) {
721 unsigned char *trace_t = current_trace_t + bci.width;
722 if (!is_pixel_queued(trace_t)) {
723 bool ok_to_paint = check_if_pixel_is_paintable(px, trace_t, bci.x, bottom_ty, orig_color, bci);
725 if (initial_paint) { currently_painting_bottom = !ok_to_paint; }
727 if (ok_to_paint && (!currently_painting_bottom)) {
728 currently_painting_bottom = true;
729 push_point_onto_queue(fill_queue, bci.max_queue_size, trace_t, bci.x, bottom_ty);
730 }
731 if ((!ok_to_paint) && currently_painting_bottom) {
732 currently_painting_bottom = false;
733 }
734 }
735 }
736 }
738 if (bci.is_left) {
739 if (paint_directions & PAINT_DIRECTION_LEFT) {
740 bci.x--; current_trace_t--;
741 ok = true;
742 }
743 } else {
744 if (paint_directions & PAINT_DIRECTION_RIGHT) {
745 bci.x++; current_trace_t++;
746 ok = true;
747 }
748 }
750 initial_paint = false;
751 }
752 } else {
753 if (bci.bbox.min()[NR::X] > bci.screen.min()[NR::X]) {
754 aborted = true; break;
755 } else {
756 reached_screen_boundary = true;
757 }
758 }
759 } while (ok);
761 if (aborted) { return SCANLINE_CHECK_ABORTED; }
762 if (reached_screen_boundary) { return SCANLINE_CHECK_BOUNDARY; }
763 return SCANLINE_CHECK_OK;
764 }
766 /**
767 * \brief Sort the rendered pixel buffer check queue vertically.
768 */
769 static bool sort_fill_queue_vertical(NR::Point a, NR::Point b) {
770 return a[NR::Y] > b[NR::Y];
771 }
773 /**
774 * \brief Sort the rendered pixel buffer check queue horizontally.
775 */
776 static bool sort_fill_queue_horizontal(NR::Point a, NR::Point b) {
777 return a[NR::X] > b[NR::X];
778 }
780 /**
781 * \brief Perform a flood fill operation.
782 * \param event_context The event context for this tool.
783 * \param event The details of this event.
784 * \param union_with_selection If true, union the new fill with the current selection.
785 * \param is_point_fill If false, use the Rubberband "touch selection" to get the initial points for the fill.
786 * \param is_touch_fill If true, use only the initial contact point in the Rubberband "touch selection" as the fill target color.
787 */
788 static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *event, bool union_with_selection, bool is_point_fill, bool is_touch_fill) {
789 SPDesktop *desktop = event_context->desktop;
790 SPDocument *document = sp_desktop_document(desktop);
792 /* Create new arena */
793 NRArena *arena = NRArena::create();
794 unsigned dkey = sp_item_display_key_new(1);
796 sp_document_ensure_up_to_date (document);
798 SPItem *document_root = SP_ITEM(SP_DOCUMENT_ROOT(document));
799 NR::Maybe<NR::Rect> bbox = document_root->getBounds(NR::identity());
801 if (!bbox) {
802 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Area is not bounded</b>, cannot fill."));
803 return;
804 }
806 double zoom_scale = desktop->current_zoom();
808 // Render 160% of the physical display to the render pixel buffer, so that available
809 // fill areas off the screen can be included in the fill.
810 double padding = 1.6;
812 NR::Rect screen = desktop->get_display_area();
814 unsigned int width = (int)ceil(screen.extent(NR::X) * zoom_scale * padding);
815 unsigned int height = (int)ceil(screen.extent(NR::Y) * zoom_scale * padding);
817 NR::Point origin(screen.min()[NR::X],
818 sp_document_height(document) - screen.extent(NR::Y) - screen.min()[NR::Y]);
820 origin[NR::X] = origin[NR::X] + (screen.extent(NR::X) * ((1 - padding) / 2));
821 origin[NR::Y] = origin[NR::Y] + (screen.extent(NR::Y) * ((1 - padding) / 2));
823 NR::scale scale(zoom_scale, zoom_scale);
824 NR::Matrix affine = scale * NR::translate(-origin * scale);
826 /* Create ArenaItems and set transform */
827 NRArenaItem *root = sp_item_invoke_show(SP_ITEM(sp_document_root(document)), arena, dkey, SP_ITEM_SHOW_DISPLAY);
828 nr_arena_item_set_transform(NR_ARENA_ITEM(root), affine);
830 NRGC gc(NULL);
831 gc.transform.set_identity();
833 NRRectL final_bbox;
834 final_bbox.x0 = 0;
835 final_bbox.y0 = 0; //row;
836 final_bbox.x1 = width;
837 final_bbox.y1 = height; //row + num_rows;
839 nr_arena_item_invoke_update(root, &final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
841 guchar *px = g_new(guchar, 4 * width * height);
843 NRPixBlock B;
844 nr_pixblock_setup_extern( &B, NR_PIXBLOCK_MODE_R8G8B8A8N,
845 final_bbox.x0, final_bbox.y0, final_bbox.x1, final_bbox.y1,
846 px, 4 * width, FALSE, FALSE );
848 SPNamedView *nv = sp_desktop_namedview(desktop);
849 unsigned long bgcolor = nv->pagecolor;
851 unsigned char dtc[4];
852 dtc[0] = NR_RGBA32_R(bgcolor);
853 dtc[1] = NR_RGBA32_G(bgcolor);
854 dtc[2] = NR_RGBA32_B(bgcolor);
855 dtc[3] = NR_RGBA32_A(bgcolor);
857 for (unsigned int fy = 0; fy < height; fy++) {
858 guchar *p = NR_PIXBLOCK_PX(&B) + fy * B.rs;
859 for (unsigned int fx = 0; fx < width; fx++) {
860 for (int i = 0; i < 4; i++) {
861 *p++ = dtc[i];
862 }
863 }
864 }
866 nr_arena_item_invoke_render(NULL, root, &final_bbox, &B, NR_ARENA_ITEM_RENDER_NO_CACHE );
867 nr_pixblock_release(&B);
869 // Hide items
870 sp_item_invoke_hide(SP_ITEM(sp_document_root(document)), dkey);
872 nr_arena_item_unref(root);
873 nr_object_unref((NRObject *) arena);
875 guchar *trace_px = g_new(guchar, width * height);
876 memset(trace_px, 0x00, width * height);
878 std::deque<NR::Point> fill_queue;
879 std::queue<NR::Point> color_queue;
881 std::vector<NR::Point> fill_points;
883 bool aborted = false;
884 int y_limit = height - 1;
886 PaintBucketChannels method = (PaintBucketChannels)prefs_get_int_attribute("tools.paintbucket", "channels", 0);
887 int threshold = prefs_get_int_attribute_limited("tools.paintbucket", "threshold", 1, 0, 100);
889 switch(method) {
890 case FLOOD_CHANNELS_ALPHA:
891 case FLOOD_CHANNELS_RGB:
892 case FLOOD_CHANNELS_R:
893 case FLOOD_CHANNELS_G:
894 case FLOOD_CHANNELS_B:
895 threshold = (255 * threshold) / 100;
896 break;
897 case FLOOD_CHANNELS_H:
898 case FLOOD_CHANNELS_S:
899 case FLOOD_CHANNELS_L:
900 break;
901 }
903 bitmap_coords_info bci;
905 bci.y_limit = y_limit;
906 bci.width = width;
907 bci.height = height;
908 bci.threshold = threshold;
909 bci.method = method;
910 bci.bbox = *bbox;
911 bci.screen = screen;
912 bci.dtc = dtc;
913 bci.radius = prefs_get_int_attribute_limited("tools.paintbucket", "autogap", 0, 0, 3);
914 bci.max_queue_size = (width * height) / 4;
915 bci.current_step = 0;
917 if (is_point_fill) {
918 fill_points.push_back(NR::Point(event->button.x, event->button.y));
919 } else {
920 Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get();
921 fill_points = r->getPoints();
922 }
924 for (unsigned int i = 0; i < fill_points.size(); i++) {
925 NR::Point pw = NR::Point(fill_points[i][NR::X] / zoom_scale, sp_document_height(document) + (fill_points[i][NR::Y] / zoom_scale)) * affine;
927 pw[NR::X] = (int)MIN(width - 1, MAX(0, pw[NR::X]));
928 pw[NR::Y] = (int)MIN(height - 1, MAX(0, pw[NR::Y]));
930 if (is_touch_fill) {
931 if (i == 0) {
932 color_queue.push(pw);
933 } else {
934 unsigned char *trace_t = get_trace_pixel(trace_px, (int)pw[NR::X], (int)pw[NR::Y], width);
935 push_point_onto_queue(&fill_queue, bci.max_queue_size, trace_t, (int)pw[NR::X], (int)pw[NR::Y]);
936 }
937 } else {
938 color_queue.push(pw);
939 }
940 }
942 bool reached_screen_boundary = false;
944 bool first_run = true;
946 unsigned long sort_size_threshold = 5;
948 while (!color_queue.empty() && !aborted) {
949 NR::Point color_point = color_queue.front();
950 color_queue.pop();
952 int cx = (int)color_point[NR::X];
953 int cy = (int)color_point[NR::Y];
955 unsigned char *orig_px = get_pixel(px, cx, cy, width);
956 unsigned char orig_color[4];
957 for (int i = 0; i < 4; i++) { orig_color[i] = orig_px[i]; }
959 unsigned char merged_orig[3];
961 merge_pixel_with_background(orig_color, dtc, merged_orig);
963 bci.merged_orig_pixel = merged_orig;
965 unsigned char *trace_t = get_trace_pixel(trace_px, cx, cy, width);
966 if (!is_pixel_checked(trace_t) && !is_pixel_colored(trace_t)) {
967 if (check_if_pixel_is_paintable(px, trace_px, cx, cy, orig_color, bci)) {
968 shift_point_onto_queue(&fill_queue, bci.max_queue_size, trace_t, cx, cy);
970 if (!first_run) {
971 for (unsigned int y = 0; y < height; y++) {
972 trace_t = get_trace_pixel(trace_px, 0, y, width);
973 for (unsigned int x = 0; x < width; x++) {
974 clear_pixel_paintability(trace_t);
975 trace_t++;
976 }
977 }
978 }
979 first_run = false;
980 }
981 }
983 unsigned long old_fill_queue_size = fill_queue.size();
985 while (!fill_queue.empty() && !aborted) {
986 NR::Point cp = fill_queue.front();
988 if (bci.radius == 0) {
989 unsigned long new_fill_queue_size = fill_queue.size();
991 /*
992 * To reduce the number of points in the fill queue, periodically
993 * resort all of the points in the queue so that scanline checks
994 * can complete more quickly. A point cannot be checked twice
995 * in a normal scanline checks, so forcing scanline checks to start
996 * from one corner of the rendered area as often as possible
997 * will reduce the number of points that need to be checked and queued.
998 */
999 if (new_fill_queue_size > sort_size_threshold) {
1000 if (new_fill_queue_size > old_fill_queue_size) {
1001 std::sort(fill_queue.begin(), fill_queue.end(), sort_fill_queue_vertical);
1003 std::deque<NR::Point>::iterator start_sort = fill_queue.begin();
1004 std::deque<NR::Point>::iterator end_sort = fill_queue.begin();
1005 unsigned int sort_y = (unsigned int)cp[NR::Y];
1006 unsigned int current_y = sort_y;
1008 for (std::deque<NR::Point>::iterator i = fill_queue.begin(); i != fill_queue.end(); i++) {
1009 NR::Point current = *i;
1010 current_y = (unsigned int)current[NR::Y];
1011 if (current_y != sort_y) {
1012 if (start_sort != end_sort) {
1013 std::sort(start_sort, end_sort, sort_fill_queue_horizontal);
1014 }
1015 sort_y = current_y;
1016 start_sort = i;
1017 }
1018 end_sort = i;
1019 }
1020 if (start_sort != end_sort) {
1021 std::sort(start_sort, end_sort, sort_fill_queue_horizontal);
1022 }
1024 cp = fill_queue.front();
1025 }
1026 }
1028 old_fill_queue_size = new_fill_queue_size;
1029 }
1031 fill_queue.pop_front();
1033 int x = (int)cp[NR::X];
1034 int y = (int)cp[NR::Y];
1036 unsigned char *trace_t = get_trace_pixel(trace_px, x, y, width);
1037 if (!is_pixel_checked(trace_t)) {
1038 mark_pixel_checked(trace_t);
1040 if (y == 0) {
1041 if (bbox->min()[NR::Y] > screen.min()[NR::Y]) {
1042 aborted = true; break;
1043 } else {
1044 reached_screen_boundary = true;
1045 }
1046 }
1048 if (y == y_limit) {
1049 if (bbox->max()[NR::Y] < screen.max()[NR::Y]) {
1050 aborted = true; break;
1051 } else {
1052 reached_screen_boundary = true;
1053 }
1054 }
1056 bci.is_left = true;
1057 bci.x = x;
1058 bci.y = y;
1060 ScanlineCheckResult result = perform_bitmap_scanline_check(&fill_queue, px, trace_px, orig_color, bci);
1062 switch (result) {
1063 case SCANLINE_CHECK_ABORTED:
1064 aborted = true;
1065 break;
1066 case SCANLINE_CHECK_BOUNDARY:
1067 reached_screen_boundary = true;
1068 break;
1069 default:
1070 break;
1071 }
1073 if (bci.x < width) {
1074 trace_t++;
1075 if (!is_pixel_checked(trace_t) && !is_pixel_queued(trace_t)) {
1076 mark_pixel_checked(trace_t);
1077 bci.is_left = false;
1078 bci.x = x + 1;
1080 result = perform_bitmap_scanline_check(&fill_queue, px, trace_px, orig_color, bci);
1082 switch (result) {
1083 case SCANLINE_CHECK_ABORTED:
1084 aborted = true;
1085 break;
1086 case SCANLINE_CHECK_BOUNDARY:
1087 reached_screen_boundary = true;
1088 break;
1089 default:
1090 break;
1091 }
1092 }
1093 }
1094 }
1096 bci.current_step++;
1098 if (bci.current_step > bci.max_queue_size) {
1099 aborted = true;
1100 }
1101 }
1102 }
1104 g_free(px);
1106 if (aborted) {
1107 g_free(trace_px);
1108 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Area is not bounded</b>, cannot fill."));
1109 return;
1110 }
1112 if (reached_screen_boundary) {
1113 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Only the visible part of the bounded area was filled.</b> If you want to fill all of the area, undo, zoom out, and fill again."));
1114 }
1116 NR::Matrix inverted_affine = NR::Matrix(affine).inverse();
1118 do_trace(bci, trace_px, desktop, inverted_affine, union_with_selection);
1120 g_free(trace_px);
1122 sp_document_done(document, SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area"));
1123 }
1125 static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
1126 {
1127 gint ret = FALSE;
1129 SPDesktop *desktop = event_context->desktop;
1131 switch (event->type) {
1132 case GDK_BUTTON_PRESS:
1133 if ((event->button.state & GDK_CONTROL_MASK) && event->button.button == 1 && !event_context->space_panning) {
1134 NR::Point const button_w(event->button.x,
1135 event->button.y);
1137 SPItem *item = sp_event_context_find_item (desktop, button_w, TRUE, TRUE);
1139 Inkscape::XML::Node *pathRepr = SP_OBJECT_REPR(item);
1140 /* Set style */
1141 sp_desktop_apply_style_tool (desktop, pathRepr, "tools.paintbucket", false);
1142 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object"));
1143 ret = TRUE;
1144 }
1145 break;
1146 default:
1147 break;
1148 }
1150 if (((SPEventContextClass *) parent_class)->item_handler) {
1151 ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
1152 }
1154 return ret;
1155 }
1157 static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event)
1158 {
1159 static bool dragging;
1161 gint ret = FALSE;
1162 SPDesktop *desktop = event_context->desktop;
1164 switch (event->type) {
1165 case GDK_BUTTON_PRESS:
1166 if (event->button.button == 1 && !event_context->space_panning) {
1167 if (!(event->button.state & GDK_CONTROL_MASK)) {
1168 NR::Point const button_w(event->button.x,
1169 event->button.y);
1171 if (Inkscape::have_viable_layer(desktop, event_context->defaultMessageContext())) {
1172 // save drag origin
1173 event_context->xp = (gint) button_w[NR::X];
1174 event_context->yp = (gint) button_w[NR::Y];
1175 event_context->within_tolerance = true;
1177 dragging = true;
1179 NR::Point const p(desktop->w2d(button_w));
1180 Inkscape::Rubberband::get()->setMode(RUBBERBAND_MODE_TOUCHPATH);
1181 Inkscape::Rubberband::get()->start(desktop, p);
1182 }
1183 }
1184 }
1185 case GDK_MOTION_NOTIFY:
1186 if ( dragging
1187 && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning)
1188 {
1189 if ( event_context->within_tolerance
1190 && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
1191 && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
1192 break; // do not drag if we're within tolerance from origin
1193 }
1195 event_context->within_tolerance = false;
1197 NR::Point const motion_pt(event->motion.x, event->motion.y);
1198 NR::Point const p(desktop->w2d(motion_pt));
1199 if (Inkscape::Rubberband::get()->is_started()) {
1200 Inkscape::Rubberband::get()->move(p);
1201 event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> areas to add to fill, hold <b>Alt</b> for touch fill"));
1202 gobble_motion_events(GDK_BUTTON1_MASK);
1203 }
1204 }
1205 break;
1207 case GDK_BUTTON_RELEASE:
1208 if (event->button.button == 1 && !event_context->space_panning) {
1209 Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get();
1210 if (r->is_started()) {
1211 // set "busy" cursor
1212 desktop->setWaitingCursor();
1214 if (SP_IS_EVENT_CONTEXT(event_context)) {
1215 // Since setWaitingCursor runs main loop iterations, we may have already left this tool!
1216 // So check if the tool is valid before doing anything
1217 dragging = false;
1219 bool is_point_fill = event_context->within_tolerance;
1220 bool is_touch_fill = event->button.state & GDK_MOD1_MASK;
1222 sp_flood_do_flood_fill(event_context, event, event->button.state & GDK_SHIFT_MASK, is_point_fill, is_touch_fill);
1224 desktop->clearWaitingCursor();
1225 // restore cursor when done; note that it may already be different if e.g. user
1226 // switched to another tool during interruptible tracing or drawing, in which case do nothing
1228 ret = TRUE;
1229 }
1231 r->stop();
1233 if (SP_IS_EVENT_CONTEXT(event_context)) {
1234 event_context->defaultMessageContext()->clear();
1235 }
1236 }
1237 }
1238 break;
1239 case GDK_KEY_PRESS:
1240 switch (get_group0_keyval (&event->key)) {
1241 case GDK_Up:
1242 case GDK_Down:
1243 case GDK_KP_Up:
1244 case GDK_KP_Down:
1245 // prevent the zoom field from activation
1246 if (!MOD__CTRL_ONLY)
1247 ret = TRUE;
1248 break;
1249 default:
1250 break;
1251 }
1252 break;
1253 default:
1254 break;
1255 }
1257 if (!ret) {
1258 if (((SPEventContextClass *) parent_class)->root_handler) {
1259 ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
1260 }
1261 }
1263 return ret;
1264 }
1267 static void sp_flood_finish(SPFloodContext *rc)
1268 {
1269 rc->_message_context->clear();
1271 if ( rc->item != NULL ) {
1272 SPDesktop * desktop;
1274 desktop = SP_EVENT_CONTEXT_DESKTOP(rc);
1276 SP_OBJECT(rc->item)->updateRepr();
1278 sp_canvas_end_forced_full_redraws(desktop->canvas);
1280 sp_desktop_selection(desktop)->set(rc->item);
1281 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET,
1282 _("Fill bounded area"));
1284 rc->item = NULL;
1285 }
1286 }
1288 void flood_channels_set_channels( gint channels )
1289 {
1290 prefs_set_int_attribute("tools.paintbucket", "channels", channels);
1291 }
1293 /*
1294 Local Variables:
1295 mode:c++
1296 c-file-style:"stroustrup"
1297 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1298 indent-tabs-mode:nil
1299 fill-column:99
1300 End:
1301 */
1302 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :