From: cilix42 Date: Wed, 30 Jul 2008 10:57:19 +0000 (+0000) Subject: Move coordinate transform workaround to a more logical place X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4fdeee79088242d2c81462c4738811a564916d27;p=inkscape.git Move coordinate transform workaround to a more logical place --- diff --git a/src/display/canvas-bpath.cpp b/src/display/canvas-bpath.cpp index d28f63600..5b0acb31d 100644 --- a/src/display/canvas-bpath.cpp +++ b/src/display/canvas-bpath.cpp @@ -42,6 +42,7 @@ **/ #include #include +#include /** #ifdef HAVE_CONFIG_H @@ -336,6 +337,7 @@ sp_canvastext_init (SPCanvasText *canvastext) canvastext->affine = NR::identity(); canvastext->fontsize = 10.0; canvastext->item = NULL; + canvastext->desktop = NULL; canvastext->text = NULL; } @@ -426,12 +428,14 @@ sp_canvastext_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned int } SPCanvasItem * -sp_canvastext_new(SPCanvasGroup *parent, Geom::Point pos, char *new_text) +sp_canvastext_new(SPCanvasGroup *parent, SPDesktop *desktop, Geom::Point pos, char *new_text) { SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_CANVASTEXT, NULL); SPCanvasText *ct = SP_CANVASTEXT(item); + ct->desktop = desktop; + ct->s = pos; g_free(ct->text); ct->text = g_strdup(new_text); @@ -463,23 +467,25 @@ sp_canvastext_set_rgba32 (SPCanvasText *ct, guint32 rgba) void sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0) { + sp_canvastext_set_coords(ct, NR::Point(x0, y0)); +} + +void +sp_canvastext_set_coords (SPCanvasText *ct, const NR::Point start) +{ + NR::Point pos = ct->desktop->doc2dt(start); + g_return_if_fail (ct != NULL); g_return_if_fail (SP_IS_CANVASTEXT (ct)); - if (DIFFER (x0, ct->s[NR::X]) || DIFFER (y0, ct->s[NR::Y])) { - ct->s[NR::X] = x0; - ct->s[NR::Y] = y0; + if (DIFFER (pos[0], ct->s[NR::X]) || DIFFER (pos[1], ct->s[NR::Y])) { + ct->s[NR::X] = pos[0]; + ct->s[NR::Y] = pos[1]; sp_canvas_item_request_update (SP_CANVAS_ITEM (ct)); } sp_canvas_item_request_update (SP_CANVAS_ITEM (ct)); } -void -sp_canvastext_set_coords (SPCanvasText *ct, const NR::Point start) -{ - sp_canvastext_set_coords(ct, start[0], start[1]); -} - void sp_canvastext_set_text (SPCanvasText *ct, const char* new_text) { diff --git a/src/display/canvas-bpath.h b/src/display/canvas-bpath.h index 0f0b44484..5a6e6e7ff 100644 --- a/src/display/canvas-bpath.h +++ b/src/display/canvas-bpath.h @@ -101,6 +101,7 @@ void sp_canvas_bpath_set_stroke (SPCanvasBPath *cbp, guint32 rgba, gdouble width */ struct SPItem; +struct SPDesktop; #define SP_TYPE_CANVASTEXT (sp_canvastext_get_type ()) #define SP_CANVASTEXT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_CANVASTEXT, SPCanvasText)) @@ -109,6 +110,7 @@ struct SPItem; struct SPCanvasText : public SPCanvasItem{ SPItem *item; // the item to which this line belongs in some sense; may be NULL for some users guint32 rgba; + SPDesktop *desktop; // the desktop to which this text is attached; needed for coordinate transforms (TODO: these should be eliminated) char* text; NR::Point s; @@ -121,7 +123,7 @@ struct SPCanvasTextClass : public SPCanvasItemClass{}; GtkType sp_canvastext_get_type (void); -SPCanvasItem *sp_canvastext_new(SPCanvasGroup *parent, Geom::Point pos, char *text); +SPCanvasItem *sp_canvastext_new(SPCanvasGroup *parent, SPDesktop *desktop, Geom::Point pos, char *text); void sp_canvastext_set_rgba32 (SPCanvasText *ct, guint32 rgba); void sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0); diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index e90163781..f41e752cb 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -93,7 +93,7 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise > const & pwd2_i g_free(dist); double angle = Geom::angle_between(dir, Geom::Point(1,0)); - info_text.setPos(inkscape_active_desktop()->doc2dt((A + B) / 2 + 2.0 * n).to_2geom()); + info_text.setPos((A + B) / 2 + 2.0 * n); info_text.setAnchor(std::sin(angle), -std::cos(angle)); Point C, D; diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp index f55dca4d8..fab69578a 100644 --- a/src/live_effects/parameter/text.cpp +++ b/src/live_effects/parameter/text.cpp @@ -31,7 +31,8 @@ TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, value(default_value), defvalue(default_value) { - canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(inkscape_active_desktop()), Geom::Point(0,0), ""); + SPDesktop *desktop = inkscape_active_desktop(); // FIXME: we shouldn't use this! + canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), ""); sp_canvastext_set_text (canvas_text, default_value.c_str()); sp_canvastext_set_coords (canvas_text, 0, 0); }