X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fstar-context.cpp;h=9dc2db296dcb978d09c40f14b2d9edf518051107;hb=ea479a317d3fb2890308a1cc99ee730dd7b76de8;hp=824fd53a4085e1badeb9133f2c41eee90dbb9fac;hpb=ed70cc908f7fe9d5f2d86042e3fe1f758984c03a;p=inkscape.git diff --git a/src/star-context.cpp b/src/star-context.cpp index 824fd53a4..9dc2db296 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -38,11 +38,12 @@ #include "pixmaps/cursor-star.xpm" #include "sp-metrics.h" #include -#include "prefs-utils.h" +#include "preferences.h" #include "xml/repr.h" #include "xml/node-event-vector.h" #include "object-edit.h" #include "context-fns.h" +#include "shape-editor.h" #include "star-context.h" @@ -51,10 +52,10 @@ static void sp_star_context_init (SPStarContext * star_context); static void sp_star_context_dispose (GObject *object); static void sp_star_context_setup (SPEventContext *ec); -static void sp_star_context_set (SPEventContext *ec, const gchar *key, const gchar *val); +static void sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val); static gint sp_star_context_root_handler (SPEventContext *ec, GdkEvent *event); -static void sp_star_drag (SPStarContext * sc, NR::Point p, guint state); +static void sp_star_drag (SPStarContext * sc, Geom::Point p, guint state); static void sp_star_finish (SPStarContext * sc); static SPEventContextClass * parent_class; @@ -108,9 +109,6 @@ sp_star_context_init (SPStarContext * star_context) event_context->within_tolerance = false; event_context->item_to_select = NULL; - event_context->shape_repr = NULL; - event_context->shape_knot_holder = NULL; - star_context->item = NULL; star_context->magnitude = 5; @@ -131,16 +129,8 @@ sp_star_context_dispose (GObject *object) sc->sel_changed_connection.disconnect(); sc->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 (sc->item) sp_star_finish (sc); @@ -152,14 +142,6 @@ sp_star_context_dispose (GObject *object) 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 @@ -173,27 +155,9 @@ sp_star_context_selection_changed (Inkscape::Selection * selection, gpointer dat SPStarContext *sc = SP_STAR_CONTEXT (data); SPEventContext *ec = SP_EVENT_CONTEXT (sc); - 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->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->unset_item(SH_KNOTHOLDER); + SPItem *item = selection->singleItem(); + ec->shape_editor->set_item(item, SH_KNOTHOLDER); } static void @@ -210,27 +174,23 @@ sp_star_context_setup (SPEventContext *ec) sp_event_context_read (ec, "rounded"); sp_event_context_read (ec, "randomized"); - Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); + ec->shape_editor = new ShapeEditor(ec->desktop); - SPItem *item = selection->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); - } - } + SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); + if (item) { + ec->shape_editor->set_item(item, SH_KNOTHOLDER); + } + Inkscape::Selection *selection = sp_desktop_selection(ec->desktop); sc->sel_changed_connection.disconnect(); sc->sel_changed_connection = selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_star_context_selection_changed), (gpointer)sc)); - if (prefs_get_int_attribute("tools.shapes", "selcue", 0) != 0) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/tools/shapes/selcue")) { ec->enableSelectionCue(); } - if (prefs_get_int_attribute("tools.shapes", "gradientdrag", 0) != 0) { + if (prefs->getBool("/tools/shapes/gradientdrag")) { ec->enableGrDrag(); } @@ -238,24 +198,21 @@ sp_star_context_setup (SPEventContext *ec) } static void -sp_star_context_set (SPEventContext *ec, const gchar *key, const gchar *val) +sp_star_context_set (SPEventContext *ec, Inkscape::Preferences::Entry *val) { SPStarContext *sc = SP_STAR_CONTEXT (ec); - if (!strcmp (key, "magnitude")) { - sc->magnitude = (val) ? atoi (val) : 5; - sc->magnitude = CLAMP (sc->magnitude, 3, 1024); - } else if (!strcmp (key, "proportion")) { - sc->proportion = (val) ? g_ascii_strtod (val, NULL) : 0.5; - sc->proportion = CLAMP (sc->proportion, 0.01, 2.0); - } else if (!strcmp (key, "isflatsided")) { - if (val && !strcmp(val, "true")) - sc->isflatsided = true; - else - sc->isflatsided = false; - } else if (!strcmp (key, "rounded")) { - sc->rounded = (val) ? g_ascii_strtod (val, NULL) : 0.0; - } else if (!strcmp (key, "randomized")) { - sc->randomized = (val) ? g_ascii_strtod (val, NULL) : 0.0; + Glib::ustring path = val->getEntryName(); + + if (path == "magnitude") { + sc->magnitude = CLAMP (val->getInt(5), 3, 1024); + } else if (path == "proportion") { + sc->proportion = CLAMP (val->getDouble(0.5), 0.01, 2.0); + } else if (path == "isflatsided") { + sc->isflatsided = val->getBool(); + } else if (path == "rounded") { + sc->rounded = val->getDouble(); + } else if (path == "randomized") { + sc->randomized = val->getDouble(); } } @@ -265,10 +222,11 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent SPDesktop *desktop = event_context->desktop; Inkscape::Selection *selection = sp_desktop_selection (desktop); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPStarContext *sc = SP_STAR_CONTEXT (event_context); - event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100); + event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); gint ret = FALSE; @@ -282,9 +240,9 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent /* Snap center */ SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, NULL); //null, because we don't have an item yet + m.setup(desktop, true); Geom::Point pt2g = to_2geom(sc->center); - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); + m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g); sc->center = from_2geom(pt2g); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), @@ -309,8 +267,8 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent // motion notify coordinates as given (no snapping back to origin) event_context->within_tolerance = false; - NR::Point const motion_w(event->motion.x, event->motion.y); - NR::Point motion_dt(desktop->w2d(motion_w)); + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point motion_dt(desktop->w2d(motion_w)); sp_star_drag (sc, motion_dt, event->motion.state); @@ -422,11 +380,12 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent return ret; } -static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state) +static void sp_star_drag(SPStarContext *sc, Geom::Point p, guint state) { SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; - int const snaps = prefs_get_int_attribute ("options.rotationsnapsperpi", "value", 12); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); if (!sc->item) { @@ -440,11 +399,11 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state) repr->setAttribute("sodipodi:type", "star"); /* Set style */ - sp_desktop_apply_style_tool(desktop, repr, "tools.shapes.star", false); + sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/star", false); sc->item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); Inkscape::GC::release(repr); - sc->item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer()); + sc->item->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse(); sc->item->updateRepr(); sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5); @@ -452,12 +411,12 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state) /* Snap corner point with no constraints */ SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, sc->item); + m.setup(desktop, true, sc->item); Geom::Point pt2g = to_2geom(p); - m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g); + m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g); - Geom::Point const p0 = to_2geom(sp_desktop_dt2root_xy_point(desktop, sc->center)); - Geom::Point const p1 = to_2geom(sp_desktop_dt2root_xy_point(desktop, from_2geom(pt2g))); + Geom::Point const p0 = to_2geom(sp_desktop_dt2doc_xy_point(desktop, sc->center)); + Geom::Point const p1 = to_2geom(sp_desktop_dt2doc_xy_point(desktop, from_2geom(pt2g))); SPStar *star = SP_STAR(sc->item);