KeyingSets: More work on preparing the UI
authorJoshua Leung <aligorith@gmail.com>
Thu, 12 Feb 2009 01:11:29 +0000 (01:11 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 12 Feb 2009 01:11:29 +0000 (01:11 +0000)
KeyingSets can now be added/removed. Next up, the code for the operators to add items to Keying Sets.

source/blender/editors/animation/keyframing.c
source/blender/editors/include/ED_keyframing.h
source/blender/editors/space_outliner/outliner.c
source/blender/editors/space_outliner/outliner_header.c
source/blender/editors/space_outliner/space_outliner.c
source/blender/editors/space_time/space_time.c
source/blender/editors/space_time/time_header.c
source/blender/makesdna/DNA_space_types.h
source/blender/windowmanager/WM_types.h

index 42ed4fddc99008c1cf53610f03ba8d40eddbc52c..08ee83277a8610881138fba7a3cfa3c169d87231 100644 (file)
@@ -877,23 +877,32 @@ enum {
 /* Build menu-string of available keying-sets (allocates memory for string)
  * NOTE: mode must not be longer than 64 chars
  */
-char *ANIM_build_keyingsets_menu (ListBase *list)
+char *ANIM_build_keyingsets_menu (ListBase *list, short for_edit)
 {
        DynStr *pupds= BLI_dynstr_new();
        KeyingSet *ks;
        char buf[64];
        char *str;
+       int i;
        
        /* add title first */
        BLI_dynstr_append(pupds, "Keying Sets%t|");
        
-       /* add dummy entry for none-active */
-       BLI_dynstr_append(pupds, "<No Keying Set Active>%x0|");
+       /* add dummy entries for none-active */
+       if (for_edit) { 
+               BLI_dynstr_append(pupds, "Add New%x-1|");
+               BLI_dynstr_append(pupds, " %x0|");
+       }
+       else
+               BLI_dynstr_append(pupds, "<No Keying Set Active>%x0|");
        
        /* loop through keyingsets, adding them */
-       for (ks= list->first; ks; ks= ks->next) {
+       for (ks=list->first, i=1; ks; ks=ks->next, i++) {
+               if (for_edit == 0)
+                       BLI_dynstr_append(pupds, "KS: ");
+               
                BLI_dynstr_append(pupds, ks->name);
-               BLI_snprintf( buf, 64, "%s", ((ks->next)?"|":"") );
+               BLI_snprintf( buf, 64, "%%x%d%s", i, ((ks->next)?"|":"") );
                BLI_dynstr_append(pupds, buf);
        }
        
index e7441188fc30160b1b07da506281dc39fc8db161..d310066c9994093a4ae80b56b0b0d007bdb5e8f3 100644 (file)
@@ -84,7 +84,7 @@ short deletekey(struct ID *id, const char group[], const char rna_path[], int ar
 
 
 /* Generate menu of KeyingSets */
-char *ANIM_build_keyingsets_menu(struct ListBase *list);
+char *ANIM_build_keyingsets_menu(struct ListBase *list, short for_edit);
 
 /* Main Keyframe Management operators: 
  *     These handle keyframes management from various spaces. They will handle the menus 
index 7d06c98577d598a5772c0aa6555f279eae47ead9..dafe0cb4e0341535c1f879601da82923b56887d3 100644 (file)
@@ -3105,8 +3105,10 @@ static KeyingSet *verify_active_keyingset(Scene *scene, short add)
                
        /* add if none found */
        // XXX the default settings have yet to evolve
-       if ((add) && (ks==NULL))
+       if ((add) && (ks==NULL)) {
                ks= BKE_keyingset_add(&scene->keyingsets, "KeyingSet", KEYINGSET_ABSOLUTE, 0);
+               scene->active_keyingset= BLI_countlist(&scene->keyingsets);
+       }
        
        return ks;
 }
index 7add3f85ea0a73b162367fa0f8166e335b8fc0ad..f5b93254693d5883f5b48157223bf4cef5383f67 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 
 #include "DNA_ID.h"
+#include "DNA_anim_types.h"
 #include "DNA_space_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
@@ -39,6 +40,7 @@
 
 #include "BLI_blenlib.h"
 
+#include "BKE_animsys.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
@@ -159,15 +161,51 @@ static uiBlock *outliner_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
        return block;
 }
 
-#define B_REDR 1
+enum {
+       B_REDR  = 1,
+       
+       B_KEYINGSET_CHANGE,
+       B_KEYINGSET_REMOVE,
+} eOutlinerHeader_Events;
+
 static void do_outliner_buttons(bContext *C, void *arg, int event)
 {
        ScrArea *sa= CTX_wm_area(C);
+       Scene *scene= CTX_data_scene(C);
        
        switch(event) {
                case B_REDR:
                        ED_area_tag_redraw(sa);
                        break;
+                       
+               case B_KEYINGSET_CHANGE:
+                       /* add a new KeyingSet if active is -1 */
+                       if (scene->active_keyingset == -1) {
+                               // XXX the default settings have yet to evolve... need to keep this in sync with the 
+                               BKE_keyingset_add(&scene->keyingsets, "KeyingSet", KEYINGSET_ABSOLUTE, 0);
+                               scene->active_keyingset= BLI_countlist(&scene->keyingsets);
+                       }
+                       
+                       /* redraw regions with KeyingSet info */
+                       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, scene);
+                       break;
+                       
+               case B_KEYINGSET_REMOVE:
+                       /* remove the active KeyingSet */
+                       if (scene->active_keyingset) {
+                               KeyingSet *ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1);
+                               
+                               /* firstly free KeyingSet's data, then free the KeyingSet itself */
+                               if (ks) {
+                                       BKE_keyingset_free(ks);
+                                       BLI_freelinkN(&scene->keyingsets, ks);
+                                       scene->active_keyingset= 0;
+                               }
+                       }
+                       
+                       /* redraw regions with KeyingSet info */
+                       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, scene);
+                       break;
        }
 }
 
