summaryrefslogtreecommitdiffstats
path: root/src/lpe-tool-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/lpe-tool-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/lpe-tool-context.cpp')
-rw-r--r--src/lpe-tool-context.cpp165
1 files changed, 63 insertions, 102 deletions
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index 49af2be47..14a536b7d 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -43,13 +43,6 @@
using Inkscape::Util::unit_table;
-static void sp_lpetool_context_dispose(GObject *object);
-
-static void sp_lpetool_context_setup(SPEventContext *ec);
-static void sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *);
-static gint sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
-static gint sp_lpetool_context_root_handler(SPEventContext *ec, GdkEvent *event);
-
void sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpointer data);
const int num_subtools = 8;
@@ -66,96 +59,80 @@ SubtoolEntry lpesubtools[] = {
{Inkscape::LivePathEffect::MIRROR_SYMMETRY, "draw-geometry-mirror"}
};
-G_DEFINE_TYPE(SPLPEToolContext, sp_lpetool_context, SP_TYPE_PEN_CONTEXT);
-static void
-sp_lpetool_context_class_init(SPLPEToolContextClass *klass)
-{
- GObjectClass *object_class = (GObjectClass *) klass;
- SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
+#include "tool-factory.h"
- object_class->dispose = sp_lpetool_context_dispose;
+namespace {
+ SPEventContext* createLPEToolContext() {
+ return new SPLPEToolContext();
+ }
- event_context_class->setup = sp_lpetool_context_setup;
- event_context_class->set = sp_lpetool_context_set;
- event_context_class->root_handler = sp_lpetool_context_root_handler;
- event_context_class->item_handler = sp_lpetool_context_item_handler;
+ bool lpetoolContextRegistered = ToolFactory::instance().registerObject("/tools/lpetool", createLPEToolContext);
}
-static void
-sp_lpetool_context_init(SPLPEToolContext *lc)
-{
- lc->cursor_shape = cursor_crosshairs_xpm;
- lc->hot_x = 7;
- lc->hot_y = 7;
-
- lc->canvas_bbox = NULL;
- lc->measuring_items = new std::map<SPPath *, SPCanvasItem*>;
-
- new (&lc->sel_changed_connection) sigc::connection();
+const std::string& SPLPEToolContext::getPrefsPath() {
+ return SPLPEToolContext::prefsPath;
}
-static void
-sp_lpetool_context_dispose(GObject *object)
-{
- SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(object);
- delete lc->shape_editor;
+const std::string SPLPEToolContext::prefsPath = "/tools/lpetool";
- if (lc->canvas_bbox) {
- sp_canvas_item_destroy(SP_CANVAS_ITEM(lc->canvas_bbox));
- lc->canvas_bbox = NULL;
- }
+SPLPEToolContext::SPLPEToolContext() : SPPenContext() {
+ this->mode = Inkscape::LivePathEffect::BEND_PATH;
+ this->shape_editor = 0;
- lpetool_delete_measuring_items(lc);
- delete lc->measuring_items;
- lc->measuring_items = NULL;
+ this->cursor_shape = cursor_crosshairs_xpm;
+ this->hot_x = 7;
+ this->hot_y = 7;
- lc->sel_changed_connection.disconnect();
- lc->sel_changed_connection.~connection();
+ this->canvas_bbox = NULL;
+ this->measuring_items = new std::map<SPPath *, SPCanvasItem*>;
+}
- if (lc->_lpetool_message_context) {
- delete lc->_lpetool_message_context;
+SPLPEToolContext::~SPLPEToolContext() {
+ delete this->shape_editor;
+ this->shape_editor = NULL;
+
+ if (this->canvas_bbox) {
+ sp_canvas_item_destroy(SP_CANVAS_ITEM(this->canvas_bbox));
+ this->canvas_bbox = NULL;
}
- G_OBJECT_CLASS(sp_lpetool_context_parent_class)->dispose(object);
-}
+ lpetool_delete_measuring_items(this);
+ delete this->measuring_items;
+ this->measuring_items = NULL;
-static void
-sp_lpetool_context_setup(SPEventContext *ec)
-{
- SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(ec);
+ this->sel_changed_connection.disconnect();
+}
- if (((SPEventContextClass *) sp_lpetool_context_parent_class)->setup)
- ((SPEventContextClass *) sp_lpetool_context_parent_class)->setup(ec);
+void SPLPEToolContext::setup() {
+ SPPenContext::setup();
- Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
+ Inkscape::Selection *selection = sp_desktop_selection (this->desktop);
SPItem *item = selection->singleItem();
- lc->sel_changed_connection.disconnect();
- lc->sel_changed_connection =
- selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_lpetool_context_selection_changed), (gpointer)lc));
+ this->sel_changed_connection.disconnect();
+ this->sel_changed_connection =
+ selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_lpetool_context_selection_changed), (gpointer)this));
- lc->shape_editor = new ShapeEditor(ec->desktop);
+ this->shape_editor = new ShapeEditor(this->desktop);
- lpetool_context_switch_mode(lc, Inkscape::LivePathEffect::INVALID_LPE);
- lpetool_context_reset_limiting_bbox(lc);
- lpetool_create_measuring_items(lc);
+ lpetool_context_switch_mode(this, Inkscape::LivePathEffect::INVALID_LPE);
+ lpetool_context_reset_limiting_bbox(this);
+ lpetool_create_measuring_items(this);
// TODO temp force:
- ec->enableSelectionCue();
+ this->enableSelectionCue();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (item) {
- lc->shape_editor->set_item(item, SH_NODEPATH);
- lc->shape_editor->set_item(item, SH_KNOTHOLDER);
+ this->shape_editor->set_item(item, SH_NODEPATH);
+ this->shape_editor->set_item(item, SH_KNOTHOLDER);
}
if (prefs->getBool("/tools/lpetool/selcue")) {
- ec->enableSelectionCue();
+ this->enableSelectionCue();
}
-
- lc->_lpetool_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
}
/**
@@ -171,32 +148,21 @@ void sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpoint
lc->shape_editor->set_item(item, SH_KNOTHOLDER);
}
-static void
-sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val)
-{
- if (val->getEntryName() == "mode") {
+void SPLPEToolContext::set(const Inkscape::Preferences::Entry& val) {
+ if (val.getEntryName() == "mode") {
Inkscape::Preferences::get()->setString("/tools/geometric/mode", "drag");
- SP_PEN_CONTEXT(ec)->mode = SP_PEN_CONTEXT_MODE_DRAG;
- }
-
- /*
- //pass on up to parent class to handle common attributes.
- if ( sp_lpetool_context_parent_class->set ) {
- sp_lpetool_context_parent_class->set(ec, key, val);
+ SP_PEN_CONTEXT(this)->mode = SPPenContext::MODE_DRAG;
}
- */
}
-static gint
-sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
-{
+bool SPLPEToolContext::item_handler(SPItem* item, GdkEvent* event) {
gint ret = FALSE;
switch (event->type) {
case GDK_BUTTON_PRESS:
{
// select the clicked item but do nothing else
- Inkscape::Selection * const selection = sp_desktop_selection(ec->desktop);
+ Inkscape::Selection * const selection = sp_desktop_selection(this->desktop);
selection->clear();
selection->add(item);
ret = TRUE;
@@ -211,32 +177,28 @@ sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *even
}
if (!ret) {
- if (((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler)
- ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->item_handler(ec, item, event);
+ ret = SPPenContext::item_handler(item, event);
}
return ret;
}
-gint
-sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
-{
- SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(event_context);
- SPDesktop *desktop = event_context->desktop;
+bool SPLPEToolContext::root_handler(GdkEvent* event) {
Inkscape::Selection *selection = sp_desktop_selection (desktop);
bool ret = false;
- if (sp_pen_context_has_waiting_LPE(lc)) {
+ if (sp_pen_context_has_waiting_LPE(this)) {
// quit when we are waiting for a LPE to be applied
- ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event);
+ //ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event);
+ ret = this->root_handler(event);
return ret;
}
switch (event->type) {
case GDK_BUTTON_PRESS:
- if (event->button.button == 1 && !event_context->space_panning) {
- if (lc->mode == Inkscape::LivePathEffect::INVALID_LPE) {
+ if (event->button.button == 1 && !this->space_panning) {
+ if (this->mode == Inkscape::LivePathEffect::INVALID_LPE) {
// don't do anything for now if we are inactive (except clearing the selection
// since this was a click into empty space)
selection->clear();
@@ -246,9 +208,9 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
}
// save drag origin
- event_context->xp = (gint) event->button.x;
- event_context->yp = (gint) event->button.y;
- event_context->within_tolerance = true;
+ this->xp = (gint) event->button.x;
+ this->yp = (gint) event->button.y;
+ this->within_tolerance = true;
using namespace Inkscape::LivePathEffect;
@@ -258,10 +220,11 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
//bool over_stroke = lc->shape_editor->is_over_stroke(Geom::Point(event->button.x, event->button.y), true);
- sp_pen_context_wait_for_LPE_mouse_clicks(lc, type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type));
+ sp_pen_context_wait_for_LPE_mouse_clicks(this, type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type));
// we pass the mouse click on to pen tool as the first click which it should collect
- ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event);
+ //ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event);
+ ret = this->root_handler(event);
}
break;
@@ -297,9 +260,7 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
}
if (!ret) {
- if (((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler) {
- ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event);
- }
+ ret = SPPenContext::root_handler(event);
}
return ret;