mask transform now works in the image space
authorCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 19:36:59 +0000 (19:36 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 25 Jul 2012 19:36:59 +0000 (19:36 +0000)
source/blender/editors/mask/mask_edit.c
source/blender/editors/space_clip/clip_editor.c
source/blender/editors/space_image/image_edit.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_snap.c
source/blender/makesdna/DNA_space_types.h

index 3af61b366b29ff3427bf87a22851d5df3101020b..6667b9b69a58c043f7dedd5c903793e0fd6c6eeb 100644 (file)
@@ -263,7 +263,7 @@ void ED_mask_aspect(const bContext *C, float *aspx, float *aspy)
                        case SPACE_IMAGE:
                        {
                                SpaceImage *sima = sa->spacedata.first;
-                               ED_space_image_get_uv_aspect(sima, aspx, aspy);
+                               ED_space_image_get_aspect(sima, aspx, aspy);
                                break;
                        }
                        default:
@@ -312,7 +312,7 @@ void ED_mask_pixelspace_factor(const bContext *C, float *scalex, float *scaley)
 
                                ED_space_image_get_size(sima, &width, &height);
                                ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
-                               ED_space_image_get_uv_aspect(sima, &aspx, &aspy);
+                               ED_space_image_get_aspect(sima, &aspx, &aspy);
 
                                *scalex = ((float)width * aspx) * zoomx;
                                *scaley = ((float)height * aspy) * zoomy;
index 9bde3a3d4d5e52aeaebfa661cea9551c5912523b..52f5960c55917f51f7276e23cee2e8b1d71058a1 100644 (file)
@@ -128,11 +128,11 @@ 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;
+       if (sc->clip) {
+               BKE_movieclip_get_size(sc->clip, &sc->user, width, height);
        }
        else {
-               BKE_movieclip_get_size(sc->clip, &sc->user, width, height);
+               *width = *height = IMG_SIZE_FALLBACK;
        }
 }
 
index 736b585864befad6dfee82c727700fa26d9834e1..8ae2b76cd4ee62edc582c1675814245c92e25a87 100644 (file)
@@ -149,8 +149,8 @@ void ED_image_get_size(Image *ima, int *width, int *height)
                *height = ibuf->y;
        }
        else {
-               *width = 256;
-               *height = 256;
+               *width  = IMG_SIZE_FALLBACK;
+               *height = IMG_SIZE_FALLBACK;
        }
 
        if (ima)
@@ -183,8 +183,8 @@ void ED_space_image_get_size(SpaceImage *sima, int *width, int *height)
        /* I know a bit weak... but preview uses not actual image size */
        // XXX else if (image_preview_active(sima, width, height));
        else {
-               *width = 256;
-               *height = 256;
+               *width  = IMG_SIZE_FALLBACK;
+               *height = IMG_SIZE_FALLBACK;
        }
 
        ED_space_image_release_buffer(sima, lock);
index ceb10060826c53f6a3b0f9a38b57ac1341b713db..81e836a2f7de51ee72118492d22ed0b4e25a138a 100644 (file)
@@ -120,16 +120,44 @@ void setTransformViewMatrices(TransInfo *t)
        calculateCenter2D(t);
 }
 
-static void convertViewVec2D(View2D *v2d, float vec[3], int dx, int dy)
+static void convertViewVec2D(View2D *v2d, float r_vec[3], int dx, int dy)
 {
        float divx, divy;
        
        divx = v2d->mask.xmax - v2d->mask.xmin;
        divy = v2d->mask.ymax - v2d->mask.ymin;
 
-       vec[0] = (v2d->cur.xmax - v2d->cur.xmin) * dx / divx;
-       vec[1] = (v2d->cur.ymax - v2d->cur.ymin) * dy / divy;
-       vec[2] = 0.0f;
+       r_vec[0] = (v2d->cur.xmax - v2d->cur.xmin) * dx / divx;
+       r_vec[1] = (v2d->cur.ymax - v2d->cur.ymin) * dy / divy;
+       r_vec[2] = 0.0f;
+}
+
+static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy)
+{
+       float divx, divy;
+       float mulx, muly;
+
+       divx = v2d->mask.xmax - v2d->mask.xmin;
+       divy = v2d->mask.ymax - v2d->mask.ymin;
+
+       mulx = (v2d->cur.xmax - v2d->cur.xmin);
+       muly = (v2d->cur.ymax - v2d->cur.ymin);
+
+       /* difference with convertViewVec2D */
+       /* clamp w/h, mask only */
+       if (mulx / divx < muly / divy) {
+               divy = divx;
+               muly = mulx;
+       }
+       else {
+               divx = divy;
+               mulx = muly;
+       }
+       /* end difference */
+
+       r_vec[0] = mulx * dx / divx;
+       r_vec[1] = muly * dy / divy;
+       r_vec[2] = 0.0f;
 }
 
 void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
