wip mask/image commit, mostly internal function & added some TODO's
authorCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 10:39:54 +0000 (10:39 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 10:39:54 +0000 (10:39 +0000)
source/blender/editors/include/ED_clip.h
source/blender/editors/include/ED_image.h
source/blender/editors/mask/mask_edit.c
source/blender/editors/mask/mask_ops.c
source/blender/editors/mask/mask_select.c
source/blender/editors/space_image/image_edit.c

index 2670fb5b04203fa51f089998ec885030ecb2f78e..8949eb8442da64ef58396fccc9109840bb8ae1a0 100644 (file)
@@ -65,7 +65,7 @@ struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2]
 void ED_clip_update_frame(const struct Main *mainp, int cfra);
 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_undistorted_pos(struct 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(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]);
index 915d93c74308a1e1cefd9a3d898edc30f53f9094..c07d6e699a80aec792ae055b369e0ea6c2cd6760 100644 (file)
@@ -42,7 +42,9 @@ struct ARegion;
 
 /* image_edit.c, exported for transform */
 struct Image *ED_space_image(struct SpaceImage *sima);
-void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit, struct Image *ima);
+void          ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit, struct Image *ima);
+struct Mask  *ED_space_image_get_mask(struct SpaceImage *sima);
+void          ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask);
 
 struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **lock_r);
 void ED_space_image_release_buffer(struct SpaceImage *sima, void *lock);
@@ -65,6 +67,10 @@ int ED_space_image_show_paint(struct SpaceImage *sima);
 int ED_space_image_show_uvedit(struct SpaceImage *sima, struct Object *obedit);
 int ED_space_image_show_uvshadow(struct SpaceImage *sima, struct Object *obedit);
 
+int ED_space_image_check_show_maskedit(struct SpaceImage *sima);
+int ED_space_image_maskedit_poll(struct bContext *C);
+int ED_space_image_maskedit_mask_poll(struct bContext *C);
+
 /* UI level image (texture) updating... render calls own stuff (too) */
 void ED_image_update_frame(const struct Main *mainp, int cfra);
 
index a739d88dbd40f006548845c58e9ab77bba4cc458..5837a8eaa837f0f6fc0b242beb934b692f76fd85 100644 (file)
@@ -63,6 +63,8 @@ int ED_maskedit_poll(bContext *C)
                                return ED_space_clip_maskedit_poll(C);
                        case SPACE_SEQ:
                                return ED_space_sequencer_maskedit_poll(C);
+                       case SPACE_IMAGE:
+                               return ED_space_image_maskedit_poll(C);
                }
        }
        return FALSE;
@@ -77,6 +79,8 @@ int ED_maskedit_mask_poll(bContext *C)
                                return ED_space_clip_maskedit_mask_poll(C);
                        case SPACE_SEQ:
                                return ED_space_sequencer_maskedit_mask_poll(C);
+                       case SPACE_IMAGE:
+                               return ED_space_sequencer_maskedit_mask_poll(C);
                }
        }
        return FALSE;
@@ -86,14 +90,31 @@ int ED_maskedit_mask_poll(bContext *C)
 
 void ED_mask_mouse_pos(const bContext *C, wmEvent *event, float co[2])
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
-
-       if (sc) {
-               ED_clip_mouse_pos(C, event, co);
-               BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
+       ScrArea *sa = CTX_wm_area(C);
+       if (sa) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                       {
+                               SpaceClip *sc = sa->spacedata.first;
+                               ED_clip_mouse_pos(C, event, co);
+                               BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
+                               break;
+                       }
+                       case SPACE_SEQ:
+                               zero_v2(co); /* MASKTODO */
+                               break;
+                       case SPACE_IMAGE:
+                               zero_v2(co); /* MASKTODO */
+                               break;
+                       default:
+                               /* possible other spaces from which mask editing is available */
+                               BLI_assert(0);
+                               zero_v2(co);
+                               break;
+               }
        }
        else {
-               /* possible other spaces from which mask editing is available */
+               BLI_assert(0);
                zero_v2(co);
        }
 }
@@ -102,15 +123,33 @@ void ED_mask_mouse_pos(const bContext *C, wmEvent *event, float co[2])
  * output: xr/yr - mask point space */
 void ED_mask_point_pos(const bContext *C, float x, float y, float *xr, float *yr)
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
+       ScrArea *sa = CTX_wm_area(C);
        float co[2];
 
