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