Two in one:
[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
509         sprintf(str, "%s -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
510         system(str);
511 }
512
513 void playback_anim(void)
514 {       
515         char file[FILE_MAX];
516
517         if(BKE_imtype_is_movie(G.scene->r.imtype)) {
518                 switch (G.scene->r.imtype) {
519 #ifdef WITH_QUICKTIME
520                         case R_QUICKTIME:
521                                 makeqtstring(file);
522                                 break;
523 #endif
524 #ifdef WITH_FFMPEG
525                 case R_FFMPEG:
526                         makeffmpegstring(file);
527                         break;
528 #endif
529                 default:
530                         makeavistring(&G.scene->r, file);
531                         break;
532                 }
533                 if(BLI_exist(file)) {
534                         run_playanim(file);
535                 }
536                 else error("Can't find movie: %s", file);
537         }
538         else {
539                 BKE_makepicstring(file, G.scene->r.pic, G.scene->r.sfra, G.scene->r.imtype);
540                 if(BLI_exist(file)) {
541                         run_playanim(file);
542                 }
543                 else error("Can't find image: %s", file);
544         }
545 }
546
547 #ifdef WITH_FFMPEG
548 static void set_ffmpeg_preset(int preset);
549 #endif
550
551 void do_render_panels(unsigned short event)
552 {
553         ScrArea *sa;
554         ID *id;
555
556         switch(event) {
557
558         case B_DORENDER:
559                 BIF_do_render(0);
560                 break;
561         case B_RTCHANGED:
562                 allqueue(REDRAWALL, 0);
563                 break;
564         case B_SWITCHRENDER:
565                 /* new panels added, so... */
566                 G.buts->re_align= 1;
567                 allqueue(REDRAWBUTSSCENE, 0);
568                 break;
569         case B_PLAYANIM:
570                 playback_anim();
571                 break;
572                 
573         case B_DOANIM:
574                 BIF_do_render(1);
575                 break;
576         
577         case B_FS_PIC:
578                 sa= closest_bigger_area();
579                 areawinset(sa->win);
580                 if(G.qual == LR_CTRLKEY)
581                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
582                 else
583                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
584                 break;
585
586         case B_FS_BACKBUF:
587                 sa= closest_bigger_area();
588                 areawinset(sa->win);
589                 if(G.qual == LR_CTRLKEY)
590                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
591                 else
592                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
593                 break;
594
595         case B_FS_FTYPE:
596                 sa= closest_bigger_area();
597                 areawinset(sa->win);
598                 if(G.qual == LR_CTRLKEY)
599                         activate_imageselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
600                 else
601                         activate_fileselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
602                 break;
603         
604         case B_PR_PAL:
605                 G.scene->r.xsch= 720;
606                 G.scene->r.ysch= 576;
607                 G.scene->r.xasp= 54;
608                 G.scene->r.yasp= 51;
609                 G.scene->r.size= 100;
610                 G.scene->r.frs_sec= 25;
611                 G.scene->r.mode &= ~R_PANORAMA;
612                 G.scene->r.xparts=  G.scene->r.yparts= 4;
613 #ifdef WITH_FFMPEG
614                 G.scene->r.ffcodecdata.gop_size = 15;
615 #endif          
616                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
617                 BIF_undo_push("Set PAL");
618                 allqueue(REDRAWBUTSSCENE, 0);
619                 allqueue(REDRAWVIEWCAM, 0);
620                 break;
621
622         case B_FILETYPEMENU:
623                 allqueue(REDRAWBUTSSCENE, 0);
624 #ifdef WITH_FFMPEG
625                 if (G.scene->r.imtype == R_FFMPEG) {
626                         if (G.scene->r.ffcodecdata.type <= 0 ||
627                             G.scene->r.ffcodecdata.codec <= 0 ||
628                             G.scene->r.ffcodecdata.audio_codec <= 0 ||
629                             G.scene->r.ffcodecdata.video_bitrate <= 1) {
630                                 G.scene->r.ffcodecdata.codec 
631                                         = CODEC_ID_MPEG2VIDEO;
632                                 set_ffmpeg_preset(FFMPEG_PRESET_DVD);
633                         }
634
635                         if (G.scene->r.ffcodecdata.audio_codec <= 0) {
636                                 G.scene->r.ffcodecdata.audio_codec 
637                                         = CODEC_ID_MP2;
638                                 G.scene->r.ffcodecdata.audio_bitrate = 128;
639                         }
640                         break;
641                 }
642 #endif
643 #if defined (_WIN32) || defined (__APPLE__)
644                 // fall through to codec settings if this is the first
645                 // time R_AVICODEC is selected for this scene.
646                 if (((G.scene->r.imtype == R_AVICODEC) 
647                          && (G.scene->r.avicodecdata == NULL)) ||
648                         ((G.scene->r.imtype == R_QUICKTIME) 
649                          && (G.scene->r.qtcodecdata == NULL))) {
650                 } else {
651                   break;
652                 }
653 #endif /*_WIN32 || __APPLE__ */
654
655         case B_SELECTCODEC:
656 #if defined (_WIN32) || defined (__APPLE__)
657                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
658 #ifdef WITH_QUICKTIME
659                         get_qtcodec_settings();
660 #endif /* WITH_QUICKTIME */
661                 }
662 #if defined (_WIN32) && !defined(FREE_WINDOWS)
663                 else
664                         get_avicodec_settings();
665 #endif /* _WIN32 && !FREE_WINDOWS */
666 #endif /* _WIN32 || __APPLE__ */
667                 break;
668
669         case B_PR_HD:
670                 G.scene->r.xsch= 1920;
671                 G.scene->r.ysch= 1080;
672                 G.scene->r.xasp= 1;
673                 G.scene->r.yasp= 1;
674                 G.scene->r.size= 100;
675                 G.scene->r.mode &= ~R_PANORAMA;
676                 G.scene->r.xparts=  G.scene->r.yparts= 4;
677                 
678                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
679                 BIF_undo_push("Set FULL");
680                 allqueue(REDRAWBUTSSCENE, 0);
681                 allqueue(REDRAWVIEWCAM, 0);
682                 break;
683         case B_PR_FULL:
684                 G.scene->r.xsch= 1280;
685                 G.scene->r.ysch= 1024;
686                 G.scene->r.xasp= 1;
687                 G.scene->r.yasp= 1;
688                 G.scene->r.size= 100;
689                 G.scene->r.mode &= ~R_PANORAMA;
690                 G.scene->r.xparts=  G.scene->r.yparts= 4;
691
692                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
693                 BIF_undo_push("Set FULL");
694                 allqueue(REDRAWBUTSSCENE, 0);
695                 allqueue(REDRAWVIEWCAM, 0);
696                 break;
697         case B_PR_PRV:
698                 G.scene->r.xsch= 640;
699                 G.scene->r.ysch= 512;
700                 G.scene->r.xasp= 1;
701                 G.scene->r.yasp= 1;
702                 G.scene->r.size= 50;
703                 G.scene->r.mode &= ~R_PANORAMA;
704                 G.scene->r.xparts=  G.scene->r.yparts= 2;
705
706                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
707                 allqueue(REDRAWVIEWCAM, 0);
708                 allqueue(REDRAWBUTSSCENE, 0);
709                 break;
710         case B_PR_PAL169:
711                 G.scene->r.xsch= 720;
712                 G.scene->r.ysch= 576;
713                 G.scene->r.xasp= 64;
714                 G.scene->r.yasp= 45;
715                 G.scene->r.size= 100;
716                 G.scene->r.frs_sec= 25;
717                 G.scene->r.mode &= ~R_PANORAMA;
718                 G.scene->r.xparts=  G.scene->r.yparts= 4;
719 #ifdef WITH_FFMPEG
720                 G.scene->r.ffcodecdata.gop_size = 15;
721 #endif          
722
723                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
724                 BIF_undo_push("Set PAL 16/9");
725                 allqueue(REDRAWVIEWCAM, 0);
726                 allqueue(REDRAWBUTSSCENE, 0);
727                 break;
728         case B_PR_PC:
729                 G.scene->r.xsch= 640;
730                 G.scene->r.ysch= 480;
731                 G.scene->r.xasp= 100;
732                 G.scene->r.yasp= 100;
733                 G.scene->r.size= 100;
734                 G.scene->r.mode &= ~R_PANORAMA;
735                 G.scene->r.xparts=  G.scene->r.yparts= 4;
736
737                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
738                 BIF_undo_push("Set PC");
739                 allqueue(REDRAWVIEWCAM, 0);
740                 allqueue(REDRAWBUTSSCENE, 0);
741                 break;
742         case B_PR_PRESET:
743                 G.scene->r.xsch= 720;
744                 G.scene->r.ysch= 576;
745                 G.scene->r.xasp= 54;
746                 G.scene->r.yasp= 51;
747                 G.scene->r.size= 100;
748                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS;
749                 G.scene->r.imtype= R_TARGA;
750                 G.scene->r.xparts=  G.scene->r.yparts= 4;
751
752                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
753                 BIF_undo_push("Set Default");
754                 allqueue(REDRAWVIEWCAM, 0);
755                 allqueue(REDRAWBUTSSCENE, 0);
756                 break;
757         case B_PR_PANO:
758                 G.scene->r.xsch= 576;
759                 G.scene->r.ysch= 176;
760                 G.scene->r.xasp= 115;
761                 G.scene->r.yasp= 100;
762                 G.scene->r.size= 100;
763                 G.scene->r.mode |= R_PANORAMA;
764                 G.scene->r.xparts=  16;
765                 G.scene->r.yparts= 1;
766
767                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
768                 BIF_undo_push("Set Panorama");
769                 allqueue(REDRAWVIEWCAM, 0);
770                 allqueue(REDRAWBUTSSCENE, 0);
771                 break;
772         case B_PR_NTSC:
773                 G.scene->r.xsch= 720;
774                 G.scene->r.ysch= 480;
775                 G.scene->r.xasp= 10;
776                 G.scene->r.yasp= 11;
777                 G.scene->r.size= 100;
778                 G.scene->r.frs_sec= 30;
779                 G.scene->r.mode &= ~R_PANORAMA;
780                 G.scene->r.xparts=  G.scene->r.yparts= 2;
781 #ifdef WITH_FFMPEG
782                 G.scene->r.ffcodecdata.gop_size = 18;
783 #endif          
784                 
785                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
786                 BIF_undo_push("Set NTSC");
787                 allqueue(REDRAWBUTSSCENE, 0);
788                 allqueue(REDRAWVIEWCAM, 0);
789                 break;
790
791         case B_SETBROWSE:
792                 id= (ID*) G.scene->set;
793                 
794                 if (G.buts->menunr==-2) {
795                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
796                 } 
797                 else if (G.buts->menunr>0) {
798                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
799                         
800                         if (newset==G.scene)
801                                 error("Not allowed");
802                         else if (newset) {
803                                 G.scene->set= newset;
804                                 if (scene_check_setscene(G.scene)==0)
805                                         error("This would create a cycle");
806
807                                 allqueue(REDRAWBUTSSCENE, 0);
808                                 allqueue(REDRAWVIEW3D, 0);
809                                 BIF_undo_push("Change Set Scene");
810                         }
811                 }  
812                 break;
813         case B_CLEARSET:
814                 G.scene->set= NULL;
815                 allqueue(REDRAWBUTSSCENE, 0);
816                 allqueue(REDRAWVIEW3D, 0);
817                 BIF_undo_push("Clear Set Scene");
818                 
819                 break;
820         case B_SET_EDGE:
821                 allqueue(REDRAWBUTSSCENE, 0);
822                 break;
823         case B_SET_ZBLUR:
824                 G.scene->r.mode &= ~R_EDGE;
825                 allqueue(REDRAWBUTSSCENE, 0);
826                 break;
827         case B_ADD_RENDERLAYER:
828                 if(G.scene->r.actlay==32767) {
829                         scene_add_render_layer(G.scene);
830                         G.scene->r.actlay= BLI_countlist(&G.scene->r.layers) - 1;
831                 }
832                 allqueue(REDRAWBUTSSCENE, 0);
833                 allqueue(REDRAWNODE, 0);
834                 break;
835         case B_SET_PASS:
836                 if(G.scene->nodetree) {
837                         ntreeCompositForceHidden(G.scene->nodetree);
838                         allqueue(REDRAWNODE, 0);
839                 }
840                 allqueue(REDRAWBUTSSCENE, 0);
841                 allqueue(REDRAWOOPS, 0);
842         }
843 }
844
845 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
846 static uiBlock *edge_render_menu(void *arg_unused)
847 {
848         uiBlock *block;
849         
850         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
851                 
852         /* use this for a fake extra empy space around the buttons */
853         uiDefBut(block, LABEL, 0, "",  0, 0, 220, 115, NULL,  0, 0, 0, 0, "");
854         
855         uiDefButS(block, NUM, 0,"Eint:",        45,75,175,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
856                   "Sets edge intensity for Toon shading");
857
858         /* colour settings for the toon shading */
859         uiDefButF(block, COL, 0, "",            10, 10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, B_EDGECOLSLI, "");
860         
861         uiBlockBeginAlign(block);
862         uiDefButF(block, NUMSLI, 0, "R ",   45, 50, 175,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
863                   "Colour for edges in toon shading mode.");
864         uiDefButF(block, NUMSLI, 0, "G ",       45, 30, 175,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
865                   "Colour for edges in toon shading mode.");
866         uiDefButF(block, NUMSLI, 0, "B ",       45, 10, 175,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
867                   "Colour for edges in toon shading mode.");
868
869         
870         uiBlockSetDirection(block, UI_TOP);
871         
872         return block;
873 }
874
875
876 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
877 static uiBlock *framing_render_menu(void *arg_unused)
878 {
879         uiBlock *block;
880         short yco = 190, xco = 0;
881         int randomcolorindex = 1234;
882
883         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
884
885         /* use this for a fake extra empy space around the buttons */
886         uiDefBut(block, LABEL, 0, "",                   -5, -10, 295, 224, NULL, 0, 0, 0, 0, "");
887
888         uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
889         uiBlockBeginAlign(block);
890         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");
891         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");
892         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");
893         uiBlockEndAlign(block);
894
895         yco -= 25;
896         xco = 40;
897
898         uiDefButF(block, COL, 0, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, "");
899
900         uiBlockBeginAlign(block);
901         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");
902         yco -= 20;
903         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");
904         yco -= 20;
905         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");
906         uiBlockEndAlign(block);
907         
908         xco = 0;
909         uiDefBut(block, LABEL, 0, "Fullscreen:",                xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, "");
910         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");
911         uiBlockBeginAlign(block);
912         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.");
913         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.");
914         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.");
915         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.");
916         uiBlockEndAlign(block);
917
918         /* stereo settings */
919         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
920          * RAS_IRasterizer has definitions:
921          * RAS_STEREO_NOSTEREO           1
922          * RAS_STEREO_QUADBUFFERED 2
923          * RAS_STEREO_ABOVEBELOW         3
924          * RAS_STEREO_INTERLACED         4       future
925          * RAS_STEREO_ANAGLYPH          5
926          * RAS_STEREO_SIDEBYSIDE        6
927          * RAS_STEREO_VINTERLACE        7
928          */
929         uiBlockBeginAlign(block);
930         uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo");
931         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");
932         uiDefButS(block, ROW, 0, "Syncdouble", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
933         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");
934         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");
935         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");
936         
937         uiBlockEndAlign(block);
938
939         uiBlockSetDirection(block, UI_TOP);
940
941         return block;
942 }
943
944 #ifdef WITH_FFMPEG
945
946 static char* ffmpeg_format_pup(void) 
947 {
948         static char string[2048];
949         char formatstring[2048];
950 #if 0
951        int i = 0;
952        int stroffs = 0;
953        AVOutputFormat* next = first_oformat;
954        formatstring = "FFMpeg format: %%t";
955       sprintf(string, formatstring);
956        formatstring = "|%s %%x%d";
957        /* FIXME: This should only be generated once */
958        while (next != NULL) {
959                if (next->video_codec != CODEC_ID_NONE && !(next->flags & AVFMT_NOFILE)) {
960                        sprintf(string+stroffs, formatstring, next->name, i++);
961                        stroffs += strlen(string+stroffs);
962                }
963                next = next->next;
964        }
965        return string;
966 #endif
967        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");
968        sprintf(string, formatstring,
969                "MPEG-1", FFMPEG_MPEG1,
970                "MPEG-2", FFMPEG_MPEG2,
971                "MPEG-4", FFMPEG_MPEG4,
972                "AVI",    FFMPEG_AVI,
973                "Quicktime", FFMPEG_MOV,
974                "DV", FFMPEG_DV,
975                "H264", FFMPEG_H264,
976                "XVid", FFMPEG_XVID);
977        return string;
978 }
979
980 static char* ffmpeg_preset_pup(void) 
981 {
982         static char string[2048];
983         char formatstring[2048];
984
985        strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
986        sprintf(string, formatstring,
987                "", FFMPEG_PRESET_NONE,
988                "DVD", FFMPEG_PRESET_DVD,
989                "SVCD", FFMPEG_PRESET_SVCD,
990                "VCD", FFMPEG_PRESET_VCD,
991                "DV", FFMPEG_PRESET_DV);
992        return string;
993 }
994
995
996 static char* ffmpeg_codec_pup(void) {
997        static char string[2048];
998        char formatstring[2048];
999        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");
1000        sprintf(string, formatstring,
1001                "MPEG1", CODEC_ID_MPEG1VIDEO,
1002                "MPEG2", CODEC_ID_MPEG2VIDEO,
1003                "MPEG4(divx)", CODEC_ID_MPEG4,
1004                "HuffYUV", CODEC_ID_HUFFYUV,
1005                "DV", CODEC_ID_DVVIDEO,
1006                "H264", CODEC_ID_H264,
1007                "XVid", CODEC_ID_XVID);
1008        return string;
1009
1010 }
1011
1012 static char* ffmpeg_audio_codec_pup(void) {
1013        static char string[2048];
1014        char formatstring[2048];
1015        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1016        sprintf(string, formatstring,
1017                "MP2", CODEC_ID_MP2,
1018                "MP3", CODEC_ID_MP3,
1019                "AC3", CODEC_ID_AC3,
1020                "AAC", CODEC_ID_AAC,
1021                "PCM", CODEC_ID_PCM_S16LE);
1022        return string;
1023
1024 }
1025
1026 #endif
1027
1028 static char *imagetype_pup(void)
1029 {
1030         static char string[1024];
1031         char formatstring[1024];
1032         char appendstring[1024];
1033
1034         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");
1035
1036 #ifdef __sgi
1037         strcat(formatstring, "|%s %%x%d");      // add space for Movie
1038 #endif
1039
1040         strcat(formatstring, "|%s %%x%d");      // add space for PNG
1041         strcat(formatstring, "|%s %%x%d");      // add space for BMP
1042         strcat(formatstring, "|%s %%x%d");      // add space for Radiance HDR
1043         strcat(formatstring, "|%s %%x%d");      // add space for Cineon
1044         strcat(formatstring, "|%s %%x%d");      // add space for DPX
1045         
1046 #ifdef _WIN32
1047         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
1048 #endif
1049
1050 #ifdef WITH_FFMPEG
1051        strcat(formatstring, "|%s %%x%d"); // Add space for ffmpeg
1052 #endif
1053        strcat(formatstring, "|%s %%x%d"); // Add space for frameserver
1054
1055 #ifdef WITH_QUICKTIME
1056         if(G.have_quicktime)
1057                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
1058 #endif
1059
1060         if(G.have_quicktime) {
1061                 sprintf(string, formatstring,
1062                         "Frameserver",   R_FRAMESERVER,
1063 #ifdef WITH_FFMPEG
1064                        "FFMpeg",         R_FFMPEG,
1065 #endif
1066                         "AVI Raw",        R_AVIRAW,
1067                         "AVI Jpeg",       R_AVIJPEG,
1068 #ifdef _WIN32
1069                         "AVI Codec",      R_AVICODEC,
1070 #endif
1071 #ifdef WITH_QUICKTIME
1072                         "QuickTime",      R_QUICKTIME,
1073 #endif
1074                         "Targa",          R_TARGA,
1075                         "Targa Raw",      R_RAWTGA,
1076                         "PNG",            R_PNG,
1077                         "BMP",            R_BMP,
1078                         "Jpeg",           R_JPEG90,
1079                         "HamX",           R_HAMX,
1080                         "Iris",           R_IRIS,
1081                         "Radiance HDR",   R_RADHDR,
1082                         "Cineon",                 R_CINEON,
1083                         "DPX",                    R_DPX
1084 #ifdef __sgi
1085                         ,"Movie",          R_MOVIE
1086 #endif
1087                 );
1088         } else {
1089                 sprintf(string, formatstring,
1090                         "Frameserver",   R_FRAMESERVER,
1091 #ifdef WITH_FFMPEG
1092                        "FFMpeg",         R_FFMPEG,
1093 #endif
1094                         "AVI Raw",        R_AVIRAW,
1095                         "AVI Jpeg",       R_AVIJPEG,
1096 #ifdef _WIN32
1097                         "AVI Codec",      R_AVICODEC,
1098 #endif
1099                         "Targa",          R_TARGA,
1100                         "Targa Raw",      R_RAWTGA,
1101                         "PNG",            R_PNG,
1102                         "BMP",            R_BMP,
1103                         "Jpeg",           R_JPEG90,
1104                         "HamX",           R_HAMX,
1105                         "Iris",           R_IRIS,
1106                         "Radiance HDR",   R_RADHDR,
1107                         "Cineon",                 R_CINEON,
1108                         "DPX",                    R_DPX
1109 #ifdef __sgi
1110                         ,"Movie",          R_MOVIE
1111 #endif
1112                 );
1113         }
1114
1115 #ifdef WITH_OPENEXR
1116         strcpy(formatstring, "|%s %%x%d");
1117         sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
1118         strcat(string, appendstring);
1119         sprintf(appendstring, formatstring, "MultiLayer", R_MULTILAYER);
1120         strcat(string, appendstring);
1121 #endif
1122         
1123         if (G.have_libtiff) {
1124                 strcpy(formatstring, "|%s %%x%d");
1125                 sprintf(appendstring, formatstring, "TIFF", R_TIFF);
1126                 strcat(string, appendstring);
1127         }
1128
1129         return (string);
1130 }
1131
1132 #ifdef _WIN32
1133 static char *avicodec_str(void)
1134 {
1135         static char string[1024];
1136
1137         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
1138
1139         return string;
1140 }
1141 #endif
1142
1143 static void render_panel_output(void)
1144 {
1145         ID *id;
1146         int a,b;
1147         uiBlock *block;
1148         char *strp;
1149
1150
1151         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
1152         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
1153         
1154         uiBlockBeginAlign(block);
1155         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        10, 190, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Pics dir/name");
1156         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");
1157         uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
1158         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");
1159         uiDefIconBut(block, BUT,B_FS_FTYPE, ICON_FILESEL,       10, 146, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Ftype image");
1160         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");
1161         uiBlockEndAlign(block);
1162         
1163         
1164         /* SET BUTTON */
1165         uiBlockBeginAlign(block);
1166         id= (ID *)G.scene->set;
1167         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
1168         if(strp[0])
1169                 uiDefButS(block, MENU, B_SETBROWSE, strp, 10, 120, 20, 20, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
1170         MEM_freeN(strp);
1171
1172         if(G.scene->set) {
1173                 uiSetButLock(1, NULL);
1174                 uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, B_NOP, "",    31, 120, 100, 20, &(G.scene->set), "Name of the Set");
1175                 uiClearButLock();
1176                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            132, 120, 20, 20, 0, 0, 0, 0, 0, "Remove Set link");
1177         }
1178         uiBlockEndAlign(block);
1179
1180         uiBlockSetCol(block, TH_BUT_SETTING1);
1181         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");        
1182         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");    
1183         uiBlockSetCol(block, TH_AUTO);
1184                 
1185         uiBlockBeginAlign(block);
1186         for(b=2; b>=0; b--)
1187                 for(a=0; a<3; a++)
1188                         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");
1189         uiBlockEndAlign(block);
1190
1191         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");
1192         
1193         uiDefButS(block, MENU, B_REDR, "Render Display %t|Render Window %x1|Image Editor %x0|Full Screen %x2",  
1194                                         72, 10, 120, 19, &G.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output display");
1195
1196         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");
1197
1198         /* Dither control */
1199         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)");
1200         
1201         /* Toon shading buttons */
1202         uiBlockBeginAlign(block);
1203         uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   100, 94, 70, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
1204         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 170, 94, 140, 20, "Display Edge settings");
1205         uiBlockEndAlign(block);
1206         
1207         uiBlockBeginAlign(block);
1208         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");
1209         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");
1210         uiBlockEndAlign(block);
1211 }
1212
1213 static void do_bake_func(void *unused_v, void *unused_p)
1214 {
1215         objects_bake_render(0);
1216 }
1217
1218 static void render_panel_bake(void)
1219 {
1220         uiBlock *block;
1221         uiBut *but;
1222         
1223         block= uiNewBlock(&curarea->uiblocks, "render_panel_bake", UI_EMBOSS, UI_HELV, curarea->win);
1224         uiNewPanelTabbed("Anim", "Render");
1225         if(uiNewPanel(curarea, block, "Bake", "Render", 320, 0, 318, 204)==0) return;
1226         
1227         but= uiDefBut(block, BUT, B_NOP, "BAKE",        10, 150, 190,40, 0, 0, 0, 0, 0, "Start the bake render for selected Objects");
1228         uiButSetFunc(but, do_bake_func, NULL, NULL);
1229 #if 0   
1230         uiBlockBeginAlign(block);
1231         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)");
1232         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");
1233         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");
1234         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");
1235         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");
1236 #endif  
1237         uiBlockBeginAlign(block);
1238         uiDefButS(block, ROW,B_DIFF,"Full Render",              210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, "");
1239         uiDefButS(block, ROW,B_DIFF,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, "");
1240         uiDefButS(block, ROW,B_DIFF,"Normals",          210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, "");
1241         uiDefButS(block, ROW,B_DIFF,"Textures",         210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, "");
1242         uiBlockEndAlign(block);
1243         
1244         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");
1245         
1246         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");
1247 }
1248
1249 static void render_panel_render(void)
1250 {
1251         uiBlock *block;
1252         char str[256];
1253
1254         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
1255         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
1256
1257         uiBlockBeginAlign(block);
1258         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369, 164, 191,37, 0, 0, 0, 0, 0, "Start the rendering");
1259 #ifndef DISABLE_YAFRAY
1260         /* yafray: on request, render engine menu is back again, and moved to Render panel */
1261         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0|YafRay %x1", 
1262                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
1263 #else
1264         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0", 
1265                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
1266 #endif /* disable yafray */
1267
1268         uiBlockBeginAlign(block);
1269         uiDefButBitI(block, TOG, R_OSA, B_DIFF, "OSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
1270         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");
1271         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)");
1272         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");
1273         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");
1274         uiBlockEndAlign(block);
1275
1276         uiBlockBeginAlign(block);
1277         uiDefButBitI(block, TOG, R_MBLUR, 0, "MBLUR",   496,109,64,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
1278         uiDefButF(block, NUM,B_DIFF,"Bf:",                      496,88,64,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
1279         uiBlockEndAlign(block);
1280
1281         uiBlockBeginAlign(block);
1282         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)");
1283         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");
1284         uiBlockEndAlign(block);
1285
1286         uiBlockBeginAlign(block);
1287         uiDefButS(block, ROW,800,"Sky",         369,13,35,20,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
1288         uiDefButS(block, ROW,800,"Premul",      405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
1289         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");
1290         uiBlockEndAlign(block);
1291
1292         if(G.scene->r.mode & R_RAYTRACE)
1293                 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");
1294
1295         uiBlockBeginAlign(block);
1296         uiDefButBitI(block, TOG, R_SHADOW, 0,"Shadow",  565,172,60,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
1297         uiDefButBitI(block, TOG, R_ENVMAP, 0,"EnvMap",  627,172,60,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map rendering");
1298         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)");
1299         uiDefButBitI(block, TOG, R_RAYTRACE, B_REDR,"Ray",606,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
1300         uiDefButBitI(block, TOG, R_RADIO, 0,"Radio",    647,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
1301         uiBlockEndAlign(block);
1302         
1303         uiBlockBeginAlign(block);
1304         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");
1305         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");
1306         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");
1307         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");
1308         uiBlockEndAlign(block);
1309
1310         uiBlockBeginAlign(block);
1311         uiDefButBitI(block, TOG, R_FIELDS, 0,"Fields",  565,55,60,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
1312         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)");
1313         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");
1314         
1315         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);
1316         uiDefButS(block, MENU, B_DIFF,str,              565,34,60,20, &G.scene->r.filtertype, 0, 0, 0, 0, "Set sampling filter for antialiasing");
1317         uiDefButF(block, NUM,B_DIFF,"",                 627,34,60,20,&G.scene->r.gauss,0.5, 1.5, 10, 2, "Sets the filter size");
1318         
1319         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");
1320         uiBlockEndAlign(block);
1321
1322 }
1323
1324 static void render_panel_anim(void)
1325 {
1326         uiBlock *block;
1327
1328
1329         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1330         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
1331
1332
1333         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Start rendering a sequence");
1334
1335         uiBlockSetCol(block, TH_BUT_SETTING1);
1336         uiBlockBeginAlign(block);
1337         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)");
1338         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");
1339         uiBlockEndAlign(block);
1340
1341         uiBlockSetCol(block, TH_AUTO);
1342         uiDefBut(block, BUT,B_PLAYANIM, "PLAY",692,40,94,33, 0, 0, 0, 0, 0, "Play animation of rendered images/avi (searches Pics: field)");
1343         uiDefButS(block, NUM, B_RTCHANGED, "rt:",789,40,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
1344
1345         uiBlockBeginAlign(block);
1346         uiDefButI(block, NUM,REDRAWSEQ,"Sta:",692,10,94,24, &G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "The start frame of the animation");
1347         uiDefButI(block, NUM,REDRAWSEQ,"End:",789,10,95,24, &G.scene->r.efra,SFRA,MAXFRAMEF, 0, 0, "The end  frame of the animation");
1348         uiBlockEndAlign(block);
1349 }
1350
1351 #ifdef WITH_FFMPEG
1352 static void set_ffmpeg_preset(int preset)
1353 {
1354         int isntsc = (G.scene->r.frs_sec != 25);
1355         switch (preset) {
1356         case FFMPEG_PRESET_VCD:
1357                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG1;
1358                 G.scene->r.ffcodecdata.video_bitrate = 1150;
1359                 G.scene->r.xsch = 352;
1360                 G.scene->r.ysch = isntsc ? 240 : 288;
1361                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1362                 G.scene->r.ffcodecdata.rc_max_rate = 1150;
1363                 G.scene->r.ffcodecdata.rc_min_rate = 1150;
1364                 G.scene->r.ffcodecdata.rc_buffer_size = 40*8;
1365                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
1366                 G.scene->r.ffcodecdata.mux_rate = 2352 * 75 * 8;
1367                 break;
1368         case FFMPEG_PRESET_SVCD:
1369                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
1370                 G.scene->r.ffcodecdata.video_bitrate = 2040;
1371                 G.scene->r.xsch = 480;
1372                 G.scene->r.ysch = isntsc ? 480 : 576;
1373                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1374                 G.scene->r.ffcodecdata.rc_max_rate = 2516;
1375                 G.scene->r.ffcodecdata.rc_min_rate = 0;
1376                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
1377                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
1378                 G.scene->r.ffcodecdata.mux_rate = 0;
1379                 
1380                 break;
1381         case FFMPEG_PRESET_DVD:
1382                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
1383                 G.scene->r.ffcodecdata.video_bitrate = 6000;
1384                 G.scene->r.xsch = 720;
1385                 G.scene->r.ysch = isntsc ? 480 : 576;
1386                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1387                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
1388                 G.scene->r.ffcodecdata.rc_min_rate = 0;
1389                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
1390                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
1391                 G.scene->r.ffcodecdata.mux_rate = 10080000;
1392                 
1393                 break;
1394         case FFMPEG_PRESET_DV:
1395                 G.scene->r.ffcodecdata.type = FFMPEG_DV;
1396                 G.scene->r.xsch = 720;
1397                 G.scene->r.ysch = isntsc ? 480 : 576;
1398                 break;
1399         }
1400 }
1401
1402 static void render_panel_ffmpeg_video(void)
1403 {
1404         uiBlock *block;
1405         int yofs;
1406         int xcol1;
1407         int xcol2;
1408         
1409         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_video", 
1410                                            UI_EMBOSS, UI_HELV, curarea->win);
1411         
1412         uiNewPanelTabbed("Format", "Render");
1413         if (uiNewPanel(curarea, block, "Video", "Render", 960, 0, 318, 204)== 0) 
1414                 return;
1415         
1416         if (ffmpeg_preset_sel != 0) {
1417                 set_ffmpeg_preset(ffmpeg_preset_sel);
1418                 ffmpeg_preset_sel = 0;
1419                 allqueue(REDRAWBUTSSCENE, 0);
1420         }
1421         
1422         xcol1 = 872;
1423         xcol2 = 1002;
1424         
1425         yofs = 54;
1426         uiDefBut(block, LABEL, B_DIFF, "Format", xcol1, yofs+88, 
1427                          110, 20, 0, 0, 0, 0, 0, "");
1428         uiDefBut(block, LABEL, B_DIFF, "Preset", xcol2, yofs+88, 
1429                          110, 20, 0, 0, 0, 0, 0, "");
1430         uiDefButI(block, MENU, B_DIFF, ffmpeg_format_pup(), 
1431                           xcol1, yofs+66, 110, 20, &G.scene->r.ffcodecdata.type, 
1432                           0,0,0,0, "output file format");
1433         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
1434                           xcol1, yofs+44, 110, 20, 
1435                           &G.scene->r.ffcodecdata.video_bitrate, 
1436                           1, 14000, 0, 0, "Video bitrate(kb/s)");
1437         uiDefButI(block, NUM, B_DIFF, "Min Rate", 
1438                           xcol1, yofs+22, 110, 20, &G.scene->r.ffcodecdata.rc_min_rate, 
1439                           0, 14000, 0, 0, "Rate control: min rate(kb/s)");
1440         uiDefButI(block, NUM, B_DIFF, "Max Rate", 
1441                           xcol1, yofs, 110, 20, &G.scene->r.ffcodecdata.rc_max_rate, 
1442                           1, 14000, 0, 0, "Rate control: max rate(kb/s)");
1443         
1444         uiDefButI(block, NUM, B_DIFF, "Mux Rate", 
1445                           xcol1, yofs-22, 110, 20, 
1446                           &G.scene->r.ffcodecdata.mux_rate, 
1447                           0, 100000000, 0, 0, "Mux rate (bits/s(!))");
1448         
1449         
1450         uiDefButI(block, MENU, B_REDR, ffmpeg_preset_pup(), 
1451                           xcol2, yofs+66, 110, 20, &ffmpeg_preset_sel, 
1452                           0,0,0,0, "Output file format preset selection");
1453         uiDefButI(block, NUM, B_DIFF, "GOP Size", 
1454                           xcol2, yofs+44, 110, 20, &G.scene->r.ffcodecdata.gop_size, 
1455                           0, 100, 0, 0, "Distance between key frames");
1456         uiDefButI(block, NUM, B_DIFF, "Buffersize", 
1457                           xcol2, yofs+22, 110, 20,
1458                           &G.scene->r.ffcodecdata.rc_buffer_size, 
1459                           0, 2000, 0, 0, "Rate control: buffer size (kb)");
1460         uiDefButI(block, NUM, B_DIFF, "Mux PSize", 
1461                           xcol2, yofs, 110, 20, 
1462                           &G.scene->r.ffcodecdata.mux_packet_size, 
1463                           0, 16384, 0, 0, "Mux packet size (byte)");
1464         
1465         uiDefButBitI(block, TOG, FFMPEG_AUTOSPLIT_OUTPUT, B_NOP,
1466                                  "Autosplit Output", 
1467                                  xcol2, yofs-22, 110, 20, 
1468                                  &G.scene->r.ffcodecdata.flags, 
1469                                  0, 1, 0,0, "Autosplit output at 2GB boundary.");
1470         
1471         
1472         if (ELEM(G.scene->r.ffcodecdata.type, FFMPEG_AVI, FFMPEG_MOV)) {
1473                 uiDefBut(block, LABEL, 0, "Codec", 
1474                                 xcol1, yofs-44, 110, 20, 0, 0, 0, 0, 0, "");
1475                 uiDefButI(block, MENU,B_REDR, ffmpeg_codec_pup(), 
1476                                   xcol1, yofs-66, 110, 20, 
1477                                   &G.scene->r.ffcodecdata.codec, 
1478                                   0,0,0,0, "FFMpeg codec to use");
1479         }
1480 }
1481
1482 static void render_panel_ffmpeg_audio(void)
1483 {
1484         uiBlock *block;
1485         int yofs;
1486         int xcol;
1487         
1488         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_audio", UI_EMBOSS, UI_HELV, curarea->win);
1489         uiNewPanelTabbed("Format", "Render");
1490         if (uiNewPanel(curarea, block, "Audio", "Render", 960, 0, 318, 204) == 0) return;
1491         
1492         yofs = 54;
1493         xcol = 892;
1494         
1495         uiDefButBitI(block, TOG, FFMPEG_MULTIPLEX_AUDIO, B_NOP,
1496                                  "Multiplex audio", xcol, yofs, 225, 20, 
1497                                  &G.scene->r.ffcodecdata.flags, 
1498                                  0, 1, 0,0, "Interleave audio with the output video");
1499         uiDefBut(block, LABEL, 0, "Codec", 
1500                          xcol, yofs-22, 225, 20, 0, 0, 0, 0, 0, "");
1501         uiDefButI(block, MENU,B_NOP, ffmpeg_audio_codec_pup(), 
1502                           xcol, yofs-44, 225, 20, 
1503                           &G.scene->r.ffcodecdata.audio_codec, 
1504                           0,0,0,0, "FFMpeg codec to use");
1505         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
1506                           xcol, yofs-66, 110, 20, 
1507                           &G.scene->r.ffcodecdata.audio_bitrate, 
1508                           32, 384, 0, 0, "Audio bitrate(kb/s)");
1509 }
1510 #endif
1511
1512
1513 static void render_panel_format(void)
1514 {
1515         uiBlock *block;
1516         int yofs;
1517
1518
1519         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
1520         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
1521         uiDefBlockBut(block, framing_render_menu, NULL, 
1522                                   "Game framing settings", 
1523                                   892, 169, 227, 20, "Display game framing settings");
1524         /* uiDefIconTextBlockBut(block, framing_render_menu, NULL, 
1525                                                    ICON_BLOCKBUT_CORNER, 
1526                                                    "Game framing settings", 
1527                                                    892, 169, 227, 20, 
1528                                                    "Display game framing settings"); */
1529
1530         uiBlockBeginAlign(block);
1531         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
1532         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
1533         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspX:",     892 ,114,112,20, &G.scene->r.xasp, 1.0,200.0, 0, 0, "The horizontal aspect ratio");
1534         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspY:",     1007,114,112,20, &G.scene->r.yasp, 1.0,200.0, 0, 0, "The vertical aspect ratio");
1535         uiBlockEndAlign(block);
1536
1537         yofs = 54;
1538
1539 #ifdef __sgi
1540         yofs = 76;
1541         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");
1542         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");
1543 #endif
1544
1545         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");
1546         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");
1547
1548         yofs -= 22;
1549
1550         if(G.scene->r.quality==0) G.scene->r.quality= 90;
1551
1552 #ifdef WITH_QUICKTIME
1553         if (G.scene->r.imtype == R_AVICODEC || G.scene->r.imtype == R_QUICKTIME) {
1554 #else /* WITH_QUICKTIME */
1555         if (0) {
1556 #endif
1557                 if(G.scene->r.imtype == R_QUICKTIME) {
1558 #ifdef WITH_QUICKTIME
1559 #if defined (_WIN32) || defined (__APPLE__)
1560                         //glColor3f(0.65, 0.65, 0.7);
1561                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1562                         if(G.scene->r.qtcodecdata == NULL)
1563                                 uiDefBut(block, LABEL, 0, "Codec: not set",  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1564                         else
1565                                 uiDefBut(block, LABEL, 0, G.scene->r.qtcodecdata->qtcodecname,  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1566                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for Quicktime");
1567 #endif
1568 #endif /* WITH_QUICKTIME */
1569                 } else {
1570 #ifdef _WIN32
1571                         //glColor3f(0.65, 0.65, 0.7);
1572                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1573                         if(G.scene->r.avicodecdata == NULL)
1574                                 uiDefBut(block, LABEL, 0, "Codec: not set.",  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1575                         else
1576                                 uiDefBut(block, LABEL, 0, avicodec_str(),  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1577 #endif
1578                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
1579                 }
1580 #ifdef WITH_OPENEXR
1581         } 
1582         else if (ELEM(G.scene->r.imtype, R_OPENEXR, R_MULTILAYER)) {
1583                 if (G.scene->r.quality > 5) G.scene->r.quality = 2;
1584                 
1585                 if(G.scene->r.imtype==R_OPENEXR) {
1586                         uiBlockBeginAlign(block);
1587                         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");
1588                         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");
1589                         uiBlockEndAlign(block);
1590                         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");
1591                 }               
1592                 uiDefButS(block, MENU,B_NOP, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",  
1593                                                                                                                         892,yofs,112,20, &G.scene->r.quality, 0, 0, 0, 0, "Set codec settings for OpenEXR");
1594                 
1595 #endif
1596         } else {
1597                 if(G.scene->r.quality < 5) G.scene->r.quality = 90;     /* restore from openexr */
1598                 
1599                 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");
1600         }
1601         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");
1602
1603
1604         uiBlockBeginAlign(block);
1605         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");
1606         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");
1607         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)");
1608
1609         uiBlockBeginAlign(block);
1610         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");
1611         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");
1612         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)");
1613         uiDefBut(block, BUT,B_PR_PRV, "Preview",        1146,110,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x512, Render size 50%");
1614         uiDefBut(block, BUT,B_PR_PC, "PC",                      1146,90,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x480, Aspect ratio - 100x100");
1615         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");
1616         uiDefBut(block, BUT,B_PR_PANO, "PANO",          1146,50,100,18, 0, 0, 0, 0, 0, "Standard panorama settings");
1617         uiDefBut(block, BUT,B_PR_FULL, "FULL",          1146,30,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1280x1024, Aspect ratio - 1x1");
1618         uiDefBut(block, BUT,B_PR_HD, "HD",              1146,10,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1920x1080, Aspect ratio - 1x1");
1619         uiBlockEndAlign(block);
1620 }
1621
1622
1623 /* yafray: global illumination options panel */
1624 static void render_panel_yafrayGI()
1625 {
1626         uiBlock *block;
1627
1628         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGI", UI_EMBOSS, UI_HELV, curarea->win);
1629         uiNewPanelTabbed("Render", "Render");
1630         if(uiNewPanel(curarea, block, "YafRay GI", "Render", 320, 0, 318, 204)==0) return;
1631
1632         // label to force a boundbox for buttons not to be centered
1633         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
1634
1635         uiDefBut(block, LABEL, 0, "Method", 5,175,70,20, 0, 1.0, 0, 0, 0, "");
1636         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");
1637
1638         uiDefBut(block, LABEL, 0, "Quality", 5,150,70,20, 0, 1.0, 0, 0, 0, "");
1639         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");
1640
1641         if (G.scene->r.GImethod>0) {
1642                 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");
1643                 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");
1644         }
1645
1646         if (G.scene->r.GImethod>0)
1647         {
1648                 if (G.scene->r.GIdepth==0) G.scene->r.GIdepth=2;
1649
1650                 if (G.scene->r.GImethod==2) {
1651                         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");
1652                         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)");
1653                         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");
1654                 }
1655
1656                 uiDefButBitS(block, TOG, 1, B_REDR, "Cache",6,125,95,20, &G.scene->r.GIcache, 0, 0, 0, 0, "Cache occlusion/irradiance samples (faster)");
1657                 if (G.scene->r.GIcache) 
1658                 {
1659                         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)");
1660                         uiDefBut(block, LABEL, 0, "Cache parameters:", 5,105,130,20, 0, 1.0, 0, 0, 0, "");
1661                         if (G.scene->r.GIshadowquality==0.0) G.scene->r.GIshadowquality=0.9;
1662                         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 :-) ");
1663                         if (G.scene->r.GIpixelspersample==0) G.scene->r.GIpixelspersample=10;
1664                         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");
1665                         if (G.scene->r.GIrefinement==0) G.scene->r.GIrefinement=1.0;
1666                         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");
1667                 }
1668
1669                 if (G.scene->r.GImethod==2) {
1670                         if (G.scene->r.GIphotons)
1671                         {
1672                                 uiDefBut(block, LABEL, 0, "Photon parameters:", 170,105,130,20, 0, 1.0, 0, 0, 0, "");
1673                                 if(G.scene->r.GIphotoncount==0) G.scene->r.GIphotoncount=100000;
1674                                 uiDefButI(block, NUM, B_DIFF, "Count:", 170,85,140,20, &G.scene->r.GIphotoncount, 
1675                                                 0, 10000000, 10, 10, "Number of photons to shoot");
1676                                 if(G.scene->r.GIphotonradius==0.0) G.scene->r.GIphotonradius=1.0;
1677                                 uiDefButF(block, NUMSLI, B_DIFF,"Radius:", 170,60,140,20,       &(G.scene->r.GIphotonradius), 
1678                                                 0.00001, 100.0 ,0,0, "Radius to search for photons to mix (blur)");
1679                                 if(G.scene->r.GImixphotons==0) G.scene->r.GImixphotons=100;
1680                                 uiDefButI(block, NUM, B_DIFF, "MixCount:", 170,35,140,20, &G.scene->r.GImixphotons, 
1681                                                 0, 1000, 10, 10, "Number of photons to mix");
1682                                 uiDefButBitS(block, TOG, 1, B_REDR, "Tune Photons",170,10,140,20, &G.scene->r.GIdirect, 
1683                                                 0, 0, 0, 0, "Show the photonmap directly in the render for tuning");
1684                         }
1685                 }
1686
1687         }
1688 }
1689
1690 /* yafray: global  options panel */
1691 static void render_panel_yafrayGlobal()
1692 {
1693         uiBlock *block;
1694
1695         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGlobal", UI_EMBOSS, UI_HELV, curarea->win);
1696         uiNewPanelTabbed("Render", "Render");
1697         if(uiNewPanel(curarea, block, "YafRay", "Render", 320, 0, 318, 204)==0) return;
1698
1699         // label to force a boundbox for buttons not to be centered
1700         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
1701
1702         uiDefButBitS(block, TOGN, 1, B_REDR, "xml", 5,180,75,20, &G.scene->r.YFexportxml,
1703                                         0, 0, 0, 0, "Export to an xml file and call yafray instead of plugin");
1704
1705         uiDefButF(block, NUMSLI, B_DIFF,"Bi ", 5,35,150,20,     &(G.scene->r.YF_raybias), 
1706                                 0.0, 10.0 ,0,0, "Shadow ray bias to avoid self shadowing");
1707         uiDefButI(block, NUM, B_DIFF, "Raydepth ", 5,60,150,20,
1708                                 &G.scene->r.YF_raydepth, 1.0, 80.0, 10, 10, "Maximum render ray depth from the camera");
1709         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");
1710         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");
1711         
1712         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");
1713
1714         /*AA Settings*/
1715         uiDefButBitS(block, TOGN, 1, B_REDR, "Auto AA", 5,140,150,20, &G.scene->r.YF_AA, 
1716                                         0, 0, 0, 0, "Set AA using OSA and GI quality, disable for manual control");
1717         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.");
1718         if(G.scene->r.YF_AA){
1719                 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)");
1720                 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");
1721                 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");
1722                 uiDefButF(block, NUMSLI, B_DIFF, "Thr ", 160,90,150,20, &G.scene->r.YF_AAthreshold, 0.000001, 1.0, 0, 0, "AA threshold");
1723         }
1724 }
1725
1726
1727 static void layer_copy_func(void *lay_v, void *lay_p)
1728 {
1729         unsigned int *lay= lay_p;
1730         int laybit= (int)lay_v;
1731
1732         if(G.qual & LR_SHIFTKEY) {
1733                 if(*lay==0) *lay= 1<<laybit;
1734         }
1735         else
1736                 *lay= 1<<laybit;
1737         
1738         copy_view3d_lock(REDRAW);
1739         allqueue(REDRAWBUTSSCENE, 0);
1740 }
1741
1742 static void delete_scene_layer_func(void *srl_v, void *act_i)
1743 {
1744         if(BLI_countlist(&G.scene->r.layers)>1) {
1745                 long act= (long)act_i;
1746                 
1747                 BLI_remlink(&G.scene->r.layers, srl_v);
1748                 MEM_freeN(srl_v);
1749                 G.scene->r.actlay= 0;
1750                 
1751                 if(G.scene->nodetree) {
1752                         bNode *node;
1753                         for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
1754                                 if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
1755                                         if(node->custom1==act)
1756                                                 node->custom1= 0;
1757                                         else if(node->custom1>act)
1758                                                 node->custom1--;
1759                                 }
1760                         }
1761                 }
1762                 allqueue(REDRAWBUTSSCENE, 0);
1763                 allqueue(REDRAWNODE, 0);
1764         }
1765 }
1766
1767 static void rename_scene_layer_func(void *srl_v, void *unused_v)
1768 {
1769         if(G.scene->nodetree) {
1770                 SceneRenderLayer *srl= srl_v;
1771                 bNode *node;
1772                 for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
1773                         if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
1774                                 if(node->custom1==G.scene->r.actlay)
1775                                         BLI_strncpy(node->name, srl->name, NODE_MAXSTR);
1776                         }
1777                 }
1778         }
1779         allqueue(REDRAWBUTSSCENE, 0);
1780         allqueue(REDRAWOOPS, 0);
1781         allqueue(REDRAWNODE, 0);
1782 }
1783
1784 static char *scene_layer_menu(void)
1785 {
1786         SceneRenderLayer *srl;
1787         int len= 32 + 32*BLI_countlist(&G.scene->r.layers);
1788         short a, nr;
1789         char *str= MEM_callocN(len, "menu layers");
1790         
1791         strcpy(str, "ADD NEW %x32767");
1792         a= strlen(str);
1793         for(nr=0, srl= G.scene->r.layers.first; srl; srl= srl->next, nr++) {
1794                 if(srl->layflag & SCE_LAY_DISABLE)
1795                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_BLANK1, nr);
1796                 else 
1797                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_CHECKBOX_HLT, nr);
1798         }
1799         
1800         return str;
1801 }
1802
1803 static void draw_3d_layer_buttons(uiBlock *block, unsigned int *poin, short xco, short yco, short dx, short dy)
1804 {
1805         uiBut *bt;
1806         long a;
1807         
1808         uiBlockBeginAlign(block);
1809         for(a=0; a<5; a++) {
1810                 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, "");
1811                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
1812         }
1813         for(a=0; a<5; a++) {
1814                 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, "");
1815                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
1816         }
1817         
1818         xco+= 7;
1819         uiBlockBeginAlign(block);
1820         for(a=5; a<10; a++) {
1821                 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, "");
1822                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
1823         }
1824         for(a=5; a<10; a++) {
1825                 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, "");
1826                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
1827         }
1828         
1829         uiBlockEndAlign(block);
1830 }
1831
1832 static void render_panel_layers(void)
1833 {
1834         uiBlock *block;
1835         uiBut *bt;
1836         SceneRenderLayer *srl= BLI_findlink(&G.scene->r.layers, G.scene->r.actlay);
1837         char *strp;
1838         
1839         if(srl==NULL) {
1840                 G.scene->r.actlay= 0;
1841                 srl= G.scene->r.layers.first;
1842         }
1843         
1844         block= uiNewBlock(&curarea->uiblocks, "render_panel_layers", UI_EMBOSS, UI_HELV, curarea->win);
1845         uiNewPanelTabbed("Output", "Render");
1846         if(uiNewPanel(curarea, block, "Render Layers", "Render", 320, 0, 318, 204)==0) return;
1847         
1848         /* first, as reminder, the scene layers */
1849         uiDefBut(block, LABEL, 0, "Scene:",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
1850         draw_3d_layer_buttons(block, &G.scene->lay,             130, 170, 35, 30);
1851         
1852         /* layer disable, menu, name, delete button */
1853         uiBlockBeginAlign(block);
1854         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");
1855         strp= scene_layer_menu();
1856         uiDefButS(block, MENU, B_ADD_RENDERLAYER, strp, 30,145,23,20, &(G.scene->r.actlay), 0, 0, 0, 0, "Choose Active Render Layer");
1857         MEM_freeN(strp);
1858         
1859         /* name max 20, exr format limit... */
1860         bt= uiDefBut(block, TEX, REDRAWNODE, "",  53,145,172,20, srl->name, 0.0, 20.0, 0, 0, "");
1861         uiButSetFunc(bt, rename_scene_layer_func, srl, NULL);
1862         
1863         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");      
1864         bt=uiDefIconBut(block, BUT, B_NOP, ICON_X,      285, 145, 25, 20, 0, 0, 0, 0, 0, "Deletes current Render Layer");
1865         uiButSetFunc(bt, delete_scene_layer_func, srl, (void *)(long)G.scene->r.actlay);
1866         uiBlockEndAlign(block);
1867
1868         /* RenderLayer visible-layers */
1869         uiDefBut(block, LABEL, 0, "Layer:",                     10,110,100,20, NULL, 0, 0, 0, 0, "");
1870         draw_3d_layer_buttons(block, &srl->lay,         130,110, 35, 30);
1871         
1872         uiBlockBeginAlign(block);
1873         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"); 
1874         uiBlockBeginAlign(block);
1875         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"); 
1876         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)");    
1877         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)");    
1878         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");  
1879         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)");  
1880         
1881         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");
1882         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");
1883         uiBlockEndAlign(block);
1884
1885         uiBlockBeginAlign(block);
1886         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");       
1887         uiDefButBitI(block, TOG, SCE_PASS_Z, B_SET_PASS,"Z",                    90, 30, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Z values pass");   
1888         uiDefButBitI(block, TOG, SCE_PASS_VECTOR, B_SET_PASS,"Vec",             120, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Speed Vector pass");      
1889         uiDefButBitI(block, TOG, SCE_PASS_NORMAL, B_SET_PASS,"Nor",             160, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Normal pass");    
1890         uiDefButBitI(block, TOG, SCE_PASS_UV, B_SET_PASS,"UV",                  200, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Texture UV pass");        
1891         uiDefButBitI(block, TOG, SCE_PASS_INDEXOB, B_SET_PASS,"IndexOb",240, 30, 70, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Object Index pass");      
1892         
1893         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");   
1894         uiDefButBitI(block, TOG, SCE_PASS_DIFFUSE, B_SET_PASS,"Diff",                   45, 10, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Diffuse pass");    
1895         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SPEC, B_SET_PASS,"Spec",              80, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Specular pass");   
1896         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SHADOW, B_SET_PASS,"Shad",    120, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Shadow pass");    
1897         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_AO, B_SET_PASS,"AO",                  160, 10, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver AO pass");        
1898         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");      
1899         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");      
1900         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_RADIO, B_SET_PASS,"Rad",              270, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Radiosity pass"); 
1901 }       
1902
1903 void render_panels()
1904 {
1905
1906         render_panel_output();
1907         render_panel_layers();
1908         render_panel_render();
1909         render_panel_anim();
1910         render_panel_bake();
1911
1912         render_panel_format();
1913 #ifdef WITH_FFMPEG
1914        if (G.scene->r.imtype == R_FFMPEG) {
1915                    render_panel_ffmpeg_video();
1916                render_panel_ffmpeg_audio();
1917        }
1918 #endif
1919
1920 #ifndef DISABLE_YAFRAY
1921         /* yafray: GI & Global panel, only available when yafray enabled for rendering */
1922         if (G.scene->r.renderer==R_YAFRAY) {
1923                 if (G.scene->r.YF_gamma==0.0) G.scene->r.YF_gamma=1.0;
1924                 if (G.scene->r.YF_raybias==0.0) G.scene->r.YF_raybias=0.001;
1925                 if (G.scene->r.YF_raydepth==0) G.scene->r.YF_raydepth=5;
1926                 if (G.scene->r.YF_AApixelsize==0.0) G.scene->r.YF_AApixelsize=1.5;
1927                 if (G.scene->r.YF_AAthreshold==0.0) G.scene->r.YF_AAthreshold=0.05;
1928                 if (G.scene->r.GIpower==0.0) G.scene->r.GIpower=1.0;
1929                 if (G.scene->r.GIindirpower==0.0) G.scene->r.GIindirpower=1.0;
1930                 render_panel_yafrayGlobal();
1931                 render_panel_yafrayGI();
1932         }
1933 #endif
1934
1935 }
1936
1937 /* --------------------------------------------- */
1938
1939 void anim_panels()
1940 {
1941         uiBlock *block;
1942
1943         block= uiNewBlock(&curarea->uiblocks, "anim_panel", UI_EMBOSS, UI_HELV, curarea->win);
1944         if(uiNewPanel(curarea, block, "Anim", "Anim", 0, 0, 318, 204)==0) return;
1945
1946         uiBlockBeginAlign(block);
1947         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");
1948         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");
1949
1950         uiBlockBeginAlign(block);
1951         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");
1952         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");
1953         
1954         uiBlockBeginAlign(block);
1955         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");
1956         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");
1957
1958         uiBlockBeginAlign(block);
1959         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");
1960
1961
1962 }
1963
1964 /* --------------------------------------------- */
1965
1966 void sound_panels()
1967 {
1968         bSound *sound;
1969
1970         /* paranoia check */
1971         sound = G.buts->lockpoin;
1972         if(sound && GS(sound->id.name)!=ID_SO) {
1973                 sound= NULL;
1974                 G.buts->lockpoin= NULL;
1975         }
1976         
1977         sound_panel_sound(sound);
1978         sound_panel_listener();
1979         sound_panel_sequencer();
1980 }
1981
1982
1983