diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop-events.cpp | 58 | ||||
| -rw-r--r-- | src/guide-snapper.cpp | 2 | ||||
| -rw-r--r-- | src/snap.cpp | 2 | ||||
| -rw-r--r-- | src/sp-guide-constraint.h | 2 | ||||
| -rw-r--r-- | src/sp-guide.cpp | 203 | ||||
| -rw-r--r-- | src/sp-guide.h | 73 | ||||
| -rw-r--r-- | src/sp-item-notify-moveto.cpp | 2 | ||||
| -rw-r--r-- | src/sp-namedview.cpp | 16 | ||||
| -rw-r--r-- | src/ui/dialog/guides.cpp | 21 |
9 files changed, 165 insertions, 214 deletions
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 332de3630..91023d213 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -295,7 +295,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) // here must be exactly on the guide line though, otherwise // small errors will occur once we snap, see // https://bugs.launchpad.net/inkscape/+bug/333762 - drag_origin = Geom::projection(event_dt, Geom::Line(guide->point_on_line, guide->angle())); + drag_origin = Geom::projection(event_dt, Geom::Line(guide->getPoint(), guide->angle())); if (event->button.state & GDK_SHIFT_MASK) { // with shift we rotate the guide @@ -336,7 +336,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) // be forced to be on the guide. If we don't snap however, then // the origin should still be constrained to the guide. So let's do // that explicitly first: - Geom::Line line(guide->point_on_line, guide->angle()); + Geom::Line line(guide->getPoint(), guide->angle()); Geom::Coord t = line.nearestPoint(motion_dt); motion_dt = line.pointAt(t); if (!(event->motion.state & GDK_SHIFT_MASK)) { @@ -344,10 +344,15 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) { // cannot use shift here to disable snapping, because we already use it for rotating the guide + Geom::Point temp; if (drag_type == SP_DRAG_ROTATE) { - m.guideFreeSnap(motion_dt, guide->point_on_line, true, false); + temp = guide->getPoint(); + m.guideFreeSnap(motion_dt, temp, true, false); + guide->moveto(temp, false); } else { - m.guideFreeSnap(motion_dt, guide->normal_to_line, false, true); + temp = guide->getNormal(); + m.guideFreeSnap(motion_dt, temp, false, true); + guide->set_normal(temp, false); } } m.unSetup(); @@ -355,12 +360,12 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) switch (drag_type) { case SP_DRAG_TRANSLATE: { - sp_guide_moveto(*guide, motion_dt, false); + guide->moveto(motion_dt, false); break; } case SP_DRAG_ROTATE: { - Geom::Point pt = motion_dt - guide->point_on_line; + Geom::Point pt = motion_dt - guide->getPoint(); Geom::Angle angle(pt); if (event->motion.state & GDK_CONTROL_MASK) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -368,7 +373,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) bool const relative_snaps = prefs->getBool("/options/relativeguiderotationsnap/value", false); if (snaps) { if (relative_snaps) { - Geom::Angle orig_angle(guide->normal_to_line); + Geom::Angle orig_angle(guide->getNormal()); Geom::Angle snap_angle = angle - orig_angle; double sections = floor(snap_angle.radians0() * snaps / M_PI + .5); angle = (M_PI / snaps) * sections + orig_angle.radians0(); @@ -378,16 +383,16 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } } } - sp_guide_set_normal(*guide, Geom::Point::polar(angle).cw(), false); + guide->set_normal(Geom::Point::polar(angle).cw(), false); break; } case SP_DRAG_MOVE_ORIGIN: { - sp_guide_moveto(*guide, motion_dt, false); + guide->moveto(motion_dt, false); break; } case SP_DRAG_NONE: - g_assert_not_reached(); + assert(false); break; } moved = true; @@ -412,7 +417,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) // be forced to be on the guide. If we don't snap however, then // the origin should still be constrained to the guide. So let's // do that explicitly first: - Geom::Line line(guide->point_on_line, guide->angle()); + Geom::Line line(guide->getPoint(), guide->angle()); Geom::Coord t = line.nearestPoint(event_dt); event_dt = line.pointAt(t); if (!(event->button.state & GDK_SHIFT_MASK)) { @@ -420,10 +425,15 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } } else if (!((drag_type == SP_DRAG_ROTATE) && (event->motion.state & GDK_CONTROL_MASK))) { // cannot use shift here to disable snapping, because we already use it for rotating the guide + Geom::Point temp; if (drag_type == SP_DRAG_ROTATE) { - m.guideFreeSnap(event_dt, guide->point_on_line, true, false); + temp = guide->getPoint(); + m.guideFreeSnap(event_dt, temp, true, false); + guide->moveto(temp, false); } else { - m.guideFreeSnap(event_dt, guide->normal_to_line, false, true); + temp = guide->getNormal(); + m.guideFreeSnap(event_dt, temp, false, true); + guide->set_normal(temp, false); } } m.unSetup(); @@ -432,12 +442,12 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) switch (drag_type) { case SP_DRAG_TRANSLATE: { - sp_guide_moveto(*guide, event_dt, true); + guide->moveto(event_dt, true); break; } case SP_DRAG_ROTATE: { - Geom::Point pt = event_dt - guide->point_on_line; + Geom::Point pt = event_dt - guide->getPoint(); Geom::Angle angle(pt); if (event->motion.state & GDK_CONTROL_MASK) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -445,7 +455,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) bool const relative_snaps = prefs->getBool("/options/relativeguiderotationsnap/value", false); if (snaps) { if (relative_snaps) { - Geom::Angle orig_angle(guide->normal_to_line); + Geom::Angle orig_angle(guide->getNormal()); Geom::Angle snap_angle = angle - orig_angle; double sections = floor(snap_angle.radians0() * snaps / M_PI + .5); angle = (M_PI / snaps) * sections + orig_angle.radians0(); @@ -455,24 +465,24 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) } } } - sp_guide_set_normal(*guide, Geom::Point::polar(angle).cw(), true); + guide->set_normal(Geom::Point::polar(angle).cw(), true); break; } case SP_DRAG_MOVE_ORIGIN: { - sp_guide_moveto(*guide, event_dt, true); + guide->moveto(event_dt, true); break; } case SP_DRAG_NONE: - g_assert_not_reached(); + assert(false); break; } DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, _("Move guide")); } else { /* Undo movement of any attached shapes. */ - sp_guide_moveto(*guide, guide->point_on_line, false); - sp_guide_set_normal(*guide, guide->normal_to_line, false); + guide->moveto(guide->getPoint(), false); + guide->set_normal(guide->getNormal(), false); sp_guide_remove(guide); DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, _("Delete guide")); @@ -487,7 +497,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) break; case GDK_ENTER_NOTIFY: { - sp_guideline_set_color(SP_GUIDELINE(item), guide->hicolor); + sp_guideline_set_color(SP_GUIDELINE(item), guide->getHiColor()); // set move or rotate cursor Geom::Point const event_w(event->crossing.x, event->crossing.y); @@ -512,13 +522,13 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) #endif } - char *guide_description = sp_guide_description(guide); + char *guide_description = guide->description(); desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, _("<b>Guideline</b>: %s"), guide_description); g_free(guide_description); break; } case GDK_LEAVE_NOTIFY: - sp_guideline_set_color(SP_GUIDELINE(item), guide->color); + sp_guideline_set_color(SP_GUIDELINE(item), guide->getColor()); // restore event context's cursor gdk_window_set_cursor(gtk_widget_get_window (GTK_WIDGET(sp_desktop_canvas(desktop))), desktop->event_context->cursor); diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index 20c95459d..960caed67 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -48,7 +48,7 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Poi for (GSList const *l = _snapmanager->getNamedView()->guides; l != NULL; l = l->next) { SPGuide const *g = SP_GUIDE(l->data); if (g != guide_to_ignore) { - s.push_back(std::make_pair(g->normal_to_line, g->point_on_line)); + s.push_back(std::pair<Geom::Point, Geom::Point>(g->getNormal(), g->getPoint())); } } diff --git a/src/snap.cpp b/src/snap.cpp index fb87aae6b..8138e4546 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -430,7 +430,7 @@ void SnapManager::guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) Inkscape::SnapCandidatePoint candidate(p, Inkscape::SNAPSOURCE_GUIDE_ORIGIN, Inkscape::SNAPTARGET_UNDEFINED); IntermSnapResults isr; - Inkscape::Snapper::SnapConstraint cl(guideline.point_on_line, Geom::rot90(guideline.normal_to_line)); + Inkscape::Snapper::SnapConstraint cl(guideline.getPoint(), Geom::rot90(guideline.getNormal())); SnapperList snappers = getSnappers(); for (SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); ++i) { diff --git a/src/sp-guide-constraint.h b/src/sp-guide-constraint.h index ebc3b01ce..29f47f45a 100644 --- a/src/sp-guide-constraint.h +++ b/src/sp-guide-constraint.h @@ -29,10 +29,8 @@ public: } }; - #endif // SEEN_SP_GUIDE_CONSTRAINT_H - /* Local Variables: mode:c++ diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 0e83c2acf..695dab6ed 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -46,15 +46,6 @@ using Inkscape::DocumentUndo; using std::vector; -//enum { -// PROP_0, -// PROP_COLOR, -// PROP_HICOLOR -//}; -// -//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); - #include "sp-factory.h" namespace { @@ -65,51 +56,15 @@ namespace { bool guideRegistered = SPFactory::instance().registerObject("sodipodi:guide", createGuide); } -//static void sp_guide_class_init(SPGuideClass *gc) -//{ -// GObjectClass *gobject_class = (GObjectClass *) gc; -// -// gobject_class->set_property = sp_guide_set_property; -// gobject_class->get_property = sp_guide_get_property; -// -// g_object_class_install_property(gobject_class, -// PROP_COLOR, -// g_param_spec_uint("color", "Color", "Color", -// 0, -// 0xffffffff, -// 0xff000000, -// (GParamFlags) G_PARAM_READWRITE)); -// -// g_object_class_install_property(gobject_class, -// PROP_HICOLOR, -// g_param_spec_uint("hicolor", "HiColor", "HiColor", -// 0, -// 0xffffffff, -// 0xff000000, -// (GParamFlags) G_PARAM_READWRITE)); -//} -// CPPIFY: properties! - -SPGuide::SPGuide() : SPObject() { - this->label = NULL; - this->views = NULL; - - this->normal_to_line = Geom::Point(0.,1.); - this->point_on_line = Geom::Point(0.,0.); - this->color = 0x0000ff7f; - this->hicolor = 0xff00007f; -} - -SPGuide::~SPGuide() { -} - -guint32 SPGuide::getColor() const { - return color; -} - -guint32 SPGuide::getHiColor() const { - return hicolor; -} +SPGuide::SPGuide() + : SPObject() + , label(NULL) + , views(NULL) + , normal_to_line(Geom::Point(0.,1.)) + , point_on_line(Geom::Point(0.,0.)) + , color(0x0000ff7f) + , hicolor(0xff00007f) +{} void SPGuide::setColor(guint32 c) { color = c; @@ -119,42 +74,6 @@ void SPGuide::setColor(guint32 c) { } } -void SPGuide::setHiColor(guint32 h) { - this->hicolor = h; -} - -//static void sp_guide_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec */*pspec*/) -//{ -// SPGuide &guide = *SP_GUIDE(object); -// -// switch (prop_id) { -// case PROP_COLOR: -// guide.color = g_value_get_uint(value); -// for (GSList *l = guide.views; l != NULL; l = l->next) { -// sp_guideline_set_color(SP_GUIDELINE(l->data), guide.color); -// } -// break; -// -// case PROP_HICOLOR: -// guide.hicolor = g_value_get_uint(value); -// break; -// } -//} -// -//static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec */*pspec*/) -//{ -// SPGuide const &guide = *SP_GUIDE(object); -// -// switch (prop_id) { -// case PROP_COLOR: -// g_value_set_uint(value, guide.color); -// break; -// case PROP_HICOLOR: -// g_value_set_uint(value, guide.hicolor); -// break; -// } -//} - void SPGuide::build(SPDocument *document, Inkscape::XML::Node *repr) { SPObject::build(document, repr); @@ -191,7 +110,7 @@ void SPGuide::set(unsigned int key, const gchar *value) { this->label = NULL; } - sp_guide_set_label(*this, this->label, false); + this->set_label(this->label, false); break; case SP_ATTR_ORIENTATION: { @@ -218,7 +137,7 @@ void SPGuide::set(unsigned int key, const gchar *value) { // default to vertical line for bad arguments this->normal_to_line = Geom::Point(1., 0.); } - sp_guide_set_normal(*this, this->normal_to_line, false); + this->set_normal(this->normal_to_line, false); } break; case SP_ATTR_POSITION: @@ -246,7 +165,7 @@ void SPGuide::set(unsigned int key, const gchar *value) { } // update position in non-committing way // fixme: perhaps we need to add an update method instead, and request_update here - sp_guide_moveto(*this, this->point_on_line, false); + this->moveto(this->point_on_line, false); } break; default: @@ -325,6 +244,14 @@ void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) views = g_slist_prepend(views, item); } +void SPGuide::showSPGuide() +{ + for (GSList *v = views; v != NULL; v = v->next) { + sp_canvas_item_show(SP_CANVAS_ITEM(v->data)); + sp_canvas_item_show(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin)); + } +} + void SPGuide::hideSPGuide(SPCanvas *canvas) { g_assert(canvas != NULL); @@ -338,7 +265,15 @@ void SPGuide::hideSPGuide(SPCanvas *canvas) } } - g_assert_not_reached(); + assert(false); +} + +void SPGuide::hideSPGuide() +{ + for (GSList *v = views; v != NULL; v = v->next) { + sp_canvas_item_hide(SP_CANVAS_ITEM(v->data)); + sp_canvas_item_hide(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin)); + } } void SPGuide::sensitize(SPCanvas *canvas, bool sensitive) @@ -353,7 +288,7 @@ void SPGuide::sensitize(SPCanvas *canvas, bool sensitive) } } - g_assert_not_reached(); + assert(false); } Geom::Point SPGuide::getPositionFrom(Geom::Point const &pt) const @@ -371,11 +306,9 @@ double SPGuide::getDistanceFrom(Geom::Point const &pt) const * true indicates a "committing" version: in response to button release event after * dragging a guideline, or clicking OK in guide editing dialog. */ -void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const commit) +void SPGuide::moveto(Geom::Point const point_on_line, bool const commit) { - g_assert(SP_IS_GUIDE(&guide)); - - for (GSList *l = guide.views; l != NULL; l = l->next) { + for (GSList *l = views; l != NULL; l = l->next) { sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line); } @@ -383,16 +316,16 @@ void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */ if (commit) { //XML Tree being used here directly while it shouldn't be. - sp_repr_set_point(guide.getRepr(), "position", point_on_line); + sp_repr_set_point(getRepr(), "position", point_on_line); } /* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan) - for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()), - iEnd(guide.attached_items.end()); + for (vector<SPGuideAttachment>::const_iterator i(attached_items.begin()), + iEnd(attached_items.end()); i != iEnd; ++i) { SPGuideAttachment const &att = *i; - sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit); + sp_item_notify_moveto(*att.item, this, att.snappoint_ix, position, commit); } */ } @@ -402,11 +335,9 @@ void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const * true indicates a "committing" version: in response to button release event after * dragging a guideline, or clicking OK in guide editing dialog. */ -void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool const commit) +void SPGuide::set_normal(Geom::Point const normal_to_line, bool const commit) { - g_assert(SP_IS_GUIDE(&guide)); - - for (GSList *l = guide.views; l != NULL; l = l->next) { + for (GSList *l = this->views; l != NULL; l = l->next) { sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line); } @@ -414,47 +345,45 @@ void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */ if (commit) { //XML Tree being used directly while it shouldn't be - sp_repr_set_point(guide.getRepr(), "orientation", normal_to_line); + sp_repr_set_point(getRepr(), "orientation", normal_to_line); } /* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan) - for (vector<SPGuideAttachment>::const_iterator i(guide.attached_items.begin()), - iEnd(guide.attached_items.end()); + for (vector<SPGuideAttachment>::const_iterator i(attached_items.begin()), + iEnd(attached_items.end()); i != iEnd; ++i) { SPGuideAttachment const &att = *i; - sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit); + sp_item_notify_moveto(*att.item, this, att.snappoint_ix, position, commit); } */ } -void sp_guide_set_color(SPGuide &guide, const unsigned r, const unsigned g, const unsigned b, bool const commit) +void SPGuide::set_color(const unsigned r, const unsigned g, const unsigned b, bool const commit) { - g_assert(SP_IS_GUIDE(&guide)); - guide.color = (r << 24) | (g << 16) | (b << 8) | 0x7f; + this->color = (r << 24) | (g << 16) | (b << 8) | 0x7f; - if (guide.views){ - sp_guideline_set_color(SP_GUIDELINE(guide.views->data), guide.color); + if (views) { + sp_guideline_set_color(SP_GUIDELINE(views->data), this->color); } - if (commit){ + if (commit) { std::ostringstream os; os << "rgb(" << r << "," << g << "," << b << ")"; //XML Tree being used directly while it shouldn't be - guide.getRepr()->setAttribute("inkscape:color", os.str().c_str()); + getRepr()->setAttribute("inkscape:color", os.str().c_str()); } } -void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit) +void SPGuide::set_label(const char* label, bool const commit) { - g_assert(SP_IS_GUIDE(&guide)); - if (guide.views){ - sp_guideline_set_label(SP_GUIDELINE(guide.views->data), label); + if (views) { + sp_guideline_set_label(SP_GUIDELINE(views->data), label); } - if (commit){ + if (commit) { //XML Tree being used directly while it shouldn't be - guide.getRepr()->setAttribute("inkscape:label", label); + getRepr()->setAttribute("inkscape:label", label); } } @@ -464,33 +393,33 @@ void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit) * * The caller is responsible for freeing the string. */ -char *sp_guide_description(SPGuide const *guide, const bool verbose) +char* SPGuide::description(bool const verbose) const { using Geom::X; using Geom::Y; - char *descr = 0; - if ( !guide->document ) { + char *descr = NULL; + if ( !this->document ) { // Guide has probably been deleted and no longer has an attached namedview. - descr = g_strdup_printf("%s", _("Deleted")); + descr = g_strdup(_("Deleted")); } else { - SPNamedView *namedview = sp_document_namedview(guide->document, NULL); + SPNamedView *namedview = sp_document_namedview(this->document, NULL); - Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px"); - Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px"); + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(this->point_on_line[X], "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(this->point_on_line[Y], "px"); GString *position_string_x = g_string_new(x_q.string(namedview->doc_units).c_str()); GString *position_string_y = g_string_new(y_q.string(namedview->doc_units).c_str()); gchar *shortcuts = g_strdup_printf("; %s", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete")); - if ( are_near(guide->normal_to_line, Geom::Point(1., 0.)) || - are_near(guide->normal_to_line, -Geom::Point(1., 0.)) ) { + if ( are_near(this->normal_to_line, Geom::Point(1., 0.)) || + are_near(this->normal_to_line, -Geom::Point(1., 0.)) ) { descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str); - } else if ( are_near(guide->normal_to_line, Geom::Point(0., 1.)) || - are_near(guide->normal_to_line, -Geom::Point(0., 1.)) ) { + } else if ( are_near(this->normal_to_line, Geom::Point(0., 1.)) || + are_near(this->normal_to_line, -Geom::Point(0., 1.)) ) { descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str); } else { - double const radians = guide->angle(); + double const radians = this->angle(); double const degrees = Geom::rad_to_deg(radians); int const degrees_int = (int) round(degrees); descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"), @@ -537,4 +466,4 @@ void sp_guide_remove(SPGuide *guide) fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-guide.h b/src/sp-guide.h index cd67df222..382ea56f0 100644 --- a/src/sp-guide.h +++ b/src/sp-guide.h @@ -20,11 +20,14 @@ #include "sp-guide-attachment.h" typedef unsigned int guint32; -typedef void (*GCallback) (void); +extern "C" { + typedef void (*GCallback) (void); + typedef struct _GSList GSList; +} +class SPDesktop; struct SPCanvas; struct SPCanvasGroup; -class SPDesktop; #define SP_GUIDE(obj) (dynamic_cast<SPGuide*>((SPObject*)obj)) #define SP_IS_GUIDE(obj) (dynamic_cast<const SPGuide*>((SPObject*)obj) != NULL) @@ -32,51 +35,65 @@ class SPDesktop; /* Represents the constraint on p that dot(g.direction, p) == g.position. */ class SPGuide : public SPObject { public: - SPGuide(); - virtual ~SPGuide(); + SPGuide(); + virtual ~SPGuide() {} - char* label; - Geom::Point normal_to_line; - Geom::Point point_on_line; + void set_color(const unsigned r, const unsigned g, const unsigned b, bool const commit); + void setColor(guint32 c); + void setHiColor(guint32 h) { hicolor = h; } - guint32 color; - guint32 hicolor; - GSList *views; - std::vector<SPGuideAttachment> attached_items; + guint32 getColor() const { return color; } + guint32 getHiColor() const { return hicolor; } + Geom::Point getPoint() const { return point_on_line; } + Geom::Point getNormal() const { return normal_to_line; } - guint32 getColor() const; - guint32 getHiColor() const; - void setColor(guint32 c); - void setHiColor(guint32 h); + void moveto(Geom::Point const point_on_line, bool const commit); + void set_normal(Geom::Point const normal_to_line, bool const commit); + + void set_label(const char* label, bool const commit); + char const* getLabel() const { return label; } - inline bool isHorizontal() const { return (normal_to_line[Geom::X] == 0.); }; - inline bool isVertical() const { return (normal_to_line[Geom::Y] == 0.); }; - inline double angle() const { return std::atan2( - normal_to_line[Geom::X], normal_to_line[Geom::Y] ); }; static SPGuide *createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::Point const &pt2); + void showSPGuide(SPCanvasGroup *group, GCallback handler); void hideSPGuide(SPCanvas *canvas); + void showSPGuide(); // argument-free versions + void hideSPGuide(); + void sensitize(SPCanvas *canvas, bool sensitive); - Geom::Point getPositionFrom(Geom::Point const &pt) const; + + bool isHorizontal() const { return (normal_to_line[Geom::X] == 0.); }; + bool isVertical() const { return (normal_to_line[Geom::Y] == 0.); }; + + char* description(bool const verbose = true) const; + + double angle() const { return std::atan2( - normal_to_line[Geom::X], normal_to_line[Geom::Y] ); } double getDistanceFrom(Geom::Point const &pt) const; + Geom::Point getPositionFrom(Geom::Point const &pt) const; protected: - virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); - virtual void release(); - virtual void set(unsigned int key, const char* value); + virtual void build(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void release(); + virtual void set(unsigned int key, const char* value); + + char* label; + GSList *views; // contains an object of type SPGuideline (see display/guideline.cpp for definition) + Geom::Point normal_to_line; + Geom::Point point_on_line; + + guint32 color; + guint32 hicolor; +public: + std::vector<SPGuideAttachment> attached_items; // unused }; +// These functions rightfully belong to SPDesktop. What gives?! void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts); void sp_guide_create_guides_around_page(SPDesktop *dt); void sp_guide_delete_all_guides(SPDesktop *dt); -void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const commit); -void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool const commit); -void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit); -void sp_guide_set_color(SPGuide &guide, const unsigned r, const unsigned g, const unsigned b, bool const commit); void sp_guide_remove(SPGuide *guide); -char *sp_guide_description(SPGuide const *guide, const bool verbose = true); - #endif // SEEN_SP_GUIDE_H /* diff --git a/src/sp-item-notify-moveto.cpp b/src/sp-item-notify-moveto.cpp index 90fd676ee..dcc91fd0b 100644 --- a/src/sp-item-notify-moveto.cpp +++ b/src/sp-item-notify-moveto.cpp @@ -22,7 +22,7 @@ void sp_item_notify_moveto(SPItem &item, SPGuide const &mv_g, int const snappoin { return_if_fail(SP_IS_ITEM(&item)); return_if_fail( unsigned(snappoint_ix) < 8 ); - Geom::Point const dir( mv_g.normal_to_line ); + Geom::Point const dir( mv_g.getNormal() ); double const dir_lensq(dot(dir, dir)); return_if_fail( dir_lensq != 0 ); diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 1d9fa06a3..8b28347f1 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -956,14 +956,10 @@ static void sp_namedview_setup_guides(SPNamedView *nv) static void sp_namedview_show_single_guide(SPGuide* guide, bool show) { - for (GSList *v = guide->views; v != NULL; v = v->next) { - if (show) { - sp_canvas_item_show(SP_CANVAS_ITEM(v->data)); - sp_canvas_item_show(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin)); - } else { - sp_canvas_item_hide(SP_CANVAS_ITEM(v->data)); - sp_canvas_item_hide(SP_CANVAS_ITEM(SP_GUIDELINE(v->data)->origin)); - } + if (show) { + guide->showSPGuide(); + } else { + guide->hideSPGuide(); } } @@ -1156,9 +1152,9 @@ Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedvie void SPNamedView::translateGuides(Geom::Translate const &tr) { for (GSList *l = guides; l != NULL; l = l->next) { SPGuide &guide = *SP_GUIDE(l->data); - Geom::Point point_on_line = guide.point_on_line; + Geom::Point point_on_line = guide.getPoint(); point_on_line *= tr; - sp_guide_moveto(guide, point_on_line, true); + guide.moveto(point_on_line, true); } } diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp index 76c26a3cb..4519a905f 100644 --- a/src/ui/dialog/guides.cpp +++ b/src/ui/dialog/guides.cpp @@ -100,7 +100,7 @@ void GuidelinePropertiesDialog::_onOK() double rad_angle = Geom::deg_to_rad( deg_angle ); normal = Geom::rot90(Geom::Point::polar(rad_angle, 1.0)); } - sp_guide_set_normal(*_guide, normal, true); + _guide->set_normal(normal, true); double const points_x = _spin_button_x.getValue("px"); double const points_y = _spin_button_y.getValue("px"); @@ -108,11 +108,11 @@ void GuidelinePropertiesDialog::_onOK() if (!_mode) newpos += _oldpos; - sp_guide_moveto(*_guide, newpos, true); + _guide->moveto(newpos, true); const gchar* name = g_strdup( _label_entry.getEntry()->get_text().c_str() ); - sp_guide_set_label(*_guide, name, true); + _guide->set_label(name, true); g_free((gpointer) name); #if WITH_GTKMM_3_0 @@ -124,7 +124,7 @@ void GuidelinePropertiesDialog::_onOK() #endif //TODO: why 257? verify this! - sp_guide_set_color(*_guide, r, g, b, true); + _guide->set_color(r, g, b, true); DocumentUndo::done(_guide->document, SP_VERB_NONE, _("Set guide properties")); @@ -295,16 +295,17 @@ void GuidelinePropertiesDialog::_setup() { signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response)); // initialize dialog - _oldpos = _guide->point_on_line; + _oldpos = _guide->getPoint(); if (_guide->isVertical()) { _oldangle = 90; } else if (_guide->isHorizontal()) { _oldangle = 0; } else { - _oldangle = Geom::rad_to_deg( std::atan2( - _guide->normal_to_line[Geom::X], _guide->normal_to_line[Geom::Y] ) ); + _oldangle = Geom::rad_to_deg( std::atan2( - _guide->getNormal()[Geom::X], _guide->getNormal()[Geom::Y] ) ); } { + // FIXME holy crap!!! Inkscape::XML::Node *repr = _guide->getRepr(); const gchar *guide_id = repr->attribute("id"); gchar *label = g_strdup_printf(_("Guideline ID: %s"), guide_id); @@ -312,7 +313,7 @@ void GuidelinePropertiesDialog::_setup() { g_free(label); } { - gchar *guide_description = sp_guide_description(_guide, false); + gchar *guide_description = _guide->description(false); gchar *label = g_strdup_printf(_("Current: %s"), guide_description); g_free(guide_description); _label_descr.set_markup(label); @@ -320,15 +321,15 @@ void GuidelinePropertiesDialog::_setup() { } // init name entry - _label_entry.getEntry()->set_text(_guide->label ? _guide->label : ""); + _label_entry.getEntry()->set_text(_guide->getLabel() ? _guide->getLabel() : ""); #if WITH_GTKMM_3_0 Gdk::RGBA c; - c.set_rgba(((_guide->color>>24)&0xff) / 255.0, ((_guide->color>>16)&0xff) / 255.0, ((_guide->color>>8)&0xff) / 255.0); + c.set_rgba(((_guide->getColor()>>24)&0xff) / 255.0, ((_guide->getColor()>>16)&0xff) / 255.0, ((_guide->getColor()>>8)&0xff) / 255.0); _color.set_rgba(c); #else Gdk::Color c; - c.set_rgb_p(((_guide->color>>24)&0xff) / 255.0, ((_guide->color>>16)&0xff) / 255.0, ((_guide->color>>8)&0xff) / 255.0); + c.set_rgb_p(((_guide->getColor()>>24)&0xff) / 255.0, ((_guide->getColor()>>16)&0xff) / 255.0, ((_guide->getColor()>>8)&0xff) / 255.0); _color.set_color(c); #endif |
