== Action/IPO Editors - Code Cleanup ==
authorJoshua Leung <aligorith@gmail.com>
Tue, 26 Jun 2007 10:08:58 +0000 (10:08 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 26 Jun 2007 10:08:58 +0000 (10:08 +0000)
Added two macros which are used to test if the active Action/IPO editor is displaying data from a scaled NLA-strip.

source/blender/include/BIF_editaction.h
source/blender/src/drawaction.c
source/blender/src/drawipo.c
source/blender/src/editaction.c
source/blender/src/editipo.c
source/blender/src/editipo_mods.c

index 838bbb5c34c4ca1a0d94c84ceaaecab8a8d766be..b6dd9ae55a86acbf43b33375802dc98043971f5b 100644 (file)
@@ -64,6 +64,9 @@
 #define EDITABLE_ICU(icu) ((icu->flag & IPO_PROTECT)==0)
 #define SEL_ICU(icu) (icu->flag & IPO_SELECT)
 
+#define NLA_ACTION_SCALED (G.saction->pin==0 && OBACT)
+#define NLA_IPO_SCALED (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname)
+
 /* constants for setting ipo-interpolation type */
 #define SET_IPO_POPUP    0
 #define SET_IPO_CONSTANT 1
index 357614f24abb84efe40740bdd1d023d6ba376b55..3f80e524ae3e8d7b8725c11162d75a1fd0de2fd1 100644 (file)
@@ -25,7 +25,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Joshua Leung
  *
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  * Drawing routines for the Action window type
@@ -716,7 +716,7 @@ static void draw_channel_strips(SpaceAction *saction)
        di= glaBegin2DDraw(&scr_rct, &G.v2d->cur);
 
        /* if in NLA there's a strip active, map the view */
-       if (G.saction->pin==0 && OBACT)
+       if (NLA_ACTION_SCALED)
                map_active_strip(di, OBACT, 0);
        
        /* start and end of action itself */
@@ -724,7 +724,7 @@ static void draw_channel_strips(SpaceAction *saction)
        gla2DDrawTranslatePt(di, sta, 0.0f, &act_start, &dummy);
        gla2DDrawTranslatePt(di, end, 0.0f, &act_end, &dummy);
        
-       if (G.saction->pin==0 && OBACT)
+       if (NLA_ACTION_SCALED)
                map_active_strip(di, OBACT, 1);
        
        /* first backdrop strips */
@@ -795,7 +795,7 @@ static void draw_channel_strips(SpaceAction *saction)
        }               
        glDisable(GL_BLEND);
        
-       if (G.saction->pin==0 && OBACT)
+       if (NLA_ACTION_SCALED)
                map_active_strip(di, OBACT, 0);
        
        /* keyframes  */
index e2acee267c1524cc787972e26d2391613743cdd5..633d1b1ee313e626a8a4a582434f47f651fa4783 100644 (file)
@@ -2158,9 +2158,8 @@ void drawipospace(ScrArea *sa, void *spacedata)
                }
                
                /* map ipo-points for drawing if scaled ipo */
-               if (OBACT && OBACT->action && sipo->pin==0 && sipo->actname) {
+               if (NLA_IPO_SCALED)
                        actstrip_map_ipo_keys(OBACT, sipo->ipo, 0, 0);
-               }
 
                /* draw deselect */
                draw_ipocurves(0);
@@ -2173,9 +2172,8 @@ void drawipospace(ScrArea *sa, void *spacedata)
                draw_ipovertices(1);
                
                /* undo mapping of ipo-points for drawing if scaled ipo */
-               if (OBACT && OBACT->action && sipo->pin==0 && sipo->actname) {
+               if (NLA_IPO_SCALED)
                        actstrip_map_ipo_keys(OBACT, sipo->ipo, 1, 0);
-               }
                
                /* Draw 'curtains' for preview */
                draw_anim_preview_timespace();
