summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/desktop-events.cpp2
-rw-r--r--src/display/guideline.cpp58
-rw-r--r--src/display/guideline.h4
-rw-r--r--src/sp-guide.cpp25
-rw-r--r--src/sp-guide.h2
-rw-r--r--src/ui/widget/ruler.cpp2
6 files changed, 80 insertions, 13 deletions
diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp
index b458827f0..b7b7529a1 100644
--- a/src/desktop-events.cpp
+++ b/src/desktop-events.cpp
@@ -131,7 +131,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
}
}
- guide = sp_guideline_new(desktop->guides, event_dt, normal);
+ guide = sp_guideline_new(desktop->guides, NULL, event_dt, normal);
sp_guideline_set_color(SP_GUIDELINE(guide), desktop->namedview->guidehicolor);
gdk_pointer_grab(widget->window, FALSE,
(GdkEventMask)(GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ),
diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp
index bebec2852..f0e1c7724 100644
--- a/src/display/guideline.cpp
+++ b/src/display/guideline.cpp
@@ -19,6 +19,8 @@
#include "sp-canvas-util.h"
#include "sp-ctrlpoint.h"
#include "guideline.h"
+#include "cairo.h"
+#include "inkscape-cairo.h"
static void sp_guideline_class_init(SPGuideLineClass *c);
static void sp_guideline_init(SPGuideLine *guideline);
@@ -78,6 +80,7 @@ static void sp_guideline_init(SPGuideLine *gl)
gl->sensitive = 0;
gl->origin = NULL;
+ gl->label = NULL;
}
static void sp_guideline_destroy(GtkObject *object)
@@ -99,25 +102,35 @@ static void sp_guideline_destroy(GtkObject *object)
static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
{
+ //TODO: the routine that renders the label of a specific guideline sometimes
+ // ends up erasing the labels of the other guidelines.
+ // Maybe we should render all labels everytime.
+
SPGuideLine const *gl = SP_GUIDELINE (item);
sp_canvas_prepare_buffer(buf);
+ cairo_t* ctx = nr_create_cairo_context_canvasbuf (NULL /*area*/, buf); //this function ignores the "area" parameter
+ cairo_set_font_size (ctx, 10);
+ cairo_set_line_width (ctx, 10);
+ cairo_set_source_rgb (ctx, 0, 0, 0);
unsigned int const r = NR_RGBA32_R (gl->rgba);
unsigned int const g = NR_RGBA32_G (gl->rgba);
unsigned int const b = NR_RGBA32_B (gl->rgba);
unsigned int const a = NR_RGBA32_A (gl->rgba);
+ int px = (int) Inkscape::round(gl->point_on_line[Geom::X]);
+ int py = (int) Inkscape::round(gl->point_on_line[Geom::Y]);
+
if (gl->is_vertical()) {
- int position = (int) Inkscape::round(gl->point_on_line[Geom::X]);
- if (position < buf->rect.x0 || position >= buf->rect.x1) {
+ if (px < buf->rect.x0 || px >= buf->rect.x1) {
return;
}
int p0 = buf->rect.y0;
int p1 = buf->rect.y1;
int step = buf->buf_rowstride;
- unsigned char *d = buf->buf + 4 * (position - buf->rect.x0);
+ unsigned char *d = buf->buf + 4 * (px - buf->rect.x0);
for (int p = p0; p < p1; p++) {
d[0] = NR_COMPOSEN11_1111(r, a, d[0]);
@@ -125,16 +138,22 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
d[2] = NR_COMPOSEN11_1111(b, a, d[2]);
d += step;
}
+
+ if (gl->label){
+ cairo_move_to(ctx, px - buf->rect.x0 + 5, py - buf->rect.y0);
+ cairo_rotate(ctx, 3.1415/2);
+ cairo_show_text(ctx, gl->label);
+ }
+
} else if (gl->is_horizontal()) {
- int position = (int) Inkscape::round(gl->point_on_line[Geom::Y]);
- if (position < buf->rect.y0 || position >= buf->rect.y1) {
+ if (py < buf->rect.y0 || py >= buf->rect.y1) {
return;
}
int p0 = buf->rect.x0;
int p1 = buf->rect.x1;
int step = 4;
- unsigned char *d = buf->buf + (position - buf->rect.y0) * buf->buf_rowstride;
+ unsigned char *d = buf->buf + (py - buf->rect.y0) * buf->buf_rowstride;
for (int p = p0; p < p1; p++) {
d[0] = NR_COMPOSEN11_1111(r, a, d[0]);
@@ -142,6 +161,12 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
d[2] = NR_COMPOSEN11_1111(b, a, d[2]);
d += step;
}
+
+ if (gl->label){
+ cairo_move_to(ctx, px - buf->rect.x0, py - buf->rect.y0 - 5);
+ cairo_show_text(ctx, gl->label);
+ }
+
} else {
// render angled line, once intersection has been detected, draw from there.
Geom::Point parallel_to_line( gl->normal_to_line[Geom::Y],
@@ -180,6 +205,12 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf)
sp_guideline_drawline (buf, static_cast<gint>(round(x_intersect_bottom)), buf->rect.y1, static_cast<gint>(round(x_intersect_top)), buf->rect.y0, gl->rgba);
return;
}
+
+ if (gl->label){
+ cairo_move_to(ctx, px - buf->rect.x0 + 5, py - buf->rect.y0);
+ cairo_rotate(ctx, atan2(gl->normal_to_line[Geom::X], gl->normal_to_line[Geom::Y]));
+ cairo_show_text(ctx, gl->label);
+ }
}
}
@@ -198,10 +229,11 @@ static void sp_guideline_update(SPCanvasItem *item, Geom::Affine const &affine,
sp_canvas_item_request_update(SP_CANVAS_ITEM (gl->origin));
if (gl->is_horizontal()) {
- sp_canvas_update_bbox (item, -1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y]), 1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y] + 1));
+ sp_canvas_update_bbox (item, -1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y] - 16), 1000000, (int) Inkscape::round(gl->point_on_line[Geom::Y] + 1));
} else if (gl->is_vertical()) {
- sp_canvas_update_bbox (item, (int) Inkscape::round(gl->point_on_line[Geom::X]), -1000000, (int) Inkscape::round(gl->point_on_line[Geom::X] + 1), 1000000);
+ sp_canvas_update_bbox (item, (int) Inkscape::round(gl->point_on_line[Geom::X]), -1000000, (int) Inkscape::round(gl->point_on_line[Geom::X] + 16), 1000000);
} else {
+ //TODO: labels in angled guidelines are not showing up for some reason.
sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000);
}
}
@@ -222,7 +254,7 @@ static double sp_guideline_point(SPCanvasItem *item, Geom::Point p, SPCanvasItem
return MAX(fabs(distance)-1, 0);
}
-SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal)
+SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point point_on_line, Geom::Point normal)
{
SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL);
SPCanvasItem *origin = sp_canvas_item_new(parent, SP_TYPE_CTRLPOINT, NULL);
@@ -232,6 +264,7 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line,
gl->origin = cp;
normal.normalize();
+ gl->label = label;
gl->normal_to_line = normal;
gl->angle = tan( -gl->normal_to_line[Geom::X] / gl->normal_to_line[Geom::Y]);
sp_guideline_set_position(gl, point_on_line);
@@ -241,6 +274,13 @@ SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line,
return item;
}
+void sp_guideline_set_label(SPGuideLine *gl, char* label)
+{
+ gl->label = label;
+
+ sp_canvas_item_request_update(SP_CANVAS_ITEM (gl));
+}
+
void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line)
{
sp_canvas_item_affine_absolute(SP_CANVAS_ITEM (gl), Geom::Affine(Geom::Translate(point_on_line)));
diff --git a/src/display/guideline.h b/src/display/guideline.h
index 9654d04a1..dbf990d1f 100644
--- a/src/display/guideline.h
+++ b/src/display/guideline.h
@@ -29,6 +29,7 @@ struct SPGuideLine {
guint32 rgba;
+ char* label;
Geom::Point normal_to_line;
Geom::Point point_on_line;
double angle;
@@ -45,8 +46,9 @@ struct SPGuideLineClass {
GType sp_guideline_get_type();
-SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal);
+SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, char* label, Geom::Point point_on_line, Geom::Point normal);
+void sp_guideline_set_label(SPGuideLine *gl, char* label);
void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line);
void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line);
void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba);
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 7d36df4a3..1e51ee4d5 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -160,6 +160,7 @@ static void sp_guide_build(SPObject *object, SPDocument *document, Inkscape::XML
(* ((SPObjectClass *) (parent_class))->build)(object, document, repr);
}
+ object->readAttr( "inkscape:label" );
object->readAttr( "orientation" );
object->readAttr( "position" );
}
@@ -183,6 +184,15 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
SPGuide *guide = SP_GUIDE(object);
switch (key) {
+ case SP_ATTR_INKSCAPE_LABEL:
+ if (value) {
+ guide->label = g_strdup(value);
+ } else {
+ guide->label = NULL;
+ }
+
+ sp_guide_set_label(*guide, guide->label, false);
+ break;
case SP_ATTR_ORIENTATION:
{
if (value && !strcmp(value, "horizontal")) {
@@ -291,7 +301,7 @@ sp_guide_create_guides_around_page(SPDesktop *dt) {
void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler)
{
- SPCanvasItem *item = sp_guideline_new(group, point_on_line, normal_to_line);
+ SPCanvasItem *item = sp_guideline_new(group, label, point_on_line, normal_to_line);
sp_guideline_set_color(SP_GUIDELINE(item), color);
g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this);
@@ -402,6 +412,19 @@ void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool
*/
}
+void sp_guide_set_label(SPGuide &guide, 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 (commit){
+ //XML Tree being used directly while it shouldn't be
+ guide.getRepr()->setAttribute("label", label);
+ }
+}
+
/**
* Returns a human-readable description of the guideline for use in dialog boxes and status bar.
* If verbose is false, only positioning information is included (useful for dialogs).
diff --git a/src/sp-guide.h b/src/sp-guide.h
index c53042da5..1dcdbc662 100644
--- a/src/sp-guide.h
+++ b/src/sp-guide.h
@@ -31,6 +31,7 @@ struct SPCanvasGroup;
/* Represents the constraint on p that dot(g.direction, p) == g.position. */
class SPGuide : public SPObject {
public:
+ char* label;
Geom::Point normal_to_line;
Geom::Point point_on_line;
@@ -62,6 +63,7 @@ void sp_guide_create_guides_around_page(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, char* const label, bool const commit);
void sp_guide_remove(SPGuide *guide);
char *sp_guide_description(SPGuide const *guide, const bool verbose = true);
diff --git a/src/ui/widget/ruler.cpp b/src/ui/widget/ruler.cpp
index a220a54ad..c6ac3a381 100644
--- a/src/ui/widget/ruler.cpp
+++ b/src/ui/widget/ruler.cpp
@@ -108,7 +108,7 @@ Ruler::on_button_press_event(GdkEventButton *evb)
_dragging = true;
sp_repr_set_boolean(repr, "showguides", TRUE);
sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE);
- _guide = sp_guideline_new(_dt->guides, event_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.));
+ _guide = sp_guideline_new(_dt->guides, NULL, event_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.));
sp_guideline_set_color(SP_GUIDELINE(_guide), _dt->namedview->guidehicolor);
(void) get_window()->pointer_grab(false,
Gdk::BUTTON_RELEASE_MASK |