Revision: 19595
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19595
Author:   aligorith
Date:     2009-04-08 03:07:46 +0200 (Wed, 08 Apr 2009)

Log Message:
-----------
Graph Editor: 'Ghost Curves' functionality from Apricot

This feature takes a 'snapshot' of the visible+selected F-Curves, and displays 
these in the background as 'ghosts curves' in the background. Such curves are 
drawn semi-transparent, slightly darker, and with dotted lines. 

To use, simply click the 'curve' button beside the Auto-Snapping selector. To 
clear, simply click that button again (with a different icon now). 

These 'ghost curves' are stored per Graph Editor instance, and are not saved to 
file (i.e. per session only). They are useful to be used as guides when 
refining the shape of existing curves.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c
    
branches/blender2.5/blender/source/blender/editors/space_graph/graph_header.c
    
branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h
    branches/blender2.5/blender/source/blender/editors/space_graph/graph_ops.c
    
branches/blender2.5/blender/source/blender/editors/space_graph/graph_select.c
    branches/blender2.5/blender/source/blender/editors/space_graph/space_graph.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_space_types.h

Modified: 
branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c     
2009-04-07 23:22:20 UTC (rev 19594)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c     
2009-04-08 01:07:46 UTC (rev 19595)
@@ -4599,6 +4599,7 @@
                                SpaceIpo *sipo= (SpaceIpo*)sl;
                                
                                sipo->ads= newdataadr(fd, sipo->ads);
