Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

void Inkscape::SelTrans::moveTo ( Geom::Point const &  xy,
guint  state 
)

shift: with snapping

Definition at line 1409 of file seltrans.cpp.

References SnapManager::constrainedSnapTranslation(), SnapManager::freeSnapTranslation(), SPNamedView::getDefaultMetric(), SnapManager::multipleOfGridPitch(), and SnapManager::setup().

{
    SnapManager &m = _desktop->namedview->snap_manager;

    /* The amount that we've moved by during this drag */
    Geom::Point dxy = xy - _point;

    bool const alt = (state & GDK_MOD1_MASK);
    bool const control = (state & GDK_CONTROL_MASK);
    bool const shift = (state & GDK_SHIFT_MASK);

    if (alt) {

        // Alt pressed means: move only by integer multiples of the grid spacing

        if (control) { // ... if also constrained to the orthogonal axes
            if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) {
                dxy[Geom::Y] = 0;
            } else {
                dxy[Geom::X] = 0;
            }
        }
        m.setup(_desktop, true, _items_const);
        dxy = m.multipleOfGridPitch(dxy, _point);
    } else if (shift) {
        if (control) { // shift & control: constrained movement without snapping
            if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) {
                dxy[Geom::Y] = 0;
            } else {
                dxy[Geom::X] = 0;
            }
        }
    } else { //!shift: with snapping

        /* We're snapping to things, possibly with a constraint to horizontal or
        ** vertical movement.  Obtain a list of possible translations and then
        ** pick the smallest.
        */

        m.setup(_desktop, false, _items_const);

        /* This will be our list of possible translations */
        std::list<Inkscape::SnappedPoint> s;

        if (control) { // constrained movement with snapping

            /* Snap to things, and also constrain to horizontal or vertical movement */

            unsigned int dim = fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y]) ? Geom::X : Geom::Y;
            // When doing a constrained translation, all points will move in the same direction, i.e.
            // either horizontally or vertically. Therefore we only have to specify the direction of
            // the constraint-line once. The constraint lines are parallel, but might not be colinear.
            // Therefore we will have to set the point through which the constraint-line runs
            // individually for each point to be snapped; this will be handled however by _snapTransformed()
            s.push_back(m.constrainedSnapTranslation(_bbox_points_for_translating,
                                                     _point,
                                                     Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
                                                     dxy));

            s.push_back(m.constrainedSnapTranslation(_snap_points,
                                                     _point,
                                                     Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
                                                     dxy));
        } else { // !control

            // Let's leave this timer code here for a while. I'll probably need it in the near future (Diederik van Lierop)
            /* GTimeVal starttime;
            GTimeVal endtime;
            g_get_current_time(&starttime); */

            /* Snap to things with no constraint */
            s.push_back(m.freeSnapTranslation(_bbox_points_for_translating, _point, dxy));
            s.push_back(m.freeSnapTranslation(_snap_points, _point, dxy));

              /*g_get_current_time(&endtime);
              double elapsed = ((((double)endtime.tv_sec - starttime.tv_sec) * G_USEC_PER_SEC + (endtime.tv_usec - starttime.tv_usec))) / 1000.0;
              std::cout << "Time spent snapping: " << elapsed << std::endl; */
        }

        /* Pick one */
        Inkscape::SnappedPoint best_snapped_point;
        for (std::list<Inkscape::SnappedPoint>::const_iterator i = s.begin(); i != s.end(); i++) {
            if (i->getSnapped()) {
                if (best_snapped_point.isOtherSnapBetter(*i, true)) {
                    best_snapped_point = *i;
                    dxy = i->getTransformation();
                }
            }
        }

        if (best_snapped_point.getSnapped()) {
            _desktop->snapindicator->set_new_snaptarget(best_snapped_point);
        } else {
            // We didn't snap, so remove any previous snap indicator
            _desktop->snapindicator->remove_snaptarget();
            if (control) {
                // If we didn't snap, then we should still constrain horizontally or vertically
                // (When we did snap, then this constraint has already been enforced by
                // calling constrainedSnapTranslation() above)
                if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) {
                    dxy[Geom::Y] = 0;
                } else {
                    dxy[Geom::X] = 0;
                }
            }
        }
    }

    Geom::Matrix const move((Geom::Translate(dxy)));
    Geom::Point const norm(0, 0);
    transform(move, norm);

    // status text
    GString *xs = SP_PX_TO_METRIC_STRING(dxy[Geom::X], _desktop->namedview->getDefaultMetric());
    GString *ys = SP_PX_TO_METRIC_STRING(dxy[Geom::Y], _desktop->namedview->getDefaultMetric());
    _message_context.setF(Inkscape::NORMAL_MESSAGE, _("<b>Move</b> by %s, %s; with <b>Ctrl</b> to restrict to horizontal/vertical; with <b>Shift</b> to disable snapping"), xs->str, ys->str);
    g_string_free(xs, TRUE);
    g_string_free(ys, TRUE);
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index