2.5
[blender.git] / source / blender / editors / space_sequencer / sequencer_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_space_types.h"
33 #include "DNA_sequence_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_utildefines.h"
43 #include "BKE_context.h"
44 #include "BKE_screen.h"
45 #include "BKE_sequence.h"
46
47 #include "ED_screen.h"
48 #include "ED_types.h"
49 #include "ED_util.h"
50
51 #include "WM_api.h"
52 #include "WM_types.h"
53
54 #include "RNA_access.h"
55
56 #include "BIF_gl.h"
57 #include "BIF_glutil.h"
58 #include "BIF_transform.h"
59
60 #include "UI_interface.h"
61 #include "UI_resources.h"
62 #include "UI_view2d.h"
63
64 #include "sequencer_intern.h"
65
66
67 /* ************************ header area region *********************** */
68
69 #define B_FULL                  1
70 #define B_VIEW2DZOOM    2
71 #define B_REDR                  3
72 #define B_IPOBORDER             4
73 #define B_SEQCLEAR              5
74
75 static uiBlock *seq_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
76 {
77         ScrArea *sa= CTX_wm_area(C);
78         SpaceSeq *sseq= sa->spacedata.first;
79         View2D *v2d= UI_view2d_fromcontext(C);
80
81         uiBlock *block= uiBeginBlock(C, ar, "seq_viewmenu", UI_EMBOSSP);
82         short yco= 0, menuwidth=120;
83
84         if (sseq->mainb == SEQ_DRAW_SEQUENCE) {
85                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
86                                  "Play Back Animation "
87                                  "in all Sequence Areas|Alt A", 0, yco-=20,
88                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
89         }
90         else {
91                 uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL,
92                                  "Grease Pencil...", 0, yco-=20,
93                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
94                 uiDefMenuSep(block);
95
96                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
97                                  "Play Back Animation "
98                                  "in this window|Alt A", 0, yco-=20,
99                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
100         }
101         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1,
102                          "Play Back Animation in all "
103                          "3D Views and Sequence Areas|Alt Shift A",
104                          0, yco-=20,
105                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
106
107         uiDefMenuSep(block);
108
109         uiDefMenuButO(block, "SEQUENCER_OT_view_all", NULL);
110         uiDefMenuButO(block, "SEQUENCER_OT_view_selected", NULL);
111         
112         uiDefMenuSep(block);
113
114         /* Lock Time */
115         uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
116                         "Lock Time to Other Windows|", 0, yco-=20,
117                         menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
118
119         /* Draw time or frames.*/
120         uiDefMenuSep(block);
121
122         if(sseq->flag & SEQ_DRAWFRAMES)
123                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Seconds|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
124         else
125                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Frames|Ctrl T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
126
127         
128         if(!sa->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,0, "");
129         else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 0, "");
130
131
132         if(sa->headertype==HEADERTOP) {
133                 uiBlockSetDirection(block, UI_DOWN);
134         }
135         else {
136                 uiBlockSetDirection(block, UI_TOP);
137                 uiBlockFlipOrder(block);
138         }
139         
140         uiTextBoundsBlock(block, 50);
141         uiEndBlock(C, block);
142         
143         return block;
144 }
145
146 //static uiBlock *seq_selectmenu(bContext *C, ARegion *ar, void *arg_unused)
147 static void seq_selectmenu(bContext *C, uiLayout *layout, void *arg_unused)
148 {
149         uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_REGION_WIN);
150
151         uiItemEnumO(layout, "Strips to the Left", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_LEFT);
152         uiItemEnumO(layout, "Strips to the Right", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_RIGHT);
153         uiItemS(layout);
154         uiItemEnumO(layout, "Surrounding Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_BOTH);
155         uiItemEnumO(layout, "Left Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_LEFT);
156         uiItemEnumO(layout, "Right Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_RIGHT);
157         uiItemS(layout);
158         uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_linked");
159         uiItemS(layout);
160         uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_linked");
161         uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_all_toggle");
162         uiItemO(layout, NULL, 0, "SEQUENCER_OT_select_invert");
163 }
164
165 static uiBlock *seq_markermenu(bContext *C, ARegion *ar, void *arg_unused)
166 {
167         ScrArea *sa= CTX_wm_area(C);
168         SpaceSeq *sseq= sa->spacedata.first;
169
170
171         uiBlock *block= uiBeginBlock(C, ar, "seq_markermenu", UI_EMBOSSP);
172         short yco= 0, menuwidth=120;
173
174
175
176
177         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Marker|Ctrl Alt M", 0, yco-=20,
178                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");
179         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate Marker|Ctrl Shift D", 0, yco-=20,
180                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
181         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Marker|Shift X", 0, yco-=20,
182                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
183
184         uiDefMenuSep(block);
185
186         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "(Re)Name Marker|Ctrl M", 0, yco-=20,
187                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
188         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Marker|Ctrl G", 0, yco-=20,
189                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
190
191         uiDefMenuSep(block);
192
193         uiDefIconTextBut(block, BUTM, 1, (sseq->flag & SEQ_MARKER_TRANS)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT,
194                                          "Transform Markers", 0, yco-=20,
195                                         menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
196
197
198         if(sa->headertype==HEADERTOP) {
199                 uiBlockSetDirection(block, UI_DOWN);
200         }
201         else {
202                 uiBlockSetDirection(block, UI_TOP);
203                 uiBlockFlipOrder(block);
204         }
205
206         uiTextBoundsBlock(block, 50);
207         uiEndBlock(C, block);
208
209         return block;
210 }
211
212 //static uiBlock *seq_addmenu_effectmenu(bContext *C, ARegion *ar, void *arg_unused)
213 static void seq_addmenu_effectmenu(bContext *C, uiLayout *layout, void *arg_unused)
214 {
215         uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_REGION_WIN);
216         
217         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ADD);
218         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SUB);
219         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_MUL);
220         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_CROSS);
221         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GAMCROSS);
222         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAOVER);
223         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAUNDER);
224         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_OVERDROP);
225         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_WIPE);
226         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GLOW);
227         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_TRANSFORM);
228         /* Color is an effect but moved to the other menu since its not that exciting */
229         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SPEED);
230         uiItemS(layout);
231         uiItemEnumO(layout, NULL, 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_PLUGIN);
232 }
233
234
235 //static uiBlock *seq_addmenu(bContext *C, ARegion *ar, void *arg_unused)
236 static void seq_addmenu(bContext *C, uiLayout *layout, void *arg_unused)
237 {
238         uiItemMenuF(layout, "Effects...", 0, seq_addmenu_effectmenu);
239         uiItemS(layout);
240
241         uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_REGION_WIN);
242
243 #ifdef WITH_FFMPEG
244         uiItemBooleanO(layout, "Audio (RAM)", 0, "SEQUENCER_OT_sound_strip_add", "hd", FALSE);
245         uiItemBooleanO(layout, "Audio (HD)", 0, "SEQUENCER_OT_sound_strip_add", "hd", TRUE);
246 #else
247         uiItemO(layout, NULL, 0, "SEQUENCER_OT_sound_strip_add");
248 #endif
249         uiItemEnumO(layout, "Add Color Strip", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_COLOR);
250
251         uiItemO(layout, NULL, 0, "SEQUENCER_OT_image_strip_add");
252         uiItemO(layout, NULL, 0, "SEQUENCER_OT_movie_strip_add");
253         uiItemO(layout, NULL, 0, "SEQUENCER_OT_scene_strip_add");
254 #ifdef WITH_FFMPEG
255         uiItemBooleanO(layout, "Movie and Sound", 0, "SEQUENCER_OT_movie_strip_add", "sound", TRUE);
256 #endif
257 }
258
259 //static uiBlock *seq_editmenu(bContext *C, ARegion *ar, void *arg_unused)
260 static void seq_editmenu(bContext *C, uiLayout *layout, void *arg_unused)
261 {
262         Scene *scene= CTX_data_scene(C);
263         Editing *ed= seq_give_editing(scene, FALSE);
264         
265         uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_REGION_WIN);
266
267         uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_TRANSLATION);
268         uiItemEnumO(layout, NULL, 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND);
269
270         // uiItemO(layout, NULL, 0, "SEQUENCER_OT_strip_snap"); // TODO - add this operator
271
272         uiItemEnumO(layout, "Cut Hard", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_HARD);
273         uiItemEnumO(layout, "Cut Soft", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_SOFT);
274
275         uiItemO(layout, NULL, 0, "SEQUENCER_OT_images_separate");
276         uiItemS(layout);
277         uiItemO(layout, NULL, 0, "SEQUENCER_OT_duplicate_add");
278         uiItemO(layout, NULL, 0, "SEQUENCER_OT_delete");
279
280         if (ed && ed->act_seq) {
281                 switch(ed->act_seq->type) {
282                 case SEQ_EFFECT:
283                         uiItemS(layout);
284                         uiItemO(layout, NULL, 0, "SEQUENCER_OT_effect_change");
285                         uiItemO(layout, NULL, 0, "SEQUENCER_OT_effect_reassign_inputs");
286                         break;
287                 case SEQ_IMAGE:
288                         uiItemS(layout);
289                         uiItemO(layout, NULL, 0, "SEQUENCER_OT_image_change"); // Change Scene...
290                         break;
291                 case SEQ_SCENE:
292                         uiItemS(layout);
293                         uiItemO(layout, NULL, 0, "SEQUENCER_OT_scene_change"); // Remap Paths...
294                         break;
295                 case SEQ_MOVIE:
296                         uiItemS(layout);
297                         uiItemO(layout, NULL, 0, "SEQUENCER_OT_movie_change"); // Remap Paths...
298                         break;
299                 }
300         }
301
302         uiItemS(layout);
303
304         uiItemO(layout, NULL, 0, "SEQUENCER_OT_meta_make");
305         uiItemO(layout, NULL, 0, "SEQUENCER_OT_meta_separate");
306
307         if (ed && (ed->metastack.first || (ed->act_seq && ed->act_seq->type == SEQ_META))) {
308                 uiItemS(layout);
309                 uiItemO(layout, NULL, 0, "SEQUENCER_OT_meta_toggle");
310         }
311         uiItemS(layout);
312         uiItemO(layout, NULL, 0, "SEQUENCER_OT_reload");
313         uiItemS(layout);
314         uiItemO(layout, NULL, 0, "SEQUENCER_OT_lock");
315         uiItemO(layout, NULL, 0, "SEQUENCER_OT_unlock");
316         uiItemO(layout, NULL, 0, "SEQUENCER_OT_mute");
317         uiItemO(layout, NULL, 0, "SEQUENCER_OT_unmute");
318
319         uiItemEnumO(layout, "Mute Deselected Strips", 0, "SEQUENCER_OT_mute", "type", SEQ_UNSELECTED);
320 }
321
322 void sequencer_header_buttons(const bContext *C, ARegion *ar)
323 {
324         ScrArea *sa= CTX_wm_area(C);
325         SpaceSeq *sseq= sa->spacedata.first;
326         Scene *scene= CTX_data_scene(C);
327         Editing *ed= seq_give_editing(scene, FALSE);
328         
329         uiBlock *block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
330         int xco=3, yco= 3;
331         
332         xco= ED_area_header_standardbuttons(C, block, yco);
333         
334         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
335                 int xmax;
336                 
337                 xmax= GetButStringLength("View");
338
339                 //uiDefMenuBut(block, seq_viewmenu, NULL, "View", xco, 0, xmax-3, 24, ""); // TODO
340                 uiDefPulldownBut(block, seq_viewmenu, sa, "View", xco, 0, xmax-3, 24, ""); 
341                 xco+=xmax;
342
343                 xmax= GetButStringLength("Select");
344                 uiDefMenuBut(block, seq_selectmenu, NULL, "Select", xco, 0, xmax-3, 24, "");
345                 //uiDefPulldownBut(block, seq_selectmenu, sa, "Select", xco, 0, xmax-3, 24, "");
346                 xco+=xmax;
347
348                 xmax= GetButStringLength("Marker");
349                 //uiDefMenuBut(block, seq_markermenu, NULL, "Marker", xco, 0, xmax-3, 24, "");
350                 uiDefPulldownBut(block, seq_markermenu, sa, "Marker", xco, 0, xmax-3, 24, ""); // TODO
351                 xco+=xmax;
352
353                 xmax= GetButStringLength("Add");
354                 uiDefMenuBut(block, seq_addmenu, NULL, "Add", xco, 0, xmax-3, 24, "");
355                 //uiDefPulldownBut(block, seq_addmenu, sa, "Add", xco, 0, xmax-3, 24, "");
356                 xco+=xmax;
357
358                 xmax= GetButStringLength("Strip");
359                 uiDefMenuBut(block, seq_editmenu, NULL, "Strip", xco, 0, xmax-3, 24, "");
360                 //uiDefPulldownBut(block, seq_editmenu, sa, "Strip", xco, 0, xmax-3, 24, "");
361                 xco+=xmax;
362         }
363
364         uiBlockSetEmboss(block, UI_EMBOSS);
365
366         /* IMAGE */
367         uiDefIconTextButS(block, ICONTEXTROW,B_REDR, ICON_SEQ_SEQUENCER,
368                           "Image Preview: %t"
369                           "|Sequence %x0"
370                           "|Image Preview %x1"
371                           "|Luma Waveform %x2"
372                           "|Chroma Vectorscope %x3"
373                           "|Histogram %x4",
374                           xco,yco,XIC+10,YIC, &sseq->mainb, 0.0, 3.0,
375                           0, 0,
376                           "Shows the sequence output image preview");
377
378         xco+= 8 + XIC+10;
379
380         if(sseq->mainb != SEQ_DRAW_SEQUENCE) {
381                 int minchan = 0;
382
383                 /* CHANNEL shown in image preview */
384
385                 if (ed && ed->metastack.first)
386                         minchan = -BLI_countlist(&ed->metastack);
387
388                 uiDefButS(block, NUM, B_REDR, "Chan:",
389                           xco, yco, 3.5 * XIC,YIC,
390                           &sseq->chanshown, minchan, MAXSEQ, 0, 0,
391                           "The channel number shown in the image preview. 0 is the result of all strips combined.");
392
393                 xco+= 8 + XIC*3.5;
394
395                 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
396                         uiDefButS(block, MENU, B_REDR,
397                                   "Show zebra: %t"
398                                   "|Z 110 %x110"
399                                   "|Z 100 %x100"
400                                   "|Z 95  %x95"
401                                   "|Z 90  %x90"
402                                   "|Z 70  %x70"
403                                   "|Z Off %x0",
404                                   xco,yco,3.0 * XIC, YIC, &sseq->zebra,
405                                   0,0,0,0,
406                                   "Show overexposed "
407                                   "areas with zebra stripes");
408
409                         xco+= 8 + XIC*3.0;
410
411                         uiDefButBitI(block, TOG, SEQ_DRAW_SAFE_MARGINS,
412                                      B_REDR, "T",
413                                      xco,yco,XIC,YIC, &sseq->flag,
414                                      0, 0, 0, 0,
415                                      "Draw title safe margins in preview");
416                         xco+= 8 + XIC;
417                 }
418
419                 if (sseq->mainb == SEQ_DRAW_IMG_WAVEFORM) {
420                         uiDefButBitI(block, TOG, SEQ_DRAW_COLOR_SEPERATED,
421                                      B_REDR, "CS",
422                                      xco,yco,XIC,YIC, &sseq->flag,
423                                      0, 0, 0, 0,
424                                      "Seperate color channels in preview");
425                         xco+= 8 + XIC;
426                 }
427         } else {
428                 /* ZOOM and BORDER */
429                 static int viewmovetemp; // XXX dummy var
430                 
431                 uiBlockBeginAlign(block);
432                 uiDefIconButI(block, TOG, B_VIEW2DZOOM,
433                               ICON_VIEWZOOM,
434                               xco,yco,XIC,YIC, &viewmovetemp,
435                               0, 0, 0, 0,
436                               "Zooms view in and out (Ctrl MiddleMouse)");
437                 xco += XIC;
438                 uiDefIconButO(block, BUT, "VIEW2D_OT_zoom_border", WM_OP_INVOKE_REGION_WIN, ICON_BORDERMOVE, xco,yco,XIC,YIC, "Zooms view to fit area");
439                 
440                 uiBlockEndAlign(block);
441                 xco += 8 + XIC;
442         }
443
444         uiDefButO(block, BUT, "SEQUENCER_OT_refresh_all", WM_OP_EXEC_DEFAULT, "Refresh", xco, yco, 3*XIC, YIC, "Clears all buffered images in memory");
445
446         uiBlockSetEmboss(block, UI_EMBOSS);
447
448         /* always as last  */
449         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
450         
451         uiEndBlock(C, block);
452         uiDrawBlock(C, block);
453 }
454