Patch by GSR #7628, I also added alpha for text background.
[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_userdef_types.h"
45 #include "DNA_packedFile_types.h"
46
47 #include "BKE_global.h"
48 #include "BKE_main.h"
49 #include "BKE_node.h"
50 #include "BKE_library.h"
51 #include "BKE_scene.h"
52 #include "BKE_sound.h"
53 #include "BKE_packedFile.h"
54 #include "BKE_utildefines.h"
55
56 #include "BLI_blenlib.h"
57
58 #include "BSE_filesel.h"
59
60 #include "BIF_gl.h"
61 #include "BIF_graphics.h"
62 #include "BIF_glutil.h"
63 #include "BIF_interface.h"
64 #include "BIF_imasel.h"
65 #include "BIF_keyval.h"
66 #include "BIF_mainqueue.h"
67 #include "BIF_mywindow.h"
68 #include "BIF_meshtools.h"
69 #include "BIF_resources.h"
70 #include "BIF_renderwin.h"
71 #include "BIF_screen.h"
72 #include "BIF_space.h"
73 #include "BIF_toolbox.h"
74
75 #include "BIF_butspace.h"
76
77 #include "mydevice.h"
78 #include "blendef.h"
79
80 /* -----includes for this file specific----- */
81
82 #include "DNA_image_types.h"
83
84 #include "BKE_writeavi.h"
85 #include "BKE_writeffmpeg.h"
86 #include "BKE_image.h"
87
88 #include "BLI_threads.h"
89
90 #include "BIF_editsound.h"
91 #include "BIF_writeimage.h"
92 #include "BIF_writeavicodec.h"
93
94 #include "BSE_seqaudio.h"
95 #include "BSE_headerbuttons.h"
96
97 #include "RE_pipeline.h"
98
99 #include "butspace.h" // own module
100
101 #ifdef WITH_QUICKTIME
102 #include "quicktime_export.h"
103 #endif
104
105 #ifdef WITH_FFMPEG
106
107 #include <ffmpeg/avcodec.h> /* for PIX_FMT_* and CODEC_ID_* */
108 #include <ffmpeg/avformat.h>
109
110 static int ffmpeg_preset_sel = 0;
111
112 extern int is_container(int);
113
114 extern void makeffmpegstring(char* string);
115
116 #endif
117
118 /* here the calls for scene buttons
119    - render
120    - world
121    - anim settings, audio
122 */
123
124 /* prototypes */
125 void playback_anim(void);
126
127 /* ************************ SOUND *************************** */
128 static void load_new_sample(char *str)  /* called from fileselect */
129 {
130         char name[FILE_MAX];
131         bSound *sound;
132         bSample *sample, *newsample;
133
134         sound = G.buts->lockpoin;
135
136         if (sound) {
137                 // save values
138                 sample = sound->sample;
139                 strcpy(name, sound->sample->name);
140
141                 strcpy(sound->name, str);
142                 sound_set_sample(sound, NULL);
143                 sound_initialize_sample(sound);
144
145                 if (sound->sample->type == SAMPLE_INVALID) {
146                         error("Not a valid sample: %s", str);
147
148                         newsample = sound->sample;
149
150                         // restore values
151                         strcpy(sound->name, name);
152                         sound_set_sample(sound, sample);
153
154                         // remove invalid sample
155
156                         sound_free_sample(newsample);
157                         BLI_remlink(samples, newsample);
158                         MEM_freeN(newsample);
159                 }
160         }
161
162         BIF_undo_push("Load new audio file");
163         allqueue(REDRAWBUTSSCENE, 0);
164
165 }
166
167
168 void do_soundbuts(unsigned short event)
169 {
170         char name[FILE_MAX];
171         bSound *sound;
172         bSample *sample;
173         bSound* tempsound;
174         ID *id;
175         
176         sound = G.buts->lockpoin;
177         
178         switch(event) {
179         case B_SOUND_REDRAW:
180                 allqueue(REDRAWBUTSSCENE, 0);
181                 break;
182
183         case B_SOUND_LOAD_SAMPLE:
184                 if (sound) strcpy(name, sound->name);
185                 else strcpy(name, U.sounddir);
186                         
187                 activate_fileselect(FILE_SPECIAL, "SELECT WAV FILE", name, load_new_sample);
188                 break;
189
190         case B_SOUND_PLAY_SAMPLE:
191                 if (sound) {
192                         if (sound->sample->type != SAMPLE_INVALID) {
193                                 sound_play_sound(sound);
194                                 allqueue(REDRAWBUTSSCENE, 0);
195                         }
196                 }
197                 break;
198
199         case B_SOUND_MENU_SAMPLE:
200                 if (G.buts->menunr > 0) {
201                         sample = BLI_findlink(samples, G.buts->menunr - 1);
202                         if (sample && sound) {
203                                 BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
204                                 sound_set_sample(sound, sample);
205                                 do_soundbuts(B_SOUND_REDRAW);
206                         }
207                 }
208                         
209                 break;
210         case B_SOUND_NAME_SAMPLE:
211                 load_new_sample(sound->name);
212                 break;
213         
214         case B_SOUND_UNPACK_SAMPLE:
215                 if(sound && sound->sample) {
216                         sample = sound->sample;
217                         
218                         if (sample->packedfile) {
219                                 if (G.fileflags & G_AUTOPACK) {
220                                         if (okee("Disable AutoPack ?")) {
221                                                 G.fileflags &= ~G_AUTOPACK;
222                                         }
223                                 }
224                                 
225                                 if ((G.fileflags & G_AUTOPACK) == 0) {
226                                         unpackSample(sample, PF_ASK);
227                                 }
228                         } else {
229                                 sound_set_packedfile(sample, newPackedFile(sample->name));
230                         }
231                         allqueue(REDRAWHEADERS, 0);
232                         do_soundbuts(B_SOUND_REDRAW);
233                 }
234                 break;
235
236         case B_SOUND_COPY_SOUND:
237                 if (sound) {
238                         tempsound = sound_make_copy(sound);
239                         sound = tempsound;
240                         id = &sound->id;
241                         G.buts->lockpoin = (bSound*)id;
242                         BIF_undo_push("Copy sound");
243                         do_soundbuts(B_SOUND_REDRAW);
244                 }
245                 break;
246
247         case B_SOUND_RECALC:
248                 waitcursor(1);
249                 sound = G.main->sound.first;
250                 while (sound) {
251                         free(sound->stream);
252                         sound->stream = 0;
253                         audio_makestream(sound);
254                         sound = (bSound *) sound->id.next;
255                 }
256                 waitcursor(0);
257                 allqueue(REDRAWSEQ, 0);
258                 break;
259
260         case B_SOUND_RATECHANGED:
261
262                 allqueue(REDRAWBUTSSCENE, 0);
263                 allqueue(REDRAWSEQ, 0);
264                 break;
265
266         case B_SOUND_MIXDOWN:
267                 audio_mixdown();
268                 break;
269
270         default: 
271                 if (G.f & G_DEBUG) {
272                         printf("do_soundbuts: unhandled event %d\n", event);
273                 }
274         }
275 }
276
277
278 static void sound_panel_listener(void)
279 {
280         uiBlock *block;
281         int xco= 100, yco=100, mixrate;
282         char mixrateinfo[256];
283         
284         block= uiNewBlock(&curarea->uiblocks, "sound_panel_listener", UI_EMBOSS, UI_HELV, curarea->win);
285         if(uiNewPanel(curarea, block, "Listener", "Sound", 320, 0, 318, 204)==0) return;
286
287         mixrate = sound_get_mixrate();
288         sprintf(mixrateinfo, "Game Mixrate: %d Hz", mixrate);
289         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
290
291         yco -= 30;
292         uiDefBut(block, LABEL, 0, "Game listener settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
293
294         yco -= 30;
295         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
296                 xco,yco,195,24,&G.listener->gain, 0.0, 1.0, 1.0, 0, "Sets the maximum volume for the overall sound");
297         
298         yco -= 30;
299         uiDefBut(block, LABEL, 0, "Game Doppler effect settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
300
301         yco -= 30;
302         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Doppler: ",
303         xco,yco,195,24,&G.listener->dopplerfactor, 0.0, 10.0, 1.0, 0, "Use this for scaling the doppler effect");
304         
305         yco -=30;
306         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Velocity: ",
307         xco,yco,195,24,&G.listener->dopplervelocity,0.0,10000.0, 1.0,0, "Sets the propagation speed of sound");
308
309         
310 }
311
312 static void sound_panel_sequencer(void)
313 {
314         uiBlock *block;
315         short xco, yco;
316         char mixrateinfo[256];
317         
318         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sequencer", UI_EMBOSS, UI_HELV, curarea->win);
319         if(uiNewPanel(curarea, block, "Sequencer", "Sound", 640, 0, 318, 204)==0) return;
320
321         /* audio sequence engine settings ------------------------------------------------------------------ */
322
323         xco = 1010;
324         yco = 195;
325
326         uiDefBut(block, LABEL, 0, "Audio sequencer settings", xco,yco,295,20, 0, 0, 0, 0, 0, "");
327
328         yco -= 25;
329         sprintf(mixrateinfo, "Mixing/Sync (latency: %d ms)", (int)( (((float)U.mixbufsize)/(float)G.scene->audio.mixrate)*1000.0 ) );
330         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
331
332         yco -= 25;              
333         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");
334         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");
335         uiDefBut(block, BUT, B_SOUND_RECALC, "Recalc",          xco+160,yco,75,20, 0, 0, 0, 0, 0, "Recalculate samples");
336
337         yco -= 25;
338         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");
339         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");
340
341         yco -= 25;
342         uiDefBut(block, LABEL, 0, "Main mix", xco,yco,295,20, 0, 0, 0, 0, 0, "");
343
344         yco -= 25;              
345         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Main (dB): ",
346                 xco,yco,235,24,&G.scene->audio.main, -24.0, 6.0, 0, 0, "Set the audio master gain/attenuation in dB");
347
348         yco -= 25;
349         uiDefButBitS(block, TOG, AUDIO_MUTE, 0, "Mute", xco,yco,235,24, &G.scene->audio.flag, 0, 0, 0, 0, "Mute audio from sequencer");         
350         
351         yco -= 35;
352         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)");
353         
354 }
355
356 static char *make_sample_menu(void)
357 {
358         int len= BLI_countlist(samples);        /* BKE_sound.h */
359         
360         if(len) {
361                 bSample *sample;
362                 char *str;
363                 int nr, a=0;
364                 
365                 str= MEM_callocN(32*len, "menu");
366                 
367                 for(nr=1, sample= samples->first; sample; sample= sample->id.next, nr++) {
368                         a+= sprintf(str+a, "|%s %%x%d", sample->id.name+2, nr);
369                 }
370                 return str;
371         }
372         return NULL;
373 }
374
375 static void sound_panel_sound(bSound *sound)
376 {
377         static int packdummy=0;
378         ID *id, *idfrom;
379         uiBlock *block;
380         bSample *sample;
381         char *strp, ch[256];
382
383         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sound", UI_EMBOSS, UI_HELV, curarea->win);
384         if(uiNewPanel(curarea, block, "Sound", "Sound", 0, 0, 318, 204)==0) return;
385         
386         uiDefBut(block, LABEL, 0, "Blender Sound block",10,180,195,20, 0, 0, 0, 0, 0, "");
387         
388         // warning: abuse of texnr here! (ton didnt code!)
389         buttons_active_id(&id, &idfrom);
390         std_libbuttons(block, 10, 160, 0, NULL, B_SOUNDBROWSE2, ID_SO, 0, id, idfrom, &(G.buts->texnr), 1, 0, 0, 0, 0);
391
392         if (sound) {
393         
394                 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");
395
396                 uiSetButLock(sound->id.lib!=0, ERROR_LIBDATA_MESSAGE);
397                 sound_initialize_sample(sound);
398                 sample = sound->sample;
399
400                 /* info string */
401                 if (sound->sample && sound->sample->len) {
402                         char *tmp;
403                         if (sound->sample->channels == 1) tmp= "Mono";
404                         else if (sound->sample->channels == 2) tmp= "Stereo";
405                         else tmp= "Unknown";
406                         
407                         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));
408                         uiDefBut(block, LABEL, 0, ch,                   35,140,225,20, 0, 0, 0, 0, 0, "");
409                 }
410                 else {
411                         uiDefBut(block, LABEL, 0, "Sample: No sample info available.",35,140,225,20, 0, 0, 0, 0, 0, "");
412                 }
413
414                 /* sample browse buttons */
415                 uiBlockBeginAlign(block);
416                 strp= make_sample_menu();
417                 if (strp) {
418                         uiDefButS(block, MENU, B_SOUND_MENU_SAMPLE, strp, 10,120,23,20, &(G.buts->menunr), 0, 0, 0, 0, "Select another loaded sample");
419                         MEM_freeN(strp);
420                 }
421                 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");
422                 
423                 if (sound->sample->packedfile) packdummy = 1;
424                 else packdummy = 0;
425                 
426                 uiDefIconButBitI(block, TOG, 1, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
427                         285, 120,25,20, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
428                 
429                 uiBlockBeginAlign(block);
430                 uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
431
432                 uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play",       160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
433                 
434                 uiBlockBeginAlign(block);
435                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
436                         10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Game engine only: Set the volume of this sound");
437
438                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Pitch: ",
439                         160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Game engine only: Set the pitch of this sound");
440
441                 /* looping */
442                 uiBlockBeginAlign(block);
443                 uiDefButBitI(block, TOG, SOUND_FLAGS_LOOP, B_SOUND_REDRAW, "Loop",
444                         10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between looping on/off");
445
446                 if (sound->flags & SOUND_FLAGS_LOOP) {
447                         uiDefButBitI(block, TOG, SOUND_FLAGS_BIDIRECTIONAL_LOOP, B_SOUND_REDRAW, "Ping Pong",
448                                 105, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between A->B and A->B->A looping");
449                         
450                 }
451         
452
453                 /* 3D settings ------------------------------------------------------------------ */
454                 uiBlockBeginAlign(block);
455
456                 if (sound->sample->channels == 1) {
457                         uiDefButBitI(block, TOG, SOUND_FLAGS_3D, B_SOUND_REDRAW, "3D Sound",
458                                 10, 10, 90, 20, &sound->flags, 0, 0, 0, 0, "Game engine only: Turns 3D sound on");
459                         
460                         if (sound->flags & SOUND_FLAGS_3D) {
461                                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Scale: ",
462                                         100,10,210,20, &sound->attenuation, 0.0, 5.0, 1.0, 0, "Game engine only: Sets the surround scaling factor for this sound");
463                                 
464                         }
465                 }
466         }
467 }
468
469
470 /* ************************* SCENE *********************** */
471
472
473 static void output_pic(char *name)
474 {
475         strcpy(G.scene->r.pic, name);
476         allqueue(REDRAWBUTSSCENE, 0);
477         BIF_undo_push("Change output picture directory");
478 }
479
480 static void backbuf_pic(char *name)
481 {
482         Image *ima;
483         
484         strcpy(G.scene->r.backbuf, name);
485         allqueue(REDRAWBUTSSCENE, 0);
486
487         ima= BKE_add_image_file(name);
488         if(ima)
489                 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
490
491         BIF_undo_push("Change background picture");
492 }
493
494 static void ftype_pic(char *name)
495 {
496         strcpy(G.scene->r.ftype, name);
497         allqueue(REDRAWBUTSSCENE, 0);
498 }
499
500 static void run_playanim(char *file) 
501 {
502         extern char bprogname[];        /* usiblender.c */
503         char str[FILE_MAX];
504         int pos[2], size[2];
505
506         /* use current settings for defining position of window. it actually should test image size */
507         calc_renderwin_rectangle((G.scene->r.xsch*G.scene->r.size)/100, 
508                                                          (G.scene->r.ysch*G.scene->r.size)/100, G.winpos, pos, size);
509 #ifdef WIN32
510         sprintf(str, "%s -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
511 #else
512         sprintf(str, "\"%s\" -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
513 #endif
514         system(str);
515 }
516
517 void playback_anim(void)
518 {       
519         char file[FILE_MAX];
520
521         if(BKE_imtype_is_movie(G.scene->r.imtype)) {
522                 switch (G.scene->r.imtype) {
523 #ifdef WITH_QUICKTIME
524                         case R_QUICKTIME:
525                                 makeqtstring(file);
526                                 break;
527 #endif
528 #ifdef WITH_FFMPEG
529                 case R_FFMPEG:
530                         makeffmpegstring(file);
531                         break;
532 #endif
533                 default:
534                         makeavistring(&G.scene->r, file);
535                         break;
536                 }
537                 if(BLI_exist(file)) {
538                         run_playanim(file);
539                 }
540                 else error("Can't find movie: %s", file);
541         }
542         else {
543                 BKE_makepicstring(file, G.scene->r.pic, G.scene->r.sfra, G.scene->r.imtype);
544                 if(BLI_exist(file)) {
545                         run_playanim(file);
546                 }
547                 else error("Can't find image: %s", file);
548         }
549 }
550
551 #ifdef WITH_FFMPEG
552 static void set_ffmpeg_preset(int preset);
553 #endif
554
555 void do_render_panels(unsigned short event)
556 {
557         ScrArea *sa;
558         ID *id;
559
560         switch(event) {
561
562         case B_DORENDER:
563                 BIF_do_render(0);
564                 break;
565         case B_RTCHANGED:
566                 allqueue(REDRAWALL, 0);
567                 break;
568         case B_SWITCHRENDER:
569                 /* new panels added, so... */
570                 G.buts->re_align= 1;
571                 allqueue(REDRAWBUTSSCENE, 0);
572                 break;
573         case B_PLAYANIM:
574                 playback_anim();
575                 break;
576                 
577         case B_DOANIM:
578                 BIF_do_render(1);
579                 break;
580         
581         case B_FS_PIC:
582                 sa= closest_bigger_area();
583                 areawinset(sa->win);
584                 if(G.qual == LR_CTRLKEY)
585                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
586                 else
587                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
588                 break;
589
590         case B_FS_BACKBUF:
591                 sa= closest_bigger_area();
592                 areawinset(sa->win);
593                 if(G.qual == LR_CTRLKEY)
594                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
595                 else
596                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
597                 break;
598
599         case B_FS_FTYPE:
600                 sa= closest_bigger_area();
601                 areawinset(sa->win);
602                 if(G.qual == LR_CTRLKEY)
603                         activate_imageselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
604                 else
605                         activate_fileselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
606                 break;
607         
608         case B_PR_PAL:
609                 G.scene->r.xsch= 720;
610                 G.scene->r.ysch= 576;
611                 G.scene->r.xasp= 54;
612                 G.scene->r.yasp= 51;
613                 G.scene->r.size= 100;
614                 G.scene->r.frs_sec= 25;
615                 G.scene->r.frs_sec_base= 1;
616                 G.scene->r.mode &= ~R_PANORAMA;
617                 G.scene->r.xparts=  G.scene->r.yparts= 4;
618 #ifdef WITH_FFMPEG
619                 G.scene->r.ffcodecdata.gop_size = 15;
620 #endif          
621                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
622                 BIF_undo_push("Set PAL");
623                 allqueue(REDRAWBUTSSCENE, 0);
624                 allqueue(REDRAWVIEWCAM, 0);
625                 break;
626
627         case B_FILETYPEMENU:
628                 allqueue(REDRAWBUTSSCENE, 0);
629 #ifdef WITH_FFMPEG
630                 if (G.scene->r.imtype == R_FFMPEG) {
631                         if (G.scene->r.ffcodecdata.type <= 0 ||
632                             G.scene->r.ffcodecdata.codec <= 0 ||
633                             G.scene->r.ffcodecdata.audio_codec <= 0 ||
634                             G.scene->r.ffcodecdata.video_bitrate <= 1) {
635                                 G.scene->r.ffcodecdata.codec 
636                                         = CODEC_ID_MPEG2VIDEO;
637                                 set_ffmpeg_preset(FFMPEG_PRESET_DVD);
638                         }
639
640                         if (G.scene->r.ffcodecdata.audio_codec <= 0) {
641                                 G.scene->r.ffcodecdata.audio_codec 
642                                         = CODEC_ID_MP2;
643                                 G.scene->r.ffcodecdata.audio_bitrate = 128;
644                         }
645                         break;
646                 }
647 #endif
648 #if defined (_WIN32) || defined (__APPLE__)
649                 // fall through to codec settings if this is the first
650                 // time R_AVICODEC is selected for this scene.
651                 if (((G.scene->r.imtype == R_AVICODEC) 
652                          && (G.scene->r.avicodecdata == NULL)) ||
653                         ((G.scene->r.imtype == R_QUICKTIME) 
654                          && (G.scene->r.qtcodecdata == NULL))) {
655                 } else {
656                   break;
657                 }
658 #endif /*_WIN32 || __APPLE__ */
659
660         case B_SELECTCODEC:
661 #if defined (_WIN32) || defined (__APPLE__)
662                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
663 #ifdef WITH_QUICKTIME
664                         get_qtcodec_settings();
665 #endif /* WITH_QUICKTIME */
666                 }
667 #if defined (_WIN32) && !defined(FREE_WINDOWS)
668                 else
669                         get_avicodec_settings();
670 #endif /* _WIN32 && !FREE_WINDOWS */
671 #endif /* _WIN32 || __APPLE__ */
672                 break;
673
674         case B_PR_HD:
675                 G.scene->r.xsch= 1920;
676                 G.scene->r.ysch= 1080;
677                 G.scene->r.xasp= 1;
678                 G.scene->r.yasp= 1;
679                 G.scene->r.size= 100;
680                 G.scene->r.mode &= ~R_PANORAMA;
681                 G.scene->r.xparts=  G.scene->r.yparts= 4;
682                 
683                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
684                 BIF_undo_push("Set FULL");
685                 allqueue(REDRAWBUTSSCENE, 0);
686                 allqueue(REDRAWVIEWCAM, 0);
687                 break;
688         case B_PR_FULL:
689                 G.scene->r.xsch= 1280;
690                 G.scene->r.ysch= 1024;
691                 G.scene->r.xasp= 1;
692                 G.scene->r.yasp= 1;
693                 G.scene->r.size= 100;
694                 G.scene->r.mode &= ~R_PANORAMA;
695                 G.scene->r.xparts=  G.scene->r.yparts= 4;
696
697                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
698                 BIF_undo_push("Set FULL");
699                 allqueue(REDRAWBUTSSCENE, 0);
700                 allqueue(REDRAWVIEWCAM, 0);
701                 break;
702         case B_PR_PRV:
703                 G.scene->r.xsch= 640;
704                 G.scene->r.ysch= 512;
705                 G.scene->r.xasp= 1;
706                 G.scene->r.yasp= 1;
707                 G.scene->r.size= 50;
708                 G.scene->r.mode &= ~R_PANORAMA;
709                 G.scene->r.xparts=  G.scene->r.yparts= 2;
710
711                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
712                 allqueue(REDRAWVIEWCAM, 0);
713                 allqueue(REDRAWBUTSSCENE, 0);
714                 break;
715         case B_PR_PAL169:
716                 G.scene->r.xsch= 720;
717                 G.scene->r.ysch= 576;
718                 G.scene->r.xasp= 64;
719                 G.scene->r.yasp= 45;
720                 G.scene->r.size= 100;
721                 G.scene->r.frs_sec= 25;
722                 G.scene->r.frs_sec_base= 1;
723                 G.scene->r.mode &= ~R_PANORAMA;
724                 G.scene->r.xparts=  G.scene->r.yparts= 4;
725 #ifdef WITH_FFMPEG
726                 G.scene->r.ffcodecdata.gop_size = 15;
727 #endif          
728
729                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
730                 BIF_undo_push("Set PAL 16/9");
731                 allqueue(REDRAWVIEWCAM, 0);
732                 allqueue(REDRAWBUTSSCENE, 0);
733                 break;
734         case B_PR_PC:
735                 G.scene->r.xsch= 640;
736                 G.scene->r.ysch= 480;
737                 G.scene->r.xasp= 100;
738                 G.scene->r.yasp= 100;
739                 G.scene->r.size= 100;
740                 G.scene->r.mode &= ~R_PANORAMA;
741                 G.scene->r.xparts=  G.scene->r.yparts= 4;
742
743                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
744                 BIF_undo_push("Set PC");
745                 allqueue(REDRAWVIEWCAM, 0);
746                 allqueue(REDRAWBUTSSCENE, 0);
747                 break;
748         case B_PR_PRESET:
749                 G.scene->r.xsch= 720;
750                 G.scene->r.ysch= 576;
751                 G.scene->r.xasp= 54;
752                 G.scene->r.yasp= 51;
753                 G.scene->r.size= 100;
754                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS;
755                 G.scene->r.imtype= R_TARGA;
756                 G.scene->r.xparts=  G.scene->r.yparts= 4;
757
758                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
759                 BIF_undo_push("Set Default");
760                 allqueue(REDRAWVIEWCAM, 0);
761                 allqueue(REDRAWBUTSSCENE, 0);
762                 break;
763         case B_PR_PANO:
764                 G.scene->r.xsch= 576;
765                 G.scene->r.ysch= 176;
766                 G.scene->r.xasp= 115;
767                 G.scene->r.yasp= 100;
768                 G.scene->r.size= 100;
769                 G.scene->r.mode |= R_PANORAMA;
770                 G.scene->r.xparts=  16;
771                 G.scene->r.yparts= 1;
772
773                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
774                 BIF_undo_push("Set Panorama");
775                 allqueue(REDRAWVIEWCAM, 0);
776                 allqueue(REDRAWBUTSSCENE, 0);
777                 break;
778         case B_PR_NTSC:
779                 G.scene->r.xsch= 720;
780                 G.scene->r.ysch= 480;
781                 G.scene->r.xasp= 10;
782                 G.scene->r.yasp= 11;
783                 G.scene->r.size= 100;
784                 G.scene->r.frs_sec= 30;
785                 G.scene->r.frs_sec_base = 1.001;
786                 G.scene->r.mode &= ~R_PANORAMA;
787                 G.scene->r.xparts=  G.scene->r.yparts= 2;
788 #ifdef WITH_FFMPEG
789                 G.scene->r.ffcodecdata.gop_size = 18;
790 #endif          
791                 
792                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
793                 BIF_undo_push("Set NTSC");
794                 allqueue(REDRAWBUTSSCENE, 0);
795                 allqueue(REDRAWVIEWCAM, 0);
796                 break;
797
798         case B_SETBROWSE:
799                 id= (ID*) G.scene->set;
800                 
801                 if (G.buts->menunr==-2) {
802                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
803                 } 
804                 else if (G.buts->menunr>0) {
805                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
806                         
807                         if (newset==G.scene)
808                                 error("Can't use the same scene as its own set");
809                         else if (newset) {
810                                 G.scene->set= newset;
811                                 if (scene_check_setscene(G.scene)==0)
812                                         error("This would create a cycle");
813
814                                 allqueue(REDRAWBUTSSCENE, 0);
815                                 allqueue(REDRAWVIEW3D, 0);
816                                 BIF_undo_push("Change Set Scene");
817                         }
818                 }  
819                 break;
820         case B_CLEARSET:
821                 G.scene->set= NULL;
822                 allqueue(REDRAWBUTSSCENE, 0);
823                 allqueue(REDRAWVIEW3D, 0);
824                 BIF_undo_push("Clear Set Scene");
825                 
826                 break;
827         case B_SET_EDGE:
828                 allqueue(REDRAWBUTSSCENE, 0);
829                 break;
830         case B_SET_ZBLUR:
831                 G.scene->r.mode &= ~R_EDGE;
832                 allqueue(REDRAWBUTSSCENE, 0);
833                 break;
834         case B_ADD_RENDERLAYER:
835                 if(G.scene->r.actlay==32767) {
836                         scene_add_render_layer(G.scene);
837                         G.scene->r.actlay= BLI_countlist(&G.scene->r.layers) - 1;
838                 }
839                 allqueue(REDRAWBUTSSCENE, 0);
840                 allqueue(REDRAWNODE, 0);
841                 break;
842         case B_SET_PASS:
843                 if(G.scene->nodetree) {
844                         ntreeCompositForceHidden(G.scene->nodetree);
845                         allqueue(REDRAWNODE, 0);
846                 }
847                 allqueue(REDRAWBUTSSCENE, 0);
848                 allqueue(REDRAWOOPS, 0);
849         }
850 }
851
852 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
853 static uiBlock *edge_render_menu(void *arg_unused)
854 {
855         uiBlock *block;
856         
857         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
858                 
859         /* use this for a fake extra empy space around the buttons */
860         uiDefBut(block, LABEL, 0, "",  0, 0, 220, 115, NULL,  0, 0, 0, 0, "");
861         
862         uiDefButS(block, NUM, 0,"Eint:",        45,75,175,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
863                   "Sets edge intensity for Toon shading");
864
865         /* color settings for the toon shading */
866         uiDefButF(block, COL, 0, "",            10, 10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, B_EDGECOLSLI, "");
867         
868         uiBlockBeginAlign(block);
869         uiDefButF(block, NUMSLI, 0, "R ",   45, 50, 175,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
870                   "Color for edges in toon shading mode.");
871         uiDefButF(block, NUMSLI, 0, "G ",       45, 30, 175,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
872                   "Color for edges in toon shading mode.");
873         uiDefButF(block, NUMSLI, 0, "B ",       45, 10, 175,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
874                   "Color for edges in toon shading mode.");
875
876         
877         uiBlockSetDirection(block, UI_TOP);
878         
879         return block;
880 }
881
882
883 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
884 static uiBlock *framing_render_menu(void *arg_unused)
885 {
886         uiBlock *block;
887         short yco = 190, xco = 0;
888         int randomcolorindex = 1234;
889
890         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
891
892         /* use this for a fake extra empy space around the buttons */
893         uiDefBut(block, LABEL, 0, "",                   -5, -10, 295, 224, NULL, 0, 0, 0, 0, "");
894
895         uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
896         uiBlockBeginAlign(block);
897         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");
898         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");
899         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");
900         uiBlockEndAlign(block);
901
902         yco -= 25;
903         xco = 40;
904
905         uiDefButF(block, COL, 0, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, "");
906
907         uiBlockBeginAlign(block);
908         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");
909         yco -= 20;
910         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");
911         yco -= 20;
912         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");
913         uiBlockEndAlign(block);
914         
915         xco = 0;
916         uiDefBut(block, LABEL, 0, "Fullscreen:",                xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, "");
917         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");
918         uiBlockBeginAlign(block);
919         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.");
920         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.");
921         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.");
922         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.");
923         uiBlockEndAlign(block);
924
925         /* stereo settings */
926         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
927          * RAS_IRasterizer has definitions:
928          * RAS_STEREO_NOSTEREO           1
929          * RAS_STEREO_QUADBUFFERED 2
930          * RAS_STEREO_ABOVEBELOW         3
931          * RAS_STEREO_INTERLACED         4       future
932          * RAS_STEREO_ANAGLYPH          5
933          * RAS_STEREO_SIDEBYSIDE        6
934          * RAS_STEREO_VINTERLACE        7
935          */
936         uiBlockBeginAlign(block);
937         uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo");
938         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");
939         uiDefButS(block, ROW, 0, "Syncdouble", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
940         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");
941         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");
942         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");
943         
944         uiBlockEndAlign(block);
945
946         uiBlockSetDirection(block, UI_TOP);
947
948         return block;
949 }
950
951 #ifdef WITH_FFMPEG
952
953 static char* ffmpeg_format_pup(void) 
954 {
955         static char string[2048];
956         char formatstring[2048];
957 #if 0
958        int i = 0;
959        int stroffs = 0;
960        AVOutputFormat* next = first_oformat;
961        formatstring = "FFMpeg format: %%t";
962       sprintf(string, formatstring);
963        formatstring = "|%s %%x%d";
964        /* FIXME: This should only be generated once */
965        while (next != NULL) {
966                if (next->video_codec != CODEC_ID_NONE && !(next->flags & AVFMT_NOFILE)) {
967                        sprintf(string+stroffs, formatstring, next->name, i++);
968                        stroffs += strlen(string+stroffs);
969                }
970                next = next->next;
971        }
972        return string;
973 #endif
974        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");
975        sprintf(string, formatstring,
976                "MPEG-1", FFMPEG_MPEG1,
977                "MPEG-2", FFMPEG_MPEG2,
978                "MPEG-4", FFMPEG_MPEG4,
979                "AVI",    FFMPEG_AVI,
980                "Quicktime", FFMPEG_MOV,
981                "DV", FFMPEG_DV,
982                "H264", FFMPEG_H264,
983                "XVid", FFMPEG_XVID);
984        return string;
985 }
986
987 static char* ffmpeg_preset_pup(void) 
988 {
989         static char string[2048];
990         char formatstring[2048];
991
992        strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
993        sprintf(string, formatstring,
994                "", FFMPEG_PRESET_NONE,
995                "DVD", FFMPEG_PRESET_DVD,
996                "SVCD", FFMPEG_PRESET_SVCD,
997                "VCD", FFMPEG_PRESET_VCD,
998                "DV", FFMPEG_PRESET_DV);
999        return string;
1000 }
1001
1002
1003 static char* ffmpeg_codec_pup(void) {
1004        static char string[2048];
1005        char formatstring[2048];
1006        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");
1007        sprintf(string, formatstring,
1008                "MPEG1", CODEC_ID_MPEG1VIDEO,
1009                "MPEG2", CODEC_ID_MPEG2VIDEO,
1010                "MPEG4(divx)", CODEC_ID_MPEG4,
1011                "HuffYUV", CODEC_ID_HUFFYUV,
1012                "DV", CODEC_ID_DVVIDEO,
1013                "H264", CODEC_ID_H264,
1014                "XVid", CODEC_ID_XVID);
1015        return string;
1016
1017 }
1018
1019 static char* ffmpeg_audio_codec_pup(void) {
1020        static char string[2048];
1021        char formatstring[2048];
1022        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1023        sprintf(string, formatstring,
1024                "MP2", CODEC_ID_MP2,
1025                "MP3", CODEC_ID_MP3,
1026                "AC3", CODEC_ID_AC3,
1027                "AAC", CODEC_ID_AAC,
1028                "PCM", CODEC_ID_PCM_S16LE);
1029        return string;
1030
1031 }
1032
1033 #endif
1034
1035 static char *imagetype_pup(void)
1036 {
1037         static char string[1024];
1038         char formatstring[1024];
1039         char appendstring[1024];
1040
1041         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");
1042
1043 #ifdef __sgi
1044         strcat(formatstring, "|%s %%x%d");      // add space for Movie
1045 #endif
1046
1047         strcat(formatstring, "|%s %%x%d");      // add space for PNG
1048 /*  Commented out until implemented
1049 #ifdef WITH_DDS
1050         strcat(formatstring, "|%s %%x%d");      // add space for DDS
1051 #endif
1052 */
1053         strcat(formatstring, "|%s %%x%d");      // add space for BMP
1054         strcat(formatstring, "|%s %%x%d");      // add space for Radiance HDR
1055         strcat(formatstring, "|%s %%x%d");      // add space for Cineon
1056         strcat(formatstring, "|%s %%x%d");      // add space for DPX
1057         
1058 #ifdef _WIN32
1059         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
1060 #endif
1061
1062 #ifdef WITH_FFMPEG
1063        strcat(formatstring, "|%s %%x%d"); // Add space for ffmpeg
1064 #endif
1065        strcat(formatstring, "|%s %%x%d"); // Add space for frameserver
1066
1067 #ifdef WITH_QUICKTIME
1068         if(G.have_quicktime)
1069                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
1070 #endif
1071
1072         if(G.have_quicktime) {
1073                 sprintf(string, formatstring,
1074                         "Frameserver",   R_FRAMESERVER,
1075 #ifdef WITH_FFMPEG
1076                        "FFMpeg",         R_FFMPEG,
1077 #endif
1078                         "AVI Raw",        R_AVIRAW,
1079                         "AVI Jpeg",       R_AVIJPEG,
1080 #ifdef _WIN32
1081                         "AVI Codec",      R_AVICODEC,
1082 #endif
1083 #ifdef WITH_QUICKTIME
1084                         "QuickTime",      R_QUICKTIME,
1085 #endif
1086                         "Targa",          R_TARGA,
1087                         "Targa Raw",      R_RAWTGA,
1088                         "PNG",            R_PNG,
1089 /* commented out until implemented 
1090 #ifdef WITH_DDS
1091                         "DDS",            R_DDS,
1092 #endif
1093 */
1094                         "BMP",            R_BMP,
1095                         "Jpeg",           R_JPEG90,
1096                         "HamX",           R_HAMX,
1097                         "Iris",           R_IRIS,
1098                         "Radiance HDR",   R_RADHDR,
1099                         "Cineon",                 R_CINEON,
1100                         "DPX",                    R_DPX
1101 #ifdef __sgi
1102                         ,"Movie",          R_MOVIE
1103 #endif
1104                 );
1105         } else {
1106                 sprintf(string, formatstring,
1107                         "Frameserver",   R_FRAMESERVER,
1108 #ifdef WITH_FFMPEG
1109                        "FFMpeg",         R_FFMPEG,
1110 #endif
1111                         "AVI Raw",        R_AVIRAW,
1112                         "AVI Jpeg",       R_AVIJPEG,
1113 #ifdef _WIN32
1114                         "AVI Codec",      R_AVICODEC,
1115 #endif
1116                         "Targa",          R_TARGA,
1117                         "Targa Raw",      R_RAWTGA,
1118                         "PNG",            R_PNG,
1119 #ifdef WITH_DDS
1120                         "DDS",            R_DDS,
1121 #endif
1122                         "BMP",            R_BMP,
1123                         "Jpeg",           R_JPEG90,
1124                         "HamX",           R_HAMX,
1125                         "Iris",           R_IRIS,
1126                         "Radiance HDR",   R_RADHDR,
1127                         "Cineon",                 R_CINEON,
1128                         "DPX",                    R_DPX
1129 #ifdef __sgi
1130                         ,"Movie",          R_MOVIE
1131 #endif
1132                 );
1133         }
1134
1135 #ifdef WITH_OPENEXR
1136         strcpy(formatstring, "|%s %%x%d");
1137         sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
1138         strcat(string, appendstring);
1139         sprintf(appendstring, formatstring, "MultiLayer", R_MULTILAYER);
1140         strcat(string, appendstring);
1141 #endif
1142         
1143         if (G.have_libtiff) {
1144                 strcpy(formatstring, "|%s %%x%d");
1145                 sprintf(appendstring, formatstring, "TIFF", R_TIFF);
1146                 strcat(string, appendstring);
1147         }
1148
1149         return (string);
1150 }
1151
1152 #ifdef _WIN32
1153 static char *avicodec_str(void)
1154 {
1155         static char string[1024];
1156
1157         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
1158
1159         return string;
1160 }
1161 #endif
1162
1163 static void render_panel_output(void)
1164 {
1165         ID *id;
1166         int a,b;
1167         uiBlock *block;
1168         char *strp;
1169
1170
1171         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
1172         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
1173         
1174         uiBlockBeginAlign(block);
1175         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        10, 190, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Pics dir/name");
1176         uiDefBut(block, TEX,0,"",                                                       31, 190, 279, 20,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save rendered Pics to");
1177         uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
1178         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");
1179         uiDefIconBut(block, BUT,B_FS_FTYPE, ICON_FILESEL,       10, 146, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Ftype image");
1180         uiDefBut(block, TEX,0,"",                                                       31, 146, 279, 20,G.scene->r.ftype,0.0,79.0, 0, 0, "Image to use with FTYPE Image type");
1181         uiBlockEndAlign(block);
1182         
1183         
1184         /* SET BUTTON */
1185         uiBlockBeginAlign(block);
1186         id= (ID *)G.scene->set;
1187         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
1188         if(strp[0])
1189                 uiDefButS(block, MENU, B_SETBROWSE, strp, 10, 120, 20, 20, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
1190         MEM_freeN(strp);
1191
1192         if(G.scene->set) {
1193                 uiSetButLock(1, NULL);
1194                 uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, B_NOP, "",    31, 120, 100, 20, &(G.scene->set), "Name of the Set");
1195                 uiClearButLock();
1196                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            132, 120, 20, 20, 0, 0, 0, 0, 0, "Remove Set link");
1197         }
1198         uiBlockEndAlign(block);
1199
1200         uiBlockSetCol(block, TH_BUT_SETTING1);
1201         uiDefButBitS(block, TOG, R_BACKBUF, B_NOP,"Backbuf",    10, 94, 80, 20, &G.scene->r.bufflag, 0, 0, 0, 0, "Enable/Disable use of Backbuf image");        
1202         uiDefButS(block, NUM, B_NOP, "Threads:",                                10, 68, 100, 20, &G.scene->r.threads, 1, BLENDER_MAX_THREADS, 0, 0, "Amount of threads for render");    
1203         uiBlockSetCol(block, TH_AUTO);
1204                 
1205         uiBlockBeginAlign(block);
1206         for(b=2; b>=0; b--)
1207                 for(a=0; a<3; a++)
1208                         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");
1209         uiBlockEndAlign(block);
1210
1211         uiDefButBitS(block, TOG, R_EXR_TILE_FILE, B_NOP, "Save Buffers", 72, 31, 120, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Save the tiles for all RenderLayers and used SceneNodes to files, to save memory");
1212         
1213         uiDefButS(block, MENU, B_REDR, "Render Display %t|Render Window %x1|Image Editor %x0|Full Screen %x2",  
1214                                         72, 10, 120, 19, &G.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output display");
1215
1216         uiDefButBitS(block, TOG, R_EXTENSION, B_NOP, "Extensions", 205, 10, 105, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Adds extensions to the output when rendering animations");
1217
1218         /* Dither control */
1219         uiDefButF(block, NUM,B_DIFF, "Dither:",         205,31,105,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)");
1220         
1221         /* Toon shading buttons */
1222         uiBlockBeginAlign(block);
1223         uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   100, 94, 70, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
1224         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 170, 94, 140, 20, "Display Edge settings");
1225         uiBlockEndAlign(block);
1226         
1227         uiBlockBeginAlign(block);
1228         uiDefButBitS(block, TOG, R_NO_TEX, B_NOP, "Disable Tex", 115, 68, 70, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Disables Textures for render");
1229         uiDefButBitS(block, TOG, R_FREE_IMAGE, B_NOP, "Free Tex Images", 205, 68, 100, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Frees all Images used by Textures after each render");
1230         uiBlockEndAlign(block);
1231 }
1232
1233 static void do_bake_func(void *unused_v, void *unused_p)
1234 {
1235         objects_bake_render(0);
1236 }
1237
1238 static void render_panel_bake(void)
1239 {
1240         uiBlock *block;
1241         uiBut *but;
1242         
1243         block= uiNewBlock(&curarea->uiblocks, "render_panel_bake", UI_EMBOSS, UI_HELV, curarea->win);
1244         uiNewPanelTabbed("Anim", "Render");
1245         if(uiNewPanel(curarea, block, "Bake", "Render", 320, 0, 318, 204)==0) return;
1246         
1247         but= uiDefBut(block, BUT, B_NOP, "BAKE",        10, 150, 190,40, 0, 0, 0, 0, 0, "Start the bake render for selected Objects");
1248         uiButSetFunc(but, do_bake_func, NULL, NULL);
1249 #if 0   
1250         uiBlockBeginAlign(block);
1251         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)");
1252         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");
1253         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");
1254         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");
1255         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");
1256 #endif  
1257         uiBlockBeginAlign(block);
1258         uiDefButS(block, ROW,B_DIFF,"Full Render",              210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, "");
1259         uiDefButS(block, ROW,B_DIFF,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, "");
1260         uiDefButS(block, ROW,B_DIFF,"Normals",          210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, "");
1261         uiDefButS(block, ROW,B_DIFF,"Textures",         210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, "");
1262         uiBlockEndAlign(block);
1263         
1264         uiDefButBitS(block, TOG, R_BAKE_CLEAR, B_DIFF, "Clear",         210,80,120,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Clear Images before baking");
1265         
1266         uiDefButS(block, NUM, B_DIFF,"Margin:",                         210,50,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");
1267 }
1268
1269 static void render_panel_render(void)
1270 {
1271         uiBlock *block;
1272         char str[256];
1273
1274         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
1275         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
1276
1277         uiBlockBeginAlign(block);
1278         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369, 164, 191,37, 0, 0, 0, 0, 0, "Start the rendering");
1279 #ifndef DISABLE_YAFRAY
1280         /* yafray: on request, render engine menu is back again, and moved to Render panel */
1281         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0|YafRay %x1", 
1282                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
1283 #else
1284         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0", 
1285                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
1286 #endif /* disable yafray */
1287
1288         uiBlockBeginAlign(block);
1289         uiDefButBitI(block, TOG, R_OSA, B_DIFF, "OSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
1290         uiDefButS(block, ROW,B_DIFF,"5",                        369,88,29,20,&G.scene->r.osa,2.0,5.0, 0, 0, "Sets oversample level to 5");
1291         uiDefButS(block, ROW,B_DIFF,"8",                        400,88,29,20,&G.scene->r.osa,2.0,8.0, 0, 0, "Sets oversample level to 8 (Recommended)");
1292         uiDefButS(block, ROW,B_DIFF,"11",                       431,88,29,20,&G.scene->r.osa,2.0,11.0, 0, 0, "Sets oversample level to 11");
1293         uiDefButS(block, ROW,B_DIFF,"16",                       462,88,29,20,&G.scene->r.osa,2.0,16.0, 0, 0, "Sets oversample level to 16");
1294         uiBlockEndAlign(block);
1295
1296         uiBlockBeginAlign(block);
1297         uiDefButBitI(block, TOG, R_MBLUR, B_REDR, "MBLUR",      496,109,64,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
1298         uiDefButF(block, NUM,B_DIFF,"Bf:",                      496,88,64,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
1299         uiBlockEndAlign(block);
1300
1301         uiBlockBeginAlign(block);
1302         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)");
1303         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");
1304         uiBlockEndAlign(block);
1305
1306         uiBlockBeginAlign(block);
1307         uiDefButS(block, ROW,800,"Sky",         369,13,35,20,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
1308         uiDefButS(block, ROW,800,"Premul",      405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
1309         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");
1310         uiBlockEndAlign(block);
1311
1312         if(G.scene->r.mode & R_RAYTRACE)
1313                 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");
1314
1315         uiBlockBeginAlign(block);
1316         uiDefButBitI(block, TOG, R_SHADOW, B_REDR,"Shadow",     565,172,60,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
1317         uiDefButBitI(block, TOG, R_ENVMAP, B_REDR,"EnvMap",     627,172,60,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map rendering");
1318         uiDefButBitI(block, TOG, R_PANORAMA, B_REDR,"Pano",     565,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable panorama rendering (output width is multiplied by Xparts)");
1319         uiDefButBitI(block, TOG, R_RAYTRACE, B_REDR,"Ray",606,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
1320         uiDefButBitI(block, TOG, R_RADIO, B_REDR,"Radio",       647,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
1321         uiBlockEndAlign(block);
1322         
1323         uiBlockBeginAlign(block);
1324         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");
1325         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");
1326         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");
1327         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");
1328         uiBlockEndAlign(block);
1329
1330         uiBlockBeginAlign(block);
1331         uiDefButBitI(block, TOG, R_FIELDS, B_REDR,"Fields",  565,55,60,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
1332         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)");
1333         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");
1334         
1335         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);
1336         uiDefButS(block, MENU, B_DIFF,str,              565,34,60,20, &G.scene->r.filtertype, 0, 0, 0, 0, "Set sampling filter for antialiasing");
1337         uiDefButF(block, NUM,B_DIFF,"",                 627,34,60,20,&G.scene->r.gauss,0.5, 1.5, 10, 2, "Sets the filter size");
1338         
1339         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");
1340         uiBlockEndAlign(block);
1341
1342 }
1343
1344 static void render_panel_anim(void)
1345 {
1346         uiBlock *block;
1347
1348
1349         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1350         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
1351
1352
1353         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Start rendering a sequence");
1354
1355         uiBlockSetCol(block, TH_BUT_SETTING1);
1356         uiBlockBeginAlign(block);
1357         uiDefButBitS(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)");
1358         uiDefButBitS(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");
1359         uiBlockEndAlign(block);
1360
1361         uiBlockSetCol(block, TH_AUTO);
1362         uiDefBut(block, BUT,B_PLAYANIM, "PLAY",692,40,94,33, 0, 0, 0, 0, 0, "Play animation of rendered images/avi (searches Pics: field)");
1363         uiDefButS(block, NUM, B_RTCHANGED, "rt:",789,40,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
1364
1365         uiBlockBeginAlign(block);
1366         uiDefButI(block, NUM,REDRAWSEQ,"Sta:",692,10,94,24, &G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "The start frame of the animation");
1367         uiDefButI(block, NUM,REDRAWSEQ,"End:",789,10,95,24, &G.scene->r.efra,SFRA,MAXFRAMEF, 0, 0, "The end  frame of the animation");
1368         uiBlockEndAlign(block);
1369 }
1370
1371 #ifdef WITH_FFMPEG
1372 static void set_ffmpeg_preset(int preset)
1373 {
1374         int isntsc = (G.scene->r.frs_sec != 25);
1375         switch (preset) {
1376         case FFMPEG_PRESET_VCD:
1377                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG1;
1378                 G.scene->r.ffcodecdata.video_bitrate = 1150;
1379                 G.scene->r.xsch = 352;
1380                 G.scene->r.ysch = isntsc ? 240 : 288;
1381                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1382                 G.scene->r.ffcodecdata.rc_max_rate = 1150;
1383                 G.scene->r.ffcodecdata.rc_min_rate = 1150;
1384                 G.scene->r.ffcodecdata.rc_buffer_size = 40*8;
1385                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
1386                 G.scene->r.ffcodecdata.mux_rate = 2352 * 75 * 8;
1387                 break;
1388         case FFMPEG_PRESET_SVCD:
1389                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
1390                 G.scene->r.ffcodecdata.video_bitrate = 2040;
1391                 G.scene->r.xsch = 480;
1392                 G.scene->r.ysch = isntsc ? 480 : 576;
1393                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1394                 G.scene->r.ffcodecdata.rc_max_rate = 2516;
1395                 G.scene->r.ffcodecdata.rc_min_rate = 0;
1396                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
1397                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
1398                 G.scene->r.ffcodecdata.mux_rate = 0;
1399                 
1400                 break;
1401         case FFMPEG_PRESET_DVD:
1402                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
1403                 G.scene->r.ffcodecdata.video_bitrate = 6000;
1404                 G.scene->r.xsch = 720;
1405                 G.scene->r.ysch = isntsc ? 480 : 576;
1406                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1407                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
1408                 G.scene->r.ffcodecdata.rc_min_rate = 0;
1409                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
1410                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
1411                 G.scene->r.ffcodecdata.mux_rate = 10080000;
1412                 
1413                 break;
1414         case FFMPEG_PRESET_DV:
1415                 G.scene->r.ffcodecdata.type = FFMPEG_DV;
1416                 G.scene->r.xsch = 720;
1417                 G.scene->r.ysch = isntsc ? 480 : 576;
1418                 break;
1419         }
1420 }
1421
1422 static void render_panel_ffmpeg_video(void)
1423 {
1424         uiBlock *block;
1425         int yofs;
1426         int xcol1;
1427         int xcol2;
1428         
1429         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_video", 
1430                                            UI_EMBOSS, UI_HELV, curarea->win);
1431         
1432         uiNewPanelTabbed("Format", "Render");
1433         if (uiNewPanel(curarea, block, "Video", "Render", 960, 0, 318, 204)== 0) 
1434                 return;
1435         
1436         if (ffmpeg_preset_sel != 0) {
1437                 set_ffmpeg_preset(ffmpeg_preset_sel);
1438                 ffmpeg_preset_sel = 0;
1439                 allqueue(REDRAWBUTSSCENE, 0);
1440         }
1441         
1442         xcol1 = 872;
1443         xcol2 = 1002;
1444         
1445         yofs = 54;
1446         uiDefBut(block, LABEL, B_DIFF, "Format", xcol1, yofs+88, 
1447                          110, 20, 0, 0, 0, 0, 0, "");
1448         uiDefBut(block, LABEL, B_DIFF, "Preset", xcol2, yofs+88, 
1449                          110, 20, 0, 0, 0, 0, 0, "");
1450         uiDefButI(block, MENU, B_DIFF, ffmpeg_format_pup(), 
1451                           xcol1, yofs+66, 110, 20, &G.scene->r.ffcodecdata.type, 
1452                           0,0,0,0, "output file format");
1453         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
1454                           xcol1, yofs+44, 110, 20, 
1455                           &G.scene->r.ffcodecdata.video_bitrate, 
1456                           1, 14000, 0, 0, "Video bitrate(kb/s)");
1457         uiDefButI(block, NUM, B_DIFF, "Min Rate", 
1458                           xcol1, yofs+22, 110, 20, &G.scene->r.ffcodecdata.rc_min_rate, 
1459                           0, 14000, 0, 0, "Rate control: min rate(kb/s)");
1460         uiDefButI(block, NUM, B_DIFF, "Max Rate", 
1461                           xcol1, yofs, 110, 20, &G.scene->r.ffcodecdata.rc_max_rate, 
1462                           1, 14000, 0, 0, "Rate control: max rate(kb/s)");
1463         
1464         uiDefButI(block, NUM, B_DIFF, "Mux Rate", 
1465                           xcol1, yofs-22, 110, 20, 
1466                           &G.scene->r.ffcodecdata.mux_rate, 
1467                           0, 100000000, 0, 0, "Mux rate (bits/s(!))");
1468         
1469         
1470         uiDefButI(block, MENU, B_REDR, ffmpeg_preset_pup(), 
1471                           xcol2, yofs+66, 110, 20, &ffmpeg_preset_sel, 
1472                           0,0,0,0, "Output file format preset selection");
1473         uiDefButI(block, NUM, B_DIFF, "GOP Size", 
1474                           xcol2, yofs+44, 110, 20, &G.scene->r.ffcodecdata.gop_size, 
1475                           0, 100, 0, 0, "Distance between key frames");
1476         uiDefButI(block, NUM, B_DIFF, "Buffersize", 
1477                           xcol2, yofs+22, 110, 20,
1478                           &G.scene->r.ffcodecdata.rc_buffer_size, 
1479                           0, 2000, 0, 0, "Rate control: buffer size (kb)");
1480         uiDefButI(block, NUM, B_DIFF, "Mux PSize", 
1481                           xcol2, yofs, 110, 20, 
1482                           &G.scene->r.ffcodecdata.mux_packet_size, 
1483                           0, 16384, 0, 0, "Mux packet size (byte)");
1484         
1485         uiDefButBitI(block, TOG, FFMPEG_AUTOSPLIT_OUTPUT, B_NOP,
1486                                  "Autosplit Output", 
1487                                  xcol2, yofs-22, 110, 20, 
1488                                  &G.scene->r.ffcodecdata.flags, 
1489                                  0, 1, 0,0, "Autosplit output at 2GB boundary.");
1490         
1491         
1492         if (ELEM(G.scene->r.ffcodecdata.type, FFMPEG_AVI, FFMPEG_MOV)) {
1493                 uiDefBut(block, LABEL, 0, "Codec", 
1494                                 xcol1, yofs-44, 110, 20, 0, 0, 0, 0, 0, "");
1495                 uiDefButI(block, MENU,B_REDR, ffmpeg_codec_pup(), 
1496                                   xcol1, yofs-66, 110, 20, 
1497                                   &G.scene->r.ffcodecdata.codec, 
1498                                   0,0,0,0, "FFMpeg codec to use");
1499         }
1500 }
1501
1502 static void render_panel_ffmpeg_audio(void)
1503 {
1504         uiBlock *block;
1505         int yofs;
1506         int xcol;
1507         
1508         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_audio", UI_EMBOSS, UI_HELV, curarea->win);
1509         uiNewPanelTabbed("Format", "Render");
1510         if (uiNewPanel(curarea, block, "Audio", "Render", 960, 0, 318, 204) == 0) return;
1511         
1512         yofs = 54;
1513         xcol = 892;
1514         
1515         uiDefButBitI(block, TOG, FFMPEG_MULTIPLEX_AUDIO, B_NOP,
1516                                  "Multiplex audio", xcol, yofs, 225, 20, 
1517                                  &G.scene->r.ffcodecdata.flags, 
1518                                  0, 1, 0,0, "Interleave audio with the output video");
1519         uiDefBut(block, LABEL, 0, "Codec", 
1520                          xcol, yofs-22, 225, 20, 0, 0, 0, 0, 0, "");
1521         uiDefButI(block, MENU,B_NOP, ffmpeg_audio_codec_pup(), 
1522                           xcol, yofs-44, 225, 20, 
1523                           &G.scene->r.ffcodecdata.audio_codec, 
1524                           0,0,0,0, "FFMpeg codec to use");
1525         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
1526                           xcol, yofs-66, 110, 20, 
1527                           &G.scene->r.ffcodecdata.audio_bitrate, 
1528                           32, 384, 0, 0, "Audio bitrate(kb/s)");
1529 }
1530 #endif
1531
1532 static void render_panel_stamp(void)
1533 {
1534         uiBlock *block;
1535         int yofs=0, xofs=550;
1536
1537         block= uiNewBlock (&curarea->uiblocks, "render_panel_stamp", UI_EMBOSS, UI_HELV, curarea->win);
1538         uiNewPanelTabbed ("Format", "Render");
1539         if(uiNewPanel (curarea, block, "Stamp", "Render", 960, 0, 318, 204)==0) return;
1540
1541         if (G.scene->r.scemode & R_STAMP_INFO) {
1542                 uiBlockBeginAlign(block);
1543                 uiDefButBitI(block, TOG, R_STAMP_NOTE, B_REDR, "Note", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp user data");
1544                 uiDefBut(block, TEX, B_NOP, "", xofs+100, yofs, 200, 19, &G.scene->r.stamp_udata, 0.0, 128.0, 100, 0, "User Note");
1545                 uiBlockEndAlign(block);
1546                 yofs += 30; /* gap */
1547                 
1548                 
1549                 yofs += 100;
1550                 // Order is important for alligning ... grr
1551                 uiBlockBeginAlign(block);
1552                 uiDefButBitI(block, TOG, R_STAMP_SCENE, B_REDR, "Scene", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp scene name");
1553                 yofs -= 20;
1554                 uiDefButBitI(block, TOG, R_STAMP_CAMERA, B_REDR, "Camera", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp camera name");
1555                 yofs -= 20;
1556                 uiDefButBitI(block, TOG, R_STAMP_DATE, B_REDR, "Date", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp date");
1557                 yofs -= 20;
1558                 uiDefButBitI(block, TOG, R_STAMP_TIME, B_REDR, "Time", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp time (HH:MM:SS)");
1559                 yofs -= 20;
1560                 uiDefButBitI(block, TOG, R_STAMP_FRAME, B_REDR, "Frame", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp frame number");
1561                 yofs -= 20;
1562                 uiDefButBitI(block, TOG, R_STAMP_MARKER, B_REDR, "Marker", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the last marker");
1563                 uiBlockEndAlign(block);
1564                 yofs += 100;
1565                 
1566                 /* draw font selector */
1567                 if (G.scene->r.stamp & R_STAMP_DRAW) {
1568                         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|",
1569                                         xofs+110, yofs, 190, 19, &G.scene->r.stamp_font_id, 0, 0, 0, 0, "Choose stamp text size");
1570                         
1571                         /* draw fg/bg next to the scene */
1572                         yofs -= 25;
1573                         uiDefBut(block, LABEL, B_NOP, "Text Color", xofs+110, yofs, 80, 19, 0, 0, 0, 0, 0, "");
1574                         uiDefBut(block, LABEL, B_NOP, "Background", xofs+205, yofs, 80, 19, 0, 0, 0, 0, 0, "");
1575                         yofs -= 20;
1576                         uiDefButF(block, COL, B_NOP, "", xofs+110, yofs, 90, 19, G.scene->r.fg_stamp, 0, 0, 0, 0, "Foreground text color");
1577                         uiDefButF(block, COL, B_NOP, "", xofs+210, yofs, 90, 19, G.scene->r.bg_stamp, 0, 0, 0, 0, "Background color");
1578                         yofs -= 30;
1579                         uiDefButF(block, NUMSLI, B_NOP, "A", xofs+110, yofs, 180, 19, &G.scene->r.bg_stamp[3], 0, 1.0, 0, 0, "Alpha for text background");
1580                         yofs += 105;
1581                 } else {
1582                         yofs += 30;
1583                 }
1584                 
1585                 uiDefButBitS(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, yofs, 100, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Disable stamp info in images metadata");
1586                 uiDefButBitI(block, TOG, R_STAMP_DRAW, B_REDR, "Draw Stamp", xofs+110, yofs, 190, 20, &G.scene->r.stamp, 0, 0, 0, 0, "Draw the stamp info into each frame");
1587                 yofs += 20;
1588         }
1589         else {
1590                 uiDefButBitS(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, 142, 100, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Enable stamp info to image metadata");
1591                 yofs += 20;
1592                 uiDefBut(block, LABEL, 0, "", xofs, yofs, 300, 19, 0, 0, 0, 0, 0, "");
1593         }
1594 }
1595
1596 static void render_panel_format(void)
1597 {
1598         uiBlock *block;
1599         int yofs;
1600
1601
1602         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
1603         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
1604         uiDefBlockBut(block, framing_render_menu, NULL, 
1605                                   "Game framing settings", 
1606                                   892, 169, 227, 20, "Display game framing settings");
1607         /* uiDefIconTextBlockBut(block, framing_render_menu, NULL, 
1608                                                    ICON_BLOCKBUT_CORNER, 
1609                                                    "Game framing settings", 
1610                                                    892, 169, 227, 20, 
1611                                                    "Display game framing settings"); */
1612
1613         uiBlockBeginAlign(block);
1614         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
1615         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
1616         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspX:",     892 ,114,112,20, &G.scene->r.xasp, 1.0,200.0, 0, 0, "The horizontal aspect ratio");
1617         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspY:",     1007,114,112,20, &G.scene->r.yasp, 1.0,200.0, 0, 0, "The vertical aspect ratio");
1618         uiBlockEndAlign(block);
1619
1620         yofs = 54;
1621
1622 #ifdef __sgi
1623         yofs = 76;
1624         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");
1625         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");
1626 #endif
1627
1628         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");
1629         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");
1630
1631         yofs -= 22;
1632
1633         if(G.scene->r.quality==0) G.scene->r.quality= 90;
1634
1635 #ifdef WITH_QUICKTIME
1636         if (G.scene->r.imtype == R_AVICODEC || G.scene->r.imtype == R_QUICKTIME) {
1637 #else /* WITH_QUICKTIME */
1638         if (0) {
1639 #endif
1640                 if(G.scene->r.imtype == R_QUICKTIME) {
1641 #ifdef WITH_QUICKTIME
1642 #if defined (_WIN32) || defined (__APPLE__)
1643                         //glColor3f(0.65, 0.65, 0.7);
1644                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1645                         if(G.scene->r.qtcodecdata == NULL)
1646                                 uiDefBut(block, LABEL, 0, "Codec: not set",  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1647                         else
1648                                 uiDefBut(block, LABEL, 0, G.scene->r.qtcodecdata->qtcodecname,  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1649                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,74,20, 0, 0, 0, 0, 0, "Set codec settings for Quicktime");
1650 #endif
1651 #endif /* WITH_QUICKTIME */
1652                 } else {
1653 #ifdef _WIN32
1654                         //glColor3f(0.65, 0.65, 0.7);
1655                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1656                         if(G.scene->r.avicodecdata == NULL)
1657                                 uiDefBut(block, LABEL, 0, "Codec: not set.",  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1658                         else
1659                                 uiDefBut(block, LABEL, 0, avicodec_str(),  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1660 #endif
1661                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,74,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
1662                 }
1663 #ifdef WITH_OPENEXR
1664         } 
1665         else if (ELEM(G.scene->r.imtype, R_OPENEXR, R_MULTILAYER)) {
1666                 if (G.scene->r.quality > 5) G.scene->r.quality = 2;
1667                 
1668                 if(G.scene->r.imtype==R_OPENEXR) {
1669                         uiBlockBeginAlign(block);
1670                         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");
1671                         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)");
1672                         uiBlockEndAlign(block);
1673                         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");
1674                 }               
1675                 uiDefButS(block, MENU,B_NOP, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",  
1676                                                                                                                         892,yofs,74,20, &G.scene->r.quality, 0, 0, 0, 0, "Set codec settings for OpenEXR");
1677                 
1678 #endif
1679         } else {
1680                 if(G.scene->r.quality < 5) G.scene->r.quality = 90;     /* restore from openexr */
1681                 
1682                 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");
1683         }
1684         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");
1685         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");
1686
1687
1688         uiBlockBeginAlign(block);
1689         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");
1690         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");
1691         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)");
1692
1693         uiBlockBeginAlign(block);
1694         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");
1695         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");
1696         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)");
1697         uiDefBut(block, BUT,B_PR_PRV, "Preview",        1146,110,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x512, Render size 50%");
1698         uiDefBut(block, BUT,B_PR_PC, "PC",                      1146,90,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x480, Aspect ratio - 100x100");
1699         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");
1700         uiDefBut(block, BUT,B_PR_PANO, "PANO",          1146,50,100,18, 0, 0, 0, 0, 0, "Standard panorama settings");
1701         uiDefBut(block, BUT,B_PR_FULL, "FULL",          1146,30,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1280x1024, Aspect ratio - 1x1");
1702         uiDefBut(block, BUT,B_PR_HD, "HD",              1146,10,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1920x1080, Aspect ratio - 1x1");
1703         uiBlockEndAlign(block);
1704 }
1705
1706 #ifndef DISABLE_YAFRAY /* disable yafray stuff */
1707 /* yafray: global illumination options panel */
1708 static void render_panel_yafrayGI()
1709 {
1710         uiBlock *block;
1711
1712         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGI", UI_EMBOSS, UI_HELV, curarea->win);
1713         uiNewPanelTabbed("Render", "Render");
1714         if(uiNewPanel(curarea, block, "YafRay GI", "Render", 320, 0, 318, 204)==0) return;
1715
1716         // label to force a boundbox for buttons not to be centered
1717         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
1718
1719         uiDefBut(block, LABEL, 0, "Method", 5,175,70,20, 0, 1.0, 0, 0, 0, "");
1720         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");
1721
1722         uiDefBut(block, LABEL, 0, "Quality", 5,150,70,20, 0, 1.0, 0, 0, 0, "");
1723         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");
1724
1725         if (G.scene->r.GImethod>0) {
1726                 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");
1727                 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");
1728         }
1729
1730         if (G.scene->r.GImethod>0)
1731         {
1732                 if (G.scene->r.GIdepth==0) G.scene->r.GIdepth=2;
1733
1734                 if (G.scene->r.GImethod==2) {
1735                         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");
1736                         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)");
1737                         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");
1738                 }
1739
1740                 uiDefButBitS(block, TOG, 1, B_REDR, "Cache",6,125,95,20, &G.scene->r.GIcache, 0, 0, 0, 0, "Cache occlusion/irradiance samples (faster)");
1741                 if (G.scene->r.GIcache) 
1742                 {
1743                         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)");
1744                         uiDefBut(block, LABEL, 0, "Cache parameters:", 5,105,130,20, 0, 1.0, 0, 0, 0, "");
1745                         if (G.scene->r.GIshadowquality==0.0) G.scene->r.GIshadowquality=0.9;
1746                         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 :-) ");
1747                         if (G.scene->r.GIpixelspersample==0) G.scene->r.GIpixelspersample=10;
1748                         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");
1749                         if (G.scene->r.GIrefinement==0) G.scene->r.GIrefinement=1.0;
1750                         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");
1751                 }
1752
1753                 if (G.scene->r.GImethod==2) {
1754                         if (G.scene->r.GIphotons)
1755                         {
1756                                 uiDefBut(block, LABEL, 0, "Photon parameters:", 170,105,130,20, 0, 1.0, 0, 0, 0, "");
1757                                 if(G.scene->r.GIphotoncount==0) G.scene->r.GIphotoncount=100000;
1758                                 uiDefButI(block, NUM, B_DIFF, "Count:", 170,85,140,20, &G.scene->r.GIphotoncount, 
1759                                                 0, 10000000, 10, 10, "Number of photons to shoot");
1760                                 if(G.scene->r.GIphotonradius==0.0) G.scene->r.GIphotonradius=1.0;
1761                                 uiDefButF(block, NUMSLI, B_DIFF,"Radius:", 170,60,140,20,       &(G.scene->r.GIphotonradius), 
1762                                                 0.00001, 100.0 ,0,0, "Radius to search for photons to mix (blur)");
1763                                 if(G.scene->r.GImixphotons==0) G.scene->r.GImixphotons=100;
1764                                 uiDefButI(block, NUM, B_DIFF, "MixCount:", 170,35,140,20, &G.scene->r.GImixphotons, 
1765                                                 0, 1000, 10, 10, "Number of photons to mix");
1766                                 uiDefButBitS(block, TOG, 1, B_REDR, "Tune Photons",170,10,140,20, &G.scene->r.GIdirect, 
1767                                                 0, 0, 0, 0, "Show the photonmap directly in the render for tuning");
1768                         }
1769                 }
1770
1771         }
1772 }
1773
1774 /* yafray: global  options panel */
1775 static void render_panel_yafrayGlobal()
1776 {
1777         uiBlock *block;
1778
1779         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGlobal", UI_EMBOSS, UI_HELV, curarea->win);
1780         uiNewPanelTabbed("Render", "Render");
1781         if(uiNewPanel(curarea, block, "YafRay", "Render", 320, 0, 318, 204)==0) return;
1782
1783         // label to force a boundbox for buttons not to be centered
1784         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
1785
1786         uiDefButBitS(block, TOGN, 1, B_REDR, "xml", 5,180,75,20, &G.scene->r.YFexportxml,
1787                                         0, 0, 0, 0, "Export to an xml file and call yafray instead of plugin");
1788
1789         uiDefButF(block, NUMSLI, B_DIFF,"Bi ", 5,35,150,20,     &(G.scene->r.YF_raybias), 
1790                                 0.0, 10.0 ,0,0, "Shadow ray bias to avoid self shadowing");
1791         uiDefButI(block, NUM, B_DIFF, "Raydepth ", 5,60,150,20,
1792                                 &G.scene->r.YF_raydepth, 1.0, 80.0, 10, 10, "Maximum render ray depth from the camera");
1793         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");
1794         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");
1795         
1796         uiDefButI(block, NUM, B_DIFF, "Processors:", 160,60,150,20, &G.scene->r.YF_numprocs, 1.0, 8.0, 10, 10, "Number of processors to use");
1797
1798         /*AA Settings*/
1799         uiDefButBitS(block, TOGN, 1, B_REDR, "Auto AA", 5,140,150,20, &G.scene->r.YF_AA, 
1800                                         0, 0, 0, 0, "Set AA using OSA and GI quality, disable for manual control");
1801         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.");
1802         if(G.scene->r.YF_AA){
1803                 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)");
1804                 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");
1805                 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");
1806                 uiDefButF(block, NUMSLI, B_DIFF, "Thr ", 160,90,150,20, &G.scene->r.YF_AAthreshold, 0.000001, 1.0, 0, 0, "AA threshold");
1807         }
1808 }
1809 #endif /* disable yafray stuff */
1810
1811 static void layer_copy_func(void *lay_v, void *lay_p)
1812 {
1813         unsigned int *lay= lay_p;
1814         int laybit= (int)lay_v;
1815
1816         if(G.qual & LR_SHIFTKEY) {
1817                 if(*lay==0) *lay= 1<<laybit;
1818         }
1819         else
1820                 *lay= 1<<laybit;
1821         
1822         copy_view3d_lock(REDRAW);
1823         allqueue(REDRAWBUTSSCENE, 0);
1824 }
1825
1826 static void delete_scene_layer_func(void *srl_v, void *act_i)
1827 {
1828         if(BLI_countlist(&G.scene->r.layers)>1) {
1829                 long act= (long)act_i;
1830                 
1831                 BLI_remlink(&G.scene->r.layers, srl_v);
1832                 MEM_freeN(srl_v);
1833                 G.scene->r.actlay= 0;
1834                 
1835                 if(G.scene->nodetree) {
1836                         bNode *node;
1837                         for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
1838                                 if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
1839                                         if(node->custom1==act)
1840                                                 node->custom1= 0;
1841                                         else if(node->custom1>act)
1842                                                 node->custom1--;
1843                                 }
1844                         }
1845                 }
1846                 allqueue(REDRAWBUTSSCENE, 0);
1847                 allqueue(REDRAWNODE, 0);
1848         }
1849 }
1850
1851 static void rename_scene_layer_func(void *srl_v, void *unused_v)
1852 {
1853         if(G.scene->nodetree) {
1854                 SceneRenderLayer *srl= srl_v;
1855                 bNode *node;
1856                 for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
1857                         if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
1858                                 if(node->custom1==G.scene->r.actlay)
1859                                         BLI_strncpy(node->name, srl->name, NODE_MAXSTR);
1860                         }
1861                 }
1862         }
1863         allqueue(REDRAWBUTSSCENE, 0);
1864         allqueue(REDRAWOOPS, 0);
1865         allqueue(REDRAWNODE, 0);
1866 }
1867
1868 static char *scene_layer_menu(void)
1869 {
1870         SceneRenderLayer *srl;
1871         int len= 32 + 32*BLI_countlist(&G.scene->r.layers);
1872         short a, nr;
1873         char *str= MEM_callocN(len, "menu layers");
1874         
1875         strcpy(str, "ADD NEW %x32767");
1876         a= strlen(str);
1877         for(nr=0, srl= G.scene->r.layers.first; srl; srl= srl->next, nr++) {
1878                 if(srl->layflag & SCE_LAY_DISABLE)
1879                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_BLANK1, nr);
1880                 else 
1881                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_CHECKBOX_HLT, nr);
1882         }
1883         
1884         return str;
1885 }
1886
1887 static void draw_3d_layer_buttons(uiBlock *block, unsigned int *poin, short xco, short yco, short dx, short dy)
1888 {
1889         uiBut *bt;
1890         long a;
1891         
1892         uiBlockBeginAlign(block);
1893         for(a=0; a<5; a++) {
1894                 bt= uiDefButBitI(block, TOG, 1<<a, B_NOP, "",   (short)(xco+a*(dx/2)), yco+dy/2, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1895                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
1896         }
1897         for(a=0; a<5; a++) {
1898                 bt=uiDefButBitI(block, TOG, 1<<(a+10), B_NOP, "",       (short)(xco+a*(dx/2)), yco, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1899                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
1900         }
1901         
1902         xco+= 7;
1903         uiBlockBeginAlign(block);
1904         for(a=5; a<10; a++) {
1905                 bt=uiDefButBitI(block, TOG, 1<<a, B_NOP, "",    (short)(xco+a*(dx/2)), yco+dy/2, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1906                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
1907         }
1908         for(a=5; a<10; a++) {
1909                 bt=uiDefButBitI(block, TOG, 1<<(a+10), B_NOP, "",       (short)(xco+a*(dx/2)), yco, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1910                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
1911         }
1912         
1913         uiBlockEndAlign(block);
1914 }
1915
1916 static void render_panel_layers(void)
1917 {
1918         uiBlock *block;
1919         uiBut *bt;
1920         SceneRenderLayer *srl= BLI_findlink(&G.scene->r.layers, G.scene->r.actlay);
1921         char *strp;
1922         
1923         if(srl==NULL) {
1924                 G.scene->r.actlay= 0;
1925                 srl= G.scene->r.layers.first;
1926         }
1927         
1928         block= uiNewBlock(&curarea->uiblocks, "render_panel_layers", UI_EMBOSS, UI_HELV, curarea->win);
1929         uiNewPanelTabbed("Output", "Render");
1930         if(uiNewPanel(curarea, block, "Render Layers", "Render", 320, 0, 318, 204)==0) return;
1931         
1932         /* first, as reminder, the scene layers */
1933         uiDefBut(block, LABEL, 0, "Scene:",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
1934         draw_3d_layer_buttons(block, &G.scene->lay,             130, 170, 35, 30);
1935         
1936         /* layer disable, menu, name, delete button */
1937         uiBlockBeginAlign(block);
1938         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");
1939         strp= scene_layer_menu();
1940         uiDefButS(block, MENU, B_ADD_RENDERLAYER, strp, 30,145,23,20, &(G.scene->r.actlay), 0, 0, 0, 0, "Choose Active Render Layer");
1941         MEM_freeN(strp);
1942         
1943         /* name max 20, exr format limit... */
1944         bt= uiDefBut(block, TEX, REDRAWNODE, "",  53,145,172,20, srl->name, 0.0, 20.0, 0, 0, "");
1945         uiButSetFunc(bt, rename_scene_layer_func, srl, NULL);
1946         
1947         uiDefButBitS(block, TOG, R_SINGLE_LAYER, B_NOP, "Single",       230,145,60,20, &G.scene->r.scemode, 0, 0, 0, 0, "Only render this layer");      
1948         bt=uiDefIconBut(block, BUT, B_NOP, ICON_X,      285, 145, 25, 20, 0, 0, 0, 0, 0, "Deletes current Render Layer");
1949         uiButSetFunc(bt, delete_scene_layer_func, srl, (void *)(long)G.scene->r.actlay);
1950         uiBlockEndAlign(block);
1951
1952         /* RenderLayer visible-layers */
1953         uiDefBut(block, LABEL, 0, "Layer:",                     10,110,100,20, NULL, 0, 0, 0, 0, "");
1954         draw_3d_layer_buttons(block, &srl->lay,         130,110, 35, 30);
1955         
1956         uiBlockBeginAlign(block);
1957         uiDefButBitI(block, TOG, SCE_LAY_ALL_Z, B_NOP,"AllZ",   10, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Fill in Z values for all not-rendered faces, for masking"); 
1958         uiBlockBeginAlign(block);
1959         uiDefButBitI(block, TOG, SCE_LAY_SOLID, B_NOP,"Solid",  50, 85, 60, 20, &srl->layflag, 0, 0, 0, 0, "Render Solid faces in this Layer"); 
1960         uiDefButBitI(block, TOG, SCE_LAY_HALO, B_NOP,"Halo",    110, 85, 55, 20, &srl->layflag, 0, 0, 0, 0, "Render Halos in this Layer (on top of Solid)");    
1961         uiDefButBitI(block, TOG, SCE_LAY_ZTRA, B_NOP,"Ztra",    165, 85, 55, 20, &srl->layflag, 0, 0, 0, 0, "Render Z-Transparent faces in this Layer (On top of Solid and Halos)");    
1962         uiDefButBitI(block, TOG, SCE_LAY_SKY, B_NOP,"Sky",              220, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Sky or backbuffer in this Layer");  
1963         uiDefButBitI(block, TOG, SCE_LAY_EDGE, B_NOP,"Edge",    260, 85, 50, 20, &srl->layflag, 0, 0, 0, 0, "Render Edge-enhance in this Layer (only works for Solid faces)");  
1964         
1965         uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_SET_PASS, "Light:",  10, 65, 150, 20, &(srl->light_override), "Name of Group to use as Lamps instead");
1966         uiDefIDPoinBut(block, test_matpoin_but, ID_MA, B_SET_PASS, "Mat:",      160, 65, 150, 20, &(srl->mat_override), "Name of Material to use as Materials instead");
1967         uiBlockEndAlign(block);
1968
1969         uiBlockBeginAlign(block);
1970         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");       
1971         uiDefButBitI(block, TOG, SCE_PASS_Z, B_SET_PASS,"Z",                    90, 30, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Z values pass");   
1972         uiDefButBitI(block, TOG, SCE_PASS_VECTOR, B_SET_PASS,"Vec",             120, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Speed Vector pass");      
1973         uiDefButBitI(block, TOG, SCE_PASS_NORMAL, B_SET_PASS,"Nor",             160, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Normal pass");    
1974         uiDefButBitI(block, TOG, SCE_PASS_UV, B_SET_PASS,"UV",                  200, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Texture UV pass");        
1975         uiDefButBitI(block, TOG, SCE_PASS_INDEXOB, B_SET_PASS,"IndexOb",240, 30, 70, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Object Index pass");      
1976         
1977         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");   
1978         uiDefButBitI(block, TOG, SCE_PASS_DIFFUSE, B_SET_PASS,"Diff",                   45, 10, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Diffuse pass");    
1979         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SPEC, B_SET_PASS,"Spec",              80, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Specular pass");   
1980         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SHADOW, B_SET_PASS,"Shad",    120, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Shadow pass");    
1981         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_AO, B_SET_PASS,"AO",                  160, 10, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver AO pass");        
1982         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");      
1983         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");      
1984         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_RADIO, B_SET_PASS,"Rad",              270, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Radiosity pass"); 
1985 }       
1986
1987 void render_panels()
1988 {
1989
1990         render_panel_output();
1991         render_panel_layers();
1992         render_panel_render();
1993         render_panel_anim();
1994         render_panel_bake();
1995
1996         render_panel_format();
1997         render_panel_stamp();
1998 #ifdef WITH_FFMPEG
1999        if (G.scene->r.imtype == R_FFMPEG) {
2000                    render_panel_ffmpeg_video();
2001                render_panel_ffmpeg_audio();
2002        }
2003 #endif
2004
2005 #ifndef DISABLE_YAFRAY
2006         /* yafray: GI & Global panel, only available when yafray enabled for rendering */
2007         if (G.scene->r.renderer==R_YAFRAY) {
2008                 if (G.scene->r.YF_gamma==0.0) G.scene->r.YF_gamma=1.0;
2009                 if (G.scene->r.YF_raybias==0.0) G.scene->r.YF_raybias=0.001;
2010                 if (G.scene->r.YF_raydepth==0) G.scene->r.YF_raydepth=5;
2011                 if (G.scene->r.YF_AApixelsize==0.0) G.scene->r.YF_AApixelsize=1.5;
2012                 if (G.scene->r.YF_AAthreshold==0.0) G.scene->r.YF_AAthreshold=0.05;
2013                 if (G.scene->r.GIpower==0.0) G.scene->r.GIpower=1.0;
2014                 if (G.scene->r.GIindirpower==0.0) G.scene->r.GIindirpower=1.0;
2015                 render_panel_yafrayGlobal();
2016                 render_panel_yafrayGI();
2017         }
2018 #endif
2019
2020 }
2021
2022 /* --------------------------------------------- */
2023
2024 void anim_panels()
2025 {
2026         uiBlock *block;
2027
2028         block= uiNewBlock(&curarea->uiblocks, "anim_panel", UI_EMBOSS, UI_HELV, curarea->win);
2029         if(uiNewPanel(curarea, block, "Anim", "Anim", 0, 0, 318, 204)==0) return;
2030
2031         uiBlockBeginAlign(block);
2032         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");
2033         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");
2034
2035         uiBlockBeginAlign(block);
2036         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");
2037         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");
2038
2039         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");
2040         
2041         uiBlockBeginAlign(block);
2042         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");
2043         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");
2044
2045         uiBlockBeginAlign(block);
2046         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");
2047
2048
2049 }
2050
2051 /* --------------------------------------------- */
2052
2053 void sound_panels()
2054 {
2055         bSound *sound;
2056
2057         /* paranoia check */
2058         sound = G.buts->lockpoin;
2059         if(sound && GS(sound->id.name)!=ID_SO) {
2060                 sound= NULL;
2061                 G.buts->lockpoin= NULL;
2062         }
2063         
2064         sound_panel_sound(sound);
2065         sound_panel_listener();
2066         sound_panel_sequencer();
2067 }
2068
2069
2070