Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_navigate_move.c
| Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | WM_modalkeymap_add_item(keymap, | ||||
| }, | }, | ||||
| VIEWROT_MODAL_SWITCH_ROTATE); | VIEWROT_MODAL_SWITCH_ROTATE); | ||||
| #endif | #endif | ||||
| /* assign map to operators */ | /* assign map to operators */ | ||||
| WM_modalkeymap_assign(keymap, "VIEW3D_OT_move"); | WM_modalkeymap_assign(keymap, "VIEW3D_OT_move"); | ||||
| } | } | ||||
| static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) | int viewmove_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 26 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, false, true); | ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); | ||||
| } | } | ||||
| return ret; | |||||
| } | |||||
| static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) | |||||
| { | |||||
| ViewOpsData *vod = op->customdata; | |||||
| int ret = viewmove_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; | ||||
| } | } | ||||
| int viewmove_invoke_impl(ViewOpsData *vod, const wmEvent *event) | |||||
| { | |||||
| if (event->type == MOUSEPAN) { | |||||
| /* invert it, trackpad scroll follows same principle as 2d windows this way */ | |||||
| viewmove_apply( | |||||
| vod, 2 * event->xy[0] - event->prev_xy[0], 2 * event->xy[1] - event->prev_xy[1]); | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| return OPERATOR_RUNNING_MODAL; | |||||
| } | |||||
| static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| ViewOpsData *vod; | ViewOpsData *vod; | ||||
| 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( | vod = op->customdata = viewops_data_create( | ||||
| C, | C, | ||||
| event, | event, | ||||
| (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | | (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | | ||||
| (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); | ||||
| vod = op->customdata; | vod = op->customdata; | ||||
| ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); | ||||
| if (event->type == MOUSEPAN) { | int ret = viewmove_invoke_impl(vod, event); | ||||
| /* invert it, trackpad scroll follows same principle as 2d windows this way */ | |||||
| viewmove_apply( | |||||
| vod, 2 * event->xy[0] - event->prev_xy[0], 2 * event->xy[1] - event->prev_xy[1]); | |||||
| viewops_data_free(C, op->customdata); | |||||
| op->customdata = NULL; | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| 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 viewmove_cancel(bContext *C, wmOperator *op) | static void viewmove_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_move(wmOperatorType *ot) | void VIEW3D_OT_move(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Pan View"; | ot->name = "Pan View"; | ||||
| ot->description = "Move the view"; | ot->description = "Move the view"; | ||||
| ot->idname = "VIEW3D_OT_move"; | ot->idname = op_idnames[V3D_MOVE]; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = viewmove_invoke; | ot->invoke = viewmove_invoke; | ||||
| ot->modal = viewmove_modal; | ot->modal = viewmove_modal; | ||||
| ot->poll = view3d_location_poll; | ot->poll = view3d_location_poll; | ||||
| ot->cancel = viewmove_cancel; | ot->cancel = viewmove_cancel; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; | ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; | ||||
| /* properties */ | /* properties */ | ||||
| view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); | view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||