-       if (sc) {
-               ED_clip_point_stable_pos(C, x, y, &co[0], &co[1]);
-               BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
+       if (sa) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                       {
+                               SpaceClip *sc = sa->spacedata.first;
+                               ED_clip_point_stable_pos(C, x, y, &co[0], &co[1]);
+                               BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
+                               break;
+                       }
+                       case SPACE_SEQ:
+                               zero_v2(co); /* MASKTODO */
+                               break;
+                       case SPACE_IMAGE:
+                               zero_v2(co); /* MASKTODO */
+                               break;
+                       default:
+                               /* possible other spaces from which mask editing is available */
+                               BLI_assert(0);
+                               zero_v2(co);
+                               break;
+               }
        }
        else {
-               /* possible other spaces from which mask editing is available */
+               BLI_assert(0);
                zero_v2(co);
        }
 
@@ -120,19 +159,35 @@ void ED_mask_point_pos(const bContext *C, float x, float y, float *xr, float *yr
 
 void ED_mask_point_pos__reverse(const bContext *C, float x, float y, float *xr, float *yr)
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
-       ARegion *ar = CTX_wm_region(C);
-
+       ScrArea *sa = CTX_wm_area(C);
        float co[2];
 
-       if (sc && ar) {
-               co[0] = x;
-               co[1] = y;
-               BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co);
-               ED_clip_point_stable_pos__reverse(C, co, co);
+       if (sa) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                       {
+                               SpaceClip *sc = sa->spacedata.first;
+                               co[0] = x;
+                               co[1] = y;
+                               BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co);
+                               ED_clip_point_stable_pos__reverse(C, co, co);
+                               break;
+                       }
+                       case SPACE_SEQ:
+                               zero_v2(co); /* MASKTODO */
+                               break;
+                       case SPACE_IMAGE:
+                               zero_v2(co); /* MASKTODO */
+                               break;
+                       default:
+                               /* possible other spaces from which mask editing is available */
+                               BLI_assert(0);
+                               zero_v2(co);
+                               break;
+               }
        }
        else {
-               /* possible other spaces from which mask editing is available */
+               BLI_assert(0);
                zero_v2(co);
        }
 
@@ -148,40 +203,68 @@ void ED_mask_size(const bContext *C, int *width, int *height)
                        case SPACE_CLIP:
                        {
                                ED_space_clip_get_size(C, width, height);
-                               return;
+                               break;
                        }
                        case SPACE_SEQ:
                        {
                                Scene *scene = CTX_data_scene(C);
                                *width = (scene->r.size * scene->r.xsch) / 100;
                                *height = (scene->r.size * scene->r.ysch) / 100;
-                               return;
+                               break;
                        }
                        case SPACE_IMAGE:
                        {
                                SpaceImage *sima = sa->spacedata.first;
                                ED_space_image_size(sima, width, height);
-                               return;
+                               break;
                        }
+                       default:
+                               /* possible other spaces from which mask editing is available */
+                               BLI_assert(0);
+                               *width = 0;
+                               *height = 0;
+                               break;
                }
        }
-
-       /* possible other spaces from which mask editing is available */
-       *width = 0;
-       *height = 0;
+       else {
+               BLI_assert(0);
+               *width = 0;
+               *height = 0;
+       }
 }
 
 void ED_mask_aspect(const bContext *C, float *aspx, float *aspy)
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
-
-       if (sc) {
-               ED_space_clip_get_aspect(sc, aspx, aspy);
+       ScrArea *sa = CTX_wm_area(C);
+       if (sa && sa->spacedata.first) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                       {
+                               SpaceClip *sc = sa->spacedata.first;
+                               ED_space_clip_get_aspect(sc, aspx, aspy);
+                               break;
+                       }
+                       case SPACE_SEQ:
+                       {
+                               *aspx = *aspy = 1.0f;  /* MASKTODO - render aspect? */
+                               break;
+                       }
+                       case SPACE_IMAGE:
+                       {
+                               // SpaceImage *sima = sa->spacedata.first;
+                               *aspx = *aspy = 1.0f;  /* MASKTODO - image aspect? */
+                               break;
+                       }
+                       default:
+                               /* possible other spaces from which mask editing is available */
+                               BLI_assert(0);
+                               *aspx = *aspy = 1.0f;
+                               break;
+               }
        }
        else {
-               /* possible other spaces from which mask editing is available */
-               *aspx = 1.0f;
-               *aspy = 1.0f;
+               BLI_assert(0);
+               *aspx = *aspy = 1.0f;
        }
 }
 
