summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 201e34f)
raw | patch | inline | side by side (parent: 201e34f)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Wed, 19 Dec 2007 00:01:46 +0000 (00:01 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Wed, 19 Dec 2007 00:01:46 +0000 (00:01 +0000) |
start conversion to use point_on_line instead of position.
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp
index d3c521fec548850ec331c4608da1af09a9a83d9c..fec316bd3687706a6e5ace002c4fd12563fc4d6b 100644 (file)
--- a/src/desktop-events.cpp
+++ b/src/desktop-events.cpp
// 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;
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 b660bab9da473b163acc99bc54a12d94b566e1a8..1e78f609aae0a39934ae578823cb6f44ebe04a00 100644 (file)
--- a/src/guide-snapper.cpp
+++ b/src/guide-snapper.cpp
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;
index 3353b1fdfebc2d9fd6664e608919c34fbf822354..ece5118c58297175e3f0dcb25a9b078619b728be 100644 (file)
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 4fc5a0f85a474e996a34a3ea38dec4218b1d57b3..ff16c53819af43c25399f516183531ea486e333b 100644 (file)
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
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);
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);
}
/**
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 5349921747bd69761053eedccdc27f020127c890..aa34649184948e93e11281c0ea8514d7f3d40966 100644 (file)
--- a/src/sp-guide.h
+++ b/src/sp-guide.h
/* 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;
};
struct SPGuideClass {
- SPObjectClass parent_class;
+ SPObjectClass parent_class;
};
GType sp_guide_get_type();
index 7781b15f0350b30c5fd937db21a792b4a11a900d..c7b852af5ccc599d94fba19b4b7d813dc305d0ed 100644 (file)
{
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 );
index 4071a639c6da560f615fc738c2baedbb45c7f370..1f6a9ebe787a42e675bd53c78218c910e6107d69 100644 (file)
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]);