@@ -143,11 +171,17 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
        else if (t->spacetype == SPACE_IMAGE) {
                float aspx, aspy;
 
-               convertViewVec2D(t->view, r_vec, dx, dy);
+               if (t->options & CTX_MASK) {
 
-               /* MASKTODO - see clip clamp w/h */
+                       convertViewVec2D_mask(t->view, r_vec, dx, dy);
+
+                       ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy);
+               }
+               else {
+                       convertViewVec2D(t->view, r_vec, dx, dy);
+                       ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
+               }
 
-               ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
                r_vec[0] *= aspx;
                r_vec[1] *= aspy;
        }
@@ -158,32 +192,14 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
                convertViewVec2D(&t->ar->v2d, r_vec, dx, dy);
        }
        else if (t->spacetype == SPACE_CLIP) {
-               View2D *v2d = t->view;
-               float divx, divy;
-               float mulx, muly;
-               float aspx = 1.0f, aspy = 1.0f;
-
-               divx = v2d->mask.xmax - v2d->mask.xmin;
-               divy = v2d->mask.ymax - v2d->mask.ymin;
-
-               mulx = (v2d->cur.xmax - v2d->cur.xmin);
-               muly = (v2d->cur.ymax - v2d->cur.ymin);
+               float aspx, aspy;
 
                if (t->options & CTX_MASK) {
-                       /* clamp w/h, mask only */
-                       if (mulx / divx < muly / divy) {
-                               divy = divx;
-                               muly = mulx;
-                       }
-                       else {
-                               divx = divy;
-                               mulx = muly;
-                       }
+                       convertViewVec2D_mask(t->view, r_vec, dx, dy);
+               }
+               else {
+                       convertViewVec2D(t->view, r_vec, dx, dy);
                }
-
-               r_vec[0] = mulx * (dx) / divx;
-               r_vec[1] = muly * (dy) / divy;
-               r_vec[2] = 0.0f;
 
                if (t->options & CTX_MOVIECLIP) {
                        ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy);
index 6dc0e98605846426088a47cfadd6e3eef51f56fd..e3a9d06222bea8a16c2ddf91016e5dd6cff90427 100644 (file)
@@ -4964,6 +4964,36 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o
        }
 }
 
