Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d_ops.c
| Show First 20 Lines • Show All 2,005 Lines • ▼ Show 20 Lines | |||||
| /* initialize customdata for scroller manipulation operator */ | /* initialize customdata for scroller manipulation operator */ | ||||
| static void scroller_activate_init(bContext *C, | static void scroller_activate_init(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| const wmEvent *event, | const wmEvent *event, | ||||
| const char in_scroller) | const char in_scroller) | ||||
| { | { | ||||
| v2dScrollerMove *vsm; | v2dScrollerMove *vsm; | ||||
| View2DScrollers *scrollers; | View2DScrollers scrollers; | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| View2D *v2d = ®ion->v2d; | View2D *v2d = ®ion->v2d; | ||||
| rctf tot_cur_union; | rctf tot_cur_union; | ||||
| float mask_size; | float mask_size; | ||||
| /* set custom-data for operator */ | /* set custom-data for operator */ | ||||
| vsm = MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove"); | vsm = MEM_callocN(sizeof(v2dScrollerMove), "v2dScrollerMove"); | ||||
| op->customdata = vsm; | op->customdata = vsm; | ||||
| /* set general data */ | /* set general data */ | ||||
| vsm->v2d = v2d; | vsm->v2d = v2d; | ||||
| vsm->region = region; | vsm->region = region; | ||||
| vsm->scroller = in_scroller; | vsm->scroller = in_scroller; | ||||
| /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */ | /* store mouse-coordinates, and convert mouse/screen coordinates to region coordinates */ | ||||
| vsm->lastx = event->x; | vsm->lastx = event->x; | ||||
| vsm->lasty = event->y; | vsm->lasty = event->y; | ||||
| /* 'zone' depends on where mouse is relative to bubble | /* 'zone' depends on where mouse is relative to bubble | ||||
| * - zooming must be allowed on this axis, otherwise, default to pan | * - zooming must be allowed on this axis, otherwise, default to pan | ||||
| */ | */ | ||||
| scrollers = UI_view2d_scrollers_calc(v2d, NULL); | UI_view2d_scrollers_calc(v2d, NULL, &scrollers); | ||||
| /* 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. */ | ||||
| tot_cur_union = v2d->tot; | 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 */ | ||||
| mask_size = (float)BLI_rcti_size_x(&v2d->hor); | 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 */ | ||||
| mask_size = (float)BLI_rcti_size_y(&v2d->vert); | 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; | ||||
| } | } | ||||
| vsm->scrollbarwidth = scrollers->vert_max - scrollers->vert_min; | vsm->scrollbarwidth = scrollers.vert_max - scrollers.vert_min; | ||||
| vsm->scrollbar_orig = ((scrollers->vert_max + scrollers->vert_min) / 2) + region->winrct.ymin; | vsm->scrollbar_orig = ((scrollers.vert_max + scrollers.vert_min) / 2) + region->winrct.ymin; | ||||
| } | } | ||||
| UI_view2d_scrollers_free(scrollers); | |||||
| ED_region_tag_redraw_no_rebuild(region); | ED_region_tag_redraw_no_rebuild(region); | ||||
| } | } | ||||
| /* cleanup temp customdata */ | /* cleanup temp customdata */ | ||||
| static void scroller_activate_exit(bContext *C, wmOperator *op) | static void scroller_activate_exit(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| if (op->customdata) { | if (op->customdata) { | ||||
| v2dScrollerMove *vsm = op->customdata; | v2dScrollerMove *vsm = op->customdata; | ||||
| ▲ Show 20 Lines • Show All 371 Lines • Show Last 20 Lines | |||||