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