summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-12-20 16:07:52 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-12-20 16:07:52 +0000
commit64e80ad6870950aff58300b3034e8848b63c9049 (patch)
treeb6f2f881eb0b7fb199e937e5eedbafb8a5e8afcb
parent(Hopefully) proper fix this time for stolen 'D + modifier' shortcuts. (diff)
downloadinkscape-64e80ad6870950aff58300b3034e8848b63c9049.tar.gz
inkscape-64e80ad6870950aff58300b3034e8848b63c9049.zip
guidelines: minor corrections
add point reading to repr-util.cpp (bzr r4264)
-rw-r--r--src/desktop-events.cpp2
-rw-r--r--src/display/guideline.cpp83
-rw-r--r--src/sp-guide.cpp6
-rw-r--r--src/xml/repr-util.cpp26
-rw-r--r--src/xml/repr.h3
5 files changed, 112 insertions, 8 deletions
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp
index faa735733..bc2ffa530 100644
--- a/src/desktop-events.cpp
+++ b/src/desktop-events.cpp
@@ -100,7 +100,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide");
repr->setAttribute("orientation", (horiz) ? "horizontal" : "vertical");
- sp_repr_set_svg_point(repr, "position", event_dt.to_2geom());
+ sp_repr_set_point(repr, "position", event_dt.to_2geom());
SP_OBJECT_REPR(desktop->namedview)->appendChild(repr);
Inkscape::GC::release(repr);
sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE,
diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp
index 1f1d996ff..166ed0e6b 100644
--- a/src/display/guideline.cpp
+++ b/src/display/guideline.cpp
@@ -28,6 +28,8 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf);
static double sp_guideline_point(SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
+static void sp_guideline_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba);
+
static SPCanvasItemClass *parent_class;
GType sp_guideline_get_type()
@@ -137,8 +139,8 @@ static void sp_guideline_update(SPCanvasItem *item, NR::Matrix const &affine, un
((SPCanvasItemClass *) parent_class)->update(item, affine, flags);
}
- gl->point_on_line[Geom::X] = affine[4];
- gl->point_on_line[Geom::Y] = affine[5];
+ gl->point_on_line[Geom::X] = affine[4] +0.5;
+ gl->point_on_line[Geom::Y] = affine[5] -0.5;
if (gl->normal_to_line[Geom::Y] == 1.) {
sp_canvas_update_bbox (item, -1000000, gl->point_on_line[Geom::Y], 1000000, gl->point_on_line[Geom::Y] + 1);
@@ -201,6 +203,83 @@ void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive)
gl->sensitive = sensitive;
}
+//##########################################################
+// Line rendering
+#define SAFE_SETPIXEL //undefine this when it is certain that setpixel is never called with invalid params
+
+/**
+ \brief This function renders a pixel on a particular buffer.
+
+ The topleft of the buffer equals
+ ( rect.x0 , rect.y0 ) in screen coordinates
+ ( 0 , 0 ) in setpixel coordinates
+ The bottomright of the buffer equals
+ ( rect.x1 , rect,y1 ) in screen coordinates
+ ( rect.x1 - rect.x0 , rect.y1 - rect.y0 ) in setpixel coordinates
+*/
+static void
+sp_guideline_setpixel (SPCanvasBuf *buf, gint x, gint y, guint32 rgba)
+{
+#ifdef SAFE_SETPIXEL
+ if ( (x >= buf->rect.x0) && (x < buf->rect.x1) && (y >= buf->rect.y0) && (y < buf->rect.y1) ) {
+#endif
+ guint r, g, b, a;
+ r = NR_RGBA32_R (rgba);
+ g = NR_RGBA32_G (rgba);
+ b = NR_RGBA32_B (rgba);
+ a = NR_RGBA32_A (rgba);
+ guchar * p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride + (x - buf->rect.x0) * 3;
+ p[0] = NR_COMPOSEN11_1111 (r, a, p[0]);
+ p[1] = NR_COMPOSEN11_1111 (g, a, p[1]);
+ p[2] = NR_COMPOSEN11_1111 (b, a, p[2]);
+#ifdef SAFE_SETPIXEL
+ }
+#endif
+}
+
+/**
+ \brief This function renders a line on a particular canvas buffer,
+ using Bresenham's line drawing function.
+ http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html
+ Coordinates are interpreted as SCREENcoordinates
+*/
+static void
+sp_guideline_drawline (SPCanvasBuf *buf, gint x0, gint y0, gint x1, gint y1, guint32 rgba)
+{
+ int dy = y1 - y0;
+ int dx = x1 - x0;
+ int stepx, stepy;
+
+ if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
+ if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
+ dy <<= 1; // dy is now 2*dy
+ dx <<= 1; // dx is now 2*dx
+
+ sp_guideline_setpixel(buf, x0, y0, rgba);
+ if (dx > dy) {
+ int fraction = dy - (dx >> 1); // same as 2*dy - dx
+ while (x0 != x1) {
+ if (fraction >= 0) {
+ y0 += stepy;
+ fraction -= dx; // same as fraction -= 2*dx
+ }
+ x0 += stepx;
+ fraction += dy; // same as fraction -= 2*dy
+ sp_guideline_setpixel(buf, x0, y0, rgba);
+ }
+ } else {
+ int fraction = dx - (dy >> 1);
+ while (y0 != y1) {
+ if (fraction >= 0) {
+ x0 += stepx;
+ fraction -= dy;
+ }
+ y0 += stepy;
+ fraction += dx;
+ sp_guideline_setpixel(buf, x0, y0, rgba);
+ }
+ }
+}
/*
Local Variables:
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index bd5823e16..7ee29e231 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -302,10 +302,10 @@ void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool
sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line);
}
- /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit
+ /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit
case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
if (commit) {
- sp_repr_set_svg_point(SP_OBJECT(&guide)->repr, "position", point_on_line);
+ sp_repr_set_point(SP_OBJECT(&guide)->repr, "position", point_on_line);
}
/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
@@ -335,7 +335,7 @@ void sp_guide_set_normal(SPGuide const &guide, Geom::Point const normal_to_line,
/* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit
case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */
if (commit) {
- sp_repr_set_svg_point(SP_OBJECT(&guide)->repr, "orientation", normal_to_line);
+ sp_repr_set_point(SP_OBJECT(&guide)->repr, "orientation", normal_to_line);
}
/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan)
diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp
index 560a70004..7a45f6fcd 100644
--- a/src/xml/repr-util.cpp
+++ b/src/xml/repr-util.cpp
@@ -576,7 +576,7 @@ sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val)
return true;
}
-unsigned sp_repr_set_svg_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val)
+unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val)
{
g_return_val_if_fail(repr != NULL, FALSE);
g_return_val_if_fail(key != NULL, FALSE);
@@ -588,6 +588,30 @@ unsigned sp_repr_set_svg_point(Inkscape::XML::Node *repr, gchar const *key, Geom
return true;
}
+unsigned int
+sp_repr_get_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point *val)
+{
+ g_return_val_if_fail(repr != NULL, FALSE);
+ g_return_val_if_fail(key != NULL, FALSE);
+ g_return_val_if_fail(val != NULL, FALSE);
+
+ gchar const *v = repr->attribute(key);
+
+ gchar ** strarray = g_strsplit(v, ",", 2);
+
+ if (strarray && strarray[0] && strarray[1]) {
+ double newx, newy;
+ newx = g_ascii_strtod(strarray[0], NULL);
+ newy = g_ascii_strtod(strarray[1], NULL);
+ g_strfreev (strarray);
+ *val = Geom::Point(newx, newy);
+ return TRUE;
+ }
+
+ g_strfreev (strarray);
+ return FALSE;
+}
+
/*
Local Variables:
mode:c++
diff --git a/src/xml/repr.h b/src/xml/repr.h
index 2b5f4ad1e..aab96a617 100644
--- a/src/xml/repr.h
+++ b/src/xml/repr.h
@@ -221,7 +221,8 @@ unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, gchar const *key, unsign
unsigned sp_repr_set_int(Inkscape::XML::Node *repr, gchar const *key, int val);
unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, gchar const *key, double val);
unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val);
-unsigned sp_repr_set_svg_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val);
+unsigned sp_repr_set_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val);
+unsigned sp_repr_get_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point *val);
/// \deprecated !
double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, double def);