summaryrefslogtreecommitdiffstats
path: root/src/flood-context.cpp
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-09-20 17:05:24 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-09-20 17:05:24 +0000
commit48b4ee48e518d65c3c5e49369a747c2aa4b0081b (patch)
tree7159f8bc67d3f96ae43c42c32cacec6f7813f6fa /src/flood-context.cpp
parentFix bug in rectangle toolbar. (diff)
parentFix grids after C++ification. Patch from Markus Engel (diff)
downloadinkscape-48b4ee48e518d65c3c5e49369a747c2aa4b0081b.tar.gz
inkscape-48b4ee48e518d65c3c5e49369a747c2aa4b0081b.zip
Merge from trunk.
(bzr r12475.1.29)
Diffstat (limited to 'src/flood-context.cpp')
-rw-r--r--src/flood-context.cpp212
1 files changed, 85 insertions, 127 deletions
diff --git a/src/flood-context.cpp b/src/flood-context.cpp
index c944e5683..28aedba6e 100644
--- a/src/flood-context.cpp
+++ b/src/flood-context.cpp
@@ -74,112 +74,79 @@ using Inkscape::Display::ExtractARGB32;
using Inkscape::Display::ExtractRGB32;
using Inkscape::Display::AssembleARGB32;
-static void sp_flood_context_dispose(GObject *object);
+#include "tool-factory.h"
-static void sp_flood_context_setup(SPEventContext *ec);
+namespace {
+ SPEventContext* createPaintbucketContext() {
+ return new SPFloodContext();
+ }
-static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event);
-static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
-
-static void sp_flood_finish(SPFloodContext *rc);
-
-G_DEFINE_TYPE(SPFloodContext, sp_flood_context, SP_TYPE_EVENT_CONTEXT);
-
-static void sp_flood_context_class_init(SPFloodContextClass *klass)
-{
- GObjectClass *object_class = (GObjectClass *) klass;
- SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
-
- object_class->dispose = sp_flood_context_dispose;
-
- event_context_class->setup = sp_flood_context_setup;
- event_context_class->root_handler = sp_flood_context_root_handler;
- event_context_class->item_handler = sp_flood_context_item_handler;
+ bool paintbucketContextRegistered = ToolFactory::instance().registerObject("/tools/paintbucket", createPaintbucketContext);
}
-static void sp_flood_context_init(SPFloodContext *flood_context)
-{
- SPEventContext *event_context = SP_EVENT_CONTEXT(flood_context);
+const std::string& SPFloodContext::getPrefsPath() {
+ return SPFloodContext::prefsPath;
+}
- event_context->cursor_shape = cursor_paintbucket_xpm;
- event_context->hot_x = 11;
- event_context->hot_y = 30;
- event_context->xp = 0;
- event_context->yp = 0;
- event_context->tolerance = 4;
- event_context->within_tolerance = false;
- event_context->item_to_select = NULL;
+const std::string SPFloodContext::prefsPath = "/tools/paintbucket";
- flood_context->item = NULL;
+SPFloodContext::SPFloodContext() : SPEventContext() {
+ this->cursor_shape = cursor_paintbucket_xpm;
+ this->hot_x = 11;
+ this->hot_y = 30;
+ this->xp = 0;
+ this->yp = 0;
+ this->tolerance = 4;
+ this->within_tolerance = false;
+ this->item_to_select = NULL;
- new (&flood_context->sel_changed_connection) sigc::connection();
+ this->item = NULL;
}
-static void sp_flood_context_dispose(GObject *object)
-{
- SPFloodContext *rc = SP_FLOOD_CONTEXT(object);
- SPEventContext *ec = SP_EVENT_CONTEXT(object);
+SPFloodContext::~SPFloodContext() {
+ this->sel_changed_connection.disconnect();
- rc->sel_changed_connection.disconnect();
- rc->sel_changed_connection.~connection();
-
- delete ec->shape_editor;
- ec->shape_editor = NULL;
+ delete this->shape_editor;
+ this->shape_editor = NULL;
/* fixme: This is necessary because we do not grab */
- if (rc->item) {
- sp_flood_finish(rc);
+ if (this->item) {
+ this->finishItem();
}
-
- if (rc->_message_context) {
- delete rc->_message_context;
- }
-
- G_OBJECT_CLASS(sp_flood_context_parent_class)->dispose(object);
}
/**
* Callback that processes the "changed" signal on the selection;
* destroys old and creates new knotholder.
*/
-static void sp_flood_context_selection_changed(Inkscape::Selection *selection, gpointer data)
-{
- SPFloodContext *rc = SP_FLOOD_CONTEXT(data);
- SPEventContext *ec = SP_EVENT_CONTEXT(rc);
-
- ec->shape_editor->unset_item(SH_KNOTHOLDER);
- SPItem *item = selection->singleItem();
- ec->shape_editor->set_item(item, SH_KNOTHOLDER);
+void SPFloodContext::selection_changed(Inkscape::Selection* selection) {
+ this->shape_editor->unset_item(SH_KNOTHOLDER);
+ this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER);
}
-static void sp_flood_context_setup(SPEventContext *ec)
-{
- SPFloodContext *rc = SP_FLOOD_CONTEXT(ec);
-
- if (((SPEventContextClass *) sp_flood_context_parent_class)->setup) {
- ((SPEventContextClass *) sp_flood_context_parent_class)->setup(ec);
- }
+void SPFloodContext::setup() {
+ SPEventContext::setup();
- ec->shape_editor = new ShapeEditor(ec->desktop);
+ this->shape_editor = new ShapeEditor(this->desktop);
- SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
+ SPItem *item = sp_desktop_selection(this->desktop)->singleItem();
if (item) {
- ec->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item, SH_KNOTHOLDER);
}
- rc->sel_changed_connection.disconnect();
- rc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
- sigc::bind(sigc::ptr_fun(&sp_flood_context_selection_changed), (gpointer)rc)
+ this->sel_changed_connection.disconnect();
+ this->sel_changed_connection = sp_desktop_selection(this->desktop)->connectChanged(
+ sigc::mem_fun(this, &SPFloodContext::selection_changed)
);
- rc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
-
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
if (prefs->getBool("/tools/paintbucket/selcue")) {
- rc->enableSelectionCue();
+ this->enableSelectionCue();
}
}
+
// Changes from 0.48 -> 0.49 (Cairo)
// 0.49: Ignores alpha in background
// 0.48: RGBA, 0.49 ARGB
@@ -1117,56 +1084,54 @@ static void sp_flood_do_flood_fill(SPEventContext *event_context, GdkEvent *even
DocumentUndo::done(document, SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area"));
}
-static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
-{
+bool SPFloodContext::item_handler(SPItem* item, GdkEvent* event) {
gint ret = FALSE;
- SPDesktop *desktop = event_context->desktop;
-
switch (event->type) {
case GDK_BUTTON_PRESS:
- if ((event->button.state & GDK_CONTROL_MASK) && event->button.button == 1 && !event_context->space_panning) {
- Geom::Point const button_w(event->button.x,
- event->button.y);
+ if ((event->button.state & GDK_CONTROL_MASK) && event->button.button == 1 && !this->space_panning) {
+ Geom::Point const button_w(event->button.x, event->button.y);
SPItem *item = sp_event_context_find_item (desktop, button_w, TRUE, TRUE);
// Set style
desktop->applyCurrentOrToolStyle(item, "/tools/paintbucket", false);
+
DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Set style on object"));
+
ret = TRUE;
}
break;
+
default:
break;
}
- if (((SPEventContextClass *) sp_flood_context_parent_class)->item_handler) {
- ret = ((SPEventContextClass *) sp_flood_context_parent_class)->item_handler(event_context, item, event);
- }
+// if (((SPEventContextClass *) sp_flood_context_parent_class)->item_handler) {
+// ret = ((SPEventContextClass *) sp_flood_context_parent_class)->item_handler(event_context, item, event);
+// }
+ // CPPIFY: ret is overwritten...
+ ret = SPEventContext::item_handler(item, event);
return ret;
}
-static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEvent *event)
-{
+bool SPFloodContext::root_handler(GdkEvent* event) {
static bool dragging;
gint ret = FALSE;
- SPDesktop *desktop = event_context->desktop;
switch (event->type) {
case GDK_BUTTON_PRESS:
- if (event->button.button == 1 && !event_context->space_panning) {
+ if (event->button.button == 1 && !this->space_panning) {
if (!(event->button.state & GDK_CONTROL_MASK)) {
- Geom::Point const button_w(event->button.x,
- event->button.y);
+ Geom::Point const button_w(event->button.x, event->button.y);
- if (Inkscape::have_viable_layer(desktop, event_context->defaultMessageContext())) {
+ if (Inkscape::have_viable_layer(desktop, this->defaultMessageContext())) {
// save drag origin
- event_context->xp = (gint) button_w[Geom::X];
- event_context->yp = (gint) button_w[Geom::Y];
- event_context->within_tolerance = true;
+ this->xp = (gint) button_w[Geom::X];
+ this->yp = (gint) button_w[Geom::Y];
+ this->within_tolerance = true;
dragging = true;
@@ -1176,44 +1141,45 @@ static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEven
}
}
}
+
case GDK_MOTION_NOTIFY:
- if ( dragging
- && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning)
- {
- if ( event_context->within_tolerance
- && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
- && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
+ if ( dragging && ( event->motion.state & GDK_BUTTON1_MASK ) && !this->space_panning) {
+ if ( this->within_tolerance
+ && ( abs( (gint) event->motion.x - this->xp ) < this->tolerance )
+ && ( abs( (gint) event->motion.y - this->yp ) < this->tolerance ) ) {
break; // do not drag if we're within tolerance from origin
}
- event_context->within_tolerance = false;
+ this->within_tolerance = false;
Geom::Point const motion_pt(event->motion.x, event->motion.y);
Geom::Point const p(desktop->w2d(motion_pt));
+
if (Inkscape::Rubberband::get(desktop)->is_started()) {
Inkscape::Rubberband::get(desktop)->move(p);
- event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> areas to add to fill, hold <b>Alt</b> for touch fill"));
+ this->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> areas to add to fill, hold <b>Alt</b> for touch fill"));
gobble_motion_events(GDK_BUTTON1_MASK);
}
}
break;
case GDK_BUTTON_RELEASE:
- if (event->button.button == 1 && !event_context->space_panning) {
+ if (event->button.button == 1 && !this->space_panning) {
Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
+
if (r->is_started()) {
// set "busy" cursor
desktop->setWaitingCursor();
- if (SP_IS_EVENT_CONTEXT(event_context)) {
+ if (SP_IS_EVENT_CONTEXT(this)) {
// Since setWaitingCursor runs main loop iterations, we may have already left this tool!
// So check if the tool is valid before doing anything
dragging = false;
- bool is_point_fill = event_context->within_tolerance;
+ bool is_point_fill = this->within_tolerance;
bool is_touch_fill = event->button.state & GDK_MOD1_MASK;
- sp_flood_do_flood_fill(event_context, event, event->button.state & GDK_SHIFT_MASK, is_point_fill, is_touch_fill);
+ sp_flood_do_flood_fill(this, event, event->button.state & GDK_SHIFT_MASK, is_point_fill, is_touch_fill);
desktop->clearWaitingCursor();
// restore cursor when done; note that it may already be different if e.g. user
@@ -1224,9 +1190,9 @@ static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEven
r->stop();
- if (SP_IS_EVENT_CONTEXT(event_context)) {
- event_context->defaultMessageContext()->clear();
- }
+ //if (SP_IS_EVENT_CONTEXT(this)) {
+ this->defaultMessageContext()->clear();
+ //}
}
}
break;
@@ -1244,43 +1210,35 @@ static gint sp_flood_context_root_handler(SPEventContext *event_context, GdkEven
break;
}
break;
+
default:
break;
}
if (!ret) {
- if (((SPEventContextClass *) sp_flood_context_parent_class)->root_handler) {
- ret = ((SPEventContextClass *) sp_flood_context_parent_class)->root_handler(event_context, event);
- }
+ ret = SPEventContext::root_handler(event);
}
return ret;
}
+void SPFloodContext::finishItem() {
+ this->message_context->clear();
-static void sp_flood_finish(SPFloodContext *rc)
-{
- rc->_message_context->clear();
-
- if ( rc->item != NULL ) {
- SPDesktop * desktop;
-
- desktop = SP_EVENT_CONTEXT_DESKTOP(rc);
-
- SP_OBJECT(rc->item)->updateRepr();
+ if (this->item != NULL) {
+ this->item->updateRepr();
desktop->canvas->endForcedFullRedraws();
- sp_desktop_selection(desktop)->set(rc->item);
- DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET,
- _("Fill bounded area"));
+ sp_desktop_selection(desktop)->set(this->item);
- rc->item = NULL;
+ DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_PAINTBUCKET, _("Fill bounded area"));
+
+ this->item = NULL;
}
}
-void flood_channels_set_channels( gint channels )
-{
+void SPFloodContext::set_channels(gint channels) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt("/tools/paintbucket/channels", channels);
}