Cleanup: transform aspect
authorCampbell Barton <ideasman42@gmail.com>
Fri, 26 Jun 2015 05:45:09 +0000 (15:45 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 26 Jun 2015 05:45:09 +0000 (15:45 +1000)
Transform code had duplicate aspect checking,
now store aspect in TransInfo.aspect for reuse.

source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_constraints.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_snap.c

index cba620c6264df80540ca0f8e7e904cfec3a9c221..1c8c21cadd189e47a4880b4a72476e1e7fd092ec 100644 (file)
@@ -239,6 +239,38 @@ void setTransformViewMatrices(TransInfo *t)
        calculateCenter2D(t);
 }
 
+void setTransformViewAspect(TransInfo *t, float r_aspect[3])
+{
+       copy_v3_fl(r_aspect, 1.0f);
+
+       if (t->spacetype == SPACE_IMAGE) {
+               SpaceImage *sima = t->sa->spacedata.first;
+
+               if (t->options & CTX_MASK) {
+                       ED_space_image_get_aspect(sima, &r_aspect[0], &r_aspect[1]);
+               }
+               else if (t->options & CTX_PAINT_CURVE) {
+                       /* pass */
+               }
+               else {
+                       ED_space_image_get_uv_aspect(sima, &r_aspect[0], &r_aspect[1]);
+               }
+       }
+       else if (t->spacetype == SPACE_CLIP) {
+               SpaceClip *sclip = t->sa->spacedata.first;
+
+               if (t->options & CTX_MOVIECLIP) {
+                       ED_space_clip_get_aspect_dimension_aware(sclip, &r_aspect[0], &r_aspect[1]);
+               }
+               else {
+                       ED_space_clip_get_aspect(sclip, &r_aspect[0], &r_aspect[1]);
+               }
+       }
+       else if (t->spacetype == SPACE_IPO) {
+               /* depemds on context of usage */
+       }
+}
+
 static void convertViewVec2D(View2D *v2d, float r_vec[3], int dx, int dy)
 {
        float divx, divy;
@@ -292,25 +324,19 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
                }
        }
        else if (t->spacetype == SPACE_IMAGE) {
-               float aspx, aspy;
-
                if (t->options & CTX_MASK) {
                        convertViewVec2D_mask(t->view, r_vec, dx, dy);
-                       ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy);
                }
                else if (t->options & CTX_PAINT_CURVE) {
                        r_vec[0] = dx;
                        r_vec[1] = dy;
-
-                       aspx = aspy = 1.0;
                }
                else {
                        convertViewVec2D(t->view, r_vec, dx, dy);
-                       ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
                }
 
-               r_vec[0] *= aspx;
-               r_vec[1] *= aspy;
+               r_vec[0] *= t->aspect[0];
+               r_vec[1] *= t->aspect[1];
        }
        else if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
                convertViewVec2D(t->view, r_vec, dx, dy);
@@ -319,8 +345,6 @@ 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) {
-               float aspx, aspy;
-
                if (t->options & CTX_MASK) {
                        convertViewVec2D_mask(t->view, r_vec, dx, dy);
                }
@@ -328,21 +352,8 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
                        convertViewVec2D(t->view, r_vec, dx, dy);
                }
 
-               if (t->options & CTX_MOVIECLIP) {
-                       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_aspect(t->sa->spacedata.first, &aspx, &aspy);
-               }
-               else {
-                       /* should never happen, quiet warnings */
-                       BLI_assert(0);
-                       aspx = aspy = 1.0f;
-               }
-
-               r_vec[0] *= aspx;
-               r_vec[1] *= aspy;
+               r_vec[0] *= t->aspect[0];
+               r_vec[1] *= t->aspect[1];
        }
        else {
                printf("%s: called in an invalid context\n", __func__);
@@ -364,15 +375,10 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                SpaceImage *sima = t->sa->spacedata.first;
 
                if (t->options & CTX_MASK) {
-                       float aspx, aspy;
                        float v[2];
 
-                       ED_space_image_get_aspect(sima, &aspx, &aspy);
-
-                       copy_v2_v2(v, vec);
-
-                       v[0] = v[0] / aspx;
-                       v[1] = v[1] / aspy;
+                       v[0] = vec[0] / t->aspect[0];
+                       v[1] = vec[1] / t->aspect[1];
 
                        BKE_mask_coord_to_image(sima->image, &sima->iuser, v, v);
 
@@ -386,11 +392,10 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                        adr[1] = vec[1];
                }
                else {
-                       float aspx, aspy, v[2];
+                       float v[2];
 
-                       ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
-                       v[0] = vec[0] / aspx;
-                       v[1] = vec[1] / aspy;
+                       v[0] = vec[0] / t->aspect[0];
+                       v[1] = vec[1] / t->aspect[1];
 
                        UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]);
                }
