== Action Editor - NKEY Properties Panel ==
authorJoshua Leung <aligorith@gmail.com>
Sat, 12 Jul 2008 05:00:37 +0000 (05:00 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sat, 12 Jul 2008 05:00:37 +0000 (05:00 +0000)
When the NKEY is pressed in the Action Editor while hovering over the keyframes area, a floating properties panel can now be accessed. It shows relevant properties for the active channel, however this is currently only for Action Groups. Action Channel support will come later.

The key benefit of this panel is that it is now possible to edit the colour set used by a group. Also, there is a button for selecting all the channels in that group (which can also be done by simply Ctrl-Shift clicking on any group).

source/blender/include/BIF_editaction.h
source/blender/include/BIF_resources.h
source/blender/include/blendef.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/src/buttons_editing.c
source/blender/src/drawaction.c
source/blender/src/editaction.c
source/blender/src/resources.c

index 2d751f56fc5b18f732961a16d05e7bc0e31bbf3d..7e0f703681b4aec57c1a7b34323d450aa8c2e7dd 100644 (file)
@@ -141,6 +141,7 @@ void paste_actdata(void);
 /* Group/Channel Operations */
 struct bActionGroup *get_active_actiongroup(struct bAction *act);
 void set_active_actiongroup(struct bAction *act, struct bActionGroup *agrp, short select);
+void actionbone_group_copycolors(struct bActionGroup *grp, short init_new);
 void verify_pchan2achan_grouping(struct bAction *act, struct bPose *pose, char name[]);
 void sync_pchan2achan_grouping(void); 
 void action_groups_group(short add_group);
@@ -166,6 +167,7 @@ void deselect_action_channels(short mode);
 void deselect_actionchannels(struct bAction *act, short mode);
 int select_channel(struct bAction *act, struct bActionChannel *achan, int selectmode);
 void select_actionchannel_by_name(struct bAction *act, char *name, int select);
+void select_action_group_channels(struct bAction *act, struct bActionGroup *agrp);
 void selectkeys_leftright (short leftright, short select_mode);
 
 /* Action Markers */
index e6cbe7bb69aa1aa02fcfa2c6a03eb2fbc2df60c3..df514190270acb8b7d95e9aac3ecb5fec1be0f62 100644 (file)
@@ -591,6 +591,9 @@ void        BIF_load_ui_colors              (void);
 char   *BIF_ThemeGetColorPtr(struct bTheme *btheme, int spacetype, int colorid);
 char   *BIF_ThemeColorsPup(int spacetype);
 
+/* only for Bone Color sets */
+char *BIF_ThemeColorSetsPup(short inc_custom);
+
 
 void   BIF_def_color                   (BIFColorID colorid, unsigned char r, unsigned char g, unsigned char b);
 
index a798224b35b4b20694c3ae08f6bad7e443774c92..6f8b94d7cd177a4be1c4f4226b111ba89ae96c25 100644 (file)
 #define B_ACTCOPYKEYS          710
 #define B_ACTPASTEKEYS         711
 
+#define B_ACTCUSTCOLORS                712
+#define B_ACTCOLSSELECTOR      713
+#define B_ACTGRP_SELALL                714
+#define B_ACTGRP_ADDTOSELF     715
+#define B_ACTGRP_UNGROUP       716
+
 /* TIME: 751 - 800 */
 #define B_TL_REW               751
 #define B_TL_PLAY              752
index 3de5b0ff5baf5ba1921159ed09f9ca3f0c7b59c9..cd1c047dac9a24e8b87510ea2ebe759174b6d488 100644 (file)
@@ -116,6 +116,7 @@ typedef struct ThemeWireColor {
 
 /* flags for ThemeWireColor */
 #define TH_WIRECOLOR_CONSTCOLS (1<<0)
+#define TH_WIRECOLOR_TEXTCOLS  (1<<1)
 
 /* A theme */
 typedef struct bTheme {
index 7eff79fec88da0348d371a04e5bea787ab80792e..3863161017f42f9e9c2487189a4fd8dbf6e9e6a0 100644 (file)
@@ -5153,32 +5153,6 @@ static void verify_posegroup_groupname(void *arg1, void *arg2)
        BLI_uniquename(&pose->agroups, grp, "Group", offsetof(bActionGroup, name), 32);
 }
 
-static char *build_colorsets_menustr ()
-{
-       DynStr *pupds= BLI_dynstr_new();
-       char *str;
-       char buf[48];
-       int i;
-       
-       /* add title first (and the "default" entry) */
-       BLI_dynstr_append(pupds, "Bone Color Set%t|Default Colors%x0|");
-       
-       /* loop through set indices, adding them */
-       for (i=1; i<21; i++) {
-               sprintf(buf, "%d - Theme Color Set%%x%d|", i, i);
-               BLI_dynstr_append(pupds, buf);
-       }
-       
-       /* add the 'custom' entry */
-       BLI_dynstr_append(pupds, "Custom Set %x-1");
-       
-       /* convert to normal MEM_malloc'd string */
-       str= BLI_dynstr_get_cstring(pupds);
-       BLI_dynstr_free(pupds);
-       
-       return str;
-}
-
 static void editing_panel_links(Object *ob)
 {
        uiBlock *block;
@@ -5338,32 +5312,14 @@ static void editing_panel_links(Object *ob)
                        /* color set for 'active' group */
                        if (pose->active_group && grp) {
                                uiBlockBeginAlign(block);
-                                       menustr= build_colorsets_menustr();
+                                       menustr= BIF_ThemeColorSetsPup(1);
                                        uiDefButI(block, MENU,B_POSEGRP_RECALC, menustr, xco,85,140,19, &grp->customCol, -1, 20, 0.0, 0.0, "Index of set of Custom Colors to shade Group's bones with. 0 = Use Default Color Scheme, -1 = Use Custom Color Scheme");                                            
                                        MEM_freeN(menustr);
                                        
                                        /* show color-selection/preview */
                                        if (grp->customCol) {
-                                               if (grp->customCol > 0) {
-                                                       /* copy theme colors on-to group's custom color in case user tries to edit color */
-                                                       bTheme *btheme= U.themes.first;
-                                                       ThemeWireColor *col_set= &btheme->tarm[(grp->customCol - 1)];
-                                                       
-                                                       memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
-                                               }
-                                               else {
-                                                       /* init custom colors with a generic multi-color rgb set, if not initialised already */
-                                                       if (grp->cs.solid[0] == 0) {
-                                                               /* define for setting colors in theme below */
-                                                               #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
-                                                               
-                                                               SETCOL(grp->cs.solid, 0xff, 0x00, 0x00, 255);
-                                                               SETCOL(grp->cs.select, 0x81, 0xe6, 0x14, 255);
-                                                               SETCOL(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
-                                                               
-                                                               #undef SETCOL
-                                                       }
-                                               }
+                                               /* do color copying/init (to stay up to date) */
+                                               actionbone_group_copycolors(grp, 1);
                                                
                                                /* color changing */
                                                uiDefButC(block, COL, B_POSEGRP_MCUSTOM, "",            xco, 65, 30, 19, grp->cs.solid, 0, 0, 0, 0, "Color to use for surface of bones");
index 89466151a39f9216e6cbdac597c95587ae4b35e5..6fe37c1c6e50b569773ba527b55ce448d97d9982 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <math.h>
 #include <stdlib.h>
+#include <string.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -56,6 +57,7 @@
 #include "DNA_space_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_key_types.h"
+#include "DNA_userdef_types.h"
 
 #include "BKE_action.h"
 #include "BKE_depsgraph.h"
@@ -928,12 +930,55 @@ static void draw_channel_strips(void)
 void do_actionbuts(unsigned short event)
 {
        switch(event) {
+               /* general */
        case REDRAWVIEW3D:
                allqueue(REDRAWVIEW3D, 0);
                break;
        case B_REDR:
                allqueue(REDRAWACTION, 0);
                break;
+               
+               /* action-groups */
+       case B_ACTCUSTCOLORS:   /* only when of the color wells is edited */
+       {
+               bActionGroup *agrp= get_active_actiongroup(G.saction->action);
+               
+               if (agrp)
+                       agrp->customCol= -1;
+                       
+               allqueue(REDRAWACTION, 0);
+       }
+               break;
+       case B_ACTCOLSSELECTOR: /* sync color set after using selector */
+       {
+               bActionGroup *agrp= get_active_actiongroup(G.saction->action);
+               
+               if (agrp) 
+                       actionbone_group_copycolors(agrp, 1);
+                       
+               allqueue(REDRAWACTION, 0);
+       }
+               break;
+       case B_ACTGRP_SELALL: /* select all grouped channels */
+       {
+               bAction *act= G.saction->action;
+               bActionGroup *agrp= get_active_actiongroup(act);
+               
+               /* select all in group, then reselect/activate group as the previous operation clears that */
+               select_action_group_channels(act, agrp);
+               agrp->flag |= (AGRP_ACTIVE|AGRP_SELECTED);
+               
+               allqueue(REDRAWACTION, 0);
+       }
+               break;
+       case B_ACTGRP_ADDTOSELF: /* add all selected action channels to self */
+               action_groups_group(0);
+               break;
+       case B_ACTGRP_UNGROUP: /* remove channels from active group */
+               // FIXME: todo...
+               printf("FIXME: remove achans from active Action-Group not implemented yet! \n");
+               break;
+       
        }
 }
 
@@ -941,14 +986,68 @@ void do_actionbuts(unsigned short event)
 static void action_panel_properties(short cntrl)       // ACTION_HANDLER_PROPERTIES
 {
        uiBlock *block;
-
+       void *data;
+       short datatype;
+       
        block= uiNewBlock(&curarea->uiblocks, "action_panel_properties", UI_EMBOSS, UI_HELV, curarea->win);
        uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
        uiSetPanelHandler(ACTION_HANDLER_PROPERTIES);  // for close and esc
-       if (uiNewPanel(curarea, block, "Transform Properties", "Action", 10, 230, 318, 204)==0) 
+       
+       /* get datatype */
+       data= get_action_context(&datatype);
+       //if (data == NULL) return;
+       
+       if (uiNewPanel(curarea, block, "Active Channel Properties", "Action", 10, 230, 318, 204)==0) 
                return;
-
-       uiDefBut(block, LABEL, 0, "test text",          10,180,300,19, 0, 0, 0, 0, 0, "");
+       
+       /* currently, only show data for actions */
+       if (datatype == ACTCONT_ACTION) {
+               bActionGroup *agrp= get_active_actiongroup(data);
+               //bActionChannel *achan= get_hilighted_action_channel(data);
+               char *menustr;
+               
+               /* only for action-groups */
+               if (agrp) {
+                       /* general stuff */
+                       uiDefBut(block, LABEL, 1, "Action Group:",                                      10, 180, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
+                       
+                       uiDefBut(block, TEX, B_REDR, "Name: ",  10,160,150,20, agrp->name, 0.0, 31.0, 0, 0, "");
+                       uiBlockBeginAlign(block);
+                               uiDefButBitI(block, TOG, AGRP_EXPANDED, B_REDR, "Expanded", 170, 160, 75, 20, &agrp->flag, 0, 0, 0, 0, "Action Group is expanded");
+                               uiDefButBitI(block, TOG, AGRP_PROTECTED, B_REDR, "Protected", 245, 160, 75, 20, &agrp->flag, 0, 0, 0, 0, "Action Group is protected");
+                       uiBlockEndAlign(block);
+                       
+                       /* color stuff */
+                       uiDefBut(block, LABEL, 1, "Group Colors:",      10, 107, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
+                       uiBlockBeginAlign(block);
+                               menustr= BIF_ThemeColorSetsPup(1);
+                               uiDefButI(block, MENU,B_ACTCOLSSELECTOR, menustr, 10,85,150,19, &agrp->customCol, -1, 20, 0.0, 0.0, "Index of set of Custom Colors to shade Group's bones with. 0 = Use Default Color Scheme, -1 = Use Custom Color Scheme");                                           
+                               MEM_freeN(menustr);
+                               
+                               /* show color-selection/preview */
+                               if (agrp->customCol) {
+                                       /* do color copying/init (to stay up to date) */
+                                       actionbone_group_copycolors(agrp, 1);
+                                       
+                                       /* color changing */
+                                       uiDefButC(block, COL, B_ACTCUSTCOLORS, "",              10, 65, 50, 19, agrp->cs.active, 0, 0, 0, 0, "Color to use for 'top-level' channels");
+                                       uiDefButC(block, COL, B_ACTCUSTCOLORS, "",              60, 65, 50, 19, agrp->cs.select, 0, 0, 0, 0, "Color to use for '2nd-level' channels");
+                                       uiDefButC(block, COL, B_ACTCUSTCOLORS, "",              110, 65, 50, 19, agrp->cs.solid, 0, 0, 0, 0, "Color to use for '3rd-level' channels");
+                               }
+                       uiBlockEndAlign(block);
+                       
+                       /* commands for active group */
+                       uiDefBut(block, BUT, B_ACTGRP_SELALL, "Select Grouped", 170,85,150,20, 0, 21, 0, 0, 0, "Select all action-channels belonging to this group (same as doing Ctrl-Shift-LMB)");
+                       
+                       uiBlockBeginAlign(block);
+                               uiDefBut(block, BUT, B_ACTGRP_ADDTOSELF, "Add to Group",        170,60,150,20, 0, 21, 0, 0, 0, "Add selected action-channels to this group");
+                               uiDefBut(block, BUT, B_ACTGRP_UNGROUP, "Un-Group",      170,40,150,20, 0, 21, 0, 0, 0, "Remove selected action-channels from this group (unimplemented)");
+                       uiBlockEndAlign(block);
+               }
+       }
+       else {
+               /* Currently, there isn't anything to display for these types ... */
+       }
 }
 
 static void action_blockhandlers(ScrArea *sa)
index f93a1526e3cb891d53a389e24115595736f4531a..4cc0e52ce3f757a85ba8a39ac921310bf66c8157 100644 (file)
@@ -1114,6 +1114,38 @@ void action_groups_ungroup (void)
        allqueue(REDRAWACTION, 0);
 }
 
+/* Copy colors from a specified theme's color set to an Action/Bone Group */
+void actionbone_group_copycolors (bActionGroup *grp, short init_new)
+{
+       /* error checking */
+       if (grp == NULL)
+               return;
+       
+       /* only do color copying if using a custom color */
+       if (grp->customCol) {
+               if (grp->customCol > 0) {
+                       /* copy theme colors on-to group's custom color in case user tries to edit color */
+                       bTheme *btheme= U.themes.first;
+                       ThemeWireColor *col_set= &btheme->tarm[(grp->customCol - 1)];
+                       
+                       memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
+               }
+               else if (init_new) {
+                       /* init custom colors with a generic multi-color rgb set, if not initialised already (and allowed to do so) */
+                       if (grp->cs.solid[0] == 0) {
+                               /* define for setting colors in theme below */
+                               #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
+                               
+                               SETCOL(grp->cs.solid, 0xff, 0x00, 0x00, 255);
+                               SETCOL(grp->cs.select, 0x81, 0xe6, 0x14, 255);
+                               SETCOL(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
+                               
+                               #undef SETCOL
+                       }
+               }
+       }
+}
+
 /* This function is used when inserting keyframes for pose-channels. It assigns the
  * action-channel with the nominated name to a group with the same name as that of 
  * the pose-channel with the nominated name.
@@ -1160,34 +1192,9 @@ void verify_pchan2achan_grouping (bAction *act, bPose *pose, char name[])
                        /* copy name */
                        sprintf(grp->name, agrp->name);
                        
-                       /* deal with group-color copying */
-                       if (agrp->customCol) {
-                               if (agrp->customCol > 0) {
-                                       /* copy theme colors on-to group's custom color in case user tries to edit color */
-                                       bTheme *btheme= U.themes.first;
-                                       ThemeWireColor *col_set= &btheme->tarm[(agrp->customCol - 1)];
-                                       
-                                       memcpy(&grp->cs, col_set, sizeof(ThemeWireColor));
-                               }
-                               else {
-                                       /* init custom colors with a generic multi-color rgb set, if not initialised already */
-                                       if (agrp->cs.solid[0] == 0) {
-                                               /* define for setting colors in theme below */
-                                               #define SETCOL(col, r, g, b, a)  col[0]=r; col[1]=g; col[2]= b; col[3]= a;
-                                               
-                                               SETCOL(grp->cs.solid, 0xff, 0x00, 0x00, 255);
-                                               SETCOL(grp->cs.select, 0x81, 0xe6, 0x14, 255);
-                                               SETCOL(grp->cs.active, 0x18, 0xb6, 0xe0, 255);
-                                               
-                                               #undef SETCOL
-                                       }
-                                       else {
-                                               /* just copy color set specified */
-                                               memcpy(&grp->cs, &agrp->cs, sizeof(ThemeWireColor));
-                                       }
-                               }
-                       }
-                       grp->customCol= agrp->customCol;
+                       /* deal with group-color copying (grp is destination, agrp is source) */
+                       memcpy(grp, agrp, sizeof(bActionGroup));
+                       actionbone_group_copycolors(grp, 1);
                        
                        BLI_addtail(&act->groups, grp);
                }
@@ -2697,6 +2704,28 @@ int select_icu_channel(bAction *act, IpoCurve *icu, int selectmode)
        return flag;
 }
 
+
+/* select only the active action-group's action channels */
+void select_action_group_channels (bAction *act, bActionGroup *agrp)
+{
+       bActionChannel *achan;
+       
+       /* error checking */
+       if (ELEM(NULL, act, agrp))
+               return;
+       
+       /* deselect all other channels */
+       deselect_actionchannels(act, 0);
+       
+       /* only select channels in group */
+       for (achan= agrp->channels.first; achan && achan->grp==agrp; achan= achan->next) {
+               select_channel(act, achan, SELECT_ADD);
+               
+               /* messy... set active bone */
+               select_poseelement_by_name(achan->name, 1);
+       }
+}
+
 /* ----------------------------------------- */
 
 /* De-selects or inverts the selection of Channels in a given Action 
@@ -3672,17 +3701,8 @@ static void mouse_actionchannels (short mval[])
                                                select_action_group(act, agrp, SELECT_INVERT);
                                        }
                                        else if (G.qual == (LR_CTRLKEY|LR_SHIFTKEY)) {
-                                               bActionChannel *achan;
-                                               
                                                /* select all in group (and deselect everthing else) */ 
-                                               deselect_actionchannels(act, 0);
-                                               
-                                               for (achan= agrp->channels.first; achan && achan->grp==agrp; achan= achan->next) {
-                                                       select_channel(act, achan, SELECT_ADD);
-                                                       
-                                                       /* messy... set active bone */
-                                                       select_poseelement_by_name(achan->name, 1);
-                                               }
+                                               select_action_group_channels(act, agrp);
                                                select_action_group(act, agrp, SELECT_ADD);
                                        }
                                        else {
@@ -4682,11 +4702,13 @@ void winqreadactionspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        
                case NKEY:
                        if (G.qual==0) {
-                               numbuts_action();
-                               
-                               /* no panel (yet). current numbuts are not easy to put in panel... */
-                               //add_blockhandler(curarea, ACTION_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
-                               //scrarea_queue_winredraw(curarea);
+                               /* panel will not always show useful info! */
+                               if (mval[0] > ACTWIDTH) {
+                                       add_blockhandler(curarea, ACTION_HANDLER_PROPERTIES, UI_PNL_TO_MOUSE);
+                                       scrarea_queue_winredraw(curarea);
+                               }
+                               else 
+                                       numbuts_action();
                        }
                        break;
                        
index 046d14c990da59f1945c5b971e2910179492bf19..f47f14a605cb32c300699b4a900d95bdff9bfeaf 100644 (file)
@@ -52,6 +52,7 @@
 #include "BIF_interface_icons.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_dynstr.h"
 #include "blendef.h"   // CLAMP
 #include "datatoc.h"
 
@@ -784,6 +785,33 @@ char *BIF_ThemeColorsPup(int spacetype)
        return cp;
 }
 
+char *BIF_ThemeColorSetsPup (short inc_custom)
+{
+       DynStr *pupds= BLI_dynstr_new();
+       char *str;
+       char buf[48];
+       int i;
+       
+       /* add title first (and the "default" entry) */
+       BLI_dynstr_append(pupds, "Bone Color Set%t|Default Colors%x0|");
+       
+       /* loop through set indices, adding them */
+       for (i=1; i<21; i++) {
+               sprintf(buf, "%d - Theme Color Set%%x%d|", i, i);
+               BLI_dynstr_append(pupds, buf);
+       }
+       
+       /* add the 'custom' entry */
+       if (inc_custom)
+               BLI_dynstr_append(pupds, "Custom Set %x-1");
+       
+       /* convert to normal MEM_malloc'd string */
+       str= BLI_dynstr_get_cstring(pupds);
+       BLI_dynstr_free(pupds);
+       
+       return str;
+}
+
 void BIF_SetTheme(ScrArea *sa)
 {
        if(sa==NULL) {  // called for safety, when delete themes