4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_windowmanager_types.h"
38 #include "MEM_guardedalloc.h"
40 #include "BLI_blenlib.h"
42 #include "BKE_context.h"
43 #include "BKE_global.h"
44 #include "BKE_screen.h"
46 #include "ED_screen.h"
54 #include "BIF_glutil.h"
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
60 #include "ED_markers.h"
62 #include "time_intern.h"
65 /* ************************ header time area region *********************** */
68 static void do_time_redrawmenu(bContext *C, void *arg, int event)
70 SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
74 stime->redraws ^= event;
75 /* update handler when it's running */
76 // if(has_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM))
77 // start_animated_screen(stime);
81 // button(&CTX_data_scene(C)->r.frs_sec,1,120,"FPS:");
87 static uiBlock *time_redrawmenu(bContext *C, ARegion *ar, void *arg_unused)
89 ScrArea *curarea= CTX_wm_area(C);
90 SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
91 Scene *scene= CTX_data_scene(C);
93 short yco= 0, menuwidth=120, icon;
96 block= uiBeginBlock(C, ar, "header time_redrawmenu", UI_EMBOSSP, UI_HELV);
97 uiBlockSetButmFunc(block, do_time_redrawmenu, NULL);
99 if(stime->redraws & TIME_LEFTMOST_3D_WIN) icon= ICON_CHECKBOX_HLT;
100 else icon= ICON_CHECKBOX_DEHLT;
101 uiDefIconTextBut(block, BUTM, 1, icon, "Top-Left 3D Window", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_LEFTMOST_3D_WIN, "");
103 if(stime->redraws & TIME_ALL_3D_WIN) icon= ICON_CHECKBOX_HLT;
104 else icon= ICON_CHECKBOX_DEHLT;
105 uiDefIconTextBut(block, BUTM, 1, icon, "All 3D Windows", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_ALL_3D_WIN, "");
107 if(stime->redraws & TIME_ALL_ANIM_WIN) icon= ICON_CHECKBOX_HLT;
108 else icon= ICON_CHECKBOX_DEHLT;
109 uiDefIconTextBut(block, BUTM, 1, icon, "Animation Windows", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_ALL_ANIM_WIN, "");
111 if(stime->redraws & TIME_ALL_BUTS_WIN) icon= ICON_CHECKBOX_HLT;
112 else icon= ICON_CHECKBOX_DEHLT;
113 uiDefIconTextBut(block, BUTM, 1, icon, "Buttons Windows", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_ALL_BUTS_WIN, "");
115 if(stime->redraws & TIME_ALL_IMAGE_WIN) icon= ICON_CHECKBOX_HLT;
116 else icon= ICON_CHECKBOX_DEHLT;
117 uiDefIconTextBut(block, BUTM, 1, icon, "Image Windows", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_ALL_IMAGE_WIN, "");
119 /* Add sequencer only redraw*/
120 if(stime->redraws & TIME_SEQ) icon= ICON_CHECKBOX_HLT;
121 else icon= ICON_CHECKBOX_DEHLT;
122 uiDefIconTextBut(block, BUTM, 1, icon, "Sequencer Windows", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_SEQ, "");
124 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
126 sprintf(str, "Set Frames/Sec (%d/%f)", scene->r.frs_sec, scene->r.frs_sec_base);
127 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, str, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1001, "");
129 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
131 if(stime->redraws & TIME_CONTINUE_PHYSICS) icon= ICON_CHECKBOX_HLT;
132 else icon= ICON_CHECKBOX_DEHLT;
133 uiDefIconTextBut(block, BUTM, 1, icon, "Continue Physics", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, TIME_CONTINUE_PHYSICS, "During playblack, continue physics simulations regardless of the frame number");
136 if(curarea->headertype==HEADERTOP) {
137 uiBlockSetDirection(block, UI_DOWN);
140 uiBlockSetDirection(block, UI_TOP);
141 uiBlockFlipOrder(block);
144 uiTextBoundsBlock(block, 50);
145 uiEndBlock(C, block);
150 static void do_time_viewmenu(bContext *C, void *arg, int event)
152 ScrArea *curarea= CTX_wm_area(C);
153 SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
154 View2D *v2d= UI_view2d_fromcontext_rwin(C);
155 Scene *scene= CTX_data_scene(C);
159 case 2: /* Play Back Animation */
160 //if(!has_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM))
161 // start_animated_screen(stime);
163 case 3: /* View All */
165 first= scene->r.sfra;
166 if(first >= scene->r.efra) first= scene->r.efra;
167 v2d->cur.xmin=v2d->tot.xmin= (float)first-2;
168 v2d->cur.xmax=v2d->tot.xmax= (float)scene->r.efra+2;
170 ED_area_tag_redraw(curarea);
173 case 4: /* Maximize Window */
174 /* using event B_FULL */
176 case 5: /* show time or frames */
177 stime->flag ^= TIME_DRAWFRAMES;
178 ED_area_tag_redraw(curarea);
181 //nextprev_marker(1);
184 //nextprev_marker(-1);
187 //nextprev_timeline_key(1);
190 //nextprev_timeline_key(-1);
193 //timeline_frame_to_center();
197 v2d->flag ^= V2D_VIEWSYNC_SCREEN_TIME;
198 UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_SET);
201 case 12: /* only show keyframes from selected data */
202 stime->flag ^= TIME_ONLYACTSEL;
203 ED_area_tag_redraw(curarea);
208 static uiBlock *time_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
210 ScrArea *curarea= CTX_wm_area(C);
211 SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
212 View2D *v2d= UI_view2d_fromcontext_rwin(C);
214 short yco= 0, menuwidth=120;
216 block= uiBeginBlock(C, ar, "time_viewmenu", UI_EMBOSSP, UI_HELV);
217 uiBlockSetButmFunc(block, do_time_viewmenu, NULL);
219 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation", 0, yco-=20,
220 menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
222 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
224 if(stime->flag & TIME_DRAWFRAMES)
225 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
227 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Frames|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
229 uiDefIconTextBut(block, BUTM, 1, (stime->flag & TIME_ONLYACTSEL)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
230 "Only Selected Data Keys|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
232 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
234 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Marker|PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, "");
235 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Marker|PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, "");
236 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Next Key|Ctrl PageUp", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, "");
237 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Jump To Prev Key|Ctrl PageDown", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, "");
239 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
241 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
242 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
243 uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
244 "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, "");
246 // if (!curarea->full)
247 // uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
249 // uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
251 if(curarea->headertype==HEADERTOP) {
252 uiBlockSetDirection(block, UI_DOWN);
255 uiBlockSetDirection(block, UI_TOP);
256 uiBlockFlipOrder(block);
259 uiTextBoundsBlock(block, 50);
260 uiEndBlock(C, block);
265 static void do_time_framemenu(bContext *C, void *arg, int event)
267 Scene *scene= CTX_data_scene(C);
270 case 1: /*Set as Start */
271 if (scene->r.psfra) {
272 if (scene->r.pefra < scene->r.cfra)
273 scene->r.pefra= scene->r.cfra;
274 scene->r.psfra= scene->r.cfra;
277 scene->r.sfra = scene->r.cfra;
278 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
280 case 2: /* Set as End */
281 if (scene->r.psfra) {
282 if (scene->r.cfra < scene->r.psfra)
283 scene->r.psfra= scene->r.cfra;
284 scene->r.pefra= scene->r.cfra;
287 scene->r.efra = scene->r.cfra;
288 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
290 case 3: /* Rename Marker */
296 static uiBlock *time_framemenu(bContext *C, ARegion *ar, void *arg_unused)
298 ScrArea *curarea= CTX_wm_area(C);
300 short yco= 0, menuwidth=120;
302 block= uiBeginBlock(C, ar, "time_framemenu", UI_EMBOSSP, UI_HELV);
303 uiBlockSetButmFunc(block, do_time_framemenu, NULL);
305 uiDefIconTextButO(block, BUTM, "MARKER_OT_add", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Add Marker",
306 0, yco-=2, menuwidth, 19, "");
307 uiDefIconTextButO(block, BUTM, "MARKER_OT_duplicate", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Duplicate Marker",
308 0, yco-=20, menuwidth, 19, "");
309 uiDefIconTextButO(block, BUTM, "MARKER_OT_delete", WM_OP_EXEC_REGION_WIN, ICON_BLANK1, "Delete Marker",
310 0, yco-=20, menuwidth, 19, "");
312 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
314 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Name Marker|Ctrl M",
315 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
316 uiDefIconTextButO(block, BUTM, "MARKER_OT_move", WM_OP_INVOKE_REGION_WIN, ICON_BLANK1, "Grab/Move Marker",
317 0, yco-=20, menuwidth, 19, "");
319 uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
321 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set as Start|S",
322 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
323 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set as End|E",
324 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
326 if(curarea->headertype==HEADERTOP) {
327 uiBlockSetDirection(block, UI_DOWN);
330 uiBlockSetDirection(block, UI_TOP);
331 uiBlockFlipOrder(block);
334 uiTextBoundsBlock(block, 50);
335 uiEndBlock(C, block);
341 #define B_REDRAWALL 750
343 #define B_TL_PLAY 752
345 #define B_TL_PREVKEY 754
346 #define B_TL_NEXTKEY 755
347 #define B_TL_STOP 756
348 #define B_TL_PREVIEWON 757
349 #define B_TL_INSERTKEY 758
350 #define B_TL_DELETEKEY 759
352 #define B_FLIPINFOMENU 0
358 void do_time_buttons(bContext *C, void *arg, int event)
360 // SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
361 Scene *scene= CTX_data_scene(C);
365 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
368 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
371 scene->r.cfra= PSFRA;
372 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
373 //update_for_newframe();
376 ED_screen_animation_timer(C, 1);
379 ED_screen_animation_timer(C, 0);
383 scene->r.cfra= PEFRA;
384 WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
385 //update_for_newframe();
388 /* previous keyframe */
389 //nextprev_timeline_key(-1);
393 //nextprev_timeline_key(1);
397 if (scene->r.psfra) {
398 /* turn on preview range */
399 scene->r.psfra= scene->r.sfra;
400 scene->r.pefra= scene->r.efra;
403 /* turn off preview range */
407 //BIF_undo_push("Set anim-preview range");
408 WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene);
412 /* insert keyframe */
413 //common_insertkey();
414 //allqueue(REDRAWTIME, 1);
417 /* delete keyframe */
418 //common_deletekey();
419 //allqueue(REDRAWTIME, 1);
425 void time_header_buttons(const bContext *C, ARegion *ar)
427 ScrArea *sa= CTX_wm_area(C);
428 SpaceTime *stime= (SpaceTime*)CTX_wm_space_data(C);
429 Scene *scene= CTX_data_scene(C);
433 block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
434 uiBlockSetHandleFunc(block, do_time_buttons, NULL);
436 xco= ED_area_header_standardbuttons(C, block, yco);
438 if((sa->flag & HEADER_NO_PULLDOWN)==0) {
441 /* pull down menus */
442 uiBlockSetEmboss(block, UI_EMBOSSP);
444 xmax= GetButStringLength("View");
445 uiDefPulldownBut(block, time_viewmenu, sa,
446 "View", xco, yco-2, xmax-3, 24, "");
448 xmax= GetButStringLength("Frame");
449 uiDefPulldownBut(block, time_framemenu, sa,
450 "Frame", xco, yco-2, xmax-3, 24, "");
453 xmax= GetButStringLength("Playback");
454 uiDefPulldownBut(block, time_redrawmenu, sa,
455 "Playback", xco, yco-2, xmax-3, 24, "");
459 uiBlockSetEmboss(block, UI_EMBOSS);
461 uiBlockBeginAlign(block);
463 uiDefButI(block, TOG, B_TL_PREVIEWON,"PR",
465 &scene->r.psfra,0, 1, 0, 0,
466 "Show settings for frame range of animation preview");
470 if (scene->r.psfra) {
471 uiDefButI(block, NUM, B_REDRAWALL,"Start:",
472 xco,yco, (int)4.5*XIC, YIC,
473 &scene->r.psfra,MINFRAMEF, MAXFRAMEF, 0, 0,
474 "The start frame of the animation preview (inclusive)");
476 xco += (int)(4.5*XIC);
478 uiDefButI(block, NUM, B_REDRAWALL,"End:",
479 xco,yco, (int)4.5*XIC,YIC,
480 &scene->r.pefra,(float)PSFRA, MAXFRAMEF, 0, 0,
481 "The end frame of the animation preview (inclusive)");
484 uiDefButI(block, NUM, B_REDRAWALL,"Start:",
485 xco,yco, (int)4.5*XIC, YIC,
486 &scene->r.sfra,MINFRAMEF, MAXFRAMEF, 0, 0,
487 "The start frame of the animation (inclusive)");
489 xco += (short)(4.5*XIC);
491 uiDefButI(block, NUM, B_REDRAWALL,"End:",
492 xco,yco, (int)4.5*XIC,YIC,
493 &scene->r.efra,(float)SFRA, MAXFRAMEF, 0, 0,
494 "The end frame of the animation (inclusive)");
496 uiBlockEndAlign(block);
498 xco += (short)(4.5 * XIC + 16);
500 uiDefButI(block, NUM, B_NEWFRAME, "",
501 xco,yco, (int)3.5*XIC,YIC,
502 &(scene->r.cfra), MINFRAMEF, MAXFRAMEF, 0, 0,
503 "Displays Current Frame of animation");
505 xco += (short)(3.5 * XIC + 16);
507 uiDefIconBut(block, BUT, B_TL_REW, ICON_REW,
508 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Skip to Start frame (Shift DownArrow)");
510 uiDefIconBut(block, BUT, B_TL_PREVKEY, ICON_PREV_KEYFRAME,
511 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Skip to previous keyframe (Ctrl PageDown)");
514 if(CTX_wm_screen(C)->animtimer)
515 uiDefIconBut(block, BUT, B_TL_STOP, ICON_PAUSE,
516 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Stop Playing Timeline");
518 uiDefIconBut(block, BUT, B_TL_PLAY, ICON_PLAY,
519 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Play Timeline ");
522 uiDefIconBut(block, BUT, B_TL_NEXTKEY, ICON_NEXT_KEYFRAME,
523 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Skip to next keyframe (Ctrl PageUp)");
525 uiDefIconBut(block, BUT, B_TL_FF, ICON_FF,
526 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Skip to End frame (Shift UpArrow)");
529 uiDefIconButBitS(block, TOG, AUTOKEY_ON, REDRAWINFO, ICON_REC,
530 xco, yco, XIC, YIC, &(scene->autokey_mode), 0, 0, 0, 0, "Automatic keyframe insertion for Objects and Bones");
532 if (scene->autokey_mode & AUTOKEY_ON) {
533 uiDefButS(block, MENU, REDRAWINFO,
534 "Auto-Keying Mode %t|Add/Replace Keys%x3|Replace Keys %x5",
535 xco, yco, (int)3.5*XIC, YIC, &(scene->autokey_mode), 0, 1, 0, 0,
536 "Mode of automatic keyframe insertion for Objects and Bones");
542 uiDefIconBut(block, BUT, B_TL_INSERTKEY, ICON_KEY_HLT,
543 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Insert Keyframe for the context of the largest area (IKEY)");
545 uiDefIconBut(block, BUT, B_TL_DELETEKEY, ICON_KEY_DEHLT,
546 xco, yco, XIC, YIC, 0, 0, 0, 0, 0, "Delete Keyframe for the context of the largest area (ALTKEY-IKEY)");
551 uiDefIconButBitI(block, TOG, TIME_WITH_SEQ_AUDIO, B_DIFF, ICON_SPEAKER,
552 xco, yco, XIC, YIC, &(stime->redraws), 0, 0, 0, 0, "Play back and sync with audio from Sequence Editor");
556 UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
558 uiEndBlock(C, block);
559 uiDrawBlock(C, block);