2.5 - Action Editor
[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_action.h"
47 #include "BKE_context.h"
48 #include "BKE_screen.h"
49
50 #include "ED_anim_api.h"
51 #include "ED_screen.h"
52 #include "ED_transform.h"
53 #include "ED_types.h"
54 #include "ED_util.h"
55
56 #include "RNA_access.h"
57
58 #include "WM_api.h"
59 #include "WM_types.h"
60
61 #include "BIF_gl.h"
62 #include "BIF_glutil.h"
63
64 #include "UI_interface.h"
65 #include "UI_resources.h"
66 #include "UI_view2d.h"
67
68 #include "action_intern.h"
69
70 enum {
71         B_REDR= 0,
72 } eActHeader_Events;
73
74 /* ********************************************************* */
75 /* Menu Defines... */
76
77 static void act_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
78 {
79         bScreen *sc= CTX_wm_screen(C);
80         ScrArea *sa= CTX_wm_area(C);
81         SpaceAction *sact= CTX_wm_space_action(C);
82         PointerRNA spaceptr;
83         
84         /* retrieve state */
85         RNA_pointer_create(&sc->id, &RNA_SpaceDopeSheetEditor, sact, &spaceptr);
86         
87         /* create menu */
88         //uiItemO(layout, NULL, ICON_MENU_PANEL, "ACT_OT_properties");
89         
90         //uiItemS(layout);
91         
92         uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0);
93         uiItemR(layout, NULL, 0, &spaceptr, "show_sliders", 0);
94         uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0);
95         
96         if (sact->flag & SACTION_DRAWTIME)
97                 uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle");
98         else
99                 uiItemO(layout, "Show Seconds", 0, "ANIM_OT_time_toggle");
100         
101         uiItemS(layout);
102         
103         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_set");
104         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_clear");
105         
106         uiItemO(layout, NULL, 0, "ACT_OT_previewrange_set");
107         
108         uiItemS(layout);
109         
110         uiItemO(layout, NULL, 0, "ACT_OT_frame_jump");
111         
112         uiItemO(layout, NULL, 0, "ACT_OT_view_all");
113         
114         if (sa->full) 
115                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow
116         else 
117                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctrl DownArrow
118 }
119
120 static void act_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
121 {
122         uiItemO(layout, NULL, 0, "ACT_OT_select_all_toggle");
123         uiItemBooleanO(layout, "Invert All", 0, "ACT_OT_select_all_toggle", "invert", 1);
124         
125         uiItemS(layout);
126         
127         uiItemO(layout, NULL, 0, "ACT_OT_select_border");
128         uiItemBooleanO(layout, "Border Axis Range", 0, "ACT_OT_select_border", "axis_range", 1);
129         
130         uiItemS(layout);
131         
132         uiItemEnumO(layout, "Columns on Selected Keys", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_KEYS);
133         uiItemEnumO(layout, "Column on Current Frame", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_CFRA);
134         
135         uiItemEnumO(layout, "Columns on Selected Markers", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_COLUMN);
136         uiItemEnumO(layout, "Between Selected Markers", 0, "ACT_OT_select_column", "mode", ACTKEYS_COLUMNSEL_MARKERS_BETWEEN);
137 }
138
139 static void act_channelmenu(bContext *C, uiLayout *layout, void *arg_unused)
140 {
141         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_toggle");
142         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_enable");
143         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_disable");
144         
145         uiItemS(layout);
146         
147         uiItemO(layout, NULL, 0, "ANIM_OT_channels_editable_toggle");
148         
149         uiItemS(layout);
150         
151         uiItemO(layout, NULL, 0, "ANIM_OT_channels_expand");
152         uiItemO(layout, NULL, 0, "ANIM_OT_channels_collapse");
153 }
154
155 static void act_gplayermenu(bContext *C, uiLayout *layout, void *arg_unused)
156 {
157         //uiItemMenuF(layout, "Transform", 0, nla_edit_transformmenu, NULL, NULL);
158         //uiItemS(layout);
159         //uiItemO(layout, NULL, 0, "NLAEDIT_OT_duplicate");
160 }
161
162 static void act_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unused)
163 {
164         uiItemEnumO(layout, "Grab/Move", 0, "TFM_OT_transform", "mode", TFM_TIME_TRANSLATE);
165         uiItemEnumO(layout, "Extend", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND);
166         uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE);
167 }
168
169 static void act_edit_snapmenu(bContext *C, uiLayout *layout, void *arg_unused)
170 {
171         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
172         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_CFRA);
173         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_FRAME);
174         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_SECOND);
175         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_MARKER);
176 }
177
178 static void act_edit_mirrormenu(bContext *C, uiLayout *layout, void *arg_unused)
179 {
180         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
181         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_CFRA);
182         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_YAXIS);
183         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_XAXIS);
184         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_MARKER);
185 }
186
187 static void act_edit_handlesmenu(bContext *C, uiLayout *layout, void *arg_unused)
188 {
189         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
190         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_FREE);
191         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO);
192         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_VECT);
193         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_ALIGN);
194         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO_ANIM); // xxx?
195 }
196
197 static void act_edit_ipomenu(bContext *C, uiLayout *layout, void *arg_unused)
198 {
199         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
200         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_CONST);
201         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_LIN);
202         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_BEZ);
203 }
204
205 static void act_edit_expomenu(bContext *C, uiLayout *layout, void *arg_unused)
206 {
207         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
208         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_CONSTANT);
209         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_LINEAR);
210 }
211
212 static void act_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
213 {
214         uiItemMenuF(layout, "Transform", 0, act_edit_transformmenu, NULL);
215         uiItemMenuF(layout, "Snap", 0, act_edit_snapmenu, NULL);
216         uiItemMenuF(layout, "Mirror", 0, act_edit_mirrormenu, NULL);
217         
218         uiItemS(layout);
219         
220         uiItemO(layout, NULL, 0, "ACT_OT_insert_keyframe");
221         
222         uiItemS(layout);
223         
224         uiItemO(layout, NULL, 0, "ACT_OT_duplicate");
225         uiItemO(layout, NULL, 0, "ACT_OT_delete");
226         
227         uiItemS(layout);
228         
229         uiItemMenuF(layout, "Handle Type", 0, act_edit_handlesmenu, NULL);
230         uiItemMenuF(layout, "Interpolation Mode", 0, act_edit_ipomenu, NULL);
231         uiItemMenuF(layout, "Extrapolation Mode", 0, act_edit_expomenu, NULL);
232         
233         uiItemS(layout);
234         
235         uiItemO(layout, NULL, 0, "ACT_OT_clean");
236         uiItemO(layout, NULL, 0, "ACT_OT_sample");
237         
238         uiItemS(layout);
239         
240         uiItemO(layout, NULL, 0, "ACT_OT_copy");
241         uiItemO(layout, NULL, 0, "ACT_OT_paste");
242 }
243
244 /* ************************ header area region *********************** */
245
246 static void do_action_buttons(bContext *C, void *arg, int event)
247 {
248         switch (event) {
249                 case B_REDR:
250                         ED_area_tag_redraw(CTX_wm_area(C));
251                         break;
252         }
253 }
254
255 static void saction_idpoin_handle(bContext *C, ID *id, int event)
256 {
257         SpaceAction *saction= CTX_wm_space_action(C);
258         Object *obact= CTX_data_active_object(C);
259         
260         printf("actedit do id: \n");
261         
262         switch (event) {
263                 case UI_ID_BROWSE:
264                         printf("browse \n");
265                 case UI_ID_DELETE:
266                         printf("browse or delete \n");
267                         saction->action= (bAction*)id;
268                         
269                         /* we must set this action to be the one used by active object (if not pinned) */
270                         if (saction->pin == 0) {
271                                 AnimData *adt= BKE_id_add_animdata(&obact->id); /* this only adds if non-existant */
272                                 
273                                 /* set action */
274                                 printf("\tset action \n");
275                                 adt->action= saction->action;
276                                 adt->action->id.us++;
277                         }
278                         
279                         ED_area_tag_redraw(CTX_wm_area(C));
280                         ED_undo_push(C, "Assign Action");
281                         break;
282                 case UI_ID_RENAME:
283                         printf("actedit rename \n");
284                         break;
285                 case UI_ID_ADD_NEW:
286                         printf("actedit addnew \n");
287                         if (saction->pin == 0) {
288                                 AnimData *adt= BKE_id_add_animdata(&obact->id); /* this only adds if non-existant */
289                                 
290                                 /* set new action */
291                                 // XXX need to restore behaviour to copy old actions...
292                                 printf("\tset new action \n");
293                                 adt->action= saction->action= add_empty_action("Action");
294                         }
295                         break;
296                 case UI_ID_OPEN:
297                         printf("actedit open \n");
298                         /* XXX not implemented */
299                         break;
300                 case UI_ID_ALONE:
301                         printf("actedit alone \n");
302                         /* XXX not implemented */
303                         break;
304                 case UI_ID_PIN:
305                         printf("actedit pin \n");
306                         break;
307         }
308 }
309
310 void action_header_buttons(const bContext *C, ARegion *ar)
311 {
312         ScrArea *sa= CTX_wm_area(C);
313         SpaceAction *saction= CTX_wm_space_action(C);
314         bAnimContext ac;
315         uiBlock *block;
316         int xco, yco= 3, xmax;
317         
318         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
319         uiBlockSetHandleFunc(block, do_action_buttons, NULL);
320         
321         xco= ED_area_header_standardbuttons(C, block, yco);
322         
323         uiBlockSetEmboss(block, UI_EMBOSS);
324         
325         /* get context... (also syncs data) */
326         ANIM_animdata_get_context(C, &ac);
327         
328         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
329                 
330                 xmax= GetButStringLength("View");
331                 uiDefMenuBut(block, act_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
332                 xco+= xmax;
333                 
334                 xmax= GetButStringLength("Select");
335                 uiDefMenuBut(block, act_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
336                 xco+= xmax;
337                 
338                 if ( (saction->mode == SACTCONT_DOPESHEET) ||
339                          ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) 
340                 {
341                         xmax= GetButStringLength("Channel");
342                         uiDefMenuBut(block, act_channelmenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
343                         xco+= xmax;
344                 }
345                 else if (saction->mode==SACTCONT_GPENCIL) {
346                         xmax= GetButStringLength("Channel");
347                         uiDefMenuBut(block, act_gplayermenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
348                         xco+= xmax;
349                 }
350                 
351                 //xmax= GetButStringLength("Marker");
352                 //uiDefMenuBut(block, act_markermenu, NULL, "Marker", xco, yco, xmax-3, 20, "");
353                 //xco+= xmax;
354                 
355                 if (saction->mode == SACTCONT_GPENCIL) {
356                         //xmax= GetButStringLength("Frame");
357                         //uiDefMenuBut(block, act_selectmenu, NULL, "Frame", xco, yco, xmax-3, 20, "");
358                         //xco+= xmax;
359                 }
360                 else {
361                         xmax= GetButStringLength("Key");
362                         uiDefMenuBut(block, act_editmenu, NULL, "Key", xco, yco, xmax-3, 20, "");
363                         xco+= xmax;
364                 }
365         }
366
367         uiBlockSetEmboss(block, UI_EMBOSS);
368         
369         /* MODE SELECTOR */
370         uiDefButC(block, MENU, B_REDR, 
371                         "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
372                         xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
373                         "Editing modes for this editor");
374         
375         
376         xco += (90 + 8);
377         
378         /*if (ac.data)*/ 
379         {
380                 /* MODE-DEPENDENT DRAWING */
381                 if (saction->mode == SACTCONT_DOPESHEET) {
382                         /* FILTERING OPTIONS */
383                         xco -= 10;
384                         
385                         //uiBlockBeginAlign(block);
386                                 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");
387                         //uiBlockEndAlign(block);
388                         xco += 5;
389                         
390                         uiBlockBeginAlign(block);
391                                 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");
392                                 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");
393                                 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");
394                                 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");
395                                 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");
396                                 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");
397                                 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");
398                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMBA, B_REDR, ICON_META_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display MetaBalls");
399                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOPART, B_REDR, ICON_PARTICLE_DATA,    (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Particles");
400                         uiBlockEndAlign(block);
401                         xco += 30;
402                 }
403                 else if (saction->mode == SACTCONT_ACTION) {
404                         /* NAME ETC  */
405                         xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)saction->action, ID_AC, &saction->pin, xco, yco,
406                                 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);
407                         
408                         xco += 8;
409                 }
410                 
411                 /* draw AUTOSNAP */
412                 if (saction->mode != SACTCONT_GPENCIL) {
413                         if (saction->flag & SACTION_DRAWTIME) {
414                                 uiDefButC(block, MENU, B_REDR,
415                                                 "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
416                                                 xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, 
417                                                 "Auto-snapping mode for keyframes when transforming");
418                         }
419                         else {
420                                 uiDefButC(block, MENU, B_REDR, 
421                                                 "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
422                                                 xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, 
423                                                 "Auto-snapping mode for keyframes when transforming");
424                         }
425                         
426                         xco += (70 + 8);
427                 }
428                 
429                 /* COPY PASTE */
430                 uiBlockBeginAlign(block);
431                         uiDefIconButO(block, BUT, "ACT_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer.");
432                         xco += XIC;
433                         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.");
434                 uiBlockEndAlign(block);
435                 xco += (XIC + 8);
436         }
437
438         /* always as last  */
439         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
440         
441         uiEndBlock(C, block);
442         uiDrawBlock(C, block);
443 }
444
445