Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.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= CTX_wm_space_action(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, NULL, NULL);
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         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
171         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_CFRA);
172         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_FRAME);
173         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_SECOND);
174         uiItemEnumO(layout, NULL, 0, "ACT_OT_snap", "type", ACTKEYS_SNAP_NEAREST_MARKER);
175 }
176
177 static void act_edit_mirrormenu(bContext *C, uiLayout *layout, void *arg_unused)
178 {
179         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
180         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_CFRA);
181         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_YAXIS);
182         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_XAXIS);
183         uiItemEnumO(layout, NULL, 0, "ACT_OT_mirror", "type", ACTKEYS_MIRROR_MARKER);
184 }
185
186 static void act_edit_handlesmenu(bContext *C, uiLayout *layout, void *arg_unused)
187 {
188         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
189         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_FREE);
190         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO);
191         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_VECT);
192         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_ALIGN);
193         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO_ANIM); // xxx?
194 }
195
196 static void act_edit_ipomenu(bContext *C, uiLayout *layout, void *arg_unused)
197 {
198         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
199         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_CONST);
200         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_LIN);
201         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_BEZ);
202 }
203
204 static void act_edit_expomenu(bContext *C, uiLayout *layout, void *arg_unused)
205 {
206         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
207         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_CONSTANT);
208         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_LINEAR);
209 }
210
211 static void act_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
212 {
213         uiItemMenuF(layout, "Transform", 0, act_edit_transformmenu, NULL);
214         uiItemMenuF(layout, "Snap", 0, act_edit_snapmenu, NULL);
215         uiItemMenuF(layout, "Mirror", 0, act_edit_mirrormenu, NULL);
216         
217         uiItemS(layout);
218         
219         uiItemO(layout, NULL, 0, "ACT_OT_insert_keyframe");
220         
221         uiItemS(layout);
222         
223         uiItemO(layout, NULL, 0, "ACT_OT_duplicate");
224         uiItemO(layout, NULL, 0, "ACT_OT_delete");
225         
226         uiItemS(layout);
227         
228         uiItemMenuF(layout, "Handle Type", 0, act_edit_handlesmenu, NULL);
229         uiItemMenuF(layout, "Interpolation Mode", 0, act_edit_ipomenu, NULL);
230         uiItemMenuF(layout, "Extrapolation Mode", 0, act_edit_expomenu, NULL);
231         
232         uiItemS(layout);
233         
234         uiItemO(layout, NULL, 0, "ACT_OT_clean");
235         uiItemO(layout, NULL, 0, "ACT_OT_sample");
236         
237         uiItemS(layout);
238         
239         uiItemO(layout, NULL, 0, "ACT_OT_copy");
240         uiItemO(layout, NULL, 0, "ACT_OT_paste");
241 }
242
243 /* ************************ header area region *********************** */
244
245 static void do_action_buttons(bContext *C, void *arg, int event)
246 {
247         switch (event) {
248                 case B_REDR:
249                         ED_area_tag_redraw(CTX_wm_area(C));
250                         break;
251         }
252 }
253
254 static void saction_idpoin_handle(bContext *C, ID *id, int event)
255 {
256         SpaceAction *saction= CTX_wm_space_action(C);
257         Object *obact= CTX_data_active_object(C);
258         
259         printf("actedit do id: \n");
260         
261         switch (event) {
262                 case UI_ID_BROWSE:
263                         printf("browse \n");
264                 case UI_ID_DELETE:
265                         printf("browse or delete \n");
266                         saction->action= (bAction*)id;
267                         
268                         /* we must set this action to be the one used by active object (if not pinned) */
269                         if (saction->pin == 0) {
270                                 AnimData *adt= BKE_id_add_animdata(&obact->id); /* this only adds if non-existant */
271                                 
272                                 /* set action */
273                                 printf("\tset action \n");
274                                 adt->action= saction->action;
275                         }
276                         
277                         ED_area_tag_redraw(CTX_wm_area(C));
278                         ED_undo_push(C, "Assign Action");
279                         break;
280                 case UI_ID_RENAME:
281                         printf("actedit rename \n");
282                         break;
283                 case UI_ID_ADD_NEW:
284                         printf("actedit addnew \n");
285                         /* XXX not implemented */
286                         break;
287                 case UI_ID_OPEN:
288                         printf("actedit open \n");
289                         /* XXX not implemented */
290                         break;
291                 case UI_ID_ALONE:
292                         printf("actedit alone \n");
293                         /* XXX not implemented */
294                         break;
295                 case UI_ID_PIN:
296                         printf("actedit pin \n");
297                         break;
298         }
299 }
300
301 void action_header_buttons(const bContext *C, ARegion *ar)
302 {
303         ScrArea *sa= CTX_wm_area(C);
304         SpaceAction *saction= CTX_wm_space_action(C);
305         bAnimContext ac;
306         uiBlock *block;
307         int xco, yco= 3, xmax;
308         
309         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
310         uiBlockSetHandleFunc(block, do_action_buttons, NULL);
311         
312         xco= ED_area_header_standardbuttons(C, block, yco);
313         
314         uiBlockSetEmboss(block, UI_EMBOSS);
315         
316         /* get context... (also syncs data) */
317         ANIM_animdata_get_context(C, &ac);
318         
319         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
320                 
321                 xmax= GetButStringLength("View");
322                 uiDefMenuBut(block, act_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
323                 xco+= xmax;
324                 
325                 xmax= GetButStringLength("Select");
326                 uiDefMenuBut(block, act_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
327                 xco+= xmax;
328                 
329                 if ( (saction->mode == SACTCONT_DOPESHEET) ||
330                          ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) 
331                 {
332                         xmax= GetButStringLength("Channel");
333                         uiDefMenuBut(block, act_channelmenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
334                         xco+= xmax;
335                 }
336                 else if (saction->mode==SACTCONT_GPENCIL) {
337                         xmax= GetButStringLength("Channel");
338                         uiDefMenuBut(block, act_gplayermenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
339                         xco+= xmax;
340                 }
341                 
342                 //xmax= GetButStringLength("Marker");
343                 //uiDefMenuBut(block, act_markermenu, NULL, "Marker", xco, yco, xmax-3, 20, "");
344                 //xco+= xmax;
345                 
346                 if (saction->mode == SACTCONT_GPENCIL) {
347                         //xmax= GetButStringLength("Frame");
348                         //uiDefMenuBut(block, act_selectmenu, NULL, "Frame", xco, yco, xmax-3, 20, "");
349                         //xco+= xmax;
350                 }
351                 else {
352                         xmax= GetButStringLength("Key");
353                         uiDefMenuBut(block, act_editmenu, NULL, "Key", xco, yco, xmax-3, 20, "");
354                         xco+= xmax;
355                 }
356         }
357
358         uiBlockSetEmboss(block, UI_EMBOSS);
359         
360         /* MODE SELECTOR */
361         uiDefButC(block, MENU, B_REDR, 
362                         "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
363                         xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
364                         "Editing modes for this editor");
365         
366         
367         xco += (90 + 8);
368         
369         /*if (ac.data)*/ 
370         {
371                 /* MODE-DEPENDENT DRAWING */
372                 if (saction->mode == SACTCONT_DOPESHEET) {
373                         /* FILTERING OPTIONS */
374                         xco -= 10;
375                         
376                         //uiBlockBeginAlign(block);
377                                 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");
378                         //uiBlockEndAlign(block);
379                         xco += 5;
380                         
381                         uiBlockBeginAlign(block);
382                                 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");
383                                 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");
384                                 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");
385                                 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");
386                                 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");
387                                 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");
388                                 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");
389                                 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");
390                                 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");
391                         uiBlockEndAlign(block);
392                         xco += 30;
393                 }
394                 else if (saction->mode == SACTCONT_ACTION) {
395                         /* NAME ETC  */
396                         xco= uiDefIDPoinButs(block, CTX_data_main(C), NULL, (ID*)saction->action, ID_AC, &saction->pin, xco, yco,
397                                 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);
398                         
399                         xco += 8;
400                 }
401                 
402                 /* draw AUTOSNAP */
403                 if (saction->mode != SACTCONT_GPENCIL) {
404                         if (saction->flag & SACTION_DRAWTIME) {
405                                 uiDefButC(block, MENU, B_REDR,
406                                                 "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
407                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
408                                                 "Auto-snapping mode for keyframes when transforming");
409                         }
410                         else {
411                                 uiDefButC(block, MENU, B_REDR, 
412                                                 "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
413                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
414                                                 "Auto-snapping mode for keyframes when transforming");
415                         }
416                         
417                         xco += (70 + 8);
418                 }
419                 
420                 /* COPY PASTE */
421                 uiBlockBeginAlign(block);
422                         uiDefIconButO(block, BUT, "ACT_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer.");
423                         xco += XIC;
424                         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.");
425                 uiBlockEndAlign(block);
426                 xco += (XIC + 8);
427         }
428
429         /* always as last  */
430         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
431         
432         uiEndBlock(C, block);
433         uiDrawBlock(C, block);
434 }
435
436