soc-2008-mxcurioni: merged changes to revision 15705
[blender.git] / source / blender / src / drawaction.c
index 89466151a39f9216e6cbdac597c95587ae4b35e5..9b1af3f1a065b7eb588a01ed07d4693435528c3a 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,8 @@
 #include "DNA_space_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_key_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_gpencil_types.h"
 
 #include "BKE_action.h"
 #include "BKE_depsgraph.h"
@@ -72,6 +75,7 @@
 #include "BIF_editnla.h"
 #include "BIF_interface.h"
 #include "BIF_interface_icons.h"
+#include "BIF_drawgpencil.h"
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 #include "BIF_resources.h"
@@ -81,6 +85,7 @@
 
 #include "BDR_drawaction.h"
 #include "BDR_editcurve.h"
+#include "BDR_gpencil.h"
 
 #include "BSE_drawnla.h"
 #include "BSE_drawipo.h"
@@ -620,6 +625,28 @@ static void draw_channel_names(void)
                                        sprintf(name, "Constraint");
                                }
                                        break;
+                               case ACTTYPE_GPLAYER: /* gpencil layer */
+                               {
+                                       bGPDlayer *gpl = (bGPDlayer *)ale->data;
+                                       
+                                       indent = 0;
+                                       special = -1;
+                                       expand = -1;
+                                               
+                                       if (EDITABLE_GPL(gpl))
+                                               protect = ICON_UNLOCKED;
+                                       else
+                                               protect = ICON_LOCKED;
+                                               
+                                       if (gpl->flag & GP_LAYER_HIDE)
+                                               mute = ICON_MUTE_IPO_ON;
+                                       else
+                                               mute = ICON_MUTE_IPO_OFF;
+                                       
+                                       sel = SEL_GPL(gpl);
+                                       BLI_snprintf(name, 32, gpl->info);
+                               }
+                                       break;
                        }       
 
                        /* now, start drawing based on this information */
@@ -825,6 +852,12 @@ static void draw_channel_strips(void)
                                        sel = SEL_ICU(icu);
                                }
                                        break;
+                               case ACTTYPE_GPLAYER:
+                               {
+                                       bGPDlayer *gpl = (bGPDlayer *)ale->data;
+                                       sel = SEL_GPL(gpl);
+                               }
+                                       break;
                        }
                        
                        if (datatype == ACTCONT_ACTION) {
@@ -863,6 +896,19 @@ static void draw_channel_strips(void)
                                glColor4ub(col2[0], col2[1], col2[2], 0x44);
                                glRectf(frame1_x, channel_y-CHANNELHEIGHT/2, G.v2d->hor.xmax,  channel_y+CHANNELHEIGHT/2);
                        }
+                       else if (datatype == ACTCONT_GPENCIL) {
+                               gla2DDrawTranslatePt(di, G.v2d->cur.xmin, y, &frame1_x, &channel_y);
+                               
+                               /* frames less than one get less saturated background */
+                               if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
+                               else glColor4ub(col2[0], col2[1], col2[2], 0x22);
+                               glRectf(0, channel_y-CHANNELHEIGHT/2, frame1_x, channel_y+CHANNELHEIGHT/2);
+                               
+                               /* frames one and higher get a saturated background */
+                               if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x44);
+                               else glColor4ub(col2[0], col2[1], col2[2], 0x44);
+                               glRectf(frame1_x, channel_y-CHANNELHEIGHT/2, G.v2d->hor.xmax,  channel_y+CHANNELHEIGHT/2);
+                       }
                }
                
                /*      Increment the step */
@@ -897,6 +943,9 @@ static void draw_channel_strips(void)
                                case ALE_ICU:
                                        draw_icu_channel(di, ale->key_data, y);
                                        break;
+                               case ALE_GPFRAME:
+                                       draw_gpl_channel(di, ale->data, y);
+                                       break;
                        }
                }
                
