Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_navigate_rotate.c
| Show First 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | #endif | ||||
| vod->prev.event_xy[0] = event_xy[0]; | vod->prev.event_xy[0] = event_xy[0]; | ||||
| vod->prev.event_xy[1] = event_xy[1]; | vod->prev.event_xy[1] = event_xy[1]; | ||||
| ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, rv3d); | ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, rv3d); | ||||
| ED_region_tag_redraw(vod->region); | ED_region_tag_redraw(vod->region); | ||||
| } | } | ||||
| static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) | int viewrotate_modal_impl(bContext *C, ViewOpsData *vod, const wmEvent *event) | ||||
| { | { | ||||
| 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 == MOUSEMOVE) { | if (event->type == MOUSEMOVE) { | ||||
| event_code = VIEW_APPLY; | event_code = VIEW_APPLY; | ||||
| } | } | ||||
| Show All 35 Lines | 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, true, true); | ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, true); | ||||
| } | } | ||||
| return ret; | |||||
| } | |||||
| static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) | |||||
| { | |||||
| ViewOpsData *vod = op->customdata; | |||||
| int ret = viewrotate_modal_impl(C, vod, event); | |||||
| 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 viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) | int viewrotate_invoke_impl(ViewOpsData *vod, const wmEvent *event) | ||||
| { | { | ||||
| ViewOpsData *vod; | |||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | |||||
| /* makes op->customdata */ | |||||
| vod = op->customdata = viewops_data_create( | |||||
| C, | |||||
| event, | |||||
| viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | | |||||
| (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | |||||
| ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | |||||
| if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { | if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { | ||||
| /* Rotate direction we keep always same */ | /* Rotate direction we keep always same */ | ||||
| int event_xy[2]; | int event_xy[2]; | ||||
| if (event->type == MOUSEPAN) { | if (event->type == MOUSEPAN) { | ||||
| if (event->flag & WM_EVENT_SCROLL_INVERT) { | if (event->flag & WM_EVENT_SCROLL_INVERT) { | ||||
| event_xy[0] = 2 * event->xy[0] - event->prev_xy[0]; | event_xy[0] = 2 * event->xy[0] - event->prev_xy[0]; | ||||
| event_xy[1] = 2 * event->xy[1] - event->prev_xy[1]; | event_xy[1] = 2 * event->xy[1] - event->prev_xy[1]; | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v2_v2_int(event_xy, event->prev_xy); | copy_v2_v2_int(event_xy, event->prev_xy); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */ | /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */ | ||||
| copy_v2_v2_int(event_xy, event->prev_xy); | copy_v2_v2_int(event_xy, event->prev_xy); | ||||
| } | } | ||||
| viewrotate_apply(vod, event_xy); | viewrotate_apply(vod, event_xy); | ||||
| viewops_data_free(C, op->customdata); | |||||
| op->customdata = NULL; | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| return OPERATOR_RUNNING_MODAL; | |||||
| } | |||||
| static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) | |||||
| { | |||||
| ViewOpsData *vod; | |||||
| const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); | |||||
| /* makes op->customdata */ | |||||
| vod = op->customdata = viewops_data_create( | |||||
| C, | |||||
| event, | |||||
| viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | | |||||
| (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | |||||
| ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | |||||
| int ret = viewrotate_invoke_impl(vod, event); | |||||
| 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; | ||||
| } | } | ||||
| viewops_data_free(C, op->customdata); | |||||
| op->customdata = NULL; | |||||
| return ret; | |||||
| } | |||||
| static void viewrotate_cancel(bContext *C, wmOperator *op) | static void viewrotate_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_rotate(wmOperatorType *ot) | void VIEW3D_OT_rotate(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Rotate View"; | ot->name = "Rotate View"; | ||||
| ot->description = "Rotate the view"; | ot->description = "Rotate the view"; | ||||
| ot->idname = "VIEW3D_OT_rotate"; | ot->idname = op_idnames[V3D_ROTATE]; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = viewrotate_invoke; | ot->invoke = viewrotate_invoke; | ||||
| ot->modal = viewrotate_modal; | ot->modal = viewrotate_modal; | ||||
| ot->poll = view3d_rotation_poll; | ot->poll = view3d_rotation_poll; | ||||
| ot->cancel = viewrotate_cancel; | ot->cancel = viewrotate_cancel; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; | ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; | ||||
| view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); | view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||