+                               sipo->ghostCurves.first= 
sipo->ghostCurves.last= NULL;
                        }
                        else if (sl->spacetype==SPACE_OUTLINER) {
                                SpaceOops *soops= (SpaceOops*) sl;

Modified: 
branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c    
2009-04-07 23:22:20 UTC (rev 19594)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c    
2009-04-08 01:07:46 UTC (rev 19595)
@@ -1807,7 +1807,17 @@
                                        if(v3d->gpd) write_gpencil(wd, 
v3d->gpd);
                                }
                                else if(sl->spacetype==SPACE_IPO) {
+                                       SpaceIpo *sipo= (SpaceIpo *)sl;
+                                       ListBase tmpGhosts = sipo->ghostCurves;
+                                       
+                                       /* temporarily disable ghost curves 
when saving */
+                                       sipo->ghostCurves.first= 
sipo->ghostCurves.last= NULL;
+                                       
                                        writestruct(wd, DATA, "SpaceIpo", 1, 
sl);
+                                       if(sipo->ads) writestruct(wd, DATA, 
"bDopeSheet", 1, sipo->ads);
+                                       
+                                       /* reenable ghost curves */
+                                       sipo->ghostCurves= tmpGhosts;
                                }
                                else if(sl->spacetype==SPACE_BUTS) {
                                        writestruct(wd, DATA, "SpaceButs", 1, 
sl);

Modified: 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c 
2009-04-07 23:22:20 UTC (rev 19594)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_draw.c 
2009-04-08 01:07:46 UTC (rev 19595)
@@ -744,14 +744,51 @@
 
 /* Public Curve-Drawing API  ---------------- */
 
-void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, 
View2DGrid *grid)
+/* Draw the 'ghost' F-Curves (i.e. snapshots of the curve) */
+void graph_draw_ghost_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, 
View2DGrid *grid)
 {
+       FCurve *fcu;
+       
+       /* draw with thick dotted lines */
+       setlinestyle(1);
+       glLineWidth(3.0f);
+       
+       /* anti-aliased lines for less jagged appearance */
+       glEnable(GL_LINE_SMOOTH);
+       glEnable(GL_BLEND);
+       
+       /* the ghost curves are simply sampled F-Curves stored in 
sipo->ghostCurves */
+       for (fcu= sipo->ghostCurves.first; fcu; fcu= fcu->next) {
+               /* set whatever color the curve has set 
+                *      - this is set by the function which creates these
+                *      - draw with a fixed opacity of 2
+                */
+               glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], 0.5f);
+               
+               /* simply draw the stored samples */
+               draw_fcurve_curve_samples(fcu, &ar->v2d);
+       }
+       
+       /* restore settings */
+       setlinestyle(0);
+       glLineWidth(1.0f);
+       
+       glDisable(GL_LINE_SMOOTH);
+       glDisable(GL_BLEND);
+}
+
+/* This is called twice from space_graph.c -> graph_main_area_draw()
+ * Unselected then selected F-Curves are drawn so that they do not occlude 
each other.
+ */
+void graph_draw_curves (bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, 
View2DGrid *grid, short sel)
+{
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
        int filter;
        
        /* build list of curves to draw */
        filter= 
(ANIMFILTER_VISIBLE|ANIMFILTER_CURVESONLY|ANIMFILTER_CURVEVISIBLE);
+       filter |= (sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL);
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
                
        /* for each curve:

Modified: 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 
2009-04-07 23:22:20 UTC (rev 19594)
+++ branches/blender2.5/blender/source/blender/editors/space_graph/graph_edit.c 
2009-04-08 01:07:46 UTC (rev 19595)
@@ -238,7 +238,155 @@
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* ******************** Create Ghost-Curves Operator *********************** */
+/* This operator samples the data of the selected F-Curves to F-Points, 
storing them
+ * as 'ghost curves' in the active Graph Editor
+ */
 
+/* Bake each F-Curve into a set of samples, and store as a ghost curve */
+static void create_ghost_curves (bAnimContext *ac, int start, int end)
+{      
+       SpaceIpo *sipo= (SpaceIpo *)ac->sa->spacedata.first;
+       ListBase anim_data = {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       /* free existing ghost curves */
+       free_fcurves(&sipo->ghostCurves);
+       
+       /* sanity check */
+       if (start >= end) {
+               printf("Error: Frame range for Ghost F-Curve creation is 
inappropriate \n");
+               return;
+       }
+       
+       /* filter data */
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_SEL 
| ANIMFILTER_CURVESONLY);
+       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+       
+       /* loop through filtered data and add keys between selected keyframes 
on every frame  */
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               FCurve *fcu= (FCurve *)ale->key_data;
+               FCurve *gcu= MEM_callocN(sizeof(FCurve), "Ghost FCurve");
+               ChannelDriver *driver= fcu->driver;
+               FPoint *fpt;
+               int cfra;               
+               
+               /* disable driver so that it don't muck up the sampling process 
*/
+               fcu->driver= NULL;
+               
+               /* create samples, but store them in a new curve 
+                *      - we cannot use fcurve_store_samples() as that will 
only overwrite the original curve 
+                */
+               gcu->fpt= fpt= MEM_callocN(sizeof(FPoint)*(end-start+1), "Ghost 
FPoint Samples");
+               gcu->totvert= end - start + 1;
+               
+               /* use the sampling callback at 1-frame intervals from start to 
end frames */
+               for (cfra= start; cfra <= end; cfra++, fpt++) {
+                       fpt->vec[0]= (float)cfra;
+                       fpt->vec[1]= fcurve_samplingcb_evalcurve(fcu, NULL, 
(float)cfra);
+               }
+               
+               /* set color of ghost curve 
+                *      - make the color slightly darker
+                */
+               gcu->color[0]= fcu->color[0] - 0.07f;
+               gcu->color[1]= fcu->color[1] - 0.07f;
+               gcu->color[2]= fcu->color[2] - 0.07f;
+               
+               /* store new ghost curve */
+               BLI_addtail(&sipo->ghostCurves, gcu);
+               
+               /* restore driver */
+               fcu->driver= driver;
+       }
+       
+       /* admin and redraws */
+       BLI_freelistN(&anim_data);
+}
+
+/* ------------------- */
+
+static int graphkeys_create_ghostcurves_exec(bContext *C, wmOperator *op)
+{
+       bAnimContext ac;
+       View2D *v2d;
+       int start, end;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+               
+       /* ghost curves are snapshots of the visible portions of the curves, so 
set range to be the visible range */
+       v2d= &ac.ar->v2d;
+       start= (int)v2d->cur.xmin;
+       end= (int)v2d->cur.xmax;
+       
+       /* bake selected curves into a ghost curve */
+       create_ghost_curves(&ac, start, end);
+       
+       /* update this editor only */
+       ED_area_tag_redraw(CTX_wm_area(C));
+       
+       return OPERATOR_FINISHED;
+}
+ 
+void GRAPHEDIT_OT_ghost_curves_create (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Create Ghost Curves";
+       ot->idname= "GRAPHEDIT_OT_ghost_curves_create";
+       
+       /* api callbacks */
+       ot->exec= graphkeys_create_ghostcurves_exec;
+       ot->poll= ED_operator_areaactive;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       // todo: add props for start/end frames
+}
+
+/* ******************** Clear Ghost-Curves Operator *********************** */
+/* This operator clears the 'ghost curves' for the active Graph Editor */
+
+static int graphkeys_clear_ghostcurves_exec(bContext *C, wmOperator *op)
+{
+       bAnimContext ac;
+       SpaceIpo *sipo;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+       sipo= (SpaceIpo *)ac.sa->spacedata.first;
+               
+       /* if no ghost curves, don't do anything */
+       if (sipo->ghostCurves.first == NULL)
+               return OPERATOR_CANCELLED;
+       
+       /* free ghost curves */
+       free_fcurves(&sipo->ghostCurves);
+       
+       /* update this editor only */
+       ED_area_tag_redraw(CTX_wm_area(C));
+       
+       return OPERATOR_FINISHED;
+}
+ 
+void GRAPHEDIT_OT_ghost_curves_clear (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Create Ghost Curves";
+       ot->idname= "GRAPHEDIT_OT_ghost_curves_clear";
+       
+       /* api callbacks */
+       ot->exec= graphkeys_clear_ghostcurves_exec;
+       ot->poll= ED_operator_areaactive;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 /* ************************************************************************** 
*/
 /* GENERAL STUFF */
 

Modified: 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_header.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_header.c   
    2009-04-07 23:22:20 UTC (rev 19594)
+++ 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_header.c   
    2009-04-08 01:07:46 UTC (rev 19595)
@@ -225,7 +225,17 @@
                                xco,yco,90,YIC, &sipo->autosnap, 0, 1, 0, 0, 
                                "Auto-snapping mode for keyframe times when 
transforming");
        }
+       xco += 98;
        
+       /* ghost curves */
+       // XXX these icons need to be changed
+       if (sipo->ghostCurves.first)
+               uiDefIconButO(block, BUT, "GRAPHEDIT_OT_ghost_curves_clear", 
WM_OP_INVOKE_REGION_WIN, ICON_OUTLINER_DATA_CURVE, xco,yco,XIC,YIC, "Clear 
F-Curve snapshots (Ghosts)");
+       else 
+               uiDefIconButO(block, BUT, "GRAPHEDIT_OT_ghost_curves_create", 
WM_OP_INVOKE_REGION_WIN, ICON_OUTLINER_OB_CURVE, xco,yco,XIC,YIC, "Create 
snapshot (Ghosts) of selected F-Curves as background aid");
+       xco+= XIC;
+       
+       
        /* always as last  */
        UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax - 
ar->v2d.tot.ymin));
        

Modified: 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h   
    2009-04-07 23:22:20 UTC (rev 19594)
+++ 
branches/blender2.5/blender/source/blender/editors/space_graph/graph_intern.h   
    2009-04-08 01:07:46 UTC (rev 19595)
@@ -46,8 +46,10 @@
 /* ***************************************** */
 /* graph_draw.c */
 void graph_draw_channel_names(struct bAnimContext *ac, struct SpaceIpo *sipo, 
struct ARegion *ar);
-void graph_draw_curves(struct bAnimContext *ac, struct SpaceIpo *sipo, struct 
ARegion *ar, struct View2DGrid *grid);
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to