Revision: 19527
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19527
Author:   blendix
Date:     2009-04-04 01:30:32 +0200 (Sat, 04 Apr 2009)

Log Message:
-----------
2.5: Added basic insert/remove keyframes from UI buttons.

- I key over a button inserts a keyframe.
- Alt+I removes a keyframe.
- With right mouse button a menu with these options pops up.
- Buttons are colored green if the property is animated, yellow
  if it is on a keyframe. I followed the colors from the UI
  mockups, but the flicker on keyframes seems too distracting in
  practice?

- This only works for properties on the ID itself at the moment,
  path callbacks need to be filled in for all structs but mesh
  still.
- It doesn't work when you're over a related label, that needs to
  be made to work.
- I made it insert keyframes outside of any keyingset. Not sure
  how this is supposed to integrate?

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
    branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
    branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
    branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h
    branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
    branches/blender2.5/blender/source/blender/editors/interface/interface.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
    
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_panel.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_widgets.c
    
branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c

Added Paths:
-----------
    
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h  
2009-04-03 20:03:09 UTC (rev 19526)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_fcurve.h  
2009-04-03 23:30:32 UTC (rev 19527)
@@ -116,6 +116,9 @@
 /* find matching F-Curve in the given list of F-Curves */
 struct FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const 
int array_index);
 
+/* test if there is a keyframe at cfra */
+int on_keyframe_fcurve(struct FCurve *fcu, float cfra);
+
 /* get the time extents for F-Curve */
 void calc_fcurve_range(struct FCurve *fcu, float *min, float *max);
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c       
2009-04-03 20:03:09 UTC (rev 19526)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/fcurve.c       
2009-04-03 23:30:32 UTC (rev 19527)
@@ -171,6 +171,19 @@
        return NULL;
 }
 
