Code

3dbox cursor
[inkscape.git] / src / box3d-context.cpp
1 #define __SP_3DBOX_CONTEXT_C__
3 /*
4  * 3D box drawing context
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *   bulia byak <buliabyak@users.sf.net>
9  *
10  * Copyright (C) 2007      Maximilian Albert <Anhalter42@gmx.de>
11  * Copyright (C) 2006      Johan Engelen <johan@shouraizou.nl>
12  * Copyright (C) 2000-2005 authors
13  * Copyright (C) 2000-2001 Ximian, Inc.
14  *
15  * Released under GNU GPL, read the file 'COPYING' for more information
16  */
18 #include "config.h"
20 #include <gdk/gdkkeysyms.h>
22 #include "macros.h"
23 #include "display/sp-canvas.h"
24 #include "document.h"
25 #include "sp-namedview.h"
26 #include "selection.h"
27 #include "desktop-handles.h"
28 #include "snap.h"
29 #include "display/curve.h"
30 #include "desktop.h"
31 #include "message-context.h"
32 #include "pixmaps/cursor-3dbox.xpm"
33 #include "box3d.h"
34 #include "box3d-context.h"
35 #include "sp-metrics.h"
36 #include <glibmm/i18n.h>
37 #include "object-edit.h"
38 #include "xml/repr.h"
39 #include "xml/node-event-vector.h"
40 #include "prefs-utils.h"
41 #include "context-fns.h"
43 static void sp_3dbox_context_class_init(SP3DBoxContextClass *klass);
44 static void sp_3dbox_context_init(SP3DBoxContext *box3d_context);
45 static void sp_3dbox_context_dispose(GObject *object);
47 static void sp_3dbox_context_setup(SPEventContext *ec);
48 static void sp_3dbox_context_set(SPEventContext *ec, gchar const *key, gchar const *val);
50 static gint sp_3dbox_context_root_handler(SPEventContext *event_context, GdkEvent *event);
51 static gint sp_3dbox_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
53 static void sp_3dbox_drag(SP3DBoxContext &bc, guint state);
54 static void sp_3dbox_finish(SP3DBoxContext *bc);
56 static SPEventContextClass *parent_class;
59 GtkType sp_3dbox_context_get_type()
60 {
61     static GType type = 0;
62     if (!type) {
63         GTypeInfo info = {
64             sizeof(SP3DBoxContextClass),
65             NULL, NULL,
66             (GClassInitFunc) sp_3dbox_context_class_init,
67             NULL, NULL,
68             sizeof(SP3DBoxContext),
69             4,
70             (GInstanceInitFunc) sp_3dbox_context_init,
71             NULL,    /* value_table */
72         };
73         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SP3DBoxContext", &info, (GTypeFlags) 0);
74     }
75     return type;
76 }
78 static void sp_3dbox_context_class_init(SP3DBoxContextClass *klass)
79 {
80     GObjectClass *object_class = (GObjectClass *) klass;
81     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
83     parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass);
85     object_class->dispose = sp_3dbox_context_dispose;
87     event_context_class->setup = sp_3dbox_context_setup;
88     event_context_class->set = sp_3dbox_context_set;
89     event_context_class->root_handler  = sp_3dbox_context_root_handler;
90     event_context_class->item_handler  = sp_3dbox_context_item_handler;
91 }
93 static void sp_3dbox_context_init(SP3DBoxContext *box3d_context)
94 {
95     SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context);
97     event_context->cursor_shape = cursor_3dbox_xpm;
98     event_context->hot_x = 4;
99     event_context->hot_y = 4;
100     event_context->xp = 0;
101     event_context->yp = 0;
102     event_context->tolerance = 0;
103     event_context->within_tolerance = false;
104     event_context->item_to_select = NULL;
106     event_context->shape_repr = NULL;
107     event_context->shape_knot_holder = NULL;
109     box3d_context->item = NULL;
111     box3d_context->ctrl_dragged = false;
112     box3d_context->extruded = false;
113     
114     box3d_context->_vpdrag = NULL;
116     new (&box3d_context->sel_changed_connection) sigc::connection();
119 static void sp_3dbox_context_dispose(GObject *object)
121     SP3DBoxContext *bc = SP_3DBOX_CONTEXT(object);
122     SPEventContext *ec = SP_EVENT_CONTEXT(object);
124     ec->enableGrDrag(false);
126     delete (bc->_vpdrag);
127     bc->_vpdrag = NULL;
129     bc->sel_changed_connection.disconnect();
130     bc->sel_changed_connection.~connection();
132     /* fixme: This is necessary because we do not grab */
133     if (bc->item) {
134         sp_3dbox_finish(bc);
135     }
137     if (ec->shape_knot_holder) {
138         sp_knot_holder_destroy(ec->shape_knot_holder);
139         ec->shape_knot_holder = NULL;
140     }
142     if (ec->shape_repr) { // remove old listener
143         sp_repr_remove_listener_by_data(ec->shape_repr, ec);
144         Inkscape::GC::release(ec->shape_repr);
145         ec->shape_repr = 0;
146     }
148     if (bc->_message_context) {
149         delete bc->_message_context;
150     }
152     G_OBJECT_CLASS(parent_class)->dispose(object);
155 static Inkscape::XML::NodeEventVector ec_shape_repr_events = {
156     NULL, /* child_added */
157     NULL, /* child_removed */
158     ec_shape_event_attr_changed,
159     NULL, /* content_changed */
160     NULL  /* order_changed */
161 };
163 /**
164 \brief  Callback that processes the "changed" signal on the selection;
165 destroys old and creates new knotholder
166 */
167 void sp_3dbox_context_selection_changed(Inkscape::Selection *selection, gpointer data)
169     SP3DBoxContext *bc = SP_3DBOX_CONTEXT(data);
170     SPEventContext *ec = SP_EVENT_CONTEXT(bc);
172     if (ec->shape_knot_holder) { // destroy knotholder
173         sp_knot_holder_destroy(ec->shape_knot_holder);
174         ec->shape_knot_holder = NULL;
175     }
177     if (ec->shape_repr) { // remove old listener
178         sp_repr_remove_listener_by_data(ec->shape_repr, ec);
179         Inkscape::GC::release(ec->shape_repr);
180         ec->shape_repr = 0;
181     }
183     SPItem *item = selection->singleItem();
184     if (item) {
185         ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
186         Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
187         if (shape_repr) {
188             ec->shape_repr = shape_repr;
189             Inkscape::GC::anchor(shape_repr);
190             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
191         }
192         if (SP_IS_3DBOX (item)) {
193             bc->_vpdrag->document->current_perspective = bc->_vpdrag->document->get_persp_of_box (SP_3DBOX (item));
194         }
195     } else {
196         /* If several boxes sharing the same perspective are selected,
197            we can still set the current selection accordingly */
198         std::set<Box3D::Perspective3D *> perspectives;
199         for (GSList *i = (GSList *) selection->itemList(); i != NULL; i = i->next) {
200             if (SP_IS_3DBOX (i->data)) {
201                 perspectives.insert (bc->_vpdrag->document->get_persp_of_box (SP_3DBOX (i->data)));
202             }
203         }
204         if (perspectives.size() == 1) {
205             bc->_vpdrag->document->current_perspective = *(perspectives.begin());
206         }
207         // TODO: What to do if several boxes with different perspectives are selected?
208     }
211 static void sp_3dbox_context_setup(SPEventContext *ec)
213     SP3DBoxContext *bc = SP_3DBOX_CONTEXT(ec);
215     if (((SPEventContextClass *) parent_class)->setup) {
216         ((SPEventContextClass *) parent_class)->setup(ec);
217     }
219     SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
220     if (item) {
221         ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
222         Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
223         if (shape_repr) {
224             ec->shape_repr = shape_repr;
225             Inkscape::GC::anchor(shape_repr);
226             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
227         }
228     }
230     bc->sel_changed_connection.disconnect();
231     bc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
232         sigc::bind(sigc::ptr_fun(&sp_3dbox_context_selection_changed), (gpointer)bc)
233     );
235     bc->_vpdrag = new Box3D::VPDrag(sp_desktop_document (ec->desktop));
237     if (prefs_get_int_attribute("tools.shapes", "selcue", 0) != 0) {
238         ec->enableSelectionCue();
239     }
241     if (prefs_get_int_attribute("tools.shapes", "gradientdrag", 0) != 0) {
242         ec->enableGrDrag();
243     }
245     bc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
248 static void sp_3dbox_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
250     //SP3DBoxContext *bc = SP_3DBOX_CONTEXT(ec);
252     /* fixme: Proper error handling for non-numeric data.  Use a locale-independent function like
253      * g_ascii_strtod (or a thin wrapper that does the right thing for invalid values inf/nan). */
254     /**
255     if ( strcmp(key, "rx") == 0 ) {
256         bc->rx = ( val
257                          ? g_ascii_strtod (val, NULL)
258                          : 0.0 );
259     } else if ( strcmp(key, "ry") == 0 ) {
260         bc->ry = ( val
261                          ? g_ascii_strtod (val, NULL)
262                          : 0.0 );
263     }
264     **/
267 static gint sp_3dbox_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
269     SPDesktop *desktop = event_context->desktop;
271     gint ret = FALSE;
273     switch (event->type) {
274     case GDK_BUTTON_PRESS:
275         if ( event->button.button == 1 && !event_context->space_panning) {
276             Inkscape::setup_for_drag_start(desktop, event_context, event);
277             ret = TRUE;
278         }
279         break;
280         // motion and release are always on root (why?)
281     default:
282         break;
283     }
285     if (((SPEventContextClass *) parent_class)->item_handler) {
286         ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
287     }
289     return ret;
292 static gint sp_3dbox_context_root_handler(SPEventContext *event_context, GdkEvent *event)
294     static bool dragging;
296     SPDesktop *desktop = event_context->desktop;
297     Inkscape::Selection *selection = sp_desktop_selection (desktop);
298     int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
300     SP3DBoxContext *bc = SP_3DBOX_CONTEXT(event_context);
302     event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100);
304     gint ret = FALSE;
305     switch (event->type) {
306     case GDK_BUTTON_PRESS:
307         if ( event->button.button == 1  && !event_context->space_panning) {
308             NR::Point const button_w(event->button.x,
309                                      event->button.y);
311             // save drag origin
312             event_context->xp = (gint) button_w[NR::X];
313             event_context->yp = (gint) button_w[NR::Y];
314             event_context->within_tolerance = true;
315             
316             // remember clicked item, disregarding groups, honoring Alt
317             event_context->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, event->button.state & GDK_CONTROL_MASK);
319             dragging = true;
320             
321             /* Position center */
322             NR::Point const button_dt(desktop->w2d(button_w));
323             bc->drag_origin = button_dt;
324             bc->drag_ptB = button_dt;
325             bc->drag_ptC = button_dt;
327             /* Snap center */
328             SnapManager const &m = desktop->namedview->snap_manager;
329             bc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE,
330                                     button_dt, bc->item).getPoint();
332             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
333                                 ( GDK_KEY_PRESS_MASK |
334                                   GDK_BUTTON_RELEASE_MASK       |
335                                   GDK_POINTER_MOTION_MASK       |
336                                   GDK_BUTTON_PRESS_MASK ),
337                                 NULL, event->button.time);
338             ret = TRUE;
339         }
340         break;
341     case GDK_MOTION_NOTIFY:
342         if ( dragging
343              && ( event->motion.state & GDK_BUTTON1_MASK )  && !event_context->space_panning)
344         {
345             if ( event_context->within_tolerance
346                  && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
347                  && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
348                 break; // do not drag if we're within tolerance from origin
349             }
350             // Once the user has moved farther than tolerance from the original location
351             // (indicating they intend to draw, not click), then always process the
352             // motion notify coordinates as given (no snapping back to origin)
353             event_context->within_tolerance = false;
355             NR::Point const motion_w(event->motion.x,
356                                      event->motion.y);
357             NR::Point motion_dt(desktop->w2d(motion_w));
359             SnapManager const &m = desktop->namedview->snap_manager;
360             motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, bc->item).getPoint();
362             bc->ctrl_dragged  = event->motion.state & GDK_CONTROL_MASK;
364             if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) {
365                 /* once shift is pressed, set bc->extruded (no need to create further faces;
366                    all of them are already created in sp_3dbox_init); since we made the rear face
367                    invisible in the beginning to avoid "flashing", we must set its correct style now */
368                 bc->extruded = true;
369                 SP_3DBOX (bc->item)->faces[5]->set_style (NULL, true);
370             }
372             if (!bc->extruded) {
373                 bc->drag_ptB = motion_dt;
374                 bc->drag_ptC = motion_dt;
375             } else {
376                 // Without Ctrl, motion of the extruded corner is constrained to the
377                 // perspective line from drag_ptB to vanishing point Y.
378                 if (!bc->ctrl_dragged) {
379                         bc->drag_ptC = Box3D::perspective_line_snap (bc->drag_ptB, Box3D::Z, motion_dt, bc->_vpdrag->document->current_perspective);
380                 } else {
381                     bc->drag_ptC = motion_dt;
382                 }
383                 bc->drag_ptC = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, bc->drag_ptC, bc->item).getPoint();
384                 if (bc->ctrl_dragged) {
385                         Box3D::PerspectiveLine pl1 (NR::Point (event_context->xp, event_context->yp), Box3D::Y, bc->_vpdrag->document->current_perspective);
386                         Box3D::PerspectiveLine pl2 (bc->drag_ptB, Box3D::X, bc->_vpdrag->document->current_perspective);
387                         NR::Point corner1 = pl1.meet(pl2);
388                         
389                         Box3D::PerspectiveLine pl3 (corner1, Box3D::X, bc->_vpdrag->document->current_perspective);
390                         Box3D::PerspectiveLine pl4 (bc->drag_ptC, Box3D::Z, bc->_vpdrag->document->current_perspective);
391                         bc->drag_ptB = pl3.meet(pl4);
392                 }
393             }
394             
395             
396             sp_3dbox_drag(*bc, event->motion.state);
397             
398             ret = TRUE;
399         }
400         break;
401     case GDK_BUTTON_RELEASE:
402         event_context->xp = event_context->yp = 0;
403         if ( event->button.button == 1  && !event_context->space_panning) {
404             dragging = false;
406             if (!event_context->within_tolerance) {
407                 // we've been dragging, finish the box
408                 sp_3dbox_finish(bc);
409             } else if (event_context->item_to_select) {
410                 // no dragging, select clicked item if any
411                 if (event->button.state & GDK_SHIFT_MASK) {
412                     selection->toggle(event_context->item_to_select);
413                 } else {
414                     selection->set(event_context->item_to_select);
415                 }
416             } else {
417                 // click in an empty space
418                 selection->clear();
419             }
421             event_context->item_to_select = NULL;
422             ret = TRUE;
423             sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
424                                   event->button.time);
425         }
426         break;
427     case GDK_KEY_PRESS:
428         switch (get_group0_keyval (&event->key)) {
429         case GDK_Alt_L:
430         case GDK_Alt_R:
431         case GDK_Control_L:
432         case GDK_Control_R:
433         case GDK_Shift_L:
434         case GDK_Shift_R:
435         case GDK_Meta_L:  // Meta is when you press Shift+Alt (at least on my machine)
436         case GDK_Meta_R:
437             /***
438             if (!dragging){
439                 sp_event_show_modifier_tip (event_context->defaultMessageContext(), event,
440                                             _("<b>Ctrl</b>: make square or integer-ratio rect, lock a rounded corner circular"),
441                                             _("<b>Shift</b>: draw around the starting point"),
442                                             NULL);
443             }
444             ***/
445             break;
446         case GDK_Up:
447         case GDK_Down:
448         case GDK_KP_Up:
449         case GDK_KP_Down:
450             // prevent the zoom field from activation
451             if (!MOD__CTRL_ONLY)
452                 ret = TRUE;
453             break;
455         case GDK_bracketright:
456             inkscape_active_document()->current_perspective->rotate (Box3D::X, -180/snaps, MOD__ALT);
457             ret = true;
458             break;
460         case GDK_bracketleft:
461             inkscape_active_document()->current_perspective->rotate (Box3D::X, 180/snaps, MOD__ALT);
462             ret = true;
463             break;
465         case GDK_parenright:
466             inkscape_active_document()->current_perspective->rotate (Box3D::Y, -180/snaps, MOD__ALT);
467             ret = true;
468             break;
470         case GDK_parenleft:
471             inkscape_active_document()->current_perspective->rotate (Box3D::Y, 180/snaps, MOD__ALT);
472             ret = true;
473             break;
475         case GDK_braceright:
476             inkscape_active_document()->current_perspective->rotate (Box3D::Z, -180/snaps, MOD__ALT);
477             ret = true;
478             break;
480         case GDK_braceleft:
481             inkscape_active_document()->current_perspective->rotate (Box3D::Z, 180/snaps, MOD__ALT);
482             ret = true;
483             break;
485         case GDK_I:
486             Box3D::Perspective3D::print_debugging_info();
487             ret = true;
488             break;
490         case GDK_L:
491             if (MOD__CTRL) break; // Don't catch Shift+Ctrl+L (Layers dialog)
492             bc->_vpdrag->show_lines = !bc->_vpdrag->show_lines;
493             bc->_vpdrag->updateLines();
494             ret = true;
495             break;
497         case GDK_A:
498             if (MOD__CTRL) break; // Don't catch Ctrl+A ("select all")
499             if (bc->_vpdrag->show_lines) {
500                 bc->_vpdrag->front_or_rear_lines = bc->_vpdrag->front_or_rear_lines ^ 0x2; // toggle rear PLs
501             }
502             bc->_vpdrag->updateLines();
503             ret = true;
504             break;
506         case GDK_X:
507         {
508             if (MOD__CTRL) break; // Don't catch Ctrl+X ('cut') and Ctrl+Shift+X ('open XML editor')
509             Inkscape::Selection *selection = sp_desktop_selection (inkscape_active_desktop());
510             for (GSList const *i = selection->itemList(); i != NULL; i = i->next) {
511                 if (!SP_IS_3DBOX (i->data)) continue;
512                 sp_3dbox_switch_front_face (SP_3DBOX (i->data), Box3D::X);
513              }
514             bc->_vpdrag->updateLines();
515             ret = true;
516             break;
517         }
518  
519         case GDK_Y:
520         {
521             if (MOD__CTRL) break; // Don't catch Ctrl+Y ("redo")
522             Inkscape::Selection *selection = sp_desktop_selection (inkscape_active_desktop());
523             for (GSList const *i = selection->itemList(); i != NULL; i = i->next) {
524                 if (!SP_IS_3DBOX (i->data)) continue;
525                 sp_3dbox_switch_front_face (SP_3DBOX (i->data), Box3D::Y);
526             }
527             bc->_vpdrag->updateLines();
528             ret = true;
529             break;
530         }
532         case GDK_Z:
533         {
534             if (MOD__CTRL) break; // Don't catch Ctrl+Z ("undo")
535             Inkscape::Selection *selection = sp_desktop_selection (inkscape_active_desktop());
536             for (GSList const *i = selection->itemList(); i != NULL; i = i->next) {
537                 if (!SP_IS_3DBOX (i->data)) continue;
538                 sp_3dbox_switch_front_face (SP_3DBOX (i->data), Box3D::Z);
539             }
540             bc->_vpdrag->updateLines();
541             ret = true;
542             break;
543         }
545         case GDK_Escape:
546             sp_desktop_selection(desktop)->clear();
547             //TODO: make dragging escapable by Esc
548             break;
550         case GDK_space:
551             if (dragging) {
552                 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
553                                       event->button.time);
554                 dragging = false;
555                 if (!event_context->within_tolerance) {
556                     // we've been dragging, finish the box
557                     sp_3dbox_finish(bc);
558                 }
559                 // do not return true, so that space would work switching to selector
560             }
561             break;
563         default:
564             break;
565         }
566         break;
567     case GDK_KEY_RELEASE:
568         switch (get_group0_keyval (&event->key)) {
569         case GDK_Alt_L:
570         case GDK_Alt_R:
571         case GDK_Control_L:
572         case GDK_Control_R:
573         case GDK_Shift_L:
574         case GDK_Shift_R:
575         case GDK_Meta_L:  // Meta is when you press Shift+Alt
576         case GDK_Meta_R:
577             event_context->defaultMessageContext()->clear();
578             break;
579         default:
580             break;
581         }
582         break;
583     default:
584         break;
585     }
587     if (!ret) {
588         if (((SPEventContextClass *) parent_class)->root_handler) {
589             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
590         }
591     }
593     return ret;
596 static void sp_3dbox_drag(SP3DBoxContext &bc, guint state)
598     SPDesktop *desktop = SP_EVENT_CONTEXT(&bc)->desktop;
600     if (!bc.item) {
602         if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) {
603             return;
604         }
606         /* Create object */
607         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(&bc));
608         Inkscape::XML::Node *repr = xml_doc->createElement("svg:g");
609         repr->setAttribute("sodipodi:type", "inkscape:3dbox");
611         /* Set style */
612         sp_desktop_apply_style_tool (desktop, repr, "tools.shapes.3dbox", false);
614         bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr);
615         Inkscape::GC::release(repr);
616         bc.item->transform = SP_ITEM(desktop->currentRoot())->getRelativeTransform(desktop->currentLayer());
618         /* Hook paths to the faces of the box (applies last used style if necessary) */
619         for (int i = 0; i < 6; ++i) {
620             SP_3DBOX(bc.item)->faces[i]->hook_path_to_3dbox();
621         }
622         // make rear face invisible in the beginning to avoid "flashing"
623         SP_3DBOX (bc.item)->faces[5]->set_style (NULL, false);
625         bc.item->updateRepr();
626         sp_3dbox_set_z_orders_in_the_first_place (SP_3DBOX (bc.item));
628         // TODO: It would be nice to show the VPs during dragging, but since there is no selection
629         //       at this point (only after finishing the box), we must do this "manually"
630         bc._vpdrag->updateDraggers();
632         sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
633     }
635     // FIXME: remove these extra points
636     NR::Point pt = bc.drag_ptB;
637     NR::Point shift_pt = bc.drag_ptC;
639     NR::Rect r;
640     if (!(state & GDK_SHIFT_MASK)) {
641         r = Inkscape::snap_rectangular_box(desktop, bc.item, pt, bc.center, state);
642     } else {
643         r = Inkscape::snap_rectangular_box(desktop, bc.item, shift_pt, bc.center, state);
644     }
646     SPEventContext *ec = SP_EVENT_CONTEXT(&bc);
647     NR::Point origin_w(ec->xp, ec->yp);
648     NR::Point origin(desktop->w2d(origin_w));
649     sp_3dbox_position_set(bc);
650     sp_3dbox_set_z_orders_in_the_first_place (SP_3DBOX (bc.item));
652     // status text
653     //GString *Ax = SP_PX_TO_METRIC_STRING(origin[NR::X], desktop->namedview->getDefaultMetric());
654     //GString *Ay = SP_PX_TO_METRIC_STRING(origin[NR::Y], desktop->namedview->getDefaultMetric());
655     bc._message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis"));
656     //g_string_free(Ax, FALSE);
657     //g_string_free(Ay, FALSE);
660 static void sp_3dbox_finish(SP3DBoxContext *bc)
662     bc->_message_context->clear();
664     if ( bc->item != NULL ) {
665         SPDesktop * desktop;
667         desktop = SP_EVENT_CONTEXT_DESKTOP(bc);
669         SP_OBJECT(bc->item)->updateRepr();
670         sp_3dbox_set_ratios(SP_3DBOX(bc->item));
672         sp_canvas_end_forced_full_redraws(desktop->canvas);
674         sp_desktop_selection(desktop)->set(bc->item);
675         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
676                          _("Create 3D box"));
678         bc->item = NULL;
679     }
681     bc->ctrl_dragged = false;
682     bc->extruded = false;
685 /*
686   Local Variables:
687   mode:c++
688   c-file-style:"stroustrup"
689   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
690   indent-tabs-mode:nil
691   fill-column:99
692   End:
693 */
694 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :