Revision: 18429
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18429
Author:   aligorith
Date:     2009-01-09 07:25:14 +0100 (Fri, 09 Jan 2009)

Log Message:
-----------
2.5 - IPO Editor

Porting relevant drawing code over from AnimSys2. It is currently not hooked up 
to anything else yet, so don't expect any curves to draw for a while. I'll need 
this for validating that my recorded animation system will work. ;)

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/editors/space_ipo/ipo_draw.c

Added: branches/blender2.5/blender/source/blender/editors/space_ipo/ipo_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_ipo/ipo_draw.c     
                        (rev 0)
+++ branches/blender2.5/blender/source/blender/editors/space_ipo/ipo_draw.c     
2009-01-09 06:25:14 UTC (rev 18429)
@@ -0,0 +1,713 @@
+/**
+ * $Id: drawipo.c 17512 2008-11-20 05:55:42Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ *
+ * Contributor(s): Joshua Leung (2009 Recode)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef _WIN32
+#include <unistd.h>
+#else
+#include <io.h>
+#endif
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+
+#include "DNA_action_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_key_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_sequence_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view2d_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_depsgraph.h"
+#include "BKE_ipo.h"
+#include "BKE_key.h"
+#include "BKE_object.h"
+#include "BKE_utildefines.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "ED_anim_api.h"
+#include "ED_util.h"
+
+#include "UI_resources.h"
+#include "UI_view2d.h"
+
+/* **************************** */
+// XXX stubs to remove!
+
+// NOTE: the code in this file has yet to be rewritten to get rid of the 
editipo system which is past its use-by-date - Aligorith
+
+typedef struct EditIpo {
+       IpoCurve *icu;
+       short disptype;
+       short flag;
+       unsigned int col;
+} EditIpo;
+
+#define ISPOIN(a, b, c)                       ( (a->b) && (a->c) )  
+#define ISPOIN3(a, b, c, d)           ( (a->b) && (a->c) && (a->d) )
+#define ISPOIN4(a, b, c, d, e)        ( (a->b) && (a->c) && (a->d) && (a->e) )
+
+/* *************************** */
+
+/* helper func - draw keyframe vertices only for an IPO-curve */
+static void draw_ipovertices_keyframes(IpoCurve *icu, View2D *v2d, short 
disptype, short edit, short sel)
+{
+       BezTriple *bezt= icu->bezt;
+       float v1[2];
+       int a, b;
+       
+       bglBegin(GL_POINTS);
+       
+       for (a = 0; a < icu->totvert; a++, bezt++) {
+               /* IPO_DISPBITS is used for displaying curves for bitflag 
variables */
+               if (disptype == IPO_DISPBITS) {
+                       /*if (v2d->cur.xmin < bezt->vec[1][0] < v2d->cur.xmax) 
{*/
+                       short ok= 0;
+                       
+                       if (edit) {
+                               if ((bezt->f2 & SELECT) == sel) 
+                                       ok= 1;
+                       }
+                       else ok= 1;
+                       
+                       if (ok) {
+                               int val= (int)bezt->vec[1][1];
+                               v1[0]= bezt->vec[1][0];
+                               
+                               for (b= 0; b < 31; b++) {
+                                       if (val & (1<<b)) {     
+                                               v1[1]= b + 1;
+                                               bglVertex3fv(v1);
+                                       }
+                               }
+                       }
+                       /*}*/
+               } 
+               else { /* normal (non bit) curves */
+                       if (edit) {
+                               /* Only the vertex of the line, the
+                                * handler are drawn later
+                                */
+                               if ((bezt->f2 & SELECT) == sel) /* && 
G.v2d->cur.xmin < bezt->vec[1][0] < G.v2d->cur.xmax)*/
+                                       bglVertex3fv(bezt->vec[1]);
+                       }
+                       else {
+                               /* draw only if in bounds */
+                               /*if (G.v2d->cur.xmin < bezt->vec[1][0] < 
G.v2d->cur.xmax)*/
+                               bglVertex3fv(bezt->vec[1]);
+                       }
+               }
+       }
+       bglEnd();
+}
+
+/* helper func - draw handle vertex for an IPO-Curve as a round unfilled 
circle */
+static void draw_ipohandle_control(float x, float y, float xscale, float 
yscale, float hsize)
+{
+       static GLuint displist=0;
+       
+       /* initialise round circle shape */
+       if (displist == 0) {
+               GLUquadricObj *qobj;
+               
+               displist= glGenLists(1);
+               glNewList(displist, GL_COMPILE_AND_EXECUTE);
+               
+               qobj    = gluNewQuadric(); 
+               gluQuadricDrawStyle(qobj, GLU_SILHOUETTE); 
+               gluDisk(qobj, 0.07,  0.8, 12, 1);
+               gluDeleteQuadric(qobj);  
+               
+               glEndList();
+       }
+       
+       /* adjust view transform before starting */
+       glTranslatef(x, y, 0.0f);
+       glScalef(1.0/xscale*hsize, 1.0/yscale*hsize, 1.0);
+       
+       /* draw! */
+       glCallList(displist);
+       
+       /* restore view transform */
+       glScalef(xscale/hsize, yscale/hsize, 1.0);
+       glTranslatef(-x, -y, 0.0f);
+}
+
+/* helper func - draw handle vertices only for an IPO-curve (if it is in 
EditMode) */
+static void draw_ipovertices_handles(IpoCurve *icu, View2D *v2d, short 
disptype, short sel)
+{
+       BezTriple *bezt= icu->bezt;
+       BezTriple *prevbezt = NULL;
+       float hsize, xscale, yscale;
+       int a;
+       
+       /* get view settings */
+       hsize= UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE);
+       UI_view2d_getscale(v2d, &xscale, &yscale);
+       
+       /* set handle color */
+       if (sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
+       else UI_ThemeColor(TH_HANDLE_VERTEX);
+       
+       for (a= 0; a < icu->totvert; a++, prevbezt=bezt, bezt++) {
+               if (disptype != IPO_DISPBITS) {
+                       if (ELEM(icu->ipo, IPO_BEZ, IPO_MIXED)) {
+                               /* Draw the editmode handels for a bezier curve 
(others don't have handles) 
+                                * if their selection status matches the 
selection status we're drawing for
+                                *      - first handle only if previous 
beztriple was bezier-mode
+                                *      - second handle only if current 
beztriple is bezier-mode
+                                */
+                               if ( (!prevbezt && (bezt->ipo==IPO_BEZ)) || 
(prevbezt && (prevbezt->ipo==IPO_BEZ)) ) {
+                                       if ((bezt->f1 & SELECT) == sel)/* && 
v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/
+                                               
draw_ipohandle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize);
+                               }
+                               
+                               if (bezt->ipo==IPO_BEZ) {
+                                       if ((bezt->f3 & SELECT) == sel)/* && 
v2d->cur.xmin < bezt->vec[2][0] < v2d->cur.xmax)*/
+                                               
draw_ipohandle_control(bezt->vec[2][0], bezt->vec[2][1], xscale, yscale, hsize);
+                               }
+                       }
+               }
+       }
+}
+
+static void draw_ipovertices(SpaceIpo *sipo, ARegion *ar, int sel)
+{
+       View2D *v2d= &ar->v2d;
+       EditIpo *ei= sipo->editipo;
+       int nr, val = 0;
+       
+       /* this shouldn't get called while drawing in selection-buffer anyway */
+       //if (G.f & G_PICKSEL) return;
+       
+       glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
+       
+       for (nr=0; nr<sipo->totipo; nr++, ei++) {
+               if ISPOIN(ei, flag & IPO_VISIBLE, icu) {
+                       /* select colors to use to draw keyframes */
+                       if (sipo->showkey) {
+                               if (sel) UI_ThemeColor(TH_TEXT_HI);
+                               else UI_ThemeColor(TH_TEXT);
+                       } 
+                       else if (ei->flag & IPO_EDIT) {
+                               if (sel) UI_ThemeColor(TH_VERTEX_SELECT); 
+                               else UI_ThemeColor(TH_VERTEX);
+                       } 
+                       else {
+                               if (sel) UI_ThemeColor(TH_TEXT_HI);
+                               else UI_ThemeColor(TH_TEXT);
+                               
+                               val= (ei->icu->flag & IPO_SELECT)!=0;
+                               if (sel != val) continue;
+                       }
+                       
+                       /* We can't change the color in the middle of
+                        * GL_POINTS because then Blender will segfault
+                        * on TNT2 / Linux with NVidia's drivers
+                        * (at least up to ver. 4349) 
+                        */             
+                       
+                       /* draw keyframes, then the handles (if in editmode) */
+                       draw_ipovertices_keyframes(ei->icu, v2d, ei->disptype, 
(ei->flag & IPO_EDIT), sel);
+                       
+                       /* Now draw the two vertex of the handles,
+                        * This needs to be done after the keyframes, 
+                        * because we can't call glPointSize
+                        * in the middle of a glBegin/glEnd also the
+                        * bug comment before.
+                        */
+                       if ((ei->flag & IPO_EDIT) && (sipo->flag & 
SIPO_NOHANDLES)==0)
+                               draw_ipovertices_handles(ei->icu, v2d, 
ei->disptype, sel);
+               }
+       }
+       
+       glPointSize(1.0);
+}
+
+/* draw lines for IPO-curve handles only (this is only done in EditMode) */
+static void draw_ipohandles(SpaceIpo *sipo, ARegion *ar, int sel)
+{
+       EditIpo *ei;
+       extern unsigned int nurbcol[];
+       unsigned int *col;
+       int a, b;
+       
+       /* don't draw handle lines if handles are not shown */
+       if (sipo->flag & SIPO_NOHANDLES)
+               return;
+       
+       if (sel) col= nurbcol+4;
+       else col= nurbcol;
+       
+       ei= sipo->editipo;
+       for (a=0; a<sipo->totipo; a++, ei++) {
+               if ISPOIN4(ei, flag & IPO_VISIBLE, flag & IPO_EDIT, icu, 
disptype!=IPO_DISPBITS) {
+                       if (ELEM(ei->icu->ipo, IPO_BEZ, IPO_MIXED)) {
+                               BezTriple *bezt=ei->icu->bezt, *prevbezt=NULL;
+                               float *fp;
+                               
+                               for (b= 0; b < ei->icu->totvert; b++, 
prevbezt=bezt, bezt++) {
+                                       if ((bezt->f2 & SELECT)==sel) {
+                                               fp= bezt->vec[0];
+                                               
+                                               /* only draw first handle if 
previous segment had handles */
+                                               if ( (!prevbezt && 
(bezt->ipo==IPO_BEZ)) || (prevbezt && (prevbezt->ipo==IPO_BEZ)) ) 
+                                               {
+                                                       cpack(col[bezt->h1]);
+                                                       glBegin(GL_LINE_STRIP); 
+                                                       glVertex2fv(fp); 
glVertex2fv(fp+3); 
+                                                       glEnd();
+                                                       
+                                               }
+                                               
+                                               /* only draw second handle if 
this segment is bezier */
+                                               if (bezt->ipo == IPO_BEZ) 
+                                               {
+                                                       cpack(col[bezt->h2]);
+                                                       glBegin(GL_LINE_STRIP); 
+                                                       glVertex2fv(fp+3); 
glVertex2fv(fp+6); 
+                                                       glEnd();
+                                               }
+                                       }
+                                       else {
+                                               /* only draw first handle if 
previous segment was had handles, and selection is ok */
+                                               if ( ((bezt->f1 & SELECT)==sel) 
&& 
+                                                        ( (!prevbezt && 
(bezt->ipo==IPO_BEZ)) || (prevbezt && (prevbezt->ipo==IPO_BEZ)) ) ) 
+                                               {
+                                                       fp= bezt->vec[0];
+                                                       cpack(col[bezt->h1]);
+                                                       
+                                                       glBegin(GL_LINE_STRIP); 
+                                                       glVertex2fv(fp); 
glVertex2fv(fp+3); 
+                                                       glEnd();
+                                               }
+                                               
+                                               /* only draw second handle if 
this segment is bezier, and selection is ok */
+                                               if ( ((bezt->f3 & SELECT)==sel) 
&&
+                                                        (bezt->ipo == IPO_BEZ) 
)
+                                               {
+                                                       fp= bezt->vec[1];
+                                                       cpack(col[bezt->h2]);
+                                                       
+                                                       glBegin(GL_LINE_STRIP); 
+                                                       glVertex2fv(fp); 
glVertex2fv(fp+3); 
+                                                       glEnd();
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
+/* helper func - draw one repeat of an ipo-curve: bitflag curve only (this is 
evil stuff to expose to user like this) */
+static void draw_ipocurve_repeat_bits (IpoCurve *icu, View2D *v2d, float 
cycxofs)
+{
+       BezTriple *bezt= icu->bezt;
+       int a;
+       

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to