2.5: Fix timeline space redraw properties, these were not RNA wrapped
[blender.git] / source / blender / editors / space_time / time_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  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <string.h>
31 #include <stdio.h>
32
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 #include "DNA_userdef_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42
43 #include "BKE_context.h"
44 #include "BKE_global.h"
45 #include "BKE_screen.h"
46
47 #include "ED_keyframing.h"
48 #include "ED_screen.h"
49 #include "ED_screen_types.h"
50 #include "ED_types.h"
51 #include "ED_util.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "RNA_access.h"
57
58 #include "BIF_gl.h"
59 #include "BIF_glutil.h"
60
61 #include "UI_interface.h"
62 #include "UI_resources.h"
63 #include "UI_view2d.h"
64
65 #include "ED_markers.h"
66
67 #include "time_intern.h"
68
69
70 /* ************************ header time area region *********************** */
71
72 static void do_time_viewmenu(bContext *C, void *arg, int event)
73 {
74         ScrArea *curarea= CTX_wm_area(C);
75         SpaceTime *stime= CTX_wm_space_time(C);
76         View2D *v2d= UI_view2d_fromcontext_rwin(C);
77         Scene *scene= CTX_data_scene(C);
78         int first;
79         
80         switch(event) {
81                 case 2: /* Play Back Animation */
82                         //if(!has_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM))
83                         //      start_animated_screen(stime);
84                         break;
85                 case 3: /* View All */
86                         if(v2d) {
87                                 first= scene->r.sfra;
88                                 if(first >= scene->r.efra) first= scene->r.efra;
89                                         v2d->cur.xmin=v2d->tot.xmin= (float)first-2;
90                                 v2d->cur.xmax=v2d->tot.xmax= (float)scene->r.efra+2;
91                         
92                                 ED_area_tag_redraw(curarea);
93                         }
94                         break;
95                 case 4: /* Maximize Window */
96                         /* using event B_FULL */
97                         break;
98                 case 5: /* show time or frames */
99                         stime->flag ^= TIME_DRAWFRAMES;
100                         ED_area_tag_redraw(curarea);
101                         break;
102                 case 6:
103                         //nextprev_marker(1);
104                         break;
105                 case 7:
106                         //nextprev_marker(-1);
107                         break;
108                 case 10:
109                         //timeline_frame_to_center();
110                         break;
111                 case 11:
112                         if(v2d) {
113                                 v2d->flag ^= V2D_VIEWSYNC_SCREEN_TIME;
114                                 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_SET);
115                         }
116                         break;
117                 case 12: /* only show keyframes from selected data */
118                         stime->flag ^= TIME_ONLYACTSEL;
119                         ED_area_tag_redraw(curarea);
120                         break;
121         }
122 }
123
124 static uiBlock *time_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
125 {
126         ScrArea *curarea= CTX_wm_area(C);
127         SpaceTime *stime= CTX_wm_space_time(C);
128         View2D *v2d= UI_view2d_fromcontext_rwin(C);
129         uiBlock *block;
130         short yco= 0, menuwidth=120;
131         
132         block= uiBeginBlock(C, ar, "time_viewmenu", UI_EMBOSSP);
133         uiBlockSetButmFunc(block, do_time_viewmenu, NULL);
134         
135         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
136                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
137         
138         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
139         
140         if(stime->flag & TIME_DRAWFRAMES)
141                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
142         else 
143                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Frames|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
144         
145         uiDefIconTextBut(block, BUTM, 1, (stime->flag & TIME_ONLYACTSEL)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
146                                          "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
147         
148         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
149         
150         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
151         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
152         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
153         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
154         
155         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
156         
157         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
158         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
159         uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
160                                          "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
161         
162 //      if (!curarea->full) 
163 //              uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
164 //      else 
165 //              uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
166         
167         if(curarea->headertype==HEADERTOP) {
168                 uiBlockSetDirection(block, UI_DOWN);
169         }
170         else {
171                 uiBlockSetDirection(block, UI_TOP);
172                 uiBlockFlipOrder(block);
173         }
174         
175         uiTextBoundsBlock(block, 50);
176         uiEndBlock(C, block);
177         
178         return block;
179 }
180
181 static void do_time_framemenu(bContext *C, void *arg, int event)
182 {
183         Scene *scene= CTX_data_scene(C);
184
185         switch(event) {
186                 case 1: /*Set as Start */
187                         if (scene->r.psfra) {
188                                 if (scene->r.pefra < scene->r.cfra)
189                                         scene->r.pefra= scene->r.cfra;
190                                 scene->r.psfra= scene->r.cfra;
191                         }                               
192                         else
193                                 scene->r.sfra = scene->r.cfra;
194                         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
195                         break;
196                 case 2: /* Set as End */
197                         if (scene->r.psfra) {
198                                 if (scene->r.cfra < scene->r.psfra)
199                                         scene->r.psfra= scene->r.cfra;
200                                 scene->r.pefra= scene->r.cfra;
201                         }                               
202                         else
203                                 scene->r.efra = scene->r.cfra;
204                         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
205                         break;
206                 case 3: /* Rename Marker */
207                         //rename_marker();
208                         break;
209         }
210 }
211
212 static uiBlock *time_framemenu(bContext *C, ARegion *ar, void *arg_unused)
213 {
214         ScrArea *curarea= CTX_wm_area(C);
215         uiBlock *block;
216         short yco= 0, menuwidth=120;
217         
218         block= uiBeginBlock(C, ar, "time_framemenu", UI_EMBOSSP);
219         uiBlockSetButmFunc(block, do_time_framemenu, NULL);
220
221         uiDefIconTextButO(block, BUTM, "MARKER_OT_add", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Add Marker",
222                                           0, yco-=2, menuwidth, 19, "");
223         uiDefIconTextButO(block, BUTM, "MARKER_OT_duplicate", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Duplicate Marker",
224                                           0, yco-=20, menuwidth, 19, "");
225         uiDefIconTextButO(block, BUTM, "MARKER_OT_delete", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Delete Marker",
226                                           0, yco-=20, menuwidth, 19, "");
227         
228         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
229         
230         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Name Marker|Ctrl M",
231                                          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
232         uiDefIconTextButO(block, BUTM, "MARKER_OT_move", WM_OP_INVOKE_REGION_WIN, ICON_BLANK1, "Grab/Move Marker",
233                                           0, yco-=20, menuwidth, 19, "");
234         
235         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
236         
237         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set as Start|S",
238                                          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
239         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set as End|E",
240                                          0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
241         
242         if(curarea->headertype==HEADERTOP) {
243                 uiBlockSetDirection(block, UI_DOWN);
244         }
245         else {
246                 uiBlockSetDirection(block, UI_TOP);
247                 uiBlockFlipOrder(block);
248         }
249         
250         uiTextBoundsBlock(block, 50);
251         uiEndBlock(C, block);
252         
253         return block;
254 }
255
256
257 #define B_REDRAWALL             750
258 #define B_TL_PLAY               752
259 #define B_TL_RPLAY              760
260 #define B_TL_STOP               756
261 #define B_TL_PREVIEWON  757
262
263 #define B_FLIPINFOMENU 0
264 #define B_NEWFRAME 0
265 #define B_DIFF 0
266
267
268 void do_time_buttons(bContext *C, void *arg, int event)
269 {
270         Scene *scene= CTX_data_scene(C);
271         
272         switch(event) {
273                 case B_REDRAWALL:
274                         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
275                         break;
276                 case B_NEWFRAME:
277                         WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
278                         break;
279                 case B_TL_PREVIEWON:
280                         if (scene->r.psfra) {
281                                 /* turn on preview range */
282                                 scene->r.psfra= scene->r.sfra;
283                                 scene->r.pefra= scene->r.efra;
284                         }
285                         else {
286                                 /* turn off preview range */
287                                 scene->r.psfra= 0;
288                                 scene->r.pefra= 0;
289                         }
290                         //BIF_undo_push("Set anim-preview range");
291                         WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
292                         break;
293         }
294 }
295
296
297 void time_header_buttons(const bContext *C, ARegion *ar)
298 {
299         ScrArea *sa= CTX_wm_area(C);
300         Scene *scene= CTX_data_scene(C);
301         wmTimer *animtimer= CTX_wm_screen(C)->animtimer;
302         uiBlock *block;
303         uiBut *but;
304         int xco, yco= 3;
305         char *menustr= NULL;
306         
307         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
308         uiBlockSetHandleFunc(block, do_time_buttons, NULL);
309         
310         xco= ED_area_header_standardbuttons(C, block, yco);
311         
312         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
313                 int xmax;
314                 
315                 xmax= GetButStringLength("View");
316                 uiDefPulldownBut(block, time_viewmenu, sa, 
317                                                  "View", xco, yco, xmax-3, 20, "");
318                 xco+= xmax;
319                 xmax= GetButStringLength("Frame");
320                 uiDefPulldownBut(block, time_framemenu, sa, 
321                                                  "Frame", xco, yco, xmax-3, 20, "");
322                 xco+= xmax;
323         }
324         
325         uiBlockSetEmboss(block, UI_EMBOSS);
326         
327         
328         
329         uiDefButI(block, TOG, B_TL_PREVIEWON,"PR",      
330                           xco,yco, XIC*2, YIC,
331                           &scene->r.psfra,0, 1, 0, 0,
332                           "Show settings for frame range of animation preview");
333         
334         xco += XIC*2;
335         
336         uiBlockBeginAlign(block);
337         
338         if (scene->r.psfra) {
339                 uiDefButI(block, NUM, B_REDRAWALL,"Start:",     
340                                   xco,yco, (int)4.5*XIC, YIC,
341                                   &scene->r.psfra,MINFRAMEF, MAXFRAMEF, 0, 0,
342                                   "The start frame of the animation preview (inclusive)");
343                 
344                 xco += (int)(4.5*XIC);
345                 
346                 uiDefButI(block, NUM, B_REDRAWALL,"End:",       
347                                   xco,yco, (int)4.5*XIC,YIC,
348                                   &scene->r.pefra,(float)PSFRA, MAXFRAMEF, 0, 0,
349                                   "The end frame of the animation preview (inclusive)");
350         }
351         else {
352                 uiDefButI(block, NUM, B_REDRAWALL,"Start:",     
353                                   xco,yco, (int)4.5*XIC, YIC,
354                                   &scene->r.sfra,MINFRAMEF, MAXFRAMEF, 0, 0,
355                                   "The start frame of the animation (inclusive)");
356                 
357                 xco += (short)(4.5*XIC);
358                 
359                 uiDefButI(block, NUM, B_REDRAWALL,"End:",       
360                                   xco,yco, (int)4.5*XIC,YIC,
361                                   &scene->r.efra,(float)SFRA, MAXFRAMEF, 0, 0,
362                                   "The end frame of the animation (inclusive)");
363         }
364         uiBlockEndAlign(block);
365         
366         xco += (short)(4.5 * XIC);
367         
368         /* MINAFRAMEF not MINFRAMEF, since MINAFRAMEF allows to set current frame negative 
369          * to facilitate easier keyframing in some situations
370          */
371         uiDefButI(block, NUM, B_NEWFRAME, "",
372                           xco,yco, (int)4.5*XIC,YIC,
373                           &(scene->r.cfra), MINAFRAMEF, MAXFRAMEF, 0, 0,
374                           "Displays Current Frame of animation");
375         
376         xco += (short)(4.5 * XIC);
377         
378         uiBlockBeginAlign(block);
379         
380         but= uiDefIconButO(block, BUT, "SCREEN_OT_frame_jump", WM_OP_INVOKE_REGION_WIN, ICON_REW, xco,yco,XIC,YIC, "Skip to Start frame (Shift DownArrow)");
381                 RNA_boolean_set(uiButGetOperatorPtrRNA(but), "end", 0);
382         xco+= XIC;
383         
384         but= uiDefIconButO(block, BUT, "SCREEN_OT_keyframe_jump", WM_OP_INVOKE_REGION_WIN, ICON_PREV_KEYFRAME, xco,yco,XIC,YIC, "Skip to previous keyframe (Ctrl PageDown)");
385                 RNA_boolean_set(uiButGetOperatorPtrRNA(but), "next", 0);
386         xco+= XIC;
387         
388         if (animtimer) {
389                 /* pause button 2*size to keep buttons in place */
390                 but=uiDefIconButO(block, BUT, "SCREEN_OT_animation_play", WM_OP_INVOKE_REGION_WIN, ICON_PAUSE, xco,yco,XIC*2,YIC, "Stop Playing Timeline");
391                 
392                 xco+= XIC;
393         }
394         else {     
395                 but=uiDefIconButO(block, BUT, "SCREEN_OT_animation_play", WM_OP_INVOKE_REGION_WIN, ICON_PLAY_REVERSE, xco,yco,XIC,YIC, "Play Timeline in Reverse");
396                         RNA_boolean_set(uiButGetOperatorPtrRNA(but), "reverse", 1);     
397                 xco+= XIC;
398                                          
399                 but=uiDefIconButO(block, BUT, "SCREEN_OT_animation_play", WM_OP_INVOKE_REGION_WIN, ICON_PLAY, xco,yco,XIC,YIC, "Play Timeline");
400                         RNA_boolean_set(uiButGetOperatorPtrRNA(but), "reverse", 0);     
401         }
402         xco+= XIC;
403         
404         but= uiDefIconButO(block, BUT, "SCREEN_OT_keyframe_jump", WM_OP_INVOKE_REGION_WIN, ICON_NEXT_KEYFRAME, xco,yco,XIC,YIC, "Skip to next keyframe (Ctrl PageUp)");
405                 RNA_boolean_set(uiButGetOperatorPtrRNA(but), "next", 1);
406         xco+= XIC;
407         
408         but= uiDefIconButO(block, BUT, "SCREEN_OT_frame_jump", WM_OP_INVOKE_REGION_WIN, ICON_FF, xco,yco,XIC,YIC, "Skip to End frame (Shift UpArrow)");
409                 RNA_boolean_set(uiButGetOperatorPtrRNA(but), "end", 1);
410         xco+= XIC;
411         uiBlockEndAlign(block);
412
413         xco+= (short)(0.5*XIC);
414         
415         uiBlockBeginAlign(block);
416         uiDefIconButBitS(block, TOG, AUTOKEY_ON, B_REDRAWALL, ICON_REC,
417                                          xco, yco, XIC, YIC, &(scene->toolsettings->autokey_mode), 0, 0, 0, 0, "Automatic keyframe insertion for Objects and Bones");
418         xco+= 1*XIC;
419         if (IS_AUTOKEY_ON(scene)) {
420                 uiDefButS(block, MENU, B_REDRAWALL, 
421                                   "Auto-Keying Mode %t|Add/Replace%x3|Replace%x5", 
422                                   xco, yco, (int)(4.25*XIC), YIC, &(scene->toolsettings->autokey_mode), 0, 1, 0, 0, 
423                                   "Mode of automatic keyframe insertion for Objects and Bones");
424                 xco+= (short)(4.25*XIC);
425                 
426                 if (animtimer) {
427                         uiDefButBitS(block, TOG, ANIMRECORD_FLAG_WITHNLA, B_REDRAWALL, "Layered",       
428                                   xco,yco, (int)(3.5*XIC), YIC,
429                                   &(scene->toolsettings->autokey_flag),0, 1, 0, 0,
430                                   "Add a new NLA Track + Strip for every loop/pass made over the animation to allow non-destructive tweaking.");
431                         uiBlockEndAlign(block);
432                         
433                         xco+= (short)(3.5*XIC);
434                 }
435                 
436                 xco += XIC;
437                 
438                 uiBlockEndAlign(block);
439         }
440         else {
441                 xco+= (short)(5.25*XIC);
442                 uiBlockEndAlign(block);
443         }
444         
445         menustr= ANIM_build_keyingsets_menu(&scene->keyingsets, 0);
446         uiDefButI(block, MENU, B_DIFF, 
447                                   menustr, 
448                                   xco, yco, (int)5.5*XIC, YIC, &(scene->active_keyingset), 0, 1, 0, 0, 
449                                   "Active Keying Set (i.e. set of channels to Insert Keyframes for)");
450         MEM_freeN(menustr);
451         xco+= (5.5*XIC);
452         
453         /* NOTE: order of these buttons needs to be kept in sync with other occurances 
454          * (see Outliner header for instance, also +/- stuff for filebrowser) 
455          */
456         uiBlockBeginAlign(block);
457         uiDefIconButO(block, BUT, "ANIM_OT_delete_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_DEHLT, xco,yco,XIC,YIC, "Delete Keyframes for the Active Keying Set (Alt-I)");
458         xco += XIC;
459         uiDefIconButO(block, BUT, "ANIM_OT_insert_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_HLT, xco,yco,XIC,YIC, "Insert Keyframes for the Active Keying Set (I)");
460         xco += XIC;
461         uiBlockEndAlign(block);
462         
463         xco+= XIC;
464         
465         uiDefIconButBitS(block, TOG, AUDIO_SYNC, B_DIFF, ICON_SPEAKER,
466                                          xco, yco, XIC, YIC, &(scene->r.audio.flag), 0, 0, 0, 0, "Play back and sync with audio from Sequence Editor");
467         
468         
469         /* always as last  */
470         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
471         
472         uiEndBlock(C, block);
473         uiDrawBlock(C, block);
474 }
475
476