From c0c46f35e9dc39d15e9232b92176858ac49734d0 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 2 Oct 2010 20:59:18 +0200 Subject: Implement snapping in the text tool (bzr r9810) --- src/text-context.cpp | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'src/text-context.cpp') diff --git a/src/text-context.cpp b/src/text-context.cpp index 4f89bd1e1..c10e0d1a0 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -610,7 +610,14 @@ sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *cons event_context->within_tolerance = true; Geom::Point const button_pt(event->button.x, event->button.y); - tc->p0 = desktop->w2d(button_pt); + Geom::Point button_dt(desktop->w2d(button_pt)); + + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); + m.unSetup(); + + tc->p0 = button_dt; Inkscape::Rubberband::get(desktop)->start(desktop, tc->p0); sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, @@ -645,7 +652,12 @@ sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *cons event_context->within_tolerance = false; Geom::Point const motion_pt(event->motion.x, event->motion.y); - Geom::Point const p = desktop->w2d(motion_pt); + Geom::Point p = desktop->w2d(motion_pt); + + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); + m.unSetup(); Inkscape::Rubberband::get(desktop)->move(p); gobble_motion_events(GDK_BUTTON1_MASK); @@ -657,10 +669,26 @@ sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *cons g_string_free(xs, FALSE); g_string_free(ys, FALSE); + } else if (!sp_event_context_knot_mouseover(event_context)) { + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point motion_dt(desktop->w2d(motion_w)); + m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE)); + m.unSetup(); } break; case GDK_BUTTON_RELEASE: if (event->button.button == 1 && !event_context->space_panning) { + sp_event_context_discard_delayed_snap_event(event_context); + + Geom::Point p1 = desktop->w2d(Geom::Point(event->button.x, event->button.y)); + + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); + m.freeSnapReturnByRef(p1, Inkscape::SNAPSOURCE_NODE_HANDLE); + m.unSetup(); if (tc->grabbed) { sp_canvas_item_ungrab(tc->grabbed, GDK_CURRENT_TIME); @@ -672,9 +700,7 @@ sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *cons if (tc->creating && event_context->within_tolerance) { /* Button 1, set X & Y & new item */ sp_desktop_selection(desktop)->clear(); - Geom::Point dtp = desktop->w2d(Geom::Point(event->button.x, event->button.y)); - tc->pdoc = desktop->dt2doc(dtp); - + tc->pdoc = desktop->dt2doc(p1); tc->show = TRUE; tc->phase = 1; tc->nascent_object = 1; // new object was just created @@ -682,15 +708,13 @@ sp_text_context_root_handler(SPEventContext *const event_context, GdkEvent *cons /* Cursor */ sp_canvas_item_show(tc->cursor); // Cursor height is defined by the new text object's font size; it needs to be set - // articifically here, for the text object does not exist yet: + // artificially here, for the text object does not exist yet: double cursor_height = sp_desktop_get_font_size_tool(desktop); - sp_ctrlline_set_coords(SP_CTRLLINE(tc->cursor), dtp, dtp + Geom::Point(0, cursor_height)); + sp_ctrlline_set_coords(SP_CTRLLINE(tc->cursor), p1, p1 + Geom::Point(0, cursor_height)); event_context->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Type text; Enter to start new line.")); // FIXME:: this is a copy of a string from _update_cursor below, do not desync event_context->within_tolerance = false; } else if (tc->creating) { - Geom::Point const button_pt(event->button.x, event->button.y); - Geom::Point p1 = desktop->w2d(button_pt); double cursor_height = sp_desktop_get_font_size_tool(desktop); if (fabs(p1[Geom::Y] - tc->p0[Geom::Y]) > cursor_height) { // otherwise even one line won't fit; most probably a slip of hand (even if bigger than tolerance) -- cgit v1.2.3 From 144819c918dc761641c3cb5a490205fb73194ee3 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Wed, 17 Nov 2010 13:12:56 +1100 Subject: Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in all 1074 Vim modelines. The reason for this is that (a) setting the encoding isn't nice, and (b) Vim 7.3 (with modeline enabled) disallows it and pops up an error whenever you open any file with it ("invalid modeline"). Also corrected five deviant modestrings: * src/ui/widget/dock.cpp and src/ui/widget/dock.h: missing colon at the end * src/ui/dialog/tile.cpp: removed gratuitous second colon at the end * src/helper/units-test.h: removed gratuitous space before a colon * share/extensions/export_gimp_palette.py: missing textwidth=99 That's my geekiest commit yet. (bzr r9900) --- src/text-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/text-context.cpp') diff --git a/src/text-context.cpp b/src/text-context.cpp index c10e0d1a0..9d94e0e78 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -1798,4 +1798,4 @@ Inkscape::Text::Layout::iterator *sp_text_context_get_cursor_position(SPTextCont fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3