2.5 / Nodes
[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_action_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_screen.h"
47 #include "ED_types.h"
48 #include "ED_util.h"
49
50 #include "WM_api.h"
51 #include "WM_types.h"
52
53 #include "BIF_gl.h"
54 #include "BIF_glutil.h"
55
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
59
60 #include "action_intern.h"
61
62 /* ********************************************************* */
63 /* Menu Defines... */
64
65 // XXX button events
66 enum {
67         B_REDR  = 0,
68         B_ACTCOPYKEYS,
69         B_ACTPASTEKEYS,
70 } eActHeader_ButEvents;
71
72 // ---------------- menus 
73
74 /* Key menu ---------------------------  */
75
76 static void do_keymenu(bContext *C, void *arg, int event)
77 {
78         
79 }
80
81 static uiBlock *action_keymenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
82 {
83         ScrArea *curarea= CTX_wm_area(C);
84         uiBlock *block;
85         short yco= 0, menuwidth=120;
86         
87         block= uiBeginBlock(C, handle->region, "dummy_keymenu", UI_EMBOSSP, UI_HELV);
88         uiBlockSetButmFunc(block, do_keymenu, NULL);
89         
90         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
91                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
92         
93         if(curarea->headertype==HEADERTOP) {
94                 uiBlockSetDirection(block, UI_DOWN);
95         }
96         else {
97                 uiBlockSetDirection(block, UI_TOP);
98                 uiBlockFlipOrder(block);
99         }
100         
101         uiTextBoundsBlock(block, 50);
102         uiEndBlock(C, block);
103         
104         return block;
105 }
106
107 /* Frame menu ---------------------------  */
108
109 static void do_framemenu(bContext *C, void *arg, int event)
110 {
111         
112 }
113
114 static uiBlock *action_framemenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
115 {
116         ScrArea *curarea= CTX_wm_area(C);
117         uiBlock *block;
118         short yco= 0, menuwidth=120;
119         
120         block= uiBeginBlock(C, handle->region, "dummy_framemenu", UI_EMBOSSP, UI_HELV);
121         uiBlockSetButmFunc(block, do_framemenu, NULL);
122         
123         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
124                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
125         
126         if(curarea->headertype==HEADERTOP) {
127                 uiBlockSetDirection(block, UI_DOWN);
128         }
129         else {
130                 uiBlockSetDirection(block, UI_TOP);
131                 uiBlockFlipOrder(block);
132         }
133         
134         uiTextBoundsBlock(block, 50);
135         uiEndBlock(C, block);
136         
137         return block;
138 }
139
140 /* Marker menu ---------------------------  */
141
142 static void do_markermenu(bContext *C, void *arg, int event)
143 {
144         
145 }
146
147 static uiBlock *action_markermenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
148 {
149         ScrArea *curarea= CTX_wm_area(C);
150         uiBlock *block;
151         short yco= 0, menuwidth=120;
152         
153         block= uiBeginBlock(C, handle->region, "dummy_markermenu", UI_EMBOSSP, UI_HELV);
154         uiBlockSetButmFunc(block, do_markermenu, NULL);
155         
156         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
157                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
158         
159         if(curarea->headertype==HEADERTOP) {
160                 uiBlockSetDirection(block, UI_DOWN);
161         }
162         else {
163                 uiBlockSetDirection(block, UI_TOP);
164                 uiBlockFlipOrder(block);
165         }
166         
167         uiTextBoundsBlock(block, 50);
168         uiEndBlock(C, block);
169         
170         return block;
171 }
172
173 /* Grease Pencil ---------------------------  */
174
175 static void do_gplayermenu(bContext *C, void *arg, int event)
176 {
177         
178 }
179
180 static uiBlock *action_gplayermenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
181 {
182         ScrArea *curarea= CTX_wm_area(C);
183         uiBlock *block;
184         short yco= 0, menuwidth=120;
185         
186         block= uiBeginBlock(C, handle->region, "dummy_gplayermenu", UI_EMBOSSP, UI_HELV);
187         uiBlockSetButmFunc(block, do_gplayermenu, NULL);
188         
189         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
190                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
191         
192         if(curarea->headertype==HEADERTOP) {
193                 uiBlockSetDirection(block, UI_DOWN);
194         }
195         else {
196                 uiBlockSetDirection(block, UI_TOP);
197                 uiBlockFlipOrder(block);
198         }
199         
200         uiTextBoundsBlock(block, 50);
201         uiEndBlock(C, block);
202         
203         return block;
204 }
205
206 /* Channel menu ---------------------------  */
207
208 static void do_channelmenu(bContext *C, void *arg, int event)
209 {
210         
211 }
212
213 static uiBlock *action_channelmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
214 {
215         ScrArea *curarea= CTX_wm_area(C);
216         uiBlock *block;
217         short yco= 0, menuwidth=120;
218         
219         block= uiBeginBlock(C, handle->region, "dummy_channelmenu", UI_EMBOSSP, UI_HELV);
220         uiBlockSetButmFunc(block, do_channelmenu, NULL);
221         
222         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
223                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
224         
225         if(curarea->headertype==HEADERTOP) {
226                 uiBlockSetDirection(block, UI_DOWN);
227         }
228         else {
229                 uiBlockSetDirection(block, UI_TOP);
230                 uiBlockFlipOrder(block);
231         }
232         
233         uiTextBoundsBlock(block, 50);
234         uiEndBlock(C, block);
235         
236         return block;
237 }
238
239 /* Select menu ---------------------------  */
240
241 static void do_selectmenu(bContext *C, void *arg, int event)
242 {
243         
244 }
245
246 static uiBlock *action_selectmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
247 {
248         ScrArea *curarea= CTX_wm_area(C);
249         uiBlock *block;
250         short yco= 0, menuwidth=120;
251         
252         block= uiBeginBlock(C, handle->region, "dummy_selectmenu", UI_EMBOSSP, UI_HELV);
253         uiBlockSetButmFunc(block, do_selectmenu, NULL);
254         
255         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
256                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
257         
258         if(curarea->headertype==HEADERTOP) {
259                 uiBlockSetDirection(block, UI_DOWN);
260         }
261         else {
262                 uiBlockSetDirection(block, UI_TOP);
263                 uiBlockFlipOrder(block);
264         }
265         
266         uiTextBoundsBlock(block, 50);
267         uiEndBlock(C, block);
268         
269         return block;
270 }
271
272 /* View menu ---------------------------  */
273
274 static void do_viewmenu(bContext *C, void *arg, int event)
275 {
276         
277 }
278
279 static uiBlock *action_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
280 {
281         ScrArea *curarea= CTX_wm_area(C);
282         uiBlock *block;
283         short yco= 0, menuwidth=120;
284         
285         block= uiBeginBlock(C, handle->region, "dummy_viewmenu", UI_EMBOSSP, UI_HELV);
286         uiBlockSetButmFunc(block, do_viewmenu, NULL);
287         
288         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Nothing yet", 0, yco-=20, 
289                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
290         
291         if(curarea->headertype==HEADERTOP) {
292                 uiBlockSetDirection(block, UI_DOWN);
293         }
294         else {
295                 uiBlockSetDirection(block, UI_TOP);
296                 uiBlockFlipOrder(block);
297         }
298         
299         uiTextBoundsBlock(block, 50);
300         uiEndBlock(C, block);
301         
302         return block;
303 }
304
305 /* ************************ header area region *********************** */
306
307 static void do_action_buttons(bContext *C, void *arg, int event)
308 {
309         switch(event) {
310                 case B_REDR:
311                         ED_region_tag_redraw(CTX_wm_region(C));
312                         break;
313         }
314 }
315
316 void action_header_buttons(const bContext *C, ARegion *ar)
317 {
318         ScrArea *sa= CTX_wm_area(C);
319         SpaceAction *saction= (SpaceAction *)CTX_wm_space_data(C);
320         bAnimContext ac;
321         uiBlock *block;
322         int xco, yco= 3, xmax;
323         
324         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
325         uiBlockSetHandleFunc(block, do_action_buttons, NULL);
326         
327         xco= ED_area_header_standardbuttons(C, block, yco);
328         
329         uiBlockSetEmboss(block, UI_EMBOSS);
330         
331         /* get context... (also syncs data) */
332         ANIM_animdata_get_context(C, &ac);
333         
334         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
335                 /* pull down menus */
336                 uiBlockSetEmboss(block, UI_EMBOSSP);
337                 
338                 xmax= GetButStringLength("View");
339                 uiDefPulldownBut(block, action_viewmenu, CTX_wm_area(C), 
340                                           "View", xco, yco, xmax-3, 24, "");
341                 xco+= xmax;
342                 
343                 xmax= GetButStringLength("Select");
344                 uiDefPulldownBut(block, action_selectmenu, CTX_wm_area(C), 
345                                           "Select", xco, yco, xmax-3, 24, "");
346                 xco+= xmax;
347                 
348                 if ( (saction->mode == SACTCONT_DOPESHEET) ||
349                          ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) 
350                 {
351                         xmax= GetButStringLength("Channel");
352                         uiDefPulldownBut(block, action_channelmenu, CTX_wm_area(C), 
353                                                   "Channel", xco, yco, xmax-3, 24, "");
354                         xco+= xmax;
355                 }
356                 else if (saction->mode==SACTCONT_GPENCIL) {
357                         xmax= GetButStringLength("Channel");
358                         uiDefPulldownBut(block, action_gplayermenu, CTX_wm_area(C), 
359                                                   "Channel", xco, yco, xmax-3, 24, "");
360                         xco+= xmax;
361                 }
362                 
363                 xmax= GetButStringLength("Marker");
364                 uiDefPulldownBut(block, action_markermenu, CTX_wm_area(C), 
365                                           "Marker", xco, yco, xmax-3, 24, "");
366                 xco+= xmax;
367                 
368                 if (saction->mode == SACTCONT_GPENCIL) {
369                         xmax= GetButStringLength("Frame");
370                         uiDefPulldownBut(block, action_framemenu, CTX_wm_area(C), 
371                                                   "Frame", xco, yco, xmax-3, 24, "");
372                         xco+= xmax;
373                 }
374                 else {
375                         xmax= GetButStringLength("Key");
376                         uiDefPulldownBut(block, action_keymenu, CTX_wm_area(C), 
377                                                   "Key", xco, yco, xmax-3, 24, "");
378                         xco+= xmax;
379                 }
380         }
381
382         uiBlockSetEmboss(block, UI_EMBOSS);
383         
384         /* MODE SELECTOR */
385         uiDefButC(block, MENU, B_REDR, 
386                         "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
387                         xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
388                         "Editing modes for this editor");
389         
390         
391         xco += (90 + 8);
392         
393         if (ac.data) {
394                 /* MODE-DEPENDENT DRAWING */
395                 if (saction->mode == SACTCONT_DOPESHEET) {
396                         /* FILTERING OPTIONS */
397                         xco -= 10;
398                         
399                         //uiBlockBeginAlign(block);
400                                 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");
401                         //uiBlockEndAlign(block);
402                         xco += 5;
403                         
404                         uiBlockBeginAlign(block);
405                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOOBJ, B_REDR, ICON_OBJECT,    (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Non-Armature Objects");
406                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOARM, B_REDR, ICON_ARMATURE,  (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Armature Objects");
407                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_EDIT,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display ShapeKeys");
408                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL,  (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Materials");
409                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Lamps");
410                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA,    (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Cameras");
411                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE,     (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Curves");
412                         uiBlockEndAlign(block);
413                         xco += 5;
414                         
415                         uiBlockBeginAlign(block);               
416                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOIPOS, B_REDR, ICON_IPO,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Object IPO's");
417                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOACTS, B_REDR, ICON_ACTION,   (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Actions");
418                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCONSTRAINTS, B_REDR, ICON_CONSTRAINT,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Object Constraints");
419                         uiBlockEndAlign(block);
420                         xco += 30;
421                 }
422                 else if (saction->mode == SACTCONT_ACTION) { // not too appropriate for shapekeys atm...
423                         /* NAME ETC */
424                                 // XXX missing stuff here!
425                         //ob= OBACT;
426                         //from = (ID *)ob;
427                         
428                         //xco= std_libbuttons(block, xco, 0, B_ACTPIN, saction->pin, 
429                         //                                      B_ACTIONBROWSE, ID_AC, 0, (ID*)saction->action, 
430                         //                                      from, &(saction->actnr), B_ACTALONE, 
431                         //                                      B_ACTLOCAL, B_ACTIONDELETE, 0, B_KEEPDATA);     
432                         
433                         //uiClearButLock();
434                         
435                         xco += 8;
436                 }
437                 
438                 /* COPY PASTE */
439                 uiBlockBeginAlign(block);
440                 uiDefIconBut(block, BUT, B_ACTCOPYKEYS, ICON_COPYDOWN,  xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Copies the selected keyframes from the selected channel(s) to the buffer");
441                 uiDefIconBut(block, BUT, B_ACTPASTEKEYS, ICON_PASTEDOWN,        xco+=XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Pastes the keyframes from the buffer");
442                 uiBlockEndAlign(block);
443                 xco += (XIC + 8);
444                 
445                 /* draw AUTOSNAP */
446                 if (saction->mode != SACTCONT_GPENCIL) {
447                         if (saction->flag & SACTION_DRAWTIME) {
448                                 uiDefButC(block, MENU, B_REDR,
449                                                 "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
450                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
451                                                 "Auto-snapping mode for keyframes when transforming");
452                         }
453                         else {
454                                 uiDefButC(block, MENU, B_REDR, 
455                                                 "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
456                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
457                                                 "Auto-snapping mode for keyframes when transforming");
458                         }
459                         
460                         xco += (70 + 8);
461                 }
462                 
463                 /* draw LOCK */
464                 uiDefIconButS(block, ICONTOG, 1, ICON_UNLOCKED, xco, yco, XIC, YIC, 
465                                           &(saction->lock), 0, 0, 0, 0, 
466                                           "Updates other affected window spaces automatically "
467                                           "to reflect changes in real time");
468         }
469
470         /* always as last  */
471         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
472         
473         uiEndBlock(C, block);
474         uiDrawBlock(C, block);
475 }
476
477