Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2012-06-20 14:28:51 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2012-06-20 14:28:51 +0400
commit4b955a60eda06526e3a793fd9bb3c942b641d877 (patch)
treee5706d5afef06f2b2e09b4022bfb537acf5d24d8 /source/blender/editors/space_clip/clip_editor.c
parentfca0112ba3e534c90fd0afaca9e901bc9c022b47 (diff)
Cleanup up space clip API:
- Remove clip/mask specific size/aspect getters, they shall just use the same size/aspect ratio. - Made size getter (and some other public functions) accept context instead of SpaceClip. Currently only SpaceClip is being get from this context, but later it'll be helpful when adding support of editing mask without opening clip in clip editor (in this case using render resolution for mask would be ideal, but this requires knowing scene in size getter). - Rearrange some functions in clip_editor.c for easier navigation in the file.
Diffstat (limited to 'source/blender/editors/space_clip/clip_editor.c')
-rw-r--r--source/blender/editors/space_clip/clip_editor.c349
1 files changed, 161 insertions, 188 deletions
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,90 +122,12 @@ int ED_space_clip_maskedit_mask_poll(bContext *C)
return FALSE;
}
-/* ******** editing functions ******** */
+/* ******** common editing functions ******** */
-void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *clip)
+void ED_space_clip_get_size(const bContext *C, int *width, int *height)
{
- MovieClip *old_clip;
-
- if (!screen && C)
- screen = CTX_wm_screen(C);
-
- old_clip = sc->clip;
- sc->clip = clip;
-
- if (sc->clip && sc->clip->id.us == 0)
- sc->clip->id.us = 1;
-
- if (screen && sc->view == SC_VIEW_CLIP) {
- ScrArea *area;
- SpaceLink *sl;
-
- for (area = screen->areabase.first; area; area = area->next) {
- for (sl = area->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_CLIP) {
- SpaceClip *cur_sc = (SpaceClip *) sl;
-
- if (cur_sc != sc && cur_sc->view != SC_VIEW_CLIP) {
- if (cur_sc->clip == old_clip || cur_sc->clip == NULL) {
- cur_sc->clip = clip;
- }
- }
- }
- }
- }
- }
-
- if (C)
- WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
-}
-
-MovieClip *ED_space_clip_get_clip(SpaceClip *sc)
-{
- return sc->clip;
-}
-
-Mask *ED_space_clip_get_mask(SpaceClip *sc)
-{
- return sc->mask;
-}
-
-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;
-}
+ SpaceClip *sc = CTX_wm_space_clip(C);
-void ED_space_clip_get_clip_size(SpaceClip *sc, int *width, int *height)
-{
if (!sc->clip) {
*width = *height = 0;
}
@@ -214,40 +136,25 @@ void ED_space_clip_get_clip_size(SpaceClip *sc, int *width, int *height)
}
}
-void ED_space_clip_get_mask_size(SpaceClip *sc, int *width, int *height)
+void ED_space_clip_get_zoom(const bContext *C, float *zoomx, float *zoomy)
{
- /* 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;
+ ARegion *ar = CTX_wm_region(C);
+ int width, height;
- 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);
- *width *= aspx;
- *height *= aspy;
- }
+ *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_mask_aspect(SpaceClip *sc, float *aspx, float *aspy)
+void ED_space_clip_get_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);
+ MovieClip *clip = ED_space_clip_get_clip(sc);
- /* now this is not accounted for! */
-#if 0
- *aspx *= (float)w;
- *aspy *= (float)h;
-#endif
+ if (clip)
+ BKE_movieclip_aspect(clip, aspx, aspy);
+ else
+ *aspx = *aspy = 1.0f;
if (*aspx < *aspy) {
*aspy = *aspy / *aspx;
@@ -259,27 +166,7 @@ void ED_space_clip_get_mask_aspect(SpaceClip *sc, float *aspx, float *aspy)
}
}
-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)
+void ED_space_clip_get_aspect_dimension_aware(SpaceClip *sc, float *aspx, float *aspy)
{
int w, h;
@@ -290,11 +177,11 @@ void ED_space_clip_get_clip_aspect_dimension_aware(SpaceClip *sc, float *aspx, f
* 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);
+ ED_space_clip_get_aspect(sc, aspx, aspy);
+ BKE_movieclip_get_size(sc->clip, &sc->user, &w, &h);
- *aspx *= (float)w;
- *aspy *= (float)h;
+ *aspx *= (float) w;
+ *aspy *= (float) h;
if (*aspx < *aspy) {
*aspy = *aspy / *aspx;
@@ -306,6 +193,48 @@ void ED_space_clip_get_clip_aspect_dimension_aware(SpaceClip *sc, float *aspx, f
}
}
+/* 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;
@@ -329,16 +258,9 @@ void ED_clip_update_frame(const Main *mainp, int 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])
+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;
@@ -346,7 +268,7 @@ static int selected_boundbox(SpaceClip *sc, float min[2], float max[2])
INIT_MINMAX2(min, max);
- ED_space_clip_get_clip_size(sc, &width, &height);
+ ED_space_clip_get_size(C, &width, &height);
track = tracksbase->first;
while (track) {
@@ -383,22 +305,23 @@ static int selected_boundbox(SpaceClip *sc, float min[2], float max[2])
return ok;
}
-int ED_clip_view_selection(SpaceClip *sc, ARegion *ar, int fit)
+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_clip_size(sc, &frame_width, &frame_height);
+ ED_space_clip_get_size(C, &frame_width, &frame_height);
if (frame_width == 0 || frame_height == 0)
return FALSE;
- if (!selected_boundbox(sc, min, max))
+ if (!selected_boundbox(C, 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));
+ 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];
@@ -408,7 +331,7 @@ int ED_clip_view_selection(SpaceClip *sc, ARegion *ar, int fit)
int width, height;
float zoomx, zoomy, newzoom, aspx, aspy;
- ED_space_clip_get_clip_aspect(sc, &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;
@@ -434,7 +357,7 @@ void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[
float aspy = 1.0f / clip->tracking.camera.pixel_aspect;
int width, height;
- ED_space_clip_get_clip_size(sc, &width, &height);
+ BKE_movieclip_get_size(sc->clip, &sc->user, &width, &height);
r_co[0] *= width;
r_co[1] *= height * aspy;
@@ -453,8 +376,8 @@ void ED_clip_point_stable_pos(const bContext *C, float x, float y, float *xr, fl
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);
+ 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);
@@ -485,16 +408,18 @@ void ED_clip_point_stable_pos(const bContext *C, float x, float y, float *xr, fl
* \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])
+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_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);
ED_clip_point_undistorted_pos(sc, co, pos);
pos[2] = 0.0f;
@@ -511,6 +436,87 @@ 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)
+{
+ MovieClip *old_clip;
+
+ if (!screen && C)
+ screen = CTX_wm_screen(C);
+
+ old_clip = sc->clip;
+ sc->clip = clip;
+
+ if (sc->clip && sc->clip->id.us == 0)
+ sc->clip->id.us = 1;
+
+ if (screen && sc->view == SC_VIEW_CLIP) {
+ ScrArea *area;
+ SpaceLink *sl;
+
+ for (area = screen->areabase.first; area; area = area->next) {
+ for (sl = area->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_CLIP) {
+ SpaceClip *cur_sc = (SpaceClip *) sl;
+
+ if (cur_sc != sc && cur_sc->view != SC_VIEW_CLIP) {
+ if (cur_sc->clip == old_clip || cur_sc->clip == NULL) {
+ cur_sc->clip = clip;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (C)
+ WM_event_add_notifier(C, NC_MOVIECLIP | NA_SELECTED, sc->clip);
+}
+
+/* ******** masking editing functions ******** */
+
+Mask *ED_space_clip_get_mask(SpaceClip *sc)
+{
+ return sc->mask;
+}
+
+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);
+ }
+}
+
/* OpenGL draw context */
typedef struct SpaceClipDrawContext {
@@ -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);
- }
-}