New option; "Lock Time to Other Windows" for Ipo, Action, NLA and Time
[blender.git] / source / blender / src / header_time.c
1 /**
2  *
3  * $Id:
4  *
5  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version. The Blender
11  * Foundation also sells licenses for use in proprietary software under
12  * the Blender License.  See http://www.blender.org/BL/ for information
13  * about this.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
23  *
24  * The Original Code is Copyright (C) 2005 Blender Foundation.
25  * All rights reserved.
26  *
27  * The Original Code is: all of this file.
28  *
29  * Contributor(s): none yet.
30  *
31  * ***** END GPL/BL DUAL LICENSE BLOCK *****
32  */
33
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdio.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "DNA_ID.h"
43 #include "DNA_screen_types.h"
44 #include "DNA_scene_types.h"
45 #include "DNA_space_types.h"
46 #include "DNA_view2d_types.h"
47 #include "DNA_userdef_types.h"
48
49 #include "BIF_gl.h"
50 #include "BIF_interface.h"
51 #include "BIF_resources.h"
52 #include "BIF_screen.h"
53 #include "BIF_space.h"
54 #include "BIF_toolbox.h"
55 #include "BIF_butspace.h"
56
57 #include "BKE_global.h"
58 #include "BKE_main.h"
59
60 #include "BSE_drawipo.h"
61 #include "BSE_drawview.h"
62 #include "BSE_editipo.h"
63 #include "BSE_filesel.h"
64 #include "BSE_headerbuttons.h"
65 #include "BSE_seqaudio.h"
66 #include "BSE_time.h"
67
68 #include "blendef.h"
69 #include "butspace.h"
70 #include "mydevice.h"
71
72 void do_time_buttons(ScrArea *sa, unsigned short event)
73 {
74         SpaceTime *stime= sa->spacedata.first;
75         
76         switch(event) {
77
78         case B_TL_REW:
79                 CFRA= SFRA;
80                 update_for_newframe();
81                 break;
82         case B_TL_PLAY:
83                 add_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM, stime->redraws);
84                 if(stime->redraws & TIME_WITH_SEQ_AUDIO)
85                         audiostream_start( CFRA );
86
87                 break;
88         case B_TL_STOP:
89                 rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
90                 if(stime->redraws & TIME_WITH_SEQ_AUDIO)
91                         audiostream_stop();
92                 allqueue(REDRAWALL, 0);
93                 
94                 break;
95         case B_TL_FF:
96                 /* end frame */
97                 CFRA= EFRA;
98                 update_for_newframe();
99                 break;
100         case B_TL_PREVKEY:
101                 /* previous keyframe */
102                 nextprev_timeline_key(-1);
103                 break;
104         case B_TL_NEXTKEY:
105                 /* next keyframe */
106                 nextprev_timeline_key(1);
107                 break;
108         }
109 }
110
111 static void do_time_redrawmenu(void *arg, int event)
112 {
113         SpaceTime *stime= curarea->spacedata.first;
114         
115         if(event < 1001) {
116                 
117                 stime->redraws ^= event;
118                 /* update handler when it's running */
119                 if(has_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM))
120                         add_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM, stime->redraws);
121         }
122         else {
123                 if(event==1001) {
124                         button(&G.scene->r.frs_sec,1,120,"Frames/Second:");
125                 }
126         }
127 }
128                         
129
130 static uiBlock *time_redrawmenu(void *arg_unused)
131 {
132         SpaceTime *stime= curarea->spacedata.first;
133         uiBlock *block;
134         short yco= 0, menuwidth=120, icon;
135         char str[32];
136         
137         block= uiNewBlock(&curarea->uiblocks, "time_redrawmenu", 
138                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
139         uiBlockSetButmFunc(block, do_time_redrawmenu, NULL);
140         
141         if(stime->redraws & TIME_LEFTMOST_3D_WIN) icon= ICON_CHECKBOX_HLT;
142         else icon= ICON_CHECKBOX_DEHLT;
143         uiDefIconTextBut(block, BUTM, 1, icon, "Top-Left 3D Window",     0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_LEFTMOST_3D_WIN, "");
144
145         if(stime->redraws & TIME_ALL_3D_WIN) icon= ICON_CHECKBOX_HLT;
146         else icon= ICON_CHECKBOX_DEHLT;
147         uiDefIconTextBut(block, BUTM, 1, icon, "All 3D Windows",         0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_ALL_3D_WIN, "");
148         
149         if(stime->redraws & TIME_ALL_ANIM_WIN) icon= ICON_CHECKBOX_HLT;
150         else icon= ICON_CHECKBOX_DEHLT;
151         uiDefIconTextBut(block, BUTM, 1, icon, "Animation Windows",      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_ALL_ANIM_WIN, "");
152         
153         if(stime->redraws & TIME_ALL_BUTS_WIN) icon= ICON_CHECKBOX_HLT;
154         else icon= ICON_CHECKBOX_DEHLT;
155         uiDefIconTextBut(block, BUTM, 1, icon, "Buttons Windows",        0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_ALL_BUTS_WIN, "");
156         
157         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
158         
159         sprintf(str, "Set Frames/Sec (%d)", G.scene->r.frs_sec);
160         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, str,       0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1001, "");
161         
162         
163         if(curarea->headertype==HEADERTOP) {
164                 uiBlockSetDirection(block, UI_DOWN);
165         }
166         else {
167                 uiBlockSetDirection(block, UI_TOP);
168                 uiBlockFlipOrder(block);
169         }
170         
171         uiTextBoundsBlock(block, 50);
172         
173         return block;
174 }
175
176 static void do_time_viewmenu(void *arg, int event)
177 {
178         SpaceTime *stime= curarea->spacedata.first;
179         int first;
180         
181         switch(event) {
182                 case 2: /* Play Back Animation */
183                         add_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM, stime->redraws);
184                         break;
185                 case 3: /* View All */
186                         first= G.scene->r.sfra;
187                         if(first >= G.scene->r.efra) first= G.scene->r.efra;
188                         G.v2d->cur.xmin=G.v2d->tot.xmin= (float)first-2;
189                         G.v2d->cur.xmax=G.v2d->tot.xmax= (float)G.scene->r.efra+2;
190                         
191                         test_view2d(G.v2d, curarea->winx, curarea->winy);
192                         scrarea_queue_winredraw(curarea);
193                         break;
194                 case 4: /* Maximize Window */
195                                 /* using event B_FULL */
196                         break;
197                 case 5: /* show time or frames */
198                         stime->flag ^= TIME_DRAWFRAMES;
199                         break;
200                 case 6:
201                         nextprev_timeline_marker(1);
202                         break;
203                 case 7:
204                         nextprev_timeline_marker(-1);
205                         break;
206                 case 8:
207                         nextprev_timeline_key(1);
208                         break;
209                 case 9:
210                         nextprev_timeline_key(-1);
211                         break;
212                 case 10:
213                         timeline_frame_to_center();
214                         break;
215                 case 11:
216                         G.v2d->flag ^= V2D_VIEWLOCK;
217                         if(G.v2d->flag & V2D_VIEWLOCK)
218                                 view2d_do_locks(curarea, 0);
219                         break;
220         }
221         allqueue(REDRAWVIEW3D, 0);
222 }
223
224 static uiBlock *time_viewmenu(void *arg_unused)
225 {
226         SpaceTime *stime= curarea->spacedata.first;
227         uiBlock *block;
228         short yco= 0, menuwidth=120;
229         
230         block= uiNewBlock(&curarea->uiblocks, "time_viewmenu", 
231                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
232         uiBlockSetButmFunc(block, do_time_viewmenu, NULL);
233         
234         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
235                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
236
237         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
238         
239         if(stime->flag & TIME_DRAWFRAMES)
240                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
241         else 
242                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Frames|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
243         
244         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
245         
246         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
247         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
248         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
249         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
250         
251         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
252         
253         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
254         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
255         uiDefIconTextBut(block, BUTM, 1, (G.v2d->flag & V2D_VIEWLOCK)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
256                                          "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
257         
258         if (!curarea->full) 
259                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
260         else 
261                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
262         
263         if(curarea->headertype==HEADERTOP) {
264                 uiBlockSetDirection(block, UI_DOWN);
265         }
266         else {
267                 uiBlockSetDirection(block, UI_TOP);
268                 uiBlockFlipOrder(block);
269         }
270
271         uiTextBoundsBlock(block, 50);
272         
273         return block;
274 }
275
276 static void do_time_framemenu(void *arg, int event)
277 {
278         switch(event) {
279                 case 1: /*Set as Start */
280                         G.scene->r.sfra = CFRA;
281                         allqueue(REDRAWALL, 1);
282                         break;
283                 case 2: /* Set as End */
284                         G.scene->r.efra = CFRA;
285                         allqueue(REDRAWALL, 1);
286                         break;
287                 case 3: /* Add Marker */
288                         add_timeline_marker(CFRA);
289                         break;
290                 case 4: /* Remove Marker */
291                         remove_timeline_marker();
292                         break;
293                 case 5: /* Rename Marker */
294                         rename_timeline_marker();
295                         break;
296                 case 6: /* Grab Marker */
297                         timeline_grab('g', 0);
298                         break;
299         }
300         allqueue(REDRAWTIME, 0);
301 }
302
303 static uiBlock *time_framemenu(void *arg_unused)
304 {
305         uiBlock *block;
306         short yco= 0, menuwidth=120;
307         
308         block= uiNewBlock(&curarea->uiblocks, "time_framemenu", 
309                                           UI_EMBOSSP, UI_HELV, curarea->headwin);
310         uiBlockSetButmFunc(block, do_time_framemenu, NULL);
311         
312         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Marker|M", 0, yco-=20, 
313                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
314         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Remove Marker|X", 0, yco-=20,
315                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
316         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Name Marker|Ctrl M", 0, yco-=20,
317                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
318         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/move Marker|G", 0, yco-=20,
319                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
320                                          
321         uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
322         
323         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set as Start|S", 0, yco-=20, 
324                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
325         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set as End|E", 0, yco-=20,
326                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
327
328         if(curarea->headertype==HEADERTOP) {
329                 uiBlockSetDirection(block, UI_DOWN);
330         }
331         else {
332                 uiBlockSetDirection(block, UI_TOP);
333                 uiBlockFlipOrder(block);
334         }
335
336         uiTextBoundsBlock(block, 50);
337         
338         return block;
339 }
340
341 void time_buttons(ScrArea *sa)
342 {
343         SpaceTime *stime= sa->spacedata.first;
344         uiBlock *block;
345         short xco, xmax;
346         char name[256];
347         
348         sprintf(name, "header %d", sa->headwin);
349         block= uiNewBlock(&sa->uiblocks, name, UI_EMBOSS, UI_HELV, sa->headwin);
350
351         if(area_is_active_area(sa)) uiBlockSetCol(block, TH_HEADER);
352         else uiBlockSetCol(block, TH_HEADERDESEL);
353         
354         sa->butspacetype= SPACE_TIME;
355
356         xco = 8;
357         
358         uiDefIconTextButC(block, ICONTEXTROW,B_NEWSPACE, ICON_VIEW3D, 
359                                           windowtype_pup(), xco, 0, XIC+10, YIC, 
360                                           &(sa->butspacetype), 1.0, SPACEICONMAX, 0, 0, 
361                                           "Displays Current Window Type. "
362                                           "Click for menu of available types.");
363
364         xco += XIC + 14;
365
366         uiBlockSetEmboss(block, UI_EMBOSSN);
367         if (sa->flag & HEADER_NO_PULLDOWN) {
368                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, 
369                                           ICON_DISCLOSURE_TRI_RIGHT,
370                                           xco,2,XIC,YIC-2,
371                                           &(sa->flag), 0, 0, 0, 0, 
372                                           "Show pulldown menus");
373         }
374         else {
375                 uiDefIconButBitS(block, TOG, HEADER_NO_PULLDOWN, B_FLIPINFOMENU, 
376                                           ICON_DISCLOSURE_TRI_DOWN,
377                                           xco,2,XIC,YIC-2,
378                                           &(sa->flag), 0, 0, 0, 0, 
379                                           "Hide pulldown menus");
380         }
381         uiBlockSetEmboss(block, UI_EMBOSS);
382         xco+=XIC;
383
384         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
385                 /* pull down menus */
386                 uiBlockSetEmboss(block, UI_EMBOSSP);
387         
388                 xmax= GetButStringLength("View");
389                 uiDefPulldownBut(block, time_viewmenu, NULL, 
390                                           "View", xco, -2, xmax-3, 24, "");
391                 xco+= xmax;
392                 xmax= GetButStringLength("Frame");
393                 uiDefPulldownBut(block, time_framemenu, NULL, 
394                                           "Frame", xco, -2, xmax-3, 24, "");
395                 xco+= xmax;
396
397                 xmax= GetButStringLength("Playback");
398                 uiDefPulldownBut(block, time_redrawmenu, NULL, 
399                                                  "Playback", xco, -2, xmax-3, 24, "");
400                 xco+= xmax;
401         }
402
403         uiBlockSetEmboss(block, UI_EMBOSS);
404         
405         uiBlockBeginAlign(block);
406         uiDefButS(block, NUM, REDRAWALL,"Start:",       
407                 xco,0, 4.5*XIC, YIC,
408                 &G.scene->r.sfra,MINFRAMEF, MAXFRAMEF, 0, 0,
409                 "The start frame of the animation");
410
411         xco += 4.5*XIC;
412
413         uiDefButS(block, NUM, REDRAWALL,"End:", 
414                 xco,0,4.5*XIC,YIC,
415                 &G.scene->r.efra,MINFRAMEF,MAXFRAMEF, 0, 0,
416                 "The end  frame of the animation");
417         uiBlockEndAlign(block);
418
419         xco += 4.5*XIC+16;
420         
421         uiDefButS(block, NUM, B_NEWFRAME, "",
422                 xco,0,3.5*XIC,YIC,
423                 &(G.scene->r.cfra), MINFRAMEF, MAXFRAMEF, 0, 0,
424                 "Displays Current Frame of animation. Click to change.");
425         
426         xco += 3.5*XIC+16;
427         
428         uiDefIconBut(block, BUT, B_TL_REW, ICON_REW,
429                         xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Skip to Start frame (Shift DownArrow)");
430         xco+= XIC+4;
431         uiDefIconBut(block, BUT, B_TL_PREVKEY, ICON_PREV_KEYFRAME,
432                         xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Skip to previous keyframe (Ctrl PageDown)");
433         xco+= XIC+4;
434         
435         if(has_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM))
436            uiDefIconBut(block, BUT, B_TL_STOP, ICON_PAUSE,
437                         xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Stop Playing Timeline");
438         else       
439                 uiDefIconBut(block, BUT, B_TL_PLAY, ICON_PLAY,
440                         xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Play Timeline ");
441         
442         xco+= XIC+4;
443         uiDefIconBut(block, BUT, B_TL_NEXTKEY, ICON_NEXT_KEYFRAME,
444                         xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Skip to next keyframe (Ctrl PageUp)");
445         xco+= XIC+4;
446         uiDefIconBut(block, BUT, B_TL_FF, ICON_FF,
447                         xco, 0, XIC, YIC, 0, 0, 0, 0, 0, "Skip to End frame (Shift UpArrow)");
448         xco+= XIC+8;
449         
450         uiDefIconButBitI(block, TOG, G_RECORDKEYS, REDRAWINFO, ICON_REC,
451                         xco, 0, XIC, YIC, &(G.flags), 0, 0, 0, 0, "Automatically insert keyframes in Object and Action Ipo curves");
452         
453         xco+= XIC+16;
454
455         uiDefIconButBitI(block, TOG, TIME_WITH_SEQ_AUDIO, B_DIFF, ICON_SPEAKER,
456                                          xco, 0, XIC, YIC, &(stime->redraws), 0, 0, 0, 0, "Play back and sync with audio from Sequence Editor");
457         
458         /* always as last  */
459         sa->headbutlen= xco+2*XIC;
460
461         uiDrawBlock(block);
462 }