diff --git a/src/arc-context.cpp b/src/arc-context.cpp
index 50d348e7b408783396df625a64333732bef6604f..799167a72a156528d79b5536a604c9d3bb8c75aa 100644 (file)
--- a/src/arc-context.cpp
+++ b/src/arc-context.cpp
#include "desktop-style.h"
#include "context-fns.h"
#include "verbs.h"
+#include "shape-editor.h"
+#include "event-context.h"
#include "arc-context.h"
static void sp_arc_context_dispose(GObject *object);
static void sp_arc_context_setup(SPEventContext *ec);
+static void sp_arc_context_finish(SPEventContext *ec);
static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent *event);
static gint sp_arc_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
static void sp_arc_drag(SPArcContext *ec, Geom::Point pt, guint state);
static void sp_arc_finish(SPArcContext *ec);
+static void sp_arc_cancel(SPArcContext *ec);
static SPEventContextClass *parent_class;
object_class->dispose = sp_arc_context_dispose;
event_context_class->setup = sp_arc_context_setup;
+ event_context_class->finish = sp_arc_context_finish;
event_context_class->root_handler = sp_arc_context_root_handler;
event_context_class->item_handler = sp_arc_context_item_handler;
}
event_context->within_tolerance = false;
event_context->item_to_select = NULL;
- event_context->shape_repr = NULL;
- event_context->shape_knot_holder = NULL;
-
arc_context->item = NULL;
new (&arc_context->sel_changed_connection) sigc::connection();
}
+static void sp_arc_context_finish(SPEventContext *ec)
+{
+ SPArcContext *ac = SP_ARC_CONTEXT(ec);
+ SPDesktop *desktop = ec->desktop;
+
+ sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
+ sp_arc_finish(ac);
+ ac->sel_changed_connection.disconnect();
+
+ if (((SPEventContextClass *) parent_class)->finish) {
+ ((SPEventContextClass *) parent_class)->finish(ec);
+ }
+}
+
static void sp_arc_context_dispose(GObject *object)
{
SPEventContext *ec = SP_EVENT_CONTEXT(object);
ac->sel_changed_connection.disconnect();
ac->sel_changed_connection.~connection();
- if (ec->shape_knot_holder) {
- delete ec->shape_knot_holder;
- ec->shape_knot_holder = NULL;
- }
-
- if (ec->shape_repr) { // remove old listener
- sp_repr_remove_listener_by_data(ec->shape_repr, ec);
- Inkscape::GC::release(ec->shape_repr);
- ec->shape_repr = 0;
- }
+ delete ec->shape_editor;
+ ec->shape_editor = NULL;
/* fixme: This is necessary because we do not grab */
if (ac->item) {
G_OBJECT_CLASS(parent_class)->dispose(object);
}
-static Inkscape::XML::NodeEventVector ec_shape_repr_events = {
- NULL, /* child_added */
- NULL, /* child_removed */
- ec_shape_event_attr_changed,
- NULL, /* content_changed */
- NULL /* order_changed */
-};
-
/**
\brief Callback that processes the "changed" signal on the selection;
destroys old and creates new knotholder.
@@ -159,27 +159,9 @@ void sp_arc_context_selection_changed(Inkscape::Selection * selection, gpointer
SPArcContext *ac = SP_ARC_CONTEXT(data);
SPEventContext *ec = SP_EVENT_CONTEXT(ac);
- if (ec->shape_knot_holder) { // desktroy knotholder
- delete ec->shape_knot_holder;
- ec->shape_knot_holder = NULL;
- }
-
- if (ec->shape_repr) { // remove old listener
- sp_repr_remove_listener_by_data(ec->shape_repr, ec);
- Inkscape::GC::release(ec->shape_repr);
- ec->shape_repr = 0;
- }
-
- SPItem *item = selection ? selection->singleItem() : NULL;
- if (item) {
- ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
- Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
- if (shape_repr) {
- ec->shape_repr = shape_repr;
- Inkscape::GC::anchor(shape_repr);
- sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
- }
- }
+ ec->shape_editor->unset_item(SH_KNOTHOLDER);
+ SPItem *item = selection->singleItem();
+ ec->shape_editor->set_item(item, SH_KNOTHOLDER);
}
static void sp_arc_context_setup(SPEventContext *ec)
((SPEventContextClass *) parent_class)->setup(ec);
}
- SPItem *item = selection->singleItem();
+ ec->shape_editor = new ShapeEditor(ec->desktop);
+ SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
if (item) {
- ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
- Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
- if (shape_repr) {
- ec->shape_repr = shape_repr;
- Inkscape::GC::anchor(shape_repr);
- sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
- }
+ ec->shape_editor->set_item(item, SH_KNOTHOLDER);
}
ac->sel_changed_connection.disconnect();
@@ -263,13 +240,11 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
dragging = true;
ac->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
-
+
/* Snap center */
SnapManager &m = desktop->namedview->snap_manager;
m.setup(desktop);
- Geom::Point pt2g = to_2geom(ac->center);
- m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g);
- ac->center = from_2geom(pt2g);
+ m.freeSnapReturnByRef(ac->center, Inkscape::SNAPSOURCE_NODE_HANDLE);
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -293,21 +268,29 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
Geom::Point const motion_w(event->motion.x, event->motion.y);
Geom::Point motion_dt(desktop->w2d(motion_w));
-
+
sp_arc_drag(ac, motion_dt, event->motion.state);
gobble_motion_events(GDK_BUTTON1_MASK);
ret = TRUE;
+ } else if (!sp_event_context_knot_mouseover(ac)){
+ SnapManager &m = desktop->namedview->snap_manager;
+ m.setup(desktop);
+
+ Geom::Point const motion_w(event->motion.x, event->motion.y);
+ Geom::Point motion_dt(desktop->w2d(motion_w));
+ m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE));
}
break;
case GDK_BUTTON_RELEASE:
event_context->xp = event_context->yp = 0;
if (event->button.button == 1 && !event_context->space_panning) {
dragging = false;
+ sp_event_context_discard_delayed_snap_event(event_context);
if (!event_context->within_tolerance) {
// we've been dragging, finish the arc
- sp_arc_finish(ac);
+ sp_arc_finish(ac);
} else if (event_context->item_to_select) {
// no dragging, select clicked item if any
if (event->button.state & GDK_SHIFT_MASK) {
@@ -359,17 +342,22 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
}
break;
case GDK_Escape:
- sp_desktop_selection(desktop)->clear();
- //TODO: make dragging escapable by Esc
+ if (dragging) {
+ dragging = false;
+ sp_event_context_discard_delayed_snap_event(event_context);
+ // if drawing, cancel, otherwise pass it up for deselecting
+ sp_arc_cancel(ac);
+ ret = TRUE;
+ }
break;
-
case GDK_space:
if (dragging) {
sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
event->button.time);
dragging = false;
+ sp_event_context_discard_delayed_snap_event(event_context);
if (!event_context->within_tolerance) {
- // we've been dragging, finish the rect
+ // we've been dragging, finish the arc
sp_arc_finish(ac);
}
// do not return true, so that space would work switching to selector
ac->item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
Inkscape::GC::release(repr);
- ac->item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
+ ac->item->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
ac->item->updateRepr();
sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
ac->_message_context->clear();
if (ac->item != NULL) {
+
+ SPGenericEllipse *ge = SP_GENERICELLIPSE(SP_ARC(ac->item));
+ if (ge->rx.computed == 0 || ge->ry.computed == 0) {
+ sp_arc_cancel(ac); // Don't allow the creating of zero sized arc, for example when the start and and point snap to the snap grid point
+ return;
+ }
+
SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop;
SP_OBJECT(ac->item)->updateRepr();
sp_canvas_end_forced_full_redraws(desktop->canvas);
-
+
sp_desktop_selection(desktop)->set(ac->item);
- sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC,
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ARC,
_("Create ellipse"));
ac->item = NULL;
}
}
+static void sp_arc_cancel(SPArcContext *ac)
+{
+ SPDesktop *desktop = SP_EVENT_CONTEXT(ac)->desktop;
+
+ sp_desktop_selection(desktop)->clear();
+ sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), 0);
+
+ if (ac->item != NULL) {
+ SP_OBJECT(ac->item)->deleteObject();
+ ac->item = NULL;
+ }
+
+ ac->within_tolerance = false;
+ ac->xp = 0;
+ ac->yp = 0;
+ ac->item_to_select = NULL;
+
+ sp_canvas_end_forced_full_redraws(desktop->canvas);
+
+ sp_document_cancel(sp_desktop_document(desktop));
+}
+
/*
Local Variables: