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