Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[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         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
162         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_CFRA);
163         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_FRAME);
164         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_SECOND);
165         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_snap", "type", GRAPHKEYS_SNAP_NEAREST_MARKER);
166 }
167
168 static void graph_edit_mirrormenu(bContext *C, uiLayout *layout, void *arg_unused)
169 {
170         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
171         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_CFRA);
172         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_YAXIS);
173         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_XAXIS);
174         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_mirror", "type", GRAPHKEYS_MIRROR_MARKER);
175 }
176
177 static void graph_edit_handlesmenu(bContext *C, uiLayout *layout, void *arg_unused)
178 {
179         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
180         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_FREE);
181         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_AUTO);
182         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_VECT);
183         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_ALIGN);
184         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_handle_type", "type", HD_AUTO_ANIM); // xxx?
185 }
186
187 static void graph_edit_ipomenu(bContext *C, uiLayout *layout, void *arg_unused)
188 {
189         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
190         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_interpolation_type", "type", BEZT_IPO_CONST);
191         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_interpolation_type", "type", BEZT_IPO_LIN);
192         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_interpolation_type", "type", BEZT_IPO_BEZ);
193 }
194
195 static void graph_edit_expomenu(bContext *C, uiLayout *layout, void *arg_unused)
196 {
197         uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); // xxx?
198         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_CONSTANT);
199         uiItemEnumO(layout, NULL, 0, "GRAPH_OT_extrapolation_type", "type", FCURVE_EXTRAPOLATE_LINEAR);
200 }
201
202 static void graph_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
203 {
204         uiItemMenuF(layout, "Transform", 0, graph_edit_transformmenu, NULL);
205         uiItemMenuF(layout, "Snap", 0, graph_edit_snapmenu, NULL);
206         uiItemMenuF(layout, "Mirror", 0, graph_edit_mirrormenu, NULL);
207         
208         uiItemS(layout);
209         
210         uiItemO(layout, NULL, 0, "GRAPH_OT_insert_keyframe");
211         uiItemO(layout, NULL, 0, "GRAPH_OT_fmodifier_add");
212         
213         uiItemS(layout);
214         
215         uiItemO(layout, NULL, 0, "GRAPH_OT_duplicate");
216         uiItemO(layout, NULL, 0, "GRAPH_OT_delete");
217         
218         uiItemS(layout);
219         
220         uiItemMenuF(layout, "Handle Type", 0, graph_edit_handlesmenu, NULL);
221         uiItemMenuF(layout, "Interpolation Mode", 0, graph_edit_ipomenu, NULL);
222         uiItemMenuF(layout, "Extrapolation Mode", 0, graph_edit_expomenu, NULL);
223         
224         uiItemS(layout);
225         
226         uiItemO(layout, NULL, 0, "GRAPH_OT_clean");
227         uiItemO(layout, NULL, 0, "GRAPH_OT_sample");
228         uiItemO(layout, NULL, 0, "GRAPH_OT_bake");
229         
230         uiItemS(layout);
231         
232         uiItemO(layout, NULL, 0, "GRAPH_OT_copy");
233         uiItemO(layout, NULL, 0, "GRAPH_OT_paste");
234 }
235
236 /* ********************************************************* */
237
238 enum {
239         B_REDR = 0,
240         B_MODECHANGE,
241 } eGraphEdit_Events;
242
243 static void do_graph_buttons(bContext *C, void *arg, int event)
244 {
245         switch (event) {
246                 case B_MODECHANGE: /* change mode with mode selector */
247                         ED_area_tag_refresh(CTX_wm_area(C));
248                         /* no break, as we need redraw flush too... */
249                         
250                 case B_REDR:
251                         ED_area_tag_redraw(CTX_wm_area(C));
252                         break;
253         }
254 }
255
256
257 void graph_header_buttons(const bContext *C, ARegion *ar)
258 {
259         ScrArea *sa= CTX_wm_area(C);
260         SpaceIpo *sipo= CTX_wm_space_graph(C);
261         uiBlock *block;
262         int xco, yco= 3;
263         
264         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
265         uiBlockSetHandleFunc(block, do_graph_buttons, NULL);
266         
267         xco= ED_area_header_standardbuttons(C, block, yco);
268         
269         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
270                 int xmax;
271                 
272                 xmax= GetButStringLength("View");
273                 uiDefMenuBut(block, graph_viewmenu, NULL, "View", xco, yco, xmax-3, 20, "");
274                 xco+= xmax;
275                 
276                 xmax= GetButStringLength("Select");
277                 uiDefMenuBut(block, graph_selectmenu, NULL, "Select", xco, yco, xmax-3, 20, "");
278                 xco+= xmax;
279                 
280                 xmax= GetButStringLength("Channel");
281                 uiDefMenuBut(block, graph_channelmenu, NULL, "Channel", xco, yco, xmax-3, 20, "");
282                 xco+= xmax;
283                 
284                 xmax= GetButStringLength("Key");
285                 uiDefMenuBut(block, graph_editmenu, NULL, "Key", xco, yco, xmax-3, 20, "");
286                 xco+= xmax;
287         }
288         
289         uiBlockSetEmboss(block, UI_EMBOSS);
290         
291         /* mode selector */
292         uiDefButS(block, MENU, B_MODECHANGE, 
293                         "Editor Mode %t|F-Curve Editor %x0|Drivers %x1", 
294                         xco,yco,110,YIC, &sipo->mode, 0, 1, 0, 0, 
295                         "Editing modes for this editor");
296         xco+= 120;
297         
298         /* filtering buttons */
299         if (sipo->ads) {
300                 //uiBlockBeginAlign(block);
301                         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");
302                 //uiBlockEndAlign(block);
303                 xco += 5;
304                 
305                 uiBlockBeginAlign(block);
306                         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");
307                                 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");
308                         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");
309                         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");
310                         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");
311                         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");
312                         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");
313                         uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMBA, B_REDR, ICON_META_DATA, (short)(xco+=XIC),yco,XIC,YIC, &(sipo->ads->filterflag), 0, 0, 0, 0, "Display MetaBalls");
314                         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");
315                 uiBlockEndAlign(block);
316                 xco += 30;
317         }
318         else {
319                 // XXX this case shouldn't happen at all... for now, just pad out same amount of space
320                 xco += 10*XIC + 30;
321         }
322         
323         /* auto-snap selector */
324         if (sipo->flag & SIPO_DRAWTIME) {
325                 uiDefButS(block, MENU, B_REDR,
326                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Second %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         else {
331                 uiDefButS(block, MENU, B_REDR, 
332                                 "Auto-Snap Keyframes %t|No Time-Snap %x0|Nearest Frame %x2|Nearest Marker %x3", 
333                                 xco,yco,90,YIC, &sipo->autosnap, 0, 1, 0, 0, 
334                                 "Auto-snapping mode for keyframe times when transforming");
335         }
336         xco += 98;
337         
338         /* copy + paste */
339         uiBlockBeginAlign(block);
340                 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");
341                 uiDefIconButO(block, BUT, "GRAPH_OT_paste", WM_OP_INVOKE_REGION_WIN, ICON_PASTEDOWN, xco+=XIC,yco,XIC,YIC, "Pastes the keyframes from the buffer");
342         uiBlockEndAlign(block);
343         xco += (XIC + 8);
344         
345         /* ghost curves */
346         // XXX these icons need to be changed
347         if (sipo->ghostCurves.first)
348                 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");
349         else 
350                 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");
351         xco+= XIC;
352         
353         
354         /* always as last  */
355         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax - ar->v2d.tot.ymin));
356         
357         uiEndBlock(C, block);
358         uiDrawBlock(C, block);
359 }
360
361