5a7b7d654b1c2f02ddf8f5393bf79c0211f1a1a6
[blender.git] / source / blender / editors / space_graph / graph_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_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_windowmanager_types.h"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41
42 #include "BKE_context.h"
43 #include "BKE_screen.h"
44
45 #include "ED_anim_api.h"
46 #include "ED_transform.h"
47 #include "ED_screen.h"
48 #include "ED_types.h"
49 #include "ED_util.h"
50
51 #include "RNA_access.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "BIF_gl.h"
57 #include "BIF_glutil.h"
58
59 #include "UI_interface.h"
60 #include "UI_resources.h"
61 #include "UI_view2d.h"
62
63 #include "graph_intern.h"
64
65 /* ********************************************************* */
66 /* Menu Defines... */
67
68 static void graph_viewmenu(bContext *C, uiLayout *layout, void *arg_unused)
69 {
70         bScreen *sc= CTX_wm_screen(C);
71         ScrArea *sa= CTX_wm_area(C);
72         SpaceIpo *sipo= CTX_wm_space_graph(C);
73         PointerRNA spaceptr;
74         
75         /* retrieve state */
76         RNA_pointer_create(&sc->id, &RNA_SpaceGraphEditor, sipo, &spaceptr);
77         
78         /* create menu */
79         uiItemO(layout, NULL, ICON_MENU_PANEL, "GRAPH_OT_properties");
80         
81         uiItemS(layout);
82         
83         uiItemR(layout, NULL, 0, &spaceptr, "show_cframe_indicator", 0, 0, 0);
84         
85         if (sipo->flag & SIPO_NOHANDLES)
86                 uiItemO(layout, "Show Handles", ICON_CHECKBOX_DEHLT, "GRAPH_OT_handles_view_toggle");
87         else
88                 uiItemO(layout, "Show Handles", ICON_CHECKBOX_HLT, "GRAPH_OT_handles_view_toggle");
89         
90         uiItemR(layout, NULL, 0, &spaceptr, "only_selected_curves_handles", 0, 0, 0);
91         uiItemR(layout, NULL, 0, &spaceptr, "automerge_keyframes", 0, 0, 0);
92         
93         if (sipo->flag & SIPO_DRAWTIME)
94                 uiItemO(layout, "Show Frames", 0, "ANIM_OT_time_toggle");
95         else
96                 uiItemO(layout, "Show Seconds", 0, "ANIM_OT_time_toggle");
97         
98         uiItemS(layout);
99         
100         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_set");
101         uiItemO(layout, NULL, 0, "ANIM_OT_previewrange_clear");
102         
103         uiItemO(layout, NULL, 0, "GRAPH_OT_previewrange_set");
104         
105         uiItemS(layout);
106         
107         uiItemO(layout, NULL, 0, "GRAPH_OT_frame_jump");
108         
109         uiItemO(layout, NULL, 0, "GRAPH_OT_view_all");
110         
111         if (sa->full) 
112                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Tile Window", Ctrl UpArrow
113         else 
114                 uiItemO(layout, NULL, 0, "SCREEN_OT_screen_full_area"); // "Maximize Window", Ctrl DownArrow
115 }
116
117 static void graph_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
118 {
119         uiItemO(layout, NULL, 0, "GRAPH_OT_select_all_toggle");
120         uiItemBooleanO(layout, "Invert All", 0, "GRAPH_OT_select_all_toggle", "invert", 1);
121         
122         uiItemS(layout);
123         
124         uiItemO(layout, NULL, 0, "GRAPH_OT_select_border");
125         uiItemBooleanO(layout, "Border Axis Range", 0, "GRAPH_OT_select_border", "axis_range", 1);
126         
127         uiItemS(layout);
128         
129         uiItemEnumO(layout, "Columns on Selected Keys", 0, "GRAPH_OT_select_column", "mode", GRAPHKEYS_COLUMNSEL_KEYS);
130         uiItemEnumO(layout, "Column on Current Frame", 0, "GRAPH_OT_select_column", "mode", GRAPHKEYS_COLUMNSEL_CFRA);
131         
132         uiItemEnumO(layout, "Columns on Selected Markers", 0, "GRAPH_OT_select_column", "mode", GRAPHKEYS_COLUMNSEL_MARKERS_COLUMN);
133         uiItemEnumO(layout, "Between Selected Markers", 0, "GRAPH_OT_select_column", "mode", GRAPHKEYS_COLUMNSEL_MARKERS_BETWEEN);
134 }
135
136 static void graph_channelmenu(bContext *C, uiLayout *layout, void *arg_unused)
137 {
138         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_toggle");
139         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_enable");
140         uiItemO(layout, NULL, 0, "ANIM_OT_channels_setting_disable");
141         
142         uiItemS(layout);
143         
144         uiItemO(layout, NULL, 0, "ANIM_OT_channels_editable_toggle");
145         
146         uiItemS(layout);
147         
148         uiItemO(layout, NULL, 0, "ANIM_OT_channels_expand");
149         uiItemO(layout, NULL, 0, "ANIM_OT_channels_collapse");
150 }
151
152 static void graph_edit_transformmenu(bContext *C, uiLayout *layout, void *arg_unused)
153 {
154         uiItemEnumO(layout, "Grab/Move", 0, "TFM_OT_transform", "mode", TFM_TIME_TRANSLATE);
155         uiItemEnumO(layout, "Extend", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND);
156         uiItemEnumO(layout, "Scale", 0, "TFM_OT_transform", "mode", TFM_TIME_SCALE);
157 }
158
159 static void graph_edit_snapmenu(bContext *C, uiLayout *layout, void *arg_unused)
160 {
161         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_CFRA);
162         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_FRAME);
163         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_SECOND);
164         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_MARKER);
165 }
166
167 static void graph_edit_mirrormenu(bContext *C, uiLayout *layout, void *arg_unused)
168 {
169         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_CFRA);
170         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_YAXIS);
171         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_XAXIS);
172         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_MARKER);
173 }
174
175 static void graph_edit_handlesmenu(bContext *C, uiLayout *layout, void *arg_unused)
176 {
177         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_FREE);
178         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_AUTO);
179         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_VECT);
180         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_ALIGN);
181         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_AUTO_ANIM); // xxx?
182 }
183
184 static void graph_edit_ipomenu(bContext *C, uiLayout *layout, void *arg_unused)
185 {
186         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_interpolation_type", "type", BEZT_IPO_CONST);
187         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_interpolation_type", "type", BEZT_IPO_LIN);
188         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_interpolation_type", "type", BEZT_IPO_BEZ);
189 }
190
191 static void graph_edit_expomenu(bContext *C, uiLayout *layout, void *arg_unused)
192 {
193         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_CONSTANT);
194         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_LINEAR);
195 }
196
197 static void graph_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
198 {
199         uiItemMenuF(layout, "Transform", 0, graph_edit_transformmenu);
200         uiItemMenuF(layout, "Snap", 0, graph_edit_snapmenu);
201         uiItemMenuF(layout, "Mirror", 0, graph_edit_mirrormenu);
202         
203         uiItemS(layout);
204         
205         uiItemO(layout, NULL, 0, "GRAPH_OT_insert_keyframe");
206         uiItemO(layout, NULL, 0, "GRAPH_OT_fmodifier_add");
207         
208         uiItemS(layout);
209         
210         uiItemO(layout, NULL, 0, "GRAPH_OT_duplicate");
211         uiItemO(layout, NULL, 0, "GRAPH_OT_delete");
212         
213         uiItemS(layout);
214         
215         uiItemMenuF(layout, "Handle Type", 0, graph_edit_handlesmenu);
216         uiItemMenuF(layout, "Interpolation Mode", 0, graph_edit_ipomenu);
217         uiItemMenuF(layout, "Extrapolation Mode", 0, graph_edit_expomenu);
218         
219         uiItemS(layout);
220         
221         uiItemO(layout, NULL, 0, "GRAPH_OT_clean");
222         uiItemO(layout, NULL, 0, "GRAPH_OT_sample");
223         uiItemO(layout, NULL, 0, "GRAPH_OT_bake");
224         
225         uiItemS(layout);
226         
227         uiItemO(layout, NULL, 0, "GRAPH_OT_copy");
228         uiItemO(layout, NULL, 0, "GRAPH_OT_paste");
229 }
230
231 /* ********************************************************* */
232
233 enum {
234         B_REDR = 0,
235         B_MODECHANGE,
236 } eGraphEdit_Events;
237
238 static void do_graph_buttons(bContext *C, void *arg, int event)
239 {
240         switch (event) {
241                 case B_MODECHANGE: /* change mode with mode selector */
242                         ED_area_tag_refresh(CTX_wm_area(C));
243                         /* no break, as we need redraw flush too... */
244                         
245                 case B_REDR:
246                         ED_area_tag_redraw(CTX_wm_area(C));
247                         break;
248         }
249 }
250
251
252 void graph_header_buttons(const bContext *C, ARegion *ar)
253 {
254         ScrArea *sa= CTX_wm_area(C);
255         SpaceIpo *sipo= CTX_wm_space_graph(C);
256         uiBlock *block;
257         int xco, yco= 3;
258         
259         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
260         uiBlockSetHandleFunc(block, do_graph_buttons, NULL);
261         
262         xco= ED_area_header_standardbuttons(C, block, yco);
263         
264         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
265                 int xmax;
266                 
267                 xmax= GetButStringLength("View");
268                 uiDefMenuBut(block, graph_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
269                 xco+= xmax;
270                 
271                 xmax= GetButStringLength("Select");
272                 uiDefMenuBut(block, graph_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
273                 xco+= xmax;
274                 
275                 xmax= GetButStringLength("Channel");
276                 uiDefMenuBut(block, graph_channelmenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
277                 xco+= xmax;
278                 
279                 xmax= GetButStringLength("Key");
280                 uiDefMenuBut(block, graph_editmenu, NULL, "Key", xco, yco, xmax-3, 20, "");
281                 xco+= xmax;
282         }
283         
284         uiBlockSetEmboss(block, UI_EMBOSS);
285         
286         /* mode selector */
287         uiDefButS(block, MENU, B_MODECHANGE, 
288                         "Editor Mode %t|F-Curve Editor %x0|Drivers %x1", 
289                         xco,yco,110,YIC, &sipo->mode, 0, 1, 0, 0, 
290                         "Editing modes for this editor");
291         xco+= 120;
292         
293         /* filtering buttons */
294         if (sipo->ads) {
295                 //uiBlockBeginAlign(block);
296                         uiDefIconButBitI(block, TOG, ADS_FILTER_ONLYSEL, B_REDR, ICON_RESTRICT_SELECT_OFF,      (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Only display selected Objects");
297                 //uiBlockEndAlign(block);
298                 xco += 5;
299                 
300                 uiBlockBeginAlign(block);
301                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSCE, B_REDR, ICON_SCENE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display Scene Animation");
302                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOWOR, B_REDR, ICON_WORLD_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display World Animation");
303                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_SHAPEKEY_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display ShapeKeys");
304                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL_DATA,     (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display Materials");
305                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display Lamps");
306                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA_DATA,       (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display Cameras");
307                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE_DATA,        (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display Curves");
308                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOPART, B_REDR, ICON_PARTICLE_DATA,    (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display Particles");
309                 uiBlockEndAlign(block);
310                 xco += 30;
311         }
312         else {
313                 // XXX this case shouldn't happen at all... for now, just pad out same amount of space
314                 xco += 9*XIC + 30;
315         }
316         
317         /* auto-snap selector */
318         if (sipo->flag & SIPO_DRAWTIME) {
319                 uiDefButS(block, MENU, B_REDR,
320                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Second %x2|Nearest Marker %x3", 
321                                 xco,yco,90,YIC, &sipo->autosnap, 0, 1, 0, 0, 
322                                 "Auto-snapping mode for keyframe times when transforming");
323         }
324         else {
325                 uiDefButS(block, MENU, B_REDR, 
326                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Frame %x2|Nearest Marker %x3", 
327                                 xco,yco,90,YIC, &sipo->autosnap, 0, 1, 0, 0, 
328                                 "Auto-snapping mode for keyframe times when transforming");
329         }
330         xco += 98;
331         
332         /* copy + paste */
333         uiBlockBeginAlign(block);
334                 uiDefIconButO(block, BUT, "GRAPH_OT_copy", WM_OP_INVOKE_REGION_WIN, ICON_COPYDOWN, xco+=XIC,yco,XIC,YIC, "Copies the selected keyframes from the selected channel(s) to the buffer");
335                 uiDefIconButO(block, BUT, "GRAPH_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_PASTEDOWN, xco+=XIC,yco,XIC,YIC, "Pastes the keyframes from the buffer");
336         uiBlockEndAlign(block);
337         xco += (XIC + 8);
338         
339         /* ghost curves */
340         // XXX these icons need to be changed
341         if (sipo->ghostCurves.first)
342                 uiDefIconButO(block, BUT, "GRAPH_OT_ghost_curves_clear", WM_OP_INVOKE_REGION_WIN, ICON_OUTLINER_DATA_CURVE, xco,yco,XIC,YIC, "Clear F-Curve snapshots (Ghosts) for this Graph Editor instance");
343         else 
344                 uiDefIconButO(block, BUT, "GRAPH_OT_ghost_curves_create", WM_OP_INVOKE_REGION_WIN, ICON_OUTLINER_OB_CURVE, xco,yco,XIC,YIC, "Create snapshot (Ghosts) of selected F-Curves as background aid for this Graph Editor instance");
345         xco+= XIC;
346         
347         
348         /* always as last  */
349         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax - ar->v2d.tot.ymin));
350         
351         uiEndBlock(C, block);
352         uiDrawBlock(C, block);
353 }
354
355