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