Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d_ops.c
| Show First 20 Lines • Show All 1,100 Lines • ▼ Show 20 Lines | static void view_zoomdrag_apply(bContext *C, wmOperator *op) | ||||
| 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 105 Lines • ▼ Show 20 Lines | UI_view2d_region_to_view( | ||||
| ®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.0f; | |||||
| facy *= -1.0f; | |||||
| } | |||||
| } | |||||
| else { /* MOUSEZOOM */ | |||||
| facx = facy = zoomfac * WM_event_absolute_delta_x(event); | |||||
| } | |||||
| /* Only respect user setting zoom axis if the view does not have any zoom restrictions | |||||
| * any will be scaled uniformly. */ | |||||
| if (((v2d->keepzoom & (V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y)) == 0) && | |||||
| (v2d->keepzoom & V2D_KEEPASPECT)) { | |||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | |||||
| facy = 0.0f; | |||||
| } | |||||
| else { | |||||
| facx = 0.0f; | |||||
| } | |||||
| } | } | ||||
| float dy = fac * BLI_rctf_size_y(&v2d->cur) / 10.0f; | |||||
| /* 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 52 Lines • ▼ Show 20 Lines | else if (event->type == MOUSEMOVE) { | ||||
| if (U.viewzoom == USER_ZOOM_SCALE) { | if (U.viewzoom == USER_ZOOM_SCALE) { | ||||
| /* 'scale' zooming */ | /* 'scale' zooming */ | ||||
| float dist; | float dist; | ||||
| float len_old[2]; | float len_old[2]; | ||||
| float len_new[2]; | float len_new[2]; | ||||
| /* x-axis transform */ | /* x-axis transform */ | ||||
| dist = BLI_rcti_size_x(&v2d->mask) / 2.0f; | dist = BLI_rcti_size_x(&v2d->mask) / 2.0f; | ||||
| len_old[0] = fabsf(vzd->lastx - vzd->region->winrct.xmin - dist); | len_old[0] = zoomfac * fabsf(vzd->lastx - vzd->region->winrct.xmin - dist); | ||||
| len_new[0] = fabsf(event->x - vzd->region->winrct.xmin - dist); | len_new[0] = zoomfac * fabsf(event->x - vzd->region->winrct.xmin - dist); | ||||
| len_old[0] *= zoomfac * BLI_rctf_size_x(&v2d->cur); | |||||
| len_new[0] *= zoomfac * BLI_rctf_size_x(&v2d->cur); | |||||
| /* y-axis transform */ | /* y-axis transform */ | ||||
| dist = BLI_rcti_size_y(&v2d->mask) / 2.0f; | dist = BLI_rcti_size_y(&v2d->mask) / 2.0f; | ||||
| len_old[1] = fabsf(vzd->lasty - vzd->region->winrct.ymin - dist); | len_old[1] = zoomfac * fabsf(vzd->lasty - vzd->region->winrct.ymin - dist); | ||||
| len_new[1] = fabsf(event->y - vzd->region->winrct.ymin - dist); | len_new[1] = zoomfac * fabsf(event->y - vzd->region->winrct.ymin - dist); | ||||
| len_old[1] *= zoomfac * BLI_rctf_size_y(&v2d->cur); | |||||
| len_new[1] *= zoomfac * BLI_rctf_size_y(&v2d->cur); | |||||
| /* Calculate distance */ | /* Calculate distance */ | ||||
| if (v2d->keepzoom & V2D_KEEPASPECT) { | if (v2d->keepzoom & V2D_KEEPASPECT) { | ||||
| 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 { | |||||
| /* 'continuous' or 'dolly' */ | |||||
| float fac; | |||||
| /* x-axis transform */ | |||||
| fac = zoomfac * (event->x - vzd->lastx); | |||||
| dx = fac * BLI_rctf_size_x(&v2d->cur); | |||||
| /* y-axis transform */ | dx *= BLI_rctf_size_x(&v2d->cur); | ||||
| fac = zoomfac * (event->y - vzd->lasty); | dy *= BLI_rctf_size_y(&v2d->cur); | ||||
| dy = fac * BLI_rctf_size_y(&v2d->cur); | } | ||||
| else { /* USER_ZOOM_CONT or USER_ZOOM_DOLLY */ | |||||
| float facx = zoomfac * (event->x - vzd->lastx); | |||||
| float facy = zoomfac * (event->y - vzd->lasty); | |||||
| /* 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.0f; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = 0; | facx = 0.0f; | ||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /* 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.0f; | |||||
| dy *= -1.0f; | |||||
| } | } | ||||
| /* 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 1,019 Lines • Show Last 20 Lines | |||||