aa633536c3083ef9b578641b85382b3a010180ff
[blender-staging.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, uiMenuItem *head, void *arg_unused)
148 {
149         uiMenuContext(head, WM_OP_INVOKE_REGION_WIN);
150
151         uiMenuItemEnumO(head, "Strips to the Left", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_LEFT);
152         uiMenuItemEnumO(head, "Strips to the Right", 0, "SEQUENCER_OT_select_active_side", "side", SEQ_SIDE_RIGHT);
153         uiMenuSeparator(head);
154         uiMenuItemEnumO(head, "Surrounding Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_BOTH);
155         uiMenuItemEnumO(head, "Left Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_LEFT);
156         uiMenuItemEnumO(head, "Right Handles", 0, "SEQUENCER_OT_select_handles", "side", SEQ_SIDE_RIGHT);
157         uiMenuSeparator(head);
158         uiMenuItemO(head, 0, "SEQUENCER_OT_select_linked");
159         uiMenuSeparator(head);
160         uiMenuItemO(head, 0, "SEQUENCER_OT_select_linked");
161         uiMenuItemO(head, 0, "SEQUENCER_OT_select_all_toggle");
162         uiMenuItemO(head, 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, uiMenuItem *head, void *arg_unused)
214 {
215         uiMenuContext(head, WM_OP_INVOKE_REGION_WIN);
216         
217         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ADD);
218         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SUB);
219         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_MUL);
220         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_CROSS);
221         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GAMCROSS);
222         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAOVER);
223         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_ALPHAUNDER);
224         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_OVERDROP);
225         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_WIPE);
226         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_GLOW);
227         uiMenuItemEnumO(head, "", 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         uiMenuItemEnumO(head, "", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_SPEED);
230         uiMenuSeparator(head);
231         uiMenuItemEnumO(head, "", 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, uiMenuItem *head, void *arg_unused)
237 {
238         uiMenuLevel(head, "Effects...", seq_addmenu_effectmenu);
239         uiMenuSeparator(head);
240
241         uiMenuContext(head, WM_OP_INVOKE_REGION_WIN);
242
243 #ifdef WITH_FFMPEG
244         uiMenuItemBooleanO(head, "Audio (RAM)", 0, "SEQUENCER_OT_sound_strip_add", "hd", FALSE);
245         uiMenuItemBooleanO(head, "Audio (HD)", 0, "SEQUENCER_OT_sound_strip_add", "hd", TRUE);
246 #else
247         uiMenuItemO(head, 0, "SEQUENCER_OT_sound_strip_add");
248 #endif
249         uiMenuItemEnumO(head, "Add Color Strip", 0, "SEQUENCER_OT_effect_strip_add", "type", SEQ_COLOR);
250
251         uiMenuItemO(head, 0, "SEQUENCER_OT_image_strip_add");
252         uiMenuItemO(head, 0, "SEQUENCER_OT_movie_strip_add");
253         uiMenuItemO(head, 0, "SEQUENCER_OT_scene_strip_add");
254 #ifdef WITH_FFMPEG
255         uiMenuItemBooleanO(head, "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, uiMenuItem *head, void *arg_unused)
261 {
262         
263         Scene *scene= CTX_data_scene(C);
264         Editing *ed= seq_give_editing(scene, FALSE);
265         
266         uiMenuContext(head, WM_OP_INVOKE_REGION_WIN);
267
268         uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TRANSLATION);
269         uiMenuItemEnumO(head, "", 0, "TFM_OT_transform", "mode", TFM_TIME_EXTEND);
270
271         // uiMenuItemO(head, 0, "SEQUENCER_OT_strip_snap"); // TODO - add this operator
272
273         uiMenuItemEnumO(head, "Cut Hard", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_HARD);
274         uiMenuItemEnumO(head, "Cut Soft", 0, "SEQUENCER_OT_cut", "type", SEQ_CUT_SOFT);
275
276         uiMenuItemO(head, 0, "SEQUENCER_OT_images_separate");
277         uiMenuSeparator(head);
278         uiMenuItemO(head, 0, "SEQUENCER_OT_duplicate_add");
279         uiMenuItemO(head, 0, "SEQUENCER_OT_delete");
280
281         if (ed && ed->act_seq) {
282                 switch(ed->act_seq->type) {
283                 case SEQ_EFFECT:
284                         uiMenuSeparator(head);
285                         uiMenuItemO(head, 0, "SEQUENCER_OT_effect_change");
286                         uiMenuItemO(head, 0, "SEQUENCER_OT_effect_reassign_inputs");
287                         break;
288                 case SEQ_IMAGE:
289                         uiMenuSeparator(head);
290                         uiMenuItemO(head, 0, "SEQUENCER_OT_image_change"); // Change Scene...
291                         break;
292                 case SEQ_SCENE:
293                         uiMenuSeparator(head);
294                         uiMenuItemO(head, 0, "SEQUENCER_OT_scene_change"); // Remap Paths...
295                         break;
296                 case SEQ_MOVIE:
297                         uiMenuSeparator(head);
298                         uiMenuItemO(head, 0, "SEQUENCER_OT_movie_change"); // Remap Paths...
299                         break;
300                 }
301         }
302
303         uiMenuSeparator(head);
304
305         uiMenuItemO(head, 0, "SEQUENCER_OT_meta_make");
306         uiMenuItemO(head, 0, "SEQUENCER_OT_meta_separate");
307
308         if (ed && (ed->metastack.first || (ed->act_seq && ed->act_seq->type == SEQ_META))) {
309                 uiMenuSeparator(head);
310                 uiMenuItemO(head, 0, "SEQUENCER_OT_meta_toggle");
311         }
312         uiMenuSeparator(head);
313         uiMenuItemO(head, 0, "SEQUENCER_OT_reload");
314         uiMenuSeparator(head);
315         uiMenuItemO(head, 0, "SEQUENCER_OT_lock");
316         uiMenuItemO(head, 0, "SEQUENCER_OT_unlock");
317         uiMenuItemO(head, 0, "SEQUENCER_OT_mute");
318         uiMenuItemO(head, 0, "SEQUENCER_OT_unmute");
319
320         uiMenuItemEnumO(head, "Mute Deselected Strips", 0, "SEQUENCER_OT_mute", "type", SEQ_UNSELECTED);
321 }
322
323 void sequencer_header_buttons(const bContext *C, ARegion *ar)
324 {
325         ScrArea *sa= CTX_wm_area(C);
326         SpaceSeq *sseq= sa->spacedata.first;
327         Scene *scene= CTX_data_scene(C);
328         Editing *ed= seq_give_editing(scene, FALSE);
329         
330         uiBlock *block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
331         int xco=3, yco= 3;
332         
333         xco= ED_area_header_standardbuttons(C, block, yco);
334         
335         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
336                 int xmax;
337                 
338                 /* pull down menus */
339                 uiBlockSetEmboss(block, UI_EMBOSSP);
340                 
341                 xmax= GetButStringLength("View");
342
343                 //uiDefMenuBut(block, seq_viewmenu, NULL, "View", xco, 0, xmax-3, 24, ""); // TODO
344                 uiDefPulldownBut(block, seq_viewmenu, sa, "View", xco, 0, xmax-3, 24, ""); 
345                 xco+=xmax;
346
347                 xmax= GetButStringLength("Select");
348                 uiDefMenuBut(block, seq_selectmenu, NULL, "Select", xco, 0, xmax-3, 24, "");
349                 //uiDefPulldownBut(block, seq_selectmenu, sa, "Select", xco, 0, xmax-3, 24, "");
350                 xco+=xmax;
351
352                 xmax= GetButStringLength("Marker");
353                 //uiDefMenuBut(block, seq_markermenu, NULL, "Marker", xco, 0, xmax-3, 24, "");
354                 uiDefPulldownBut(block, seq_markermenu, sa, "Marker", xco, 0, xmax-3, 24, ""); // TODO
355                 xco+=xmax;
356
357                 xmax= GetButStringLength("Add");
358                 uiDefMenuBut(block, seq_addmenu, NULL, "Add", xco, 0, xmax-3, 24, "");
359                 //uiDefPulldownBut(block, seq_addmenu, sa, "Add", xco, 0, xmax-3, 24, "");
360                 xco+=xmax;
361
362                 xmax= GetButStringLength("Strip");
363                 uiDefMenuBut(block, seq_editmenu, NULL, "Strip", xco, 0, xmax-3, 24, "");
364                 //uiDefPulldownBut(block, seq_editmenu, sa, "Strip", xco, 0, xmax-3, 24, "");
365                 xco+=xmax;
366         }
367
368         uiBlockSetEmboss(block, UI_EMBOSS);
369
370         /* IMAGE */
371         uiDefIconTextButS(block, ICONTEXTROW,B_REDR, ICON_SEQ_SEQUENCER,
372                           "Image Preview: %t"
373                           "|Sequence %x0"
374                           "|Image Preview %x1"
375                           "|Luma Waveform %x2"
376                           "|Chroma Vectorscope %x3"
377                           "|Histogram %x4",
378                           xco,yco,XIC+10,YIC, &sseq->mainb, 0.0, 3.0,
379                           0, 0,
380                           "Shows the sequence output image preview");
381
382         xco+= 8 + XIC+10;
383
384         if(sseq->mainb != SEQ_DRAW_SEQUENCE) {
385                 int minchan = 0;
386
387                 /* CHANNEL shown in image preview */
388
389                 if (ed && ed->metastack.first)
390                         minchan = -BLI_countlist(&ed->metastack);
391
392                 uiDefButS(block, NUM, B_REDR, "Chan:",
393                           xco, yco, 3.5 * XIC,YIC,
394                           &sseq->chanshown, minchan, MAXSEQ, 0, 0,
395                           "The channel number shown in the image preview. 0 is the result of all strips combined.");
396
397                 xco+= 8 + XIC*3.5;
398
399                 if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
400                         uiDefButS(block, MENU, B_REDR,
401                                   "Show zebra: %t"
402                                   "|Z 110 %x110"
403                                   "|Z 100 %x100"
404                                   "|Z 95  %x95"
405                                   "|Z 90  %x90"
406                                   "|Z 70  %x70"
407                                   "|Z Off %x0",
408                                   xco,yco,3.0 * XIC, YIC, &sseq->zebra,
409                                   0,0,0,0,
410                                   "Show overexposed "
411                                   "areas with zebra stripes");
412
413                         xco+= 8 + XIC*3.0;
414
415                         uiDefButBitI(block, TOG, SEQ_DRAW_SAFE_MARGINS,
416                                      B_REDR, "T",
417                                      xco,yco,XIC,YIC, &sseq->flag,
418                                      0, 0, 0, 0,
419                                      "Draw title safe margins in preview");
420                         xco+= 8 + XIC;
421                 }
422
423                 if (sseq->mainb == SEQ_DRAW_IMG_WAVEFORM) {
424                         uiDefButBitI(block, TOG, SEQ_DRAW_COLOR_SEPERATED,
425                                      B_REDR, "CS",
426                                      xco,yco,XIC,YIC, &sseq->flag,
427                                      0, 0, 0, 0,
428                                      "Seperate color channels in preview");
429                         xco+= 8 + XIC;
430                 }
431         } else {
432                 /* ZOOM and BORDER */
433                 static int viewmovetemp; // XXX dummy var
434                 
435                 uiBlockBeginAlign(block);
436                 uiDefIconButI(block, TOG, B_VIEW2DZOOM,
437                               ICON_VIEWZOOM,
438                               xco,yco,XIC,YIC, &viewmovetemp,
439                               0, 0, 0, 0,
440                               "Zooms view in and out (Ctrl MiddleMouse)");
441                 xco += XIC;
442                 uiDefIconButO(block, BUT, "VIEW2D_OT_zoom_border", WM_OP_INVOKE_REGION_WIN, ICON_BORDERMOVE, xco,yco,XIC,YIC, "Zooms view to fit area");
443                 
444                 uiBlockEndAlign(block);
445                 xco += 8 + XIC;
446         }
447
448         uiDefButO(block, BUT, "SEQUENCER_OT_refresh_all", WM_OP_EXEC_DEFAULT, "Refresh", xco, yco, 3*XIC, YIC, "Clears all buffered images in memory");
449
450         uiBlockSetEmboss(block, UI_EMBOSS);
451
452         /* always as last  */
453         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, ar->v2d.tot.ymax-ar->v2d.tot.ymin);
454         
455         uiEndBlock(C, block);
456         uiDrawBlock(C, block);
457 }
458