diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_edit.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 181 |
1 files changed, 114 insertions, 67 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index d3bd59cacc8..aab307babe8 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -49,7 +49,6 @@ #include "BKE_camera.h" #include "BKE_context.h" #include "BKE_font.h" -#include "BKE_image.h" #include "BKE_library.h" #include "BKE_object.h" #include "BKE_paint.h" @@ -626,9 +625,9 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) * center, in other cases it's not clear what rotation center shall be * so just rotate around object origin */ - if (ob->mode & OB_MODE_SCULPT) { + if (ob->mode & (OB_MODE_SCULPT | OB_MODE_TEXTURE_PAINT)) { float stroke[3]; - ED_sculpt_stroke_get_average(ob, stroke); + BKE_paint_stroke_get_average(scene, ob, stroke); copy_v3_v3(lastofs, stroke); } else { @@ -1119,6 +1118,8 @@ static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod = op->customdata; short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; /* execute the events */ if (event->type == MOUSEMOVE) { @@ -1153,17 +1154,25 @@ static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event_code == VIEW_APPLY) { viewrotate_apply(vod, event->x, event->y); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } } else if (event_code == VIEW_CONFIRM) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, true); ED_view3d_depth_tag_update(vod->rv3d); + use_autokey = true; + ret = OPERATOR_FINISHED; + } - viewops_data_free(C, op); + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, true); + } - return OPERATOR_FINISHED; + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op); } - return OPERATOR_RUNNING_MODAL; + return ret; } /** @@ -1221,26 +1230,31 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) ED_region_tag_redraw(vod->ar); } - if (event->type == MOUSEPAN) { + if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { /* Rotate direction we keep always same */ - if (U.uiflag2 & USER_TRACKPAD_NATURAL) - viewrotate_apply(vod, 2 * event->x - event->prevx, 2 * event->y - event->prevy); - else - viewrotate_apply(vod, event->prevx, event->prevy); - - ED_view3d_depth_tag_update(vod->rv3d); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; - } - else if (event->type == MOUSEROTATE) { - /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */ - viewrotate_apply(vod, event->prevx, event->y); + int x, y; + + if (event->type == MOUSEPAN) { + if (U.uiflag2 & USER_TRACKPAD_NATURAL) { + x = 2 * event->x - event->prevx; + y = 2 * event->y - event->prevy; + } + else { + x = event->prevx; + y = event->prevy; + } + } + else { + /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */ + x = event->prevx; + y = event->y; + } + + viewrotate_apply(vod, x, y); ED_view3d_depth_tag_update(vod->rv3d); - + viewops_data_free(C, op); - + return OPERATOR_FINISHED; } else { @@ -1946,6 +1960,8 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) ViewOpsData *vod = op->customdata; short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; /* execute the events */ if (event->type == MOUSEMOVE) { @@ -1972,17 +1988,25 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event_code == VIEW_APPLY) { viewmove_apply(vod, event->x, event->y); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } } else if (event_code == VIEW_CONFIRM) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); ED_view3d_depth_tag_update(vod->rv3d); + use_autokey = true; + ret = OPERATOR_FINISHED; + } - viewops_data_free(C, op); + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); + } - return OPERATOR_FINISHED; + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op); } - return OPERATOR_RUNNING_MODAL; + return ret; } static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) @@ -2214,6 +2238,8 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod = op->customdata; short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; /* execute the events */ if (event->type == TIMER && event->customdata == vod->timer) { @@ -2244,16 +2270,25 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event_code == VIEW_APPLY) { viewzoom_apply(vod, &event->x, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } } else if (event_code == VIEW_CONFIRM) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); ED_view3d_depth_tag_update(vod->rv3d); - viewops_data_free(C, op); + use_autokey = true; + ret = OPERATOR_FINISHED; + } - return OPERATOR_FINISHED; + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); + } + + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op); } - return OPERATOR_RUNNING_MODAL; + return ret; } static int viewzoom_exec(bContext *C, wmOperator *op) @@ -2315,6 +2350,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op) ED_view3d_depth_tag_update(rv3d); ED_view3d_camera_lock_sync(v3d, rv3d); + ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true); ED_region_tag_redraw(ar); @@ -2389,8 +2425,10 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) vod->origy = vod->oldy = vod->origy + event->x - event->prevx; viewzoom_apply(vod, &event->prevx, USER_ZOOM_DOLLY, (U.uiflag & USER_ZOOM_INVERT) != 0); } + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); + ED_view3d_depth_tag_update(vod->rv3d); - + viewops_data_free(C, op); return OPERATOR_FINISHED; } @@ -2486,6 +2524,8 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod = op->customdata; short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; /* execute the events */ if (event->type == MOUSEMOVE) { @@ -2512,16 +2552,25 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event_code == VIEW_APPLY) { viewdolly_apply(vod, event->x, event->y, (U.uiflag & USER_ZOOM_INVERT) != 0); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } } else if (event_code == VIEW_CONFIRM) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); ED_view3d_depth_tag_update(vod->rv3d); - viewops_data_free(C, op); + use_autokey = true; + ret = OPERATOR_FINISHED; + } - return OPERATOR_FINISHED; + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); } - return OPERATOR_RUNNING_MODAL; + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op); + } + + return ret; } static int viewdolly_exec(bContext *C, wmOperator *op) @@ -2926,8 +2975,10 @@ static int viewselected_exec(bContext *C, wmOperator *op) else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) { ok = PE_minmax(scene, min, max); } - else if (ob && (ob->mode & OB_MODE_SCULPT)) { - ok = ED_sculpt_minmax(C, min, max); + else if (ob && (ob->mode & (OB_MODE_SCULPT | OB_MODE_TEXTURE_PAINT))) { + BKE_paint_stroke_get_average(scene, ob, min); + copy_v3_v3(max, min); + ok = true; ok_dist = 0; /* don't zoom */ } else { @@ -3970,6 +4021,8 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) { ViewOpsData *vod = op->customdata; short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; /* execute the events */ if (event->type == MOUSEMOVE) { @@ -3996,16 +4049,25 @@ static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) if (event_code == VIEW_APPLY) { viewroll_apply(vod, event->x, event->y); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } } else if (event_code == VIEW_CONFIRM) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, false); ED_view3d_depth_tag_update(vod->rv3d); - viewops_data_free(C, op); + use_autokey = true; + ret = OPERATOR_FINISHED; + } - return OPERATOR_FINISHED; + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, false); } - return OPERATOR_RUNNING_MODAL; + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op); + } + + return ret; } static EnumPropertyItem prop_view_roll_items[] = { @@ -4279,32 +4341,16 @@ static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op)) static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { View3D *v3d = CTX_wm_view3d(C); - Image *ima = NULL; + Image *ima; BGpic *bgpic; - char name[MAX_ID_NAME - 2]; - - /* check input variables */ - if (RNA_struct_property_is_set(op->ptr, "filepath")) { - char path[FILE_MAX]; - - RNA_string_get(op->ptr, "filepath", path); - ima = BKE_image_load_exists(path); - } - else if (RNA_struct_property_is_set(op->ptr, "name")) { - RNA_string_get(op->ptr, "name", name); - ima = (Image *)BKE_libblock_find_name(ID_IM, name); - } + ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM); + /* may be NULL, continue anyway */ + bgpic = background_image_add(C); - - if (ima) { - bgpic->ima = ima; - - id_us_plus(&ima->id); - - if (!(v3d->flag & V3D_DISPBGPICS)) - v3d->flag |= V3D_DISPBGPICS; - } + bgpic->ima = ima; + + v3d->flag |= V3D_DISPBGPICS; WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); @@ -4330,7 +4376,8 @@ void VIEW3D_OT_background_image_add(wmOperatorType *ot) /* properties */ RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Image name to assign"); - RNA_def_string(ot->srna, "filepath", "Path", FILE_MAX, "Filepath", "Path to image file"); + WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); } |