diff --git a/source/blender/editors/include/ED_clip.h b/source/blender/editors/include/ED_clip.h index 3a9d73ccf10..2670fb5b042 100644 --- a/source/blender/editors/include/ED_clip.h +++ b/source/blender/editors/include/ED_clip.h @@ -42,6 +42,8 @@ struct SpaceClip; struct wmEvent; /* ** clip_editor.c ** */ + +/* common poll functions */ int ED_space_clip_poll(struct bContext *C); int ED_space_clip_view_clip_poll(struct bContext *C); @@ -50,14 +52,10 @@ int ED_space_clip_tracking_poll(struct bContext *C); int ED_space_clip_maskedit_poll(struct bContext *C); int ED_space_clip_maskedit_mask_poll(bContext *C); -struct MovieClip *ED_space_clip_get_clip(struct SpaceClip *sc); -void ED_space_clip_set_clip(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *clip); - -void ED_space_clip_get_zoom(struct SpaceClip *sc, ARegion *ar, float *zoomx, float *zoomy); - -void ED_space_clip_get_clip_size(struct SpaceClip *sc, int *width, int *height); -void ED_space_clip_get_clip_aspect(struct SpaceClip *sc, float *aspx, float *aspy); -void ED_space_clip_get_clip_aspect_dimension_aware(struct SpaceClip *sc, float *aspx, float *aspy); +void ED_space_clip_get_size(const struct bContext *C, int *width, int *height); +void ED_space_clip_get_zoom(const struct bContext *C, float *zoomx, float *zoomy); +void ED_space_clip_get_aspect(struct SpaceClip *sc, float *aspx, float *aspy); +void ED_space_clip_get_aspect_dimension_aware(struct SpaceClip *sc, float *aspx, float *aspy); int ED_space_clip_get_clip_frame_number(struct SpaceClip *sc); @@ -65,18 +63,18 @@ struct ImBuf *ED_space_clip_get_buffer(struct SpaceClip *sc); struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2], float *scale, float *angle); void ED_clip_update_frame(const struct Main *mainp, int cfra); -int ED_clip_view_selection(struct SpaceClip *sc, struct ARegion *ar, int fit); +int ED_clip_view_selection(const struct bContext *C, struct ARegion *ar, int fit); void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[2]); void ED_clip_point_stable_pos(const struct bContext *C, float x, float y, float *xr, float *yr); -void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, const float co[2], float r_co[2]); +void ED_clip_point_stable_pos__reverse(const struct bContext *C, const float co[2], float r_co[2]); void ED_clip_mouse_pos(const struct bContext *C, struct wmEvent *event, float co[2]); int ED_space_clip_check_show_trackedit(struct SpaceClip *sc); int ED_space_clip_check_show_maskedit(struct SpaceClip *sc); -void ED_space_clip_get_mask_size(struct SpaceClip *sc, int *width, int *height); -void ED_space_clip_get_mask_aspect(struct SpaceClip *sc, float *aspx, float *aspy); +struct MovieClip *ED_space_clip_get_clip(struct SpaceClip *sc); +void ED_space_clip_set_clip(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *clip); struct Mask *ED_space_clip_get_mask(struct SpaceClip *sc); void ED_space_clip_set_mask(struct bContext *C, struct SpaceClip *sc, struct Mask *mask); diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index fdf72043464..76fc7126cf2 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -121,7 +121,7 @@ void ED_mask_point_pos__reverse(const bContext *C, float x, float y, float *xr, co[0] = x; co[1] = y; BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co); - ED_clip_point_stable_pos__reverse(sc, ar, co, co); + ED_clip_point_stable_pos__reverse(C, co, co); } else { /* possible other spaces from which mask editing is available */ @@ -137,8 +137,7 @@ void ED_mask_size(const bContext *C, int *width, int *height) ScrArea *sa = CTX_wm_area(C); if (sa && sa->spacedata.first) { if (sa->spacetype == SPACE_CLIP) { - SpaceClip *sc = sa->spacedata.first; - ED_space_clip_get_mask_size(sc, width, height); + ED_space_clip_get_size(C, width, height); return; } else if (sa->spacetype == SPACE_SEQ) { @@ -159,7 +158,7 @@ void ED_mask_aspect(const bContext *C, float *aspx, float *aspy) SpaceClip *sc = CTX_wm_space_clip(C); if (sc) { - ED_space_clip_get_mask_aspect(sc, aspx, aspy); + ED_space_clip_get_aspect(sc, aspx, aspy); } else { /* possible other spaces from which mask editing is available */ @@ -173,13 +172,12 @@ void ED_mask_pixelspace_factor(const bContext *C, float *scalex, float *scaley) SpaceClip *sc = CTX_wm_space_clip(C); if (sc) { - ARegion *ar = CTX_wm_region(C); int width, height; float zoomx, zoomy, aspx, aspy; - ED_space_clip_get_clip_size(sc, &width, &height); - ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); - ED_space_clip_get_clip_aspect(sc, &aspx, &aspy); + ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_zoom(C, &zoomx, &zoomy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); *scalex = ((float)width * aspx) * zoomx; *scaley = ((float)height * aspy) * zoomy; diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index e34823278cb..e619277456e 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -581,8 +581,6 @@ static int circle_select_exec(bContext *C, wmOperator *op) MaskLayer *masklay; int i; - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); int x, y, radius, width, height, mode, change = FALSE; float zoomx, zoomy, offset[2], ellipse[2]; @@ -595,8 +593,8 @@ static int circle_select_exec(bContext *C, wmOperator *op) /* TODO - make generic! - this is SpaceClip only! */ /* compute ellipse and position in unified coordinates */ - ED_space_clip_get_clip_size(sc, &width, &height); - ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); + ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_zoom(C, &zoomx, &zoomy); width = height = MAX2(width, height); ellipse[0] = width * zoomx / radius; diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 9b9e2223ae6..936c462a161 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -1408,19 +1408,23 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, glPopMatrix(); } -void clip_draw_main(SpaceClip *sc, ARegion *ar, Scene *scene) +void clip_draw_main(const bContext *C, ARegion *ar) { + SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); + Scene *scene = CTX_data_scene(C); ImBuf *ibuf; int width, height; float zoomx, zoomy; - /* if no clip, nothing to do */ - if (!clip) - return; + ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_zoom(C, &zoomx, &zoomy); - ED_space_clip_get_clip_size(sc, &width, &height); - ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); + /* if no clip, nothing to do */ + if (!clip) { + ED_region_grid_draw(ar, zoomx, zoomy); + return; + } if (sc->flag & SC_SHOW_STABLE) { float smat[4][4], ismat[4][4]; diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 4dd2f82df02..6aacd4d5450 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -122,7 +122,344 @@ int ED_space_clip_maskedit_mask_poll(bContext *C) return FALSE; } -/* ******** editing functions ******** */ +/* ******** common editing functions ******** */ + +void ED_space_clip_get_size(const bContext *C, int *width, int *height) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + + if (!sc->clip) { + *width = *height = 0; + } + else { + BKE_movieclip_get_size(sc->clip, &sc->user, width, height); + } +} + +void ED_space_clip_get_zoom(const bContext *C, float *zoomx, float *zoomy) +{ + ARegion *ar = CTX_wm_region(C); + int width, height; + + ED_space_clip_get_size(C, &width, &height); + + *zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin) * width); + *zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin) * height); +} + +void ED_space_clip_get_aspect(SpaceClip *sc, float *aspx, float *aspy) +{ + MovieClip *clip = ED_space_clip_get_clip(sc); + + if (clip) + BKE_movieclip_aspect(clip, aspx, aspy); + else + *aspx = *aspy = 1.0f; + + if (*aspx < *aspy) { + *aspy = *aspy / *aspx; + *aspx = 1.0f; + } + else { + *aspx = *aspx / *aspy; + *aspy = 1.0f; + } +} + +void ED_space_clip_get_aspect_dimension_aware(SpaceClip *sc, float *aspx, float *aspy) +{ + int w, h; + + /* most of tools does not require aspect to be returned with dimensions correction + * due to they're invariant to this stuff, but some transformation tools like rotation + * should be aware of aspect correction caused by different resolution in different + * directions. + * mainly this is sued for transformation stuff + */ + + ED_space_clip_get_aspect(sc, aspx, aspy); + BKE_movieclip_get_size(sc->clip, &sc->user, &w, &h); + + *aspx *= (float) w; + *aspy *= (float) h; + + if (*aspx < *aspy) { + *aspy = *aspy / *aspx; + *aspx = 1.0f; + } + else { + *aspx = *aspx / *aspy; + *aspy = 1.0f; + } +} + +/* return current frame number in clip space */ +int ED_space_clip_get_clip_frame_number(SpaceClip *sc) +{ + MovieClip *clip = ED_space_clip_get_clip(sc); + + return BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr); +} + +ImBuf *ED_space_clip_get_buffer(SpaceClip *sc) +{ + if (sc->clip) { + ImBuf *ibuf; + + ibuf = BKE_movieclip_get_postprocessed_ibuf(sc->clip, &sc->user, sc->postproc_flag); + + if (ibuf && (ibuf->rect || ibuf->rect_float)) + return ibuf; + + if (ibuf) + IMB_freeImBuf(ibuf); + } + + return NULL; +} + +ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale, float *angle) +{ + if (sc->clip) { + ImBuf *ibuf; + + ibuf = BKE_movieclip_get_stable_ibuf(sc->clip, &sc->user, loc, scale, angle, sc->postproc_flag); + + if (ibuf && (ibuf->rect || ibuf->rect_float)) + return ibuf; + + if (ibuf) + IMB_freeImBuf(ibuf); + } + + return NULL; +} + +void ED_clip_update_frame(const Main *mainp, int cfra) +{ + wmWindowManager *wm; + wmWindow *win; + + /* image window, compo node users */ + for (wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */ + for (win = wm->windows.first; win; win = win->next) { + ScrArea *sa; + + for (sa = win->screen->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_CLIP) { + SpaceClip *sc = sa->spacedata.first; + + sc->scopes.ok = FALSE; + + BKE_movieclip_user_set_frame(&sc->user, cfra); + } + } + } + } +} + +static int selected_boundbox(const bContext *C, float min[2], float max[2]) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTrackingTrack *track; + int width, height, ok = FALSE; + ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking); + + INIT_MINMAX2(min, max); + + ED_space_clip_get_size(C, &width, &height); + + track = tracksbase->first; + while (track) { + if (TRACK_VIEW_SELECTED(sc, track)) { + MovieTrackingMarker *marker = BKE_tracking_marker_get(track, sc->user.framenr); + + if (marker) { + float pos[3]; + + pos[0] = marker->pos[0] + track->offset[0]; + pos[1] = marker->pos[1] + track->offset[1]; + pos[2] = 0.0f; + + /* undistortion happens for normalized coords */ + if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { + /* undistortion happens for normalized coords */ + ED_clip_point_undistorted_pos(sc, pos, pos); + } + + pos[0] *= width; + pos[1] *= height; + + mul_v3_m4v3(pos, sc->stabmat, pos); + + DO_MINMAX2(pos, min, max); + + ok = TRUE; + } + } + + track = track->next; + } + + return ok; +} + +int ED_clip_view_selection(const bContext *C, ARegion *ar, int fit) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + int w, h, frame_width, frame_height; + float min[2], max[2]; + + ED_space_clip_get_size(C, &frame_width, &frame_height); + + if (frame_width == 0 || frame_height == 0) + return FALSE; + + if (!selected_boundbox(C, min, max)) + return FALSE; + + /* center view */ + clip_view_center_to_point(C, (max[0] + min[0]) / (2 * frame_width), + (max[1] + min[1]) / (2 * frame_height)); + + w = max[0] - min[0]; + h = max[1] - min[1]; + + /* set zoom to see all selection */ + if (w > 0 && h > 0) { + int width, height; + float zoomx, zoomy, newzoom, aspx, aspy; + + ED_space_clip_get_aspect(sc, &aspx, &aspy); + + width = ar->winrct.xmax - ar->winrct.xmin + 1; + height = ar->winrct.ymax - ar->winrct.ymin + 1; + + zoomx = (float)width / w / aspx; + zoomy = (float)height / h / aspy; + + newzoom = 1.0f / power_of_2(1.0f / MIN2(zoomx, zoomy)); + + if (fit || sc->zoom > newzoom) + sc->zoom = newzoom; + } + + return TRUE; +} + +void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[2]) +{ + copy_v2_v2(r_co, co); + + if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { + MovieClip *clip = ED_space_clip_get_clip(sc); + float aspy = 1.0f / clip->tracking.camera.pixel_aspect; + int width, height; + + BKE_movieclip_get_size(sc->clip, &sc->user, &width, &height); + + r_co[0] *= width; + r_co[1] *= height * aspy; + + BKE_tracking_undistort_v2(&clip->tracking, r_co, r_co); + + r_co[0] /= width; + r_co[1] /= height * aspy; + } +} + +void ED_clip_point_stable_pos(const bContext *C, float x, float y, float *xr, float *yr) +{ + ARegion *ar = CTX_wm_region(C); + SpaceClip *sc = CTX_wm_space_clip(C); + int sx, sy, width, height; + float zoomx, zoomy, pos[3], imat[4][4]; + + ED_space_clip_get_zoom(C, &zoomx, &zoomy); + ED_space_clip_get_size(C, &width, &height); + + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + + pos[0] = (x - sx) / zoomx; + pos[1] = (y - sy) / zoomy; + pos[2] = 0.0f; + + invert_m4_m4(imat, sc->stabmat); + mul_v3_m4v3(pos, imat, pos); + + *xr = pos[0] / width; + *yr = pos[1] / height; + + if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + float aspy = 1.0f / tracking->camera.pixel_aspect; + float tmp[2] = {*xr * width, *yr * height * aspy}; + + BKE_tracking_distort_v2(tracking, tmp, tmp); + + *xr = tmp[0] / width; + *yr = tmp[1] / (height * aspy); + } +} + +/** + * \brief the reverse of ED_clip_point_stable_pos(), gets the marker region coords. + * better name here? view_to_track / track_to_view or so? + */ +void ED_clip_point_stable_pos__reverse(const bContext *C, const float co[2], float r_co[2]) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + 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_get_size(C, &width, &height); + ED_space_clip_get_zoom(C, &zoomx, &zoomy); + + ED_clip_point_undistorted_pos(sc, co, pos); + pos[2] = 0.0f; + + /* untested */ + mul_v3_m4v3(pos, sc->stabmat, pos); + + r_co[0] = (pos[0] * width * zoomx) + (float)sx; + r_co[1] = (pos[1] * height * zoomy) + (float)sy; +} + +void ED_clip_mouse_pos(const bContext *C, wmEvent *event, float co[2]) +{ + ED_clip_point_stable_pos(C, event->mval[0], event->mval[1], &co[0], &co[1]); +} + +int ED_space_clip_check_show_trackedit(SpaceClip *sc) +{ + if (sc) { + return ELEM3(sc->mode, SC_MODE_TRACKING, SC_MODE_RECONSTRUCTION, SC_MODE_DISTORTION); + } + + return FALSE; +} + +int ED_space_clip_check_show_maskedit(SpaceClip *sc) +{ + if (sc) { + return sc->mode == SC_MODE_MASKEDIT; + } + + return FALSE; +} + +/* ******** clip editing functions ******** */ + +MovieClip *ED_space_clip_get_clip(SpaceClip *sc) +{ + return sc->clip; +} void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip) { @@ -160,355 +497,24 @@ void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieCl WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip); } -MovieClip *ED_space_clip_get_clip(SpaceClip *sc) -{ - return sc->clip; -} +/* ******** masking editing functions ******** */ Mask *ED_space_clip_get_mask(SpaceClip *sc) { return sc->mask; } -ImBuf *ED_space_clip_get_buffer(SpaceClip *sc) +void ED_space_clip_set_mask(bContext *C, SpaceClip *sc, Mask *mask) { - if (sc->clip) { - ImBuf *ibuf; + sc->mask = mask; - ibuf = BKE_movieclip_get_postprocessed_ibuf(sc->clip, &sc->user, sc->postproc_flag); - - if (ibuf && (ibuf->rect || ibuf->rect_float)) - return ibuf; - - if (ibuf) - IMB_freeImBuf(ibuf); + if (sc->mask && sc->mask->id.us == 0) { + sc->clip->id.us = 1; } - return NULL; -} - -ImBuf *ED_space_clip_get_stable_buffer(SpaceClip *sc, float loc[2], float *scale, float *angle) -{ - if (sc->clip) { - ImBuf *ibuf; - - ibuf = BKE_movieclip_get_stable_ibuf(sc->clip, &sc->user, loc, scale, angle, sc->postproc_flag); - - if (ibuf && (ibuf->rect || ibuf->rect_float)) - return ibuf; - - if (ibuf) - IMB_freeImBuf(ibuf); + if (C) { + WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask); } - - return NULL; -} - -void ED_space_clip_get_clip_size(SpaceClip *sc, int *width, int *height) -{ - if (!sc->clip) { - *width = *height = 0; - } - else { - BKE_movieclip_get_size(sc->clip, &sc->user, width, height); - } -} - -void ED_space_clip_get_mask_size(SpaceClip *sc, int *width, int *height) -{ - /* quite the same as ED_space_clip_size, but it also runs aspect correction on output resolution - * this is needed because mask should be rasterized with exactly the same resolution as - * currently displaying frame and it doesn't have access to aspect correction currently - * used for display. (sergey) - */ - - if (!sc->mask) { - *width = 0; - *height = 0; - } else { - float aspx, aspy; - - ED_space_clip_get_clip_size(sc, width, height); - ED_space_clip_get_clip_aspect(sc, &aspx, &aspy); - - *width *= aspx; - *height *= aspy; - } -} - -void ED_space_clip_get_mask_aspect(SpaceClip *sc, float *aspx, float *aspy) -{ - int w, h; - - ED_space_clip_get_clip_aspect(sc, aspx, aspy); - ED_space_clip_get_clip_size(sc, &w, &h); - - /* now this is not accounted for! */ -#if 0 - *aspx *= (float)w; - *aspy *= (float)h; -#endif - - if (*aspx < *aspy) { - *aspy = *aspy / *aspx; - *aspx = 1.0f; - } - else { - *aspx = *aspx / *aspy; - *aspy = 1.0f; - } -} - -void ED_space_clip_get_zoom(SpaceClip *sc, ARegion *ar, float *zoomx, float *zoomy) -{ - int width, height; - - ED_space_clip_get_clip_size(sc, &width, &height); - - *zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin) * width); - *zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin) * height); -} - -void ED_space_clip_get_clip_aspect(SpaceClip *sc, float *aspx, float *aspy) -{ - MovieClip *clip = ED_space_clip_get_clip(sc); - - if (clip) - BKE_movieclip_aspect(clip, aspx, aspy); - else - *aspx = *aspy = 1.0f; -} - -void ED_space_clip_get_clip_aspect_dimension_aware(SpaceClip *sc, float *aspx, float *aspy) -{ - int w, h; - - /* most of tools does not require aspect to be returned with dimensions correction - * due to they're invariant to this stuff, but some transformation tools like rotation - * should be aware of aspect correction caused by different resolution in different - * directions. - * mainly this is sued for transformation stuff - */ - - ED_space_clip_get_clip_aspect(sc, aspx, aspy); - ED_space_clip_get_clip_size(sc, &w, &h); - - *aspx *= (float)w; - *aspy *= (float)h; - - if (*aspx < *aspy) { - *aspy = *aspy / *aspx; - *aspx = 1.0f; - } - else { - *aspx = *aspx / *aspy; - *aspy = 1.0f; - } -} - -void ED_clip_update_frame(const Main *mainp, int cfra) -{ - wmWindowManager *wm; - wmWindow *win; - - /* image window, compo node users */ - for (wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */ - for (win = wm->windows.first; win; win = win->next) { - ScrArea *sa; - - for (sa = win->screen->areabase.first; sa; sa = sa->next) { - if (sa->spacetype == SPACE_CLIP) { - SpaceClip *sc = sa->spacedata.first; - - sc->scopes.ok = FALSE; - - BKE_movieclip_user_set_frame(&sc->user, cfra); - } - } - } - } -} - -/* return current frame number in clip space */ -int ED_space_clip_get_clip_frame_number(SpaceClip *sc) -{ - MovieClip *clip = ED_space_clip_get_clip(sc); - - return BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr); -} - -static int selected_boundbox(SpaceClip *sc, float min[2], float max[2]) -{ - MovieClip *clip = ED_space_clip_get_clip(sc); - MovieTrackingTrack *track; - int width, height, ok = FALSE; - ListBase *tracksbase = BKE_tracking_get_active_tracks(&clip->tracking); - - INIT_MINMAX2(min, max); - - ED_space_clip_get_clip_size(sc, &width, &height); - - track = tracksbase->first; - while (track) { - if (TRACK_VIEW_SELECTED(sc, track)) { - MovieTrackingMarker *marker = BKE_tracking_marker_get(track, sc->user.framenr); - - if (marker) { - float pos[3]; - - pos[0] = marker->pos[0] + track->offset[0]; - pos[1] = marker->pos[1] + track->offset[1]; - pos[2] = 0.0f; - - /* undistortion happens for normalized coords */ - if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { - /* undistortion happens for normalized coords */ - ED_clip_point_undistorted_pos(sc, pos, pos); - } - - pos[0] *= width; - pos[1] *= height; - - mul_v3_m4v3(pos, sc->stabmat, pos); - - DO_MINMAX2(pos, min, max); - - ok = TRUE; - } - } - - track = track->next; - } - - return ok; -} - -int ED_clip_view_selection(SpaceClip *sc, ARegion *ar, int fit) -{ - int w, h, frame_width, frame_height; - float min[2], max[2]; - - ED_space_clip_get_clip_size(sc, &frame_width, &frame_height); - - if (frame_width == 0 || frame_height == 0) - return FALSE; - - if (!selected_boundbox(sc, min, max)) - return FALSE; - - /* center view */ - clip_view_center_to_point(sc, (max[0] + min[0]) / (2 * frame_width), - (max[1] + min[1]) / (2 * frame_height)); - - w = max[0] - min[0]; - h = max[1] - min[1]; - - /* set zoom to see all selection */ - if (w > 0 && h > 0) { - int width, height; - float zoomx, zoomy, newzoom, aspx, aspy; - - ED_space_clip_get_clip_aspect(sc, &aspx, &aspy); - - width = ar->winrct.xmax - ar->winrct.xmin + 1; - height = ar->winrct.ymax - ar->winrct.ymin + 1; - - zoomx = (float)width / w / aspx; - zoomy = (float)height / h / aspy; - - newzoom = 1.0f / power_of_2(1.0f / MIN2(zoomx, zoomy)); - - if (fit || sc->zoom > newzoom) - sc->zoom = newzoom; - } - - return TRUE; -} - -void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[2]) -{ - copy_v2_v2(r_co, co); - - if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { - MovieClip *clip = ED_space_clip_get_clip(sc); - float aspy = 1.0f / clip->tracking.camera.pixel_aspect; - int width, height; - - ED_space_clip_get_clip_size(sc, &width, &height); - - r_co[0] *= width; - r_co[1] *= height * aspy; - - BKE_tracking_undistort_v2(&clip->tracking, r_co, r_co); - - r_co[0] /= width; - r_co[1] /= height * aspy; - } -} - -void ED_clip_point_stable_pos(const bContext *C, float x, float y, float *xr, float *yr) -{ - ARegion *ar = CTX_wm_region(C); - SpaceClip *sc = CTX_wm_space_clip(C); - int sx, sy, width, height; - float zoomx, zoomy, pos[3], imat[4][4]; - - ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); - ED_space_clip_get_clip_size(sc, &width, &height); - - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); - - pos[0] = (x - sx) / zoomx; - pos[1] = (y - sy) / zoomy; - pos[2] = 0.0f; - - invert_m4_m4(imat, sc->stabmat); - mul_v3_m4v3(pos, imat, pos); - - *xr = pos[0] / width; - *yr = pos[1] / height; - - if (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT) { - MovieClip *clip = ED_space_clip_get_clip(sc); - MovieTracking *tracking = &clip->tracking; - float aspy = 1.0f / tracking->camera.pixel_aspect; - float tmp[2] = {*xr * width, *yr * height * aspy}; - - BKE_tracking_distort_v2(tracking, tmp, tmp); - - *xr = tmp[0] / width; - *yr = tmp[1] / (height * aspy); - } -} - -/** - * \brief the reverse of ED_clip_point_stable_pos(), gets the marker region coords. - * better name here? view_to_track / track_to_view or so? - */ -void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, const float co[2], float r_co[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_get_clip_size(sc, &width, &height); - ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); - - ED_clip_point_undistorted_pos(sc, co, pos); - pos[2] = 0.0f; - - /* untested */ - mul_v3_m4v3(pos, sc->stabmat, pos); - - r_co[0] = (pos[0] * width * zoomx) + (float)sx; - r_co[1] = (pos[1] * height * zoomy) + (float)sy; -} - -void ED_clip_mouse_pos(const bContext *C, wmEvent *event, float co[2]) -{ - ED_clip_point_stable_pos(C, event->mval[0], event->mval[1], &co[0], &co[1]); } /* OpenGL draw context */ @@ -654,36 +660,3 @@ void ED_space_clip_free_texture_buffer(SpaceClip *sc) MEM_freeN(context); } } - -/* ******** masking editing related functions ******** */ - -int ED_space_clip_check_show_trackedit(SpaceClip *sc) -{ - if (sc) { - return ELEM3(sc->mode, SC_MODE_TRACKING, SC_MODE_RECONSTRUCTION, SC_MODE_DISTORTION); - } - - return FALSE; -} - -int ED_space_clip_check_show_maskedit(SpaceClip *sc) -{ - if (sc) { - return sc->mode == SC_MODE_MASKEDIT; - } - - return FALSE; -} - -void ED_space_clip_set_mask(bContext *C, SpaceClip *sc, Mask *mask) -{ - sc->mask = mask; - - if (sc->mask && sc->mask->id.us == 0) { - sc->clip->id.us = 1; - } - - if (C) { - WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask); - } -} diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index 5bc195a1ae2..c61a0baa82e 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -69,7 +69,7 @@ void clip_draw_dopesheet_channels(const struct bContext *C, struct ARegion *ar); void CLIP_OT_dopesheet_select_channel(struct wmOperatorType *ot); /* clip_draw.c */ -void clip_draw_main(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene); +void clip_draw_main(const struct bContext *C, struct ARegion *ar); void clip_draw_grease_pencil(struct bContext *C, int onlyv2d); void clip_draw_curfra_label(struct SpaceClip *sc, float x, float y); @@ -125,7 +125,7 @@ void clip_graph_tracking_iterate(struct SpaceClip *sc, int selected_only, int in void clip_delete_track(struct bContext *C, struct MovieClip *clip, struct ListBase *tracksbase, struct MovieTrackingTrack *track); void clip_delete_marker(struct bContext *C, struct MovieClip *clip, struct ListBase *tracksbase, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker); -void clip_view_center_to_point(struct SpaceClip *sc, float x, float y); +void clip_view_center_to_point(const struct bContext *C, float x, float y); void clip_draw_cfra(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene); void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene); diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index b3f7b221af0..e76edcf0290 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -69,8 +69,10 @@ /******************** view navigation utilities *********************/ -static void sclip_zoom_set(SpaceClip *sc, ARegion *ar, float zoom, float location[2]) +static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) { + SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); float oldzoom = sc->zoom; int width, height; @@ -78,7 +80,7 @@ static void sclip_zoom_set(SpaceClip *sc, ARegion *ar, float zoom, float locatio if (sc->zoom < 0.1f || sc->zoom > 4.0f) { /* check zoom limits */ - ED_space_clip_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); width *= sc->zoom; height *= sc->zoom; @@ -92,22 +94,22 @@ static void sclip_zoom_set(SpaceClip *sc, ARegion *ar, float zoom, float locatio } if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) { - ED_space_clip_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); sc->xof += ((location[0] - 0.5f) * width - sc->xof) * (sc->zoom - oldzoom) / sc->zoom; sc->yof += ((location[1] - 0.5f) * height - sc->yof) * (sc->zoom - oldzoom) / sc->zoom; } } -static void sclip_zoom_set_factor(SpaceClip *sc, ARegion *ar, float zoomfac, float location[2]) +static void sclip_zoom_set_factor(const bContext *C, float zoomfac, float location[2]) { - sclip_zoom_set(sc, ar, sc->zoom*zoomfac, location); + SpaceClip *sc = CTX_wm_space_clip(C); + + sclip_zoom_set(C, sc->zoom * zoomfac, location); } static void sclip_zoom_set_factor_exec(bContext *C, wmEvent *event, float factor) { - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); float location[2], *mpos = NULL; if (event) { @@ -115,7 +117,7 @@ static void sclip_zoom_set_factor_exec(bContext *C, wmEvent *event, float factor mpos = location; } - sclip_zoom_set_factor(sc, ar, factor, mpos); + sclip_zoom_set_factor(C, factor, mpos); ED_region_tag_redraw(CTX_wm_region(C)); } @@ -494,10 +496,7 @@ static void view_zoom_exit(bContext *C, wmOperator *op, int cancel) static int view_zoom_exec(bContext *C, wmOperator *op) { - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); - - sclip_zoom_set_factor(sc, ar, RNA_float_get(op->ptr, "factor"), NULL); + sclip_zoom_set_factor(C, RNA_float_get(op->ptr, "factor"), NULL); ED_region_tag_redraw(CTX_wm_region(C)); @@ -525,8 +524,6 @@ static int view_zoom_invoke(bContext *C, wmOperator *op, wmEvent *event) static int view_zoom_modal(bContext *C, wmOperator *op, wmEvent *event) { - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); ViewZoomData *vpd = op->customdata; float factor; @@ -534,7 +531,7 @@ static int view_zoom_modal(bContext *C, wmOperator *op, wmEvent *event) case MOUSEMOVE: factor = 1.0f + (vpd->x - event->x + vpd->y - event->y) / 300.0f; RNA_float_set(op->ptr, "factor", factor); - sclip_zoom_set(sc, ar, vpd->zoom * factor, vpd->location); + sclip_zoom_set(C, vpd->zoom * factor, vpd->location); ED_region_tag_redraw(CTX_wm_region(C)); break; default: @@ -582,13 +579,11 @@ void CLIP_OT_view_zoom(wmOperatorType *ot) static int view_zoom_in_exec(bContext *C, wmOperator *op) { - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); float location[2]; RNA_float_get_array(op->ptr, "location", location); - sclip_zoom_set_factor(sc, ar, 1.25f, location); + sclip_zoom_set_factor(C, 1.25f, location); ED_region_tag_redraw(CTX_wm_region(C)); @@ -624,13 +619,11 @@ void CLIP_OT_view_zoom_in(wmOperatorType *ot) static int view_zoom_out_exec(bContext *C, wmOperator *op) { - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); float location[2]; RNA_float_get_array(op->ptr, "location", location); - sclip_zoom_set_factor(sc, ar, 0.8f, location); + sclip_zoom_set_factor(C, 0.8f, location); ED_region_tag_redraw(CTX_wm_region(C)); @@ -669,9 +662,8 @@ void CLIP_OT_view_zoom_out(wmOperatorType *ot) static int view_zoom_ratio_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); - sclip_zoom_set(sc, ar, RNA_float_get(op->ptr, "ratio"), NULL); + sclip_zoom_set(C, RNA_float_get(op->ptr, "ratio"), NULL); /* ensure pixel exact locations for draw */ sc->xof = (int) sc->xof; @@ -713,8 +705,8 @@ static int view_all_exec(bContext *C, wmOperator *op) sc = CTX_wm_space_clip(C); ar = CTX_wm_region(C); - ED_space_clip_get_clip_size(sc, &w, &h); - ED_space_clip_get_clip_aspect(sc, &aspx, &aspy); + ED_space_clip_get_size(C, &w, &h); + ED_space_clip_get_aspect(sc, &aspx, &aspy); w = w * aspx; h = h * aspy; @@ -729,7 +721,7 @@ static int view_all_exec(bContext *C, wmOperator *op) zoomx = (float) width / (w + 2 * margin); zoomy = (float) height / (h + 2 * margin); - sclip_zoom_set(sc, ar, MIN2(zoomx, zoomy), NULL); + sclip_zoom_set(C, MIN2(zoomx, zoomy), NULL); } else { if ((w >= width || h >= height) && (width > 0 && height > 0)) { @@ -737,10 +729,10 @@ static int view_all_exec(bContext *C, wmOperator *op) zoomy = (float) height / h; /* find the zoom value that will fit the image in the image space */ - sclip_zoom_set(sc, ar, 1.0f / power_of_2(1.0f / MIN2(zoomx, zoomy)), NULL); + sclip_zoom_set(C, 1.0f / power_of_2(1.0f / MIN2(zoomx, zoomy)), NULL); } else - sclip_zoom_set(sc, ar, 1.0f, NULL); + sclip_zoom_set(C, 1.0f, NULL); } sc->xof = sc->yof = 0.0f; @@ -775,7 +767,7 @@ static int view_selected_exec(bContext *C, wmOperator *UNUSED(op)) sc->xlockof = 0.0f; sc->ylockof = 0.0f; - ED_clip_view_selection(sc, ar, 1); + ED_clip_view_selection(C, ar, 1); ED_region_tag_redraw(CTX_wm_region(C)); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index 1c040c69fa9..d9c9f63e4a3 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -223,13 +223,14 @@ void clip_delete_marker(bContext *C, MovieClip *clip, ListBase *tracksbase, } } -void clip_view_center_to_point(SpaceClip *sc, float x, float y) +void clip_view_center_to_point(const bContext *C, float x, float y) { + SpaceClip *sc = CTX_wm_space_clip(C); int width, height; float aspx, aspy; - ED_space_clip_get_clip_size(sc, &width, &height); - ED_space_clip_get_clip_aspect(sc, &aspx, &aspy); + ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_aspect(sc, &aspx, &aspy); sc->xof = (x - 0.5f) * width * aspx; sc->yof = (y - 0.5f) * height * aspy; diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 49ee6b65256..0a6a4af6960 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -1008,13 +1008,14 @@ static void clip_refresh(const bContext *C, ScrArea *sa) /********************* main region ********************/ /* sets up the fields of the View2D from zoom and offset */ -static void movieclip_main_area_set_view2d(SpaceClip *sc, ARegion *ar) +static void movieclip_main_area_set_view2d(const bContext *C, ARegion *ar) { + SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); float x1, y1, w, h; int width, height, winx, winy; - ED_space_clip_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); w = width; h = height; @@ -1074,11 +1075,54 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar) WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } +static void clip_main_area_draw_mask(const bContext *C, ARegion *ar) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + int x, y; + int width, height; + float zoomx, zoomy; + + /* frame image */ + float maxdim; + float xofs, yofs; + + /* find window pixel coordinates of origin */ + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + + ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_zoom(C, &zoomx, &zoomy); + + /* frame the image */ + maxdim = maxf(width, height); + if (width == height) { + xofs = yofs = 0; + } + else if (width < height) { + xofs = ((height - width) / -2.0f) * zoomx; + yofs = 0.0f; + } + else { /* (width > height) */ + xofs = 0.0f; + yofs = ((width - height) / -2.0f) * zoomy; + } + + /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */ + glPushMatrix(); + glTranslatef(x + xofs, y + yofs, 0); + glScalef(maxdim * zoomx, maxdim * zoomy, 0); + glMultMatrixf(sc->stabmat); + + ED_mask_draw(C, sc->mask_draw_flag, sc->mask_draw_type); + + ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); + + glPopMatrix(); +} + static void clip_main_area_draw(const bContext *C, ARegion *ar) { /* draw entirely, view changes should be handled here */ SpaceClip *sc = CTX_wm_space_clip(C); - Scene *scene = CTX_data_scene(C); MovieClip *clip = ED_space_clip_get_clip(sc); /* if tracking is in progress, we should synchronize framenr from clipuser @@ -1093,7 +1137,7 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar) tmpibuf = ED_space_clip_get_stable_buffer(sc, NULL, NULL, NULL); } - if (ED_clip_view_selection(sc, ar, 0)) { + if (ED_clip_view_selection(C, ar, 0)) { sc->xof += sc->xlockof; sc->yof += sc->ylockof; } @@ -1107,51 +1151,12 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar) glClear(GL_COLOR_BUFFER_BIT); /* data... */ - movieclip_main_area_set_view2d(sc, ar); + movieclip_main_area_set_view2d(C, ar); - clip_draw_main(sc, ar, scene); + clip_draw_main(C, ar); if (sc->mode == SC_MODE_MASKEDIT) { - int x, y; - int width, height; - float zoomx, zoomy, aspx, aspy; - - /* frame image */ - float maxdim; - float xofs, yofs; - - /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); - - ED_space_clip_get_clip_size(sc, &width, &height); - ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); - ED_space_clip_get_clip_aspect(sc, &aspx, &aspy); - - /* frame the image */ - maxdim = maxf(width, height); - if (width == height) { - xofs = yofs = 0; - } - else if (width < height) { - xofs = ((height - width) / -2.0f) * zoomx; - yofs = 0.0f; - } - else { /* (width > height) */ - xofs = 0.0f; - yofs = ((width - height) / -2.0f) * zoomy; - } - - /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */ - glPushMatrix(); - glTranslatef(x + xofs, y + yofs, 0); - glScalef(maxdim * zoomx, maxdim * zoomy, 0); - glMultMatrixf(sc->stabmat); - - ED_mask_draw(C, sc->mask_draw_flag, sc->mask_draw_type); - - ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); - - glPopMatrix(); + clip_main_area_draw_mask(C, ar); } /* Grease Pencil */ diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 8f58df1cb2c..af2847492ad 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -81,8 +81,9 @@ /********************** add marker operator *********************/ -static void add_marker(SpaceClip *sc, float x, float y) +static void add_marker(const bContext *C, float x, float y) { + SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); @@ -90,7 +91,7 @@ static void add_marker(SpaceClip *sc, float x, float y) int width, height; int framenr = ED_space_clip_get_clip_frame_number(sc); - ED_space_clip_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); track = BKE_tracking_track_add(tracking, tracksbase, x, y, framenr, width, height); @@ -106,14 +107,14 @@ static int add_marker_exec(bContext *C, wmOperator *op) float pos[2]; int width, height; - ED_space_clip_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); if (!width || !height) return OPERATOR_CANCELLED; RNA_float_get_array(op->ptr, "location", pos); - add_marker(sc, pos[0], pos[1]); + add_marker(C, pos[0], pos[1]); /* reset offset from locked position, so frame jumping wouldn't be so confusing */ sc->xlockof = 0; @@ -532,7 +533,7 @@ MovieTrackingTrack *tracking_marker_check_slide(bContext *C, wmEvent *event, int int framenr = ED_space_clip_get_clip_frame_number(sc); int action = -1, area = 0, corner = -1; - ED_space_clip_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); if (width == 0 || height == 0) return NULL; @@ -628,7 +629,7 @@ static void *slide_marker_customdata(bContext *C, wmEvent *event) int framenr = ED_space_clip_get_clip_frame_number(sc); int area, action, corner; - ED_space_clip_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); if (width == 0 || height == 0) return NULL; diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index f8f786e549c..0ebb84b3953 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -110,15 +110,16 @@ static int mouse_on_crns(float co[2], float pos[2], float crns[4][2], float epsx return dist < MAX2(epsx, epsy); } -static int track_mouse_area(SpaceClip *sc, float co[2], MovieTrackingTrack *track) +static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack *track) { + SpaceClip *sc = CTX_wm_space_clip(C); int framenr = ED_space_clip_get_clip_frame_number(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_get_clip_size(sc, &width, &height); + ED_space_clip_get_size(C, &width, &height); BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); @@ -235,7 +236,7 @@ static int mouse_select(bContext *C, float co[2], int extend) track = find_nearest_track(sc, tracksbase, co); if (track) { - int area = track_mouse_area(sc, co, track); + int area = track_mouse_area(C, co, track); if (!extend || !TRACK_VIEW_SELECTED(sc, track)) area = TRACK_AREA_ALL; @@ -412,7 +413,6 @@ void CLIP_OT_select_border(wmOperatorType *ot) static int do_lasso_select_marker(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_get_clip(sc); MovieTracking *tracking = &clip->tracking; @@ -435,7 +435,7 @@ static int do_lasso_select_marker(bContext *C, int mcords[][2], short moves, sho float screen_co[2]; /* marker in screen coords */ - ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co); + ED_clip_point_stable_pos__reverse(C, 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)) @@ -520,7 +520,6 @@ static int circle_select_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); - ARegion *ar = CTX_wm_region(C); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *track; ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking); @@ -536,8 +535,8 @@ static int circle_select_exec(bContext *C, wmOperator *op) mode = RNA_int_get(op->ptr, "gesture_mode"); /* compute ellipse and position in unified coordinates */ - ED_space_clip_get_clip_size(sc, &width, &height); - ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); + ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_zoom(C, &zoomx, &zoomy); ellipse[0] = width * zoomx / radius; ellipse[1] = height * zoomy / radius; diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 67e87afc5c3..cedb09e187c 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -183,11 +183,11 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) r_vec[2] = 0.0f; if (t->options & CTX_MOVIECLIP) { - ED_space_clip_get_clip_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); + ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); } else if (t->options & CTX_MASK) { /* TODO - NOT WORKING, this isnt so bad since its only display aspect */ - ED_space_clip_get_mask_aspect(t->sa->spacedata.first, &aspx, &aspy); + ED_space_clip_get_aspect(t->sa->spacedata.first, &aspx, &aspy); } r_vec[0] *= aspx; @@ -254,9 +254,9 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) copy_v2_v2(v, vec); if (t->options & CTX_MOVIECLIP) - ED_space_clip_get_clip_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); + ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); else if (t->options & CTX_MASK) - ED_space_clip_get_mask_aspect(t->sa->spacedata.first, &aspx, &aspy); + ED_space_clip_get_aspect(t->sa->spacedata.first, &aspx, &aspy); v[0] /= aspx; v[1] /= aspy; @@ -317,13 +317,13 @@ void applyAspectRatio(TransInfo *t, float vec[2]) if (t->options & CTX_MOVIECLIP) { - ED_space_clip_get_clip_aspect_dimension_aware(sc, &aspx, &aspy); + ED_space_clip_get_aspect_dimension_aware(sc, &aspx, &aspy); vec[0] /= aspx; vec[1] /= aspy; } else if (t->options & CTX_MASK) { - ED_space_clip_get_mask_aspect(sc, &aspx, &aspy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); vec[0] /= aspx; vec[1] /= aspy; @@ -356,10 +356,10 @@ void removeAspectRatio(TransInfo *t, float vec[2]) float aspx = 1.0f, aspy = 1.0f; if (t->options & CTX_MOVIECLIP) { - ED_space_clip_get_clip_aspect_dimension_aware(sc, &aspx, &aspy); + ED_space_clip_get_aspect_dimension_aware(sc, &aspx, &aspy); } else if (t->options & CTX_MASK) { - ED_space_clip_get_mask_aspect(sc, &aspx, &aspy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); } vec[0] *= aspx; diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index a9716483db7..e924ce15286 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -5736,7 +5736,7 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t) if (t->total == 0) return; - ED_space_clip_get_clip_aspect_dimension_aware(sc, &aspx, &aspy); + ED_space_clip_get_aspect_dimension_aware(sc, &aspx, &aspy); td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransTracking TransData"); td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransTracking TransData2D"); @@ -5992,7 +5992,7 @@ void flushTransTracking(TransInfo *t) int a; float aspx, aspy; - ED_space_clip_get_clip_aspect_dimension_aware(sc, &aspx, &aspy); + ED_space_clip_get_aspect_dimension_aware(sc, &aspx, &aspy); if (t->state == TRANS_CANCEL) cancelTransTracking(t); @@ -6072,7 +6072,7 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, tdm->point = point; copy_m3_m3(tdm->vec, bezt->vec); - ED_space_clip_get_mask_aspect(sc, &aspx, &aspy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); if (propmode || is_sel_point) { int i; @@ -6250,7 +6250,7 @@ void flushTransMasking(TransInfo *t) int a; float aspx, aspy, invx, invy; - ED_space_clip_get_mask_aspect(sc, &aspx, &aspy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); invx = 1.0f / aspx; invy = 1.0f / aspy;