diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-04-21 21:58:15 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-04-21 21:58:15 +0000 |
| commit | bdde74bbab299f2ee448f1c55469c56a66fb01f7 (patch) | |
| tree | 45bccef1ec815708f9b54171e2d567344f155074 /src | |
| parent | More cleaning. (diff) | |
| download | inkscape-bdde74bbab299f2ee448f1c55469c56a66fb01f7.tar.gz inkscape-bdde74bbab299f2ee448f1c55469c56a66fb01f7.zip | |
Removed some unused files; more refactoring in EventContext tree.
(bzr r11608.1.104)
Diffstat (limited to 'src')
37 files changed, 451 insertions, 694 deletions
diff --git a/src/Makefile_insert b/src/Makefile_insert index 06e3f2d79..440757e5c 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -59,7 +59,6 @@ ink_common_sources += \ fill-or-stroke.h \ filter-chemistry.cpp filter-chemistry.h \ filter-enums.cpp filter-enums.h \ - fixes.cpp \ flood-context.cpp flood-context.h \ gc-alloc.h \ gc-anchored.h gc-anchored.cpp \ @@ -100,7 +99,6 @@ ink_common_sources += \ main-cmdlineact.cpp main-cmdlineact.h \ marker.cpp marker.h \ media.cpp media.h \ - memeq.h \ menus-skeleton.h \ mesh-context.cpp mesh-context.h \ message-context.cpp message-context.h \ diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 1c8e7c860..13b75db98 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -453,8 +453,6 @@ void SPArcContext::finishItem() { return; } - SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; - this->arc->updateRepr(); desktop->canvas->endForcedFullRedraws(); diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index dea91185a..c009dc699 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -53,10 +53,6 @@ using Inkscape::DocumentUndo; -static void sp_box3d_drag(Box3DContext &bc, guint state); -static void sp_box3d_finish(Box3DContext *bc); - - #include "tool-factory.h" namespace { @@ -74,92 +70,66 @@ const std::string& Box3DContext::getPrefsPath() { const std::string Box3DContext::prefsPath = "/tools/shapes/3dbox"; Box3DContext::Box3DContext() : SPEventContext() { - Box3DContext* box3d_context = this; - - box3d_context->_message_context = 0; - - SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context); - - event_context->cursor_shape = cursor_3dbox_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; - event_context->xp = 0; - event_context->yp = 0; - event_context->tolerance = 0; - event_context->within_tolerance = false; - event_context->item_to_select = NULL; + this->_message_context = 0; - box3d_context->item = NULL; + this->cursor_shape = cursor_3dbox_xpm; + this->hot_x = 4; + this->hot_y = 4; + this->xp = 0; + this->yp = 0; + this->tolerance = 0; + this->within_tolerance = false; + this->item_to_select = NULL; - box3d_context->ctrl_dragged = false; - box3d_context->extruded = false; + this->box3d = NULL; - box3d_context->_vpdrag = NULL; + this->ctrl_dragged = false; + this->extruded = false; - //new (&box3d_context->sel_changed_connection) sigc::connection(); + this->_vpdrag = NULL; } void Box3DContext::finish() { - SPEventContext* ec = this; - - Box3DContext *bc = SP_BOX3D_CONTEXT(ec); - SPDesktop *desktop = ec->desktop; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), GDK_CURRENT_TIME); - sp_box3d_finish(bc); - bc->sel_changed_connection.disconnect(); -// sp_repr_remove_listener_by_data(cc->active_shape_repr, cc); + this->finishItem(); + this->sel_changed_connection.disconnect(); -// if (((SPEventContextClass *) sp_box3d_context_parent_class)->finish) { -// ((SPEventContextClass *) sp_box3d_context_parent_class)->finish(ec); -// } SPEventContext::finish(); } Box3DContext::~Box3DContext() { - Box3DContext *bc = SP_BOX3D_CONTEXT(this); - SPEventContext *ec = SP_EVENT_CONTEXT(this); + this->enableGrDrag(false); - ec->enableGrDrag(false); + delete (this->_vpdrag); + this->_vpdrag = NULL; - delete (bc->_vpdrag); - bc->_vpdrag = NULL; + this->sel_changed_connection.disconnect(); - bc->sel_changed_connection.disconnect(); - //bc->sel_changed_connection.~connection(); - - delete ec->shape_editor; - ec->shape_editor = NULL; + delete this->shape_editor; + this->shape_editor = NULL; /* fixme: This is necessary because we do not grab */ - if (bc->item) { - sp_box3d_finish(bc); + if (this->box3d) { + this->finishItem(); } - if (bc->_message_context) { - delete bc->_message_context; + if (this->_message_context) { + delete this->_message_context; } - - //G_OBJECT_CLASS(sp_box3d_context_parent_class)->dispose(object); } /** * Callback that processes the "changed" signal on the selection; * destroys old and creates new knotholder. */ -static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, gpointer data) -{ - Box3DContext *bc = SP_BOX3D_CONTEXT(data); - SPEventContext *ec = SP_EVENT_CONTEXT(bc); - - ec->shape_editor->unset_item(SH_KNOTHOLDER); - SPItem *item = selection->singleItem(); - ec->shape_editor->set_item(item, SH_KNOTHOLDER); +void Box3DContext::selection_changed(Inkscape::Selection* selection) { + this->shape_editor->unset_item(SH_KNOTHOLDER); + this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); if (selection->perspList().size() == 1) { // selecting a single box changes the current perspective - ec->desktop->doc()->setCurrentPersp3D(selection->perspList().front()); + this->desktop->doc()->setCurrentPersp3D(selection->perspList().front()); } } @@ -183,52 +153,42 @@ static void sp_box3d_context_ensure_persp_in_defs(SPDocument *document) { } void Box3DContext::setup() { - SPEventContext* ec = this; - - Box3DContext *bc = SP_BOX3D_CONTEXT(ec); - -// if (((SPEventContextClass *) sp_box3d_context_parent_class)->setup) { -// ((SPEventContextClass *) sp_box3d_context_parent_class)->setup(ec); -// } SPEventContext::setup(); - ec->shape_editor = new ShapeEditor(ec->desktop); + this->shape_editor = new ShapeEditor(this->desktop); - SPItem *item = sp_desktop_selection(ec->desktop)->singleItem(); + SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - ec->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item, SH_KNOTHOLDER); } - bc->sel_changed_connection.disconnect(); - bc->sel_changed_connection = sp_desktop_selection(ec->desktop)->connectChanged( - sigc::bind(sigc::ptr_fun(&sp_box3d_context_selection_changed), (gpointer)bc) + this->sel_changed_connection.disconnect(); + this->sel_changed_connection = sp_desktop_selection(this->desktop)->connectChanged( + sigc::mem_fun(this, &Box3DContext::selection_changed) ); - bc->_vpdrag = new Box3D::VPDrag(sp_desktop_document (ec->desktop)); + this->_vpdrag = new Box3D::VPDrag(sp_desktop_document(this->desktop)); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/shapes/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } if (prefs->getBool("/tools/shapes/gradientdrag")) { - ec->enableGrDrag(); + this->enableGrDrag(); } - bc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } gint Box3DContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* event_context = this; - - SPDesktop *desktop = event_context->desktop; - gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if ( event->button.button == 1 && !event_context->space_panning) { - Inkscape::setup_for_drag_start(desktop, event_context, event); + if ( event->button.button == 1 && !this->space_panning) { + Inkscape::setup_for_drag_start(desktop, this, event); ret = TRUE; } break; @@ -247,48 +207,43 @@ gint Box3DContext::item_handler(SPItem* item, GdkEvent* event) { } gint Box3DContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - static bool dragging; - SPDesktop *desktop = event_context->desktop; SPDocument *document = sp_desktop_document (desktop); Inkscape::Selection *selection = sp_desktop_selection (desktop); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); - Box3DContext *bc = SP_BOX3D_CONTEXT(event_context); Persp3D *cur_persp = document->getCurrentPersp3D(); - event_context->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if ( event->button.button == 1 && !event_context->space_panning) { - Geom::Point const button_w(event->button.x, - event->button.y); + if ( event->button.button == 1 && !this->space_panning) { + Geom::Point const button_w(event->button.x, event->button.y); Geom::Point button_dt(desktop->w2d(button_w)); // save drag origin - event_context->xp = (gint) button_w[Geom::X]; - event_context->yp = (gint) button_w[Geom::Y]; - event_context->within_tolerance = true; + this->xp = (gint) button_w[Geom::X]; + this->yp = (gint) button_w[Geom::Y]; + this->within_tolerance = true; - // remember clicked item, *not* disregarding groups (since a 3D box is a group), honoring Alt - 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); + // remember clicked box3d, *not* disregarding groups (since a 3D box is a group), honoring Alt + this->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, event->button.state & GDK_CONTROL_MASK); dragging = true; SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, true, bc->item); + m.setup(desktop, true, this->box3d); m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); - bc->center = button_dt; + this->center = button_dt; - bc->drag_origin = button_dt; - bc->drag_ptB = button_dt; - bc->drag_ptC = button_dt; + this->drag_origin = button_dt; + this->drag_ptB = button_dt; + this->drag_ptC = button_dt; // This can happen after saving when the last remaining perspective was purged and must be recreated. if (!cur_persp) { @@ -297,11 +252,11 @@ gint Box3DContext::root_handler(GdkEvent* event) { } /* Projective preimages of clicked point under current perspective */ - bc->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (button_dt, 0, Proj::Z); - bc->drag_ptB_proj = bc->drag_origin_proj; - bc->drag_ptC_proj = bc->drag_origin_proj; - bc->drag_ptC_proj.normalize(); - bc->drag_ptC_proj[Proj::Z] = 0.25; + this->drag_origin_proj = cur_persp->perspective_impl->tmat.preimage (button_dt, 0, Proj::Z); + this->drag_ptB_proj = this->drag_origin_proj; + this->drag_ptC_proj = this->drag_origin_proj; + this->drag_ptC_proj.normalize(); + this->drag_ptC_proj[Proj::Z] = 0.25; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | @@ -312,66 +267,67 @@ gint Box3DContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_MOTION_NOTIFY: - if ( dragging - && ( event->motion.state & GDK_BUTTON1_MASK ) && !event_context->space_panning) - { - if ( event_context->within_tolerance - && ( abs( (gint) event->motion.x - event_context->xp ) < event_context->tolerance ) - && ( abs( (gint) event->motion.y - event_context->yp ) < event_context->tolerance ) ) { + if (dragging && ( event->motion.state & GDK_BUTTON1_MASK ) && !this->space_panning) { + if ( this->within_tolerance + && ( abs( (gint) event->motion.x - this->xp ) < this->tolerance ) + && ( abs( (gint) event->motion.y - this->yp ) < this->tolerance ) ) { break; // do not drag if we're within tolerance from origin } // Once the user has moved farther than tolerance from the original location // (indicating they intend to draw, not click), then always process the // motion notify coordinates as given (no snapping back to origin) - event_context->within_tolerance = false; + this->within_tolerance = false; Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point motion_dt(desktop->w2d(motion_w)); SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop, true, bc->item); + m.setup(desktop, true, this->box3d); m.freeSnapReturnByRef(motion_dt, Inkscape::SNAPSOURCE_NODE_HANDLE); - bc->ctrl_dragged = event->motion.state & GDK_CONTROL_MASK; + this->ctrl_dragged = event->motion.state & GDK_CONTROL_MASK; - if (event->motion.state & GDK_SHIFT_MASK && !bc->extruded && bc->item) { - // once shift is pressed, set bc->extruded - bc->extruded = true; + if ((event->motion.state & GDK_SHIFT_MASK) && !this->extruded && this->box3d) { + // once shift is pressed, set this->extruded + this->extruded = true; } - if (!bc->extruded) { - bc->drag_ptB = motion_dt; - bc->drag_ptC = motion_dt; + if (!this->extruded) { + this->drag_ptB = motion_dt; + this->drag_ptC = motion_dt; - bc->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (motion_dt, 0, Proj::Z); - bc->drag_ptC_proj = bc->drag_ptB_proj; - bc->drag_ptC_proj.normalize(); - bc->drag_ptC_proj[Proj::Z] = 0.25; + this->drag_ptB_proj = cur_persp->perspective_impl->tmat.preimage (motion_dt, 0, Proj::Z); + this->drag_ptC_proj = this->drag_ptB_proj; + this->drag_ptC_proj.normalize(); + this->drag_ptC_proj[Proj::Z] = 0.25; } else { // Without Ctrl, motion of the extruded corner is constrained to the // perspective line from drag_ptB to vanishing point Y. - if (!bc->ctrl_dragged) { + if (!this->ctrl_dragged) { /* snapping */ - Box3D::PerspectiveLine pline (bc->drag_ptB, Proj::Z, document->getCurrentPersp3D()); - bc->drag_ptC = pline.closest_to (motion_dt); + Box3D::PerspectiveLine pline (this->drag_ptB, Proj::Z, document->getCurrentPersp3D()); + this->drag_ptC = pline.closest_to (motion_dt); - bc->drag_ptB_proj.normalize(); - bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (bc->drag_ptC, bc->drag_ptB_proj[Proj::X], Proj::X); + this->drag_ptB_proj.normalize(); + this->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (this->drag_ptC, this->drag_ptB_proj[Proj::X], Proj::X); } else { - bc->drag_ptC = motion_dt; + this->drag_ptC = motion_dt; - bc->drag_ptB_proj.normalize(); - bc->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (motion_dt, bc->drag_ptB_proj[Proj::X], Proj::X); + this->drag_ptB_proj.normalize(); + this->drag_ptC_proj = cur_persp->perspective_impl->tmat.preimage (motion_dt, this->drag_ptB_proj[Proj::X], Proj::X); } - m.freeSnapReturnByRef(bc->drag_ptC, Inkscape::SNAPSOURCE_NODE_HANDLE); + + m.freeSnapReturnByRef(this->drag_ptC, Inkscape::SNAPSOURCE_NODE_HANDLE); } + m.unSetup(); - sp_box3d_drag(*bc, event->motion.state); + this->drag(event->motion.state); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(bc)) { + } else if (!sp_event_context_knot_mouseover(this)) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); @@ -381,33 +337,36 @@ gint Box3DContext::root_handler(GdkEvent* event) { m.unSetup(); } break; + case GDK_BUTTON_RELEASE: - event_context->xp = event_context->yp = 0; - if ( event->button.button == 1 && !event_context->space_panning) { + this->xp = this->yp = 0; + + if (event->button.button == 1 && !this->space_panning) { dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); - if (!event_context->within_tolerance) { + if (!this->within_tolerance) { // we've been dragging, finish the box - sp_box3d_finish(bc); - } else if (event_context->item_to_select) { - // no dragging, select clicked item if any + this->finishItem(); + } else if (this->item_to_select) { + // no dragging, select clicked box3d if any if (event->button.state & GDK_SHIFT_MASK) { - selection->toggle(event_context->item_to_select); + selection->toggle(this->item_to_select); } else { - selection->set(event_context->item_to_select); + selection->set(this->item_to_select); } } else { // click in an empty space selection->clear(); } - event_context->item_to_select = NULL; + this->item_to_select = NULL; ret = TRUE; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); } break; + case GDK_KEY_PRESS: switch (get_group0_keyval (&event->key)) { case GDK_KEY_Up: @@ -495,9 +454,10 @@ gint Box3DContext::root_handler(GdkEvent* event) { desktop->setToolboxFocusTo ("altx-box3d"); ret = TRUE; } + if (MOD__SHIFT_ONLY) { persp3d_toggle_VPs(selection->perspList(), Proj::X); - bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically? + this->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically? ret = true; } break; @@ -506,7 +466,7 @@ gint Box3DContext::root_handler(GdkEvent* event) { case GDK_KEY_Y: if (MOD__SHIFT_ONLY) { persp3d_toggle_VPs(selection->perspList(), Proj::Y); - bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically? + this->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically? ret = true; } break; @@ -515,7 +475,7 @@ gint Box3DContext::root_handler(GdkEvent* event) { case GDK_KEY_Z: if (MOD__SHIFT_ONLY) { persp3d_toggle_VPs(selection->perspList(), Proj::Z); - bc->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically? + this->_vpdrag->updateLines(); // FIXME: Shouldn't this be done automatically? ret = true; } break; @@ -530,56 +490,50 @@ gint Box3DContext::root_handler(GdkEvent* event) { sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); dragging = false; - sp_event_context_discard_delayed_snap_event(event_context); - if (!event_context->within_tolerance) { + sp_event_context_discard_delayed_snap_event(this); + if (!this->within_tolerance) { // we've been dragging, finish the box - sp_box3d_finish(bc); + this->finishItem(); } // do not return true, so that space would work switching to selector } break; + case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY); break; default: break; } break; + default: break; } if (!ret) { -// if (((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler) { -// ret = ((SPEventContextClass *) sp_box3d_context_parent_class)->root_handler(event_context, event); -// } ret = SPEventContext::root_handler(event); } return ret; } -static void sp_box3d_drag(Box3DContext &bc, guint /*state*/) -{ - SPDesktop *desktop = bc.desktop; - - if (!bc.item) { - - if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) { +void Box3DContext::drag(guint state) { + if (!this->box3d) { + if (Inkscape::have_viable_layer(desktop, this->_message_context) == false) { return; } // Create object - SPBox3D *box3d = 0; - box3d = SPBox3D::createBox3D((SPItem *)desktop->currentLayer()); + SPBox3D *box3d = SPBox3D::createBox3D((SPItem*)desktop->currentLayer()); // Set style desktop->applyCurrentOrToolStyle(box3d, "/tools/shapes/3dbox", false); - bc.item = box3d; + this->box3d = box3d; // TODO: Incorporate this in box3d-side.cpp! for (int i = 0; i < 6; ++i) { @@ -599,13 +553,14 @@ static void sp_box3d_drag(Box3DContext &bc, guint /*state*/) Glib::ustring descr = "/desktop/"; descr += box3d_side_axes_string(side); descr += "/style"; + Glib::ustring cur_style = prefs->getString(descr); bool use_current = prefs->getBool("/tools/shapes/3dbox/usecurrent", false); + if (use_current && !cur_style.empty()) { // use last used style side->setAttribute("style", cur_style.data()); - } else { // use default style GString *pstring = g_string_new(""); @@ -616,71 +571,59 @@ static void sp_box3d_drag(Box3DContext &bc, guint /*state*/) side->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description } - box3d_set_z_orders(SP_BOX3D(bc.item)); - bc.item->updateRepr(); + box3d_set_z_orders(this->box3d); + this->box3d->updateRepr(); // TODO: It would be nice to show the VPs during dragging, but since there is no selection // at this point (only after finishing the box), we must do this "manually" - /* bc._vpdrag->updateDraggers(); */ + /* this._vpdrag->updateDraggers(); */ desktop->canvas->forceFullRedrawAfterInterruptions(5); } - g_assert(bc.item); - - SPBox3D *box = SP_BOX3D(bc.item); + g_assert(this->box3d); - box->orig_corner0 = bc.drag_origin_proj; - box->orig_corner7 = bc.drag_ptC_proj; + this->box3d->orig_corner0 = this->drag_origin_proj; + this->box3d->orig_corner7 = this->drag_ptC_proj; - box3d_check_for_swapped_coords(box); + box3d_check_for_swapped_coords(this->box3d); /* we need to call this from here (instead of from box3d_position_set(), for example) because z-order setting must not interfere with display updates during undo/redo */ - box3d_set_z_orders (box); + box3d_set_z_orders (this->box3d); - box3d_position_set(box); + box3d_position_set(this->box3d); // status text - bc._message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis")); + this->_message_context->setF(Inkscape::NORMAL_MESSAGE, _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis")); } -static void sp_box3d_finish(Box3DContext *bc) -{ - bc->_message_context->clear(); - bc->ctrl_dragged = false; - bc->extruded = false; +void Box3DContext::finishItem() { + this->_message_context->clear(); + this->ctrl_dragged = false; + this->extruded = false; - if ( bc->item != NULL ) { - SPDesktop * desktop = SP_EVENT_CONTEXT_DESKTOP(bc); - SPDocument *doc = sp_desktop_document(desktop); - if (!doc || !doc->getCurrentPersp3D()) - return; + if (this->box3d != NULL) { + SPDocument *doc = sp_desktop_document(this->desktop); - SPBox3D *box = SP_BOX3D(bc->item); + if (!doc || !doc->getCurrentPersp3D()) { + return; + } - box->orig_corner0 = bc->drag_origin_proj; - box->orig_corner7 = bc->drag_ptC_proj; + this->box3d->orig_corner0 = this->drag_origin_proj; + this->box3d->orig_corner7 = this->drag_ptC_proj; - box->updateRepr(); + this->box3d->updateRepr(); - box3d_relabel_corners(box); + box3d_relabel_corners(this->box3d); desktop->canvas->endForcedFullRedraws(); - sp_desktop_selection(desktop)->set(bc->item); + sp_desktop_selection(desktop)->set(this->box3d); DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_3DBOX, _("Create 3D box")); - bc->item = NULL; - } -} - -void sp_box3d_context_update_lines(SPEventContext *ec) { - /* update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */ - if (SP_IS_BOX3D_CONTEXT (ec)) { - Box3DContext *bc = SP_BOX3D_CONTEXT (ec); - bc->_vpdrag->updateLines(); + this->box3d = NULL; } } diff --git a/src/box3d-context.h b/src/box3d-context.h index 8fc230660..0c7630eb4 100644 --- a/src/box3d-context.h +++ b/src/box3d-context.h @@ -21,6 +21,8 @@ #include "proj_pt.h" #include "vanishing-point.h" +#include "box3d.h" + #define SP_BOX3D_CONTEXT(obj) ((Box3DContext*)obj) #define SP_IS_BOX3D_CONTEXT(obj) (dynamic_cast<const Box3DContext*>((const SPEventContext*)obj)) @@ -29,7 +31,19 @@ public: Box3DContext(); virtual ~Box3DContext(); - SPItem *item; + Box3D::VPDrag * _vpdrag; + + static const std::string prefsPath; + + virtual void setup(); + virtual void finish(); + virtual gint root_handler(GdkEvent* event); + virtual gint item_handler(SPItem* item, GdkEvent* event); + + virtual const std::string& getPrefsPath(); + +private: + SPBox3D* box3d; Geom::Point center; /** @@ -51,24 +65,16 @@ public: bool ctrl_dragged; /* whether we are ctrl-dragging */ bool extruded; /* whether shift-dragging already occured (i.e. the box is already extruded) */ - Box3D::VPDrag * _vpdrag; - sigc::connection sel_changed_connection; Inkscape::MessageContext *_message_context; - static const std::string prefsPath; - - virtual void setup(); - virtual void finish(); - virtual gint root_handler(GdkEvent* event); - virtual gint item_handler(SPItem* item, GdkEvent* event); + void selection_changed(Inkscape::Selection* selection); - virtual const std::string& getPrefsPath(); + void drag(guint state); + void finishItem(); }; -void sp_box3d_context_update_lines(SPEventContext *ec); - #endif /* __SP_BOX3D_CONTEXT_H__ */ /* diff --git a/src/common-context.cpp b/src/common-context.cpp index 4d2125f91..5ccbaaf5a 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -106,40 +106,40 @@ SPCommonContext::~SPCommonContext() { //G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } -void SPCommonContext::set(Inkscape::Preferences::Entry* value) { +void SPCommonContext::set(const Inkscape::Preferences::Entry& value) { SPEventContext* ec = this; SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); - Glib::ustring path = value->getEntryName(); + Glib::ustring path = value.getEntryName(); // ignore preset modifications static Glib::ustring const presets_path = ec->pref_observer->observed_path + "/preset"; - Glib::ustring const &full_path = value->getPath(); + Glib::ustring const &full_path = value.getPath(); if (full_path.compare(0, presets_path.size(), presets_path) == 0) return; if (path == "mass") { - ctx->mass = 0.01 * CLAMP(value->getInt(10), 0, 100); + ctx->mass = 0.01 * CLAMP(value.getInt(10), 0, 100); } else if (path == "wiggle") { - ctx->drag = CLAMP((1 - 0.01 * value->getInt()), + ctx->drag = CLAMP((1 - 0.01 * value.getInt()), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle } else if (path == "angle") { - ctx->angle = CLAMP(value->getDouble(), -90, 90); + ctx->angle = CLAMP(value.getDouble(), -90, 90); } else if (path == "width") { - ctx->width = 0.01 * CLAMP(value->getInt(10), 1, 100); + ctx->width = 0.01 * CLAMP(value.getInt(10), 1, 100); } else if (path == "thinning") { - ctx->vel_thin = 0.01 * CLAMP(value->getInt(10), -100, 100); + ctx->vel_thin = 0.01 * CLAMP(value.getInt(10), -100, 100); } else if (path == "tremor") { - ctx->tremor = 0.01 * CLAMP(value->getInt(), 0, 100); + ctx->tremor = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "flatness") { - ctx->flatness = 0.01 * CLAMP(value->getInt(), 0, 100); + ctx->flatness = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "usepressure") { - ctx->usepressure = value->getBool(); + ctx->usepressure = value.getBool(); } else if (path == "usetilt") { - ctx->usetilt = value->getBool(); + ctx->usetilt = value.getBool(); } else if (path == "abs_width") { - ctx->abs_width = value->getBool(); + ctx->abs_width = value.getBool(); } else if (path == "cap_rounding") { - ctx->cap_rounding = value->getDouble(); + ctx->cap_rounding = value.getDouble(); } } diff --git a/src/common-context.h b/src/common-context.h index d807c3f2f..ffcf8de38 100644 --- a/src/common-context.h +++ b/src/common-context.h @@ -96,7 +96,7 @@ public: /** uses absolute width independent of zoom */ bool abs_width; - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); }; #endif // COMMON_CONTEXT_H_SEEN diff --git a/src/connector-context.cpp b/src/connector-context.cpp index b7e3942b9..42bf6584b 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -306,19 +306,19 @@ void SPConnectorContext::setup() { dt->canvas->gen_all_enter_events = true; } -void SPConnectorContext::set(Inkscape::Preferences::Entry* val) { +void SPConnectorContext::set(const Inkscape::Preferences::Entry& val) { SPEventContext* ec = this; SPConnectorContext *cc = SP_CONNECTOR_CONTEXT(ec); /* fixme: Proper error handling for non-numeric data. Use a locale-independent function like * g_ascii_strtod (or a thin wrapper that does the right thing for invalid values inf/nan). */ - Glib::ustring name = val->getEntryName(); + Glib::ustring name = val.getEntryName(); if ( name == "curvature" ) { - cc->curvature = val->getDoubleLimited(); // prevents NaN and +/-Inf from messing up + cc->curvature = val.getDoubleLimited(); // prevents NaN and +/-Inf from messing up } else if ( name == "orthogonal" ) { - cc->isOrthogonal = val->getBool(); + cc->isOrthogonal = val.getBool(); } } diff --git a/src/connector-context.h b/src/connector-context.h index 1bc7b5a18..44f3cd3c0 100644 --- a/src/connector-context.h +++ b/src/connector-context.h @@ -98,7 +98,7 @@ public: virtual void setup(); virtual void finish(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual gint item_handler(SPItem* item, GdkEvent* event); diff --git a/src/desktop.cpp b/src/desktop.cpp index a9e608057..d999c780e 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -897,7 +897,10 @@ SPDesktop::set_display_area (double x0, double y0, double x1, double y1, double canvas->scrollTo(x0 * newscale - border, y1 * -newscale - border, clear); /* update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */ - sp_box3d_context_update_lines(event_context); + //sp_box3d_context_update_lines(event_context); + if (SP_IS_BOX3D_CONTEXT(event_context)) { + SP_BOX3D_CONTEXT(event_context)->_vpdrag->updateLines(); + } _widget->updateRulers(); _widget->updateScrollbars(_d2w.descrim()); @@ -1218,7 +1221,10 @@ SPDesktop::scroll_world (double dx, double dy, bool is_scrolling) canvas->scrollTo(viewbox.min()[Geom::X] - dx, viewbox.min()[Geom::Y] - dy, FALSE, is_scrolling); /* update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */ - sp_box3d_context_update_lines(event_context); + //sp_box3d_context_update_lines(event_context); + if (SP_IS_BOX3D_CONTEXT(event_context)) { + SP_BOX3D_CONTEXT(event_context)->_vpdrag->updateLines(); + } _widget->updateRulers(); _widget->updateScrollbars(_d2w.descrim()); diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 39cb3d613..244a16c91 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -189,7 +189,7 @@ void SPDrawContext::finish() { spdc_free_colors(dc); } -void SPDrawContext::set(Inkscape::Preferences::Entry* value) { +void SPDrawContext::set(const Inkscape::Preferences::Entry& value) { } gint SPDrawContext::root_handler(GdkEvent* event) { diff --git a/src/draw-context.h b/src/draw-context.h index 4bc61461a..af21d7ec3 100644 --- a/src/draw-context.h +++ b/src/draw-context.h @@ -82,7 +82,7 @@ public: virtual void setup(); virtual void finish(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); }; diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index 0e9ed570c..233c27f10 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -222,16 +222,16 @@ void SPDynaDrawContext::setup() { } } -void SPDynaDrawContext::set(Inkscape::Preferences::Entry* val) { +void SPDynaDrawContext::set(const Inkscape::Preferences::Entry& val) { SPEventContext* ec = this; SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); - Glib::ustring path = val->getEntryName(); + Glib::ustring path = val.getEntryName(); if (path == "tracebackground") { - ddc->trace_bg = val->getBool(); + ddc->trace_bg = val.getBool(); } else if (path == "keep_selected") { - ddc->keep_selected = val->getBool(); + ddc->keep_selected = val.getBool(); } else { //pass on up to parent class to handle common attributes. // if ( SP_COMMON_CONTEXT_CLASS(sp_dyna_draw_context_parent_class)->set ) { diff --git a/src/dyna-draw-context.h b/src/dyna-draw-context.h index 3b4af3dbc..cfb6b2b12 100644 --- a/src/dyna-draw-context.h +++ b/src/dyna-draw-context.h @@ -58,7 +58,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp index f256dd8ef..d84f6cfaa 100644 --- a/src/eraser-context.cpp +++ b/src/eraser-context.cpp @@ -112,37 +112,30 @@ const std::string& SPEraserContext::getPrefsPath() { const std::string SPEraserContext::prefsPath = "/tools/eraser"; SPEraserContext::SPEraserContext() : SPCommonContext() { - SPEraserContext* erc = this; - - erc->cursor_shape = cursor_eraser_xpm; - erc->hot_x = 4; - erc->hot_y = 4; + this->cursor_shape = cursor_eraser_xpm; + this->hot_x = 4; + this->hot_y = 4; } SPEraserContext::~SPEraserContext() { } void SPEraserContext::setup() { - SPEventContext* ec = this; + SPCommonContext::setup(); - SPEraserContext *erc = SP_ERASER_CONTEXT(ec); - SPDesktop *desktop = ec->desktop; + this->accumulated = new SPCurve(); + this->currentcurve = new SPCurve(); -// if ((SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->setup) -// (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->setup(ec); - SPCommonContext::setup(); + this->cal1 = new SPCurve(); + this->cal2 = new SPCurve(); - erc->accumulated = new SPCurve(); - erc->currentcurve = new SPCurve(); + this->currentshape = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); - erc->cal1 = new SPCurve(); - erc->cal2 = new SPCurve(); + sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(this->currentshape), ERC_RED_RGBA, SP_WIND_RULE_EVENODD); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->currentshape), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - erc->currentshape = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(erc->currentshape), ERC_RED_RGBA, SP_WIND_RULE_EVENODD); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(erc->currentshape), 0x00000000, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); /* fixme: Cannot we cascade it to root more clearly? */ - g_signal_connect(G_OBJECT(erc->currentshape), "event", G_CALLBACK(sp_desktop_root_handler), desktop); + g_signal_connect(G_OBJECT(this->currentshape), "event", G_CALLBACK(sp_desktop_root_handler), desktop); /* static ProfileFloatElement f_profile[PROFILE_FLOAT_SIZE] = { @@ -156,30 +149,30 @@ static ProfileFloatElement f_profile[PROFILE_FLOAT_SIZE] = { }; */ - sp_event_context_read(ec, "mass"); - sp_event_context_read(ec, "wiggle"); - sp_event_context_read(ec, "angle"); - sp_event_context_read(ec, "width"); - sp_event_context_read(ec, "thinning"); - sp_event_context_read(ec, "tremor"); - sp_event_context_read(ec, "flatness"); - sp_event_context_read(ec, "tracebackground"); - sp_event_context_read(ec, "usepressure"); - sp_event_context_read(ec, "usetilt"); - sp_event_context_read(ec, "abs_width"); - sp_event_context_read(ec, "cap_rounding"); + sp_event_context_read(this, "mass"); + sp_event_context_read(this, "wiggle"); + sp_event_context_read(this, "angle"); + sp_event_context_read(this, "width"); + sp_event_context_read(this, "thinning"); + sp_event_context_read(this, "tremor"); + sp_event_context_read(this, "flatness"); + sp_event_context_read(this, "tracebackground"); + sp_event_context_read(this, "usepressure"); + sp_event_context_read(this, "usetilt"); + sp_event_context_read(this, "abs_width"); + sp_event_context_read(this, "cap_rounding"); - erc->is_drawing = false; + this->is_drawing = false; - erc->_message_context = new Inkscape::MessageContext(desktop->messageStack()); + this->_message_context = new Inkscape::MessageContext(desktop->messageStack()); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/eraser/selcue", 0) != 0) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } -// TODO temp force: - ec->enableSelectionCue(); + // TODO temp force: + this->enableSelectionCue(); } static double @@ -425,37 +418,33 @@ eraser_cancel(SPEraserContext *dc) } gint SPEraserContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this; - - SPEraserContext *dc = SP_ERASER_CONTEXT(event_context); - SPDesktop *desktop = event_context->desktop; - gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - if (event->button.button == 1 && !event_context->space_panning) { - - if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) { + if (event->button.button == 1 && !this->space_panning) { + if (Inkscape::have_viable_layer(desktop, this->_message_context) == false) { return TRUE; } - Geom::Point const button_w(event->button.x, - event->button.y); + Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - sp_eraser_reset(dc, button_dt); - sp_eraser_extinput(dc, event); - sp_eraser_apply(dc, button_dt); - dc->accumulated->reset(); - if (dc->repr) { - dc->repr = NULL; + + sp_eraser_reset(this, button_dt); + sp_eraser_extinput(this, event); + sp_eraser_apply(this, button_dt); + + this->accumulated->reset(); + + if (this->repr) { + this->repr = NULL; } Inkscape::Rubberband::get(desktop)->start(desktop, button_dt); Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH); /* initialize first point */ - dc->npoints = 0; + this->npoints = 0; sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), ( GDK_KEY_PRESS_MASK | @@ -468,76 +457,77 @@ gint SPEraserContext::root_handler(GdkEvent* event) { ret = TRUE; desktop->canvas->forceFullRedrawAfterInterruptions(3); - dc->is_drawing = true; + this->is_drawing = true; } break; - case GDK_MOTION_NOTIFY: - { - Geom::Point const motion_w(event->motion.x, - event->motion.y); - Geom::Point motion_dt(desktop->w2d(motion_w)); - sp_eraser_extinput(dc, event); - dc->_message_context->clear(); + case GDK_MOTION_NOTIFY: { + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point motion_dt(desktop->w2d(motion_w) + ); + sp_eraser_extinput(this, event); - if ( dc->is_drawing && (event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { - dc->dragging = TRUE; + this->_message_context->clear(); - dc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drawing</b> an eraser stroke")); + if ( this->is_drawing && (event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { + this->dragging = TRUE; - if (!sp_eraser_apply(dc, motion_dt)) { + this->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drawing</b> an eraser stroke")); + + if (!sp_eraser_apply(this, motion_dt)) { ret = TRUE; break; } - if ( dc->cur != dc->last ) { - sp_eraser_brush(dc); - g_assert( dc->npoints > 0 ); - fit_and_split(dc, FALSE); + if ( this->cur != this->last ) { + sp_eraser_brush(this); + g_assert( this->npoints > 0 ); + fit_and_split(this, FALSE); } + ret = TRUE; } + Inkscape::Rubberband::get(desktop)->move(motion_dt); } break; - - case GDK_BUTTON_RELEASE: - { + case GDK_BUTTON_RELEASE: { Geom::Point const motion_w(event->button.x, event->button.y); Geom::Point const motion_dt(desktop->w2d(motion_w)); sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); desktop->canvas->endForcedFullRedraws(); - dc->is_drawing = false; + this->is_drawing = false; - if (dc->dragging && event->button.button == 1 && !event_context->space_panning) { - dc->dragging = FALSE; + if (this->dragging && event->button.button == 1 && !this->space_panning) { + this->dragging = FALSE; - sp_eraser_apply(dc, motion_dt); + sp_eraser_apply(this, motion_dt); /* Remove all temporary line segments */ - while (dc->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(dc->segments->data)); - dc->segments = g_slist_remove(dc->segments, dc->segments->data); + while (this->segments) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); + this->segments = g_slist_remove(this->segments, this->segments->data); } /* Create object */ - fit_and_split(dc, TRUE); - accumulate_eraser(dc); - set_to_accumulated(dc); // performs document_done + fit_and_split(this, TRUE); + accumulate_eraser(this); + set_to_accumulated(this); // performs document_done /* reset accumulated curve */ - dc->accumulated->reset(); + this->accumulated->reset(); - clear_current(dc); - if (dc->repr) { - dc->repr = NULL; + clear_current(this); + if (this->repr) { + this->repr = NULL; } - dc->_message_context->clear(); + this->_message_context->clear(); ret = TRUE; } + if (Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::Rubberband::get(desktop)->stop(); } @@ -550,55 +540,73 @@ gint SPEraserContext::root_handler(GdkEvent* event) { case GDK_KEY_Up: case GDK_KEY_KP_Up: if (!MOD__CTRL_ONLY) { - dc->angle += 5.0; - if (dc->angle > 90.0) - dc->angle = 90.0; - sp_erc_update_toolbox (desktop, "eraser-angle", dc->angle); + this->angle += 5.0; + + if (this->angle > 90.0) { + this->angle = 90.0; + } + + sp_erc_update_toolbox (desktop, "eraser-angle", this->angle); ret = TRUE; } break; + case GDK_KEY_Down: case GDK_KEY_KP_Down: if (!MOD__CTRL_ONLY) { - dc->angle -= 5.0; - if (dc->angle < -90.0) - dc->angle = -90.0; - sp_erc_update_toolbox (desktop, "eraser-angle", dc->angle); + this->angle -= 5.0; + + if (this->angle < -90.0) { + this->angle = -90.0; + } + + sp_erc_update_toolbox (desktop, "eraser-angle", this->angle); ret = TRUE; } break; + case GDK_KEY_Right: case GDK_KEY_KP_Right: if (!MOD__CTRL_ONLY) { - dc->width += 0.01; - if (dc->width > 1.0) - dc->width = 1.0; - sp_erc_update_toolbox (desktop, "altx-eraser", dc->width * 100); // the same spinbutton is for alt+x + this->width += 0.01; + + if (this->width > 1.0) { + this->width = 1.0; + } + + sp_erc_update_toolbox (desktop, "altx-eraser", this->width * 100); // the same spinbutton is for alt+x ret = TRUE; } break; + case GDK_KEY_Left: case GDK_KEY_KP_Left: if (!MOD__CTRL_ONLY) { - dc->width -= 0.01; - if (dc->width < 0.01) - dc->width = 0.01; - sp_erc_update_toolbox (desktop, "altx-eraser", dc->width * 100); + this->width -= 0.01; + + if (this->width < 0.01) { + this->width = 0.01; + } + + sp_erc_update_toolbox (desktop, "altx-eraser", this->width * 100); ret = TRUE; } break; + case GDK_KEY_Home: case GDK_KEY_KP_Home: - dc->width = 0.01; - sp_erc_update_toolbox (desktop, "altx-eraser", dc->width * 100); + this->width = 0.01; + sp_erc_update_toolbox (desktop, "altx-eraser", this->width * 100); ret = TRUE; break; + case GDK_KEY_End: case GDK_KEY_KP_End: - dc->width = 1.0; - sp_erc_update_toolbox (desktop, "altx-eraser", dc->width * 100); + this->width = 1.0; + sp_erc_update_toolbox (desktop, "altx-eraser", this->width * 100); ret = TRUE; break; + case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY) { @@ -606,22 +614,26 @@ gint SPEraserContext::root_handler(GdkEvent* event) { ret = TRUE; } break; + case GDK_KEY_Escape: Inkscape::Rubberband::get(desktop)->stop(); - if (dc->is_drawing) { + + if (this->is_drawing) { // if drawing, cancel, otherwise pass it up for deselecting - eraser_cancel (dc); + eraser_cancel (this); ret = TRUE; } break; + case GDK_KEY_z: case GDK_KEY_Z: - if (MOD__CTRL_ONLY && dc->is_drawing) { + if (MOD__CTRL_ONLY && this->is_drawing) { // if drawing, cancel, otherwise pass it up for undo - eraser_cancel (dc); + eraser_cancel (this); ret = TRUE; } break; + default: break; } @@ -631,20 +643,19 @@ gint SPEraserContext::root_handler(GdkEvent* event) { switch (get_group0_keyval(&event->key)) { case GDK_KEY_Control_L: case GDK_KEY_Control_R: - dc->_message_context->clear(); + this->_message_context->clear(); break; + default: break; } + break; default: break; } if (!ret) { -// if ((SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->root_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(sp_eraser_context_parent_class))->root_handler(event_context, event); -// } ret = SPCommonContext::root_handler(event); } @@ -685,9 +696,11 @@ set_to_accumulated(SPEraserContext *dc) SPItem *item=SP_ITEM(desktop->currentLayer()->appendChildRepr(dc->repr)); Inkscape::GC::release(dc->repr); + item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); item->updateRepr(); } + Geom::PathVector pathv = dc->accumulated->get_pathvector() * desktop->dt2doc(); gchar *str = sp_svg_write_path(pathv); g_assert( str != NULL ); @@ -707,6 +720,7 @@ set_to_accumulated(SPEraserContext *dc) Geom::Rect bounds = (*eraserBbox) * desktop->doc2dt(); std::vector<SPItem*> remainingItems; GSList* toWorkOn = 0; + if (selection->isEmpty()) { if ( eraserMode ) { toWorkOn = sp_desktop_document(desktop)->getItemsPartiallyInBox(desktop->dkey, bounds); @@ -714,6 +728,7 @@ set_to_accumulated(SPEraserContext *dc) Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); toWorkOn = sp_desktop_document(desktop)->getItemsAtPoints(desktop->dkey, r->getPoints()); } + toWorkOn = g_slist_remove( toWorkOn, acid ); } else { toWorkOn = g_slist_copy(const_cast<GSList*>(selection->itemList())); @@ -724,8 +739,10 @@ set_to_accumulated(SPEraserContext *dc) if ( eraserMode ) { for (GSList *i = toWorkOn ; i ; i = i->next ) { SPItem *item = SP_ITEM(i->data); + if ( eraserMode ) { Geom::OptRect bbox = item->visualBounds(); + if (bbox && bbox->intersects(*eraserBbox)) { Inkscape::XML::Node* dup = dc->repr->duplicate(xml_doc); dc->repr->parent()->appendChild(dup); @@ -735,12 +752,15 @@ set_to_accumulated(SPEraserContext *dc) selection->add(dup); sp_selected_path_diff_skip_undo(desktop); workDone = true; // TODO set this only if something was cut. + if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. GSList *nowSel = g_slist_copy(const_cast<GSList *>(selection->itemList())); + for (GSList const *i2 = nowSel ; i2 ; i2 = i2->next ) { remainingItems.push_back(SP_ITEM(i2->data)); } + g_slist_free(nowSel); } } else { @@ -752,6 +772,7 @@ set_to_accumulated(SPEraserContext *dc) for (GSList *i = toWorkOn ; i ; i = i->next ) { sp_object_ref( SP_ITEM(i->data), 0 ); } + for (GSList *i = toWorkOn ; i ; i = i->next ) { SPItem *item = SP_ITEM(i->data); item->deleteObject(true); @@ -768,6 +789,7 @@ set_to_accumulated(SPEraserContext *dc) } selection->clear(); + if ( wasSelection ) { if ( !remainingItems.empty() ) { selection->add(remainingItems.begin(), remainingItems.end()); @@ -788,8 +810,7 @@ set_to_accumulated(SPEraserContext *dc) if ( workDone ) { - DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ERASER, - _("Draw eraser stroke")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); } else { DocumentUndo::cancel(sp_desktop_document(desktop)); } @@ -806,6 +827,7 @@ add_cap(SPCurve *curve, Geom::Point v_in = from - pre; double mag_in = Geom::L2(v_in); + if ( mag_in > ERASER_EPSILON ) { v_in = mag * v_in / mag_in; } else { @@ -814,6 +836,7 @@ add_cap(SPCurve *curve, Geom::Point v_out = to - post; double mag_out = Geom::L2(v_out); + if ( mag_out > ERASER_EPSILON ) { v_out = mag * v_out / mag_out; } else { @@ -841,6 +864,7 @@ accumulate_eraser(SPEraserContext *dc) Geom::CubicBezier const * rev_cal2_firstseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->first_segment() ); Geom::CubicBezier const * dc_cal1_lastseg = dynamic_cast<Geom::CubicBezier const *>( dc->cal1->last_segment() ); Geom::CubicBezier const * rev_cal2_lastseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->last_segment() ); + g_assert( dc_cal1_firstseg ); g_assert( rev_cal2_firstseg ); g_assert( dc_cal1_lastseg ); @@ -904,13 +928,11 @@ fit_and_split(SPEraserContext *dc, gboolean release) } Geom::Point b1[BEZIER_MAX_LENGTH]; - gint const nb1 = Geom::bezier_fit_cubic_r(b1, dc->point1, dc->npoints, - tolerance_sq, BEZIER_MAX_BEZIERS); + gint const nb1 = Geom::bezier_fit_cubic_r(b1, dc->point1, dc->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); g_assert( nb1 * BEZIER_SIZE <= gint(G_N_ELEMENTS(b1)) ); Geom::Point b2[BEZIER_MAX_LENGTH]; - gint const nb2 = Geom::bezier_fit_cubic_r(b2, dc->point2, dc->npoints, - tolerance_sq, BEZIER_MAX_BEZIERS); + gint const nb2 = Geom::bezier_fit_cubic_r(b2, dc->point2, dc->npoints, tolerance_sq, BEZIER_MAX_BEZIERS); g_assert( nb2 * BEZIER_SIZE <= gint(G_N_ELEMENTS(b2)) ); if ( nb1 != -1 && nb2 != -1 ) { @@ -918,22 +940,27 @@ fit_and_split(SPEraserContext *dc, gboolean release) #ifdef ERASER_VERBOSE g_print("nb1:%d nb2:%d\n", nb1, nb2); #endif + /* CanvasShape */ if (! release) { dc->currentcurve->reset(); dc->currentcurve->moveto(b1[0]); + for (Geom::Point *bp1 = b1; bp1 < b1 + BEZIER_SIZE * nb1; bp1 += BEZIER_SIZE) { - dc->currentcurve->curveto(bp1[1], - bp1[2], bp1[3]); + dc->currentcurve->curveto(bp1[1], bp1[2], bp1[3]); } + dc->currentcurve->lineto(b2[BEZIER_SIZE*(nb2-1) + 3]); + for (Geom::Point *bp2 = b2 + BEZIER_SIZE * ( nb2 - 1 ); bp2 >= b2; bp2 -= BEZIER_SIZE) { dc->currentcurve->curveto(bp2[2], bp2[1], bp2[0]); } + // FIXME: dc->segments is always NULL at this point?? if (!dc->segments) { // first segment add_cap(dc->currentcurve, b2[1], b2[0], b1[0], b1[1], dc->cap_rounding); } + dc->currentcurve->closepath(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(dc->currentshape), dc->currentcurve); } @@ -942,6 +969,7 @@ fit_and_split(SPEraserContext *dc, gboolean release) for (Geom::Point *bp1 = b1; bp1 < b1 + BEZIER_SIZE * nb1; bp1 += BEZIER_SIZE) { dc->cal1->curveto(bp1[1], bp1[2], bp1[3]); } + for (Geom::Point *bp2 = b2; bp2 < b2 + BEZIER_SIZE * nb2; bp2 += BEZIER_SIZE) { dc->cal2->curveto(bp2[1], bp2[2], bp2[3]); } @@ -955,6 +983,7 @@ fit_and_split(SPEraserContext *dc, gboolean release) for (gint i = 1; i < dc->npoints; i++) { dc->cal1->lineto(dc->point1[i]); } + for (gint i = 1; i < dc->npoints; i++) { dc->cal2->lineto(dc->point2[i]); } @@ -969,9 +998,7 @@ fit_and_split(SPEraserContext *dc, gboolean release) gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; g_assert(!dc->currentcurve->is_empty()); - SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(desktop), - SP_TYPE_CANVAS_BPATH, - NULL); + SPCanvasItem *cbp = sp_canvas_item_new(sp_desktop_sketch(desktop), SP_TYPE_CANVAS_BPATH, NULL); SPCurve *curve = dc->currentcurve->copy(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve); curve->unref(); @@ -1010,12 +1037,15 @@ draw_temporary_box(SPEraserContext *dc) dc->currentcurve->reset(); dc->currentcurve->moveto(dc->point1[dc->npoints-1]); + for (gint i = dc->npoints-2; i >= 0; i--) { dc->currentcurve->lineto(dc->point1[i]); } + for (gint i = 0; i < dc->npoints; i++) { dc->currentcurve->lineto(dc->point2[i]); } + if (dc->npoints >= 2) { add_cap(dc->currentcurve, dc->point2[dc->npoints-2], dc->point2[dc->npoints-1], dc->point1[dc->npoints-1], dc->point1[dc->npoints-2], dc->cap_rounding); } diff --git a/src/event-context.cpp b/src/event-context.cpp index 75d156a38..622936fdb 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -73,7 +73,7 @@ static guint32 scroll_event_time = 0; static gdouble scroll_multiply = 1; static guint scroll_keyval = 0; -void SPEventContext::set(Inkscape::Preferences::Entry* val) { +void SPEventContext::set(const Inkscape::Preferences::Entry& val) { } void SPEventContext::activate() { @@ -1019,7 +1019,7 @@ void sp_event_context_read(SPEventContext *ec, gchar const *key) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::Preferences::Entry val = prefs->getEntry(ec->pref_observer->observed_path + '/' + key); - ec->set(&val); + ec->set(val); } /** diff --git a/src/event-context.h b/src/event-context.h index d7db70104..15cab4bf0 100644 --- a/src/event-context.h +++ b/src/event-context.h @@ -108,9 +108,6 @@ public: SPEventContext(); virtual ~SPEventContext(); - /// Desktop eventcontext stack - //SPEventContext *next; - //unsigned key; SPDesktop *desktop; Inkscape::Preferences::Observer *pref_observer; gchar const *const *cursor_shape; @@ -142,13 +139,11 @@ public: DelayedSnapEvent *_delayed_snap_event; bool _dse_callback_in_process; - //char const * tool_url; ///< the (preferences) url for the tool (if a subclass corresponding to a tool is used) - virtual void setup(); virtual void finish(); // Is called by our pref_observer if a preference has been changed. - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual void activate(); virtual void deactivate(); @@ -158,6 +153,23 @@ public: virtual const std::string& getPrefsPath() = 0; + /** + * An observer that relays pref changes to the derived classes. + */ + class ToolPrefObserver: public Inkscape::Preferences::Observer { + public: + ToolPrefObserver(Glib::ustring const &path, SPEventContext *ec) : + Inkscape::Preferences::Observer(path), ec(ec) { + } + + virtual void notify(Inkscape::Preferences::Entry const &val) { + ec->set(val); + } + + private: + SPEventContext * const ec; + }; + private: SPEventContext(const SPEventContext&); SPEventContext& operator=(const SPEventContext&); @@ -205,24 +217,6 @@ void ec_shape_event_attr_changed(Inkscape::XML::Node *shape_repr, void event_context_print_event_info(GdkEvent *event, bool print_return = true); - -/** - * An observer that relays pref changes to the derived classes. - */ -class ToolPrefObserver: public Inkscape::Preferences::Observer { -public: - ToolPrefObserver(Glib::ustring const &path, SPEventContext *ec) : - Inkscape::Preferences::Observer(path), ec(ec) { - } - - virtual void notify(Inkscape::Preferences::Entry const &val) { - ec->set(const_cast<Inkscape::Preferences::Entry*>(&val)); - } - -private: - SPEventContext * const ec; -}; - #endif // SEEN_SP_EVENT_CONTEXT_H diff --git a/src/fixes.cpp b/src/fixes.cpp deleted file mode 100644 index 4aed2c313..000000000 --- a/src/fixes.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * - * This is the header file to include to fix any broken definitions or funcs - * - * $Id$ - * - * 2004 Kees Cook - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -//#if defined(g_ascii_strtod) -#if 0 -/* - * until 2004-04-22, g_ascii_strtod could not handle having a locale-based - * decimal separator immediately following the number ("5,4" would - * parse to "5,4" instead of "5.0" in fr_FR) - * - * This is the corrected function, lifted from 1.107 gstrfuncs.c in glib - */ -extern "C" { -#include <glib.h> -#include <locale.h> -#include <string.h> -#include <errno.h> -#include <stdlib.h> - -gdouble -fixed_g_ascii_strtod (const gchar *nptr, - gchar **endptr) -{ - gchar *fail_pos; - gdouble val; - struct lconv *locale_data; - const char *decimal_point; - int decimal_point_len; - const char *p, *decimal_point_pos; - const char *end = NULL; /* Silence gcc */ - - g_return_val_if_fail (nptr != NULL, 0); - - fail_pos = NULL; - - locale_data = localeconv (); - decimal_point = locale_data->decimal_point; - decimal_point_len = strlen (decimal_point); - - g_assert (decimal_point_len != 0); - - decimal_point_pos = NULL; - if (decimal_point[0] != '.' || - decimal_point[1] != 0) - { - p = nptr; - /* Skip leading space */ - while (g_ascii_isspace (*p)) - p++; - - /* Skip leading optional sign */ - if (*p == '+' || *p == '-') - p++; - - if (p[0] == '0' && - (p[1] == 'x' || p[1] == 'X')) - { - p += 2; - /* HEX - find the (optional) decimal point */ - - while (g_ascii_isxdigit (*p)) - p++; - - if (*p == '.') - { - decimal_point_pos = p++; - - while (g_ascii_isxdigit (*p)) - p++; - - if (*p == 'p' || *p == 'P') - p++; - if (*p == '+' || *p == '-') - p++; - while (g_ascii_isdigit (*p)) - p++; - } - } - else - { - while (g_ascii_isdigit (*p)) - p++; - - if (*p == '.') - { - decimal_point_pos = p++; - - while (g_ascii_isdigit (*p)) - p++; - - if (*p == 'e' || *p == 'E') - p++; - if (*p == '+' || *p == '-') - p++; - while (g_ascii_isdigit (*p)) - p++; - } - } - /* For the other cases, we need not convert the decimal point */ - end = p; - } - - /* Set errno to zero, so that we can distinguish zero results - and underflows */ - errno = 0; - - if (decimal_point_pos) - { - char *copy, *c; - - /* We need to convert the '.' to the locale specific decimal point */ - copy = (char*)g_malloc (end - nptr + 1 + decimal_point_len); - - c = copy; - memcpy (c, nptr, decimal_point_pos - nptr); - c += decimal_point_pos - nptr; - memcpy (c, decimal_point, decimal_point_len); - c += decimal_point_len; - memcpy (c, decimal_point_pos + 1, end - (decimal_point_pos + 1)); - c += end - (decimal_point_pos + 1); - *c = 0; - - val = strtod (copy, &fail_pos); - - if (fail_pos) - { - if (fail_pos - copy > decimal_point_pos - nptr) - fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1); - else - fail_pos = (char *)nptr + (fail_pos - copy); - } - - g_free (copy); - - } - else if (decimal_point[0] != '.' || - decimal_point[1] != 0) - { - char *copy; - - copy = (char*)g_malloc (end - (char *)nptr + 1); - memcpy (copy, nptr, end - nptr); - *(copy + (end - (char *)nptr)) = 0; - - val = strtod (copy, &fail_pos); - - if (fail_pos) - { - fail_pos = (char *)nptr + (fail_pos - copy); - } - - g_free (copy); - } - else - { - val = strtod (nptr, &fail_pos); - } - - if (endptr) - *endptr = fail_pos; - - return val; -} -} - -#endif /* BROKEN_G_ASCII_STRTOD */ - - diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index e519619f9..bce2fb800 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -166,10 +166,10 @@ void sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpoint lc->shape_editor->set_item(item, SH_KNOTHOLDER); } -void SPLPEToolContext::set(Inkscape::Preferences::Entry* val) { +void SPLPEToolContext::set(const Inkscape::Preferences::Entry& val) { SPEventContext* ec = this; - if (val->getEntryName() == "mode") { + if (val.getEntryName() == "mode") { Inkscape::Preferences::get()->setString("/tools/geometric/mode", "drag"); SP_PEN_CONTEXT(ec)->mode = SP_PEN_CONTEXT_MODE_DRAG; } diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h index c7c50c28e..18eaedf69 100644 --- a/src/lpe-tool-context.h +++ b/src/lpe-tool-context.h @@ -61,7 +61,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual gint item_handler(SPItem* item, GdkEvent* event); diff --git a/src/memeq.h b/src/memeq.h deleted file mode 100644 index ebccc3c9e..000000000 --- a/src/memeq.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef INKSCAPE_MEMEQ_H -#define INKSCAPE_MEMEQ_H - -#include <cstring> - -/** Convenience/readability wrapper for memcmp(a,b,n)==0. */ -inline bool -memeq(void const *a, void const *b, size_t n) -{ - return std::memcmp(a, b, n) == 0; -} - - -#endif /* !INKSCAPE_MEMEQ_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 177aeaca9..00f7294be 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -234,14 +234,14 @@ void SPPenContext::finish() { /** * Callback that sets key to value in pen context. */ -void SPPenContext::set(Inkscape::Preferences::Entry* val) { +void SPPenContext::set(const Inkscape::Preferences::Entry& val) { SPEventContext* ec = this; SPPenContext *pc = SP_PEN_CONTEXT(ec); - Glib::ustring name = val->getEntryName(); + Glib::ustring name = val.getEntryName(); if (name == "mode") { - if ( val->getString() == "drag" ) { + if ( val.getString() == "drag" ) { pc->mode = SP_PEN_CONTEXT_MODE_DRAG; } else { pc->mode = SP_PEN_CONTEXT_MODE_CLICK; diff --git a/src/pen-context.h b/src/pen-context.h index 6ae31eab0..a5f87507c 100644 --- a/src/pen-context.h +++ b/src/pen-context.h @@ -62,7 +62,7 @@ public: virtual void setup(); virtual void finish(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual gint item_handler(SPItem* item, GdkEvent* event); diff --git a/src/rect-context.cpp b/src/rect-context.cpp index e6c3cfdd9..42e6c4452 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -150,15 +150,15 @@ void SPRectContext::setup() { this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } -void SPRectContext::set(Inkscape::Preferences::Entry* val) { +void SPRectContext::set(const Inkscape::Preferences::Entry& val) { /* fixme: Proper error handling for non-numeric data. Use a locale-independent function like * g_ascii_strtod (or a thin wrapper that does the right thing for invalid values inf/nan). */ - Glib::ustring name = val->getEntryName(); + Glib::ustring name = val.getEntryName(); if ( name == "rx" ) { - this->rx = val->getDoubleLimited(); // prevents NaN and +/-Inf from messing up + this->rx = val.getDoubleLimited(); // prevents NaN and +/-Inf from messing up } else if ( name == "ry" ) { - this->ry = val->getDoubleLimited(); + this->ry = val.getDoubleLimited(); } } diff --git a/src/rect-context.h b/src/rect-context.h index ae7bc4f3f..ab65a3b7a 100644 --- a/src/rect-context.h +++ b/src/rect-context.h @@ -33,7 +33,7 @@ public: virtual void setup(); virtual void finish(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual gint item_handler(SPItem* item, GdkEvent* event); diff --git a/src/select-context.cpp b/src/select-context.cpp index a347bcd9e..365d2f905 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -171,11 +171,11 @@ void SPSelectContext::setup() { } } -void SPSelectContext::set(Inkscape::Preferences::Entry* val) { - Glib::ustring path = val->getEntryName(); +void SPSelectContext::set(const Inkscape::Preferences::Entry& val) { + Glib::ustring path = val.getEntryName(); if (path == "show") { - if (val->getString() == "outline") { + if (val.getString() == "outline") { this->_seltrans->setShow(Inkscape::SelTrans::SHOW_OUTLINE); } else { this->_seltrans->setShow(Inkscape::SelTrans::SHOW_CONTENT); diff --git a/src/select-context.h b/src/select-context.h index 0efd0839c..2f9406a8c 100644 --- a/src/select-context.h +++ b/src/select-context.h @@ -51,7 +51,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual gint item_handler(SPItem* item, GdkEvent* event); diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index f9c5c3a17..70109a3a7 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -151,15 +151,15 @@ void SPSpiralContext::setup() { this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } -void SPSpiralContext::set(Inkscape::Preferences::Entry* val) { - Glib::ustring name = val->getEntryName(); +void SPSpiralContext::set(const Inkscape::Preferences::Entry& val) { + Glib::ustring name = val.getEntryName(); if (name == "expansion") { - this->exp = CLAMP(val->getDouble(), 0.0, 1000.0); + this->exp = CLAMP(val.getDouble(), 0.0, 1000.0); } else if (name == "revolution") { - this->revo = CLAMP(val->getDouble(3.0), 0.05, 40.0); + this->revo = CLAMP(val.getDouble(3.0), 0.05, 40.0); } else if (name == "t0") { - this->t0 = CLAMP(val->getDouble(), 0.0, 0.999); + this->t0 = CLAMP(val.getDouble(), 0.0, 0.999); } } @@ -390,19 +390,17 @@ void SPSpiralContext::drag(Geom::Point const &p, guint state) { Geom::Point const p0 = desktop->dt2doc(this->center); Geom::Point const p1 = desktop->dt2doc(pt2g); - SPSpiral *spiral = SP_SPIRAL(this->spiral); - Geom::Point const delta = p1 - p0; gdouble const rad = Geom::L2(delta); - gdouble arg = Geom::atan2(delta) - 2.0*M_PI*spiral->revo; + gdouble arg = Geom::atan2(delta) - 2.0*M_PI*this->spiral->revo; if (state & GDK_CONTROL_MASK) { arg = sp_round(arg, M_PI/snaps); } /* Fixme: these parameters should be got from dialog box */ - spiral->setPosition(p0[Geom::X], p0[Geom::Y], + this->spiral->setPosition(p0[Geom::X], p0[Geom::Y], /*expansion*/ this->exp, /*revolution*/ this->revo, rad, arg, @@ -412,7 +410,7 @@ void SPSpiralContext::drag(Geom::Point const &p, guint state) { GString *rads = SP_PX_TO_METRIC_STRING(rad, desktop->namedview->getDefaultMetric()); this->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Spiral</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle"), - rads->str, sp_round((arg + 2.0*M_PI*spiral->revo)*180/M_PI, 0.0001)); + rads->str, sp_round((arg + 2.0*M_PI*this->spiral->revo)*180/M_PI, 0.0001)); g_string_free(rads, FALSE); } diff --git a/src/spiral-context.h b/src/spiral-context.h index 65a10dd04..c2f579e28 100644 --- a/src/spiral-context.h +++ b/src/spiral-context.h @@ -35,7 +35,7 @@ public: virtual void setup(); virtual void finish(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/spray-context.cpp b/src/spray-context.cpp index 9c4a22053..8bedb237b 100644 --- a/src/spray-context.cpp +++ b/src/spray-context.cpp @@ -282,38 +282,38 @@ void SPSprayContext::setup() { } } -void SPSprayContext::set(Inkscape::Preferences::Entry* val) { +void SPSprayContext::set(const Inkscape::Preferences::Entry& val) { SPEventContext* ec = this; SPSprayContext *tc = SP_SPRAY_CONTEXT(ec); - Glib::ustring path = val->getEntryName(); + Glib::ustring path = val.getEntryName(); if (path == "mode") { - tc->mode = val->getInt(); + tc->mode = val.getInt(); sp_spray_update_cursor(tc, false); } else if (path == "width") { - tc->width = 0.01 * CLAMP(val->getInt(10), 1, 100); + tc->width = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "usepressure") { - tc->usepressure = val->getBool(); + tc->usepressure = val.getBool(); } else if (path == "population") { - tc->population = 0.01 * CLAMP(val->getInt(10), 1, 100); + tc->population = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "rotation_variation") { - tc->rotation_variation = CLAMP(val->getDouble(0.0), 0, 100.0); + tc->rotation_variation = CLAMP(val.getDouble(0.0), 0, 100.0); } else if (path == "scale_variation") { - tc->scale_variation = CLAMP(val->getDouble(1.0), 0, 100.0); + tc->scale_variation = CLAMP(val.getDouble(1.0), 0, 100.0); } else if (path == "standard_deviation") { - tc->standard_deviation = 0.01 * CLAMP(val->getInt(10), 1, 100); + tc->standard_deviation = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "mean") { - tc->mean = 0.01 * CLAMP(val->getInt(10), 1, 100); + tc->mean = 0.01 * CLAMP(val.getInt(10), 1, 100); // Not implemented in the toolbar and preferences yet } else if (path == "distribution") { - tc->distrib = val->getInt(1); + tc->distrib = val.getInt(1); } else if (path == "tilt") { - tc->tilt = CLAMP(val->getDouble(0.1), 0, 1000.0); + tc->tilt = CLAMP(val.getDouble(0.1), 0, 1000.0); } else if (path == "ratio") { - tc->ratio = CLAMP(val->getDouble(), 0.0, 0.9); + tc->ratio = CLAMP(val.getDouble(), 0.0, 0.9); } else if (path == "force") { - tc->force = CLAMP(val->getDouble(1.0), 0, 1.0); + tc->force = CLAMP(val.getDouble(1.0), 0, 1.0); } } diff --git a/src/spray-context.h b/src/spray-context.h index 7ededcd0b..327402945 100644 --- a/src/spray-context.h +++ b/src/spray-context.h @@ -91,7 +91,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/star-context.cpp b/src/star-context.cpp index aecdd1b0d..cb3e663d7 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -167,19 +167,19 @@ void SPStarContext::setup() { this->_message_context = new Inkscape::MessageContext(this->desktop->messageStack()); } -void SPStarContext::set(Inkscape::Preferences::Entry* val) { - Glib::ustring path = val->getEntryName(); +void SPStarContext::set(const Inkscape::Preferences::Entry& val) { + Glib::ustring path = val.getEntryName(); if (path == "magnitude") { - this->magnitude = CLAMP(val->getInt(5), 3, 1024); + this->magnitude = CLAMP(val.getInt(5), 3, 1024); } else if (path == "proportion") { - this->proportion = CLAMP(val->getDouble(0.5), 0.01, 2.0); + this->proportion = CLAMP(val.getDouble(0.5), 0.01, 2.0); } else if (path == "isflatsided") { - this->isflatsided = val->getBool(); + this->isflatsided = val.getBool(); } else if (path == "rounded") { - this->rounded = val->getDouble(); + this->rounded = val.getDouble(); } else if (path == "randomized") { - this->randomized = val->getDouble(); + this->randomized = val.getDouble(); } } diff --git a/src/star-context.h b/src/star-context.h index c1e010d19..8902b5450 100644 --- a/src/star-context.h +++ b/src/star-context.h @@ -33,7 +33,7 @@ public: virtual void setup(); virtual void finish(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index 990a62000..d1cf8bbf9 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -297,28 +297,28 @@ void SPTweakContext::setup() { } } -void SPTweakContext::set(Inkscape::Preferences::Entry* val) { - Glib::ustring path = val->getEntryName(); +void SPTweakContext::set(const Inkscape::Preferences::Entry& val) { + Glib::ustring path = val.getEntryName(); if (path == "width") { - this->width = CLAMP(val->getDouble(0.1), -1000.0, 1000.0); + this->width = CLAMP(val.getDouble(0.1), -1000.0, 1000.0); } else if (path == "mode") { - this->mode = val->getInt(); + this->mode = val.getInt(); sp_tweak_update_cursor(this, false); } else if (path == "fidelity") { - this->fidelity = CLAMP(val->getDouble(), 0.0, 1.0); + this->fidelity = CLAMP(val.getDouble(), 0.0, 1.0); } else if (path == "force") { - this->force = CLAMP(val->getDouble(1.0), 0, 1.0); + this->force = CLAMP(val.getDouble(1.0), 0, 1.0); } else if (path == "usepressure") { - this->usepressure = val->getBool(); + this->usepressure = val.getBool(); } else if (path == "doh") { - this->do_h = val->getBool(); + this->do_h = val.getBool(); } else if (path == "dos") { - this->do_s = val->getBool(); + this->do_s = val.getBool(); } else if (path == "dol") { - this->do_l = val->getBool(); + this->do_l = val.getBool(); } else if (path == "doo") { - this->do_o = val->getBool(); + this->do_o = val.getBool(); } } diff --git a/src/tweak-context.h b/src/tweak-context.h index f513b573e..1ca279ca1 100644 --- a/src/tweak-context.h +++ b/src/tweak-context.h @@ -78,7 +78,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp index f64aa4d2a..b65ca22b9 100644 --- a/src/ui/tool/node-tool.cpp +++ b/src/ui/tool/node-tool.cpp @@ -285,37 +285,37 @@ void InkNodeTool::setup() { this->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive } -void InkNodeTool::set(Inkscape::Preferences::Entry* value) { - Glib::ustring entry_name = value->getEntryName(); +void InkNodeTool::set(const Inkscape::Preferences::Entry& value) { + Glib::ustring entry_name = value.getEntryName(); if (entry_name == "show_handles") { - this->show_handles = value->getBool(true); + this->show_handles = value.getBool(true); this->_multipath->showHandles(this->show_handles); } else if (entry_name == "show_outline") { - this->show_outline = value->getBool(); + this->show_outline = value.getBool(); this->_multipath->showOutline(this->show_outline); } else if (entry_name == "live_outline") { - this->live_outline = value->getBool(); + this->live_outline = value.getBool(); this->_multipath->setLiveOutline(this->live_outline); } else if (entry_name == "live_objects") { - this->live_objects = value->getBool(); + this->live_objects = value.getBool(); this->_multipath->setLiveObjects(this->live_objects); } else if (entry_name == "show_path_direction") { - this->show_path_direction = value->getBool(); + this->show_path_direction = value.getBool(); this->_multipath->showPathDirection(this->show_path_direction); } else if (entry_name == "show_transform_handles") { - this->show_transform_handles = value->getBool(true); + this->show_transform_handles = value.getBool(true); this->_selected_nodes->showTransformHandles( this->show_transform_handles, this->single_node_transform_handles); } else if (entry_name == "single_node_transform_handles") { - this->single_node_transform_handles = value->getBool(); + this->single_node_transform_handles = value.getBool(); this->_selected_nodes->showTransformHandles( this->show_transform_handles, this->single_node_transform_handles); } else if (entry_name == "edit_clipping_paths") { - this->edit_clipping_paths = value->getBool(); + this->edit_clipping_paths = value.getBool(); this->selection_changed(this->desktop->selection); } else if (entry_name == "edit_masks") { - this->edit_masks = value->getBool(); + this->edit_masks = value.getBool(); this->selection_changed(this->desktop->selection); } else { SPEventContext::set(value); diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h index 597f2a347..df8b5d782 100644 --- a/src/ui/tool/node-tool.h +++ b/src/ui/tool/node-tool.h @@ -46,7 +46,7 @@ public: static const std::string prefsPath; virtual void setup(); - virtual void set(Inkscape::Preferences::Entry* val); + virtual void set(const Inkscape::Preferences::Entry& val); virtual gint root_handler(GdkEvent* event); virtual gint item_handler(SPItem* item, GdkEvent* event); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 4af7c0795..55451c035 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1806,7 +1806,10 @@ sp_desktop_widget_adjustment_value_changed (GtkAdjustment */*adj*/, SPDesktopWid sp_desktop_widget_update_rulers (dtw); /* update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */ - sp_box3d_context_update_lines(dtw->desktop->event_context); + //sp_box3d_context_update_lines(dtw->desktop->event_context); + if (SP_IS_BOX3D_CONTEXT(dtw->desktop->event_context)) { + SP_BOX3D_CONTEXT(dtw->desktop->event_context)->_vpdrag->updateLines(); + } dtw->update = 0; } |
