2256def0cd7703d23621f6ed515a7cd00c3ac3cb
[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_EMBOSSX, UI_HELV, curarea->win);
268         if(uiNewPanel(curarea, block, "Listener", "Sound", 320, 0, 318, 204)==0) return;
269
270         uiBlockSetCol(block, BUTGREY);
271         mixrate = sound_get_mixrate();
272         sprintf(mixrateinfo, "Game Mixrate: %d Hz", mixrate);
273         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
274
275         yco -= 30;
276         uiDefBut(block, LABEL, 0, "Game listener settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
277
278         yco -= 30;
279         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
280                 xco,yco,195,24,&G.listener->gain, 0.0, 1.0, 1.0, 0, "Sets the maximum volume for the overall sound");
281         
282         yco -= 30;
283         uiDefBut(block, LABEL, 0, "Game Doppler effect settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
284
285         yco -= 30;
286         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Doppler: ",
287         xco,yco,195,24,&G.listener->dopplervelocity, 0.0, 10.0, 1.0, 0, "Use this for scaling the doppler effect");
288
289         
290 }
291
292 static void sound_panel_sequencer()
293 {
294         uiBlock *block;
295         short xco, yco;
296         char mixrateinfo[256];
297         
298         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sequencer", UI_EMBOSSX, UI_HELV, curarea->win);
299         if(uiNewPanel(curarea, block, "Sequencer", "Sound", 640, 0, 318, 204)==0) return;
300
301         /* audio sequence engine settings ------------------------------------------------------------------ */
302
303         xco = 1010;
304         yco = 195;
305
306         uiDefBut(block, LABEL, 0, "Audio sequencer settings", xco,yco,295,20, 0, 0, 0, 0, 0, "");
307
308         yco -= 25;
309         sprintf(mixrateinfo, "Mixing/Sync (latency: %d ms)", (int)( (((float)U.mixbufsize)/(float)G.scene->audio.mixrate)*1000.0 ) );
310         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
311
312         yco -= 25;              
313         uiBlockSetCol(block, BUTGREY);
314         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");
315         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");
316         uiBlockSetCol(block, BUTSALMON);
317         uiDefBut(block, BUT, B_SOUND_RECALC, "Recalc",          xco+160,yco,75,20, 0, 0, 0, 0, 0, "Recalculate samples");
318
319         yco -= 25;
320         uiBlockSetCol(block, BUTGREEN);
321         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");
322         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");
323
324         yco -= 25;
325         uiDefBut(block, LABEL, 0, "Main mix", xco,yco,295,20, 0, 0, 0, 0, 0, "");
326
327         yco -= 25;              
328         uiBlockSetCol(block, BUTGREY);
329         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Main (dB): ",
330                 xco,yco,235,24,&G.scene->audio.main, -24.0, 6.0, 0, 0, "Set the audio master gain/attenuation in dB");
331
332         yco -= 25;
333         uiDefButS(block, TOG|BIT|0, 0, "Mute",  xco,yco,235,24, &G.scene->audio.flag, 0, 0, 0, 0, "Mute audio from sequencer");         
334         
335         yco -= 35;
336         uiBlockSetCol(block, BUTSALMON);
337         uiDefBut(block, BUT, B_SOUND_MIXDOWN, "MIXDOWN",        xco,yco,235,24, 0, 0, 0, 0, 0, "Create WAV file from sequenced audio");
338         
339 }
340
341 static void sound_panel_sound(bSound *sound)
342 {
343         static int packdummy=0;
344         ID *id, *idfrom;
345         uiBlock *block;
346         bSample *sample;
347         char *strp, str[32], ch[256];
348
349         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sound", UI_EMBOSSX, UI_HELV, curarea->win);
350         if(uiNewPanel(curarea, block, "Sound", "Sound", 0, 0, 318, 204)==0) return;
351         
352         uiDefBut(block, LABEL, 0, "Blender Sound block",10,180,195,20, 0, 0, 0, 0, 0, "");
353         
354         // warning: abuse of texnr here! (ton didnt code!)
355         buttons_active_id(&id, &idfrom);
356         std_libbuttons(block, 10, 160, 0, NULL, B_SOUNDBROWSE2, id, idfrom, &(G.buts->texnr), 1, 0, 0, 0, 0);
357
358         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");
359
360         if (sound) {
361         
362                 uiSetButLock(sound->id.lib!=0, "Can't edit library data");
363                 sound_initialize_sample(sound);
364                 sample = sound->sample;
365
366                 /* info string */
367                 if (sound->sample && sound->sample->len) {
368                         if (sound->sample->channels == 1) strcpy(ch, "Mono");
369                         else if (sound->sample->channels == 2) strcpy(ch, "Stereo");
370                         else strcpy(ch, "Unknown");
371                         
372                         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));
373                         uiDefBut(block, LABEL, 0, ch,                   35,140,225,20, 0, 0, 0, 0, 0, "");
374                 }
375                 else {
376                         uiDefBut(block, LABEL, 0, "Sample: No sample info available.",35,140,225,20, 0, 0, 0, 0, 0, "");
377                 }
378
379                 /* sample browse buttons */
380
381                 id= (ID *)sound->sample;
382                 IDnames_to_pupstring(&strp, NULL, NULL, samples, id, &(G.buts->menunr));
383                 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");
384                 MEM_freeN(strp);
385                 
386                 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");
387                 
388                 sprintf(str, "%d", sample->id.us);
389                 uiDefBut(block, BUT, B_SOUND_UNLINK_SAMPLE, str,        260,120,25,20, 0, 0, 0, 0, 0, "The number of users");
390                 
391                 if (sound->sample->packedfile) packdummy = 1;
392                 else packdummy = 0;
393                 
394                 uiDefIconButI(block, TOG|BIT|0, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
395                         285, 120,25,24, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
396                 
397                 uiBlockSetCol(block, BUTSALMON);
398                 uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
399
400                 uiBlockSetCol(block, BUTPURPLE);
401                 uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play",       160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
402                 
403
404                 uiBlockSetCol(block, BUTGREY);
405                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
406                         10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Set the volume of this sound");
407
408                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Pitch: ",
409                         160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Set the pitch of this sound");
410
411                 /* looping */
412                 uiBlockSetCol(block, BUTGREEN);
413                 uiDefButI(block, TOG|BIT|SOUND_FLAGS_LOOP_BIT, B_SOUND_REDRAW, "Loop",
414                         10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Toggle between looping on/off");
415
416                 if (sound->flags & SOUND_FLAGS_LOOP) {
417                         uiDefButI(block, TOG|BIT|SOUND_FLAGS_BIDIRECTIONAL_LOOP_BIT, B_SOUND_REDRAW, "Ping Pong",
418                                 105, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Toggle between A->B and A->B->A looping");
419                         
420                 }
421         
422
423                 /* 3D settings ------------------------------------------------------------------ */
424
425                 if (sound->sample->channels == 1) {
426                         uiBlockSetCol(block, BUTGREEN);
427                         uiDefButI(block, TOG|BIT|SOUND_FLAGS_3D_BIT, B_SOUND_REDRAW, "3D Sound",
428                                 10, 10, 90, 20, &sound->flags, 0, 0, 0, 0, "Turns 3D sound on");
429                         
430                         if (sound->flags & SOUND_FLAGS_3D) {
431                                 uiBlockSetCol(block, BUTGREY);
432                                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Scale: ",
433                                         100,10,210,20, &sound->attenuation, 0.0, 5.0, 1.0, 0, "Sets the surround scaling factor for this sound");
434                                 
435                         }
436                 }
437         }
438 }
439
440
441 /* ************************* SCENE *********************** */
442
443
444 static void output_pic(char *name)
445 {
446         strcpy(G.scene->r.pic, name);
447         allqueue(REDRAWBUTSSCENE, 0);
448 }
449
450 static void backbuf_pic(char *name)
451 {
452         Image *ima;
453         
454         strcpy(G.scene->r.backbuf, name);
455         allqueue(REDRAWBUTSSCENE, 0);
456
457         ima= add_image(name);
458         if(ima) {
459                 free_image_buffers(ima);        /* force read again */
460                 ima->ok= 1;
461         }
462 }
463
464 static void ftype_pic(char *name)
465 {
466         strcpy(G.scene->r.ftype, name);
467         allqueue(REDRAWBUTSSCENE, 0);
468 }
469
470
471 static void scene_change_set(Scene *sc, Scene *set) {
472         if (sc->set!=set) {
473                 sc->set= set;
474                 
475                 allqueue(REDRAWBUTSSCENE, 0);
476                 allqueue(REDRAWVIEW3D, 0);
477         }
478 }
479
480 static void run_playanim(char *file) {
481         extern char bprogname[];        /* usiblender.c */
482         char str[FILE_MAXDIR+FILE_MAXFILE];
483         int pos[2], size[2];
484
485         calc_renderwin_rectangle(R.winpos, pos, size);
486
487         sprintf(str, "%s -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
488         system(str);
489 }
490
491 void do_render_panels(unsigned short event)
492 {
493         ScrArea *sa;
494         ID *id;
495         char file[FILE_MAXDIR+FILE_MAXFILE];
496
497         switch(event) {
498
499         case B_DORENDER:
500                 BIF_do_render(0);
501                 break;
502         case B_RTCHANGED:
503                 allqueue(REDRAWALL, 0);
504                 break;
505         case B_PLAYANIM:
506 #ifdef WITH_QUICKTIME
507                 if(G.scene->r.imtype == R_QUICKTIME) 
508                         makeqtstring(file);
509                 else
510 #endif
511                         makeavistring(file);
512                 if(BLI_exist(file)) {
513                         run_playanim(file);
514                 }
515                 else {
516                         makepicstring(file, G.scene->r.sfra);
517                         if(BLI_exist(file)) {
518                                 run_playanim(file);
519                         }
520                         else error("Can't find image: %s", file);
521                 }
522                 break;
523                 
524         case B_DOANIM:
525                 BIF_do_render(1);
526                 break;
527         
528         case B_FS_PIC:
529                 sa= closest_bigger_area();
530                 areawinset(sa->win);
531                 activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
532                 break;
533         case B_FS_BACKBUF:
534                 sa= closest_bigger_area();
535                 areawinset(sa->win);
536                 activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
537                 break;
538         case B_IS_BACKBUF:
539                 sa= closest_bigger_area();
540                 areawinset(sa->win);
541                 activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
542                 break;
543         case B_FS_FTYPE:
544                 sa= closest_bigger_area();
545                 areawinset(sa->win);
546                 activate_fileselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
547                 break;
548         case B_IS_FTYPE:
549                 sa= closest_bigger_area();
550                 areawinset(sa->win);
551                 activate_imageselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
552                 break;
553         
554         case B_PR_PAL:
555                 G.scene->r.xsch= 720;
556                 G.scene->r.ysch= 576;
557                 G.scene->r.xasp= 54;
558                 G.scene->r.yasp= 51;
559                 G.scene->r.size= 100;
560                 G.scene->r.frs_sec= 25;
561                 G.scene->r.mode &= ~R_PANORAMA;
562                 G.scene->r.xparts=  G.scene->r.yparts= 1;
563                 
564                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
565                 allqueue(REDRAWBUTSSCENE, 0);
566                 allqueue(REDRAWVIEWCAM, 0);
567                 break;
568
569 #ifdef WITH_QUICKTIME
570         case B_FILETYPEMENU:
571                 allqueue(REDRAWBUTSSCENE, 0);
572 #if defined (_WIN32) || defined (__APPLE__)
573                 // fall through to codec settings if this is the first
574                 // time R_AVICODEC is selected for this scene.
575                 if (((G.scene->r.imtype == R_AVICODEC) 
576                          && (G.scene->r.avicodecdata == NULL)) ||
577                         ((G.scene->r.imtype == R_QUICKTIME) 
578                          && (G.scene->r.qtcodecdata == NULL))) {
579                 } else {
580                   break;
581                 }
582 #else /* libquicktime */
583                 if(G.scene->r.imtype == R_QUICKTIME) {
584                   /* i'm not sure if this should be here... */
585                   /* set default quicktime codec */
586                   if (!G.scene->r.qtcodecdata) {
587                         G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData), 
588                                                                                                  "QtCodecData");
589                         qtcodec_idx = 1;
590                   }
591                         
592                   qt_init_codecs();
593                   if (qtcodec_idx < 1) qtcodec_idx = 1; 
594                         
595                   G.scene->r.qtcodecdata->fourcc = 
596                         qtcodecidx_to_fcc(qtcodec_idx-1);
597                   qt_init_codecdata(G.scene->r.qtcodecdata);
598 /* I'm not sure if this is really needed, so don't remove it yet */
599 #if 0
600                   /* get index of codec that can handle a given fourcc */
601                   if (qtcodec_idx < 1)
602                         qtcodec_idx = get_qtcodec_idx(G.scene->r.qtcodecdata->fourcc)+1;
603
604                   /* no suitable codec found, alert user */
605                   if (qtcodec_idx < -1) {
606                         error("no suitable codec found!");
607                         qtcodec_idx = 1;
608                   }
609 #endif /* 0 */
610                 }
611 #endif /*_WIN32 || __APPLE__ */
612
613         case B_SELECTCODEC:
614 #if defined (_WIN32) || defined (__APPLE__)
615                 if ((G.scene->r.imtype == R_QUICKTIME)) /* || (G.scene->r.qtcodecdata)) */
616                         get_qtcodec_settings();
617 #ifdef _WIN32
618                 else
619                         get_avicodec_settings();
620 #endif /* _WIN32 */
621 #else /* libquicktime */
622                   if (!G.scene->r.qtcodecdata) {
623                         G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData), 
624                                                                                                  "QtCodecData");
625                         qtcodec_idx = 1;
626                   }
627                 if (qtcodec_idx < 1) {
628                         qtcodec_idx = 1;
629                         qt_init_codecs();
630                 }
631
632                 G.scene->r.qtcodecdata->fourcc = qtcodecidx_to_fcc(qtcodec_idx-1);
633                 /* if the selected codec differs from the previous one, reinit it */
634                 qt_init_codecdata(G.scene->r.qtcodecdata);      
635                 allqueue(REDRAWBUTSSCENE, 0);
636 #endif /* _WIN32 || __APPLE__ */
637                 break;
638 #endif /* WITH_QUICKTIME */
639
640         case B_PR_FULL:
641                 G.scene->r.xsch= 1280;
642                 G.scene->r.ysch= 1024;
643                 G.scene->r.xasp= 1;
644                 G.scene->r.yasp= 1;
645                 G.scene->r.size= 100;
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(REDRAWBUTSSCENE, 0);
651                 allqueue(REDRAWVIEWCAM, 0);
652                 break;
653         case B_PR_PRV:
654                 G.scene->r.xsch= 640;
655                 G.scene->r.ysch= 512;
656                 G.scene->r.xasp= 1;
657                 G.scene->r.yasp= 1;
658                 G.scene->r.size= 50;
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.1, 0.9, 0.1, 0.9);
663                 allqueue(REDRAWVIEWCAM, 0);
664                 allqueue(REDRAWBUTSSCENE, 0);
665                 break;
666         case B_PR_CDI:
667                 G.scene->r.xsch= 384;
668                 G.scene->r.ysch= 280;
669                 G.scene->r.xasp= 1;
670                 G.scene->r.yasp= 1;
671                 G.scene->r.size= 100;
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.15, 0.85, 0.15, 0.85);
676                 allqueue(REDRAWVIEWCAM, 0);
677                 allqueue(REDRAWBUTSSCENE, 0);
678                 break;
679         case B_PR_PAL169:
680                 G.scene->r.xsch= 720;
681                 G.scene->r.ysch= 576;
682                 G.scene->r.xasp= 64;
683                 G.scene->r.yasp= 45;
684                 G.scene->r.size= 100;
685                 G.scene->r.frs_sec= 25;
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_D2MAC:
694                 G.scene->r.xsch= 1024;
695                 G.scene->r.ysch= 576;
696                 G.scene->r.xasp= 1;
697                 G.scene->r.yasp= 1;
698                 G.scene->r.size= 50;
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_MPEG:
707                 G.scene->r.xsch= 368;
708                 G.scene->r.ysch= 272;
709                 G.scene->r.xasp= 105;
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.1, 0.9, 0.1, 0.9);
716                 allqueue(REDRAWVIEWCAM, 0);
717                 allqueue(REDRAWBUTSSCENE, 0);
718                 break;
719         case B_PR_PC:
720                 G.scene->r.xsch= 640;
721                 G.scene->r.ysch= 480;
722                 G.scene->r.xasp= 100;
723                 G.scene->r.yasp= 100;
724                 G.scene->r.size= 100;
725                 G.scene->r.mode &= ~R_PANORAMA;
726                 G.scene->r.xparts=  G.scene->r.yparts= 1;
727
728                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
729                 allqueue(REDRAWVIEWCAM, 0);
730                 allqueue(REDRAWBUTSSCENE, 0);
731                 break;
732         case B_PR_PRESET:
733                 G.scene->r.xsch= 720;
734                 G.scene->r.ysch= 576;
735                 G.scene->r.xasp= 54;
736                 G.scene->r.yasp= 51;
737                 G.scene->r.size= 100;
738                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS;
739                 G.scene->r.imtype= R_TARGA;
740                 G.scene->r.xparts=  G.scene->r.yparts= 1;
741
742                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
743                 allqueue(REDRAWVIEWCAM, 0);
744                 allqueue(REDRAWBUTSSCENE, 0);
745                 break;
746         case B_PR_PANO:
747                 G.scene->r.xsch= 36;
748                 G.scene->r.ysch= 176;
749                 G.scene->r.xasp= 115;
750                 G.scene->r.yasp= 100;
751                 G.scene->r.size= 100;
752                 G.scene->r.mode |= R_PANORAMA;
753                 G.scene->r.xparts=  16;
754                 G.scene->r.yparts= 1;
755
756                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
757                 allqueue(REDRAWVIEWCAM, 0);
758                 allqueue(REDRAWBUTSSCENE, 0);
759                 break;
760         case B_PR_NTSC:
761                 G.scene->r.xsch= 720;
762                 G.scene->r.ysch= 480;
763                 G.scene->r.xasp= 10;
764                 G.scene->r.yasp= 11;
765                 G.scene->r.size= 100;
766                 G.scene->r.frs_sec= 30;
767                 G.scene->r.mode &= ~R_PANORAMA;
768                 G.scene->r.xparts=  G.scene->r.yparts= 1;
769                 
770                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
771                 allqueue(REDRAWBUTSSCENE, 0);
772                 allqueue(REDRAWVIEWCAM, 0);
773                 break;
774
775         case B_SETBROWSE:
776                 id= (ID*) G.scene->set;
777                 
778                 if (G.buts->menunr==-2) {
779                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
780                 } else if (G.buts->menunr>0) {
781                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
782                         
783                         if (newset==G.scene)
784                                 error("Not allowed");
785                         else if (newset)
786                                 scene_change_set(G.scene, newset);
787                 }  
788                 break;
789         case B_CLEARSET:
790                 scene_change_set(G.scene, NULL);
791                 break;
792         }
793 }
794
795 static uiBlock *edge_render_menu(void *arg_unused)
796 {
797         uiBlock *block;
798         
799         block= uiNewBlock(&curarea->uiblocks,
800                           "edge render", UI_EMBOSSX, UI_HELV,
801                           curarea->win);
802                 
803         /* use this for a fake extra empy space around the buttons */
804         uiDefBut(block, LABEL, 0, "",
805 /*               285, -20, 230, 100, NULL, */
806                  285, -20, 230, 120, NULL,
807                  0, 0, 0, 0, "");
808         
809         uiDefButS(block, NUM, 0,"Eint:",
810                   295,50,70,19,
811                   &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
812                   "Sets edge intensity for Toon shading");
813         uiBlockSetCol(block, BUTGREEN);
814         uiDefButI(block, TOG, 0,"Shift",
815                   365,50,70,19,
816                   &G.compat, 0, 0, 0, 0,
817                   "For unified renderer: use old offsets for edges");
818         uiDefButI(block, TOG, 0,"All",          435,50,70,19,
819                   &G.notonlysolid, 0, 0, 0, 0,
820                   "For unified renderer: also consider transparent "
821                   "faces for toon shading");
822
823         /* colour settings for the toon shading */
824         uiBlockSetCol(block, BUTGREY);
825         uiDefButF(block, COL, B_EDGECOLSLI, "",
826                   295,-10,30,60,
827                   &(G.scene->r.edgeR), 0, 0, 0, 0,
828                   "");
829         
830         uiDefButF(block, NUMSLI, 0, "R ",
831                   325, 30, 180,19,
832                   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
833                   "For unified renderer: Colour for edges in toon shading mode.");
834         uiDefButF(block, NUMSLI, 0, "G ",
835                   325, 10, 180,19,
836                   &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
837                   "For unified renderer: Colour for edges in toon shading mode.");
838         uiDefButF(block, NUMSLI, 0, "B ",
839                   325, -10, 180,19,
840                   &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
841                   "For unified renderer: Colour for edges in toon shading mode.");
842
843         uiDefButS(block, NUM, 0,"AntiShift",
844                   365,70,140,19,
845                   &(G.scene->r.same_mat_redux), 0, 255.0, 0, 0,
846                   "For unified renderer: reduce intensity on boundaries "
847                   "with identical materials with this number.");
848         
849         uiBlockSetDirection(block, UI_TOP);
850         
851         return block;
852 }
853
854 static uiBlock *post_render_menu(void *arg_unused)
855 {
856         uiBlock *block;
857         
858         block= uiNewBlock(&curarea->uiblocks, "post render", UI_EMBOSSX, UI_HELV, curarea->win);
859                 
860         /* use this for a fake extra empy space around the buttons */
861         uiDefBut(block, LABEL, 0, "",                   -10, 10, 200, 80, NULL, 0, 0, 0, 0, "");
862         
863         uiDefButF(block, NUMSLI, 0,"Add:",              0,60,180,19,
864                          &G.scene->r.postadd, -1.0, 1.0, 0, 0, "");
865         uiDefButF(block, NUMSLI, 0,"Mul:",              0,40,180,19,
866                          &G.scene->r.postmul, 0.01, 4.0, 0, 0, "");
867         uiDefButF(block, NUMSLI, 0,"Gamma:",            0,20,180,19,
868                          &G.scene->r.postgamma, 0.2, 2.0, 0, 0, "");
869
870         uiBlockSetDirection(block, UI_TOP);
871         
872         return block;
873 }
874
875
876 static uiBlock *framing_render_menu(void *arg_unused)
877 {
878         uiBlock *block;
879         short yco = 60, xco = 0;
880         int randomcolorindex = 1234;
881
882         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSSX, UI_HELV, curarea->win);
883
884         /* use this for a fake extra empy space around the buttons */
885         uiDefBut(block, LABEL, 0, "",                   -10, -10, 300, 100, NULL, 0, 0, 0, 0, "");
886
887         uiDefBut(block, LABEL, B_NOP, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
888         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");
889         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");
890         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");
891
892         yco -= 20;
893         xco = 35;
894
895         uiDefButF(block, COL, randomcolorindex, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, 0, "");
896
897         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");
898         yco -= 20;
899         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");
900         yco -= 20;
901         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");
902
903         uiBlockSetDirection(block, UI_TOP);
904
905         return block;
906 }
907
908
909 static char *imagetype_pup(void)
910 {
911         static char string[1024];
912         char formatstring[1024];
913
914         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");
915
916 #ifdef __sgi
917         strcat(formatstring, "|%s %%x%d");      // add space for Movie
918 #endif
919
920         strcat(formatstring, "|%s %%x%d");      // add space for PNG
921
922 #ifdef _WIN32
923         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
924 #endif
925
926 #ifdef WITH_QUICKTIME
927         if(G.have_quicktime)
928                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
929 #endif
930
931         if(G.have_quicktime) {
932                 sprintf(string, formatstring,
933                         "AVI Raw",        R_AVIRAW,
934                         "AVI Jpeg",       R_AVIJPEG,
935 #ifdef _WIN32
936                         "AVI Codec",      R_AVICODEC,
937 #endif
938 #ifdef WITH_QUICKTIME
939                         "QuickTime",      R_QUICKTIME,
940 #endif
941                         "Targa",          R_TARGA,
942                         "Targa Raw",      R_RAWTGA,
943                         "PNG",            R_PNG,
944                         "Jpeg",           R_JPEG90,
945                         "HamX",           R_HAMX,
946                         "Iris",           R_IRIS,
947                         "Iris + Zbuffer", R_IRIZ,
948                         "Ftype",          R_FTYPE,
949                         "Movie",          R_MOVIE
950                 );
951         } else {
952                 sprintf(string, formatstring,
953                         "AVI Raw",        R_AVIRAW,
954                         "AVI Jpeg",       R_AVIJPEG,
955 #ifdef _WIN32
956                         "AVI Codec",      R_AVICODEC,
957 #endif
958                         "Targa",          R_TARGA,
959                         "Targa Raw",      R_RAWTGA,
960                         "PNG",            R_PNG,
961                         "Jpeg",           R_JPEG90,
962                         "HamX",           R_HAMX,
963                         "Iris",           R_IRIS,
964                         "Iris + Zbuffer", R_IRIZ,
965                         "Ftype",          R_FTYPE,
966                         "Movie",          R_MOVIE
967                 );
968         }
969
970         return (string);
971 }
972
973 #ifdef _WIN32
974 static char *avicodec_str(void)
975 {
976         static char string[1024];
977
978         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
979
980         return string;
981 }
982 #endif
983
984 static void render_panel_output()
985 {
986         ID *id;
987         int a,b;
988         uiBlock *block;
989         char *strp;
990
991
992         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSSX, UI_HELV, curarea->win);
993         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
994         
995         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");
996         uiDefBut(block, BUT,B_FS_PIC," ",               8, 170, 20, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Pics dir/name");
997         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");
998         uiDefBut(block, BUT,B_FS_BACKBUF," ",   15, 148, 10, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
999         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");
1000         uiDefBut(block, BUT,B_FS_FTYPE," ",             15, 125, 10, 19, 0, 0, 0, 0, 0, "Open Fileselect to get Ftype image");
1001         uiDefIconBut(block, BUT, B_CLEARSET, ICON_X, 131, 95, 20, 19, 0, 0, 0, 0, 0, "Remove Set link");
1002         uiBlockSetCol(block, BUTSALMON);
1003         uiDefBut(block, BUT,B_IS_BACKBUF," ",   8, 148, 10, 19, 0, 0, 0, 0, 0, "Open Imageselect to get Backbuf image");
1004         uiDefBut(block, BUT,B_IS_FTYPE," ",             8, 125, 10, 19, 0, 0, 0, 0, 0, "Open Imageselect to get Ftype image");
1005         uiBlockSetCol(block, BUTGREY);
1006
1007         /* SET BUTTON */
1008         id= (ID *)G.scene->set;
1009         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
1010         if(strp[0])
1011                 uiDefButS(block, MENU, B_SETBROWSE, strp, 8, 96, 20, 19, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
1012         MEM_freeN(strp);
1013
1014         uiBlockSetCol(block, BUTBLUE);
1015
1016         if(G.scene->set) {
1017                 uiSetButLock(1, NULL);
1018                 uiDefIDPoinBut(block, test_scenepoin_but, 0, "",                        25, 97, 104, 19, &(G.scene->set), "Name of the Set");
1019                 uiClearButLock();
1020         }
1021
1022
1023         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"); 
1024         
1025         uiBlockSetCol(block, BUTGREY);
1026                         
1027         for(b=0; b<3; b++) 
1028                 for(a=0; a<3; a++)
1029                         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");
1030
1031         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");
1032         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");
1033
1034         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");
1035
1036         /* Toon shading buttons */
1037         uiDefButS(block, TOG|BIT|5, 0,"Edge",   154, 70, 47, 19, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon shading");
1038         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings |>> ", 204, 71, 93, 19, "Display edge settings");
1039
1040         /* unified render buttons */
1041         if(G.scene->r.mode & R_UNIFIED) {
1042                 uiDefBlockBut(block, post_render_menu, NULL, "Post process |>> ", 205, 48, 92, 19, "Only for unified render");
1043                 if (G.scene->r.mode & R_GAMMA) {
1044                         uiDefButF(block, NUMSLI, 0,"Gamma:",            8, 48, 143, 19,
1045                                          &(G.scene->r.gamma), 0.2, 5.0, B_GAMMASLI, 0,
1046                                          "The gamma value for blending oversampled images (1.0 = no correction).");
1047                 }               
1048         }
1049 }
1050
1051 static void render_panel_render()
1052 {
1053         uiBlock *block;
1054
1055
1056         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSSX, UI_HELV, curarea->win);
1057         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
1058
1059         uiBlockSetCol(block, BUTSALMON);
1060         
1061         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369,142,192,47, 0, 0, 0, 0, 0, "Start the rendering");
1062         
1063         uiBlockSetCol(block, BUTGREY);
1064         
1065         uiDefButS(block, TOG|BIT|0, 0, "OSA",           369,114,124,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
1066         uiDefButF(block, NUM,B_DIFF,"Bf:",                                                      495,90,65,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 0, "Sets motion blur factor");
1067         uiDefButS(block, TOG|BIT|14, 0, "MBLUR",        495,114,66,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
1068         
1069         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");
1070         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)");
1071         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");
1072         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");
1073                 
1074         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)");
1075         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");
1076
1077         uiDefButS(block, ROW,800,"Sky",         369,11,38,24,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
1078         uiDefButS(block, ROW,800,"Premul",      410,11,54,24,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
1079         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");
1080
1081         uiBlockSetCol(block, BUTGREY);
1082         uiDefButS(block, TOG|BIT|1,0,"Shadow",  565,167,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
1083         uiDefButS(block, TOG|BIT|4,0,"EnvMap",  626,167,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map renering");
1084         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)");
1085         uiDefButS(block, TOG|BIT|8,0,"Radio",   626,142,61,22, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
1086         
1087         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");
1088         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");
1089         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");
1090         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");
1091
1092         uiDefButS(block, TOG|BIT|6,0,"Fields", 564,42,90,31,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
1093
1094         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)");
1095         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");
1096
1097         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");
1098         uiDefButS(block, TOG|BIT|2,0, "Gamma",  626,11,58,24, &G.scene->r.mode, 0, 0, 0, 0, "Enable gamma correction");
1099
1100
1101 }
1102
1103 static void render_panel_anim()
1104 {
1105         uiBlock *block;
1106
1107
1108         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSSX, UI_HELV, curarea->win);
1109         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
1110
1111
1112         uiBlockSetCol(block, BUTSALMON);
1113         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Start rendering a sequence");
1114         
1115         uiBlockSetCol(block, BUTBLUE);
1116
1117         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)");
1118         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");
1119         
1120         uiBlockSetCol(block, BUTGREY);
1121         uiDefBut(block, BUT,B_PLAYANIM, "PLAY", 692,40,94,33, 0, 0, 0, 0, 0, "Play animation of rendered images/avi (searches Pics: field)");
1122         uiDefButS(block, NUM, B_RTCHANGED, "rt:",       790,40,95,33, &G.rt, 0.0, 256.0, 0, 0, "General testing/debug button");
1123
1124         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");
1125         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");
1126
1127 }
1128
1129 static void render_panel_format()
1130 {
1131         uiBlock *block;
1132         int yofs;
1133
1134
1135         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSSX, UI_HELV, curarea->win);
1136         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
1137
1138         uiDefBlockBut(block, framing_render_menu, NULL, "Game framing settings |>> ", 892, 169, 227, 20, "Display game framing settings");
1139
1140         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
1141         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
1142         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspX:",     892 ,114,112,20, &G.scene->r.xasp, 1.0,200.0, 0, 0, "The horizontal aspect ratio");
1143         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspY:",     1007,114,112,20, &G.scene->r.yasp, 1.0,200.0, 0, 0, "The vertical aspect ratio");
1144         
1145
1146         yofs = 54;
1147
1148 #ifdef __sgi
1149         yofs = 76;
1150         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");
1151         uiBlockSetCol(block, BUTGREEN);
1152         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");
1153         uiBlockSetCol(block, BUTGREY);
1154 #endif
1155
1156         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");
1157         uiBlockSetCol(block, BUTGREEN);
1158         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");
1159         uiBlockSetCol(block, BUTGREY);
1160
1161         yofs -= 22;
1162
1163         if(G.scene->r.quality==0) G.scene->r.quality= 90;
1164
1165 #ifdef WITH_QUICKTIME
1166         if (G.scene->r.imtype == R_AVICODEC || G.scene->r.imtype == R_QUICKTIME) {
1167 #else /* WITH_QUICKTIME */
1168         if (0) {
1169 #endif
1170                 if(G.scene->r.imtype == R_QUICKTIME) {
1171 #ifdef WITH_QUICKTIME
1172 #if defined (_WIN32) || defined (__APPLE__)
1173                         glColor3f(0.65, 0.65, 0.7);
1174                         glRecti(892,yofs+46,892+225,yofs+45+20);
1175                         if(G.scene->r.qtcodecdata == NULL)
1176                                 uiDefBut(block, LABEL, 0, "Codec: not set",  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1177                         else
1178                                 uiDefBut(block, LABEL, 0, G.scene->r.qtcodecdata->qtcodecname,  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1179                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for Quicktime");
1180 #else /* libquicktime */
1181                         if (!G.scene->r.qtcodecdata) G.scene->r.qtcodecdata = MEM_callocN(sizeof(QtCodecData), "QtCodecData");
1182                         uiDefButI(block, MENU, B_SELECTCODEC, qtcodecs_pup(), 892,yofs, 112, 20, &qtcodec_idx, 0, 0, 0, 0, "Codec");
1183                         /* make sure the codec stored in G.scene->r.qtcodecdata matches the selected
1184                          * one, especially if it's not set.. */
1185                         if (!G.scene->r.qtcodecdata->fourcc) {
1186                                 G.scene->r.qtcodecdata->fourcc = qtcodecidx_to_fcc(qtcodec_idx-1);
1187                                 qt_init_codecdata(G.scene->r.qtcodecdata);      
1188                         }
1189                         
1190                         yofs -= 22;
1191                         uiDefBlockBut(block, qtcodec_menu, NULL, "Codec Settings |>> ", 892,yofs, 227, 20, "Edit Codec settings for QuickTime");
1192                         yofs +=22;
1193
1194 #endif /* libquicktime */
1195 #endif /* WITH_QUICKTIME */
1196                 } else {
1197 #ifdef _WIN32
1198                         glColor3f(0.65, 0.65, 0.7);
1199                         glRecti(892,yofs+46,892+225,yofs+45+20);
1200                         if(G.scene->r.avicodecdata == NULL)
1201                                 uiDefBut(block, LABEL, 0, "Codec: not set.",  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1202                         else
1203                                 uiDefBut(block, LABEL, 0, avicodec_str(),  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1204 #endif
1205                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
1206                 }
1207         } else {
1208                 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");
1209         }
1210         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");
1211
1212
1213
1214         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");
1215         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");
1216         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)");
1217
1218
1219         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");
1220         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");
1221         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)");
1222         uiDefBut(block, BUT,B_PR_PRV, "Preview",        1146,110,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x512, Render size 50%");
1223         uiDefBut(block, BUT,B_PR_PC, "PC",                      1146,90,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x480, Aspect ratio - 100x100");
1224         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");
1225         uiDefBut(block, BUT,B_PR_PANO, "PANO",          1146,50,100,18, 0, 0, 0, 0, 0, "Standard panorama settings");
1226         uiDefBut(block, BUT,B_PR_FULL, "FULL",          1146,30,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1280x1024, Aspect ratio - 1x1");
1227         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.");
1228
1229 }
1230
1231
1232 void render_panels()
1233 {
1234
1235         render_panel_output();
1236         render_panel_render();
1237         render_panel_anim();
1238         render_panel_format();
1239         
1240 }
1241
1242 /* --------------------------------------------- */
1243
1244 void anim_panels()
1245 {
1246         uiBlock *block;
1247         
1248         
1249         block= uiNewBlock(&curarea->uiblocks, "anim_panels", UI_EMBOSSX, UI_HELV, curarea->win);
1250
1251         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");
1252         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");
1253
1254         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");
1255         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");
1256
1257         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");
1258         
1259         uiBlockSetCol(block, BUTGREEN);
1260         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");
1261
1262
1263         uiDrawBlock(block);
1264         
1265
1266 }
1267
1268 /* --------------------------------------------- */
1269
1270 void sound_panels()
1271 {
1272         bSound *sound;
1273         
1274         sound = G.buts->lockpoin;
1275         if ((sound) && (sound->flags & SOUND_FLAGS_SEQUENCE)) sound = NULL;
1276
1277         sound_panel_sound(sound);
1278         sound_panel_listener();
1279         sound_panel_sequencer();
1280 }
1281
1282
1283