code cleanup: use uppercase defines and change drawFCurveFade into static function.
[blender.git] / source / blender / editors / space_graph / graph_draw.c
index d3b9c68a492a011fae5ed1d279780522fc152047..25998e7bce21a0189871d8142e523c55e3c73b18 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -50,6 +48,7 @@
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BKE_context.h"
 #include "BKE_curve.h"
  * 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 color 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 */
@@ -155,7 +146,7 @@ static void draw_fcurve_vertices_keyframes (FCurve *fcu, SpaceIpo *UNUSED(sipo),
        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)) {
@@ -187,7 +178,7 @@ static void draw_fcurve_handle_control (float x, float y, float xscale, float ys
 {
        static GLuint displist=0;
        
-       /* initialise round circle shape */
+       /* initialize round circle shape */
        if (displist == 0) {
                GLUquadricObj *qobj;
                
@@ -264,7 +255,7 @@ static void draw_fcurve_vertices_handles (FCurve *fcu, SpaceIpo *sipo, View2D *v
 static void set_fcurve_vertex_color (FCurve *fcu, short sel)
 {
        /* 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) {
@@ -294,8 +285,7 @@ static void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu, shor
        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)
-       {
+       if (do_handles) {
                set_fcurve_vertex_color(fcu, 0);
                draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only);
                
@@ -320,15 +310,16 @@ 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 */
+#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 */
+#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;
        } 
-       else 
-       {
+       else {
                return 1;
        }
 }
@@ -340,7 +331,7 @@ 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
-        * 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);
@@ -354,10 +345,6 @@ static void draw_fcurve_handles (SpaceIpo *sipo, FCurve *fcu)
                float *fp;
                unsigned char col[4];
                
-               /* if only selected keyframes have handles shown, skip the first round */
-               if ((sel == 0) && (sipo->flag & SIPO_SELVHANDLESONLY))
-                       continue;
-               
                for (b= 0; b < fcu->totvert; b++, prevbezt=bezt, bezt++) {
                        /* if only selected keyframes can get their handles shown, 
                         * check that keyframe is selected
@@ -370,24 +357,22 @@ static void draw_fcurve_handles (SpaceIpo *sipo, FCurve *fcu)
                        /* 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 */
-                               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);
-                                       col[3]= drawFCurveFade(fcu) * 255;
+                                       col[3]= fcurve_display_alpha(fcu) * 255;
                                        glColor4ubv((GLubyte *)col);
                                        
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
-
+                               
                                /* 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);
-                                       col[3]= drawFCurveFade(fcu) * 255;
+                                       col[3]= fcurve_display_alpha(fcu) * 255;
                                        glColor4ubv((GLubyte *)col);
-
+                                       
                                        glVertex2fv(fp+3); glVertex2fv(fp+6); 
                                }
                        }
@@ -398,9 +383,9 @@ static void draw_fcurve_handles (SpaceIpo *sipo, FCurve *fcu)
                                {
                                        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);
-
+                                       
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
                                }
                                
@@ -410,7 +395,7 @@ static void draw_fcurve_handles (SpaceIpo *sipo, FCurve *fcu)
                                {
                                        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);
                                        
                                        glVertex2fv(fp); glVertex2fv(fp+3); 
@@ -432,7 +417,7 @@ static void draw_fcurve_sample_control (float x, float y, float xscale, float ys
 {
        static GLuint displist=0;
        
-       /* initialise X shape */
+       /* initialize X shape */
        if (displist == 0) {
                displist= glGenLists(1);
                glNewList(displist, GL_COMPILE);
@@ -506,7 +491,7 @@ static void draw_fcurve_curve (bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2
        /* 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;
 
 
@@ -682,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) */
+       // 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 */
@@ -704,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 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 
-                               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 */
@@ -719,6 +705,7 @@ static void draw_fcurve_curve_bezts (bAnimContext *ac, ID *id, FCurve *fcu, View
                        }
                        else {
                                /* clamp resolution to max of 32 */
+                               // NOTE: higher values will crash
                                if (resol > 32) resol= 32;
                                
                                v1[0]= prevbezt->vec[1][0];
@@ -832,7 +819,7 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
        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);
                
@@ -852,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
-                *      - 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!)
                 */
                 
@@ -872,7 +859,12 @@ 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
                                 */
-                               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 */
@@ -896,6 +888,7 @@ void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGri
                        
                        /* restore settings */
                        setlinestyle(0);
+                       glLineWidth(1.0);
                        
                        if ((sipo->flag & SIPO_BEAUTYDRAW_OFF)==0) glDisable(GL_LINE_SMOOTH);
                        glDisable(GL_BLEND);
@@ -962,10 +955,11 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
        
        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 */
-       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):
@@ -998,7 +992,8 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
                }
        }
        {       /* 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;
                
@@ -1015,11 +1010,12 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
                                 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;
+                       channel_index++;
                }
                
                uiEndBlock(C, block);