Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d_ops.cc
| Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | struct v2dViewPanData { | ||||||||
| /* options for version 1 */ | /* options for version 1 */ | ||||||||
| /** mouse x/y values in window when operator was initiated */ | /** mouse x/y values in window when operator was initiated */ | ||||||||
| int startx, starty; | int startx, starty; | ||||||||
| /** previous x/y values of mouse in window */ | /** previous x/y values of mouse in window */ | ||||||||
| int lastx, lasty; | int lastx, lasty; | ||||||||
| /** event starting pan, for modal exit */ | /** event starting pan, for modal exit */ | ||||||||
| int invoke_event; | int invoke_event; | ||||||||
| /** Tag if the scroll is done in the category tab. */ | |||||||||
| bool do_category_scroll; | |||||||||
| /** for MMB in scrollers (old feature in past, but now not that useful) */ | /** for MMB in scrollers (old feature in past, but now not that useful) */ | ||||||||
| short in_scroller; | short in_scroller; | ||||||||
| /* View2D Edge Panning */ | /* View2D Edge Panning */ | ||||||||
| double edge_pan_last_time; | double edge_pan_last_time; | ||||||||
| double edge_pan_start_time_x, edge_pan_start_time_y; | double edge_pan_start_time_x, edge_pan_start_time_y; | ||||||||
| }; | }; | ||||||||
| Show All 35 Lines | static void view_pan_init(bContext *C, wmOperator *op) | ||||||||
| /* calculate translation factor - based on size of view */ | /* calculate translation factor - based on size of view */ | ||||||||
| const float winx = (float)(BLI_rcti_size_x(&vpd->region->winrct) + 1); | const float winx = (float)(BLI_rcti_size_x(&vpd->region->winrct) + 1); | ||||||||
| const float winy = (float)(BLI_rcti_size_y(&vpd->region->winrct) + 1); | const float winy = (float)(BLI_rcti_size_y(&vpd->region->winrct) + 1); | ||||||||
| vpd->facx = (BLI_rctf_size_x(&vpd->v2d->cur)) / winx; | vpd->facx = (BLI_rctf_size_x(&vpd->v2d->cur)) / winx; | ||||||||
| vpd->facy = (BLI_rctf_size_y(&vpd->v2d->cur)) / winy; | vpd->facy = (BLI_rctf_size_y(&vpd->v2d->cur)) / winy; | ||||||||
| vpd->v2d->flag |= V2D_IS_NAVIGATING; | vpd->v2d->flag |= V2D_IS_NAVIGATING; | ||||||||
| vpd->do_category_scroll = false; | |||||||||
| } | } | ||||||||
| /* apply transform to view (i.e. adjust 'cur' rect) */ | /* apply transform to view (i.e. adjust 'cur' rect) */ | ||||||||
| static void view_pan_apply_ex(bContext *C, v2dViewPanData *vpd, float dx, float dy) | static void view_pan_apply_ex(bContext *C, v2dViewPanData *vpd, float dx, float dy) | ||||||||
| { | { | ||||||||
| View2D *v2d = vpd->v2d; | View2D *v2d = vpd->v2d; | ||||||||
| /* calculate amount to move view by */ | /* calculate amount to move view by */ | ||||||||
| dx *= vpd->facx; | dx *= vpd->facx; | ||||||||
| dy *= vpd->facy; | dy *= vpd->facy; | ||||||||
| if (!vpd->do_category_scroll) { | |||||||||
| /* only move view on an axis if change is allowed */ | /* only move view on an axis if change is allowed */ | ||||||||
| if ((v2d->keepofs & V2D_LOCKOFS_X) == 0) { | if ((v2d->keepofs & V2D_LOCKOFS_X) == 0) { | ||||||||
| v2d->cur.xmin += dx; | v2d->cur.xmin += dx; | ||||||||
| v2d->cur.xmax += dx; | v2d->cur.xmax += dx; | ||||||||
| } | } | ||||||||
| if ((v2d->keepofs & V2D_LOCKOFS_Y) == 0) { | if ((v2d->keepofs & V2D_LOCKOFS_Y) == 0) { | ||||||||
| v2d->cur.ymin += dy; | v2d->cur.ymin += dy; | ||||||||
| v2d->cur.ymax += dy; | v2d->cur.ymax += dy; | ||||||||
| } | } | ||||||||
| } | |||||||||
| else { | |||||||||
| vpd->region->category_scroll -= dy; | |||||||||
| } | |||||||||
| /* 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); | ||||||||
| /* don't rebuild full tree in outliner, since we're just changing our view */ | /* don't rebuild full tree in outliner, since we're just changing our view */ | ||||||||
| ED_region_tag_redraw_no_rebuild(vpd->region); | ED_region_tag_redraw_no_rebuild(vpd->region); | ||||||||
| /* request updates to be done... */ | /* request updates to be done... */ | ||||||||
| Show All 27 Lines | |||||||||
| static int view_pan_exec(bContext *C, wmOperator *op) | static int view_pan_exec(bContext *C, wmOperator *op) | ||||||||
| { | { | ||||||||
| view_pan_init(C, op); | view_pan_init(C, op); | ||||||||
| view_pan_apply(C, op); | view_pan_apply(C, op); | ||||||||
| view_pan_exit(op); | view_pan_exit(op); | ||||||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||||||
| } | } | ||||||||
| /* Check if the mouse is on the category tab. */ | |||||||||
| bool in_category_tab(ARegion *region, int mvalx) | |||||||||
| { | |||||||||
| if (region->runtime.category && !BLI_listbase_is_empty(®ion->panels_category)) { | |||||||||
| const PanelCategoryDyn *pc_dyn = static_cast<PanelCategoryDyn *>( | |||||||||
| region->panels_category.first); | |||||||||
| const bool inside_category_tab = (mvalx < pc_dyn->rect.xmax) && (mvalx > pc_dyn->rect.xmin); | |||||||||
HooglyBoogly: Just a bit more obvious this way | |||||||||
| return inside_category_tab; | |||||||||
Done Inline Actions
HooglyBoogly: | |||||||||
| } | |||||||||
| return false; | |||||||||
| } | |||||||||
| /* set up modal operator and relevant settings */ | /* set up modal operator and relevant settings */ | ||||||||
| static int view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||||||
| { | { | ||||||||
| wmWindow *window = CTX_wm_window(C); | wmWindow *window = CTX_wm_window(C); | ||||||||
| /* set up customdata */ | /* set up customdata */ | ||||||||
| view_pan_init(C, op); | view_pan_init(C, op); | ||||||||
| v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata); | v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata); | ||||||||
| View2D *v2d = vpd->v2d; | View2D *v2d = vpd->v2d; | ||||||||
| /* set initial settings */ | /* set initial settings */ | ||||||||
| vpd->startx = vpd->lastx = event->xy[0]; | vpd->startx = vpd->lastx = event->xy[0]; | ||||||||
| vpd->starty = vpd->lasty = event->xy[1]; | vpd->starty = vpd->lasty = event->xy[1]; | ||||||||
| vpd->invoke_event = event->type; | vpd->invoke_event = event->type; | ||||||||
| vpd->do_category_scroll = in_category_tab(vpd->region, event->mval[0]); | |||||||||
| if (event->type == MOUSEPAN) { | if (event->type == MOUSEPAN) { | ||||||||
| RNA_int_set(op->ptr, "deltax", event->prev_xy[0] - event->xy[0]); | RNA_int_set(op->ptr, "deltax", event->prev_xy[0] - event->xy[0]); | ||||||||
| RNA_int_set(op->ptr, "deltay", event->prev_xy[1] - event->xy[1]); | RNA_int_set(op->ptr, "deltay", event->prev_xy[1] - event->xy[1]); | ||||||||
| view_pan_apply(C, op); | view_pan_apply(C, op); | ||||||||
| view_pan_exit(op); | view_pan_exit(op); | ||||||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||||||
| ▲ Show 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | static int view_scrolldown_exec(bContext *C, wmOperator *op) | ||||||||
| /* also, check if can pan in vertical axis */ | /* also, check if can pan in vertical axis */ | ||||||||
| v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata); | v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata); | ||||||||
| if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) { | if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) { | ||||||||
| view_pan_exit(op); | view_pan_exit(op); | ||||||||
| return OPERATOR_PASS_THROUGH; | return OPERATOR_PASS_THROUGH; | ||||||||
| } | } | ||||||||
| /* Check if category scrolling is being performed. | |||||||||
| * Although mouse wheel events are not set in event_last_handled, | |||||||||
Not Done Inline Actions"correctly" is vague here-- it would be better to be more specific or to avoid the comment in the first place. HooglyBoogly: "correctly" is vague here-- it would be better to be more specific or to avoid the comment in… | |||||||||
Done Inline ActionsNow the comment is clearer, I think it's good to be aware of what happens with the variable guishe: Now the comment is clearer, I think it's good to be aware of what happens with the variable | |||||||||
| * any event set here works fine to get the last mouse position. */ | |||||||||
| wmWindow *win = CTX_wm_window(C); | |||||||||
| wmEvent *event = win->event_last_handled; | |||||||||
Done Inline ActionsBased on the format here, it looks like the patch is missing clang format HooglyBoogly: Based on the format here, it looks like the patch is missing [[ https://wiki.blender. | |||||||||
Done Inline ActionsFixed guishe: Fixed | |||||||||
| if (event != nullptr) { | |||||||||
| vpd->do_category_scroll = in_category_tab(vpd->region, event->mval[0]); | |||||||||
| } | |||||||||
| /* set RNA-Props */ | /* set RNA-Props */ | ||||||||
| RNA_int_set(op->ptr, "deltax", 0); | RNA_int_set(op->ptr, "deltax", 0); | ||||||||
| RNA_int_set(op->ptr, "deltay", -40); | RNA_int_set(op->ptr, "deltay", -40); | ||||||||
| PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page"); | PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page"); | ||||||||
| if (RNA_property_is_set(op->ptr, prop) && RNA_property_boolean_get(op->ptr, prop)) { | if (RNA_property_is_set(op->ptr, prop) && RNA_property_boolean_get(op->ptr, prop)) { | ||||||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||||||
| RNA_int_set(op->ptr, "deltay", region->v2d.mask.ymin - region->v2d.mask.ymax); | RNA_int_set(op->ptr, "deltay", region->v2d.mask.ymin - region->v2d.mask.ymax); | ||||||||
| Show All 31 Lines | static int view_scrollup_exec(bContext *C, wmOperator *op) | ||||||||
| /* also, check if can pan in vertical axis */ | /* also, check if can pan in vertical axis */ | ||||||||
| v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata); | v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata); | ||||||||
| if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) { | if (vpd->v2d->keepofs & V2D_LOCKOFS_Y) { | ||||||||
| view_pan_exit(op); | view_pan_exit(op); | ||||||||
| return OPERATOR_PASS_THROUGH; | return OPERATOR_PASS_THROUGH; | ||||||||
| } | } | ||||||||
| /* Check if category scrolling is being performed. | |||||||||
| * Although mouse wheel events are not set in event_last_handled, | |||||||||
| * any event set here works fine to get the last mouse position. */ | |||||||||
| wmWindow *win = CTX_wm_window(C); | |||||||||
| wmEvent *event = win->event_last_handled; | |||||||||
| if (event != nullptr) { | |||||||||
| vpd->do_category_scroll = in_category_tab(vpd->region, event->mval[0]); | |||||||||
| } | |||||||||
| /* set RNA-Props */ | /* set RNA-Props */ | ||||||||
| RNA_int_set(op->ptr, "deltax", 0); | RNA_int_set(op->ptr, "deltax", 0); | ||||||||
| RNA_int_set(op->ptr, "deltay", 40); | RNA_int_set(op->ptr, "deltay", 40); | ||||||||
| PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page"); | PropertyRNA *prop = RNA_struct_find_property(op->ptr, "page"); | ||||||||
| if (RNA_property_is_set(op->ptr, prop) && RNA_property_boolean_get(op->ptr, prop)) { | if (RNA_property_is_set(op->ptr, prop) && RNA_property_boolean_get(op->ptr, prop)) { | ||||||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||||||
| RNA_int_set(op->ptr, "deltay", BLI_rcti_size_y(®ion->v2d.mask)); | RNA_int_set(op->ptr, "deltay", BLI_rcti_size_y(®ion->v2d.mask)); | ||||||||
| ▲ Show 20 Lines • Show All 1,631 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); | ||||||||
| region->category_scroll = 0; | |||||||||
| /* 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 */ | ||||||||
| ▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines | |||||||||
Just a bit more obvious this way