F-Curve Modifiers: Basic GUI for Generator Modifier working
[blender.git] / source / blender / editors / space_graph / graph_draw.c
1 /**
2  * $Id: drawipo.c 17512 2008-11-20 05:55:42Z aligorith $
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) Blender Foundation
21  *
22  * Contributor(s): Joshua Leung (2009 Recode)
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 #include <stdio.h>
28 #include <math.h>
29 #include <string.h>
30 #include <float.h>
31
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35
36 #ifndef _WIN32
37 #include <unistd.h>
38 #else
39 #include <io.h>
40 #endif
41
42 #include "MEM_guardedalloc.h"
43
44 #include "BLI_blenlib.h"
45 #include "BLI_arithb.h"
46
47 #include "DNA_anim_types.h"
48 #include "DNA_action_types.h"
49 #include "DNA_camera_types.h"
50 #include "DNA_curve_types.h"
51 #include "DNA_key_types.h"
52 #include "DNA_lamp_types.h"
53 #include "DNA_material_types.h"
54 #include "DNA_object_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_screen_types.h"
57 #include "DNA_space_types.h"
58 #include "DNA_sequence_types.h"
59 #include "DNA_userdef_types.h"
60 #include "DNA_view2d_types.h"
61 #include "DNA_windowmanager_types.h"
62 #include "DNA_world_types.h"
63
64 #include "BKE_animsys.h"
65 #include "BKE_context.h"
66 #include "BKE_curve.h"
67 #include "BKE_depsgraph.h"
68 #include "BKE_fcurve.h"
69 #include "BKE_global.h"
70 #include "BKE_key.h"
71 #include "BKE_object.h"
72 #include "BKE_screen.h"
73 #include "BKE_utildefines.h"
74
75 #include "BIF_gl.h"
76 #include "BIF_glutil.h"
77
78 #include "ED_anim_api.h"
79 #include "ED_util.h"
80
81 #include "graph_intern.h"
82
83 #include "UI_interface.h"
84 #include "UI_interface_icons.h"
85 #include "UI_resources.h"
86 #include "UI_view2d.h"
87 #include "UI_text.h"
88
89 /* XXX */
90 extern void ui_rasterpos_safe(float x, float y, float aspect);
91 extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad);
92
93 /* *************************** */
94 /* Curve Drawing */
95
96 /* Points ---------------- */
97
98 /* helper func - draw keyframe vertices only for an F-Curve */
99 static void draw_fcurve_vertices_keyframes (FCurve *fcu, View2D *v2d, short edit, short sel)
100 {
101         BezTriple *bezt= fcu->bezt;
102         const float fac= 0.05f * (v2d->cur.xmax - v2d->cur.xmin);
103         int i;
104         
105         /* we use bgl points not standard gl points, to workaround vertex 
106          * drawing bugs that some drivers have (probably legacy ones only though)
107          */
108         bglBegin(GL_POINTS);
109         
110         for (i = 0; i < fcu->totvert; i++, bezt++) {
111                 /* as an optimisation step, only draw those in view 
112                  *      - we apply a correction factor to ensure that points don't pop in/out due to slight twitches of view size
113                  */
114                 if IN_RANGE(bezt->vec[1][0], (v2d->cur.xmin - fac), (v2d->cur.xmax + fac)) {
115                         if (edit) {
116                                 /* 'Keyframe' vertex only, as handle lines and handles have already been drawn
117                                  *      - only draw those with correct selection state for the current drawing color
118                                  *      - 
119                                  */
120                                 if ((bezt->f2 & SELECT) == sel)
121                                         bglVertex3fv(bezt->vec[1]);
122                         }
123                         else {
124                                 /* no check for selection here, as curve is not editable... */
125                                 // XXX perhaps we don't want to even draw points?   maybe add an option for that later
126                                 bglVertex3fv(bezt->vec[1]);
127                         }
128                 }
129         }
130         
131         bglEnd();
132 }
133
134
135 /* helper func - draw handle vertex for an F-Curve as a round unfilled circle */
136 static void draw_fcurve_handle_control (float x, float y, float xscale, float yscale, float hsize)
137 {
138         static GLuint displist=0;
139         
140         /* initialise round circle shape */
141         if (displist == 0) {
142                 GLUquadricObj *qobj;
143                 
144                 displist= glGenLists(1);
145                 glNewList(displist, GL_COMPILE);
146                 
147                 qobj    = gluNewQuadric(); 
148                 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
149                 gluDisk(qobj, 0,  0.7, 8, 1);
150                 gluDeleteQuadric(qobj);  
151                 
152                 glEndList();
153         }
154         
155         /* adjust view transform before starting */
156         glTranslatef(x, y, 0.0f);
157         glScalef(1.0f/xscale*hsize, 1.0f/yscale*hsize, 1.0f);
158         
159         /* anti-aliased lines for more consistent appearance */
160         glEnable(GL_LINE_SMOOTH);
161         glEnable(GL_BLEND);
162         
163         /* draw! */
164         glCallList(displist);
165         
166         glDisable(GL_LINE_SMOOTH);
167         glDisable(GL_BLEND);
168         
169         /* restore view transform */
170         glScalef(xscale/hsize, yscale/hsize, 1.0);
171         glTranslatef(-x, -y, 0.0f);
172 }
173
174 /* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
175 static void draw_fcurve_vertices_handles (FCurve *fcu, View2D *v2d, short sel)
176 {
177         BezTriple *bezt= fcu->bezt;
178         BezTriple *prevbezt = NULL;
179         float hsize, xscale, yscale;
180         int i;
181         
182         /* get view settings */
183         hsize= UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE);
184         UI_view2d_getscale(v2d, &xscale, &yscale);
185         
186         /* set handle color */
187         if (sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
188         else UI_ThemeColor(TH_HANDLE_VERTEX);
189         
190         for (i=0; i < fcu->totvert; i++, prevbezt=bezt, bezt++) {
191                 /* Draw the editmode handels for a bezier curve (others don't have handles) 
192                  * if their selection status matches the selection status we're drawing for
193                  *      - first handle only if previous beztriple was bezier-mode
194                  *      - second handle only if current beztriple is bezier-mode
195                  */
196                 if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) {
197                         if ((bezt->f1 & SELECT) == sel)/* && v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/
198                                 draw_fcurve_handle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize);
199                 }
200                 
201                 if (bezt->ipo==BEZT_IPO_BEZ) {
202                         if ((bezt->f3 & SELECT) == sel)/* && v2d->cur.xmin < bezt->vec[2][0] < v2d->cur.xmax)*/
203                                 draw_fcurve_handle_control(bezt->vec[2][0], bezt->vec[2][1], xscale, yscale, hsize);
204                 }
205         }
206 }
207
208 /* helper func - set color to draw F-Curve data with */
209 static void set_fcurve_vertex_color (SpaceIpo *sipo, FCurve *fcu, short sel)
210 {
211 #if 0
212                 if (sipo->showkey) {
213                         if (sel) UI_ThemeColor(TH_TEXT_HI);
214                         else UI_ThemeColor(TH_TEXT);
215                 } 
216 #endif
217                 if ((fcu->flag & FCURVE_PROTECTED)==0) {
218                         /* Curve's points are being edited */
219                         if (sel) UI_ThemeColor(TH_VERTEX_SELECT); 
220                         else UI_ThemeColor(TH_VERTEX);
221                 } 
222                 else {
223                         /* Curve's points cannot be edited */
224                         if (sel) UI_ThemeColor(TH_TEXT_HI);
225                         else UI_ThemeColor(TH_TEXT);
226                 }
227 }
228
229
230 void draw_fcurve_vertices (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
231 {
232         View2D *v2d= &ar->v2d;
233         
234         /* only draw points if curve is visible 
235          *      - draw unselected points before selected points as separate passes to minimise color-changing overhead
236          *         (XXX dunno if this is faster than drawing all in one pass though) 
237          *         and also to make sure in the case of overlapping points that the selected is always visible
238          *      - draw handles before keyframes, so that keyframes will overlap handles (keyframes are more important for users)
239          */
240         
241         glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
242         
243         /* draw the two handles first (if they're shown, and if curve is being edited) */
244         if ((fcu->flag & FCURVE_PROTECTED)==0 && (fcu->flag & FCURVE_INT_VALUES)==0 && (sipo->flag & SIPO_NOHANDLES)==0) {
245                 set_fcurve_vertex_color(sipo, fcu, 0);
246                 draw_fcurve_vertices_handles(fcu, v2d, 0);
247                 
248                 set_fcurve_vertex_color(sipo, fcu, 1);
249                 draw_fcurve_vertices_handles(fcu, v2d, 1);
250         }
251                 
252         /* draw keyframes over the handles */
253         set_fcurve_vertex_color(sipo, fcu, 0);
254         draw_fcurve_vertices_keyframes(fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
255         
256         set_fcurve_vertex_color(sipo, fcu, 1);
257         draw_fcurve_vertices_keyframes(fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
258         
259         glPointSize(1.0f);
260 }
261
262 /* Handles ---------------- */
263
264 /* draw lines for F-Curve handles only (this is only done in EditMode) */
265 static void draw_fcurve_handles (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
266 {
267         extern unsigned int nurbcol[];
268         unsigned int *col;
269         int sel, b;
270         
271         /* don't draw handle lines if handles are not shown */
272         if ((sipo->flag & SIPO_NOHANDLES) || (fcu->flag & FCURVE_PROTECTED) || (fcu->flag & FCURVE_INT_VALUES))
273                 return;
274         
275         /* slightly hacky, but we want to draw unselected points before selected ones*/
276         for (sel= 0; sel < 2; sel++) {
277                 BezTriple *bezt=fcu->bezt, *prevbezt=NULL;
278                 float *fp;
279                 
280                 if (sel) col= nurbcol+4;
281                 else col= nurbcol;
282                         
283                 for (b= 0; b < fcu->totvert; b++, prevbezt=bezt, bezt++) {
284                         if ((bezt->f2 & SELECT)==sel) {
285                                 fp= bezt->vec[0];
286                                 
287                                 /* only draw first handle if previous segment had handles */
288                                 if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) 
289                                 {
290                                         cpack(col[(unsigned char)bezt->h1]);
291                                         glBegin(GL_LINE_STRIP); 
292                                                 glVertex2fv(fp); glVertex2fv(fp+3); 
293                                         glEnd();
294                                         
295                                 }
296                                 
297                                 /* only draw second handle if this segment is bezier */
298                                 if (bezt->ipo == BEZT_IPO_BEZ) 
299                                 {
300                                         cpack(col[(unsigned char)bezt->h2]);
301                                         glBegin(GL_LINE_STRIP); 
302                                                 glVertex2fv(fp+3); glVertex2fv(fp+6); 
303                                         glEnd();
304                                 }
305                         }
306                         else {
307                                 /* only draw first handle if previous segment was had handles, and selection is ok */
308                                 if ( ((bezt->f1 & SELECT)==sel) && 
309                                          ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) ) 
310                                 {
311                                         fp= bezt->vec[0];
312                                         cpack(col[(unsigned char)bezt->h1]);
313                                         
314                                         glBegin(GL_LINE_STRIP); 
315                                                 glVertex2fv(fp); glVertex2fv(fp+3); 
316                                         glEnd();
317                                 }
318                                 
319                                 /* only draw second handle if this segment is bezier, and selection is ok */
320                                 if ( ((bezt->f3 & SELECT)==sel) &&
321                                          (bezt->ipo == BEZT_IPO_BEZ) )
322                                 {
323                                         fp= bezt->vec[1];
324                                         cpack(col[(unsigned char)bezt->h2]);
325                                         
326                                         glBegin(GL_LINE_STRIP); 
327                                                 glVertex2fv(fp); glVertex2fv(fp+3); 
328                                         glEnd();
329                                 }
330                         }
331                 }
332         }
333 }
334
335 /* Samples ---------------- */
336
337 /* helper func - draw sample-range marker for an F-Curve as a cross */
338 static void draw_fcurve_sample_control (float x, float y, float xscale, float yscale, float hsize)
339 {
340         static GLuint displist=0;
341         
342         /* initialise X shape */
343         if (displist == 0) {
344                 displist= glGenLists(1);
345                 glNewList(displist, GL_COMPILE);
346                 
347                 glBegin(GL_LINES);
348                         glVertex2f(-0.7f, -0.7f);
349                         glVertex2f(+0.7f, +0.7f);
350                         
351                         glVertex2f(-0.7f, +0.7f);
352                         glVertex2f(+0.7f, -0.7f);
353                 glEnd(); // GL_LINES
354                 
355                 glEndList();
356         }
357         
358         /* adjust view transform before starting */
359         glTranslatef(x, y, 0.0f);
360         glScalef(1.0f/xscale*hsize, 1.0f/yscale*hsize, 1.0f);
361         
362         /* anti-aliased lines for more consistent appearance */
363                 // XXX needed here?
364         glEnable(GL_LINE_SMOOTH);
365         glEnable(GL_BLEND);
366         
367         /* draw! */
368         glCallList(displist);
369         
370         glDisable(GL_BLEND);
371         glDisable(GL_LINE_SMOOTH);
372         
373         /* restore view transform */
374         glScalef(xscale/hsize, yscale/hsize, 1.0);
375         glTranslatef(-x, -y, 0.0f);
376 }
377
378 /* helper func - draw keyframe vertices only for an F-Curve */
379 static void draw_fcurve_samples (SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
380 {
381         FPoint *first, *last;
382         float hsize, xscale, yscale;
383         
384         /* get view settings */
385         hsize= UI_GetThemeValuef(TH_VERTEX_SIZE);
386         UI_view2d_getscale(&ar->v2d, &xscale, &yscale);
387         
388         /* set vertex color */
389         if (fcu->flag & (FCURVE_ACTIVE|FCURVE_SELECTED)) UI_ThemeColor(TH_TEXT_HI);
390         else UI_ThemeColor(TH_TEXT);
391         
392         /* get verts */
393         first= fcu->fpt;
394         last= (first) ? (first + (fcu->totvert-1)) : (NULL);
395         
396         /* draw */
397         if (first && last) {
398                 draw_fcurve_sample_control(first->vec[0], first->vec[1], xscale, yscale, hsize);
399                 draw_fcurve_sample_control(last->vec[0], last->vec[1], xscale, yscale, hsize);
400         }
401 }
402
403 /* Curve ---------------- */
404
405 /* minimum pixels per gridstep 
406  * XXX: defined in view2d.c - must keep these in sync or relocate to View2D header!
407  */
408 #define MINGRIDSTEP     35
409
410 /* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
411 static void draw_fcurve_curve (FCurve *fcu, SpaceIpo *sipo, View2D *v2d, View2DGrid *grid)
412 {
413         ChannelDriver *driver;
414         float samplefreq, ctime;
415         float stime, etime;
416         
417         /* disable any drivers temporarily */
418         driver= fcu->driver;
419         fcu->driver= NULL;
420         
421         
422         /* Note about sampling frequency:
423          *      Ideally, this is chosen such that we have 1-2 pixels = 1 segment
424          *      which means that our curves can be as smooth as possible. However,
425          *      this does mean that curves may not be fully accurate (i.e. if they have
426          *      sudden spikes which happen at the sampling point, we may have problems).
427          *      Also, this may introduce lower performance on less densely detailed curves,'
428          *      though it is impossible to predict this from the modifiers!
429          *
430          *      If the automatically determined sampling frequency is likely to cause an infinite
431          *      loop (i.e. too close to FLT_EPSILON), fall back to default of 0.001
432          */
433                 /* grid->dx is the first float in View2DGrid struct, so just cast to float pointer, and use it
434                  * It represents the number of 'frames' between gridlines, but we divide by MINGRIDSTEP to get pixels-steps
435                  */
436                 // TODO: perhaps we should have 1.0 frames as upper limit so that curves don't get too distorted?
437         samplefreq= *((float *)grid) / MINGRIDSTEP;
438         if (IS_EQ(samplefreq, 0)) samplefreq= 0.001f;
439         
440         
441         /* the start/end times are simply the horizontal extents of the 'cur' rect */
442         stime= v2d->cur.xmin;
443         etime= v2d->cur.xmax;
444         
445         
446         /* at each sampling interval, add a new vertex */
447         glBegin(GL_LINE_STRIP);
448         
449         for (ctime= stime; ctime <= etime; ctime += samplefreq)
450                 glVertex2f( ctime, evaluate_fcurve(fcu, ctime) );
451         
452         glEnd();
453         
454         /* restore driver */
455         fcu->driver= driver;
456 }
457
458 /* helper func - draw a samples-based F-Curve */
459 // TODO: add offset stuff...
460 static void draw_fcurve_curve_samples (FCurve *fcu, View2D *v2d)
461 {
462         FPoint *prevfpt= fcu->fpt;
463         FPoint *fpt= prevfpt + 1;
464         float fac, v[2];
465         int b= fcu->totvert-1;
466         
467         glBegin(GL_LINE_STRIP);
468         
469         /* extrapolate to left? - left-side of view comes before first keyframe? */
470         if (prevfpt->vec[0] > v2d->cur.xmin) {
471                 v[0]= v2d->cur.xmin;
472                 
473                 /* y-value depends on the interpolation */
474                 if ((fcu->extend==FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (fcu->totvert==1)) {
475                         /* just extend across the first keyframe's value */
476                         v[1]= prevfpt->vec[1];
477                 } 
478                 else {
479                         /* extrapolate linear dosnt use the handle, use the next points center instead */
480                         fac= (prevfpt->vec[0]-fpt->vec[0])/(prevfpt->vec[0]-v[0]);
481                         if (fac) fac= 1.0f/fac;
482                         v[1]= prevfpt->vec[1]-fac*(prevfpt->vec[1]-fpt->vec[1]);
483                 }
484                 
485                 glVertex2fv(v);
486         }
487         
488         /* if only one sample, add it now */
489         if (fcu->totvert == 1)
490                 glVertex2fv(prevfpt->vec);
491         
492         /* loop over samples, drawing segments */
493         /* draw curve between first and last keyframe (if there are enough to do so) */
494         while (b--) {
495                 /* Linear interpolation: just add one point (which should add a new line segment) */
496                 glVertex2fv(prevfpt->vec);
497                 
498                 /* get next pointers */
499                 prevfpt= fpt; 
500                 fpt++;
501                 
502                 /* last point? */
503                 if (b == 0)
504                         glVertex2fv(prevfpt->vec);
505         }
506         
507         /* extrapolate to right? (see code for left-extrapolation above too) */
508         if (prevfpt->vec[0] < v2d->cur.xmax) {
509                 v[0]= v2d->cur.xmax;
510                 
511                 /* y-value depends on the interpolation */
512                 if ((fcu->extend==FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (fcu->totvert==1)) {
513                         /* based on last keyframe's value */
514                         v[1]= prevfpt->vec[1];
515                 } 
516                 else {
517                         /* extrapolate linear dosnt use the handle, use the previous points center instead */
518                         fpt = prevfpt-1;
519                         fac= (prevfpt->vec[0]-fpt->vec[0])/(prevfpt->vec[0]-v[0]);
520                         if (fac) fac= 1.0f/fac;
521                         v[1]= prevfpt->vec[1]-fac*(prevfpt->vec[1]-fpt->vec[1]);
522                 }
523                 
524                 glVertex2fv(v);
525         }
526         
527         glEnd();
528 }
529
530 /* helper func - draw one repeat of an F-Curve */
531 static void draw_fcurve_curve_bezts (FCurve *fcu, View2D *v2d, View2DGrid *grid)
532 {
533         BezTriple *prevbezt= fcu->bezt;
534         BezTriple *bezt= prevbezt+1;
535         float v1[2], v2[2], v3[2], v4[2];
536         float *fp, data[120];
537         float fac= 0.0f;
538         int b= fcu->totvert-1;
539         int resol;
540         
541         glBegin(GL_LINE_STRIP);
542         
543         /* extrapolate to left? */
544         if (prevbezt->vec[1][0] > v2d->cur.xmin) {
545                 /* left-side of view comes before first keyframe, so need to extend as not cyclic */
546                 v1[0]= v2d->cur.xmin;
547                 
548                 /* y-value depends on the interpolation */
549                 if ((fcu->extend==FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (prevbezt->ipo==BEZT_IPO_CONST) || (fcu->totvert==1)) {
550                         /* just extend across the first keyframe's value */
551                         v1[1]= prevbezt->vec[1][1];
552                 } 
553                 else if (prevbezt->ipo==BEZT_IPO_LIN) {
554                         /* extrapolate linear dosnt use the handle, use the next points center instead */
555                         fac= (prevbezt->vec[1][0]-bezt->vec[1][0])/(prevbezt->vec[1][0]-v1[0]);
556                         if (fac) fac= 1.0f/fac;
557                         v1[1]= prevbezt->vec[1][1]-fac*(prevbezt->vec[1][1]-bezt->vec[1][1]);
558                 } 
559                 else {
560                         /* based on angle of handle 1 (relative to keyframe) */
561                         fac= (prevbezt->vec[0][0]-prevbezt->vec[1][0])/(prevbezt->vec[1][0]-v1[0]);
562                         if (fac) fac= 1.0f/fac;
563                         v1[1]= prevbezt->vec[1][1]-fac*(prevbezt->vec[0][1]-prevbezt->vec[1][1]);
564                 }
565                 
566                 glVertex2fv(v1);
567         }
568         
569         /* if only one keyframe, add it now */
570         if (fcu->totvert == 1) {
571                 v1[0]= prevbezt->vec[1][0];
572                 v1[1]= prevbezt->vec[1][1];
573                 glVertex2fv(v1);
574         }
575         
576         /* draw curve between first and last keyframe (if there are enough to do so) */
577         while (b--) {
578                 if ((fcu->flag & FCURVE_INT_VALUES) || (prevbezt->ipo==BEZT_IPO_CONST)) {
579                         /* Constant-Interpolation: draw segment between previous keyframe and next, but holding same value */
580                         v1[0]= prevbezt->vec[1][0];
581                         v1[1]= prevbezt->vec[1][1];
582                         glVertex2fv(v1);
583                         
584                         v1[0]= bezt->vec[1][0];
585                         v1[1]= prevbezt->vec[1][1];
586                         glVertex2fv(v1);
587                 }
588                 else if (prevbezt->ipo==BEZT_IPO_LIN) {
589                         /* Linear interpolation: just add one point (which should add a new line segment) */
590                         v1[0]= prevbezt->vec[1][0];
591                         v1[1]= prevbezt->vec[1][1];
592                         glVertex2fv(v1);
593                 }
594                 else {
595                         /* Bezier-Interpolation: draw curve as series of segments between keyframes 
596                          *      - resol determines number of points to sample in between keyframes
597                          */
598                         
599                         /* resol not depending on horizontal resolution anymore, drivers for example... */
600                         // XXX need to take into account the scale
601                         if (fcu->driver) 
602                                 resol= 32;
603                         else 
604                                 resol= (int)(3.0*sqrt(bezt->vec[1][0] - prevbezt->vec[1][0]));
605                         
606                         if (resol < 2) {
607                                 /* only draw one */
608                                 v1[0]= prevbezt->vec[1][0];
609                                 v1[1]= prevbezt->vec[1][1];
610                                 glVertex2fv(v1);
611                         }
612                         else {
613                                 /* clamp resolution to max of 32 */
614                                 if (resol > 32) resol= 32;
615                                 
616                                 v1[0]= prevbezt->vec[1][0];
617                                 v1[1]= prevbezt->vec[1][1];
618                                 v2[0]= prevbezt->vec[2][0];
619                                 v2[1]= prevbezt->vec[2][1];
620                                 
621                                 v3[0]= bezt->vec[0][0];
622                                 v3[1]= bezt->vec[0][1];
623                                 v4[0]= bezt->vec[1][0];
624                                 v4[1]= bezt->vec[1][1];
625                                 
626                                 correct_bezpart(v1, v2, v3, v4);
627                                 
628                                 forward_diff_bezier(v1[0], v2[0], v3[0], v4[0], data, resol, 3);
629                                 forward_diff_bezier(v1[1], v2[1], v3[1], v4[1], data+1, resol, 3);
630                                 
631                                 for (fp= data; resol; resol--, fp+= 3)
632                                         glVertex2fv(fp);
633                         }
634                 }
635                 
636                 /* get next pointers */
637                 prevbezt= bezt; 
638                 bezt++;
639                 
640                 /* last point? */
641                 if (b == 0) {
642                         v1[0]= prevbezt->vec[1][0];
643                         v1[1]= prevbezt->vec[1][1];
644                         glVertex2fv(v1);
645                 }
646         }
647         
648         /* extrapolate to right? (see code for left-extrapolation above too) */
649         if (prevbezt->vec[1][0] < v2d->cur.xmax) {
650                 v1[0]= v2d->cur.xmax;
651                 
652                 /* y-value depends on the interpolation */
653                 if ((fcu->extend==FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (prevbezt->ipo==BEZT_IPO_CONST) || (fcu->totvert==1)) {
654                         /* based on last keyframe's value */
655                         v1[1]= prevbezt->vec[1][1];
656                 } 
657                 else if (prevbezt->ipo==BEZT_IPO_LIN) {
658                         /* extrapolate linear dosnt use the handle, use the previous points center instead */
659                         bezt = prevbezt-1;
660                         fac= (prevbezt->vec[1][0]-bezt->vec[1][0])/(prevbezt->vec[1][0]-v1[0]);
661                         if (fac) fac= 1.0f/fac;
662                         v1[1]= prevbezt->vec[1][1]-fac*(prevbezt->vec[1][1]-bezt->vec[1][1]);
663                 } 
664                 else {
665                         /* based on angle of handle 1 (relative to keyframe) */
666                         fac= (prevbezt->vec[2][0]-prevbezt->vec[1][0])/(prevbezt->vec[1][0]-v1[0]);
667                         if (fac) fac= 1.0f/fac;
668                         v1[1]= prevbezt->vec[1][1]-fac*(prevbezt->vec[2][1]-prevbezt->vec[1][1]);
669                 }
670                 
671                 glVertex2fv(v1);
672         }
673         
674         glEnd();
675
676
677 #if 0
678 static void draw_ipokey(SpaceIpo *sipo, ARegion *ar)
679 {
680         View2D *v2d= &ar->v2d;
681         IpoKey *ik;
682         
683         glBegin(GL_LINES);
684         for (ik= sipo->ipokey.first; ik; ik= ik->next) {
685                 if (ik->flag & SELECT) glColor3ub(0xFF, 0xFF, 0x99);
686                 else glColor3ub(0xAA, 0xAA, 0x55);
687                 
688                 glVertex2f(ik->val, v2d->cur.ymin);
689                 glVertex2f(ik->val, v2d->cur.ymax);
690         }
691         glEnd();
692 }
693 #endif
694
695 /* Public Curve-Drawing API  ---------------- */
696
697 void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid)
698 {
699         ListBase anim_data = {NULL, NULL};
700         bAnimListElem *ale;
701         int filter;
702         
703         /* build list of curves to draw */
704         filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CURVESONLY|ANIMFILTER_CURVEVISIBLE);
705         ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
706                 
707         /* for each curve:
708          *      draw curve, then handle-lines, and finally vertices in this order so that 
709          *      the data will be layered correctly
710          */
711         for (ale=anim_data.first; ale; ale=ale->next) {
712                 FCurve *fcu= (FCurve *)ale->key_data;
713                 FModifier *fcm= fcurve_active_modifier(fcu);
714                 //Object *nob= ANIM_nla_mapping_get(ac, ale);
715                 
716                 /* map keyframes for drawing if scaled F-Curve */
717                 //if (nob)
718                 //      ANIM_nla_mapping_apply_fcurve(nob, ale->key_data, 0, 0); 
719                 
720                 /* draw curve:
721                  *      - curve line may be result of one or more destructive modifiers or just the raw data,
722                  *        so we need to check which method should be used
723                  *      - controls from active modifier take precidence over keyframes
724                  *        (XXX! editing tools need to take this into account!)
725                  */
726                  
727                 /* 1) draw curve line */
728                 {
729                         /* set color/drawing style for curve itself */
730                         if ( ((fcu->grp) && (fcu->grp->flag & AGRP_PROTECTED)) || (fcu->flag & FCURVE_PROTECTED) ) {
731                                 /* protected curves (non editable) are drawn with dotted lines */
732                                 setlinestyle(2);
733                         }
734                         if (fcu->flag & FCURVE_MUTED) {
735                                 /* muted curves are drawn in a greyish hue */
736                                 // XXX should we have some variations?
737                                 UI_ThemeColorShade(TH_HEADER, 50);
738                         }
739                         else {
740                                 /* set whatever color the curve has set */
741                                 glColor3fv(fcu->color);
742                         }
743                         
744                         /* anti-aliased lines for less jagged appearance */
745                         glEnable(GL_LINE_SMOOTH);
746                         glEnable(GL_BLEND);
747                         
748                         /* draw F-Curve */
749                         if (fcu->modifiers.first) {
750                                 /* draw a curve affected by modifiers by sampling its points  */
751                                 draw_fcurve_curve(fcu, sipo, &ar->v2d, grid);
752                         }
753                         else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { 
754                                 /* just draw curve based on defined data (i.e. no modifiers) */
755                                 if (fcu->bezt)
756                                         draw_fcurve_curve_bezts(fcu, &ar->v2d, grid);
757                                 else if (fcu->fpt)
758                                         draw_fcurve_curve_samples(fcu, &ar->v2d);
759                         }
760                         
761                         /* restore settings */
762                         setlinestyle(0);
763                         
764                         glDisable(GL_LINE_SMOOTH);
765                         glDisable(GL_BLEND);
766                 }
767                 
768                 /* 2) draw handles and vertices as appropriate based on active */
769                 if ( ((fcm) && (fcm->type != FMODIFIER_TYPE_CYCLES)) || (fcu->modifiers.first) ) {
770                         // TODO: need to add code to show these... for cycles modifier, should fall through though...
771                 }
772                 else if ( ((fcu->bezt) || (fcu->fpt)) && (fcu->totvert) ) { 
773                         if (fcu->bezt) {
774                                 /* only draw handles/vertices on keyframes */
775                                 draw_fcurve_handles(sipo, ar, fcu);
776                                 draw_fcurve_vertices(sipo, ar, fcu);
777                         }
778                         else {
779                                 /* samples: should we only draw two indicators at either end as indicators? */
780                                 draw_fcurve_samples(sipo, ar, fcu);
781                         }
782                 }
783                 
784                 /* undo mapping of keyframes for drawing if scaled F-Curve */
785                 //if (nob)
786                 //      ANIM_nla_mapping_apply_fcurve(nob, ale->key_data, 1, 0); 
787         }
788         
789         /* free list of curves */
790         BLI_freelistN(&anim_data);
791 }
792
793 /* ************************************************************************* */
794 /* Channel List */
795
796 // XXX quite a few of these need to be kept in sync with their counterparts in Action Editor
797 // as they're the same. We have 2 separate copies of this for now to make it easier to develop
798 // the diffences between the two editors, but one day these should be merged!
799
800 /* left hand part */
801 void graph_draw_channel_names(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar) 
802 {
803         ListBase anim_data = {NULL, NULL};
804         bAnimListElem *ale;
805         int filter;
806         
807         View2D *v2d= &ar->v2d;
808         float x= 0.0f, y= 0.0f, height;
809         int items, i=0;
810         
811         /* build list of channels to draw */
812         filter= (ANIMFILTER_VISIBLE|ANIMFILTER_CHANNELS);
813         items= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
814         
815         /* Update max-extent of channels here (taking into account scrollers):
816          *      - this is done to allow the channel list to be scrollable, but must be done here
817          *        to avoid regenerating the list again and/or also because channels list is drawn first
818          *      - offset of ACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for 
819          *        start of list offset, and the second is as a correction for the scrollers.
820          */
821         height= (float)((items*ACHANNEL_STEP) + (ACHANNEL_HEIGHT*2));
822         
823 #if 0
824         if (height > (v2d->mask.ymax - v2d->mask.ymin)) {
825                 /* don't use totrect set, as the width stays the same 
826                  * (NOTE: this is ok here, the configuration is pretty straightforward) 
827                  */
828                 v2d->tot.ymin= (float)(-height);
829         }
830         
831         /* XXX I would call the below line! (ton) */
832 #endif
833         UI_view2d_totRect_set(v2d, ar->winx, height);
834         
835         /* loop through channels, and set up drawing depending on their type  */        
836         y= (float)ACHANNEL_FIRST;
837         
838         for (ale= anim_data.first, i=0; ale; ale= ale->next, i++) {
839                 const float yminc= (float)(y - ACHANNEL_HEIGHT_HALF);
840                 const float ymaxc= (float)(y + ACHANNEL_HEIGHT_HALF);
841                 
842                 /* check if visible */
843                 if ( IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
844                          IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) ) 
845                 {
846                         bActionGroup *grp = NULL;
847                         short indent= 0, offset= 0, sel= 0, group= 0;
848                         int expand= -1, protect = -1, special= -1, mute = -1;
849                         char name[128];
850                         
851                         /* determine what needs to be drawn */
852                         switch (ale->type) {
853                                 case ANIMTYPE_SCENE: /* scene */
854                                 {
855                                         Scene *sce= (Scene *)ale->data;
856                                         
857                                         group= 4;
858                                         indent= 0;
859                                         
860                                         special= ICON_SCENE_DATA;
861                                         
862                                         /* only show expand if there are any channels */
863                                         if (EXPANDED_SCEC(sce))
864                                                 expand= ICON_TRIA_DOWN;
865                                         else
866                                                 expand= ICON_TRIA_RIGHT;
867                                         
868                                         sel = SEL_SCEC(sce);
869                                         strcpy(name, sce->id.name+2);
870                                 }
871                                         break;
872                                 case ANIMTYPE_OBJECT: /* object */
873                                 {
874                                         Base *base= (Base *)ale->data;
875                                         Object *ob= base->object;
876                                         
877                                         group= 4;
878                                         indent= 0;
879                                         
880                                         /* icon depends on object-type */
881                                         if (ob->type == OB_ARMATURE)
882                                                 special= ICON_ARMATURE_DATA;
883                                         else    
884                                                 special= ICON_OBJECT_DATA;
885                                                 
886                                         /* only show expand if there are any channels */
887                                         if (EXPANDED_OBJC(ob))
888                                                 expand= ICON_TRIA_DOWN;
889                                         else
890                                                 expand= ICON_TRIA_RIGHT;
891                                         
892                                         sel = SEL_OBJC(base);
893                                         strcpy(name, ob->id.name+2);
894                                 }
895                                         break;
896                                 case ANIMTYPE_FILLACTD: /* action widget */
897                                 {
898                                         bAction *act= (bAction *)ale->data;
899                                         
900                                         group = 4;
901                                         indent= 1;
902                                         special= ICON_ACTION;
903                                         
904                                         if (EXPANDED_ACTC(act))
905                                                 expand= ICON_TRIA_DOWN;
906                                         else
907                                                 expand= ICON_TRIA_RIGHT;
908                                         
909                                         sel = SEL_ACTC(act);
910                                         strcpy(name, "Action");
911                                 }
912                                         break;
913                                 case ANIMTYPE_FILLDRIVERS: /* drivers widget */
914                                 {
915                                         AnimData *adt= (AnimData *)ale->data;
916                                         
917                                         group = 4;
918                                         indent= 1;
919                                         special= ICON_ANIM_DATA;
920                                         
921                                         if (EXPANDED_DRVD(adt))
922                                                 expand= ICON_TRIA_DOWN;
923                                         else
924                                                 expand= ICON_TRIA_RIGHT;
925                                         
926                                         strcpy(name, "Drivers");
927                                 }
928                                         break;
929                                 case ANIMTYPE_FILLMATD: /* object materials (dopesheet) expand widget */
930                                 {
931                                         Object *ob = (Object *)ale->data;
932                                         
933                                         group = 4;
934                                         indent = 1;
935                                         special = ICON_MATERIAL_DATA;
936                                         
937                                         if (FILTER_MAT_OBJC(ob))
938                                                 expand = ICON_TRIA_DOWN;
939                                         else
940                                                 expand = ICON_TRIA_RIGHT;
941                                                 
942                                         strcpy(name, "Materials");
943                                 }
944                                         break;
945                                 
946                                 
947                                 case ANIMTYPE_DSMAT: /* single material (dopesheet) expand widget */
948                                 {
949                                         Material *ma = (Material *)ale->data;
950                                         
951                                         group = 0;
952                                         indent = 0;
953                                         special = ICON_MATERIAL_DATA;
954                                         offset = 21;
955                                         
956                                         if (FILTER_MAT_OBJD(ma))
957                                                 expand = ICON_TRIA_DOWN;
958                                         else
959                                                 expand = ICON_TRIA_RIGHT;
960                                         
961                                         strcpy(name, ma->id.name+2);
962                                 }
963                                         break;
964                                 case ANIMTYPE_DSLAM: /* lamp (dopesheet) expand widget */
965                                 {
966                                         Lamp *la = (Lamp *)ale->data;
967                                         
968                                         group = 4;
969                                         indent = 1;
970                                         special = ICON_LAMP_DATA;
971                                         
972                                         if (FILTER_LAM_OBJD(la))
973                                                 expand = ICON_TRIA_DOWN;
974                                         else
975                                                 expand = ICON_TRIA_RIGHT;
976                                         
977                                         strcpy(name, la->id.name+2);
978                                 }
979                                         break;
980                                 case ANIMTYPE_DSCAM: /* camera (dopesheet) expand widget */
981                                 {
982                                         Camera *ca = (Camera *)ale->data;
983                                         
984                                         group = 4;
985                                         indent = 1;
986                                         special = ICON_CAMERA_DATA;
987                                         
988                                         if (FILTER_CAM_OBJD(ca))
989                                                 expand = ICON_TRIA_DOWN;
990                                         else
991                                                 expand = ICON_TRIA_RIGHT;
992                                         
993                                         strcpy(name, ca->id.name+2);
994                                 }
995                                         break;
996                                 case ANIMTYPE_DSCUR: /* curve (dopesheet) expand widget */
997                                 {
998                                         Curve *cu = (Curve *)ale->data;
999                                         
1000                                         group = 4;
1001                                         indent = 1;
1002                                         special = ICON_CURVE_DATA;
1003                                         
1004                                         if (FILTER_CUR_OBJD(cu))
1005                                                 expand = ICON_TRIA_DOWN;
1006                                         else
1007                                                 expand = ICON_TRIA_RIGHT;
1008                                         
1009                                         strcpy(name, cu->id.name+2);
1010                                 }
1011                                         break;
1012                                 case ANIMTYPE_DSSKEY: /* shapekeys (dopesheet) expand widget */
1013                                 {
1014                                         Key *key= (Key *)ale->data;
1015                                         
1016                                         group = 4;
1017                                         indent = 1;
1018                                         special = ICON_SHAPEKEY_DATA;
1019                                         
1020                                         if (FILTER_SKE_OBJD(key))       
1021                                                 expand = ICON_TRIA_DOWN;
1022                                         else
1023                                                 expand = ICON_TRIA_RIGHT;
1024                                                 
1025                                         //sel = SEL_OBJC(base);
1026                                         strcpy(name, "Shape Keys");
1027                                 }
1028                                         break;
1029                                 case ANIMTYPE_DSWOR: /* world (dopesheet) expand widget */
1030                                 {
1031                                         World *wo= (World *)ale->data;
1032                                         
1033                                         group = 4;
1034                                         indent = 1;
1035                                         special = ICON_WORLD_DATA;
1036                                         
1037                                         if (FILTER_WOR_SCED(wo))        
1038                                                 expand = ICON_TRIA_DOWN;
1039                                         else
1040                                                 expand = ICON_TRIA_RIGHT;
1041                                         
1042                                         strcpy(name, wo->id.name+2);
1043                                 }
1044                                         break;
1045                                 
1046                                 
1047                                 case ANIMTYPE_GROUP: /* action group */
1048                                 {
1049                                         bActionGroup *agrp= (bActionGroup *)ale->data;
1050                                         
1051                                         group= 2;
1052                                         indent= 0;
1053                                         special= -1;
1054                                         
1055                                         if (ale->id) {
1056                                                 /* special exception for materials */
1057                                                 if (GS(ale->id->name) == ID_MA) 
1058                                                         offset= 25;
1059                                                 else
1060                                                         offset= 14;
1061                                         }
1062                                         else
1063                                                 offset= 0;
1064                                         
1065                                         /* only show expand if there are any channels */
1066                                         if (agrp->channels.first) {
1067                                                 if (EXPANDED_AGRP(agrp))
1068                                                         expand = ICON_TRIA_DOWN;
1069                                                 else
1070                                                         expand = ICON_TRIA_RIGHT;
1071                                         }
1072                                         
1073                                         if (EDITABLE_AGRP(agrp))
1074                                                 protect = ICON_UNLOCKED;
1075                                         else
1076                                                 protect = ICON_LOCKED;
1077                                                 
1078                                         sel = SEL_AGRP(agrp);
1079                                         strcpy(name, agrp->name);
1080                                 }
1081                                         break;
1082                                 case ANIMTYPE_FCURVE: /* F-Curve channel */
1083                                 {
1084                                         FCurve *fcu = (FCurve *)ale->data;
1085                                         
1086                                         indent = 0;
1087                                         
1088                                         group= (fcu->grp) ? 1 : 0;
1089                                         grp= fcu->grp;
1090                                         
1091                                         if (ale->id) {
1092                                                 /* special exception for materials */
1093                                                 if (GS(ale->id->name) == ID_MA) {
1094                                                         offset= 21;
1095                                                         indent= 1;
1096                                                 }
1097                                                 else
1098                                                         offset= 14;
1099                                         }
1100                                         else
1101                                                 offset= 0;
1102                                         
1103                                         /* for now, 'special' (i.e. in front of name) is used to show visibility status */
1104                                         if (fcu->flag & FCURVE_VISIBLE)
1105                                                 special= ICON_CHECKBOX_HLT;
1106                                         else
1107                                                 special= ICON_CHECKBOX_DEHLT;
1108                                         
1109                                         if (fcu->flag & FCURVE_MUTED)
1110                                                 mute = ICON_MUTE_IPO_ON;
1111                                         else    
1112                                                 mute = ICON_MUTE_IPO_OFF;
1113                                                 
1114                                         if (EDITABLE_FCU(fcu))
1115                                                 protect = ICON_UNLOCKED;
1116                                         else
1117                                                 protect = ICON_LOCKED;
1118                                         
1119                                         sel = SEL_FCU(fcu);
1120                                         
1121                                         getname_anim_fcurve(name, ale->id, fcu);
1122                                 }
1123                                         break;
1124                                         
1125                                 case ANIMTYPE_SHAPEKEY: /* shapekey channel */
1126                                 {
1127                                         KeyBlock *kb = (KeyBlock *)ale->data;
1128                                         
1129                                         indent = 0;
1130                                         special = -1;
1131                                         
1132                                         offset= (ale->id) ? 21 : 0;
1133                                         
1134                                         if (kb->name[0] == '\0')
1135                                                 sprintf(name, "Key %d", ale->index);
1136                                         else
1137                                                 strcpy(name, kb->name);
1138                                 }
1139                                         break;
1140                         }       
1141                         
1142                         /* now, start drawing based on this information */
1143                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1144                         glEnable(GL_BLEND);
1145                         
1146                         /* draw backing strip behind channel name */
1147                         if (group == 4) {
1148                                 /* only used in dopesheet... */
1149                                 if (ELEM(ale->type, ANIMTYPE_SCENE, ANIMTYPE_OBJECT)) {
1150                                         /* object channel - darker */
1151                                         UI_ThemeColor(TH_DOPESHEET_CHANNELOB);
1152                                         uiSetRoundBox((expand == ICON_TRIA_DOWN)? (1):(1|8));
1153                                         gl_round_box(GL_POLYGON, x+offset,  yminc, (float)ACHANNEL_NAMEWIDTH, ymaxc, 8);
1154                                 }
1155                                 else {
1156                                         /* sub-object folders - lighter */
1157                                         UI_ThemeColor(TH_DOPESHEET_CHANNELSUBOB);
1158                                         
1159                                         offset += 7 * indent;
1160                                         glBegin(GL_QUADS);
1161                                                 glVertex2f(x+offset, yminc);
1162                                                 glVertex2f(x+offset, ymaxc);
1163                                                 glVertex2f((float)ACHANNEL_NAMEWIDTH, ymaxc);
1164                                                 glVertex2f((float)ACHANNEL_NAMEWIDTH, yminc);
1165                                         glEnd();
1166                                         
1167                                         /* clear group value, otherwise we cause errors... */
1168                                         group = 0;
1169                                 }
1170                         }
1171                         else if (group == 3) {
1172                                 /* only for gp-data channels */
1173                                 UI_ThemeColorShade(TH_GROUP, 20);
1174                                 uiSetRoundBox((expand == ICON_TRIA_DOWN)? (1):(1|8));
1175                                 gl_round_box(GL_POLYGON, x+offset,  yminc, (float)ACHANNEL_NAMEWIDTH, ymaxc, 8);
1176                         }
1177                         else if (group == 2) {
1178                                 /* only for action group channels */
1179                                 if (ale->flag & AGRP_ACTIVE)
1180                                         UI_ThemeColorShade(TH_GROUP_ACTIVE, 10);
1181                                 else
1182                                         UI_ThemeColorShade(TH_GROUP, 20);
1183                                 uiSetRoundBox((expand == ICON_TRIA_DOWN)? (1):(1|8));
1184                                 gl_round_box(GL_POLYGON, x+offset,  yminc, (float)ACHANNEL_NAMEWIDTH, ymaxc, 8);
1185                         }
1186                         else {
1187                                 short shadefac= ((indent==0)?20: (indent==1)?-20: -40);
1188                                 
1189                                 indent += group;
1190                                 offset += 7 * indent;
1191                                 
1192                                 /* draw channel backdrop */
1193                                 UI_ThemeColorShade(TH_HEADER, shadefac);
1194                                 
1195                                 glBegin(GL_QUADS);
1196                                         glVertex2f(x+offset, yminc);
1197                                         glVertex2f(x+offset, ymaxc);
1198                                         glVertex2f((float)ACHANNEL_NAMEWIDTH, ymaxc);
1199                                         glVertex2f((float)ACHANNEL_NAMEWIDTH, yminc);
1200                                 glEnd();
1201                                 
1202                                 /* most of the time, only F-Curves are going to be drawn here */
1203                                 if (ale->type == ANIMTYPE_FCURVE) {
1204                                         /* F-Curve channels need to have a special 'color code' box drawn, which is colored with whatever 
1205                                          * color the curve has stored 
1206                                          */
1207                                         FCurve *fcu= (FCurve *)ale->data;
1208                                         glColor3fv(fcu->color);
1209                                         
1210                                         // NOTE: only enable the following line for the fading-out gradient
1211                                         //glShadeModel(GL_SMOOTH);
1212                                         
1213                                         glBegin(GL_QUADS);
1214                                                 /* solid color for the area around the checkbox */
1215                                                 glVertex2f(x+offset, yminc);
1216                                                 glVertex2f(x+offset, ymaxc);
1217                                                 glVertex2f(x+offset+18, ymaxc);
1218                                                 glVertex2f(x+offset+18, yminc);
1219                                                 
1220 #if 0 // fading out gradient
1221                                                 /* fading out gradient for the rest of the box */
1222                                                 glVertex2f(x+offset+18, yminc);
1223                                                 glVertex2f(x+offset+18, ymaxc);
1224                                                 
1225                                                 UI_ThemeColorShade(TH_HEADER, shadefac); // XXX does this cause any problems on some cards?
1226                                                 
1227                                                 glVertex2f(x+offset+20, ymaxc);
1228                                                 glVertex2f(x+offset+20, yminc);
1229 #endif // fading out gradient
1230                                         glEnd();
1231                                         
1232                                         // NOTE: only enable the following line for the fading-out gradient
1233                                         //glShadeModel(GL_FLAT);
1234                                 }
1235                         }
1236                         
1237                         /* draw expand/collapse triangle */
1238                         if (expand > 0) {
1239                                 UI_icon_draw(x+offset, yminc, expand);
1240                                 offset += 17;
1241                         }
1242                         
1243                         /* draw special icon indicating certain data-types */
1244                         if (special > -1) {
1245                                 if (ELEM(group, 3, 4)) {
1246                                         /* for gpdatablock channels */
1247                                         UI_icon_draw(x+offset, yminc, special);
1248                                         offset += 17;
1249                                 }
1250                                 else {
1251                                         /* for normal channels */
1252                                         UI_icon_draw(x+offset, yminc, special);
1253                                         offset += 17;
1254                                 }
1255                         }
1256                         glDisable(GL_BLEND);
1257                         
1258                         /* draw name */
1259                         if (sel)
1260                                 UI_ThemeColor(TH_TEXT_HI);
1261                         else
1262                                 UI_ThemeColor(TH_TEXT);
1263                         offset += 3;
1264                         ui_rasterpos_safe(x+offset, y-4, 1.0f);
1265                         UI_DrawString(G.font, name, 0);
1266                         
1267                         /* reset offset - for RHS of panel */
1268                         offset = 0;
1269                         
1270                         /* set blending again, as text drawing may clear it */
1271                         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1272                         glEnable(GL_BLEND);
1273                         
1274                         /* draw protect 'lock' */
1275                         if (protect > -1) {
1276                                 offset = 16;
1277                                 UI_icon_draw((float)ACHANNEL_NAMEWIDTH-offset, yminc, protect);
1278                         }
1279                         
1280                         /* draw mute 'eye' */
1281                         if (mute > -1) {
1282                                 offset += 16;
1283                                 UI_icon_draw((float)(ACHANNEL_NAMEWIDTH-offset), yminc, mute);
1284                         }
1285                         glDisable(GL_BLEND);
1286                 }
1287                 
1288                 /* adjust y-position for next one */
1289                 y -= ACHANNEL_STEP;
1290         }
1291         
1292         /* free tempolary channels */
1293         BLI_freelistN(&anim_data);
1294 }