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 | |||||
| * - `deltax, deltay` - amounts to add to each side of the 'cur' rect | * - `deltax, deltay` - amounts to add to each side of the 'cur' rect | ||||
| */ | */ | ||||
| /* apply transform to view (i.e. adjust 'cur' rect) */ | /* apply transform to view (i.e. adjust 'cur' rect) */ | ||||
| static void view_zoomdrag_apply(bContext *C, wmOperator *op) | static void view_zoomdrag_apply(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| v2dViewZoomData *vzd = op->customdata; | v2dViewZoomData *vzd = op->customdata; | ||||
| View2D *v2d = vzd->v2d; | View2D *v2d = vzd->v2d; | ||||
| 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") / U.dpi_fac; | ||||
| Show All 17 Lines | |||||
| } | } | ||||
| /* only move view on an axis if change is allowed */ | /* only move view on an axis if change is allowed */ | ||||
| if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) { | if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) { | ||||
| if (v2d->keepofs & V2D_LOCKOFS_X) { | if (v2d->keepofs & V2D_LOCKOFS_X) { | ||||
| v2d->cur.xmax -= 2 * dx; | v2d->cur.xmax -= 2 * dx; | ||||
| } | } | ||||
| else { | else { | ||||
| v2d->cur.xmin += dx; | |||||
| v2d->cur.xmax -= dx; | |||||
| if (zoom_to_pos) { | if (zoom_to_pos) { | ||||
| const float mval_fac = (vzd->mx_2d - v2d->cur.xmin) / BLI_rctf_size_x(&v2d->cur); | /* Get zoom fac the same way as in | ||||
| const float mval_faci = 1.0f - mval_fac; | * ui_view2d_curRect_validate_resize - better keep in sync! */ | ||||
| const float ofs = (mval_fac * dx) - (mval_faci * dx); | const float zoomx = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); | ||||
| v2d->cur.xmin += ofs + dx; | /* Only move view to mouse if zoom fac is inside minzoom/maxzoom. */ | ||||
| v2d->cur.xmax += ofs - dx; | if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) || | ||||
| } | IN_RANGE_INCL(zoomx, v2d->minzoom, v2d->maxzoom)) { | ||||
| else { | const float mval_fac = (vzd->mx_2d - cur_old.xmin) / BLI_rctf_size_x(&cur_old); | ||||
| v2d->cur.xmin += dx; | const float mval_faci = 1.0f - mval_fac; | ||||
| v2d->cur.xmax -= dx; | const float ofs = (mval_fac * dx) - (mval_faci * dx); | ||||
| v2d->cur.xmin += ofs; | |||||
| v2d->cur.xmax += ofs; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) { | if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) { | ||||
| if (v2d->keepofs & V2D_LOCKOFS_Y) { | if (v2d->keepofs & V2D_LOCKOFS_Y) { | ||||
| v2d->cur.ymax -= 2 * dy; | v2d->cur.ymax -= 2 * dy; | ||||
| } | } | ||||
| else { | else { | ||||
| v2d->cur.ymin += dy; | |||||
| v2d->cur.ymax -= dy; | |||||
| if (zoom_to_pos) { | if (zoom_to_pos) { | ||||
| const float mval_fac = (vzd->my_2d - v2d->cur.ymin) / BLI_rctf_size_y(&v2d->cur); | /* Get zoom fac the same way as in | ||||
| const float mval_faci = 1.0f - mval_fac; | * ui_view2d_curRect_validate_resize - better keep in sync! */ | ||||
| const float ofs = (mval_fac * dy) - (mval_faci * dy); | const float zoomy = (float)(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur); | ||||
| v2d->cur.ymin += ofs + dy; | /* Only move view to mouse if zoom fac is inside minzoom/maxzoom. */ | ||||
| v2d->cur.ymax += ofs - dy; | if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) || | ||||
| } | IN_RANGE_INCL(zoomy, v2d->minzoom, v2d->maxzoom)) { | ||||
| else { | const float mval_fac = (vzd->my_2d - cur_old.ymin) / BLI_rctf_size_y(&cur_old); | ||||
| v2d->cur.ymin += dy; | const float mval_faci = 1.0f - mval_fac; | ||||
| v2d->cur.ymax -= dy; | const float ofs = (mval_fac * dy) - (mval_faci * dy); | ||||
| v2d->cur.ymin += ofs; | |||||
| v2d->cur.ymax += ofs; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Inform v2d about changes after this operation. */ | /* Inform v2d about changes after this operation. */ | ||||
| UI_view2d_curRect_changed(C, v2d); | UI_view2d_curRect_changed(C, v2d); | ||||
| if (ED_region_snap_size_apply(vzd->region, snap_test)) { | if (ED_region_snap_size_apply(vzd->region, snap_test)) { | ||||
| ▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines | |||||