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