[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47945] trunk/blender/source/blender/ editors/space_clip: Move selection operators of Clip Editor into their own file
Sergey Sharybin
sergey.vfx at gmail.com
Fri Jun 15 13:40:10 CEST 2012
Revision: 47945
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47945
Author: nazgul
Date: 2012-06-15 11:40:04 +0000 (Fri, 15 Jun 2012)
Log Message:
-----------
Move selection operators of Clip Editor into their own file
Modified Paths:
--------------
trunk/blender/source/blender/editors/space_clip/CMakeLists.txt
trunk/blender/source/blender/editors/space_clip/clip_intern.h
trunk/blender/source/blender/editors/space_clip/tracking_ops.c
Added Paths:
-----------
trunk/blender/source/blender/editors/space_clip/tracking_select.c
Modified: trunk/blender/source/blender/editors/space_clip/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/space_clip/CMakeLists.txt 2012-06-15 11:15:48 UTC (rev 47944)
+++ trunk/blender/source/blender/editors/space_clip/CMakeLists.txt 2012-06-15 11:40:04 UTC (rev 47945)
@@ -52,6 +52,7 @@
clip_utils.c
space_clip.c
tracking_ops.c
+ tracking_select.c
clip_intern.h
)
Modified: trunk/blender/source/blender/editors/space_clip/clip_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_intern.h 2012-06-15 11:15:48 UTC (rev 47944)
+++ trunk/blender/source/blender/editors/space_clip/clip_intern.h 2012-06-15 11:40:04 UTC (rev 47945)
@@ -131,12 +131,7 @@
void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene);
/* tracking_ops.c */
-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);
+struct MovieTrackingTrack *tracking_marker_check_slide(struct bContext *C, struct wmEvent *event);
void CLIP_OT_add_marker(struct wmOperatorType *ot);
void CLIP_OT_delete_track(struct wmOperatorType *ot);
@@ -182,4 +177,12 @@
void CLIP_OT_copy_tracks(struct wmOperatorType *ot);
void CLIP_OT_paste_tracks(struct wmOperatorType *ot);
+/* tracking_select.c */
+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);
+
#endif /* __CLIP_INTERN_H__ */
Modified: trunk/blender/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/tracking_ops.c 2012-06-15 11:15:48 UTC (rev 47944)
+++ trunk/blender/source/blender/editors/space_clip/tracking_ops.c 2012-06-15 11:40:04 UTC (rev 47945)
@@ -79,8 +79,6 @@
#include "clip_intern.h" // own include
-static float dist_to_crns(float co[2], float pos[2], float crns[4][2]);
-
/********************** add marker operator *********************/
static void add_marker(SpaceClip *sc, float x, float y)
@@ -485,6 +483,74 @@
WM_cursor_set(win, CURSOR_STD);
}
+MovieTrackingTrack *tracking_marker_check_slide(bContext *C, wmEvent *event)
+{
+ SpaceClip *sc = CTX_wm_space_clip(C);
+ MovieClip *clip = ED_space_clip(sc);
+ MovieTrackingTrack *track;
+ int width, height;
+ float co[2];
+ ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking);
+ int framenr = ED_space_clip_clip_framenr(sc);
+
+ ED_space_clip_size(sc, &width, &height);
+
+ if (width == 0 || height == 0)
+ return NULL;
+
+ ED_clip_mouse_pos(C, event, co);
+
+ track = tracksbase->first;
+ while (track) {
+ if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) {
+ MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
+ int ok = FALSE;
+
+ if ((marker->flag & MARKER_DISABLED) == 0) {
+ if (mouse_on_offset(sc, track, marker, co, width, height))
+ ok = TRUE;
+
+ if (!ok && (sc->flag & SC_SHOW_MARKER_SEARCH)) {
+ if (mouse_on_corner(sc, marker, TRACK_AREA_SEARCH, co, 1, width, height)) {
+ ok = TRUE;
+ }
+ else if (mouse_on_corner(sc, marker, TRACK_AREA_SEARCH, co, 0, width, height)) {
+ ok = TRUE;
+ }
+ }
+
+ if (!ok && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
+ /* XXX: need to be real check if affine tracking is enabled, but for now not
+ * sure how to do this, so assume affine tracker is always enabled */
+ if (TRUE) {
+ int corner = get_mouse_pattern_corner(sc, marker, co, width, height);
+
+ if (corner != -1) {
+ ok = TRUE;
+ }
+ }
+ else {
+ if (mouse_on_corner(sc, marker, TRACK_AREA_PAT, co, 1, width, height)) {
+ ok = TRUE;
+ }
+
+ if (!ok && mouse_on_corner(sc, marker, TRACK_AREA_PAT, co, 0, width, height)) {
+ ok = TRUE;
+ }
+ }
+ }
+
+ if (ok)
+ return track;
+ }
+ }
+
+ track = track->next;
+ }
+
+ return NULL;
+}
+
static void *slide_marker_customdata(bContext *C, wmEvent *event)
{
SpaceClip *sc = CTX_wm_space_clip(C);
@@ -810,708 +876,6 @@
"Offset", "Offset in floating point units, 1.0 is the width and height of the image", -FLT_MAX, FLT_MAX);
}
-/********************** mouse select operator *********************/
-
-static int mouse_on_side(float co[2], float x1, float y1, float x2, float y2, float epsx, float epsy)
-{
- if (x1 > x2)
-
- SWAP(float, x1, x2);
-
- if (y1 > y2)
- SWAP(float, y1, y2);
-
- return (co[0] >= x1 - epsx && co[0] <= x2 + epsx) && (co[1] >= y1 - epsy && co[1] <= y2 + epsy);
-}
-
-static int mouse_on_rect(float co[2], float pos[2], float min[2], float max[2], float epsx, float epsy)
-{
- return mouse_on_side(co, pos[0] + min[0], pos[1] + min[1], pos[0] + max[0], pos[1] + min[1], epsx, epsy) ||
- mouse_on_side(co, pos[0] + min[0], pos[1] + min[1], pos[0] + min[0], pos[1] + max[1], epsx, epsy) ||
- mouse_on_side(co, pos[0] + min[0], pos[1] + max[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy) ||
- mouse_on_side(co, pos[0] + max[0], pos[1] + min[1], pos[0] + max[0], pos[1] + max[1], epsx, epsy);
-}
-
-static int mouse_on_crns(float co[2], float pos[2], float crns[4][2], float epsx, float epsy)
-{
- float dist = dist_to_crns(co, pos, crns);
-
- return dist < MAX2(epsx, epsy);
-}
-
-static int track_mouse_area(SpaceClip *sc, float co[2], MovieTrackingTrack *track)
-{
- int framenr = ED_space_clip_clip_framenr(sc);
- MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
- float pat_min[2], pat_max[2];
- float epsx, epsy;
- int width, height;
-
- ED_space_clip_size(sc, &width, &height);
-
- BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
-
- epsx = MIN4(pat_min[0] - marker->search_min[0], marker->search_max[0] - pat_max[0],
- fabsf(pat_min[0]), fabsf(pat_max[0])) / 2;
- epsy = MIN4(pat_min[1] - marker->search_min[1], marker->search_max[1] - pat_max[1],
- fabsf(pat_min[1]), fabsf(pat_max[1])) / 2;
-
- epsx = MAX2(epsx, 2.0f / width);
- epsy = MAX2(epsy, 2.0f / height);
-
- if (sc->flag & SC_SHOW_MARKER_SEARCH) {
- if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy))
- return TRACK_AREA_SEARCH;
- }
-
- if ((marker->flag & MARKER_DISABLED) == 0) {
- if (sc->flag & SC_SHOW_MARKER_PATTERN)
- if (mouse_on_crns(co, marker->pos, marker->pattern_corners, epsx, epsy))
- return TRACK_AREA_PAT;
-
- epsx = 12.0f / width;
- epsy = 12.0f / height;
-
- if (fabsf(co[0] - marker->pos[0] - track->offset[0]) < epsx &&
- fabsf(co[1] - marker->pos[1] - track->offset[1]) <= epsy)
- {
- return TRACK_AREA_POINT;
- }
- }
-
- return TRACK_AREA_NONE;
-}
-
-static float dist_to_rect(float co[2], float pos[2], float min[2], float max[2])
-{
- float d1, d2, d3, d4;
- float p[2] = {co[0] - pos[0], co[1] - pos[1]};
- float v1[2] = {min[0], min[1]}, v2[2] = {max[0], min[1]};
- float v3[2] = {max[0], max[1]}, v4[2] = {min[0], max[1]};
-
- d1 = dist_to_line_segment_v2(p, v1, v2);
- d2 = dist_to_line_segment_v2(p, v2, v3);
- d3 = dist_to_line_segment_v2(p, v3, v4);
- d4 = dist_to_line_segment_v2(p, v4, v1);
-
- return MIN4(d1, d2, d3, d4);
-}
-
-static float dist_to_crns(float co[2], float pos[2], float crns[4][2])
-{
- float d1, d2, d3, d4;
- float p[2] = {co[0] - pos[0], co[1] - pos[1]};
- float *v1 = crns[0], *v2 = crns[1];
- float *v3 = crns[2], *v4 = crns[3];
-
- d1 = dist_to_line_segment_v2(p, v1, v2);
- d2 = dist_to_line_segment_v2(p, v2, v3);
- d3 = dist_to_line_segment_v2(p, v3, v4);
- d4 = dist_to_line_segment_v2(p, v4, v1);
-
- return MIN4(d1, d2, d3, d4);
-}
-
-static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbase, float co[2])
-{
- MovieTrackingTrack *track = NULL, *cur;
- float mindist = 0.0f;
- int framenr = ED_space_clip_clip_framenr(sc);
-
- cur = tracksbase->first;
- while (cur) {
- MovieTrackingMarker *marker = BKE_tracking_marker_get(cur, framenr);
-
- if (((cur->flag & TRACK_HIDDEN) == 0) && MARKER_VISIBLE(sc, cur, marker)) {
- float dist, d1, d2 = FLT_MAX, d3 = FLT_MAX;
-
- /* distance to marker point */
- d1 = sqrtf((co[0] - marker->pos[0] - cur->offset[0]) * (co[0] - marker->pos[0] - cur->offset[0]) +
- (co[1] - marker->pos[1] - cur->offset[1]) * (co[1] - marker->pos[1] - cur->offset[1]));
-
- /* distance to pattern boundbox */
- if (sc->flag & SC_SHOW_MARKER_PATTERN)
- d2 = dist_to_crns(co, marker->pos, marker->pattern_corners);
-
- /* distance to search boundbox */
- if (sc->flag & SC_SHOW_MARKER_SEARCH && TRACK_VIEW_SELECTED(sc, cur))
- d3 = dist_to_rect(co, marker->pos, marker->search_min, marker->search_max);
-
- /* choose minimal distance. useful for cases of overlapped markers. */
- dist = MIN3(d1, d2, d3);
-
- if (track == NULL || dist < mindist) {
- track = cur;
- mindist = dist;
- }
- }
-
- cur = cur->next;
- }
-
- return track;
-}
-
-static int mouse_select(bContext *C, float co[2], int extend)
-{
- SpaceClip *sc = CTX_wm_space_clip(C);
- MovieClip *clip = ED_space_clip(sc);
- MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
- MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
- MovieTrackingTrack *track = NULL; /* selected marker */
-
- track = find_nearest_track(sc, tracksbase, co);
-
- if (track) {
- int area = track_mouse_area(sc, co, track);
-
- if (!extend || !TRACK_VIEW_SELECTED(sc, track))
- area = TRACK_AREA_ALL;
-
- if (extend && TRACK_AREA_SELECTED(track, area)) {
- if (track == act_track)
- BKE_tracking_track_deselect(track, area);
- else
- clip->tracking.act_track = track;
- }
- else {
- if (area == TRACK_AREA_POINT)
- area = TRACK_AREA_ALL;
-
- BKE_tracking_track_select(tracksbase, track, area, extend);
- clip->tracking.act_track = track;
- }
- }
-
- if (!extend) {
- sc->xlockof = 0.0f;
- sc->ylockof = 0.0f;
- }
-
- BKE_tracking_dopesheet_tag_update(tracking);
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list