Another mega commit... loadsof restructure, and a pretty good one! :)
[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 #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()
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()
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         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");
353
354         if (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                 activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
519                 break;
520         case B_FS_BACKBUF:
521                 sa= closest_bigger_area();
522                 areawinset(sa->win);
523                 activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
524                 break;
525         case B_IS_BACKBUF:
526                 sa= closest_bigger_area();
527                 areawinset(sa->win);
528                 activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
529                 break;
530         case B_FS_FTYPE:
531                 sa= closest_bigger_area();
532                 areawinset(sa->win);
533                 activate_fileselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
534                 break;
535         case B_IS_FTYPE:
536                 sa= closest_bigger_area();
537                 areawinset(sa->win);
538                 activate_imageselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
539                 break;
540         
541         case B_PR_PAL:
542                 G.scene->r.xsch= 720;
543                 G.scene->r.ysch= 576;
544                 G.scene->r.xasp= 54;
545                 G.scene->r.yasp= 51;
546                 G.scene->r.size= 100;
547                 G.scene->r.frs_sec= 25;
548                 G.scene->r.mode &= ~R_PANORAMA;
549                 G.scene->r.xparts=  G.scene->r.yparts= 1;
550                 
551                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
552                 allqueue(REDRAWBUTSSCENE, 0);
553                 allqueue(REDRAWVIEWCAM, 0);
554                 break;
555
556 #ifdef WITH_QUICKTIME
557         case B_FILETYPEMENU:
558                 allqueue(REDRAWBUTSSCENE, 0);
559 #if defined (_WIN32) || defined (__APPLE__)
560                 // fall through to codec settings if this is the first
561                 // time R_AVICODEC is selected for this scene.
562                 if (((G.scene->r.imtype == R_AVICODEC) 
563                          && (G.scene->r.avicodecdata == NULL)) ||
564                         ((G.scene->r.imtype == R_QUICKTIME) 
565                          && (G.scene->r.qtcodecdata == NULL))) {
566                 } else {
567                   break;
568                 }
569 #else /* libquicktime */
570                 if(G.scene->r.imtype == R_QUICKTIME) {
571                   /* i'm not sure if this should be here... */
572                   /* set default quicktime codec */
573                   if (!G.scene->r.qtcodecdata) {
574                         G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData), 
575                                                                                                  "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 = 
583                         qtcodecidx_to_fcc(qtcodec_idx-1);
584                   qt_init_codecdata(G.scene->r.qtcodecdata);
585 /* I'm not sure if this is really needed, so don't remove it yet */
586 #if 0
587                   /* get index of codec that can handle a given fourcc */
588                   if (qtcodec_idx < 1)
589                         qtcodec_idx = get_qtcodec_idx(G.scene->r.qtcodecdata->fourcc)+1;
590
591                   /* no suitable codec found, alert user */
592                   if (qtcodec_idx < -1) {
593                         error("no suitable codec found!");
594                         qtcodec_idx = 1;
595                   }
596 #endif /* 0 */
597                 }
598 #endif /*_WIN32 || __APPLE__ */
599
600         case B_SELECTCODEC:
601 #if defined (_WIN32) || defined (__APPLE__)
602                 if ((G.scene->r.imtype == R_QUICKTIME)) /* || (G.scene->r.qtcodecdata)) */
603                         get_qtcodec_settings();
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), 
611                                                                                                  "QtCodecData");
612                         qtcodec_idx = 1;
613                   }
614                 if (qtcodec_idx < 1) {
615                         qtcodec_idx = 1;
616                         qt_init_codecs();
617                 }
618
619                 G.scene->r.qtcodecdata->fourcc = qtcodecidx_to_fcc(qtcodec_idx-1);
620                 /* if the selected codec differs from the previous one, reinit it */
621                 qt_init_codecdata(G.scene->r.qtcodecdata);      
622                 allqueue(REDRAWBUTSSCENE, 0);
623 #endif /* _WIN32 || __APPLE__ */
624                 break;
625 #endif /* WITH_QUICKTIME */
626
627         case B_PR_FULL:
628                 G.scene->r.xsch= 1280;
629                 G.scene->r.ysch= 1024;
630                 G.scene->r.xasp= 1;
631                 G.scene->r.yasp= 1;
632                 G.scene->r.size= 100;
633                 G.scene->r.mode &= ~R_PANORAMA;
634                 G.scene->r.xparts=  G.scene->r.yparts= 1;
635
636                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
637                 allqueue(REDRAWBUTSSCENE, 0);
638                 allqueue(REDRAWVIEWCAM, 0);
639                 break;
640         case B_PR_PRV:
641                 G.scene->r.xsch= 640;
642                 G.scene->r.ysch= 512;
643                 G.scene->r.xasp= 1;
644                 G.scene->r.yasp= 1;
645                 G.scene->r.size= 50;
646                 G.scene->r.mode &= ~R_PANORAMA;
647                 G.scene->r.xparts=  G.scene->r.yparts= 1;
648
649                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
650                 allqueue(REDRAWVIEWCAM, 0);
651                 allqueue(REDRAWBUTSSCENE, 0);
652                 break;
653         case B_PR_CDI:
654                 G.scene->r.xsch= 384;
655                 G.scene->r.ysch= 280;
656                 G.scene->r.xasp= 1;
657                 G.scene->r.yasp= 1;
658                 G.scene->r.size= 100;
659                 G.scene->r.mode &= ~R_PANORAMA;
660                 G.scene->r.xparts=  G.scene->r.yparts= 1;
661
662                 BLI_init_rctf(&G.scene->r.safety, 0.15, 0.85, 0.15, 0.85);
663                 allqueue(REDRAWVIEWCAM, 0);
664                 allqueue(REDRAWBUTSSCENE, 0);
665                 break;
666         case B_PR_PAL169:
667                 G.scene->r.xsch= 720;
668                 G.scene->r.ysch= 576;
669                 G.scene->r.xasp= 64;
670                 G.scene->r.yasp= 45;
671                 G.scene->r.size= 100;
672                 G.scene->r.frs_sec= 25;
673                 G.scene->r.mode &= ~R_PANORAMA;
674                 G.scene->r.xparts=  G.scene->r.yparts= 1;
675
676                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
677                 allqueue(REDRAWVIEWCAM, 0);
678                 allqueue(REDRAWBUTSSCENE, 0);
679                 break;
680         case B_PR_D2MAC:
681                 G.scene->r.xsch= 1024;
682                 G.scene->r.ysch= 576;
683                 G.scene->r.xasp= 1;
684                 G.scene->r.yasp= 1;
685                 G.scene->r.size= 50;
686                 G.scene->r.mode &= ~R_PANORAMA;
687                 G.scene->r.xparts=  G.scene->r.yparts= 1;
688
689                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
690                 allqueue(REDRAWVIEWCAM, 0);
691                 allqueue(REDRAWBUTSSCENE, 0);
692                 break;
693         case B_PR_MPEG:
694                 G.scene->r.xsch= 368;
695                 G.scene->r.ysch= 272;
696                 G.scene->r.xasp= 105;
697                 G.scene->r.yasp= 100;
698                 G.scene->r.size= 100;
699                 G.scene->r.mode &= ~R_PANORAMA;
700                 G.scene->r.xparts=  G.scene->r.yparts= 1;
701
702                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
703                 allqueue(REDRAWVIEWCAM, 0);
704                 allqueue(REDRAWBUTSSCENE, 0);
705                 break;
706         case B_PR_PC:
707                 G.scene->r.xsch= 640;
708                 G.scene->r.ysch= 480;
709                 G.scene->r.xasp= 100;
710                 G.scene->r.yasp= 100;
711                 G.scene->r.size= 100;
712                 G.scene->r.mode &= ~R_PANORAMA;
713                 G.scene->r.xparts=  G.scene->r.yparts= 1;
714
715                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
716                 allqueue(REDRAWVIEWCAM, 0);
717                 allqueue(REDRAWBUTSSCENE, 0);
718                 break;
719         case B_PR_PRESET:
720                 G.scene->r.xsch= 720;
721                 G.scene->r.ysch= 576;
722                 G.scene->r.xasp= 54;
723                 G.scene->r.yasp= 51;
724                 G.scene->r.size= 100;
725                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS;
726                 G.scene->r.imtype= R_TARGA;
727                 G.scene->r.xparts=  G.scene->r.yparts= 1;
728
729                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
730                 allqueue(REDRAWVIEWCAM, 0);
731                 allqueue(REDRAWBUTSSCENE, 0);
732                 break;
733         case B_PR_PANO:
734                 G.scene->r.xsch= 36;
735                 G.scene->r.ysch= 176;
736                 G.scene->r.xasp= 115;
737                 G.scene->r.yasp= 100;
738                 G.scene->r.size= 100;
739                 G.scene->r.mode |= R_PANORAMA;
740                 G.scene->r.xparts=  16;
741                 G.scene->r.yparts= 1;
742
743                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
744                 allqueue(REDRAWVIEWCAM, 0);
745                 allqueue(REDRAWBUTSSCENE, 0);
746                 break;
747         case B_PR_NTSC:
748                 G.scene->r.xsch= 720;
749                 G.scene->r.ysch= 480;
750                 G.scene->r.xasp= 10;
751                 G.scene->r.yasp= 11;
752                 G.scene->r.size= 100;
753                 G.scene->r.frs_sec= 30;
754                 G.scene->r.mode &= ~R_PANORAMA;
755                 G.scene->r.xparts=  G.scene->r.yparts= 1;
756                 
757                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
758                 allqueue(REDRAWBUTSSCENE, 0);
759                 allqueue(REDRAWVIEWCAM, 0);
760                 break;
761
762         case B_SETBROWSE:
763                 id= (ID*) G.scene->set;
764                 
765                 if (G.buts->menunr==-2) {
766                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
767                 } else if (G.buts->menunr>0) {
768                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
769                         
770                         if (newset==G.scene)
771                                 error("Not allowed");
772                         else if (newset)
773                                 scene_change_set(G.scene, newset);
774                 }  
775                 break;
776         case B_CLEARSET:
777                 scene_change_set(G.scene, NULL);
778                 break;
779         }
780 }
781
782 static uiBlock *edge_render_menu(void *arg_unused)
783 {
784         uiBlock *block;
785         
786         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
787                 
788         /* use this for a fake extra empy space around the buttons */
789         uiDefBut(block, LABEL, 0, "",  285, -20, 230, 120, NULL,  0, 0, 0, 0, "");
790         
791         uiDefButS(block, NUM, 0,"Eint:",  295,50,70,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
792                   "Sets edge intensity for Toon shading");
793         uiDefButI(block, TOG, 0,"Shift", 365,50,70,19,  &G.compat, 0, 0, 0, 0,
794                   "For unified renderer: use old offsets for edges");
795         uiDefButI(block, TOG, 0,"All",          435,50,70,19,  &G.notonlysolid, 0, 0, 0, 0,
796                   "For unified renderer: also consider transparent faces for toon shading");
797
798         /* colour settings for the toon shading */
799         uiDefButF(block, COL, B_EDGECOLSLI, "", 295,-10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, 0, "");
800         
801         uiDefButF(block, NUMSLI, 0, "R ",   325, 30, 180,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
802                   "For unified renderer: Colour for edges in toon shading mode.");
803         uiDefButF(block, NUMSLI, 0, "G ",  325, 10, 180,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
804                   "For unified renderer: Colour for edges in toon shading mode.");
805         uiDefButF(block, NUMSLI, 0, "B ",  325, -10, 180,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
806                   "For unified renderer: Colour for edges in toon shading mode.");
807
808         uiDefButS(block, NUM, 0,"AntiShift",   365,70,140,19,  &(G.scene->r.same_mat_redux), 0, 255.0, 0, 0,
809                   "For unified renderer: reduce intensity on boundaries "
810                   "with identical materials with this number.");
811         
812         uiBlockSetDirection(block, UI_TOP);
813         
814         return block;
815 }
816
817 static uiBlock *post_render_menu(void *arg_unused)
818 {
819         uiBlock *block;
820         
821         block= uiNewBlock(&curarea->uiblocks, "post render", UI_EMBOSS, UI_HELV, curarea->win);
822                 
823         /* use this for a fake extra empy space around the buttons */
824         uiDefBut(block, LABEL, 0, "",                   -10, 10, 200, 80, NULL, 0, 0, 0, 0, "");
825         
826         uiDefButF(block, NUMSLI, 0,"Add:",              0,60,180,19,  &G.scene->r.postadd, -1.0, 1.0, 0, 0, "");
827         uiDefButF(block, NUMSLI, 0,"Mul:",              0,40,180,19,  &G.scene->r.postmul, 0.01, 4.0, 0, 0, "");
828         uiDefButF(block, NUMSLI, 0,"Gamma:",            0,20,180,19,  &G.scene->r.postgamma, 0.2, 2.0, 0, 0, "");
829
830         uiBlockSetDirection(block, UI_TOP);
831         
832         return block;
833 }
834
835
836 static uiBlock *framing_render_menu(void *arg_unused)
837 {
838         uiBlock *block;
839         short yco = 60, xco = 0;
840         int randomcolorindex = 1234;
841
842         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
843
844         /* use this for a fake extra empy space around the buttons */
845         uiDefBut(block, LABEL, 0, "",                   -10, -10, 300, 100, NULL, 0, 0, 0, 0, "");
846
847         uiDefBut(block, LABEL, B_NOP, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
848         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");
849         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");
850         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");
851
852         yco -= 20;
853         xco = 35;
854
855         uiDefButF(block, COL, randomcolorindex, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, 0, "");
856
857         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");
858         yco -= 20;
859         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");
860         yco -= 20;
861         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");
862
863         uiBlockSetDirection(block, UI_TOP);
864
865         return block;
866 }
867
868
869 static char *imagetype_pup(void)
870 {
871         static char string[1024];
872         char formatstring[1024];
873
874         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");
875
876 #ifdef __sgi
877         strcat(formatstring, "|%s %%x%d");      // add space for Movie
878 #endif
879
880         strcat(formatstring, "|%s %%x%d");      // add space for PNG
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                         "Jpeg",           R_JPEG90,
905                         "HamX",           R_HAMX,
906                         "Iris",           R_IRIS,
907                         "Iris + Zbuffer", R_IRIZ,
908                         "Ftype",          R_FTYPE,
909                         "Movie",          R_MOVIE
910                 );
911         } else {
912                 sprintf(string, formatstring,
913                         "AVI Raw",        R_AVIRAW,
914                         "AVI Jpeg",       R_AVIJPEG,
915 #ifdef _WIN32
916                         "AVI Codec",      R_AVICODEC,
917 #endif
918                         "Targa",          R_TARGA,
919                         "Targa Raw",      R_RAWTGA,
920                         "PNG",            R_PNG,
921                         "Jpeg",           R_JPEG90,
922                         "HamX",           R_HAMX,
923                         "Iris",           R_IRIS,
924                         "Iris + Zbuffer", R_IRIZ,
925                         "Ftype",          R_FTYPE,
926                         "Movie",          R_MOVIE
927                 );
928         }
929
930         return (string);
931 }
932
933 #ifdef _WIN32
934 static char *avicodec_str(void)
935 {
936         static char string[1024];
937
938         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
939
940         return string;
941 }
942 #endif
943
944 static void render_panel_output()
945 {
946         ID *id;
947         int a,b;
948         uiBlock *block;
949         char *strp;
950
951
952         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
953         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
954         
955         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");
956         uiDefBut(block, BUT,B_FS_PIC," ",               8, 170, 20, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Pics dir/name");
957         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");
958         uiDefBut(block, BUT,B_FS_BACKBUF," ",   15, 148, 10, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
959         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");
960         uiDefBut(block, BUT,B_FS_FTYPE," ",             15, 125, 10, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Ftype image");
961         uiDefIconBut(block, BUT, B_CLEARSET, ICON_X, 131, 95, 20, 19, 0, 0, 0, 0, 0, "Remove Set link");
962         uiDefBut(block, BUT,B_IS_BACKBUF," ",   8, 148, 10, 19, 0, 0, 0, 0, 0, "Open Imageselect to get Backbuf image");
963         uiDefBut(block, BUT,B_IS_FTYPE," ",             8, 125, 10, 19, 0, 0, 0, 0, 0, "Open Imageselect to get Ftype image");
964
965         /* SET BUTTON */
966         id= (ID *)G.scene->set;
967         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
968         if(strp[0])
969                 uiDefButS(block, MENU, B_SETBROWSE, strp, 8, 96, 20, 19, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
970         MEM_freeN(strp);
971
972         uiBlockSetCol(block, TH_BUT_SETTING1);
973
974         if(G.scene->set) {
975                 uiSetButLock(1, NULL);
976                 uiDefIDPoinBut(block, test_scenepoin_but, 0, "",                        25, 97, 104, 19, &(G.scene->set), "Name of the Set");
977                 uiClearButLock();
978         }
979
980
981         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"); 
982         
983         uiBlockSetCol(block, TH_AUTO);
984                         
985         for(b=0; b<3; b++) 
986                 for(a=0; a<3; a++)
987                         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");
988
989         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");
990         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");
991
992         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");
993
994         /* Toon shading buttons */
995         uiDefButS(block, TOG|BIT|5, 0,"Edge",   154, 70, 47, 19, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon shading");
996         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings |>> ", 204, 71, 93, 19, "Display edge settings");
997
998         /* unified render buttons */
999         if(G.scene->r.mode & R_UNIFIED) {
1000                 uiDefBlockBut(block, post_render_menu, NULL, "Post process |>> ", 205, 48, 92, 19, "Only for unified render");
1001                 if (G.scene->r.mode & R_GAMMA) {
1002                         uiDefButF(block, NUMSLI, 0,"Gamma:",            8, 48, 143, 19,
1003                                          &(G.scene->r.gamma), 0.2, 5.0, B_GAMMASLI, 0,
1004                                          "The gamma value for blending oversampled images (1.0 = no correction).");
1005                 }               
1006         }
1007 }
1008
1009 static void render_panel_render()
1010 {
1011         uiBlock *block;
1012
1013
1014         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
1015         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
1016
1017         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369,142,192,47, 0, 0, 0, 0, 0, "Start the rendering");
1018         
1019         uiDefButS(block, TOG|BIT|0, 0, "OSA",           369,114,124,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
1020         uiDefButF(block, NUM,B_DIFF,"Bf:",                                                      495,90,65,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 0, "Sets motion blur factor");
1021         uiDefButS(block, TOG|BIT|14, 0, "MBLUR",        495,114,66,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
1022         
1023         uiDefButS(block, ROW,B_DIFF,"5",                        369,90,29,20,&G.scene->r.osa,2.0,5.0, 0, 0, "Sets oversample level to 5");
1024         uiDefButS(block, ROW,B_DIFF,"8",                        400,90,29,20,&G.scene->r.osa,2.0,8.0, 0, 0, "Sets oversample level to 8 (Recommended)");
1025         uiDefButS(block, ROW,B_DIFF,"11",                       431,90,33,20,&G.scene->r.osa,2.0,11.0, 0, 0, "Sets oversample level to 11");
1026         uiDefButS(block, ROW,B_DIFF,"16",                       466,90,28,20,&G.scene->r.osa,2.0,16.0, 0, 0, "Sets oversample level to 16");
1027                 
1028         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)");
1029         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");
1030
1031         uiDefButS(block, ROW,800,"Sky",         369,11,38,24,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
1032         uiDefButS(block, ROW,800,"Premul",      410,11,54,24,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
1033         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");
1034
1035         uiDefButS(block, TOG|BIT|1,0,"Shadow",  565,167,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
1036         uiDefButS(block, TOG|BIT|4,0,"EnvMap",  626,167,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map renering");
1037         uiDefButS(block, TOG|BIT|10,0,"Pano",   565,142,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable panorama rendering (output width is multiplied by Xparts)");
1038         uiDefButS(block, TOG|BIT|8,0,"Radio",   626,142,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
1039         
1040         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");
1041         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");
1042         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");
1043         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");
1044
1045         uiDefButS(block, TOG|BIT|6,0,"Fields", 564,42,90,31,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
1046
1047         uiDefButS(block, TOG|BIT|13,0,"Odd",    655,57,30,16,&G.scene->r.mode, 0, 0, 0, 0, "Enables Odd field first rendering (Default: Even field)");
1048         uiDefButS(block, TOG|BIT|7,0,"x",               655,42,30,15,&G.scene->r.mode, 0, 0, 0, 0, "Disables time difference in field calculations");
1049
1050         uiDefButS(block, TOG|BIT|9,REDRAWVIEWCAM, "Border",     565,11,58,24, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image");
1051         uiDefButS(block, TOG|BIT|2,0, "Gamma",  626,11,58,24, &G.scene->r.mode, 0, 0, 0, 0, "Enable gamma correction");
1052
1053
1054 }
1055
1056 static void render_panel_anim()
1057 {
1058         uiBlock *block;
1059
1060
1061         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1062         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
1063
1064
1065         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Start rendering a sequence");
1066         
1067         uiBlockSetCol(block, TH_BUT_SETTING1);
1068         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)");
1069         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");
1070         
1071         uiBlockSetCol(block, TH_AUTO);
1072         uiDefBut(block, BUT,B_PLAYANIM, "PLAY", 692,40,94,33, 0, 0, 0, 0, 0, "Play animation of rendered images/avi (searches Pics: field)");
1073         uiDefButS(block, NUM, B_RTCHANGED, "rt:",       790,40,95,33, &G.rt, 0.0, 256.0, 0, 0, "General testing/debug button");
1074
1075         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");
1076         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");
1077
1078 }
1079
1080 static void render_panel_format()
1081 {
1082         uiBlock *block;
1083         int yofs;
1084
1085
1086         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
1087         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
1088
1089         uiDefBlockBut(block, framing_render_menu, NULL, "Game framing settings |>> ", 892, 169, 227, 20, "Display game framing settings");
1090
1091         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
1092         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
1093         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspX:",     892 ,114,112,20, &G.scene->r.xasp, 1.0,200.0, 0, 0, "The horizontal aspect ratio");
1094         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspY:",     1007,114,112,20, &G.scene->r.yasp, 1.0,200.0, 0, 0, "The vertical aspect ratio");
1095         
1096
1097         yofs = 54;
1098
1099 #ifdef __sgi
1100         yofs = 76;
1101         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");
1102         uiDefButS(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");
1103 #endif
1104
1105         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");
1106         uiDefButS(block, TOG|BIT|11,0, "Crop",          1068,yofs,51,20, &G.scene->r.mode, 0, 0, 0, 0, "Exclude border rendering from total image");
1107
1108         yofs -= 22;
1109
1110         if(G.scene->r.quality==0) G.scene->r.quality= 90;
1111
1112 #ifdef WITH_QUICKTIME
1113         if (G.scene->r.imtype == R_AVICODEC || G.scene->r.imtype == R_QUICKTIME) {
1114 #else /* WITH_QUICKTIME */
1115         if (0) {
1116 #endif
1117                 if(G.scene->r.imtype == R_QUICKTIME) {
1118 #ifdef WITH_QUICKTIME
1119 #if defined (_WIN32) || defined (__APPLE__)
1120                         glColor3f(0.65, 0.65, 0.7);
1121                         glRecti(892,yofs+46,892+225,yofs+45+20);
1122                         if(G.scene->r.qtcodecdata == NULL)
1123                                 uiDefBut(block, LABEL, 0, "Codec: not set",  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1124                         else
1125                                 uiDefBut(block, LABEL, 0, G.scene->r.qtcodecdata->qtcodecname,  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1126                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for Quicktime");
1127 #else /* libquicktime */
1128                         if (!G.scene->r.qtcodecdata) G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData), "QtCodecData");
1129                         uiDefButI(block, MENU, B_SELECTCODEC, qtcodecs_pup(), 892,yofs, 112, 20, &qtcodec_idx, 0, 0, 0, 0, "Codec");
1130                         /* make sure the codec stored in G.scene->r.qtcodecdata matches the selected
1131                          * one, especially if it's not set.. */
1132                         if (!G.scene->r.qtcodecdata->fourcc) {
1133                                 G.scene->r.qtcodecdata->fourcc = qtcodecidx_to_fcc(qtcodec_idx-1);
1134                                 qt_init_codecdata(G.scene->r.qtcodecdata);      
1135                         }
1136                         
1137                         yofs -= 22;
1138                         uiDefBlockBut(block, qtcodec_menu, NULL, "Codec Settings |>> ", 892,yofs, 227, 20, "Edit Codec settings for QuickTime");
1139                         yofs +=22;
1140
1141 #endif /* libquicktime */
1142 #endif /* WITH_QUICKTIME */
1143                 } else {
1144 #ifdef _WIN32
1145                         glColor3f(0.65, 0.65, 0.7);
1146                         glRecti(892,yofs+46,892+225,yofs+45+20);
1147                         if(G.scene->r.avicodecdata == NULL)
1148                                 uiDefBut(block, LABEL, 0, "Codec: not set.",  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1149                         else
1150                                 uiDefBut(block, LABEL, 0, avicodec_str(),  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1151 #endif
1152                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
1153                 }
1154         } else {
1155                 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");
1156         }
1157         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");
1158
1159
1160
1161         uiDefButS(block, ROW,B_DIFF,"BW",                       892, 10,74,20, &G.scene->r.planes, 5.0,(float)R_PLANESBW, 0, 0, "Images are saved with BW (grayscale) data");
1162         uiDefButS(block, ROW,B_DIFF,"RGB",                  968, 10,74,20, &G.scene->r.planes, 5.0,(float)R_PLANES24, 0, 0, "Images are saved with RGB (color) data");
1163         uiDefButS(block, ROW,B_DIFF,"RGBA",                1044, 10,75,20, &G.scene->r.planes, 5.0,(float)R_PLANES32, 0, 0, "Images are saved with RGB and Alpha data (if supported)");
1164
1165
1166         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");
1167         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");
1168         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)");
1169         uiDefBut(block, BUT,B_PR_PRV, "Preview",        1146,110,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x512, Render size 50%");
1170         uiDefBut(block, BUT,B_PR_PC, "PC",                      1146,90,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x480, Aspect ratio - 100x100");
1171         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");
1172         uiDefBut(block, BUT,B_PR_PANO, "PANO",          1146,50,100,18, 0, 0, 0, 0, 0, "Standard panorama settings");
1173         uiDefBut(block, BUT,B_PR_FULL, "FULL",          1146,30,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1280x1024, Aspect ratio - 1x1");
1174         uiDefButS(block, TOG|BIT|15, B_REDR, "Unified Renderer", 1146,10,100,18,  &G.scene->r.mode, 0, 0, 0, 0, "Use the unified renderer.");
1175
1176 }
1177
1178
1179 void render_panels()
1180 {
1181
1182         render_panel_output();
1183         render_panel_render();
1184         render_panel_anim();
1185         render_panel_format();
1186         
1187 }
1188
1189 /* --------------------------------------------- */
1190
1191 void anim_panels()
1192 {
1193         uiBlock *block;
1194         
1195         
1196         block= uiNewBlock(&curarea->uiblocks, "anim_panels", UI_EMBOSS, UI_HELV, curarea->win);
1197
1198         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");
1199         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");
1200
1201         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");
1202         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");
1203
1204         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");
1205         
1206         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");
1207
1208
1209         uiDrawBlock(block);
1210         
1211
1212 }
1213
1214 /* --------------------------------------------- */
1215
1216 void sound_panels()
1217 {
1218         bSound *sound;
1219         
1220         sound = G.buts->lockpoin;
1221         if ((sound) && (sound->flags & SOUND_FLAGS_SEQUENCE)) sound = NULL;
1222
1223         sound_panel_sound(sound);
1224         sound_panel_listener();
1225         sound_panel_sequencer();
1226 }
1227
1228
1229