@@ -175,6 +213,7 @@ static void do_outliner_buttons(bContext *C, void *arg, int event)
 void outliner_header_buttons(const bContext *C, ARegion *ar)
 {
        ScrArea *sa= CTX_wm_area(C);
+       Scene *scene= CTX_data_scene(C);
        SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
        uiBlock *block;
        int xco, yco= 3, xmax;
@@ -201,13 +240,63 @@ void outliner_header_buttons(const bContext *C, ARegion *ar)
        }
        
        //if (outliner->type==SO_OUTLINER) {
+               /* data selector*/
                if(G.main->library.first) 
                        uiDefButS(block, MENU, B_REDR, "Outliner Display%t|Libraries %x7|All Scenes %x0|Current Scene %x1|Visible Layers %x2|Groups %x6|Same Types %x5|Selected %x3|Active %x4|Sequence %x10|Datablocks %x11|User Preferences %x12",     xco, yco, 120, 20,  &soutliner->outlinevis, 0, 0, 0, 0, "");
                else
-                       uiDefButS(block, MENU, B_REDR, "Outliner Display%t|All Scenes %x0|Current Scene %x1|Visible Layers %x2|Groups %x6|Same Types %x5|Selected %x3|Active %x4|Sequence %x10|Datablocks %x11|User Preferences %x12",   xco, yco, 120, 20,  &soutliner->outlinevis, 0, 0, 0, 0, "");
+                       uiDefButS(block, MENU, B_REDR, "Outliner Display%t|All Scenes %x0|Current Scene %x1|Visible Layers %x2|Groups %x6|Same Types %x5|Selected %x3|Active %x4|Sequence %x10|Datablocks %x11|User Preferences %x12",   xco, yco, 120, 20,  &soutliner->outlinevis, 0, 0, 0, 0, "");   
+               xco += 120;
+               
+               /* KeyingSet editing buttons */
+               if ((soutliner->flag & SO_HIDE_KEYINGSETINFO)==0 && (soutliner->outlinevis==SO_DATABLOCKS)) {
+                       KeyingSet *ks= NULL;
+                       char *menustr= NULL;
+                       
+                       xco+= (int)(XIC*1.5);
+                       
+                       if (scene->active_keyingset)
+                               ks= (KeyingSet *)BLI_findlink(&scene->keyingsets, scene->active_keyingset-1);
+                       
+                       uiBlockBeginAlign(block);
+                               /* currently 'active' KeyingSet */
+                               menustr= ANIM_build_keyingsets_menu(&scene->keyingsets, 1);
+                               uiDefButI(block, MENU, B_KEYINGSET_CHANGE, menustr, xco,yco, 18,20, &scene->active_keyingset, 0, 0, 0, 0, "Browse Keying Sets");
+                               MEM_freeN(menustr);
+                               xco += 18;
+                               
+                               /* currently 'active' KeyingSet - change name */
+                               if (ks) {
+                                       /* active KeyingSet */
+                                       uiDefBut(block, TEX, B_KEYINGSET_CHANGE,"", xco,yco,120,20, ks->name, 0, 63, 0, 0, "Name of Active Keying Set");
+                                       xco += 120;
+                                       uiDefIconBut(block, BUT, B_KEYINGSET_REMOVE, VICON_X, xco, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove this Keying Set");
+                                       xco += 20;
+                               }
+                               else {
+                                       /* no active KeyingSet... so placeholder instead */
+                                       uiDefBut(block, LABEL, 0,"<No Keying Set Active>", xco,yco,140,20, NULL, 0, 63, 0, 0, "Name of Active Keying Set");
+                                       xco += 140;
+                               }
+                       uiBlockEndAlign(block);
+                       
+                       /* current 'active' KeyingSet */
+                       if (ks) {
+                               xco += 5;
+                               
+                               /* operator buttons to add/remove selected items from set */
+                               uiBlockBeginAlign(block);
+                                               // XXX the icons here are temporary
+                                       uiDefIconButO(block, BUT, "OUTLINER_OT_keyingset_remove_selected", WM_OP_INVOKE_REGION_WIN, ICON_ZOOMOUT, xco,yco,XIC,YIC, "Remove selected properties from active Keying Set (Alt-K)");
+                                       xco += XIC;
+                                       uiDefIconButO(block, BUT, "OUTLINER_OT_keyingset_add_selected", WM_OP_INVOKE_REGION_WIN, ICON_ZOOMIN, xco,yco,XIC,YIC, "Add selected properties to active Keying Set (K)");
+                                       xco += XIC;
+                               uiBlockEndAlign(block);
+                       }
+                       
+                       xco += XIC*2;
+               }
        //}
        
-       
        /* always as last  */
        UI_view2d_totRect_set(&ar->v2d, xco+XIC+100, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
        
index 69f57d507b9cf9228e8907a8af79a18134fd091d..b8187309c0d63dc87fe0a4a2c406664fe216361b 100644 (file)
@@ -119,6 +119,7 @@ static void outliner_main_area_listener(ARegion *ar, wmNotifier *wmn)
                                case ND_OB_ACTIVE:
                                case ND_OB_SELECT:
                                case ND_MODE:
+                               case ND_KEYINGSET:
                                        ED_region_tag_redraw(ar);
                                        break;
                        }
@@ -170,6 +171,17 @@ static void outliner_header_area_free(ARegion *ar)
 {
 }
 
+static void outliner_header_area_listener(ARegion *ar, wmNotifier *wmn)
+{
+       /* context changes */
+       switch(wmn->category) {
+               case NC_SCENE:
+                       if(wmn->data == ND_KEYINGSET)
+                               ED_region_tag_redraw(ar);
+                       break;
+       }
+}
+
 /* ******************** default callbacks for outliner space ***************** */
 
 static SpaceLink *outliner_new(const bContext *C)
@@ -289,6 +301,7 @@ void ED_spacetype_outliner(void)
        art->init= outliner_header_area_init;
        art->draw= outliner_header_area_draw;
        art->free= outliner_header_area_free;
+       art->listener= outliner_header_area_listener;
        BLI_addhead(&st->regiontypes, art);
        
        BKE_spacetype_register(st);
index d28fdc7f371ace1e93aaeacb0b6e6f74e8dfa70e..3df57208bbd49c61b767ef99a2acbb05d1e10c2b 100644 (file)
@@ -207,11 +207,13 @@ static void time_header_area_listener(ARegion *ar, wmNotifier *wmn)
 {
        /* context changes */
        switch(wmn->category) {
-               
                case NC_SCENE:
-                       if(wmn->data==ND_FRAME)
-                               ED_region_tag_redraw(ar);
-                       break;
+                       switch (wmn->data) {
+                               case ND_FRAME:
+                               case ND_KEYINGSET:
+                                       ED_region_tag_redraw(ar);
+                               break;
+                       }
        }
 }
 
index 1f03530b6807997dfae97fb6a7e2999295ec25d5..38c0f2dfc1dd5a40de8fb32f706e7ef308715a06 100644 (file)
@@ -542,7 +542,7 @@ void time_header_buttons(const bContext *C, ARegion *ar)
        xco+= 16;
        
        
-       menustr= ANIM_build_keyingsets_menu(&scene->keyingsets);
+       menustr= ANIM_build_keyingsets_menu(&scene->keyingsets, 0);
        uiDefButI(block, MENU, B_DIFF, 
                                  menustr, 
                                  xco, yco, (int)5.5*XIC, YIC, &(scene->active_keyingset), 0, 1, 0, 0, 
index a1d8c5cd13b648f0ade04b7acd409631836eb722..678179f6f6041b0949a97c8785d9fde252d754d9 100644 (file)
@@ -619,6 +619,7 @@ enum {
 #define SO_TESTBLOCKS  1
 #define SO_NEWSELECTED 2
 #define SO_HIDE_RESTRICTCOLS           4
+#define SO_HIDE_KEYINGSETINFO          8
 
 /* SpaceOops->visiflag */
 #define OOPS_SCE       1
index a8fb42c4ed0896ad4648ae39afaafb39c9c9d3f4..2e7b31b070060a13a64847aad4fcfc542d6d429f 100644 (file)
@@ -176,6 +176,7 @@ typedef struct wmNotifier {
 #define ND_MODE                                (9<<16)
 #define ND_RENDER_RESULT       (10<<16)
 #define ND_COMPO_RESULT                (11<<16)
+#define ND_KEYINGSET           (12<<16)
 
        /* NC_OBJECT Object */
 #define        ND_TRANSFORM            (16<<16)