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 "preferences.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;
119 box3d_context->_vpdrag = NULL;
121 new (&box3d_context->sel_changed_connection) sigc::connection();
122 }
124 static void sp_box3d_context_dispose(GObject *object)
125 {
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);
158 }
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)
173 {
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 }
203 }
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 }
221 }
223 static void sp_box3d_context_setup(SPEventContext *ec)
224 {
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));
250 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
252 if (prefs->getBool("/tools/shapes/selcue")) {
253 ec->enableSelectionCue();
254 }
256 if (prefs->getBool("/tools/shapes/gradientdrag")) {
257 ec->enableGrDrag();
258 }
260 bc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
261 }
263 static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
264 {
265 SPDesktop *desktop = event_context->desktop;
267 gint ret = FALSE;
269 switch (event->type) {
270 case GDK_BUTTON_PRESS:
271 if ( event->button.button == 1 && !event_context->space_panning) {
272 Inkscape::setup_for_drag_start(desktop, event_context, event);
273 ret = TRUE;
274 }
275 break;
276 // motion and release are always on root (why?)
277 default:
278 break;
279 }
281 if (((SPEventContextClass *) parent_class)->item_handler) {
282 ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
283 }
285 return ret;
286 }
288 static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event)
289 {
290 static bool dragging;
292 SPDesktop *desktop = event_context->desktop;
293 Inkscape::Selection *selection = sp_desktop_selection (desktop);
294 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
295 int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
297 Box3DContext *bc = SP_BOX3D_CONTEXT(event_context);
298 g_assert (SP_ACTIVE_DOCUMENT->current_persp3d);
299 Persp3D *cur_persp = SP_ACTIVE_DOCUMENT->current_persp3d;
301 event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
303 gint ret = FALSE;
304 switch (event->type) {
305 case GDK_BUTTON_PRESS:
306 if ( event->button.button == 1 && !event_context->space_panning) {
307 Geom::Point const button_w(event->button.x,
308 event->button.y);
310 // save drag origin
311 event_context->xp = (gint) button_w[Geom::X];
312 event_context->yp = (gint) button_w[Geom::Y];
313 event_context->within_tolerance = true;
315 // remember clicked item, *not* disregarding groups (since a 3D box is a group), honoring Alt
316 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);
318 dragging = true;
320 /* */
321 Geom::Point button_dt(desktop->w2d(button_w));
322 bc->drag_origin = from_2geom(button_dt);
323 bc->drag_ptB = from_2geom(button_dt);
324 bc->drag_ptC = from_2geom(button_dt);
326 /* Projective preimages of clicked point under current perspective */
327 bc->drag_origin_proj = cur_persp->tmat.preimage (from_2geom(button_dt), 0, Proj::Z);
328 bc->drag_ptB_proj = bc->drag_origin_proj;
329 bc->drag_ptC_proj = bc->drag_origin_proj;
330 bc->drag_ptC_proj.normalize();
331 bc->drag_ptC_proj[Proj::Z] = 0.25;
333 /* Snap center */
334 SnapManager &m = desktop->namedview->snap_manager;
335 m.setup(desktop, true, bc->item);
336 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, button_dt);
337 bc->center = from_2geom(button_dt);
339 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
340 ( GDK_KEY_PRESS_MASK |
341 GDK_BUTTON_RELEASE_MASK |
342 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
343 GDK_BUTTON_PRESS_MASK ),
344 NULL, event->button.time);
345 ret = TRUE;
346 }
347 break;
348 case GDK_MOTION_NOTIFY:
349 if ( dragging
350 && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning)
351 {
352 if ( event_context->within_tolerance
353 && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
354 && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
355 break; // do not drag if we're within tolerance from origin
356 }
357 // Once the user has moved farther than tolerance from the original location
358 // (indicating they intend to draw, not click), then always process the
359 // motion notify coordinates as given (no snapping back to origin)
360 event_context->within_tolerance = false;
362 Geom::Point const motion_w(event->motion.x,
363 event->motion.y);
364 Geom::Point motion_dt(desktop->w2d(motion_w));
366 SnapManager &m = desktop->namedview->snap_manager;
367 m.setup(desktop, true, bc->item);
368 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, motion_dt);
370 bc->ctrl_dragged = event->motion.state & GDK_CONTROL_MASK;
372 if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) {
373 // once shift is pressed, set bc->extruded
374 bc->extruded = true;
375 }
377 if (!bc->extruded) {
378 bc->drag_ptB = from_2geom(motion_dt);
379 bc->drag_ptC = from_2geom(motion_dt);
381 bc->drag_ptB_proj = cur_persp->tmat.preimage (from_2geom(motion_dt), 0, Proj::Z);
382 bc->drag_ptC_proj = bc->drag_ptB_proj;
383 bc->drag_ptC_proj.normalize();
384 bc->drag_ptC_proj[Proj::Z] = 0.25;
385 } else {
386 // Without Ctrl, motion of the extruded corner is constrained to the
387 // perspective line from drag_ptB to vanishing point Y.
388 if (!bc->ctrl_dragged) {
389 /* snapping */
390 Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, SP_ACTIVE_DOCUMENT->current_persp3d);
391 bc->drag_ptC = pline.closest_to (from_2geom(motion_dt));
393 bc->drag_ptB_proj.normalize();
394 bc->drag_ptC_proj = cur_persp->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X);
395 } else {
396 bc->drag_ptC = from_2geom(motion_dt);
398 bc->drag_ptB_proj.normalize();
399 bc->drag_ptC_proj = cur_persp->tmat.preimage (from_2geom(motion_dt), bc->drag_ptB_proj[Proj::X], Proj::X);
400 }
401 Geom::Point pt2g = to_2geom(bc->drag_ptC);
402 m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, pt2g);
403 bc->drag_ptC = from_2geom(pt2g);
404 }
406 sp_box3d_drag(*bc, event->motion.state);
408 ret = TRUE;
409 }
410 break;
411 case GDK_BUTTON_RELEASE:
412 event_context->xp = event_context->yp = 0;
413 if ( event->button.button == 1 && !event_context->space_panning) {
414 dragging = false;
416 if (!event_context->within_tolerance) {
417 // we've been dragging, finish the box
418 sp_box3d_finish(bc);
419 } else if (event_context->item_to_select) {
420 // no dragging, select clicked item if any
421 if (event->button.state & GDK_SHIFT_MASK) {
422 selection->toggle(event_context->item_to_select);
423 } else {
424 selection->set(event_context->item_to_select);
425 }
426 } else {
427 // click in an empty space
428 selection->clear();
429 }
431 event_context->item_to_select = NULL;
432 ret = TRUE;
433 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
434 event->button.time);
435 }
436 break;
437 case GDK_KEY_PRESS:
438 switch (get_group0_keyval (&event->key)) {
439 case GDK_Up:
440 case GDK_Down:
441 case GDK_KP_Up:
442 case GDK_KP_Down:
443 // prevent the zoom field from activation
444 if (!MOD__CTRL_ONLY)
445 ret = TRUE;
446 break;
448 case GDK_bracketright:
449 persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::X, -180/snaps, MOD__ALT);
450 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
451 _("Change perspective (angle of PLs)"));
452 ret = true;
453 break;
455 case GDK_bracketleft:
456 persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::X, 180/snaps, MOD__ALT);
457 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
458 _("Change perspective (angle of PLs)"));
459 ret = true;
460 break;
462 case GDK_parenright:
463 persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Y, -180/snaps, MOD__ALT);
464 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
465 _("Change perspective (angle of PLs)"));
466 ret = true;
467 break;
469 case GDK_parenleft:
470 persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Y, 180/snaps, MOD__ALT);
471 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
472 _("Change perspective (angle of PLs)"));
473 ret = true;
474 break;
476 case GDK_braceright:
477 persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Z, -180/snaps, MOD__ALT);
478 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
479 _("Change perspective (angle of PLs)"));
480 ret = true;
481 break;
483 case GDK_braceleft:
484 persp3d_rotate_VP (inkscape_active_document()->current_persp3d, Proj::Z, 180/snaps, MOD__ALT);
485 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
486 _("Change perspective (angle of PLs)"));
487 ret = true;
488 break;
490 case GDK_O:
491 if (MOD__CTRL && MOD__SHIFT) {
492 Box3D::create_canvas_point(persp3d_get_VP(inkscape_active_document()->current_persp3d, Proj::W).affine(),
493 6, 0xff00ff00);
494 }
495 ret = true;
496 break;
498 case GDK_g:
499 case GDK_G:
500 if (MOD__SHIFT_ONLY) {
501 sp_selection_to_guides(desktop);
502 ret = true;
503 }
504 break;
506 case GDK_x:
507 case GDK_X:
508 if (MOD__ALT_ONLY) {
509 desktop->setToolboxFocusTo ("altx-box3d");
510 ret = TRUE;
511 }
512 if (MOD__SHIFT_ONLY) {
513 persp3d_toggle_VPs(selection->perspList(), Proj::X);
514 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
515 ret = true;
516 }
517 break;
519 case GDK_y:
520 case GDK_Y:
521 if (MOD__SHIFT_ONLY) {
522 persp3d_toggle_VPs(selection->perspList(), Proj::Y);
523 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
524 ret = true;
525 }
526 break;
528 case GDK_z:
529 case GDK_Z:
530 if (MOD__SHIFT_ONLY) {
531 persp3d_toggle_VPs(selection->perspList(), Proj::Z);
532 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
533 ret = true;
534 }
535 break;
537 case GDK_Escape:
538 sp_desktop_selection(desktop)->clear();
539 //TODO: make dragging escapable by Esc
540 break;
542 case GDK_space:
543 if (dragging) {
544 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
545 event->button.time);
546 dragging = false;
547 if (!event_context->within_tolerance) {
548 // we've been dragging, finish the box
549 sp_box3d_finish(bc);
550 }
551 // do not return true, so that space would work switching to selector
552 }
553 break;
555 default:
556 break;
557 }
558 break;
559 default:
560 break;
561 }
563 if (!ret) {
564 if (((SPEventContextClass *) parent_class)->root_handler) {
565 ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
566 }
567 }
569 return ret;
570 }
572 static void sp_box3d_drag(Box3DContext &bc, guint /*state*/)
573 {
574 SPDesktop *desktop = SP_EVENT_CONTEXT(&bc)->desktop;
576 if (!bc.item) {
578 if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) {
579 return;
580 }
582 /* Create object */
583 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(&bc));
584 Inkscape::XML::Node *repr = xml_doc->createElement("svg:g");
585 repr->setAttribute("sodipodi:type", "inkscape:box3d");
587 /* Set style */
588 sp_desktop_apply_style_tool (desktop, repr, "/tools/shapes/3dbox", false);
590 bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr);
591 Inkscape::GC::release(repr);
592 Inkscape::XML::Node *repr_side;
593 // TODO: Incorporate this in box3d-side.cpp!
594 for (int i = 0; i < 6; ++i) {
595 repr_side = xml_doc->createElement("svg:path");
596 repr_side->setAttribute("sodipodi:type", "inkscape:box3dside");
597 repr->addChild(repr_side, NULL);
599 Box3DSide *side = SP_BOX3D_SIDE(inkscape_active_document()->getObjectByRepr (repr_side));
601 guint desc = Box3D::int_to_face(i);
603 Box3D::Axis plane = (Box3D::Axis) (desc & 0x7);
604 plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane));
605 side->dir1 = Box3D::extract_first_axis_direction(plane);
606 side->dir2 = Box3D::extract_second_axis_direction(plane);
607 side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
609 /* Set style */
610 box3d_side_apply_style(side);
612 SP_OBJECT(side)->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description
613 }
615 box3d_set_z_orders(SP_BOX3D(bc.item));
616 bc.item->updateRepr();
618 // TODO: It would be nice to show the VPs during dragging, but since there is no selection
619 // at this point (only after finishing the box), we must do this "manually"
620 /**** bc._vpdrag->updateDraggers(); ****/
622 sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
623 }
625 g_assert(bc.item);
627 SPBox3D *box = SP_BOX3D(bc.item);
629 box->orig_corner0 = bc.drag_origin_proj;
630 box->orig_corner7 = bc.drag_ptC_proj;
632 box3d_check_for_swapped_coords(box);
634 /* we need to call this from here (instead of from box3d_position_set(), for example)
635 because z-order setting must not interfere with display updates during undo/redo */
636 box3d_set_z_orders (box);
638 box3d_position_set(box);
640 // status text
641 bc._message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis"));
642 }
644 static void sp_box3d_finish(Box3DContext *bc)
645 {
646 bc->_message_context->clear();
647 g_assert (SP_ACTIVE_DOCUMENT->current_persp3d);
649 if ( bc->item != NULL ) {
650 SPDesktop * desktop = SP_EVENT_CONTEXT_DESKTOP(bc);
652 SPBox3D *box = SP_BOX3D(bc->item);
654 box->orig_corner0 = bc->drag_origin_proj;
655 box->orig_corner7 = bc->drag_ptC_proj;
657 box->updateRepr();
659 box3d_relabel_corners(box);
661 sp_canvas_end_forced_full_redraws(desktop->canvas);
663 sp_desktop_selection(desktop)->set(bc->item);
664 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
665 _("Create 3D box"));
667 bc->item = NULL;
668 }
670 bc->ctrl_dragged = false;
671 bc->extruded = false;
672 }
674 void sp_box3d_context_update_lines(SPEventContext *ec) {
675 /* update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
676 if (SP_IS_BOX3D_CONTEXT (ec)) {
677 Box3DContext *bc = SP_BOX3D_CONTEXT (ec);
678 bc->_vpdrag->updateLines();
679 }
680 }
682 /*
683 Local Variables:
684 mode:c++
685 c-file-style:"stroustrup"
686 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
687 indent-tabs-mode:nil
688 fill-column:99
689 End:
690 */
691 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :