Logo Search packages:      
Sourcecode: inkscape version File versions

void SPDesktop::set_display_area ( double  x0,
double  y0,
double  x1,
double  y1,
double  border,
bool  log = true 
)

Set viewbox (x0, x1, y0 and y1 are in document pixels. Border is in screen pixels).

Definition at line 748 of file desktop.cpp.

References Geom::Matrix::descrim(), Geom::D2< Interval >::dimensions(), Geom::D2< Interval >::expandBy(), SPCanvas::getViewbox(), main(), push_current_zoom(), sp_canvas_item_affine_absolute(), and sp_canvas_scroll_to().

Referenced by next_zoom(), prev_zoom(), sp_desktop_widget_realize(), sp_event_context_private_root_handler(), zoom_absolute_keep_point(), zoom_drawing(), zoom_page(), zoom_page_width(), zoom_quick(), and zoom_selection().

{
    g_assert(_widget);

    // save the zoom
    if (log) {
        push_current_zoom(&zooms_past);
        // if we do a logged zoom, our zoom-forward list is invalidated, so delete it
        g_list_free (zooms_future);
        zooms_future = NULL;
    }

    double const cx = 0.5 * (x0 + x1);
    double const cy = 0.5 * (y0 + y1);

    // FIXME: This 2geom idiom doesn't allow us to declare dbox const
    Geom::Rect viewbox = canvas->getViewbox();
    viewbox.expandBy(-border);

    double scale = _d2w.descrim();
    double newscale;
    if (((x1 - x0) * viewbox.dimensions()[Geom::Y]) > ((y1 - y0) * viewbox.dimensions()[Geom::X])) {
        newscale = viewbox.dimensions()[Geom::X] / (x1 - x0);
    } else {
        newscale = viewbox.dimensions()[Geom::Y] / (y1 - y0);
    }

    newscale = CLAMP(newscale, SP_DESKTOP_ZOOM_MIN, SP_DESKTOP_ZOOM_MAX); // unit: 'screen pixels' per 'document pixels'

    int clear = FALSE;
    if (!NR_DF_TEST_CLOSE (newscale, scale, 1e-4 * scale)) {
        /* Set zoom factors */
        _d2w = Geom::Scale(newscale, -newscale);
        _w2d = Geom::Scale(1/newscale, 1/-newscale);
        sp_canvas_item_affine_absolute(SP_CANVAS_ITEM(main), _d2w);
        clear = TRUE;
    }

    /* Calculate top left corner (in document pixels) */
    x0 = cx - 0.5 * viewbox.dimensions()[Geom::X] / newscale;
    y1 = cy + 0.5 * viewbox.dimensions()[Geom::Y] / newscale;

    /* Scroll */
    sp_canvas_scroll_to (canvas, 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);

    _widget->updateRulers();
    _widget->updateScrollbars(_d2w.descrim());
    _widget->updateZoom();
}


Generated by  Doxygen 1.6.0   Back to index