Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d_ops.cc
| Show First 20 Lines • Show All 1,622 Lines • ▼ Show 20 Lines | static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) | ||||
| /* escape if not our timer */ | /* escape if not our timer */ | ||||
| if (v2d->smooth_timer == nullptr || v2d->smooth_timer != event->customdata) { | if (v2d->smooth_timer == nullptr || v2d->smooth_timer != event->customdata) { | ||||
| return OPERATOR_PASS_THROUGH; | return OPERATOR_PASS_THROUGH; | ||||
| } | } | ||||
| float step; | float step; | ||||
| if (sms->time_allowed != 0.0) { | if (sms->time_allowed != 0.0) { | ||||
| step = (float)((v2d->smooth_timer->duration) / sms->time_allowed); | step = float((v2d->smooth_timer->duration) / sms->time_allowed); | ||||
| } | } | ||||
| else { | else { | ||||
| step = 1.0f; | step = 1.0f; | ||||
| } | } | ||||
| /* end timer */ | /* end timer */ | ||||
| if (step >= 1.0f) { | if (step >= 1.0f) { | ||||
| v2d->cur = sms->new_cur; | v2d->cur = sms->new_cur; | ||||
| ▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Lines | static void scroller_activate_init(bContext *C, | ||||
| /* Use a union of 'cur' & 'tot' in case the current view is far outside 'tot'. In this cases | /* Use a union of 'cur' & 'tot' in case the current view is far outside 'tot'. In this cases | ||||
| * moving the scroll bars has far too little effect and the view can get stuck T31476. */ | * moving the scroll bars has far too little effect and the view can get stuck T31476. */ | ||||
| rctf tot_cur_union = v2d->tot; | rctf tot_cur_union = v2d->tot; | ||||
| BLI_rctf_union(&tot_cur_union, &v2d->cur); | BLI_rctf_union(&tot_cur_union, &v2d->cur); | ||||
| if (in_scroller == 'h') { | if (in_scroller == 'h') { | ||||
| /* horizontal scroller - calculate adjustment factor first */ | /* horizontal scroller - calculate adjustment factor first */ | ||||
| const float mask_size = (float)BLI_rcti_size_x(&v2d->hor); | const float mask_size = float(BLI_rcti_size_x(&v2d->hor)); | ||||
| vsm->fac = BLI_rctf_size_x(&tot_cur_union) / mask_size; | vsm->fac = BLI_rctf_size_x(&tot_cur_union) / mask_size; | ||||
| /* pixel rounding */ | /* pixel rounding */ | ||||
| vsm->fac_round = (BLI_rctf_size_x(&v2d->cur)) / (float)(BLI_rcti_size_x(®ion->winrct) + 1); | vsm->fac_round = (BLI_rctf_size_x(&v2d->cur)) / float(BLI_rcti_size_x(®ion->winrct) + 1); | ||||
| /* get 'zone' (i.e. which part of scroller is activated) */ | /* get 'zone' (i.e. which part of scroller is activated) */ | ||||
| vsm->zone = mouse_in_scroller_handle( | vsm->zone = mouse_in_scroller_handle( | ||||
| event->mval[0], v2d->hor.xmin, v2d->hor.xmax, scrollers.hor_min, scrollers.hor_max); | event->mval[0], v2d->hor.xmin, v2d->hor.xmax, scrollers.hor_min, scrollers.hor_max); | ||||
| if ((v2d->keepzoom & V2D_LOCKZOOM_X) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { | if ((v2d->keepzoom & V2D_LOCKZOOM_X) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { | ||||
| /* default to scroll, as handles not usable */ | /* default to scroll, as handles not usable */ | ||||
| vsm->zone = SCROLLHANDLE_BAR; | vsm->zone = SCROLLHANDLE_BAR; | ||||
| } | } | ||||
| vsm->scrollbarwidth = scrollers.hor_max - scrollers.hor_min; | vsm->scrollbarwidth = scrollers.hor_max - scrollers.hor_min; | ||||
| vsm->scrollbar_orig = ((scrollers.hor_max + scrollers.hor_min) / 2) + region->winrct.xmin; | vsm->scrollbar_orig = ((scrollers.hor_max + scrollers.hor_min) / 2) + region->winrct.xmin; | ||||
| } | } | ||||
| else { | else { | ||||
| /* vertical scroller - calculate adjustment factor first */ | /* vertical scroller - calculate adjustment factor first */ | ||||
| const float mask_size = (float)BLI_rcti_size_y(&v2d->vert); | const float mask_size = float(BLI_rcti_size_y(&v2d->vert)); | ||||
| vsm->fac = BLI_rctf_size_y(&tot_cur_union) / mask_size; | vsm->fac = BLI_rctf_size_y(&tot_cur_union) / mask_size; | ||||
| /* pixel rounding */ | /* pixel rounding */ | ||||
| vsm->fac_round = (BLI_rctf_size_y(&v2d->cur)) / (float)(BLI_rcti_size_y(®ion->winrct) + 1); | vsm->fac_round = (BLI_rctf_size_y(&v2d->cur)) / float(BLI_rcti_size_y(®ion->winrct) + 1); | ||||
| /* get 'zone' (i.e. which part of scroller is activated) */ | /* get 'zone' (i.e. which part of scroller is activated) */ | ||||
| vsm->zone = mouse_in_scroller_handle( | vsm->zone = mouse_in_scroller_handle( | ||||
| event->mval[1], v2d->vert.ymin, v2d->vert.ymax, scrollers.vert_min, scrollers.vert_max); | event->mval[1], v2d->vert.ymin, v2d->vert.ymax, scrollers.vert_min, scrollers.vert_max); | ||||
| if ((v2d->keepzoom & V2D_LOCKZOOM_Y) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { | if ((v2d->keepzoom & V2D_LOCKZOOM_Y) && ELEM(vsm->zone, SCROLLHANDLE_MIN, SCROLLHANDLE_MAX)) { | ||||
| /* default to scroll, as handles not usable */ | /* default to scroll, as handles not usable */ | ||||
| vsm->zone = SCROLLHANDLE_BAR; | vsm->zone = SCROLLHANDLE_BAR; | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | static int scroller_activate_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case MOUSEMOVE: { | case MOUSEMOVE: { | ||||
| /* calculate new delta transform, then store mouse-coordinates for next-time */ | /* calculate new delta transform, then store mouse-coordinates for next-time */ | ||||
| if (ELEM(vsm->zone, SCROLLHANDLE_BAR, SCROLLHANDLE_MAX)) { | if (ELEM(vsm->zone, SCROLLHANDLE_BAR, SCROLLHANDLE_MAX)) { | ||||
| /* if using bar (i.e. 'panning') or 'max' zoom widget */ | /* if using bar (i.e. 'panning') or 'max' zoom widget */ | ||||
| switch (vsm->scroller) { | switch (vsm->scroller) { | ||||
| case 'h': /* horizontal scroller - so only horizontal movement | case 'h': /* horizontal scroller - so only horizontal movement | ||||
| * ('cur' moves opposite to mouse) */ | * ('cur' moves opposite to mouse) */ | ||||
| vsm->delta = (float)(event->xy[0] - vsm->lastx); | vsm->delta = float(event->xy[0] - vsm->lastx); | ||||
| break; | break; | ||||
| case 'v': /* vertical scroller - so only vertical movement | case 'v': /* vertical scroller - so only vertical movement | ||||
| * ('cur' moves opposite to mouse) */ | * ('cur' moves opposite to mouse) */ | ||||
| vsm->delta = (float)(event->xy[1] - vsm->lasty); | vsm->delta = float(event->xy[1] - vsm->lasty); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (vsm->zone == SCROLLHANDLE_MIN) { | else if (vsm->zone == SCROLLHANDLE_MIN) { | ||||
| /* using 'min' zoom widget */ | /* using 'min' zoom widget */ | ||||
| switch (vsm->scroller) { | switch (vsm->scroller) { | ||||
| case 'h': /* horizontal scroller - so only horizontal movement | case 'h': /* horizontal scroller - so only horizontal movement | ||||
| * ('cur' moves with mouse) */ | * ('cur' moves with mouse) */ | ||||
| vsm->delta = (float)(vsm->lastx - event->xy[0]); | vsm->delta = float(vsm->lastx - event->xy[0]); | ||||
| break; | break; | ||||
| case 'v': /* vertical scroller - so only vertical movement | case 'v': /* vertical scroller - so only vertical movement | ||||
| * ('cur' moves with to mouse) */ | * ('cur' moves with to mouse) */ | ||||
| vsm->delta = (float)(vsm->lasty - event->xy[1]); | vsm->delta = float(vsm->lasty - event->xy[1]); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* store previous coordinates */ | /* store previous coordinates */ | ||||
| vsm->lastx = event->xy[0]; | vsm->lastx = event->xy[0]; | ||||
| vsm->lasty = event->xy[1]; | vsm->lasty = event->xy[1]; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (in_scroller) { | ||||
| scroller_activate_init(C, op, event, in_scroller); | scroller_activate_init(C, op, event, in_scroller); | ||||
| v2dScrollerMove *vsm = (v2dScrollerMove *)op->customdata; | v2dScrollerMove *vsm = (v2dScrollerMove *)op->customdata; | ||||
| /* Support for quick jump to location - GTK and QT do this on Linux. */ | /* Support for quick jump to location - GTK and QT do this on Linux. */ | ||||
| if (event->type == MIDDLEMOUSE) { | if (event->type == MIDDLEMOUSE) { | ||||
| switch (vsm->scroller) { | switch (vsm->scroller) { | ||||
| case 'h': /* horizontal scroller - so only horizontal movement | case 'h': /* horizontal scroller - so only horizontal movement | ||||
| * ('cur' moves opposite to mouse) */ | * ('cur' moves opposite to mouse) */ | ||||
| vsm->delta = (float)(event->xy[0] - vsm->scrollbar_orig); | vsm->delta = float(event->xy[0] - vsm->scrollbar_orig); | ||||
| break; | break; | ||||
| case 'v': /* vertical scroller - so only vertical movement | case 'v': /* vertical scroller - so only vertical movement | ||||
| * ('cur' moves opposite to mouse) */ | * ('cur' moves opposite to mouse) */ | ||||
| vsm->delta = (float)(event->xy[1] - vsm->scrollbar_orig); | vsm->delta = float(event->xy[1] - vsm->scrollbar_orig); | ||||
| break; | break; | ||||
| } | } | ||||
| scroller_activate_apply(C, op); | scroller_activate_apply(C, op); | ||||
| vsm->zone = SCROLLHANDLE_BAR; | vsm->zone = SCROLLHANDLE_BAR; | ||||
| } | } | ||||
| /* check if zoom zones are inappropriate (i.e. zoom widgets not shown), so cannot continue | /* check if zoom zones are inappropriate (i.e. zoom widgets not shown), so cannot continue | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| static int reset_exec(bContext *C, wmOperator *UNUSED(op)) | static int reset_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| const uiStyle *style = UI_style_get(); | const uiStyle *style = UI_style_get(); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| View2D *v2d = ®ion->v2d; | View2D *v2d = ®ion->v2d; | ||||
| const int snap_test = ED_region_snap_size_test(region); | const int snap_test = ED_region_snap_size_test(region); | ||||
| /* zoom 1.0 */ | /* zoom 1.0 */ | ||||
| const int winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1); | const int winx = float(BLI_rcti_size_x(&v2d->mask) + 1); | ||||
| const int winy = (float)(BLI_rcti_size_y(&v2d->mask) + 1); | const int winy = float(BLI_rcti_size_y(&v2d->mask) + 1); | ||||
| v2d->cur.xmax = v2d->cur.xmin + winx; | v2d->cur.xmax = v2d->cur.xmin + winx; | ||||
| v2d->cur.ymax = v2d->cur.ymin + winy; | v2d->cur.ymax = v2d->cur.ymin + winy; | ||||
| /* align */ | /* align */ | ||||
| if (v2d->align) { | if (v2d->align) { | ||||
| /* posx and negx flags are mutually exclusive, so watch out */ | /* posx and negx flags are mutually exclusive, so watch out */ | ||||
| if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) { | if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) { | ||||
| ▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines | |||||