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