summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b7c96b1)
raw | patch | inline | side by side (parent: b7c96b1)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Thu, 20 Dec 2007 16:07:52 +0000 (16:07 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Thu, 20 Dec 2007 16:07:52 +0000 (16:07 +0000) |
add point reading to repr-util.cpp
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp
index faa735733c7a46f62cceeb49a93a07dd6f03482d..bc2ffa530d208f3f518c285d86dc79358c6130b8 100644 (file)
--- 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,
index 1f1d996ffd03d129e553488bb1b32f01aa9a4d87..166ed0e6ba8df312b897bc36e076fda64c10bee0 100644 (file)
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);
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 bd5823e16732bda24911d25fef6cc4f7e6f3ffd5..7ee29e2316e7f6d4e7e78ccb853ebd699b4307e1 100644 (file)
--- 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 560a700041b4f4dd6d27b921fb7384e39852938a..7a45f6fcd32b6f279e91057636b0ae4733a2a1e3 100644 (file)
--- a/src/xml/repr-util.cpp
+++ b/src/xml/repr-util.cpp
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 2b5f4ad1e8c1a438301f57e0e75eb228034301a0..aab96a6176cfbfae92a8daa32621aa5564d48678 100644 (file)
--- 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);