@@ -435,15 +440,10 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                        MovieClip *clip = ED_space_clip_get_clip(sc);
 
                        if (clip) {
-                               float aspx, aspy;
                                float v[2];
 
-                               ED_space_clip_get_aspect(sc, &aspx, &aspy);
-
-                               copy_v2_v2(v, vec);
-
-                               v[0] = v[0] / aspx;
-                               v[1] = v[1] / aspy;
+                               v[0] = vec[0] / t->aspect[0];
+                               v[1] = vec[1] / t->aspect[1];
 
                                BKE_mask_coord_to_movieclip(sc->clip, &sc->user, v, v);
 
@@ -458,13 +458,10 @@ void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DPr
                        }
                }
                else if (t->options & CTX_MOVIECLIP) {
-                       float v[2], aspx, aspy;
-
-                       copy_v2_v2(v, vec);
-                       ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy);
+                       float v[2];
 
-                       v[0] /= aspx;
-                       v[1] /= aspy;
+                       v[0] = vec[0] / t->aspect[0];
+                       v[1] = vec[1] / t->aspect[1];
 
                        UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]);
                }
@@ -520,7 +517,6 @@ void applyAspectRatio(TransInfo *t, float vec[2])
 {
        if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION) && !(t->options & CTX_PAINT_CURVE)) {
                SpaceImage *sima = t->sa->spacedata.first;
-               float aspx, aspy;
 
                if ((sima->flag & SI_COORDFLOATS) == 0) {
                        int width, height;
@@ -530,28 +526,13 @@ void applyAspectRatio(TransInfo *t, float vec[2])
                        vec[1] *= height;
                }
 
-               ED_space_image_get_uv_aspect(sima, &aspx, &aspy);
-               vec[0] /= aspx;
-               vec[1] /= aspy;
+               vec[0] /= t->aspect[0];
+               vec[1] /= t->aspect[1];
        }
        else if ((t->spacetype == SPACE_CLIP) && (t->mode == TFM_TRANSLATION)) {
                if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
-                       SpaceClip *sc = t->sa->spacedata.first;
-                       float aspx, aspy;
-
-
-                       if (t->options & CTX_MOVIECLIP) {
-                               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_aspect(sc, &aspx, &aspy);
-
-                               vec[0] /= aspx;
-                               vec[1] /= aspy;
-                       }
+                       vec[0] /= t->aspect[0];
+                       vec[1] /= t->aspect[1];
                }
        }
 }
@@ -560,7 +541,6 @@ void removeAspectRatio(TransInfo *t, float vec[2])
 {
        if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) {
                SpaceImage *sima = t->sa->spacedata.first;
-               float aspx, aspy;
 
                if ((sima->flag & SI_COORDFLOATS) == 0) {
                        int width, height;
@@ -570,24 +550,13 @@ void removeAspectRatio(TransInfo *t, float vec[2])
                        vec[1] /= height;
                }
 
-               ED_space_image_get_uv_aspect(sima, &aspx, &aspy);
-               vec[0] *= aspx;
-               vec[1] *= aspy;
+               vec[0] *= t->aspect[0];
+               vec[1] *= t->aspect[1];
        }
        else if ((t->spacetype == SPACE_CLIP) && (t->mode == TFM_TRANSLATION)) {
                if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
-                       SpaceClip *sc = t->sa->spacedata.first;
-                       float aspx = 1.0f, aspy = 1.0f;
-
-                       if (t->options & CTX_MOVIECLIP) {
-                               ED_space_clip_get_aspect_dimension_aware(sc, &aspx, &aspy);
-                       }
-                       else if (t->options & CTX_MASK) {
-                               ED_space_clip_get_aspect(sc, &aspx, &aspy);
-                       }
-
-                       vec[0] *= aspx;
-                       vec[1] *= aspy;
+                       vec[0] *= t->aspect[0];
+                       vec[1] *= t->aspect[1];
                }
        }
 }
