diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_clip.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_editor.c | 24 | ||||
-rw-r--r-- | source/blender/editors/space_clip/clip_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_clip/space_clip.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_clip/tracking_ops.c | 100 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_ops.c | 14 |
6 files changed, 144 insertions, 4 deletions
diff --git a/source/blender/editors/include/ED_clip.h b/source/blender/editors/include/ED_clip.h index 02a8b99c280..7943a17c377 100644 --- a/source/blender/editors/include/ED_clip.h +++ b/source/blender/editors/include/ED_clip.h @@ -63,6 +63,7 @@ int ED_clip_view_selection(struct SpaceClip *sc, struct ARegion *ar, int fit); void ED_clip_point_undistorted_pos(SpaceClip * sc, float co[2], float nco[2]); void ED_clip_point_stable_pos(struct bContext *C, float x, float y, float *xr, float *yr); +void ED_clip_point_stable_pos__reverse(SpaceClip * sc, ARegion *ar, float co[2], float nco[2]); void ED_clip_mouse_pos(struct bContext *C, struct wmEvent *event, float co[2]); int ED_space_clip_texture_buffer_supported(struct SpaceClip *sc); diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index b3ac535ab9d..aceb7a398f9 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -400,6 +400,30 @@ void ED_clip_point_stable_pos(bContext *C, float x, float y, float *xr, float *y } } +/** + * \brief the reverse of ED_clip_point_stable_pos(), gets the marker region coords. + * better name here? view_to_tracker / tracker_to_view or so? + */ +void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, float co[2], float nco[2]) +{ + float zoomx, zoomy; + float pos[3]; + int width, height; + int sx, sy; + + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + ED_space_clip_size(sc, &width, &height); + ED_space_clip_zoom(sc, ar, &zoomx, &zoomy); + + ED_clip_point_undistorted_pos(sc, co, pos); + + /* untested */ + mul_v3_m4v3(pos, sc->stabmat, pos); + + nco[0] = (pos[0] * width * zoomx) + (float)sx; + nco[1] = (pos[1] * height * zoomy) + (float)sy; +} + void ED_clip_mouse_pos(bContext *C, wmEvent *event, float co[2]) { ED_clip_point_stable_pos(C, event->mval[0], event->mval[1], &co[0], &co[1]); diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index f32cb1651a1..00105fb8561 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -134,6 +134,7 @@ void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene); void CLIP_OT_select(struct wmOperatorType *ot); void CLIP_OT_select_all(struct wmOperatorType *ot); void CLIP_OT_select_border(struct wmOperatorType *ot); +void CLIP_OT_select_lasso(struct wmOperatorType *ot); void CLIP_OT_select_circle(struct wmOperatorType *ot); void CLIP_OT_select_grouped(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index a3e17d420b3..448b5da09f3 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -416,6 +416,7 @@ static void clip_operatortypes(void) WM_operatortype_append(CLIP_OT_select); WM_operatortype_append(CLIP_OT_select_all); WM_operatortype_append(CLIP_OT_select_border); + WM_operatortype_append(CLIP_OT_select_lasso); WM_operatortype_append(CLIP_OT_select_circle); WM_operatortype_append(CLIP_OT_select_grouped); @@ -589,8 +590,13 @@ static void clip_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "CLIP_OT_select_circle", CKEY, KM_PRESS, 0, 0); WM_keymap_add_menu(keymap, "CLIP_MT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0); + kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0); + RNA_boolean_set(kmi->ptr, "deselect", FALSE); + kmi = WM_keymap_add_item(keymap, "CLIP_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_SHIFT, 0); + RNA_boolean_set(kmi->ptr, "deselect", TRUE); + /* marker */ - WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "CLIP_OT_add_marker_slide", LEFTMOUSE, KM_CLICK, KM_CTRL, 0); WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", DELKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "CLIP_OT_delete_marker", XKEY, KM_PRESS, KM_SHIFT, 0); diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index fc93bcc0409..14fdadd65c7 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -42,6 +42,7 @@ #include "BLI_math.h" #include "BLI_listbase.h" #include "BLI_rect.h" +#include "BLI_lasso.h" #include "BLI_blenlib.h" #include "BKE_main.h" @@ -943,6 +944,105 @@ void CLIP_OT_select_border(wmOperatorType *ot) WM_operator_properties_gesture_border(ot, TRUE); } + +static int do_lasso_select_mar(bContext *C, int mcords[][2], short moves, short select) +{ + ARegion *ar = CTX_wm_region(C); + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip(sc); + MovieTracking *tracking = &clip->tracking; + MovieTrackingTrack *track; + ListBase *tracksbase = BKE_tracking_get_tracks(tracking); + rcti rect; + int change = FALSE; + + /* get rectangle from operator */ + BLI_lasso_boundbox(&rect, mcords, moves); + + /* do actual selection */ + track = tracksbase->first; + while (track) { + if ((track->flag & TRACK_HIDDEN) == 0) { + if (MARKER_VISIBLE(sc, track, marker)) { + MovieTrackingMarker *marker = BKE_tracking_get_marker(track, sc->user.framenr); + float screen_co[2]; + + /* tracker in screen coords */ + ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co); + + if (BLI_in_rcti(&rect, screen_co[0], screen_co[1]) && + BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED)) + { + BKE_tracking_track_flag(track, TRACK_AREA_ALL, SELECT, !select); + } + + change = TRUE; + } + } + + track = track->next; + } + + if (change) { + BKE_tracking_dopesheet_tag_update(tracking); + + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); + } + + return change; +} + +static int clip_lasso_select_exec(bContext *C, wmOperator *op) +{ + int i = 0; + int mcords[1024][2]; + + RNA_BEGIN (op->ptr, itemptr, "path") + { + float loc[2]; + + RNA_float_get_array(&itemptr, "loc", loc); + mcords[i][0] = (int)loc[0]; + mcords[i][1] = (int)loc[1]; + i++; + if (i >= 1024) break; + } + RNA_END; + + if (i > 1) { + short select; + + select = !RNA_boolean_get(op->ptr, "deselect"); + do_lasso_select_movieclip(C, mcords, i, select); + + return OPERATOR_FINISHED; + } + return OPERATOR_PASS_THROUGH; +} + +void CLIP_OT_select_lasso(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Lasso Select"; + ot->description = "Select markers using lasso selection"; + ot->idname = "CLIP_OT_select_lasso"; + + /* api callbacks */ + ot->invoke = WM_gesture_lasso_invoke; + ot->modal = WM_gesture_lasso_modal; + ot->exec = clip_lasso_select_exec; + ot->poll = ED_space_clip_tracking_poll; + ot->cancel = WM_gesture_lasso_cancel; + + /* flags */ + ot->flag = OPTYPE_UNDO; + + /* properties */ + RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); + RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect rather than select items"); + RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection instead of deselecting everything first"); +} + /********************** circle select operator *********************/ static int marker_inside_ellipse(MovieTrackingMarker *marker, float offset[2], float ellipse[2]) diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 53bf19c04cc..595d1905e16 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -2636,7 +2636,7 @@ static void UV_OT_circle_select(wmOperatorType *ot) /* ******************** lasso select operator **************** */ -static void do_lasso_select_mesh_uv(bContext *C, int mcords[][2], short moves, short select) +static int do_lasso_select_mesh_uv(bContext *C, int mcords[][2], short moves, short select) { Image *ima = CTX_data_edit_image(C); ARegion *ar = CTX_wm_region(C); @@ -2695,6 +2695,7 @@ static void do_lasso_select_mesh_uv(bContext *C, int mcords[][2], short moves, s } } } + if (change) { uv_select_sync_flush(scene->toolsettings, em, select); @@ -2702,6 +2703,8 @@ static void do_lasso_select_mesh_uv(bContext *C, int mcords[][2], short moves, s WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); } } + + return change; } static int uv_lasso_select_exec(bContext *C, wmOperator *op) @@ -2725,9 +2728,14 @@ static int uv_lasso_select_exec(bContext *C, wmOperator *op) short select; select = !RNA_boolean_get(op->ptr, "deselect"); - do_lasso_select_mesh_uv(C, mcords, i, select); - return OPERATOR_FINISHED; + if (do_lasso_select_mesh_uv(C, mcords, i, select)) { + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } + } return OPERATOR_PASS_THROUGH; } |