Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d_ops.c
| Show First 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | |||||
| View2D *v2d = vzd->v2d; | View2D *v2d = vzd->v2d; | ||||
| const rctf cur_old = v2d->cur; | const rctf cur_old = v2d->cur; | ||||
| float dx, dy; | float dx, dy; | ||||
| const int snap_test = ED_region_snap_size_test(vzd->region); | const int snap_test = ED_region_snap_size_test(vzd->region); | ||||
| 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. */ | ||||
| dx = RNA_float_get(op->ptr, "deltax") / U.dpi_fac; | dx = RNA_float_get(op->ptr, "deltax"); | ||||
| dy = RNA_float_get(op->ptr, "deltay") / U.dpi_fac; | dy = RNA_float_get(op->ptr, "deltay"); | ||||
| 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; | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
| /* Store initial mouse position (in view space). */ | /* Store initial mouse position (in view space). */ | ||||
| UI_view2d_region_to_view( | 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 (event->type == MOUSEZOOM || event->type == MOUSEPAN) { | if (event->type == MOUSEZOOM || event->type == MOUSEPAN) { | ||||
| float dx, dy, fac; | float facx, facy, dx, dy; | ||||
| float zoomfac = 0.01f; | |||||
| /* Some view2d's (graph) don't have min/max zoom, or extreme ones. */ | |||||
| if (v2d->maxzoom > 0.0f) { | |||||
| zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); | |||||
| } | |||||
| 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 | facx = zoomfac * (event->prevx - event->x); | ||||
| * with magnify information that is stored in x axis | |||||
| */ | |||||
| fac = 0.01f * (event->prevx - event->x); | |||||
| dx = fac * BLI_rctf_size_x(&v2d->cur) / 10.0f; | |||||
| if (event->type == MOUSEPAN) { | if (event->type == MOUSEPAN) { | ||||
| fac = 0.01f * (event->prevy - event->y); | facy = zoomfac * (event->prevy - event->y); | ||||
| } | |||||
| else { | |||||
| /* Set to equal as MOUSEZOOM uses only X axis to pass magnification value. */ | |||||
| facy = facx; | |||||
| } | } | ||||
| dy = fac * BLI_rctf_size_y(&v2d->cur) / 10.0f; | |||||
| /* Support zoom to always zoom entirely. Only respect Zoom Axis user setting | /* Support zoom to always zoom entirely. Only respect Zoom Axis user setting | ||||
| * if the view does not have any zoom restrictions any will be scaled uniformly. */ | * if the view does not have any zoom restrictions any will be scaled uniformly. */ | ||||
| if (v2d->keepzoom & V2D_KEEPASPECT) { | if (v2d->keepzoom & V2D_KEEPASPECT) { | ||||
| 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) { | ||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (U.uiflag & USER_ZOOM_HORIZ) { | ||||
| dy = 0; | facy = 0; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = 0; | facx = 0; | ||||
| } | } | ||||
| } | } | ||||
| 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 (event->type == MOUSEPAN) { | |||||
| const bool user_zoom_invert = (U.uiflag & USER_ZOOM_INVERT) != 0; | |||||
| const bool user_trackpad_natural = (U.uiflag2 & USER_TRACKPAD_NATURAL) != 0; | |||||
| if (user_zoom_invert != user_trackpad_natural) { | |||||
| dx *= -1; | |||||
| dy *= -1; | |||||
| } | } | ||||
| } | } | ||||
| 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 All 35 Lines | |||||
| v2dViewZoomData *vzd = op->customdata; | v2dViewZoomData *vzd = op->customdata; | ||||
| View2D *v2d = vzd->v2d; | View2D *v2d = vzd->v2d; | ||||
| /* execute the events */ | /* execute the events */ | ||||
| if (event->type == TIMER && event->customdata == vzd->timer) { | if (event->type == TIMER && event->customdata == vzd->timer) { | ||||
| view_zoomdrag_apply(C, op); | view_zoomdrag_apply(C, op); | ||||
| } | } | ||||
| else if (event->type == MOUSEMOVE) { | else if (event->type == MOUSEMOVE) { | ||||
| float dx, dy; | float facx, facy, dx, dy; | ||||
| float zoomfac = 0.01f; | float zoomfac = 0.01f; | ||||
| /* some view2d's (graph) don't have min/max zoom, or extreme ones */ | /* some view2d's (graph) don't have min/max zoom, or extreme ones */ | ||||
| if (v2d->maxzoom > 0.0f) { | if (v2d->maxzoom > 0.0f) { | ||||
| zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); | zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); | ||||
| } | } | ||||
| /* calculate new delta transform, based on zooming mode */ | /* calculate new delta transform, based on zooming mode */ | ||||
| Show All 25 Lines | |||||
| 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 { | ||||
| /* 'continuous' or 'dolly' */ | /* "Continue" or "Dolly" zoom style. */ | ||||
| float fac; | facx = zoomfac * (event->x - vzd->lastx) / U.dpi_fac; | ||||
| /* x-axis transform */ | facy = zoomfac * (event->y - vzd->lasty) / U.dpi_fac; | ||||
| 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); | |||||
| /* Support zoom to always zoom entirely. Only respect Zoom Axis user setting | /* Support zoom to always zoom entirely. Only respect Zoom Axis user setting | ||||
| * if the view does not have any zoom restrictions any will be scaled uniformly. */ | * if the view does not have any zoom restrictions any will be scaled uniformly. */ | ||||
| if (v2d->keepzoom & V2D_KEEPASPECT) { | if (v2d->keepzoom & V2D_KEEPASPECT) { | ||||
| 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) { | ||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (U.uiflag & USER_ZOOM_HORIZ) { | ||||
| dy = 0; | facy = 0; | ||||
| } | } | ||||
| else { | else { | ||||
| dx = 0; | facx = 0; | ||||
| } | } | ||||
| } | } | ||||
| 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 292 Lines • Show Last 20 Lines | |||||