Added support for outputting bmp's
[blender.git] / source / blender / src / buttons_scene.c
1 /**
2  * $Id: 
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #ifdef WIN32
43 #include "BLI_winstuff.h"
44 #endif
45
46 #include "MEM_guardedalloc.h"
47 #include "DNA_screen_types.h"
48 #include "DNA_space_types.h"
49 #include "DNA_scene_types.h"
50 #include "DNA_sound_types.h"
51 #include "DNA_userdef_types.h"
52 #include "DNA_packedFile_types.h"
53
54 #include "BKE_global.h"
55 #include "BKE_main.h"
56 #include "BKE_library.h"
57 #include "BKE_sound.h"
58 #include "BKE_packedFile.h"
59 #include "BKE_utildefines.h"
60
61 #include "BLI_blenlib.h"
62
63 #include "BSE_filesel.h"
64
65 #include "BIF_gl.h"
66 #include "BIF_graphics.h"
67 #include "BIF_keyval.h"
68 #include "BIF_mainqueue.h"
69 #include "BIF_resources.h"
70 #include "BIF_screen.h"
71 #include "BIF_mywindow.h"
72 #include "BIF_space.h"
73 #include "BIF_glutil.h"
74 #include "BIF_interface.h"
75 #include "BIF_toolbox.h"
76
77 #include "BIF_butspace.h"
78
79 #include "mydevice.h"
80 #include "blendef.h"
81
82 /* -----includes for this file specific----- */
83
84 #include "render.h"
85 #include "DNA_image_types.h"
86 #include "BKE_writeavi.h"
87 #include "BKE_image.h"
88 #include "BIF_renderwin.h"
89 #include "BIF_writeimage.h"
90 #include "BIF_writeavicodec.h"
91 #include "BIF_editsound.h"
92 #include "BSE_seqaudio.h"
93 #include "BSE_headerbuttons.h"
94 #include "butspace.h" // own module
95
96 #ifdef WITH_QUICKTIME
97 #include "quicktime_export.h"
98 #endif
99
100
101 /* here the calls for scene buttons
102    - render
103    - world
104    - anim settings, audio
105 */
106
107
108 /* ************************ SOUND *************************** */
109 static void load_new_sample(char *str)  /* called from fileselect */
110 {
111         char name[FILE_MAXDIR+FILE_MAXFILE];
112         bSound *sound;
113         bSample *sample, *newsample;
114
115         sound = G.buts->lockpoin;
116
117         if (sound) {
118                 // save values
119                 sample = sound->sample;
120                 strcpy(name, sound->sample->name);
121
122                 strcpy(sound->name, str);
123                 sound_set_sample(sound, NULL);
124                 sound_initialize_sample(sound);
125
126                 if (sound->sample->type == SAMPLE_INVALID) {
127                         error("Not a valid sample: %s", str);
128
129                         newsample = sound->sample;
130
131                         // restore values
132                         strcpy(sound->name, name);
133                         sound_set_sample(sound, sample);
134
135                         // remove invalid sample
136
137                         sound_free_sample(newsample);
138                         BLI_remlink(samples, newsample);
139                         MEM_freeN(newsample);
140                 }
141         }
142
143         allqueue(REDRAWBUTSSCENE, 0);
144
145 }
146
147
148 void do_soundbuts(unsigned short event)
149 {
150         char name[FILE_MAXDIR+FILE_MAXFILE];
151         bSound *sound;
152         bSample *sample;
153         bSound* tempsound;
154         ID *id;
155         
156         sound = G.buts->lockpoin;
157         
158         switch(event) {
159         case B_SOUND_REDRAW:
160                 allqueue(REDRAWBUTSSCENE, 0);
161                 break;
162
163         case B_SOUND_LOAD_SAMPLE:
164                 if (sound) strcpy(name, sound->name);
165                 else strcpy(name, U.sounddir);
166                         
167                 activate_fileselect(FILE_SPECIAL, "SELECT WAV FILE", name, load_new_sample);
168                 break;
169
170         case B_SOUND_PLAY_SAMPLE:
171                 if (sound) {
172                         if (sound->sample->type != SAMPLE_INVALID) {
173                                 sound_play_sound(sound);
174                                 allqueue(REDRAWBUTSSCENE, 0);
175                         }
176                 }
177                 break;
178
179         case B_SOUND_MENU_SAMPLE:
180                 if (G.buts->menunr == -2) {
181                         if (sound) {
182                                 activate_databrowse((ID *)sound->sample, ID_SAMPLE, 0, B_SOUND_MENU_SAMPLE, &G.buts->menunr, do_soundbuts);
183                         }
184                 } else if (G.buts->menunr > 0) {
185                         sample = BLI_findlink(samples, G.buts->menunr - 1);
186                         if (sample && sound) {
187                                 BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
188                                 sound_set_sample(sound, sample);
189                                 do_soundbuts(B_SOUND_REDRAW);
190                         }
191                 }
192                         
193                 break;
194         case B_SOUND_NAME_SAMPLE:
195                 load_new_sample(sound->name);
196                 break;
197         
198         case B_SOUND_UNPACK_SAMPLE:
199                 if(sound && sound->sample) {
200                         sample = sound->sample;
201                         
202                         if (sample->packedfile) {
203                                 if (G.fileflags & G_AUTOPACK) {
204                                         if (okee("Disable AutoPack ?")) {
205                                                 G.fileflags &= ~G_AUTOPACK;
206                                         }
207                                 }
208                                 
209                                 if ((G.fileflags & G_AUTOPACK) == 0) {
210                                         unpackSample(sample, PF_ASK);
211                                 }
212                         } else {
213                                 sound_set_packedfile(sample, newPackedFile(sample->name));
214                         }
215                         allqueue(REDRAWHEADERS, 0);
216                         do_soundbuts(B_SOUND_REDRAW);
217                 }
218                 break;
219
220         case B_SOUND_COPY_SOUND:
221                 if (sound) {
222                         tempsound = sound_make_copy(sound);
223                         sound = tempsound;
224                         id = &sound->id;
225                         G.buts->lockpoin = (bSound*)id;
226                         do_soundbuts(B_SOUND_REDRAW);
227                 }
228                 break;
229
230         case B_SOUND_RECALC:
231                 waitcursor(1);
232                 sound = G.main->sound.first;
233                 while (sound) {
234                         MEM_freeN(sound->stream);
235                         sound->stream = 0;
236                         audio_makestream(sound);
237                         sound = (bSound *) sound->id.next;
238                 }
239                 waitcursor(0);
240                 allqueue(REDRAWSEQ, 0);
241                 break;
242
243         case B_SOUND_RATECHANGED:
244
245                 allqueue(REDRAWBUTSSCENE, 0);
246                 allqueue(REDRAWSEQ, 0);
247                 break;
248
249         case B_SOUND_MIXDOWN:
250                 audio_mixdown();
251                 break;
252
253         default: 
254                 if (G.f & G_DEBUG) {
255                         printf("do_soundbuts: unhandled event %d\n", event);
256                 }
257         }
258 }
259
260
261 static void sound_panel_listener(void)
262 {
263         uiBlock *block;
264         int xco= 100, yco=100, mixrate;
265         char mixrateinfo[256];
266         
267         block= uiNewBlock(&curarea->uiblocks, "sound_panel_listener", UI_EMBOSS, UI_HELV, curarea->win);
268         if(uiNewPanel(curarea, block, "Listener", "Sound", 320, 0, 318, 204)==0) return;
269
270         mixrate = sound_get_mixrate();
271         sprintf(mixrateinfo, "Game Mixrate: %d Hz", mixrate);
272         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
273
274         yco -= 30;
275         uiDefBut(block, LABEL, 0, "Game listener settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
276
277         yco -= 30;
278         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
279                 xco,yco,195,24,&G.listener->gain, 0.0, 1.0, 1.0, 0, "Sets the maximum volume for the overall sound");
280         
281         yco -= 30;
282         uiDefBut(block, LABEL, 0, "Game Doppler effect settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
283
284         yco -= 30;
285         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Doppler: ",
286         xco,yco,195,24,&G.listener->dopplervelocity, 0.0, 10.0, 1.0, 0, "Use this for scaling the doppler effect");
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         uiDefButS(block, TOG|BIT|1, 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         uiDefButS(block, TOG|BIT|2, 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         uiDefButS(block, TOG|BIT|0, 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, 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                         if (sound->sample->channels == 1) strcpy(ch, "Mono");
363                         else if (sound->sample->channels == 2) strcpy(ch, "Stereo");
364                         else strcpy(ch, "Unknown");
365                         
366                         sprintf(ch, "Sample: %s, %d bit, %d Hz, %d samples", ch, sound->sample->bits, sound->sample->rate, (sound->sample->len/(sound->sample->bits/8)/sound->sample->channels));
367                         uiDefBut(block, LABEL, 0, ch,                   35,140,225,20, 0, 0, 0, 0, 0, "");
368                 }
369                 else {
370                         uiDefBut(block, LABEL, 0, "Sample: No sample info available.",35,140,225,20, 0, 0, 0, 0, 0, "");
371                 }
372
373                 /* sample browse buttons */
374
375                 id= (ID *)sound->sample;
376                 IDnames_to_pupstring(&strp, NULL, NULL, samples, id, &(G.buts->menunr));
377                 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");
378                 MEM_freeN(strp);
379                 
380                 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");
381                 
382                 sprintf(str, "%d", sample->id.us);
383                 uiDefBut(block, BUT, B_SOUND_UNLINK_SAMPLE, str,        260,120,25,20, 0, 0, 0, 0, 0, "The number of users");
384                 
385                 if (sound->sample->packedfile) packdummy = 1;
386                 else packdummy = 0;
387                 
388                 uiDefIconButI(block, TOG|BIT|0, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
389                         285, 120,25,24, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
390                 
391                 uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
392
393                 uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play",       160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
394                 
395                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
396                         10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Set the volume of this sound");
397
398                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Pitch: ",
399                         160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Set the pitch of this sound");
400
401                 /* looping */
402                 uiDefButI(block, TOG|BIT|SOUND_FLAGS_LOOP_BIT, B_SOUND_REDRAW, "Loop",
403                         10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Toggle between looping on/off");
404
405                 if (sound->flags & SOUND_FLAGS_LOOP) {
406                         uiDefButI(block, TOG|BIT|SOUND_FLAGS_BIDIRECTIONAL_LOOP_BIT, B_SOUND_REDRAW, "Ping Pong",
407                                 105, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Toggle between A->B and A->B->A looping");
408                         
409                 }
410         
411
412                 /* 3D settings ------------------------------------------------------------------ */
413
414                 if (sound->sample->channels == 1) {
415                         uiDefButI(block, TOG|BIT|SOUND_FLAGS_3D_BIT, B_SOUND_REDRAW, "3D Sound",
416                                 10, 10, 90, 20, &sound->flags, 0, 0, 0, 0, "Turns 3D sound on");
417                         
418                         if (sound->flags & SOUND_FLAGS_3D) {
419                                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Scale: ",
420                                         100,10,210,20, &sound->attenuation, 0.0, 5.0, 1.0, 0, "Sets the surround scaling factor for this sound");
421                                 
422                         }
423                 }
424         }
425 }
426
427
428 /* ************************* SCENE *********************** */
429
430
431 static void output_pic(char *name)
432 {
433         strcpy(G.scene->r.pic, name);
434         allqueue(REDRAWBUTSSCENE, 0);
435 }
436
437 static void backbuf_pic(char *name)
438 {
439         Image *ima;
440         
441         strcpy(G.scene->r.backbuf, name);
442         allqueue(REDRAWBUTSSCENE, 0);
443
444         ima= add_image(name);
445         if(ima) {
446                 free_image_buffers(ima);        /* force read again */
447                 ima->ok= 1;
448         }
449 }
450
451 static void ftype_pic(char *name)
452 {
453         strcpy(G.scene->r.ftype, name);
454         allqueue(REDRAWBUTSSCENE, 0);
455 }
456
457
458 static void scene_change_set(Scene *sc, Scene *set) {
459         if (sc->set!=set) {
460                 sc->set= set;
461                 
462                 allqueue(REDRAWBUTSSCENE, 0);
463                 allqueue(REDRAWVIEW3D, 0);
464         }
465 }
466
467 static void run_playanim(char *file) {
468         extern char bprogname[];        /* usiblender.c */
469         char str[FILE_MAXDIR+FILE_MAXFILE];
470         int pos[2], size[2];
471
472         calc_renderwin_rectangle(R.winpos, pos, size);
473
474         sprintf(str, "%s -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
475         system(str);
476 }
477
478 void do_render_panels(unsigned short event)
479 {
480         ScrArea *sa;
481         ID *id;
482         char file[FILE_MAXDIR+FILE_MAXFILE];
483
484         switch(event) {
485
486         case B_DORENDER:
487                 BIF_do_render(0);
488                 break;
489         case B_RTCHANGED:
490                 allqueue(REDRAWALL, 0);
491                 break;
492         case B_PLAYANIM:
493 #ifdef WITH_QUICKTIME
494                 if(G.scene->r.imtype == R_QUICKTIME)
495                         makeqtstring(file);
496                 else
497 #endif
498                         makeavistring(file);
499                 if(BLI_exist(file)) {
500                         run_playanim(file);
501                 }
502                 else {
503                         makepicstring(file, G.scene->r.sfra);
504                         if(BLI_exist(file)) {
505                                 run_playanim(file);
506                         }
507                         else error("Can't find image: %s", file);
508                 }
509                 break;
510                 
511         case B_DOANIM:
512                 BIF_do_render(1);
513                 break;
514         
515         case B_FS_PIC:
516                 sa= closest_bigger_area();
517                 areawinset(sa->win);
518                 if(G.qual == LR_CTRLKEY)
519                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
520                 else
521                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
522                 break;
523
524         case B_FS_BACKBUF:
525                 sa= closest_bigger_area();
526                 areawinset(sa->win);
527                 if(G.qual == LR_CTRLKEY)
528                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
529                 else
530                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
531                 break;
532
533         case B_FS_FTYPE:
534                 sa= closest_bigger_area();
535                 areawinset(sa->win);
536                 if(G.qual == LR_CTRLKEY)
537                         activate_imageselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
538                 else
539                         activate_fileselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
540                 break;
541         
542         case B_PR_PAL:
543                 G.scene->r.xsch= 720;
544                 G.scene->r.ysch= 576;
545                 G.scene->r.xasp= 54;
546                 G.scene->r.yasp= 51;
547                 G.scene->r.size= 100;
548                 G.scene->r.frs_sec= 25;
549                 G.scene->r.mode &= ~R_PANORAMA;
550                 G.scene->r.xparts=  G.scene->r.yparts= 1;
551                 
552                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
553                 allqueue(REDRAWBUTSSCENE, 0);
554                 allqueue(REDRAWVIEWCAM, 0);
555                 break;
556
557 #ifdef WITH_QUICKTIME
558         case B_FILETYPEMENU:
559                 allqueue(REDRAWBUTSSCENE, 0);
560 #if defined (_WIN32) || defined (__APPLE__)
561                 // fall through to codec settings if this is the first
562                 // time R_AVICODEC is selected for this scene.
563                 if (((G.scene->r.imtype == R_AVICODEC) 
564                          && (G.scene->r.avicodecdata == NULL)) ||
565                         ((G.scene->r.imtype == R_QUICKTIME) 
566                          && (G.scene->r.qtcodecdata == NULL))) {
567                 } else {
568                   break;
569                 }
570 #else /* libquicktime */
571                 if(G.scene->r.imtype == R_QUICKTIME) {
572                         /* i'm not sure if this should be here... */
573                         /* set default quicktime codec */
574                         if (!G.scene->r.qtcodecdata) {
575                                 G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData),   "QtCodecData");
576                                 qtcodec_idx = 1;
577                         }
578                         
579                         qt_init_codecs();
580                         if (qtcodec_idx < 1) qtcodec_idx = 1;   
581                         
582                         G.scene->r.qtcodecdata->fourcc =  qtcodecidx_to_fcc(qtcodec_idx-1);
583                         qt_init_codecdata(G.scene->r.qtcodecdata);
584 /* I'm not sure if this is really needed, so don't remove it yet */
585 #if 0
586                         /* get index of codec that can handle a given fourcc */
587                         if (qtcodec_idx < 1)
588                                 qtcodec_idx = get_qtcodec_idx(G.scene->r.qtcodecdata->fourcc)+1;
589
590                         /* no suitable codec found, alert user */
591                         if (qtcodec_idx < -1) {
592                                 error("no suitable codec found!");
593                                 qtcodec_idx = 1;
594                         }
595 #endif /* 0 */
596                 }
597 #endif /*_WIN32 || __APPLE__ */
598
599         case B_SELECTCODEC:
600 #if defined (_WIN32) || defined (__APPLE__)
601                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
602                         get_qtcodec_settings();
603                 }
604 #ifdef _WIN32
605                 else
606                         get_avicodec_settings();
607 #endif /* _WIN32 */
608 #else /* libquicktime */
609                 if (!G.scene->r.qtcodecdata) {
610                         G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData),  "QtCodecData");
611                         qtcodec_idx = 1;
612                 }
613                 if (qtcodec_idx < 1) {
614                         qtcodec_idx = 1;
615                         qt_init_codecs();
616                 }
617
618                 G.scene->r.qtcodecdata->fourcc = qtcodecidx_to_fcc(qtcodec_idx-1);
619                 /* if the selected codec differs from the previous one, reinit it */
620                 qt_init_codecdata(G.scene->r.qtcodecdata);      
621                 allqueue(REDRAWBUTSSCENE, 0);
622 #endif /* _WIN32 || __APPLE__ */
623                 break;
624 #endif /* WITH_QUICKTIME */
625
626         case B_PR_FULL:
627                 G.scene->r.xsch= 1280;
628                 G.scene->r.ysch= 1024;
629                 G.scene->r.xasp= 1;
630                 G.scene->r.yasp= 1;
631                 G.scene->r.size= 100;
632                 G.scene->r.mode &= ~R_PANORAMA;
633                 G.scene->r.xparts=  G.scene->r.yparts= 1;
634
635                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
636                 allqueue(REDRAWBUTSSCENE, 0);
637                 allqueue(REDRAWVIEWCAM, 0);
638                 break;
639         case B_PR_PRV:
640                 G.scene->r.xsch= 640;
641                 G.scene->r.ysch= 512;
642                 G.scene->r.xasp= 1;
643                 G.scene->r.yasp= 1;
644                 G.scene->r.size= 50;
645                 G.scene->r.mode &= ~R_PANORAMA;
646                 G.scene->r.xparts=  G.scene->r.yparts= 1;
647
648                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
649                 allqueue(REDRAWVIEWCAM, 0);
650                 allqueue(REDRAWBUTSSCENE, 0);
651                 break;
652         case B_PR_CDI:
653                 G.scene->r.xsch= 384;
654                 G.scene->r.ysch= 280;
655                 G.scene->r.xasp= 1;
656                 G.scene->r.yasp= 1;
657                 G.scene->r.size= 100;
658                 G.scene->r.mode &= ~R_PANORAMA;
659                 G.scene->r.xparts=  G.scene->r.yparts= 1;
660
661                 BLI_init_rctf(&G.scene->r.safety, 0.15, 0.85, 0.15, 0.85);
662                 allqueue(REDRAWVIEWCAM, 0);
663                 allqueue(REDRAWBUTSSCENE, 0);
664                 break;
665         case B_PR_PAL169:
666                 G.scene->r.xsch= 720;
667                 G.scene->r.ysch= 576;
668                 G.scene->r.xasp= 64;
669                 G.scene->r.yasp= 45;
670                 G.scene->r.size= 100;
671                 G.scene->r.frs_sec= 25;
672                 G.scene->r.mode &= ~R_PANORAMA;
673                 G.scene->r.xparts=  G.scene->r.yparts= 1;
674
675                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
676                 allqueue(REDRAWVIEWCAM, 0);
677                 allqueue(REDRAWBUTSSCENE, 0);
678                 break;
679         case B_PR_D2MAC:
680                 G.scene->r.xsch= 1024;
681                 G.scene->r.ysch= 576;
682                 G.scene->r.xasp= 1;
683                 G.scene->r.yasp= 1;
684                 G.scene->r.size= 50;
685                 G.scene->r.mode &= ~R_PANORAMA;
686                 G.scene->r.xparts=  G.scene->r.yparts= 1;
687
688                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
689                 allqueue(REDRAWVIEWCAM, 0);
690                 allqueue(REDRAWBUTSSCENE, 0);
691                 break;
692         case B_PR_MPEG:
693                 G.scene->r.xsch= 368;
694                 G.scene->r.ysch= 272;
695                 G.scene->r.xasp= 105;
696                 G.scene->r.yasp= 100;
697                 G.scene->r.size= 100;
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_PC:
706                 G.scene->r.xsch= 640;
707                 G.scene->r.ysch= 480;
708                 G.scene->r.xasp= 100;
709                 G.scene->r.yasp= 100;
710                 G.scene->r.size= 100;
711                 G.scene->r.mode &= ~R_PANORAMA;
712                 G.scene->r.xparts=  G.scene->r.yparts= 1;
713
714                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
715                 allqueue(REDRAWVIEWCAM, 0);
716                 allqueue(REDRAWBUTSSCENE, 0);
717                 break;
718         case B_PR_PRESET:
719                 G.scene->r.xsch= 720;
720                 G.scene->r.ysch= 576;
721                 G.scene->r.xasp= 54;
722                 G.scene->r.yasp= 51;
723                 G.scene->r.size= 100;
724                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS;
725                 G.scene->r.imtype= R_TARGA;
726                 G.scene->r.xparts=  G.scene->r.yparts= 1;
727
728                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
729                 allqueue(REDRAWVIEWCAM, 0);
730                 allqueue(REDRAWBUTSSCENE, 0);
731                 break;
732         case B_PR_PANO:
733                 G.scene->r.xsch= 36;
734                 G.scene->r.ysch= 176;
735                 G.scene->r.xasp= 115;
736                 G.scene->r.yasp= 100;
737                 G.scene->r.size= 100;
738                 G.scene->r.mode |= R_PANORAMA;
739                 G.scene->r.xparts=  16;
740                 G.scene->r.yparts= 1;
741
742                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
743                 allqueue(REDRAWVIEWCAM, 0);
744                 allqueue(REDRAWBUTSSCENE, 0);
745                 break;
746         case B_PR_NTSC:
747                 G.scene->r.xsch= 720;
748                 G.scene->r.ysch= 480;
749                 G.scene->r.xasp= 10;
750                 G.scene->r.yasp= 11;
751                 G.scene->r.size= 100;
752                 G.scene->r.frs_sec= 30;
753                 G.scene->r.mode &= ~R_PANORAMA;
754                 G.scene->r.xparts=  G.scene->r.yparts= 1;
755                 
756                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
757                 allqueue(REDRAWBUTSSCENE, 0);
758                 allqueue(REDRAWVIEWCAM, 0);
759                 break;
760
761         case B_SETBROWSE:
762                 id= (ID*) G.scene->set;
763                 
764                 if (G.buts->menunr==-2) {
765                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
766                 } else if (G.buts->menunr>0) {
767                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
768                         
769                         if (newset==G.scene)
770                                 error("Not allowed");
771                         else if (newset)
772                                 scene_change_set(G.scene, newset);
773                 }  
774                 break;
775         case B_CLEARSET:
776                 scene_change_set(G.scene, NULL);
777                 break;
778         }
779 }
780
781 static uiBlock *edge_render_menu(void *arg_unused)
782 {
783         uiBlock *block;
784         
785         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
786                 
787         /* use this for a fake extra empy space around the buttons */
788         uiDefBut(block, LABEL, 0, "",  285, -20, 230, 120, NULL,  0, 0, 0, 0, "");
789         
790         uiDefButS(block, NUM, 0,"Eint:",  295,50,70,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
791                   "Sets edge intensity for Toon shading");
792         uiDefButI(block, TOG, 0,"Shift", 365,50,70,19,  &G.compat, 0, 0, 0, 0,
793                   "For unified renderer: use old offsets for edges");
794         uiDefButI(block, TOG, 0,"All",          435,50,70,19,  &G.notonlysolid, 0, 0, 0, 0,
795                   "For unified renderer: also consider transparent faces for toon shading");
796
797         /* colour settings for the toon shading */
798         uiDefButF(block, COL, B_EDGECOLSLI, "", 295,-10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, 0, "");
799         
800         uiDefButF(block, NUMSLI, 0, "R ",   325, 30, 180,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
801                   "For unified renderer: Colour for edges in toon shading mode.");
802         uiDefButF(block, NUMSLI, 0, "G ",  325, 10, 180,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
803                   "For unified renderer: Colour for edges in toon shading mode.");
804         uiDefButF(block, NUMSLI, 0, "B ",  325, -10, 180,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
805                   "For unified renderer: Colour for edges in toon shading mode.");
806
807         uiDefButS(block, NUM, 0,"AntiShift",   365,70,140,19,  &(G.scene->r.same_mat_redux), 0, 255.0, 0, 0,
808                   "For unified renderer: reduce intensity on boundaries "
809                   "with identical materials with this number.");
810         
811         uiBlockSetDirection(block, UI_TOP);
812         
813         return block;
814 }
815
816 static uiBlock *post_render_menu(void *arg_unused)
817 {
818         uiBlock *block;
819         
820         block= uiNewBlock(&curarea->uiblocks, "post render", UI_EMBOSS, UI_HELV, curarea->win);
821                 
822         /* use this for a fake extra empy space around the buttons */
823         uiDefBut(block, LABEL, 0, "",                   -10, 10, 200, 80, NULL, 0, 0, 0, 0, "");
824         
825         uiDefButF(block, NUMSLI, 0,"Add:",              0,60,180,19,  &G.scene->r.postadd, -1.0, 1.0, 0, 0, "");
826         uiDefButF(block, NUMSLI, 0,"Mul:",              0,40,180,19,  &G.scene->r.postmul, 0.01, 4.0, 0, 0, "");
827         uiDefButF(block, NUMSLI, 0,"Gamma:",            0,20,180,19,  &G.scene->r.postgamma, 0.2, 2.0, 0, 0, "");
828
829         uiBlockSetDirection(block, UI_TOP);
830         
831         return block;
832 }
833
834
835 static uiBlock *framing_render_menu(void *arg_unused)
836 {
837         uiBlock *block;
838         short yco = 60, xco = 0;
839         int randomcolorindex = 1234;
840
841         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
842
843         /* use this for a fake extra empy space around the buttons */
844         uiDefBut(block, LABEL, 0, "",                   -10, -10, 300, 100, NULL, 0, 0, 0, 0, "");
845
846         uiDefBut(block, LABEL, B_NOP, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
847         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");
848         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");
849         uiDefButC(block, ROW, 0, "Bars",            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");
850
851         yco -= 20;
852         xco = 35;
853
854         uiDefButF(block, COL, randomcolorindex, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, 0, "");
855
856         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");
857         yco -= 20;
858         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");
859         yco -= 20;
860         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");
861
862         uiBlockSetDirection(block, UI_TOP);
863
864         return block;
865 }
866
867
868 static char *imagetype_pup(void)
869 {
870         static char string[1024];
871         char formatstring[1024];
872
873         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|%s %%x%d");
874
875 #ifdef __sgi
876         strcat(formatstring, "|%s %%x%d");      // add space for Movie
877 #endif
878
879         strcat(formatstring, "|%s %%x%d");      // add space for PNG
880         strcat(formatstring, "|%s %%x%d");      // add space for BMP
881
882 #ifdef _WIN32
883         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
884 #endif
885
886 #ifdef WITH_QUICKTIME
887         if(G.have_quicktime)
888                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
889 #endif
890
891         if(G.have_quicktime) {
892                 sprintf(string, formatstring,
893                         "AVI Raw",        R_AVIRAW,
894                         "AVI Jpeg",       R_AVIJPEG,
895 #ifdef _WIN32
896                         "AVI Codec",      R_AVICODEC,
897 #endif
898 #ifdef WITH_QUICKTIME
899                         "QuickTime",      R_QUICKTIME,
900 #endif
901                         "Targa",          R_TARGA,
902                         "Targa Raw",      R_RAWTGA,
903                         "PNG",            R_PNG,
904                         "BMP",            R_BMP,
905                         "Jpeg",           R_JPEG90,
906                         "HamX",           R_HAMX,
907                         "Iris",           R_IRIS,
908                         "Iris + Zbuffer", R_IRIZ,
909                         "Ftype",          R_FTYPE,
910                         "Movie",          R_MOVIE
911                 );
912         } else {
913                 sprintf(string, formatstring,
914                         "AVI Raw",        R_AVIRAW,
915                         "AVI Jpeg",       R_AVIJPEG,
916 #ifdef _WIN32
917                         "AVI Codec",      R_AVICODEC,
918 #endif
919                         "Targa",          R_TARGA,
920                         "Targa Raw",      R_RAWTGA,
921                         "PNG",            R_PNG,
922                         "BMP",            R_BMP,
923                         "Jpeg",           R_JPEG90,
924                         "HamX",           R_HAMX,
925                         "Iris",           R_IRIS,
926                         "Iris + Zbuffer", R_IRIZ,
927                         "Ftype",          R_FTYPE,
928                         "Movie",          R_MOVIE
929                 );
930         }
931
932         return (string);
933 }
934
935 #ifdef _WIN32
936 static char *avicodec_str(void)
937 {
938         static char string[1024];
939
940         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
941
942         return string;
943 }
944 #endif
945
946 static void render_panel_output(void)
947 {
948         ID *id;
949         int a,b;
950         uiBlock *block;
951         char *strp;
952
953
954         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
955         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
956         
957         uiBlockBeginAlign(block);
958         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        8, 170, 20, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Pics dir/name");
959         uiDefBut(block, TEX,0,"",                                                       30, 170, 268, 19,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save rendered Pics to");
960         uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 8, 148, 20, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
961         uiDefBut(block, TEX,0,"",                                                       30, 148, 268, 19,G.scene->r.backbuf, 0.0,79.0, 0, 0, "Image to use as background for rendering");
962         uiDefIconBut(block, BUT,B_FS_FTYPE, ICON_FILESEL,       8, 125, 20, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Ftype image");
963         uiDefBut(block, TEX,0,"",                                                       30, 125, 268, 19,G.scene->r.ftype,0.0,79.0, 0, 0, "Image to use with FTYPE Image type");
964         
965         
966         /* SET BUTTON */
967         uiBlockBeginAlign(block);
968         id= (ID *)G.scene->set;
969         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
970         if(strp[0])
971                 uiDefButS(block, MENU, B_SETBROWSE, strp, 8, 96, 20, 19, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
972         MEM_freeN(strp);
973
974         if(G.scene->set) {
975                 uiSetButLock(1, NULL);
976                 uiDefIDPoinBut(block, test_scenepoin_but, 0, "",        29, 96, 100, 19, &(G.scene->set), "Name of the Set");
977                 uiClearButLock();
978                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            131, 96, 20, 19, 0, 0, 0, 0, 0, "Remove Set link");
979         }
980         uiBlockEndAlign(block);
981
982         uiBlockSetCol(block, TH_BUT_SETTING1);
983         uiDefButS(block, TOG|BIT|0, 0,"Backbuf",        8, 70, 62, 19, &G.scene->r.bufflag, 0, 0, 0, 0, "Enable/Disable use of Backbuf image"); 
984         uiBlockSetCol(block, TH_AUTO);
985                 
986         uiBlockBeginAlign(block);
987         for(b=2; b>=0; b--)
988                 for(a=0; a<3; a++)
989                         uiDefButS(block, TOG|BIT|(3*b+a), 800,"",       (short)(9+18*a),(short)(7+12*b),16,10, &R.winpos, 0, 0, 0, 0, "Render window placement on screen");
990
991         uiBlockBeginAlign(block);
992         uiDefButS(block, ROW, B_REDR, "DispView",       72, 7, 65, 19, &R.displaymode, 0.0, (float)R_DISPLAYVIEW, 0, 0, "Sets render output to display in 3D view");
993         uiDefButS(block, ROW, B_REDR, "DispWin",        139, 7, 62, 19, &R.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output to display in a seperate window");
994         uiBlockEndAlign(block);
995
996         /* yafray: enable/disable button */
997         uiDefButI(block, TOG|BIT|18, B_REDR, "YafRay", 154, 28, 141, 18, &G.scene->r.mode, 0, 0, 0, 0, "Use YafRay for rendering");
998
999         uiDefButS(block, TOG|BIT|4, 0, "Extensions",    228, 8, 67, 18, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Adds extensions to the output when rendering animations");
1000
1001         /* Toon shading buttons */
1002         uiBlockBeginAlign(block);
1003         uiDefButI(block, TOG|BIT|5, 0,"Edge",   154, 70, 47, 19, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon shading");
1004         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings |>> ", 204, 70, 93, 19, "Display edge settings");
1005         uiBlockEndAlign(block);
1006
1007         /* unified render buttons */
1008         if(G.scene->r.mode & R_UNIFIED) {
1009                 uiDefBlockBut(block, post_render_menu, NULL, "Post process |>> ", 205, 48, 92, 19, "Only for unified render");
1010                 if (G.scene->r.mode & R_GAMMA) {
1011                         uiDefButF(block, NUMSLI, 0,"Gamma:",            8, 48, 143, 19,
1012                                          &(G.scene->r.gamma), 0.2, 5.0, B_GAMMASLI, 0,
1013                                          "The gamma value for blending oversampled images (1.0 = no correction).");
1014                 }
1015         }
1016 }
1017
1018 static void render_panel_render(void)
1019 {
1020         uiBlock *block;
1021
1022
1023         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
1024         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
1025
1026         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369,142,192,47, 0, 0, 0, 0, 0, "Start the rendering");
1027
1028         uiBlockBeginAlign(block);
1029         uiDefButI(block, TOG|BIT|0, 0, "OSA",           369,114,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
1030         uiDefButS(block, ROW,B_DIFF,"5",                        369,90,28,20,&G.scene->r.osa,2.0,5.0, 0, 0, "Sets oversample level to 5");
1031         uiDefButS(block, ROW,B_DIFF,"8",                        397,90,28,20,&G.scene->r.osa,2.0,8.0, 0, 0, "Sets oversample level to 8 (Recommended)");
1032         uiDefButS(block, ROW,B_DIFF,"11",                       425,90,33,20,&G.scene->r.osa,2.0,11.0, 0, 0, "Sets oversample level to 11");
1033         uiDefButS(block, ROW,B_DIFF,"16",                       458,90,33,20,&G.scene->r.osa,2.0,16.0, 0, 0, "Sets oversample level to 16");
1034
1035         uiBlockBeginAlign(block);
1036         uiDefButI(block, TOG|BIT|14, 0, "MBLUR",        495,114,66,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
1037         uiDefButF(block, NUM,B_DIFF,"Bf:",                      495,90,65,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
1038
1039         uiBlockBeginAlign(block);
1040         uiDefButS(block, NUM,B_DIFF,"Xparts:",          369,42,99,31,&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)");
1041         uiDefButS(block, NUM,B_DIFF,"Yparts:",          472,42,86,31,&G.scene->r.yparts,1.0, 64.0, 0, 0, "Sets the number of vertical parts to render image in");
1042
1043         uiBlockBeginAlign(block);
1044         uiDefButS(block, ROW,800,"Sky",         369,11,38,24,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
1045         uiDefButS(block, ROW,800,"Premul",      410,11,54,24,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
1046         uiDefButS(block, ROW,800,"Key",         467,11,44,24,&G.scene->r.alphamode,3.0,2.0, 0, 0, "Alpha and colour values remain unchanged");
1047
1048         uiBlockBeginAlign(block);
1049         uiDefButI(block, TOG|BIT|1,0,"Shadow",  565,167,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
1050         uiDefButI(block, TOG|BIT|4,0,"EnvMap",  626,167,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map renering");
1051         uiDefButI(block, TOG|BIT|10,0,"Pano",   565,142,41,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable panorama rendering (output width is multiplied by Xparts)");
1052         uiDefButI(block, TOG|BIT|16,0,"Ray",    606,142,35,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
1053         uiDefButI(block, TOG|BIT|8,0,"Radio",   641,142,46,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
1054         
1055         uiBlockBeginAlign(block);
1056         uiDefButS(block, ROW,B_DIFF,"100%",                     565,114,121,20,&G.scene->r.size,1.0,100.0, 0, 0, "Set render size to defined size");
1057         uiDefButS(block, ROW,B_DIFF,"75%",                      565,90,36,20,&G.scene->r.size,1.0,75.0, 0, 0, "Set render size to 3/4 of defined size");
1058         uiDefButS(block, ROW,B_DIFF,"50%",                      604,90,40,20,&G.scene->r.size,1.0,50.0, 0, 0, "Set render size to 1/2 of defined size");
1059         uiDefButS(block, ROW,B_DIFF,"25%",                      647,90,39,20,&G.scene->r.size,1.0,25.0, 0, 0, "Set render size to 1/4 of defined size");
1060
1061         uiBlockBeginAlign(block);
1062         uiDefButI(block, TOG|BIT|6,0,"Fields",  564,50,60,23,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
1063         uiDefButI(block, TOG|BIT|13,0,"Odd",    624,50,40,23,&G.scene->r.mode, 0, 0, 0, 0, "Enables Odd field first rendering (Default: Even field)");
1064         uiDefButI(block, TOG|BIT|7,0,"x",               665,50,20,23,&G.scene->r.mode, 0, 0, 0, 0, "Disables time difference in field calculations");
1065
1066         uiDefButI(block, TOG|BIT|17,0,"Gauss",  564,30,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Gauss sampling filter for antialiasing");
1067         uiDefButF(block, NUM,B_DIFF,"",                 624,30,60,20,&G.scene->r.gauss,0.5, 1.5, 100, 2, "Sets the Gauss filter size)");
1068         
1069         uiDefButI(block, TOG|BIT|9,REDRAWVIEWCAM, "Border",     564,10,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image");
1070         uiDefButI(block, TOG|BIT|2,0, "Gamma",  624,10,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Enable gamma correction");
1071
1072
1073 }
1074
1075 static void render_panel_anim(void)
1076 {
1077         uiBlock *block;
1078
1079
1080         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1081         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
1082
1083
1084         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Start rendering a sequence");
1085         
1086         uiBlockSetCol(block, TH_BUT_SETTING1);
1087         uiBlockBeginAlign(block);
1088         uiDefButS(block, TOG|BIT|0, 0, "Do Sequence",   692,114,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Enables sequence output rendering (Default: 3D rendering)");
1089         uiDefButS(block, TOG|BIT|1, 0, "Render Daemon", 692,90,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Let external network render current scene");
1090         uiBlockEndAlign(block);
1091         
1092         uiBlockSetCol(block, TH_AUTO);
1093         uiDefBut(block, BUT,B_PLAYANIM, "PLAY", 692,40,94,33, 0, 0, 0, 0, 0, "Play animation of rendered images/avi (searches Pics: field)");
1094         uiDefButS(block, NUM, B_RTCHANGED, "rt:",       790,40,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
1095         
1096         uiBlockBeginAlign(block);
1097         uiDefButS(block, NUM,REDRAWSEQ,"Sta:",  692,10,94,24, &G.scene->r.sfra,1.0,18000.0, 0, 0, "The start frame of the animation");
1098         uiDefButS(block, NUM,REDRAWSEQ,"End:",  790,10,95,24, &G.scene->r.efra,1.0,18000.0, 0, 0, "The end  frame of the animation");
1099         uiBlockEndAlign(block);
1100 }
1101
1102 static void render_panel_format(void)
1103 {
1104         uiBlock *block;
1105         int yofs;
1106
1107
1108         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
1109         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
1110
1111         uiDefBlockBut(block, framing_render_menu, NULL, "Game framing settings |>> ", 892, 169, 227, 20, "Display game framing settings");
1112
1113         uiBlockBeginAlign(block);
1114         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
1115         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
1116         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspX:",     892 ,114,112,20, &G.scene->r.xasp, 1.0,200.0, 0, 0, "The horizontal aspect ratio");
1117         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspY:",     1007,114,112,20, &G.scene->r.yasp, 1.0,200.0, 0, 0, "The vertical aspect ratio");
1118         uiBlockEndAlign(block);
1119
1120         yofs = 54;
1121
1122 #ifdef __sgi
1123         yofs = 76;
1124         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");
1125         uiDefButI(block, TOG|BIT|12,0,"Cosmo", 1059,32,60,20, &G.scene->r.mode, 0, 0, 0, 0, "Attempt to save SGI movies using Cosmo hardware");
1126 #endif
1127
1128         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");
1129         uiDefButI(block, TOG|BIT|11,0, "Crop",          1068,yofs,51,20, &G.scene->r.mode, 0, 0, 0, 0, "Exclude border rendering from total image");
1130
1131         yofs -= 22;
1132
1133         if(G.scene->r.quality==0) G.scene->r.quality= 90;
1134
1135 #ifdef WITH_QUICKTIME
1136         if (G.scene->r.imtype == R_AVICODEC || G.scene->r.imtype == R_QUICKTIME) {
1137 #else /* WITH_QUICKTIME */
1138         if (0) {
1139 #endif
1140                 if(G.scene->r.imtype == R_QUICKTIME) {
1141 #ifdef WITH_QUICKTIME
1142 #if defined (_WIN32) || defined (__APPLE__)
1143                         //glColor3f(0.65, 0.65, 0.7);
1144                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1145                         if(G.scene->r.qtcodecdata == NULL)
1146                                 uiDefBut(block, LABEL, 0, "Codec: not set",  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1147                         else
1148                                 uiDefBut(block, LABEL, 0, G.scene->r.qtcodecdata->qtcodecname,  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1149                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for Quicktime");
1150 #else /* libquicktime */
1151                         if (!G.scene->r.qtcodecdata) G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData), "QtCodecData");
1152                         uiDefButI(block, MENU, B_SELECTCODEC, qtcodecs_pup(), 892,yofs, 112, 20, &qtcodec_idx, 0, 0, 0, 0, "Codec");
1153                         /* make sure the codec stored in G.scene->r.qtcodecdata matches the selected
1154                          * one, especially if it's not set.. */
1155                         if (!G.scene->r.qtcodecdata->fourcc) {
1156                                 G.scene->r.qtcodecdata->fourcc = qtcodecidx_to_fcc(qtcodec_idx-1);
1157                                 qt_init_codecdata(G.scene->r.qtcodecdata);      
1158                         }
1159
1160                         yofs -= 22;
1161                         uiDefBlockBut(block, qtcodec_menu, NULL, "Codec Settings |>> ", 892,yofs, 227, 20, "Edit Codec settings for QuickTime");
1162                         yofs +=22;
1163
1164 #endif /* libquicktime */
1165 #endif /* WITH_QUICKTIME */
1166                 } else {
1167 #ifdef _WIN32
1168                         //glColor3f(0.65, 0.65, 0.7);
1169                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1170                         if(G.scene->r.avicodecdata == NULL)
1171                                 uiDefBut(block, LABEL, 0, "Codec: not set.",  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1172                         else
1173                                 uiDefBut(block, LABEL, 0, avicodec_str(),  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1174 #endif
1175                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
1176                 }
1177         } else {
1178                 uiDefButS(block, NUM,0, "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");
1179         }
1180         uiDefButS(block, NUM,REDRAWALL,"Frs/sec:",   1006,yofs,113,20, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second");
1181
1182
1183         uiBlockBeginAlign(block);
1184         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");
1185         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");
1186         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)");
1187
1188         uiBlockBeginAlign(block);
1189         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");
1190         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");
1191         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)");
1192         uiDefBut(block, BUT,B_PR_PRV, "Preview",        1146,110,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x512, Render size 50%");
1193         uiDefBut(block, BUT,B_PR_PC, "PC",                      1146,90,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x480, Aspect ratio - 100x100");
1194         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");
1195         uiDefBut(block, BUT,B_PR_PANO, "PANO",          1146,50,100,18, 0, 0, 0, 0, 0, "Standard panorama settings");
1196         uiDefBut(block, BUT,B_PR_FULL, "FULL",          1146,30,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1280x1024, Aspect ratio - 1x1");
1197         uiDefButI(block, TOG|BIT|15, B_REDR, "Unified Renderer", 1146,10,100,18,  &G.scene->r.mode, 0, 0, 0, 0, "Use the unified renderer.");
1198         uiBlockEndAlign(block);
1199 }
1200
1201
1202 /* yafray: global illumination options panel */
1203 static void render_panel_yafrayGI()
1204 {
1205         uiBlock *block;
1206
1207         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGI", UI_EMBOSS, UI_HELV, curarea->win);
1208         uiNewPanelTabbed("Render", "Render");
1209         if(uiNewPanel(curarea, block, "YafRay GI", "Render", 320, 0, 318, 204)==0) return;
1210
1211         // label to force a boundbox for buttons not to be centered
1212         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
1213
1214         uiDefBut(block, LABEL, 0, "Method", 5,175,70,20, 0, 1.0, 0, 0, 0, "");
1215         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");
1216         uiDefBut(block, LABEL, 0, "Quality", 5,150,70,20, 0, 1.0, 0, 0, 0, "");
1217         uiDefButS(block, MENU, B_REDR, "GiQuality %t|None %x0|Low %x1|Medium %x2 |High %x3|Best %x4|", 70,150,89,20, &G.scene->r.GIquality, 0, 0, 0, 0, "Global Illumination Quality");
1218
1219         if (G.scene->r.GImethod>0) {
1220                 if (G.scene->r.GIpower==0) G.scene->r.GIpower=1;
1221                 uiDefButF(block, NUM, 0, "Power:", 5,35,154,20, &G.scene->r.GIpower, 0.01, 100.0, 0, 0, "GI lighting intensity scale, 1 is normal");
1222         }
1223         uiDefButF(block, NUMSLI, 0, "Gam ", 5,10,154,20, &G.scene->r.YF_gamma, 0.001, 5.0, 0, 0, "Gamma correction, 1 is off");
1224         uiDefButF(block, NUMSLI, 0, "Exp ", 159,10,154,20, &G.scene->r.YF_exposure, 0.0, 10.0, 0, 0, "Exposure adjustment, 0 is off");
1225         
1226   uiDefButI(block, NUM, 0, "Processors:", 159,35,154,20,
1227                                 &G.scene->r.YF_numprocs, 1.0, 8.0, 10, 10, "Number of processors to use");
1228
1229         if (G.scene->r.GImethod==2) {
1230                 if (G.scene->r.GIdepth==0) G.scene->r.GIdepth=2;
1231                 uiDefButI(block, NUM, 0, "Depth:", 180,175,110,20, &G.scene->r.GIdepth, 1.0, 8.0, 10, 10, "Number of bounces of the indirect light");
1232                 uiDefButI(block, NUM, 0, "CDepth:", 180,150,110,20, &G.scene->r.GIcausdepth, 1.0, 8.0, 10, 10, "Number of bounces inside objects (for caustics)");
1233                 uiDefButS(block,TOG|BIT|0, B_REDR, "Cache",70,125,89,20, &G.scene->r.GIcache, 0, 0, 0, 0, "Cache irradiance samples (faster)");
1234                 if (G.scene->r.GIcache) {
1235                         uiDefBut(block, LABEL, 0, "Cache parameters:", 5,105,130,20, 0, 1.0, 0, 0, 0, "");
1236                         if (G.scene->r.GIshadowquality==0.0) G.scene->r.GIshadowquality=0.9;
1237                         uiDefButF(block, NUMSLI, 0,"ShadQu ", 5,85,154,20,      &(G.scene->r.GIshadowquality), 0.0, 1.0 ,0,0, "Sets the shadow quality, keep it under 0.95 :-) ");
1238                         if (G.scene->r.GIpixelspersample==0) G.scene->r.GIpixelspersample=10;
1239                         uiDefButI(block, NUM, 0, "Pixel Precision:",    5,60,154,20, &G.scene->r.GIpixelspersample, 1, 50, 10, 10, "Maximum number of pixels without samples, the lower the better and slower");
1240                         uiDefButS(block,TOG|BIT|0, 0, "UseGradient",180,85,110,20, &G.scene->r.GIgradient, 0, 0, 0, 0, "Try to smooth lighting using a gradient");
1241                 }
1242         }
1243 }
1244
1245
1246 void render_panels()
1247 {
1248
1249         render_panel_output();
1250         render_panel_render();
1251         render_panel_anim();
1252         render_panel_format();
1253         /* yafray: GI panel only available when yafray enabled for rendering */
1254         if (G.scene->r.mode & R_YAFRAY) {
1255                 if (G.scene->r.YF_gamma==0.0) G.scene->r.YF_gamma=1.0;
1256                 render_panel_yafrayGI();
1257         }
1258
1259 }
1260
1261 /* --------------------------------------------- */
1262
1263 void anim_panels()
1264 {
1265         uiBlock *block;
1266
1267         block= uiNewBlock(&curarea->uiblocks, "anim_panel", UI_EMBOSS, UI_HELV, curarea->win);
1268         if(uiNewPanel(curarea, block, "Anim", "Anim", 0, 0, 318, 204)==0) return;
1269
1270         uiDefButS(block, NUM,REDRAWSEQ,"Sta:",  320,17,93,27,&G.scene->r.sfra,1.0,18000.0, 0, 0, "Specify the start frame of the animation");
1271         uiDefButS(block, NUM,REDRAWSEQ,"End:",  416,17,95,27,&G.scene->r.efra,1.0,18000.0, 0, 0, "Specify the end frame of the animation");
1272
1273         uiDefButS(block, NUM,B_FRAMEMAP,"Map Old:",     320,69,93,22,&G.scene->r.framapto,1.0,900.0, 0, 0, "Specify old map value in frames");
1274         uiDefButS(block, NUM,B_FRAMEMAP,"Map New:",     416,69,95,22,&G.scene->r.images,1.0,900.0, 0, 0, "Specify new map value in frames");
1275
1276         uiDefButS(block, NUM,REDRAWSEQ,"Frs/sec:",   320,47,93,19, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second");
1277
1278         uiDefButS(block, TOG|BIT|1, B_SOUND_CHANGED, "Sync",    416,47,95,19, &G.scene->audio.flag, 0, 0, 0, 0, "Use sample clock for syncing animation to audio");
1279
1280
1281 }
1282
1283 /* --------------------------------------------- */
1284
1285 void sound_panels()
1286 {
1287         bSound *sound;
1288
1289         sound = G.buts->lockpoin;
1290         if ((sound) && (sound->flags & SOUND_FLAGS_SEQUENCE)) sound = NULL;
1291
1292         sound_panel_sound(sound);
1293         sound_panel_listener();
1294         sound_panel_sequencer();
1295 }
1296
1297
1298