Made octree size always available since its used for baking.
[blender.git] / source / blender / src / buttons_scene.c
1 /**
2  * $Id$ 
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #include "MEM_guardedalloc.h"
39 #include "DNA_node_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_sound_types.h"
44 #include "DNA_sequence_types.h"
45 #include "DNA_userdef_types.h"
46 #include "DNA_packedFile_types.h"
47
48 #include "BKE_global.h"
49 #include "BKE_main.h"
50 #include "BKE_node.h"
51 #include "BKE_library.h"
52 #include "BKE_scene.h"
53 #include "BKE_sound.h"
54 #include "BKE_packedFile.h"
55 #include "BKE_utildefines.h"
56
57 #include "BLI_blenlib.h"
58
59 #include "BSE_filesel.h"
60
61 #include "BIF_gl.h"
62 #include "BIF_graphics.h"
63 #include "BIF_glutil.h"
64 #include "BIF_interface.h"
65 #include "BIF_imasel.h"
66 #include "BIF_keyval.h"
67 #include "BIF_mainqueue.h"
68 #include "BIF_mywindow.h"
69 #include "BIF_meshtools.h"
70 #include "BIF_resources.h"
71 #include "BIF_renderwin.h"
72 #include "BIF_screen.h"
73 #include "BIF_space.h"
74 #include "BIF_toolbox.h"
75 #include "BIF_editseq.h"
76
77 #include "BIF_butspace.h"
78
79 #include "mydevice.h"
80 #include "blendef.h"
81
82 /* -----includes for this file specific----- */
83
84 #include "DNA_image_types.h"
85
86 #include "BKE_writeavi.h"
87 #include "BKE_writeffmpeg.h"
88 #include "BKE_image.h"
89 #include "BKE_plugin_types.h"
90
91 #include "BLI_threads.h"
92
93 #include "BIF_editsound.h"
94 #include "BIF_writeimage.h"
95 #include "BIF_writeavicodec.h"
96
97 #include "BSE_headerbuttons.h"
98 #include "BSE_sequence.h"
99 #include "BSE_seqeffects.h"
100 #include "BSE_seqscopes.h"
101 #include "BSE_seqaudio.h"
102
103 #include "RE_pipeline.h"
104
105 #include "butspace.h" // own module
106
107 #ifdef WITH_QUICKTIME
108 #include "quicktime_export.h"
109 #endif
110
111 #ifdef WITH_FFMPEG
112
113 #include <ffmpeg/avcodec.h> /* for PIX_FMT_* and CODEC_ID_* */
114 #include <ffmpeg/avformat.h>
115
116 static int ffmpeg_preset_sel = 0;
117
118 extern int is_container(int);
119
120 extern void makeffmpegstring(char* string);
121
122 #endif
123
124 /* here the calls for scene buttons
125    - render
126    - world
127    - anim settings, audio
128 */
129
130 /* prototypes */
131 void playback_anim(void);
132
133 /* ************************ SOUND *************************** */
134 static void load_new_sample(char *str)  /* called from fileselect */
135 {
136         char name[FILE_MAX];
137         bSound *sound;
138         bSample *sample, *newsample;
139
140         sound = G.buts->lockpoin;
141
142         if (sound) {
143                 // save values
144                 sample = sound->sample;
145                 strcpy(name, sound->sample->name);
146
147                 strcpy(sound->name, str);
148                 sound_set_sample(sound, NULL);
149                 sound_initialize_sample(sound);
150
151                 if (sound->sample->type == SAMPLE_INVALID) {
152                         error("Not a valid sample: %s", str);
153
154                         newsample = sound->sample;
155
156                         // restore values
157                         strcpy(sound->name, name);
158                         sound_set_sample(sound, sample);
159
160                         // remove invalid sample
161
162                         sound_free_sample(newsample);
163                         BLI_remlink(samples, newsample);
164                         MEM_freeN(newsample);
165                 }
166         }
167
168         BIF_undo_push("Load new audio file");
169         allqueue(REDRAWBUTSSCENE, 0);
170
171 }
172
173
174 void do_soundbuts(unsigned short event)
175 {
176         char name[FILE_MAX];
177         bSound *sound;
178         bSample *sample;
179         bSound* tempsound;
180         ID *id;
181         
182         sound = G.buts->lockpoin;
183         
184         switch(event) {
185         case B_SOUND_REDRAW:
186                 allqueue(REDRAWBUTSSCENE, 0);
187                 break;
188
189         case B_SOUND_LOAD_SAMPLE:
190                 if (sound) strcpy(name, sound->name);
191                 else strcpy(name, U.sounddir);
192                         
193                 activate_fileselect(FILE_SPECIAL, "SELECT WAV FILE", name, load_new_sample);
194                 break;
195
196         case B_SOUND_PLAY_SAMPLE:
197                 if (sound) {
198                         if (sound->sample->type != SAMPLE_INVALID) {
199                                 sound_play_sound(sound);
200                                 allqueue(REDRAWBUTSSCENE, 0);
201                         }
202                 }
203                 break;
204
205         case B_SOUND_MENU_SAMPLE:
206                 if (G.buts->menunr > 0) {
207                         sample = BLI_findlink(samples, G.buts->menunr - 1);
208                         if (sample && sound) {
209                                 BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
210                                 sound_set_sample(sound, sample);
211                                 do_soundbuts(B_SOUND_REDRAW);
212                         }
213                 }
214                         
215                 break;
216         case B_SOUND_NAME_SAMPLE:
217                 load_new_sample(sound->name);
218                 break;
219         
220         case B_SOUND_UNPACK_SAMPLE:
221                 if(sound && sound->sample) {
222                         sample = sound->sample;
223                         
224                         if (sample->packedfile) {
225                                 if (G.fileflags & G_AUTOPACK) {
226                                         if (okee("Disable AutoPack ?")) {
227                                                 G.fileflags &= ~G_AUTOPACK;
228                                         }
229                                 }
230                                 
231                                 if ((G.fileflags & G_AUTOPACK) == 0) {
232                                         unpackSample(sample, PF_ASK);
233                                 }
234                         } else {
235                                 sound_set_packedfile(sample, newPackedFile(sample->name));
236                         }
237                         allqueue(REDRAWHEADERS, 0);
238                         do_soundbuts(B_SOUND_REDRAW);
239                 }
240                 break;
241
242         case B_SOUND_COPY_SOUND:
243                 if (sound) {
244                         tempsound = sound_make_copy(sound);
245                         sound = tempsound;
246                         id = &sound->id;
247                         G.buts->lockpoin = (bSound*)id;
248                         BIF_undo_push("Copy sound");
249                         do_soundbuts(B_SOUND_REDRAW);
250                 }
251                 break;
252
253         case B_SOUND_RECALC:
254                 waitcursor(1);
255                 sound = G.main->sound.first;
256                 while (sound) {
257                         free(sound->stream);
258                         sound->stream = 0;
259                         audio_makestream(sound);
260                         sound = (bSound *) sound->id.next;
261                 }
262                 waitcursor(0);
263                 allqueue(REDRAWSEQ, 0);
264                 break;
265
266         case B_SOUND_RATECHANGED:
267
268                 allqueue(REDRAWBUTSSCENE, 0);
269                 allqueue(REDRAWSEQ, 0);
270                 break;
271
272         case B_SOUND_MIXDOWN:
273                 audio_mixdown();
274                 break;
275
276         default: 
277                 if (G.f & G_DEBUG) {
278                         printf("do_soundbuts: unhandled event %d\n", event);
279                 }
280         }
281 }
282
283
284 static void sound_panel_listener(void)
285 {
286         uiBlock *block;
287         int xco= 100, yco=100, mixrate;
288         char mixrateinfo[256];
289         
290         block= uiNewBlock(&curarea->uiblocks, "sound_panel_listener", UI_EMBOSS, UI_HELV, curarea->win);
291         if(uiNewPanel(curarea, block, "Listener", "Sound", 320, 0, 318, 204)==0) return;
292
293         mixrate = sound_get_mixrate();
294         sprintf(mixrateinfo, "Game Mixrate: %d Hz", mixrate);
295         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
296
297         yco -= 30;
298         uiDefBut(block, LABEL, 0, "Game listener settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
299
300         yco -= 30;
301         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
302                 xco,yco,195,24,&G.listener->gain, 0.0, 1.0, 1.0, 0, "Sets the maximum volume for the overall sound");
303         
304         yco -= 30;
305         uiDefBut(block, LABEL, 0, "Game Doppler effect settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
306
307         yco -= 30;
308         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Doppler: ",
309         xco,yco,195,24,&G.listener->dopplerfactor, 0.0, 10.0, 1.0, 0, "Use this for scaling the doppler effect");
310         
311         yco -=30;
312         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Velocity: ",
313         xco,yco,195,24,&G.listener->dopplervelocity,0.0,10000.0, 1.0,0, "Sets the propagation speed of sound");
314
315         
316 }
317
318 static void sound_panel_sequencer(void)
319 {
320         uiBlock *block;
321         short xco, yco;
322         char mixrateinfo[256];
323         
324         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sequencer", UI_EMBOSS, UI_HELV, curarea->win);
325         if(uiNewPanel(curarea, block, "Sequencer", "Sound", 640, 0, 318, 204)==0) return;
326
327         /* audio sequence engine settings ------------------------------------------------------------------ */
328
329         xco = 1010;
330         yco = 195;
331
332         uiDefBut(block, LABEL, 0, "Audio sequencer settings", xco,yco,295,20, 0, 0, 0, 0, 0, "");
333
334         yco -= 25;
335         sprintf(mixrateinfo, "Mixing/Sync (latency: %d ms)", (int)( (((float)U.mixbufsize)/(float)G.scene->audio.mixrate)*1000.0 ) );
336         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
337
338         yco -= 25;              
339         uiDefButI(block, ROW, B_SOUND_RATECHANGED, "44.1 kHz",  xco,yco,75,20, &G.scene->audio.mixrate, 2.0, 44100.0, 0, 0, "Mix at 44.1 kHz");
340         uiDefButI(block, ROW, B_SOUND_RATECHANGED, "48.0 kHz",          xco+80,yco,75,20, &G.scene->audio.mixrate, 2.0, 48000.0, 0, 0, "Mix at 48 kHz");
341         uiDefBut(block, BUT, B_SOUND_RECALC, "Recalc",          xco+160,yco,75,20, 0, 0, 0, 0, 0, "Recalculate samples");
342
343         yco -= 25;
344         uiDefButBitS(block, TOG, AUDIO_SYNC, B_SOUND_CHANGED, "Sync",   xco,yco,115,20, &G.scene->audio.flag, 0, 0, 0, 0, "Use sample clock for syncing animation to audio");
345         uiDefButBitS(block, TOG, AUDIO_SCRUB, B_SOUND_CHANGED, "Scrub",         xco+120,yco,115,20, &G.scene->audio.flag, 0, 0, 0, 0, "Scrub when changing frames");
346
347         yco -= 25;
348         uiDefBut(block, LABEL, 0, "Main mix", xco,yco,295,20, 0, 0, 0, 0, 0, "");
349
350         yco -= 25;              
351         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Main (dB): ",
352                 xco,yco,235,24,&G.scene->audio.main, -24.0, 6.0, 0, 0, "Set the audio master gain/attenuation in dB");
353
354         yco -= 25;
355         uiDefButBitS(block, TOG, AUDIO_MUTE, 0, "Mute", xco,yco,235,24, &G.scene->audio.flag, 0, 0, 0, 0, "Mute audio from sequencer");         
356         
357         yco -= 35;
358         uiDefBut(block, BUT, B_SOUND_MIXDOWN, "MIXDOWN",        xco,yco,235,24, 0, 0, 0, 0, 0, "Create WAV file from sequenced audio (output goes to render output dir)");
359         
360 }
361
362 static char *make_sample_menu(void)
363 {
364         int len= BLI_countlist(samples);        /* BKE_sound.h */
365         
366         if(len) {
367                 bSample *sample;
368                 char *str;
369                 int nr, a=0;
370                 
371                 str= MEM_callocN(32*len, "menu");
372                 
373                 for(nr=1, sample= samples->first; sample; sample= sample->id.next, nr++) {
374                         a+= sprintf(str+a, "|%s %%x%d", sample->id.name+2, nr);
375                 }
376                 return str;
377         }
378         return NULL;
379 }
380
381 static void sound_panel_sound(bSound *sound)
382 {
383         static int packdummy=0;
384         ID *id, *idfrom;
385         uiBlock *block;
386         bSample *sample;
387         char *strp, ch[256];
388
389         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sound", UI_EMBOSS, UI_HELV, curarea->win);
390         if(uiNewPanel(curarea, block, "Sound", "Sound", 0, 0, 318, 204)==0) return;
391         
392         uiDefBut(block, LABEL, 0, "Blender Sound block",10,180,195,20, 0, 0, 0, 0, 0, "");
393         
394         // warning: abuse of texnr here! (ton didnt code!)
395         buttons_active_id(&id, &idfrom);
396         std_libbuttons(block, 10, 160, 0, NULL, B_SOUNDBROWSE2, ID_SO, 0, id, idfrom, &(G.buts->texnr), 1, 0, 0, 0, 0);
397
398         if (sound) {
399         
400                 uiDefBut(block, BUT, B_SOUND_COPY_SOUND, "Copy sound", 220,160,90,20, 0, 0, 0, 0, 0, "Make another copy (duplicate) of the current sound");
401
402                 uiSetButLock(sound->id.lib!=0, ERROR_LIBDATA_MESSAGE);
403                 sound_initialize_sample(sound);
404                 sample = sound->sample;
405
406                 /* info string */
407                 if (sound->sample && sound->sample->len) {
408                         char *tmp;
409                         if (sound->sample->channels == 1) tmp= "Mono";
410                         else if (sound->sample->channels == 2) tmp= "Stereo";
411                         else tmp= "Unknown";
412                         
413                         sprintf(ch, "Sample: %s, %d bit, %d Hz, %d samples", tmp, sound->sample->bits, sound->sample->rate, (sound->sample->len/(sound->sample->bits/8)/sound->sample->channels));
414                         uiDefBut(block, LABEL, 0, ch,                   35,140,225,20, 0, 0, 0, 0, 0, "");
415                 }
416                 else {
417                         uiDefBut(block, LABEL, 0, "Sample: No sample info available.",35,140,225,20, 0, 0, 0, 0, 0, "");
418                 }
419
420                 /* sample browse buttons */
421                 uiBlockBeginAlign(block);
422                 strp= make_sample_menu();
423                 if (strp) {
424                         uiDefButS(block, MENU, B_SOUND_MENU_SAMPLE, strp, 10,120,23,20, &(G.buts->menunr), 0, 0, 0, 0, "Select another loaded sample");
425                         MEM_freeN(strp);
426                 }
427                 uiDefBut(block, TEX, B_SOUND_NAME_SAMPLE, "",           35,120,250,20, sound->name, 0.0, 79.0, 0, 0, "The sample file used by this Sound");
428                 
429                 if (sound->sample->packedfile) packdummy = 1;
430                 else packdummy = 0;
431                 
432                 uiDefIconButBitI(block, TOG, 1, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
433                         285, 120,25,20, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
434                 
435                 uiBlockBeginAlign(block);
436                 uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
437
438                 uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play",       160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
439                 
440                 uiBlockBeginAlign(block);
441                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
442                         10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Game engine only: Set the volume of this sound");
443
444                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Pitch: ",
445                         160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Game engine only: Set the pitch of this sound");
446
447                 /* looping */
448                 uiBlockBeginAlign(block);
449                 uiDefButBitI(block, TOG, SOUND_FLAGS_LOOP, B_SOUND_REDRAW, "Loop",
450                         10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between looping on/off");
451
452                 if (sound->flags & SOUND_FLAGS_LOOP) {
453                         uiDefButBitI(block, TOG, SOUND_FLAGS_BIDIRECTIONAL_LOOP, B_SOUND_REDRAW, "Ping Pong",
454                                 105, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between A->B and A->B->A looping");
455                         
456                 }
457         
458
459                 /* 3D settings ------------------------------------------------------------------ */
460                 uiBlockBeginAlign(block);
461
462                 if (sound->sample->channels == 1) {
463                         uiDefButBitI(block, TOG, SOUND_FLAGS_3D, B_SOUND_REDRAW, "3D Sound",
464                                 10, 10, 90, 20, &sound->flags, 0, 0, 0, 0, "Game engine only: Turns 3D sound on");
465                         
466                         if (sound->flags & SOUND_FLAGS_3D) {
467                                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Scale: ",
468                                         100,10,210,20, &sound->attenuation, 0.0, 5.0, 1.0, 0, "Game engine only: Sets the surround scaling factor for this sound");
469                                 
470                         }
471                 }
472         }
473 }
474
475 /* ************************* Sequencer *********************** */
476
477 #define SEQ_PANEL_EDITING 1
478 #define SEQ_PANEL_INPUT   2
479 #define SEQ_PANEL_FILTER  4
480 #define SEQ_PANEL_EFFECT  8
481 #define SEQ_PANEL_PROXY   16
482
483 static char* seq_panel_blend_modes()
484 {
485         static char string[2048];
486
487         Sequence *last_seq = get_last_seq();
488
489         sprintf(string, "Blend mode: %%t|%s %%x%d",
490                 "Replace", SEQ_BLEND_REPLACE);
491
492         /*
493           Blending can only work without effect strips. 
494           Otherwise, one would have
495           to decide, what the effect strips IPO should do:
496           - drive the effect _or_
497           - drive the blend mode ?
498
499           Also: effectdata is used by these implicit effects,
500           so that would collide also.
501         */
502
503         if (!(last_seq->type & SEQ_EFFECT)) {
504                 int i;
505
506                 for (i = SEQ_EFFECT; i <= SEQ_EFFECT_MAX; i++) {
507                         if (get_sequence_effect_num_inputs(i) == 2) {
508                                 sprintf(string + strlen(string), 
509                                         "|%s %%x%d", 
510                                         give_seqname_by_type(i), i);
511                         }
512                 }
513         }
514         return string;
515 }
516
517 static char* seq_panel_scenes()
518 {
519         static char rstr[8192];
520         char * str;
521
522         IDnames_to_pupstring(&str, NULL, NULL, 
523                              &G.main->scene, (ID *)G.scene, NULL);
524
525         strncpy(rstr, str, 8192);
526         MEM_freeN(str);
527
528         return rstr;
529 }
530
531 static void seq_update_scenenr(Sequence * seq)
532 {
533         Scene * sce;
534         int nr;
535         if (seq->type != SEQ_SCENE) {
536                 return;
537         }
538
539         seq->scenenr = 0;
540
541         sce = G.main->scene.first;
542         nr = 1;
543         while(sce) {
544                 if (sce == seq->scene) {
545                         seq->scenenr = nr;
546                         break;
547                 }
548                 nr++;
549                 sce = sce->id.next;
550         }
551 }
552
553
554 static void seq_panel_editing()
555 {
556         Sequence *last_seq = get_last_seq();
557         uiBlock *block;
558         static char strdata[1024];
559         char * str = strdata;
560         char * p;
561         int yco;
562
563         block = uiNewBlock(&curarea->uiblocks, "seq_panel_editing", 
564                            UI_EMBOSS, UI_HELV, curarea->win);
565
566         if(uiNewPanel(curarea, block, "Edit", "Sequencer", 
567                       10, 230, 318, 204) == 0) return;
568
569         uiDefBut(block, LABEL, 
570                  0, give_seqname(last_seq), 
571                  10,140,60,19, 0, 
572                  0, 0, 0, 0, "");
573
574         uiDefBut(block, TEX, 
575                  B_NOP, "Name: ", 
576                  70,140,180,19, last_seq->name+2, 
577                  0.0, 21.0, 100, 0, "");
578
579         uiDefButI(block, MENU, B_SEQ_BUT_RELOAD, seq_panel_blend_modes(), 
580                   10, 120, 120, 19, &last_seq->blend_mode, 
581                   0,0,0,0, "Strip Blend Mode");
582
583         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Blend:",
584                   130, 120, 120, 19, &last_seq->blend_opacity, 
585                   0.0, 100.0, 100.0, 0, 
586                   "Blend opacity");
587
588         uiDefButBitI(block, TOG, SEQ_MUTE,
589                      B_SEQ_BUT_RELOAD_ALL, "Mute",
590                      10,100,60,19, &last_seq->flag,
591                      0.0, 1.0, 0, 0,
592                      "Mute the current strip.");
593
594         uiDefButBitI(block, TOG, SEQ_LOCK,
595                      B_REDR, "Lock",
596                      70,100,60,19, &last_seq->flag,
597                      0.0, 1.0, 0, 0,
598                      "Lock strip, so that it can't be transformed.");
599         
600         uiDefButBitI(block, TOG, SEQ_IPO_FRAME_LOCKED,
601                      B_SEQ_BUT_RELOAD_ALL, "IPO Frame locked",
602                      130,100,120,19, &last_seq->flag,
603                      0.0, 1.0, 0, 0,
604                      "Lock the IPO coordinates to the "
605                      "global frame counter.");
606         
607         if (!(last_seq->flag & SEQ_LOCK)) {
608                 uiDefButI(block, NUM, 
609                           B_SEQ_BUT_TRANSFORM, "Start", 
610                           10, 80, 120, 20, &last_seq->start, 
611                           -MAXFRAMEF, MAXFRAMEF, 0.0, 0.0, "Start of strip");
612                 uiDefButI(block, NUM, 
613                           B_SEQ_BUT_TRANSFORM, "Chan", 
614                           130, 80, 120, 20, &last_seq->machine, 
615                           0.0, MAXSEQ, 0.0, 0.0, "Channel used (Y position)");
616                 
617                 if (check_single_seq(last_seq) || last_seq->len == 0) {
618                         uiDefButI(block, NUM, 
619                                 B_SEQ_BUT_TRANSFORM, "End-Still", 
620                                 130, 60, 120, 19, &last_seq->endstill, 
621                                 0.0, MAXFRAMEF, 0.0, 0.0, "End still");
622                 } else {
623                         uiDefButI(block, NUM, 
624                                   B_SEQ_BUT_TRANSFORM, "Start-Still", 
625                                   10, 60, 120, 20, &last_seq->startstill, 
626                                   0.0, MAXFRAMEF, 0.0, 0.0, "Start still");
627                         uiDefButI(block, NUM, 
628                                   B_SEQ_BUT_TRANSFORM, "End-Still", 
629                                   130, 60, 120, 19, &last_seq->endstill, 
630                                   0.0, MAXFRAMEF, 0.0, 0.0, "End still");
631                         uiDefButI(block, NUM, 
632                                   B_SEQ_BUT_TRANSFORM, "Start-Ofs", 
633                                   10, 40, 120, 20, &last_seq->startofs, 
634                                   0.0, last_seq->len - last_seq->endofs, 
635                                   0.0, 0.0, "Start offset");
636                         uiDefButI(block, NUM, 
637                                   B_SEQ_BUT_TRANSFORM, "End-Ofs", 
638                                   130, 40, 120, 19, &last_seq->endofs, 
639                                   0.0, last_seq->len - last_seq->startofs, 
640                                   0.0, 0.0, "End offset");
641                 }
642         }
643
644
645         if(last_seq->type & SEQ_EFFECT)
646                 sprintf(str, "Len: %d\nFrom %d - %d\n", last_seq->len, last_seq->startdisp, last_seq->enddisp-1);
647         else
648                 sprintf(str, "Len: %d(%d)\n", last_seq->enddisp-last_seq->startdisp, last_seq->len);
649
650         str += strlen(str);
651
652         if(last_seq->type==SEQ_IMAGE) {
653                 if (last_seq->len > 1) {
654                         /* CURRENT */
655                         StripElem * se= give_stripelem(last_seq, CFRA);
656                         StripElem * last;
657
658                         /* FIRST AND LAST */
659         
660                         if(last_seq->strip) {
661                                 se= last_seq->strip->stripdata;
662                                 last= se+last_seq->len-1;
663                                 if(last_seq->startofs) se+= last_seq->startofs;
664                                 if(last_seq->endofs) last-= last_seq->endofs;
665         
666                                 sprintf(str, "First: %s at %d\nLast: %s at %d\n", se->name, last_seq->startdisp, last->name, last_seq->enddisp-1);
667                         }
668                 } else { /* single image */
669                         if (last_seq->strip) {
670                                 sprintf(str, "Len: %d\n", last_seq->enddisp-last_seq->startdisp);
671                         }
672                 }
673
674                 str += strlen(str);
675
676                 /* orig size */
677                 if(last_seq->strip) {
678                         sprintf(str, "OrigSize: %d x %d\n", last_seq->strip->orx, last_seq->strip->ory);
679                 }
680         }
681         else if(last_seq->type==SEQ_MOVIE) {
682                 int sta= last_seq->startofs;
683                 int end= last_seq->len-1-last_seq->endofs;
684
685                 sprintf(str, "First: %d at %d\nLast: %d at %d\nCur: %d\n",
686                         sta, last_seq->startdisp, end, last_seq->enddisp-1,  
687                         (G.scene->r.cfra)-last_seq->startdisp);
688
689                 str += strlen(str);
690                 /* orig size */
691                 if(last_seq->strip) {
692                         sprintf(str, "OrigSize: %d x %d\n", 
693                                 last_seq->strip->orx, last_seq->strip->ory);
694                 }
695         }
696         else if(last_seq->type==SEQ_SCENE) {
697                 TStripElem * se= give_tstripelem(last_seq,  (G.scene->r.cfra));
698                 if(se && last_seq->scene) {
699                         sprintf(str, "First: %d\nLast: %d\nCur: %d\n", last_seq->sfra+se->nr, last_seq->sfra, last_seq->sfra+last_seq->len-1); 
700                 }
701                 str += strlen(str);
702                 /* orig size */
703                 if(last_seq->strip) {
704                         sprintf(str, "OrigSize: %d x %d\n", 
705                                 last_seq->strip->orx, last_seq->strip->ory);
706                 }
707         }
708         else if(last_seq->type==SEQ_RAM_SOUND
709                 || last_seq->type == SEQ_HD_SOUND) {
710
711                 int sta= last_seq->startofs;
712                 int end= last_seq->len-1-last_seq->endofs;
713
714                 sprintf(str, "First: %d at %d\nLast: %d at %d\nCur: %d\n",
715                         sta, last_seq->startdisp, end, last_seq->enddisp-1,  
716                         (G.scene->r.cfra)-last_seq->startdisp);
717         }
718         else if(last_seq->type == SEQ_SPEED) {
719                 SpeedControlVars * vars = 
720                         (SpeedControlVars*) last_seq->effectdata;
721
722                 if (vars) {
723                         sprintf(str, "Last mapped frame: %d at %d\n", 
724                                 vars->lastValidFrame, 
725                                 vars->lastValidFrame 
726                                 + last_seq->startdisp);
727                 }
728         }
729
730         str = strdata;
731         yco = 20;
732
733         while ((p = strchr(str, '\n'))) {
734                 *p = 0;
735                 uiDefBut(block, LABEL, 0, str, 10,yco,240,17, 0, 
736                          0, 0, 0, 0, "");
737                 str = p+1;
738                 yco -= 18;
739         }
740 }
741
742 static void seq_panel_input()
743 {
744         Sequence *last_seq = get_last_seq();
745         uiBlock *block;
746
747         block = uiNewBlock(&curarea->uiblocks, "seq_panel_input", 
748                            UI_EMBOSS, UI_HELV, curarea->win);
749
750         if(uiNewPanel(curarea, block, "Input", "Sequencer", 
751                       10, 230, 318, 204) == 0) return;
752
753         if (last_seq->type == SEQ_MOVIE 
754             || last_seq->type == SEQ_IMAGE 
755             || last_seq->type == SEQ_HD_SOUND 
756             || last_seq->type == SEQ_RAM_SOUND) {
757                 uiDefBut(block, TEX, 
758                          B_SEQ_BUT_RELOAD_FILE, "Dir: ", 
759                          10,140,240,19, last_seq->strip->dir, 
760                          0.0, 160.0, 100, 0, "");
761         }
762
763         if (last_seq->type == SEQ_IMAGE) {
764                 StripElem * se = give_stripelem(last_seq, CFRA);
765
766                 if (se) {
767                         uiDefBut(block, TEX, 
768                                  B_SEQ_BUT_RELOAD_FILE, "File: ", 
769                                  10, 120, 190,19, se->name, 
770                                  0.0, 80.0, 100, 0, "");
771                 }
772
773         } else if (last_seq->type == SEQ_MOVIE || 
774                    last_seq->type == SEQ_HD_SOUND ||
775                    last_seq->type == SEQ_RAM_SOUND) {
776                 uiDefBut(block, TEX, 
777                          B_SEQ_BUT_RELOAD_FILE, "File: ", 
778                          10,120,190,19, last_seq->strip->stripdata->name, 
779                          0.0, 80.0, 100, 0, "");
780         } else if (last_seq->type == SEQ_SCENE) {
781                 seq_update_scenenr(last_seq);
782                 uiDefButI(block, MENU, B_SEQ_BUT_RELOAD_FILE, 
783                           seq_panel_scenes(), 
784                           10, 120, 190, 19, &last_seq->scenenr, 
785                           0,0,0,0, "Linked Scene");
786         }
787
788         uiDefBut(block, BUT, B_SEQ_BUT_RELOAD_FILE, 
789                  "Reload",
790                  200,120,50,19, 0, 0, 0, 0, 0, 
791                  "Reload files/scenes from disk and update strip length.");
792
793         if (last_seq->type == SEQ_MOVIE 
794             || last_seq->type == SEQ_IMAGE 
795             || last_seq->type == SEQ_SCENE
796             || last_seq->type == SEQ_META) {
797                 uiDefButBitI(block, TOG, SEQ_USE_CROP,
798                              B_SEQ_BUT_RELOAD, "Use Crop",
799                              10,100,240,19, &last_seq->flag,
800                              0.0, 1.0, 0, 0,
801                              "Crop image before processing.");
802
803                 if (last_seq->flag & SEQ_USE_CROP) {
804                         if (!last_seq->strip->crop) {
805                                 last_seq->strip->crop = 
806                                         MEM_callocN(sizeof(struct StripCrop), 
807                                                     "StripCrop");
808                         }
809                         uiDefButI(block, NUM, 
810                                   B_SEQ_BUT_RELOAD, "Top", 
811                                   10, 80, 120, 20, 
812                                   &last_seq->strip->crop->top, 
813                                   0.0, 4096, 0.0, 0.0, "Top of source image");
814                         uiDefButI(block, NUM, 
815                                   B_SEQ_BUT_RELOAD, "Bottom", 
816                                   130, 80, 120, 20, 
817                                   &last_seq->strip->crop->bottom, 
818                                   0.0, 4096, 0.0, 0.0,
819                                   "Bottom of source image");
820                         
821                         uiDefButI(block, NUM, 
822                                   B_SEQ_BUT_RELOAD, "Left", 
823                                   10, 60, 120, 20,
824                                   &last_seq->strip->crop->left, 
825                                   0.0, 4096, 0.0, 0.0, "Left");
826                         uiDefButI(block, NUM, 
827                                   B_SEQ_BUT_RELOAD, "Right", 
828                                   130, 60, 120, 19, 
829                                   &last_seq->strip->crop->right, 
830                                   0.0, 4096, 0.0, 0.0, "Right");
831                 }
832                 
833                 uiDefButBitI(block, TOG, SEQ_USE_TRANSFORM,
834                              B_SEQ_BUT_RELOAD, "Use Translate",
835                              10,40,240,19, &last_seq->flag,
836                              0.0, 1.0, 0, 0,
837                              "Translate image before processing.");
838                 
839                 if (last_seq->flag & SEQ_USE_TRANSFORM) {
840                         if (!last_seq->strip->transform) {
841                                 last_seq->strip->transform = 
842                                         MEM_callocN(
843                                                 sizeof(struct StripTransform), 
844                                                 "StripTransform");
845                         }
846                         uiDefButI(block, NUM, 
847                                   B_SEQ_BUT_RELOAD, "X-Ofs", 
848                                   10, 20, 120, 20, 
849                                   &last_seq->strip->transform->xofs, 
850                                   -4096.0, 4096, 0.0, 0.0, "X Offset");
851                         uiDefButI(block, NUM, 
852                                   B_SEQ_BUT_RELOAD, "Y-Ofs", 
853                                   130, 20, 120, 20, 
854                                   &last_seq->strip->transform->yofs, 
855                                   -4096.0, 4096, 0.0, 0.0, "Y Offset");
856                 }
857         }
858
859         uiDefButI(block, NUM, 
860                   B_SEQ_BUT_RELOAD_FILE, "A-Start", 
861                   10, 0, 120, 20, &last_seq->anim_startofs, 
862                   0.0, last_seq->len + last_seq->anim_startofs, 0.0, 0.0, 
863                   "Animation start offset (trim start)");
864         uiDefButI(block, NUM, 
865                   B_SEQ_BUT_RELOAD_FILE, "A-End", 
866                   130, 0, 120, 20, &last_seq->anim_endofs, 
867                   0.0, last_seq->len + last_seq->anim_endofs, 0.0, 0.0, 
868                   "Animation end offset (trim end)");
869
870
871         if (last_seq->type == SEQ_MOVIE) {
872                 uiDefButI(block, NUM, B_SEQ_BUT_RELOAD, "MPEG-Preseek:",
873                           10, -20, 240,19, &last_seq->anim_preseek, 
874                           0.0, 50.0, 100,0,
875                           "On MPEG-seeking preseek this many frames");
876         }
877
878 }
879
880 static void seq_panel_filter_video()
881 {
882         Sequence *last_seq = get_last_seq();
883         uiBlock *block;
884         block = uiNewBlock(&curarea->uiblocks, "seq_panel_filter", 
885                            UI_EMBOSS, UI_HELV, curarea->win);
886
887         if(uiNewPanel(curarea, block, "Filter", "Sequencer", 
888                       10, 230, 318, 204) == 0) return;
889
890
891         uiBlockBeginAlign(block);
892
893
894         uiDefButBitI(block, TOG, SEQ_MAKE_PREMUL, 
895                      B_SEQ_BUT_RELOAD, "Premul", 
896                      10,110,80,19, &last_seq->flag, 
897                      0.0, 21.0, 100, 0, 
898                      "Converts RGB values to become premultiplied with Alpha");
899
900         uiDefButBitI(block, TOG, SEQ_MAKE_FLOAT, 
901                      B_SEQ_BUT_RELOAD, "Float", 
902                      90,110,80,19, &last_seq->flag, 
903                      0.0, 21.0, 100, 0, 
904                      "Convert input to float data");
905
906         uiDefButBitI(block, TOG, SEQ_FILTERY, 
907                      B_SEQ_BUT_RELOAD, "FilterY",       
908                      170,110,80,19, &last_seq->flag, 
909                      0.0, 21.0, 100, 0, 
910                      "For video movies to remove fields");
911
912         uiDefButBitI(block, TOG, SEQ_FLIPX, 
913                      B_SEQ_BUT_RELOAD, "FlipX", 
914                      10,90,80,19, &last_seq->flag, 
915                      0.0, 21.0, 100, 0, 
916                      "Flip on the X axis");
917         uiDefButBitI(block, TOG, SEQ_FLIPY, 
918                      B_SEQ_BUT_RELOAD, "FlipY", 
919                      90,90,80,19, &last_seq->flag, 
920                      0.0, 21.0, 100, 0, 
921                      "Flip on the Y axis");
922
923         uiDefButBitI(block, TOG, SEQ_REVERSE_FRAMES,
924                      B_SEQ_BUT_RELOAD, "Flip Time", 
925                      170,90,80,19, &last_seq->flag, 
926                      0.0, 21.0, 100, 0, 
927                      "Reverse frame order");
928                 
929         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Mul:",
930                   10,70,120,19, &last_seq->mul, 
931                   0.001, 20.0, 0.1, 0, 
932                   "Multiply colors");
933
934         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Strobe:",
935                   130,70,120,19, &last_seq->strobe, 
936                   1.0, 30.0, 100, 0, 
937                   "Only display every nth frame");
938
939         uiDefButBitI(block, TOG, SEQ_USE_COLOR_BALANCE,
940                      B_SEQ_BUT_RELOAD, "Use Color Balance", 
941                      10,50,240,19, &last_seq->flag, 
942                      0.0, 21.0, 100, 0, 
943                      "Activate Color Balance "
944                      "(3-Way color correction) on input");
945
946
947         if (last_seq->flag & SEQ_USE_COLOR_BALANCE) {
948                 if (!last_seq->strip->color_balance) {
949                         int c;
950                         StripColorBalance * cb 
951                                 = last_seq->strip->color_balance 
952                                 = MEM_callocN(
953                                         sizeof(struct StripColorBalance), 
954                                         "StripColorBalance");
955                         for (c = 0; c < 3; c++) {
956                                 cb->lift[c] = 1.0;
957                                 cb->gamma[c] = 1.0;
958                                 cb->gain[c] = 1.0;
959                         }
960                 }
961
962                 uiDefBut(block, LABEL, 0, "Lift",
963                          10,30,80,19, 0, 0, 0, 0, 0, "");
964                 uiDefBut(block, LABEL, 0, "Gamma",
965                          90,30,80,19, 0, 0, 0, 0, 0, "");
966                 uiDefBut(block, LABEL, 0, "Gain",
967                          170,30,80,19, 0, 0, 0, 0, 0, "");
968
969                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Lift",
970                           10,10,80,19, last_seq->strip->color_balance->lift, 
971                           0, 0, 0, 0, "Lift (shadows)");
972
973                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Gamma",
974                           90,10,80,19, last_seq->strip->color_balance->gamma, 
975                           0, 0, 0, 0, "Gamma (midtones)");
976
977                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Gain",
978                           170,10,80,19, last_seq->strip->color_balance->gain, 
979                           0, 0, 0, 0, "Gain (highlights)");
980
981                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_LIFT,
982                              B_SEQ_BUT_RELOAD, "Inv Lift", 
983                              10,-10,80,19, 
984                              &last_seq->strip->color_balance->flag, 
985                              0.0, 21.0, 100, 0, 
986                              "Inverse Lift");
987                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_GAMMA,
988                              B_SEQ_BUT_RELOAD, "Inv Gamma", 
989                              90,-10,80,19, 
990                              &last_seq->strip->color_balance->flag, 
991                              0.0, 21.0, 100, 0, 
992                              "Inverse Gamma");
993                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_GAIN,
994                              B_SEQ_BUT_RELOAD, "Inv Gain", 
995                              170,-10,80,19, 
996                              &last_seq->strip->color_balance->flag, 
997                              0.0, 21.0, 100, 0, 
998                              "Inverse Gain");
999         }
1000
1001
1002         uiBlockEndAlign(block);
1003
1004 }
1005
1006
1007 static void seq_panel_filter_audio()
1008 {
1009         Sequence *last_seq = get_last_seq();
1010         uiBlock *block;
1011         block = uiNewBlock(&curarea->uiblocks, "seq_panel_filter", 
1012                            UI_EMBOSS, UI_HELV, curarea->win);
1013
1014         if(uiNewPanel(curarea, block, "Filter", "Sequencer", 
1015                       10, 230, 318, 204) == 0) return;
1016
1017         uiBlockBeginAlign(block);
1018         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Gain (dB):", 10,50,150,19, &last_seq->level, -96.0, 6.0, 100, 0, "");
1019         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Pan:",         10,30,150,19, &last_seq->pan, -1.0, 1.0, 100, 0, "");
1020         uiBlockEndAlign(block);
1021 }
1022
1023 static void seq_panel_effect()
1024 {
1025         Sequence *last_seq = get_last_seq();
1026         uiBlock *block;
1027         block = uiNewBlock(&curarea->uiblocks, "seq_panel_effect", 
1028                            UI_EMBOSS, UI_HELV, curarea->win);
1029
1030         if(uiNewPanel(curarea, block, "Effect", "Sequencer", 
1031                       10, 230, 318, 204) == 0) return;
1032
1033         if(last_seq->type == SEQ_PLUGIN) {
1034                 PluginSeq *pis;
1035                 VarStruct *varstr;
1036                 int a, xco, yco;
1037
1038                 get_sequence_effect(last_seq);/* make sure, plugin is loaded */
1039
1040                 pis= last_seq->plugin;
1041                 if(pis->vars==0) return;
1042
1043                 varstr= pis->varstr;
1044                 if(varstr) {
1045                         for(a=0; a<pis->vars; a++, varstr++) {
1046                                 xco= 150*(a/6)+10;
1047                                 yco= 125 - 20*(a % 6)+1;
1048                                 uiDefBut(block, varstr->type, B_SEQ_BUT_PLUGIN, varstr->name, xco,yco,150,19, &(pis->data[a]), varstr->min, varstr->max, 100, 0, varstr->tip);
1049
1050                         }
1051                 }
1052                 return;
1053         } 
1054
1055         uiBlockBeginAlign(block);
1056
1057         if(last_seq->type==SEQ_WIPE){
1058                 WipeVars *wipe = (WipeVars *)last_seq->effectdata;
1059                 char formatstring[256];
1060                         
1061                 strncpy(formatstring, "Transition Type %t|Single Wipe%x0|Double Wipe %x1|Iris Wipe %x4|Clock Wipe %x5", 255);
1062                 uiDefButS(block, MENU,B_SEQ_BUT_EFFECT, formatstring,   10,65,220,22, &wipe->wipetype, 0, 0, 0, 0, "What type of wipe should be performed");
1063                 uiDefButF(block, NUM,B_SEQ_BUT_EFFECT,"Blur:",  10,40,220,22, &wipe->edgeWidth,0.0,1.0, 1, 2, "The percent width of the blur edge");
1064                 switch(wipe->wipetype){ /*Skip Types that do not require angle*/
1065                 case DO_IRIS_WIPE:
1066                 case DO_CLOCK_WIPE:
1067                         break;
1068                         
1069                 default:
1070                         uiDefButF(block, NUM,B_SEQ_BUT_EFFECT,"Angle:", 10,15,220,22, &wipe->angle,-90.0,90.0, 1, 2, "The Angle of the Edge");
1071                 }
1072                 uiDefButS(block, TOG,B_SEQ_BUT_EFFECT,"Wipe In",  10,-10,220,22, &wipe->forward,0,0, 0, 0, "Controls Primary Direction of Wipe");                               
1073         } else if(last_seq->type==SEQ_GLOW){
1074                 GlowVars *glow = (GlowVars *)last_seq->effectdata;
1075
1076                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Threshold:",   10,70,150,19, &glow->fMini, 0.0, 1.0, 0, 0, "Trigger Intensity");
1077                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Clamp:",                       10,50,150,19, &glow->fClamp, 0.0, 1.0, 0, 0, "Brightness limit of intensity");
1078                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Boost factor:",        10,30,150,19, &glow->fBoost, 0.0, 10.0, 0, 0, "Brightness multiplier");
1079                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Blur distance:",       10,10,150,19, &glow->dDist, 0.5, 20.0, 0, 0, "Radius of glow effect");
1080                 uiDefButI(block, NUM, B_NOP, "Quality:", 10,-5,150,19, &glow->dQuality, 1.0, 5.0, 0, 0, "Accuracy of the blur effect");
1081                 uiDefButI(block, TOG, B_NOP, "Only boost", 10,-25,150,19, &glow->bNoComp, 0.0, 0.0, 0, 0, "Show the glow buffer only");
1082         }
1083         else if(last_seq->type==SEQ_TRANSFORM){
1084                 TransformVars *transform = (TransformVars *)last_seq->effectdata;
1085
1086                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "xScale Start:",        10,70,150,19, &transform->ScalexIni, 0.0, 10.0, 0, 0, "X Scale Start");
1087                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "xScale End:",  160,70,150,19, &transform->ScalexFin, 0.0, 10.0, 0, 0, "X Scale End");
1088                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "yScale Start:",        10,50,150,19, &transform->ScaleyIni, 0.0, 10.0, 0, 0, "Y Scale Start");
1089                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "yScale End:",  160,50,150,19, &transform->ScaleyFin, 0.0, 10.0, 0, 0, "Y Scale End");
1090                 
1091                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Percent", 10, 30, 150, 19, &transform->percent, 0.0, 1.0, 0.0, 0.0, "Percent Translate");
1092                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Pixels", 160, 30, 150, 19, &transform->percent, 0.0, 0.0, 0.0, 0.0, "Pixels Translate");
1093                 if(transform->percent==1){
1094                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x Start:",     10,10,150,19, &transform->xIni, -500.0, 500.0, 0, 0, "X Position Start");
1095                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x End:",       160,10,150,19, &transform->xFin, -500.0, 500.0, 0, 0, "X Position End");
1096                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y Start:",     10,-10,150,19, &transform->yIni, -500.0, 500.0, 0, 0, "Y Position Start");
1097                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y End:",       160,-10,150,19, &transform->yFin, -500.0, 500.0, 0, 0, "Y Position End");
1098                 } else {
1099                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x Start:",     10,10,150,19, &transform->xIni, -10000.0, 10000.0, 0, 0, "X Position Start");
1100                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x End:",       160,10,150,19, &transform->xFin, -10000.0, 10000.0, 0, 0, "X Position End");
1101                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y Start:",     10,-10,150,19, &transform->yIni, -10000.0, 10000.0, 0, 0, "Y Position Start");
1102                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y End:",       160,-10,150,19, &transform->yFin, -10000.0, 10000.0, 0, 0, "Y Position End");
1103                         
1104                 }
1105                 
1106                 
1107                 
1108                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "rot Start:",10,-30,150,19, &transform->rotIni, 0.0, 360.0, 0, 0, "Rotation Start");
1109                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "rot End:",160,-30,150,19, &transform->rotFin, 0.0, 360.0, 0, 0, "Rotation End");
1110                 
1111                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "No Interpolat", 10, -50, 100, 19, &transform->interpolation, 0.0, 0.0, 0.0, 0.0, "No interpolation");
1112                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Bilinear", 101, -50, 100, 19, &transform->interpolation, 0.0, 1.0, 0.0, 0.0, "Bilinear interpolation");
1113                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Bicubic", 202, -50, 100, 19, &transform->interpolation, 0.0, 2.0, 0.0, 0.0, "Bicubic interpolation");
1114         } else if(last_seq->type==SEQ_COLOR) {
1115                 SolidColorVars *colvars = (SolidColorVars *)last_seq->effectdata;
1116                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "",10,90,150,19, colvars->col, 0, 0, 0, 0, "");
1117         } else if(last_seq->type==SEQ_SPEED){
1118                 SpeedControlVars *sp = 
1119                         (SpeedControlVars *)last_seq->effectdata;
1120                 
1121                 uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Global Speed:",        10,70,150,19, &sp->globalSpeed, 0.0, 100.0, 0, 0, "Global Speed");
1122                 
1123                 uiDefButBitI(block, TOG, SEQ_SPEED_INTEGRATE,
1124                              B_SEQ_BUT_RELOAD, 
1125                              "IPO is velocity",
1126                              10,50,150,19, &sp->flags, 
1127                              0.0, 1.0, 0, 0, 
1128                              "Interpret the IPO value as a "
1129                              "velocity instead of a frame number");
1130
1131                 uiDefButBitI(block, TOG, SEQ_SPEED_BLEND,
1132                              B_SEQ_BUT_RELOAD, 
1133                              "Enable frame blending",
1134                              10,30,150,19, &sp->flags, 
1135                              0.0, 1.0, 0, 0, 
1136                              "Blend two frames into the "
1137                              "target for a smoother result");
1138                 
1139                 uiDefButBitI(block, TOG, SEQ_SPEED_COMPRESS_IPO_Y,
1140                              B_SEQ_BUT_RELOAD, 
1141                              "IPO value runs from [0..1]",
1142                              10,10,150,19, &sp->flags, 
1143                              0.0, 1.0, 0, 0, 
1144                              "Scale IPO value to get the "
1145                              "target frame number.");
1146         }
1147
1148         uiBlockEndAlign(block);
1149 }
1150
1151 static void seq_panel_proxy()
1152 {
1153         Sequence *last_seq = get_last_seq();
1154         uiBlock *block;
1155         block = uiNewBlock(&curarea->uiblocks, "seq_panel_proxy", 
1156                            UI_EMBOSS, UI_HELV, curarea->win);
1157
1158         if(uiNewPanel(curarea, block, "Proxy", "Sequencer", 
1159                       10, 230, 318, 204) == 0) return;
1160
1161         uiBlockBeginAlign(block);
1162
1163         uiDefButBitI(block, TOG, SEQ_USE_PROXY, 
1164                      B_SEQ_BUT_RELOAD, "Use Proxy", 
1165                      10,140,120,19, &last_seq->flag, 
1166                      0.0, 21.0, 100, 0, 
1167                      "Use a preview proxy for this strip");
1168
1169         if (last_seq->flag & SEQ_USE_PROXY) {
1170                 if (!last_seq->strip->proxy) {
1171                         last_seq->strip->proxy = 
1172                                 MEM_callocN(sizeof(struct StripProxy),
1173                                             "StripProxy");
1174                 }
1175
1176                 uiDefButBitI(block, TOG, SEQ_USE_PROXY_CUSTOM_DIR, 
1177                              B_SEQ_BUT_RELOAD, "Custom Dir", 
1178                              130,140,120,19, &last_seq->flag, 
1179                              0.0, 21.0, 100, 0, 
1180                              "Use a custom directory to store data");
1181         }
1182
1183         if (last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) {
1184                 uiDefBut(block, TEX, 
1185                          B_SEQ_BUT_RELOAD, "Dir: ", 
1186                          10,120,240,19, last_seq->strip->proxy->dir, 
1187                          0.0, 160.0, 100, 0, "");
1188         }
1189
1190         if (last_seq->flag & SEQ_USE_PROXY) {
1191                 if (G.scene->r.size == 100) {
1192                         uiDefBut(block, LABEL, 0, 
1193                                  "Full render size selected, ",
1194                                  10,100,240,19, 0, 0, 0, 0, 0, "");
1195                         uiDefBut(block, LABEL, 0, 
1196                                  "so no proxy enabled!",
1197                                  10,80,240,19, 0, 0, 0, 0, 0, "");
1198                 } else if (last_seq->type != SEQ_MOVIE 
1199                            && last_seq->type != SEQ_IMAGE
1200                            && !(last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) {
1201                         uiDefBut(block, LABEL, 0, 
1202                                  "Cannot proxy this strip without ",
1203                                  10,100,240,19, 0, 0, 0, 0, 0, "");
1204                         uiDefBut(block, LABEL, 0, 
1205                                  "custom directory selection!",
1206                                  10,80,240,19, 0, 0, 0, 0, 0, "");
1207
1208                 } else {
1209                         uiDefBut(block, BUT, B_SEQ_BUT_REBUILD_PROXY, 
1210                                  "Rebuild proxy",
1211                                  10,100,240,19, 0, 0, 0, 0, 0, 
1212                                  "Rebuild proxy for the "
1213                                  "currently selected strip.");
1214                 }
1215         }
1216
1217         uiBlockEndAlign(block);
1218 }
1219
1220
1221 void sequencer_panels()
1222 {
1223         Sequence *last_seq = get_last_seq();
1224         int panels = 0;
1225         int type;
1226
1227         if(last_seq == NULL) {
1228                 return;
1229         }
1230         
1231         type = last_seq->type;
1232
1233         panels = SEQ_PANEL_EDITING;
1234
1235         if (type == SEQ_MOVIE || type == SEQ_IMAGE || type == SEQ_SCENE
1236             || type == SEQ_META) {
1237                 panels |= SEQ_PANEL_INPUT | SEQ_PANEL_FILTER | SEQ_PANEL_PROXY;
1238         }
1239
1240         if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1241                 panels |= SEQ_PANEL_FILTER | SEQ_PANEL_INPUT;
1242         }
1243
1244         if (type == SEQ_PLUGIN || type >= SEQ_EFFECT) {
1245                 panels |= SEQ_PANEL_EFFECT | SEQ_PANEL_PROXY;
1246         }
1247
1248         if (panels & SEQ_PANEL_EDITING) {
1249                 seq_panel_editing();
1250         }
1251
1252         if (panels & SEQ_PANEL_INPUT) {
1253                 seq_panel_input();
1254         }
1255
1256         if (panels & SEQ_PANEL_FILTER) {
1257                 if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1258                         seq_panel_filter_audio();
1259                 } else {
1260                         seq_panel_filter_video();
1261                 }
1262         }
1263
1264         if (panels & SEQ_PANEL_EFFECT) {
1265                 seq_panel_effect();
1266         }
1267
1268         if (panels & SEQ_PANEL_PROXY) {
1269                 seq_panel_proxy();
1270         }
1271 }
1272
1273
1274 void do_sequencer_panels(unsigned short event)
1275 {
1276         Sequence *last_seq = get_last_seq();
1277
1278         switch(event) {
1279         case B_SEQ_BUT_PLUGIN:
1280         case B_SEQ_BUT_EFFECT:
1281                 update_changed_seq_and_deps(last_seq, 0, 1);
1282                 break;
1283         case B_SEQ_BUT_RELOAD_FILE:
1284                 reload_sequence_new_file(last_seq);
1285                 break;
1286         case B_SEQ_BUT_REBUILD_PROXY:
1287                 seq_proxy_rebuild(last_seq);
1288                 break;
1289         case B_SEQ_BUT_RELOAD:
1290         case B_SEQ_BUT_RELOAD_ALL:
1291                 update_seq_ipo_rect(last_seq);
1292                 update_seq_icu_rects(last_seq);
1293
1294                 free_imbuf_seq();       // frees all
1295
1296                 break;
1297         case B_SEQ_BUT_TRANSFORM:
1298                 calc_sequence(last_seq);
1299                 if (test_overlap_seq(last_seq))
1300                         shuffle_seq(last_seq);
1301                 break;
1302         }
1303
1304         if (event == B_SEQ_BUT_RELOAD_ALL) {
1305                 allqueue(REDRAWALL, 0);
1306         } else {
1307                 allqueue(REDRAWSEQ, 0);
1308         }
1309 }
1310
1311
1312 /* ************************* SCENE *********************** */
1313
1314
1315 static void output_pic(char *name)
1316 {
1317         strcpy(G.scene->r.pic, name);
1318         allqueue(REDRAWBUTSSCENE, 0);
1319         BIF_undo_push("Change output picture directory");
1320 }
1321
1322 static void backbuf_pic(char *name)
1323 {
1324         Image *ima;
1325         
1326         strcpy(G.scene->r.backbuf, name);
1327         allqueue(REDRAWBUTSSCENE, 0);
1328
1329         ima= BKE_add_image_file(name);
1330         if(ima)
1331                 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
1332
1333         BIF_undo_push("Change background picture");
1334 }
1335
1336 static void run_playanim(char *file) 
1337 {
1338         extern char bprogname[];        /* usiblender.c */
1339         char str[FILE_MAX*2]; /* FILE_MAX*2 is a bit arbitary, but this should roughly allow for the args + the max-file-length */
1340         int pos[2], size[2];
1341
1342         /* use current settings for defining position of window. it actually should test image size */
1343         calc_renderwin_rectangle((G.scene->r.xsch*G.scene->r.size)/100, 
1344                                                          (G.scene->r.ysch*G.scene->r.size)/100, G.winpos, pos, size);
1345 #ifdef WIN32
1346         sprintf(str, "%s -a -s %d -e %d -p %d %d -f %d %g \"%s\"", bprogname, G.scene->r.sfra, G.scene->r.efra, pos[0], pos[1], G.scene->r.frs_sec, G.scene->r.frs_sec_base, file);
1347 #else
1348         sprintf(str, "\"%s\" -a -s %d -e %d  -p %d %d -f %d %g \"%s\"", bprogname, G.scene->r.sfra, G.scene->r.efra, pos[0], pos[1], G.scene->r.frs_sec, G.scene->r.frs_sec_base, file);
1349 #endif
1350         system(str);
1351 }
1352
1353 void playback_anim(void)
1354 {       
1355         char file[FILE_MAX];
1356
1357         if(BKE_imtype_is_movie(G.scene->r.imtype)) {
1358                 switch (G.scene->r.imtype) {
1359 #ifdef WITH_QUICKTIME
1360                         case R_QUICKTIME:
1361                                 makeqtstring(file);
1362                                 break;
1363 #endif
1364 #ifdef WITH_FFMPEG
1365                 case R_FFMPEG:
1366                         makeffmpegstring(file);
1367                         break;
1368 #endif
1369                 default:
1370                         makeavistring(&G.scene->r, file);
1371                         break;
1372                 }
1373                 if(BLI_exist(file)) {
1374                         run_playanim(file);
1375                 }
1376                 else error("Can't find movie: %s", file);
1377         }
1378         else {
1379                 BKE_makepicstring(file, G.scene->r.pic, G.scene->r.sfra, G.scene->r.imtype);
1380                 if(BLI_exist(file)) {
1381                         run_playanim(file);
1382                 }
1383                 else error("Can't find image: %s", file);
1384         }
1385 }
1386
1387 #ifdef WITH_FFMPEG
1388 static void set_ffmpeg_preset(int preset);
1389 #endif
1390
1391 void do_render_panels(unsigned short event)
1392 {
1393         ScrArea *sa;
1394         ID *id;
1395
1396         switch(event) {
1397
1398         case B_DORENDER:
1399                 BIF_do_render(0);
1400                 break;
1401         case B_RTCHANGED:
1402                 allqueue(REDRAWALL, 0);
1403                 break;
1404         case B_SWITCHRENDER:
1405                 /* new panels added, so... */
1406                 G.buts->re_align= 1;
1407                 allqueue(REDRAWBUTSSCENE, 0);
1408                 break;
1409         case B_PLAYANIM:
1410                 playback_anim();
1411                 break;
1412                 
1413         case B_DOANIM:
1414                 BIF_do_render(1);
1415                 break;
1416         
1417         case B_FS_PIC:
1418                 sa= closest_bigger_area();
1419                 areawinset(sa->win);
1420                 if(G.qual == LR_CTRLKEY)
1421                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1422                 else
1423                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1424                 break;
1425
1426         case B_FS_BACKBUF:
1427                 sa= closest_bigger_area();
1428                 areawinset(sa->win);
1429                 if(G.qual == LR_CTRLKEY)
1430                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1431                 else
1432                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1433                 break;
1434         
1435         case B_PR_PAL:
1436                 G.scene->r.xsch= 720;
1437                 G.scene->r.ysch= 576;
1438                 G.scene->r.xasp= 54;
1439                 G.scene->r.yasp= 51;
1440                 G.scene->r.size= 100;
1441                 G.scene->r.frs_sec= 25;
1442                 G.scene->r.frs_sec_base= 1;
1443                 G.scene->r.mode &= ~R_PANORAMA;
1444                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1445 #ifdef WITH_FFMPEG
1446                 G.scene->r.ffcodecdata.gop_size = 15;
1447 #endif          
1448                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1449                 BIF_undo_push("Set PAL");
1450                 allqueue(REDRAWBUTSSCENE, 0);
1451                 allqueue(REDRAWVIEWCAM, 0);
1452                 break;
1453
1454         case B_FILETYPEMENU:
1455                 allqueue(REDRAWBUTSSCENE, 0);
1456 #ifdef WITH_FFMPEG
1457                 if (G.scene->r.imtype == R_FFMPEG) {
1458                         if (G.scene->r.ffcodecdata.type <= 0 ||
1459                             G.scene->r.ffcodecdata.codec <= 0 ||
1460                             G.scene->r.ffcodecdata.audio_codec <= 0 ||
1461                             G.scene->r.ffcodecdata.video_bitrate <= 1) {
1462                                 G.scene->r.ffcodecdata.codec 
1463                                         = CODEC_ID_MPEG2VIDEO;
1464                                 set_ffmpeg_preset(FFMPEG_PRESET_DVD);
1465                         }
1466
1467                         if (G.scene->r.ffcodecdata.audio_codec <= 0) {
1468                                 G.scene->r.ffcodecdata.audio_codec 
1469                                         = CODEC_ID_MP2;
1470                                 G.scene->r.ffcodecdata.audio_bitrate = 128;
1471                         }
1472                         break;
1473                 }
1474 #endif
1475 #if defined (_WIN32) || defined (__APPLE__)
1476                 // fall through to codec settings if this is the first
1477                 // time R_AVICODEC is selected for this scene.
1478                 if (((G.scene->r.imtype == R_AVICODEC) 
1479                          && (G.scene->r.avicodecdata == NULL)) ||
1480                         ((G.scene->r.imtype == R_QUICKTIME) 
1481                          && (G.scene->r.qtcodecdata == NULL))) {
1482                 } else {
1483                   break;
1484                 }
1485 #endif /*_WIN32 || __APPLE__ */
1486
1487         case B_SELECTCODEC:
1488 #if defined (_WIN32) || defined (__APPLE__)
1489                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
1490 #ifdef WITH_QUICKTIME
1491                         get_qtcodec_settings();
1492 #endif /* WITH_QUICKTIME */
1493                 }
1494 #if defined (_WIN32) && !defined(FREE_WINDOWS)
1495                 else
1496                         get_avicodec_settings();
1497 #endif /* _WIN32 && !FREE_WINDOWS */
1498 #endif /* _WIN32 || __APPLE__ */
1499                 break;
1500
1501         case B_PR_HD:
1502                 G.scene->r.xsch= 1920;
1503                 G.scene->r.ysch= 1080;
1504                 G.scene->r.xasp= 1;
1505                 G.scene->r.yasp= 1;
1506                 G.scene->r.size= 100;
1507                 G.scene->r.mode &= ~R_PANORAMA;
1508                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1509                 
1510                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1511                 BIF_undo_push("Set FULL");
1512                 allqueue(REDRAWBUTSSCENE, 0);
1513                 allqueue(REDRAWVIEWCAM, 0);
1514                 break;
1515         case B_PR_FULL:
1516                 G.scene->r.xsch= 1280;
1517                 G.scene->r.ysch= 1024;
1518                 G.scene->r.xasp= 1;
1519                 G.scene->r.yasp= 1;
1520                 G.scene->r.size= 100;
1521                 G.scene->r.mode &= ~R_PANORAMA;
1522                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1523
1524                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1525                 BIF_undo_push("Set FULL");
1526                 allqueue(REDRAWBUTSSCENE, 0);
1527                 allqueue(REDRAWVIEWCAM, 0);
1528                 break;
1529         case B_PR_PRV:
1530                 G.scene->r.xsch= 640;
1531                 G.scene->r.ysch= 512;
1532                 G.scene->r.xasp= 1;
1533                 G.scene->r.yasp= 1;
1534                 G.scene->r.size= 50;
1535                 G.scene->r.mode &= ~R_PANORAMA;
1536                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1537
1538                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1539                 allqueue(REDRAWVIEWCAM, 0);
1540                 allqueue(REDRAWBUTSSCENE, 0);
1541                 break;
1542         case B_PR_PAL169:
1543                 G.scene->r.xsch= 720;
1544                 G.scene->r.ysch= 576;
1545                 G.scene->r.xasp= 64;
1546                 G.scene->r.yasp= 45;
1547                 G.scene->r.size= 100;
1548                 G.scene->r.frs_sec= 25;
1549                 G.scene->r.frs_sec_base= 1;
1550                 G.scene->r.mode &= ~R_PANORAMA;
1551                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1552 #ifdef WITH_FFMPEG
1553                 G.scene->r.ffcodecdata.gop_size = 15;
1554 #endif          
1555
1556                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1557                 BIF_undo_push("Set PAL 16/9");
1558                 allqueue(REDRAWVIEWCAM, 0);
1559                 allqueue(REDRAWBUTSSCENE, 0);
1560                 break;
1561         case B_PR_PC:
1562                 G.scene->r.xsch= 640;
1563                 G.scene->r.ysch= 480;
1564                 G.scene->r.xasp= 100;
1565                 G.scene->r.yasp= 100;
1566                 G.scene->r.size= 100;
1567                 G.scene->r.mode &= ~R_PANORAMA;
1568                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1569
1570                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
1571                 BIF_undo_push("Set PC");
1572                 allqueue(REDRAWVIEWCAM, 0);
1573                 allqueue(REDRAWBUTSSCENE, 0);
1574                 break;
1575         case B_PR_PRESET:
1576                 G.scene->r.xsch= 720;
1577                 G.scene->r.ysch= 576;
1578                 G.scene->r.xasp= 54;
1579                 G.scene->r.yasp= 51;
1580                 G.scene->r.size= 100;
1581                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS+R_SSS;
1582                 G.scene->r.imtype= R_TARGA;
1583                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1584
1585                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1586                 BIF_undo_push("Set Default");
1587                 allqueue(REDRAWVIEWCAM, 0);
1588                 allqueue(REDRAWBUTSSCENE, 0);
1589                 break;
1590         case B_PR_PANO:
1591                 G.scene->r.xsch= 576;
1592                 G.scene->r.ysch= 176;
1593                 G.scene->r.xasp= 115;
1594                 G.scene->r.yasp= 100;
1595                 G.scene->r.size= 100;
1596                 G.scene->r.mode |= R_PANORAMA;
1597                 G.scene->r.xparts=  16;
1598                 G.scene->r.yparts= 1;
1599
1600                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1601                 BIF_undo_push("Set Panorama");
1602                 allqueue(REDRAWVIEWCAM, 0);
1603                 allqueue(REDRAWBUTSSCENE, 0);
1604                 break;
1605         case B_PR_NTSC:
1606                 G.scene->r.xsch= 720;
1607                 G.scene->r.ysch= 480;
1608                 G.scene->r.xasp= 10;
1609                 G.scene->r.yasp= 11;
1610                 G.scene->r.size= 100;
1611                 G.scene->r.frs_sec= 30;
1612                 G.scene->r.frs_sec_base = 1.001;
1613                 G.scene->r.mode &= ~R_PANORAMA;
1614                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1615 #ifdef WITH_FFMPEG
1616                 G.scene->r.ffcodecdata.gop_size = 18;
1617 #endif          
1618                 
1619                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1620                 BIF_undo_push("Set NTSC");
1621                 allqueue(REDRAWBUTSSCENE, 0);
1622                 allqueue(REDRAWVIEWCAM, 0);
1623                 break;
1624
1625         case B_SETBROWSE:
1626                 id= (ID*) G.scene->set;
1627                 
1628                 if (G.buts->menunr==-2) {
1629                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
1630                 } 
1631                 else if (G.buts->menunr>0) {
1632                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
1633                         
1634                         if (newset==G.scene)
1635                                 error("Can't use the same scene as its own set");
1636                         else if (newset) {
1637                                 G.scene->set= newset;
1638                                 if (scene_check_setscene(G.scene)==0)
1639                                         error("This would create a cycle");
1640
1641                                 allqueue(REDRAWBUTSSCENE, 0);
1642                                 allqueue(REDRAWVIEW3D, 0);
1643                                 BIF_undo_push("Change Set Scene");
1644                         }
1645                 }  
1646                 break;
1647         case B_CLEARSET:
1648                 G.scene->set= NULL;
1649                 allqueue(REDRAWBUTSSCENE, 0);
1650                 allqueue(REDRAWVIEW3D, 0);
1651                 BIF_undo_push("Clear Set Scene");
1652                 
1653                 break;
1654         case B_SET_EDGE:
1655                 allqueue(REDRAWBUTSSCENE, 0);
1656                 break;
1657         case B_SET_ZBLUR:
1658                 G.scene->r.mode &= ~R_EDGE;
1659                 allqueue(REDRAWBUTSSCENE, 0);
1660                 break;
1661         case B_ADD_RENDERLAYER:
1662                 if(G.scene->r.actlay==32767) {
1663                         scene_add_render_layer(G.scene);
1664                         G.scene->r.actlay= BLI_countlist(&G.scene->r.layers) - 1;
1665                 }
1666                 allqueue(REDRAWBUTSSCENE, 0);
1667                 allqueue(REDRAWNODE, 0);
1668                 break;
1669         case B_SET_PASS:
1670                 if(G.scene->nodetree) {
1671                         ntreeCompositForceHidden(G.scene->nodetree);
1672                         allqueue(REDRAWNODE, 0);
1673                 }
1674                 allqueue(REDRAWBUTSSCENE, 0);
1675                 allqueue(REDRAWOOPS, 0);
1676         }
1677 }
1678
1679 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1680 static uiBlock *edge_render_menu(void *arg_unused)
1681 {
1682         uiBlock *block;
1683         
1684         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
1685                 
1686         /* use this for a fake extra empy space around the buttons */
1687         uiDefBut(block, LABEL, 0, "",  0, 0, 220, 115, NULL,  0, 0, 0, 0, "");
1688         
1689         uiDefButS(block, NUM, 0,"Eint:",        45,75,175,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
1690                   "Sets edge intensity for Toon shading");
1691
1692         /* color settings for the toon shading */
1693         uiDefButF(block, COL, 0, "",            10, 10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, B_EDGECOLSLI, "");
1694         
1695         uiBlockBeginAlign(block);
1696         uiDefButF(block, NUMSLI, 0, "R ",   45, 50, 175,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
1697                   "Color for edges in toon shading mode.");
1698         uiDefButF(block, NUMSLI, 0, "G ",       45, 30, 175,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
1699                   "Color for edges in toon shading mode.");
1700         uiDefButF(block, NUMSLI, 0, "B ",       45, 10, 175,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
1701                   "Color for edges in toon shading mode.");
1702
1703         
1704         uiBlockSetDirection(block, UI_TOP);
1705         
1706         return block;
1707 }
1708
1709
1710 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1711 static uiBlock *framing_render_menu(void *arg_unused)
1712 {
1713         uiBlock *block;
1714         short yco = 190, xco = 0;
1715         int randomcolorindex = 1234;
1716
1717         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
1718
1719         /* use this for a fake extra empy space around the buttons */
1720         uiDefBut(block, LABEL, 0, "",                   -5, -10, 295, 224, NULL, 0, 0, 0, 0, "");
1721
1722         uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
1723         uiBlockBeginAlign(block);
1724         uiDefButC(block, ROW, 0, "Stretch",     xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_SCALE , 0, 0, "Stretch or squeeze the viewport to fill the display window");
1725         uiDefButC(block, ROW, 0, "Expose",      xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_EXTEND, 0, 0, "Show the entire viewport in the display window, viewing more horizontally or vertically");
1726         uiDefButC(block, ROW, 0, "Letterbox",       xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_BARS  , 0, 0, "Show the entire viewport in the display window, using bar horizontally or vertically");
1727         uiBlockEndAlign(block);
1728
1729         yco -= 25;
1730         xco = 40;
1731
1732         uiDefButF(block, COL, 0, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, "");
1733
1734         uiBlockBeginAlign(block);
1735         uiDefButF(block, NUMSLI, 0, "R ", xco,yco,243,18, &G.scene->framing.col[0], 0.0, 1.0, randomcolorindex, 0, "Set the red component of the bars");
1736         yco -= 20;
1737         uiDefButF(block, NUMSLI, 0, "G ", xco,yco,243,18, &G.scene->framing.col[1], 0.0, 1.0, randomcolorindex, 0, "Set the green component of the bars");
1738         yco -= 20;
1739         uiDefButF(block, NUMSLI, 0, "B ", xco,yco,243,18, &G.scene->framing.col[2], 0.0, 1.0, randomcolorindex, 0, "Set the blue component of the bars");
1740         uiBlockEndAlign(block);
1741         
1742         xco = 0;
1743         uiDefBut(block, LABEL, 0, "Fullscreen:",                xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, "");
1744         uiDefButS(block, TOG, 0, "Fullscreen", xco+70, yco, 68, 19, &G.scene->r.fullscreen, 0.0, 0.0, 0, 0, "Starts player in a new fullscreen display");
1745         uiBlockBeginAlign(block);
1746         uiDefButS(block, NUM, 0, "X:",          xco+40, yco-=27, 100, 19, &G.scene->r.xplay, 10.0, 2000.0, 0, 0, "Displays current X screen/window resolution. Click to change.");
1747         uiDefButS(block, NUM, 0, "Y:",          xco+140, yco, 100, 19, &G.scene->r.yplay,    10.0, 2000.0, 0, 0, "Displays current Y screen/window resolution. Click to change.");
1748         uiDefButS(block, NUM, 0, "Freq:",       xco+40, yco-=21, 100, 19, &G.scene->r.freqplay, 10.0, 2000.0, 0, 0, "Displays clock frequency of fullscreen display. Click to change.");
1749         uiDefButS(block, NUM, 0, "Bits:",       xco+140, yco, 100, 19, &G.scene->r.depth, 8.0, 32.0, 800.0, 0, "Displays bit depth of full screen display. Click to change.");
1750         uiBlockEndAlign(block);
1751
1752         /* stereo settings */
1753         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
1754          * RAS_IRasterizer has definitions:
1755          * RAS_STEREO_NOSTEREO           1
1756          * RAS_STEREO_QUADBUFFERED 2
1757          * RAS_STEREO_ABOVEBELOW         3
1758          * RAS_STEREO_INTERLACED         4       future
1759          * RAS_STEREO_ANAGLYPH          5
1760          * RAS_STEREO_SIDEBYSIDE        6
1761          * RAS_STEREO_VINTERLACE        7
1762          */
1763         uiBlockBeginAlign(block);
1764         uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo");
1765         uiDefButS(block, ROW, 0, "Pageflip", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 2.0, 0, 0, "Enables hardware pageflip stereo method");
1766         uiDefButS(block, ROW, 0, "Syncdouble", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
1767         uiDefButS(block, ROW, 0, "Anaglyph", xco-=180, yco-=21, 88, 19, &(G.scene->r.stereomode), 7.0, 5.0, 0, 0, "Enables anaglyph (Red-Blue) stereo method");
1768         uiDefButS(block, ROW, 0, "Side by Side", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 6.0, 0, 0, "Enables side by side left and right images");
1769         uiDefButS(block, ROW, 0, "V Interlace", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 7.0, 0, 0, "Enables interlaced vertical strips for autostereo display");
1770         
1771         uiBlockEndAlign(block);
1772
1773         uiBlockSetDirection(block, UI_TOP);
1774
1775         return block;
1776 }
1777
1778 #ifdef WITH_FFMPEG
1779
1780 static char* ffmpeg_format_pup(void) 
1781 {
1782         static char string[2048];
1783         char formatstring[2048];
1784 #if 0
1785        int i = 0;
1786        int stroffs = 0;
1787        AVOutputFormat* next = first_oformat;
1788        formatstring = "FFMpeg format: %%t";
1789       sprintf(string, formatstring);
1790        formatstring = "|%s %%x%d";
1791        /* FIXME: This should only be generated once */
1792        while (next != NULL) {
1793                if (next->video_codec != CODEC_ID_NONE && !(next->flags & AVFMT_NOFILE)) {
1794                        sprintf(string+stroffs, formatstring, next->name, i++);
1795                        stroffs += strlen(string+stroffs);
1796                }
1797                next = next->next;
1798        }
1799        return string;
1800 #endif
1801        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1802        sprintf(string, formatstring,
1803                "MPEG-1", FFMPEG_MPEG1,
1804                "MPEG-2", FFMPEG_MPEG2,
1805                "MPEG-4", FFMPEG_MPEG4,
1806                "AVI",    FFMPEG_AVI,
1807                "Quicktime", FFMPEG_MOV,
1808                "DV", FFMPEG_DV,
1809                "H264", FFMPEG_H264,
1810                "XVid", FFMPEG_XVID);
1811        return string;
1812 }
1813
1814 static char* ffmpeg_preset_pup(void) 
1815 {
1816         static char string[2048];
1817         char formatstring[2048];
1818
1819        strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1820        sprintf(string, formatstring,
1821                "", FFMPEG_PRESET_NONE,
1822                "DVD", FFMPEG_PRESET_DVD,
1823                "SVCD", FFMPEG_PRESET_SVCD,
1824                "VCD", FFMPEG_PRESET_VCD,
1825                "DV", FFMPEG_PRESET_DV);
1826        return string;
1827 }
1828
1829
1830 static char* ffmpeg_codec_pup(void) {
1831        static char string[2048];
1832        char formatstring[2048];
1833        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1834        sprintf(string, formatstring,
1835                "MPEG1", CODEC_ID_MPEG1VIDEO,
1836                "MPEG2", CODEC_ID_MPEG2VIDEO,
1837                "MPEG4(divx)", CODEC_ID_MPEG4,
1838                "HuffYUV", CODEC_ID_HUFFYUV,
1839                "DV", CODEC_ID_DVVIDEO,
1840                "H264", CODEC_ID_H264,
1841                "XVid", CODEC_ID_XVID);
1842        return string;
1843
1844 }
1845
1846 static char* ffmpeg_audio_codec_pup(void) {
1847        static char string[2048];
1848        char formatstring[2048];
1849        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1850        sprintf(string, formatstring,
1851                "MP2", CODEC_ID_MP2,
1852                "MP3", CODEC_ID_MP3,
1853                "AC3", CODEC_ID_AC3,
1854                "AAC", CODEC_ID_AAC,
1855                "PCM", CODEC_ID_PCM_S16LE);
1856        return string;
1857
1858 }
1859
1860 #endif
1861
1862 static char *imagetype_pup(void)
1863 {
1864         static char string[1024];
1865         char formatstring[1024];
1866         char appendstring[1024];
1867
1868         strcpy(formatstring, "Save image as: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1869
1870 #ifdef __sgi
1871         strcat(formatstring, "|%s %%x%d");      // add space for Movie
1872 #endif
1873
1874         strcat(formatstring, "|%s %%x%d");      // add space for PNG
1875 /*  Commented out until implemented
1876 #ifdef WITH_DDS
1877         strcat(formatstring, "|%s %%x%d");      // add space for DDS
1878 #endif
1879 */
1880         strcat(formatstring, "|%s %%x%d");      // add space for BMP
1881         strcat(formatstring, "|%s %%x%d");      // add space for Radiance HDR
1882         strcat(formatstring, "|%s %%x%d");      // add space for Cineon
1883         strcat(formatstring, "|%s %%x%d");      // add space for DPX
1884         
1885 #ifdef _WIN32
1886         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
1887 #endif
1888
1889 #ifdef WITH_FFMPEG
1890        strcat(formatstring, "|%s %%x%d"); // Add space for ffmpeg
1891 #endif
1892        strcat(formatstring, "|%s %%x%d"); // Add space for frameserver
1893
1894 #ifdef WITH_QUICKTIME
1895         if(G.have_quicktime)
1896                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
1897 #endif
1898
1899         if(G.have_quicktime) {
1900                 sprintf(string, formatstring,
1901                         "Frameserver",   R_FRAMESERVER,
1902 #ifdef WITH_FFMPEG
1903                        "FFMpeg",         R_FFMPEG,
1904 #endif
1905                         "AVI Raw",        R_AVIRAW,
1906                         "AVI Jpeg",       R_AVIJPEG,
1907 #ifdef _WIN32
1908                         "AVI Codec",      R_AVICODEC,
1909 #endif
1910 #ifdef WITH_QUICKTIME
1911                         "QuickTime",      R_QUICKTIME,
1912 #endif
1913                         "Targa",          R_TARGA,
1914                         "Targa Raw",      R_RAWTGA,
1915                         "PNG",            R_PNG,
1916 /* commented out until implemented 
1917 #ifdef WITH_DDS
1918                         "DDS",            R_DDS,
1919 #endif
1920 */
1921                         "BMP",            R_BMP,
1922                         "Jpeg",           R_JPEG90,
1923                         "HamX",           R_HAMX,
1924                         "Iris",           R_IRIS,
1925                         "Radiance HDR",   R_RADHDR,
1926                         "Cineon",                 R_CINEON,
1927                         "DPX",                    R_DPX
1928 #ifdef __sgi
1929                         ,"Movie",          R_MOVIE
1930 #endif
1931                 );
1932         } else {
1933                 sprintf(string, formatstring,
1934                         "Frameserver",   R_FRAMESERVER,
1935 #ifdef WITH_FFMPEG
1936                        "FFMpeg",         R_FFMPEG,
1937 #endif
1938                         "AVI Raw",        R_AVIRAW,
1939                         "AVI Jpeg",       R_AVIJPEG,
1940 #ifdef _WIN32
1941                         "AVI Codec",      R_AVICODEC,
1942 #endif
1943                         "Targa",          R_TARGA,
1944                         "Targa Raw",      R_RAWTGA,
1945                         "PNG",            R_PNG,
1946 /*#ifdef WITH_DDS
1947                         "DDS",            R_DDS,
1948 #endif*/
1949                         "BMP",            R_BMP,
1950                         "Jpeg",           R_JPEG90,
1951                         "HamX",           R_HAMX,
1952                         "Iris",           R_IRIS,
1953                         "Radiance HDR",   R_RADHDR,
1954                         "Cineon",                 R_CINEON,
1955                         "DPX",                    R_DPX
1956 #ifdef __sgi
1957                         ,"Movie",          R_MOVIE
1958 #endif
1959                 );
1960         }
1961
1962 #ifdef WITH_OPENEXR
1963         strcpy(formatstring, "|%s %%x%d");
1964         sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
1965         strcat(string, appendstring);
1966         sprintf(appendstring, formatstring, "MultiLayer", R_MULTILAYER);
1967         strcat(string, appendstring);
1968 #endif
1969         
1970         if (G.have_libtiff) {
1971                 strcpy(formatstring, "|%s %%x%d");
1972                 sprintf(appendstring, formatstring, "TIFF", R_TIFF);
1973                 strcat(string, appendstring);
1974         }
1975
1976         return (string);
1977 }
1978
1979 #ifdef _WIN32
1980 static char *avicodec_str(void)
1981 {
1982         static char string[1024];
1983
1984         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
1985
1986         return string;
1987 }
1988 #endif
1989
1990 static void render_panel_output(void)
1991 {
1992         ID *id;
1993         int a,b;
1994         uiBlock *block;
1995         char *strp;
1996
1997         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
1998         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
1999         
2000         uiBlockBeginAlign(block);
2001         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        10, 190, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for saving animations");
2002         uiDefBut(block, TEX,0,"",                                                       31, 190, 279, 20,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save animations, # characters defines the position and length of frame numbers");
2003         uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for a Backbuf image");
2004         uiDefBut(block, TEX,0,"",                                                       31, 168, 279, 20,G.scene->r.backbuf, 0.0,79.0, 0, 0, "Image to use as background for rendering");
2005         uiBlockEndAlign(block);
2006         
2007         uiBlockBeginAlign(block);
2008         uiDefButBitI(block, TOG, R_TOUCH, B_NOP, "Touch",       10, 142, 50, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Create an empty file before rendering each frame, remove if cancelled (and empty)");
2009         uiDefButBitI(block, TOG, R_NO_OVERWRITE, B_NOP, "No Overwrite", 60, 142, 90, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Skip rendering frames when the file exists (image output only)");
2010         uiBlockEndAlign(block);
2011         uiDefButBitS(block, TOG, R_BACKBUF, B_NOP,"Backbuf",    160, 142, 80, 20, &G.scene->r.bufflag, 0, 0, 0, 0, "Enable/Disable use of Backbuf image");      
2012         
2013         /* SET BUTTON */
2014         uiBlockBeginAlign(block);
2015         id= (ID *)G.scene->set;
2016         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
2017         if(strp[0])
2018                 uiDefButS(block, MENU, B_SETBROWSE, strp,                       10, 114, 20, 20, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
2019         MEM_freeN(strp);
2020
2021         if(G.scene->set) {
2022                 uiSetButLock(1, NULL);
2023                 uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, B_NOP, "",    31, 114, 100, 20, &(G.scene->set), "Name of the Set");
2024                 uiClearButLock();
2025                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            132, 114, 20, 20, 0, 0, 0, 0, 0, "Remove Set link");
2026         }
2027         uiBlockEndAlign(block);
2028
2029         uiBlockBeginAlign(block);
2030         uiDefIconButBitI(block, TOGN, R_FIXED_THREADS, B_REDR, ICON_AUTO,       10, 63, 20, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Automatically set the threads to the number of processors on the system");
2031         if ((G.scene->r.mode & R_FIXED_THREADS)==0) {
2032                 char thread_str[16];
2033                 sprintf(thread_str, " Threads: %d", BLI_system_thread_count());
2034                 uiDefBut(block, LABEL, 0, thread_str, 30, 63,80,20, 0, 0, 0, 0, 0, "");
2035         } else {
2036                 uiDefButS(block, NUM, B_NOP, "Threads:", 30, 63, 80, 20, &G.scene->r.threads, 1, BLENDER_MAX_THREADS, 0, 0, "Amount of threads for render (takes advantage of multi-core and multi-processor computers)");
2037         }
2038         uiBlockEndAlign(block);
2039         
2040         uiBlockSetCol(block, TH_AUTO);
2041                 
2042         uiBlockBeginAlign(block);
2043         for(b=2; b>=0; b--)
2044                 for(a=0; a<3; a++)
2045                         uiDefButBitS(block, TOG, 1<<(3*b+a), 800,"",    (short)(10+18*a),(short)(10+14*b),16,12, &G.winpos, 0, 0, 0, 0, "Render window placement on screen");
2046
2047         uiBlockBeginAlign(block);
2048         uiDefButBitI(block, TOG, R_EXR_TILE_FILE, B_REDR, "Save Buffers", 72, 31, 120, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Save tiles for all RenderLayers and used SceneNodes to files in the temp directory (saves memory, allows Full Sampling)");
2049         if(G.scene->r.scemode & R_EXR_TILE_FILE)
2050                 uiDefButBitI(block, TOG, R_FULL_SAMPLE, B_REDR, "FullSample",    192, 31, 118, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Saves for every OSA sample the entire RenderLayer results (Higher quality sampling but slower)");
2051         uiBlockEndAlign(block);
2052         
2053         uiDefButS(block, MENU, B_REDR, "Render Display %t|Render Window %x1|Image Editor %x0|Full Screen %x2",  
2054                                         72, 10, 120, 19, &G.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output display");
2055
2056         uiDefButBitI(block, TOG, R_EXTENSION, B_NOP, "Extensions", 205, 10, 105, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Adds filetype extensions to the filename when rendering animations");
2057         
2058         /* Dither control */
2059         uiDefButF(block, NUM,B_DIFF, "Dither:",         10,89,100,19, &G.scene->r.dither_intensity, 0.0, 2.0, 0, 0, "The amount of dithering noise present in the output image (0.0 = no dithering)");
2060         
2061         /* Toon shading buttons */
2062         uiBlockBeginAlign(block);
2063         uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   115, 89, 60, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
2064         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 175, 89, 135, 20, "Display Edge settings");
2065         uiBlockEndAlign(block);
2066         
2067         uiBlockBeginAlign(block);
2068         uiDefButBitI(block, TOG, R_NO_TEX, B_NOP, "Disable Tex", 115, 63, 70, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Disables Textures for render");
2069         uiDefButBitI(block, TOG, R_FREE_IMAGE, B_NOP, "Free Tex Images", 205, 63, 100, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Frees all Images used by Textures after each render");
2070         uiBlockEndAlign(block);
2071 }
2072
2073 static void do_bake_func(void *unused_v, void *unused_p)
2074 {
2075         objects_bake_render_ui(0);
2076 }
2077
2078 static void render_panel_bake(void)
2079 {
2080         uiBlock *block;
2081         uiBut *but;
2082         
2083         block= uiNewBlock(&curarea->uiblocks, "render_panel_bake", UI_EMBOSS, UI_HELV, curarea->win);
2084         uiNewPanelTabbed("Anim", "Render");
2085         if(uiNewPanel(curarea, block, "Bake", "Render", 320, 0, 318, 204)==0) return;
2086         
2087         but= uiDefBut(block, BUT, B_NOP, "BAKE",        10, 150, 190,40, 0, 0, 0, 0, 0, "Start the bake render for selected Objects");
2088         uiButSetFunc(but, do_bake_func, NULL, NULL);
2089
2090         uiBlockBeginAlign(block);
2091         uiDefButBitS(block, TOG, R_BAKE_TO_ACTIVE, B_DIFF, "Selected to Active", 10,120,190,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Bake shading on the surface of selected objects to the active object");
2092         uiDefButF(block, NUM, B_DIFF, "Dist:", 10,100,95,20,&G.scene->r.bake_maxdist, 0.0, 1000.0, 1, 0, "Maximum distance from active object to other object (in blender units)");
2093         uiDefButF(block, NUM, B_DIFF, "Bias:", 105,100,95,20,&G.scene->r.bake_biasdist, 0.0, 1000.0, 1, 0, "Bias towards faces further away from the object (in blender units)");
2094         uiBlockEndAlign(block);
2095
2096         if(G.scene->r.bake_mode == RE_BAKE_NORMALS)
2097                 uiDefButS(block, MENU, B_DIFF, "Normal Space %t|Camera %x0|World %x1|Object %x2|Tangent %x3", 
2098                         10,70,190,20, &G.scene->r.bake_normal_space, 0, 0, 0, 0, "Choose normal space for baking");
2099         else if(G.scene->r.bake_mode == RE_BAKE_AO || G.scene->r.bake_mode == RE_BAKE_DISPLACEMENT) {
2100                 uiDefButBitS(block, TOG, R_BAKE_NORMALIZE, B_DIFF, "Normalized", 10,70,190,20, &G.scene->r.bake_flag, 0.0, 0, 0, 0,
2101                                 G.scene->r.bake_mode == RE_BAKE_AO ?
2102                                  "Bake ambient occlusion normalized, without taking into acount material settings":
2103                                  "Normalized displacement value to fit the 'Dist' range"
2104                 );
2105         }
2106 #if 0   
2107         uiBlockBeginAlign(block);
2108         uiDefButBitS(block, TOG, R_BAKE_OSA, B_DIFF, "OSA",             10,120,190,20, &G.scene->r.bake_flag, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
2109         uiDefButS(block, ROW,B_DIFF,"5",                        10,100,50,20,&G.scene->r.bake_osa,2.0,5.0, 0, 0, "Sets oversample level to 5");
2110         uiDefButS(block, ROW,B_DIFF,"8",                        60,100,45,20,&G.scene->r.bake_osa,2.0,8.0, 0, 0, "Sets oversample level to 8");
2111         uiDefButS(block, ROW,B_DIFF,"11",                       105,100,45,20,&G.scene->r.bake_osa,2.0,11.0, 0, 0, "Sets oversample level to 11");
2112         uiDefButS(block, ROW,B_DIFF,"16",                       150,100,50,20,&G.scene->r.bake_osa,2.0,16.0, 0, 0, "Sets oversample level to 16");
2113 #endif  
2114         uiBlockBeginAlign(block);
2115         uiDefButS(block, ROW,B_REDR,"Full Render",              210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, "");
2116         uiDefButS(block, ROW,B_REDR,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, "");
2117         uiDefButS(block, ROW,B_REDR,"Normals",          210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, "");
2118         uiDefButS(block, ROW,B_REDR,"Textures",         210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, "");
2119         uiDefButS(block, ROW,B_REDR,"Displacement",             210,90,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_DISPLACEMENT, 0, 0, "");
2120         uiBlockEndAlign(block);
2121         
2122         uiDefButBitS(block, TOG, R_BAKE_CLEAR, B_DIFF, "Clear",         210,60,120,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Clear Images before baking");
2123         
2124         uiDefButS(block, NUM, B_DIFF,"Margin:",                         210,30,120,20,&G.scene->r.bake_filter, 0.0, 32.0, 0, 0, "Amount of pixels to extend the baked result with, as post process filter");
2125 }
2126
2127 static void render_panel_simplify(void)
2128 {
2129         uiBlock *block;
2130         
2131         block= uiNewBlock(&curarea->uiblocks, "render_panel_simplify", UI_EMBOSS, UI_HELV, curarea->win);
2132         uiNewPanelTabbed("Render", "Render");
2133         if(uiNewPanel(curarea, block, "Simplifcation", "Render", 320, 0, 318, 204)==0) return;
2134
2135         uiDefButBitI(block, TOG, R_SIMPLIFY, B_DIFF,"Render Simplification",    10,150,190,20, &G.scene->r.mode, 0, 0, 0, 0, "Enable simplification of scene");
2136
2137         uiBlockBeginAlign(block);
2138         uiDefButI(block, NUM,B_DIFF, "Subsurf:",        10,120,190,20, &G.scene->r.simplify_subsurf, 0.0, 6.0, 0, 0, "Global maximum subsurf level percentage");
2139         uiDefButF(block, NUM,B_DIFF, "Child Particles:",        10,100,190,20, &G.scene->r.simplify_particles, 0.0, 1.0, 0, 0, "Global child particle percentage");
2140         uiBlockEndAlign(block);
2141
2142         uiBlockBeginAlign(block);
2143         uiDefButI(block, NUM,B_DIFF, "Shadow Samples:", 10,70,190,20, &G.scene->r.simplify_shadowsamples, 1.0, 16.0, 0, 0, "Global maximum shadow map samples");
2144         uiDefButF(block, NUM,B_DIFF, "AO and SSS:",     10,50,190,20, &G.scene->r.simplify_aosss, 0.0, 1.0, 0, 0, "Global approximate AO and SSS quality factor");
2145         uiBlockEndAlign(block);
2146 }
2147
2148 static void render_panel_render(void)
2149 {
2150         uiBlock *block;
2151         char str[256];
2152
2153         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
2154         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
2155
2156         uiBlockBeginAlign(block);
2157         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369, 164, 191,37, 0, 0, 0, 0, 0, "Render the current frame (F12)");
2158 #ifndef DISABLE_YAFRAY
2159         /* yafray: on request, render engine menu is back again, and moved to Render panel */
2160         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0|YafRay %x1", 
2161                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
2162 #else
2163         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0", 
2164                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
2165 #endif /* disable yafray */
2166
2167         uiBlockBeginAlign(block);
2168         if((G.scene->r.scemode & R_FULL_SAMPLE) && (G.scene->r.scemode & R_EXR_TILE_FILE))
2169                 uiDefButBitI(block, TOG, R_OSA, B_DIFF, "FSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Saves all samples, then composites, and then merges (for best Anti-aliasing)");
2170         else
2171                 uiDefButBitI(block, TOG, R_OSA, B_DIFF, "OSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
2172         uiDefButS(block, ROW,B_DIFF,"5",                        369,88,29,20,&G.scene->r.osa,2.0,5.0, 0, 0, "Render 5 samples per pixel for smooth edges (Fast)");
2173         uiDefButS(block, ROW,B_DIFF,"8",                        400,88,29,20,&G.scene->r.osa,2.0,8.0, 0, 0, "Render 8 samples per pixel for smooth edges (Recommended)");
2174         uiDefButS(block, ROW,B_DIFF,"11",                       431,88,29,20,&G.scene->r.osa,2.0,11.0, 0, 0, "Render 11 samples per pixel for smooth edges (High Quality)");
2175         uiDefButS(block, ROW,B_DIFF,"16",                       462,88,29,20,&G.scene->r.osa,2.0,16.0, 0, 0, "Render 16 samples per pixel for smooth edges (Highest Quality)");
2176         uiBlockEndAlign(block);
2177
2178         uiBlockBeginAlign(block);
2179         uiDefButBitI(block, TOG, R_MBLUR, B_REDR, "MBLUR",      496,109,64,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
2180         uiDefButF(block, NUM,B_DIFF,"Bf:",                      496,88,64,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
2181         uiBlockEndAlign(block);
2182
2183         uiBlockBeginAlign(block);
2184         uiDefButS(block, NUM,B_DIFF,"Xparts:",          369,46,95,29,&G.scene->r.xparts,1.0, 512.0, 0, 0, "Sets the number of horizontal parts to render image in (For panorama sets number of camera slices)");
2185         uiDefButS(block, NUM,B_DIFF,"Yparts:",          465,46,95,29,&G.scene->r.yparts,1.0, 64.0, 0, 0, "Sets the number of vertical parts to render image in");
2186         uiBlockEndAlign(block);
2187
2188         uiBlockBeginAlign(block);
2189         uiDefButS(block, ROW,800,"Sky",         369,13,35,20,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
2190         uiDefButS(block, ROW,800,"Premul",      405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
2191         uiDefButS(block, ROW,800,"Key",         456,13,35,20,&G.scene->r.alphamode,3.0,2.0, 0, 0, "Alpha and color values remain unchanged");
2192         uiBlockEndAlign(block);
2193
2194         uiDefButS(block, MENU, B_DIFF,"Octree resolution %t|64 %x64|128 %x128|256 %x256|512 %x512",     496,13,64,20,&G.scene->r.ocres,0.0,0.0, 0, 0, "Octree resolution for ray tracing and baking, Use higher values for complex scenes");
2195
2196         uiBlockBeginAlign(block);
2197         uiDefButBitI(block, TOG, R_SHADOW, B_REDR,"Shadow",     565,172,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
2198         uiDefButBitI(block, TOG, R_SSS, B_REDR,"SSS",   617,172,32,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable subsurface scattering map rendering");
2199         uiDefButBitI(block, TOG, R_PANORAMA, B_REDR,"Pano",     649,172,38,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable panorama rendering (output width is multiplied by Xparts)");
2200         uiDefButBitI(block, TOG, R_ENVMAP, B_REDR,"EnvMap",     565,142,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map rendering");
2201         uiDefButBitI(block, TOG, R_RAYTRACE, B_REDR,"Ray",617,142,32,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
2202         uiDefButBitI(block, TOG, R_RADIO, B_REDR,"Radio",       649,142,38,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
2203         uiBlockEndAlign(block);
2204         
2205         uiBlockBeginAlign(block);
2206         uiDefButS(block, ROW,B_DIFF,"100%",                     565,109,122,20,&G.scene->r.size,1.0,100.0, 0, 0, "Set render size to defined size");
2207         uiDefButS(block, ROW,B_DIFF,"75%",                      565,88,40,20,&G.scene->r.size,1.0,75.0, 0, 0, "Set render size to 3/4 of defined size");
2208         uiDefButS(block, ROW,B_DIFF,"50%",                      606,88,40,20,&G.scene->r.size,1.0,50.0, 0, 0, "Set render size to 1/2 of defined size");
2209         uiDefButS(block, ROW,B_DIFF,"25%",                      647,88,40,20,&G.scene->r.size,1.0,25.0, 0, 0, "Set render size to 1/4 of defined size");
2210         uiBlockEndAlign(block);
2211
2212         uiBlockBeginAlign(block);
2213         uiDefButBitI(block, TOG, R_FIELDS, B_REDR,"Fields",  565,55,60,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
2214         uiDefButBitI(block, TOG, R_ODDFIELD, B_REDR,"Odd",      627,55,39,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Odd field first rendering (Default: Even field)");
2215         uiDefButBitI(block, TOG, R_FIELDSTILL, B_REDR,"X",              668,55,19,20,&G.scene->r.mode, 0, 0, 0, 0, "Disables time difference in field calculations");
2216         
2217         sprintf(str, "Filter%%t|Box %%x%d|Tent %%x%d|Quad %%x%d|Cubic %%x%d|Gauss %%x%d|CatRom %%x%d|Mitch %%x%d", R_FILTER_BOX, R_FILTER_TENT, R_FILTER_QUAD, R_FILTER_CUBIC, R_FILTER_GAUSS, R_FILTER_CATROM, R_FILTER_MITCH);
2218         uiDefButS(block, MENU, B_DIFF,str,              565,34,60,20, &G.scene->r.filtertype, 0, 0, 0, 0, "Set sampling filter for antialiasing");
2219         uiDefButF(block, NUM,B_DIFF,"",                 627,34,60,20,&G.scene->r.gauss,0.5, 1.5, 10, 2, "Sets the filter size");
2220         
2221         uiDefButBitI(block, TOG, R_BORDER, REDRAWVIEWCAM, "Border",     565,13,122,20, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image (Shift+B to set in the camera view)");
2222         uiBlockEndAlign(block);
2223
2224 }
2225
2226 static void render_panel_anim(void)
2227 {
2228         uiBlock *block;
2229
2230
2231         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2232         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
2233
2234
2235         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Render the animation to disk from start to end frame, (Ctrl+F12)");
2236
2237         uiBlockSetCol(block, TH_BUT_SETTING1);
2238         uiBlockBeginAlign(block);
2239         uiDefButBitI(block, TOG, R_DOSEQ, B_NOP, "Do Sequence",692,114,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Enables sequence output rendering (Default: 3D rendering)");
2240         uiDefButBitI(block, TOG, R_DOCOMP, B_NOP, "Do Composite",692,90,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Uses compositing nodes for output rendering");
2241         uiBlockEndAlign(block);
2242
2243         uiBlockSetCol(block, TH_AUTO);
2244         uiDefBut(block, BUT,B_PLAYANIM, "PLAY",692,40,94,33, 0, 0, 0, 0, 0, "Play rendered images/avi animation (Ctrl+F11), (Play Hotkeys: A-Noskip, P-PingPong)");
2245         uiDefButS(block, NUM, B_RTCHANGED, "rt:",789,40,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
2246
2247         uiBlockBeginAlign(block);
2248         uiDefButI(block, NUM,REDRAWSEQ,"Sta:",692,10,94,24, &G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "The start frame of the animation (inclusive)");
2249         uiDefButI(block, NUM,REDRAWSEQ,"End:",789,10,95,24, &G.scene->r.efra,SFRA,MAXFRAMEF, 0, 0, "The end  frame of the animation  (inclusive)");
2250         uiBlockEndAlign(block);
2251 }
2252
2253 #ifdef WITH_FFMPEG
2254 static void set_ffmpeg_preset(int preset)
2255 {
2256         int isntsc = (G.scene->r.frs_sec != 25);
2257         switch (preset) {
2258         case FFMPEG_PRESET_VCD:
2259                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG1;
2260                 G.scene->r.ffcodecdata.video_bitrate = 1150;
2261                 G.scene->r.xsch = 352;
2262                 G.scene->r.ysch = isntsc ? 240 : 288;
2263                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2264                 G.scene->r.ffcodecdata.rc_max_rate = 1150;
2265                 G.scene->r.ffcodecdata.rc_min_rate = 1150;
2266                 G.scene->r.ffcodecdata.rc_buffer_size = 40*8;
2267                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2268                 G.scene->r.ffcodecdata.mux_rate = 2352 * 75 * 8;
2269                 break;
2270         case FFMPEG_PRESET_SVCD:
2271                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2272                 G.scene->r.ffcodecdata.video_bitrate = 2040;
2273                 G.scene->r.xsch = 480;
2274                 G.scene->r.ysch = isntsc ? 480 : 576;
2275                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2276                 G.scene->r.ffcodecdata.rc_max_rate = 2516;
2277                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2278                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2279                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2280                 G.scene->r.ffcodecdata.mux_rate = 0;
2281                 
2282                 break;
2283         case FFMPEG_PRESET_DVD:
2284                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2285                 G.scene->r.ffcodecdata.video_bitrate = 6000;
2286                 G.scene->r.xsch = 720;
2287                 G.scene->r.ysch = isntsc ? 480 : 576;
2288                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2289                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
2290                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2291                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2292                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
2293                 G.scene->r.ffcodecdata.mux_rate = 10080000;
2294                 
2295                 break;
2296         case FFMPEG_PRESET_DV:
2297                 G.scene->r.ffcodecdata.type = FFMPEG_DV;
2298                 G.scene->r.xsch = 720;
2299                 G.scene->r.ysch = isntsc ? 480 : 576;
2300                 break;
2301         }
2302 }
2303
2304 static void render_panel_ffmpeg_video(void)
2305 {
2306         uiBlock *block;
2307         int yofs;
2308         int xcol1;
2309         int xcol2;
2310         
2311         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_video", 
2312                                            UI_EMBOSS, UI_HELV, curarea->win);
2313         
2314         uiNewPanelTabbed("Format", "Render");
2315         if (uiNewPanel(curarea, block, "Video", "Render", 960, 0, 318, 204)== 0) 
2316                 return;
2317         
2318         if (ffmpeg_preset_sel != 0) {
2319                 set_ffmpeg_preset(ffmpeg_preset_sel);
2320                 ffmpeg_preset_sel = 0;
2321                 allqueue(REDRAWBUTSSCENE, 0);
2322         }
2323         
2324         xcol1 = 872;
2325         xcol2 = 1002;
2326         
2327         yofs = 54;
2328         uiDefBut(block, LABEL, B_DIFF, "Format", xcol1, yofs+88, 
2329                          110, 20, 0, 0, 0, 0, 0, "");
2330         uiDefBut(block, LABEL, B_DIFF, "Preset", xcol2, yofs+88, 
2331                          110, 20, 0, 0, 0, 0, 0, "");
2332         uiDefButI(block, MENU, B_DIFF, ffmpeg_format_pup(), 
2333                           xcol1, yofs+66, 110, 20, &G.scene->r.ffcodecdata.type, 
2334                           0,0,0,0, "output file format");
2335         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
2336                           xcol1, yofs+44, 110, 20, 
2337                           &G.scene->r.ffcodecdata.video_bitrate, 
2338                           1, 14000, 0, 0, "Video bitrate(kb/s)");
2339         uiDefButI(block, NUM, B_DIFF, "Min Rate", 
2340                           xcol1, yofs+22, 110, 20, &G.scene->r.ffcodecdata.rc_min_rate, 
2341                           0, 14000, 0, 0, "Rate control: min rate(kb/s)");
2342         uiDefButI(block, NUM, B_DIFF, "Max Rate", 
2343                           xcol1, yofs, 110, 20, &G.scene->r.ffcodecdata.rc_max_rate, 
2344                           1, 14000, 0, 0, "Rate control: max rate(kb/s)");
2345         
2346         uiDefButI(block, NUM, B_DIFF, "Mux Rate", 
2347                           xcol1, yofs-22, 110, 20, 
2348                           &G.scene->r.ffcodecdata.mux_rate, 
2349                           0, 100000000, 0, 0, "Mux rate (bits/s(!))");
2350         
2351         
2352         uiDefButI(block, MENU, B_REDR, ffmpeg_preset_pup(), 
2353                           xcol2, yofs+66, 110, 20, &ffmpeg_preset_sel, 
2354                           0,0,0,0, "Output file format preset selection");
2355         uiDefButI(block, NUM, B_DIFF, "GOP Size", 
2356                           xcol2, yofs+44, 110, 20, &G.scene->r.ffcodecdata.gop_size, 
2357                           0, 100, 0, 0, "Distance between key frames");
2358         uiDefButI(block, NUM, B_DIFF, "Buffersize", 
2359                           xcol2, yofs+22, 110, 20,
2360                           &G.scene->r.ffcodecdata.rc_buffer_size, 
2361                           0, 2000, 0, 0, "Rate control: buffer size (kb)");
2362         uiDefButI(block, NUM, B_DIFF, "Mux PSize", 
2363                           xcol2, yofs, 110, 20, 
2364                           &G.scene->r.ffcodecdata.mux_packet_size, 
2365                           0, 16384, 0, 0, "Mux packet size (byte)");
2366         
2367         uiDefButBitI(block, TOG, FFMPEG_AUTOSPLIT_OUTPUT, B_NOP,
2368                                  "Autosplit Output", 
2369                                  xcol2, yofs-22, 110, 20, 
2370                                  &G.scene->r.ffcodecdata.flags, 
2371                                  0, 1, 0,0, "Autosplit output at 2GB boundary.");
2372         
2373         
2374         if (ELEM(G.scene->r.ffcodecdata.type, FFMPEG_AVI, FFMPEG_MOV)) {
2375                 uiDefBut(block, LABEL, 0, "Codec", 
2376                                 xcol1, yofs-44, 110, 20, 0, 0, 0, 0, 0, "");
2377                 uiDefButI(block, MENU,B_REDR, ffmpeg_codec_pup(), 
2378                                   xcol1, yofs-66, 110, 20, 
2379                                   &G.scene->r.ffcodecdata.codec, 
2380                                   0,0,0,0, "FFMpeg codec to use");
2381         }
2382 }
2383
2384 static void render_panel_ffmpeg_audio(void)
2385 {
2386         uiBlock *block;
2387         int yofs;
2388         int xcol;
2389         
2390         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_audio", UI_EMBOSS, UI_HELV, curarea->win);
2391         uiNewPanelTabbed("Format", "Render");
2392         if (uiNewPanel(curarea, block, "Audio", "Render", 960, 0, 318, 204) == 0) return;
2393         
2394         yofs = 54;
2395         xcol = 892;
2396         
2397         uiDefButBitI(block, TOG, FFMPEG_MULTIPLEX_AUDIO, B_NOP,
2398                                  "Multiplex audio", xcol, yofs, 225, 20, 
2399                                  &G.scene->r.ffcodecdata.flags, 
2400                                  0, 1, 0,0, "Interleave audio with the output video");
2401         uiDefBut(block, LABEL, 0, "Codec", 
2402                          xcol, yofs-22, 225, 20, 0, 0, 0, 0, 0, "");
2403         uiDefButI(block, MENU,B_NOP, ffmpeg_audio_codec_pup(), 
2404                           xcol, yofs-44, 225, 20, 
2405                           &G.scene->r.ffcodecdata.audio_codec, 
2406                           0,0,0,0, "FFMpeg codec to use");
2407         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
2408                           xcol, yofs-66, 110, 20, 
2409                           &G.scene->r.ffcodecdata.audio_bitrate, 
2410                           32, 384, 0, 0, "Audio bitrate(kb/s)");
2411 }
2412 #endif
2413
2414 static void render_panel_stamp(void)
2415 {
2416         uiBlock *block;
2417         int yofs=0, xofs=550;
2418
2419         block= uiNewBlock (&curarea->uiblocks, "render_panel_stamp", UI_EMBOSS, UI_HELV, curarea->win);
2420         uiNewPanelTabbed ("Format", "Render");
2421         if(uiNewPanel (curarea, block, "Stamp", "Render", 960, 0, 318, 204)==0) return;
2422
2423         if (G.scene->r.scemode & R_STAMP_INFO) {
2424                 uiBlockBeginAlign(block);
2425                 uiDefButBitI(block, TOG, R_STAMP_NOTE, B_REDR, "Note", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp user data");
2426                 uiDefBut(block, TEX, B_NOP, "", xofs+120, yofs, 180, 19, &G.scene->r.stamp_udata, 0.0, 128.0, 100, 0, "User Note");
2427                 uiBlockEndAlign(block);
2428                 yofs += 30; /* gap */
2429                 
2430                 
2431                 yofs += 80;
2432                 /* Order is important for alligning ... grr */
2433                 uiBlockBeginAlign(block);
2434                 uiDefButBitI(block, TOG, R_STAMP_FILENAME, B_REDR, "Filename", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp blend filename");
2435                 yofs -= 20;
2436                 uiDefButBitI(block, TOG, R_STAMP_SCENE, B_REDR, "Scene", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp scene name");
2437                 uiDefButBitI(block, TOG, R_STAMP_CAMERA, B_REDR, "Camera", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp camera name");
2438                 yofs -= 20;
2439                 uiDefButBitI(block, TOG, R_STAMP_TIME, B_REDR, "Time", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp time (HH:MM:SS)");
2440                 uiDefButBitI(block, TOG, R_STAMP_DATE, B_REDR, "Date", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp date");
2441                 yofs -= 20;
2442                 uiDefButBitI(block, TOG, R_STAMP_FRAME, B_REDR, "Frame", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp frame number");
2443                 uiDefButBitI(block, TOG, R_STAMP_MARKER, B_REDR, "Marker", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the last marker");
2444                 yofs -= 20;
2445                 uiDefButBitI(block, TOG, R_STAMP_SEQSTRIP, B_REDR, "Sequence Strip", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the forground sequence strip name");
2446                 uiBlockEndAlign(block);
2447                 yofs += 80;
2448                 
2449                 /* draw font selector */
2450                 if (G.scene->r.stamp & R_STAMP_DRAW) {
2451                         uiDefButS(block, MENU, B_REDR, "Stamp Font Size%t|Tiny Text%x1|Small Text%x2|Medium Text%x3|Large Text%x0|Extra Large Text%x4|",
2452                                         xofs+130, yofs, 170, 19, &G.scene->r.stamp_font_id, 0, 0, 0, 0, "Choose stamp text size");
2453                         
2454                         /* draw fg/bg next to the scene */
2455                         yofs -= 25;
2456                         uiDefBut(block, LABEL, B_NOP, "Text Color", xofs+130, yofs, 70, 19, 0, 0, 0, 0, 0, "");
2457                         uiDefBut(block, LABEL, B_NOP, "Background", xofs+215, yofs, 70, 19, 0, 0, 0, 0, 0, "");
2458                         yofs -= 20;
2459                         uiDefButF(block, COL, B_NOP, "", xofs+130, yofs, 80, 19, G.scene->r.fg_stamp, 0, 0, 0, 0, "Foreground text color");
2460                         uiDefButF(block, COL, B_NOP, "", xofs+220, yofs, 80, 19, G.scene->r.bg_stamp, 0, 0, 0, 0, "Background color");
2461                         yofs -= 30;
2462                         uiDefButF(block, NUMSLI, B_NOP, "A ", xofs+130, yofs, 170, 19, &G.scene->r.bg_stamp[3], 0, 1.0, 0, 0, "Alpha for text background");
2463                         yofs += 105;
2464                 } else {
2465                         yofs += 30;
2466                 }
2467                 
2468                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, yofs, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Disable stamp info in images metadata");
2469                 uiDefButBitI(block, TOG, R_STAMP_DRAW, B_REDR, "Draw Stamp", xofs+130, yofs, 170, 20, &G.scene->r.stamp, 0, 0, 0, 0, "Draw the stamp info into each frame");
2470                 yofs += 20;
2471         }
2472         else {
2473                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, 142, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Enable stamp info to image metadata");
2474                 yofs += 20;
2475                 uiDefBut(block, LABEL, 0, "", xofs, yofs, 300, 19, 0, 0, 0, 0, 0, "");
2476         }
2477 }
2478
2479 static void render_panel_format(void)
2480 {
2481         uiBlock *block;
2482         int yofs;
2483
2484
2485         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
2486         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
2487         uiDefBlockBut(block, framing_render_menu, NULL, 
2488                                   "Game framing settings", 
2489                                   892, 169, 227, 20, "Display game framing settings");
2490         /* uiDefIconTextBlockBut(block, framing_render_menu, NULL, 
2491                                                    ICON_BLOCKBUT_CORNER, 
2492                                                    "Game framing settings", 
2493                                                    892, 169, 227, 20, 
2494                                                    "Display game framing settings"); */
2495
2496         uiBlockBeginAlign(block);
2497         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
2498         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
2499         
2500         uiDefButF(block, NUM, REDRAWVIEWCAM, "AspX:",
2501                                 892 ,114,112,20,
2502                                 &G.scene->r.xasp,
2503                                 1, 200, 100, 2,
2504                                 "Horizontal Aspect Ratio");
2505         uiDefButF(block, NUM, REDRAWVIEWCAM, "AspY:",
2506                                 1007,114,112,20,
2507                                 &G.scene->r.yasp,
2508                                 1, 200, 100, 2,
2509                                 "Vertical Aspect Ratio");
2510         
2511         uiBlockEndAlign(block);
2512
2513         yofs = 54;
2514
2515 #ifdef __sgi
2516         yofs = 76;
2517         uiDefButS(block, NUM,B_DIFF,"MaxSize:",                 892,32,165,20, &G.scene->r.maximsize, 0.0, 500.0, 0, 0, "Maximum size per frame to save in an SGI movie");
2518         uiDefButBitI(block, TOG, R_COSMO, 0,"Cosmo",    1059,32,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Attempt to save SGI movies using Cosmo hardware");
2519 #endif
2520
2521         uiDefButS(block, MENU,B_FILETYPEMENU,imagetype_pup(),   892,yofs,174,20, &G.scene->r.imtype, 0, 0, 0, 0, "Images are saved in this file format");
2522         uiDefButBitI(block, TOG, R_CROP, B_DIFF, "Crop",        1068,yofs,51,20, &G.scene->r.mode, 0, 0, 0, 0, "When Border render, the resulting image gets cropped");
2523
2524         yofs -= 22;
2525
2526         if(G.scene->r.quality==0) G.scene->r.quality= 90;
2527
2528         if (G.scene->r.imtype == R_AVICODEC || G.scene->r.imtype == R_QUICKTIME) {
2529                 if(G.scene->r.imtype == R_QUICKTIME) {
2530 #ifdef WITH_QUICKTIME
2531 #if defined (_WIN32) || defined (__APPLE__)
2532                         //glColor3f(0.65, 0.65, 0.7);
2533                         //glRecti(892,yofs+46,892+225,yofs+45+20);
2534                         if(G.scene->r.qtcodecdata == NULL)
2535                                 uiDefBut(block, LABEL, 0, "Codec: not set",  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
2536                         else
2537                                 uiDefBut(block, LABEL, 0, G.scene->r.qtcodecdata->qtcodecname,  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
2538                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,74,20, 0, 0, 0, 0, 0, "Set codec settings for Quicktime");
2539 #endif
2540 #endif /* WITH_QUICKTIME */
2541                 } else {
2542 #ifdef _WIN32
2543                         //glColor3f(0.65, 0.65, 0.7);
2544                         //glRecti(892,yofs+46,892+225,yofs+45+20);
2545                         if(G.scene->r.avicodecdata == NULL)
2546                                 uiDefBut(block, LABEL, 0, "Codec: not set.",  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
2547                         else
2548                                 uiDefBut(block, LABEL, 0, avicodec_str(),  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
2549 #endif
2550                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,74,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
2551                 }
2552 #ifdef WITH_OPENEXR
2553         } 
2554         else if (ELEM(G.scene->r.imtype, R_OPENEXR, R_MULTILAYER)) {
2555                 if (G.scene->r.quality > 5) G.scene->r.quality = 2;
2556                 
2557                 if(G.scene->r.imtype==R_OPENEXR) {
2558                         uiBlockBeginAlign(block);
2559                         uiDefButBitS(block, TOG, R_OPENEXR_HALF, B_NOP,"Half",  892,yofs+44,60,20, &G.scene->r.subimtype, 0, 0, 0, 0, "Use 16 bit floats instead of 32 bit floats per channel");
2560                         uiDefButBitS(block, TOG, R_OPENEXR_ZBUF, B_NOP,"Zbuf",  952,yofs+44,60,20, &G.scene->r.subimtype, 0, 0, 0, 0, "Save the z-depth per pixel (32 bit unsigned int zbuffer)");
2561                         uiBlockEndAlign(block);
2562                         uiDefButBitS(block, TOG, R_PREVIEW_JPG, B_NOP,"Preview",1027,yofs+44,90,20, &G.scene->r.subimtype, 0, 0, 0, 0, "When animation render, save JPG preview images in same directory");
2563                 }               
2564                 uiDefButS(block, MENU,B_NOP, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",  
2565                                                                                                                         892,yofs,74,20, &G.scene->r.quality, 0, 0, 0, 0, "Set codec settings for OpenEXR");
2566                 
2567 #endif
2568         } else if (G.scene->r.imtype == R_DPX || G.scene->r.imtype == R_CINEON) {
2569                 uiDefButBitS(block, TOG, R_CINEON_LOG, B_REDR, "Log",           892,yofs,74,20, &G.scene->r.subimtype, 0, 0, 0, 0, "Convert to log color space");
2570
2571                 if(G.scene->r.subimtype & R_CINEON_LOG) {
2572                         uiBlockBeginAlign(block);
2573                         uiDefButS(block, NUM, B_NOP, "B",       892,yofs+44,80,20, &G.scene->r.cineonblack, 0, 1024, 0, 0, "Log conversion reference black");
2574                         uiDefButS(block, NUM, B_NOP, "W",       972,yofs+44,80,20, &G.scene->r.cineonwhite, 0, 1024, 0, 0, "Log conversion reference white");
2575                         uiDefButF(block, NUM, B_NOP, "G",       1052,yofs+44,70,20, &G.scene->r.cineongamma, 0.0f, 10.0f, 1, 2, "Log conversion gamma");
2576                         uiBlockEndAlign(block);
2577                 }
2578         } else if (G.scene->r.imtype == R_TIFF) {
2579                 uiDefButBitS(block, TOG, R_TIFF_16BIT, B_REDR, "16 Bit",           892,yofs,74,20, &G.scene->r.subimtype, 0, 0, 0, 0, "Save 16 bit per channel TIFF");
2580         } else {
2581                 if(G.scene->r.quality < 5) G.scene->r.quality = 90;     /* restore from openexr */
2582                 
2583                 uiDefButS(block, NUM,B_DIFF, "Q:",           892,yofs,74,20, &G.scene->r.quality, 10.0, 100.0, 0, 0, "Quality setting for JPEG images, AVI Jpeg and SGI movies");
2584         }
2585         uiDefButS(block, NUM,B_FRAMEMAP,"FPS:",   968,yofs,75,20, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second");
2586         uiDefButF(block, NUM,B_FRAMEMAP,"/",  1043,yofs,75,20, &G.scene->r.frs_sec_base, 1.0, 120.0, 0.1, 3, "Frames per second base");
2587
2588
2589         uiBlockBeginAlign(block);
2590         uiDefButS(block, ROW,B_DIFF,"BW",                       892, 10,74,19, &G.scene->r.planes, 5.0,(float)R_PLANESBW, 0, 0, "Images are saved with BW (grayscale) data");
2591         uiDefButS(block, ROW,B_DIFF,"RGB",                  968, 10,74,19, &G.scene->r.planes, 5.0,(float)R_PLANES24, 0, 0, "Images are saved with RGB (color) data");
2592         uiDefButS(block, ROW,B_DIFF,"RGBA",                1044, 10,75,19, &G.scene->r.planes, 5.0,(float)R_PLANES32, 0, 0, "Images are saved with RGB and Alpha data (if supported)");
2593
2594         uiBlockBeginAlign(block);
2595         uiDefBut(block, BUT,B_PR_PAL, "PAL",            1146,170,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 720x576, Aspect ratio - 54x51, 25 fps");
2596         uiDefBut(block, BUT,B_PR_NTSC, "NTSC",          1146,150,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 720x480, Aspect ratio - 10x11, 30 fps");
2597         uiDefBut(block, BUT,B_PR_PRESET, "Default",     1146,130,100,18, 0, 0, 0, 0, 0, "Same as PAL, with render settings (OSA, Shadows, Fields)");
2598         uiDefBut(block, BUT,B_PR_PRV, "Preview",        1146,110,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x512, Render size 50%");
2599         uiDefBut(block, BUT,B_PR_PC, "PC",                      1146,90,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x480, Aspect ratio - 100x100");
2600         uiDefBut(block, BUT,B_PR_PAL169, "PAL 16:9",1146,70,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 720x576, Aspect ratio - 64x45");
2601         uiDefBut(block, BUT,B_PR_PANO, "PANO",          1146,50,100,18, 0, 0, 0, 0, 0, "Standard panorama settings");
2602         uiDefBut(block, BUT,B_PR_FULL, "FULL",          1146,30,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1280x1024, Aspect ratio - 1x1");
2603         uiDefBut(block, BUT,B_PR_HD, "HD",              1146,10,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1920x1080, Aspect ratio - 1x1");
2604         uiBlockEndAlign(block);
2605 }
2606
2607 #ifndef DISABLE_YAFRAY /* disable yafray stuff */
2608 /* yafray: global illumination options panel */
2609 static void render_panel_yafrayGI()
2610 {
2611         uiBlock *block;
2612
2613         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGI", UI_EMBOSS, UI_HELV, curarea->win);
2614         uiNewPanelTabbed("Render", "Render");
2615         if(uiNewPanel(curarea, block, "YafRay GI", "Render", 320, 0, 318, 204)==0) return;
2616
2617         // label to force a boundbox for buttons not to be centered
2618         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
2619
2620         uiDefBut(block, LABEL, 0, "Method", 5,175,70,20, 0, 1.0, 0, 0, 0, "");
2621         uiDefButS(block, MENU, B_REDR, "GiMethod %t|None %x0|SkyDome %x1|Full %x2", 70,175,89,20, &G.scene->r.GImethod, 0, 0, 0, 0, "Global Illumination Method");
2622
2623         uiDefBut(block, LABEL, 0, "Quality", 5,150,70,20, 0, 1.0, 0, 0, 0, "");
2624         uiDefButS(block, MENU, B_REDR, "GiQuality %t|None %x0|Low %x1|Medium %x2 |High %x3|Higher %x4|Best %x5|Use Blender AO settings %x6", 70,150,89,20, &G.scene->r.GIquality, 0, 0, 0, 0, "Global Illumination Quality");
2625
2626         if (G.scene->r.GImethod>0) {
2627                 uiDefButF(block, NUM, B_DIFF, "EmitPwr:", 5,35,154,20, &G.scene->r.GIpower, 0.01, 100.0, 10, 0, "arealight, material emit and background intensity scaling, 1 is normal");
2628                 if (G.scene->r.GImethod==2) uiDefButF(block, NUM, B_DIFF, "GI Pwr:", 5,10,154,20, &G.scene->r.GIindirpower, 0.01, 100.0, 10, 0, "GI indirect lighting intensity scaling, 1 is normal");
2629         }
2630
2631         if (G.scene->r.GImethod>0)
2632         {
2633                 if (G.scene->r.GIdepth==0) G.scene->r.GIdepth=2;
2634
2635                 if (G.scene->r.GImethod==2) {
2636                         uiDefButI(block, NUM, B_DIFF, "Depth:", 180,175,110,20, &G.scene->r.GIdepth, 1.0, 100.0, 10, 10, "Number of bounces of the indirect light");
2637                         uiDefButI(block, NUM, B_DIFF, "CDepth:", 180,150,110,20, &G.scene->r.GIcausdepth, 1.0, 100.0, 10, 10, "Number of bounces inside objects (for caustics)");
2638                         uiDefButBitS(block, TOG, 1,  B_REDR, "Photons",210,125,100,20, &G.scene->r.GIphotons, 0, 0, 0, 0, "Use global photons to help in GI");
2639                 }
2640
2641                 uiDefButBitS(block, TOG, 1, B_REDR, "Cache",6,125,95,20, &G.scene->r.GIcache, 0, 0, 0, 0, "Cache occlusion/irradiance samples (faster)");
2642                 if (G.scene->r.GIcache) 
2643                 {
2644                         uiDefButBitS(block,TOG, 1, B_REDR, "NoBump",108,125,95,20, &G.scene->r.YF_nobump, 0, 0, 0, 0, "Don't use bumpnormals for cache (faster, but no bumpmapping in total indirectly lit areas)");
2645                         uiDefBut(block, LABEL, 0, "Cache parameters:", 5,105,130,20, 0, 1.0, 0, 0, 0, "");
2646                         if (G.scene->r.GIshadowquality==0.0) G.scene->r.GIshadowquality=0.9;
2647                         uiDefButF(block, NUM, B_DIFF,"ShadQu:", 5,85,154,20,    &(G.scene->r.GIshadowquality), 0.01, 1.0 ,1,0, "Sets the shadow quality, keep it under 0.95 :-) ");
2648                         if (G.scene->r.GIpixelspersample==0) G.scene->r.GIpixelspersample=10;
2649                         uiDefButI(block, NUM, B_DIFF, "Prec:",  5,60,75,20, &G.scene->r.GIpixelspersample, 1, 50, 10, 10, "Maximum number of pixels without samples, the lower the better and slower");
2650                         if (G.scene->r.GIrefinement==0) G.scene->r.GIrefinement=1.0;
2651                         uiDefButF(block, NUM, B_DIFF, "Ref:", 84,60,75,20, &G.scene->r.GIrefinement, 0.001, 1.0, 1, 0, "Threshold to refine shadows EXPERIMENTAL. 1 = no refinement");
2652                 }
2653
2654                 if (G.scene->r.GImethod==2) {
2655                         if (G.scene->r.GIphotons)
2656                         {
2657                                 uiDefBut(block, LABEL, 0, "Photon parameters:", 170,105,130,20, 0, 1.0, 0, 0, 0, "");
2658                                 if(G.scene->r.GIphotoncount==0) G.scene->r.GIphotoncount=100000;
2659                                 uiDefButI(block, NUM, B_DIFF, "Count:", 170,85,140,20, &G.scene->r.GIphotoncount, 
2660                                                 0, 10000000, 10, 10, "Number of photons to shoot");
2661                                 if(G.scene->r.GIphotonradius==0.0) G.scene->r.GIphotonradius=1.0;
2662                                 uiDefButF(block, NUMSLI, B_DIFF,"Radius:", 170,60,140,20,       &(G.scene->r.GIphotonradius), 
2663                                                 0.00001, 100.0 ,0,0, "Radius to search for photons to mix (blur)");
2664                                 if(G.scene->r.GImixphotons==0) G.scene->r.GImixphotons=100;
2665                                 uiDefButI(block, NUM, B_DIFF, "MixCount:", 170,35,140,20, &G.scene->r.GImixphotons, 
2666                                                 0, 1000, 10, 10, "Number of photons to mix");
2667                                 uiDefButBitS(block, TOG, 1, B_REDR, "Tune Photons",170,10,140,20, &G.scene->r.GIdirect, 
2668                                                 0, 0, 0, 0, "Show the photonmap directly in the render for tuning");
2669                         }
2670                 }
2671
2672         }
2673 }
2674
2675 /* yafray: global  options panel */
2676 static void render_panel_yafrayGlobal()
2677 {
2678         uiBlock *block;
2679
2680         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGlobal", UI_EMBOSS, UI_HELV, curarea->win);
2681         uiNewPanelTabbed("Render", "Render");
2682         if(uiNewPanel(curarea, block, "YafRay", "Render", 320, 0, 318, 204)==0) return;
2683
2684         // label to force a boundbox for buttons not to be centered
2685         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
2686
2687         uiDefButBitS(block, TOGN, 1, B_REDR, "xml", 5,180,75,20, &G.scene->r.YFexportxml,
2688                                         0, 0, 0, 0, "Export to an xml file and call yafray instead of plugin");
2689
2690         uiDefButF(block, NUMSLI, B_DIFF,"Bi ", 5,35,150,20,     &(G.scene->r.YF_raybias), 
2691                                 0.0, 10.0 ,0,0, "Shadow ray bias to avoid self shadowing");
2692         uiDefButI(block, NUM, B_DIFF, "Raydepth ", 5,60,150,20,
2693                                 &G.scene->r.YF_raydepth, 1.0, 80.0, 10, 10, "Maximum render ray depth from the camera");
2694         uiDefButF(block, NUMSLI, B_DIFF, "Gam ", 5,10,150,20, &G.scene->r.YF_gamma, 0.001, 5.0, 0, 0, "Gamma correction, 1 is off");
2695         uiDefButF(block, NUMSLI, B_DIFF, "Exp ", 160,10,150,20,&G.scene->r.YF_exposure, 0.0, 10.0, 0, 0, "Exposure adjustment, 0 is off");
2696         
2697         /*AA Settings*/
2698         uiDefButBitS(block, TOGN, 1, B_REDR, "Auto AA", 5,140,150,20, &G.scene->r.YF_AA, 
2699                                         0, 0, 0, 0, "Set AA using OSA and GI quality, disable for manual control");
2700         uiDefButBitS(block, TOGN, 1, B_DIFF, "Clamp RGB", 160,140,150,20, &G.scene->r.YF_clamprgb, 1.0, 8.0, 10, 10, "For AA on fast high contrast changes. Not advisable for Bokeh! Dulls lens shape detail.");
2701         if(G.scene->r.YF_AA){
2702                 uiDefButI(block, NUM, B_DIFF, "AA Passes ", 5,115,150,20, &G.scene->r.YF_AApasses, 0, 64, 10, 10, "Number of AA passes (0 is no AA)");
2703                 uiDefButI(block, NUM, B_DIFF, "AA Samples ", 160,115,150,20, &G.scene->r.YF_AAsamples, 0, 2048, 10, 10, "Number of samples per pass");
2704                 uiDefButF(block, NUMSLI, B_DIFF, "Psz ", 5,90,150,20, &G.scene->r.YF_AApixelsize, 1.0, 2.0, 0, 0, "AA pixel filter size");
2705                 uiDefButF(block, NUMSLI, B_DIFF, "Thr ", 160,90,150,20, &G.scene->r.YF_AAthreshold, 0.000001, 1.0, 0, 0, "AA threshold");
2706         }
2707 }
2708 #endif /* disable yafray stuff */
2709
2710 static void layer_copy_func(void *lay_v, void *lay_p)
2711 {
2712         unsigned int *lay= lay_p;
2713         int laybit= (int)lay_v;
2714
2715         if(G.qual & (LR_SHIFTKEY|LR_CTRLKEY)) {
2716                 if(*lay==0) *lay= 1<<laybit;
2717         }
2718         else
2719                 *lay= 1<<laybit;
2720         
2721         copy_view3d_lock(REDRAW);
2722         allqueue(REDRAWBUTSSCENE, 0);
2723 }
2724
2725 static void delete_scene_layer_func(void *srl_v, void *act_i)
2726 {
2727         if(BLI_countlist(&G.scene->r.layers)>1) {
2728                 long act= (long)act_i;
2729                 
2730                 BLI_remlink(&G.scene->r.layers, srl_v);
2731                 MEM_freeN(srl_v);
2732                 G.scene->r.actlay= 0;
2733                 
2734                 if(G.scene->nodetree) {
2735                         bNode *node;
2736                         for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
2737                                 if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
2738                                         if(node->custom1==act)
2739                                                 node->custom1= 0;
2740                                         else if(node->custom1>act)
2741                                                 node->custom1--;
2742                                 }
2743                         }
2744                 }
2745                 allqueue(REDRAWBUTSSCENE, 0);
2746                 allqueue(REDRAWNODE, 0);
2747         }
2748 }
2749
2750 static void rename_scene_layer_func(void *srl_v, void *unused_v)
2751 {
2752         if(G.scene->nodetree) {
2753                 SceneRenderLayer *srl= srl_v;
2754                 bNode *node;
2755                 for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
2756                         if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
2757                                 if(node->custom1==G.scene->r.actlay)
2758                                         BLI_strncpy(node->name, srl->name, NODE_MAXSTR);
2759                         }
2760                 }
2761         }
2762         allqueue(REDRAWBUTSSCENE, 0);
2763         allqueue(REDRAWOOPS, 0);
2764         allqueue(REDRAWNODE, 0);
2765 }
2766
2767 static char *scene_layer_menu(void)
2768 {
2769         SceneRenderLayer *srl;
2770         int len= 32 + 32*BLI_countlist(&G.scene->r.layers);
2771         short a, nr;
2772         char *str= MEM_callocN(len, "menu layers");
2773         
2774         strcpy(str, "ADD NEW %x32767");
2775         a= strlen(str);
2776         for(nr=0, srl= G.scene->r.layers.first; srl; srl= srl->next, nr++) {
2777                 if(srl->layflag & SCE_LAY_DISABLE)
2778                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_BLANK1, nr);
2779                 else 
2780                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_CHECKBOX_HLT, nr);
2781         }
2782         
2783         return str;
2784 }
2785
2786 static void draw_3d_layer_buttons(uiBlock *block, int type, unsigned int *poin, short xco, short yco, short dx, short dy, char *tip)
2787 {
2788         uiBut *bt;
2789         long a;
2790         
2791         uiBlockBeginAlign(block);
2792         for(a=0; a<5; a++) {
2793                 bt= uiDefButBitI(block, type, 1<<a, B_NOP, "",  (short)(xco+a*(dx/2)), yco+dy/2, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, tip);
2794                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
2795         }
2796         for(a=0; a<5; a++) {
2797                 bt=uiDefButBitI(block, type, 1<<(a+10), B_NOP, "",      (short)(xco+a*(dx/2)), yco, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, tip);
2798                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
2799         }
2800         
2801         xco+= 7;
2802         uiBlockBeginAlign(block);
2803         for(a=5; a<10; a++) {
2804                 bt=uiDefButBitI(block, type, 1<<a, B_NOP, "",   (short)(xco+a*(dx/2)), yco+dy/2, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, tip);
2805                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
2806         }
2807         for(a=5; a<10; a++) {
2808                 bt=uiDefButBitI(block, type, 1<<(a+10), B_NOP, "",      (short)(xco+a*(dx/2)), yco, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, tip);
2809                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
2810         }
2811         
2812         uiBlockEndAlign(block);
2813 }
2814
2815 static void render_panel_layers(void)
2816 {
2817         uiBlock *block;
2818         uiBut *bt;
2819         SceneRenderLayer *srl= BLI_findlink(&G.scene->r.layers, G.scene->r.actlay);
2820         char *strp;
2821         
2822         if(srl==NULL) {
2823                 G.scene->r.actlay= 0;
2824                 srl= G.scene->r.layers.first;
2825         }
2826         
2827         block= uiNewBlock(&curarea->uiblocks, "render_panel_layers", UI_EMBOSS, UI_HELV, curarea->win);
2828         uiNewPanelTabbed("Output", "Render");
2829         if(uiNewPanel(curarea, block, "Render Layers", "Render", 320, 0, 318, 204)==0) return;
2830         
2831         /* first, as reminder, the scene layers */
2832         uiDefBut(block, LABEL, 0, "Scene:",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
2833         draw_3d_layer_buttons(block, TOG, &G.scene->lay,                130, 170, 35, 30, "Scene layers to render");
2834         
2835         /* layer disable, menu, name, delete button */
2836         uiBlockBeginAlign(block);
2837         uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, B_REDR, ICON_CHECKBOX_HLT-1, 10, 145, 20, 20, &srl->layflag, 0.0, 0.0, 0, 0, "Disable or enable this RenderLayer");
2838         strp= scene_layer_menu();
2839         uiDefButS(block, MENU, B_ADD_RENDERLAYER, strp, 30,145,23,20, &(G.scene->r.actlay), 0, 0, 0, 0, "Choose Active Render Layer");
2840         MEM_freeN(strp);
2841         
2842         /* name max 20, exr format limit... */
2843         bt= uiDefBut(block, TEX, REDRAWNODE, "",  53,145,172,20, srl->name, 0.0, 20.0, 0, 0, "");
2844         uiButSetFunc(bt, rename_scene_layer_func, srl, NULL);
2845         
2846         uiDefButBitI(block, TOG, R_SINGLE_LAYER, B_NOP, "Single",       230,145,60,20, &G.scene->r.scemode, 0, 0, 0, 0, "Only render this layer");      
2847         bt=uiDefIconBut(block, BUT, B_NOP, ICON_X,      285, 145, 25, 20, 0, 0, 0, 0, 0, "Deletes current Render Layer");
2848         uiButSetFunc(bt, delete_scene_layer_func, srl, (void *)(long)G.scene->r.actlay);
2849         uiBlockEndAlign(block);
2850
2851         /* RenderLayer visible-layers */
2852         uiDefBut(block, LABEL, 0, "Layer:",                     10,110,100,20, NULL, 0, 0, 0, 0, "");
2853         draw_3d_layer_buttons(block, BUT_TOGDUAL, &srl->lay,            130,110, 35, 30, "Scene-layers included in this render-layer (Hold CTRL for Z-mask)");
2854         
2855         uiBlockBeginAlign(block);
2856         uiDefButBitI(block, TOG, SCE_LAY_ZMASK, B_REDR,"Zmask", 10, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Only render what's in front of the solid z values");        
2857         if(srl->layflag & SCE_LAY_ZMASK)
2858                 uiDefButBitI(block, TOG, SCE_LAY_NEG_ZMASK, B_NOP,"Neg",        10, 65, 40, 20, &srl->layflag, 0, 0, 0, 0, "For Zmask, only render what is behind solid z values instead of in front");
2859         else
2860                 uiDefButBitI(block, TOG, SCE_LAY_ALL_Z, B_NOP,"AllZ",   10, 65, 40, 20, &srl->layflag, 0, 0, 0, 0, "Fill in Z values for solid faces in invisible layers, for masking");        
2861         uiBlockBeginAlign(block);
2862         uiDefButBitI(block, TOG, SCE_LAY_SOLID, B_NOP,"Solid",  50,  85, 45, 20, &srl->layflag, 0, 0, 0, 0, "Render Solid faces in this Layer");        
2863         uiDefButBitI(block, TOG, SCE_LAY_HALO, B_NOP,"Halo",    95,  85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Halos in this Layer (on top of Solid)");    
2864         uiDefButBitI(block, TOG, SCE_LAY_ZTRA, B_NOP,"Ztra",    135, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Z-Transparent faces in this Layer (On top of Solid and Halos)");    
2865         uiDefButBitI(block, TOG, SCE_LAY_SKY, B_NOP,"Sky",              175, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Sky or backbuffer in this Layer");  
2866         uiDefButBitI(block, TOG, SCE_LAY_EDGE, B_NOP,"Edge",    215, 85, 45, 20, &srl->layflag, 0, 0, 0, 0, "Render Edge-enhance in this Layer (only works for Solid faces)");  
2867         uiDefButBitI(block, TOG, SCE_LAY_STRAND, B_NOP,"Strand",260, 85, 50, 20, &srl->layflag, 0, 0, 0, 0, "Render Strands in this Layer");    
2868         
2869         uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_SET_PASS, "Light:",  50, 65, 130, 20, &(srl->light_override), "Name of Group to use as Lamps instead");
2870         uiDefIDPoinBut(block, test_matpoin_but, ID_MA, B_SET_PASS, "Mat:",      180, 65, 130, 20, &(srl->mat_override), "Name of Material to use as Materials instead");
2871         uiBlockEndAlign(block);
2872
2873         uiBlockBeginAlign(block);
2874         uiDefButBitI(block, TOG, SCE_PASS_COMBINED, B_SET_PASS,"Combined",      10, 30, 80, 20, &srl->passflag, 0, 0, 0, 0, "Deliver full combined RGBA buffer");       
2875         uiDefButBitI(block, TOG, SCE_PASS_Z, B_SET_PASS,"Z",                    90, 30, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Z values pass");   
2876         uiDefButBitI(block, TOG, SCE_PASS_VECTOR, B_SET_PASS,"Vec",             120, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Speed Vector pass");      
2877         uiDefButBitI(block, TOG, SCE_PASS_NORMAL, B_SET_PASS,"Nor",             160, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Normal pass");    
2878         uiDefButBitI(block, TOG, SCE_PASS_UV, B_SET_PASS,"UV",                  200, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Texture UV pass");        
2879         uiDefButBitI(block, TOG, SCE_PASS_MIST, B_SET_PASS,"Mist",              240, 30, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Mist factor pass (0-1)"); 
2880         uiDefButBitI(block, TOG, SCE_PASS_INDEXOB, B_SET_PASS,"Index",  275, 30, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Object Index pass");      
2881         
2882         uiDefButBitI(block, TOG, SCE_PASS_RGBA, B_SET_PASS,"Col",                               10, 10, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver shade-less Color pass");   
2883         uiDefButBitI(block, TOG, SCE_PASS_DIFFUSE, B_SET_PASS,"Diff",                   45, 10, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Diffuse pass");    
2884         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SPEC, B_SET_PASS,"Spec",              80, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Specular pass (Hold Ctrl to exclude from combined)");      
2885         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SHADOW, B_SET_PASS,"Shad",    120, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Shadow pass (Hold Ctrl to exclude from combined)");       
2886         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_AO, B_SET_PASS,"AO",                  160, 10, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver AO pass (Hold Ctrl to exclude from combined)");
2887         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_REFLECT, B_SET_PASS,"Refl",   190, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Raytraced Reflection pass (Hold Ctrl to exclude from combined)"); 
2888         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_REFRACT, B_SET_PASS,"Refr",   230, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Raytraced Refraction pass (Hold Ctrl to exclude from combined)"); 
2889         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_RADIO, B_SET_PASS,"Rad",              270, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Radiosity pass (Hold Ctrl to exclude from combined)");    
2890 }       
2891
2892 void render_panels()
2893 {
2894
2895         render_panel_output();
2896         render_panel_layers();
2897         render_panel_render();
2898         if(G.rt == 1) render_panel_simplify();
2899         render_panel_anim();
2900         render_panel_bake();
2901
2902         render_panel_format();
2903         render_panel_stamp();
2904 #ifdef WITH_FFMPEG
2905        if (G.scene->r.imtype == R_FFMPEG) {
2906                    render_panel_ffmpeg_video();
2907                render_panel_ffmpeg_audio();
2908        }
2909 #endif
2910
2911 #ifndef DISABLE_YAFRAY
2912         /* yafray: GI & Global panel, only available when yafray enabled for rendering */
2913         if (G.scene->r.renderer==R_YAFRAY) {
2914                 if (G.scene->r.YF_gamma==0.0) G.scene->r.YF_gamma=1.0;
2915                 if (G.scene->r.YF_raybias==0.0) G.scene->r.YF_raybias=0.001;
2916                 if (G.scene->r.YF_raydepth==0) G.scene->r.YF_raydepth=5;
2917                 if (G.scene->r.YF_AApixelsize==0.0) G.scene->r.YF_AApixelsize=1.5;
2918                 if (G.scene->r.YF_AAthreshold==0.0) G.scene->r.YF_AAthreshold=0.05;
2919                 if (G.scene->r.GIpower==0.0) G.scene->r.GIpower=1.0;
2920                 if (G.scene->r.GIindirpower==0.0) G.scene->r.GIindirpower=1.0;
2921                 render_panel_yafrayGlobal();
2922                 render_panel_yafrayGI();
2923         }
2924 #endif
2925
2926 }
2927
2928 /* --------------------------------------------- */
2929
2930 void anim_panels()
2931 {
2932         uiBlock *block;
2933
2934         block= uiNewBlock(&curarea->uiblocks, "anim_panel", UI_EMBOSS, UI_HELV, curarea->win);
2935         if(uiNewPanel(curarea, block, "Anim", "Anim", 0, 0, 318, 204)==0) return;
2936
2937         uiBlockBeginAlign(block);
2938         uiDefButI(block, NUM,B_FRAMEMAP,"Map Old:",     10,160,150,20,&G.scene->r.framapto,1.0,900.0, 0, 0, "Specify old mapping value in frames");
2939         uiDefButI(block, NUM,B_FRAMEMAP,"Map New:",     160,160,150,20,&G.scene->r.images,1.0,900.0, 0, 0, "Specify how many frames the Map Old will last");
2940
2941         uiBlockBeginAlign(block);
2942         uiDefButS(block, NUM,B_FRAMEMAP,"FPS:",  10,130,75,20, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second");
2943         uiDefButF(block, NUM,B_FRAMEMAP,"/",  85,130,75,20, &G.scene->r.frs_sec_base, 1.0, 120.0, 0.1, 3, "Frames per second base");
2944
2945         uiDefButBitS(block, TOG, AUDIO_SYNC, B_SOUND_CHANGED, "Sync",160,130,150,20, &G.scene->audio.flag, 0, 0, 0, 0, "Use sample clock for syncing animation to audio");
2946         
2947         uiBlockBeginAlign(block);
2948         uiDefButI(block, NUM,REDRAWALL,"Sta:",  10,100,150,20,&G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "Specify the start frame of the animation");
2949         uiDefButI(block, NUM,REDRAWALL,"End:",  160,100,150,20,&G.scene->r.efra,1.0,MAXFRAMEF, 0, 0, "Specify the end frame of the animation");
2950
2951         uiBlockBeginAlign(block);
2952         uiDefButS(block, NUM, REDRAWTIME, "Steps:",10, 70, 150, 20,&(G.scene->jumpframe), 1, 100, 1, 100, "Set spacing between frames changes with up and down arrow keys");
2953
2954
2955 }
2956
2957 /* --------------------------------------------- */
2958
2959 void sound_panels()
2960 {
2961         bSound *sound;
2962
2963         /* paranoia check */
2964         sound = G.buts->lockpoin;
2965         if(sound && GS(sound->id.name)!=ID_SO) {
2966                 sound= NULL;
2967                 G.buts->lockpoin= NULL;
2968         }
2969         
2970         sound_panel_sound(sound);
2971         sound_panel_listener();
2972         sound_panel_sequencer();
2973 }
2974
2975
2976