NLA SoC: Merge from 2.5
[blender-staging.git] / source / blender / editors / space_action / action_header.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_anim_types.h"
33 #include "DNA_action_types.h"
34 #include "DNA_key_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_space_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_windowmanager_types.h"
40
41 #include "MEM_guardedalloc.h"
42
43 #include "BLI_blenlib.h"
44
45 #include "BKE_animsys.h"
46 #include "BKE_context.h"
47 #include "BKE_screen.h"
48
49 #include "ED_anim_api.h"
50 #include "ED_screen.h"
51 #include "ED_transform.h"
52 #include "ED_types.h"
53 #include "ED_util.h"
54
55 #include "RNA_access.h"
56
57 #include "WM_api.h"
58 #include "WM_types.h"
59
60 #include "BIF_gl.h"
61 #include "BIF_glutil.h"
62
63 #include "UI_interface.h"
64 #include "UI_resources.h"
65 #include "UI_view2d.h"
66
67 #include "action_intern.h"
68
69 enum {
70         B_REDR= 0,
71 } eActHeader_Events;
72
73 /* ********************************************************* */
74 /* Menu Defines... */
75
76 static void act_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
77 {
78         bScreen *sc= CTX_wm_screen(C);
79         ScrArea *sa= CTX_wm_area(C);
80         SpaceAction *sact= (SpaceAction*)CTX_wm_space_data(C);
81         PointerRNA spaceptr;
82         
83         /* retrieve state */
84         RNA_pointer_create(&sc->id, &RNA_SpaceDopeSheetEditor, sact, &spaceptr);
85         
86         /* create menu */
87         //uiItemO(layout, NULL, ICON_MENU_PANEL, "ACT_OT_properties");
88         
89         //uiItemS(layout);
90         
91         uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0);
92         uiItemR(layout, NULL, 0, &spaceptr, "show_sliders", 0, 0, 0);
93         uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0, 0, 0);
94         
95         if (sact->flag & SACTION_DRAWTIME)
96                 uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle");
97         else
98                 uiItemO(layout, "Show Seconds", 0, "ANIM_OT_time_toggle");
99         
100         uiItemS(layout);
101         
102         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_set");
103         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_clear");
104         
105         uiItemO(layout, NULL, 0, "ACT_OT_previewrange_set");
106         
107         uiItemS(layout);
108         
109         uiItemO(layout, NULL, 0, "ACT_OT_frame_jump");
110         
111         uiItemO(layout, NULL, 0, "ACT_OT_view_all");
112         
113         if (sa->full) 
114                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow
115         else 
116                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctrl DownArrow
117 }
118
119 static void act_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
120 {
121         uiItemO(layout, NULL, 0, "ACT_OT_select_all_toggle");
122         uiItemBooleanO(layout, "Invert All", 0, "ACT_OT_select_all_toggle", "invert", 1);
123         
124         uiItemS(layout);
125         
126         uiItemO(layout, NULL, 0, "ACT_OT_select_border");
127         uiItemBooleanO(layout, "Border Axis Range", 0, "ACT_OT_select_border", "axis_range", 1);
128         
129         uiItemS(layout);
130         
131         uiItemEnumO(layout, "Columns on Selected Keys", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_KEYS);
132         uiItemEnumO(layout, "Column on Current Frame", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_CFRA);
133         
134         uiItemEnumO(layout, "Columns on Selected Markers", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
135         uiItemEnumO(layout, "Between Selected Markers", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
136 }
137
138 static void act_channelmenu(bContext *C, uiLayout *layout, void *arg_unused)
139 {
140         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_toggle");
141         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_enable");
142         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_disable");
143         
144         uiItemS(layout);
145         
146         uiItemO(layout, NULL, 0, "ANIM_OT_channels_editable_toggle");
147         
148         uiItemS(layout);
149         
150         uiItemO(layout, NULL, 0, "ANIM_OT_channels_expand");
151         uiItemO(layout, NULL, 0, "ANIM_OT_channels_collapse");
152 }
153
154 static void act_gplayermenu(bContext *C, uiLayout *layout, void *arg_unused)
155 {
156         //uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu);
157         //uiItemS(layout);
158         //uiItemO(layout, NULL, 0, "NLAEDIT_OT_duplicate");
159 }
160
161 static void act_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unused)
162 {
163         uiItemEnumO(layout, "Grab/Move", 0, "TFM_OT_transform", "mode", TFM_TIME_TRANSLATE);
164         uiItemEnumO(layout, "Extend", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND);
165         uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE);
166 }
167
168 static void act_edit_snapmenu(bContext *C, uiLayout *layout, void *arg_unused)
169 {
170         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_CFRA);
171         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_FRAME);
172         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_SECOND);
173         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_MARKER);
174 }
175
176 static void act_edit_mirrormenu(bContext *C, uiLayout *layout, void *arg_unused)
177 {
178         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_CFRA);
179         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_YAXIS);
180         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_XAXIS);
181         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_MARKER);
182 }
183
184 static void act_edit_handlesmenu(bContext *C, uiLayout *layout, void *arg_unused)
185 {
186         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_FREE);
187         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO);
188         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_VECT);
189         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_ALIGN);
190         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO_ANIM); // xxx?
191 }
192
193 static void act_edit_ipomenu(bContext *C, uiLayout *layout, void *arg_unused)
194 {
195         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_CONST);
196         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_LIN);
197         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_BEZ);
198 }
199
200 static void act_edit_expomenu(bContext *C, uiLayout *layout, void *arg_unused)
201 {
202         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_CONSTANT);
203         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_LINEAR);
204 }
205
206 static void act_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
207 {
208         uiItemMenuF(layout, "Transform", 0, act_edit_transformmenu);
209         uiItemMenuF(layout, "Snap", 0, act_edit_snapmenu);
210         uiItemMenuF(layout, "Mirror", 0, act_edit_mirrormenu);
211         
212         uiItemS(layout);
213         
214         uiItemO(layout, NULL, 0, "ACT_OT_insert_keyframe");
215         
216         uiItemS(layout);
217         
218         uiItemO(layout, NULL, 0, "ACT_OT_duplicate");
219         uiItemO(layout, NULL, 0, "ACT_OT_delete");
220         
221         uiItemS(layout);
222         
223         uiItemMenuF(layout, "Handle Type", 0, act_edit_handlesmenu);
224         uiItemMenuF(layout, "Interpolation Mode", 0, act_edit_ipomenu);
225         uiItemMenuF(layout, "Extrapolation Mode", 0, act_edit_expomenu);
226         
227         uiItemS(layout);
228         
229         uiItemO(layout, NULL, 0, "ACT_OT_clean");
230         uiItemO(layout, NULL, 0, "ACT_OT_sample");
231         
232         uiItemS(layout);
233         
234         uiItemO(layout, NULL, 0, "ACT_OT_copy");
235         uiItemO(layout, NULL, 0, "ACT_OT_paste");
236 }
237
238 /* ************************ header area region *********************** */
239
240 static void do_action_buttons(bContext *C, void *arg, int event)
241 {
242         switch (event) {
243                 case B_REDR:
244                         ED_area_tag_redraw(CTX_wm_area(C));
245                         break;
246         }
247 }
248
249 static void saction_idpoin_handle(bContext *C, ID *id, int event)
250 {
251         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
252         Object *obact= CTX_data_active_object(C);
253         
254         printf("actedit do id: \n");
255         
256         switch (event) {
257                 case UI_ID_BROWSE:
258                         printf("browse \n");
259                 case UI_ID_DELETE:
260                         printf("browse or delete \n");
261                         saction->action= (bAction*)id;
262                         
263                         /* we must set this action to be the one used by active object (if not pinned) */
264                         if (saction->pin == 0) {
265                                 AnimData *adt= BKE_id_add_animdata(&obact->id); /* this only adds if non-existant */
266                                 
267                                 /* set action */
268                                 printf("\tset action \n");
269                                 adt->action= saction->action;
270                         }
271                         
272                         ED_area_tag_redraw(CTX_wm_area(C));
273                         ED_undo_push(C, "Assign Action");
274                         break;
275                 case UI_ID_RENAME:
276                         printf("actedit rename \n");
277                         break;
278                 case UI_ID_ADD_NEW:
279                         printf("actedit addnew \n");
280                         /* XXX not implemented */
281                         break;
282                 case UI_ID_OPEN:
283                         printf("actedit open \n");
284                         /* XXX not implemented */
285                         break;
286                 case UI_ID_ALONE:
287                         printf("actedit alone \n");
288                         /* XXX not implemented */
289                         break;
290                 case UI_ID_PIN:
291                         printf("actedit pin \n");
292                         break;
293         }
294 }
295
296 void action_header_buttons(const bContext *C, ARegion *ar)
297 {
298         ScrArea *sa= CTX_wm_area(C);
299         SpaceAction *saction= (SpaceAction *)CTX_wm_space_data(C);
300         bAnimContext ac;
301         uiBlock *block;
302         int xco, yco= 3, xmax;
303         
304         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
305         uiBlockSetHandleFunc(block, do_action_buttons, NULL);
306         
307         xco= ED_area_header_standardbuttons(C, block, yco);
308         
309         uiBlockSetEmboss(block, UI_EMBOSS);
310         
311         /* get context... (also syncs data) */
312         ANIM_animdata_get_context(C, &ac);
313         
314         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
315                 
316                 xmax= GetButStringLength("View");
317                 uiDefMenuBut(block, act_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
318                 xco+= xmax;
319                 
320                 xmax= GetButStringLength("Select");
321                 uiDefMenuBut(block, act_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
322                 xco+= xmax;
323                 
324                 if ( (saction->mode == SACTCONT_DOPESHEET) ||
325                          ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) 
326                 {
327                         xmax= GetButStringLength("Channel");
328                         uiDefMenuBut(block, act_channelmenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
329                         xco+= xmax;
330                 }
331                 else if (saction->mode==SACTCONT_GPENCIL) {
332                         xmax= GetButStringLength("Channel");
333                         uiDefMenuBut(block, act_gplayermenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
334                         xco+= xmax;
335                 }
336                 
337                 //xmax= GetButStringLength("Marker");
338                 //uiDefMenuBut(block, act_markermenu, NULL, "Marker", xco, yco, xmax-3, 20, "");
339                 //xco+= xmax;
340                 
341                 if (saction->mode == SACTCONT_GPENCIL) {
342                         //xmax= GetButStringLength("Frame");
343                         //uiDefMenuBut(block, act_selectmenu, NULL, "Frame", xco, yco, xmax-3, 20, "");
344                         //xco+= xmax;
345                 }
346                 else {
347                         xmax= GetButStringLength("Key");
348                         uiDefMenuBut(block, act_editmenu, NULL, "Key", xco, yco, xmax-3, 20, "");
349                         xco+= xmax;
350                 }
351         }
352
353         uiBlockSetEmboss(block, UI_EMBOSS);
354         
355         /* MODE SELECTOR */
356         uiDefButC(block, MENU, B_REDR, 
357                         "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
358                         xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
359                         "Editing modes for this editor");
360         
361         
362         xco += (90 + 8);
363         
364         /*if (ac.data)*/ 
365         {
366                 /* MODE-DEPENDENT DRAWING */
367                 if (saction->mode == SACTCONT_DOPESHEET) {
368                         /* FILTERING OPTIONS */
369                         xco -= 10;
370                         
371                         //uiBlockBeginAlign(block);
372                                 uiDefIconButBitI(block, TOG, ADS_FILTER_ONLYSEL, B_REDR, ICON_RESTRICT_SELECT_OFF,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Only display selected Objects");
373                         //uiBlockEndAlign(block);
374                         xco += 5;
375                         
376                         uiBlockBeginAlign(block);
377                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSCE, B_REDR, ICON_SCENE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Scene Animation");
378                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOWOR, B_REDR, ICON_WORLD_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display World Animation");
379                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_SHAPEKEY_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display ShapeKeys");
380                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL_DATA,     (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Materials");
381                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Lamps");
382                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Cameras");
383                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Curves");
384                         uiBlockEndAlign(block);
385                         xco += 30;
386                 }
387                 else if (saction->mode == SACTCONT_ACTION) { // not too appropriate for shapekeys atm...
388                         /* NAME ETC */
389                         //uiClearButLock();
390                         
391                         /* NAME ETC  */
392                         xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)saction->action, ID_AC, &saction->pin, xco, yco,
393                                 saction_idpoin_handle, UI_ID_BROWSE|UI_ID_RENAME|UI_ID_ADD_NEW|UI_ID_DELETE|UI_ID_FAKE_USER|UI_ID_ALONE|UI_ID_PIN);
394                         
395                         xco += 8;
396                 }
397                 
398                 /* COPY PASTE */
399                 uiBlockBeginAlign(block);
400                         uiDefIconButO(block, BUT, "ACT_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer.");
401                         xco += XIC;
402                         uiDefIconButO(block, BUT, "ACT_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_PASTEDOWN, xco,yco,XIC,YIC, "Pastes the keyframes from the buffer into the selected channels.");
403                 uiBlockEndAlign(block);
404                 xco += (XIC + 8);
405                 
406                 /* draw AUTOSNAP */
407                 if (saction->mode != SACTCONT_GPENCIL) {
408                         if (saction->flag & SACTION_DRAWTIME) {
409                                 uiDefButC(block, MENU, B_REDR,
410                                                 "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
411                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
412                                                 "Auto-snapping mode for keyframes when transforming");
413                         }
414                         else {
415                                 uiDefButC(block, MENU, B_REDR, 
416                                                 "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
417                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
418                                                 "Auto-snapping mode for keyframes when transforming");
419                         }
420                         
421                         xco += (70 + 8);
422                 }
423                 
424                 /* draw LOCK */
425                         // XXX this feature is probably not relevant anymore!
426                 //uiDefIconButS(block, ICONTOG, B_LOCK, ICON_UNLOCKED,  xco, yco, XIC, YIC, 
427                 //                        &(saction->lock), 0, 0, 0, 0, 
428                 //                        "Updates other affected window spaces automatically "
429                 //                        "to reflect changes in real time");
430         }
431
432         /* always as last  */
433         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
434         
435         uiEndBlock(C, block);
436         uiDrawBlock(C, block);
437 }
438
439