+int on_keyframe_fcurve(FCurve *fcu, float cfra)
+{
+       BezTriple *bezt;
+       int i;
+
+       bezt= fcu->bezt;
+       for (i=0; i<fcu->totvert; i++, bezt++)
+               if(IS_EQ(bezt->vec[1][0], cfra))
+                       return 1;
+       
+       return 0;
+}
+
 /* Calculate the extents of F-Curve's data */
 void calc_fcurve_bounds (FCurve *fcu, float *xmin, float *xmax, float *ymin, 
float *ymax)
 {

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c     
2009-04-03 20:03:09 UTC (rev 19526)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c     
2009-04-03 23:30:32 UTC (rev 19527)
@@ -382,6 +382,8 @@
        WM_operatortype_append(ANIM_OT_delete_keyframe);
        WM_operatortype_append(ANIM_OT_insert_keyframe_menu);
        //WM_operatortype_append(ANIM_OT_delete_keyframe_menu);
+       WM_operatortype_append(ANIM_OT_insert_keyframe_button);
+       WM_operatortype_append(ANIM_OT_delete_keyframe_button);
        WM_operatortype_append(ANIM_OT_delete_keyframe_old); // xxx remove?
        
        WM_operatortype_append(ANIM_OT_keyingset_add_new);

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/keyframing.c   
2009-04-03 20:03:09 UTC (rev 19526)
+++ branches/blender2.5/blender/source/blender/editors/animation/keyframing.c   
2009-04-03 23:30:32 UTC (rev 19527)
@@ -2367,6 +2367,134 @@
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+
+/* Insert Key Button Operator ------------------------ */
+
+static int insert_key_button_exec (bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       PointerRNA ptr;
+       PropertyRNA *prop;
+       char *path;
+       float cfra= (float)CFRA; // XXX for now, don't bother about all the 
yucky offset crap
+       short success= 0;
+       int a, index, length, all= RNA_boolean_get(op->ptr, "all");
+       
+       /* try to insert keyframe using property retrieved from UI */
+       uiAnimContextProperty(C, &ptr, &prop, &index);
+
+       if(ptr.data && prop && RNA_property_animateable(ptr.data, prop)) {
+               path= RNA_path_from_ID_to_property(&ptr, prop);
+
+               if(path) {
+                       if(all) {
+                               length= RNA_property_array_length(&ptr, prop);
+
+                               if(length) index= 0;
+                               else length= 1;
+                       }
+                       else
+                               length= 1;
+
+                       for(a=0; a<length; a++)
+                               success+= insertkey(ptr.id.data, NULL, path, 
index+a, cfra, 0);
+
+                       MEM_freeN(path);
+               }
+       }
+       
+       if(success) {
+               /* send updates */
+               ED_anim_dag_flush_update(C);    
+               
+               /* for now, only send ND_KEYS for KeyingSets */
+               WM_event_add_notifier(C, ND_KEYS, NULL);
+       }
+       
+       return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void ANIM_OT_insert_keyframe_button (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Insert Keyframe";
+       ot->idname= "ANIM_OT_insert_keyframe_button";
+       
+       /* callbacks */
+       ot->exec= insert_key_button_exec; 
+       ot->poll= modify_key_op_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_boolean(ot->srna, "all", 1, "All", "Insert a keyframe for all 
element of the array.");
+}
+
+/* Delete Key Button Operator ------------------------ */
+
+static int delete_key_button_exec (bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       PointerRNA ptr;
+       PropertyRNA *prop;
+       char *path;
+       float cfra= (float)CFRA; // XXX for now, don't bother about all the 
yucky offset crap
+       short success= 0;
+       int a, index, length, all= RNA_boolean_get(op->ptr, "all");
+       
+       /* try to insert keyframe using property retrieved from UI */
+       uiAnimContextProperty(C, &ptr, &prop, &index);
+
+       if(ptr.data && prop) {
+               path= RNA_path_from_ID_to_property(&ptr, prop);
+
+               if(path) {
+                       if(all) {
+                               length= RNA_property_array_length(&ptr, prop);
+
+                               if(length) index= 0;
+                               else length= 1;
+                       }
+                       else
+                               length= 1;
+
+                       for(a=0; a<length; a++)
+                               success+= deletekey(ptr.id.data, NULL, path, 
index+a, cfra, 0);
+
+                       MEM_freeN(path);
+               }
+       }
+       
+       
+       if(success) {
+               /* send updates */
+               ED_anim_dag_flush_update(C);    
+               
+               /* for now, only send ND_KEYS for KeyingSets */
+               WM_event_add_notifier(C, ND_KEYS, NULL);
+       }
+       
+       return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void ANIM_OT_delete_keyframe_button (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Delete Keyframe";
+       ot->idname= "ANIM_OT_delete_keyframe_button";
+       
+       /* callbacks */
+       ot->exec= delete_key_button_exec; 
+       ot->poll= modify_key_op_poll;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_boolean(ot->srna, "all", 1, "All", "Delete keyfames from all 
elements of the array.");
+}
+
 /* ******************************************* */
 /* KEYFRAME DETECTION */
 

Modified: 
branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h  
2009-04-03 20:03:09 UTC (rev 19526)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h  
2009-04-03 23:30:32 UTC (rev 19527)
@@ -94,6 +94,11 @@
 void ANIM_OT_delete_keyframe_menu(struct wmOperatorType *ot); // xxx 
unimplemented yet
 void ANIM_OT_delete_keyframe_old(struct wmOperatorType *ot); // xxx rename and 
keep?
 
+/* Keyframe managment operators for UI buttons. */
+
+void ANIM_OT_insert_keyframe_button(struct wmOperatorType *ot);
+void ANIM_OT_delete_keyframe_button(struct wmOperatorType *ot);
+
 /* ************ Auto-Keyframing ********************** */
 /* Notes:
  * - All the defines for this (User-Pref settings and Per-Scene settings)

Modified: 
branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-04-03 20:03:09 UTC (rev 19526)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-04-03 23:30:32 UTC (rev 19527)
@@ -131,6 +131,8 @@
 #define UI_BUT_DISABLED                (1<<18)
 /* dont draw hilite on mouse over */
 #define UI_NO_HILITE           (1<<19)
+#define UI_BUT_ANIMATED                (1<<20)
+#define UI_BUT_ANIMATED_KEY    (1<<21)
 
 /* Button types, bits stored in 1 value... and a short even!
 - bits 0-4:  bitnr (0-31)
@@ -626,5 +628,9 @@
 void uiRegionPanelLayout(const struct bContext *C, struct ARegion *ar, int 
vertical, char *context);
 void uiRegionHeaderLayout(const struct bContext *C, struct ARegion *ar);
 
+/* Animation */
+
+void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, 
struct PropertyRNA **prop, int *index);
+
 #endif /*  UI_INTERFACE_H */
 

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface.c    
2009-04-03 20:03:09 UTC (rev 19526)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface.c    
2009-04-03 23:30:32 UTC (rev 19527)
@@ -33,6 +33,7 @@
 
 #include "DNA_ID.h"
 #include "DNA_listBase.h"
+#include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_userdef_types.h"
@@ -591,6 +592,7 @@
 void uiEndBlock(const bContext *C, uiBlock *block)
 {
        uiBut *but;
+       Scene *scene= CTX_data_scene(C);
 
        /* inherit flags from 'old' buttons that was drawn here previous, based
         * on matching buttons, we need this to make button event handling non
@@ -612,6 +614,8 @@
                /* only update soft range while not editing */
                if(but->rnaprop && !(but->editval || but->editstr || 
but->editvec))
                        ui_set_but_soft_range(but, ui_get_but_val(but));
+
+               ui_but_anim_flag(but, (scene)? scene->r.cfra: 0.0f);
        }
 
        if(block->oldblock) {

Added: 
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c   
                            (rev 0)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c   
    2009-04-03 23:30:32 UTC (rev 19527)
@@ -0,0 +1,121 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_anim_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+
+#include "BLI_listbase.h"
+
+#include "BKE_animsys.h"
+#include "BKE_context.h"
+#include "BKE_fcurve.h"
+
+#include "RNA_access.h"
+#include "RNA_types.h"
+
+#include "UI_interface.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "interface_intern.h"
+
+void ui_but_anim_flag(uiBut *but, float cfra)
+{
+       but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY);
+
+       if(but->rnaprop && but->rnapoin.id.data) {
+               AnimData *adt= BKE_animdata_from_id(but->rnapoin.id.data);
+               FCurve *fcu;
+               char *path;
+
+               if(adt && adt->action && adt->action->curves.first) {
+                       /* XXX this function call can become a performance 
bottleneck */
+                       path= RNA_path_from_ID_to_property(&but->rnapoin, 
but->rnaprop);
+
+                       if(path) {
+                               fcu= list_find_fcurve(&adt->action->curves, 
path, but->rnaindex);
+
+                               if(fcu) {
+                                       but->flag |= UI_BUT_ANIMATED;
+
+                                       if(on_keyframe_fcurve(fcu, cfra))

@@ 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