summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/desktop-events.cpp4
-rw-r--r--src/guide-snapper.cpp4
-rw-r--r--src/satisfied-guide-cns.cpp2
-rw-r--r--src/sp-guide.cpp59
-rw-r--r--src/sp-guide.h5
-rw-r--r--src/sp-item-notify-moveto.cpp2
-rw-r--r--src/sp-item-rm-unsatisfied-cns.cpp2
7 files changed, 50 insertions, 28 deletions
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp
index d3c521fec..fec316bd3 100644
--- a/src/desktop-events.cpp
+++ b/src/desktop-events.cpp
@@ -176,7 +176,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
// This is for snapping while dragging existing guidelines. New guidelines,
// which are dragged off the ruler, are being snapped in sp_dt_ruler_event
SnapManager const &m = desktop->namedview->snap_manager;
- motion_dt = m.guideSnap(motion_dt, guide->normal).getPoint();
+ motion_dt = m.guideSnap(motion_dt, guide->normal_to_line).getPoint();
sp_guide_moveto(*guide, sp_guide_position_from_pt(guide, motion_dt), false);
moved = true;
@@ -193,7 +193,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
NR::Point event_dt(desktop->w2d(event_w));
SnapManager const &m = desktop->namedview->snap_manager;
- event_dt = m.guideSnap(event_dt, guide->normal).getPoint();
+ event_dt = m.guideSnap(event_dt, guide->normal_to_line).getPoint();
if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) {
sp_guide_moveto(*guide, sp_guide_position_from_pt(guide, event_dt), true);
diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp
index b660bab9d..1e78f609a 100644
--- a/src/guide-snapper.cpp
+++ b/src/guide-snapper.cpp
@@ -32,8 +32,8 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point
for (GSList const *l = _named_view->guides; l != NULL; l = l->next) {
SPGuide const *g = SP_GUIDE(l->data);
- NR::Point point_on_line = (g->normal == component_vectors[NR::X]) ? NR::Point(g->position, 0) : NR::Point(0, g->position);
- s.push_back(std::make_pair(g->normal, point_on_line));
+ NR::Point point_on_line = (g->normal_to_line == component_vectors[NR::X]) ? NR::Point(g->position, 0) : NR::Point(0, g->position);
+ s.push_back(std::make_pair(g->normal_to_line, point_on_line));
}
return s;
diff --git a/src/satisfied-guide-cns.cpp b/src/satisfied-guide-cns.cpp
index 3353b1fdf..ece5118c5 100644
--- a/src/satisfied-guide-cns.cpp
+++ b/src/satisfied-guide-cns.cpp
@@ -13,7 +13,7 @@ void satisfied_guide_cns(SPDesktop const &desktop,
for (GSList const *l = nv.guides; l != NULL; l = l->next) {
SPGuide &g = *SP_GUIDE(l->data);
for (unsigned int i = 0; i < snappoints.size(); ++i) {
- if (approx_equal(dot(g.normal, snappoints[i]), g.position)) {
+ if (approx_equal(dot(g.normal_to_line, snappoints[i]), g.position)) {
cns.push_back(SPGuideConstraint(&g, i));
}
}
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 4fc5a0f85..ff16c5381 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -101,7 +101,7 @@ static void sp_guide_class_init(SPGuideClass *gc)
static void sp_guide_init(SPGuide *guide)
{
- guide->normal = component_vectors[NR::Y];
+ guide->normal_to_line = component_vectors[NR::Y];
/* constrain y coordinate; horizontal line. I doubt it ever matters what we initialize
this to. */
guide->position = 0.0;
@@ -170,12 +170,13 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
SPGuide *guide = SP_GUIDE(object);
switch (key) {
- case SP_ATTR_ORIENTATION:
+ case SP_ATTR_ORIENTATION:
+ {
if (value && !strcmp(value, "horizontal")) {
/* Visual representation of a horizontal line, constrain vertically (y coordinate). */
- guide->normal = component_vectors[NR::Y];
+ guide->normal_to_line = component_vectors[NR::Y];
} else if (value && !strcmp(value, "vertical")) {
- guide->normal = component_vectors[NR::X];
+ guide->normal_to_line = component_vectors[NR::X];
} else if (value) {
gchar ** strarray = g_strsplit(value, ",", 2);
double newx, newy;
@@ -185,23 +186,43 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
if (success == 2) {
Geom::Point direction(newx, newy);
direction.normalize();
- guide->normal = direction;
+ guide->normal_to_line = direction;
} else {
// default to vertical line for bad arguments
- guide->normal = component_vectors[NR::X];
+ guide->normal_to_line = component_vectors[NR::X];
}
} else {
// default to vertical line for bad arguments
- guide->normal = component_vectors[NR::X];
+ guide->normal_to_line = component_vectors[NR::X];
+ }
+ }
+ break;
+ case SP_ATTR_POSITION:
+ {
+ gchar ** strarray = g_strsplit(value, ",", 2);
+ double newx, newy;
+ unsigned int success = sp_svg_number_read_d(strarray[0], &newx);
+ success += sp_svg_number_read_d(strarray[1], &newy);
+ g_strfreev (strarray);
+ if (success == 2) {
+ guide->point_on_line = Geom::Point(newx, newy);
+ } else if (success == 1) {
+ // before 0.46 style guideline definition.
+ const gchar *attr = SP_OBJECT_REPR(object)->attribute("orientation");
+ if (attr && !strcmp(attr, "horizontal")) {
+ guide->point_on_line = Geom::Point(0, newx);
+ } else {
+ guide->point_on_line = Geom::Point(newx, 0);
+ }
}
- break;
- case SP_ATTR_POSITION:
sp_svg_number_read_d(value, &guide->position);
+
// update position in non-committing way
// fixme: perhaps we need to add an update method instead, and request_update here
sp_guide_moveto(*guide, guide->position, false);
- break;
- default:
+ }
+ break;
+ default:
if (((SPObjectClass *) (parent_class))->set) {
((SPObjectClass *) (parent_class))->set(object, key, value);
}
@@ -211,9 +232,9 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler)
{
- bool const vertical_line_p = ( guide->normal == component_vectors[NR::X] );
- g_assert(( guide->normal == component_vectors[NR::X] ) ||
- ( guide->normal == component_vectors[NR::Y] ) );
+ bool const vertical_line_p = ( guide->normal_to_line == component_vectors[NR::X] );
+ g_assert(( guide->normal_to_line == component_vectors[NR::X] ) ||
+ ( guide->normal_to_line == component_vectors[NR::Y] ) );
SPCanvasItem *item = sp_guideline_new(group, guide->position, vertical_line_p ? Geom::Point(1.,0.) : Geom::Point(0.,1.));
sp_guideline_set_color(SP_GUIDELINE(item), guide->color);
@@ -259,7 +280,7 @@ void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive)
double sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt)
{
- return dot(guide->normal, pt);
+ return dot(guide->normal_to_line, pt);
}
/**
@@ -302,13 +323,13 @@ char *sp_guide_description(SPGuide const *guide)
using NR::X;
using NR::Y;
- if ( guide->normal == component_vectors[X] ) {
+ if ( guide->normal_to_line == component_vectors[X] ) {
return g_strdup(_("vertical guideline"));
- } else if ( guide->normal == component_vectors[Y] ) {
+ } else if ( guide->normal_to_line == component_vectors[Y] ) {
return g_strdup(_("horizontal guideline"));
} else {
- double const radians = atan2(guide->normal[X],
- guide->normal[Y]);
+ double const radians = atan2(guide->normal_to_line[X],
+ guide->normal_to_line[Y]);
/* flip y axis and rotate 90 degrees to convert to line angle */
double const degrees = ( radians / M_PI ) * 180.0;
int const degrees_int = (int) floor( degrees + .5 );
diff --git a/src/sp-guide.h b/src/sp-guide.h
index 534992174..aa3464918 100644
--- a/src/sp-guide.h
+++ b/src/sp-guide.h
@@ -26,7 +26,8 @@
/* Represents the constraint on p that dot(g.direction, p) == g.position. */
struct SPGuide : public SPObject {
- NR::Point normal;
+ NR::Point normal_to_line;
+ Geom::Point point_on_line;
gdouble position;
guint32 color;
guint32 hicolor;
@@ -35,7 +36,7 @@ struct SPGuide : public SPObject {
};
struct SPGuideClass {
- SPObjectClass parent_class;
+ SPObjectClass parent_class;
};
GType sp_guide_get_type();
diff --git a/src/sp-item-notify-moveto.cpp b/src/sp-item-notify-moveto.cpp
index 7781b15f0..c7b852af5 100644
--- a/src/sp-item-notify-moveto.cpp
+++ b/src/sp-item-notify-moveto.cpp
@@ -20,7 +20,7 @@ void sp_item_notify_moveto(SPItem &item, SPGuide const &mv_g, int const snappoin
{
g_return_if_fail(SP_IS_ITEM(&item));
g_return_if_fail( unsigned(snappoint_ix) < 8 );
- NR::Point const dir( mv_g.normal );
+ NR::Point const dir( mv_g.normal_to_line );
double const dir_lensq(dot(dir, dir));
g_return_if_fail( dir_lensq != 0 );
diff --git a/src/sp-item-rm-unsatisfied-cns.cpp b/src/sp-item-rm-unsatisfied-cns.cpp
index 4071a639c..1f6a9ebe7 100644
--- a/src/sp-item-rm-unsatisfied-cns.cpp
+++ b/src/sp-item-rm-unsatisfied-cns.cpp
@@ -18,7 +18,7 @@ void sp_item_rm_unsatisfied_cns(SPItem &item)
SPGuideConstraint const &cn = item.constraints[i];
int const snappoint_ix = cn.snappoint_ix;
g_assert( snappoint_ix < int(snappoints.size()) );
- if (!approx_equal(dot(cn.g->normal, snappoints[snappoint_ix]), cn.g->position)) {
+ if (!approx_equal(dot(cn.g->normal_to_line, snappoints[snappoint_ix]), cn.g->position)) {
remove_last(cn.g->attached_items, SPGuideAttachment(&item, cn.snappoint_ix));
g_assert( i < item.constraints.size() );
vector<SPGuideConstraint>::iterator const ei(&item.constraints[i]);