style cleanup: mostly whitespace around operators
authorCampbell Barton <ideasman42@gmail.com>
Sun, 25 Mar 2012 23:54:33 +0000 (23:54 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 25 Mar 2012 23:54:33 +0000 (23:54 +0000)
16 files changed:
source/blender/editors/space_view3d/drawanimviz.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/drawvolume.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_fly.c
source/blender/editors/space_view3d/view3d_header.c
source/blender/editors/space_view3d/view3d_ops.c
source/blender/editors/space_view3d/view3d_select.c
source/blender/editors/space_view3d/view3d_snap.c
source/blender/editors/space_view3d/view3d_toolbar.c
source/blender/editors/space_view3d/view3d_view.c

index 545ec42e72fae56a8d4f2366c7199ff4480cfa26..d0e344ef0d52d6a572b70ca0c8005cd8bb31a55f 100644 (file)
@@ -70,7 +70,7 @@
 /* Set up drawing environment for drawing motion paths */
 void draw_motion_paths_init(View3D *v3d, ARegion *ar) 
 {
-       RegionView3D *rv3d= ar->regiondata;
+       RegionView3D *rv3d = ar->regiondata;
        
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
@@ -79,15 +79,15 @@ void draw_motion_paths_init(View3D *v3d, ARegion *ar)
 }
 
 /* Draw the given motion path for an Object or a Bone 
- *     - assumes that the viewport has already been initialized properly
+ *  - assumes that the viewport has already been initialized properly
  *             i.e. draw_motion_paths_init() has been called
  */
 void draw_motion_path_instance(Scene *scene, 
-                       Object *ob, bPoseChannel *pchan, bAnimVizSettings *avs, bMotionPath *mpath)
+                               Object *ob, bPoseChannel *pchan, bAnimVizSettings *avs, bMotionPath *mpath)
 {
        //RegionView3D *rv3d= ar->regiondata;
        bMotionPathVert *mpv, *mpv_start;
-       int i, stepsize= avs->path_step;
+       int i, stepsize = avs->path_step;
        int sfra, efra, len;
        
        
@@ -99,21 +99,21 @@ void draw_motion_path_instance(Scene *scene,
                 * the current frame to draw. However, this range is still 
                 * restricted by the limits of the original path.
                 */
-               sfra= CFRA - avs->path_bc;
-               efra= CFRA + avs->path_ac;
-               if (sfra < mpath->start_frame) sfra= mpath->start_frame;
-               if (efra > mpath->end_frame) efra= mpath->end_frame;
+               sfra = CFRA - avs->path_bc;
+               efra = CFRA + avs->path_ac;
+               if (sfra < mpath->start_frame) sfra = mpath->start_frame;
+               if (efra > mpath->end_frame) efra = mpath->end_frame;
                
-               len= efra - sfra;
+               len = efra - sfra;
                
-               sind= sfra - mpath->start_frame;
-               mpv_start= (mpath->points + sind);
+               sind = sfra - mpath->start_frame;
+               mpv_start = (mpath->points + sind);
        }
        else {
-               sfra= mpath->start_frame;
+               sfra = mpath->start_frame;
                efra = sfra + mpath->length;
                len = mpath->length;
-               mpv_start= mpath->points;
+               mpv_start = mpath->points;
        }
 
        if (len <= 0) {
@@ -124,17 +124,17 @@ void draw_motion_path_instance(Scene *scene,
        glShadeModel(GL_SMOOTH);
        
        glBegin(GL_LINE_STRIP);                                 
-       for (i=0, mpv=mpv_start; i < len; i++, mpv++) {
-               short sel= (pchan) ? (pchan->bone->flag & BONE_SELECTED) : (ob->flag & SELECT);
+       for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
+               short sel = (pchan) ? (pchan->bone->flag & BONE_SELECTED) : (ob->flag & SELECT);
                float intensity; /* how faint */
                
                /* set color
-                *      - more intense for active/selected bones, less intense for unselected bones
-                *      - black for before current frame, green for current frame, blue for after current frame
-                *      - intensity decreases as distance from current frame increases
+                * - more intense for active/selected bones, less intense for unselected bones
+                * - black for before current frame, green for current frame, blue for after current frame
+                * - intensity decreases as distance from current frame increases
                 */
-               #define SET_INTENSITY(A, B, C, min, max) (((1.0f - ((C - B) / (C - A))) * (max-min)) + min) 
-               if ((sfra+i) < CFRA) {
+               #define SET_INTENSITY(A, B, C, min, max) (((1.0f - ((C - B) / (C - A))) * (max - min)) + min)
+               if ((sfra + i) < CFRA) {
                        /* black - before cfra */
                        if (sel) {
                                // intensity= 0.5f;
@@ -146,7 +146,7 @@ void draw_motion_path_instance(Scene *scene,
                        }
                        UI_ThemeColorBlend(TH_WIRE, TH_BACK, intensity);
                }
-               else if ((sfra+i) > CFRA) {
+               else if ((sfra + i) > CFRA) {
                        /* blue - after cfra */
                        if (sel) {
                                //intensity = 0.5f;
@@ -161,10 +161,10 @@ void draw_motion_path_instance(Scene *scene,
                else {
                        /* green - on cfra */
                        if (sel) {
-                               intensity= 0.5f;
+                               intensity = 0.5f;
                        }
                        else {
-                               intensity= 0.99f;
+                               intensity = 0.99f;
                        }
                        UI_ThemeColorBlendShade(TH_CFRAME, TH_BACK, intensity, 10);
                }       
@@ -182,28 +182,28 @@ void draw_motion_path_instance(Scene *scene,
         * NOTE: this is not really visible/noticeable
         */
        glBegin(GL_POINTS);
-       for (i=0, mpv=mpv_start; i < len; i++, mpv++) 
+       for (i = 0, mpv = mpv_start; i < len; i++, mpv++)
                glVertex3fv(mpv->co);
        glEnd();
        
        /* Draw little white dots at each framestep value */
        UI_ThemeColor(TH_TEXT_HI);
        glBegin(GL_POINTS);
-       for (i=0, mpv=mpv_start; i < len; i+=stepsize, mpv+=stepsize) 
+       for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize)
                glVertex3fv(mpv->co);
        glEnd();
        
        /* Draw big green dot where the current frame is */
        // NOTE: only do this when drawing keyframes for now... 
        if ((avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) &&
-               (sfra < CFRA) && (CFRA <= efra))
+           (sfra < CFRA) && (CFRA <= efra))
        {
                UI_ThemeColor(TH_CFRAME);
                glPointSize(6.0f);
                
                glBegin(GL_POINTS);
-                       mpv = mpv_start + (CFRA - sfra);
-                       glVertex3fv(mpv->co);
+               mpv = mpv_start + (CFRA - sfra);
+               glVertex3fv(mpv->co);
                glEnd();
                
                glPointSize(1.0f);
@@ -217,26 +217,26 @@ void draw_motion_path_instance(Scene *scene,
        if (avs->path_viewflag & MOTIONPATH_VIEW_FNUMS) {
                unsigned char col[4];
                UI_GetThemeColor3ubv(TH_TEXT_HI, col);
-               col[3]= 255;
+               col[3] = 255;
 
-               for (i=0, mpv=mpv_start; i < len; i+=stepsize, mpv+=stepsize) {
+               for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize) {
                        char numstr[32];
                        float co[3];
                        
                        /* only draw framenum if several consecutive highlighted points don't occur on same point */
                        if (i == 0) {
-                               sprintf(numstr, "%d", (i+sfra));
+                               sprintf(numstr, "%d", (i + sfra));
                                mul_v3_m4v3(co, ob->imat, mpv->co);
-                               view3d_cached_text_draw_add(co, numstr, 0, V3D_CACHE_TEXT_WORLDSPACE|V3D_CACHE_TEXT_ASCII, col);
+                               view3d_cached_text_draw_add(co, numstr, 0, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, col);
                        }
-                       else if ((i > stepsize) && (i < len-stepsize)) { 
+                       else if ((i > stepsize) && (i < len - stepsize)) {
                                bMotionPathVert *mpvP = (mpv - stepsize);
                                bMotionPathVert *mpvN = (mpv + stepsize);
                                
-                               if ((equals_v3v3(mpv->co, mpvP->co)==0) || (equals_v3v3(mpv->co, mpvN->co)==0)) {
-                                       sprintf(numstr, "%d", (sfra+i));
+                               if ((equals_v3v3(mpv->co, mpvP->co) == 0) || (equals_v3v3(mpv->co, mpvN->co) == 0)) {
+                                       sprintf(numstr, "%d", (sfra + i));
                                        mul_v3_m4v3(co, ob->imat, mpv->co);
-                                       view3d_cached_text_draw_add(co, numstr, 0, V3D_CACHE_TEXT_WORLDSPACE|V3D_CACHE_TEXT_ASCII, col);
+                                       view3d_cached_text_draw_add(co, numstr, 0, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, col);
                                }
                        }
                }
@@ -246,7 +246,7 @@ void draw_motion_path_instance(Scene *scene,
        if (avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) {
                unsigned char col[4];
 
-               AnimData *adt= BKE_animdata_from_id(&ob->id);
+               AnimData *adt = BKE_animdata_from_id(&ob->id);
                DLRBT_Tree keys;
                
                /* build list of all keyframes in active action for object or pchan */
@@ -256,8 +256,8 @@ void draw_motion_path_instance(Scene *scene,
                        /* it is assumed that keyframes for bones are all grouped in a single group
                         * unless an option is set to always use the whole action
                         */
-                       if ((pchan) && (avs->path_viewflag & MOTIONPATH_VIEW_KFACT)==0) {
-                               bActionGroup *agrp= action_groups_find_named(adt->action, pchan->name);
+                       if ((pchan) && (avs->path_viewflag & MOTIONPATH_VIEW_KFACT) == 0) {
+                               bActionGroup *agrp = action_groups_find_named(adt->action, pchan->name);
                                
                                if (agrp) {
                                        agroup_to_keylist(adt, agrp, &keys, NULL);
@@ -272,14 +272,14 @@ void draw_motion_path_instance(Scene *scene,
                
                /* Draw slightly-larger yellow dots at each keyframe */
                UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col);
-               col[3]= 255;
+               col[3] = 255;
 
                glPointSize(4.0f); // XXX perhaps a bit too big
                glColor3ubv(col);
                
                glBegin(GL_POINTS);
-               for (i=0, mpv=mpv_start; i < len; i++, mpv++) {
-                       float mframe= (float)(sfra + i);
+               for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
+                       float mframe = (float)(sfra + i);
                        
                        if (BLI_dlrbTree_search_exact(&keys, compare_ak_cfraPtr, &mframe))
                                glVertex3fv(mpv->co);
@@ -291,15 +291,15 @@ void draw_motion_path_instance(Scene *scene,
                /* Draw frame numbers of keyframes  */
                if (avs->path_viewflag & MOTIONPATH_VIEW_KFNOS) {
                        float co[3];
-                       for (i=0, mpv=mpv_start; i < len; i++, mpv++) {
-                               float mframe= (float)(sfra + i);
+                       for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
+                               float mframe = (float)(sfra + i);
                                
                                if (BLI_dlrbTree_search_exact(&keys, compare_ak_cfraPtr, &mframe)) {
                                        char numstr[32];
                                        
-                                       sprintf(numstr, "%d", (sfra+i));
+                                       sprintf(numstr, "%d", (sfra + i));
                                        mul_v3_m4v3(co, ob->imat, mpv->co);
-                                       view3d_cached_text_draw_add(co, numstr, 0, V3D_CACHE_TEXT_WORLDSPACE|V3D_CACHE_TEXT_ASCII, col);
+                                       view3d_cached_text_draw_add(co, numstr, 0, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, col);
                                }
                        }
                }
index fae271e5beea98bcdf03b48ddf659d77038d3a2e..fec93b3b9aa87d65f095e1e766cb90cff8ee1c66 100644 (file)
 /* *************** Armature Drawing - Coloring API ***************************** */
 
 /* global here is reset before drawing each bone */
-static ThemeWireColor *bcolor= NULL;
+static ThemeWireColor *bcolor = NULL;
 
 /* values of colCode for set_pchan_glcolor */
 enum {
-       PCHAN_COLOR_NORMAL      = 0,            /* normal drawing */
-       PCHAN_COLOR_SOLID,                              /* specific case where "solid" color is needed */
-       PCHAN_COLOR_CONSTS,                             /* "constraint" colors (which may/may-not be suppressed) */
-       
-       PCHAN_COLOR_SPHEREBONE_BASE,    /* for the 'stick' of sphere (envelope) bones */
-       PCHAN_COLOR_SPHEREBONE_END,             /* for the ends of sphere (envelope) bones */
-       PCHAN_COLOR_LINEBONE                    /* for the middle of line-bones */
+       PCHAN_COLOR_NORMAL  = 0,        /* normal drawing */
+       PCHAN_COLOR_SOLID,              /* specific case where "solid" color is needed */
+       PCHAN_COLOR_CONSTS,             /* "constraint" colors (which may/may-not be suppressed) */
+
+       PCHAN_COLOR_SPHEREBONE_BASE,    /* for the 'stick' of sphere (envelope) bones */
+       PCHAN_COLOR_SPHEREBONE_END,     /* for the ends of sphere (envelope) bones */
+       PCHAN_COLOR_LINEBONE            /* for the middle of line-bones */
 };
 
 /* This function sets the color-set for coloring a certain bone */
-static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
+static void set_pchan_colorset(Object *ob, bPoseChannel *pchan)
 {
-       bPose *pose= (ob) ? ob->pose : NULL;
-       bArmature *arm= (ob) ? ob->data : NULL;
-       bActionGroup *grp= NULL;
-       short color_index= 0;
+       bPose *pose = (ob) ? ob->pose : NULL;
+       bArmature *arm = (ob) ? ob->data : NULL;
+       bActionGroup *grp = NULL;
+       short color_index = 0;
        
        /* sanity check */
        if (ELEM4(NULL, ob, arm, pose, pchan)) {
-               bcolor= NULL;
+               bcolor = NULL;
                return;
        }
        
@@ -105,9 +105,9 @@ static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
                 * has been set to use one
                 */
                if (pchan->agrp_index) {
-                       grp= (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
+                       grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
                        if (grp)
-                               color_index= grp->customCol;
+                               color_index = grp->customCol;
                }
        }
        
@@ -115,181 +115,181 @@ static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
         * color set (based on the theme colors for 3d-view) is used. 
         */
        if (color_index > 0) {
-               bTheme *btheme= UI_GetTheme();
-               bcolor= &btheme->tarm[(color_index - 1)];
+               bTheme *btheme = UI_GetTheme();
+               bcolor = &btheme->tarm[(color_index - 1)];
        }
        else if (color_index == -1) {
                /* use the group's own custom color set */
-               bcolor= (grp)? &grp->cs : NULL;
+               bcolor = (grp) ? &grp->cs : NULL;
        }
        else 
-               bcolor= NULL;
+               bcolor = NULL;
 }
 
 /* This function is for brightening/darkening a given color (like UI_ThemeColorShade()) */
-static void cp_shade_color3ub (unsigned char cp[3], const int offset)
+static void cp_shade_color3ub(unsigned char cp[3], const int offset)
 {
        int r, g, b;
        
-       r= offset + (int) cp[0];
+       r = offset + (int) cp[0];
        CLAMP(r, 0, 255);
-       g= offset + (int) cp[1];
+       g = offset + (int) cp[1];
        CLAMP(g, 0, 255);
-       b= offset + (int) cp[2];
+       b = offset + (int) cp[2];
        CLAMP(b, 0, 255);
        
-       cp[0]= r;
-       cp[1]= g;
-       cp[2]= b;
+       cp[0] = r;
+       cp[1] = g;
+       cp[2] = b;
 }
 
 /* This function sets the gl-color for coloring a certain bone (based on bcolor) */
-static short set_pchan_glColor (short colCode, int boneflag, short constflag)
+static short set_pchan_glColor(short colCode, int boneflag, short constflag)
 {
        switch (colCode) {
-       case PCHAN_COLOR_NORMAL:
-       {
-               if (bcolor) {
-                       unsigned char cp[3];
+               case PCHAN_COLOR_NORMAL:
+               {
+                       if (bcolor) {
+                               unsigned char cp[3];
                        
-                       if (boneflag & BONE_DRAW_ACTIVE) {
-                               copy_v3_v3_char((char *)cp, bcolor->active);
-                               if (!(boneflag & BONE_SELECTED)) {
-                                       cp_shade_color3ub(cp, -80);
+                               if (boneflag & BONE_DRAW_ACTIVE) {
+                                       copy_v3_v3_char((char *)cp, bcolor->active);
+                                       if (!(boneflag & BONE_SELECTED)) {
+                                               cp_shade_color3ub(cp, -80);
+                                       }
+                               }
+                               else if (boneflag & BONE_SELECTED) {
+                                       copy_v3_v3_char((char *)cp, bcolor->select);
+                               }
+                               else {
+                                       /* a bit darker than solid */
+                                       copy_v3_v3_char((char *)cp, bcolor->solid);
+                                       cp_shade_color3ub(cp, -50);
                                }
-                       }
-                       else if (boneflag & BONE_SELECTED) {
-                               copy_v3_v3_char((char *)cp, bcolor->select);
-                       }
-                       else {
-                               /* a bit darker than solid */
-                               copy_v3_v3_char((char *)cp, bcolor->solid);
-                               cp_shade_color3ub(cp, -50);
-                       }
                        
-                       glColor3ubv(cp);
-               }
-               else {
-                       if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) {
-                               UI_ThemeColorShade(TH_BONE_POSE, 40);
-                       }
-                       else if (boneflag & BONE_DRAW_ACTIVE) {
-                               UI_ThemeColorBlend(TH_WIRE, TH_BONE_POSE, 0.15f); /* unselected active */
-                       }
-                       else if (boneflag & BONE_SELECTED) {
-                               UI_ThemeColor(TH_BONE_POSE);
+                               glColor3ubv(cp);
                        }
                        else {
-                               UI_ThemeColor(TH_WIRE);
+                               if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) {
+                                       UI_ThemeColorShade(TH_BONE_POSE, 40);
+                               }
+                               else if (boneflag & BONE_DRAW_ACTIVE) {
+                                       UI_ThemeColorBlend(TH_WIRE, TH_BONE_POSE, 0.15f); /* unselected active */
+                               }
+                               else if (boneflag & BONE_SELECTED) {
+                                       UI_ThemeColor(TH_BONE_POSE);
+                               }
+                               else {
+                                       UI_ThemeColor(TH_WIRE);
+                               }
                        }
-               }
-               
-               return 1;
-       }
-               break;
        
-       case PCHAN_COLOR_SOLID:
-       {
-               if (bcolor) {
-                       glColor3ubv((unsigned char *)bcolor->solid);
+                       return 1;
                }
-               else 
-                       UI_ThemeColor(TH_BONE_SOLID);
-                       
-               return 1;
-       }
                break;
                
-       case PCHAN_COLOR_CONSTS:
-       {
-               if ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) {
-                       if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
-                       else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
-                       else if (constflag & PCHAN_HAS_SPLINEIK) glColor4ub(200, 255, 0, 80);
-                       else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
+               case PCHAN_COLOR_SOLID:
+               {
+                       if (bcolor) {
+                               glColor3ubv((unsigned char *)bcolor->solid);
+                       }
+                       else
+                               UI_ThemeColor(TH_BONE_SOLID);
                        
                        return 1;
                }
-               else 
-                       return 0;
-       }
                break;
                
-       case PCHAN_COLOR_SPHEREBONE_BASE:
-       {
-               if (bcolor) {
-                       unsigned char cp[3];
+               case PCHAN_COLOR_CONSTS:
+               {
+                       if ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) {
+                               if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
+                               else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
+                               else if (constflag & PCHAN_HAS_SPLINEIK) glColor4ub(200, 255, 0, 80);
+                               else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
                        
-                       if (boneflag & BONE_DRAW_ACTIVE) {
-                               copy_v3_v3_char((char *)cp, bcolor->active);
+                               return 1;
                        }
-                       else if (boneflag & BONE_SELECTED) {
-                               copy_v3_v3_char((char *)cp, bcolor->select);
+                       else
+                               return 0;
+               }
+               break;
+
+               case PCHAN_COLOR_SPHEREBONE_BASE:
+               {
+                       if (bcolor) {
+                               unsigned char cp[3];
+
+                               if (boneflag & BONE_DRAW_ACTIVE) {
+                                       copy_v3_v3_char((char *)cp, bcolor->active);
+                               }
+                               else if (boneflag & BONE_SELECTED) {
+                                       copy_v3_v3_char((char *)cp, bcolor->select);
+                               }
+                               else {
+                                       copy_v3_v3_char((char *)cp, bcolor->solid);
+                               }
+
+                               glColor3ubv(cp);
                        }
                        else {
-                               copy_v3_v3_char((char *)cp, bcolor->solid);
+                               if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
+                               else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
+                               else UI_ThemeColor(TH_BONE_SOLID);
                        }
                        
-                       glColor3ubv(cp);
-               }
-               else {
-                       if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
-                       else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
-                       else UI_ThemeColor(TH_BONE_SOLID);
+                       return 1;
                }
-               
-               return 1;
-       }
                break;
-       case PCHAN_COLOR_SPHEREBONE_END:
-       {
-               if (bcolor) {
-                       unsigned char cp[3];
+               case PCHAN_COLOR_SPHEREBONE_END:
+               {
+                       if (bcolor) {
+                               unsigned char cp[3];
+
+                               if (boneflag & BONE_DRAW_ACTIVE) {
+                                       copy_v3_v3_char((char *)cp, bcolor->active);
+                                       cp_shade_color3ub(cp, 10);
+                               }
+                               else if (boneflag & BONE_SELECTED) {
+                                       copy_v3_v3_char((char *)cp, bcolor->select);
+                                       cp_shade_color3ub(cp, -30);
+                               }
+                               else {
+                                       copy_v3_v3_char((char *)cp, bcolor->solid);
+                                       cp_shade_color3ub(cp, -30);
+                               }
                        
-                       if (boneflag & BONE_DRAW_ACTIVE) {
-                               copy_v3_v3_char((char *)cp, bcolor->active);
-                               cp_shade_color3ub(cp, 10);
-                       }
-                       else if (boneflag & BONE_SELECTED) {
-                               copy_v3_v3_char((char *)cp, bcolor->select);
-                               cp_shade_color3ub(cp, -30);
+                               glColor3ubv(cp);
                        }
                        else {
-                               copy_v3_v3_char((char *)cp, bcolor->solid);
-                               cp_shade_color3ub(cp, -30);
+                               if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10);
+                               else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, -30);
+                               else UI_ThemeColorShade(TH_BONE_SOLID, -30);
                        }
-                       
-                       glColor3ubv(cp);
-               }
-               else {
-                       if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10);
-                       else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, -30);
-                       else UI_ThemeColorShade(TH_BONE_SOLID, -30);
                }
-       }
                break;
                
-       case PCHAN_COLOR_LINEBONE:
-       {
-               /* inner part in background color or constraint */
-               if ( (constflag) && ((bcolor==NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) {
-                       if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
-                       else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
-                       else if (constflag & PCHAN_HAS_SPLINEIK) glColor3ub(200, 255, 0);
-                       else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
-                       else if (constflag) UI_ThemeColor(TH_BONE_POSE);        /* PCHAN_HAS_ACTION */ 
-               }
-               else {
-                       if (bcolor) {
-                               char *cp= bcolor->solid;
-                               glColor4ub(cp[0], cp[1], cp[2], 204);   
+               case PCHAN_COLOR_LINEBONE:
+               {
+                       /* inner part in background color or constraint */
+                       if ( (constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) ) {
+                               if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
+                               else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
+                               else if (constflag & PCHAN_HAS_SPLINEIK) glColor3ub(200, 255, 0);
+                               else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
+                               else if (constflag) UI_ThemeColor(TH_BONE_POSE);  /* PCHAN_HAS_ACTION */
+                       }
+                       else {
+                               if (bcolor) {
+                                       char *cp = bcolor->solid;
+                                       glColor4ub(cp[0], cp[1], cp[2], 204);
+                               }
+                               else
+                                       UI_ThemeColorShade(TH_BACK, -30);
                        }
-                       else
-                               UI_ThemeColorShade(TH_BACK, -30);
-               }
                
-               return 1;
-       }
+                       return 1;
+               }
                break;
        }
        
@@ -316,48 +316,48 @@ static void set_ebone_glColor(const unsigned int boneflag)
 
 /* half the cube, in Y */
 static float cube[8][3] = {
-{-1.0,  0.0, -1.0},
-{-1.0,  0.0,  1.0},
-{-1.0,  1.0,  1.0},
-{-1.0,  1.0, -1.0},
-{ 1.0,  0.0, -1.0},
-{ 1.0,  0.0,  1.0},
-{ 1.0,  1.0,  1.0},
-{ 1.0,  1.0, -1.0},
+       {-1.0,  0.0, -1.0},
+       {-1.0,  0.0,  1.0},
+       {-1.0,  1.0,  1.0},
+       {-1.0,  1.0, -1.0},
+       { 1.0,  0.0, -1.0},
+       { 1.0,  0.0,  1.0},
+       { 1.0,  1.0,  1.0},
+       { 1.0,  1.0, -1.0},
 };
 
 static void drawsolidcube_size(float xsize, float ysize, float zsize)
 {
-       static GLuint displist=0;
-       float n[3]= {0.0f};
+       static GLuint displist = 0;
+       float n[3] = {0.0f};
        
        glScalef(xsize, ysize, zsize);
 
-       if (displist==0) {
-               displist= glGenLists(1);
+       if (displist == 0) {
+               displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
 
                glBegin(GL_QUADS);
-               n[0]= -1.0;
+               n[0] = -1.0;
                glNormal3fv(n); 
                glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
-               n[0]=0;
-               n[1]= -1.0;
+               n[0] = 0;
+               n[1] = -1.0;
                glNormal3fv(n); 
                glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
-               n[1]=0;
-               n[0]= 1.0;
+               n[1] = 0;
+               n[0] = 1.0;
                glNormal3fv(n); 
                glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
-               n[0]=0;
-               n[1]= 1.0;
+               n[0] = 0;
+               n[1] = 1.0;
                glNormal3fv(n); 
                glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
-               n[1]=0;
-               n[2]= 1.0;
+               n[1] = 0;
+               n[2] = 1.0;
                glNormal3fv(n); 
                glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
-               n[2]= -1.0;
+               n[2] = -1.0;
                glNormal3fv(n); 
                glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
                glEnd();
@@ -370,15 +370,15 @@ static void drawsolidcube_size(float xsize, float ysize, float zsize)
 
 static void drawcube_size(float xsize, float ysize, float zsize)
 {
-       static GLuint displist=0;
+       static GLuint displist = 0;
        
        if (displist == 0) {
-               displist= glGenLists(1);
+               displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
                
                glBegin(GL_LINE_STRIP);
-               glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
-               glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
+               glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
+               glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[6]);
                glVertex3fv(cube[7]); glVertex3fv(cube[4]);
                glEnd();
                
@@ -399,17 +399,17 @@ static void drawcube_size(float xsize, float ysize, float zsize)
 
 static void draw_bonevert(void)
 {
-       static GLuint displist=0;
+       static GLuint displist = 0;
        
        if (displist == 0) {
-               GLUquadricObj   *qobj;
+               GLUquadricObj   *qobj;
                
-               displist= glGenLists(1);
+               displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
                        
                glPushMatrix();
                
-               qobj    = gluNewQuadric(); 
+               qobj    = gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
                gluDisk(qobj, 0.0,  0.05, 16, 1);
                
@@ -430,15 +430,15 @@ static void draw_bonevert(void)
 
 static void draw_bonevert_solid(void)
 {
-       static GLuint displist=0;
+       static GLuint displist = 0;
        
        if (displist == 0) {
-               GLUquadricObj   *qobj;
+               GLUquadricObj *qobj;
                
-               displist= glGenLists(1);
+               displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
                
-               qobj    = gluNewQuadric();
+               qobj = gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_FILL); 
                glShadeModel(GL_SMOOTH);
                gluSphere(qobj, 0.05, 8, 5);
@@ -451,7 +451,7 @@ static void draw_bonevert_solid(void)
        glCallList(displist);
 }
 
-static float bone_octahedral_verts[6][3]= {
+static float bone_octahedral_verts[6][3] = {
        { 0.0f, 0.0f,  0.0f},
        { 0.1f, 0.1f,  0.1f},
        { 0.1f, 0.1f, -0.1f},
@@ -460,10 +460,10 @@ static float bone_octahedral_verts[6][3]= {
        { 0.0f, 1.0f,  0.0f}
 };
 
-static unsigned int bone_octahedral_wire_sides[8]= {0, 1, 5, 3, 0, 4, 5, 2};
-static unsigned int bone_octahedral_wire_square[8]= {1, 2, 3, 4, 1};
+static unsigned int bone_octahedral_wire_sides[8] = {0, 1, 5, 3, 0, 4, 5, 2};
+static unsigned int bone_octahedral_wire_square[8] = {1, 2, 3, 4, 1};
 
-static unsigned int bone_octahedral_solid_tris[8][3]= {
+static unsigned int bone_octahedral_solid_tris[8][3] = {
        {2, 1, 0}, /* bottom */
        {3, 2, 0},
        {4, 3, 0},
@@ -476,7 +476,7 @@ static unsigned int bone_octahedral_solid_tris[8][3]= {
 };
 
 /* aligned with bone_octahedral_solid_tris */
-static float bone_octahedral_solid_normals[8][3]= {
+static float bone_octahedral_solid_normals[8][3] = {
        { 0.70710683f, -0.70710683f,  0.00000000f},
        {-0.00000000f, -0.70710683f, -0.70710683f},
        {-0.70710683f, -0.70710683f,  0.00000000f},
@@ -489,23 +489,23 @@ static float bone_octahedral_solid_normals[8][3]= {
 
 static void draw_bone_octahedral(void)
 {
-       static GLuint displist=0;
+       static GLuint displist = 0;
        
        if (displist == 0) {
-               displist= glGenLists(1);
+               displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
 
                /*      Section 1, sides */
                glEnableClientState(GL_VERTEX_ARRAY);
                glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts);
                glDrawElements(GL_LINE_LOOP,
-                              sizeof(bone_octahedral_wire_sides)/sizeof(*bone_octahedral_wire_sides),
+                              sizeof(bone_octahedral_wire_sides) / sizeof(*bone_octahedral_wire_sides),
                               GL_UNSIGNED_INT,
                               bone_octahedral_wire_sides);
 
                /*      Section 1, square */
                glDrawElements(GL_LINE_LOOP,
-                              sizeof(bone_octahedral_wire_square)/sizeof(*bone_octahedral_wire_square),
+                              sizeof(bone_octahedral_wire_square) / sizeof(*bone_octahedral_wire_square),
                               GL_UNSIGNED_INT,
                               bone_octahedral_wire_square);
                glDisableClientState(GL_VERTEX_ARRAY);
@@ -518,17 +518,17 @@ static void draw_bone_octahedral(void)
 
 static void draw_bone_solid_octahedral(void)
 {
-       static GLuint displist=0;
+       static GLuint displist = 0;
 
        if (displist == 0) {
                int i;
 
-               displist= glGenLists(1);
+               displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
 
 #if 1
                glBegin(GL_TRIANGLES);
-               for (i= 0; i < 8; i++) {
+               for (i = 0; i < 8; i++) {
                        glNormal3fv(bone_octahedral_solid_normals[i]);
                        glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][0]]);
                        glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][1]]);
@@ -537,12 +537,12 @@ static void draw_bone_solid_octahedral(void)
 
                glEnd();
 
-#else  /* not working because each vert needs a different normal */
+#else   /* not working because each vert needs a different normal */
                glEnableClientState(GL_NORMAL_ARRAY);
                glEnableClientState(GL_VERTEX_ARRAY);
                glNormalPointer(GL_FLOAT, 0, bone_octahedral_solid_normals);
                glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts);
-               glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris)/sizeof(unsigned int),
+               glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris) / sizeof(unsigned int),
                               GL_UNSIGNED_INT, bone_octahedral_solid_tris);
                glDisableClientState(GL_NORMAL_ARRAY);
                glDisableClientState(GL_VERTEX_ARRAY);
@@ -560,7 +560,7 @@ static void draw_bone_solid_octahedral(void)
 static void draw_bone_points(int dt, int armflag, unsigned int boneflag, int id)
 {
        /*      Draw root point if we are not connected */
-       if ((boneflag & BONE_CONNECTED)==0) {
+       if ((boneflag & BONE_CONNECTED) == 0) {
                if (id != -1)
                        glLoadName(id | BONESEL_ROOT);
                
@@ -622,7 +622,7 @@ static float si[16] = {
        0.10116832f
 };
 /* 16 values of cos function (still same result!) */
-static float co[16] ={
+static float co[16] = {
        1.00000000f,
        0.97952994f, 0.91895781f,
        0.82076344f, 0.68896691f,
@@ -648,25 +648,25 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel
                ebone->length = len_v3v3(ebone->head, ebone->tail);
 
                /*length= ebone->length;*/ /*UNUSED*/
-               tail= ebone->rad_tail;
-               dist= ebone->dist;
+               tail = ebone->rad_tail;
+               dist = ebone->dist;
                if (ebone->parent && (ebone->flag & BONE_CONNECTED))
-                       head= ebone->parent->rad_tail;
+                       head = ebone->parent->rad_tail;
                else
-                       head= ebone->rad_head;
-               headvec= ebone->head;
-               tailvec= ebone->tail;
+                       head = ebone->rad_head;
+               headvec = ebone->head;
+               tailvec = ebone->tail;
        }
        else {
                /*length= pchan->bone->length;*/ /*UNUSED*/
-               tail= pchan->bone->rad_tail;
-               dist= pchan->bone->dist;
+               tail = pchan->bone->rad_tail;
+               dist = pchan->bone->dist;
                if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED))
-                       head= pchan->parent->bone->rad_tail;
+                       head = pchan->parent->bone->rad_tail;
                else
-                       head= pchan->bone->rad_head;
-               headvec= pchan->pose_head;
-               tailvec= pchan->pose_tail;
+                       head = pchan->bone->rad_head;
+               headvec = pchan->pose_head;
+               tailvec = pchan->pose_tail;
        }
        
        /* ***** draw it ***** */
@@ -675,24 +675,24 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel
        sub_v3_v3v3(dirvec, tailvec, headvec);
        mul_mat3_m4_v3(smat, dirvec);
        /* clear zcomp */
-       dirvec[2]= 0.0f;
+       dirvec[2] = 0.0f;
 
        if (head != tail) {
-       /* correction when viewing along the bones axis
-        * it pops in and out but better then artifacts, [#23841] */
-               float view_dist= len_v2(dirvec);
+               /* correction when viewing along the bones axis
+                * it pops in and out but better then artifacts, [#23841] */
+               float view_dist = len_v2(dirvec);
 
                if (head - view_dist > tail) {
-                       tailvec= headvec;
+                       tailvec = headvec;
                        tail = head;
                        zero_v3(dirvec);
-                       dirvec[0]= 0.00001; // XXX. weak but ok
+                       dirvec[0] = 0.00001; // XXX. weak but ok
                }
                else if (tail - view_dist > head) {
-                       headvec= tailvec;
+                       headvec = tailvec;
                        head = tail;
                        zero_v3(dirvec);
-                       dirvec[0]= 0.00001; // XXX. weak but ok
+                       dirvec[0] = 0.00001; // XXX. weak but ok
                }
        }
 
@@ -708,10 +708,10 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel
                
                glBegin(GL_QUAD_STRIP);
                
-               for (a=0; a<16; a++) {
-                       vec[0]= - *(si+a) * dirvec[0] + *(co+a) * norvec[0];
-                       vec[1]= - *(si+a) * dirvec[1] + *(co+a) * norvec[1];
-                       vec[2]= - *(si+a) * dirvec[2] + *(co+a) * norvec[2];
+               for (a = 0; a < 16; a++) {
+                       vec[0] = -*(si + a) * dirvec[0] + *(co + a) * norvec[0];
+                       vec[1] = -*(si + a) * dirvec[1] + *(co + a) * norvec[1];
+                       vec[2] = -*(si + a) * dirvec[2] + *(co + a) * norvec[2];
 
                        madd_v3_v3v3fl(vec1, headvec, vec, head);
                        madd_v3_v3v3fl(vec2, headvec, vec, head + dist);
@@ -722,10 +722,10 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel
                        glVertex3fv(vec2);
                }
                
-               for (a=15; a>=0; a--) {
-                       vec[0]= *(si+a) * dirvec[0] + *(co+a) * norvec[0];
-                       vec[1]= *(si+a) * dirvec[1] + *(co+a) * norvec[1];
-                       vec[2]= *(si+a) * dirvec[2] + *(co+a) * norvec[2];
+               for (a = 15; a >= 0; a--) {
+                       vec[0] = *(si + a) * dirvec[0] + *(co + a) * norvec[0];
+                       vec[1] = *(si + a) * dirvec[1] + *(co + a) * norvec[1];
+                       vec[2] = *(si + a) * dirvec[2] + *(co + a) * norvec[2];
 
                        madd_v3_v3v3fl(vec1, tailvec, vec, tail);
                        madd_v3_v3v3fl(vec2, tailvec, vec, tail + dist);
@@ -737,9 +737,9 @@ static void draw_sphere_bone_dist(float smat[][4], float imat[][4], bPoseChannel
                }
                /* make it cyclic... */
                
-               vec[0]= - *(si) * dirvec[0] + *(co) * norvec[0];
-               vec[1]= - *(si) * dirvec[1] + *(co) * norvec[1];
-               vec[2]= - *(si) * dirvec[2] + *(co) * norvec[2];
+               vec[0] = -*(si) * dirvec[0] + *(co) * norvec[0];
+               vec[1] = -*(si) * dirvec[1] + *(co) * norvec[1];
+               vec[2] = -*(si) * dirvec[2] + *(co) * norvec[2];
 
                madd_v3_v3v3fl(vec1, headvec, vec, head);
                madd_v3_v3v3fl(vec2, headvec, vec, head + dist);
@@ -768,23 +768,23 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4],
                ebone->length = len_v3v3(ebone->head, ebone->tail);
                
                /*length= ebone->length;*/ /*UNUSED*/
-               tail= ebone->rad_tail;
+               tail = ebone->rad_tail;
                if (ebone->parent && (boneflag & BONE_CONNECTED))
-                       head= ebone->parent->rad_tail;
+                       head = ebone->parent->rad_tail;
                else
-                       head= ebone->rad_head;
-               headvec= ebone->head;
-               tailvec= ebone->tail;
+                       head = ebone->rad_head;
+               headvec = ebone->head;
+               tailvec = ebone->tail;
        }
        else {
                /*length= pchan->bone->length;*/ /*UNUSED*/
-               tail= pchan->bone->rad_tail;
+               tail = pchan->bone->rad_tail;
                if ((pchan->parent) && (boneflag & BONE_CONNECTED))
-                       head= pchan->parent->bone->rad_tail;
+                       head = pchan->parent->bone->rad_tail;
                else
-                       head= pchan->bone->rad_head;
-               headvec= pchan->pose_head;
-               tailvec= pchan->pose_tail;
+                       head = pchan->bone->rad_head;
+               headvec = pchan->pose_head;
+               tailvec = pchan->pose_tail;
        }
        
        /* sphere root color */
@@ -796,7 +796,7 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4],
                set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
        
        /*      Draw root point if we are not connected */
-       if ((boneflag & BONE_CONNECTED)==0) {
+       if ((boneflag & BONE_CONNECTED) == 0) {
                if (id != -1)
                        glLoadName(id | BONESEL_ROOT);
                
@@ -825,7 +825,7 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4],
        /* move vector to viewspace */
        mul_mat3_m4_v3(smat, dirvec);
        /* clear zcomp */
-       dirvec[2]= 0.0f;
+       dirvec[2] = 0.0f;
        /* move vector back */
        mul_mat3_m4_v3(imat, dirvec);
        
@@ -865,35 +865,35 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4],
 static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag, unsigned int id,
                              bPoseChannel *pchan, EditBone *ebone)
 {
-       GLUquadricObj   *qobj;
+       GLUquadricObj *qobj;
        float head, tail, length;
        float fac1, fac2;
        
        glPushMatrix();
-       qobj    = gluNewQuadric();
+       qobj = gluNewQuadric();
 
        /* figure out the sizes of spheres */
        if (ebone) {
-               length= ebone->length;
-               tail= ebone->rad_tail;
+               length = ebone->length;
+               tail = ebone->rad_tail;
                if (ebone->parent && (boneflag & BONE_CONNECTED))
-                       head= ebone->parent->rad_tail;
+                       head = ebone->parent->rad_tail;
                else
-                       head= ebone->rad_head;
+                       head = ebone->rad_head;
        }
        else {
-               length= pchan->bone->length;
-               tail= pchan->bone->rad_tail;
+               length = pchan->bone->length;
+               tail = pchan->bone->rad_tail;
                if (pchan->parent && (boneflag & BONE_CONNECTED))
-                       head= pchan->parent->bone->rad_tail;
+                       head = pchan->parent->bone->rad_tail;
                else
-                       head= pchan->bone->rad_head;
+                       head = pchan->bone->rad_head;
        }
        
        /* move to z-axis space */
        glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
 
-       if (dt==OB_SOLID) {
+       if (dt == OB_SOLID) {
                /* set up solid drawing */
                glEnable(GL_COLOR_MATERIAL);
                glEnable(GL_LIGHTING);
@@ -912,11 +912,11 @@ static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag,
        }
        else if (armflag & ARM_POSEMODE)
                set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_END, boneflag, constflag);
-       else if (dt==OB_SOLID) 
+       else if (dt == OB_SOLID)
                UI_ThemeColorShade(TH_BONE_SOLID, -30);
        
        /*      Draw root point if we are not connected */
-       if ((boneflag & BONE_CONNECTED)==0) {
+       if ((boneflag & BONE_CONNECTED) == 0) {
                if (id != -1)
                        glLoadName(id | BONESEL_ROOT);
                gluSphere(qobj, head, 16, 10);
@@ -945,38 +945,38 @@ static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag,
        else if (dt == OB_SOLID)
                UI_ThemeColor(TH_BONE_SOLID);
        
-       fac1= (length-head)/length;
-       fac2= (length-tail)/length;
+       fac1 = (length - head) / length;
+       fac2 = (length - tail) / length;
        
-       if (length > (head+tail)) {
+       if (length > (head + tail)) {
                if (id != -1)
-                       glLoadName (id | BONESEL_BONE);
+                       glLoadName(id | BONESEL_BONE);
                
                glEnable(GL_POLYGON_OFFSET_FILL);
                glPolygonOffset(-1.0f, -1.0f);
                
                glTranslatef(0.0f, 0.0f, head);
-               gluCylinder(qobj, fac1*head + (1.0f-fac1)*tail, fac2*tail + (1.0f-fac2)*head, length-head-tail, 16, 1);
+               gluCylinder(qobj, fac1 * head + (1.0f - fac1) * tail, fac2 * tail + (1.0f - fac2) * head, length - head - tail, 16, 1);
                glTranslatef(0.0f, 0.0f, -head);
                
                glDisable(GL_POLYGON_OFFSET_FILL);
                
                /* draw sphere on extrema */
-               glTranslatef(0.0f, 0.0f, length-tail);
-               gluSphere(qobj, fac2*tail + (1.0f-fac2)*head, 16, 10);
-               glTranslatef(0.0f, 0.0f, -length+tail);
+               glTranslatef(0.0f, 0.0f, length - tail);
+               gluSphere(qobj, fac2 * tail + (1.0f - fac2) * head, 16, 10);
+               glTranslatef(0.0f, 0.0f, -length + tail);
                
                glTranslatef(0.0f, 0.0f, head);
-               gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
+               gluSphere(qobj, fac1 * head + (1.0f - fac1) * tail, 16, 10);
        }
        else {          
                /* 1 sphere in center */
-               glTranslatef(0.0f, 0.0f, (head + length-tail)/2.0f);
-               gluSphere(qobj, fac1*head + (1.0f-fac1)*tail, 16, 10);
+               glTranslatef(0.0f, 0.0f, (head + length - tail) / 2.0f);
+               gluSphere(qobj, fac1 * head + (1.0f - fac1) * tail, 16, 10);
        }
        
        /* restore */
-       if (dt==OB_SOLID) {
+       if (dt == OB_SOLID) {
                glShadeModel(GL_FLAT);
                glDisable(GL_LIGHTING);
                glDisable(GL_COLOR_MATERIAL);
@@ -986,11 +986,11 @@ static void draw_sphere_bone(int dt, int armflag, int boneflag, short constflag,
        gluDeleteQuadric(qobj);  
 }
 
-static GLubyte bm_dot6[]= {0x0, 0x18, 0x3C, 0x7E, 0x7E, 0x3C, 0x18, 0x0}; 
-static GLubyte bm_dot8[]= {0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C}; 
+static GLubyte bm_dot6[] = {0x0, 0x18, 0x3C, 0x7E, 0x7E, 0x3C, 0x18, 0x0};
+static GLubyte bm_dot8[] = {0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C};
 
-static GLubyte bm_dot5[]= {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0}; 
-static GLubyte bm_dot7[]= {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38}; 
+static GLubyte bm_dot5[] = {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
+static GLubyte bm_dot7[] = {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
 
 
 static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned int id,
@@ -1001,15 +1001,15 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        
        if (pchan) 
-               length= pchan->bone->length;
+               length = pchan->bone->length;
        else 
-               length= ebone->length;
+               length = ebone->length;
        
        glPushMatrix();
        glScalef(length, length, length);
        
        /* this chunk not in object mode */
-       if (armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
+       if (armflag & (ARM_EDITMODE | ARM_POSEMODE)) {
                glLineWidth(4.0f);
                if (armflag & ARM_POSEMODE)
                        set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
@@ -1018,9 +1018,9 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
                }
                
                /*      Draw root point if we are not connected */
-               if ((boneflag & BONE_CONNECTED)==0) {
-                       if (G.f & G_PICKSEL) {  // no bitmap in selection mode, crashes 3d cards...
-                               glLoadName (id | BONESEL_ROOT);
+               if ((boneflag & BONE_CONNECTED) == 0) {
+                       if (G.f & G_PICKSEL) {  // no bitmap in selection mode, crashes 3d cards...
+                               glLoadName(id | BONESEL_ROOT);
                                glBegin(GL_POINTS);
                                glVertex3f(0.0f, 0.0f, 0.0f);
                                glEnd();
@@ -1032,7 +1032,7 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
                }
                
                if (id != -1)
-                       glLoadName((GLuint) id|BONESEL_BONE);
+                       glLoadName((GLuint) id | BONESEL_BONE);
                
                glBegin(GL_LINES);
                glVertex3f(0.0f, 0.0f, 0.0f);
@@ -1054,7 +1054,7 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
                
                /* further we send no names */
                if (id != -1)
-                       glLoadName(id & 0xFFFF);        /* object tag, for bordersel optim */
+                       glLoadName(id & 0xFFFF);  /* object tag, for bordersel optim */
                
                if (armflag & ARM_POSEMODE)
                        set_pchan_glColor(PCHAN_COLOR_LINEBONE, boneflag, constflag);
@@ -1063,8 +1063,8 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
        glLineWidth(2.0);
        
        /*Draw root point if we are not connected */
-       if ((boneflag & BONE_CONNECTED)==0) {
-               if ((G.f & G_PICKSEL)==0) {     
+       if ((boneflag & BONE_CONNECTED) == 0) {
+               if ((G.f & G_PICKSEL) == 0) {
                        /* no bitmap in selection mode, crashes 3d cards... */
                        if (armflag & ARM_EDITMODE) {
                                if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
@@ -1085,7 +1085,7 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
        glEnd();
        
        /* tip */
-       if ((G.f & G_PICKSEL)==0) {     
+       if ((G.f & G_PICKSEL) == 0) {
                /* no bitmap in selection mode, crashes 3d cards... */
                if (armflag & ARM_EDITMODE) {
                        if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
@@ -1102,27 +1102,27 @@ static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned
 
 static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float length, float zwidth)
 {
-       int segments= 0;
+       int segments = 0;
        
        if (pchan) 
-               segments= pchan->bone->segments;
+               segments = pchan->bone->segments;
        
        if ((segments > 1) && (pchan)) {
-               float dlen= length/(float)segments;
-               Mat4 *bbone= b_bone_spline_setup(pchan, 0);
+               float dlen = length / (float)segments;
+               Mat4 *bbone = b_bone_spline_setup(pchan, 0);
                int a;
                
-               for (a=0; a<segments; a++, bbone++) {
+               for (a = 0; a < segments; a++, bbone++) {
                        glPushMatrix();
                        glMultMatrixf(bbone->mat);
-                       if (dt==OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
+                       if (dt == OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
                        else drawcube_size(xwidth, dlen, zwidth);
                        glPopMatrix();
                }
        }
        else {
                glPushMatrix();
-               if (dt==OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
+               if (dt == OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
                else drawcube_size(xwidth, length, zwidth);
                glPopMatrix();
        }
@@ -1134,14 +1134,14 @@ static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsi
        float xwidth, length, zwidth;
        
        if (pchan) {
-               xwidth= pchan->bone->xwidth;
-               length= pchan->bone->length;
-               zwidth= pchan->bone->zwidth;
+               xwidth = pchan->bone->xwidth;
+               length = pchan->bone->length;
+               zwidth = pchan->bone->zwidth;
        }
        else {
-               xwidth= ebone->xwidth;
-               length= ebone->length;
-               zwidth= ebone->zwidth;
+               xwidth = ebone->xwidth;
+               length = ebone->length;
+               zwidth = ebone->zwidth;
        }
        
        /* draw points only if... */
@@ -1151,7 +1151,7 @@ static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsi
                glScalef(length, length, length);
                draw_bone_points(dt, armflag, boneflag, id);
                glPopMatrix();
-               length*= 0.95f; // make vertices visible
+               length *= 0.95f; // make vertices visible
        }
 
        /* colors for modes */
@@ -1162,7 +1162,7 @@ static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsi
                        set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
        }
        else if (armflag & ARM_EDITMODE) {
-               if (dt==OB_WIRE) {
+               if (dt == OB_WIRE) {
                        set_ebone_glColor(boneflag);
                }
                else 
@@ -1170,7 +1170,7 @@ static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsi
        }
        
        if (id != -1) {
-               glLoadName ((GLuint) id|BONESEL_BONE);
+               glLoadName((GLuint) id | BONESEL_BONE);
        }
        
        /* set up solid drawing */
@@ -1214,11 +1214,11 @@ static void draw_b_bone(int dt, int armflag, int boneflag, short constflag, unsi
 static void draw_wire_bone_segments(bPoseChannel *pchan, Mat4 *bbones, float length, int segments)
 {
        if ((segments > 1) && (pchan)) {
-               float dlen= length/(float)segments;
+               float dlen = length / (float)segments;
                Mat4 *bbone = bbones;
                int a;
                
-               for (a=0; a<segments; a++, bbone++) {
+               for (a = 0; a < segments; a++, bbone++) {
                        glPushMatrix();
                        glMultMatrixf(bbone->mat);
                        
@@ -1250,14 +1250,14 @@ static void draw_wire_bone(int dt, int armflag, int boneflag, short constflag, u
        float length;
        
        if (pchan) {
-               segments= pchan->bone->segments;
-               length= pchan->bone->length;
+               segments = pchan->bone->segments;
+               length = pchan->bone->length;
                
                if (segments > 1)
                        bbones = b_bone_spline_setup(pchan, 0);
        }
        else 
-               length= ebone->length;
+               length = ebone->length;
        
        /* draw points only if... */
        if (armflag & ARM_EDITMODE) {
@@ -1266,19 +1266,19 @@ static void draw_wire_bone(int dt, int armflag, int boneflag, short constflag, u
                glScalef(length, length, length);
                draw_bone_points(dt, armflag, boneflag, id);
                glPopMatrix();
-               length *= 0.95f;        // make vertices visible
+               length *= 0.95f;    // make vertices visible
        }
        
        /* this chunk not in object mode */
-       if (armflag & (ARM_EDITMODE|ARM_POSEMODE)) {
+       if (armflag & (ARM_EDITMODE | ARM_POSEMODE)) {
                if (id != -1)
-                       glLoadName((GLuint) id|BONESEL_BONE);
+                       glLoadName((GLuint) id | BONESEL_BONE);
                
                draw_wire_bone_segments(pchan, bbones, length, segments);
                
                /* further we send no names */
                if (id != -1)
-                       glLoadName(id & 0xFFFF);        /* object tag, for bordersel optim */
+                       glLoadName(id & 0xFFFF);    /* object tag, for bordersel optim */
        }
        
        /* colors for modes */
@@ -1321,7 +1321,7 @@ static void draw_bone(int dt, int armflag, int boneflag, short constflag, unsign
        
        /* now draw the bone itself */
        if (id != -1) {
-               glLoadName((GLuint) id|BONESEL_BONE);
+               glLoadName((GLuint) id | BONESEL_BONE);
        }
        
        /* wire? */
@@ -1366,7 +1366,7 @@ static void draw_bone(int dt, int armflag, int boneflag, short constflag, unsign
 static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob,
                              int dt, int armflag, int boneflag, unsigned int id, float length)
 {
-       if (ob==NULL) return;
+       if (ob == NULL) return;
        
        glScalef(length, length, length);
        
@@ -1376,7 +1376,7 @@ static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Obje
        }
        
        if (id != -1) {
-               glLoadName((GLuint) id|BONESEL_BONE);
+               glLoadName((GLuint) id | BONESEL_BONE);
        }
        
        draw_object_instance(scene, v3d, rv3d, ob, dt, armflag & ARM_POSEMODE);
@@ -1388,15 +1388,15 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
        bConstraint *con;
        bPoseChannel *parchan;
        
-       for (con= pchan->constraints.first; con; con= con->next) {
+       for (con = pchan->constraints.first; con; con = con->next) {
                if (con->enforce == 0.0f)
                        continue;
                
                switch (con->type) {
                        case CONSTRAINT_TYPE_KINEMATIC:
                        {
-                               bKinematicConstraint *data = (bKinematicConstraint*)con->data;
-                               int segcount= 0;
+                               bKinematicConstraint *data = (bKinematicConstraint *)con->data;
+                               int segcount = 0;
                                
                                /* if only_temp, only draw if it is a temporary ik-chain */
                                if ((only_temp) && !(data->flag & CONSTRAINT_IK_TEMP))
@@ -1406,18 +1406,18 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
                                glBegin(GL_LINES);
                                
                                /* exclude tip from chain? */
-                               if ((data->flag & CONSTRAINT_IK_TIP)==0)
-                                       parchan= pchan->parent;
+                               if ((data->flag & CONSTRAINT_IK_TIP) == 0)
+                                       parchan = pchan->parent;
                                else
-                                       parchan= pchan;
+                                       parchan = pchan;
                                
                                glVertex3fv(parchan->pose_tail);
                                
                                /* Find the chain's root */
                                while (parchan->parent) {
                                        segcount++;
-                                       if (segcount==data->rootbone || segcount>255) break; // 255 is weak
-                                       parchan= parchan->parent;
+                                       if (segcount == data->rootbone || segcount > 255) break;  // 255 is weak
+                                       parchan = parchan->parent;
                                }
                                if (parchan)
                                        glVertex3fv(parchan->pose_head);
@@ -1425,24 +1425,24 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
                                glEnd();
                                setlinestyle(0);
                        }
-                               break;
+                       break;
                        case CONSTRAINT_TYPE_SPLINEIK: 
                        {
-                               bSplineIKConstraint *data = (bSplineIKConstraint*)con->data;
-                               int segcount= 0;
+                               bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
+                               int segcount = 0;
                                
                                setlinestyle(3);
                                glBegin(GL_LINES);
                                
-                               parchan= pchan;
+                               parchan = pchan;
                                glVertex3fv(parchan->pose_tail);
                                
                                /* Find the chain's root */
                                while (parchan->parent) {
                                        segcount++;
                                        // FIXME: revise the breaking conditions
-                                       if (segcount==data->chainlen || segcount>255) break; // 255 is weak
-                                       parchan= parchan->parent;
+                                       if (segcount == data->chainlen || segcount > 255) break;  // 255 is weak
+                                       parchan = parchan->parent;
                                }
                                if (parchan) // XXX revise the breaking conditions to only stop at the tail?
                                        glVertex3fv(parchan->pose_head);
@@ -1450,7 +1450,7 @@ static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
                                glEnd();
                                setlinestyle(0);
                        }
-                               break;
+                       break;
                }
        }
 }
@@ -1459,12 +1459,12 @@ static void bgl_sphere_project(float ax, float az)
 {
        float dir[3], sine, q3;
 
-       sine= 1.0f - ax*ax - az*az;
-       q3= (sine < 0.0f)? 0.0f: (float)(2.0*sqrt(sine));
+       sine = 1.0f - ax * ax - az * az;
+       q3 = (sine < 0.0f) ? 0.0f : (float)(2.0 * sqrt(sine));
 
-       dir[0]= -az*q3;
-       dir[1]= 1.0f - 2.0f*sine;
-       dir[2]= ax*q3;
+       dir[0] = -az * q3;
+       dir[1] = 1.0f - 2.0f * sine;
+       dir[2] = ax * q3;
 
        glVertex3fv(dir);
 }
@@ -1479,7 +1479,7 @@ static void draw_dof_ellipse(float ax, float az)
                0.994521895368f, 1.0f
        };
 
-       int i, j, n=16;
+       int i, j, n = 16;
        float x, z, px, pz;
 
        glEnable(GL_BLEND);
@@ -1488,33 +1488,33 @@ static void draw_dof_ellipse(float ax, float az)
        glColor4ub(70, 70, 70, 50);
 
        glBegin(GL_QUADS);
-       pz= 0.0f;
-       for (i=1; i<n; i++) {
-               z= staticSine[i];
+       pz = 0.0f;
+       for (i = 1; i < n; i++) {
+               z = staticSine[i];
                
-               px= 0.0f;
-               for (j=1; j<n-i+1; j++) {
+               px = 0.0f;
+               for (j = 1; j < n - i + 1; j++) {
                        x = staticSine[j];
                        
-                       if (j == n-i) {
+                       if (j == n - i) {
                                glEnd();
                                glBegin(GL_TRIANGLES);
-                               bgl_sphere_project(ax*px, az*z);
-                               bgl_sphere_project(ax*px, az*pz);
-                               bgl_sphere_project(ax*x, az*pz);
+                               bgl_sphere_project(ax * px, az * z);
+                               bgl_sphere_project(ax * px, az * pz);
+                               bgl_sphere_project(ax * x, az * pz);
                                glEnd();
                                glBegin(GL_QUADS);
                        }
                        else {
-                               bgl_sphere_project(ax*x, az*z);
-                               bgl_sphere_project(ax*x, az*pz);
-                               bgl_sphere_project(ax*px, az*pz);
-                               bgl_sphere_project(ax*px, az*z);
+                               bgl_sphere_project(ax * x, az * z);
+                               bgl_sphere_project(ax * x, az * pz);
+                               bgl_sphere_project(ax * px, az * pz);
+                               bgl_sphere_project(ax * px, az * z);
                        }
                        
-                       px= x;
+                       px = x;
                }
-               pz= z;
+               pz = z;
        }
        glEnd();
 
@@ -1524,27 +1524,27 @@ static void draw_dof_ellipse(float ax, float az)
        glColor3ub(0, 0, 0);
 
        glBegin(GL_LINE_STRIP);
-       for (i=0; i<n; i++)
-               bgl_sphere_project(staticSine[n-i-1]*ax, staticSine[i]*az);
+       for (i = 0; i < n; i++)
+               bgl_sphere_project(staticSine[n - i - 1] * ax, staticSine[i] * az);
        glEnd();
 }
 
 static void draw_pose_dofs(Object *ob)
 {
-       bArmature *arm= ob->data;
+       bArmature *arm = ob->data;
        bPoseChannel *pchan;
        Bone *bone;
        
-       for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-               bone= pchan->bone;
+       for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+               bone = pchan->bone;
                
-               if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
+               if ( (bone) && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
                        if (bone->flag & BONE_SELECTED) {
                                if (bone->layer & arm->layer) {
-                                       if (pchan->ikflag & (BONE_IK_XLIMIT|BONE_IK_ZLIMIT)) {
+                                       if (pchan->ikflag & (BONE_IK_XLIMIT | BONE_IK_ZLIMIT)) {
                                                if (ED_pose_channel_in_IK_chain(ob, pchan)) {
                                                        float corner[4][3], posetrans[3], mat[4][4];
-                                                       float phi=0.0f, theta=0.0f, scale;
+                                                       float phi = 0.0f, theta = 0.0f, scale;
                                                        int a, i;
                                                        
                                                        /* in parent-bone pose, but own restspace */
@@ -1555,24 +1555,24 @@ static void draw_pose_dofs(Object *ob)
                                                        
                                                        if (pchan->parent) {
                                                                copy_m4_m4(mat, pchan->parent->pose_mat);
-                                                               mat[3][0]= mat[3][1]= mat[3][2]= 0.0f;
+                                                               mat[3][0] = mat[3][1] = mat[3][2] = 0.0f;
                                                                glMultMatrixf(mat);
                                                        }
                                                        
                                                        copy_m4_m3(mat, pchan->bone->bone_mat);
                                                        glMultMatrixf(mat);
                                                        
-                                                       scale= bone->length*pchan->size[1];
+                                                       scale = bone->length * pchan->size[1];
                                                        glScalef(scale, scale, scale);
                                                        
                                                        if (pchan->ikflag & BONE_IK_XLIMIT) {
                                                                if (pchan->ikflag & BONE_IK_ZLIMIT) {
                                                                        float amin[3], amax[3];
                                                                        
-                                                                       for (i=0; i<3; i++) {
+                                                                       for (i = 0; i < 3; i++) {
                                                                                /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
-                                                                               amin[i]= (float)sin(pchan->limitmin[i]*0.5f);
-                                                                               amax[i]= (float)sin(pchan->limitmax[i]*0.5f);
+                                                                               amin[i] = (float)sin(pchan->limitmin[i] * 0.5f);
+                                                                               amax[i] = (float)sin(pchan->limitmax[i] * 0.5f);
                                                                        }
                                                                        
                                                                        glScalef(1.0f, -1.0f, 1.0f);
@@ -1591,21 +1591,21 @@ static void draw_pose_dofs(Object *ob)
                                                        /* arcs */
                                                        if (pchan->ikflag & BONE_IK_ZLIMIT) {
                                                                /* OpenGL requires rotations in degrees; so we're taking the average angle here */
-                                                               theta= RAD2DEGF(0.5f * (pchan->limitmin[2]+pchan->limitmax[2]));
+                                                               theta = RAD2DEGF(0.5f * (pchan->limitmin[2] + pchan->limitmax[2]));
                                                                glRotatef(theta, 0.0f, 0.0f, 1.0f);
                                                                
-                                                               glColor3ub(50, 50, 255);        // blue, Z axis limit
+                                                               glColor3ub(50, 50, 255);    // blue, Z axis limit
                                                                glBegin(GL_LINE_STRIP);
-                                                               for (a=-16; a<=16; a++) {
+                                                               for (a = -16; a <= 16; a++) {
                                                                        /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
-                                                                       float fac= ((float)a)/16.0f * 0.5f;
+                                                                       float fac = ((float)a) / 16.0f * 0.5f;
                                                                        
-                                                                       phi= fac * (pchan->limitmax[2] - pchan->limitmin[2]);
+                                                                       phi = fac * (pchan->limitmax[2] - pchan->limitmin[2]);
                                                                        
-                                                                       i= (a == -16) ? 0 : 1;
-                                                                       corner[i][0]= (float)sin(phi);
-                                                                       corner[i][1]= (float)cos(phi);
-                                                                       corner[i][2]= 0.0f;
+                                                                       i = (a == -16) ? 0 : 1;
+                                                                       corner[i][0] = (float)sin(phi);
+                                                                       corner[i][1] = (float)cos(phi);
+                                                                       corner[i][2] = 0.0f;
                                                                        glVertex3fv(corner[i]);
                                                                }
                                                                glEnd();
@@ -1615,20 +1615,20 @@ static void draw_pose_dofs(Object *ob)
                                                        
                                                        if (pchan->ikflag & BONE_IK_XLIMIT) {
                                                                /* OpenGL requires rotations in degrees; so we're taking the average angle here */
-                                                               theta= RAD2DEGF(0.5f * (pchan->limitmin[0] + pchan->limitmax[0]));
+                                                               theta = RAD2DEGF(0.5f * (pchan->limitmin[0] + pchan->limitmax[0]));
                                                                glRotatef(theta, 1.0f, 0.0f, 0.0f);
                                                                
-                                                               glColor3ub(255, 50, 50);        // Red, X axis limit
+                                                               glColor3ub(255, 50, 50);    // Red, X axis limit
                                                                glBegin(GL_LINE_STRIP);
-                                                               for (a=-16; a<=16; a++) {
+                                                               for (a = -16; a <= 16; a++) {
                                                                        /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
-                                                                       float fac= ((float)a)/16.0f * 0.5f;
-                                                                       phi= (float)(0.5*M_PI) + fac * (pchan->limitmax[0] - pchan->limitmin[0]);
+                                                                       float fac = ((float)a) / 16.0f * 0.5f;
+                                                                       phi = (float)(0.5 * M_PI) + fac * (pchan->limitmax[0] - pchan->limitmin[0]);
                                                                        
-                                                                       i= (a == -16) ? 2 : 3;
-                                                                       corner[i][0]= 0.0f;
-                                                                       corner[i][1]= (float)sin(phi);
-                                                                       corner[i][2]= (float)cos(phi);
+                                                                       i = (a == -16) ? 2 : 3;
+                                                                       corner[i][0] = 0.0f;
+                                                                       corner[i][1] = (float)sin(phi);
+                                                                       corner[i][2] = (float)cos(phi);
                                                                        glVertex3fv(corner[i]);
                                                                }
                                                                glEnd();
@@ -1659,19 +1659,19 @@ static void bone_matrix_translate_y(float mat[][4], float y)
 static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt,
                             const short is_ghost, const short is_outline)
 {
-       RegionView3D *rv3d= ar->regiondata;
-       Object *ob= base->object;
-       bArmature *arm= ob->data;
+       RegionView3D *rv3d = ar->regiondata;
+       Object *ob = base->object;
+       bArmature *arm = ob->data;
        bPoseChannel *pchan;
        Bone *bone;
        GLfloat tmp;
        float smat[4][4], imat[4][4], bmat[4][4];
-       int index= -1;
-       short do_dashed= 3, draw_wire= 0;
+       int index = -1;
+       short do_dashed = 3, draw_wire = 0;
        int flag;
        
        /* being set below */
-       arm->layer_used= 0;
+       arm->layer_used = 0;
        
        /* hacky... prevent outline select from drawing dashed helplines */
        glGetFloatv(GL_LINE_WIDTH, &tmp);
@@ -1679,10 +1679,10 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
        if (v3d->flag & V3D_HIDE_HELPLINES) do_dashed &= ~2;
        
        /* precalc inverse matrix for drawing screen aligned */
-       if (arm->drawtype==ARM_ENVELOPE) {
+       if (arm->drawtype == ARM_ENVELOPE) {
                /* precalc inverse matrix for drawing screen aligned */
                copy_m4_m4(smat, rv3d->viewmatob);
-               mul_mat3_m4_fl(smat, 1.0f/len_v3(ob->obmat[0]));
+               mul_mat3_m4_fl(smat, 1.0f / len_v3(ob->obmat[0]));
                invert_m4_m4(imat, smat);
                
                /* and draw blended distances */
@@ -1692,14 +1692,14 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                        
                        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
                        
-                       for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                               bone= pchan->bone;
+                       for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+                               bone = pchan->bone;
                                if (bone) {
                                        /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] 
                                         * NOTE: this is the only case with NO_DEFORM==0 flag, as this is for envelope influence drawing 
                                         */
-                                       if ( (bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))==0 && 
-                                                ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) ) 
+                                       if ( (bone->flag & (BONE_HIDDEN_P | BONE_NO_DEFORM | BONE_HIDDEN_PG)) == 0 &&
+                                            ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) )
                                        {
                                                if (bone->flag & (BONE_SELECTED)) {
                                                        if (bone->layer & arm->layer)
@@ -1722,15 +1722,15 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
        /* if solid we draw that first, with selection codes, but without names, axes etc */
        if (dt > OB_WIRE) {
                if (arm->flag & ARM_POSEMODE) 
-                       index= base->selcol;
+                       index = base->selcol;
                
-               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                       bone= pchan->bone;
+               for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+                       bone = pchan->bone;
                        arm->layer_used |= bone->layer;
                        
                        /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
-                       if ( (bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0 && 
-                                ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) ) 
+                       if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 &&
+                            ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) )
                        {
                                if (bone->layer & arm->layer) {
                                        int use_custom = (pchan->custom) && !(arm->flag & ARM_NO_CUSTOM);
@@ -1744,8 +1744,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                        }
                                        
                                        /* catch exception for bone with hidden parent */
-                                       flag= bone->flag;
-                                       if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) )
+                                       flag = bone->flag;
+                                       if ( (bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) )
                                                flag &= ~BONE_CONNECTED;
                                        
                                        /* set temporary flag for drawing bone as active, but only if selected */
@@ -1758,7 +1758,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                        if (use_custom) {
                                                /* if drawwire, don't try to draw in solid */
                                                if (pchan->bone->flag & BONE_DRAWWIRE) {
-                                                       draw_wire= 1;
+                                                       draw_wire = 1;
                                                }
                                                else {
                                                        draw_custom_bone(scene, v3d, rv3d, pchan->custom,
@@ -1785,34 +1785,34 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                }
                        }
                        
-                       if (index!= -1) 
-                               index+= 0x10000;        // pose bones count in higher 2 bytes only
+                       if (index != -1)
+                               index += 0x10000;   // pose bones count in higher 2 bytes only
                }
                
                /* very very confusing... but in object mode, solid draw, we cannot do glLoadName yet,
                 * stick bones and/or wire custom-shapes are drawn in next loop 
                 */
-               if (ELEM(arm->drawtype,ARM_LINE,ARM_WIRE)==0 && (draw_wire == 0)) {
+               if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE) == 0 && (draw_wire == 0)) {
                        /* object tag, for bordersel optim */
                        glLoadName(index & 0xFFFF);     
-                       index= -1;
+                       index = -1;
                }
        }
        
        /* draw custom bone shapes as wireframes */
-       if ( !(arm->flag & ARM_NO_CUSTOM) &&
-                ((draw_wire) || (dt <= OB_WIRE)) ) 
+       if (!(arm->flag & ARM_NO_CUSTOM) &&
+           ((draw_wire) || (dt <= OB_WIRE)) )
        {
                if (arm->flag & ARM_POSEMODE)
-                       index= base->selcol;
+                       index = base->selcol;
                        
                /* only draw custom bone shapes that need to be drawn as wires */
-               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                       bone= pchan->bone;
+               for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+                       bone = pchan->bone;
                        
                        /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
-                       if ( (bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0 && 
-                                ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) ) 
+                       if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 &&
+                            ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) )
                        {
                                if (bone->layer & arm->layer) {
                                        if (pchan->custom) {
@@ -1833,19 +1833,19 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                                        else if (arm->flag & ARM_POSEMODE)      
                                                                set_pchan_colorset(ob, pchan);
                                                        else {
-                                                               if ((scene->basact)==base) {
-                                                                       if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_ACTIVE);
+                                                               if ((scene->basact) == base) {
+                                                                       if (base->flag & (SELECT + BA_WAS_SEL)) UI_ThemeColor(TH_ACTIVE);
                                                                        else UI_ThemeColor(TH_WIRE);
                                                                }
                                                                else {
-                                                                       if (base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_SELECT);
+                                                                       if (base->flag & (SELECT + BA_WAS_SEL)) UI_ThemeColor(TH_SELECT);
                                                                        else UI_ThemeColor(TH_WIRE);
                                                                }
                                                        }
                                                                
                                                        /* catch exception for bone with hidden parent */
-                                                       flag= bone->flag;
-                                                       if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
+                                                       flag = bone->flag;
+                                                       if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)))
                                                                flag &= ~BONE_CONNECTED;
                                                                
                                                        /* set temporary flag for drawing bone as active, but only if selected */
@@ -1862,13 +1862,13 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                        }
                        
                        if (index != -1) 
-                               index+= 0x10000;        // pose bones count in higher 2 bytes only
+                               index += 0x10000;   // pose bones count in higher 2 bytes only
                }
                /* stick or wire bones have not been drawn yet so don't clear object selection in this case */
-               if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)==0 && draw_wire) {
+               if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE) == 0 && draw_wire) {
                        /* object tag, for bordersel optim */
                        glLoadName(index & 0xFFFF);     
-                       index= -1;
+                       index = -1;
                }
        }
        
@@ -1877,7 +1877,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                /* draw line check first. we do selection indices */
                if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
                        if (arm->flag & ARM_POSEMODE) 
-                               index= base->selcol;
+                               index = base->selcol;
                }
                /* if solid && posemode, we draw again with polygonoffset */
                else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
@@ -1886,26 +1886,26 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                else {
                        /* and we use selection indices if not done yet */
                        if (arm->flag & ARM_POSEMODE) 
-                               index= base->selcol;
+                               index = base->selcol;
                }
                
-               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                       bone= pchan->bone;
+               for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+                       bone = pchan->bone;
                        arm->layer_used |= bone->layer;
                        
                        /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
-                       if ( (bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0 && 
-                                ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) ) 
+                       if ( (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0 &&
+                            ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) )
                        {
                                if (bone->layer & arm->layer) {
-                                       const short constflag= pchan->constflag;
+                                       const short constflag = pchan->constflag;
                                        if ((do_dashed & 1) && (pchan->parent)) {
                                                /* Draw a line from our root to the parent's tip 
                                                 *      - only if V3D_HIDE_HELPLINES is enabled...
                                                 */
-                                               if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED)==0) ) {
+                                               if ( (do_dashed & 2) && ((bone->flag & BONE_CONNECTED) == 0) ) {
                                                        if (arm->flag & ARM_POSEMODE) {
-                                                               glLoadName(index & 0xFFFF);     // object tag, for bordersel optim
+                                                               glLoadName(index & 0xFFFF); // object tag, for bordersel optim
                                                                UI_ThemeColor(TH_WIRE);
                                                        }
                                                        setlinestyle(3);
@@ -1917,13 +1917,13 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                                }
                                                
                                                /* Draw a line to IK root bone 
-                                                *      - only if temporary chain (i.e. "autoik")
+                                                *  - only if temporary chain (i.e. "autoik")
                                                 */
                                                if (arm->flag & ARM_POSEMODE) {
                                                        if (constflag & PCHAN_HAS_IK) {
                                                                if (bone->flag & BONE_SELECTED) {
                                                                        if (constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
-                                                                       else glColor3ub(200, 200, 50);  // add theme!
+                                                                       else glColor3ub(200, 200, 50);  // add theme!
                                                                        
                                                                        glLoadName(index & 0xFFFF);
                                                                        pchan_draw_IK_root_lines(pchan, !(do_dashed & 2));
@@ -1931,7 +1931,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                                        }
                                                        else if (constflag & PCHAN_HAS_SPLINEIK) {
                                                                if (bone->flag & BONE_SELECTED) {
-                                                                       glColor3ub(150, 200, 50);       // add theme!
+                                                                       glColor3ub(150, 200, 50);   // add theme!
                                                                        
                                                                        glLoadName(index & 0xFFFF);
                                                                        pchan_draw_IK_root_lines(pchan, !(do_dashed & 2));
@@ -1945,8 +1945,8 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                                glMultMatrixf(pchan->pose_mat);
                                        
                                        /* catch exception for bone with hidden parent */
-                                       flag= bone->flag;
-                                       if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)))
+                                       flag = bone->flag;
+                                       if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)))
                                                flag &= ~BONE_CONNECTED;
                                        
                                        /* set temporary flag for drawing bone as active, but only if selected */
@@ -1961,15 +1961,15 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                        if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
                                                /* custom bone shapes should not be drawn here! */
                                        }
-                                       else if (arm->drawtype==ARM_ENVELOPE) {
+                                       else if (arm->drawtype == ARM_ENVELOPE) {
                                                if (dt < OB_SOLID)
                                                        draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL);
                                        }
-                                       else if (arm->drawtype==ARM_LINE)
+                                       else if (arm->drawtype == ARM_LINE)
                                                draw_line_bone(arm->flag, flag, constflag, index, pchan, NULL);
-                                       else if (arm->drawtype==ARM_WIRE)
+                                       else if (arm->drawtype == ARM_WIRE)
                                                draw_wire_bone(dt, arm->flag, flag, constflag, index, pchan, NULL);
-                                       else if (arm->drawtype==ARM_B_BONE)
+                                       else if (arm->drawtype == ARM_B_BONE)
                                                draw_b_bone(OB_WIRE, arm->flag, flag, constflag, index, pchan, NULL);
                                        else
                                                draw_bone(OB_WIRE, arm->flag, flag, constflag, index, bone->length);
@@ -1980,10 +1980,10 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                        
                        /* pose bones count in higher 2 bytes only */
                        if (index != -1) 
-                               index+= 0x10000;        
+                               index += 0x10000;
                }
                /* restore things */
-               if (!ELEM(arm->drawtype, ARM_WIRE, ARM_LINE) && (dt>OB_WIRE) && (arm->flag & ARM_POSEMODE))
+               if (!ELEM(arm->drawtype, ARM_WIRE, ARM_LINE) && (dt > OB_WIRE) && (arm->flag & ARM_POSEMODE))
                        bglPolygonOffset(rv3d->dist, 0.0);
        }       
        
@@ -1995,7 +1995,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                draw_pose_dofs(ob);
 
        /* finally names and axes */
-       if ((arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) && (is_outline == 0)) {
+       if ((arm->flag & (ARM_DRAWNAMES | ARM_DRAWAXES)) && (is_outline == 0)) {
                /* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
                if ((G.f & G_PICKSEL) == 0) {
                        float vec[3];
@@ -2004,22 +2004,22 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                        float col_f[4];
                        glGetFloatv(GL_CURRENT_COLOR, col_f); /* in case this is not set below */
                        rgb_float_to_uchar(col, col_f);
-                       col[3]= 255;
+                       col[3] = 255;
                        
                        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
                        
-                       for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
-                               if ((pchan->bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0) {
+                       for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+                               if ((pchan->bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) {
                                        if (pchan->bone->layer & arm->layer) {
-                                               if (arm->flag & (ARM_EDITMODE|ARM_POSEMODE)) {
-                                                       bone= pchan->bone;
+                                               if (arm->flag & (ARM_EDITMODE | ARM_POSEMODE)) {
+                                                       bone = pchan->bone;
                                                        UI_GetThemeColor3ubv((bone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, col);
                                                }
                                                else if (dt > OB_WIRE) {
                                                        UI_GetThemeColor3ubv(TH_TEXT, col);
                                                }
                                                
-                                               /*      Draw names of bone      */
+                                               /*  Draw names of bone  */
                                                if (arm->flag & ARM_DRAWNAMES) {
                                                        mid_v3_v3v3(vec, pchan->pose_head, pchan->pose_tail);
                                                        view3d_cached_text_draw_add(vec, pchan->name, 10, 0, col);
@@ -2033,7 +2033,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                                        glMultMatrixf(bmat);
                                                        
                                                        glColor3ubv(col);
-                                                       drawaxes(pchan->bone->length*0.25f, OB_ARROWS);
+                                                       drawaxes(pchan->bone->length * 0.25f, OB_ARROWS);
                                                        
                                                        glPopMatrix();
                                                }
@@ -2049,13 +2049,13 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
 /* in editmode, we don't store the bone matrix... */
 static void get_matrix_editbone(EditBone *eBone, float bmat[][4])
 {
-       float           delta[3];
-       float           mat[3][3];
+       float delta[3];
+       float mat[3][3];
        
        /* Compose the parent transforms (i.e. their translations) */
        sub_v3_v3v3(delta, eBone->tail, eBone->head);   
        
-       eBone->length = (float)sqrt(delta[0]*delta[0] + delta[1]*delta[1] +delta[2]*delta[2]);
+       eBone->length = (float)sqrt(delta[0] * delta[0] + delta[1] * delta[1] + delta[2] * delta[2]);
        
        vec_roll_to_mat3(delta, eBone->roll, mat);
        copy_m4_m3(bmat, mat);
@@ -2065,21 +2065,21 @@ static void get_matrix_editbone(EditBone *eBone, float bmat[][4])
 
 static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
 {
-       RegionView3D *rv3d= ar->regiondata;
+       RegionView3D *rv3d = ar->regiondata;
        EditBone *eBone;
-       bArmature *arm= ob->data;
+       bArmature *arm = ob->data;
        float smat[4][4], imat[4][4], bmat[4][4];
        unsigned int index;
        int flag;
        
        /* being set in code below */
-       arm->layer_used= 0;
+       arm->layer_used = 0;
        
        /* envelope (deform distance) */
-       if (arm->drawtype==ARM_ENVELOPE) {
+       if (arm->drawtype == ARM_ENVELOPE) {
                /* precalc inverse matrix for drawing screen aligned */
                copy_m4_m4(smat, rv3d->viewmatob);
-               mul_mat3_m4_fl(smat, 1.0f/len_v3(ob->obmat[0]));
+               mul_mat3_m4_fl(smat, 1.0f / len_v3(ob->obmat[0]));
                invert_m4_m4(imat, smat);
                
                /* and draw blended distances */
@@ -2088,10 +2088,10 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
                
                if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
 
-               for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
+               for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
                        if (eBone->layer & arm->layer) {
-                               if ((eBone->flag & (BONE_HIDDEN_A|BONE_NO_DEFORM))==0) {
-                                       if (eBone->flag & (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL))
+                               if ((eBone->flag & (BONE_HIDDEN_A | BONE_NO_DEFORM)) == 0) {
+                                       if (eBone->flag & (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL))
                                                draw_sphere_bone_dist(smat, imat, NULL, eBone);
                                }
                        }
@@ -2104,15 +2104,15 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
        
        /* if solid we draw it first */
        if ((dt > OB_WIRE) && (arm->drawtype != ARM_LINE)) {
-               for (eBone=arm->edbo->first, index=0; eBone; eBone=eBone->next, index++) {
+               for (eBone = arm->edbo->first, index = 0; eBone; eBone = eBone->next, index++) {
                        if (eBone->layer & arm->layer) {
-                               if ((eBone->flag & BONE_HIDDEN_A)==0) {
+                               if ((eBone->flag & BONE_HIDDEN_A) == 0) {
                                        glPushMatrix();
                                        get_matrix_editbone(eBone, bmat);
                                        glMultMatrixf(bmat);
                                        
                                        /* catch exception for bone with hidden parent */
-                                       flag= eBone->flag;
+                                       flag = eBone->flag;
                                        if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent))
                                                flag &= ~BONE_CONNECTED;
                                                
@@ -2120,11 +2120,11 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
                                        if (eBone == arm->act_edbone)
                                                flag |= BONE_DRAW_ACTIVE;
                                        
-                                       if (arm->drawtype==ARM_ENVELOPE)
+                                       if (arm->drawtype == ARM_ENVELOPE)
                                                draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
-                                       else if (arm->drawtype==ARM_B_BONE)
+                                       else if (arm->drawtype == ARM_B_BONE)
                                                draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
-                                       else if (arm->drawtype==ARM_WIRE)
+                                       else if (arm->drawtype == ARM_WIRE)
                                                draw_wire_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
                                        else {
                                                draw_bone(OB_SOLID, arm->flag, flag, 0, index, eBone->length);
@@ -2137,24 +2137,24 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
        }
        
        /* if wire over solid, set offset */
-       index= -1;
+       index = -1;
        glLoadName(-1);
        if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
                if (G.f & G_PICKSEL)
-                       index= 0;
+                       index = 0;
        }
        else if (dt > OB_WIRE) 
                bglPolygonOffset(rv3d->dist, 1.0f);
        else if (arm->flag & ARM_EDITMODE) 
-               index= 0;       /* do selection codes */
+               index = 0;  /* do selection codes */
        
-       for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
+       for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
                arm->layer_used |= eBone->layer;
                if (eBone->layer & arm->layer) {
-                       if ((eBone->flag & BONE_HIDDEN_A)==0) {
+                       if ((eBone->flag & BONE_HIDDEN_A) == 0) {
                                
                                /* catch exception for bone with hidden parent */
-                               flag= eBone->flag;
+                               flag = eBone->flag;
                                if ( (eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent))
                                        flag &= ~BONE_CONNECTED;
                                        
@@ -2173,7 +2173,7 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
                                        
                                        if (arm->drawtype == ARM_LINE) 
                                                draw_line_bone(arm->flag, flag, 0, index, NULL, eBone);
-                                       else if (arm->drawtype==ARM_WIRE)
+                                       else if (arm->drawtype == ARM_WIRE)
                                                draw_wire_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
                                        else if (arm->drawtype == ARM_B_BONE)
                                                draw_b_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
@@ -2186,7 +2186,7 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
                                /* offset to parent */
                                if (eBone->parent) {
                                        UI_ThemeColor(TH_WIRE);
-                                       glLoadName (-1);                // -1 here is OK!
+                                       glLoadName(-1);         // -1 here is OK!
                                        setlinestyle(3);
                                        
                                        glBegin(GL_LINES);
@@ -2198,27 +2198,27 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
                                }
                        }
                }
-               if (index!=-1) index++;
+               if (index != -1) index++;
        }
        
        /* restore */
-       if (index!=-1) glLoadName(-1);
-       if (ELEM(arm->drawtype,ARM_LINE,ARM_WIRE));
-       else if (dt>OB_WIRE) bglPolygonOffset(rv3d->dist, 0.0f);
+       if (index != -1) glLoadName(-1);
+       if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) ;
+       else if (dt > OB_WIRE) bglPolygonOffset(rv3d->dist, 0.0f);
        
        /* finally names and axes */
-       if (arm->flag & (ARM_DRAWNAMES|ARM_DRAWAXES)) {
+       if (arm->flag & (ARM_DRAWNAMES | ARM_DRAWAXES)) {
                // patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing
                if ((G.f & G_PICKSEL) == 0) {
                        float vec[3];
                        unsigned char col[4];
-                       col[3]= 255;
+                       col[3] = 255;
                        
                        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
                        
-                       for (eBone=arm->edbo->first; eBone; eBone=eBone->next) {
+                       for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
                                if (eBone->layer & arm->layer) {
-                                       if ((eBone->flag & BONE_HIDDEN_A)==0) {
+                                       if ((eBone->flag & BONE_HIDDEN_A) == 0) {
 
                                                UI_GetThemeColor3ubv((eBone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, col);
 
@@ -2236,7 +2236,7 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
                                                        glMultMatrixf(bmat);
 
                                                        glColor3ubv(col);
-                                                       drawaxes(eBone->length*0.25f, OB_ARROWS);
+                                                       drawaxes(eBone->length * 0.25f, OB_ARROWS);
                                                        
                                                        glPopMatrix();
                                                }
@@ -2259,15 +2259,15 @@ static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, int dt)
  */
 static void draw_pose_paths(Scene *scene, View3D *v3d, ARegion *ar, Object *ob)
 {
-       bAnimVizSettings *avs= &ob->pose->avs;
-       bArmature *arm= ob->data;
+       bAnimVizSettings *avs = &ob->pose->avs;
+       bArmature *arm = ob->data;
        bPoseChannel *pchan;
        
        /* setup drawing environment for paths */
        draw_motion_paths_init(v3d, ar);
        
        /* draw paths where they exist and they releated bone is visible */
-       for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+       for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
                if ((pchan->bone->layer & arm->layer) && (pchan->mpath))
                        draw_motion_path_instance(scene, ob, pchan, avs, pchan->mpath);
        }
@@ -2284,16 +2284,16 @@ static void draw_pose_paths(Scene *scene, View3D *v3d, ARegion *ar, Object *ob)
  */
 static void ghost_poses_tag_unselected(Object *ob, short unset)
 {
-       bArmature *arm= ob->data;
-       bPose *pose= ob->pose;
+       bArmature *arm = ob->data;
+       bPose *pose = ob->pose;
        bPoseChannel *pchan;
        
        /* don't do anything if no hiding any bones */
-       if ((arm->flag & ARM_GHOST_ONLYSEL)==0)
+       if ((arm->flag & ARM_GHOST_ONLYSEL) == 0)
                return;
                
        /* loop over all pchans, adding/removing tags as appropriate */
-       for (pchan= pose->chanbase.first; pchan; pchan= pchan->next) {
+       for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
                if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
                        if (unset) {
                                /* remove tags from all pchans if cleaning up */
@@ -2301,7 +2301,7 @@ static void ghost_poses_tag_unselected(Object *ob, short unset)
                        }
                        else {
                                /* set tags on unselected pchans only */
-                               if ((pchan->bone->flag & BONE_SELECTED)==0)
+                               if ((pchan->bone->flag & BONE_SELECTED) == 0)
                                        pchan->bone->flag |= BONE_HIDDEN_PG;
                        }
                }
@@ -2309,13 +2309,13 @@ static void ghost_poses_tag_unselected(Object *ob, short unset)
 }
 
 /* draw ghosts that occur within a frame range 
- *     note: object should be in posemode 
+ *  note: object should be in posemode
  */
 static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
 {
-       Object *ob= base->object;
-       AnimData *adt= BKE_animdata_from_id(&ob->id);
-       bArmature *arm= ob->data;
+       Object *ob = base->object;
+       AnimData *adt = BKE_animdata_from_id(&ob->id);
+       bArmature *arm = ob->data;
        bPose *posen, *poseo;
        float start, end, stepsize, range, colfac;
        int cfrao, flago, ipoflago;
@@ -2325,31 +2325,31 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base
        if (end <= start)
                return;
        
-       stepsize= (float)(arm->ghostsize);
-       range= (float)(end - start);
+       stepsize = (float)(arm->ghostsize);
+       range = (float)(end - start);
        
        /* store values */
        ob->mode &= ~OB_MODE_POSE;
-       cfrao= CFRA;
-       flago= arm->flag;
-       arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
-       ipoflago= ob->ipoflag; 
+       cfrao = CFRA;
+       flago = arm->flag;
+       arm->flag &= ~(ARM_DRAWNAMES | ARM_DRAWAXES);
+       ipoflago = ob->ipoflag;
        ob->ipoflag |= OB_DISABLE_PATH;
        
        /* copy the pose */
-       poseo= ob->pose;
+       poseo = ob->pose;
        copy_pose(&posen, ob->pose, 1);
-       ob->pose= posen;
-       armature_rebuild_pose(ob, ob->data);    /* child pointers for IK */
-       ghost_poses_tag_unselected(ob, 0);              /* hide unselected bones if need be */
+       ob->pose = posen;
+       armature_rebuild_pose(ob, ob->data);    /* child pointers for IK */
+       ghost_poses_tag_unselected(ob, 0);      /* hide unselected bones if need be */
        
        glEnable(GL_BLEND);
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
        /* draw from first frame of range to last */
-       for (CFRA= (int)start; CFRA < end; CFRA += (int)stepsize) {
+       for (CFRA = (int)start; CFRA < end; CFRA += (int)stepsize) {
                colfac = (end - (float)CFRA) / range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
                
                BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
                where_is_pose(scene, ob);
@@ -2358,16 +2358,16 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base
        glDisable(GL_BLEND);
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
 
-       ghost_poses_tag_unselected(ob, 1);              /* unhide unselected bones if need be */
+       ghost_poses_tag_unselected(ob, 1);      /* unhide unselected bones if need be */
        free_pose(posen);
        
        /* restore */
-       CFRA= cfrao;
-       ob->pose= poseo;
-       arm->flag= flago;
+       CFRA = cfrao;
+       ob->pose = poseo;
+       arm->flag = flago;
        armature_rebuild_pose(ob, ob->data);
        ob->mode |= OB_MODE_POSE;
-       ob->ipoflag= ipoflago; 
+       ob->ipoflag = ipoflago;
 }
 
 /* draw ghosts on keyframes in action within range 
@@ -2375,10 +2375,10 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base
  */
 static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
 {
-       Object *ob= base->object;
-       AnimData *adt= BKE_animdata_from_id(&ob->id);
-       bAction *act= (adt) ? adt->action : NULL;
-       bArmature *arm= ob->data;
+       Object *ob = base->object;
+       AnimData *adt = BKE_animdata_from_id(&ob->id);
+       bAction *act = (adt) ? adt->action : NULL;
+       bArmature *arm = ob->data;
        bPose *posen, *poseo;
        DLRBT_Tree keys;
        ActKeyColumn *ak, *akn;
@@ -2395,9 +2395,9 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *
        action_to_keylist(adt, act, &keys, NULL);
        BLI_dlrbTree_linkedlist_sync(&keys);
        
-       range= 0;
-       for (ak= keys.first; ak; ak= akn) {
-               akn= ak->next;
+       range = 0;
+       for (ak = keys.first; ak; ak = akn) {
+               akn = ak->next;
                
                if ((ak->cfra < start) || (ak->cfra > end))
                        BLI_freelinkN((ListBase *)&keys, ak);
@@ -2408,27 +2408,27 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *
        
        /* store values */
        ob->mode &= ~OB_MODE_POSE;
-       cfrao= CFRA;
-       flago= arm->flag;
-       arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
+       cfrao = CFRA;
+       flago = arm->flag;
+       arm->flag &= ~(ARM_DRAWNAMES | ARM_DRAWAXES);
        ob->ipoflag |= OB_DISABLE_PATH;
        
        /* copy the pose */
-       poseo= ob->pose;
+       poseo = ob->pose;
        copy_pose(&posen, ob->pose, 1);
-       ob->pose= posen;
-       armature_rebuild_pose(ob, ob->data);    /* child pointers for IK */
-       ghost_poses_tag_unselected(ob, 0);              /* hide unselected bones if need be */
+       ob->pose = posen;
+       armature_rebuild_pose(ob, ob->data);  /* child pointers for IK */
+       ghost_poses_tag_unselected(ob, 0);    /* hide unselected bones if need be */
        
        glEnable(GL_BLEND);
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
        /* draw from first frame of range to last */
-       for (ak=keys.first, i=0; ak; ak=ak->next, i++) {
-               colfac = i/range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
+       for (ak = keys.first, i = 0; ak; ak = ak->next, i++) {
+               colfac = i / range;
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
                
-               CFRA= (int)ak->cfra;
+               CFRA = (int)ak->cfra;
                
                BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
                where_is_pose(scene, ob);
@@ -2437,26 +2437,26 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *
        glDisable(GL_BLEND);
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
 
-       ghost_poses_tag_unselected(ob, 1);              /* unhide unselected bones if need be */
+       ghost_poses_tag_unselected(ob, 1);  /* unhide unselected bones if need be */
        BLI_dlrbTree_free(&keys);
        free_pose(posen);
        
        /* restore */
-       CFRA= cfrao;
-       ob->pose= poseo;
-       arm->flag= flago;
+       CFRA = cfrao;
+       ob->pose = poseo;
+       arm->flag = flago;
        armature_rebuild_pose(ob, ob->data);
        ob->mode |= OB_MODE_POSE;
 }
 
 /* draw ghosts around current frame
- *     - object is supposed to be armature in posemode 
+ *  - object is supposed to be armature in posemode
  */
 static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
 {
-       Object *ob= base->object;
-       AnimData *adt= BKE_animdata_from_id(&ob->id);
-       bArmature *arm= ob->data;
+       Object *ob = base->object;
+       AnimData *adt = BKE_animdata_from_id(&ob->id);
+       bArmature *arm = ob->data;
        bPose *posen, *poseo;
        float cur, start, end, stepsize, range, colfac, actframe, ctime;
        int cfrao, flago;
@@ -2469,35 +2469,35 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
        if (start == end)
                return;
 
-       stepsize= (float)(arm->ghostsize);
-       range= (float)(arm->ghostep)*stepsize + 0.5f;   /* plus half to make the for loop end correct */
+       stepsize = (float)(arm->ghostsize);
+       range = (float)(arm->ghostep) * stepsize + 0.5f;   /* plus half to make the for loop end correct */
        
        /* store values */
        ob->mode &= ~OB_MODE_POSE;
-       cfrao= CFRA;
-       actframe= BKE_nla_tweakedit_remap(adt, (float)CFRA, 0);
-       flago= arm->flag;
-       arm->flag &= ~(ARM_DRAWNAMES|ARM_DRAWAXES);
+       cfrao = CFRA;
+       actframe = BKE_nla_tweakedit_remap(adt, (float)CFRA, 0);
+       flago = arm->flag;
+       arm->flag &= ~(ARM_DRAWNAMES | ARM_DRAWAXES);
        
        /* copy the pose */
-       poseo= ob->pose;
+       poseo = ob->pose;
        copy_pose(&posen, ob->pose, 1);
-       ob->pose= posen;
-       armature_rebuild_pose(ob, ob->data);    /* child pointers for IK */
-       ghost_poses_tag_unselected(ob, 0);              /* hide unselected bones if need be */
+       ob->pose = posen;
+       armature_rebuild_pose(ob, ob->data);    /* child pointers for IK */
+       ghost_poses_tag_unselected(ob, 0);      /* hide unselected bones if need be */
        
        glEnable(GL_BLEND);
        if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
        
        /* draw from darkest blend to lowest */
-       for (cur= stepsize; cur<range; cur+=stepsize) {
-               ctime= cur - (float)fmod(cfrao, stepsize);      /* ensures consistent stepping */
-               colfac= ctime/range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
+       for (cur = stepsize; cur < range; cur += stepsize) {
+               ctime = cur - (float)fmod(cfrao, stepsize);  /* ensures consistent stepping */
+               colfac = ctime / range;
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
                
                /* only within action range */
-               if (actframe+ctime >= start && actframe+ctime <= end) {
-                       CFRA= (int)BKE_nla_tweakedit_remap(adt, actframe+ctime, NLATIME_CONVERT_MAP);
+               if (actframe + ctime >= start && actframe + ctime <= end) {
+                       CFRA = (int)BKE_nla_tweakedit_remap(adt, actframe + ctime, NLATIME_CONVERT_MAP);
                        
                        if (CFRA != cfrao) {
                                BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
@@ -2506,13 +2506,13 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
                        }
                }
                
-               ctime= cur + (float)fmod((float)cfrao, stepsize) - stepsize+1.0f;       /* ensures consistent stepping */
-               colfac= ctime/range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128-(int)(120.0*sqrt(colfac)));
+               ctime = cur + (float)fmod((float)cfrao, stepsize) - stepsize + 1.0f;   /* ensures consistent stepping */
+               colfac = ctime / range;
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
                
                /* only within action range */
-               if ((actframe-ctime >= start) && (actframe-ctime <= end)) {
-                       CFRA= (int)BKE_nla_tweakedit_remap(adt, actframe-ctime, NLATIME_CONVERT_MAP);
+               if ((actframe - ctime >= start) && (actframe - ctime <= end)) {
+                       CFRA = (int)BKE_nla_tweakedit_remap(adt, actframe - ctime, NLATIME_CONVERT_MAP);
                        
                        if (CFRA != cfrao) {
                                BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
@@ -2524,13 +2524,13 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
        glDisable(GL_BLEND);
        if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
 
-       ghost_poses_tag_unselected(ob, 1);              /* unhide unselected bones if need be */
+       ghost_poses_tag_unselected(ob, 1);      /* unhide unselected bones if need be */
        free_pose(posen);
        
        /* restore */
-       CFRA= cfrao;
-       ob->pose= poseo;
-       arm->flag= flago;
+       CFRA = cfrao;
+       ob->pose = poseo;
+       arm->flag = flago;
        armature_rebuild_pose(ob, ob->data);
        ob->mode |= OB_MODE_POSE;
 }
@@ -2540,22 +2540,22 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
 /* called from drawobject.c, return 1 if nothing was drawn */
 int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, int flag, const short is_outline)
 {
-       Object *ob= base->object;
-       bArmature *arm= ob->data;
-       int retval= 0;
+       Object *ob = base->object;
+       bArmature *arm = ob->data;
+       int retval = 0;
 
        if (v3d->flag2 & V3D_RENDER_OVERRIDE)
                return 1;
        
-       if (dt>OB_WIRE && !ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
+       if (dt > OB_WIRE && !ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
                /* we use color for solid lighting */
                glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
                glEnable(GL_COLOR_MATERIAL);
-               glColor3ub(255,255,255);        // clear spec
+               glColor3ub(255, 255, 255);    // clear spec
                glDisable(GL_COLOR_MATERIAL);
                
                glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
-               glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW); // only for lighting...
+               glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW); // only for lighting...
        }
        
        /* arm->flag is being used to detect mode... */
@@ -2571,9 +2571,10 @@ int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, in
                        /* drawing posemode selection indices or colors only in these cases */
                        if (!(base->flag & OB_FROMDUPLI)) {
                                if (G.f & G_PICKSEL) {
-#if 0                          /* nifty but actually confusing to allow bone selection out of posemode */
+#if 0
+                                       /* nifty but actually confusing to allow bone selection out of posemode */
                                        if (OBACT && (OBACT->mode & OB_MODE_WEIGHT_PAINT)) {
-                                               if (ob==modifiers_isDeformedByArmature(OBACT))
+                                               if (ob == modifiers_isDeformedByArmature(OBACT))
                                                        arm->flag |= ARM_POSEMODE;
                                        }
                                        else
@@ -2593,11 +2594,11 @@ int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, in
                                                if (arm->ghostep)
                                                        draw_ghost_poses(scene, v3d, ar, base);
                                        }
-                                       if ((flag & DRAW_SCENESET)==0) {
-                                               if (ob==OBACT)
+                                       if ((flag & DRAW_SCENESET) == 0) {
+                                               if (ob == OBACT)
                                                        arm->flag |= ARM_POSEMODE;
                                                else if (OBACT && (OBACT->mode & OB_MODE_WEIGHT_PAINT)) {
-                                                       if (ob==modifiers_isDeformedByArmature(OBACT))
+                                                       if (ob == modifiers_isDeformedByArmature(OBACT))
                                                                arm->flag |= ARM_POSEMODE;
                                                }
                                                draw_pose_paths(scene, v3d, ar, ob);
@@ -2608,9 +2609,11 @@ int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, in
                        arm->flag &= ~ARM_POSEMODE; 
                        
                        if (ob->mode & OB_MODE_POSE)
-                               UI_ThemeColor(TH_WIRE); /* restore, for extra draw stuff */
+                               UI_ThemeColor(TH_WIRE);  /* restore, for extra draw stuff */
+               }
+               else {
+                       retval = 1;
                }
-               else retval= 1;
        }
        /* restore */
        glFrontFace(GL_CCW);
index 0ec9e9664f6d7dab1a342201149943d7319b3310..211104e60f01c6e2e17f5e83af4436360356a3fa 100644 (file)
@@ -71,7 +71,7 @@
 #include "ED_mesh.h"
 #include "ED_uvedit.h"
 
-#include "view3d_intern.h"     // own include
+#include "view3d_intern.h"  // own include
 
 /* user data structures for derived mesh callbacks */
 typedef struct drawMeshFaceSelect_userData {
@@ -96,8 +96,8 @@ typedef struct drawTFace_userData {
 
 /* Flags for marked edges */
 enum {
-       eEdge_Visible = (1<<0),
-       eEdge_Select = (1<<1),
+       eEdge_Visible = (1 << 0),
+       eEdge_Select = (1 << 1),
 };
 
 /* Creates a hash of edges to flags indicating selected/visible */
@@ -108,7 +108,7 @@ static void get_marked_edge_info__orFlags(EdgeHash *eh, int v0, int v1, int flag
        if (!BLI_edgehash_haskey(eh, v0, v1))
                BLI_edgehash_insert(eh, v0, v1, NULL);
 
-       flags_p = (int*) BLI_edgehash_lookup_p(eh, v0, v1);
+       flags_p = (int *) BLI_edgehash_lookup_p(eh, v0, v1);
        *flags_p |= flags;
 }
 
@@ -120,7 +120,7 @@ static EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me)
        MLoop *ml_next;
        int i, j;
        
-       for (i=0; i<me->totpoly; i++) {
+       for (i = 0; i < me->totpoly; i++) {
                mp = &me->mpoly[i];
 
                if (!(mp->flag & ME_HIDE)) {
@@ -128,7 +128,7 @@ static EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me)
                        if (mp->flag & ME_FACE_SEL) flags |= eEdge_Select;
 
                        ml = me->mloop + mp->loopstart;
-                       for (j=0; j<mp->totloop; j++, ml++) {
+                       for (j = 0; j < mp->totloop; j++, ml++) {
                                ml_next = ME_POLY_LOOP_NEXT(me->mloop, mp, j);
                                get_marked_edge_info__orFlags(eh, ml->v, ml_next->v, flags);
                        }
@@ -142,7 +142,7 @@ static EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me)
 static DMDrawOption draw_mesh_face_select__setHiddenOpts(void *userData, int index)
 {
        drawMeshFaceSelect_userData *data = userData;
-       Mesh *me= data->me;
+       Mesh *me = data->me;
        MEdge *med = &me->medge[index];
        uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2);
 
@@ -170,11 +170,11 @@ static DMDrawOption draw_mesh_face_select__setSelectOpts(void *userData, int ind
 /* draws unselected */
 static DMDrawOption draw_mesh_face_select__drawFaceOptsInv(void *userData, int index)
 {
-       Mesh *me = (Mesh*)userData;
+       Mesh *me = (Mesh *)userData;
 
        MPoly *mface = &me->mpoly[index];
-       if (!(mface->flag&ME_HIDE) && !(mface->flag&ME_FACE_SEL))
-               return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */
+       if (!(mface->flag & ME_HIDE) && !(mface->flag & ME_FACE_SEL))
+               return DM_DRAW_OPTION_NO_MCOL;  /* Don't set color */
        else
                return DM_DRAW_OPTION_SKIP;
 }
@@ -202,20 +202,20 @@ static void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm)
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                /* dull unselected faces so as not to get in the way of seeing color */
                glColor4ub(96, 96, 96, 64);
-               dm->drawMappedFacesTex(dm, draw_mesh_face_select__drawFaceOptsInv, NULL, (void*)me);
+               dm->drawMappedFacesTex(dm, draw_mesh_face_select__drawFaceOptsInv, NULL, (void *)me);
                
                glDisable(GL_BLEND);
        }
        
        bglPolygonOffset(rv3d->dist, 1.0);
 
-               /* Draw Stippled Outline for selected faces */
+       /* Draw Stippled Outline for selected faces */
        glColor3ub(255, 255, 255);
        setlinestyle(1);
        dm->drawMappedEdges(dm, draw_mesh_face_select__setSelectOpts, &data);
        setlinestyle(0);
 
-       bglPolygonOffset(rv3d->dist, 0.0);      // resets correctly now, even after calling accumulated offsets
+       bglPolygonOffset(rv3d->dist, 0.0);  // resets correctly now, even after calling accumulated offsets
 
        BLI_edgehash_free(data.eh, NULL);
 }
@@ -224,10 +224,10 @@ static void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm)
 
 static Material *give_current_material_or_def(Object *ob, int matnr)
 {
-       extern Material defmaterial;    // render module abuse...
-       Material *ma= give_current_material(ob, matnr);
+       extern Material defmaterial;    // render module abuse...
+       Material *ma = give_current_material(ob, matnr);
 
-       return ma?ma:&defmaterial;
+       return ma ? ma : &defmaterial;
 }
 
 /* Icky globals, fix with userdata parameter */
@@ -255,9 +255,9 @@ static int set_draw_settings_cached(int clearcache, MTFace *texface, Material *m
        int lit = 0;
        
        if (clearcache) {
-               c_textured= c_lit= c_backculled= -1;
-               c_texface= (MTFace*) -1;
-               c_badtex= 0;
+               c_textured = c_lit = c_backculled = -1;
+               c_texface = (MTFace *) -1;
+               c_badtex = 0;
        }
        else {
                textured = gtexdraw.istex;
@@ -284,35 +284,35 @@ static int set_draw_settings_cached(int clearcache, MTFace *texface, Material *m
        else
                textured = 0;
 
-       if (backculled!=c_backculled) {
+       if (backculled != c_backculled) {
                if (backculled) glEnable(GL_CULL_FACE);
                else glDisable(GL_CULL_FACE);
 
-               c_backculled= backculled;
+               c_backculled = backculled;
        }
 
-       if (textured!=c_textured || texface!=c_texface) {
-               if (textured ) {
-                       c_badtex= !GPU_set_tpage(texface, !(litob->mode & OB_MODE_TEXTURE_PAINT), alphablend);
+       if (textured != c_textured || texface != c_texface) {
+               if (textured) {
+                       c_badtex = !GPU_set_tpage(texface, !(litob->mode & OB_MODE_TEXTURE_PAINT), alphablend);
                }
                else {
                        GPU_set_tpage(NULL, 0, 0);
-                       c_badtex= 0;
+                       c_badtex = 0;
                }
-               c_textured= textured;
-               c_texface= texface;
+               c_textured = textured;
+               c_texface = texface;
        }
 
-       if (c_badtex) lit= 0;
-       if (lit!=c_lit || ma!=c_ma) {
+       if (c_badtex) lit = 0;
+       if (lit != c_lit || ma != c_ma) {
                if (lit) {
                        float spec[4];
-                       if (!ma)ma= give_current_material_or_def(NULL, 0); //default material
+                       if (!ma) ma = give_current_material_or_def(NULL, 0);  //default material
 
-                       spec[0]= ma->spec*ma->specr;
-                       spec[1]= ma->spec*ma->specg;
-                       spec[2]= ma->spec*ma->specb;
-                       spec[3]= 1.0;
+                       spec[0] = ma->spec * ma->specr;
+                       spec[1] = ma->spec * ma->specg;
+                       spec[2] = ma->spec * ma->specb;
+                       spec[3] = 1.0;
 
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec);
                        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
@@ -324,7 +324,7 @@ static int set_draw_settings_cached(int clearcache, MTFace *texface, Material *m
                        glDisable(GL_LIGHTING); 
                        glDisable(GL_COLOR_MATERIAL);
                }
-               c_lit= lit;
+               c_lit = lit;
        }
 
        return c_badtex;
@@ -340,25 +340,25 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O
        /* texture draw is abused for mask selection mode, do this so wire draw
         * with face selection in weight paint is not lit. */
        if ((v3d->drawtype <= OB_WIRE) && (ob->mode & OB_MODE_WEIGHT_PAINT)) {
-               solidtex= FALSE;
-               Gtexdraw.islit= 0;
+               solidtex = FALSE;
+               Gtexdraw.islit = 0;
        }
-       else if (v3d->drawtype==OB_SOLID || ((ob->mode & OB_MODE_EDIT) && v3d->drawtype!=OB_TEXTURE)) {
+       else if (v3d->drawtype == OB_SOLID || ((ob->mode & OB_MODE_EDIT) && v3d->drawtype != OB_TEXTURE)) {
                /* draw with default lights in solid draw mode and edit mode */
-               solidtex= TRUE;
-               Gtexdraw.islit= -1;
+               solidtex = TRUE;
+               Gtexdraw.islit = -1;
        }
        else {
                /* draw with lights in the scene otherwise */
-               solidtex= FALSE;
-               Gtexdraw.islit= GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp);
+               solidtex = FALSE;
+               Gtexdraw.islit = GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp);
        }
        
        rgba_float_to_uchar(obcol, ob->col);
 
        glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
-       if (solidtex || v3d->drawtype==OB_TEXTURE) istex= 1;
-       else istex= 0;
+       if (solidtex || v3d->drawtype == OB_TEXTURE) istex = 1;
+       else istex = 0;
 
        Gtexdraw.ob = ob;
        Gtexdraw.istex = istex;
@@ -393,8 +393,8 @@ static void draw_textured_end(void)
 
 static DMDrawOption draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int matnr)
 {
-       Material *ma= give_current_material(Gtexdraw.ob, matnr+1);
-       int validtexture=0;
+       Material *ma = give_current_material(Gtexdraw.ob, matnr + 1);
+       int validtexture = 0;
 
        if (ma && (ma->game.flag & GEMAT_INVISIBLE))
                return DM_DRAW_OPTION_SKIP;
@@ -405,7 +405,7 @@ static DMDrawOption draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int
                glColor3ub(0xFF, 0x00, 0xFF);
                return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */
        }
-       else if (ma && (ma->shade_flag&MA_OBCOLOR)) {
+       else if (ma && (ma->shade_flag & MA_OBCOLOR)) {
                glColor3ubv(Gtexdraw.obcol);
                return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */
        }
@@ -438,7 +438,7 @@ static DMDrawOption draw_mcol__set_draw_legacy(MTFace *UNUSED(tface), int has_mc
 
 static DMDrawOption draw_tface__set_draw(MTFace *tface, int has_mcol, int matnr)
 {
-       Material *ma= give_current_material(Gtexdraw.ob, matnr+1);
+       Material *ma = give_current_material(Gtexdraw.ob, matnr + 1);
 
        if (ma && (ma->game.flag & GEMAT_INVISIBLE)) return 0;
 
@@ -461,78 +461,78 @@ static void add_tface_color_layer(DerivedMesh *dm)
        MTFace *tface = DM_get_poly_data_layer(dm, CD_MTFACE);
        MFace *mface = dm->getTessFaceArray(dm);
        MCol *finalCol;
-       int i,j;
+       int i, j;
        MCol *mcol = dm->getTessFaceDataArray(dm, CD_PREVIEW_MCOL);
        if (!mcol)
                mcol = dm->getTessFaceDataArray(dm, CD_MCOL);
 
-       finalCol = MEM_mallocN(sizeof(MCol)*4*dm->getNumTessFaces(dm),"add_tface_color_layer");
-       for (i=0;i<dm->getNumTessFaces(dm);i++) {
-               Material *ma= give_current_material(Gtexdraw.ob, mface[i].mat_nr+1);
+       finalCol = MEM_mallocN(sizeof(MCol) * 4 * dm->getNumTessFaces(dm), "add_tface_color_layer");
+       for (i = 0; i < dm->getNumTessFaces(dm); i++) {
+               Material *ma = give_current_material(Gtexdraw.ob, mface[i].mat_nr + 1);
 
-               if (ma && (ma->game.flag&GEMAT_INVISIBLE)) {
-                       if ( mcol )
-                               memcpy(&finalCol[i*4],&mcol[i*4],sizeof(MCol)*4);
+               if (ma && (ma->game.flag & GEMAT_INVISIBLE)) {
+                       if (mcol)
+                               memcpy(&finalCol[i * 4], &mcol[i * 4], sizeof(MCol) * 4);
                        else
-                               for (j=0;j<4;j++) {
-                                       finalCol[i*4+j].b = 255;
-                                       finalCol[i*4+j].g = 255;
-                                       finalCol[i*4+j].r = 255;
+                               for (j = 0; j < 4; j++) {
+                                       finalCol[i * 4 + j].b = 255;
+                                       finalCol[i * 4 + j].g = 255;
+                                       finalCol[i * 4 + j].r = 255;
                                }
                }
                else if (tface && mface && set_draw_settings_cached(0, tface, ma, Gtexdraw)) {
-                       for (j=0;j<4;j++) {
-                               finalCol[i*4+j].b = 255;
-                               finalCol[i*4+j].g = 0;
-                               finalCol[i*4+j].r = 255;
+                       for (j = 0; j < 4; j++) {
+                               finalCol[i * 4 + j].b = 255;
+                               finalCol[i * 4 + j].g = 0;
+                               finalCol[i * 4 + j].r = 255;
                        }
                }
                else if (tface && (tface->mode & TF_OBCOL)) {
-                       for (j=0;j<4;j++) {
-                               finalCol[i*4+j].b = FTOCHAR(Gtexdraw.obcol[0]);
-                               finalCol[i*4+j].g = FTOCHAR(Gtexdraw.obcol[1]);
-                               finalCol[i*4+j].r = FTOCHAR(Gtexdraw.obcol[2]);
+                       for (j = 0; j < 4; j++) {
+                               finalCol[i * 4 + j].b = FTOCHAR(Gtexdraw.obcol[0]);
+                               finalCol[i * 4 + j].g = FTOCHAR(Gtexdraw.obcol[1]);
+                               finalCol[i * 4 + j].r = FTOCHAR(Gtexdraw.obcol[2]);
                        }
                }
                else if (!mcol) {
                        if (tface) {
-                               for (j=0;j<4;j++) {
-                                       finalCol[i*4+j].b = 255;
-                                       finalCol[i*4+j].g = 255;
-                                       finalCol[i*4+j].r = 255;
+                               for (j = 0; j < 4; j++) {
+                                       finalCol[i * 4 + j].b = 255;
+                                       finalCol[i * 4 + j].g = 255;
+                                       finalCol[i * 4 + j].r = 255;
                                }
                        }
                        else {
                                float col[3];
-                               Material *ma= give_current_material(Gtexdraw.ob, mface[i].mat_nr+1);
+                               Material *ma = give_current_material(Gtexdraw.ob, mface[i].mat_nr + 1);
                                
                                if (ma) {
                                        if (Gtexdraw.color_profile) linearrgb_to_srgb_v3_v3(col, &ma->r);
                                        else copy_v3_v3(col, &ma->r);
                                        
-                                       for (j=0;j<4;j++) {
-                                               finalCol[i*4+j].b = FTOCHAR(col[0]);
-                                               finalCol[i*4+j].g = FTOCHAR(col[1]);
-                                               finalCol[i*4+j].r = FTOCHAR(col[2]);
+                                       for (j = 0; j < 4; j++) {
+                                               finalCol[i * 4 + j].b = FTOCHAR(col[0]);
+                                               finalCol[i * 4 + j].g = FTOCHAR(col[1]);
+                                               finalCol[i * 4 + j].r = FTOCHAR(col[2]);
                                        }
                                }
                                else
-                                       for (j=0;j<4;j++) {
-                                               finalCol[i*4+j].b = 255;
-                                               finalCol[i*4+j].g = 255;
-                                               finalCol[i*4+j].r = 255;
+                                       for (j = 0; j < 4; j++) {
+                                               finalCol[i * 4 + j].b = 255;
+                                               finalCol[i * 4 + j].g = 255;
+                                               finalCol[i * 4 + j].r = 255;
                                        }
                        }
                }
                else {
-                       for (j=0;j<4;j++) {
-                               finalCol[i*4+j].r = mcol[i*4+j].r;
-                               finalCol[i*4+j].g = mcol[i*4+j].g;
-                               finalCol[i*4+j].b = mcol[i*4+j].b;
+                       for (j = 0; j < 4; j++) {
+                               finalCol[i * 4 + j].r = mcol[i * 4 + j].r;
+                               finalCol[i * 4 + j].g = mcol[i * 4 + j].g;
+                               finalCol[i * 4 + j].b = mcol[i * 4 + j].b;
                        }
                }
        }
-       CustomData_add_layer( &dm->faceData, CD_TEXTURE_MCOL, CD_ASSIGN, finalCol, dm->numTessFaceData );
+       CustomData_add_layer(&dm->faceData, CD_TEXTURE_MCOL, CD_ASSIGN, finalCol, dm->numTessFaceData);
 }
 
 static DMDrawOption draw_tface_mapped__set_draw(void *userData, int index)
@@ -549,7 +549,7 @@ static DMDrawOption draw_tface_mapped__set_draw(void *userData, int index)
        }
        else {
                MTexPoly *tpoly = (me->mtpoly) ? &me->mtpoly[index] : NULL;
-               MTFace mtf= {{{0}}};
+               MTFace mtf = {{{0}}};
                int matnr = mpoly->mat_nr;
 
                if (tpoly) {
@@ -564,13 +564,13 @@ static DMDrawOption draw_em_tf_mapped__set_draw(void *userData, int index)
 {
        drawEMTFMapped_userData *data = userData;
        BMEditMesh *em = data->em;
-       BMFace *efa= EDBM_get_face_for_index(em, index);
+       BMFace *efa = EDBM_get_face_for_index(em, index);
 
-       if (efa==NULL || BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+       if (efa == NULL || BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
                return DM_DRAW_OPTION_SKIP;
        }
        else {
-               MTFace mtf= {{{0}}};
+               MTFace mtf = {{{0}}};
                int matnr = efa->mat_nr;
 
                if (data->has_mtface) {
@@ -579,16 +579,16 @@ static DMDrawOption draw_em_tf_mapped__set_draw(void *userData, int index)
                }
 
                return draw_tface__set_draw_legacy(data->has_mtface ? &mtf : NULL,
-                                                                                  data->has_mcol, matnr);
+                                                  data->has_mcol, matnr);
        }
 }
 
 static DMDrawOption wpaint__setSolidDrawOptions_material(void *userData, int index)
 {
-       Mesh *me = (Mesh*)userData;
+       Mesh *me = (Mesh *)userData;
 
        if (me->mat && me->mpoly) {
-               Material *ma= me->mat[me->mpoly[index].mat_nr];
+               Material *ma = me->mat[me->mpoly[index].mat_nr];
                if (ma && (ma->game.flag & GEMAT_INVISIBLE)) {
                        return DM_DRAW_OPTION_SKIP;
                }
@@ -600,7 +600,7 @@ static DMDrawOption wpaint__setSolidDrawOptions_material(void *userData, int ind
 /* when face select is on, use face hidden flag */
 static DMDrawOption wpaint__setSolidDrawOptions_facemask(void *userData, int index)
 {
-       Mesh *me = (Mesh*)userData;
+       Mesh *me = (Mesh *)userData;
        MPoly *mp = &me->mpoly[index];
        if (mp->flag & ME_HIDE)
                return DM_DRAW_OPTION_SKIP;
@@ -615,7 +615,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
        MTexPoly *mtpoly   = me->mtpoly;
        MLoopUV *mloopuv   = me->mloopuv;
        MLoopUV *luv;
-       MLoopCol *mloopcol = me->mloopcol;      /* why does mcol exist? */
+       MLoopCol *mloopcol = me->mloopcol;  /* why does mcol exist? */
        MLoopCol *lcol;
 
        bProperty *prop = get_ob_property(ob, "Text");
@@ -623,7 +623,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
        int a, totpoly = me->totpoly;
 
        /* fake values to pass to GPU_render_text() */
-       MCol  tmp_mcol[4]  = {{0}};
+       MCol tmp_mcol[4]  = {{0}};
        MCol *tmp_mcol_pt  = mloopcol ? tmp_mcol : NULL;
        MTFace tmp_tf      = {{{0}}};
 
@@ -634,33 +634,33 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
        /* don't draw when editing */
        if (ob->mode & OB_MODE_EDIT)
                return;
-       else if (ob==OBACT)
+       else if (ob == OBACT)
                if (paint_facesel_test(ob) || paint_vertsel_test(ob))
                        return;
 
        ddm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
 
-       for (a=0, mp=mface; a<totpoly ; a++, mtpoly++, mp++) {
-               short matnr= mp->mat_nr;
-               int mf_smooth= mp->flag & ME_SMOOTH;
+       for (a = 0, mp = mface; a < totpoly; a++, mtpoly++, mp++) {
+               short matnr = mp->mat_nr;
+               int mf_smooth = mp->flag & ME_SMOOTH;
                Material *mat = me->mat[matnr];
-               int mode= mat->game.flag;
+               int mode = mat->game.flag;
 
-               if (!(mode&GEMAT_INVISIBLE) && (mode&GEMAT_TEXT) && mp->totloop >= 3) {
+               if (!(mode & GEMAT_INVISIBLE) && (mode & GEMAT_TEXT) && mp->totloop >= 3) {
                        /* get the polygon as a tri/quad */
                        int mp_vi[4];
                        float v1[3], v2[3], v3[3], v4[3];
                        char string[MAX_PROPSTRING];
-                       int characters, i, glattrib= -1, badtex= 0;
+                       int characters, i, glattrib = -1, badtex = 0;
 
 
                        /* TEXFACE */
                        ME_MTEXFACE_CPY(&tmp_tf, mtpoly);
 
                        if (glsl) {
-                               GPU_enable_material(matnr+1, &gattribs);
+                               GPU_enable_material(matnr + 1, &gattribs);
 
-                               for (i=0; i<gattribs.totlayer; i++) {
+                               for (i = 0; i < gattribs.totlayer; i++) {
                                        if (gattribs.layer[i].type == CD_MTFACE) {
                                                glattrib = gattribs.layer[i].glindex;
                                                break;
@@ -675,9 +675,9 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
                        }
 
                        mp_vi[0] = me->mloop[mp->loopstart + 0].v;
-                   mp_vi[1] = me->mloop[mp->loopstart + 1].v;
-                   mp_vi[2] = me->mloop[mp->loopstart + 2].v;
-                   mp_vi[3] = (mp->totloop >= 4) ? me->mloop[mp->loopstart + 3].v : 0;
+                       mp_vi[1] = me->mloop[mp->loopstart + 1].v;
+                       mp_vi[2] = me->mloop[mp->loopstart + 2].v;
+                       mp_vi[3] = (mp->totloop >= 4) ? me->mloop[mp->loopstart + 3].v : 0;
 
                        /* UV */
                        luv = &mloopuv[mp->loopstart];
@@ -721,13 +721,13 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
                        if (!mf_smooth) {
                                float nor[3];
 
-                               normal_tri_v3( nor,v1, v2, v3);
+                               normal_tri_v3(nor, v1, v2, v3);
 
                                glNormal3fv(nor);
                        }
 
                        GPU_render_text(&tmp_tf, mode, string, characters,
-                               (unsigned int*)tmp_mcol_pt, v1, v2, v3, (mp->totloop >= 4 ? v4: NULL), glattrib);
+                                       (unsigned int *)tmp_mcol_pt, v1, v2, v3, (mp->totloop >= 4 ? v4 : NULL), glattrib);
                }
        }
 
@@ -749,7 +749,7 @@ static int compareDrawOptions(void *userData, int cur_index, int next_index)
 
 static int compareDrawOptionsEm(void *userData, int cur_index, int next_index)
 {
-       drawEMTFMapped_userData *data= userData;
+       drawEMTFMapped_userData *data = userData;
 
        if (data->mf && data->mf[cur_index].mat_nr != data->mf[next_index].mat_nr)
                return 0;
@@ -762,7 +762,7 @@ static int compareDrawOptionsEm(void *userData, int cur_index, int next_index)
 
 void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags)
 {
-       Mesh *me= ob->data;
+       Mesh *me = ob->data;
        
        /* correct for negative scale */
        if (ob->transflag & OB_NEG_SCALE) glFrontFace(GL_CW);
@@ -771,23 +771,23 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
        /* draw the textured mesh */
        draw_textured_begin(scene, v3d, rv3d, ob);
 
-       glColor4f(1.0f,1.0f,1.0f,1.0f);
+       glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 
        if (ob->mode & OB_MODE_EDIT) {
                drawEMTFMapped_userData data;
 
-               data.em= me->edit_btmesh;
-               data.has_mcol= CustomData_has_layer(&me->edit_btmesh->bm->ldata, CD_MLOOPCOL);
-               data.has_mtface= CustomData_has_layer(&me->edit_btmesh->bm->pdata, CD_MTEXPOLY);
-               data.mf= DM_get_tessface_data_layer(dm, CD_MFACE);
-               data.tf= DM_get_tessface_data_layer(dm, CD_MTFACE);
+               data.em = me->edit_btmesh;
+               data.has_mcol = CustomData_has_layer(&me->edit_btmesh->bm->ldata, CD_MLOOPCOL);
+               data.has_mtface = CustomData_has_layer(&me->edit_btmesh->bm->pdata, CD_MTEXPOLY);
+               data.mf = DM_get_tessface_data_layer(dm, CD_MFACE);
+               data.tf = DM_get_tessface_data_layer(dm, CD_MTFACE);
 
                dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, compareDrawOptionsEm, &data);
        }
        else if (draw_flags & DRAW_FACE_SELECT) {
                if (ob->mode & OB_MODE_WEIGHT_PAINT)
                        dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions_facemask, GPU_enable_material, NULL, me,
-                                                               DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
+                                           DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
                else
                        dm->drawMappedFacesTex(dm, me->mpoly ? draw_tface_mapped__set_draw : NULL, NULL, me);
        }
@@ -801,7 +801,7 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
                else {
                        drawTFace_userData userData;
 
-                       if (!CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL))
+                       if (!CustomData_has_layer(&dm->faceData, CD_TEXTURE_MCOL))
                                add_tface_color_layer(dm);
 
                        userData.mf = DM_get_tessface_data_layer(dm, CD_MFACE);
@@ -849,22 +849,22 @@ static void tex_mat_set_material_cb(void *UNUSED(userData), int mat_nr, void *at
 static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs)
 {
        /* texture draw mode without GLSL */
-       TexMatCallback *data= (TexMatCallback*)userData;
+       TexMatCallback *data = (TexMatCallback *)userData;
        GPUVertexAttribs *gattribs = attribs;
        Image *ima;
        ImageUser *iuser;
        bNode *node;
-       int texture_set= 0;
+       int texture_set = 0;
 
        /* draw image texture if we find one */
        if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node)) {
                /* get openl texture */
-               int mipmap= 1;
-               int bindcode= (ima)? GPU_verify_image(ima, iuser, 0, 0, mipmap): 0;
+               int mipmap = 1;
+               int bindcode = (ima) ? GPU_verify_image(ima, iuser, 0, 0, mipmap) : 0;
                float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 
                if (bindcode) {
-                       NodeTexBase *texbase= node->storage;
+                       NodeTexBase *texbase = node->storage;
 
                        /* disable existing material */
                        GPU_disable_material();
@@ -886,12 +886,12 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs)
                        /* use active UV texture layer */
                        memset(gattribs, 0, sizeof(*gattribs));
 
-                       gattribs->layer[0].type= CD_MTFACE;
-                       gattribs->layer[0].name[0]= '\0';
-                       gattribs->layer[0].gltexco= 1;
-                       gattribs->totlayer= 1;
+                       gattribs->layer[0].type = CD_MTFACE;
+                       gattribs->layer[0].name[0] = '\0';
+                       gattribs->layer[0].gltexco = 1;
+                       gattribs->totlayer = 1;
 
-                       texture_set= 1;
+                       texture_set = 1;
                }
        }
 
@@ -912,8 +912,8 @@ static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs)
 static int tex_mat_set_face_mesh_cb(void *userData, int index)
 {
        /* faceselect mode face hiding */
-       TexMatCallback *data= (TexMatCallback*)userData;
-       Mesh *me = (Mesh*)data->me;
+       TexMatCallback *data = (TexMatCallback *)userData;
+       Mesh *me = (Mesh *)data->me;
        MPoly *mp = &me->mpoly[index];
 
        return !(mp->flag & ME_HIDE);
@@ -922,9 +922,9 @@ static int tex_mat_set_face_mesh_cb(void *userData, int index)
 static int tex_mat_set_face_editmesh_cb(void *userData, int index)
 {
        /* editmode face hiding */
-       TexMatCallback *data= (TexMatCallback*)userData;
-       Mesh *me = (Mesh*)data->me;
-       BMFace *efa= EDBM_get_face_for_index(me->edit_btmesh, index);
+       TexMatCallback *data = (TexMatCallback *)userData;
+       Mesh *me = (Mesh *)data->me;
+       BMFace *efa = EDBM_get_face_for_index(me->edit_btmesh, index);
 
        return !BM_elem_flag_test(efa, BM_ELEM_HIDDEN);
 }
@@ -945,32 +945,32 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o
        if (ob->mode & OB_MODE_WEIGHT_PAINT) {
                /* weight paint mode exception */
                dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions_material,
-                       GPU_enable_material, NULL, ob->data, DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
+                                   GPU_enable_material, NULL, ob->data, DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH);
        }
        else {
-               Mesh *me= ob->data;
+               Mesh *me = ob->data;
                TexMatCallback data = {scene, ob, me, dm};
-               int (*set_face_cb)(void*, int);
+               int (*set_face_cb)(void *, int);
                int glsl;
                
                /* face hiding callback depending on mode */
                if (ob == scene->obedit)
-                       set_face_cb= tex_mat_set_face_editmesh_cb;
+                       set_face_cb = tex_mat_set_face_editmesh_cb;
                else if (draw_flags & DRAW_FACE_SELECT)
-                       set_face_cb= tex_mat_set_face_mesh_cb;
+                       set_face_cb = tex_mat_set_face_mesh_cb;
                else
-                       set_face_cb= NULL;
+                       set_face_cb = NULL;
 
                /* test if we can use glsl */
-               glsl= (v3d->drawtype == OB_MATERIAL) && GPU_glsl_support();
+               glsl = (v3d->drawtype == OB_MATERIAL) && GPU_glsl_support();
 
                GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
 
                if (glsl) {
                        /* draw glsl */
                        dm->drawMappedFacesMat(dm,
-                               tex_mat_set_material_cb,
-                               set_face_cb, &data);
+                                              tex_mat_set_material_cb,
+                                              set_face_cb, &data);
                }
                else {
                        float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
@@ -981,8 +981,8 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o
                        glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 0);
 
                        dm->drawMappedFacesMat(dm,
-                               tex_mat_set_texture_cb,
-                               set_face_cb, &data);
+                                              tex_mat_set_texture_cb,
+                                              set_face_cb, &data);
                }
 
                GPU_end_object_materials();
index b78d5b23e3fbb730dc9c5cfc2303a503e5ef636e..0332bd0bdb706f57042f34c7d6caad86f61da093 100644 (file)
@@ -55,7 +55,7 @@
 #include "BLI_rand.h"
 #include "BLI_utildefines.h"
 
-#include "BKE_anim.h"                  //for the where_on_path function
+#include "BKE_anim.h"  //for the where_on_path function
 #include "BKE_armature.h"
 #include "BKE_camera.h"
 #include "BKE_constraint.h" // for the get_constraint_target function
 #include "wm_subwindow.h"
 #include "BLF_api.h"
 
-#include "view3d_intern.h"     // own include
+#include "view3d_intern.h"  // own include
 
 
 /* this condition has been made more complex since editmode can draw textures */
 #define CHECK_OB_DRAWTEXTURE(vd, dt)                                          \
-       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) ||          \
-       (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
+    ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt > OB_SOLID) ||          \
+     (vd->drawtype == OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
 
 typedef enum eWireDrawMode {
-       OBDRAW_WIRE_OFF= 0,
-       OBDRAW_WIRE_ON= 1,
-       OBDRAW_WIRE_ON_DEPTH= 2
+       OBDRAW_WIRE_OFF = 0,
+       OBDRAW_WIRE_ON = 1,
+       OBDRAW_WIRE_ON_DEPTH = 2
 } eWireDrawMode;
 
 /* user data structures for derived mesh callbacks */
@@ -195,7 +195,7 @@ static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
                return 1;
 
        /* if its drawing textures with zbuf sel, then don't draw dots */
-       if (dt==OB_TEXTURE && vd->drawtype==OB_TEXTURE)
+       if (dt == OB_TEXTURE && vd->drawtype == OB_TEXTURE)
                return 0;
 
        if ((vd->drawtype >= OB_SOLID) && (vd->flag2 & V3D_SOLID_TEX))
@@ -209,10 +209,10 @@ static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
  * */
 static void view3d_project_short_clip(ARegion *ar, const float vec[3], short adr[2], int is_local)
 {
-       RegionView3D *rv3d= ar->regiondata;
+       RegionView3D *rv3d = ar->regiondata;
        float fx, fy, vec4[4];
        
-       adr[0]= IS_CLIPPED;
+       adr[0] = IS_CLIPPED;
        
        /* clipplanes in eye space */
        if (rv3d->rflag & RV3D_CLIPPING) {
@@ -221,21 +221,21 @@ static void view3d_project_short_clip(ARegion *ar, const float vec[3], short adr
        }
        
        copy_v3_v3(vec4, vec);
-       vec4[3]= 1.0;
+       vec4[3] = 1.0;
        
        mul_m4_v4(rv3d->persmatob, vec4);
        
        /* clipplanes in window space */
-       if ( vec4[3] > (float)BL_NEAR_CLIP ) {  /* is the NEAR clipping cutoff for picking */
-               fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]);
+       if (vec4[3] > (float)BL_NEAR_CLIP) {    /* is the NEAR clipping cutoff for picking */
+               fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
                
-               if ( fx>0 && fx<ar->winx) {
+               if (fx > 0 && fx < ar->winx) {
                        
-                       fy= (ar->winy/2)*(1 + vec4[1]/vec4[3]);
+                       fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
                        
                        if (fy > 0.0f && fy < (float)ar->winy) {
-                               adr[0]= (short)floorf(fx);
-                               adr[1]= (short)floorf(fy);
+                               adr[0] = (short)floorf(fx);
+                               adr[1] = (short)floorf(fy);
                        }
                }
        }
@@ -244,28 +244,28 @@ static void view3d_project_short_clip(ARegion *ar, const float vec[3], short adr
 /* BMESH NOTE: this function is unused in bmesh only */
 
 /* only use while object drawing */
-static void UNUSED_FUNCTION(view3d_project_short_noclip)(ARegion *ar, const float vec[3], short adr[2])
+static void UNUSED_FUNCTION(view3d_project_short_noclip) (ARegion * ar, const float vec[3], short adr[2])
 {
-       RegionView3D *rv3d= ar->regiondata;
+       RegionView3D *rv3d = ar->regiondata;
        float fx, fy, vec4[4];
        
-       adr[0]= IS_CLIPPED;
+       adr[0] = IS_CLIPPED;
        
        copy_v3_v3(vec4, vec);
-       vec4[3]= 1.0;
+       vec4[3] = 1.0;
        
        mul_m4_v4(rv3d->persmatob, vec4);
        
-       if ( vec4[3] > (float)BL_NEAR_CLIP ) {  /* is the NEAR clipping cutoff for picking */
-               fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]);
+       if (vec4[3] > (float)BL_NEAR_CLIP) {    /* is the NEAR clipping cutoff for picking */
+               fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
                
-               if ( fx>-32700 && fx<32700) {
+               if (fx > -32700 && fx < 32700) {
                        
-                       fy= (ar->winy/2)*(1 + vec4[1]/vec4[3]);
+                       fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
                        
                        if (fy > -32700.0f && fy < 32700.0f) {
-                               adr[0]= (short)floorf(fx);
-                               adr[1]= (short)floorf(fy);
+                               adr[0] = (short)floorf(fx);
+                               adr[1] = (short)floorf(fy);
                        }
                }
        }
@@ -274,10 +274,10 @@ static void UNUSED_FUNCTION(view3d_project_short_noclip)(ARegion *ar, const floa
 /* same as view3d_project_short_clip but use persmat instead of persmatob for projection */
 static void view3d_project_short_clip_persmat(ARegion *ar, const float vec[3], short adr[2], int is_local)
 {
-       RegionView3D *rv3d= ar->regiondata;
+       RegionView3D *rv3d = ar->regiondata;
        float fx, fy, vec4[4];
 
-       adr[0]= IS_CLIPPED;
+       adr[0] = IS_CLIPPED;
 
        /* clipplanes in eye space */
        if (rv3d->rflag & RV3D_CLIPPING) {
@@ -286,21 +286,21 @@ static void view3d_project_short_clip_persmat(ARegion *ar, const float vec[3], s
        }
 
        copy_v3_v3(vec4, vec);
-       vec4[3]= 1.0;
+       vec4[3] = 1.0;
 
        mul_m4_v4(rv3d->persmat, vec4);
 
        /* clipplanes in window space */
-       if ( vec4[3] > (float)BL_NEAR_CLIP ) {  /* is the NEAR clipping cutoff for picking */
-               fx= (ar->winx/2)*(1 + vec4[0]/vec4[3]);
+       if (vec4[3] > (float)BL_NEAR_CLIP) {    /* is the NEAR clipping cutoff for picking */
+               fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
 
-               if ( fx>0 && fx<ar->winx) {
+               if (fx > 0 && fx < ar->winx) {
 
-                       fy= (ar->winy/2)*(1 + vec4[1]/vec4[3]);
+                       fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
 
                        if (fy > 0.0f && fy < (float)ar->winy) {
-                               adr[0]= (short)floorf(fx);
-                               adr[1]= (short)floorf(fy);
+                               adr[0] = (short)floorf(fx);
+                               adr[1] = (short)floorf(fy);
                        }
                }
        }
@@ -317,7 +317,7 @@ int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt)
                return 0;
        if (!CHECK_OB_DRAWTEXTURE(v3d, dt))
                return 0;
-       if (ob==OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
+       if (ob == OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
                return 0;
        if (scene_use_new_shading_nodes(scene))
                return 0;
@@ -336,14 +336,13 @@ static int check_alpha_pass(Base *base)
        return (base->object->dtx & OB_DRAWTRANSP);
 }
 
-       /***/
-static unsigned int colortab[24]=
-       {0x0,           0xFF88FF, 0xFFBBFF, 
-        0x403000,      0xFFFF88, 0xFFFFBB, 
-        0x104040,      0x66CCCC, 0x77CCCC, 
-        0x104010,      0x55BB55, 0x66FF66, 
-        0xFFFFFF
-};
+/***/
+static unsigned int colortab[24] =
+{0x0,       0xFF88FF, 0xFFBBFF,
+ 0x403000,  0xFFFF88, 0xFFFFBB,
+ 0x104040,  0x66CCCC, 0x77CCCC,
+ 0x104010,  0x55BB55, 0x66FF66,
+ 0xFFFFFF};
 
 
 static float cube[8][3] = {
@@ -434,16 +433,16 @@ static const float cosval[CIRCLE_RESOL] = {
 
 static void draw_xyz_wire(const float c[3], float size, int axis)
 {
-       float v1[3]= {0.f, 0.f, 0.f}, v2[3] = {0.f, 0.f, 0.f};
+       float v1[3] = {0.f, 0.f, 0.f}, v2[3] = {0.f, 0.f, 0.f};
        float dim = size * 0.1f;
        float dx[3], dy[3], dz[3];
 
-       dx[0]=dim; dx[1]=0.f; dx[2]=0.f;
-       dy[0]=0.f; dy[1]=dim; dy[2]=0.f;
-       dz[0]=0.f; dz[1]=0.f; dz[2]=dim;
+       dx[0] = dim; dx[1] = 0.f; dx[2] = 0.f;
+       dy[0] = 0.f; dy[1] = dim; dy[2] = 0.f;
+       dz[0] = 0.f; dz[1] = 0.f; dz[2] = dim;
 
-       switch(axis) {
-               case 0:         /* x axis */
+       switch (axis) {
+               case 0:     /* x axis */
                        glBegin(GL_LINES);
                        
                        /* bottom left to top right */
@@ -465,7 +464,7 @@ static void draw_xyz_wire(const float c[3], float size, int axis)
                        
                        glEnd();
                        break;
-               case 1:         /* y axis */
+               case 1:     /* y axis */
                        glBegin(GL_LINES);
                        
                        /* bottom left to top right */
@@ -488,7 +487,7 @@ static void draw_xyz_wire(const float c[3], float size, int axis)
                        
                        glEnd();
                        break;
-               case 2:         /* z axis */
+               case 2:     /* z axis */
                        glBegin(GL_LINE_STRIP);
                        
                        /* start at top left */
@@ -521,23 +520,23 @@ static void draw_xyz_wire(const float c[3], float size, int axis)
 void drawaxes(float size, char drawtype)
 {
        int axis;
-       float v1[3]= {0.0, 0.0, 0.0};
-       float v2[3]= {0.0, 0.0, 0.0};
-       float v3[3]= {0.0, 0.0, 0.0};
+       float v1[3] = {0.0, 0.0, 0.0};
+       float v2[3] = {0.0, 0.0, 0.0};
+       float v3[3] = {0.0, 0.0, 0.0};
        
-       switch(drawtype) {
+       switch (drawtype) {
 
                case OB_PLAINAXES:
-                       for (axis=0; axis<3; axis++) {
+                       for (axis = 0; axis < 3; axis++) {
                                glBegin(GL_LINES);
 
-                               v1[axis]= size;
-                               v2[axis]= -size;
+                               v1[axis] = size;
+                               v2[axis] = -size;
                                glVertex3fv(v1);
                                glVertex3fv(v2);
 
                                /* reset v1 & v2 to zero */
-                               v1[axis]= v2[axis]= 0.0f;
+                               v1[axis] = v2[axis] = 0.0f;
 
                                glEnd();
                        }
@@ -546,7 +545,7 @@ void drawaxes(float size, char drawtype)
 
                        glBegin(GL_LINES);
                        /* in positive z direction only */
-                       v1[2]= size;
+                       v1[2] = size;
                        glVertex3fv(v1);
                        glVertex3fv(v2);
                        glEnd();
@@ -554,11 +553,11 @@ void drawaxes(float size, char drawtype)
                        /* square pyramid */
                        glBegin(GL_TRIANGLES);
 
-                       v2[0]= size * 0.035f; v2[1] = size * 0.035f;
-                       v3[0]= size * -0.035f; v3[1] = size * 0.035f;
-                       v2[2]= v3[2]= size * 0.75f;
+                       v2[0] = size * 0.035f; v2[1] = size * 0.035f;
+                       v3[0] = size * -0.035f; v3[1] = size * 0.035f;
+                       v2[2] = v3[2] = size * 0.75f;
 
-                       for (axis=0; axis<4; axis++) {
+                       for (axis = 0; axis < 4; axis++) {
                                if (axis % 2 == 1) {
                                        v2[0] = -v2[0];
                                        v3[1] = -v3[1];
@@ -595,33 +594,33 @@ void drawaxes(float size, char drawtype)
                case OB_ARROWS:
                default:
                {
-                       for (axis=0; axis<3; axis++) {
-                               const int arrow_axis= (axis==0) ? 1:0;
+                       for (axis = 0; axis < 3; axis++) {
+                               const int arrow_axis = (axis == 0) ? 1 : 0;
 
                                glBegin(GL_LINES);
 
-                               v2[axis]= size;
+                               v2[axis] = size;
                                glVertex3fv(v1);
                                glVertex3fv(v2);
                                
-                               v1[axis]= size*0.85f;
-                               v1[arrow_axis]= -size*0.08f;
+                               v1[axis] = size * 0.85f;
+                               v1[arrow_axis] = -size * 0.08f;
                                glVertex3fv(v1);
                                glVertex3fv(v2);
                                
-                               v1[arrow_axis]= size*0.08f;
+                               v1[arrow_axis] = size * 0.08f;
                                glVertex3fv(v1);
                                glVertex3fv(v2);
 
                                glEnd();
                                
-                               v2[axis]+= size*0.125f;
+                               v2[axis] += size * 0.125f;
 
                                draw_xyz_wire(v2, size, axis);
 
 
                                /* reset v1 & v2 to zero */
-                               v1[arrow_axis]= v1[axis]= v2[axis]= 0.0f;
+                               v1[arrow_axis] = v1[axis] = v2[axis] = 0.0f;
                        }
                        break;
                }
@@ -632,7 +631,7 @@ void drawaxes(float size, char drawtype)
 /* Function to draw an Image on a empty Object */
 static void draw_empty_image(Object *ob)
 {
-       Image *ima = (Image*)ob->data;
+       Image *ima = (Image *)ob->data;
        ImBuf *ibuf = ima ? BKE_image_get_ibuf(ima, NULL) : NULL;
 
        float scale, ofs_x, ofs_y, sca_x, sca_y;
@@ -644,37 +643,37 @@ static void draw_empty_image(Object *ob)
 
        /* Get the buffer dimensions so we can fallback to fake ones */
        if (ibuf && ibuf->rect) {
-               ima_x= ibuf->x;
-               ima_y= ibuf->y;
+               ima_x = ibuf->x;
+               ima_y = ibuf->y;
        }
        else {
-               ima_x= 1;
-               ima_y= 1;
+               ima_x = 1;
+               ima_y = 1;
        }
 
        /* Get the image aspect even if the buffer is invalid */
        if (ima) {
                if (ima->aspx > ima->aspy) {
-                       sca_x= 1.0f;
-                       sca_y= ima->aspy / ima->aspx;
+                       sca_x = 1.0f;
+                       sca_y = ima->aspy / ima->aspx;
                }
                else if (ima->aspx < ima->aspy) {
-                       sca_x= ima->aspx / ima->aspy;
-                       sca_y= 1.0f;
+                       sca_x = ima->aspx / ima->aspy;
+                       sca_y = 1.0f;
                }
                else {
-                       sca_x= 1.0f;
-                       sca_y= 1.0f;
+                       sca_x = 1.0f;
+                       sca_y = 1.0f;
                }
        }
        else {
-               sca_x= 1.0f;
-               sca_y= 1.0f;
+               sca_x = 1.0f;
+               sca_y = 1.0f;
        }
 
        /* Calculate the scale center based on objects origin */
-       ofs_x= ob->ima_ofs[0] * ima_x;
-       ofs_y= ob->ima_ofs[1] * ima_y;
+       ofs_x = ob->ima_ofs[0] * ima_x;
+       ofs_y = ob->ima_ofs[1] * ima_y;
 
        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
@@ -683,7 +682,7 @@ static void draw_empty_image(Object *ob)
        glTranslatef(0.0f,  0.0f,  0.0f);
 
        /* Calculate Image scale */
-       scale= (ob->empty_drawsize / (float)MAX2(ima_x * sca_x, ima_y * sca_y));
+       scale = (ob->empty_drawsize / (float)MAX2(ima_x * sca_x, ima_y * sca_y));
 
        /* Set the object scale */
        glScalef(scale * sca_x, scale * sca_y, 1.0f);
@@ -721,16 +720,16 @@ static void draw_empty_image(Object *ob)
 static void circball_array_fill(float verts[CIRCLE_RESOL][3], const float cent[3], float rad, float tmat[][4])
 {
        float vx[3], vy[3];
-       float *viter= (float *)verts;
+       float *viter = (float *)verts;
        unsigned int a;
 
        mul_v3_v3fl(vx, tmat[0], rad);
        mul_v3_v3fl(vy, tmat[1], rad);
 
-       for (a=0; a < CIRCLE_RESOL; a++, viter += 3) {
-               viter[0]= cent[0] + sinval[a] * vx[0] + cosval[a] * vy[0];
-               viter[1]= cent[1] + sinval[a] * vx[1] + cosval[a] * vy[1];
-               viter[2]= cent[2] + sinval[a] * vx[2] + cosval[a] * vy[2];
+       for (a = 0; a < CIRCLE_RESOL; a++, viter += 3) {
+               viter[0] = cent[0] + sinval[a] * vx[0] + cosval[a] * vy[0];
+               viter[1] = cent[1] + sinval[a] * vx[1] + cosval[a] * vy[1];
+               viter[2] = cent[2] + sinval[a] * vx[2] + cosval[a] * vy[2];
        }
 }
 
@@ -749,16 +748,16 @@ void drawcircball(int mode, const float cent[3], float rad, float tmat[][4])
 /* circle for object centers, special_color is for library or ob users */
 static void drawcentercircle(View3D *v3d, RegionView3D *rv3d, const float co[3], int selstate, int special_color)
 {
-       const float size= ED_view3d_pixel_size(rv3d, co) * (float)U.obcenter_dia * 0.5f;
+       const float size = ED_view3d_pixel_size(rv3d, co) * (float)U.obcenter_dia * 0.5f;
        float verts[CIRCLE_RESOL][3];
 
        /* using gldepthfunc guarantees that it does write z values,
         * but not checks for it, so centers remain visible independent order of drawing */
-       if (v3d->zbuf)  glDepthFunc(GL_ALWAYS);
+       if (v3d->zbuf) glDepthFunc(GL_ALWAYS);
        glEnable(GL_BLEND);
        
        if (special_color) {
-               if (selstate==ACTIVE || selstate==SELECT) glColor4ub(0x88, 0xFF, 0xFF, 155);
+               if (selstate == ACTIVE || selstate == SELECT) glColor4ub(0x88, 0xFF, 0xFF, 155);
 
                else glColor4ub(0x55, 0xCC, 0xCC, 155);
        }
@@ -786,12 +785,12 @@ static void drawcentercircle(View3D *v3d, RegionView3D *rv3d, const float co[3],
 
        glDisable(GL_BLEND);
 
-       if (v3d->zbuf)  glDepthFunc(GL_LEQUAL);
+       if (v3d->zbuf) glDepthFunc(GL_LEQUAL);
 }
 
 /* *********** text drawing for object/particles/armature ************* */
 static ListBase CachedText[3];
-static int CachedTextLevel= 0;
+static int CachedTextLevel = 0;
 
 typedef struct ViewCachedString {
        struct ViewCachedString *next, *prev;
@@ -809,8 +808,8 @@ typedef struct ViewCachedString {
 
 void view3d_cached_text_draw_begin(void)
 {
-       ListBase *strings= &CachedText[CachedTextLevel];
-       strings->first= strings->last= NULL;
+       ListBase *strings = &CachedText[CachedTextLevel];
+       strings->first = strings->last = NULL;
        CachedTextLevel++;
 }
 
@@ -819,17 +818,17 @@ void view3d_cached_text_draw_add(const float co[3],
                                  short xoffs, short flag,
                                  const unsigned char col[4])
 {
-       int alloc_len= strlen(str) + 1;
-       ListBase *strings= &CachedText[CachedTextLevel-1];
+       int alloc_len = strlen(str) + 1;
+       ListBase *strings = &CachedText[CachedTextLevel - 1];
        /* TODO, replace with more efficient malloc, perhaps memarena per draw? */
-       ViewCachedString *vos= MEM_callocN(sizeof(ViewCachedString) + alloc_len, "ViewCachedString");
+       ViewCachedString *vos = MEM_callocN(sizeof(ViewCachedString) + alloc_len, "ViewCachedString");
 
        BLI_addtail(strings, vos);
        copy_v3_v3(vos->vec, co);
-       vos->col.pack= *((int *)col);
-       vos->xoffs= xoffs;
-       vos->flag= flag;
-       vos->str_len= alloc_len-1;
+       vos->col.pack = *((int *)col);
+       vos->xoffs = xoffs;
+       vos->flag = flag;
+       vos->str_len = alloc_len - 1;
 
        /* allocate past the end */
        memcpy(++vos, str, alloc_len);
@@ -837,13 +836,13 @@ void view3d_cached_text_draw_add(const float co[3],
 
 void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, float mat[][4])
 {
-       RegionView3D *rv3d= ar->regiondata;
-       ListBase *strings= &CachedText[CachedTextLevel-1];
+       RegionView3D *rv3d = ar->regiondata;
+       ListBase *strings = &CachedText[CachedTextLevel - 1];
        ViewCachedString *vos;
-       int tot= 0;
+       int tot = 0;
        
        /* project first and test */
-       for (vos= strings->first; vos; vos= vos->next) {
+       for (vos = strings->first; vos; vos = vos->next) {
                if (mat && !(vos->flag & V3D_CACHE_TEXT_WORLDSPACE))
                        mul_m4_v3(mat, vos->vec);
 
@@ -852,12 +851,12 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
                else
                        view3d_project_short_clip(ar, vos->vec, vos->sco, (vos->flag & V3D_CACHE_TEXT_LOCALCLIP) != 0);
 
-               if (vos->sco[0]!=IS_CLIPPED)
+               if (vos->sco[0] != IS_CLIPPED)
                        tot++;
        }
 
        if (tot) {
-               int col_pack_prev= 0;
+               int col_pack_prev = 0;
 
 #if 0
                bglMats mats; /* ZBuffer depth vars */
@@ -884,34 +883,34 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, int depth_write, floa
                        glDepthMask(0);
                }
                
-               for (vos= strings->first; vos; vos= vos->next) {
+               for (vos = strings->first; vos; vos = vos->next) {
                        /* too slow, reading opengl info while drawing is very bad,
                         * better to see if we can use the zbuffer while in pixel space - campbell */
 #if 0
                        if (v3d->zbuf && (vos->flag & V3D_CACHE_TEXT_ZBUF)) {
                                gluProject(vos->vec[0], vos->vec[1], vos->vec[2], mats.modelview, mats.projection, (GLint *)mats.viewport, &ux, &uy, &uz);
-                               glReadPixels(ar->winrct.xmin+vos->mval[0]+vos->xoffs, ar->winrct.ymin+vos->mval[1], 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
+                               glReadPixels(ar->winrct.xmin + vos->mval[0] + vos->xoffs, ar->winrct.ymin + vos->mval[1], 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
 
                                if (uz > depth)
                                        continue;
                        }
 #endif
-                       if (vos->sco[0]!=IS_CLIPPED) {
-                               const char *str= (char *)(vos+1);
+                       if (vos->sco[0] != IS_CLIPPED) {
+                               const char *str = (char *)(vos + 1);
 
                                if (col_pack_prev != vos->col.pack) {
                                        glColor3ubv(vos->col.ub);
-                                       col_pack_prev= vos->col.pack;
+                                       col_pack_prev = vos->col.pack;
                                }
 
                                ((vos->flag & V3D_CACHE_TEXT_ASCII) ?
-                                           BLF_draw_default_ascii :
-                                           BLF_draw_default
-                                           ) ( (float)vos->sco[0] + vos->xoffs,
-                                               (float)vos->sco[1],
-                                               (depth_write) ? 0.0f: 2.0f,
-                                               str,
-                                               vos->str_len);
+                                BLF_draw_default_ascii :
+                                BLF_draw_default
+                               )( (float)vos->sco[0] + vos->xoffs,
+                                  (float)vos->sco[1],
+                                  (depth_write) ? 0.0f : 2.0f,
+                                  str,
+                                  vos->str_len);
                        }
                }
                
@@ -942,8 +941,8 @@ static void drawcube(void)
 {
 
        glBegin(GL_LINE_STRIP);
-       glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
-       glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
+       glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
+       glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[6]);
        glVertex3fv(cube[7]); glVertex3fv(cube[4]);
        glEnd();
 
@@ -966,25 +965,25 @@ static void drawcube(void)
 static void drawcube_size(float size)
 {
        glBegin(GL_LINE_STRIP);
-       glVertex3f(-size,-size,-size); glVertex3f(-size,-size,size);
-       glVertex3f(-size,size,size); glVertex3f(-size,size,-size);
+       glVertex3f(-size, -size, -size); glVertex3f(-size, -size, size);
+       glVertex3f(-size, size, size); glVertex3f(-size, size, -size);
 
-       glVertex3f(-size,-size,-size); glVertex3f(size,-size,-size);
-       glVertex3f(size,-size,size); glVertex3f(size,size,size);
+       glVertex3f(-size, -size, -size); glVertex3f(size, -size, -size);
+       glVertex3f(size, -size, size); glVertex3f(size, size, size);
 
-       glVertex3f(size,size,-size); glVertex3f(size,-size,-size);
+       glVertex3f(size, size, -size); glVertex3f(size, -size, -size);
        glEnd();
 
        glBegin(GL_LINE_STRIP);
-       glVertex3f(-size,-size,size); glVertex3f(size,-size,size);
+       glVertex3f(-size, -size, size); glVertex3f(size, -size, size);
        glEnd();
 
        glBegin(GL_LINE_STRIP);
-       glVertex3f(-size,size,size); glVertex3f(size,size,size);
+       glVertex3f(-size, size, size); glVertex3f(size, size, size);
        glEnd();
 
        glBegin(GL_LINE_STRIP);
-       glVertex3f(-size,size,-size); glVertex3f(size,size,-size);
+       glVertex3f(-size, size, -size); glVertex3f(size, size, -size);
        glEnd();
 }
 
@@ -998,8 +997,8 @@ static void drawcube_size(const float size[3])
        
 
        glBegin(GL_LINE_STRIP);
-       glVertex3fv(cube[0]); glVertex3fv(cube[1]);glVertex3fv(cube[2]); glVertex3fv(cube[3]);
-       glVertex3fv(cube[0]); glVertex3fv(cube[4]);glVertex3fv(cube[5]); glVertex3fv(cube[6]);
+       glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
+       glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[6]);
        glVertex3fv(cube[7]); glVertex3fv(cube[4]);
        glEnd();
 
@@ -1047,17 +1046,17 @@ static void drawshadbuflimits(Lamp *la, float mat[][4])
 static void spotvolume(float lvec[3], float vvec[3], const float inp)
 {
        /* camera is at 0,0,0 */
-       float temp[3],plane[3],mat1[3][3],mat2[3][3],mat3[3][3],mat4[3][3],q[4],co,si,angle;
+       float temp[3], plane[3], mat1[3][3], mat2[3][3], mat3[3][3], mat4[3][3], q[4], co, si, angle;
 
        normalize_v3(lvec);
-       normalize_v3(vvec);                             /* is this the correct vector ? */
+       normalize_v3(vvec);             /* is this the correct vector ? */
 
-       cross_v3_v3v3(temp,vvec,lvec);          /* equation for a plane through vvec en lvec */
-       cross_v3_v3v3(plane,lvec,temp);         /* a plane perpendicular to this, parrallel with lvec */
+       cross_v3_v3v3(temp, vvec, lvec);      /* equation for a plane through vvec en lvec */
+       cross_v3_v3v3(plane, lvec, temp);     /* a plane perpendicular to this, parrallel with lvec */
 
        /* vectors are exactly aligned, use the X axis, this is arbitrary */
        if (normalize_v3(plane) == 0.0f)
-               plane[1]= 1.0f;
+               plane[1] = 1.0f;
 
        /* now we've got two equations: one of a cone and one of a plane, but we have
         * three unknowns. We remove one unknown by rotating the plane to z=0 (the plane normal) */
@@ -1072,46 +1071,46 @@ static void spotvolume(float lvec[3], float vvec[3], const float inp)
        q[3] =  0;
        normalize_v3(&q[1]);
 
-       angle = saacos(plane[2])/2.0f;
+       angle = saacos(plane[2]) / 2.0f;
        co = cosf(angle);
-       si = sqrtf(1-co*co);
+       si = sqrtf(1 - co * co);
 
        q[0] =  co;
        q[1] *= si;
        q[2] *= si;
        q[3] =  0;
 
-       quat_to_mat3(mat1,q);
+       quat_to_mat3(mat1, q);
 
        /* rotate lamp vector now over acos(inp) degrees */
        copy_v3_v3(vvec, lvec);
 
        unit_m3(mat2);
        co = inp;
-       si = sqrtf(1.0f-inp*inp);
+       si = sqrtf(1.0f - inp * inp);
 
        mat2[0][0] =  co;
        mat2[1][0] = -si;
        mat2[0][1] =  si;
        mat2[1][1] =  co;
-       mul_m3_m3m3(mat3,mat2,mat1);
+       mul_m3_m3m3(mat3, mat2, mat1);
 
        mat2[1][0] =  si;
        mat2[0][1] = -si;
-       mul_m3_m3m3(mat4,mat2,mat1);
+       mul_m3_m3m3(mat4, mat2, mat1);
        transpose_m3(mat1);
 
-       mul_m3_m3m3(mat2,mat1,mat3);
-       mul_m3_v3(mat2,lvec);
-       mul_m3_m3m3(mat2,mat1,mat4);
-       mul_m3_v3(mat2,vvec);
+       mul_m3_m3m3(mat2, mat1, mat3);
+       mul_m3_v3(mat2, lvec);
+       mul_m3_m3m3(mat2, mat1, mat4);
+       mul_m3_v3(mat2, vvec);
 
        return;
 }
 
 static void draw_spot_cone(Lamp *la, float x, float z)
 {
-       z= fabs(z);
+       z = fabs(z);
 
        glBegin(GL_TRIANGLE_FAN);
        glVertex3f(0.0f, 0.0f, -x);
@@ -1127,9 +1126,9 @@ static void draw_spot_cone(Lamp *la, float x, float z)
                float angle;
                int a;
 
-               for (a=0; a<33; a++) {
-                       angle= a*M_PI*2/(33-1);
-                       glVertex3f(z*cosf(angle), z*sinf(angle), 0);
+               for (a = 0; a < 33; a++) {
+                       angle = a * M_PI * 2 / (33 - 1);
+                       glVertex3f(z * cosf(angle), z * sinf(angle), 0);
                }
        }
 
@@ -1168,22 +1167,22 @@ static void draw_transp_spot_volume(Lamp *la, float x, float z)
 
 static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
 {
-       Object *ob= base->object;
-       const float pixsize= ED_view3d_pixel_size(rv3d, ob->obmat[3]);
-       Lamp *la= ob->data;
-       float vec[3], lvec[3], vvec[3], circrad, x,y,z;
+       Object *ob = base->object;
+       const float pixsize = ED_view3d_pixel_size(rv3d, ob->obmat[3]);
+       Lamp *la = ob->data;
+       float vec[3], lvec[3], vvec[3], circrad, x, y, z;
        float lampsize;
        float imat[4][4], curcol[4];
        unsigned char col[4];
        /* cone can't be drawn for duplicated lamps, because duplilist would be freed to */
        /* the moment of view3d_draw_transp() call */
-       const short is_view= (rv3d->persp==RV3D_CAMOB && v3d->camera == base->object);
-       const short drawcone= ((dt > OB_WIRE) &&
-                              !(G.f & G_PICKSEL) &&
-                              (la->type == LA_SPOT) &&
-                              (la->mode & LA_SHOW_CONE) &&
-                              !(base->flag & OB_FROMDUPLI) &&
-                              !is_view);
+       const short is_view = (rv3d->persp == RV3D_CAMOB && v3d->camera == base->object);
+       const short drawcone = ((dt > OB_WIRE) &&
+                               !(G.f & G_PICKSEL) &&
+                               (la->type == LA_SPOT) &&
+                               (la->mode & LA_SHOW_CONE) &&
+                               !(base->flag & OB_FROMDUPLI) &&
+                               !is_view);
 
        if (drawcone && !v3d->transp) {
                /* in this case we need to draw delayed */
@@ -1196,7 +1195,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        glLoadMatrixf(rv3d->viewmat);
 
        /* lets calculate the scale: */
-       lampsize= pixsize*((float)U.obcenter_dia*0.5f);
+       lampsize = pixsize * ((float)U.obcenter_dia * 0.5f);
 
        /* and view aligned matrix: */
        copy_m4_m4(imat, rv3d->viewinv);
@@ -1208,13 +1207,13 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        
        /* for AA effects */
        glGetFloatv(GL_CURRENT_COLOR, curcol);
-       curcol[3]= 0.6;
+       curcol[3] = 0.6;
        glColor4fv(curcol);
        
        if (lampsize > 0.0f) {
 
-               if (ob->id.us>1) {
-                       if (ob==OBACT || (ob->flag & SELECT)) glColor4ub(0x88, 0xFF, 0xFF, 155);
+               if (ob->id.us > 1) {
+                       if (ob == OBACT || (ob->flag & SELECT)) glColor4ub(0x88, 0xFF, 0xFF, 155);
                        else glColor4ub(0x77, 0xCC, 0xCC, 155);
                }
                
@@ -1225,19 +1224,19 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                drawcircball(GL_POLYGON, vec, lampsize, imat);
                
                /* restore */
-               if (ob->id.us>1)
+               if (ob->id.us > 1)
                        glColor4fv(curcol);
 
                /* Outer circle */
-               circrad = 3.0f*lampsize;
+               circrad = 3.0f * lampsize;
                setlinestyle(3);
 
                drawcircball(GL_LINE_LOOP, vec, circrad, imat);
 
                /* draw dashed outer circle if shadow is on. remember some lamps can't have certain shadows! */
-               if (la->type!=LA_HEMI) {
+               if (la->type != LA_HEMI) {
                        if ((la->mode & LA_SHAD_RAY) || ((la->mode & LA_SHAD_BUF) && (la->type == LA_SPOT))) {
-                               drawcircball(GL_LINE_LOOP, vec, circrad + 3.0f*pixsize, imat);
+                               drawcircball(GL_LINE_LOOP, vec, circrad + 3.0f * pixsize, imat);
                        }
                }
        }
@@ -1247,12 +1246,12 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
        }
        
        /* draw the pretty sun rays */
-       if (la->type==LA_SUN) {
+       if (la->type == LA_SUN) {
                float v1[3], v2[3], mat[3][3];
                short axis;
                
                /* setup a 45 degree rotation matrix */
-               vec_rot_to_mat3(mat, imat[2], (float)M_PI/4.0f);
+               vec_rot_to_mat3(mat, imat[2], (float)M_PI / 4.0f);
                
                /* vectors */
                mul_v3_v3fl(v1, imat[0], circrad * 1.2f);
@@ -1264,7 +1263,7 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                setlinestyle(3);
                
                glBegin(GL_LINES);
-               for (axis=0; axis<8; axis++) {
+               for (axis = 0; axis < 8; axis++) {
                        glVertex3fv(v1);
                        glVertex3fv(v2);
                        mul_m3_v3(mat, v1);
@@ -1276,30 +1275,30 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
        }
        
-       if (la->type==LA_LOCAL) {
+       if (la->type == LA_LOCAL) {
                if (la->mode & LA_SPHERE) {
                        drawcircball(GL_LINE_LOOP, vec, la->dist, imat);
                }
                /* yafray: for photonlight also draw lightcone as for spot */
        }
        
-       glPopMatrix();  /* back in object space */
+       glPopMatrix();  /* back in object space */
        zero_v3(vec);
        
        if (is_view) {
                /* skip drawing extra info */
        }
-       else if ((la->type==LA_SPOT) || (la->type==LA_YF_PHOTON)) {
-               lvec[0]=lvec[1]= 0.0;
+       else if ((la->type == LA_SPOT) || (la->type == LA_YF_PHOTON)) {
+               lvec[0] = lvec[1] = 0.0;
                lvec[2] = 1.0;
                x = rv3d->persmat[0][2];
                y = rv3d->persmat[1][2];
                z = rv3d->persmat[2][2];
-               vvec[0]= x*ob->obmat[0][0] + y*ob->obmat[0][1] + z*ob->obmat[0][2];
-               vvec[1]= x*ob->obmat[1][0] + y*ob->obmat[1][1] + z*ob->obmat[1][2];
-               vvec[2]= x*ob->obmat[2][0] + y*ob->obmat[2][1] + z*ob->obmat[2][2];
+               vvec[0] = x * ob->obmat[0][0] + y * ob->obmat[0][1] + z * ob->obmat[0][2];
+               vvec[1] = x * ob->obmat[1][0] + y * ob->obmat[1][1] + z * ob->obmat[1][2];
+               vvec[2] = x * ob->obmat[2][0] + y * ob->obmat[2][1] + z * ob->obmat[2][2];
 
-               y = cosf(la->spotsize*(float)(M_PI/360.0));
+               y = cosf(la->spotsize * (float)(M_PI / 360.0));
                spotvolume(lvec, vvec, y);
                x = -la->dist;
                mul_v3_fl(lvec, x);
@@ -1312,33 +1311,33 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                glVertex3fv(lvec);
                glEnd();
                
-               z = x*sqrtf(1.0f - y*y);
+               z = x * sqrtf(1.0f - y * y);
                x *= y;
 
                /* draw the circle/square at the end of the cone */
-               glTranslatef(0.0, 0.0 ,  x);
+               glTranslatef(0.0, 0.0,  x);
                if (la->mode & LA_SQUARE) {
                        float tvec[3];
-                       float z_abs= fabs(z);
+                       float z_abs = fabs(z);
 
-                       tvec[0]= tvec[1]= z_abs;
-                       tvec[2]= 0.0;
+                       tvec[0] = tvec[1] = z_abs;
+                       tvec[2] = 0.0;
 
                        glBegin(GL_LINE_LOOP);
                        glVertex3fv(tvec);
-                       tvec[1]= -z_abs; /* neg */
+                       tvec[1] = -z_abs; /* neg */
                        glVertex3fv(tvec);
-                       tvec[0]= -z_abs; /* neg */
+                       tvec[0] = -z_abs; /* neg */
                        glVertex3fv(tvec);
-                       tvec[1]= z_abs; /* pos */
+                       tvec[1] = z_abs; /* pos */
                        glVertex3fv(tvec);
                        glEnd();
                }
                else circ(0.0, 0.0, fabsf(z));
                
                /* draw the circle/square representing spotbl */
-               if (la->type==LA_SPOT) {
-                       float spotblcirc = fabs(z)*(1 - pow(la->spotblend, 2));
+               if (la->type == LA_SPOT) {
+                       float spotblcirc = fabs(z) * (1 - pow(la->spotblend, 2));
                        /* hide line if it is zero size or overlaps with outer border,
                         * previously it adjusted to always to show it but that seems
                         * confusing because it doesn't show the actual blend size */
@@ -1350,11 +1349,11 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        draw_transp_spot_volume(la, x, z);
 
                /* draw clip start, useful for wide cones where its not obvious where the start is */
-               glTranslatef(0.0, 0.0 , -x); /* reverse translation above */
-               if (la->type==LA_SPOT && (la->mode & LA_SHAD_BUF) ) {
+               glTranslatef(0.0, 0.0, -x);  /* reverse translation above */
+               if (la->type == LA_SPOT && (la->mode & LA_SHAD_BUF) ) {
                        float lvec_clip[3];
                        float vvec_clip[3];
-                       float clipsta_fac= la->clipsta / -x;
+                       float clipsta_fac = la->clipsta / -x;
 
                        interp_v3_v3v3(lvec_clip, vec, lvec, clipsta_fac);
                        interp_v3_v3v3(vvec_clip, vec, vvec, clipsta_fac);
@@ -1371,11 +1370,11 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                glBegin(GL_LINE_STRIP);
                vec[2] = -circrad;
                glVertex3fv(vec);
-               vec[2]= -la->dist;
+               vec[2] = -la->dist;
                glVertex3fv(vec);
                glEnd();
                
-               if (la->type==LA_HEMI) {
+               if (la->type == LA_HEMI) {
                        /* draw the hemisphere curves */
                        short axis, steps, dir;
                        float outdist, zdist, mul;
@@ -1384,24 +1383,24 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        
                        setlinestyle(4);
                        /* loop over the 4 compass points, and draw each arc as a LINE_STRIP */
-                       for (axis=0; axis<4; axis++) {
-                               float v[3]= {0.0, 0.0, 0.0};
+                       for (axis = 0; axis < 4; axis++) {
+                               float v[3] = {0.0, 0.0, 0.0};
                                zdist = 0.02;
                                
                                glBegin(GL_LINE_STRIP);
                                
-                               for (steps=0; steps<6; steps++) {
-                                       if (axis == 0 || axis == 1) {           /* x axis up, x axis down */
+                               for (steps = 0; steps < 6; steps++) {
+                                       if (axis == 0 || axis == 1) {       /* x axis up, x axis down */
                                                /* make the arcs start at the edge of the energy circle */
-                                               if (steps == 0) v[0] = dir*circrad;
-                                               else v[0] = v[0] + dir*(steps*outdist);
+                                               if (steps == 0) v[0] = dir * circrad;
+                                               else v[0] = v[0] + dir * (steps * outdist);
                                        }
-                                       else if (axis == 2 || axis == 3) {              /* y axis up, y axis down */
+                                       else if (axis == 2 || axis == 3) {      /* y axis up, y axis down */
                                                /* make the arcs start at the edge of the energy circle */
                                                v[1] = (steps == 0) ? (dir * circrad) : (v[1] + dir * (steps * outdist));
                                        }
 
-                                       v[2] = v[2] - steps*zdist;
+                                       v[2] = v[2] - steps * zdist;
                                        
                                        glVertex3fv(v);
                                        
@@ -1414,16 +1413,16 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
                        }
                }
        }
-       else if (la->type==LA_AREA) {
+       else if (la->type == LA_AREA) {
                setlinestyle(3);
-               if (la->area_shape==LA_AREA_SQUARE)
-                       fdrawbox(-la->area_size*0.5f, -la->area_size*0.5f, la->area_size*0.5f, la->area_size*0.5f);
-               else if (la->area_shape==LA_AREA_RECT)
-                       fdrawbox(-la->area_size*0.5f, -la->area_sizey*0.5f, la->area_size*0.5f, la->area_sizey*0.5f);
+               if (la->area_shape == LA_AREA_SQUARE)
+                       fdrawbox(-la->area_size * 0.5f, -la->area_size * 0.5f, la->area_size * 0.5f, la->area_size * 0.5f);
+               else if (la->area_shape == LA_AREA_RECT)
+                       fdrawbox(-la->area_size * 0.5f, -la->area_sizey * 0.5f, la->area_size * 0.5f, la->area_sizey * 0.5f);
 
                glBegin(GL_LINE_STRIP);
-               glVertex3f(0.0,0.0,-circrad);
-               glVertex3f(0.0,0.0,-la->dist);
+               glVertex3f(0.0, 0.0, -circrad);
+               glVertex3f(0.0, 0.0, -la->dist);
                glEnd();
        }
        
@@ -1442,12 +1441,12 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
 
        glEnable(GL_BLEND);
        
-       if (vec[2]>0) vec[2] -= circrad;
+       if (vec[2] > 0) vec[2] -= circrad;
        else vec[2] += circrad;
        
        glBegin(GL_LINE_STRIP);
        glVertex3fv(vec);
-       vec[2]= 0;
+       vec[2] = 0;
        glVertex3fv(vec);
        glEnd();
        
@@ -1495,22 +1494,22 @@ static void draw_focus_cross(float dist, float size)
 
 #ifdef VIEW3D_CAMERA_BORDER_HACK
 float view3d_camera_border_hack_col[4];
-short view3d_camera_border_hack_test= FALSE;
+short view3d_camera_border_hack_test = FALSE;
 #endif
 
 /* ****************** draw clip data *************** */
 
 static void draw_bundle_sphere(void)
 {
-       static GLuint displist= 0;
+       static GLuint displist = 0;
 
        if (displist == 0) {
                GLUquadricObj *qobj;
 
-               displist= glGenLists(1);
+               displist = glGenLists(1);
                glNewList(displist, GL_COMPILE);
 
-               qobj= gluNewQuadric();
+               qobj = gluNewQuadric();
                gluQuadricDrawStyle(qobj, GLU_FILL);
                glShadeModel(GL_SMOOTH);
                gluSphere(qobj, 0.05, 8, 8);
@@ -1527,12 +1526,12 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                                 MovieClip *clip, MovieTrackingObject *tracking_object, int flag,
                                                 int *global_track_index, int draw_selected)
 {
-       MovieTracking *tracking= &clip->tracking;
+       MovieTracking *tracking = &clip->tracking;
        MovieTrackingTrack *track;
        float mat[4][4], imat[4][4];
        unsigned char col[4], scol[4];
-       int tracknr= *global_track_index;
-       ListBase *tracksbase= BKE_tracking_object_tracks(tracking, tracking_object);
+       int tracknr = *global_track_index;
+       ListBase *tracksbase = BKE_tracking_object_tracks(tracking, tracking_object);
 
        UI_GetThemeColor4ubv(TH_TEXT, col);
        UI_GetThemeColor4ubv(TH_SELECT, scol);
@@ -1559,31 +1558,31 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                glMultMatrixf(imat);
        }
 
-       for (track= tracksbase->first; track; track= track->next) {
-               int selected= TRACK_SELECTED(track);
+       for (track = tracksbase->first; track; track = track->next) {
+               int selected = TRACK_SELECTED(track);
 
                if (draw_selected && !selected)
                        continue;
 
-               if ((track->flag&TRACK_HAS_BUNDLE)==0)
+               if ((track->flag & TRACK_HAS_BUNDLE) == 0)
                        continue;
 
-               if (flag&DRAW_PICKING)
-                       glLoadName(base->selcol + (tracknr<<16));
+               if (flag & DRAW_PICKING)
+                       glLoadName(base->selcol + (tracknr << 16));
 
                glPushMatrix();
                glTranslatef(track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
-               glScalef(v3d->bundle_size/0.05f, v3d->bundle_size/0.05f, v3d->bundle_size/0.05f);
+               glScalef(v3d->bundle_size / 0.05f, v3d->bundle_size / 0.05f, v3d->bundle_size / 0.05f);
 
-               if (v3d->drawtype==OB_WIRE) {
+               if (v3d->drawtype == OB_WIRE) {
                        glDisable(GL_LIGHTING);
 
                        if (selected) {
-                               if (base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                               if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
                                else UI_ThemeColor(TH_SELECT);
                        }
                        else {
-                               if (track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
                                else UI_ThemeColor(TH_WIRE);
                        }
 
@@ -1591,11 +1590,11 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
                        glEnable(GL_LIGHTING);
                }
-               else if (v3d->drawtype>OB_WIRE) {
-                       if (v3d->bundle_drawtype==OB_EMPTY_SPHERE) {
+               else if (v3d->drawtype > OB_WIRE) {
+                       if (v3d->bundle_drawtype == OB_EMPTY_SPHERE) {
                                /* selection outline */
                                if (selected) {
-                                       if (base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                                       if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
                                        else UI_ThemeColor(TH_SELECT);
 
                                        glLineWidth(2.f);
@@ -1609,7 +1608,7 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                        glLineWidth(1.f);
                                }
 
-                               if (track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
                                else UI_ThemeColor(TH_BUNDLE_SOLID);
 
                                draw_bundle_sphere();
@@ -1618,11 +1617,11 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                glDisable(GL_LIGHTING);
 
                                if (selected) {
-                                       if (base==BASACT) UI_ThemeColor(TH_ACTIVE);
+                                       if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
                                        else UI_ThemeColor(TH_SELECT);
                                }
                                else {
-                                       if (track->flag&TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                       if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
                                        else UI_ThemeColor(TH_WIRE);
                                }
 
@@ -1634,7 +1633,7 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
                glPopMatrix();
 
-               if ((flag & DRAW_PICKING)==0 && (v3d->flag2&V3D_SHOW_BUNDLENAME)) {
+               if ((flag & DRAW_PICKING) == 0 && (v3d->flag2 & V3D_SHOW_BUNDLENAME)) {
                        float pos[3];
                        unsigned char tcol[4];
 
@@ -1648,21 +1647,21 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                tracknr++;
        }
 
-       if ((flag & DRAW_PICKING)==0) {
-               if ((v3d->flag2&V3D_SHOW_CAMERAPATH) && (tracking_object->flag&TRACKING_OBJECT_CAMERA)) {
+       if ((flag & DRAW_PICKING) == 0) {
+               if ((v3d->flag2 & V3D_SHOW_CAMERAPATH) && (tracking_object->flag & TRACKING_OBJECT_CAMERA)) {
                        MovieTrackingReconstruction *reconstruction;
-                       reconstruction= BKE_tracking_object_reconstruction(tracking, tracking_object);
+                       reconstruction = BKE_tracking_object_reconstruction(tracking, tracking_object);
 
                        if (reconstruction->camnr) {
-                               MovieReconstructedCamera *camera= reconstruction->cameras;
-                               int a= 0;
+                               MovieReconstructedCamera *camera = reconstruction->cameras;
+                               int a = 0;
 
                                glDisable(GL_LIGHTING);
                                UI_ThemeColor(TH_CAMERA_PATH);
                                glLineWidth(2.0f);
 
                                glBegin(GL_LINE_STRIP);
-                               for (a= 0; a<reconstruction->camnr; a++, camera++) {
+                               for (a = 0; a < reconstruction->camnr; a++, camera++) {
                                        glVertex3fv(camera->mat[3]);
                                }
                                glEnd();
@@ -1675,21 +1674,21 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
        glPopMatrix();
 
-       *global_track_index= tracknr;
+       *global_track_index = tracknr;
 }
 
 static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d, MovieClip *clip,
                                          int flag, int draw_selected)
 {
-       MovieTracking *tracking= &clip->tracking;
+       MovieTracking *tracking = &clip->tracking;
        MovieTrackingObject *tracking_object;
        float curcol[4];
-       int global_track_index= 1;
+       int global_track_index = 1;
 
-       if ((v3d->flag2&V3D_SHOW_RECONSTRUCTION)==0)
+       if ((v3d->flag2 & V3D_SHOW_RECONSTRUCTION) == 0)
                return;
 
-       if (v3d->flag2&V3D_RENDER_OVERRIDE)
+       if (v3d->flag2 & V3D_RENDER_OVERRIDE)
                return;
 
        glGetFloatv(GL_CURRENT_COLOR, curcol);
@@ -1699,12 +1698,12 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
        glEnable(GL_COLOR_MATERIAL);
        glShadeModel(GL_SMOOTH);
 
-       tracking_object= tracking->objects.first;
+       tracking_object = tracking->objects.first;
        while (tracking_object) {
                draw_viewport_object_reconstruction(scene, base, v3d, clip, tracking_object,
                                                    flag, &global_track_index, draw_selected);
 
-               tracking_object= tracking_object->next;
+               tracking_object = tracking_object->next;
        }
 
        /* restore */
@@ -1714,7 +1713,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
 
        glColor4fv(curcol);
 
-       if (flag&DRAW_PICKING)
+       if (flag & DRAW_PICKING)
                glLoadName(base->selcol);
 }
 
@@ -1723,13 +1722,13 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
 {
        /* a standing up pyramid with (0,0,0) as top */
        Camera *cam;
-       Object *ob= base->object;
+       Object *ob = base->object;
        float tvec[3];
        float vec[4][3], asp[2], shift[2], scale[3];
        int i;
        float drawsize;
-       const short is_view= (rv3d->persp==RV3D_CAMOB && ob==v3d->camera);
-       MovieClip *clip= object_get_movieclip(scene, base->object, 0);
+       const short is_view = (rv3d->persp == RV3D_CAMOB && ob == v3d->camera);
+       MovieClip *clip = object_get_movieclip(scene, base->object, 0);
 
        /* draw data for movie clip set as active for scene */
        if (clip) {
@@ -1740,16 +1739,16 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
 #ifdef VIEW3D_CAMERA_BORDER_HACK
        if (is_view && !(G.f & G_PICKSEL)) {
                glGetFloatv(GL_CURRENT_COLOR, view3d_camera_border_hack_col);
-               view3d_camera_border_hack_test= TRUE;
+               view3d_camera_border_hack_test = TRUE;
                return;
        }
 #endif
 
-       cam= ob->data;
+       cam = ob->data;
 
-       scale[0]= 1.0f / len_v3(ob->obmat[0]);
-       scale[1]= 1.0f / len_v3(ob->obmat[1]);
-       scale[2]= 1.0f / len_v3(ob->obmat[2]);
+       scale[0] = 1.0f / len_v3(ob->obmat[0]);
+       scale[1] = 1.0f / len_v3(ob->obmat[1]);
+       scale[2] = 1.0f / len_v3(ob->obmat[2]);
 
        camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale,
                             asp, shift, &drawsize, vec);
@@ -1782,33 +1781,33 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
 
 
        /* arrow on top */
-       tvec[2]= vec[1][2]; /* copy the depth */
+       tvec[2] = vec[1][2]; /* copy the depth */
 
 
        /* draw an outline arrow for inactive cameras and filled
         * for active cameras. We actually draw both outline+filled
         * for active cameras so the wire can be seen side-on */
-       for (i=0;i<2;i++) {
-               if (i==0) glBegin(GL_LINE_LOOP);
-               else if (i==1 && (ob == v3d->camera)) glBegin(GL_TRIANGLES);
+       for (i = 0; i < 2; i++) {
+               if (i == 0) glBegin(GL_LINE_LOOP);
+               else if (i == 1 && (ob == v3d->camera)) glBegin(GL_TRIANGLES);
                else break;
 
-               tvec[0]= shift[0] + ((-0.7f * drawsize) * scale[0]);
-               tvec[1]= shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]);
+               tvec[0] = shift[0] + ((-0.7f * drawsize) * scale[0]);
+               tvec[1] = shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]);
                glVertex3fv(tvec); /* left */
                
-               tvec[0]= shift[0] + ((0.7f * drawsize) * scale[0]);
+               tvec[0] = shift[0] + ((0.7f * drawsize) * scale[0]);
                glVertex3fv(tvec); /* right */
                
-               tvec[0]= shift[0];
-               tvec[1]= shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]);
+               tvec[0] = shift[0];
+               tvec[1] = shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]);
                glVertex3fv(tvec); /* top */
 
                glEnd();
        }
 
-       if (flag==0) {
-               if (cam->flag & (CAM_SHOWLIMITS+CAM_SHOWMIST)) {
+       if (flag == 0) {
+               if (cam->flag & (CAM_SHOWLIMITS + CAM_SHOWMIST)) {
                        float nobmat[4][4];
                        World *wrld;
 
@@ -1826,9 +1825,9 @@ static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base
                                draw_focus_cross(object_camera_dof_distance(ob), cam->drawsize);
                        }
 
-                       wrld= scene->world;
+                       wrld = scene->world;
                        if (cam->flag & CAM_SHOWMIST)
-                               if (wrld) draw_limit_line(wrld->miststa, wrld->miststa+wrld->mistdist, 0xFFFFFF);
+                               if (wrld) draw_limit_line(wrld->miststa, wrld->miststa + wrld->mistdist, 0xFFFFFF);
 
                        glPopMatrix();
                }
@@ -1847,7 +1846,7 @@ static void drawspeaker(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D
        glEnable(GL_BLEND);
 
        for (j = 0; j < 3; j++) {
-               vec[2] = 0.25f * j -0.125f;
+               vec[2] = 0.25f * j - 0.125f;
 
                glBegin(GL_LINE_LOOP);
                for (i = 0; i < 16; i++) {
@@ -1868,7 +1867,7 @@ static void drawspeaker(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D
                                vec[1] *= 0.5f;
                        }
 
-                       vec[2] = 0.25f * i -0.125f;
+                       vec[2] = 0.25f * i - 0.125f;
                        glVertex3fv(vec);
                }
                glEnd();
@@ -1880,23 +1879,23 @@ static void drawspeaker(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D
 static void lattice_draw_verts(Lattice *lt, DispList *dl, short sel)
 {
        BPoint *bp = lt->def;
-       float *co = dl?dl->verts:NULL;
+       float *co = dl ? dl->verts : NULL;
        int u, v, w;
 
-       UI_ThemeColor(sel?TH_VERTEX_SELECT:TH_VERTEX);
+       UI_ThemeColor(sel ? TH_VERTEX_SELECT : TH_VERTEX);
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
        bglBegin(GL_POINTS);
 
-       for (w=0; w<lt->pntsw; w++) {
-               int wxt = (w==0 || w==lt->pntsw-1);
-               for (v=0; v<lt->pntsv; v++) {
-                       int vxt = (v==0 || v==lt->pntsv-1);
-                       for (u=0; u<lt->pntsu; u++, bp++, co+=3) {
-                               int uxt = (u==0 || u==lt->pntsu-1);
+       for (w = 0; w < lt->pntsw; w++) {
+               int wxt = (w == 0 || w == lt->pntsw - 1);
+               for (v = 0; v < lt->pntsv; v++) {
+                       int vxt = (v == 0 || v == lt->pntsv - 1);
+                       for (u = 0; u < lt->pntsu; u++, bp++, co += 3) {
+                               int uxt = (u == 0 || u == lt->pntsu - 1);
                                if (!(lt->flag & LT_OUTSIDE) || uxt || vxt || wxt) {
-                                       if (bp->hide==0) {
-                                               if ((bp->f1 & SELECT)==sel) {
-                                                       bglVertex3fv(dl?co:bp->vec);
+                                       if (bp->hide == 0) {
+                                               if ((bp->f1 & SELECT) == sel) {
+                                                       bglVertex3fv(dl ? co : bp->vec);
                                                }
                                        }
                                }
@@ -1910,19 +1909,19 @@ static void lattice_draw_verts(Lattice *lt, DispList *dl, short sel)
 
 void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPoint *bp, int x, int y), void *userData)
 {
-       Object *obedit= vc->obedit;
-       Lattice *lt= obedit->data;
+       Object *obedit = vc->obedit;
+       Lattice *lt = obedit->data;
        BPoint *bp = lt->editlatt->latt->def;
        DispList *dl = find_displist(&obedit->disp, DL_VERTS);
-       float *co = dl?dl->verts:NULL;
-       int i, N = lt->editlatt->latt->pntsu*lt->editlatt->latt->pntsv*lt->editlatt->latt->pntsw;
+       float *co = dl ? dl->verts : NULL;
+       int i, N = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
        short s[2] = {IS_CLIPPED, 0};
 
        ED_view3d_clipping_local(vc->rv3d, obedit->obmat); /* for local clipping lookups */
 
-       for (i=0; i<N; i++, bp++, co+=3) {
-               if (bp->hide==0) {
-                       view3d_project_short_clip(vc->ar, dl?co:bp->vec, s, TRUE);
+       for (i = 0; i < N; i++, bp++, co += 3) {
+               if (bp->hide == 0) {
+                       view3d_project_short_clip(vc->ar, dl ? co : bp->vec, s, TRUE);
                        if (s[0] != IS_CLIPPED)
                                func(userData, bp, s[0], s[1]);
                }
@@ -1931,19 +1930,19 @@ void lattice_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, BPo
 
 static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, int use_wcol)
 {
-       int index = ((w*lt->pntsv + v)*lt->pntsu) + u;
+       int index = ((w * lt->pntsv + v) * lt->pntsu) + u;
 
        if (use_wcol) {
                float col[3];
-               MDeformWeight *mdw= defvert_find_index (lt->dvert+index, use_wcol-1);
+               MDeformWeight *mdw = defvert_find_index(lt->dvert + index, use_wcol - 1);
                
-               weight_to_rgb(col, mdw?mdw->weight:0.0f);
+               weight_to_rgb(col, mdw ? mdw->weight : 0.0f);
                glColor3fv(col);
 
        }
        
        if (dl) {
-               glVertex3fv(&dl->verts[index*3]);
+               glVertex3fv(&dl->verts[index * 3]);
        }
        else {
                glVertex3fv(lt->def[index].vec);
@@ -1953,45 +1952,45 @@ static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, i
 /* lattice color is hardcoded, now also shows weightgroup values in edit mode */
 static void drawlattice(Scene *scene, View3D *v3d, Object *ob)
 {
-       Lattice *lt= ob->data;
+       Lattice *lt = ob->data;
        DispList *dl;
        int u, v, w;
-       int use_wcol= 0, is_edit= (lt->editlatt != NULL);
+       int use_wcol = 0, is_edit = (lt->editlatt != NULL);
 
        /* now we default make displist, this will modifiers work for non animated case */
-       if (ob->disp.first==NULL)
+       if (ob->disp.first == NULL)
                lattice_calc_modifiers(scene, ob);
-       dl= find_displist(&ob->disp, DL_VERTS);
+       dl = find_displist(&ob->disp, DL_VERTS);
        
        if (is_edit) {
-               lt= lt->editlatt->latt;
+               lt = lt->editlatt->latt;
 
                cpack(0x004000);
                
                if (ob->defbase.first && lt->dvert) {
-                       use_wcol= ob->actdef;
+                       use_wcol = ob->actdef;
                        glShadeModel(GL_SMOOTH);
                }
        }
        
        glBegin(GL_LINES);
-       for (w=0; w<lt->pntsw; w++) {
-               int wxt = (w==0 || w==lt->pntsw-1);
-               for (v=0; v<lt->pntsv; v++) {
-                       int vxt = (v==0 || v==lt->pntsv-1);
-                       for (u=0; u<lt->pntsu; u++) {
-                               int uxt = (u==0 || u==lt->pntsu-1);
+       for (w = 0; w < lt->pntsw; w++) {
+               int wxt = (w == 0 || w == lt->pntsw - 1);
+               for (v = 0; v < lt->pntsv; v++) {
+                       int vxt = (v == 0 || v == lt->pntsv - 1);
+                       for (u = 0; u < lt->pntsu; u++) {
+                               int uxt = (u == 0 || u == lt->pntsu - 1);
 
                                if (w && ((uxt || vxt) || !(lt->flag & LT_OUTSIDE))) {
-                                       drawlattice__point(lt, dl, u, v, w-1, use_wcol);
+                                       drawlattice__point(lt, dl, u, v, w - 1, use_wcol);
                                        drawlattice__point(lt, dl, u, v, w, use_wcol);
                                }
                                if (v && ((uxt || wxt) || !(lt->flag & LT_OUTSIDE))) {
-                                       drawlattice__point(lt, dl, u, v-1, w, use_wcol);
+                                       drawlattice__point(lt, dl, u, v - 1, w, use_wcol);
                                        drawlattice__point(lt, dl, u, v, w, use_wcol);
                                }
                                if (u && ((vxt || wxt) || !(lt->flag & LT_OUTSIDE))) {
-                                       drawlattice__point(lt, dl, u-1, v, w, use_wcol);
+                                       drawlattice__point(lt, dl, u - 1, v, w, use_wcol);
                                        drawlattice__point(lt, dl, u, v, w, use_wcol);
                                }
                        }
@@ -2025,7 +2024,7 @@ static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co
        BMVert *eve = EDBM_get_vert_for_index(data->vc.em, index);
 
        if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
-               short s[2]= {IS_CLIPPED, 0};
+               short s[2] = {IS_CLIPPED, 0};
 
                if (data->clipVerts != V3D_CLIP_TEST_OFF) {
                        view3d_project_short_clip(data->vc.ar, co, s, TRUE);
@@ -2036,26 +2035,26 @@ static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co
                        project_short_noclip(data->vc.ar, co2, s);
                }
 
-               if (s[0]!=IS_CLIPPED)
+               if (s[0] != IS_CLIPPED)
                        data->func(data->userData, eve, s[0], s[1], index);
        }
 }
 
 void mesh_foreachScreenVert(
-        ViewContext *vc,
-        void (*func)(void *userData, BMVert *eve, int x, int y, int index),
-        void *userData, eV3DClipTest clipVerts)
+    ViewContext *vc,
+    void (*func)(void *userData, BMVert *eve, int x, int y, int index),
+    void *userData, eV3DClipTest clipVerts)
 {
        foreachScreenVert_userData data;
        DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
        
-       data.vc= *vc;
+       data.vc = *vc;
        data.func = func;
        data.userData = userData;
        data.clipVerts = clipVerts;
 
        if (clipVerts != V3D_CLIP_TEST_OFF)
-               ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
+               ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat);  /* for local clipping lookups */
 
        EDBM_init_index_arrays(vc->em, 1, 0, 0);
        dm->foreachMappedVert(dm, mesh_foreachScreenVert__mapFunc, &data);
@@ -2070,7 +2069,7 @@ static void drawSelectedVertices__mapFunc(void *userData, int index, float *co,
        MVert *mv = &((MVert *)userData)[index];
 
        if (!(mv->flag & ME_HIDE)) {
-               const char sel= mv->flag & SELECT;
+               const char sel = mv->flag & SELECT;
 
                // TODO define selected color
                if (sel) {
@@ -2120,8 +2119,8 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0
                        project_short_noclip(data->vc.ar, v2_co, s[1]);
 
                        if (data->clipVerts == V3D_CLIP_TEST_REGION) {
-                               if ( !is_co_in_region(data->vc.ar, s[0]) &&
-                                    !is_co_in_region(data->vc.ar, s[1]))
+                               if (!is_co_in_region(data->vc.ar, s[0]) &&
+                                   !is_co_in_region(data->vc.ar, s[1]))
                                {
                                        return;
                                }
@@ -2133,20 +2132,20 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0
 }
 
 void mesh_foreachScreenEdge(
-        ViewContext *vc,
-        void (*func)(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index),
-        void *userData, eV3DClipTest clipVerts)
+    ViewContext *vc,
+    void (*func)(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int index),
+    void *userData, eV3DClipTest clipVerts)
 {
        foreachScreenEdge_userData data;
        DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
 
-       data.vc= *vc;
+       data.vc = *vc;
        data.func = func;
        data.userData = userData;
        data.clipVerts = clipVerts;
 
        if (clipVerts != V3D_CLIP_TEST_OFF)
-               ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
+               ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat);  /* for local clipping lookups */
 
        EDBM_init_index_arrays(vc->em, 0, 1, 0);
        dm->foreachMappedEdge(dm, mesh_foreachScreenEdge__mapFunc, &data);
@@ -2174,14 +2173,14 @@ static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *ce
 }
 
 void mesh_foreachScreenFace(
-        ViewContext *vc,
-        void (*func)(void *userData, BMFace *efa, int x, int y, int index),
-        void *userData)
+    ViewContext *vc,
+    void (*func)(void *userData, BMFace *efa, int x, int y, int index),
+    void *userData)
 {
        foreachScreenFace_userData data;
        DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
 
-       data.vc= *vc;
+       data.vc = *vc;
        data.func = func;
        data.userData = userData;
 
@@ -2196,24 +2195,24 @@ void mesh_foreachScreenFace(
 }
 
 void nurbs_foreachScreenVert(
-        ViewContext *vc,
-        void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y),
-        void *userData)
+    ViewContext *vc,
+    void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt, int beztindex, int x, int y),
+    void *userData)
 {
-       Curve *cu= vc->obedit->data;
+       Curve *cu = vc->obedit->data;
        short s[2] = {IS_CLIPPED, 0};
        Nurb *nu;
        int i;
-       ListBase *nurbs= curve_editnurbs(cu);
+       ListBase *nurbs = curve_editnurbs(cu);
 
        ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
 
-       for (nu= nurbs->first; nu; nu=nu->next) {
+       for (nu = nurbs->first; nu; nu = nu->next) {
                if (nu->type == CU_BEZIER) {
-                       for (i=0; i<nu->pntsu; i++) {
+                       for (i = 0; i < nu->pntsu; i++) {
                                BezTriple *bezt = &nu->bezt[i];
 
-                               if (bezt->hide==0) {
+                               if (bezt->hide == 0) {
                                        
                                        if (cu->drawflag & CU_HIDE_HANDLES) {
                                                view3d_project_short_clip(vc->ar, bezt->vec[1], s, TRUE);
@@ -2235,10 +2234,10 @@ void nurbs_foreachScreenVert(
                        }
                }
                else {
-                       for (i=0; i<nu->pntsu*nu->pntsv; i++) {
+                       for (i = 0; i < nu->pntsu * nu->pntsv; i++) {
                                BPoint *bp = &nu->bp[i];
 
-                               if (bp->hide==0) {
+                               if (bp->hide == 0) {
                                        view3d_project_short_clip(vc->ar, bp->vec, s, TRUE);
                                        if (s[0] != IS_CLIPPED)
                                                func(userData, nu, bp, NULL, -1, s[0], s[1]);
@@ -2288,7 +2287,7 @@ static void draw_dm_face_centers__mapFunc(void *userData, int index, float *cent
        BMFace *efa = EDBM_get_face_for_index(((void **)userData)[0], index);
        int sel = *(((int **)userData)[1]);
        
-       if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BM_elem_flag_test(efa, BM_ELEM_SELECT)==sel) {
+       if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BM_elem_flag_test(efa, BM_ELEM_SELECT) == sel) {
                bglVertex3fv(cent);
        }
 }
@@ -2336,12 +2335,12 @@ static void draw_dm_vert_normals(BMEditMesh *em, Scene *scene, DerivedMesh *dm)
 /* Draw verts with color set based on selection */
 static void draw_dm_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
 {
-       drawDMVerts_userData * data = userData;
+       drawDMVerts_userData *data = userData;
        BMVert *eve = EDBM_get_vert_for_index(data->em, index);
 
-       if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BM_elem_flag_test(eve, BM_ELEM_SELECT)==data->sel) {
+       if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BM_elem_flag_test(eve, BM_ELEM_SELECT) == data->sel) {
                /* draw active larger - need to stop/start point drawing for this :/ */
-               if (eve==data->eve_act) {
+               if (eve == data->eve_act) {
                        float size = UI_GetThemeValuef(TH_VERTEX_SIZE);
                        UI_ThemeColor4(TH_EDITMESH_ACTIVE);
                        
@@ -2352,7 +2351,7 @@ static void draw_dm_verts__mapFunc(void *userData, int index, float *co, float *
                        bglVertex3fv(co);
                        bglEnd();
                        
-                       UI_ThemeColor4(data->sel?TH_VERTEX_SELECT:TH_VERTEX);
+                       UI_ThemeColor4(data->sel ? TH_VERTEX_SELECT : TH_VERTEX);
                        glPointSize(size);
                        bglBegin(GL_POINTS);
                }
@@ -2379,13 +2378,13 @@ static DMDrawOption draw_dm_edges_sel__setDrawOptions(void *userData, int index)
 {
        BMEdge *eed;
        //unsigned char **cols = userData, *col;
-       drawDMEdgesSel_userData * data = userData;
+       drawDMEdgesSel_userData *data = userData;
        unsigned char *col;
 
        eed = EDBM_get_edge_for_index(data->em, index);
 
        if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
-               if (eed==data->eed_act) {
+               if (eed == data->eed_act) {
                        glColor4ubv(data->actCol);
                }
                else {
@@ -2396,7 +2395,7 @@ static DMDrawOption draw_dm_edges_sel__setDrawOptions(void *userData, int index)
                                col = data->baseCol;
                        }
                        /* no alpha, this is used so a transparent color can disable drawing unselected edges in editmode  */
-                       if (col[3]==0)
+                       if (col[3] == 0)
                                return DM_DRAW_OPTION_SKIP;
                        
                        glColor4ubv(col);
@@ -2437,17 +2436,17 @@ static void draw_dm_edges(BMEditMesh *em, DerivedMesh *dm)
 /* Draw edges with color interpolated based on selection */
 static DMDrawOption draw_dm_edges_sel_interp__setDrawOptions(void *userData, int index)
 {
-       if (BM_elem_flag_test(EDBM_get_edge_for_index(((void**)userData)[0], index), BM_ELEM_HIDDEN))
+       if (BM_elem_flag_test(EDBM_get_edge_for_index(((void **)userData)[0], index), BM_ELEM_HIDDEN))
                return DM_DRAW_OPTION_SKIP;
        else
                return DM_DRAW_OPTION_NORMAL;
 }
 static void draw_dm_edges_sel_interp__setDrawInterpOptions(void *userData, int index, float t)
 {
-       BMEdge *eed = EDBM_get_edge_for_index(((void**)userData)[0], index);
+       BMEdge *eed = EDBM_get_edge_for_index(((void **)userData)[0], index);
        unsigned char **cols = userData;
-       unsigned char *col0 = cols[(BM_elem_flag_test(eed->v1, BM_ELEM_SELECT))?2:1];
-       unsigned char *col1 = cols[(BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))?2:1];
+       unsigned char *col0 = cols[(BM_elem_flag_test(eed->v1, BM_ELEM_SELECT)) ? 2 : 1];
+       unsigned char *col1 = cols[(BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)) ? 2 : 1];
 
        glColor4ub(col0[0] + (col1[0] - col0[0]) * t,
                   col0[1] + (col1[1] - col0[1]) * t,
@@ -2496,10 +2495,10 @@ static void draw_dm_edges_sharp(BMEditMesh *em, DerivedMesh *dm)
 
 
 /* Draw faces with color set based on selection
       * return 2 for the active face so it renders with stipple enabled */
+ * return 2 for the active face so it renders with stipple enabled */
 static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index)
 {
-       drawDMFacesSel_userData * data = userData;
+       drawDMFacesSel_userData *data = userData;
        BMFace *efa = EDBM_get_face_for_index(data->em, index);
        unsigned char *col;
        
@@ -2512,8 +2511,8 @@ static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index)
                        return DM_DRAW_OPTION_STIPPLE;
                }
                else {
-                       col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT)?1:0];
-                       if (col[3]==0)
+                       col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
+                       if (col[3] == 0)
                                return DM_DRAW_OPTION_SKIP;
                        glColor4ubv(col);
                        return DM_DRAW_OPTION_NORMAL;
@@ -2534,8 +2533,8 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
        if (!data->orig_index)
              &nbs