index aa6bf38d2fcf163038c48d5b1c8d11e303466c61..2448f791a39ba1611a19cfbc31f627c263ad2c97 100644 (file)
@@ -588,7 +588,7 @@ static void *get_nearest_action_key (float *selx, short *sel, short *ret_type, b
        areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
 
        /* if action is mapped in NLA, it returns a correction */
-       if (G.saction->pin==0 && OBACT && datatype==ACTCONT_ACTION) {
+       if (NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) {
                xmin= get_action_frame(OBACT, rectf.xmin);
                xmax= get_action_frame(OBACT, rectf.xmax);
        }
@@ -773,7 +773,7 @@ static short transform_action_loop (TransVert *tv, int tvtot, char mode, short c
        getmouseco_areawin (mvals);
        areamouseco_to_ipoco(G.v2d, mvals, &sval[0], &sval[1]);
 
-       if(G.saction->pin==0 && OBACT)
+       if (NLA_ACTION_SCALED)
                sval[0]= get_action_frame(OBACT, sval[0]);
        
        /* used for drawing */
@@ -826,10 +826,10 @@ static short transform_action_loop (TransVert *tv, int tvtot, char mode, short c
                        getmouseco_areawin (mvalc);
                        areamouseco_to_ipoco(G.v2d, mvalc, &cval[0], &cval[1]);
                        
-                       if(G.saction->pin==0 && OBACT)
+                       if (NLA_ACTION_SCALED)
                                cval[0]= get_action_frame(OBACT, cval[0]);
 
-                       if(mode=='t')
+                       if (mode=='t')
                                G.saction->timeslide= cval[0];
                        
                        if (!firsttime && lastcval[0]==cval[0] && lastcval[1]==cval[1]) {
@@ -878,7 +878,7 @@ static short transform_action_loop (TransVert *tv, int tvtot, char mode, short c
                                                }
                                                break;
                                        case 'g':
-                                               if (G.saction->pin==0 && OBACT && context==ACTCONT_ACTION) {
+                                               if (NLA_ACTION_SCALED && context==ACTCONT_ACTION) {
                                                        deltax = get_action_frame_inv(OBACT, cval[0]);
                                                        deltax -= get_action_frame_inv(OBACT, sval[0]);
                                                        
@@ -919,7 +919,7 @@ static short transform_action_loop (TransVert *tv, int tvtot, char mode, short c
                                                        fac*=-1;
                                                }
                                                startx= (G.scene->r.cfra);
-                                               if(G.saction->pin==0 && OBACT && context==ACTCONT_ACTION)
+                                               if(NLA_ACTION_SCALED && context==ACTCONT_ACTION)
                                                        startx= get_action_frame(OBACT, startx);
                                                        
                                                tv[i].loc[0]-= startx;
@@ -934,7 +934,7 @@ static short transform_action_loop (TransVert *tv, int tvtot, char mode, short c
                                                float snapval;
                                                
                                                /* convert frame to nla-action time (if needed) */
-                                               if (G.saction->pin==0 && OBACT && context==ACTCONT_ACTION) 
+                                               if (NLA_ACTION_SCALED && context==ACTCONT_ACTION) 
                                                        snapval= get_action_frame_inv(OBACT, tv[i].loc[0]);
                                                else
                                                        snapval= tv[i].loc[0];
@@ -943,7 +943,7 @@ static short transform_action_loop (TransVert *tv, int tvtot, char mode, short c
                                                snapval= (float)(floor(snapval+0.5));
                                                        
                                                /* convert frame out of nla-action time */
-                                               if (G.saction->pin==0 && OBACT && context==ACTCONT_ACTION)
+                                               if (NLA_ACTION_SCALED && context==ACTCONT_ACTION)
                                                        tv[i].loc[0]= get_action_frame(OBACT, snapval);
                                                else
                                                        tv[i].loc[0]= snapval;
@@ -955,7 +955,7 @@ static short transform_action_loop (TransVert *tv, int tvtot, char mode, short c
                                        headerprint(str);
                                }
                                else if (mode=='g') {
-                                       if(G.saction->pin==0 && OBACT && context==ACTCONT_ACTION) {
+                                       if (NLA_ACTION_SCALED && context==ACTCONT_ACTION) {
                                                /* recalculate the delta based on 'visual' times */
                                                fac = get_action_frame_inv(OBACT, cval[0]);
                                                fac -= get_action_frame_inv(OBACT, sval[0]);
@@ -1133,7 +1133,7 @@ void snap_action_keys(short mode)
        
        /* snap to frame */
        for (ale= act_data.first; ale; ale= ale->next) {
-               if (datatype==ACTCONT_ACTION && G.saction->pin==0 && OBACT) {
+               if (NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) {
                        actstrip_map_ipo_keys(OBACT, ale->key_data, 0, 1); 
                        snap_ipo_keys(ale->key_data, mode);
                        actstrip_map_ipo_keys(OBACT, ale->key_data, 1, 1);
@@ -1191,7 +1191,7 @@ void mirror_action_keys(short mode)
        
        /* mirror */
        for (ale= act_data.first; ale; ale= ale->next) {
-               if (datatype==ACTCONT_ACTION && G.saction->pin==0 && OBACT) {
+               if (NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) {
                        actstrip_map_ipo_keys(OBACT, ale->key_data, 0, 1); 
                        mirror_ipo_keys(ale->key_data, mode);
                        actstrip_map_ipo_keys(OBACT, ale->key_data, 1, 1);
@@ -2120,7 +2120,7 @@ void markers_selectkeys_between (void)
                
        /* select keys in-between */
        for (ale= act_data.first; ale; ale= ale->next) {
-               if(G.saction->pin==0 && OBACT && datatype==ACTCONT_ACTION) {
+               if(NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) {
                        actstrip_map_ipo_keys(OBACT, ale->key_data, 0, 1);
                        borderselect_ipo_key(ale->key_data, min, max, SELECT_ADD);
                        actstrip_map_ipo_keys(OBACT, ale->key_data, 1, 1);
@@ -2189,7 +2189,7 @@ void column_select_action_keys(int mode)
                        make_marker_cfra_list(&elems, 1);
                        
                        /* apply scaled action correction if needed */
-                       if (G.saction->pin==0 && OBACT && datatype==ACTCONT_ACTION) {
+                       if (NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) {
                                for (ce= elems.first; ce; ce= ce->next) 
                                        ce->cfra= get_action_frame(OBACT, ce->cfra);
                        }
@@ -2261,7 +2261,7 @@ void borderselect_action (void)
                areamouseco_to_ipoco(G.v2d, mval, &rectf.xmax, &rectf.ymax);
                
                /* if action is mapped in NLA, it returns a correction */
-               if (G.saction->pin==0 && OBACT && datatype==ACTCONT_ACTION) {
+               if (NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) {
                        rectf.xmin= get_action_frame(OBACT, rectf.xmin);
                        rectf.xmax= get_action_frame(OBACT, rectf.xmax);
                }
index ad5ffacf10325c353e420035756a71e84fd3d7b1..f4ce725ae456d29ed75e855c8ab4772aba902696 100644 (file)
@@ -1372,7 +1372,7 @@ void mouse_select_ipo(void)
        marker=find_nearest_marker(1);
        
        /* map ipo-points for editing if scaled ipo */
-       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+       if (NLA_IPO_SCALED) {
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 0, 0);
        }
        
@@ -1535,7 +1535,7 @@ void mouse_select_ipo(void)
        }
        
        /* undo mapping of ipo-points for editing if scaled ipo */
-       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+       if (NLA_IPO_SCALED) {
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 1, 0);
        }
        
@@ -1990,7 +1990,7 @@ void add_vert_ipo(void)
        areamouseco_to_ipoco(G.v2d, mval, &x, &y);
        
        /* convert click-time to ipo-time */
-       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+       if (NLA_IPO_SCALED) {
                x= get_action_frame(OBACT, x);
        }
        
@@ -2363,7 +2363,7 @@ void insertkey_editipo(void)
                                                }
                                                
                                                /* convert cfra to ipo-time */
-                                               if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+                                               if (NLA_IPO_SCALED) {
                                                        cfra= get_action_frame(OBACT, cfra);
                                                }
                                
@@ -3512,7 +3512,7 @@ void ipo_snap(short event)
        get_status_editipo();
        
        /* map ipo-points for editing if scaled ipo */
-       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+       if (NLA_IPO_SCALED) {
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 0, 0);
        }
 
@@ -3585,7 +3585,7 @@ void ipo_snap(short event)
        }
        
        /* undo mapping of ipo-points for editing if scaled ipo */
-       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+       if (NLA_IPO_SCALED) {
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 1, 0);
        }
        
@@ -3620,7 +3620,7 @@ void ipo_mirror(short mode)
        if (!ei) return;
        
        /* map ipo-points for editing if scaled ipo */
-       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+       if (NLA_IPO_SCALED) {
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 0, 0);
        }
        
@@ -3679,7 +3679,7 @@ void ipo_mirror(short mode)
        }
        
        /* undo mapping of ipo-points for editing if scaled ipo */
-       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+       if (NLA_IPO_SCALED) {
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 1, 0);
        }
        
@@ -4154,7 +4154,7 @@ void make_ipokey(void)
                else ik->flag= 0;
                
                /* map ipo-keys for drawing/editing if scaled ipo */
-               if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+               if (NLA_IPO_SCALED) {
                        ik->val= get_action_frame_inv(OBACT, ik->val);
                }
                
@@ -4258,7 +4258,7 @@ void make_ipokey_transform(Object *ob, ListBase *lb, int sel)
        ik= lb->first;
        while(ik) {
                /* map ipo-keys for drawing/editing if scaled ipo */
-               if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+               if (NLA_IPO_SCALED) {
                        ik->val= get_action_frame_inv(OBACT, ik->val);
                }
                
@@ -4278,7 +4278,7 @@ void update_ipokey_val(void)      /* after moving vertices */
                                ik->val= ik->data[a]->vec[1][0];
                                
                                /* map ipo-keys for drawing/editing if scaled ipo */
-                               if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+                               if (NLA_IPO_SCALED) {
                                        ik->val= get_action_frame_inv(OBACT, ik->val);
                                }
                                break;
@@ -4529,7 +4529,7 @@ void remake_ipo_transverts(TransVert *transmain, float *dvec, int tot)
        
        tv= transmain;
        for(a=0; a<tot; a++, tv++) {
-               if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+               if (NLA_IPO_SCALED) {
                        tv->oldloc[0] = get_action_frame_inv(OBACT, tv->loc[0]);
                        tv->oldloc[0]-= dvec[0];
                        tv->oldloc[0] = get_action_frame(OBACT, tv->loc[0]);
@@ -4715,7 +4715,7 @@ void transform_ipo(int mode)
                                tv= transmain;
                                for(a=0; a<tot; a++, tv++) {
                                        /* adjust times for scaled ipos */
-                                       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+                                       if (NLA_IPO_SCALED) {
                                                tv->loc[0] = get_action_frame_inv(OBACT, tv->oldloc[0]);
                                                tv->loc[0]+= vec[0];
                                                tv->loc[0] = get_action_frame(OBACT, tv->loc[0]);
@@ -4749,7 +4749,7 @@ void transform_ipo(int mode)
 
                                for(a=0; a<tot; a++, tv++) {
                                        /* adjust times for scaled ipo's */
-                                       if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+                                       if (NLA_IPO_SCALED) {
                                                tv->loc[0] = get_action_frame_inv(OBACT, tv->oldloc[0]) - get_action_frame_inv(OBACT, cent[0]);
                                                tv->loc[0]*= size[0];
                                                tv->loc[0]+= get_action_frame_inv(OBACT, cent[0]);
index 2621ad54979b2ab4345305af3682211dbc910a1b..08157c7eef346797b3c6e837bba22aaf368b90e7 100644 (file)
@@ -58,6 +58,7 @@
 #include "BKE_key.h"
 #include "BKE_utildefines.h"
 
+#include "BIF_editaction.h"
 #include "BIF_interface.h"
 #include "BIF_screen.h"
 #include "BIF_space.h"
@@ -927,7 +928,7 @@ void borderselect_ipo(void)
 
        if(val) {
                /* map ipo-points for editing if scaled ipo */
-               if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+               if (NLA_IPO_SCALED) {
                        actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 0, 0);
                }
                
@@ -979,7 +980,7 @@ void borderselect_ipo(void)
                }
                
                /* undo mapping of ipo-points for drawing if scaled ipo */
-               if (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) {
+               if (NLA_IPO_SCALED) {
                        actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 1, 0);
                }