summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-27 22:05:16 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-27 22:05:16 +0000
commit9b2956fbaefb4e12bad3fc359c47e5923f33bb41 (patch)
tree376539d6ec4ebeeb82f5f34e190f0f9bceb77993 /src
parentRemoved some unused files; more refactoring in EventContext tree. (diff)
downloadinkscape-9b2956fbaefb4e12bad3fc359c47e5923f33bb41.tar.gz
inkscape-9b2956fbaefb4e12bad3fc359c47e5923f33bb41.zip
various changes
(bzr r11608.1.105)
Diffstat (limited to 'src')
-rw-r--r--src/connector-context.cpp266
-rw-r--r--src/connector-context.h3
-rw-r--r--src/lpe-tool-context.cpp2
-rw-r--r--src/mesh-context.cpp340
-rw-r--r--src/mesh-context.h3
-rw-r--r--src/pen-context.cpp94
-rw-r--r--src/pen-context.h28
-rw-r--r--src/rect-context.cpp15
-rw-r--r--src/sp-rect.cpp2
-rw-r--r--src/sp-rect.h10
10 files changed, 355 insertions, 408 deletions
diff --git a/src/connector-context.cpp b/src/connector-context.cpp
index 42bf6584b..12d9e41b8 100644
--- a/src/connector-context.cpp
+++ b/src/connector-context.cpp
@@ -134,7 +134,6 @@ static bool conn_pt_handle_test(SPConnectorContext *cc, Geom::Point& p, gchar **
static void cc_select_handle(SPKnot* knot);
static void cc_deselect_handle(SPKnot* knot);
static bool cc_item_is_shape(SPItem *item);
-static void cc_selection_changed(Inkscape::Selection *selection, gpointer data);
static void cc_connector_rerouting_finish(SPConnectorContext *const cc,
Geom::Point *const p);
@@ -181,169 +180,145 @@ const std::string& SPConnectorContext::getPrefsPath() {
const std::string SPConnectorContext::prefsPath = "/tools/connector";
SPConnectorContext::SPConnectorContext() : SPEventContext() {
- SPConnectorContext* cc = this;
+ this->red_curve = 0;
+ this->isOrthogonal = false;
+ this->c1 = 0;
+ this->red_bpath = 0;
+ this->green_curve = 0;
+ this->selection = 0;
+ this->cl0 = 0;
+ this->cl1 = 0;
+ this->c0 = 0;
- cc->red_curve = 0;
- cc->isOrthogonal = false;
- cc->c1 = 0;
- cc->red_bpath = 0;
- cc->green_curve = 0;
- cc->selection = 0;
- cc->cl0 = 0;
- cc->cl1 = 0;
- cc->c0 = 0;
+ this->cursor_shape = cursor_connector_xpm;
+ this->hot_x = 1;
+ this->hot_y = 1;
+ this->xp = 0;
+ this->yp = 0;
- SPEventContext *ec = SP_EVENT_CONTEXT(cc);
+ this->red_color = 0xff00007f;
- ec->cursor_shape = cursor_connector_xpm;
- ec->hot_x = 1;
- ec->hot_y = 1;
- ec->xp = 0;
- ec->yp = 0;
+ this->newconn = NULL;
+ this->newConnRef = NULL;
+ this->curvature = 0.0;
- cc->red_color = 0xff00007f;
+ this->sel_changed_connection = sigc::connection();
- cc->newconn = NULL;
- cc->newConnRef = NULL;
- cc->curvature = 0.0;
+ this->active_shape = NULL;
+ this->active_shape_repr = NULL;
+ this->active_shape_layer_repr = NULL;
- cc->sel_changed_connection = sigc::connection();
+ this->active_conn = NULL;
+ this->active_conn_repr = NULL;
- cc->active_shape = NULL;
- cc->active_shape_repr = NULL;
- cc->active_shape_layer_repr = NULL;
-
- cc->active_conn = NULL;
- cc->active_conn_repr = NULL;
-
- cc->active_handle = NULL;
+ this->active_handle = NULL;
- cc->selected_handle = NULL;
+ this->selected_handle = NULL;
- cc->clickeditem = NULL;
- cc->clickedhandle = NULL;
-
- //new (&cc->knots) SPKnotList();
+ this->clickeditem = NULL;
+ this->clickedhandle = NULL;
for (int i = 0; i < 2; ++i) {
- cc->endpt_handle[i] = NULL;
- cc->endpt_handler_id[i] = 0;
+ this->endpt_handle[i] = NULL;
+ this->endpt_handler_id[i] = 0;
}
- cc->shref = NULL;
- cc->ehref = NULL;
- cc->npoints = 0;
- cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+
+ this->shref = NULL;
+ this->ehref = NULL;
+ this->npoints = 0;
+ this->state = SP_CONNECTOR_CONTEXT_IDLE;
}
SPConnectorContext::~SPConnectorContext() {
- SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(this);
-
- cc->sel_changed_connection.disconnect();
+ this->sel_changed_connection.disconnect();
for (int i = 0; i < 2; ++i) {
- if (cc->endpt_handle[1]) {
- g_object_unref(cc->endpt_handle[i]);
- cc->endpt_handle[i] = NULL;
+ if (this->endpt_handle[1]) {
+ g_object_unref(this->endpt_handle[i]);
+ this->endpt_handle[i] = NULL;
}
}
- if (cc->shref) {
- g_free(cc->shref);
- cc->shref = NULL;
+
+ if (this->shref) {
+ g_free(this->shref);
+ this->shref = NULL;
}
- if (cc->ehref) {
- g_free(cc->shref);
- cc->shref = NULL;
+
+ if (this->ehref) {
+ g_free(this->shref);
+ this->shref = NULL;
}
- g_assert( cc->newConnRef == NULL );
-
- //G_OBJECT_CLASS(sp_connector_context_parent_class)->dispose(object);
+
+ g_assert( this->newConnRef == NULL );
}
void SPConnectorContext::setup() {
- SPConnectorContext* ec = this;
-
- SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
- SPDesktop *dt = ec->desktop;
-
-// if ((SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->setup) {
-// (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->setup(ec);
-// }
SPEventContext::setup();
- cc->selection = sp_desktop_selection(dt);
+ this->selection = sp_desktop_selection(this->desktop);
- cc->sel_changed_connection.disconnect();
- cc->sel_changed_connection = cc->selection->connectChanged(
- sigc::bind(sigc::ptr_fun(&cc_selection_changed),
- (gpointer) cc));
+ this->sel_changed_connection.disconnect();
+ this->sel_changed_connection = this->selection->connectChanged(
+ sigc::mem_fun(this, &SPConnectorContext::selection_changed)
+ );
/* Create red bpath */
- cc->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(ec->desktop), NULL);
- sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cc->red_bpath), cc->red_color,
+ this->red_bpath = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), NULL);
+ sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->red_bpath), this->red_color,
1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
- sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cc->red_bpath), 0x00000000,
+ sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->red_bpath), 0x00000000,
SP_WIND_RULE_NONZERO);
/* Create red curve */
- cc->red_curve = new SPCurve();
+ this->red_curve = new SPCurve();
/* Create green curve */
- cc->green_curve = new SPCurve();
+ this->green_curve = new SPCurve();
// Notice the initial selection.
- cc_selection_changed(cc->selection, (gpointer) cc);
+ //cc_selection_changed(this->selection, (gpointer) this);
+ this->selection_changed(this->selection);
- cc->within_tolerance = false;
+ this->within_tolerance = false;
- sp_event_context_read(ec, "curvature");
- sp_event_context_read(ec, "orthogonal");
+ sp_event_context_read(this, "curvature");
+ sp_event_context_read(this, "orthogonal");
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/tools/connector/selcue", 0)) {
- ec->enableSelectionCue();
+ this->enableSelectionCue();
}
// Make sure we see all enter events for canvas items,
// even if a mouse button is depressed.
- dt->canvas->gen_all_enter_events = true;
+ this->desktop->canvas->gen_all_enter_events = true;
}
void SPConnectorContext::set(const Inkscape::Preferences::Entry& val) {
- SPEventContext* ec = this;
-
- SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
-
/* fixme: Proper error handling for non-numeric data. Use a locale-independent function like
* g_ascii_strtod (or a thin wrapper that does the right thing for invalid values inf/nan). */
Glib::ustring name = val.getEntryName();
- if ( name == "curvature" ) {
- cc->curvature = val.getDoubleLimited(); // prevents NaN and +/-Inf from messing up
- }
- else if ( name == "orthogonal" ) {
- cc->isOrthogonal = val.getBool();
+
+ if (name == "curvature") {
+ this->curvature = val.getDoubleLimited(); // prevents NaN and +/-Inf from messing up
+ } else if (name == "orthogonal") {
+ this->isOrthogonal = val.getBool();
}
}
void SPConnectorContext::finish() {
- SPEventContext* ec = this;
-
- SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec);
+ spcc_connector_finish(this);
+ this->state = SP_CONNECTOR_CONTEXT_IDLE;
- spcc_connector_finish(cc);
- cc->state = SP_CONNECTOR_CONTEXT_IDLE;
-
-// if ((SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->finish) {
-// (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->finish(ec);
-// }
SPEventContext::finish();
- if (cc->selection) {
- cc->selection = NULL;
+ if (this->selection) {
+ this->selection = NULL;
}
- cc_clear_active_shape(cc);
- cc_clear_active_conn(cc);
+
+ cc_clear_active_shape(this);
+ cc_clear_active_conn(this);
// Restore the default event generating behaviour.
- SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(ec);
- desktop->canvas->gen_all_enter_events = false;
+ this->desktop->canvas->gen_all_enter_events = false;
}
//-----------------------------------------------------------------------------
@@ -443,58 +418,53 @@ cc_deselect_handle(SPKnot* knot)
}
gint SPConnectorContext::item_handler(SPItem* item, GdkEvent* event) {
- SPEventContext* event_context = this;
-
gint ret = FALSE;
- SPDesktop *desktop = event_context->desktop;
-
- SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(event_context);
-
Geom::Point p(event->button.x, event->button.y);
switch (event->type) {
case GDK_BUTTON_RELEASE:
- if (event->button.button == 1 && !event_context->space_panning) {
- if ((cc->state == SP_CONNECTOR_CONTEXT_DRAGGING) &&
- (event_context->within_tolerance))
- {
- spcc_reset_colors(cc);
- cc->state = SP_CONNECTOR_CONTEXT_IDLE;
+ if (event->button.button == 1 && !this->space_panning) {
+ if ((this->state == SP_CONNECTOR_CONTEXT_DRAGGING) && this->within_tolerance) {
+ spcc_reset_colors(this);
+ this->state = SP_CONNECTOR_CONTEXT_IDLE;
}
- if (cc->state != SP_CONNECTOR_CONTEXT_IDLE) {
+
+ if (this->state != SP_CONNECTOR_CONTEXT_IDLE) {
// Doing something else like rerouting.
break;
}
+
// find out clicked item, honoring Alt
- SPItem *item = sp_event_context_find_item(desktop,
- p, event->button.state & GDK_MOD1_MASK, FALSE);
+ SPItem *item = sp_event_context_find_item(desktop, p, event->button.state & GDK_MOD1_MASK, FALSE);
if (event->button.state & GDK_SHIFT_MASK) {
- cc->selection->toggle(item);
+ this->selection->toggle(item);
} else {
- cc->selection->set(item);
+ this->selection->set(item);
/* When selecting a new item, do not allow showing
connection points on connectors. (yet?)
*/
- if ( item != cc->active_shape && !cc_item_is_connector( item ) )
- cc_set_active_shape( cc, item );
+
+ if (item != this->active_shape && !cc_item_is_connector(item)) {
+ cc_set_active_shape(this, item);
+ }
}
- ret = TRUE;
+ ret = TRUE;
}
break;
+
case GDK_ENTER_NOTIFY:
- {
- if (!cc->selected_handle)
- {
+ if (!this->selected_handle) {
if (cc_item_is_shape(item)) {
- cc_set_active_shape(cc, item);
+ cc_set_active_shape(this, item);
}
+
ret = TRUE;
}
break;
- }
+
default:
break;
}
@@ -503,26 +473,23 @@ gint SPConnectorContext::item_handler(SPItem* item, GdkEvent* event) {
}
gint SPConnectorContext::root_handler(GdkEvent* event) {
- SPEventContext* ec = this;
-
- SPConnectorContext *const cc = SP_CONNECTOR_CONTEXT(ec);
-
gint ret = FALSE;
switch (event->type) {
case GDK_BUTTON_PRESS:
- ret = connector_handle_button_press(cc, event->button);
+ ret = connector_handle_button_press(this, event->button);
break;
case GDK_MOTION_NOTIFY:
- ret = connector_handle_motion_notify(cc, event->motion);
+ ret = connector_handle_motion_notify(this, event->motion);
break;
case GDK_BUTTON_RELEASE:
- ret = connector_handle_button_release(cc, event->button);
+ ret = connector_handle_button_release(this, event->button);
break;
+
case GDK_KEY_PRESS:
- ret = connector_handle_key_press(cc, get_group0_keyval (&event->key));
+ ret = connector_handle_key_press(this, get_group0_keyval (&event->key));
break;
default:
@@ -530,11 +497,6 @@ gint SPConnectorContext::root_handler(GdkEvent* event) {
}
if (!ret) {
-// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *)
-// = (SP_EVENT_CONTEXT_CLASS(sp_connector_context_parent_class))->root_handler;
-// if (parent_root_handler) {
-// ret = parent_root_handler(ec, event);
-// }
ret = SPEventContext::root_handler(event);
}
@@ -1455,32 +1417,24 @@ void cc_selection_set_avoid(bool const set_avoid)
DocumentUndo::done(document, SP_VERB_CONTEXT_CONNECTOR, event_desc);
}
-
-static void
-cc_selection_changed(Inkscape::Selection *selection, gpointer data)
-{
- SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(data);
- //SPEventContext *ec = SP_EVENT_CONTEXT(cc);
-
+void SPConnectorContext::selection_changed(Inkscape::Selection *selection) {
SPItem *item = selection->singleItem();
- if (cc->active_conn == item)
- {
+ if (this->active_conn == item) {
// Nothing to change.
return;
}
- if (item == NULL)
- {
- cc_clear_active_conn(cc);
+
+ if (item == NULL) {
+ cc_clear_active_conn(this);
return;
}
if (cc_item_is_connector(item)) {
- cc_set_active_conn(cc, item);
+ cc_set_active_conn(this, item);
}
}
-
static void
shape_event_attr_deleted(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node *child,
Inkscape::XML::Node */*ref*/, gpointer data)
diff --git a/src/connector-context.h b/src/connector-context.h
index 44f3cd3c0..1071bdced 100644
--- a/src/connector-context.h
+++ b/src/connector-context.h
@@ -103,6 +103,9 @@ public:
virtual gint item_handler(SPItem* item, GdkEvent* event);
virtual const std::string& getPrefsPath();
+
+private:
+ void selection_changed(Inkscape::Selection *selection);
};
void cc_selection_set_avoid(bool const set_ignore);
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index bce2fb800..26d52767d 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -171,7 +171,7 @@ 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;
+ SP_PEN_CONTEXT(ec)->mode = SPPenContext::MODE_DRAG;
}
/*
diff --git a/src/mesh-context.cpp b/src/mesh-context.cpp
index a39aa3853..c7cf60d06 100644
--- a/src/mesh-context.cpp
+++ b/src/mesh-context.cpp
@@ -73,42 +73,34 @@ const std::string& SPMeshContext::getPrefsPath() {
const std::string SPMeshContext::prefsPath = "/tools/mesh";
SPMeshContext::SPMeshContext() : SPEventContext() {
- SPMeshContext* gr_context = this;
-
- gr_context->selcon = 0;
- gr_context->_message_context = 0;
- gr_context->node_added = false;
- gr_context->subselcon = 0;
-
- SPEventContext *event_context = SP_EVENT_CONTEXT(gr_context);
-
- gr_context->cursor_addnode = false;
- event_context->cursor_shape = cursor_gradient_xpm;
- event_context->hot_x = 4;
- event_context->hot_y = 4;
- event_context->xp = 0;
- event_context->yp = 0;
- event_context->tolerance = 6;
- event_context->within_tolerance = false;
- event_context->item_to_select = NULL;
+ this->selcon = 0;
+ this->_message_context = 0;
+ this->node_added = false;
+ this->subselcon = 0;
+
+ this->cursor_addnode = false;
+ this->cursor_shape = cursor_gradient_xpm;
+ this->hot_x = 4;
+ this->hot_y = 4;
+ this->xp = 0;
+ this->yp = 0;
+ this->tolerance = 6;
+ this->within_tolerance = false;
+ this->item_to_select = NULL;
}
SPMeshContext::~SPMeshContext() {
- SPMeshContext *rc = SP_MESH_CONTEXT(this);
- SPEventContext *ec = SP_EVENT_CONTEXT(this);
+ this->enableGrDrag(false);
- ec->enableGrDrag(false);
-
- if (rc->_message_context) {
- delete rc->_message_context;
+ if (this->_message_context) {
+ delete this->_message_context;
}
- rc->selcon->disconnect();
- delete rc->selcon;
- rc->subselcon->disconnect();
- delete rc->subselcon;
-
- //G_OBJECT_CLASS(sp_mesh_context_parent_class)->dispose(object);
+ this->selcon->disconnect();
+ delete this->selcon;
+
+ this->subselcon->disconnect();
+ delete this->subselcon;
}
const gchar *ms_handle_descr [] = {
@@ -117,20 +109,20 @@ const gchar *ms_handle_descr [] = {
N_("Mesh gradient <b>tensor</b>")
};
-static void
-mesh_selection_changed (Inkscape::Selection *, gpointer data)
-{
- SPMeshContext *rc = (SPMeshContext *) data;
+void SPMeshContext::selection_changed(Inkscape::Selection* sel) {
+ GrDrag *drag = this->_grdrag;
+ Inkscape::Selection *selection = sp_desktop_selection(this->desktop);
- GrDrag *drag = rc->_grdrag;
- Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(rc)->desktop);
if (selection == NULL) {
return;
}
+
guint n_obj = g_slist_length((GSList *) selection->itemList());
- if (!drag->isNonEmpty() || selection->isEmpty())
+ if (!drag->isNonEmpty() || selection->isEmpty()) {
return;
+ }
+
guint n_tot = drag->numDraggers();
guint n_sel = drag->numSelected();
@@ -143,7 +135,7 @@ mesh_selection_changed (Inkscape::Selection *, gpointer data)
//TRANSLATORS: Mind the space in front. This is part of a compound message
ngettext(" out of %d mesh handle"," out of %d mesh handles",n_tot),
ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
- rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
+ this->_message_context->setF(Inkscape::NORMAL_MESSAGE,
message,_(ms_handle_descr[drag->singleSelectedDraggerSingleDraggableType()]), n_tot, n_obj);
} else {
gchar * message =
@@ -154,7 +146,7 @@ mesh_selection_changed (Inkscape::Selection *, gpointer data)
drag->singleSelectedDraggerNumDraggables()),
ngettext(" out of %d mesh handle"," out of %d mesh handles",n_tot),
ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
- rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj);
+ this->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj);
}
} else if (n_sel > 1) {
//TRANSLATORS: The plural refers to number of selected mesh handles. This is part of a compound message (part two indicates selected object count)
@@ -162,9 +154,9 @@ mesh_selection_changed (Inkscape::Selection *, gpointer data)
g_strconcat(ngettext("<b>%d</b> mesh handle selected out of %d","<b>%d</b> mesh handles selected out of %d",n_sel),
//TRANSLATORS: Mind the space in front. (Refers to gradient handles selected). This is part of a compound message
ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL);
- rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message, n_sel, n_tot, n_obj);
+ this->_message_context->setF(Inkscape::NORMAL_MESSAGE,message, n_sel, n_tot, n_obj);
} else if (n_sel == 0) {
- rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,
+ this->_message_context->setF(Inkscape::NORMAL_MESSAGE,
//TRANSLATORS: The plural refers to number of selected objects
ngettext("<b>No</b> mesh handles selected out of %d on %d selected object",
"<b>No</b> mesh handles selected out of %d on %d selected objects",n_obj), n_tot, n_obj);
@@ -237,36 +229,31 @@ mesh_selection_changed (Inkscape::Selection *, gpointer data)
// }
}
-
-static void
-mesh_subselection_changed (gpointer, gpointer data)
-{
- mesh_selection_changed (NULL, data);
-}
-
void SPMeshContext::setup() {
- SPEventContext* ec = this;
-
- SPMeshContext *rc = SP_MESH_CONTEXT(ec);
-
-// if (((SPEventContextClass *) sp_mesh_context_parent_class)->setup) {
-// ((SPEventContextClass *) sp_mesh_context_parent_class)->setup(ec);
-// }
SPEventContext::setup();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (prefs->getBool("/tools/mesh/selcue", true)) {
- ec->enableSelectionCue();
+ this->enableSelectionCue();
}
- ec->enableGrDrag();
- Inkscape::Selection *selection = sp_desktop_selection(ec->desktop);
+ this->enableGrDrag();
+ Inkscape::Selection *selection = sp_desktop_selection(this->desktop);
- rc->_message_context = new Inkscape::MessageContext(sp_desktop_message_stack(ec->desktop));
+ this->_message_context = new Inkscape::MessageContext(sp_desktop_message_stack(this->desktop));
- rc->selcon = new sigc::connection (selection->connectChanged( sigc::bind (sigc::ptr_fun(&mesh_selection_changed), rc)));
- rc->subselcon = new sigc::connection (ec->desktop->connectToolSubselectionChanged(sigc::bind (sigc::ptr_fun(&mesh_subselection_changed), rc)));
- mesh_selection_changed(selection, rc);
+ this->selcon = new sigc::connection(selection->connectChanged(
+ sigc::mem_fun(this, &SPMeshContext::selection_changed)
+ ));
+
+ this->subselcon = new sigc::connection(this->desktop->connectToolSubselectionChanged(
+ sigc::hide(sigc::bind(
+ sigc::mem_fun(*this, &SPMeshContext::selection_changed),
+ (Inkscape::Selection*)NULL)
+ )
+ ));
+
+ this->selection_changed(selection);
}
void
@@ -457,27 +444,20 @@ sp_mesh_context_corner_operation (SPMeshContext *rc, MeshCornerOperation operati
Handles all keyboard and mouse input for meshs.
*/
gint SPMeshContext::root_handler(GdkEvent* event) {
- SPEventContext* event_context = this;
-
- // static int count = 0;
- // std::cout << "sp_mesh_context_root_handler: " << count++ << std::endl;
static bool dragging;
- SPDesktop *desktop = event_context->desktop;
Inkscape::Selection *selection = sp_desktop_selection (desktop);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- SPMeshContext *rc = SP_MESH_CONTEXT(event_context);
-
- event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
+ this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
double const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
- GrDrag *drag = event_context->_grdrag;
+ GrDrag *drag = this->_grdrag;
g_assert (drag);
gint ret = FALSE;
- switch (event->type) {
+ switch (event->type) {
case GDK_2BUTTON_PRESS:
#ifdef DEBUG_MESH
@@ -489,27 +469,24 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
// If not over a line, create new gradients for selected objects.
if ( event->button.button == 1 ) {
-
// Are we over a mesh line?
bool over_line = false;
SPCtrlCurve *line = NULL;
+
if (drag->lines) {
for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) {
line = (SPCtrlCurve*) l->data;
- over_line |= sp_mesh_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
+ over_line |= sp_mesh_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
}
}
if (over_line) {
// We take the first item in selection, because with doubleclick, the first click
// always resets selection to the single object under cursor
- sp_mesh_context_split_near_point(rc, SP_ITEM(selection->itemList()->data), rc->mousepoint_doc, event->button.time);
-
+ sp_mesh_context_split_near_point(this, SP_ITEM(selection->itemList()->data), this->mousepoint_doc, event->button.time);
} else {
// Create a new gradient with default coordinates.
-
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
-
SPItem *item = SP_ITEM(i->data);
SPGradientType new_type = SP_GRADIENT_TYPE_MESH;
Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
@@ -526,6 +503,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
DocumentUndo::done(sp_desktop_document (desktop), SP_VERB_CONTEXT_MESH,
_("Create default mesh"));
}
+
ret = TRUE;
}
break;
@@ -538,14 +516,13 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
// Button down
// If Shift key down: do rubber band selection
// Else set origin for drag. A drag creates a new gradient if one does not exist
-
- if ( event->button.button == 1 && !event_context->space_panning ) {
+ if ( event->button.button == 1 && !this->space_panning ) {
Geom::Point button_w(event->button.x, event->button.y);
// 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;
@@ -555,8 +532,9 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
} else {
// remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to
// enable Ctrl+doubleclick of exactly the selected item(s)
- if (!(event->button.state & GDK_CONTROL_MASK))
- event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
+ if (!(event->button.state & GDK_CONTROL_MASK)) {
+ this->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
+ }
if (!selection->isEmpty()) {
SnapManager &m = desktop->namedview->snap_manager;
@@ -564,7 +542,8 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
m.unSetup();
}
- rc->origin = button_dt;
+
+ this->origin = button_dt;
}
ret = TRUE;
@@ -572,41 +551,37 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
break;
case GDK_MOTION_NOTIFY:
-
// Mouse move
-
- if ( dragging
- && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning )
- {
+ if ( dragging && ( event->motion.state & GDK_BUTTON1_MASK ) && !this->space_panning ) {
#ifdef DEBUG_MESH
std::cout << "sp_mesh_context_root_handler: GDK_MOTION_NOTIFY: Dragging" << std::endl;
#endif
- 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 ( 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
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to draw, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
- event_context->within_tolerance = false;
+ this->within_tolerance = false;
Geom::Point const motion_w(event->motion.x,
event->motion.y);
- Geom::Point const motion_dt = event_context->desktop->w2d(motion_w);
+ Geom::Point const motion_dt = this->desktop->w2d(motion_w);
if (Inkscape::Rubberband::get(desktop)->is_started()) {
Inkscape::Rubberband::get(desktop)->move(motion_dt);
- event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw around</b> handles to select them"));
+ this->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw around</b> handles to select them"));
} else {
// Create new gradient with coordinates determined by drag.
- sp_mesh_drag(*rc, motion_dt, event->motion.state, event->motion.time);
+ sp_mesh_drag(*this, motion_dt, event->motion.state, event->motion.time);
}
+
gobble_motion_events(GDK_BUTTON1_MASK);
ret = TRUE;
-
} else {
// Not dragging
@@ -616,7 +591,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
m.setup(desktop);
Geom::Point const motion_w(event->motion.x, event->motion.y);
- Geom::Point const motion_dt = event_context->desktop->w2d(motion_w);
+ Geom::Point const motion_dt = this->desktop->w2d(motion_w);
m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE));
m.unSetup();
@@ -631,20 +606,21 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
// Change cursor shape if over line
bool over_line = false;
+
if (drag->lines) {
for (GSList *l = drag->lines; l != NULL; l = l->next) {
- over_line |= sp_mesh_context_is_over_line (rc, (SPItem*) l->data, Geom::Point(event->motion.x, event->motion.y));
+ over_line |= sp_mesh_context_is_over_line (this, (SPItem*) l->data, Geom::Point(event->motion.x, event->motion.y));
}
}
- if (rc->cursor_addnode && !over_line) {
- event_context->cursor_shape = cursor_gradient_xpm;
- sp_event_context_update_cursor(event_context);
- rc->cursor_addnode = false;
- } else if (!rc->cursor_addnode && over_line) {
- event_context->cursor_shape = cursor_gradient_add_xpm;
- sp_event_context_update_cursor(event_context);
- rc->cursor_addnode = true;
+ if (this->cursor_addnode && !over_line) {
+ this->cursor_shape = cursor_gradient_xpm;
+ sp_event_context_update_cursor(this);
+ this->cursor_addnode = false;
+ } else if (!this->cursor_addnode && over_line) {
+ this->cursor_shape = cursor_gradient_add_xpm;
+ sp_event_context_update_cursor(this);
+ this->cursor_addnode = true;
}
}
break;
@@ -655,29 +631,30 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
std::cout << "sp_mesh_context_root_handler: GDK_BUTTON_RELEASE" << std::endl;
#endif
- event_context->xp = event_context->yp = 0;
- if ( event->button.button == 1 && !event_context->space_panning ) {
+ this->xp = this->yp = 0;
+ if ( event->button.button == 1 && !this->space_panning ) {
// Check if over line
bool over_line = false;
SPCtrlLine *line = NULL;
+
if (drag->lines) {
for (GSList *l = drag->lines; (l != NULL) && (!over_line); l = l->next) {
line = (SPCtrlLine*) l->data;
- over_line = sp_mesh_context_is_over_line (rc, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
- if (over_line)
+ over_line = sp_mesh_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
+
+ if (over_line) {
break;
+ }
}
}
if ( (event->button.state & GDK_CONTROL_MASK) && (event->button.state & GDK_MOD1_MASK ) ) {
if (over_line && line) {
- sp_mesh_context_split_near_point(rc, line->item, rc->mousepoint_doc, 0);
+ sp_mesh_context_split_near_point(this, line->item, this->mousepoint_doc, 0);
ret = TRUE;
}
-
} else {
-
dragging = false;
// unless clicked with Ctrl (to enable Ctrl+doubleclick).
@@ -686,29 +663,28 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
break;
}
- if (!event_context->within_tolerance) {
+ if (!this->within_tolerance) {
// we've been dragging, either do nothing (grdrag handles that),
// or rubberband-select if we have rubberband
Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
- if (r->is_started() && !event_context->within_tolerance) {
+
+ if (r->is_started() && !this->within_tolerance) {
// this was a rubberband drag
if (r->getMode() == RUBBERBAND_MODE_RECT) {
Geom::OptRect const b = r->getRectangle();
drag->selectRect(*b);
}
}
-
- } else if (event_context->item_to_select) {
+ } else if (this->item_to_select) {
if (over_line && line) {
// Clicked on an existing mesh line, don't change selection. This stops
// possible change in selection during a double click with overlapping objects
- }
- else {
+ } else {
// no dragging, select clicked item if any
if (event->button.state & GDK_SHIFT_MASK) {
- selection->toggle(event_context->item_to_select);
+ selection->toggle(this->item_to_select);
} else {
- selection->set(event_context->item_to_select);
+ selection->set(this->item_to_select);
}
}
} else {
@@ -720,9 +696,10 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
}
}
- event_context->item_to_select = NULL;
+ this->item_to_select = NULL;
ret = TRUE;
}
+
Inkscape::Rubberband::get(desktop)->stop();
}
break;
@@ -743,7 +720,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_Shift_R:
case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt (at least on my machine)
case GDK_KEY_Meta_R:
- sp_event_show_modifier_tip (event_context->defaultMessageContext(), event,
+ sp_event_show_modifier_tip (this->defaultMessageContext(), event,
_("FIXME<b>Ctrl</b>: snap mesh angle"),
_("FIXME<b>Shift</b>: draw mesh around the starting point"),
NULL);
@@ -763,6 +740,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
} else {
selection->clear();
}
+
ret = TRUE;
//TODO: make dragging escapable by Esc
break;
@@ -771,33 +749,46 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_KP_Left:
case GDK_KEY_KP_4:
if (!MOD__CTRL) { // not ctrl
- gint mul = 1 + gobble_key_events(
- get_group0_keyval(&event->key), 0); // with any mask
+ gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
+
if (MOD__ALT) { // alt
- if (MOD__SHIFT) drag->selected_move_screen(mul*-10, 0); // shift
- else drag->selected_move_screen(mul*-1, 0); // no shift
- }
- else { // no alt
- if (MOD__SHIFT) drag->selected_move(mul*-10*nudge, 0); // shift
- else drag->selected_move(mul*-nudge, 0); // no shift
+ if (MOD__SHIFT) {
+ drag->selected_move_screen(mul*-10, 0); // shift
+ } else {
+ drag->selected_move_screen(mul*-1, 0); // no shift
+ }
+ } else { // no alt
+ if (MOD__SHIFT) {
+ drag->selected_move(mul*-10*nudge, 0); // shift
+ } else {
+ drag->selected_move(mul*-nudge, 0); // no shift
+ }
}
+
ret = TRUE;
}
break;
+
case GDK_KEY_Up: // move handle up
case GDK_KEY_KP_Up:
case GDK_KEY_KP_8:
if (!MOD__CTRL) { // not ctrl
- gint mul = 1 + gobble_key_events(
- get_group0_keyval(&event->key), 0); // with any mask
+ gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
+
if (MOD__ALT) { // alt
- if (MOD__SHIFT) drag->selected_move_screen(0, mul*10); // shift
- else drag->selected_move_screen(0, mul*1); // no shift
- }
- else { // no alt
- if (MOD__SHIFT) drag->selected_move(0, mul*10*nudge); // shift
- else drag->selected_move(0, mul*nudge); // no shift
+ if (MOD__SHIFT) {
+ drag->selected_move_screen(0, mul*10); // shift
+ } else {
+ drag->selected_move_screen(0, mul*1); // no shift
+ }
+ } else { // no alt
+ if (MOD__SHIFT) {
+ drag->selected_move(0, mul*10*nudge); // shift
+ } else {
+ drag->selected_move(0, mul*nudge); // no shift
+ }
}
+
ret = TRUE;
}
break;
@@ -806,16 +797,22 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_KP_Right:
case GDK_KEY_KP_6:
if (!MOD__CTRL) { // not ctrl
- gint mul = 1 + gobble_key_events(
- get_group0_keyval(&event->key), 0); // with any mask
+ gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
+
if (MOD__ALT) { // alt
- if (MOD__SHIFT) drag->selected_move_screen(mul*10, 0); // shift
- else drag->selected_move_screen(mul*1, 0); // no shift
- }
- else { // no alt
- if (MOD__SHIFT) drag->selected_move(mul*10*nudge, 0); // shift
- else drag->selected_move(mul*nudge, 0); // no shift
+ if (MOD__SHIFT) {
+ drag->selected_move_screen(mul*10, 0); // shift
+ } else {
+ drag->selected_move_screen(mul*1, 0); // no shift
+ }
+ } else { // no alt
+ if (MOD__SHIFT) {
+ drag->selected_move(mul*10*nudge, 0); // shift
+ } else {
+ drag->selected_move(mul*nudge, 0); // no shift
+ }
}
+
ret = TRUE;
}
break;
@@ -824,16 +821,22 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_KP_Down:
case GDK_KEY_KP_2:
if (!MOD__CTRL) { // not ctrl
- gint mul = 1 + gobble_key_events(
- get_group0_keyval(&event->key), 0); // with any mask
+ gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
+
if (MOD__ALT) { // alt
- if (MOD__SHIFT) drag->selected_move_screen(0, mul*-10); // shift
- else drag->selected_move_screen(0, mul*-1); // no shift
- }
- else { // no alt
- if (MOD__SHIFT) drag->selected_move(0, mul*-10*nudge); // shift
- else drag->selected_move(0, mul*-nudge); // no shift
+ if (MOD__SHIFT) {
+ drag->selected_move_screen(0, mul*-10); // shift
+ } else {
+ drag->selected_move_screen(0, mul*-1); // no shift
+ }
+ } else { // no alt
+ if (MOD__SHIFT) {
+ drag->selected_move(0, mul*-10*nudge); // shift
+ } else {
+ drag->selected_move(0, mul*-nudge); // no shift
+ }
}
+
ret = TRUE;
}
break;
@@ -860,7 +863,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_b: // Toggle mesh side between lineto and curveto.
case GDK_KEY_B:
if (MOD__ALT && drag->isNonEmpty() && drag->hasSelection()) {
- sp_mesh_context_corner_operation ( rc, MG_CORNER_SIDE_TOGGLE );
+ sp_mesh_context_corner_operation ( this, MG_CORNER_SIDE_TOGGLE );
ret = TRUE;
}
break;
@@ -868,7 +871,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_c: // Convert mesh side from generic Bezier to Bezier approximating arc,
case GDK_KEY_C: // preserving handle direction.
if (MOD__ALT && drag->isNonEmpty() && drag->hasSelection()) {
- sp_mesh_context_corner_operation ( rc, MG_CORNER_SIDE_ARC );
+ sp_mesh_context_corner_operation ( this, MG_CORNER_SIDE_ARC );
ret = TRUE;
}
break;
@@ -876,7 +879,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_g: // Toggle mesh tensor points on/off
case GDK_KEY_G:
if (MOD__ALT && drag->isNonEmpty() && drag->hasSelection()) {
- sp_mesh_context_corner_operation ( rc, MG_CORNER_TENSOR_TOGGLE );
+ sp_mesh_context_corner_operation ( this, MG_CORNER_TENSOR_TOGGLE );
ret = TRUE;
}
break;
@@ -884,7 +887,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_j: // Smooth corner color
case GDK_KEY_J:
if (MOD__ALT && drag->isNonEmpty() && drag->hasSelection()) {
- sp_mesh_context_corner_operation ( rc, MG_CORNER_COLOR_SMOOTH );
+ sp_mesh_context_corner_operation ( this, MG_CORNER_COLOR_SMOOTH );
ret = TRUE;
}
break;
@@ -892,7 +895,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_k: // Pick corner color
case GDK_KEY_K:
if (MOD__ALT && drag->isNonEmpty() && drag->hasSelection()) {
- sp_mesh_context_corner_operation ( rc, MG_CORNER_COLOR_PICK );
+ sp_mesh_context_corner_operation ( this, MG_CORNER_COLOR_PICK );
ret = TRUE;
}
break;
@@ -917,7 +920,7 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
case GDK_KEY_Shift_R:
case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt
case GDK_KEY_Meta_R:
- event_context->defaultMessageContext()->clear();
+ this->defaultMessageContext()->clear();
break;
default:
break;
@@ -928,20 +931,13 @@ gint SPMeshContext::root_handler(GdkEvent* event) {
}
if (!ret) {
-// if (((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler) {
-// ret = ((SPEventContextClass *) sp_mesh_context_parent_class)->root_handler(event_context, event);
-// }
ret = SPEventContext::root_handler(event);
}
return ret;
}
-
-
-static void sp_mesh_drag(SPMeshContext &rc, Geom::Point const /*pt*/, guint /*state*/, guint32 /*etime*/)
-{
-
+static void sp_mesh_drag(SPMeshContext &rc, Geom::Point const /*pt*/, guint /*state*/, guint32 /*etime*/) {
SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop;
Inkscape::Selection *selection = sp_desktop_selection(desktop);
SPDocument *document = sp_desktop_document(desktop);
diff --git a/src/mesh-context.h b/src/mesh-context.h
index 055c85dbe..19614a41b 100644
--- a/src/mesh-context.h
+++ b/src/mesh-context.h
@@ -48,6 +48,9 @@ public:
virtual gint root_handler(GdkEvent* event);
virtual const std::string& getPrefsPath();
+
+private:
+ void selection_changed(Inkscape::Selection* sel);
};
void sp_mesh_context_select_next(SPEventContext *event_context);
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 00f7294be..4281fdc54 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -103,8 +103,8 @@ SPPenContext::SPPenContext() : SPDrawContext() {
event_context->hot_y = 4;
pc->npoints = 0;
- pc->mode = SP_PEN_CONTEXT_MODE_CLICK;
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->mode = MODE_CLICK;
+ pc->state = POINT;
pc->c0 = NULL;
pc->c1 = NULL;
@@ -199,7 +199,7 @@ void SPPenContext::setup() {
static void pen_cancel (SPPenContext *const pc)
{
pc->num_clicks = 0;
- pc->state = SP_PEN_CONTEXT_STOP;
+ pc->state = SPPenContext::STOP;
spdc_reset_colors(pc);
sp_canvas_item_hide(pc->c0);
sp_canvas_item_hide(pc->c1);
@@ -242,9 +242,9 @@ void SPPenContext::set(const Inkscape::Preferences::Entry& val) {
if (name == "mode") {
if ( val.getString() == "drag" ) {
- pc->mode = SP_PEN_CONTEXT_MODE_DRAG;
+ pc->mode = MODE_DRAG;
} else {
- pc->mode = SP_PEN_CONTEXT_MODE_CLICK;
+ pc->mode = MODE_CLICK;
}
}
}
@@ -406,26 +406,26 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w);
switch (pc->mode) {
- case SP_PEN_CONTEXT_MODE_CLICK:
+ case SPPenContext::MODE_CLICK:
// In click mode we add point on release
switch (pc->state) {
- case SP_PEN_CONTEXT_POINT:
- case SP_PEN_CONTEXT_CONTROL:
- case SP_PEN_CONTEXT_CLOSE:
+ case SPPenContext::POINT:
+ case SPPenContext::CONTROL:
+ case SPPenContext::CLOSE:
break;
- case SP_PEN_CONTEXT_STOP:
+ case SPPenContext::STOP:
// This is allowed, if we just canceled curve
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->state = SPPenContext::POINT;
break;
default:
break;
}
break;
- case SP_PEN_CONTEXT_MODE_DRAG:
+ case SPPenContext::MODE_DRAG:
switch (pc->state) {
- case SP_PEN_CONTEXT_STOP:
+ case SPPenContext::STOP:
// This is allowed, if we just canceled curve
- case SP_PEN_CONTEXT_POINT:
+ case SPPenContext::POINT:
if (pc->npoints == 0) {
Geom::Point p;
@@ -481,7 +481,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
p = anchor->dp;
// we hit an anchor, will finish the curve (either with or without closing)
// in release handler
- pc->state = SP_PEN_CONTEXT_CLOSE;
+ pc->state = SPPenContext::CLOSE;
if (pc->green_anchor && pc->green_anchor->active) {
// we clicked on the current curve start, so close it even if
@@ -498,13 +498,13 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const
}
}
- pc->state = pc->polylines_only ? SP_PEN_CONTEXT_POINT : SP_PEN_CONTEXT_CONTROL;
+ pc->state = pc->polylines_only ? SPPenContext::POINT : SPPenContext::CONTROL;
ret = TRUE;
break;
- case SP_PEN_CONTEXT_CONTROL:
+ case SPPenContext::CONTROL:
g_warning("Button down in CONTROL state");
break;
- case SP_PEN_CONTEXT_CLOSE:
+ case SPPenContext::CLOSE:
g_warning("Button down in CLOSE state");
break;
default:
@@ -580,9 +580,9 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons
SPDrawAnchor *anchor = spdc_test_inside(pc, event_w);
switch (pc->mode) {
- case SP_PEN_CONTEXT_MODE_CLICK:
+ case SPPenContext::MODE_CLICK:
switch (pc->state) {
- case SP_PEN_CONTEXT_POINT:
+ case SPPenContext::POINT:
if ( pc->npoints != 0 ) {
// Only set point, if we are already appending
spdc_endpoint_snap(pc, p, mevent.state);
@@ -595,23 +595,23 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons
m.unSetup();
}
break;
- case SP_PEN_CONTEXT_CONTROL:
- case SP_PEN_CONTEXT_CLOSE:
+ case SPPenContext::CONTROL:
+ case SPPenContext::CLOSE:
// Placing controls is last operation in CLOSE state
spdc_endpoint_snap(pc, p, mevent.state);
spdc_pen_set_ctrl(pc, p, mevent.state);
ret = TRUE;
break;
- case SP_PEN_CONTEXT_STOP:
+ case SPPenContext::STOP:
// This is perfectly valid
break;
default:
break;
}
break;
- case SP_PEN_CONTEXT_MODE_DRAG:
+ case SPPenContext::MODE_DRAG:
switch (pc->state) {
- case SP_PEN_CONTEXT_POINT:
+ case SPPenContext::POINT:
if ( pc->npoints > 0 ) {
// Only set point, if we are already appending
@@ -647,8 +647,8 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons
}
}
break;
- case SP_PEN_CONTEXT_CONTROL:
- case SP_PEN_CONTEXT_CLOSE:
+ case SPPenContext::CONTROL:
+ case SPPenContext::CLOSE:
// Placing controls is last operation in CLOSE state
// snap the handle
@@ -662,7 +662,7 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons
gobble_motion_events(GDK_BUTTON1_MASK);
ret = TRUE;
break;
- case SP_PEN_CONTEXT_STOP:
+ case SPPenContext::STOP:
// This is perfectly valid
break;
default:
@@ -706,9 +706,9 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con
SPDrawAnchor *anchor = spdc_test_inside(pc, event_w);
switch (pc->mode) {
- case SP_PEN_CONTEXT_MODE_CLICK:
+ case SPPenContext::MODE_CLICK:
switch (pc->state) {
- case SP_PEN_CONTEXT_POINT:
+ case SPPenContext::POINT:
if ( pc->npoints == 0 ) {
// Start new thread only with button release
if (anchor) {
@@ -723,43 +723,43 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con
p = anchor->dp;
}
}
- pc->state = SP_PEN_CONTEXT_CONTROL;
+ pc->state = SPPenContext::CONTROL;
ret = TRUE;
break;
- case SP_PEN_CONTEXT_CONTROL:
+ case SPPenContext::CONTROL:
// End current segment
spdc_endpoint_snap(pc, p, revent.state);
spdc_pen_finish_segment(pc, p, revent.state);
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->state = SPPenContext::POINT;
ret = TRUE;
break;
- case SP_PEN_CONTEXT_CLOSE:
+ case SPPenContext::CLOSE:
// End current segment
if (!anchor) { // Snap node only if not hitting anchor
spdc_endpoint_snap(pc, p, revent.state);
}
spdc_pen_finish_segment(pc, p, revent.state);
spdc_pen_finish(pc, TRUE);
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->state = SPPenContext::POINT;
ret = TRUE;
break;
- case SP_PEN_CONTEXT_STOP:
+ case SPPenContext::STOP:
// This is allowed, if we just canceled curve
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->state = SPPenContext::POINT;
ret = TRUE;
break;
default:
break;
}
break;
- case SP_PEN_CONTEXT_MODE_DRAG:
+ case SPPenContext::MODE_DRAG:
switch (pc->state) {
- case SP_PEN_CONTEXT_POINT:
- case SP_PEN_CONTEXT_CONTROL:
+ case SPPenContext::POINT:
+ case SPPenContext::CONTROL:
spdc_endpoint_snap(pc, p, revent.state);
spdc_pen_finish_segment(pc, p, revent.state);
break;
- case SP_PEN_CONTEXT_CLOSE:
+ case SPPenContext::CLOSE:
spdc_endpoint_snap(pc, p, revent.state);
spdc_pen_finish_segment(pc, p, revent.state);
if (pc->green_closed) {
@@ -770,13 +770,13 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con
spdc_pen_finish(pc, FALSE);
}
break;
- case SP_PEN_CONTEXT_STOP:
+ case SPPenContext::STOP:
// This is allowed, if we just cancelled curve
break;
default:
break;
}
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->state = SPPenContext::POINT;
ret = TRUE;
break;
default:
@@ -1118,7 +1118,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
sp_canvas_item_hide(pc->c1);
sp_canvas_item_hide(pc->cl0);
sp_canvas_item_hide(pc->cl1);
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->state = SPPenContext::POINT;
spdc_pen_set_subsequent_point(pc, pt, true);
pen_last_paraxial_dir = !pen_last_paraxial_dir;
ret = TRUE;
@@ -1252,8 +1252,8 @@ static void spdc_pen_set_ctrl(SPPenContext *const pc, Geom::Point const p, guint
sp_canvas_item_show(pc->c0);
sp_canvas_item_show(pc->cl0);
bool is_symm = false;
- if ( ( ( pc->mode == SP_PEN_CONTEXT_MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) ||
- ( ( pc->mode == SP_PEN_CONTEXT_MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) {
+ if ( ( ( pc->mode == SPPenContext::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) ||
+ ( ( pc->mode == SPPenContext::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) {
Geom::Point delta = p - pc->p[3];
pc->p[2] = pc->p[3] - delta;
is_symm = true;
@@ -1323,7 +1323,7 @@ static void spdc_pen_finish(SPPenContext *const pc, gboolean const closed)
pc->ea = NULL;
pc->npoints = 0;
- pc->state = SP_PEN_CONTEXT_POINT;
+ pc->state = SPPenContext::POINT;
sp_canvas_item_hide(pc->c0);
sp_canvas_item_hide(pc->c1);
diff --git a/src/pen-context.h b/src/pen-context.h
index a5f87507c..f8549035b 100644
--- a/src/pen-context.h
+++ b/src/pen-context.h
@@ -11,18 +11,6 @@
#define SP_PEN_CONTEXT(obj) ((SPPenContext*)obj)
#define SP_IS_PEN_CONTEXT(obj) (dynamic_cast<const SPPenContext*>((const SPEventContext*)obj))
-enum {
- SP_PEN_CONTEXT_POINT,
- SP_PEN_CONTEXT_CONTROL,
- SP_PEN_CONTEXT_CLOSE,
- SP_PEN_CONTEXT_STOP
-};
-
-enum {
- SP_PEN_CONTEXT_MODE_CLICK,
- SP_PEN_CONTEXT_MODE_DRAG
-};
-
struct SPCtrlLine;
/**
@@ -33,14 +21,26 @@ public:
SPPenContext();
virtual ~SPPenContext();
+ enum Mode {
+ MODE_CLICK,
+ MODE_DRAG
+ };
+
+ enum State {
+ POINT,
+ CONTROL,
+ CLOSE,
+ STOP
+ };
+
Geom::Point p[5];
/** \invar npoints in {0, 2, 5}. */
// npoints somehow determines the type of the node (what does it mean, exactly? the number of Bezier handles?)
gint npoints;
- unsigned int mode : 1;
- unsigned int state : 2;
+ Mode mode;
+ State state;
bool polylines_only;
bool polylines_paraxial;
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index 42e6c4452..441b573f0 100644
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
@@ -74,7 +74,6 @@ SPRectContext::SPRectContext() : SPEventContext() {
this->tolerance = 0;
this->within_tolerance = false;
this->item_to_select = NULL;
- //this->tool_url = "/tools/shapes/rect";
this->rect = NULL;
@@ -83,9 +82,7 @@ SPRectContext::SPRectContext() : SPEventContext() {
}
void SPRectContext::finish() {
- SPDesktop *desktop = this->desktop;
-
- sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
+ sp_canvas_item_ungrab(SP_CANVAS_ITEM(this->desktop->acetate), GDK_CURRENT_TIME);
this->finishItem();
this->sel_changed_connection.disconnect();
@@ -163,8 +160,6 @@ void SPRectContext::set(const Inkscape::Preferences::Entry& val) {
}
gint SPRectContext::item_handler(SPItem* item, GdkEvent* event) {
- SPDesktop *desktop = this->desktop;
-
gint ret = FALSE;
switch (event->type) {
@@ -179,11 +174,9 @@ gint SPRectContext::item_handler(SPItem* item, GdkEvent* event) {
break;
}
-// if (((SPEventContextClass *) sp_rect_context_parent_class)->item_handler) {
-// ret = ((SPEventContextClass *) sp_rect_context_parent_class)->item_handler(event_context, item, event);
-// }
- // CPPIFY: ret is always overwritten...
- ret = SPEventContext::item_handler(item, event);
+ if (!ret) {
+ ret = SPEventContext::item_handler(item, event);
+ }
return ret;
}
diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp
index d16f16a9b..519b7ba6e 100644
--- a/src/sp-rect.cpp
+++ b/src/sp-rect.cpp
@@ -113,8 +113,6 @@ void SPRect::set(unsigned key, gchar const *value) {
void SPRect::update(SPCtx* ctx, unsigned int flags) {
if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
- SPStyle *style = this->style;
-
SPItemCtx const *ictx = (SPItemCtx const *) ctx;
double const w = ictx->viewport.width();
diff --git a/src/sp-rect.h b/src/sp-rect.h
index c04d57660..12f94a744 100644
--- a/src/sp-rect.h
+++ b/src/sp-rect.h
@@ -51,17 +51,17 @@ public:
virtual void build(SPDocument* doc, Inkscape::XML::Node* repr);
- void set(unsigned key, gchar const *value);
- void update(SPCtx* ctx, unsigned int flags);
+ virtual void set(unsigned key, gchar const *value);
+ virtual void update(SPCtx* ctx, unsigned int flags);
virtual Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags);
virtual gchar* description();
- void set_shape();
+ virtual void set_shape();
virtual Geom::Affine set_transform(Geom::Affine const& xform);
- void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
- void convert_to_guides();
+ virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
+ virtual void convert_to_guides();
SVGLength x;
SVGLength y;