code cleanup: use uppercase defines and change drawFCurveFade into static function.
[blender.git] / source / blender / editors / space_graph / graph_draw.c
index 543bd8b99647a84f215e79cf1d6732caf6d7fdc0..25998e7bce21a0189871d8142e523c55e3c73b18 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** END GPL LICENSE BLOCK *****
  */
 
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/space_graph/graph_draw.c
+ *  \ingroup spgraph
+ */
+
+
 #include <stdio.h>
 #include <math.h>
 #include <string.h>
 #include <stdio.h>
 #include <math.h>
 #include <string.h>
 #include <io.h>
 #endif
 
 #include <io.h>
 #endif
 
-#include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
+#include "BLI_utildefines.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_object_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_userdef_types.h"
 
 
-#include "BKE_animsys.h"
 #include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_context.h"
 #include "BKE_curve.h"
-#include "BKE_depsgraph.h"
 #include "BKE_fcurve.h"
 #include "BKE_fcurve.h"
-#include "BKE_global.h"
-#include "BKE_key.h"
-#include "BKE_object.h"
-#include "BKE_screen.h"
-#include "BKE_utildefines.h"
+
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
  * drawing components for some F-Curve (fcu)
  *     - selected F-Curves should be more visible than partially visible ones
  */
  * drawing components for some F-Curve (fcu)
  *     - selected F-Curves should be more visible than partially visible ones
  */
-#define drawFCurveFade(fcu) ( ((fcu)->flag & FCURVE_SELECTED)? 1.0f : 0.25f )
-
-/* set the colour for some point from some value given packed into an int 
- *     - intV: integer value containing color info packed into an int
- *     - alpha: float value describing the 
- */
-#define cpackA(intVC, alpha) \
-       { \
-               float _cpackCol[3]; \
-               cpack_to_rgb(intVC, &_cpackCol[0], &_cpackCol[1], &_cpackCol[2]); \
-               glColor4f(_cpackCol[0], _cpackCol[1], _cpackCol[2], alpha); \
-       }
+static float fcurve_display_alpha(FCurve *fcu)
+{
+       return (fcu->flag & FCURVE_SELECTED) ? 1.0f : U.fcu_inactive_alpha;
+}
 
 /* *************************** */
 /* F-Curve Modifier Drawing */
 
 /* *************************** */
 /* F-Curve Modifier Drawing */
@@ -94,7 +84,7 @@
 /* Envelope -------------- */
 
 // TODO: draw a shaded poly showing the region of influence too!!!
 /* Envelope -------------- */
 
 // TODO: draw a shaded poly showing the region of influence too!!!
