Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d_ops.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | ||||
| const bool zoom_to_pos = use_cursor_init && vzd->zoom_to_mouse_pos; | const bool zoom_to_pos = use_cursor_init && vzd->zoom_to_mouse_pos; | ||||
| /* get amount to move view by */ | /* get amount to move view by */ | ||||
| float dx = RNA_float_get(op->ptr, "deltax") / U.dpi_fac; | float dx = RNA_float_get(op->ptr, "deltax") / U.dpi_fac; | ||||
| float dy = RNA_float_get(op->ptr, "deltay") / U.dpi_fac; | float dy = RNA_float_get(op->ptr, "deltay") / U.dpi_fac; | ||||
| if (U.uiflag & USER_ZOOM_INVERT) { | |||||
| dx *= -1; | |||||
| dy *= -1; | |||||
| } | |||||
| /* Check if the 'timer' is initialized, as zooming with the trackpad | /* Check if the 'timer' is initialized, as zooming with the trackpad | ||||
| * never uses the "Continuous" zoom method, and the 'timer' is not initialized. */ | * never uses the "Continuous" zoom method, and the 'timer' is not initialized. */ | ||||
| if ((U.viewzoom == USER_ZOOM_CONT) && vzd->timer) { /* XXX store this setting as RNA prop? */ | if ((U.viewzoom == USER_ZOOM_CONT) && vzd->timer) { /* XXX store this setting as RNA prop? */ | ||||
| const double time = PIL_check_seconds_timer(); | const double time = PIL_check_seconds_timer(); | ||||
| const float time_step = (float)(time - vzd->timer_lastdraw); | const float time_step = (float)(time - vzd->timer_lastdraw); | ||||
| dx *= time_step * 0.5f; | dx *= time_step * 0.5f; | ||||
| dy *= time_step * 0.5f; | dy *= time_step * 0.5f; | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
| ®ion->v2d, event->mval[0], event->mval[1], &vzd->mx_2d, &vzd->my_2d); | ®ion->v2d, event->mval[0], event->mval[1], &vzd->mx_2d, &vzd->my_2d); | ||||
| vzd->zoom_to_mouse_pos = true; | vzd->zoom_to_mouse_pos = true; | ||||
| } | } | ||||
| if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { | if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { | ||||
| vzd->lastx = event->prevx; | vzd->lastx = event->prevx; | ||||
| vzd->lasty = event->prevy; | vzd->lasty = event->prevy; | ||||
| /* As we have only 1D information (magnify value), feed both axes | float facx, facy; | ||||
| * with magnify information that is stored in x axis | float zoomfac = 0.01f; | ||||
| */ | |||||
| float fac = 0.01f * (event->prevx - event->x); | /* Some view2d's (graph) don't have min/max zoom, or extreme ones. */ | ||||
| float dx = fac * BLI_rctf_size_x(&v2d->cur) / 10.0f; | if (v2d->maxzoom > 0.0f) { | ||||
| zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); | |||||
| } | |||||
| if (event->type == MOUSEPAN) { | if (event->type == MOUSEPAN) { | ||||
| fac = 0.01f * (event->prevy - event->y); | facx = zoomfac * WM_event_absolute_delta_x(event); | ||||
| facy = zoomfac * WM_event_absolute_delta_y(event); | |||||
| if (U.uiflag & USER_ZOOM_INVERT) { | |||||
| facx *= -1; | |||||
| facy *= -1; | |||||
| } | |||||
| } | |||||
| else { /* MOUSEZOOM */ | |||||
| facx = facy = zoomfac * WM_event_absolute_delta_x(event); | |||||
| } | } | ||||
| float dy = fac * BLI_rctf_size_y(&v2d->cur) / 10.0f; | |||||
| /* Only respect user setting zoom axis if the view does not have any zoom restrictions | /* Only respect user setting zoom axis if the view does not have any zoom restrictions | ||||
| * any will be scaled uniformly. */ | * any will be scaled uniformly. */ | ||||
| if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && | if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && | ||||
| (v2d->keepzoom & V2D_KEEPASPECT)) { | (v2d->keepzoom & V2D_KEEPASPECT)) { | ||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (U.uiflag & USER_ZOOM_HORIZ) { | ||||
| dy = 0; | facy = 0; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = 0; | facx = 0; | ||||
| } | } | ||||
| } | } | ||||
| /* support trackpad zoom to always zoom entirely - the v2d code uses portrait or | /* support trackpad zoom to always zoom entirely - the v2d code uses portrait or | ||||
| * landscape exceptions */ | * landscape exceptions */ | ||||
| if (v2d->keepzoom & V2D_KEEPASPECT) { | if (v2d->keepzoom & V2D_KEEPASPECT) { | ||||
| if (fabsf(dx) > fabsf(dy)) { | if (fabsf(facx) > fabsf(facy)) { | ||||
| dy = dx; | facy = facx; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = dy; | facx = facy; | ||||
| } | } | ||||
| } | } | ||||
| const float dx = facx * BLI_rctf_size_x(&v2d->cur); | |||||
| const float dy = facy * BLI_rctf_size_y(&v2d->cur); | |||||
| RNA_float_set(op->ptr, "deltax", dx); | RNA_float_set(op->ptr, "deltax", dx); | ||||
| RNA_float_set(op->ptr, "deltay", dy); | RNA_float_set(op->ptr, "deltay", dy); | ||||
| view_zoomdrag_apply(C, op); | view_zoomdrag_apply(C, op); | ||||
| view_zoomdrag_exit(C, op); | view_zoomdrag_exit(C, op); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| dist = len_v2(len_new) - len_v2(len_old); | dist = len_v2(len_new) - len_v2(len_old); | ||||
| dx = dy = dist; | dx = dy = dist; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = len_new[0] - len_old[0]; | dx = len_new[0] - len_old[0]; | ||||
| dy = len_new[1] - len_old[1]; | dy = len_new[1] - len_old[1]; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { /* USER_ZOOM_CONT or USER_ZOOM_DOLLY */ | ||||
| /* 'continuous' or 'dolly' */ | float facx = zoomfac * (event->x - vzd->lastx); | ||||
| float fac; | float facy = zoomfac * (event->y - vzd->lasty); | ||||
| /* x-axis transform */ | |||||
| fac = zoomfac * (event->x - vzd->lastx); | |||||
| dx = fac * BLI_rctf_size_x(&v2d->cur); | |||||
| /* y-axis transform */ | |||||
| fac = zoomfac * (event->y - vzd->lasty); | |||||
| dy = fac * BLI_rctf_size_y(&v2d->cur); | |||||
| /* Only respect user setting zoom axis if the view does not have any zoom restrictions | /* Only respect user setting zoom axis if the view does not have any zoom restrictions | ||||
| * any will be scaled uniformly */ | * any will be scaled uniformly */ | ||||
| if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && | if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && | ||||
| (v2d->keepzoom & V2D_KEEPASPECT)) { | (v2d->keepzoom & V2D_KEEPASPECT)) { | ||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (U.uiflag & USER_ZOOM_HORIZ) { | ||||
| dy = 0; | facy = 0; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = 0; | facx = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| /* support zoom to always zoom entirely - the v2d code uses portrait or | /* support zoom to always zoom entirely - the v2d code uses portrait or | ||||
| * landscape exceptions */ | * landscape exceptions */ | ||||
| if (v2d->keepzoom & V2D_KEEPASPECT) { | if (v2d->keepzoom & V2D_KEEPASPECT) { | ||||
| if (fabsf(dx) > fabsf(dy)) { | if (fabsf(facx) > fabsf(facy)) { | ||||
| dy = dx; | facy = facx; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = dy; | facx = facy; | ||||
| } | |||||
| } | } | ||||
| dx = facx * BLI_rctf_size_x(&v2d->cur); | |||||
| dy = facy * BLI_rctf_size_y(&v2d->cur); | |||||
| } | |||||
| if (U.uiflag & USER_ZOOM_INVERT) { | |||||
| dx *= -1; | |||||
| dy *= -1; | |||||
| } | } | ||||
| /* set transform amount, and add current deltas to stored total delta (for redo) */ | /* set transform amount, and add current deltas to stored total delta (for redo) */ | ||||
| RNA_float_set(op->ptr, "deltax", dx); | RNA_float_set(op->ptr, "deltax", dx); | ||||
| RNA_float_set(op->ptr, "deltay", dy); | RNA_float_set(op->ptr, "deltay", dy); | ||||
| vzd->dx += dx; | vzd->dx += dx; | ||||
| vzd->dy += dy; | vzd->dy += dy; | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||