Code

0ea8b1dbdaed1679968874177f0147ca188c3c7e
[inkscape.git] / src / box3d-context.cpp
1 #define __SP_BOX3D_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 "selection-chemistry.h"
28 #include "desktop-handles.h"
29 #include "snap.h"
30 #include "display/curve.h"
31 #include "desktop.h"
32 #include "message-context.h"
33 #include "pixmaps/cursor-3dbox.xpm"
34 #include "box3d.h"
35 #include "box3d-context.h"
36 #include "sp-metrics.h"
37 #include <glibmm/i18n.h>
38 #include "object-edit.h"
39 #include "xml/repr.h"
40 #include "xml/node-event-vector.h"
41 #include "prefs-utils.h"
42 #include "context-fns.h"
43 #include "desktop-style.h"
44 #include "transf_mat_3x4.h"
45 #include "perspective-line.h"
46 #include "persp3d.h"
47 #include "box3d-side.h"
48 #include "document-private.h"
49 #include "line-geometry.h"
51 static void sp_box3d_context_class_init(Box3DContextClass *klass);
52 static void sp_box3d_context_init(Box3DContext *box3d_context);
53 static void sp_box3d_context_dispose(GObject *object);
55 static void sp_box3d_context_setup(SPEventContext *ec);
57 static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event);
58 static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
60 static void sp_box3d_drag(Box3DContext &bc, guint state);
61 static void sp_box3d_finish(Box3DContext *bc);
63 static SPEventContextClass *parent_class;
65 GtkType sp_box3d_context_get_type()
66 {
67     static GType type = 0;
68     if (!type) {
69         GTypeInfo info = {
70             sizeof(Box3DContextClass),
71             NULL, NULL,
72             (GClassInitFunc) sp_box3d_context_class_init,
73             NULL, NULL,
74             sizeof(Box3DContext),
75             4,
76             (GInstanceInitFunc) sp_box3d_context_init,
77             NULL,    /* value_table */
78         };
79         type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "Box3DContext", &info, (GTypeFlags) 0);
80     }
81     return type;
82 }
84 static void sp_box3d_context_class_init(Box3DContextClass *klass)
85 {
86     GObjectClass *object_class = (GObjectClass *) klass;
87     SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
89     parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass);
91     object_class->dispose = sp_box3d_context_dispose;
93     event_context_class->setup = sp_box3d_context_setup;
94     event_context_class->root_handler  = sp_box3d_context_root_handler;
95     event_context_class->item_handler  = sp_box3d_context_item_handler;
96 }
98 static void sp_box3d_context_init(Box3DContext *box3d_context)
99 {
100     SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context);
102     event_context->cursor_shape = cursor_3dbox_xpm;
103     event_context->hot_x = 4;
104     event_context->hot_y = 4;
105     event_context->xp = 0;
106     event_context->yp = 0;
107     event_context->tolerance = 0;
108     event_context->within_tolerance = false;
109     event_context->item_to_select = NULL;
111     event_context->shape_repr = NULL;
112     event_context->shape_knot_holder = NULL;
114     box3d_context->item = NULL;
116     box3d_context->ctrl_dragged = false;
117     box3d_context->extruded = false;
118     
119     box3d_context->_vpdrag = NULL;
121     new (&box3d_context->sel_changed_connection) sigc::connection();
124 static void sp_box3d_context_dispose(GObject *object)
126     Box3DContext *bc = SP_BOX3D_CONTEXT(object);
127     SPEventContext *ec = SP_EVENT_CONTEXT(object);
129     ec->enableGrDrag(false);
131     delete (bc->_vpdrag);
132     bc->_vpdrag = NULL;
134     bc->sel_changed_connection.disconnect();
135     bc->sel_changed_connection.~connection();
137     /* fixme: This is necessary because we do not grab */
138     if (bc->item) {
139         sp_box3d_finish(bc);
140     }
142     if (ec->shape_knot_holder) {
143         delete ec->shape_knot_holder;
144         ec->shape_knot_holder = NULL;
145     }
147     if (ec->shape_repr) { // remove old listener
148         sp_repr_remove_listener_by_data(ec->shape_repr, ec);
149         Inkscape::GC::release(ec->shape_repr);
150         ec->shape_repr = 0;
151     }
153     if (bc->_message_context) {
154         delete bc->_message_context;
155     }
157     G_OBJECT_CLASS(parent_class)->dispose(object);
160 static Inkscape::XML::NodeEventVector ec_shape_repr_events = {
161     NULL, /* child_added */
162     NULL, /* child_removed */
163     ec_shape_event_attr_changed,
164     NULL, /* content_changed */
165     NULL  /* order_changed */
166 };
168 /**
169 \brief  Callback that processes the "changed" signal on the selection;
170 destroys old and creates new knotholder
171 */
172 static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, gpointer data)
174     Box3DContext *bc = SP_BOX3D_CONTEXT(data);
175     SPEventContext *ec = SP_EVENT_CONTEXT(bc);
177     if (ec->shape_knot_holder) { // destroy knotholder
178         delete ec->shape_knot_holder;
179         ec->shape_knot_holder = NULL;
180     }
182     if (ec->shape_repr) { // remove old listener
183         sp_repr_remove_listener_by_data(ec->shape_repr, ec);
184         Inkscape::GC::release(ec->shape_repr);
185         ec->shape_repr = 0;
186     }
188     SPItem *item = selection->singleItem();
189     if (item) {
190         ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
191         Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
192         if (shape_repr) {
193             ec->shape_repr = shape_repr;
194             Inkscape::GC::anchor(shape_repr);
195             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
196         }
197     }
199     if (selection->perspList().size() == 1) {
200         // selecting a single box changes the current perspective
201         ec->desktop->doc()->current_persp3d = selection->perspList().front();
202     }
205 /* create a default perspective in document defs if none is present
206    (can happen after 'vacuum defs' or when a pre-0.46 file is opened) */   
207 static void sp_box3d_context_check_for_persp_in_defs(SPDocument *document) {
208     SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
210     bool has_persp = false;
211     for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child) ) {
212         if (SP_IS_PERSP3D(child)) {
213             has_persp = true;
214             break;
215         }
216     }
218     if (!has_persp) {
219         document->current_persp3d = persp3d_create_xml_element (document);
220     }
223 static void sp_box3d_context_setup(SPEventContext *ec)
225     Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
227     if (((SPEventContextClass *) parent_class)->setup) {
228         ((SPEventContextClass *) parent_class)->setup(ec);
229     }
231     sp_box3d_context_check_for_persp_in_defs(sp_desktop_document (ec->desktop));
233     SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
234     if (item) {
235         ec->shape_knot_holder = sp_item_knot_holder(item, ec->desktop);
236         Inkscape::XML::Node *shape_repr = SP_OBJECT_REPR(item);
237         if (shape_repr) {
238             ec->shape_repr = shape_repr;
239             Inkscape::GC::anchor(shape_repr);
240             sp_repr_add_listener(shape_repr, &ec_shape_repr_events, ec);
241         }
242     }
244     bc->sel_changed_connection.disconnect();
245     bc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
246         sigc::bind(sigc::ptr_fun(&sp_box3d_context_selection_changed), (gpointer)bc)
247     );
249     bc->_vpdrag = new Box3D::VPDrag(sp_desktop_document (ec->desktop));
251     if (prefs_get_int_attribute("tools.shapes", "selcue", 0) != 0) {
252         ec->enableSelectionCue();
253     }
255     if (prefs_get_int_attribute("tools.shapes", "gradientdrag", 0) != 0) {
256         ec->enableGrDrag();
257     }
259     bc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
262 static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
264     SPDesktop *desktop = event_context->desktop;
266     gint ret = FALSE;
268     switch (event->type) {
269     case GDK_BUTTON_PRESS:
270         if ( event->button.button == 1 && !event_context->space_panning) {
271             Inkscape::setup_for_drag_start(desktop, event_context, event);
272             ret = TRUE;
273         }
274         break;
275         // motion and release are always on root (why?)
276     default:
277         break;
278     }
280     if (((SPEventContextClass *) parent_class)->item_handler) {
281         ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
282     }
284     return ret;
287 static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event)
289     static bool dragging;
291     SPDesktop *desktop = event_context->desktop;
292     Inkscape::Selection *selection = sp_desktop_selection (desktop);
293     int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
295     Box3DContext *bc = SP_BOX3D_CONTEXT(event_context);
296     g_assert (SP_ACTIVE_DOCUMENT->current_persp3d);
297     Persp3D *cur_persp = SP_ACTIVE_DOCUMENT->current_persp3d;
299     event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100);
301     gint ret = FALSE;
302     switch (event->type) {
303     case GDK_BUTTON_PRESS:
304         if ( event->button.button == 1  && !event_context->space_panning) {
305             NR::Point const button_w(event->button.x,
306                                      event->button.y);
308             // save drag origin
309             event_context->xp = (gint) button_w[NR::X];
310             event_context->yp = (gint) button_w[NR::Y];
311             event_context->within_tolerance = true;
312             
313             // remember clicked item, *not* disregarding groups (since a 3D box is a group), honoring Alt
314             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);
316             dragging = true;
317             
318             /*  */
319             Geom::Point button_dt(desktop->w2d(button_w));
320             bc->drag_origin = from_2geom(button_dt);
321             bc->drag_ptB = from_2geom(button_dt);
322             bc->drag_ptC = from_2geom(button_dt);
324             /* Projective preimages of clicked point under current perspective */
325             bc->drag_origin_proj = cur_persp->tmat.preimage (from_2geom(button_dt), 0, Proj::Z);
326             bc->drag_ptB_proj = bc->drag_origin_proj;
327             bc->drag_ptC_proj = bc->drag_origin_proj;
328             bc->drag_ptC_proj.normalize();
329             bc->drag_ptC_proj[Proj::Z] = 0.25;
331             /* Snap center */
332             SnapManager &m = desktop->namedview->snap_manager;
333             m.setup(desktop, true, bc->item);
334             m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, button_dt);
335             bc->center = from_2geom(button_dt);
337             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
338                                 ( GDK_KEY_PRESS_MASK |
339                                   GDK_BUTTON_RELEASE_MASK       |
340                                   GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK       |
341                                   GDK_BUTTON_PRESS_MASK ),
342                                 NULL, event->button.time);
343             ret = TRUE;
344         }
345         break;
346     case GDK_MOTION_NOTIFY:
347         if ( dragging
348              && ( event->motion.state & GDK_BUTTON1_MASK )  && !event_context->space_panning)
349         {
350             if ( event_context->within_tolerance
351                  && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
352                  && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
353                 break; // do not drag if we're within tolerance from origin
354             }
355             // Once the user has moved farther than tolerance from the original location
356             // (indicating they intend to draw, not click), then always process the
357             // motion notify coordinates as given (no snapping back to origin)
358             event_context->within_tolerance = false;
360             NR::Point const motion_w(event->motion.x,
361                                      event->motion.y);
362             Geom::Point motion_dt(to_2geom(desktop->w2d(motion_w)));
364             SnapManager &m = desktop->namedview->snap_manager;
365             m.setup(desktop, true, bc->item);
366             m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt);
368             bc->ctrl_dragged  = event->motion.state & GDK_CONTROL_MASK;
370             if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) {
371                 // once shift is pressed, set bc->extruded
372                 bc->extruded = true;
373             }
375             if (!bc->extruded) {
376                 bc->drag_ptB = from_2geom(motion_dt);
377                 bc->drag_ptC = from_2geom(motion_dt);
379                 bc->drag_ptB_proj = cur_persp->tmat.preimage (from_2geom(motion_dt), 0, Proj::Z);
380                 bc->drag_ptC_proj = bc->drag_ptB_proj;
381                 bc->drag_ptC_proj.normalize();
382                 bc->drag_ptC_proj[Proj::Z] = 0.25;
383             } else {
384                 // Without Ctrl, motion of the extruded corner is constrained to the
385                 // perspective line from drag_ptB to vanishing point Y.
386                 if (!bc->ctrl_dragged) {
387                     /* snapping */
388                     Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, SP_ACTIVE_DOCUMENT->current_persp3d);
389                     bc->drag_ptC = pline.closest_to (from_2geom(motion_dt));
391                     bc->drag_ptB_proj.normalize();
392                     bc->drag_ptC_proj = cur_persp->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X);
393                 } else {
394                     bc->drag_ptC = from_2geom(motion_dt);
396                     bc->drag_ptB_proj.normalize();
397                     bc->drag_ptC_proj = cur_persp->tmat.preimage (from_2geom(motion_dt), bc->drag_ptB_proj[Proj::X], Proj::X);
398                 }
399                 Geom::Point pt2g = to_2geom(bc->drag_ptC);
400                 m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, pt2g);
401                 bc->drag_ptC = from_2geom(pt2g);
402             }
404             sp_box3d_drag(*bc, event->motion.state);
406             ret = TRUE;
407         }
408         break;
409     case GDK_BUTTON_RELEASE:
410         event_context->xp = event_context->yp = 0;
411         if ( event->button.button == 1  && !event_context->space_panning) {
412             dragging = false;
414             if (!event_context->within_tolerance) {
415                 // we've been dragging, finish the box
416                 sp_box3d_finish(bc);
417             } else if (event_context->item_to_select) {
418                 // no dragging, select clicked item if any
419                 if (event->button.state & GDK_SHIFT_MASK) {
420                     selection->toggle(event_context->item_to_select);
421                 } else {
422                     selection->set(event_context->item_to_select);
423                 }
424             } else {
425                 // click in an empty space
426                 selection->clear();
427             }
429             event_context->item_to_select = NULL;
430             ret = TRUE;
431             sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
432                                   event->button.time);
433         }
434         break;
435     case GDK_KEY_PRESS:
436         switch (get_group0_keyval (&event->key)) {
437         case GDK_Up:
438         case GDK_Down:
439         case GDK_KP_Up:
440         case GDK_KP_Down:
441             // prevent the zoom field from activation
442             if (!MOD__CTRL_ONLY)
443                 ret = TRUE;
444             break;
446         case GDK_bracketright:
447             persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::X, -180/snaps, MOD__ALT);
448             sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
449                              _("Change perspective (angle of PLs)"));
450             ret = true;
451             break;
453         case GDK_bracketleft:
454             persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::X, 180/snaps, MOD__ALT);
455             sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
456                              _("Change perspective (angle of PLs)"));
457             ret = true;
458             break;
460         case GDK_parenright:
461             persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Y, -180/snaps, MOD__ALT);
462             sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
463                              _("Change perspective (angle of PLs)"));
464             ret = true;
465             break;
467         case GDK_parenleft:
468             persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Y, 180/snaps, MOD__ALT);
469             sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
470                              _("Change perspective (angle of PLs)"));
471             ret = true;
472             break;
474         case GDK_braceright:
475             persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Z, -180/snaps, MOD__ALT);
476             sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
477                              _("Change perspective (angle of PLs)"));
478             ret = true;
479             break;
481         case GDK_braceleft:
482             persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Z, 180/snaps, MOD__ALT);
483             sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
484                              _("Change perspective (angle of PLs)"));
485             ret = true;
486             break;
488         case GDK_O:
489             if (MOD__CTRL && MOD__SHIFT) {
490                 Box3D::create_canvas_point(persp3d_get_VP(inkscape_active_document()->current_persp3d, Proj::W).affine(),
491                                            6, 0xff00ff00);
492             }
493             ret = true;
494             break;
496         case GDK_g:
497         case GDK_G:
498             if (MOD__SHIFT_ONLY) {
499                 sp_selection_to_guides(desktop);
500                 ret = true;
501             }
502             break;
504         case GDK_x:
505         case GDK_X:
506             if (MOD__ALT_ONLY) {
507                 desktop->setToolboxFocusTo ("altx-box3d");
508                 ret = TRUE;
509             }
510             if (MOD__SHIFT_ONLY) {
511                 persp3d_toggle_VPs(selection->perspList(), Proj::X);
512                 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
513                 ret = true;
514             }
515             break;
517         case GDK_y:
518         case GDK_Y:
519             if (MOD__SHIFT_ONLY) {
520                 persp3d_toggle_VPs(selection->perspList(), Proj::Y);
521                 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
522                 ret = true;
523             }
524             break;
526         case GDK_z:
527         case GDK_Z:
528             if (MOD__SHIFT_ONLY) {
529                 persp3d_toggle_VPs(selection->perspList(), Proj::Z);
530                 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
531                 ret = true;
532             }
533             break;
535         case GDK_Escape:
536             sp_desktop_selection(desktop)->clear();
537             //TODO: make dragging escapable by Esc
538             break;
540         case GDK_space:
541             if (dragging) {
542                 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
543                                       event->button.time);
544                 dragging = false;
545                 if (!event_context->within_tolerance) {
546                     // we've been dragging, finish the box
547                     sp_box3d_finish(bc);
548                 }
549                 // do not return true, so that space would work switching to selector
550             }
551             break;
553         default:
554             break;
555         }
556         break;
557     default:
558         break;
559     }
561     if (!ret) {
562         if (((SPEventContextClass *) parent_class)->root_handler) {
563             ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
564         }
565     }
567     return ret;
570 static void sp_box3d_drag(Box3DContext &bc, guint /*state*/)
572     SPDesktop *desktop = SP_EVENT_CONTEXT(&bc)->desktop;
574     if (!bc.item) {
576         if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) {
577             return;
578         }
580         /* Create object */
581         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(&bc));
582         Inkscape::XML::Node *repr = xml_doc->createElement("svg:g");
583         repr->setAttribute("sodipodi:type", "inkscape:box3d");
585         /* Set style */
586         sp_desktop_apply_style_tool (desktop, repr, "tools.shapes.3dbox", false);
588         bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr);
589         Inkscape::GC::release(repr);
590         Inkscape::XML::Node *repr_side;
591         // TODO: Incorporate this in box3d-side.cpp!
592         for (int i = 0; i < 6; ++i) {
593             repr_side = xml_doc->createElement("svg:path");
594             repr_side->setAttribute("sodipodi:type", "inkscape:box3dside");
595             repr->addChild(repr_side, NULL);
597             Box3DSide *side = SP_BOX3D_SIDE(inkscape_active_document()->getObjectByRepr (repr_side));
599             guint desc = Box3D::int_to_face(i);
601             Box3D::Axis plane = (Box3D::Axis) (desc & 0x7);
602             plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane));
603             side->dir1 = Box3D::extract_first_axis_direction(plane);
604             side->dir2 = Box3D::extract_second_axis_direction(plane);
605             side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
607             /* Set style */
608             box3d_side_apply_style(side);
610             SP_OBJECT(side)->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description
611         }
613         box3d_set_z_orders(SP_BOX3D(bc.item));
614         bc.item->updateRepr();
616         // TODO: It would be nice to show the VPs during dragging, but since there is no selection
617         //       at this point (only after finishing the box), we must do this "manually"
618         /**** bc._vpdrag->updateDraggers(); ****/
620         sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
621     }
623     g_assert(bc.item);
625     SPBox3D *box = SP_BOX3D(bc.item);
627     box->orig_corner0 = bc.drag_origin_proj;
628     box->orig_corner7 = bc.drag_ptC_proj;
630     box3d_check_for_swapped_coords(box);
632     /* we need to call this from here (instead of from box3d_position_set(), for example)
633        because z-order setting must not interfere with display updates during undo/redo */
634     box3d_set_z_orders (box);
636     box3d_position_set(box);
638     // status text
639     bc._message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis"));
642 static void sp_box3d_finish(Box3DContext *bc)
644     bc->_message_context->clear();
645     g_assert (SP_ACTIVE_DOCUMENT->current_persp3d);
647     if ( bc->item != NULL ) {
648         SPDesktop * desktop = SP_EVENT_CONTEXT_DESKTOP(bc);
650         SPBox3D *box = SP_BOX3D(bc->item);
652         box->orig_corner0 = bc->drag_origin_proj;
653         box->orig_corner7 = bc->drag_ptC_proj;
655         box->updateRepr();
657         box3d_relabel_corners(box);
659         sp_canvas_end_forced_full_redraws(desktop->canvas);
661         sp_desktop_selection(desktop)->set(bc->item);
662         sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
663                          _("Create 3D box"));
665         bc->item = NULL;
666     }
668     bc->ctrl_dragged = false;
669     bc->extruded = false;
672 void sp_box3d_context_update_lines(SPEventContext *ec) {
673     /*  update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
674     if (SP_IS_BOX3D_CONTEXT (ec)) {
675         Box3DContext *bc = SP_BOX3D_CONTEXT (ec);
676         bc->_vpdrag->updateLines();
677     }
680 /*
681   Local Variables:
682   mode:c++
683   c-file-style:"stroustrup"
684   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
685   indent-tabs-mode:nil
686   fill-column:99
687   End:
688 */
689 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :