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"
50 #include "shape-editor.h"
52 static void sp_box3d_context_class_init(Box3DContextClass *klass);
53 static void sp_box3d_context_init(Box3DContext *box3d_context);
54 static void sp_box3d_context_dispose(GObject *object);
56 static void sp_box3d_context_setup(SPEventContext *ec);
57 static void sp_box3d_context_finish(SPEventContext *ec);
59 static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event);
60 static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
62 static void sp_box3d_drag(Box3DContext &bc, guint state);
63 static void sp_box3d_finish(Box3DContext *bc);
65 static SPEventContextClass *parent_class;
67 GtkType sp_box3d_context_get_type()
68 {
69 static GType type = 0;
70 if (!type) {
71 GTypeInfo info = {
72 sizeof(Box3DContextClass),
73 NULL, NULL,
74 (GClassInitFunc) sp_box3d_context_class_init,
75 NULL, NULL,
76 sizeof(Box3DContext),
77 4,
78 (GInstanceInitFunc) sp_box3d_context_init,
79 NULL, /* value_table */
80 };
81 type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "Box3DContext", &info, (GTypeFlags) 0);
82 }
83 return type;
84 }
86 static void sp_box3d_context_class_init(Box3DContextClass *klass)
87 {
88 GObjectClass *object_class = (GObjectClass *) klass;
89 SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
91 parent_class = (SPEventContextClass *) g_type_class_peek_parent(klass);
93 object_class->dispose = sp_box3d_context_dispose;
95 event_context_class->setup = sp_box3d_context_setup;
96 event_context_class->finish = sp_box3d_context_finish;
97 event_context_class->root_handler = sp_box3d_context_root_handler;
98 event_context_class->item_handler = sp_box3d_context_item_handler;
99 }
101 static void sp_box3d_context_init(Box3DContext *box3d_context)
102 {
103 SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context);
105 event_context->cursor_shape = cursor_3dbox_xpm;
106 event_context->hot_x = 4;
107 event_context->hot_y = 4;
108 event_context->xp = 0;
109 event_context->yp = 0;
110 event_context->tolerance = 0;
111 event_context->within_tolerance = false;
112 event_context->item_to_select = 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_finish(SPEventContext *ec)
125 {
126 Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
127 SPDesktop *desktop = ec->desktop;
129 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME);
130 sp_box3d_finish(bc);
131 bc->sel_changed_connection.disconnect();
132 // sp_repr_remove_listener_by_data(cc->active_shape_repr, cc);
134 if (((SPEventContextClass *) parent_class)->finish) {
135 ((SPEventContextClass *) parent_class)->finish(ec);
136 }
137 }
140 static void sp_box3d_context_dispose(GObject *object)
141 {
142 Box3DContext *bc = SP_BOX3D_CONTEXT(object);
143 SPEventContext *ec = SP_EVENT_CONTEXT(object);
145 ec->enableGrDrag(false);
147 delete (bc->_vpdrag);
148 bc->_vpdrag = NULL;
150 bc->sel_changed_connection.disconnect();
151 bc->sel_changed_connection.~connection();
153 delete ec->shape_editor;
154 ec->shape_editor = NULL;
156 /* fixme: This is necessary because we do not grab */
157 if (bc->item) {
158 sp_box3d_finish(bc);
159 }
161 if (bc->_message_context) {
162 delete bc->_message_context;
163 }
165 G_OBJECT_CLASS(parent_class)->dispose(object);
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 ec->shape_editor->unset_item(SH_KNOTHOLDER);
178 SPItem *item = selection->singleItem();
179 ec->shape_editor->set_item(item, SH_KNOTHOLDER);
181 if (selection->perspList().size() == 1) {
182 // selecting a single box changes the current perspective
183 ec->desktop->doc()->setCurrentPersp3D(selection->perspList().front());
184 }
185 }
187 /* Create a default perspective in document defs if none is present (which can happen, among other
188 * circumstances, after 'vacuum defs' or when a pre-0.46 file is opened).
189 */
190 static void sp_box3d_context_ensure_persp_in_defs(SPDocument *document) {
191 SPDefs *defs = (SPDefs *) SP_DOCUMENT_DEFS(document);
193 bool has_persp = false;
194 for (SPObject *child = sp_object_first_child(defs); child != NULL; child = SP_OBJECT_NEXT(child) ) {
195 if (SP_IS_PERSP3D(child)) {
196 has_persp = true;
197 break;
198 }
199 }
201 if (!has_persp) {
202 document->setCurrentPersp3D(persp3d_create_xml_element (document));
203 }
204 }
206 static void sp_box3d_context_setup(SPEventContext *ec)
207 {
208 Box3DContext *bc = SP_BOX3D_CONTEXT(ec);
210 if (((SPEventContextClass *) parent_class)->setup) {
211 ((SPEventContextClass *) parent_class)->setup(ec);
212 }
214 ec->shape_editor = new ShapeEditor(ec->desktop);
216 SPItem *item = sp_desktop_selection(ec->desktop)->singleItem();
217 if (item) {
218 ec->shape_editor->set_item(item, SH_KNOTHOLDER);
219 }
221 bc->sel_changed_connection.disconnect();
222 bc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged(
223 sigc::bind(sigc::ptr_fun(&sp_box3d_context_selection_changed), (gpointer)bc)
224 );
226 bc->_vpdrag = new Box3D::VPDrag(sp_desktop_document (ec->desktop));
227 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
229 if (prefs->getBool("/tools/shapes/selcue")) {
230 ec->enableSelectionCue();
231 }
233 if (prefs->getBool("/tools/shapes/gradientdrag")) {
234 ec->enableGrDrag();
235 }
237 bc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
238 }
240 static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
241 {
242 SPDesktop *desktop = event_context->desktop;
244 gint ret = FALSE;
246 switch (event->type) {
247 case GDK_BUTTON_PRESS:
248 if ( event->button.button == 1 && !event_context->space_panning) {
249 Inkscape::setup_for_drag_start(desktop, event_context, event);
250 ret = TRUE;
251 }
252 break;
253 // motion and release are always on root (why?)
254 default:
255 break;
256 }
258 if (((SPEventContextClass *) parent_class)->item_handler) {
259 ret = ((SPEventContextClass *) parent_class)->item_handler(event_context, item, event);
260 }
262 return ret;
263 }
265 static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEvent *event)
266 {
267 static bool dragging;
269 SPDesktop *desktop = event_context->desktop;
270 SPDocument *document = sp_desktop_document (desktop);
271 Inkscape::Selection *selection = sp_desktop_selection (desktop);
272 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
273 int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
275 Box3DContext *bc = SP_BOX3D_CONTEXT(event_context);
276 Persp3D *cur_persp = document->getCurrentPersp3D();
278 event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
280 gint ret = FALSE;
281 switch (event->type) {
282 case GDK_BUTTON_PRESS:
283 if ( event->button.button == 1 && !event_context->space_panning) {
284 Geom::Point const button_w(event->button.x,
285 event->button.y);
287 // save drag origin
288 event_context->xp = (gint) button_w[Geom::X];
289 event_context->yp = (gint) button_w[Geom::Y];
290 event_context->within_tolerance = true;
292 // remember clicked item, *not* disregarding groups (since a 3D box is a group), honoring Alt
293 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);
295 dragging = true;
297 /* */
298 Geom::Point button_dt(desktop->w2d(button_w));
299 bc->drag_origin = from_2geom(button_dt);
300 bc->drag_ptB = from_2geom(button_dt);
301 bc->drag_ptC = from_2geom(button_dt);
303 // This can happen after saving when the last remaining perspective was purged and must be recreated.
304 if (!cur_persp) {
305 sp_box3d_context_ensure_persp_in_defs(document);
306 cur_persp = document->getCurrentPersp3D();
307 }
309 /* Projective preimages of clicked point under current perspective */
310 bc->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(button_dt), 0, Proj::Z);
311 bc->drag_ptB_proj = bc->drag_origin_proj;
312 bc->drag_ptC_proj = bc->drag_origin_proj;
313 bc->drag_ptC_proj.normalize();
314 bc->drag_ptC_proj[Proj::Z] = 0.25;
316 /* Snap center */
317 SnapManager &m = desktop->namedview->snap_manager;
318 m.setup(desktop, true, bc->item);
319 m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
320 bc->center = from_2geom(button_dt);
322 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
323 ( GDK_KEY_PRESS_MASK |
324 GDK_BUTTON_RELEASE_MASK |
325 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
326 GDK_BUTTON_PRESS_MASK ),
327 NULL, event->button.time);
328 ret = TRUE;
329 }
330 break;
331 case GDK_MOTION_NOTIFY:
332 if ( dragging
333 && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning)
334 {
335 if ( event_context->within_tolerance
336 && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance )
337 && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) {
338 break; // do not drag if we're within tolerance from origin
339 }
340 // Once the user has moved farther than tolerance from the original location
341 // (indicating they intend to draw, not click), then always process the
342 // motion notify coordinates as given (no snapping back to origin)
343 event_context->within_tolerance = false;
345 Geom::Point const motion_w(event->motion.x,
346 event->motion.y);
347 Geom::Point motion_dt(desktop->w2d(motion_w));
349 SnapManager &m = desktop->namedview->snap_manager;
350 m.setup(desktop, true, bc->item);
351 m.freeSnapReturnByRef(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
353 bc->ctrl_dragged = event->motion.state & GDK_CONTROL_MASK;
355 if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) {
356 // once shift is pressed, set bc->extruded
357 bc->extruded = true;
358 }
360 if (!bc->extruded) {
361 bc->drag_ptB = from_2geom(motion_dt);
362 bc->drag_ptC = from_2geom(motion_dt);
364 bc->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(motion_dt), 0, Proj::Z);
365 bc->drag_ptC_proj = bc->drag_ptB_proj;
366 bc->drag_ptC_proj.normalize();
367 bc->drag_ptC_proj[Proj::Z] = 0.25;
368 } else {
369 // Without Ctrl, motion of the extruded corner is constrained to the
370 // perspective line from drag_ptB to vanishing point Y.
371 if (!bc->ctrl_dragged) {
372 /* snapping */
373 Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, document->getCurrentPersp3D());
374 bc->drag_ptC = pline.closest_to (from_2geom(motion_dt));
376 bc->drag_ptB_proj.normalize();
377 bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X);
378 } else {
379 bc->drag_ptC = from_2geom(motion_dt);
381 bc->drag_ptB_proj.normalize();
382 bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (from_2geom(motion_dt), bc->drag_ptB_proj[Proj::X], Proj::X);
383 }
384 m.freeSnapReturnByRef(bc->drag_ptC, Inkscape::SNAPSOURCE_NODE_HANDLE);
385 }
387 sp_box3d_drag(*bc, event->motion.state);
389 ret = TRUE;
390 } else if (!sp_event_context_knot_mouseover(bc)) {
391 SnapManager &m = desktop->namedview->snap_manager;
392 m.setup(desktop);
394 Geom::Point const motion_w(event->motion.x, event->motion.y);
395 Geom::Point motion_dt(desktop->w2d(motion_w));
396 m.preSnap(Inkscape::SnapCandidatePoint(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE));
397 }
398 break;
399 case GDK_BUTTON_RELEASE:
400 event_context->xp = event_context->yp = 0;
401 if ( event->button.button == 1 && !event_context->space_panning) {
402 dragging = false;
403 sp_event_context_discard_delayed_snap_event(event_context);
405 if (!event_context->within_tolerance) {
406 // we've been dragging, finish the box
407 sp_box3d_finish(bc);
408 } else if (event_context->item_to_select) {
409 // no dragging, select clicked item if any
410 if (event->button.state & GDK_SHIFT_MASK) {
411 selection->toggle(event_context->item_to_select);
412 } else {
413 selection->set(event_context->item_to_select);
414 }
415 } else {
416 // click in an empty space
417 selection->clear();
418 }
420 event_context->item_to_select = NULL;
421 ret = TRUE;
422 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
423 event->button.time);
424 }
425 break;
426 case GDK_KEY_PRESS:
427 switch (get_group0_keyval (&event->key)) {
428 case GDK_Up:
429 case GDK_Down:
430 case GDK_KP_Up:
431 case GDK_KP_Down:
432 // prevent the zoom field from activation
433 if (!MOD__CTRL_ONLY)
434 ret = TRUE;
435 break;
437 case GDK_bracketright:
438 persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::X, -180/snaps, MOD__ALT);
439 sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
440 _("Change perspective (angle of PLs)"));
441 ret = true;
442 break;
444 case GDK_bracketleft:
445 persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::X, 180/snaps, MOD__ALT);
446 sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
447 _("Change perspective (angle of PLs)"));
448 ret = true;
449 break;
451 case GDK_parenright:
452 persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Y, -180/snaps, MOD__ALT);
453 sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
454 _("Change perspective (angle of PLs)"));
455 ret = true;
456 break;
458 case GDK_parenleft:
459 persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Y, 180/snaps, MOD__ALT);
460 sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
461 _("Change perspective (angle of PLs)"));
462 ret = true;
463 break;
465 case GDK_braceright:
466 persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Z, -180/snaps, MOD__ALT);
467 sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
468 _("Change perspective (angle of PLs)"));
469 ret = true;
470 break;
472 case GDK_braceleft:
473 persp3d_rotate_VP (document->getCurrentPersp3D(), Proj::Z, 180/snaps, MOD__ALT);
474 sp_document_done(document, SP_VERB_CONTEXT_3DBOX,
475 _("Change perspective (angle of PLs)"));
476 ret = true;
477 break;
479 /* TODO: what is this???
480 case GDK_O:
481 if (MOD__CTRL && MOD__SHIFT) {
482 Box3D::create_canvas_point(persp3d_get_VP(document()->getCurrentPersp3D(), Proj::W).affine(),
483 6, 0xff00ff00);
484 }
485 ret = true;
486 break;
487 */
489 case GDK_g:
490 case GDK_G:
491 if (MOD__SHIFT_ONLY) {
492 sp_selection_to_guides(desktop);
493 ret = true;
494 }
495 break;
497 case GDK_p:
498 case GDK_P:
499 if (MOD__SHIFT_ONLY) {
500 if (document->getCurrentPersp3D()) {
501 persp3d_print_debugging_info (document->getCurrentPersp3D());
502 }
503 ret = true;
504 }
505 break;
507 case GDK_x:
508 case GDK_X:
509 if (MOD__ALT_ONLY) {
510 desktop->setToolboxFocusTo ("altx-box3d");
511 ret = TRUE;
512 }
513 if (MOD__SHIFT_ONLY) {
514 persp3d_toggle_VPs(selection->perspList(), Proj::X);
515 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
516 ret = true;
517 }
518 break;
520 case GDK_y:
521 case GDK_Y:
522 if (MOD__SHIFT_ONLY) {
523 persp3d_toggle_VPs(selection->perspList(), Proj::Y);
524 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
525 ret = true;
526 }
527 break;
529 case GDK_z:
530 case GDK_Z:
531 if (MOD__SHIFT_ONLY) {
532 persp3d_toggle_VPs(selection->perspList(), Proj::Z);
533 bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically?
534 ret = true;
535 }
536 break;
538 case GDK_Escape:
539 sp_desktop_selection(desktop)->clear();
540 //TODO: make dragging escapable by Esc
541 break;
543 case GDK_space:
544 if (dragging) {
545 sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
546 event->button.time);
547 dragging = false;
548 sp_event_context_discard_delayed_snap_event(event_context);
549 if (!event_context->within_tolerance) {
550 // we've been dragging, finish the box
551 sp_box3d_finish(bc);
552 }
553 // do not return true, so that space would work switching to selector
554 }
555 break;
557 default:
558 break;
559 }
560 break;
561 default:
562 break;
563 }
565 if (!ret) {
566 if (((SPEventContextClass *) parent_class)->root_handler) {
567 ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event);
568 }
569 }
571 return ret;
572 }
574 static void sp_box3d_drag(Box3DContext &bc, guint /*state*/)
575 {
576 SPDesktop *desktop = SP_EVENT_CONTEXT(&bc)->desktop;
578 if (!bc.item) {
580 if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) {
581 return;
582 }
584 /* Create object */
585 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(&bc));
586 Inkscape::XML::Node *repr = xml_doc->createElement("svg:g");
587 repr->setAttribute("sodipodi:type", "inkscape:box3d");
589 /* Set style */
590 sp_desktop_apply_style_tool (desktop, repr, "/tools/shapes/3dbox", false);
592 bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr);
593 Inkscape::GC::release(repr);
594 Inkscape::XML::Node *repr_side;
595 // TODO: Incorporate this in box3d-side.cpp!
596 for (int i = 0; i < 6; ++i) {
597 repr_side = xml_doc->createElement("svg:path");
598 repr_side->setAttribute("sodipodi:type", "inkscape:box3dside");
599 repr->addChild(repr_side, NULL);
601 Box3DSide *side = SP_BOX3D_SIDE(inkscape_active_document()->getObjectByRepr (repr_side));
603 guint desc = Box3D::int_to_face(i);
605 Box3D::Axis plane = (Box3D::Axis) (desc & 0x7);
606 plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane));
607 side->dir1 = Box3D::extract_first_axis_direction(plane);
608 side->dir2 = Box3D::extract_second_axis_direction(plane);
609 side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8);
611 /* Set style */
612 box3d_side_apply_style(side);
614 SP_OBJECT(side)->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description
615 }
617 box3d_set_z_orders(SP_BOX3D(bc.item));
618 bc.item->updateRepr();
620 // TODO: It would be nice to show the VPs during dragging, but since there is no selection
621 // at this point (only after finishing the box), we must do this "manually"
622 /* bc._vpdrag->updateDraggers(); */
624 sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 5);
625 }
627 g_assert(bc.item);
629 SPBox3D *box = SP_BOX3D(bc.item);
631 box->orig_corner0 = bc.drag_origin_proj;
632 box->orig_corner7 = bc.drag_ptC_proj;
634 box3d_check_for_swapped_coords(box);
636 /* we need to call this from here (instead of from box3d_position_set(), for example)
637 because z-order setting must not interfere with display updates during undo/redo */
638 box3d_set_z_orders (box);
640 box3d_position_set(box);
642 // status text
643 bc._message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis"));
644 }
646 static void sp_box3d_finish(Box3DContext *bc)
647 {
648 bc->_message_context->clear();
649 bc->ctrl_dragged = false;
650 bc->extruded = false;
652 if ( bc->item != NULL ) {
653 SPDesktop * desktop = SP_EVENT_CONTEXT_DESKTOP(bc);
654 SPDocument *doc = sp_desktop_document(desktop);
655 if (!doc || !doc->getCurrentPersp3D())
656 return;
658 SPBox3D *box = SP_BOX3D(bc->item);
660 box->orig_corner0 = bc->drag_origin_proj;
661 box->orig_corner7 = bc->drag_ptC_proj;
663 box->updateRepr();
665 box3d_relabel_corners(box);
667 sp_canvas_end_forced_full_redraws(desktop->canvas);
669 sp_desktop_selection(desktop)->set(bc->item);
670 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX,
671 _("Create 3D box"));
673 bc->item = NULL;
674 }
675 }
677 void sp_box3d_context_update_lines(SPEventContext *ec) {
678 /* update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
679 if (SP_IS_BOX3D_CONTEXT (ec)) {
680 Box3DContext *bc = SP_BOX3D_CONTEXT (ec);
681 bc->_vpdrag->updateLines();
682 }
683 }
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 :