index 418fb8e1961fc164bc76046da06128b2e90c4420..af82f416db82a67f68d298ff6f5713e4b22e6e46 100644 (file)
@@ -357,6 +357,8 @@ typedef struct TransInfo {
        eRedrawFlag redraw;         /* redraw flag                          */
        float           prop_size;              /* proportional circle radius           */
        char            proptext[20];   /* proportional falloff text                    */
+       float       aspect[3];      /* spaces using non 1:1 aspect, (uv's, f-curve, movie-clip... etc)
+                                    * use for conversion and snapping. */
        float       center[3];      /* center of transformation             */
        float       center2d[2];    /* center in screen coordinates         */
        int         imval[2];       /* initial mouse position               */
@@ -542,6 +544,7 @@ void transformApply(struct bContext *C, TransInfo *t);
 int  transformEnd(struct bContext *C, TransInfo *t);
 
 void setTransformViewMatrices(TransInfo *t);
+void setTransformViewAspect(TransInfo *t, float r_aspect[3]);
 void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy);
 void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DProjTest flag);
 void projectIntView(TransInfo *t, const float vec[3], int adr[2]);
index 03d626fe17972606e58795e65f164be12ed38f5a..50c255bc9dbd07af404f06c4dfe813c6f01bbe7f 100644 (file)
@@ -751,19 +751,7 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
                        mul_m4_v3(t->obedit->obmat, center); /* because t->center is in local space */
                }
                else if (t->spacetype == SPACE_IMAGE) {
-                       float aspx, aspy;
-
-                       if (t->options & CTX_MASK) {
-                               /* untested - mask aspect is TODO */
-                               ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy);
-                       }
-                       else if (t->options & CTX_PAINT_CURVE) {
-                               aspx = aspy = 1.0f;
-                       }
-                       else {
-                               ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
-                       }
-                       glScalef(1.0f / aspx, 1.0f / aspy, 1.0f);
+                       glScalef(1.0f / t->aspect[0], 1.0f / t->aspect[1], 1.0f);
                }
                else if (ELEM(t->spacetype, SPACE_IPO, SPACE_ACTION)) {
                        /* only scale y */
index abaa55e3e9ca2de542e30596416bf68005a70088..c9e7e085a96ea5c414aa2be69bf253f52771e7ad 100644 (file)
@@ -2727,7 +2727,6 @@ static void createTransUVs(bContext *C, TransInfo *t)
        BLI_bitmap *island_enabled = NULL;
        struct { float co[2]; int co_num; } *island_center = NULL;
        int count = 0, countsel = 0, count_rejected = 0;
-       float aspect[2];
        const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
        const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0;
        const bool is_island_center = (t->around == V3D_LOCAL);
@@ -2798,14 +2797,12 @@ static void createTransUVs(bContext *C, TransInfo *t)
                goto finally;
        }
 
-       ED_space_image_get_uv_aspect(sima, &aspect[0], &aspect[1]);
-
        if (is_island_center) {
                int i;
 
                for (i = 0; i < elementmap->totalIslands; i++) {
                        mul_v2_fl(island_center[i].co, 1.0f / island_center[i].co_num);
-                       mul_v2_v2(island_center[i].co, aspect);
+                       mul_v2_v2(island_center[i].co, t->aspect);
                }
        }
 
@@ -2852,7 +2849,7 @@ static void createTransUVs(bContext *C, TransInfo *t)
                        
                        BM_elem_flag_enable(l, BM_ELEM_TAG);
                        luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-                       UVsToTransData(aspect, td++, td2d++, luv->uv, center, selected);
+                       UVsToTransData(t->aspect, td++, td2d++, luv->uv, center, selected);
                }
        }
 