+static void special_aftertrans_update__mask(bContext *C, TransInfo *t)
+{
+       Mask *mask;
+
+       if (t->spacetype == SPACE_CLIP) {
+               SpaceClip *sc = t->sa->spacedata.first;
+               mask = ED_space_clip_get_mask(sc);
+       }
+       else if (t->spacetype == SPACE_IMAGE) {
+               SpaceImage *sima = t->sa->spacedata.first;
+               mask = ED_space_image_get_mask(sima);
+       }
+       else {
+               BLI_assert(0);
+       }
+
+       if (t->scene->nodetree) {
+               /* tracks can be used for stabilization nodes,
+                * flush update for such nodes */
+               nodeUpdateID(t->scene->nodetree, &mask->id);
+               WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL);
+       }
+
+       /* TODO - dont key all masks... */
+       if (IS_AUTOKEY_ON(t->scene)) {
+               Scene *scene = t->scene;
+
+               ED_mask_layer_shape_auto_key_select(mask, CFRA);
+       }
+}
 
 /* inserting keys, pointcache, redraw events... */
 /* 
@@ -5033,7 +5063,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                }
        }
        else if (t->spacetype == SPACE_IMAGE) {
-               /* prevent this passing through to final 'else' which assumes objects */
+               if (t->options & CTX_MASK) {
+                       special_aftertrans_update__mask(C, t);
+               }
        }
        else if (t->spacetype == SPACE_NODE) {
                SpaceNode *snode = (SpaceNode *)t->sa->spacedata.first;
@@ -5059,22 +5091,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
                        }
                }
                else if (t->options & CTX_MASK) {
-                       SpaceClip *sc = t->sa->spacedata.first;
-                       Mask *mask = ED_space_clip_get_mask(sc);
-
-                       if (t->scene->nodetree) {
-                               /* tracks can be used for stabilization nodes,
-                                * flush update for such nodes */
-                               nodeUpdateID(t->scene->nodetree, &mask->id);
-                               WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL);
-                       }
-
-                       /* TODO - dont key all masks... */
-                       if (IS_AUTOKEY_ON(t->scene)) {
-                               Scene *scene = t->scene;
-
-                               ED_mask_layer_shape_auto_key_select(mask, CFRA);
-                       }
+                       special_aftertrans_update__mask(C, t);
                }
        }
        else if (t->spacetype == SPACE_ACTION) {
@@ -6259,20 +6276,19 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
 
 void flushTransMasking(TransInfo *t)
 {
-       SpaceClip *sc = t->sa->spacedata.first;
        TransData2D *td;
        TransDataMasking *tdm;
        int a;
-       float aspx, aspy, invx, invy;
+       float asp[2], inv[2];
 
-       ED_space_clip_get_aspect(sc, &aspx, &aspy);
-       invx = 1.0f / aspx;
-       invy = 1.0f / aspy;
+       ED_mask_aspect(t->context, &asp[0], &asp[1]);
+       inv[0] = 1.0f / asp[0];
+       inv[1] = 1.0f / asp[1];
 
        /* flush to 2d vector from internally used 3d vector */
        for (a = 0, td = t->data2d, tdm = t->customData; a < t->total; a++, td++, tdm++) {
-               td->loc2d[0] = td->loc[0] * invx;
-               td->loc2d[1] = td->loc[1] * invy;
+               td->loc2d[0] = td->loc[0] * inv[0];
+               td->loc2d[1] = td->loc[1] * inv[1];
 
                if (tdm->is_handle)
                        BKE_mask_point_set_handle(tdm->point, td->loc2d, t->flag & T_ALT_TRANSFORM, tdm->orig_handle, tdm->vec);
index 8651241f3386d0359fd60eea1d4e1fab17b3ad1c..c7846b3935bc0b7a3c7a9d5ab74179874a893bef 100644 (file)
@@ -607,6 +607,15 @@ static void recalcData_nla(TransInfo *t)
        }
 }
 
+static void recalcData_mask_common(TransInfo *t)
+{
+       Mask *mask = CTX_data_edit_mask(t->context);
+
+       flushTransMasking(t);
+
+       DAG_id_tag_update(&mask->id, 0);
+}
+
 /* helper for recalcData() - for Image Editor transforms */
 static void recalcData_image(TransInfo *t)
 {
@@ -619,6 +628,9 @@ static void recalcData_image(TransInfo *t)
                
                DAG_id_tag_update(t->obedit->data, 0);
        }
+       else if (t->options & CTX_MASK) {
+               recalcData_mask_common(t);
+       }
 }
 
 /* helper for recalcData() - for Movie Clip transforms */
@@ -662,12 +674,8 @@ static void recalcData_spaceclip(TransInfo *t)
 
                DAG_id_tag_update(&clip->id, 0);
        }
-       else if (ED_space_clip_check_show_maskedit(sc)) {
-               Mask *mask = ED_space_clip_get_mask(sc);
-
-               flushTransMasking(t);
-
-               DAG_id_tag_update(&mask->id, 0);
+       else if (t->options & CTX_MASK) {
+               recalcData_mask_common(t);
        }
 }
 
@@ -908,6 +916,10 @@ void recalcData(TransInfo *t)
        else if (t->spacetype == SPACE_CLIP) {
                recalcData_spaceclip(t);
        }
+
+       if (t->options & CTX_MASK) {
+
+       }
 }
 
 void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
index 7c86b697437d4dde391666ef1071af4122a9c80f..667365488755b5b3c602c7a439bec411a7de191d 100644 (file)
@@ -208,8 +208,8 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
                        
                        ED_space_image_get_aspect(t->sa->spacedata.first, &xuser_aspx, &yuser_asp);
                        ED_space_image_width(t->sa->spacedata.first, &wi, &hi);
-                       w = (((float)wi) / 256.0f) * G.sima->zoom * xuser_asp;
-                       h = (((float)hi) / 256.0f) * G.sima->zoom * yuser_asp;
+                       w = (((float)wi) / IMG_SIZE_FALLBACK) * G.sima->zoom * xuser_asp;
+                       h = (((float)hi) / IMG_SIZE_FALLBACK) * G.sima->zoom * yuser_asp;
                        
                        cpack(0xFFFFFF);
                        glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], 0.0f);
index 6299c46171e86c4341d3ce4e27810dabb129ea04..49ea9af31e40d7ea03cc4e4834e759a8dd59ae29 100644 (file)
@@ -1115,4 +1115,6 @@ typedef enum eSpace_Type {
        SPACEICONMAX = SPACE_CLIP
 } eSpace_Type;
 
+#define IMG_SIZE_FALLBACK 256
+
 #endif