Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_navigate_zoom.c
| Show First 20 Lines • Show All 364 Lines • ▼ Show 20 Lines | if ((vod->rv3d->persp == RV3D_CAMOB) && | ||||
| (vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) == 0) { | (vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) == 0) { | ||||
| viewzoom_apply_camera(vod, xy, viewzoom, zoom_invert, zoom_to_pos); | viewzoom_apply_camera(vod, xy, viewzoom, zoom_invert, zoom_to_pos); | ||||
| } | } | ||||
| else { | else { | ||||
| viewzoom_apply_3d(vod, xy, viewzoom, zoom_invert, zoom_to_pos); | viewzoom_apply_3d(vod, xy, viewzoom, zoom_invert, zoom_to_pos); | ||||
| } | } | ||||
| } | } | ||||
| static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) | int viewzoom_modal_impl(bContext *C, | ||||
| ViewOpsData *vod, | |||||
| const wmEvent *event, | |||||
| const bool use_cursor_init) | |||||
| { | { | ||||
| ViewOpsData *vod = op->customdata; | |||||
| short event_code = VIEW_PASS; | short event_code = VIEW_PASS; | ||||
| bool use_autokey = false; | bool use_autokey = false; | ||||
| int ret = OPERATOR_RUNNING_MODAL; | int ret = OPERATOR_RUNNING_MODAL; | ||||
| /* execute the events */ | /* execute the events */ | ||||
| if (event->type == TIMER && event->customdata == vod->timer) { | if (event->type == TIMER && event->customdata == vod->timer) { | ||||
| /* continuous zoom */ | /* continuous zoom */ | ||||
| event_code = VIEW_APPLY; | event_code = VIEW_APPLY; | ||||
| Show All 16 Lines | switch (event->val) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { | ||||
| event_code = VIEW_CONFIRM; | event_code = VIEW_CONFIRM; | ||||
| } | } | ||||
| if (event_code == VIEW_APPLY) { | if (event_code == VIEW_APPLY) { | ||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | |||||
| viewzoom_apply(vod, | viewzoom_apply(vod, | ||||
| event->xy, | event->xy, | ||||
| (eViewZoom_Style)U.viewzoom, | (eViewZoom_Style)U.viewzoom, | ||||
| (U.uiflag & USER_ZOOM_INVERT) != 0, | (U.uiflag & USER_ZOOM_INVERT) != 0, | ||||
| (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); | (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); | ||||
| if (ED_screen_animation_playing(CTX_wm_manager(C))) { | if (ED_screen_animation_playing(CTX_wm_manager(C))) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (event_code == VIEW_CONFIRM) { | else if (event_code == VIEW_CONFIRM) { | ||||
| use_autokey = true; | use_autokey = true; | ||||
| ret = OPERATOR_FINISHED; | ret = OPERATOR_FINISHED; | ||||
| } | } | ||||
| if (use_autokey) { | if (use_autokey) { | ||||
| ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); | ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); | ||||
| } | } | ||||
| return ret; | |||||
| } | |||||
| static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) | |||||
| { | |||||
| ViewOpsData *vod = op->customdata; | |||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | |||||
| int ret = viewzoom_modal_impl(C, vod, event, use_cursor_init); | |||||
| if (ret & OPERATOR_FINISHED) { | if (ret & OPERATOR_FINISHED) { | ||||
| ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C); | ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C); | ||||
| viewops_data_free(C, op->customdata); | viewops_data_free(C, op->customdata); | ||||
| op->customdata = NULL; | op->customdata = NULL; | ||||
| } | } | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| static int viewzoom_exec(bContext *C, wmOperator *op) | static void view_zoom_apply_step(bContext *C, | ||||
| Depsgraph *depsgraph, | |||||
| Scene *scene, | |||||
| ScrArea *area, | |||||
| ARegion *region, | |||||
| const int delta, | |||||
| const int zoom_xy[2]) | |||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | View3D *v3d = area->spacedata.first; | ||||
| Scene *scene = CTX_data_scene(C); | RegionView3D *rv3d = region->regiondata; | ||||
| View3D *v3d; | |||||
| RegionView3D *rv3d; | |||||
| ScrArea *area; | |||||
| ARegion *region; | |||||
| bool use_cam_zoom; | bool use_cam_zoom; | ||||
| float dist_range[2]; | float dist_range[2]; | ||||
| const int delta = RNA_int_get(op->ptr, "delta"); | |||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | |||||
| if (op->customdata) { | |||||
| ViewOpsData *vod = op->customdata; | |||||
| area = vod->area; | |||||
| region = vod->region; | |||||
| } | |||||
| else { | |||||
| area = CTX_wm_area(C); | |||||
| region = CTX_wm_region(C); | |||||
| } | |||||
| v3d = area->spacedata.first; | |||||
| rv3d = region->regiondata; | |||||
| use_cam_zoom = (rv3d->persp == RV3D_CAMOB) && | use_cam_zoom = (rv3d->persp == RV3D_CAMOB) && | ||||
| !(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d)); | !(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d)); | ||||
| int zoom_xy_buf[2]; | |||||
| const int *zoom_xy = NULL; | |||||
| if (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { | |||||
| zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : | |||||
| region->winx / 2; | |||||
| zoom_xy_buf[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : | |||||
| region->winy / 2; | |||||
| zoom_xy = zoom_xy_buf; | |||||
| } | |||||
| ED_view3d_dist_range_get(v3d, dist_range); | ED_view3d_dist_range_get(v3d, dist_range); | ||||
| if (delta < 0) { | if (delta < 0) { | ||||
| const float step = 1.2f; | const float step = 1.2f; | ||||
| if (use_cam_zoom) { | if (use_cam_zoom) { | ||||
| view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy); | view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy); | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 17 Lines | static void view_zoom_apply_step(bContext *C, | ||||
| if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { | if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { | ||||
| view3d_boxview_sync(area, region); | view3d_boxview_sync(area, region); | ||||
| } | } | ||||
| ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); | ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); | ||||
| ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true); | ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true); | ||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| ED_view3d_camera_lock_undo_grouped_push(op->type->name, v3d, rv3d, C); | |||||
| viewops_data_free(C, op->customdata); | |||||
| op->customdata = NULL; | |||||
| return OPERATOR_FINISHED; | |||||
| } | } | ||||
| /* viewdolly_invoke() copied this function, changes here may apply there */ | static int viewzoom_exec(bContext *C, wmOperator *op) | ||||
| static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) | |||||
| { | { | ||||
| ViewOpsData *vod; | BLI_assert(op->customdata == NULL); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| ScrArea *area = CTX_wm_area(C); | |||||
| ARegion *region = CTX_wm_region(C); | |||||
| View3D *v3d = area->spacedata.first; | |||||
| RegionView3D *rv3d = region->regiondata; | |||||
| const int delta = RNA_int_get(op->ptr, "delta"); | |||||
| 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"); | ||||
| vod = op->customdata = viewops_data_create( | int zoom_xy_buf[2]; | ||||
| C, | const int *zoom_xy = NULL; | ||||
| event, | const bool do_zoom_to_mouse_pos = (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)); | ||||
| (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | | if (do_zoom_to_mouse_pos) { | ||||
| (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : | ||||
| region->winx / 2; | |||||
| zoom_xy_buf[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : | |||||
| region->winy / 2; | |||||
| zoom_xy = zoom_xy_buf; | |||||
| } | |||||
| ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | view_zoom_apply_step(C, depsgraph, scene, area, region, delta, zoom_xy); | ||||
| ED_view3d_camera_lock_undo_grouped_push(op->type->name, v3d, rv3d, C); | |||||
| /* if one or the other zoom position aren't set, set from event */ | return OPERATOR_FINISHED; | ||||
| if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) { | |||||
| RNA_int_set(op->ptr, "mx", event->xy[0]); | |||||
| RNA_int_set(op->ptr, "my", event->xy[1]); | |||||
| } | } | ||||
| if (RNA_struct_property_is_set(op->ptr, "delta")) { | int viewzoom_invoke_impl(bContext *C, | ||||
| viewzoom_exec(C, op); | ViewOpsData *vod, | ||||
| const int delta, | |||||
| const wmEvent *event, | |||||
| const int zoom_xy[2], | |||||
| const bool use_cursor_init) | |||||
| { | |||||
| const bool do_zoom_to_mouse_pos = (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)); | |||||
| if (delta) { | |||||
| view_zoom_apply_step(C, | |||||
| vod->depsgraph, | |||||
| vod->scene, | |||||
| vod->area, | |||||
| vod->region, | |||||
| delta, | |||||
| do_zoom_to_mouse_pos ? zoom_xy : NULL); | |||||
| return OPERATOR_FINISHED; | |||||
| } | } | ||||
| else { | |||||
| if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { | if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { | ||||
| if (U.uiflag & USER_ZOOM_HORIZ) { | if (U.uiflag & USER_ZOOM_HORIZ) { | ||||
| vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; | vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; | ||||
| } | } | ||||
| else { | else { | ||||
| /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ | /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ | ||||
| vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - | vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - | ||||
| event->prev_xy[0]; | event->prev_xy[0]; | ||||
| } | } | ||||
| viewzoom_apply(vod, | viewzoom_apply(vod, | ||||
| event->prev_xy, | event->prev_xy, | ||||
| USER_ZOOM_DOLLY, | USER_ZOOM_DOLLY, | ||||
| (U.uiflag & USER_ZOOM_INVERT) != 0, | (U.uiflag & USER_ZOOM_INVERT) != 0, | ||||
| (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); | do_zoom_to_mouse_pos); | ||||
| ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); | ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); | ||||
| viewops_data_free(C, op->customdata); | |||||
| op->customdata = NULL; | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| if (U.viewzoom == USER_ZOOM_CONTINUE) { | if (U.viewzoom == USER_ZOOM_CONTINUE) { | ||||
| /* needs a timer to continue redrawing */ | /* needs a timer to continue redrawing */ | ||||
| vod->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); | vod->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); | ||||
| vod->prev.time = PIL_check_seconds_timer(); | vod->prev.time = PIL_check_seconds_timer(); | ||||
| } | } | ||||
| return OPERATOR_RUNNING_MODAL; | |||||
| } | |||||
| /* viewdolly_invoke() copied this function, changes here may apply there */ | |||||
| static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) | |||||
| { | |||||
| ViewOpsData *vod; | |||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | |||||
| vod = op->customdata = viewops_data_create( | |||||
| C, | |||||
| event, | |||||
| (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | | |||||
| (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | |||||
| ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | |||||
| int xy[2]; | |||||
| xy[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : event->xy[0]; | |||||
| xy[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : event->xy[1]; | |||||
| int delta = RNA_struct_property_is_set(op->ptr, "delta") ? RNA_int_get(op->ptr, "delta") : 0; | |||||
| int ret = viewzoom_invoke_impl(C, vod, delta, event, xy, use_cursor_init); | |||||
| if (ret == OPERATOR_RUNNING_MODAL) { | |||||
| /* add temp handler */ | /* add temp handler */ | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| return OPERATOR_FINISHED; | |||||
| viewops_data_free(C, op->customdata); | |||||
| op->customdata = NULL; | |||||
| return ret; | |||||
| } | } | ||||
| static void viewzoom_cancel(bContext *C, wmOperator *op) | static void viewzoom_cancel(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| viewops_data_free(C, op->customdata); | viewops_data_free(C, op->customdata); | ||||
| op->customdata = NULL; | op->customdata = NULL; | ||||
| } | } | ||||
| void VIEW3D_OT_zoom(wmOperatorType *ot) | void VIEW3D_OT_zoom(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Zoom View"; | ot->name = "Zoom View"; | ||||
| ot->description = "Zoom in/out in the view"; | ot->description = "Zoom in/out in the view"; | ||||
| ot->idname = "VIEW3D_OT_zoom"; | ot->idname = op_idnames[V3D_ZOOM]; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = viewzoom_invoke; | ot->invoke = viewzoom_invoke; | ||||
| ot->exec = viewzoom_exec; | ot->exec = viewzoom_exec; | ||||
| ot->modal = viewzoom_modal; | ot->modal = viewzoom_modal; | ||||
| ot->poll = view3d_zoom_or_dolly_poll; | ot->poll = view3d_zoom_or_dolly_poll; | ||||
| ot->cancel = viewzoom_cancel; | ot->cancel = viewzoom_cancel; | ||||
| Show All 9 Lines | |||||