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.

Definition at line 625 of file desktop.cpp.

References NR::Rect::dimensions(), 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(), 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);

    NR::Rect const viewbox = NR::expand(canvas->getViewbox(), border);

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

    newscale = CLAMP(newscale, SP_DESKTOP_ZOOM_MIN, SP_DESKTOP_ZOOM_MAX);

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

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

    /* Scroll */
    sp_canvas_scroll_to (canvas, x0 * newscale - border, y1 * -newscale - border, clear);

    _widget->updateRulers();
    _widget->updateScrollbars(expansion(_d2w));
    _widget->updateZoom();
}


Generated by  Doxygen 1.6.0   Back to index