@@ -928,12 +977,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 +1033,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)
@@ -976,6 +1122,7 @@ void drawactionspace(ScrArea *sa, void *spacedata)
 {
        bAction *act = NULL;
        Key *key = NULL;
+       bGPdata *gpd = NULL;
        void *data;
        short datatype;
        
@@ -991,18 +1138,38 @@ void drawactionspace(ScrArea *sa, void *spacedata)
 
        /* only try to refresh action that's displayed if not pinned */
        if (G.saction->pin==0) {
-               if (OBACT)
-                       G.saction->action = OBACT->action;
-               else
-                       G.saction->action= NULL;
+               /* depends on mode */
+               switch (G.saction->mode) {
+                       case SACTCONT_ACTION:
+                       {
+                               if (OBACT)
+                                       G.saction->action = OBACT->action;
+                               else
+                                       G.saction->action= NULL;
+                       }
+                               break;
+                       case SACTCONT_GPENCIL:
+                       {
+                               /* this searching could be slow (so users should pin after this is found) */
+                               G.saction->gpd= gpencil_data_getetime(G.curscreen);
+                       }
+                               break;
+               }
        }
        
        /* get data */
        data = get_action_context(&datatype);
-       if (datatype == ACTCONT_ACTION)
-               act = data;
-       else if (datatype == ACTCONT_SHAPEKEY)
-               key = data;
+       switch (datatype) {
+               case ACTCONT_ACTION:
+                       act = data;
+                       break;
+               case ACTCONT_SHAPEKEY:
+                       key = data;
+                       break;
+               case ACTCONT_GPENCIL:
+                       gpd = data;
+                       break;
+       }
        
        /* Lets make sure the width of the left hand of the screen
         * is set to an appropriate value based on whether sliders
@@ -1351,10 +1518,15 @@ static ActKeysInc *init_aki_data()
        static ActKeysInc aki;
        
        /* init data of static struct here */
-       if ((curarea->spacetype == SPACE_ACTION) && NLA_ACTION_SCALED)
+       if ((curarea->spacetype == SPACE_ACTION) && NLA_ACTION_SCALED &&
+               (G.saction->mode == SACTCONT_ACTION))
+       {
                aki.ob= OBACT;
+       }
        else if (curarea->spacetype == SPACE_NLA)
+       {
                aki.ob= NULL; // FIXME
+       }
        else
                aki.ob= NULL;
                
@@ -1429,6 +1601,16 @@ void draw_action_channel(gla2DDrawInfo *di, bAction *act, float ypos)
        BLI_freelistN(&keys);
 }
 
+void draw_gpl_channel(gla2DDrawInfo *di, bGPDlayer *gpl, float ypos)
+{
+       ListBase keys = {0, 0};
+       ActKeysInc *aki = init_aki_data();
+       
+       gpl_to_keylist(gpl, &keys, NULL, aki);
+       draw_keylist(di, &keys, NULL, ypos);
+       BLI_freelistN(&keys);
+}
+
 /* --------------- Conversion: data -> keyframe list ------------------ */
 
 void ob_to_keylist(Object *ob, ListBase *keys, ListBase *blocks, ActKeysInc *aki)
@@ -1575,3 +1757,26 @@ void action_to_keylist(bAction *act, ListBase *keys, ListBase *blocks, ActKeysIn
        }
 }
 
+void gpl_to_keylist(bGPDlayer *gpl, ListBase *keys, ListBase *blocks, ActKeysInc *aki)
+{
+       bGPDframe *gpf;
+       ActKeyColumn *ak;
+       
+       if (gpl && keys) {
+               /* loop over frames, converting directly to 'keyframes' (should be in order too) */
+               for (gpf= gpl->frames.first; gpf; gpf= gpf->next) {
+                       ak= MEM_callocN(sizeof(ActKeyColumn), "ActKeyColumn");
+                       BLI_addtail(keys, ak);
+                       
+                       ak->cfra= gpf->framenum;
+                       ak->modified = 1;
+                       ak->handle_type= 0; 
+                       
+                       if (gpf->flag & GP_FRAME_SELECT)
+                               ak->sel = SELECT;
+                       else
+                               ak->sel = 0;
+               }
+       }
+}
+