Code

new button for siox
[inkscape.git] / src / seltrans.cpp
1 #define __SELTRANS_C__
3 /*
4  * Helper object for transforming selected items
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   bulia byak <buliabyak@users.sf.net>
9  *   Carl Hetherington <inkscape@carlh.net>
10  *
11  * Copyright (C) 1999-2002 Lauris Kaplinski
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
20 #include <libnr/nr-matrix-ops.h>
21 #include <libnr/nr-matrix-translate-ops.h>
22 #include <libnr/nr-rotate-ops.h>
23 #include <libnr/nr-scale-ops.h>
24 #include <libnr/nr-translate-matrix-ops.h>
25 #include <libnr/nr-translate-ops.h>
26 #include <gdk/gdkkeysyms.h>
27 #include "document.h"
28 #include "sp-namedview.h"
29 #include "desktop.h"
30 #include "desktop-handles.h"
31 #include "desktop-style.h"
32 #include "knot.h"
33 #include "snap.h"
34 #include "selection.h"
35 #include "select-context.h"
36 #include "sp-item.h"
37 #include "sp-item-transform.h"
38 #include "seltrans-handles.h"
39 #include "seltrans.h"
40 #include "selection-chemistry.h"
41 #include "sp-metrics.h"
42 #include <glibmm/i18n.h>
43 #include "display/sp-ctrlline.h"
44 #include "prefs-utils.h"
45 #include "xml/repr.h"
47 #include "isnan.h" //temp fix.  make sure included last
49 static void sp_remove_handles(SPKnot *knot[], gint num);
51 static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, gpointer data);
52 static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint state, gpointer data);
53 static void sp_sel_trans_handle_click(SPKnot *knot, guint state, gpointer data);
54 static void sp_sel_trans_handle_new_event(SPKnot *knot, NR::Point *position, guint32 state, gpointer data);
55 static gboolean sp_sel_trans_handle_request(SPKnot *knot, NR::Point *p, guint state, gboolean *data);
57 extern GdkPixbuf *handles[];
59 static gboolean sp_seltrans_handle_event(SPKnot *knot, GdkEvent *event, gpointer)
60 {
61     switch (event->type) {
62         case GDK_MOTION_NOTIFY:
63             break;
64         case GDK_KEY_PRESS:
65             if (get_group0_keyval (&event->key) == GDK_space) {
66                 /* stamping mode: both mode(show content and outline) operation with knot */
67                 if (!SP_KNOT_IS_GRABBED(knot)) {
68                     return FALSE;
69                 }
70                 SPDesktop *desktop = knot->desktop;
71                 Inkscape::SelTrans *seltrans = SP_SELECT_CONTEXT(desktop->event_context)->_seltrans;
72                 seltrans->stamp();
73                 return TRUE;
74             }
75             break;
76         default:
77             break;
78     }
80     return FALSE;
81 }
83 Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
84     _desktop(desktop),
85     _selcue(desktop),
86     _state(STATE_SCALE),
87     _show(SHOW_CONTENT),
88     _grabbed(false),
89     _show_handles(true),
90     _box(NR::Point(0,0), NR::Point(0,0)),
91     _chandle(NULL),
92     _stamp_cache(NULL),
93     _message_context(desktop->messageStack())
94 {
95     g_return_if_fail(desktop != NULL);
97     for (int i = 0; i < 8; i++) {
98         _shandle[i] = NULL;
99         _rhandle[i] = NULL;
100     }
102     _updateVolatileState();
104     _center_is_set = false; // reread _center from items, or set to bbox midpoint
106     _updateHandles();
108     _selection = SP_DT_SELECTION(desktop);
110     _norm = sp_canvas_item_new(SP_DT_CONTROLS(desktop),
111                                SP_TYPE_CTRL,
112                                "anchor", GTK_ANCHOR_CENTER,
113                                "mode", SP_CTRL_MODE_COLOR,
114                                "shape", SP_CTRL_SHAPE_BITMAP,
115                                "size", 13.0,
116                                "filled", TRUE,
117                                "fill_color", 0x00000000,
118                                "stroked", TRUE,
119                                "stroke_color", 0x000000a0,
120                                "pixbuf", handles[12],
121                                NULL);
123     _grip = sp_canvas_item_new(SP_DT_CONTROLS(desktop),
124                                SP_TYPE_CTRL,
125                                "anchor", GTK_ANCHOR_CENTER,
126                                "mode", SP_CTRL_MODE_XOR,
127                                "shape", SP_CTRL_SHAPE_CROSS,
128                                "size", 7.0,
129                                "filled", TRUE,
130                                "fill_color", 0xffffff7f,
131                                "stroked", TRUE,
132                                "stroke_color", 0xffffffff,
133                                "pixbuf", handles[12],
134                                NULL);
136     sp_canvas_item_hide(_grip);
137     sp_canvas_item_hide(_norm);
139     for (int i = 0; i < 4; i++) {
140         _l[i] = sp_canvas_item_new(SP_DT_CONTROLS(desktop), SP_TYPE_CTRLLINE, NULL);
141         sp_canvas_item_hide(_l[i]);
142     }
144     _sel_changed_connection = _selection->connectChanged(
145         sigc::mem_fun(*this, &Inkscape::SelTrans::_selChanged)
146         );
148     _sel_modified_connection = _selection->connectModified(
149         sigc::mem_fun(*this, &Inkscape::SelTrans::_selModified)
150         );
153 Inkscape::SelTrans::~SelTrans()
155     _sel_changed_connection.disconnect();
156     _sel_modified_connection.disconnect();
158     for (unsigned int i = 0; i < 8; i++) {
159         if (_shandle[i]) {
160             g_object_unref(G_OBJECT(_shandle[i]));
161             _shandle[i] = NULL;
162         }
163         if (_rhandle[i]) {
164             g_object_unref(G_OBJECT(_rhandle[i]));
165             _rhandle[i] = NULL;
166         }
167     }
168     if (_chandle) {
169         g_object_unref(G_OBJECT(_chandle));
170         _chandle = NULL;
171     }
173     if (_norm) {
174         gtk_object_destroy(GTK_OBJECT(_norm));
175         _norm = NULL;
176     }
177     if (_grip) {
178         gtk_object_destroy(GTK_OBJECT(_grip));
179         _grip = NULL;
180     }
181     for (int i = 0; i < 4; i++) {
182         if (_l[i]) {
183             gtk_object_destroy(GTK_OBJECT(_l[i]));
184             _l[i] = NULL;
185         }
186     }
188     for (unsigned i = 0; i < _items.size(); i++) {
189         sp_object_unref(SP_OBJECT(_items[i].first), NULL);
190     }
192     _items.clear();
193     _items_centers.clear();
196 void Inkscape::SelTrans::resetState()
198     _state = STATE_SCALE;
201 void Inkscape::SelTrans::increaseState()
203     if (_state == STATE_SCALE) {
204         _state = STATE_ROTATE;
205     } else {
206         _state = STATE_SCALE;
207     }
209     _center_is_set = true; // no need to reread center
211     _updateHandles();
214 void Inkscape::SelTrans::setCenter(NR::Point const &p)
216     _center = p;
217     _center_is_set = true;
219     // Write the new center position into all selected items
220     for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) {
221         SPItem *it = (SPItem*)sp_object_ref(SP_OBJECT(l->data), NULL);
222         it->setCenter(p);
223         SP_OBJECT(it)->updateRepr();
224     }
225     sp_document_maybe_done (SP_DT_DOCUMENT(_desktop), "center::move");
227     _updateHandles();
230 void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles)
232     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
234     g_return_if_fail(!_grabbed);
236     _grabbed = true;
237     _show_handles = show_handles;
238     _updateVolatileState();
240     _changed = false;
242     if (_empty) {
243         return;
244     }
246     for (GSList const *l = selection->itemList(); l; l = l->next) {
247         SPItem *it = (SPItem*)sp_object_ref(SP_OBJECT(l->data), NULL);
248         _items.push_back(std::pair<SPItem *, NR::Matrix>(it, sp_item_i2d_affine(it)));
249         _items_centers.push_back(std::pair<SPItem *, NR::Point>(it, it->getCenter())); // for content-dragging, we need to remember original centers
250     }
252     _current.set_identity();
254     _point = p;
256     _snap_points = selection->getSnapPoints();
257     _bbox_points = selection->getBBoxPoints();
259     gchar const *scale_origin = prefs_get_string_attribute("tools.select", "scale_origin");
260     bool const origin_on_bbox = (scale_origin == NULL || !strcmp(scale_origin, "bbox"));
261     NR::Rect op_box = _box;
262     if (origin_on_bbox == false && _snap_points.empty() == false) {
263         std::vector<NR::Point>::iterator i = _snap_points.begin();
264         op_box = NR::Rect(*i, *i);
265         i++;
266         while (i != _snap_points.end()) {
267             op_box.expandTo(*i);
268             i++;
269         }
270     }
272     _opposite = ( op_box.min() + ( op_box.dimensions() * NR::scale(1-x, 1-y) ) );
274     if ((x != -1) && (y != -1)) {
275         sp_canvas_item_show(_norm);
276         sp_canvas_item_show(_grip);
277     }
279     if (_show == SHOW_OUTLINE) {
280         for (int i = 0; i < 4; i++)
281             sp_canvas_item_show(_l[i]);
282     }
285     _updateHandles();
286     g_return_if_fail(_stamp_cache == NULL);
289 void Inkscape::SelTrans::transform(NR::Matrix const &rel_affine, NR::Point const &norm)
291     g_return_if_fail(_grabbed);
292     g_return_if_fail(!_empty);
294     NR::Matrix const affine( NR::translate(-norm) * rel_affine * NR::translate(norm) );
296     if (_show == SHOW_CONTENT) {
297         // update the content
298         for (unsigned i = 0; i < _items.size(); i++) {
299             SPItem &item = *_items[i].first;
300             NR::Matrix const &prev_transform = _items[i].second;
301             sp_item_set_i2d_affine(&item, prev_transform * affine);
302         }
303     } else {
304         NR::Point p[4];
305         /* update the outline */
306         for (unsigned i = 0 ; i < 4 ; i++) {
307             p[i] = _box.corner(i) * affine;
308         }
309         for (unsigned i = 0 ; i < 4 ; i++) {
310             sp_ctrlline_set_coords(SP_CTRLLINE(_l[i]), p[i], p[(i+1)%4]);
311         }
312     }
314     _current = affine;
315     _changed = true;
316     _updateHandles();
319 void Inkscape::SelTrans::ungrab()
321     g_return_if_fail(_grabbed);
323     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
324     bool updh = true;
325     if (!_empty && _changed) {
326         sp_selection_apply_affine(selection, _current, (_show == SHOW_OUTLINE)? true : false);
327         _center *= _current;
328         _center_is_set = true;
330 // If dragging showed content live, sp_selection_apply_affine cannot change the centers
331 // appropriately - it does not know the original positions of the centers (all objects already have
332 // the new bboxes). So we need to reset the centers from our saved array.
333         if (_show != SHOW_OUTLINE && !_current.is_translation()) {
334             for (unsigned i = 0; i < _items_centers.size(); i++) {
335                 SPItem *currentItem = _items_centers[i].first;
336                 if (currentItem->isCenterSet()) { // only if it's already set
337                     currentItem->setCenter (_items_centers[i].second * _current);
338                     SP_OBJECT(currentItem)->updateRepr();
339                 }
340             }
341         }
343         sp_document_done(SP_DT_DOCUMENT(_desktop));
344         updh = false;
345     }
347     for (unsigned i = 0; i < _items.size(); i++) {
348         sp_object_unref(SP_OBJECT(_items[i].first), NULL);
349     }
350     _items.clear();
351     _items_centers.clear();
353     _grabbed = false;
354     _show_handles = true;
356     sp_canvas_item_hide(_norm);
357     sp_canvas_item_hide(_grip);
359     if (_show == SHOW_OUTLINE) {
360         for (int i = 0; i < 4; i++)
361             sp_canvas_item_hide(_l[i]);
362     }
364     _updateVolatileState();
365     if (updh) {
366         _updateHandles();
367     }
368     if (_stamp_cache) {
369         g_slist_free(_stamp_cache);
370         _stamp_cache = NULL;
371     }
373     _message_context.clear();
376 /* fixme: This is really bad, as we compare positions for each stamp (Lauris) */
377 /* fixme: IMHO the best way to keep sort cache would be to implement timestamping at last */
379 void Inkscape::SelTrans::stamp()
381     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
383     /* stamping mode */
384     if (!_empty) {
385         GSList *l;
386         if (_stamp_cache) {
387             l = _stamp_cache;
388         } else {
389             /* Build cache */
390             l  = g_slist_copy((GSList *) selection->itemList());
391             l  = g_slist_sort(l, (GCompareFunc) sp_object_compare_position);
392             _stamp_cache = l;
393         }
395         while (l) {
396             SPItem *original_item = SP_ITEM(l->data);
397             Inkscape::XML::Node *original_repr = SP_OBJECT_REPR(original_item);
399             // remember the position of the item
400             gint pos = original_repr->position();
401             // remember parent
402             Inkscape::XML::Node *parent = sp_repr_parent(original_repr);
404             Inkscape::XML::Node *copy_repr = original_repr->duplicate();
406             // add the new repr to the parent
407             parent->appendChild(copy_repr);
408             // move to the saved position
409             copy_repr->setPosition(pos > 0 ? pos : 0);
411             SPItem *copy_item = (SPItem *) SP_DT_DOCUMENT(_desktop)->getObjectByRepr(copy_repr);
413             NR::Matrix const *new_affine;
414             if (_show == SHOW_OUTLINE) {
415                 NR::Matrix const i2d(sp_item_i2d_affine(original_item));
416                 NR::Matrix const i2dnew( i2d * _current );
417                 sp_item_set_i2d_affine(copy_item, i2dnew);
418                 new_affine = &copy_item->transform;
419             } else {
420                 new_affine = &original_item->transform;
421             }
423             sp_item_write_transform(copy_item, copy_repr, *new_affine);
425             Inkscape::GC::release(copy_repr);
426             l = l->next;
427         }
428         sp_document_done(SP_DT_DOCUMENT(_desktop));
429     }
432 void Inkscape::SelTrans::_updateHandles()
434     if ( !_show_handles || _empty )
435     {
436         sp_remove_handles(_shandle, 8);
437         sp_remove_handles(_rhandle, 8);
438         sp_remove_handles(&_chandle, 1);
439         return;
440     }
442     // center handle
443     if ( _chandle == NULL ) {
444         _chandle = sp_knot_new(_desktop);
445         g_object_set(G_OBJECT(_chandle),
446                      "anchor", handle_center.anchor,
447                      "shape", SP_CTRL_SHAPE_BITMAP,
448                      "size", 13,
449                      "mode", SP_CTRL_MODE_XOR,
450                      "fill", 0x00000000,
451                      "fill_mouseover", 0x00000000,
452                      "stroke", 0x000000ff,
453                      "stroke_mouseover", 0xff0000b0,
454                      "pixbuf", handles[handle_center.control],
455                      "tip", _("<b>Center</b> of rotation and skewing: drag to reposition; scaling with Shift also uses this center"),
456                      NULL);
457         g_signal_connect(G_OBJECT(_chandle), "request",
458                          G_CALLBACK(sp_sel_trans_handle_request), (gpointer) &handle_center);
459         g_signal_connect(G_OBJECT(_chandle), "moved",
460                          G_CALLBACK(sp_sel_trans_handle_new_event), (gpointer) &handle_center);
461         g_signal_connect(G_OBJECT(_chandle), "grabbed",
462                          G_CALLBACK(sp_sel_trans_handle_grab), (gpointer) &handle_center);
463         g_signal_connect(G_OBJECT(_chandle), "ungrabbed",
464                          G_CALLBACK(sp_sel_trans_handle_ungrab), (gpointer) &handle_center);
465         g_signal_connect(G_OBJECT(_chandle), "clicked",
466                          G_CALLBACK(sp_sel_trans_handle_click), (gpointer) &handle_center);
467     }
469     sp_remove_handles(&_chandle, 1);
470     if ( _state == STATE_SCALE ) {
471         sp_remove_handles(_rhandle, 8);
472         _showHandles(_shandle, handles_scale, 8,
473                     _("<b>Squeeze or stretch</b> selection; with <b>Ctrl</b> to scale uniformly; with <b>Shift</b> to scale around rotation center"),
474                     _("<b>Scale</b> selection; with <b>Ctrl</b> to scale uniformly; with <b>Shift</b> to scale around rotation center"));
475     } else {
476         sp_remove_handles(_shandle, 8);
477         _showHandles(_rhandle, handles_rotate, 8,
478                     _("<b>Skew</b> selection; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to skew around the opposite side"),
479                     _("<b>Rotate</b> selection; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to rotate around the opposite corner"));
480     }
482     if (!_center_is_set) {
483         _center = _desktop->selection->center();
484         _center_is_set = true;
485     }
487     if ( _state == STATE_SCALE ) {
488         sp_knot_hide(_chandle);
489     } else {
490         sp_knot_show(_chandle);
491         sp_knot_moveto(_chandle, &_center);
492     }
495 void Inkscape::SelTrans::_updateVolatileState()
497     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
498     _empty = selection->isEmpty();
500     if (_empty) {
501         return;
502     }
504     _box = selection->bounds();
505     if (_box.isEmpty()) {
506         _empty = true;
507         return;
508     }
510     _strokewidth = stroke_average_width (selection->itemList());
512     _current.set_identity();
515 static void sp_remove_handles(SPKnot *knot[], gint num)
517     for (int i = 0; i < num; i++) {
518         if (knot[i] != NULL) {
519             sp_knot_hide(knot[i]);
520         }
521     }
524 void Inkscape::SelTrans::_showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
525                              gchar const *even_tip, gchar const *odd_tip)
527     g_return_if_fail( !_empty );
529     for (int i = 0; i < num; i++) {
530         if (knot[i] == NULL) {
531             knot[i] = sp_knot_new(_desktop);
532             g_object_set(G_OBJECT(knot[i]),
533                          "anchor", handle[i].anchor,
534                          "shape", SP_CTRL_SHAPE_BITMAP,
535                          "size", 13,
536                          "mode", SP_KNOT_MODE_XOR,
537                          "fill", 0x000000ff, // inversion
538                          "fill_mouseover", 0x00ff6600, // green
539                          "stroke", 0x000000ff, // inversion
540                          "stroke_mouseover", 0x000000ff, // inversion
541                          "pixbuf", handles[handle[i].control],
542                          "tip", i % 2 ? even_tip : odd_tip,
543                          NULL);
545             g_signal_connect(G_OBJECT(knot[i]), "request",
546                              G_CALLBACK(sp_sel_trans_handle_request), (gpointer) &handle[i]);
547             g_signal_connect(G_OBJECT(knot[i]), "moved",
548                              G_CALLBACK(sp_sel_trans_handle_new_event), (gpointer) &handle[i]);
549             g_signal_connect(G_OBJECT(knot[i]), "grabbed",
550                              G_CALLBACK(sp_sel_trans_handle_grab), (gpointer) &handle[i]);
551             g_signal_connect(G_OBJECT(knot[i]), "ungrabbed",
552                              G_CALLBACK(sp_sel_trans_handle_ungrab), (gpointer) &handle[i]);
553             g_signal_connect(G_OBJECT(knot[i]), "event", G_CALLBACK(sp_seltrans_handle_event), (gpointer) &handle[i]);
554         }
555         sp_knot_show(knot[i]);
557         NR::Point const handle_pt(handle[i].x, handle[i].y);
558         NR::Point p( _box.min()
559                      + ( _box.dimensions()
560                          * NR::scale(handle_pt) ) );
562         sp_knot_moveto(knot[i], &p);
563     }
566 static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, gpointer data)
568     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleGrab(
569         knot, state, *(SPSelTransHandle const *) data
570         );
573 static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint state, gpointer data)
575     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->ungrab();
578 static void sp_sel_trans_handle_new_event(SPKnot *knot, NR::Point *position, guint state, gpointer data)
580     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleNewEvent(
581         knot, position, state, *(SPSelTransHandle const *) data
582         );
585 static gboolean sp_sel_trans_handle_request(SPKnot *knot, NR::Point *position, guint state, gboolean *data)
587     return SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleRequest(
588         knot, position, state, *(SPSelTransHandle const *) data
589         );
592 static void sp_sel_trans_handle_click(SPKnot *knot, guint state, gpointer data)
594     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleClick(
595         knot, state, *(SPSelTransHandle const *) data
596         );
599 void Inkscape::SelTrans::handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle)
601     switch (handle.anchor) {
602         case GTK_ANCHOR_CENTER:
603             if (state & GDK_SHIFT_MASK) {
604                 // Unset the  center position for all selected items
605                 for (GSList const *l = _desktop->selection->itemList(); l; l = l->next) {
606                     SPItem *it = (SPItem*)sp_object_ref(SP_OBJECT(l->data), NULL);
607                     it->unsetCenter();
608                     SP_OBJECT(it)->updateRepr();
609                 }
610                 sp_document_maybe_done (SP_DT_DOCUMENT(_desktop), "center::unset");
611             }
612             break;
613         default:
614             break;
615     }
618 void Inkscape::SelTrans::handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle)
620     switch (handle.anchor) {
621         case GTK_ANCHOR_CENTER:
622             g_object_set(G_OBJECT(_grip),
623                          "shape", SP_CTRL_SHAPE_BITMAP,
624                          "size", 13.0,
625                          NULL);
626             sp_canvas_item_show(_grip);
627             break;
628         default:
629             g_object_set(G_OBJECT(_grip),
630                          "shape", SP_CTRL_SHAPE_CROSS,
631                          "size", 7.0,
632                          NULL);
633             sp_canvas_item_show(_norm);
634             sp_canvas_item_show(_grip);
636             break;
637     }
639     grab(sp_knot_position(knot), handle.x, handle.y, FALSE);
643 void Inkscape::SelTrans::handleNewEvent(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle)
645     if (!SP_KNOT_IS_GRABBED(knot)) {
646         return;
647     }
649     // in case items have been unhooked from the document, don't
650     // try to continue processing events for them.
651     for (unsigned int i = 0; i < _items.size(); i++) {
652         if (!SP_OBJECT_DOCUMENT(SP_OBJECT(_items[i].first)) ) {
653             return;
654         }
655     }
657     handle.action(this, handle, *position, state);
661 gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle)
663     if (!SP_KNOT_IS_GRABBED(knot)) {
664         return TRUE;
665     }
667     knot->desktop->set_coordinate_status(*position);
668     knot->desktop->setPosition(*position);
671     if (state & GDK_MOD1_MASK) {
672         *position = _point + ( *position - _point ) / 10;
673     }
675     if (!(state & GDK_SHIFT_MASK) == !(_state == STATE_ROTATE)) {
676         _origin = _opposite;
677     } else {
678         _origin = _center;
679     }
680     if (handle.request(this, handle, *position, state)) {
681         sp_knot_set_position(knot, position, state);
682         SP_CTRL(_grip)->moveto(*position);
683         SP_CTRL(_norm)->moveto(_origin);
684     }
686     return TRUE;
690 void Inkscape::SelTrans::_selChanged(Inkscape::Selection *selection)
692     if (!_grabbed) {
693         _updateVolatileState();
694         _center_is_set = false; // center(s) may have changed
695         _updateHandles();
696     }
699 void Inkscape::SelTrans::_selModified(Inkscape::Selection *selection, guint flags)
701     if (!_grabbed) {
702         _updateVolatileState();
704         // reset internal flag
705         _changed = false;
707         _center_is_set = false;  // center(s) may have changed
709         _updateHandles();
710     }
713 /*
714  * handlers for handle move-request
715  */
717 /** Returns -1 or 1 according to the sign of x.  Returns 1 for 0 and NaN. */
718 static double sign(double const x)
720     return ( x < 0
721              ? -1
722              : 1 );
725 gboolean sp_sel_trans_scale_request(Inkscape::SelTrans *seltrans,
726                                     SPSelTransHandle const &, NR::Point &pt, guint state)
728     return seltrans->scaleRequest(pt, state);
731 gboolean sp_sel_trans_stretch_request(Inkscape::SelTrans *seltrans,
732                                       SPSelTransHandle const &handle, NR::Point &pt, guint state)
734     return seltrans->stretchRequest(handle, pt, state);
737 gboolean sp_sel_trans_skew_request(Inkscape::SelTrans *seltrans,
738                                    SPSelTransHandle const &handle, NR::Point &pt, guint state)
740     return seltrans->skewRequest(handle, pt, state);
743 gboolean sp_sel_trans_rotate_request(Inkscape::SelTrans *seltrans,
744                                      SPSelTransHandle const &, NR::Point &pt, guint state)
746     return seltrans->rotateRequest(pt, state);
749 gboolean sp_sel_trans_center_request(Inkscape::SelTrans *seltrans,
750                                      SPSelTransHandle const &, NR::Point &pt, guint state)
752     return seltrans->centerRequest(pt, state);
755 gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
757     using NR::X;
758     using NR::Y;
760     NR::Point d = _point - _origin;
761     NR::scale s(0, 0);
763     /* Work out the new scale factors `s' */
764     for ( unsigned int i = 0 ; i < 2 ; i++ ) {
765         if ( fabs(d[i]) > 0.001 ) {
766             s[i] = ( pt[i] - _origin[i] ) / d[i];
767             if ( fabs(s[i]) < 1e-9 ) {
768                 s[i] = 1e-9;
769             }
770         }
771     }
773     /* Get a STL list of the selected items.
774     ** FIXME: this should probably be done by Inkscape::Selection.
775     */
776     std::list<SPItem const*> it;
777     for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
778         it.push_back(reinterpret_cast<SPItem*>(i->data));
779     }
781     if ((state & GDK_CONTROL_MASK) || _desktop->isToolboxButtonActive ("lock")) {
782         /* Scale is locked to a 1:1 aspect ratio, so that s[X] must be made to equal s[Y] */
784         NR::Dim2 locked_dim;
786         /* Lock aspect ratio, using the smaller of the x and y factors */
787         if (fabs(s[NR::X]) > fabs(s[NR::Y])) {
788             s[NR::X] = fabs(s[NR::Y]) * sign(s[NR::X]);
789             locked_dim = NR::X;
790         } else {
791             s[NR::Y] = fabs(s[NR::X]) * sign(s[NR::Y]);
792             locked_dim = NR::Y;
793         }
795         /* Snap the scale factor */
796         std::pair<double, bool> bb = namedview_vector_snap_list(_desktop->namedview,
797                                                                 Snapper::BBOX_POINT, _bbox_points,
798                                                                 _origin, s, it);
799         std::pair<double, bool> sn = namedview_vector_snap_list(_desktop->namedview,
800                                                                 Snapper::SNAP_POINT, _snap_points,
801                                                                 _origin, s, it);
803         double bd = bb.second ? fabs(bb.first - s[locked_dim]) : NR_HUGE;
804         double sd = sn.second ? fabs(sn.first - s[locked_dim]) : NR_HUGE;
805         double r = (bd < sd) ? bb.first : sn.first;
807         for ( unsigned int i = 0 ; i < 2 ; i++ ) {
808             s[i] = r * sign(s[i]);
809         }
811     } else {
812         /* Scale aspect ratio is unlocked */
813         for ( unsigned int i = 0 ; i < 2 ; i++ ) {
814             std::pair<double, bool> bb = namedview_dim_snap_list_scale(_desktop->namedview,
815                                                                        Snapper::BBOX_POINT, _bbox_points,
816                                                                        _origin, s[i], NR::Dim2(i), it);
817             std::pair<double, bool> sn = namedview_dim_snap_list_scale(_desktop->namedview,
818                                                                        Snapper::SNAP_POINT, _snap_points,
819                                                                        _origin, s[i], NR::Dim2(i), it);
821             /* Pick the snap that puts us closest to the original scale */
822             NR::Coord bd = bb.second ? fabs(bb.first - s[i]) : NR_HUGE;
823             NR::Coord sd = sn.second ? fabs(sn.first - s[i]) : NR_HUGE;
824             s[i] = (bd < sd) ? bb.first : sn.first;
825         }
826     }
828     /* Update the knot position */
829     pt = ( _point - _origin ) * s + _origin;
831     /* Status text */
832     _message_context.setF(Inkscape::NORMAL_MESSAGE,
833                           _("<b>Scale</b>: %0.2f%% x %0.2f%%; with <b>Ctrl</b> to lock ratio"),
834                           100 * s[NR::X], 100 * s[NR::Y]);
836     return TRUE;
839 gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state)
841     using NR::X;
842     using NR::Y;
844     NR::Dim2 axis, perp;
846     switch (handle.cursor) {
847         case GDK_TOP_SIDE:
848         case GDK_BOTTOM_SIDE:
849            axis = NR::Y;
850            perp = NR::X;
851            break;
852         case GDK_LEFT_SIDE:
853         case GDK_RIGHT_SIDE:
854            axis = NR::X;
855            perp = NR::Y;
856            break;
857         default:
858             g_assert_not_reached();
859             return TRUE;
860     };
862     if ( fabs( _point[axis] - _origin[axis] ) < 1e-15 ) {
863         return FALSE;
864     }
866     NR::scale s(1, 1);
867     s[axis] = ( ( pt[axis] - _origin[axis] )
868                 / ( _point[axis] - _origin[axis] ) );
869     if ( fabs(s[axis]) < 1e-15 ) {
870         s[axis] = 1e-15;
871     }
873     /* Get a STL list of the selected items.
874     ** FIXME: this should probably be done by Inkscape::Selection.
875     */
876     std::list<SPItem const*> it;
877     for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
878         it.push_back(reinterpret_cast<SPItem*>(i->data));
879     }
881     if ( state & GDK_CONTROL_MASK ) {
882         s[perp] = fabs(s[axis]);
884         std::pair<double, bool> sn = namedview_vector_snap_list(_desktop->namedview,
885                                                                 Snapper::BBOX_POINT,
886                                                                 _bbox_points, _origin, s, it);
887         std::pair<double, bool> bb = namedview_vector_snap_list(_desktop->namedview,
888                                                                 Snapper::SNAP_POINT,
889                                                                 _snap_points, _origin, s, it);
891         double bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
892         double sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
893         double ratio = (bd < sd) ? bb.first : sn.first;
895         s[axis] = fabs(ratio) * sign(s[axis]);
896         s[perp] = fabs(s[axis]);
897     } else {
898         std::pair<NR::Coord, bool> bb = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::BBOX_POINT,
899                                                                       _bbox_points, _origin,
900                                                                       s[axis], axis, it);
901         std::pair<NR::Coord, bool> sn = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::SNAP_POINT,
902                                                                       _snap_points, _origin,
903                                                                       s[axis], axis, it);
905         /* Pick the snap that puts us closest to the original scale */
906         NR::Coord bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
907         NR::Coord sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
908         s[axis] = (bd < sd) ? bb.first : sn.first;
909     }
911     pt = ( _point - _origin ) * NR::scale(s) + _origin;
912     if (isNaN(pt[X] + pt[Y])) {
913         g_warning("point=(%g, %g), norm=(%g, %g), s=(%g, %g)\n",
914                   _point[X], _point[Y], _origin[X], _origin[Y], s[X], s[Y]);
915     }
917     // status text
918     _message_context.setF(Inkscape::NORMAL_MESSAGE,
919                           _("<b>Scale</b>: %0.2f%% x %0.2f%%; with <b>Ctrl</b> to lock ratio"),
920                           100 * s[NR::X], 100 * s[NR::Y]);
922     return TRUE;
925 gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state)
927     using NR::X;
928     using NR::Y;
930     if (handle.cursor != GDK_SB_V_DOUBLE_ARROW && handle.cursor != GDK_SB_H_DOUBLE_ARROW) {
931         return FALSE;
932     }
934     NR::Dim2 dim_a;
935     NR::Dim2 dim_b;
936     if (handle.cursor == GDK_SB_V_DOUBLE_ARROW) {
937         dim_a = X;
938         dim_b = Y;
939     } else {
940         dim_a = Y;
941         dim_b = X;
942     }
944     double skew[2];
945     double s[2] = { 1.0, 1.0 };
947     if (fabs(_point[dim_a] - _origin[dim_a]) < NR_EPSILON) {
948         return FALSE;
949     }
951     skew[dim_a] = ( pt[dim_b] - _point[dim_b] ) / ( _point[dim_a] - _origin[dim_a] );
953     s[dim_a] = ( pt[dim_a] - _origin[dim_a] ) / ( _point[dim_a] - _origin[dim_a] );
955     if ( fabs(s[dim_a]) < 1 ) {
956         s[dim_a] = sign(s[dim_a]);
957     } else {
958         s[dim_a] = floor( s[dim_a] + 0.5 );
959     }
961     double radians = atan(skew[dim_a] / s[dim_a]);
963     if (state & GDK_CONTROL_MASK) {
965         int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
967         if (snaps) {
968             double sections = floor( radians * snaps / M_PI + .5 );
969             if (fabs(sections) >= snaps / 2) sections = sign(sections) * (snaps / 2 - 1);
970             radians = ( M_PI / snaps ) * sections;
971         }
972         skew[dim_a] = tan(radians) * s[dim_a];
973     } else {
974         skew[dim_a] = namedview_dim_snap_list_skew(_desktop->namedview,
975                 Snapper::SNAP_POINT, _snap_points,
976                 _origin, skew[dim_a], dim_b);
977     }
979     pt[dim_b] = ( _point[dim_a] - _origin[dim_a] ) * skew[dim_a] + _point[dim_b];
980     pt[dim_a] = ( _point[dim_a] - _origin[dim_a] ) * s[dim_a] + _origin[dim_a];
982     /* status text */
983     double degrees = 180 / M_PI * radians;
984     if (degrees > 180) degrees -= 360;
985     if (degrees < -180) degrees += 360;
987     _message_context.setF(Inkscape::NORMAL_MESSAGE,
988                           // TRANSLATORS: don't modify the first ";"
989                           // (it will NOT be displayed as ";" - only the second one will be)
990                           _("<b>Skew</b>: %0.2f&#176;; with <b>Ctrl</b> to snap angle"),
991                           degrees);
993     return TRUE;
996 gboolean Inkscape::SelTrans::rotateRequest(NR::Point &pt, guint state)
998     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
1000     // rotate affine in rotate
1001     NR::Point const d1 = _point - _origin;
1002     NR::Point const d2 = pt     - _origin;
1004     NR::Coord const h1 = NR::L2(d1);
1005     if (h1 < 1e-15) return FALSE;
1006     NR::Point q1 = d1 / h1;
1007     NR::Coord const h2 = NR::L2(d2);
1008     if (fabs(h2) < 1e-15) return FALSE;
1009     NR::Point q2 = d2 / h2;
1011     double radians;
1012     if (state & GDK_CONTROL_MASK) {
1013         /* Have to restrict movement. */
1014         double cos_t = NR::dot(q1, q2);
1015         double sin_t = NR::dot(NR::rot90(q1), q2);
1016         radians = atan2(sin_t, cos_t);
1017         if (snaps) {
1018             radians = ( M_PI / snaps ) * floor( radians * snaps / M_PI + .5 );
1019         }
1020         q1 = NR::Point(1, 0);
1021         q2 = NR::Point(cos(radians), sin(radians));
1022     } else {
1023         radians = atan2(NR::dot(NR::rot90(d1), d2),
1024                         NR::dot(d1, d2));
1025     }
1027     NR::rotate const r1(q1);
1028     NR::rotate const r2(q2);
1029     pt = _point * NR::translate(-_origin) * ( r2 / r1 ) * NR::translate(_origin);
1031     /* status text */
1032     double degrees = 180 / M_PI * radians;
1033     if (degrees > 180) degrees -= 360;
1034     if (degrees < -180) degrees += 360;
1036     _message_context.setF(Inkscape::NORMAL_MESSAGE,
1037                           // TRANSLATORS: don't modify the first ";"
1038                           // (it will NOT be displayed as ";" - only the second one will be)
1039                           _("<b>Rotate</b>: %0.2f&#176;; with <b>Ctrl</b> to snap angle"), degrees);
1041     return TRUE;
1044 gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
1046     using NR::X;
1047     using NR::Y;
1049     SnapManager const m(_desktop->namedview);
1050     pt = m.freeSnap(Snapper::SNAP_POINT, pt, NULL).getPoint();
1052     if (state & GDK_CONTROL_MASK) {
1053         if ( fabs(_point[X] - pt[X]) > fabs(_point[Y] - pt[Y]) ) {
1054             pt[Y] = _point[Y];
1055         } else {
1056             pt[X] = _point[X];
1057         }
1058     }
1060     if (!(state & GDK_SHIFT_MASK)) {
1061         // screen pixels to snap center to bbox
1062 #define SNAP_DIST 5
1063         // FIXME: take from prefs
1064         double snap_dist = SNAP_DIST / _desktop->current_zoom();
1066         for (int i = 0; i < 2; i++) {
1068             if (fabs(pt[i] - _box.min()[i]) < snap_dist) {
1069                 pt[i] = _box.min()[i];
1070             }
1071             if (fabs(pt[i] - _box.midpoint()[i]) < snap_dist) {
1072                 pt[i] = _box.midpoint()[i];
1073             }
1074             if (fabs(pt[i] - _box.max()[i]) < snap_dist) {
1075                 pt[i] = _box.max()[i];
1076             }
1077         }
1078     }
1080     // status text
1081     GString *xs = SP_PX_TO_METRIC_STRING(pt[X], _desktop->namedview->getDefaultMetric());
1082     GString *ys = SP_PX_TO_METRIC_STRING(pt[Y], _desktop->namedview->getDefaultMetric());
1083     _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str);
1084     g_string_free(xs, FALSE);
1085     g_string_free(ys, FALSE);
1087     return TRUE;
1090 /*
1091  * handlers for handle movement
1092  *
1093  */
1095 void sp_sel_trans_stretch(Inkscape::SelTrans *seltrans, SPSelTransHandle const &handle, NR::Point &pt, guint state)
1097     seltrans->stretch(handle, pt, state);
1100 void sp_sel_trans_scale(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint state)
1102     seltrans->scale(pt, state);
1105 void sp_sel_trans_skew(Inkscape::SelTrans *seltrans, SPSelTransHandle const &handle, NR::Point &pt, guint state)
1107     seltrans->skew(handle, pt, state);
1110 void sp_sel_trans_rotate(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint state)
1112     seltrans->rotate(pt, state);
1115 void Inkscape::SelTrans::stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state)
1117     using NR::X;
1118     using NR::Y;
1120     NR::Dim2 dim;
1121     switch (handle.cursor) {
1122         case GDK_LEFT_SIDE:
1123         case GDK_RIGHT_SIDE:
1124             dim = X;
1125             break;
1126         case GDK_TOP_SIDE:
1127         case GDK_BOTTOM_SIDE:
1128             dim = Y;
1129             break;
1130         default:
1131             g_assert_not_reached();
1132             abort();
1133             break;
1134     }
1136     NR::Point const scale_origin(_origin);
1137     double const offset = _point[dim] - scale_origin[dim];
1138     if (!( fabs(offset) >= 1e-15 )) {
1139         return;
1140     }
1141     NR::scale s(1, 1);
1142     s[dim] = ( pt[dim] - scale_origin[dim] ) / offset;
1143     if (isNaN(s[dim])) {
1144         g_warning("s[dim]=%g, pt[dim]=%g, scale_origin[dim]=%g, point[dim]=%g\n",
1145                   s[dim], pt[dim], scale_origin[dim], _point[dim]);
1146     }
1147     if (!( fabs(s[dim]) >= 1e-15 )) {
1148         s[dim] = 1e-15;
1149     }
1150     if (state & GDK_CONTROL_MASK) {
1151         /* Preserve aspect ratio, but never flip in the dimension not being edited. */
1152         s[!dim] = fabs(s[dim]);
1153     }
1155     NR::Point new_bbox_min = _box.min() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
1156     NR::Point new_bbox_max = _box.max() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
1158     int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
1159     NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke,
1160                    new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
1162     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
1165 void Inkscape::SelTrans::scale(NR::Point &pt, guint state)
1167     NR::Point const offset = _point - _origin;
1169     NR::scale s (1, 1);
1170     for (int i = NR::X; i <= NR::Y; i++) {
1171         if (fabs(offset[i]) > 1e-9)
1172             s[i] = (pt[i] - _origin[i]) / offset[i];
1173         if (fabs(s[i]) < 1e-9)
1174             s[i] = 1e-9;
1175     }
1176     NR::Point new_bbox_min = _box.min() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
1177     NR::Point new_bbox_max = _box.max() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
1179     int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
1180     NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke,
1181                    new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
1183     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
1186 void Inkscape::SelTrans::skew(SPSelTransHandle const &handle, NR::Point &pt, guint state)
1188     NR::Point const offset = _point - _origin;
1190     unsigned dim;
1191     switch (handle.cursor) {
1192         case GDK_SB_H_DOUBLE_ARROW:
1193             dim = NR::Y;
1194             break;
1195         case GDK_SB_V_DOUBLE_ARROW:
1196             dim = NR::X;
1197             break;
1198         default:
1199             g_assert_not_reached();
1200             abort();
1201             break;
1202     }
1203     if (fabs(offset[dim]) < 1e-15) {
1204         return;
1205     }
1206     NR::Matrix skew = NR::identity();
1207     skew[2*dim + dim] = (pt[dim] - _origin[dim]) / offset[dim];
1208     skew[2*dim + (1-dim)] = (pt[1-dim] - _point[1-dim]) / offset[dim];
1209     skew[2*(1-dim) + (dim)] = 0;
1210     skew[2*(1-dim) + (1-dim)] = 1;
1212     for (int i = 0; i < 2; i++) {
1213         if (fabs(skew[3*i]) < 1e-15) {
1214             skew[3*i] = 1e-15;
1215         }
1216     }
1217     transform(skew, _origin);
1220 void Inkscape::SelTrans::rotate(NR::Point &pt, guint state)
1222     NR::Point const offset = _point - _origin;
1224     NR::Coord const h1 = NR::L2(offset);
1225     if (h1 < 1e-15) {
1226         return;
1227     }
1228     NR::Point const q1 = offset / h1;
1229     NR::Coord const h2 = NR::L2( pt - _origin );
1230     if (h2 < 1e-15) {
1231         return;
1232     }
1233     NR::Point const q2 = (pt - _origin) / h2;
1234     NR::rotate const r1(q1);
1235     NR::rotate const r2(q2);
1237     NR::Matrix rotate( r2 / r1 );
1238     transform(rotate, _origin);
1241 void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint state)
1243     seltrans->setCenter(pt);
1247 void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
1249     SnapManager const m(_desktop->namedview);
1251     /* The amount that we've moved by during this drag */
1252     NR::Point dxy = xy - _point;
1254     /* Get a STL list of the selected items.
1255     ** FIXME: this should probably be done by Inkscape::Selection.
1256     */
1257     std::list<SPItem const*> it;
1258     for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
1259         it.push_back(reinterpret_cast<SPItem*>(i->data));
1260     }
1262     bool const alt = (state & GDK_MOD1_MASK);
1263     bool const control = (state & GDK_CONTROL_MASK);
1264     bool const shift = (state & GDK_SHIFT_MASK);
1266     if (alt) {
1268         /* Alt pressed means keep offset: snap the moved distance to the grid.
1269         ** FIXME: this will snap to more than just the grid, nowadays.
1270         */
1272         dxy = m.freeSnap(Snapper::SNAP_POINT, dxy, NULL).getPoint();
1274     } else if (!shift) {
1276         /* We're snapping to things, possibly with a constraint to horizontal or
1277         ** vertical movement.  Obtain a list of possible translations and then
1278         ** pick the smallest.
1279         */
1281         /* This will be our list of possible translations */
1282         std::list<std::pair<NR::Point, bool> > s;
1284         if (control) {
1286             /* Snap to things, and also constrain to horizontal or vertical movement */
1288             for (unsigned int dim = 0; dim < 2; dim++) {
1289                 s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::BBOX_POINT,
1290                                                          _bbox_points,
1291                                                          component_vectors[dim], it, dxy));
1292                 s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAP_POINT,
1293                                                          _snap_points,
1294                                                          component_vectors[dim], it, dxy));
1295             }
1297         } else {
1299             /* Snap to things with no constraint */
1301             s.push_back(m.freeSnapTranslation(Inkscape::Snapper::BBOX_POINT,
1302                                               _bbox_points, it, dxy));
1303             s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAP_POINT,
1304                                               _snap_points, it, dxy));
1305         }
1307         /* Pick one */
1308         NR::Coord best = NR_HUGE;
1309         for (std::list<std::pair<NR::Point, bool> >::const_iterator i = s.begin(); i != s.end(); i++) {
1310             if (i->second) {
1311                 NR::Coord const m = NR::L2(i->first);
1312                 if (m < best) {
1313                     best = m;
1314                     dxy = i->first;
1315                 }
1316             }
1317         }
1318     }
1320     if (control) {
1321         /* Ensure that the horizontal and vertical constraint has been applied */
1322         if (fabs(dxy[NR::X]) > fabs(dxy[NR::Y])) {
1323             dxy[NR::Y] = 0;
1324         } else {
1325             dxy[NR::X] = 0;
1326         }
1327     }
1329     NR::Matrix const move((NR::translate(dxy)));
1330     NR::Point const norm(0, 0);
1331     transform(move, norm);
1333     // status text
1334     GString *xs = SP_PX_TO_METRIC_STRING(dxy[NR::X], _desktop->namedview->getDefaultMetric());
1335     GString *ys = SP_PX_TO_METRIC_STRING(dxy[NR::Y], _desktop->namedview->getDefaultMetric());
1336     _message_context.setF(Inkscape::NORMAL_MESSAGE, _("<b>Move</b> by %s, %s; with <b>Ctrl</b> to restrict to horizontal/vertical; with <b>Shift</b> to disable snapping"), xs->str, ys->str);
1337     g_string_free(xs, TRUE);
1338     g_string_free(ys, TRUE);
1342 /*
1343   Local Variables:
1344   mode:c++
1345   c-file-style:"stroustrup"
1346   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1347   indent-tabs-mode:nil
1348   fill-column:99
1349   End:
1350 */
1351 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :