Custom Ratio mouse input didn't check for initialization properly, which could lead...
authorMartin Poirier <theeth@yahoo.com>
Wed, 18 Nov 2009 17:14:56 +0000 (17:14 +0000)
committerMartin Poirier <theeth@yahoo.com>
Wed, 18 Nov 2009 17:14:56 +0000 (17:14 +0000)
Also adding missing modal keymaps for some transform operators.

source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_input.c

index 769395d4581dcfc3980a1123ba5bd6b38727d868..3f4839a7d7202dd02a5bbdae5909f74160cc6dd3 100644 (file)
@@ -555,7 +555,8 @@ void transform_modal_keymap(wmKeyConfig *keyconf)
        WM_modalkeymap_assign(keymap, "TFM_OT_shrink_fatten");
        WM_modalkeymap_assign(keymap, "TFM_OT_tilt");
        WM_modalkeymap_assign(keymap, "TFM_OT_trackball");
-       
+       WM_modalkeymap_assign(keymap, "TFM_OT_mirror");
+       WM_modalkeymap_assign(keymap, "TFM_OT_edge_slide");
 }
 
 
@@ -4445,8 +4446,9 @@ void initEdgeSlide(TransInfo *t)
 
        t->customFree = freeSlideVerts;
 
-       initMouseInputMode(t, &t->mouse, INPUT_CUSTOM_RATIO);
+       /* set custom point first if you want value to be initialized by init */
        setCustomPoints(t, &t->mouse, sld->end, sld->start);
+       initMouseInputMode(t, &t->mouse, INPUT_CUSTOM_RATIO);
        
        t->idx_max = 0;
        t->num.idx_max = 0;
index bccbfbc65f70424a6427a3596d67dc861add035c..fbc7f0dd7468c79ebb6562ac7226350fbe021587 100644 (file)
@@ -165,8 +165,14 @@ void InputVerticalAbsolute(TransInfo *t, MouseInput *mi, short mval[2], float ou
 
 void setCustomPoints(TransInfo *t, MouseInput *mi, short start[2], short end[2])
 {
-       short *data = mi->data;
+       short *data;
+
+       if (mi->data == NULL) {
+               mi->data = MEM_callocN(sizeof(short) * 4, "custom points");
+       }
        
+       data = mi->data;
+
        data[0] = start[0];
        data[1] = start[1];
        data[2] = end[0];
@@ -180,28 +186,30 @@ void InputCustomRatio(TransInfo *t, MouseInput *mi, short mval[2], float output[
        short *data = mi->data;
        short dx, dy;
        
-       dx = data[2] - data[0];
-       dy = data[3] - data[1];
-       
-       length = (float)sqrtf(dx*dx + dy*dy);
-       
-       if (mi->precision) {
-               /* deal with Shift key by adding motion / 10 to motion before shift press */
-               short mdx, mdy;
-               mdx = (mi->precision_mval[0] + (float)(mval[0] - mi->precision_mval[0]) / 10.0f) - data[2];
-               mdy = (mi->precision_mval[1] + (float)(mval[1] - mi->precision_mval[1]) / 10.0f) - data[3];
+       if (data) {
+               dx = data[2] - data[0];
+               dy = data[3] - data[1];
                
-               distance = (mdx*dx + mdy*dy) / length;
-       }
-       else {
-               short mdx, mdy;
-               mdx = mval[0] - data[2];
-               mdy = mval[1] - data[3];
+               length = (float)sqrtf(dx*dx + dy*dy);
                
-               distance = (mdx*dx + mdy*dy) / length;
-       }
+               if (mi->precision) {
+                       /* deal with Shift key by adding motion / 10 to motion before shift press */
+                       short mdx, mdy;
+                       mdx = (mi->precision_mval[0] + (float)(mval[0] - mi->precision_mval[0]) / 10.0f) - data[2];
+                       mdy = (mi->precision_mval[1] + (float)(mval[1] - mi->precision_mval[1]) / 10.0f) - data[3];
+
+                       distance = (mdx*dx + mdy*dy) / length;
+               }
+               else {
+                       short mdx, mdy;
+                       mdx = mval[0] - data[2];
+                       mdy = mval[1] - data[3];
 
-       output[0] = distance / length;
+                       distance = (mdx*dx + mdy*dy) / length;
+               }
+
+               output[0] = distance / length;
+       }
 }
 
 void InputAngle(TransInfo *t, MouseInput *mi, short mval[2], float output[3])
@@ -335,7 +343,6 @@ void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
        case INPUT_CUSTOM_RATIO:
                mi->apply = InputCustomRatio;
                t->helpline = HLP_NONE;
-               mi->data = MEM_callocN(sizeof(short) * 4, "custom points");
                break;
        case INPUT_NONE:
        default: