diff options
| author | Diederik van Lierop <mail@diedenrezi.nl> | 2012-01-01 15:46:12 +0000 |
|---|---|---|
| committer | Diederik van Lierop <mail@diedenrezi.nl> | 2012-01-01 15:46:12 +0000 |
| commit | 6a7bd5175bba266e10ff5eac5c630ec3115b2e19 (patch) | |
| tree | e3982ca0e391ecc060d2f7403e77a936783979a2 /src/display | |
| parent | Item and image properties dialog update: restoring correct behaviour in case ... (diff) | |
| download | inkscape-6a7bd5175bba266e10ff5eac5c630ec3115b2e19.tar.gz inkscape-6a7bd5175bba266e10ff5eac5c630ec3115b2e19.zip | |
1) Fix CanvasText alignment bugs caused by static variables, uninitialized variables, and variable border width
2) Snap tooltips no longer overlap with measure tool tooltips, and now have a background color (similar to the measure tool)
(bzr r10816)
Diffstat (limited to 'src/display')
| -rw-r--r-- | src/display/canvas-text.cpp | 61 | ||||
| -rw-r--r-- | src/display/canvas-text.h | 6 | ||||
| -rw-r--r-- | src/display/snap-indicator.cpp | 23 |
3 files changed, 53 insertions, 37 deletions
diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 809bb4eeb..a563bddac 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -74,6 +74,8 @@ static void sp_canvastext_init (SPCanvasText *canvastext) { canvastext->anchor_position = TEXT_ANCHOR_CENTER; + canvastext->anchor_offset_x = 0; + canvastext->anchor_offset_y = 0; canvastext->rgba = 0x33337fff; canvastext->rgba_stroke = 0xffffffff; canvastext->rgba_background = 0x0000007f; @@ -84,6 +86,9 @@ sp_canvastext_init (SPCanvasText *canvastext) canvastext->item = NULL; canvastext->desktop = NULL; canvastext->text = NULL; + canvastext->outline = false; + canvastext->background = false; + canvastext->border = 3; // must be a constant, and not proportional to any width, height, or fontsize to allow alignment with other text boxes } static void @@ -102,10 +107,6 @@ sp_canvastext_destroy (GtkObject *object) (* GTK_OBJECT_CLASS (parent_class_ct)->destroy) (object); } -// these are set in sp_canvastext_update() and then re-used in sp_canvastext_render(), which is called afterwards -static double anchor_offset_x = 0; -static double anchor_offset_y = 0; - static void sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf) { @@ -117,8 +118,8 @@ sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf) Geom::Point s = cl->s * cl->affine; double offsetx = s[Geom::X] - buf->rect.left(); double offsety = s[Geom::Y] - buf->rect.top(); - offsetx -= anchor_offset_x; - offsety -= anchor_offset_y; + offsetx -= cl->anchor_offset_x; + offsety -= cl->anchor_offset_y; cairo_set_font_size(buf->ct, cl->fontsize); @@ -126,7 +127,7 @@ sp_canvastext_render (SPCanvasItem *item, SPCanvasBuf *buf) cairo_text_extents_t extents; cairo_text_extents(buf->ct, cl->text, &extents); - double border = extents.height*0.5; + double border = cl->border; cairo_rectangle(buf->ct, offsetx - extents.x_bearing - border, offsety + extents.y_bearing - border, extents.width + 2*border, @@ -172,7 +173,7 @@ sp_canvastext_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned i cairo_set_font_size(tmp_buf, cl->fontsize); cairo_text_extents_t extents; cairo_text_extents(tmp_buf, cl->text, &extents); - double border = extents.height; + double border = cl->border; item->x1 = s[Geom::X] - extents.x_bearing - 2*border; item->y1 = s[Geom::Y] + extents.y_bearing - 2*border; @@ -182,36 +183,36 @@ sp_canvastext_update (SPCanvasItem *item, Geom::Affine const &affine, unsigned i // adjust update region according to anchor shift switch (cl->anchor_position){ case TEXT_ANCHOR_LEFT: - anchor_offset_x = -2*border; - anchor_offset_y = -extents.height/2; + cl->anchor_offset_x = -2*border; + cl->anchor_offset_y = -extents.height/2; break; case TEXT_ANCHOR_RIGHT: - anchor_offset_x = extents.width + 2*border; - anchor_offset_y = -extents.height/2; + cl->anchor_offset_x = extents.width + 2*border; + cl->anchor_offset_y = -extents.height/2; break; case TEXT_ANCHOR_BOTTOM: - anchor_offset_x = extents.width/2; - anchor_offset_y = 2*border; + cl->anchor_offset_x = extents.width/2; + cl->anchor_offset_y = 2*border; break; case TEXT_ANCHOR_TOP: - anchor_offset_x = extents.width/2; - anchor_offset_y = -extents.height - 2*border; + cl->anchor_offset_x = extents.width/2; + cl->anchor_offset_y = -extents.height - 2*border; break; case TEXT_ANCHOR_ZERO: - anchor_offset_x = 0; - anchor_offset_y = 0; + cl->anchor_offset_x = 0; + cl->anchor_offset_y = 0; break; case TEXT_ANCHOR_CENTER: default: - anchor_offset_x = extents.width/2; - anchor_offset_y = -extents.height/2; + cl->anchor_offset_x = extents.width/2; + cl->anchor_offset_y = -extents.height/2; break; } - item->x1 -= anchor_offset_x; - item->x2 -= anchor_offset_x; - item->y1 -= anchor_offset_y; - item->y2 -= anchor_offset_y; + item->x1 -= cl->anchor_offset_x; + item->x2 -= cl->anchor_offset_x; + item->y1 -= cl->anchor_offset_y; + item->y2 -= cl->anchor_offset_y; sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2); } @@ -295,12 +296,12 @@ sp_canvastext_set_fontsize (SPCanvasText *ct, double size) ct->fontsize = size; } -void -sp_canvastext_set_anchor (SPCanvasText *ct, double anchor_x, double anchor_y) -{ - ct->anchor_x = anchor_x; - ct->anchor_y = anchor_y; -} +//void +//sp_canvastext_set_anchor (SPCanvasText *ct, double anchor_x, double anchor_y) +//{ +// ct->anchor_x = anchor_x; +// ct->anchor_y = anchor_y; +//} /* diff --git a/src/display/canvas-text.h b/src/display/canvas-text.h index 90c02717c..d21a08dbd 100644 --- a/src/display/canvas-text.h +++ b/src/display/canvas-text.h @@ -39,6 +39,7 @@ struct SPCanvasText : public SPCanvasItem { guint32 rgba_background; bool outline; bool background; + double border; CanvasTextAnchorPositionEnum anchor_position; SPDesktop *desktop; // the desktop to which this text is attached; needed for coordinate transforms (TODO: these should be eliminated) @@ -47,8 +48,8 @@ struct SPCanvasText : public SPCanvasItem { Geom::Point s; Geom::Affine affine; double fontsize; - double anchor_x; - double anchor_y; + double anchor_offset_x; + double anchor_offset_y; }; struct SPCanvasTextClass : public SPCanvasItemClass{}; @@ -62,7 +63,6 @@ void sp_canvastext_set_coords (SPCanvasText *ct, const Geom::Point start); void sp_canvastext_set_text (SPCanvasText *ct, gchar const* new_text); void sp_canvastext_set_number_as_text (SPCanvasText *ct, int num); void sp_canvastext_set_fontsize (SPCanvasText *ct, double size); -void sp_canvastext_set_anchor (SPCanvasText *ct, double anchor_x, double anchor_y); #endif // SEEN_SP_CANVASTEXT_H diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp index 3b9bb57e1..7864c0e53 100644 --- a/src/display/snap-indicator.cpp +++ b/src/display/snap-indicator.cpp @@ -6,7 +6,7 @@ * Diederik van Lierop * * Copyright (C) Johan Engelen 2009 <j.b.c.engelen@utwente.nl> - * Copyright (C) Diederik van Lierop 2010 <mail@diedenrezi.nl> + * Copyright (C) Diederik van Lierop 2010 - 2012 <mail@diedenrezi.nl> * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -22,6 +22,7 @@ #include "knot.h" #include "preferences.h" #include <glibmm/i18n.h> +#include "tools-switch.h" namespace Inkscape { namespace Display { @@ -253,15 +254,29 @@ SnapIndicator::set_new_snaptarget(Inkscape::SnappedPoint const &p, bool pre_snap } else { tooltip_str = g_strdup(source_name); } - Geom::Point tooltip_pos = p.getPoint() + _desktop->w2d(Geom::Point(15, -15)); + double fontsize = prefs->getInt("/tools/measure/fontsize"); + + Geom::Point tooltip_pos = p.getPoint(); + if (tools_isactive(_desktop, TOOLS_MEASURE)) { + // Make sure that the snap tooltips do not overlap the ones from the measure tool + tooltip_pos += _desktop->w2d(Geom::Point(0, -3*fontsize)); + } else { + tooltip_pos += _desktop->w2d(Geom::Point(0, -2*fontsize)); + } SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(_desktop), _desktop, tooltip_pos, tooltip_str); + sp_canvastext_set_fontsize(SP_CANVASTEXT(canvas_tooltip), fontsize); + SP_CANVASTEXT(canvas_tooltip)->rgba = 0xffffffff; + SP_CANVASTEXT(canvas_tooltip)->outline = false; + SP_CANVASTEXT(canvas_tooltip)->background = true; if (pre_snap) { - SP_CANVASTEXT(canvas_tooltip)->rgba = 0x7f7f7fff; + SP_CANVASTEXT(canvas_tooltip)->rgba_background = 0x33337f40; + } else { + SP_CANVASTEXT(canvas_tooltip)->rgba_background = 0x33337f7f; } + SP_CANVASTEXT(canvas_tooltip)->anchor_position = TEXT_ANCHOR_CENTER; g_free(tooltip_str); - sp_canvastext_set_anchor((SPCanvasText* )canvas_tooltip, -1, 1); _snaptarget_tooltip = _desktop->add_temporary_canvasitem(canvas_tooltip, timeout_val); // Display the bounding box, if we snapped to one |