@@ -189,6 +272,8 @@ void ED_mask_pixelspace_factor(const bContext *C, float *scalex, float *scaley)
 {
        SpaceClip *sc = CTX_wm_space_clip(C);
 
+       /* MASKTODO */
+
        if (sc) {
                int width, height;
                float zoomx, zoomy, aspx, aspy;
index c8246fd53bc9d9c1d8db5919f95cdde7e6fb7b19..99c46c38bfc9b419df9de5dd766c4677574b833c 100644 (file)
 #include "WM_api.h"
 #include "WM_types.h"
 
-#include "ED_screen.h"
-#include "ED_mask.h"
 #include "ED_clip.h"
+#include "ED_image.h"
 #include "ED_keyframing.h"
+#include "ED_mask.h"
+#include "ED_screen.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -255,7 +256,7 @@ int ED_mask_feather_find_nearest(const bContext *C, Mask *mask, float normal_co[
 
 static int mask_new_exec(bContext *C, wmOperator *op)
 {
-       SpaceClip *sc = CTX_wm_space_clip(C);
+       ScrArea *sa = CTX_wm_area(C);
        Mask *mask;
        char name[MAX_ID_NAME - 2];
 
@@ -263,8 +264,27 @@ static int mask_new_exec(bContext *C, wmOperator *op)
 
        mask = BKE_mask_new(name);
 
-       if (sc)
-               ED_space_clip_set_mask(C, sc, mask);
+       if (sa && sa->spacedata.first) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                       {
+                               SpaceClip *sc = sa->spacedata.first;
+                               ED_space_clip_set_mask(C, sc, mask);
+                               break;
+                       }
+                       case SPACE_SEQ:
+                       {
+                               /* do nothing */
+                               break;
+                       }
+                       case SPACE_IMAGE:
+                       {
+                               SpaceImage *sima = sa->spacedata.first;
+                               ED_space_image_set_mask(C, sima, mask);
+                               break;
+                       }
+               }
+       }
 
        return OPERATOR_FINISHED;
 }
index a2a7a07d089e3530f48bf67862b0717d9a3107d6..c7f917548ce7edab6d6d734d0884e2e05c412c7d 100644 (file)
@@ -539,6 +539,7 @@ static int clip_lasso_select_exec(bContext *C, wmOperator *op)
        return OPERATOR_PASS_THROUGH;
 }
 
+/* MASKTODO - image space */
 void MASK_OT_select_lasso(wmOperatorType *ot)
 {
        /* identifiers */
@@ -638,6 +639,7 @@ static int circle_select_exec(bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
+/* MASKTODO - image space */
 void MASK_OT_select_circle(wmOperatorType *ot)
 {
        /* identifiers */
index 725c76d8bb62a273df618c941d49f9ae8a4b802f..1c488fe4ac7f569c19bf5143c3a0968207496a3d 100644 (file)
  *  \ingroup spimage
  */
 
+#include "DNA_mask_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
 #include "BLI_math.h"
 
-#include "BKE_image.h"
+#include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_image.h"
 #include "BKE_main.h"
 #include "BKE_tessmesh.h"
 
@@ -79,6 +81,20 @@ void ED_space_image_set(SpaceImage *sima, Scene *scene, Object *obedit, Image *i
        WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL);
 }
 
+Mask *ED_space_image_get_mask(SpaceImage *sima)
+{
+       return sima->mask_info.mask;
+}
+
+void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask)
+{
+       sima->mask_info.mask = mask;
+
+       if (C) {
+               WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask);
+       }
+}
+
 ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **lock_r)
 {
        ImBuf *ibuf;
@@ -279,6 +295,40 @@ int ED_space_image_show_uvshadow(SpaceImage *sima, Object *obedit)
        return 0;
 }
 
+/* matches clip function */
+int ED_space_image_check_show_maskedit(SpaceImage *sima)
+{
+       /* MASKTODO - whem we have a mask edit option */
+       (void)sima;
+       return TRUE;
+}
+
+int ED_space_image_maskedit_poll(bContext *C)
+{
+       SpaceImage *sima = CTX_wm_space_image(C);
+
+       if (sima && sima->image) {
+               return ED_space_image_check_show_maskedit(sima);
+       }
+
+       return FALSE;
+}
+
+int ED_space_image_maskedit_mask_poll(bContext *C)
+{
+       if (ED_space_image_maskedit_poll(C)) {
+               Image *ima = CTX_data_edit_image(C);
+
+               if (ima) {
+                       SpaceImage *sima = CTX_wm_space_image(C);
+
+                       return sima->mask_info.mask != NULL;
+               }
+       }
+
+       return FALSE;
+}
+
 /******************** TODO ********************/
 
 /* XXX notifier? */