-static void draw_fcurve_modifier_controls_envelope (FCurve *fcu, FModifier *fcm, View2D *v2d)
+static void draw_fcurve_modifier_controls_envelope (FModifier *fcm, View2D *v2d)
 {
        FMod_Envelope *env= (FMod_Envelope *)fcm->data;
        FCM_EnvelopeData *fed;
 {
        FMod_Envelope *env= (FMod_Envelope *)fcm->data;
        FCM_EnvelopeData *fed;
@@ -144,7 +134,7 @@ static void draw_fcurve_modifier_controls_envelope (FCurve *fcu, FModifier *fcm,
 /* Points ---------------- */
 
 /* helper func - draw keyframe vertices only for an F-Curve */
 /* Points ---------------- */
 
 /* helper func - draw keyframe vertices only for an F-Curve */
-static void draw_fcurve_vertices_keyframes (bAnimContext *ac, FCurve *fcu, View2D *v2d, short edit, short sel)
+static void draw_fcurve_vertices_keyframes (FCurve *fcu, SpaceIpo *UNUSED(sipo), View2D *v2d, short edit, short sel)
 {
        BezTriple *bezt= fcu->bezt;
        const float fac= 0.05f * (v2d->cur.xmax - v2d->cur.xmin);
 {
        BezTriple *bezt= fcu->bezt;
        const float fac= 0.05f * (v2d->cur.xmax - v2d->cur.xmin);
@@ -156,7 +146,7 @@ static void draw_fcurve_vertices_keyframes (bAnimContext *ac, FCurve *fcu, View2
        bglBegin(GL_POINTS);
        
        for (i = 0; i < fcu->totvert; i++, bezt++) {
        bglBegin(GL_POINTS);
        
        for (i = 0; i < fcu->totvert; i++, bezt++) {
-               /* as an optimisation step, only draw those in view 
+               /* as an optimization step, only draw those in view 
                 *      - we apply a correction factor to ensure that points don't pop in/out due to slight twitches of view size
                 */
                if IN_RANGE(bezt->vec[1][0], (v2d->cur.xmin - fac), (v2d->cur.xmax + fac)) {
                 *      - we apply a correction factor to ensure that points don't pop in/out due to slight twitches of view size
                 */
                if IN_RANGE(bezt->vec[1][0], (v2d->cur.xmin - fac), (v2d->cur.xmax + fac)) {
@@ -188,7 +178,7 @@ static void draw_fcurve_handle_control (float x, float y, float xscale, float ys
 {
        static GLuint displist=0;
        
 {
        static GLuint displist=0;
        
-       /* initialise round circle shape */
+       /* initialize round circle shape */
        if (displist == 0) {
                GLUquadricObj *qobj;
                
        if (displist == 0) {
                GLUquadricObj *qobj;
                
@@ -216,7 +206,7 @@ static void draw_fcurve_handle_control (float x, float y, float xscale, float ys
 }
 
 /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
 }
 
 /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
-static void draw_fcurve_vertices_handles (bAnimContext *ac, SpaceIpo *sipo, FCurve *fcu, View2D *v2d, short sel)
+static void draw_fcurve_vertices_handles (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, short sel, short sel_handle_only)
 {
        BezTriple *bezt= fcu->bezt;
        BezTriple *prevbezt = NULL;
 {
        BezTriple *bezt= fcu->bezt;
        BezTriple *prevbezt = NULL;
@@ -232,7 +222,7 @@ static void draw_fcurve_vertices_handles (bAnimContext *ac, SpaceIpo *sipo, FCur
        else UI_ThemeColor(TH_HANDLE_VERTEX);
        
        /* anti-aliased lines for more consistent appearance */
        else UI_ThemeColor(TH_HANDLE_VERTEX);
        
        /* anti-aliased lines for more consistent appearance */
-       glEnable(GL_LINE_SMOOTH);
+       if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glEnable(GL_LINE_SMOOTH);
        glEnable(GL_BLEND);
        
        for (i=0; i < fcu->totvert; i++, prevbezt=bezt, bezt++) {
        glEnable(GL_BLEND);
        
        for (i=0; i < fcu->totvert; i++, prevbezt=bezt, bezt++) {
@@ -244,7 +234,7 @@ static void draw_fcurve_vertices_handles (bAnimContext *ac, SpaceIpo *sipo, FCur
                 * Also, need to take into account whether the keyframe was selected
                 * if a Graph Editor option to only show handles of selected keys is on.
                 */
                 * Also, need to take into account whether the keyframe was selected
                 * if a Graph Editor option to only show handles of selected keys is on.
                 */
-               if ( !(sipo->flag & SIPO_SELVHANDLESONLY) || BEZSELECTED(bezt) ) {
+               if ( !sel_handle_only || BEZSELECTED(bezt) ) {
                        if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) {
                                if ((bezt->f1 & SELECT) == sel)/* && v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/
                                        draw_fcurve_handle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize);
                        if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) {
                                if ((bezt->f1 & SELECT) == sel)/* && v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/
                                        draw_fcurve_handle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize);
@@ -257,15 +247,15 @@ static void draw_fcurve_vertices_handles (bAnimContext *ac, SpaceIpo *sipo, FCur
                }
        }
        
                }
        }
        
-       glDisable(GL_LINE_SMOOTH);
+       if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
        glDisable(GL_BLEND);
 }
 
 /* helper func - set color to draw F-Curve data with */
        glDisable(GL_BLEND);
 }
 
 /* helper func - set color to draw F-Curve data with */
-static void set_fcurve_vertex_color (SpaceIpo *sipo, FCurve *fcu, short sel)
+static void set_fcurve_vertex_color (FCurve *fcu, short sel)
 {
        /* Fade the 'intensity' of the vertices based on the selection of the curves too */
 {
        /* Fade the 'intensity' of the vertices based on the selection of the curves too */
-       int alphaOffset= (int)((drawFCurveFade(fcu) - 1.0f) * 255);
+       int alphaOffset= (int)((fcurve_display_alpha(fcu) - 1.0f) * 255);
        
        /* Set color of curve vertex based on state of curve (i.e. 'Edit' Mode) */
        if ((fcu->flag & FCURVE_PROTECTED)==0) {
        
        /* Set color of curve vertex based on state of curve (i.e. 'Edit' Mode) */
        if ((fcu->flag & FCURVE_PROTECTED)==0) {
@@ -281,7 +271,7 @@ static void set_fcurve_vertex_color (SpaceIpo *sipo, FCurve *fcu, short sel)
 }
 
 
 }
 
 
-static void draw_fcurve_vertices (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu, int do_handles)
+static void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short do_handles, short sel_handle_only)
 {
        View2D *v2d= &ar->v2d;
        
 {
        View2D *v2d= &ar->v2d;
        
@@ -295,21 +285,20 @@ static void draw_fcurve_vertices (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar,
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
        
        /* draw the two handles first (if they're shown, the curve doesn't have just a single keyframe, and the curve is being edited) */
        glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
        
        /* draw the two handles first (if they're shown, the curve doesn't have just a single keyframe, and the curve is being edited) */
-       if (do_handles)
-       {
-               set_fcurve_vertex_color(sipo, fcu, 0);
-               draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 0);
+       if (do_handles) {
+               set_fcurve_vertex_color(fcu, 0);
+               draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only);
                
                
-               set_fcurve_vertex_color(sipo, fcu, 1);
-               draw_fcurve_vertices_handles(ac, sipo, fcu, v2d, 1);
+               set_fcurve_vertex_color(fcu, 1);
+               draw_fcurve_vertices_handles(fcu, sipo, v2d, 1, sel_handle_only);
        }
                
        /* draw keyframes over the handles */
        }
                
        /* draw keyframes over the handles */
-       set_fcurve_vertex_color(sipo, fcu, 0);
-       draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
+       set_fcurve_vertex_color(fcu, 0);
+       draw_fcurve_vertices_keyframes(fcu, sipo, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
        
        
-       set_fcurve_vertex_color(sipo, fcu, 1);
-       draw_fcurve_vertices_keyframes(ac, fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
+       set_fcurve_vertex_color(fcu, 1);
+       draw_fcurve_vertices_keyframes(fcu, sipo, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
        
        glPointSize(1.0f);
 }
        
        glPointSize(1.0f);
 }
@@ -321,27 +310,28 @@ static int draw_fcurve_handles_check(SpaceIpo *sipo, FCurve *fcu)
        /* don't draw handle lines if handles are not to be shown */
        if (    (sipo->flag & SIPO_NOHANDLES) || /* handles shouldn't be shown anywhere */
                        (fcu->flag & FCURVE_PROTECTED) || /* keyframes aren't editable */
        /* don't draw handle lines if handles are not to be shown */
        if (    (sipo->flag & SIPO_NOHANDLES) || /* handles shouldn't be shown anywhere */
                        (fcu->flag & FCURVE_PROTECTED) || /* keyframes aren't editable */
+#if 0          /* handles can still be selected and handle types set, better draw - campbell */
                        (fcu->flag & FCURVE_INT_VALUES) || /* editing the handles here will cause weird/incorrect interpolation issues */
                        (fcu->flag & FCURVE_INT_VALUES) || /* editing the handles here will cause weird/incorrect interpolation issues */
+#endif
                        ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || /* group that curve belongs to is not editable */
                        (fcu->totvert <= 1) /* do not show handles if there is only 1 keyframe, otherwise they all clump together in an ugly ball */
                ) 
        {
                return 0;
        } 
                        ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || /* group that curve belongs to is not editable */
                        (fcu->totvert <= 1) /* do not show handles if there is only 1 keyframe, otherwise they all clump together in an ugly ball */
                ) 
        {
                return 0;
        } 
-       else 
-       {
+       else {
                return 1;
        }
 }
 
 /* draw lines for F-Curve handles only (this is only done in EditMode)
  * note: draw_fcurve_handles_check must be checked before running this. */
                return 1;
        }
 }
 
 /* draw lines for F-Curve handles only (this is only done in EditMode)
  * note: draw_fcurve_handles_check must be checked before running this. */
-static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
+static void draw_fcurve_handles (SpaceIpo *sipo, FCurve *fcu)
 {
        int sel, b;
        
        /* a single call to GL_LINES here around these calls should be sufficient to still
 {
        int sel, b;
        
        /* a single call to GL_LINES here around these calls should be sufficient to still
-        * get separate line segments, but which aren't wrapped with GL_LINE_STRIP everytime we
+        * get separate line segments, but which aren't wrapped with GL_LINE_STRIP every time we
         * want a single line
         */
        glBegin(GL_LINES);
         * want a single line
         */
        glBegin(GL_LINES);
@@ -353,11 +343,7 @@ static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar,
                BezTriple *bezt=fcu->bezt, *prevbezt=NULL;
                int basecol= (sel)? TH_HANDLE_SEL_FREE : TH_HANDLE_FREE;
                float *fp;
                BezTriple *bezt=fcu->bezt, *prevbezt=NULL;
                int basecol= (sel)? TH_HANDLE_SEL_FREE : TH_HANDLE_FREE;
                float *fp;
-               char col[4];
-               
-               /* if only selected keyframes have handles shown, skip the first round */
-               if ((sel == 0) && (sipo->flag & SIPO_SELVHANDLESONLY))
-                       continue;
+               unsigned char col[4];
                
                for (b= 0; b < fcu->totvert; b++, prevbezt=bezt, bezt++) {
                        /* if only selected keyframes can get their handles shown, 
                
                for (b= 0; b < fcu->totvert; b++, prevbezt=bezt, bezt++) {
                        /* if only selected keyframes can get their handles shown, 
@@ -371,24 +357,22 @@ static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar,
                        /* draw handle with appropriate set of colors if selection is ok */
                        if ((bezt->f2 & SELECT)==sel) {
                                fp= bezt->vec[0];
                        /* draw handle with appropriate set of colors if selection is ok */
                        if ((bezt->f2 & SELECT)==sel) {
                                fp= bezt->vec[0];
-
+                               
                                /* only draw first handle if previous segment had handles */
                                /* only draw first handle if previous segment had handles */
-                               if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) 
-                               {
+                               if ((!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ))) {
                                        UI_GetThemeColor3ubv(basecol + bezt->h1, col);
                                        UI_GetThemeColor3ubv(basecol + bezt->h1, col);
-                                       col[3]= drawFCurveFade(fcu) * 255;
+                                       col[3]= fcurve_display_alpha(fcu) * 255;
                                        glColor4ubv((GLubyte *)col);
                                        
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
                                        glColor4ubv((GLubyte *)col);
                                        
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
-
+                               
                                /* only draw second handle if this segment is bezier */
                                /* only draw second handle if this segment is bezier */
-                               if (bezt->ipo == BEZT_IPO_BEZ) 
-                               {
+                               if (bezt->ipo == BEZT_IPO_BEZ) {
                                        UI_GetThemeColor3ubv(basecol + bezt->h2, col);
                                        UI_GetThemeColor3ubv(basecol + bezt->h2, col);
-                                       col[3]= drawFCurveFade(fcu) * 255;
+                                       col[3]= fcurve_display_alpha(fcu) * 255;
                                        glColor4ubv((GLubyte *)col);
                                        glColor4ubv((GLubyte *)col);
-
+                                       
                                        glVertex2fv(fp+3); glVertex2fv(fp+6); 
                                }
                        }
                                        glVertex2fv(fp+3); glVertex2fv(fp+6); 
                                }
                        }
@@ -399,9 +383,9 @@ static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar,
                                {
                                        fp= bezt->vec[0];
                                        UI_GetThemeColor3ubv(basecol + bezt->h1, col);
                                {
                                        fp= bezt->vec[0];
                                        UI_GetThemeColor3ubv(basecol + bezt->h1, col);
-                                       col[3]= drawFCurveFade(fcu) * 255;
+                                       col[3]= fcurve_display_alpha(fcu) * 255;
                                        glColor4ubv((GLubyte *)col);
                                        glColor4ubv((GLubyte *)col);
-
+                                       
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
                                
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
                                
@@ -411,9 +395,9 @@ static void draw_fcurve_handles (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar,
                                {
                                        fp= bezt->vec[1];
                                        UI_GetThemeColor3ubv(basecol + bezt->h2, col);
                                {
                                        fp= bezt->vec[1];
                                        UI_GetThemeColor3ubv(basecol + bezt->h2, col);
-                                       col[3]= drawFCurveFade(fcu) * 255;
+                                       col[3]= fcurve_display_alpha(fcu) * 255;
                                        glColor4ubv((GLubyte *)col);
                                        glColor4ubv((GLubyte *)col);
-
+                                       
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
                        }
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
                        }
@@ -433,7 +417,7 @@ static void draw_fcurve_sample_control (float x, float y, float xscale, float ys
 {
        static GLuint displist=0;
        
 {
        static GLuint displist=0;
        
-       /* initialise X shape */
+       /* initialize X shape */
        if (displist == 0) {
                displist= glGenLists(1);
                glNewList(displist, GL_COMPILE);
        if (displist == 0) {
                displist= glGenLists(1);
                glNewList(displist, GL_COMPILE);
@@ -462,7 +446,7 @@ static void draw_fcurve_sample_control (float x, float y, float xscale, float ys
 }
 
 /* helper func - draw keyframe vertices only for an F-Curve */
 }
 
 /* helper func - draw keyframe vertices only for an F-Curve */
-static void draw_fcurve_samples (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
+static void draw_fcurve_samples (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
 {
        FPoint *first, *last;
        float hsize, xscale, yscale;
 {
        FPoint *first, *last;
        float hsize, xscale, yscale;
@@ -482,21 +466,21 @@ static void draw_fcurve_samples (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar,
        /* draw */
        if (first && last) {
                /* anti-aliased lines for more consistent appearance */
        /* draw */
        if (first && last) {
                /* anti-aliased lines for more consistent appearance */
-               glEnable(GL_LINE_SMOOTH);
+               if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glEnable(GL_LINE_SMOOTH);
                glEnable(GL_BLEND);
                
                draw_fcurve_sample_control(first->vec[0], first->vec[1], xscale, yscale, hsize);
                draw_fcurve_sample_control(last->vec[0], last->vec[1], xscale, yscale, hsize);
                
                glDisable(GL_BLEND);
                glEnable(GL_BLEND);
                
                draw_fcurve_sample_control(first->vec[0], first->vec[1], xscale, yscale, hsize);
                draw_fcurve_sample_control(last->vec[0], last->vec[1], xscale, yscale, hsize);
                
                glDisable(GL_BLEND);
-               glDisable(GL_LINE_SMOOTH);
+               if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
        }
 }
 
 /* Curve ---------------- */
 
 /* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
        }
 }
 
 /* Curve ---------------- */
 
 /* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
-static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DGrid *grid)
+static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
 {
        ChannelDriver *driver;
        float samplefreq, ctime;
 {
        ChannelDriver *driver;
        float samplefreq, ctime;
@@ -507,7 +491,7 @@ static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, SpaceIpo *
        /* when opening a blend file on a different sized screen or while dragging the toolbar this can happen
         * best just bail out in this case */
        UI_view2d_grid_size(grid, &dx, &dy);
        /* when opening a blend file on a different sized screen or while dragging the toolbar this can happen
         * best just bail out in this case */
        UI_view2d_grid_size(grid, &dx, &dy);
-       if(dx <= 0.0f)
+       if (dx <= 0.0f)
                return;
 
 
                return;
 
 
@@ -634,7 +618,7 @@ static void draw_fcurve_curve_samples (bAnimContext *ac, ID *id, FCurve *fcu, Vi
 }
 
 /* helper func - draw one repeat of an F-Curve */
 }
 
 /* helper func - draw one repeat of an F-Curve */
-static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
+static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d)
 {
        BezTriple *prevbezt= fcu->bezt;
        BezTriple *bezt= prevbezt+1;
 {
        BezTriple *prevbezt= fcu->bezt;
        BezTriple *bezt= prevbezt+1;
@@ -683,6 +667,7 @@ static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View
        }
        
        /* draw curve between first and last keyframe (if there are enough to do so) */
        }
        
        /* draw curve between first and last keyframe (if there are enough to do so) */
+       // TODO: optimize this to not have to calc stuff out of view too?
        while (b--) {
                if (prevbezt->ipo==BEZT_IPO_CONST) {
                        /* Constant-Interpolation: draw segment between previous keyframe and next, but holding same value */
        while (b--) {
                if (prevbezt->ipo==BEZT_IPO_CONST) {
                        /* Constant-Interpolation: draw segment between previous keyframe and next, but holding same value */
@@ -705,12 +690,12 @@ static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View
                         *      - resol determines number of points to sample in between keyframes
                         */
                        
                         *      - resol determines number of points to sample in between keyframes
                         */
                        
-                       /* resol not depending on horizontal resolution anymore, drivers for example... */
-                       // TODO: would be nice to make this depend on the scale of the graph too...
+                       /* resol depends on distance between points (not just horizontal) OR is a fixed high res */
+                       // TODO: view scale should factor into this someday too...
                        if (fcu->driver) 
                                resol= 32;
                        else 
                        if (fcu->driver) 
                                resol= 32;
                        else 
-                               resol= (int)(3.0*sqrt(bezt->vec[1][0] - prevbezt->vec[1][0]));
+                               resol= (int)(5.0f*len_v2v2(bezt->vec[1], prevbezt->vec[1]));
                        
                        if (resol < 2) {
                                /* only draw one */
                        
                        if (resol < 2) {
                                /* only draw one */
@@ -720,6 +705,7 @@ static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View
                        }
                        else {
                                /* clamp resolution to max of 32 */
                        }
                        else {
                                /* clamp resolution to max of 32 */
+                               // NOTE: higher values will crash
                                if (resol > 32) resol= 32;
                                
                                v1[0]= prevbezt->vec[1][0];
                                if (resol > 32) resol= 32;
                                
                                v1[0]= prevbezt->vec[1][0];
@@ -791,7 +777,7 @@ static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View
 /* Draw the 'ghost' F-Curves (i.e. snapshots of the curve) 
  * NOTE: unit mapping has already been applied to the values, so do not try and apply again
  */
 /* Draw the 'ghost' F-Curves (i.e. snapshots of the curve) 
  * NOTE: unit mapping has already been applied to the values, so do not try and apply again
  */
-void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid)
+void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar)
 {
        FCurve *fcu;
        
 {
        FCurve *fcu;
        
@@ -800,7 +786,7 @@ void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, Vie
        glLineWidth(3.0f);
        
        /* anti-aliased lines for less jagged appearance */
        glLineWidth(3.0f);
        
        /* anti-aliased lines for less jagged appearance */
-       glEnable(GL_LINE_SMOOTH);
+       if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glEnable(GL_LINE_SMOOTH);
        glEnable(GL_BLEND);
        
        /* the ghost curves are simply sampled F-Curves stored in sipo->ghostCurves */
        glEnable(GL_BLEND);
        
        /* the ghost curves are simply sampled F-Curves stored in sipo->ghostCurves */
@@ -819,7 +805,7 @@ void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, Vie
        setlinestyle(0);
        glLineWidth(1.0f);
        
        setlinestyle(0);
        glLineWidth(1.0f);
        
-       glDisable(GL_LINE_SMOOTH);
+       if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
        glDisable(GL_BLEND);
 }
 
        glDisable(GL_BLEND);
 }
 
@@ -833,7 +819,7 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
        int filter;
        
        /* build list of curves to draw */
        int filter;
        
        /* build list of curves to draw */
-       filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CURVESONLY|ANIMFILTER_CURVEVISIBLE);
+       filter= (ANIMFILTER_DATA_VISIBLE|ANIMFILTER_CURVE_VISIBLE);
        filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL));
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
                
        filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL));
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
                
@@ -853,7 +839,7 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
                /* draw curve:
                 *      - curve line may be result of one or more destructive modifiers or just the raw data,
                 *        so we need to check which method should be used
                /* draw curve:
                 *      - curve line may be result of one or more destructive modifiers or just the raw data,
                 *        so we need to check which method should be used
-                *      - controls from active modifier take precidence over keyframes
+                *      - controls from active modifier take precedence over keyframes
                 *        (XXX! editing tools need to take this into account!)
                 */
                 
                 *        (XXX! editing tools need to take this into account!)
                 */
                 
@@ -873,11 +859,16 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
                                /* set whatever color the curve has set 
                                 *      - unselected curves draw less opaque to help distinguish the selected ones
                                 */
                                /* set whatever color the curve has set 
                                 *      - unselected curves draw less opaque to help distinguish the selected ones
                                 */
-                               glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], drawFCurveFade(fcu));
+                               glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], fcurve_display_alpha(fcu));
+                       }
+                       
+                       /* draw active F-Curve thicker than the rest to make it stand out */
+                       if (fcu->flag & FCURVE_ACTIVE) {
+                               glLineWidth(2.0);
                        }
                        
                        /* anti-aliased lines for less jagged appearance */
                        }
                        
                        /* anti-aliased lines for less jagged appearance */
-                       glEnable(GL_LINE_SMOOTH);
+                       if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glEnable(GL_LINE_SMOOTH);
                        glEnable(GL_BLEND);
                        
                        /* draw F-Curve */
                        glEnable(GL_BLEND);
                        
                        /* draw F-Curve */
@@ -885,20 +876,21 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
                                /* draw a curve affected by modifiers or only allowed to have integer values 
                                 * by sampling it at various small-intervals over the visible region 
                                 */
                                /* draw a curve affected by modifiers or only allowed to have integer values 
                                 * by sampling it at various small-intervals over the visible region 
                                 */
-                               draw_fcurve_curve(ac, ale->id, fcu, sipo, &ar->v2d, grid);
+                               draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid);
                        }
                        else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { 
                                /* just draw curve based on defined data (i.e. no modifiers) */
                                if (fcu->bezt)
                        }
                        else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { 
                                /* just draw curve based on defined data (i.e. no modifiers) */
                                if (fcu->bezt)
-                                       draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, grid);
+                                       draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d);
                                else if (fcu->fpt)
                                        draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d);
                        }
                        
                        /* restore settings */
                        setlinestyle(0);
                                else if (fcu->fpt)
                                        draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d);
                        }
                        
                        /* restore settings */
                        setlinestyle(0);
+                       glLineWidth(1.0);
                        
                        
-                       glDisable(GL_LINE_SMOOTH);
+                       if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
                        glDisable(GL_BLEND);
                }
                
                        glDisable(GL_BLEND);
                }
                
@@ -906,12 +898,12 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
                 *      - if the option to only show controls if the F-Curve is selected is enabled, we must obey this
                 */
                if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) {
                 *      - if the option to only show controls if the F-Curve is selected is enabled, we must obey this
                 */
                if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) {
-                       if (fcurve_needs_draw_fmodifier_controls(fcu, fcm)) {
+                       if (fcurve_are_keyframes_usable(fcu) == 0) {
                                /* only draw controls if this is the active modifier */
                                if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) {
                                        switch (fcm->type) {
                                                case FMODIFIER_TYPE_ENVELOPE: /* envelope */
                                /* only draw controls if this is the active modifier */
                                if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) {
                                        switch (fcm->type) {
                                                case FMODIFIER_TYPE_ENVELOPE: /* envelope */
-                                                       draw_fcurve_modifier_controls_envelope(fcu, fcm, &ar->v2d);
+                                                       draw_fcurve_modifier_controls_envelope(fcm, &ar->v2d);
                                                        break;
                                        }
                                }
                                                        break;
                                        }
                                }
@@ -926,15 +918,15 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
                                        if (do_handles) {
                                                /* only draw handles/vertices on keyframes */
                                                glEnable(GL_BLEND);
                                        if (do_handles) {
                                                /* only draw handles/vertices on keyframes */
                                                glEnable(GL_BLEND);
-                                               draw_fcurve_handles(ac, sipo, ar, fcu);
+                                               draw_fcurve_handles(sipo, fcu);
                                                glDisable(GL_BLEND);
                                        }
                                        
                                                glDisable(GL_BLEND);
                                        }
                                        
-                                       draw_fcurve_vertices(ac, sipo, ar, fcu, do_handles);
+                                       draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY));
                                }
                                else {
                                        /* samples: only draw two indicators at either end as indicators */
                                }
                                else {
                                        /* samples: only draw two indicators at either end as indicators */
-                                       draw_fcurve_samples(ac, sipo, ar, fcu);
+                                       draw_fcurve_samples(sipo, ar, fcu);
                                }
                                
                                /* unapply unit mapping */
                                }
                                
                                /* unapply unit mapping */
@@ -955,7 +947,7 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
 /* Channel List */
 
 /* left hand part */
 /* Channel List */
 
 /* left hand part */
-void graph_draw_channel_names(bContext *C, bAnimContext *ac, SpaceIpo *sipo, ARegion *ar) 
+void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) 
 {
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
 {
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
@@ -963,10 +955,11 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, SpaceIpo *sipo, ARe
        
        View2D *v2d= &ar->v2d;
        float y= 0.0f, height;
        
        View2D *v2d= &ar->v2d;
        float y= 0.0f, height;
-       int items, i=0;
+       size_t items;
+       int i=0;
        
        /* build list of channels to draw */
        
        /* build list of channels to draw */
-       filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CHANNELS);
+       filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
        items= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
        /* Update max-extent of channels here (taking into account scrollers):
        items= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
        /* Update max-extent of channels here (taking into account scrollers):
@@ -999,7 +992,8 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, SpaceIpo *sipo, ARe
                }
        }
        {       /* second pass: widgets */
                }
        }
        {       /* second pass: widgets */
-               uiBlock *block= uiBeginBlock(C, ar, "graph channel buttons", UI_EMBOSS);
+               uiBlock *block= uiBeginBlock(C, ar, __func__, UI_EMBOSS);
+               size_t channel_index = 0;
                
                y= (float)ACHANNEL_FIRST;
                
                
                y= (float)ACHANNEL_FIRST;
                
@@ -1016,11 +1010,12 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, SpaceIpo *sipo, ARe
                                 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) 
                        {
                                /* draw all channels using standard channel-drawing API */
                                 IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) 
                        {
                                /* draw all channels using standard channel-drawing API */
-                               ANIM_channel_draw_widgets(ac, ale, block, yminc, ymaxc);
+                               ANIM_channel_draw_widgets(C, ac, ale, block, yminc, ymaxc, channel_index);
                        }
                        
                        /* adjust y-position for next one */
                        y -= ACHANNEL_STEP;
                        }
                        
                        /* adjust y-position for next one */
                        y -= ACHANNEL_STEP;
+                       channel_index++;
                }
                
                uiEndBlock(C, block);
                }
                
                uiEndBlock(C, block);