@@ -2882,22 +2879,28 @@ void flushTransUVs(TransInfo *t)
 {
        SpaceImage *sima = t->sa->spacedata.first;
        TransData2D *td;
-       int a, width, height;
-       float aspx, aspy, invx, invy;
+       int a;
+       float aspect_inv[2], size[2];
+       const bool use_pixel_snap = ((sima->flag & SI_PIXELSNAP) && (t->state != TRANS_CANCEL));
 
-       ED_space_image_get_uv_aspect(sima, &aspx, &aspy);
-       ED_space_image_get_size(sima, &width, &height);
-       invx = 1.0f / aspx;
-       invy = 1.0f / aspy;
+       aspect_inv[0] = 1.0f / t->aspect[0];
+       aspect_inv[1] = 1.0f / t->aspect[1];
+
+       if (use_pixel_snap) {
+               int size_i[2];
+               ED_space_image_get_size(sima, &size_i[0], &size_i[1]);
+               size[0] = size_i[0];
+               size[1] = size_i[1];
+       }
 
        /* flush to 2d vector from internally used 3d vector */
        for (a = 0, td = t->data2d; a < t->total; a++, td++) {
-               td->loc2d[0] = td->loc[0] * invx;
-               td->loc2d[1] = td->loc[1] * invy;
+               td->loc2d[0] = td->loc[0] * aspect_inv[0];
+               td->loc2d[1] = td->loc[1] * aspect_inv[1];
 
-               if ((sima->flag & SI_PIXELSNAP) && (t->state != TRANS_CANCEL)) {
-                       td->loc2d[0] = roundf(width * td->loc2d[0]) / width;
-                       td->loc2d[1] = roundf(height * td->loc2d[1]) / height;
+               if (use_pixel_snap) {
+                       td->loc2d[0] = roundf(td->loc2d[0] * size[0]) / size[0];
+                       td->loc2d[1] = roundf(td->loc2d[1] * size[1]) / size[1];
                }
        }
 }
@@ -2905,44 +2908,45 @@ void flushTransUVs(TransInfo *t)
 bool clipUVTransform(TransInfo *t, float vec[2], const bool resize)
 {
        TransData *td;
-       int a, clipx = 1, clipy = 1;
-       float aspx, aspy, min[2], max[2];
+       int a;
+       bool clipx = true, clipy = true;
+       float min[2], max[2];
 
-       ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
        min[0] = min[1] = 0.0f;
-       max[0] = aspx; max[1] = aspy;
+       max[0] = t->aspect[0];
+       max[1] = t->aspect[1];
 
        for (a = 0, td = t->data; a < t->total; a++, td++) {
                minmax_v2v2_v2(min, max, td->loc);
        }
 
        if (resize) {
-               if (min[0] < 0.0f && t->center[0] > 0.0f && t->center[0] < aspx * 0.5f)
+               if (min[0] < 0.0f && t->center[0] > 0.0f && t->center[0] < t->aspect[0] * 0.5f)
                        vec[0] *= t->center[0] / (t->center[0] - min[0]);
-               else if (max[0] > aspx && t->center[0] < aspx)
-                       vec[0] *= (t->center[0] - aspx) / (t->center[0] - max[0]);
+               else if (max[0] > t->aspect[0] && t->center[0] < t->aspect[0])
+                       vec[0] *= (t->center[0] - t->aspect[0]) / (t->center[0] - max[0]);
                else
                        clipx = 0;
 
-               if (min[1] < 0.0f && t->center[1] > 0.0f && t->center[1] < aspy * 0.5f)
+               if (min[1] < 0.0f && t->center[1] > 0.0f && t->center[1] < t->aspect[1] * 0.5f)
                        vec[1] *= t->center[1] / (t->center[1] - min[1]);
-               else if (max[1] > aspy && t->center[1] < aspy)
-                       vec[1] *= (t->center[1] - aspy) / (t->center[1] - max[1]);
+               else if (max[1] > t->aspect[1] && t->center[1] < t->aspect[1])
+                       vec[1] *= (t->center[1] - t->aspect[1]) / (t->center[1] - max[1]);
                else
                        clipy = 0;
        }
        else {
                if (min[0] < 0.0f)
                        vec[0] -= min[0];
-               else if (max[0] > aspx)
-                       vec[0] -= max[0] - aspx;
+               else if (max[0] > t->aspect[0])
+                       vec[0] -= max[0] - t->aspect[0];
                else
                        clipx = 0;
 
                if (min[1] < 0.0f)
                        vec[1] -= min[1];
-               else if (max[1] > aspy)
-                       vec[1] -= max[1] - aspy;
+               else if (max[1] > t->aspect[1])
+                       vec[1] -= max[1] - t->aspect[1];
                else
                        clipy = 0;
        }
@@ -2954,9 +2958,6 @@ void clipUVData(TransInfo *t)
 {
        TransData *td = NULL;
        int a;
-       float aspx, aspy;
-
-       ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
 
        for (a = 0, td = t->data; a < t->total; a++, td++) {
                if (td->flag & TD_NOACTION)
@@ -2965,8 +2966,8 @@ void clipUVData(TransInfo *t)
                if ((td->flag & TD_SKIP) || (!td->loc))
                        continue;
 
-               td->loc[0] = min_ff(max_ff(0.0f, td->loc[0]), aspx);
-               td->loc[1] = min_ff(max_ff(0.0f, td->loc[1]), aspy);
+               td->loc[0] = min_ff(max_ff(0.0f, td->loc[0]), t->aspect[0]);
+               td->loc[1] = min_ff(max_ff(0.0f, td->loc[1]), t->aspect[1]);
        }
 }
 
@@ -6577,22 +6578,22 @@ typedef struct TransDataTracking {
 
 static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
                                   MovieTrackingTrack *track, MovieTrackingMarker *marker,
-                                  int area, float loc[2], float rel[2], const float off[2], float aspx, float aspy)
+                                  int area, float loc[2], float rel[2], const float off[2], const float aspect[2])
 {
        int anchor = area == TRACK_AREA_POINT && off;
 
        tdt->mode = transDataTracking_ModeTracks;
 
        if (anchor) {
-               td2d->loc[0] = rel[0] * aspx; /* hold original location */
-               td2d->loc[1] = rel[1] * aspy;
+               td2d->loc[0] = rel[0] * aspect[0]; /* hold original location */
+               td2d->loc[1] = rel[1] * aspect[1];
 
                tdt->loc = loc;
                td2d->loc2d = loc; /* current location */
        }
        else {
-               td2d->loc[0] = loc[0] * aspx; /* hold original location */
-               td2d->loc[1] = loc[1] * aspy;
+               td2d->loc[0] = loc[0] * aspect[0]; /* hold original location */
+               td2d->loc[1] = loc[1] * aspect[1];
 
                td2d->loc2d = loc; /* current location */
        }
@@ -6607,8 +6608,8 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTra
 
        if (rel) {
                if (!anchor) {
-                       td2d->loc[0] += rel[0] * aspx;
-                       td2d->loc[1] += rel[1] * aspy;
+                       td2d->loc[0] += rel[0] * aspect[0];
+                       td2d->loc[1] += rel[1] * aspect[1];
                }
 
                copy_v2_v2(tdt->srelative, rel);
@@ -6623,8 +6624,8 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTra
 
        //copy_v3_v3(td->center, td->loc);
        td->flag |= TD_INDIVIDUAL_SCALE;
-       td->center[0] = marker->pos[0] * aspx;
-       td->center[1] = marker->pos[1] * aspy;
+       td->center[0] = marker->pos[0] * aspect[0];
+       td->center[1] = marker->pos[1] * aspect[1];
 
        memset(td->axismtx, 0, sizeof(td->axismtx));
        td->axismtx[2][2] = 1.0f;
@@ -6639,8 +6640,9 @@ static void markerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTra
        unit_m3(td->smtx);
 }
 
-static void trackToTransData(const int framenr, TransData *td, TransData2D *td2d,
-                             TransDataTracking *tdt, MovieTrackingTrack *track, float aspx, float aspy)
+static void trackToTransData(
+        const int framenr, TransData *td, TransData2D *td2d,
+        TransDataTracking *tdt, MovieTrackingTrack *track, const float aspect[2])
 {
        MovieTrackingMarker *marker = BKE_tracking_marker_ensure(track, framenr);
 
@@ -6648,11 +6650,11 @@ static void trackToTransData(const int framenr, TransData *td, TransData2D *td2d
        marker->flag &= ~(MARKER_DISABLED | MARKER_TRACKED);
 
        markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_POINT,
-                             track->offset, marker->pos, track->offset, aspx, aspy);
+                             track->offset, marker->pos, track->offset, aspect);
 
        if (track->flag & SELECT) {
                markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_POINT,
-                                     marker->pos, NULL, NULL, aspx, aspy);
+                                     marker->pos, NULL, NULL, aspect);
        }
 
        if (track->pat_flag & SELECT) {
@@ -6660,28 +6662,28 @@ static void trackToTransData(const int framenr, TransData *td, TransData2D *td2d
 
                for (a = 0; a < 4; a++) {
                        markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_PAT,
-                                             marker->pattern_corners[a], marker->pos, NULL, aspx, aspy);
+                                             marker->pattern_corners[a], marker->pos, NULL, aspect);
                }
        }
 
        if (track->search_flag & SELECT) {
                markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_SEARCH,
-                                     marker->search_min, marker->pos, NULL, aspx, aspy);
+                                     marker->search_min, marker->pos, NULL, aspect);
 
                markerToTransDataInit(td++, td2d++, tdt++, track, marker, TRACK_AREA_SEARCH,
-                                     marker->search_max, marker->pos, NULL, aspx, aspy);
+                                     marker->search_max, marker->pos, NULL, aspect);
        }
 }
 
 static void planeMarkerToTransDataInit(TransData *td, TransData2D *td2d, TransDataTracking *tdt,
                                        MovieTrackingPlaneTrack *plane_track, float corner[2],
-                                       float aspx, float aspy)
+                                       const float aspect[2])
 {
        tdt->mode = transDataTracking_ModePlaneTracks;
        tdt->plane_track = plane_track;
 
-       td2d->loc[0] = corner[0] * aspx; /* hold original location */
-       td2d->loc[1] = corner[1] * aspy;
+       td2d->loc[0] = corner[0] * aspect[0]; /* hold original location */
+       td2d->loc[1] = corner[1] * aspect[1];
 
        td2d->loc2d = corner; /* current location */
        td2d->loc[2] = 0.0f;
@@ -6706,7 +6708,7 @@ static void planeMarkerToTransDataInit(TransData *td, TransData2D *td2d, TransDa
 
 static void planeTrackToTransData(const int framenr, TransData *td, TransData2D *td2d,
                                   TransDataTracking *tdt, MovieTrackingPlaneTrack *plane_track,
-                                  float aspx, float aspy)
+                                  const float aspect[2])
 {
        MovieTrackingPlaneMarker *plane_marker = BKE_tracking_plane_marker_ensure(plane_track, framenr);
        int i;
@@ -6715,7 +6717,7 @@ static void planeTrackToTransData(const int framenr, TransData *td, TransData2D
        plane_marker->flag &= ~PLANE_MARKER_TRACKED;
 
        for (i = 0; i < 4; i++) {
-               planeMarkerToTransDataInit(td++, td2d++, tdt++, plane_track, plane_marker->corners[i], aspx, aspy);
+               planeMarkerToTransDataInit(td++, td2d++, tdt++, plane_track, plane_marker->corners[i], aspect);
        }
 }
 
@@ -6744,7 +6746,6 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
        MovieTrackingPlaneTrack *plane_track;
        TransDataTracking *tdt;
        int framenr = ED_space_clip_get_clip_frame_number(sc);
-       float aspx, aspy;
 
        /* count */
        t->total = 0;
@@ -6779,8 +6780,6 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
        if (t->total == 0)
                return;
 
-       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");
        tdt = t->customData = MEM_callocN(t->total * sizeof(TransDataTracking), "TransTracking TransDataTracking");
@@ -6791,7 +6790,7 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
        track = tracksbase->first;
        while (track) {
                if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) {
-                       trackToTransData(framenr, td, td2d, tdt, track, aspx, aspy);
+                       trackToTransData(framenr, td, td2d, tdt, track, t->aspect);
 
                        /* offset */
                        td++;
@@ -6825,7 +6824,7 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
             plane_track = plane_track->next)
        {
                if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
-                       planeTrackToTransData(framenr, td, td2d, tdt, plane_track, aspx, aspy);
+                       planeTrackToTransData(framenr, td, td2d, tdt, plane_track, t->aspect);
                        td += 4;
                        td2d += 4;
                        tdt += 4;
@@ -7037,14 +7036,10 @@ static void cancelTransTracking(TransInfo *t)
 
 void flushTransTracking(TransInfo *t)
 {
-       SpaceClip *sc = t->sa->spacedata.first;
        TransData *td;
        TransData2D *td2d;
        TransDataTracking *tdt;
        int a;
-       float aspx, aspy;
-
-       ED_space_clip_get_aspect_dimension_aware(sc, &aspx, &aspy);
 
        if (t->state == TRANS_CANCEL)
                cancelTransTracking(t);
@@ -7058,8 +7053,8 @@ void flushTransTracking(TransInfo *t)
                                continue;
                        }
 
-                       loc2d[0] = td2d->loc[0] / aspx;
-                       loc2d[1] = td2d->loc[1] / aspy;
+                       loc2d[0] = td2d->loc[0] / t->aspect[0];
+                       loc2d[1] = td2d->loc[1] / t->aspect[1];
 
                        if (t->flag & T_ALT_TRANSFORM) {
                                if (t->mode == TFM_RESIZE) {
@@ -7101,8 +7096,8 @@ void flushTransTracking(TransInfo *t)
                        td2d->loc2d[tdt->coord] = tdt->prev_pos[tdt->coord] + td2d->loc[1] * tdt->scale;
                }
                else if (tdt->mode == transDataTracking_ModePlaneTracks) {
-                       td2d->loc2d[0] = td2d->loc[0] / aspx;
-                       td2d->loc2d[1] = td2d->loc[1] / aspy;
+                       td2d->loc2d[0] = td2d->loc[0] / t->aspect[0];
+                       td2d->loc2d[1] = td2d->loc[1] / t->aspect[1];
                }
        }
 }
index 637b6c7c24840eaf6eab68e8919fb3d0cbcbc258..f958e520c0db890fdbbaf276dda8c94cbd1899a0 100644 (file)
@@ -1401,6 +1401,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 #endif
 
        setTransformViewMatrices(t);
+       setTransformViewAspect(t, t->aspect);
        initNumInput(&t->num);
 }
 
@@ -1595,30 +1596,17 @@ void calculateCenterCursor(TransInfo *t, float r_center[3])
 
 void calculateCenterCursor2D(TransInfo *t, float r_center[2])
 {
-       float aspx = 1.0, aspy = 1.0;
        const float *cursor = NULL;
        
        if (t->spacetype == SPACE_IMAGE) {
                SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first;
-               if (t->options & CTX_MASK) {
-                       ED_space_image_get_aspect(sima, &aspx, &aspy);
-               }
-               else {
-                       ED_space_image_get_uv_aspect(sima, &aspx, &aspy);
-               }
                cursor = sima->cursor;
        }
        else if (t->spacetype == SPACE_CLIP) {
                SpaceClip *space_clip = (SpaceClip *) t->sa->spacedata.first;
-               if (t->options & CTX_MOVIECLIP) {
-                       ED_space_clip_get_aspect_dimension_aware(space_clip, &aspx, &aspy);
-               }
-               else {
-                       ED_space_clip_get_aspect(space_clip, &aspx, &aspy);
-               }
                cursor = space_clip->cursor;
        }
-       
+
        if (cursor) {
                if (t->options & CTX_MASK) {
                        float co[2];
@@ -1635,8 +1623,8 @@ void calculateCenterCursor2D(TransInfo *t, float r_center[2])
                                BLI_assert(!"Shall not happen");
                        }
 
-                       r_center[0] = co[0] * aspx;
-                       r_center[1] = co[1] * aspy;
+                       r_center[0] = co[0] * t->aspect[0];
+                       r_center[1] = co[1] * t->aspect[1];
                }
                else if (t->options & CTX_PAINT_CURVE) {
                        if (t->spacetype == SPACE_IMAGE) {
@@ -1645,8 +1633,8 @@ void calculateCenterCursor2D(TransInfo *t, float r_center[2])
                        }
                }
                else {
-                       r_center[0] = cursor[0] * aspx;
-                       r_center[1] = cursor[1] * aspy;
+                       r_center[0] = cursor[0] * t->aspect[0];
+                       r_center[1] = cursor[1] * t->aspect[1];
                }
        }
 }
