Code

noop: address ‘no newline at end of file’ warning
[inkscape.git] / src / flood-context.cpp
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;
106 static void sp_flood_context_class_init(SPFloodContextClass *klass)
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;
120 static void sp_flood_context_init(SPFloodContext *flood_context)
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();
141 static void sp_flood_context_dispose(GObject *object)
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);
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)
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     }
201 static void sp_flood_context_setup(SPEventContext *ec)
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     }
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)
241     int precalc_bg_alpha = (255 * (255 - bg[3])) / 255;
242     
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     }
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;
260 /**
261  * \brief Generate the list of trace channel selection entries.
262  */
263 GList * flood_channels_dropdown_items_list() {
264     GList *glist = NULL;
266     glist = g_list_append (glist, _("Visible Colors"));
267     glist = g_list_append (glist, _("Red"));
268     glist = g_list_append (glist, _("Green"));
269     glist = g_list_append (glist, _("Blue"));
270     glist = g_list_append (glist, _("Hue"));
271     glist = g_list_append (glist, _("Saturation"));
272     glist = g_list_append (glist, _("Lightness"));
273     glist = g_list_append (glist, _("Alpha"));
275     return glist;
278 /**
279  * \brief Generate the list of autogap selection entries.
280  */
281 GList * flood_autogap_dropdown_items_list() {
282     GList *glist = NULL;
284     glist = g_list_append (glist, _("None"));
285     glist = g_list_append (glist, _("Small"));
286     glist = g_list_append (glist, _("Medium"));
287     glist = g_list_append (glist, _("Large"));
289     return glist;
292 /**
293  * \brief Compare a pixel in a pixel buffer with another pixel to determine if a point should be included in the fill operation.
294  * \param check The pixel in the pixel buffer to check.
295  * \param orig The original selected pixel to use as the fill target color.
296  * \param merged_orig_pixel The original pixel merged with the background.
297  * \param dtc The desktop background color.
298  * \param threshold The fill threshold.
299  * \param method The fill method to use as defined in PaintBucketChannels.
300  */
301 static bool compare_pixels(unsigned char *check, unsigned char *orig, unsigned char *merged_orig_pixel, unsigned char *dtc, int threshold, PaintBucketChannels method) {
302     int diff = 0;
303     float hsl_check[3], hsl_orig[3];
304     
305     if ((method == FLOOD_CHANNELS_H) ||
306         (method == FLOOD_CHANNELS_S) ||
307         (method == FLOOD_CHANNELS_L)) {
308         sp_color_rgb_to_hsl_floatv(hsl_check, check[0] / 255.0, check[1] / 255.0, check[2] / 255.0);
309         sp_color_rgb_to_hsl_floatv(hsl_orig, orig[0] / 255.0, orig[1] / 255.0, orig[2] / 255.0);
310     }
311     
312     switch (method) {
313         case FLOOD_CHANNELS_ALPHA:
314             return ((int)abs(check[3] - orig[3]) <= threshold);
315         case FLOOD_CHANNELS_R:
316             return ((int)abs(check[0] - orig[0]) <= threshold);
317         case FLOOD_CHANNELS_G:
318             return ((int)abs(check[1] - orig[1]) <= threshold);
319         case FLOOD_CHANNELS_B:
320             return ((int)abs(check[2] - orig[2]) <= threshold);
321         case FLOOD_CHANNELS_RGB:
322             unsigned char merged_check[3];
323             
324             merge_pixel_with_background(check, dtc, merged_check);
325             
326             for (int i = 0; i < 3; i++) {
327               diff += (int)abs(merged_check[i] - merged_orig_pixel[i]);
328             }
329             return ((diff / 3) <= ((threshold * 3) / 4));
330         
331         case FLOOD_CHANNELS_H:
332             return ((int)(fabs(hsl_check[0] - hsl_orig[0]) * 100.0) <= threshold);
333         case FLOOD_CHANNELS_S:
334             return ((int)(fabs(hsl_check[1] - hsl_orig[1]) * 100.0) <= threshold);
335         case FLOOD_CHANNELS_L:
336             return ((int)(fabs(hsl_check[2] - hsl_orig[2]) * 100.0) <= threshold);
337     }
338     
339     return false;
342 static inline bool is_pixel_checked(unsigned char *t) { return t[0] == 1; }
343 static inline bool is_pixel_queued(unsigned char *t) { return t[1] == 1; }
344 static inline bool is_pixel_paintability_checked(unsigned char *t) { return t[2] != 0; }
345 static inline bool is_pixel_paintable(unsigned char *t) { return t[2] == 1; }
346 static inline bool is_pixel_colored(unsigned char *t) { return t[3] == 255; }
348 static inline void mark_pixel_checked(unsigned char *t) { t[0] = 1; }
349 static inline void mark_pixel_unchecked(unsigned char *t) { t[0] = 0; }
350 static inline void mark_pixel_queued(unsigned char *t) { t[1] = 1; }
351 static inline void mark_pixel_paintable(unsigned char *t) { t[2] = 1; }
352 static inline void mark_pixel_not_paintable(unsigned char *t) { t[2] = 2; }
353 static inline void mark_pixel_colored(unsigned char *t) { t[3] = 255; }
355 static inline void clear_pixel_paintability(unsigned char *t) { t[2] = 0; }
357 struct bitmap_coords_info {
358     bool is_left;
359     unsigned int x;
360     unsigned int y;
361     int y_limit;
362     unsigned int width;
363     unsigned int height;
364     unsigned int threshold;
365     unsigned int radius;
366     PaintBucketChannels method;
367     unsigned char *dtc;
368     unsigned char *merged_orig_pixel;
369     NR::Rect bbox;
370     NR::Rect screen;
371     unsigned int max_queue_size;
372     unsigned int current_step;
373 };
375 /**
376  * \brief Check if a pixel can be included in the fill.
377  * \param px The rendered pixel buffer to check.
378  * \param trace_t The pixel in the trace pixel buffer to check or mark.
379  * \param x The X coordinate.
380  * \param y The y coordinate.
381  * \param orig_color The original selected pixel to use as the fill target color.
382  * \param bci The bitmap_coords_info structure.
383  */
384 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) {
385     if (is_pixel_paintability_checked(trace_t)) {
386         return is_pixel_paintable(trace_t);
387     } else {
388         unsigned char *t = get_pixel(px, x, y, bci.width);
389         if (compare_pixels(t, orig_color, bci.merged_orig_pixel, bci.dtc, bci.threshold, bci.method)) {
390             mark_pixel_paintable(trace_t);
391             return true;
392         } else {
393             mark_pixel_not_paintable(trace_t);
394             return false;
395         }
396     }
399 /**
400  * \brief Perform the bitmap-to-vector tracing and place the traced path onto the document.
401  * \param px The trace pixel buffer to trace to SVG.
402  * \param desktop The desktop on which to place the final SVG path.
403  * \param transform The transform to apply to the final SVG path.
404  * \param union_with_selection If true, merge the final SVG path with the current selection.
405  */
406 static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *desktop, NR::Matrix transform, bool union_with_selection) {
407     SPDocument *document = sp_desktop_document(desktop);
409     unsigned char *trace_t;
411     GrayMap *gray_map = GrayMapCreate(bci.width, bci.height);
412     for (unsigned int y = 0; y < bci.height ; y++) {
413         unsigned long *gray_map_t = gray_map->rows[y];
415         trace_t = get_pixel(trace_px, 0, y, bci.width);
416         for (unsigned int x = 0; x < bci.width ; x++) {
417             *gray_map_t = is_pixel_colored(trace_t) ? GRAYMAP_BLACK : GRAYMAP_WHITE;
418             gray_map_t++;
419             trace_t += 4;
420         }
421     }
423     Inkscape::Trace::Potrace::PotraceTracingEngine pte;
424     std::vector<Inkscape::Trace::TracingEngineResult> results = pte.traceGrayMap(gray_map);
425     gray_map->destroy(gray_map);
427     Inkscape::XML::Node *layer_repr = SP_GROUP(desktop->currentLayer())->repr;
428     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
430     long totalNodeCount = 0L;
432     double offset = prefs_get_double_attribute("tools.paintbucket", "offset", 0.0);
434     for (unsigned int i=0 ; i<results.size() ; i++) {
435         Inkscape::Trace::TracingEngineResult result = results[i];
436         totalNodeCount += result.getNodeCount();
438         Inkscape::XML::Node *pathRepr = xml_doc->createElement("svg:path");
439         /* Set style */
440         sp_desktop_apply_style_tool (desktop, pathRepr, "tools.paintbucket", false);
442         NArtBpath *bpath = sp_svg_read_path(result.getPathData().c_str());
443         Path *path = bpath_to_Path(bpath);
444         g_free(bpath);
446         if (offset != 0) {
447         
448             Shape *path_shape = new Shape();
449         
450             path->ConvertWithBackData(0.03);
451             path->Fill(path_shape, 0);
452             delete path;
453         
454             Shape *expanded_path_shape = new Shape();
455         
456             expanded_path_shape->ConvertToShape(path_shape, fill_nonZero);
457             path_shape->MakeOffset(expanded_path_shape, offset * desktop->current_zoom(), join_round, 4);
458             expanded_path_shape->ConvertToShape(path_shape, fill_positive);
460             Path *expanded_path = new Path();
461         
462             expanded_path->Reset();
463             expanded_path_shape->ConvertToForme(expanded_path);
464             expanded_path->ConvertEvenLines(1.0);
465             expanded_path->Simplify(1.0);
466         
467             delete path_shape;
468             delete expanded_path_shape;
469         
470             gchar *str = expanded_path->svg_dump_path();
471             if (str && *str) {
472                 pathRepr->setAttribute("d", str);
473                 g_free(str);
474             } else {
475                 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Too much inset</b>, the result is empty."));
476                 Inkscape::GC::release(pathRepr);
477                 g_free(str);
478                 return;
479             }
481             delete expanded_path;
483         } else {
484             gchar *str = path->svg_dump_path();
485             delete path;
486             pathRepr->setAttribute("d", str);
487             g_free(str);
488         }
490         layer_repr->addChild(pathRepr, NULL);
492         SPObject *reprobj = document->getObjectByRepr(pathRepr);
493         if (reprobj) {
494             sp_item_write_transform(SP_ITEM(reprobj), pathRepr, transform, NULL);
495             
496             // premultiply the item transform by the accumulated parent transform in the paste layer
497             NR::Matrix local = sp_item_i2doc_affine(SP_GROUP(desktop->currentLayer()));
498             if (!local.test_identity()) {
499                 gchar const *t_str = pathRepr->attribute("transform");
500                 NR::Matrix item_t (NR::identity());
501                 if (t_str)
502                     sp_svg_transform_read(t_str, &item_t);
503                 item_t *= local.inverse();
504                 // (we're dealing with unattached repr, so we write to its attr instead of using sp_item_set_transform)
505                 gchar *affinestr=sp_svg_transform_write(item_t);
506                 pathRepr->setAttribute("transform", affinestr);
507                 g_free(affinestr);
508             }
510             Inkscape::Selection *selection = sp_desktop_selection(desktop);
512             pathRepr->setPosition(-1);
514             if (union_with_selection) {
515                 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)));
516                 selection->add(reprobj);
517                 sp_selected_path_union_skip_undo();
518             } else {
519                 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)));
520                 selection->set(reprobj);
521             }
523         }
525         Inkscape::GC::release(pathRepr);
527     }
530 /**
531  * \brief The possible return states of perform_bitmap_scanline_check()
532  */
533 enum ScanlineCheckResult {
534     SCANLINE_CHECK_OK,
535     SCANLINE_CHECK_ABORTED,
536     SCANLINE_CHECK_BOUNDARY
537 };
539 /**
540  * \brief Determine if the provided coordinates are within the pixel buffer limits.
541  * \param x The X coordinate.
542  * \param y The Y coordinate.
543  * \param bci The bitmap_coords_info structure.
544  */
545 inline static bool coords_in_range(unsigned int x, unsigned int y, bitmap_coords_info bci) {
546     return (x < bci.width) &&
547            (y < bci.height);
550 #define PAINT_DIRECTION_LEFT 1
551 #define PAINT_DIRECTION_RIGHT 2
552 #define PAINT_DIRECTION_UP 4
553 #define PAINT_DIRECTION_DOWN 8
554 #define PAINT_DIRECTION_ALL 15
556 /**
557  * \brief Paint a pixel or a square (if autogap is enabled) on the trace pixel buffer
558  * \param px The rendered pixel buffer to check.
559  * \param trace_px The trace pixel buffer.
560  * \param orig_color The original selected pixel to use as the fill target color.
561  * \param bci The bitmap_coords_info structure.
562  * \param original_point_trace_t The original pixel in the trace pixel buffer to check.
563  */
564 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) {
565     if (bci.radius == 0) {
566         mark_pixel_colored(original_point_trace_t); 
567         return PAINT_DIRECTION_ALL;
568     } else {
569         unsigned char *trace_t;
570   
571         bool can_paint_up = true;
572         bool can_paint_down = true;
573         bool can_paint_left = true;
574         bool can_paint_right = true;
575       
576         for (unsigned int ty = bci.y - bci.radius; ty <= bci.y + bci.radius; ty++) {
577             for (unsigned int tx = bci.x - bci.radius; tx <= bci.x + bci.radius; tx++) {
578                 if (coords_in_range(tx, ty, bci)) {
579                     trace_t = get_pixel(trace_px, tx, ty, bci.width);
580                     if (!is_pixel_colored(trace_t)) {
581                         if (check_if_pixel_is_paintable(px, trace_t, tx, ty, orig_color, bci)) {
582                             mark_pixel_colored(trace_t); 
583                         } else {
584                             if (tx < bci.x) { can_paint_left = false; }
585                             if (tx > bci.x) { can_paint_right = false; }
586                             if (ty < bci.y) { can_paint_up = false; }
587                             if (ty > bci.y) { can_paint_down = false; }
588                         }
589                     }
590                 }
591             }
592         }
593     
594         unsigned int paint_directions = 0;
595         if (can_paint_left) { paint_directions += PAINT_DIRECTION_LEFT; }
596         if (can_paint_right) { paint_directions += PAINT_DIRECTION_RIGHT; }
597         if (can_paint_up) { paint_directions += PAINT_DIRECTION_UP; }
598         if (can_paint_down) { paint_directions += PAINT_DIRECTION_DOWN; }
599         
600         return paint_directions;
601     }
604 /**
605  * \brief Push a point to be checked onto the bottom of the rendered pixel buffer check queue.
606  * \param fill_queue The fill queue to add the point to.
607  * \param max_queue_size The maximum size of the fill queue.
608  * \param trace_t The trace pixel buffer pixel.
609  * \param x The X coordinate.
610  * \param y The Y coordinate.
611  */
612 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) {
613     if (!is_pixel_queued(trace_t)) {
614         if ((fill_queue->size() < max_queue_size)) {
615             fill_queue->push_back(NR::Point(x, y));
616             mark_pixel_queued(trace_t);
617         }
618     }
621 /**
622  * \brief Shift a point to be checked onto the top of the rendered pixel buffer check queue.
623  * \param fill_queue The fill queue to add the point to.
624  * \param max_queue_size The maximum size of the fill queue.
625  * \param trace_t The trace pixel buffer pixel.
626  * \param x The X coordinate.
627  * \param y The Y coordinate.
628  */
629 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) {
630     if (!is_pixel_queued(trace_t)) {
631         if ((fill_queue->size() < max_queue_size)) {
632             fill_queue->push_front(NR::Point(x, y));
633             mark_pixel_queued(trace_t);
634         }
635     }
638 /**
639  * \brief Scan a row in the rendered pixel buffer and add points to the fill queue as necessary.
640  * \param fill_queue The fill queue to add the point to.
641  * \param px The rendered pixel buffer.
642  * \param trace_px The trace pixel buffer.
643  * \param orig_color The original selected pixel to use as the fill target color.
644  * \param bci The bitmap_coords_info structure.
645  */
646 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) {
647     bool aborted = false;
648     bool reached_screen_boundary = false;
649     bool ok;
651     bool keep_tracing;
652     bool initial_paint = true;
654     unsigned char *current_trace_t = get_pixel(trace_px, bci.x, bci.y, bci.width);
655     unsigned int paint_directions;
657     bool currently_painting_top = false;
658     bool currently_painting_bottom = false;
660     unsigned int pix_width = bci.width * 4;
662     unsigned int top_ty = bci.y - 1;
663     unsigned int bottom_ty = bci.y + 1;
665     bool can_paint_top = (top_ty > 0);
666     bool can_paint_bottom = (bottom_ty < bci.height);
668     NR::Point t = fill_queue->front();
670     do {
671         ok = false;
672         if (bci.is_left) {
673             keep_tracing = (bci.x != 0);
674         } else {
675             keep_tracing = (bci.x < bci.width);
676         }
678         if (keep_tracing) {
679             if (check_if_pixel_is_paintable(px, current_trace_t, bci.x, bci.y, orig_color, bci)) {
680                 paint_directions = paint_pixel(px, trace_px, orig_color, bci, current_trace_t);
681                 if (bci.radius == 0) {
682                     mark_pixel_checked(current_trace_t);
683                     if ((t[NR::X] == bci.x) && (t[NR::Y] == bci.y)) {
684                         fill_queue->pop_front(); t = fill_queue->front();
685                     }
686                 }
688                 if (can_paint_top) {
689                     if (paint_directions & PAINT_DIRECTION_UP) { 
690                         unsigned char *trace_t = current_trace_t - pix_width;
691                         if (!is_pixel_queued(trace_t)) {
692                             bool ok_to_paint = check_if_pixel_is_paintable(px, trace_t, bci.x, top_ty, orig_color, bci);
694                             if (initial_paint) { currently_painting_top = !ok_to_paint; }
696                             if (ok_to_paint && (!currently_painting_top)) {
697                                 currently_painting_top = true;
698                                 push_point_onto_queue(fill_queue, bci.max_queue_size, trace_t, bci.x, top_ty);
699                             }
700                             if ((!ok_to_paint) && currently_painting_top) {
701                                 currently_painting_top = false;
702                             }
703                         }
704                     }
705                 }
707                 if (can_paint_bottom) {
708                     if (paint_directions & PAINT_DIRECTION_DOWN) { 
709                         unsigned char *trace_t = current_trace_t + pix_width;
710                         if (!is_pixel_queued(trace_t)) {
711                             bool ok_to_paint = check_if_pixel_is_paintable(px, trace_t, bci.x, bottom_ty, orig_color, bci);
713                             if (initial_paint) { currently_painting_bottom = !ok_to_paint; }
715                             if (ok_to_paint && (!currently_painting_bottom)) {
716                                 currently_painting_bottom = true;
717                                 push_point_onto_queue(fill_queue, bci.max_queue_size, trace_t, bci.x, bottom_ty);
718                             }
719                             if ((!ok_to_paint) && currently_painting_bottom) {
720                                 currently_painting_bottom = false;
721                             }
722                         }
723                     }
724                 }
726                 if (bci.is_left) {
727                     if (paint_directions & PAINT_DIRECTION_LEFT) {
728                         bci.x -= 1; current_trace_t -= 4;
729                         ok = true;
730                     }
731                 } else {
732                     if (paint_directions & PAINT_DIRECTION_RIGHT) {
733                         bci.x += 1; current_trace_t += 4;
734                         ok = true;
735                     }
736                 }
738                 initial_paint = false;
739             }
740         } else {
741             if (bci.bbox.min()[NR::X] > bci.screen.min()[NR::X]) {
742                 aborted = true; break;
743             } else {
744                 reached_screen_boundary = true;
745             }
746         }
747     } while (ok);
749     if (aborted) { return SCANLINE_CHECK_ABORTED; }
750     if (reached_screen_boundary) { return SCANLINE_CHECK_BOUNDARY; }
751     return SCANLINE_CHECK_OK;
754 /**
755  * \brief Sort the rendered pixel buffer check queue vertically.
756  */
757 static bool sort_fill_queue_vertical(NR::Point a, NR::Point b) {
758     return a[NR::Y] > b[NR::Y];
761 /**
762  * \brief Sort the rendered pixel buffer check queue horizontally.
763  */
764 static bool sort_fill_queue_horizontal(NR::Point a, NR::Point b) {
765     return a[NR::X] > b[NR::X];
768 /**
769  * \brief Perform a flood fill operation.
770  * \param event_context The event context for this tool.
771  * \param event The details of this event.
772  * \param union_with_selection If true, union the new fill with the current selection.
773  * \param is_point_fill If false, use the Rubberband "touch selection" to get the initial points for the fill.
774  * \param is_touch_fill If true, use only the initial contact point in the Rubberband "touch selection" as the fill target color.
775  */
776 static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *event, bool union_with_selection, bool is_point_fill, bool is_touch_fill) {
777     SPDesktop *desktop = event_context->desktop;
778     SPDocument *document = sp_desktop_document(desktop);
780     /* Create new arena */
781     NRArena *arena = NRArena::create();
782     unsigned dkey = sp_item_display_key_new(1);
784     sp_document_ensure_up_to_date (document);
785     
786     SPItem *document_root = SP_ITEM(SP_DOCUMENT_ROOT(document));
787     NR::Maybe<NR::Rect> bbox = document_root->getBounds(NR::identity());
789     if (!bbox) {
790         desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Area is not bounded</b>, cannot fill."));
791         return;
792     }
793     
794     double zoom_scale = desktop->current_zoom();
795     
796     // Render 160% of the physical display to the render pixel buffer, so that available
797     // fill areas off the screen can be included in the fill.
798     double padding = 1.6;
800     NR::Rect screen = desktop->get_display_area();
802     unsigned int width = (int)ceil(screen.extent(NR::X) * zoom_scale * padding);
803     unsigned int height = (int)ceil(screen.extent(NR::Y) * zoom_scale * padding);
805     NR::Point origin(screen.min()[NR::X],
806                      sp_document_height(document) - screen.extent(NR::Y) - screen.min()[NR::Y]);
807                     
808     origin[NR::X] = origin[NR::X] + (screen.extent(NR::X) * ((1 - padding) / 2));
809     origin[NR::Y] = origin[NR::Y] + (screen.extent(NR::Y) * ((1 - padding) / 2));
810     
811     NR::scale scale(zoom_scale, zoom_scale);
812     NR::Matrix affine = scale * NR::translate(-origin * scale);
813     
814     /* Create ArenaItems and set transform */
815     NRArenaItem *root = sp_item_invoke_show(SP_ITEM(sp_document_root(document)), arena, dkey, SP_ITEM_SHOW_DISPLAY);
816     nr_arena_item_set_transform(NR_ARENA_ITEM(root), affine);
818     NRGC gc(NULL);
819     gc.transform.set_identity();
820     
821     NRRectL final_bbox;
822     final_bbox.x0 = 0;
823     final_bbox.y0 = 0; //row;
824     final_bbox.x1 = width;
825     final_bbox.y1 = height; //row + num_rows;
826     
827     nr_arena_item_invoke_update(root, &final_bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
829     guchar *px = g_new(guchar, 4 * width * height);
830     
831     NRPixBlock B;
832     nr_pixblock_setup_extern( &B, NR_PIXBLOCK_MODE_R8G8B8A8N,
833                               final_bbox.x0, final_bbox.y0, final_bbox.x1, final_bbox.y1,
834                               px, 4 * width, FALSE, FALSE );
835     
836     SPNamedView *nv = sp_desktop_namedview(desktop);
837     unsigned long bgcolor = nv->pagecolor;
838     
839     unsigned char dtc[4];
840     dtc[0] = NR_RGBA32_R(bgcolor);
841     dtc[1] = NR_RGBA32_G(bgcolor);
842     dtc[2] = NR_RGBA32_B(bgcolor);
843     dtc[3] = NR_RGBA32_A(bgcolor);
844     
845     for (unsigned int fy = 0; fy < height; fy++) {
846         guchar *p = NR_PIXBLOCK_PX(&B) + fy * B.rs;
847         for (unsigned int fx = 0; fx < width; fx++) {
848             for (int i = 0; i < 4; i++) { 
849                 *p++ = dtc[i];
850             }
851         }
852     }
854     nr_arena_item_invoke_render(NULL, root, &final_bbox, &B, NR_ARENA_ITEM_RENDER_NO_CACHE );
855     nr_pixblock_release(&B);
856     
857     // Hide items
858     sp_item_invoke_hide(SP_ITEM(sp_document_root(document)), dkey);
859     
860     nr_arena_item_unref(root);
861     nr_object_unref((NRObject *) arena);
862     
863     guchar *trace_px = g_new(guchar, 4 * width * height);
864     memset(trace_px, 0x00, 4 * width * height);
865     
866     std::deque<NR::Point> fill_queue;
867     std::queue<NR::Point> color_queue;
868     
869     std::vector<NR::Point> fill_points;
870     
871     bool aborted = false;
872     int y_limit = height - 1;
874     PaintBucketChannels method = (PaintBucketChannels)prefs_get_int_attribute("tools.paintbucket", "channels", 0);
875     int threshold = prefs_get_int_attribute_limited("tools.paintbucket", "threshold", 1, 0, 100);
877     switch(method) {
878         case FLOOD_CHANNELS_ALPHA:
879         case FLOOD_CHANNELS_RGB:
880         case FLOOD_CHANNELS_R:
881         case FLOOD_CHANNELS_G:
882         case FLOOD_CHANNELS_B:
883             threshold = (255 * threshold) / 100;
884             break;
885         case FLOOD_CHANNELS_H:
886         case FLOOD_CHANNELS_S:
887         case FLOOD_CHANNELS_L:
888             break;
889     }
891     bitmap_coords_info bci;
892     
893     bci.y_limit = y_limit;
894     bci.width = width;
895     bci.height = height;
896     bci.threshold = threshold;
897     bci.method = method;
898     bci.bbox = *bbox;
899     bci.screen = screen;
900     bci.dtc = dtc;
901     bci.radius = prefs_get_int_attribute_limited("tools.paintbucket", "autogap", 0, 0, 3);
902     bci.max_queue_size = (width * height) / 4;
903     bci.current_step = 0;
905     if (is_point_fill) {
906         fill_points.push_back(NR::Point(event->button.x, event->button.y));
907     } else {
908         Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get();
909         fill_points = r->getPoints();
910     }
912     for (unsigned int i = 0; i < fill_points.size(); i++) {
913         NR::Point pw = NR::Point(fill_points[i][NR::X] / zoom_scale, sp_document_height(document) + (fill_points[i][NR::Y] / zoom_scale)) * affine;
915         pw[NR::X] = (int)MIN(width - 1, MAX(0, pw[NR::X]));
916         pw[NR::Y] = (int)MIN(height - 1, MAX(0, pw[NR::Y]));
918         if (is_touch_fill) {
919             if (i == 0) {
920                 color_queue.push(pw);
921             } else {
922                 unsigned char *trace_t = get_pixel(trace_px, (int)pw[NR::X], (int)pw[NR::Y], width);
923                 push_point_onto_queue(&fill_queue, bci.max_queue_size, trace_t, (int)pw[NR::X], (int)pw[NR::Y]);
924             }
925         } else {
926             color_queue.push(pw);
927         }
928     }
930     bool reached_screen_boundary = false;
932     bool first_run = true;
934     unsigned long sort_size_threshold = 5;
936     while (!color_queue.empty() && !aborted) {
937         NR::Point color_point = color_queue.front();
938         color_queue.pop();
940         int cx = (int)color_point[NR::X];
941         int cy = (int)color_point[NR::Y];
943         unsigned char *orig_px = get_pixel(px, cx, cy, width);
944         unsigned char orig_color[4];
945         for (int i = 0; i < 4; i++) { orig_color[i] = orig_px[i]; }
947         unsigned char merged_orig[3];
949         merge_pixel_with_background(orig_color, dtc, merged_orig);
951         bci.merged_orig_pixel = merged_orig;
953         unsigned char *trace_t = get_pixel(trace_px, cx, cy, width);
954         if (!is_pixel_checked(trace_t) && !is_pixel_colored(trace_t)) {
955             if (check_if_pixel_is_paintable(px, trace_px, cx, cy, orig_color, bci)) {
956                 shift_point_onto_queue(&fill_queue, bci.max_queue_size, trace_t, cx, cy);
958                 if (!first_run) {
959                     for (unsigned int y = 0; y < height; y++) {
960                         trace_t = get_pixel(trace_px, 0, y, width);
961                         for (unsigned int x = 0; x < width; x++) {
962                             clear_pixel_paintability(trace_t);
963                             trace_t += 4;
964                         }
965                     }
966                 }
967                 first_run = false;
968             }
969         }
971         unsigned long old_fill_queue_size = fill_queue.size();
973         while (!fill_queue.empty() && !aborted) {
974             NR::Point cp = fill_queue.front();
976             if (bci.radius == 0) {
977                 unsigned long new_fill_queue_size = fill_queue.size();
979                 /*
980                  * To reduce the number of points in the fill queue, periodically
981                  * resort all of the points in the queue so that scanline checks
982                  * can complete more quickly.  A point cannot be checked twice
983                  * in a normal scanline checks, so forcing scanline checks to start
984                  * from one corner of the rendered area as often as possible
985                  * will reduce the number of points that need to be checked and queued.
986                  */
987                 if (new_fill_queue_size > sort_size_threshold) {
988                     if (new_fill_queue_size > old_fill_queue_size) {
989                         std::sort(fill_queue.begin(), fill_queue.end(), sort_fill_queue_vertical);
991                         std::deque<NR::Point>::iterator start_sort = fill_queue.begin();
992                         std::deque<NR::Point>::iterator end_sort = fill_queue.begin();
993                         unsigned int sort_y = (unsigned int)cp[NR::Y];
994                         unsigned int current_y = sort_y;
995                         
996                         for (std::deque<NR::Point>::iterator i = fill_queue.begin(); i != fill_queue.end(); i++) {
997                             NR::Point current = *i;
998                             current_y = (unsigned int)current[NR::Y];
999                             if (current_y != sort_y) {
1000                                 if (start_sort != end_sort) {
1001                                     std::sort(start_sort, end_sort, sort_fill_queue_horizontal);
1002                                 }
1003                                 sort_y = current_y;
1004                                 start_sort = i;
1005                             }
1006                             end_sort = i;
1007                         }
1008                         if (start_sort != end_sort) {
1009                             std::sort(start_sort, end_sort, sort_fill_queue_horizontal);
1010                         }
1011                         
1012                         cp = fill_queue.front();
1013                     }
1014                 }
1016                 old_fill_queue_size = new_fill_queue_size;
1017             }
1019             fill_queue.pop_front();
1021             int x = (int)cp[NR::X];
1022             int y = (int)cp[NR::Y];
1024             unsigned char *trace_t = get_pixel(trace_px, x, y, width);
1025             if (!is_pixel_checked(trace_t)) {
1026                 mark_pixel_checked(trace_t);
1028                 if (y == 0) {
1029                     if (bbox->min()[NR::Y] > screen.min()[NR::Y]) {
1030                         aborted = true; break;
1031                     } else {
1032                         reached_screen_boundary = true;
1033                     }
1034                 }
1036                 if (y == y_limit) {
1037                     if (bbox->max()[NR::Y] < screen.max()[NR::Y]) {
1038                         aborted = true; break;
1039                     } else {
1040                         reached_screen_boundary = true;
1041                     }
1042                 }
1044                 bci.is_left = true;
1045                 bci.x = x;
1046                 bci.y = y;
1048                 ScanlineCheckResult result = perform_bitmap_scanline_check(&fill_queue, px, trace_px, orig_color, bci);
1050                 switch (result) {
1051                     case SCANLINE_CHECK_ABORTED:
1052                         aborted = true;
1053                         break;
1054                     case SCANLINE_CHECK_BOUNDARY:
1055                         reached_screen_boundary = true;
1056                         break;
1057                     default:
1058                         break;
1059                 }
1061                 if (bci.x < width) {
1062                     trace_t += 4;
1063                     if (!is_pixel_checked(trace_t) && !is_pixel_queued(trace_t)) {
1064                         mark_pixel_checked(trace_t);
1065                         bci.is_left = false;
1066                         bci.x = x + 1;
1068                         result = perform_bitmap_scanline_check(&fill_queue, px, trace_px, orig_color, bci);
1070                         switch (result) {
1071                             case SCANLINE_CHECK_ABORTED:
1072                                 aborted = true;
1073                                 break;
1074                             case SCANLINE_CHECK_BOUNDARY:
1075                                 reached_screen_boundary = true;
1076                                 break;
1077                             default:
1078                                 break;
1079                         }
1080                     }
1081                 }
1082             }
1084             bci.current_step++;
1086             if (bci.current_step > bci.max_queue_size) {
1087                 aborted = true;
1088             }
1089         }
1090     }
1091     
1092     g_free(px);
1093     
1094     if (aborted) {
1095         g_free(trace_px);
1096         desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Area is not bounded</b>, cannot fill."));
1097         return;
1098     }
1099     
1100     if (reached_screen_boundary) {
1101         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.")); 
1102     }
1103     
1104     NR::Matrix inverted_affine = NR::Matrix(affine).inverse();
1105     
1106     do_trace(bci, trace_px, desktop, inverted_affine, union_with_selection);
1108     g_free(trace_px);
1109     
1110     sp_document_done(document, SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area"));
1113 static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
1115     gint ret = FALSE;
1117     SPDesktop *desktop = event_context->desktop;
1119     switch (event->type) {
1120     case GDK_BUTTON_PRESS:
1121         if ((event->button.state & GDK_CONTROL_MASK) && event->button.button == 1 && !event_context->space_panning) {
1122             NR::Point const button_w(event->button.x,
1123                                     event->button.y);
1124             
1125             SPItem *item = sp_event_context_find_item (desktop, button_w, TRUE, TRUE);
1126             
1127             Inkscape::XML::Node *pathRepr = SP_OBJECT_REPR(item);
1128             /* Set style */
1129             sp_desktop_apply_style_tool (desktop, pathRepr, "tools.paintbucket", false);
1130             sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object"));
1131             ret = TRUE;
1132         }
1133         break;
1134     default:
1135         break;
1136     }
1138     if (((SPEventContextClass *) parent_class)->item_handler) {
1139         ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
1140     }
1142     return ret;
1145 static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event)
1147     static bool dragging;
1148     
1149     gint ret = FALSE;
1150     SPDesktop *desktop = event_context->desktop;
1152     switch (event->type) {
1153     case GDK_BUTTON_PRESS:
1154         if (event->button.button == 1 && !event_context->space_panning) {
1155             if (!(event->button.state & GDK_CONTROL_MASK)) {
1156                 NR::Point const button_w(event->button.x,
1157                                         event->button.y);
1158     
1159                 if (Inkscape::have_viable_layer(desktop, event_context->defaultMessageContext())) {
1160                     // save drag origin
1161                     event_context->xp = (gint) button_w[NR::X];
1162                     event_context->yp = (gint) button_w[NR::Y];
1163                     event_context->within_tolerance = true;
1164                       
1165                     dragging = true;
1166                     
1167                     NR::Point const p(desktop->w2d(button_w));
1168                     Inkscape::Rubberband::get()->setMode(RUBBERBAND_MODE_TOUCHPATH);
1169                     Inkscape::Rubberband::get()->start(desktop, p);
1170                 }
1171             }
1172         }
1173     case GDK_MOTION_NOTIFY:
1174         if ( dragging
1175              && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning)
1176         {
1177             if ( event_context->within_tolerance
1178                  && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
1179                  && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
1180                 break; // do not drag if we're within tolerance from origin
1181             }
1182             
1183             event_context->within_tolerance = false;
1184             
1185             NR::Point const motion_pt(event->motion.x, event->motion.y);
1186             NR::Point const p(desktop->w2d(motion_pt));
1187             if (Inkscape::Rubberband::get()->is_started()) {
1188                 Inkscape::Rubberband::get()->move(p);
1189                 event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> areas to add to fill, hold <b>Alt</b> for touch fill"));
1190                 gobble_motion_events(GDK_BUTTON1_MASK);
1191             }
1192         }
1193         break;
1195     case GDK_BUTTON_RELEASE:
1196         if (event->button.button == 1 && !event_context->space_panning) {
1197             Inkscape::Rubberband::Rubberband *r = Inkscape::Rubberband::get();
1198             if (r->is_started()) {
1199                 // set "busy" cursor
1200                 desktop->setWaitingCursor();
1202                 if (SP_IS_EVENT_CONTEXT(event_context)) { 
1203                     // Since setWaitingCursor runs main loop iterations, we may have already left this tool!
1204                     // So check if the tool is valid before doing anything
1205                     dragging = false;
1207                     bool is_point_fill = event_context->within_tolerance;
1208                     bool is_touch_fill = event->button.state & GDK_MOD1_MASK;
1209                     
1210                     sp_flood_do_flood_fill(event_context, event, event->button.state & GDK_SHIFT_MASK, is_point_fill, is_touch_fill);
1211                     
1212                     desktop->clearWaitingCursor();
1213                     // restore cursor when done; note that it may already be different if e.g. user 
1214                     // switched to another tool during interruptible tracing or drawing, in which case do nothing
1216                     ret = TRUE;
1217                 }
1219                 r->stop();
1221                 if (SP_IS_EVENT_CONTEXT(event_context)) {
1222                     event_context->defaultMessageContext()->clear();
1223                 }
1224             }
1225         }
1226         break;
1227     case GDK_KEY_PRESS:
1228         switch (get_group0_keyval (&event->key)) {
1229         case GDK_Up:
1230         case GDK_Down:
1231         case GDK_KP_Up:
1232         case GDK_KP_Down:
1233             // prevent the zoom field from activation
1234             if (!MOD__CTRL_ONLY)
1235                 ret = TRUE;
1236             break;
1237         default:
1238             break;
1239         }
1240         break;
1241     default:
1242         break;
1243     }
1245     if (!ret) {
1246         if (((SPEventContextClass *) parent_class)->root_handler) {
1247             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
1248         }
1249     }
1251     return ret;
1255 static void sp_flood_finish(SPFloodContext *rc)
1257     rc->_message_context->clear();
1259     if ( rc->item != NULL ) {
1260         SPDesktop * desktop;
1262         desktop = SP_EVENT_CONTEXT_DESKTOP(rc);
1264         SP_OBJECT(rc->item)->updateRepr();
1266         sp_canvas_end_forced_full_redraws(desktop->canvas);
1268         sp_desktop_selection(desktop)->set(rc->item);
1269         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET,
1270                         _("Fill bounded area"));
1272         rc->item = NULL;
1273     }
1276 void flood_channels_set_channels( gint channels )
1278     prefs_set_int_attribute("tools.paintbucket", "channels", channels);
1281 /*
1282   Local Variables:
1283   mode:c++
1284   c-file-style:"stroustrup"
1285   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1286   indent-tabs-mode:nil
1287   fill-column:99
1288   End:
1289 */
1290 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :