2.5 - Timeline window now displays keyframe lines again
authorJoshua Leung <aligorith@gmail.com>
Fri, 24 Jul 2009 08:05:56 +0000 (08:05 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 24 Jul 2009 08:05:56 +0000 (08:05 +0000)
* Keyframes for scene-linked animdata is drawn first (if 'Only Selected Data Keys' is off)
* Keyframes are also drawn for the active object

source/blender/editors/animation/anim_ops.c
source/blender/editors/animation/keyframing.c
source/blender/editors/armature/armature_ops.c
source/blender/editors/include/ED_keyframing.h
source/blender/editors/object/object_ops.c
source/blender/editors/space_time/space_time.c
source/blender/editors/space_time/time_header.c
source/blender/editors/space_view3d/view3d_header.c

index 73a1c934d9734d38c774db62d9ee31f76413ee26..7107639b0369672ede546258d14a2e882b08737b 100644 (file)
@@ -386,10 +386,10 @@ void ED_operatortypes_anim(void)
        WM_operatortype_append(ANIM_OT_insert_keyframe);
        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_delete_keyframe_v3d);
        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_add_driver_button);
        WM_operatortype_append(ANIM_OT_remove_driver_button);
index a6f379a9eed14edd60a2e6c389f74f768516a9b6..60d0aa2c7bdf0ba7c7a48afdc35802a767ffd975 100644 (file)
@@ -1223,7 +1223,7 @@ void ANIM_OT_delete_keyframe (wmOperatorType *ot)
  * -- Joshua Leung, Jan 2009
  */
  
-static int delete_key_old_exec (bContext *C, wmOperator *op)
+static int delete_key_v3d_exec (bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        float cfra= (float)CFRA; // XXX for now, don't bother about all the yucky offset crap
@@ -1261,15 +1261,15 @@ static int delete_key_old_exec (bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void ANIM_OT_delete_keyframe_old (wmOperatorType *ot)
+void ANIM_OT_delete_keyframe_v3d (wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Delete Keyframe";
-       ot->idname= "ANIM_OT_delete_keyframe_old";
+       ot->idname= "ANIM_OT_delete_keyframe_v3d";
        
        /* callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= delete_key_old_exec; 
+       ot->exec= delete_key_v3d_exec; 
        
        ot->poll= ED_operator_areaactive;
        
@@ -1347,7 +1347,7 @@ static int insert_key_button_exec (bContext *C, wmOperator *op)
 void ANIM_OT_insert_keyframe_button (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Insert Keyframe";
+       ot->name= "Insert Keyframe (Buttons)";
        ot->idname= "ANIM_OT_insert_keyframe_button";
        
        /* callbacks */
@@ -1355,7 +1355,7 @@ void ANIM_OT_insert_keyframe_button (wmOperatorType *ot)
        ot->poll= modify_key_op_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_UNDO;
 
        /* properties */
        RNA_def_boolean(ot->srna, "all", 1, "All", "Insert a keyframe for all element of the array.");
@@ -1417,7 +1417,7 @@ static int delete_key_button_exec (bContext *C, wmOperator *op)
 void ANIM_OT_delete_keyframe_button (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Delete Keyframe";
+       ot->name= "Delete Keyframe (Buttons)";
        ot->idname= "ANIM_OT_delete_keyframe_button";
        
        /* callbacks */
@@ -1425,7 +1425,7 @@ void ANIM_OT_delete_keyframe_button (wmOperatorType *ot)
        ot->poll= modify_key_op_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_UNDO;
 
        /* properties */
        RNA_def_boolean(ot->srna, "all", 1, "All", "Delete keyfames from all elements of the array.");
index bf4ec09f3fbdc26e2241b1ba06269f263825096d..5de40ecc54fc3f5d3c4c06931f747e2010e702f0 100644 (file)
@@ -275,7 +275,7 @@ void ED_keymap_armature(wmWindowManager *wm)
        
        // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
        WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe_menu", IKEY, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "ANIM_OT_delete_keyframe_old", IKEY, KM_PRESS, KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "ANIM_OT_delete_keyframe_v3d", IKEY, KM_PRESS, KM_ALT, 0);
        
        /* Pose -> PoseLib ------------- */
        /* only set in posemode, by space_view3d listener */
index 3b3d01573625f763e3e794b351431f3ae3cd2ace..64672e3502b1ffa5e5e2ed0999a24e292c57da46 100644 (file)
@@ -110,8 +110,7 @@ void ANIM_OT_delete_keyframe(struct wmOperatorType *ot);
  *     required for each space.
  */
 void ANIM_OT_insert_keyframe_menu(struct wmOperatorType *ot);
-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?
+void ANIM_OT_delete_keyframe_v3d(struct wmOperatorType *ot);
 
 /* Keyframe managment operators for UI buttons. */
 void ANIM_OT_insert_keyframe_button(struct wmOperatorType *ot);
index 9971030bb66c9dfeccabe3fb26e7d130eb11e37e..ad3d13ed5118bb4dcc10ec68dd36cdecd360559e 100644 (file)
@@ -184,7 +184,7 @@ void ED_keymap_object(wmWindowManager *wm)
        
        // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
        WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe_menu", IKEY, KM_PRESS, 0, 0);
-       WM_keymap_verify_item(keymap, "ANIM_OT_delete_keyframe_old", IKEY, KM_PRESS, KM_ALT, 0);
+       WM_keymap_verify_item(keymap, "ANIM_OT_delete_keyframe_v3d", IKEY, KM_PRESS, KM_ALT, 0);
        
        WM_keymap_verify_item(keymap, "GROUP_OT_group_create", GKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove", GKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
index c4ca4d8522fafe151d14fb019e5015f6a57b677b..24afd24740a5dc1b453c32b278874c75c5a04371 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stdio.h>
 
+#include "DNA_object_types.h"
 #include "DNA_space_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_dlrbTree.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
+#include "BKE_utildefines.h"
 
+#include "ED_keyframes_draw.h"
 #include "ED_space_api.h"
 #include "ED_screen.h"
 #include "ED_util.h"
@@ -106,6 +110,95 @@ static void time_draw_sfra_efra(const bContext *C, SpaceTime *stime, ARegion *ar
        fdrawline((float)PEFRA, v2d->cur.ymin, (float)PEFRA, v2d->cur.ymax);
 }
 
+/* helper function - find actkeycolumn that occurs on cframe, or the nearest one if not found */
+static ActKeyColumn *time_cfra_find_ak (ActKeyColumn *ak, float cframe)
+{
+       ActKeyColumn *akn= NULL;
+       
+       /* sanity checks */
+       if (ak == NULL)
+               return NULL;
+       
+       /* check if this is a match, or whether it is in some subtree */
+       if (cframe < ak->cfra)
+               akn= time_cfra_find_ak(ak->left, cframe);
+       else if (cframe > ak->cfra)
+               akn= time_cfra_find_ak(ak->right, cframe);
+               
+       /* if no match found (or found match), just use the current one */
+       if (akn == NULL)
+               return ak;
+       else
+               return akn;
+}
+
+/* helper for time_draw_keyframes() */
+static void time_draw_idblock_keyframes(View2D *v2d, ID *id)
+{
+       DLRBT_Tree keys;
+       ActKeyColumn *ak;
+       
+       /* init binarytree-list for getting keyframes */
+       BLI_dlrbTree_init(&keys);
+       
+       /* populate tree with keyframe nodes */
+       switch (GS(id->name)) {
+               case ID_SCE:
+                       scene_to_keylist(NULL, (Scene *)id, &keys, NULL);
+                       break;
+               case ID_OB:
+                       ob_to_keylist(NULL, (Object *)id, &keys, NULL);
+                       break;
+       }
+               
+       /* build linked-list for searching */
+       BLI_dlrbTree_linkedlist_sync(&keys);
+       
+       /* start drawing keyframes 
+        *      - we use the binary-search capabilities of the tree to only start from 
+        *        the first visible keyframe (last one can then be easily checked)
+        *      - draw within a single GL block to be faster
+        */
+       glBegin(GL_LINES);
+               for ( ak=time_cfra_find_ak(keys.root, v2d->cur.xmin); 
+                        (ak) && (ak->cfra <= v2d->cur.xmax); 
+                         ak=ak->next ) 
+               {
+                       glVertex2f(ak->cfra, v2d->cur.ymin);
+                       glVertex2f(ak->cfra, v2d->cur.ymax);
+               }
+       glEnd(); // GL_LINES
+               
+       /* free temp stuff */
+       BLI_dlrbTree_free(&keys);
+}
+
+/* draw keyframe lines for timeline */
+static void time_draw_keyframes(const bContext *C, SpaceTime *stime, ARegion *ar)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       View2D *v2d= &ar->v2d;
+       
+       /* draw scene keyframes first 
+        *      - only if we're not only showing the 
+        */
+       if ((scene) && (stime->flag & TIME_ONLYACTSEL)==0) {
+               /* set draw color */
+               glColor3ub(0xDD, 0xA7, 0x00);
+               time_draw_idblock_keyframes(v2d, (ID *)scene);
+       }
+       
+       /* draw active object's keyframes */
+       if (ob) {
+               /* set draw color */
+               glColor3ub(0xDD, 0xD7, 0x00);
+               time_draw_idblock_keyframes(v2d, (ID *)ob);
+       }
+}
+
+/* ---------------- */
+
 /* add handlers, stuff you only do once or on area/region changes */
 static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
 {
@@ -118,7 +211,6 @@ static void time_main_area_init(wmWindowManager *wm, ARegion *ar)
        WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
 }
 
-
 static void time_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
@@ -144,7 +236,10 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
        grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
        UI_view2d_grid_draw(C, v2d, grid, (V2D_VERTICAL_LINES|V2D_VERTICAL_AXIS));
        UI_view2d_grid_free(grid);
-
+       
+       /* keyframes */
+       time_draw_keyframes(C, stime, ar);
+       
        /* current frame */
        time_draw_cfra_time(C, stime, ar);
        
index 739c23e8579520a7f30062fa27ad2e87aa395a69..84c73c8d8a4b43b3c2ae6387cd9e3ca6b85534a4 100644 (file)
@@ -448,17 +448,6 @@ void do_time_buttons(bContext *C, void *arg, int event)
                        //BIF_undo_push("Set anim-preview range");
                        WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
                        break;
-                       
-               case B_TL_INSERTKEY:
-                       /* insert keyframe */
-                       //common_insertkey();
-                       //allqueue(REDRAWTIME, 1);
-                       break;
-               case B_TL_DELETEKEY:
-                       /* delete keyframe */
-                       //common_deletekey();
-                       //allqueue(REDRAWTIME, 1);
-                       break;
        }
 }
 
index 4781e0e010841290fd82f93df6c107c091de024c..f2a386c81baccad08106bf79fd9c0f9d4c38d9a9 100644 (file)
@@ -2093,7 +2093,7 @@ static void view3d_edit_objectmenu(bContext *C, uiLayout *layout, void *arg_unus
 
        // TODO: these operators may get renamed
        uiItemO(layout, NULL, 0, "ANIM_OT_insert_keyframe_menu");
-       uiItemO(layout, NULL, 0, "ANIM_OT_delete_keyframe_old");
+       uiItemO(layout, NULL, 0, "ANIM_OT_delete_keyframe_v3d");
        
        uiItemS(layout);
        
@@ -3166,7 +3166,7 @@ static void view3d_pose_armaturemenu(bContext *C, uiLayout *layout, void *arg_un
        
        // TODO: these operators may get renamed
        uiItemO(layout, NULL, 0, "ANIM_OT_insert_keyframe_menu");
-       uiItemO(layout, NULL, 0, "ANIM_OT_delete_keyframe_old");
+       uiItemO(layout, NULL, 0, "ANIM_OT_delete_keyframe_v3d");
 
        uiItemS(layout);