soc-2008-mxcurioni: merged changes to revision 23516
[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_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); 
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);
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_keytypesmenu(bContext *C, uiLayout *layout, void *arg_unused)
188 {
189         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
190         uiItemEnumO(layout, NULL, 0, "ACT_OT_keyframe_type", "type", BEZT_KEYTYPE_KEYFRAME);
191         uiItemEnumO(layout, NULL, 0, "ACT_OT_keyframe_type", "type", BEZT_KEYTYPE_BREAKDOWN);
192         uiItemEnumO(layout, NULL, 0, "ACT_OT_keyframe_type", "type", BEZT_KEYTYPE_EXTREME);
193 }
194
195 static void act_edit_handlesmenu(bContext *C, uiLayout *layout, void *arg_unused)
196 {
197         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
198         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_FREE);
199         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO);
200         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_VECT);
201         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_ALIGN);
202         uiItemEnumO(layout, NULL, 0, "ACT_OT_handle_type", "type", HD_AUTO_ANIM); // xxx?
203 }
204
205 static void act_edit_ipomenu(bContext *C, uiLayout *layout, void *arg_unused)
206 {
207         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
208         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_CONST);
209         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_LIN);
210         uiItemEnumO(layout, NULL, 0, "ACT_OT_interpolation_type", "type", BEZT_IPO_BEZ);
211 }
212
213 static void act_edit_expomenu(bContext *C, uiLayout *layout, void *arg_unused)
214 {
215         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
216         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_CONSTANT);
217         uiItemEnumO(layout, NULL, 0, "ACT_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_LINEAR);
218 }
219
220 static void act_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
221 {
222         uiItemMenuF(layout, "Transform", 0, act_edit_transformmenu, NULL);
223         uiItemMenuF(layout, "Snap", 0, act_edit_snapmenu, NULL);
224         uiItemMenuF(layout, "Mirror", 0, act_edit_mirrormenu, NULL);
225         
226         uiItemS(layout);
227         
228         uiItemO(layout, NULL, 0, "ACT_OT_insert_keyframe");
229         
230         uiItemS(layout);
231         
232         uiItemO(layout, NULL, 0, "ACT_OT_duplicate");
233         uiItemO(layout, NULL, 0, "ACT_OT_delete");
234         
235         uiItemS(layout);
236         
237         uiItemMenuF(layout, "Keyframe Type", 0, act_edit_keytypesmenu, NULL);
238         uiItemMenuF(layout, "Handle Type", 0, act_edit_handlesmenu, NULL);
239         uiItemMenuF(layout, "Interpolation Mode", 0, act_edit_ipomenu, NULL);
240         uiItemMenuF(layout, "Extrapolation Mode", 0, act_edit_expomenu, NULL);
241         
242         uiItemS(layout);
243         
244         uiItemO(layout, NULL, 0, "ACT_OT_clean");
245         uiItemO(layout, NULL, 0, "ACT_OT_sample");
246         
247         uiItemS(layout);
248         
249         uiItemO(layout, NULL, 0, "ACT_OT_copy");
250         uiItemO(layout, NULL, 0, "ACT_OT_paste");
251 }
252
253 /* ************************ header area region *********************** */
254
255 static void do_action_buttons(bContext *C, void *arg, int event)
256 {
257         switch (event) {
258                 case B_REDR:
259                         ED_area_tag_redraw(CTX_wm_area(C));
260                         break;
261         }
262 }
263
264 void action_header_buttons(const bContext *C, ARegion *ar)
265 {
266         ScrArea *sa= CTX_wm_area(C);
267         SpaceAction *saction= CTX_wm_space_action(C);
268         bAnimContext ac;
269         uiBlock *block;
270         int xco, yco= 3, xmax;
271         
272         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
273         uiBlockSetHandleFunc(block, do_action_buttons, NULL);
274         
275         xco= ED_area_header_standardbuttons(C, block, yco);
276         
277         uiBlockSetEmboss(block, UI_EMBOSS);
278         
279         /* get context... (also syncs data) */
280         ANIM_animdata_get_context(C, &ac);
281         
282         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
283                 
284                 xmax= GetButStringLength("View");
285                 uiDefMenuBut(block, act_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
286                 xco+= xmax;
287                 
288                 xmax= GetButStringLength("Select");
289                 uiDefMenuBut(block, act_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
290                 xco+= xmax;
291                 
292                 if ( (saction->mode == SACTCONT_DOPESHEET) ||
293                          ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) 
294                 {
295                         xmax= GetButStringLength("Channel");
296                         uiDefMenuBut(block, act_channelmenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
297                         xco+= xmax;
298                 }
299                 else if (saction->mode==SACTCONT_GPENCIL) {
300                         xmax= GetButStringLength("Channel");
301                         uiDefMenuBut(block, act_gplayermenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
302                         xco+= xmax;
303                 }
304                 
305                 //xmax= GetButStringLength("Marker");
306                 //uiDefMenuBut(block, act_markermenu, NULL, "Marker", xco, yco, xmax-3, 20, "");
307                 //xco+= xmax;
308                 
309                 if (saction->mode == SACTCONT_GPENCIL) {
310                         //xmax= GetButStringLength("Frame");
311                         //uiDefMenuBut(block, act_selectmenu, NULL, "Frame", xco, yco, xmax-3, 20, "");
312                         //xco+= xmax;
313                 }
314                 else {
315                         xmax= GetButStringLength("Key");
316                         uiDefMenuBut(block, act_editmenu, NULL, "Key", xco, yco, xmax-3, 20, "");
317                         xco+= xmax;
318                 }
319         }
320
321         uiBlockSetEmboss(block, UI_EMBOSS);
322         
323         /* MODE SELECTOR */
324         uiDefButC(block, MENU, B_REDR, 
325                         "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
326                         xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
327                         "Editing modes for this editor");
328         
329         
330         xco += (90 + 8);
331         
332         /*if (ac.data)*/ 
333         {
334                 /* MODE-DEPENDENT DRAWING */
335                 if (saction->mode == SACTCONT_DOPESHEET) {
336                         /* FILTERING OPTIONS */
337                         xco -= 10;
338                         
339                         xco= ANIM_headerUI_standard_buttons(C, &saction->ads, block, xco, yco);
340                 }
341                 else if (saction->mode == SACTCONT_ACTION) {
342                         uiLayout *layout;
343                         bScreen *sc= CTX_wm_screen(C);
344                         PointerRNA ptr;
345
346                         RNA_pointer_create(&sc->id, &RNA_SpaceDopeSheetEditor, saction, &ptr);
347                         
348                         layout= uiBlockLayout(block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, 20+3, 20, 1, U.uistyles.first);
349                         uiTemplateID(layout, (bContext*)C, &ptr, "action", "ACT_OT_new", NULL, NULL);
350                         uiBlockLayoutResolve(block, &xco, NULL);
351                         
352                         xco += 8;
353                 }
354                 
355                 /* draw AUTOSNAP */
356                 if (saction->mode != SACTCONT_GPENCIL) {
357                         if (saction->flag & SACTION_DRAWTIME) {
358                                 uiDefButC(block, MENU, B_REDR,
359                                                 "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
360                                                 xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, 
361                                                 "Auto-snapping mode for keyframes when transforming");
362                         }
363                         else {
364                                 uiDefButC(block, MENU, B_REDR, 
365                                                 "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
366                                                 xco,yco,90,YIC, &(saction->autosnap), 0, 1, 0, 0, 
367                                                 "Auto-snapping mode for keyframes when transforming");
368                         }
369                         
370                         xco += (90 + 8);
371                 }
372                 
373                 /* COPY PASTE */
374                 uiBlockBeginAlign(block);
375                         uiDefIconButO(block, BUT, "ACT_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco,yco,XIC,YIC, "Copies the selected keyframes to the buffer.");
376                         xco += XIC;
377                         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.");
378                 uiBlockEndAlign(block);
379                 xco += (XIC + 8);
380         }
381
382         /* always as last  */
383         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
384         
385         uiEndBlock(C, block);
386         uiDrawBlock(C, block);
387 }
388
389