Code

fix stroke scaling for the objects with the default 1px width
[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_new_event(SPKnot *knot, NR::Point *position, guint32 state, gpointer data);
54 static gboolean sp_sel_trans_handle_request(SPKnot *knot, NR::Point *p, guint state, gboolean *data);
56 extern GdkPixbuf *handles[];
58 static gboolean sp_seltrans_handle_event(SPKnot *knot, GdkEvent *event, gpointer)
59 {
60     switch (event->type) {
61         case GDK_MOTION_NOTIFY:
62             break;
63         case GDK_KEY_PRESS:
64             if (get_group0_keyval (&event->key) == GDK_space) {
65                 /* stamping mode: both mode(show content and outline) operation with knot */
66                 if (!SP_KNOT_IS_GRABBED(knot)) {
67                     return FALSE;
68                 }
69                 SPDesktop *desktop = knot->desktop;
70                 Inkscape::SelTrans *seltrans = SP_SELECT_CONTEXT(desktop->event_context)->_seltrans;
71                 seltrans->stamp();
72                 return TRUE;
73             }
74             break;
75         default:
76             break;
77     }
79     return FALSE;
80 }
82 Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
83     _desktop(desktop),
84     _selcue(desktop),
85     _state(STATE_SCALE),
86     _show(SHOW_CONTENT),
87     _grabbed(false),
88     _show_handles(true),
89     _box(NR::Point(0,0), NR::Point(0,0)),
90     _chandle(NULL),
91     _stamp_cache(NULL),
92     _message_context(desktop->messageStack())
93 {
94     g_return_if_fail(desktop != NULL);
96     for (int i = 0; i < 8; i++) {
97         _shandle[i] = NULL;
98         _rhandle[i] = NULL;
99     }
101     _updateVolatileState();
103     _center = _box.midpoint();
105     _updateHandles();
107     _selection = SP_DT_SELECTION(desktop);
109     _norm = sp_canvas_item_new(SP_DT_CONTROLS(desktop),
110                                SP_TYPE_CTRL,
111                                "anchor", GTK_ANCHOR_CENTER,
112                                "mode", SP_CTRL_MODE_COLOR,
113                                "shape", SP_CTRL_SHAPE_BITMAP,
114                                "size", 13.0,
115                                "filled", TRUE,
116                                "fill_color", 0x00000000,
117                                "stroked", TRUE,
118                                "stroke_color", 0x000000a0,
119                                "pixbuf", handles[12],
120                                NULL);
121     
122     _grip = sp_canvas_item_new(SP_DT_CONTROLS(desktop),
123                                SP_TYPE_CTRL,
124                                "anchor", GTK_ANCHOR_CENTER,
125                                "mode", SP_CTRL_MODE_XOR,
126                                "shape", SP_CTRL_SHAPE_CROSS,
127                                "size", 7.0,
128                                "filled", TRUE,
129                                "fill_color", 0xffffff7f,
130                                "stroked", TRUE,
131                                "stroke_color", 0xffffffff,
132                                "pixbuf", handles[12],
133                                NULL);
134     
135     sp_canvas_item_hide(_grip);
136     sp_canvas_item_hide(_norm);
138     for (int i = 0; i < 4; i++) {
139         _l[i] = sp_canvas_item_new(SP_DT_CONTROLS(desktop), SP_TYPE_CTRLLINE, NULL);
140         sp_canvas_item_hide(_l[i]);
141     }
143     _sel_changed_connection = _selection->connectChanged(
144         sigc::mem_fun(*this, &Inkscape::SelTrans::_selChanged)
145         );
147     _sel_modified_connection = _selection->connectModified(
148         sigc::mem_fun(*this, &Inkscape::SelTrans::_selModified)
149         );
152 Inkscape::SelTrans::~SelTrans()
154     _sel_changed_connection.disconnect();
155     _sel_modified_connection.disconnect();
157     for (unsigned int i = 0; i < 8; i++) {
158         if (_shandle[i]) {
159             g_object_unref(G_OBJECT(_shandle[i]));
160             _shandle[i] = NULL;
161         }
162         if (_rhandle[i]) {
163             g_object_unref(G_OBJECT(_rhandle[i]));
164             _rhandle[i] = NULL;
165         }
166     }
167     if (_chandle) {
168         g_object_unref(G_OBJECT(_chandle));
169         _chandle = NULL;
170     }
172     if (_norm) {
173         gtk_object_destroy(GTK_OBJECT(_norm));
174         _norm = NULL;
175     }
176     if (_grip) {
177         gtk_object_destroy(GTK_OBJECT(_grip));
178         _grip = NULL;
179     }
180     for (int i = 0; i < 4; i++) {
181         if (_l[i]) {
182             gtk_object_destroy(GTK_OBJECT(_l[i]));
183             _l[i] = NULL;
184         }
185     }
187     for (unsigned i = 0; i < _items.size(); i++) {
188         sp_object_unref(SP_OBJECT(_items[i].first), NULL);
189     }
191     _items.clear();
194 void Inkscape::SelTrans::resetState()
196     _state = STATE_SCALE;
199 void Inkscape::SelTrans::increaseState()
201     if (_state == STATE_SCALE) {
202         _state = STATE_ROTATE;
203     } else {
204         _state = STATE_SCALE;
205     }
207     _updateHandles();
210 void Inkscape::SelTrans::setCenter(NR::Point const &p)
212     _center = p;
213     _updateHandles();
216 void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles)
218     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
220     g_return_if_fail(!_grabbed);
222     _grabbed = true;
223     _show_handles = show_handles;
224     _updateVolatileState();
226     _changed = false;
228     if (_empty) {
229         return;
230     }
232     for (GSList const *l = selection->itemList(); l; l = l->next) {
233         SPItem *it = (SPItem*)sp_object_ref(SP_OBJECT(l->data), NULL);
234         _items.push_back(std::pair<SPItem *, NR::Matrix>(it, sp_item_i2d_affine(it)));
235     }
237     _current.set_identity();
239     _point = p;
241     _snap_points = selection->getSnapPoints();
242     _bbox_points = selection->getBBoxPoints();
244     gchar const *scale_origin = prefs_get_string_attribute("tools.select", "scale_origin");
245     bool const origin_on_bbox = (scale_origin == NULL || !strcmp(scale_origin, "bbox"));
246     NR::Rect op_box = _box;
247     if (origin_on_bbox == false && _snap_points.empty() == false) {
248         std::vector<NR::Point>::iterator i = _snap_points.begin();
249         op_box = NR::Rect(*i, *i);
250         i++;
251         while (i != _snap_points.end()) {
252             op_box.expandTo(*i);
253             i++;
254         }
255     }
257     _opposite = ( op_box.min() + ( op_box.dimensions() * NR::scale(1-x, 1-y) ) );
259     if ((x != -1) && (y != -1)) {
260         sp_canvas_item_show(_norm);
261         sp_canvas_item_show(_grip);
262     }
264     if (_show == SHOW_OUTLINE) {
265         for (int i = 0; i < 4; i++)
266             sp_canvas_item_show(_l[i]);
267     }
270     _updateHandles();
271     g_return_if_fail(_stamp_cache == NULL);
274 void Inkscape::SelTrans::transform(NR::Matrix const &rel_affine, NR::Point const &norm)
276     g_return_if_fail(_grabbed);
277     g_return_if_fail(!_empty);
279     NR::Matrix const affine( NR::translate(-norm) * rel_affine * NR::translate(norm) );
281     if (_show == SHOW_CONTENT) {
282         // update the content
283         for (unsigned i = 0; i < _items.size(); i++) {
284             SPItem &item = *_items[i].first;
285             NR::Matrix const &prev_transform = _items[i].second;
286             sp_item_set_i2d_affine(&item, prev_transform * affine);
287         }
288     } else {
289         NR::Point p[4];
290         /* update the outline */
291         for (unsigned i = 0 ; i < 4 ; i++) {
292             p[i] = _box.corner(i) * affine;
293         }
294         for (unsigned i = 0 ; i < 4 ; i++) {
295             sp_ctrlline_set_coords(SP_CTRLLINE(_l[i]), p[i], p[(i+1)%4]);
296         }
297     }
299     _current = affine;
300     _changed = true;
301     _updateHandles();
304 void Inkscape::SelTrans::_centreTrans(Inkscape::XML::Node *current) const
306     for ( Inkscape::XML::Node *child = sp_repr_children(current) ; child ; child = sp_repr_next(child) ) {
307         _centreTrans(child);
308     }
309     double const cx = sp_repr_get_double_attribute(current, "inkscape:c_rx", 9999999);
310     double const cy = sp_repr_get_double_attribute(current, "inkscape:c_ry", 9999999);
311     if (cx != 9999999) {
312         NR::Point object_centre = NR::Point(cx, cy) * _current;
313         sp_repr_set_svg_double(current, "inkscape:c_rx", object_centre[NR::X]);
314         sp_repr_set_svg_double(current, "inkscape:c_ry", object_centre[NR::Y]);
315     }
316  }
321 void Inkscape::SelTrans::ungrab()
323     g_return_if_fail(_grabbed);
325     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
327     bool updh = true;
328     if (!_empty && _changed) {
329         sp_selection_apply_affine(selection, _current, (_show == SHOW_OUTLINE)? true : false);
330         _center *= _current;
331         sp_document_done(SP_DT_DOCUMENT(_desktop));
332         updh = false;
333     }
335     for (unsigned i = 0; i < _items.size(); i++)
336     {
337         Inkscape::XML::Node *current = SP_OBJECT_REPR(_items[i].first);
338         if (current != NULL) {
339             _centreTrans(current);
340         }
342         sp_object_unref(SP_OBJECT(_items[i].first), NULL);
343     }
344     _items.clear();
346     _grabbed = false;
347     _show_handles = true;
349     sp_canvas_item_hide(_norm);
350     sp_canvas_item_hide(_grip);
352     if (_show == SHOW_OUTLINE) {
353         for (int i = 0; i < 4; i++)
354             sp_canvas_item_hide(_l[i]);
355     }
357     _updateVolatileState();
358     if (updh) {
359         _updateHandles();
360     }
361     if (_stamp_cache) {
362         g_slist_free(_stamp_cache);
363         _stamp_cache = NULL;
364     }
366     _message_context.clear();
369 /* fixme: This is really bad, as we compare positions for each stamp (Lauris) */
370 /* fixme: IMHO the best way to keep sort cache would be to implement timestamping at last */
372 void Inkscape::SelTrans::stamp()
374     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
376     /* stamping mode */
377     if (!_empty) {
378         GSList *l;
379         if (_stamp_cache) {
380             l = _stamp_cache;
381         } else {
382             /* Build cache */
383             l  = g_slist_copy((GSList *) selection->itemList());
384             l  = g_slist_sort(l, (GCompareFunc) sp_object_compare_position);
385             _stamp_cache = l;
386         }
388         while (l) {
389             SPItem *original_item = SP_ITEM(l->data);
390             Inkscape::XML::Node *original_repr = SP_OBJECT_REPR(original_item);
392             // remember the position of the item
393             gint pos = original_repr->position();
394             // remember parent
395             Inkscape::XML::Node *parent = sp_repr_parent(original_repr);
397             Inkscape::XML::Node *copy_repr = original_repr->duplicate();
399             // add the new repr to the parent
400             parent->appendChild(copy_repr);
401             // move to the saved position
402             copy_repr->setPosition(pos > 0 ? pos : 0);
404             SPItem *copy_item = (SPItem *) SP_DT_DOCUMENT(_desktop)->getObjectByRepr(copy_repr);
406             NR::Matrix const *new_affine;
407             if (_show == SHOW_OUTLINE) {
408                 NR::Matrix const i2d(sp_item_i2d_affine(original_item));
409                 NR::Matrix const i2dnew( i2d * _current );
410                 sp_item_set_i2d_affine(copy_item, i2dnew);
411                 new_affine = &copy_item->transform;
412             } else {
413                 new_affine = &original_item->transform;
414             }
416             sp_item_write_transform(copy_item, copy_repr, *new_affine);
418             Inkscape::GC::release(copy_repr);
419             l = l->next;
420         }
421         sp_document_done(SP_DT_DOCUMENT(_desktop));
422     }
425 void Inkscape::SelTrans::_updateHandles()
427     if ( !_show_handles || _empty )
428     {
429         sp_remove_handles(_shandle, 8);
430         sp_remove_handles(_rhandle, 8);
431         sp_remove_handles(&_chandle, 1);
432         return;
433     }
435     // center handle
436     if ( _chandle == NULL ) {
437         _chandle = sp_knot_new(_desktop);
438         g_object_set(G_OBJECT(_chandle),
439                      "anchor", handle_center.anchor,
440                      "shape", SP_CTRL_SHAPE_BITMAP,
441                      "size", 13,
442                      "mode", SP_CTRL_MODE_XOR,
443                      "fill", 0x00000000,
444                      "fill_mouseover", 0x00000000,
445                      "stroke", 0x000000ff,
446                      "stroke_mouseover", 0xff0000b0,
447                      "pixbuf", handles[handle_center.control],
448                      "tip", _("<b>Center</b> of rotation and skewing: drag to reposition; scaling with Shift also uses this center"),
449                      NULL);
450         g_signal_connect(G_OBJECT(_chandle), "request",
451                          G_CALLBACK(sp_sel_trans_handle_request), (gpointer) &handle_center);
452         g_signal_connect(G_OBJECT(_chandle), "moved",
453                          G_CALLBACK(sp_sel_trans_handle_new_event), (gpointer) &handle_center);
454         g_signal_connect(G_OBJECT(_chandle), "grabbed",
455                          G_CALLBACK(sp_sel_trans_handle_grab), (gpointer) &handle_center);
456         g_signal_connect(G_OBJECT(_chandle), "ungrabbed",
457                          G_CALLBACK(sp_sel_trans_handle_ungrab), (gpointer) &handle_center);
458     }
460     sp_remove_handles(&_chandle, 1);
461     if ( _state == STATE_SCALE ) {
462         sp_remove_handles(_rhandle, 8);
463         _showHandles(_shandle, handles_scale, 8,
464                     _("<b>Squeeze or stretch</b> selection; with <b>Ctrl</b> to scale uniformly; with <b>Shift</b> to scale around rotation center"),
465                     _("<b>Scale</b> selection; with <b>Ctrl</b> to scale uniformly; with <b>Shift</b> to scale around rotation center"));
466     } else {
467         sp_remove_handles(_shandle, 8);
468         _showHandles(_rhandle, handles_rotate, 8,
469                     _("<b>Skew</b> selection; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to skew around the opposite side"),
470                     _("<b>Rotate</b> selection; with <b>Ctrl</b> to snap angle; with <b>Shift</b> to rotate around the opposite corner"));
471     }
472     if ( _state == STATE_SCALE ) {
473         sp_knot_hide(_chandle);
474     } else {
475         Inkscape::Selection *selection = _desktop->selection;
476         Inkscape::XML::Node *current = selection->singleRepr();
477         if (current != NULL && sp_repr_get_double_attribute(current, "inkscape:c_rx", 99999999) != 99999999) {
478             double cx = sp_repr_get_double_attribute(current, "inkscape:c_rx", _center[NR::X]);
479             double cy = sp_repr_get_double_attribute(current, "inkscape:c_ry", _center[NR::Y]);
480             _center = NR::Point(cx, cy);
481         }
482         sp_knot_show(_chandle);
483         sp_knot_moveto(_chandle, &_center);
484     }
487 void Inkscape::SelTrans::_updateVolatileState()
489     Inkscape::Selection *selection = SP_DT_SELECTION(_desktop);
490     _empty = selection->isEmpty();
492     if (_empty) {
493         return;
494     }
496     _box = selection->bounds();
497     if (_box.isEmpty()) {
498         _empty = true;
499         return;
500     }
502     _strokewidth = stroke_average_width (selection->itemList());
504     _current.set_identity();
507 static void sp_remove_handles(SPKnot *knot[], gint num)
509     for (int i = 0; i < num; i++) {
510         if (knot[i] != NULL) {
511             sp_knot_hide(knot[i]);
512         }
513     }
516 void Inkscape::SelTrans::_showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
517                              gchar const *even_tip, gchar const *odd_tip)
519     g_return_if_fail( !_empty );
521     for (int i = 0; i < num; i++) {
522         if (knot[i] == NULL) {
523             knot[i] = sp_knot_new(_desktop);
524             g_object_set(G_OBJECT(knot[i]),
525                          "anchor", handle[i].anchor,
526                          "shape", SP_CTRL_SHAPE_BITMAP,
527                          "size", 13,
528                          "mode", SP_KNOT_MODE_XOR,
529                          "fill", 0x000000ff, // inversion
530                          "fill_mouseover", 0x00ff6600, // green
531                          "stroke", 0x000000ff, // inversion
532                          "stroke_mouseover", 0x000000ff, // inversion
533                          "pixbuf", handles[handle[i].control],
534                          "tip", i % 2 ? even_tip : odd_tip,
535                          NULL);
537             g_signal_connect(G_OBJECT(knot[i]), "request",
538                              G_CALLBACK(sp_sel_trans_handle_request), (gpointer) &handle[i]);
539             g_signal_connect(G_OBJECT(knot[i]), "moved",
540                              G_CALLBACK(sp_sel_trans_handle_new_event), (gpointer) &handle[i]);
541             g_signal_connect(G_OBJECT(knot[i]), "grabbed",
542                              G_CALLBACK(sp_sel_trans_handle_grab), (gpointer) &handle[i]);
543             g_signal_connect(G_OBJECT(knot[i]), "ungrabbed",
544                              G_CALLBACK(sp_sel_trans_handle_ungrab), (gpointer) &handle[i]);
545             g_signal_connect(G_OBJECT(knot[i]), "event", G_CALLBACK(sp_seltrans_handle_event), (gpointer) &handle[i]);
546         }
547         sp_knot_show(knot[i]);
549         NR::Point const handle_pt(handle[i].x, handle[i].y);
550         NR::Point p( _box.min()
551                      + ( _box.dimensions()
552                          * NR::scale(handle_pt) ) );
554         sp_knot_moveto(knot[i], &p);
555     }
558 static void sp_sel_trans_handle_grab(SPKnot *knot, guint state, gpointer data)
560     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleGrab(
561         knot, state, *(SPSelTransHandle const *) data
562         );
565 static void sp_sel_trans_handle_ungrab(SPKnot *knot, guint state, gpointer data)
567     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->ungrab();
570 static void sp_sel_trans_handle_new_event(SPKnot *knot, NR::Point *position, guint state, gpointer data)
572     SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleNewEvent(
573         knot, position, state, *(SPSelTransHandle const *) data
574         );
577 static gboolean sp_sel_trans_handle_request(SPKnot *knot, NR::Point *position, guint state, gboolean *data)
579     return SP_SELECT_CONTEXT(knot->desktop->event_context)->_seltrans->handleRequest(
580         knot, position, state, *(SPSelTransHandle const *) data
581         );
584 void Inkscape::SelTrans::handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle)
586     switch (handle.anchor) {
587         case GTK_ANCHOR_CENTER:
588             g_object_set(G_OBJECT(_grip),
589                          "shape", SP_CTRL_SHAPE_BITMAP,
590                          "size", 13.0,
591                          NULL);
592             sp_canvas_item_show(_grip);
593             break;
594         default:
595             g_object_set(G_OBJECT(_grip),
596                          "shape", SP_CTRL_SHAPE_CROSS,
597                          "size", 7.0,
598                          NULL);
599             sp_canvas_item_show(_norm);
600             sp_canvas_item_show(_grip);
602             break;
603     }
605     grab(sp_knot_position(knot), handle.x, handle.y, FALSE);
609 void Inkscape::SelTrans::handleNewEvent(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle)
611     if (!SP_KNOT_IS_GRABBED(knot)) {
612         return;
613     }
615     // in case items have been unhooked from the document, don't
616     // try to continue processing events for them.
617     for (unsigned int i = 0; i < _items.size(); i++) {
618         if (!SP_OBJECT_DOCUMENT(SP_OBJECT(_items[i].first)) ) {
619             return;
620         }
621     }
623     handle.action(this, handle, *position, state);
627 gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle)
629     if (!SP_KNOT_IS_GRABBED(knot)) {
630         return TRUE;
631     }
633     knot->desktop->set_coordinate_status(*position);
634     knot->desktop->setPosition(*position);
636     
637     if (state & GDK_MOD1_MASK) {
638         *position = _point + ( *position - _point ) / 10;
639     }
641     if (!(state & GDK_SHIFT_MASK) == !(_state == STATE_ROTATE)) {
642         _origin = _opposite;
643     } else {
644         _origin = _center;
645     }
646     if (handle.request(this, handle, *position, state)) {
647         sp_knot_set_position(knot, position, state);
648         SP_CTRL(_grip)->moveto(*position);
649         SP_CTRL(_norm)->moveto(_origin);
650     }
652     return TRUE;
656 void Inkscape::SelTrans::_selChanged(Inkscape::Selection *selection)
658     if (!_grabbed) {
659         _updateVolatileState();
660         _center = _box.midpoint();
661         _updateHandles();
662     }
665 void Inkscape::SelTrans::_selModified(Inkscape::Selection *selection, guint flags)
667     if (!_grabbed) {
668         _updateVolatileState();
670         if (
671              (flags != (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG)) &&
672              (flags != SP_OBJECT_PARENT_MODIFIED_FLAG) &&
673              (flags != SP_OBJECT_CHILD_MODIFIED_FLAG) &&
674              !_changed) {
675             // Only reset center if object itself is modified (not style, parent or child),
676             // and this is not a local change by seltrans
677             // (still annoyingly recenters on keyboard transforms, fixme)
678             _center = _box.midpoint();
679         }
681         // reset internal flag
682         _changed = false;
684         _updateHandles();
685     }
688 /*
689  * handlers for handle move-request
690  */
692 /** Returns -1 or 1 according to the sign of x.  Returns 1 for 0 and NaN. */
693 static double sign(double const x)
695     return ( x < 0
696              ? -1
697              : 1 );
700 gboolean sp_sel_trans_scale_request(Inkscape::SelTrans *seltrans,
701                                     SPSelTransHandle const &, NR::Point &pt, guint state)
703     return seltrans->scaleRequest(pt, state);
706 gboolean sp_sel_trans_stretch_request(Inkscape::SelTrans *seltrans,
707                                       SPSelTransHandle const &handle, NR::Point &pt, guint state)
709     return seltrans->stretchRequest(handle, pt, state);
712 gboolean sp_sel_trans_skew_request(Inkscape::SelTrans *seltrans,
713                                    SPSelTransHandle const &handle, NR::Point &pt, guint state)
715     return seltrans->skewRequest(handle, pt, state);
718 gboolean sp_sel_trans_rotate_request(Inkscape::SelTrans *seltrans,
719                                      SPSelTransHandle const &, NR::Point &pt, guint state)
721     return seltrans->rotateRequest(pt, state);
724 gboolean sp_sel_trans_center_request(Inkscape::SelTrans *seltrans,
725                                      SPSelTransHandle const &, NR::Point &pt, guint state)
727     return seltrans->centerRequest(pt, state);
730 gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
732     using NR::X;
733     using NR::Y;
735     NR::Point d = _point - _origin;
736     NR::scale s(0, 0);
738     /* Work out the new scale factors `s' */
739     for ( unsigned int i = 0 ; i < 2 ; i++ ) {
740         if ( fabs(d[i]) > 0.001 ) {
741             s[i] = ( pt[i] - _origin[i] ) / d[i];
742             if ( fabs(s[i]) < 1e-9 ) {
743                 s[i] = 1e-9;
744             }
745         }
746     }
748     /* Get a STL list of the selected items.
749     ** FIXME: this should probably be done by Inkscape::Selection.
750     */
751     std::list<SPItem const*> it;
752     for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
753         it.push_back(reinterpret_cast<SPItem*>(i->data));
754     }
756     if ((state & GDK_CONTROL_MASK) || _desktop->isToolboxButtonActive ("lock")) {
757         /* Scale is locked to a 1:1 aspect ratio, so that s[X] must be made to equal s[Y] */
759         NR::Dim2 locked_dim;
761         /* Lock aspect ratio, using the smaller of the x and y factors */
762         if (fabs(s[NR::X]) > fabs(s[NR::Y])) {
763             s[NR::X] = fabs(s[NR::Y]) * sign(s[NR::X]);
764             locked_dim = NR::X;
765         } else {
766             s[NR::Y] = fabs(s[NR::X]) * sign(s[NR::Y]);
767             locked_dim = NR::Y;
768         }
770         /* Snap the scale factor */
771         std::pair<double, bool> bb = namedview_vector_snap_list(_desktop->namedview,
772                                                                 Snapper::BBOX_POINT, _bbox_points,
773                                                                 _origin, s, it);
774         std::pair<double, bool> sn = namedview_vector_snap_list(_desktop->namedview,
775                                                                 Snapper::SNAP_POINT, _snap_points,
776                                                                 _origin, s, it);
778         double bd = bb.second ? fabs(bb.first - s[locked_dim]) : NR_HUGE;
779         double sd = sn.second ? fabs(sn.first - s[locked_dim]) : NR_HUGE;
780         double r = (bd < sd) ? bb.first : sn.first;
782         for ( unsigned int i = 0 ; i < 2 ; i++ ) {
783             s[i] = r * sign(s[i]);
784         }
786     } else {
787         /* Scale aspect ratio is unlocked */
788         for ( unsigned int i = 0 ; i < 2 ; i++ ) {
789             std::pair<double, bool> bb = namedview_dim_snap_list_scale(_desktop->namedview,
790                                                                        Snapper::BBOX_POINT, _bbox_points,
791                                                                        _origin, s[i], NR::Dim2(i), it);
792             std::pair<double, bool> sn = namedview_dim_snap_list_scale(_desktop->namedview,
793                                                                        Snapper::SNAP_POINT, _snap_points,
794                                                                        _origin, s[i], NR::Dim2(i), it);
796             /* Pick the snap that puts us closest to the original scale */
797             NR::Coord bd = bb.second ? fabs(bb.first - s[i]) : NR_HUGE;
798             NR::Coord sd = sn.second ? fabs(sn.first - s[i]) : NR_HUGE;
799             s[i] = (bd < sd) ? bb.first : sn.first;
800         }
801     }
803     /* Update the knot position */
804     pt = ( _point - _origin ) * s + _origin;
806     /* Status text */
807     _message_context.setF(Inkscape::NORMAL_MESSAGE,
808                           _("<b>Scale</b>: %0.2f%% x %0.2f%%; with <b>Ctrl</b> to lock ratio"),
809                           100 * s[NR::X], 100 * s[NR::Y]);
811     return TRUE;
814 gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state)
816     using NR::X;
817     using NR::Y;
819     NR::Dim2 axis, perp;
821     switch (handle.cursor) {
822         case GDK_TOP_SIDE:
823         case GDK_BOTTOM_SIDE:
824            axis = NR::Y;
825            perp = NR::X;
826            break;
827         case GDK_LEFT_SIDE:
828         case GDK_RIGHT_SIDE:
829            axis = NR::X;
830            perp = NR::Y;
831            break;
832         default:
833             g_assert_not_reached();
834             return TRUE;
835     };
837     if ( fabs( _point[axis] - _origin[axis] ) < 1e-15 ) {
838         return FALSE;
839     }
841     NR::scale s(1, 1);
842     s[axis] = ( ( pt[axis] - _origin[axis] )
843                 / ( _point[axis] - _origin[axis] ) );
844     if ( fabs(s[axis]) < 1e-15 ) {
845         s[axis] = 1e-15;
846     }
848     /* Get a STL list of the selected items.
849     ** FIXME: this should probably be done by Inkscape::Selection.
850     */
851     std::list<SPItem const*> it;
852     for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
853         it.push_back(reinterpret_cast<SPItem*>(i->data));
854     }
855     
856     if ( state & GDK_CONTROL_MASK ) {
857         s[perp] = fabs(s[axis]);
859         std::pair<double, bool> sn = namedview_vector_snap_list(_desktop->namedview,
860                                                                 Snapper::BBOX_POINT,
861                                                                 _bbox_points, _origin, s, it);
862         std::pair<double, bool> bb = namedview_vector_snap_list(_desktop->namedview,
863                                                                 Snapper::SNAP_POINT,
864                                                                 _snap_points, _origin, s, it);
866         double bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
867         double sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
868         double ratio = (bd < sd) ? bb.first : sn.first;
870         s[axis] = fabs(ratio) * sign(s[axis]);
871         s[perp] = fabs(s[axis]);
872     } else {
873         std::pair<NR::Coord, bool> bb = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::BBOX_POINT,
874                                                                       _bbox_points, _origin,
875                                                                       s[axis], axis, it);
876         std::pair<NR::Coord, bool> sn = namedview_dim_snap_list_scale(_desktop->namedview, Snapper::SNAP_POINT,
877                                                                       _snap_points, _origin,
878                                                                       s[axis], axis, it);
880         /* Pick the snap that puts us closest to the original scale */
881         NR::Coord bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE;
882         NR::Coord sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE;
883         s[axis] = (bd < sd) ? bb.first : sn.first;
884     }
886     pt = ( _point - _origin ) * NR::scale(s) + _origin;
887     if (isNaN(pt[X] + pt[Y])) {
888         g_warning("point=(%g, %g), norm=(%g, %g), s=(%g, %g)\n",
889                   _point[X], _point[Y], _origin[X], _origin[Y], s[X], s[Y]);
890     }
892     // status text
893     _message_context.setF(Inkscape::NORMAL_MESSAGE,
894                           _("<b>Scale</b>: %0.2f%% x %0.2f%%; with <b>Ctrl</b> to lock ratio"),
895                           100 * s[NR::X], 100 * s[NR::Y]);
897     return TRUE;
900 gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state)
902     using NR::X;
903     using NR::Y;
905     if (handle.cursor != GDK_SB_V_DOUBLE_ARROW && handle.cursor != GDK_SB_H_DOUBLE_ARROW) {
906         return FALSE;
907     }
909     NR::Dim2 dim_a;
910     NR::Dim2 dim_b;
911     if (handle.cursor == GDK_SB_V_DOUBLE_ARROW) {
912         dim_a = X;
913         dim_b = Y;
914     } else {
915         dim_a = Y;
916         dim_b = X;
917     }
919     double skew[2];
920     double s[2] = { 1.0, 1.0 };
922     if (fabs(_point[dim_a] - _origin[dim_a]) < NR_EPSILON) {
923         return FALSE;
924     }
926     skew[dim_a] = ( pt[dim_b] - _point[dim_b] ) / ( _point[dim_a] - _origin[dim_a] );
928     s[dim_a] = ( pt[dim_a] - _origin[dim_a] ) / ( _point[dim_a] - _origin[dim_a] );
930     if ( fabs(s[dim_a]) < 1 ) {
931         s[dim_a] = sign(s[dim_a]);
932     } else {
933         s[dim_a] = floor( s[dim_a] + 0.5 );
934     }
936     double radians = atan(skew[dim_a] / s[dim_a]);
938     if (state & GDK_CONTROL_MASK) {
940         int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
942         if (snaps) {
943             double sections = floor( radians * snaps / M_PI + .5 );
944             if (fabs(sections) >= snaps / 2) sections = sign(sections) * (snaps / 2 - 1);
945             radians = ( M_PI / snaps ) * sections;
946         }
947         skew[dim_a] = tan(radians) * s[dim_a];
948     } else {
949         skew[dim_a] = namedview_dim_snap_list_skew(_desktop->namedview,
950                 Snapper::SNAP_POINT, _snap_points,
951                 _origin, skew[dim_a], dim_b);
952     }
954     pt[dim_b] = ( _point[dim_a] - _origin[dim_a] ) * skew[dim_a] + _point[dim_b];
955     pt[dim_a] = ( _point[dim_a] - _origin[dim_a] ) * s[dim_a] + _origin[dim_a];
957     /* status text */
958     double degrees = 180 / M_PI * radians;
959     if (degrees > 180) degrees -= 360;
960     if (degrees < -180) degrees += 360;
962     _message_context.setF(Inkscape::NORMAL_MESSAGE,
963                           // TRANSLATORS: don't modify the first ";"
964                           // (it will NOT be displayed as ";" - only the second one will be)
965                           _("<b>Skew</b>: %0.2f&#176;; with <b>Ctrl</b> to snap angle"),
966                           degrees);
968     return TRUE;
971 gboolean Inkscape::SelTrans::rotateRequest(NR::Point &pt, guint state)
973     int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
975     // rotate affine in rotate
976     NR::Point const d1 = _point - _origin;
977     NR::Point const d2 = pt     - _origin;
979     NR::Coord const h1 = NR::L2(d1);
980     if (h1 < 1e-15) return FALSE;
981     NR::Point q1 = d1 / h1;
982     NR::Coord const h2 = NR::L2(d2);
983     if (fabs(h2) < 1e-15) return FALSE;
984     NR::Point q2 = d2 / h2;
986     double radians;
987     if (state & GDK_CONTROL_MASK) {
988         /* Have to restrict movement. */
989         double cos_t = NR::dot(q1, q2);
990         double sin_t = NR::dot(NR::rot90(q1), q2);
991         radians = atan2(sin_t, cos_t);
992         if (snaps) {
993             radians = ( M_PI / snaps ) * floor( radians * snaps / M_PI + .5 );
994         }
995         q1 = NR::Point(1, 0);
996         q2 = NR::Point(cos(radians), sin(radians));
997     } else {
998         radians = atan2(NR::dot(NR::rot90(d1), d2),
999                         NR::dot(d1, d2));
1000     }
1002     NR::rotate const r1(q1);
1003     NR::rotate const r2(q2);
1004     pt = _point * NR::translate(-_origin) * ( r2 / r1 ) * NR::translate(_origin);
1006     /* status text */
1007     double degrees = 180 / M_PI * radians;
1008     if (degrees > 180) degrees -= 360;
1009     if (degrees < -180) degrees += 360;
1011     _message_context.setF(Inkscape::NORMAL_MESSAGE,
1012                           // TRANSLATORS: don't modify the first ";"
1013                           // (it will NOT be displayed as ";" - only the second one will be)
1014                           _("<b>Rotate</b>: %0.2f&#176;; with <b>Ctrl</b> to snap angle"), degrees);
1016     return TRUE;
1019 gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
1021     using NR::X;
1022     using NR::Y;
1024     SnapManager const m(_desktop->namedview);
1025     pt = m.freeSnap(Snapper::SNAP_POINT, pt, NULL).getPoint();
1027     if (state & GDK_CONTROL_MASK) {
1028         if ( fabs(_point[X] - pt[X]) > fabs(_point[Y] - pt[Y]) ) {
1029             pt[Y] = _point[Y];
1030         } else {
1031             pt[X] = _point[X];
1032         }
1033     }
1035     Inkscape::Selection *selection = _desktop->selection;
1036     Inkscape::XML::Node *current = selection->singleRepr();
1037     if (current != NULL){
1038         sp_repr_set_svg_double(current, "inkscape:c_rx", pt[X]);
1039         sp_repr_set_svg_double(current, "inkscape:c_ry", pt[Y]);
1041     }
1043     if (!(state & GDK_SHIFT_MASK)) {
1044         // screen pixels to snap center to bbox
1045 #define SNAP_DIST 5
1046         // FIXME: take from prefs
1047         double snap_dist = SNAP_DIST / _desktop->current_zoom();
1049         for (int i = 0; i < 2; i++) {
1051             if (fabs(pt[i] - _box.min()[i]) < snap_dist) {
1052                 pt[i] = _box.min()[i];
1053             }
1054             if (fabs(pt[i] - _box.midpoint()[i]) < snap_dist) {
1055                 pt[i] = _box.midpoint()[i];
1056             }
1057             if (fabs(pt[i] - _box.max()[i]) < snap_dist) {
1058                 pt[i] = _box.max()[i];
1059             }
1060         }
1061     }
1063     // status text
1064     GString *xs = SP_PX_TO_METRIC_STRING(pt[X], _desktop->namedview->getDefaultMetric());
1065     GString *ys = SP_PX_TO_METRIC_STRING(pt[Y], _desktop->namedview->getDefaultMetric());
1066     _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move <b>center</b> to %s, %s"), xs->str, ys->str);
1067     g_string_free(xs, FALSE);
1068     g_string_free(ys, FALSE);
1070     return TRUE;
1073 /*
1074  * handlers for handle movement
1075  *
1076  */
1078 void sp_sel_trans_stretch(Inkscape::SelTrans *seltrans, SPSelTransHandle const &handle, NR::Point &pt, guint state)
1080     seltrans->stretch(handle, pt, state);
1083 void sp_sel_trans_scale(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint state)
1085     seltrans->scale(pt, state);
1088 void sp_sel_trans_skew(Inkscape::SelTrans *seltrans, SPSelTransHandle const &handle, NR::Point &pt, guint state)
1090     seltrans->skew(handle, pt, state);
1093 void sp_sel_trans_rotate(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint state)
1095     seltrans->rotate(pt, state);
1097     
1098 void Inkscape::SelTrans::stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state)
1100     using NR::X;
1101     using NR::Y;
1103     NR::Dim2 dim;
1104     switch (handle.cursor) {
1105         case GDK_LEFT_SIDE:
1106         case GDK_RIGHT_SIDE:
1107             dim = X;
1108             break;
1109         case GDK_TOP_SIDE:
1110         case GDK_BOTTOM_SIDE:
1111             dim = Y;
1112             break;
1113         default:
1114             g_assert_not_reached();
1115             abort();
1116             break;
1117     }
1119     NR::Point const scale_origin(_origin);
1120     double const offset = _point[dim] - scale_origin[dim];
1121     if (!( fabs(offset) >= 1e-15 )) {
1122         return;
1123     }
1124     NR::scale s(1, 1);
1125     s[dim] = ( pt[dim] - scale_origin[dim] ) / offset;
1126     if (isNaN(s[dim])) {
1127         g_warning("s[dim]=%g, pt[dim]=%g, scale_origin[dim]=%g, point[dim]=%g\n",
1128                   s[dim], pt[dim], scale_origin[dim], _point[dim]);
1129     }
1130     if (!( fabs(s[dim]) >= 1e-15 )) {
1131         s[dim] = 1e-15;
1132     }
1133     if (state & GDK_CONTROL_MASK) {
1134         /* Preserve aspect ratio, but never flip in the dimension not being edited. */
1135         s[!dim] = fabs(s[dim]);
1136     }
1138     NR::Rect new_bbox = _box * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
1140     int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
1141     NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke, 
1142                    new_bbox.min()[NR::X], new_bbox.min()[NR::Y], new_bbox.max()[NR::X], new_bbox.max()[NR::Y]);
1144     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
1147 void Inkscape::SelTrans::scale(NR::Point &pt, guint state)
1149     NR::Point const offset = _point - _origin;
1151     NR::scale s (1, 1);
1152     for (int i = NR::X; i <= NR::Y; i++) {
1153         if (fabs(offset[i]) > 1e-9)
1154             s[i] = (pt[i] - _origin[i]) / offset[i];
1155         if (fabs(s[i]) < 1e-9)
1156             s[i] = 1e-9;
1157     }
1158     NR::Rect new_bbox = _box * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
1160     int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
1161     NR::Matrix scaler = get_scale_transform_with_stroke (_box, _strokewidth, transform_stroke, 
1162                    new_bbox.min()[NR::X], new_bbox.min()[NR::Y], new_bbox.max()[NR::X], new_bbox.max()[NR::Y]);
1164     transform(scaler, NR::Point(0, 0)); // we have already accounted for origin, so pass 0,0
1167 void Inkscape::SelTrans::skew(SPSelTransHandle const &handle, NR::Point &pt, guint state)
1169     NR::Point const offset = _point - _origin;
1171     unsigned dim;
1172     switch (handle.cursor) {
1173         case GDK_SB_H_DOUBLE_ARROW:
1174             dim = NR::Y;
1175             break;
1176         case GDK_SB_V_DOUBLE_ARROW:
1177             dim = NR::X;
1178             break;
1179         default:
1180             g_assert_not_reached();
1181             abort();
1182             break;
1183     }
1184     if (fabs(offset[dim]) < 1e-15) {
1185         return;
1186     }
1187     NR::Matrix skew = NR::identity();
1188     skew[2*dim + dim] = (pt[dim] - _origin[dim]) / offset[dim];
1189     skew[2*dim + (1-dim)] = (pt[1-dim] - _point[1-dim]) / offset[dim];
1190     skew[2*(1-dim) + (dim)] = 0;
1191     skew[2*(1-dim) + (1-dim)] = 1;
1193     for (int i = 0; i < 2; i++) {
1194         if (fabs(skew[3*i]) < 1e-15) {
1195             skew[3*i] = 1e-15;
1196         }
1197     }
1198     transform(skew, _origin);
1201 void Inkscape::SelTrans::rotate(NR::Point &pt, guint state)
1203     NR::Point const offset = _point - _origin;
1205     NR::Coord const h1 = NR::L2(offset);
1206     if (h1 < 1e-15) {
1207         return;
1208     }
1209     NR::Point const q1 = offset / h1;
1210     NR::Coord const h2 = NR::L2( pt - _origin );
1211     if (h2 < 1e-15) {
1212         return;
1213     }
1214     NR::Point const q2 = (pt - _origin) / h2;
1215     NR::rotate const r1(q1);
1216     NR::rotate const r2(q2);
1218     NR::Matrix rotate( r2 / r1 );
1219     transform(rotate, _origin);
1222 void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &, NR::Point &pt, guint state)
1224     seltrans->setCenter(pt);
1228 void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
1230     SnapManager const m(_desktop->namedview);
1231     
1232     /* The amount that we've moved by during this drag */
1233     NR::Point dxy = xy - _point;
1235     /* Get a STL list of the selected items.
1236     ** FIXME: this should probably be done by Inkscape::Selection.
1237     */
1238     std::list<SPItem const*> it;
1239     for (GSList const *i = _selection->itemList(); i != NULL; i = i->next) {
1240         it.push_back(reinterpret_cast<SPItem*>(i->data));
1241     }
1243     bool const alt = (state & GDK_MOD1_MASK);
1244     bool const control = (state & GDK_CONTROL_MASK);
1245     bool const shift = (state & GDK_SHIFT_MASK);
1247     if (alt) {
1249         /* Alt pressed means keep offset: snap the moved distance to the grid.
1250         ** FIXME: this will snap to more than just the grid, nowadays.
1251         */
1253         dxy = m.freeSnap(Snapper::SNAP_POINT, dxy, NULL).getPoint();
1255     } else if (!shift) {
1257         /* We're snapping to things, possibly with a constraint to horizontal or
1258         ** vertical movement.  Obtain a list of possible translations and then
1259         ** pick the smallest.
1260         */
1262         /* This will be our list of possible translations */
1263         std::list<std::pair<NR::Point, bool> > s;
1264         
1265         if (control) {
1266             
1267             /* Snap to things, and also constrain to horizontal or vertical movement */
1269             for (unsigned int dim = 0; dim < 2; dim++) {
1270                 s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::BBOX_POINT,
1271                                                          _bbox_points,
1272                                                          component_vectors[dim], it, dxy));
1273                 s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAP_POINT,
1274                                                          _snap_points,
1275                                                          component_vectors[dim], it, dxy));
1276             }
1277             
1278         } else {
1280             /* Snap to things with no constraint */
1282             s.push_back(m.freeSnapTranslation(Inkscape::Snapper::BBOX_POINT,
1283                                               _bbox_points, it, dxy));
1284             s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAP_POINT,
1285                                               _snap_points, it, dxy));
1286         }
1288         /* Pick one */
1289         NR::Coord best = NR_HUGE;
1290         for (std::list<std::pair<NR::Point, bool> >::const_iterator i = s.begin(); i != s.end(); i++) {
1291             if (i->second) {
1292                 NR::Coord const m = NR::L2(i->first);
1293                 if (m < best) {
1294                     best = m;
1295                     dxy = i->first;
1296                 }
1297             }
1298         }
1299     }
1300     
1301     if (control) {
1302         /* Ensure that the horizontal and vertical constraint has been applied */
1303         if (fabs(dxy[NR::X]) > fabs(dxy[NR::Y])) {
1304             dxy[NR::Y] = 0;
1305         } else {
1306             dxy[NR::X] = 0;
1307         }
1308     }
1309     
1310     NR::Matrix const move((NR::translate(dxy)));
1311     NR::Point const norm(0, 0);
1312     transform(move, norm);
1314     // status text
1315     GString *xs = SP_PX_TO_METRIC_STRING(dxy[NR::X], _desktop->namedview->getDefaultMetric());
1316     GString *ys = SP_PX_TO_METRIC_STRING(dxy[NR::Y], _desktop->namedview->getDefaultMetric());
1317     _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);
1318     g_string_free(xs, TRUE);
1319     g_string_free(ys, TRUE);
1323 /*
1324   Local Variables:
1325   mode:c++
1326   c-file-style:"stroustrup"
1327   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1328   indent-tabs-mode:nil
1329   fill-column:99
1330   End:
1331 */
1332 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :