Merging r46725 through r46963 from trunk into soc-2011-tomato
[blender.git] / source / blender / editors / transform / transform.c
index 43fdb77..a9f4ce2 100644 (file)
@@ -49,6 +49,7 @@
 #include "DNA_constraint_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_mask_types.h"
 #include "DNA_movieclip_types.h"
 #include "DNA_scene_types.h"           /* PET modes                    */
 
@@ -162,13 +163,35 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int 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;
 
-               r_vec[0] = (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               r_vec[1] = (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
+               mulx = (v2d->cur.xmax-v2d->cur.xmin);
+               muly = (v2d->cur.ymax-v2d->cur.ymin);
+
+               if (t->options & CTX_MASK) {
+                       /* clamp w/h, mask only */
+                       divx = divy = maxf(divx, divy);
+                       mulx = muly = minf(mulx, muly);
+               }
+
+               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_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_mask_aspect(t->sa->spacedata.first, &aspx, &aspy);
+               }
+
+               r_vec[0] *= aspx;
+               r_vec[1] *= aspy;
        }
        else {
                printf("%s: called in an invalid context\n", __func__);
@@ -226,9 +249,18 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2])
        }
        else if (t->spacetype==SPACE_CLIP) {
                float v[2];
+               float aspx = 1.0f, aspy = 1.0f;
 
                copy_v2_v2(v, vec);
 
+               if (t->options & CTX_MOVIECLIP)
+                       ED_space_clip_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy);
+               else if (t->options & CTX_MASK)
+                       ED_space_clip_mask_aspect(t->sa->spacedata.first, &aspx, &aspy);
+
+               v[0] /= aspx;
+               v[1] /= aspy;
+
                UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr+1);
        }
 }
@@ -279,16 +311,23 @@ void applyAspectRatio(TransInfo *t, float vec[2])
                vec[1] /= aspy;
        }
        else if ((t->spacetype==SPACE_CLIP) && (t->mode==TFM_TRANSLATION)) {
-               if (t->options & CTX_MOVIECLIP) {
+               if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
                        SpaceClip *sc = t->sa->spacedata.first;
                        float aspx, aspy;
-                       int width, height;
 
-                       ED_space_clip_size(sc, &width, &height);
-                       ED_space_clip_aspect(sc, &aspx, &aspy);
 
-                       vec[0] *= width / aspx;
-                       vec[1] *= height / aspy;
+                       if (t->options & CTX_MOVIECLIP) {
+                               ED_space_clip_aspect_dimension_aware(sc, &aspx, &aspy);
+
+                               vec[0] /= aspx;
+                               vec[1] /= aspy;
+                       }
+                       else if (t->options & CTX_MASK) {
+                               ED_space_clip_mask_aspect(sc, &aspx, &aspy);
+
+                               vec[0] /= aspx;
+                               vec[1] /= aspy;
+                       }
                }
        }
 }
@@ -312,16 +351,19 @@ void removeAspectRatio(TransInfo *t, float vec[2])
                vec[1] *= aspy;
        }
        else if ((t->spacetype==SPACE_CLIP) && (t->mode==TFM_TRANSLATION)) {
-               if (t->options & CTX_MOVIECLIP) {
+               if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
                        SpaceClip *sc = t->sa->spacedata.first;
-                       float aspx, aspy;
-                       int width, height;
+                       float aspx = 1.0f, aspy = 1.0f;
 
-                       ED_space_clip_size(sc, &width, &height);
-                       ED_space_clip_aspect(sc, &aspx, &aspy);
+                       if (t->options & CTX_MOVIECLIP) {
+                               ED_space_clip_aspect_dimension_aware(sc, &aspx, &aspy);
+                       }
+                       else if (t->options & CTX_MASK) {
+                               ED_space_clip_mask_aspect(sc, &aspx, &aspy);
+                       }
 
-                       vec[0] *= aspx / width;
-                       vec[1] *= aspy / height;
+                       vec[0] *= aspx;
+                       vec[1] *= aspy;
                }
        }
 }
@@ -367,12 +409,20 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
        }
        else if (t->spacetype==SPACE_CLIP) {
                SpaceClip *sc = (SpaceClip*)t->sa->spacedata.first;
-               MovieClip *clip = ED_space_clip(sc);
 
-               /* objects could be parented to tracking data, so send this for viewport refresh */
-               WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
+               if (ED_space_clip_show_trackedit(sc)) {
+                       MovieClip *clip = ED_space_clip(sc);
+
+                       /* objects could be parented to tracking data, so send this for viewport refresh */
+                       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
+
+                       WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
+               }
+               else if (ED_space_clip_show_maskedit(sc)) {
+                       Mask *mask = ED_space_clip_mask(sc);
 
-               WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, clip);
+                       WM_event_add_notifier(C, NC_MASK|NA_EDITED, mask);
+               }
        }
 }
 
@@ -728,7 +778,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        t->redraw |= TREDRAW_HARD;
                                }
                                else if (t->mode == TFM_TRANSLATION) {
-                                       if (t->options & CTX_MOVIECLIP) {
+                                       if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
                                                restoreTransObjects(t);
 
                                                t->flag ^= T_ALT_TRANSFORM;
@@ -738,7 +788,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                break;
                        case TFM_MODAL_ROTATE:
                                /* only switch when... */
-                               if (!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
+                               if (!(t->options & CTX_TEXTURE) && !(t->options & (CTX_MOVIECLIP | CTX_MASK))) {
                                        if ( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
                                                
                                                resetTransRestrictions(t);
@@ -765,6 +815,14 @@ int transformEvent(TransInfo *t, wmEvent *event)
                                        initSnapping(t, NULL); // need to reinit after mode change
                                        t->redraw |= TREDRAW_HARD;
                                }
+                               else if (t->mode == TFM_RESIZE) {
+                                       if (t->options & CTX_MOVIECLIP) {
+                                               restoreTransObjects(t);
+
+                                               t->flag ^= T_ALT_TRANSFORM;
+                                               t->redraw |= TREDRAW_HARD;
+                                       }
+                               }
                                break;
                                
                        case TFM_MODAL_SNAP_INV_ON:
@@ -993,7 +1051,7 @@ int transformEvent(TransInfo *t, wmEvent *event)
                        break;
                case RKEY:
                        /* only switch when... */
-                       if (!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
+                       if (!(t->options & CTX_TEXTURE)) {
                                if ( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
 
                                        resetTransRestrictions(t);
@@ -1588,9 +1646,13 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int
                t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
        }
        else if (t->spacetype == SPACE_CLIP) {
+               SpaceClip *sc = CTX_wm_space_clip(C);
                unit_m3(t->spacemtx);
                t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
-               t->options |= CTX_MOVIECLIP;
+               if (ED_space_clip_show_trackedit(sc))
+                       t->options |= CTX_MOVIECLIP;
+               else if (ED_space_clip_show_maskedit(sc))
+                       t->options |= CTX_MASK;
        }
        else
                unit_m3(t->spacemtx);
@@ -2672,6 +2734,9 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
        {
                copy_v3_v3(center, td->center);
        }
+       else if (t->options & CTX_MOVIECLIP) {
+               copy_v3_v3(center, td->center);
+       }
        else {
                copy_v3_v3(center, t->center);
        }
@@ -3045,6 +3110,10 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], short
                {
                        center = td->center;
                }
+
+               if (t->options & CTX_MOVIECLIP) {
+                       center = td->center;
+               }
        }
 
        if (t->flag & T_POINTS) {