index d9cc9588d4929c0fc826d4e74ca2e59ccbedabcb..db6620b0d46a0c9cb0120019c981e092b5017af0 100644 (file)
@@ -1045,14 +1045,13 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
        else if (t->spacetype == SPACE_IMAGE && t->obedit != NULL && t->obedit->type == OB_MESH) {
                /* same as above but for UV's */
                Image *ima = ED_space_image(t->sa->spacedata.first);
-               float aspx, aspy, co[2];
+               float co[2];
                
                UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], &co[0], &co[1]);
 
                if (ED_uvedit_nearest_uv(t->scene, t->obedit, ima, co, t->tsnap.snapPoint)) {
-                       ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
-                       t->tsnap.snapPoint[0] *= aspx;
-                       t->tsnap.snapPoint[1] *= aspy;
+                       t->tsnap.snapPoint[0] *= t->aspect[0];
+                       t->tsnap.snapPoint[1] *= t->aspect[1];
 
                        t->tsnap.status |=  POINT_INIT;
                }
@@ -2449,42 +2448,35 @@ void snapSequenceBounds(TransInfo *t, const int mval[2])
 
 static void applyGridIncrement(TransInfo *t, float *val, int max_index, const float fac[3], GearsType action)
 {
+       float asp_local[3] = {1, 1, 1};
+       const bool use_aspect = ELEM(t->mode, TFM_TRANSLATION);
+       const float *asp = use_aspect ? t->aspect : asp_local;
        int i;
-       float asp[3] = {1.0f, 1.0f, 1.0f}; // TODO: Remove hard coded limit here (3)
 
-       if (max_index > 2) {
-               printf("applyGridIncrement: invalid index %d, clamping\n", max_index);
-               max_index = 2;
-       }
+       BLI_assert(max_index <= 2);
 
-       // Early bailing out if no need to snap
-       if (fac[action] == 0.0f)
+       /* Early bailing out if no need to snap */
+       if (fac[action] == 0.0f) {
                return;
-       
-       /* evil hack - snapping needs to be adapted for image aspect ratio */
-       if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) {
-               if (t->options & CTX_MASK) {
-                       ED_space_image_get_aspect(t->sa->spacedata.first, asp, asp + 1);
-               }
-               else if (t->options & CTX_PAINT_CURVE) {
-                       asp[0] = asp[1] = 1.0;
-               }
-               else {
-                       ED_space_image_get_uv_aspect(t->sa->spacedata.first, asp, asp + 1);
-               }
        }
-       else if ((t->spacetype == SPACE_IPO) && (t->mode == TFM_TRANSLATION)) {
-               View2D *v2d = &t->ar->v2d;
-               View2DGrid *grid;
-               SpaceIpo *sipo = t->sa->spacedata.first;
-               int unity = V2D_UNIT_VALUES;
-               int unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
 
-               /* grid */
-               grid = UI_view2d_grid_calc(t->scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, t->ar->winx, t->ar->winy);
+       if (use_aspect) {
+               /* custom aspect for fcurve */
+               if (t->spacetype == SPACE_IPO) {
+                       View2D *v2d = &t->ar->v2d;
+                       View2DGrid *grid;
+                       SpaceIpo *sipo = t->sa->spacedata.first;
+                       int unity = V2D_UNIT_VALUES;
+                       int unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
+
+                       /* grid */
+                       grid = UI_view2d_grid_calc(t->scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, t->ar->winx, t->ar->winy);
 
-               UI_view2d_grid_size(grid, &asp[0], &asp[1]);
-               UI_view2d_grid_free(grid);
+                       UI_view2d_grid_size(grid, &asp_local[0], &asp_local[1]);
+                       UI_view2d_grid_free(grid);
+
+                       asp = asp_local;
+               }
        }
 
        for (i = 0; i <= max_index; i++) {