Added support for outputting bmp's
[blender.git] / source / blender / src / toets.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  *
34  * General blender hot keys (toets = dutch), special hotkeys are in space.c
35  *
36  */
37
38 #include <string.h>
39 #include <math.h>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #ifdef WIN32
46 #include "BLI_winstuff.h"
47 #endif
48
49 #include "MEM_guardedalloc.h"
50
51 #include "PIL_time.h"
52
53 #include "nla.h"        /* Only for the #ifdef flag - To be removed later */
54
55 #include "BLI_blenlib.h"
56 #include "BLI_arithb.h"
57
58 #include "DNA_object_types.h"
59 #include "DNA_screen_types.h"
60 #include "DNA_space_types.h"
61 #include "DNA_view3d_types.h"
62
63 #include "BKE_utildefines.h"
64 #include "BKE_global.h"
65 #include "BKE_anim.h"
66 #include "BKE_scene.h"
67 #include "BKE_ipo.h"
68 #include "BKE_action.h"
69 #include "BKE_ika.h"
70 #include "BKE_key.h"
71
72 #include "BIF_interface.h"
73 #include "BIF_screen.h"
74 #include "BIF_space.h"
75 #include "BIF_butspace.h"
76 #include "BIF_renderwin.h"
77 #include "BIF_toolbox.h"
78 #include "BIF_toets.h"
79 #include "BIF_editseq.h"
80 #include "BIF_editsound.h"
81 #include "BIF_poseobject.h"
82 #include "BIF_usiblender.h"
83
84 #include "BDR_vpaint.h"
85 #include "BDR_editobject.h"
86 #include "BDR_editface.h"
87
88 #include "BSE_filesel.h"        /* For activate_fileselect */
89 #include "BSE_drawview.h"       /* For play_anim */
90 #include "BSE_view.h"
91 #include "BSE_edit.h"
92 #include "BSE_editipo.h"
93 #include "BSE_headerbuttons.h"
94
95 #include "blendef.h"
96 #include "render.h"
97
98 #include "IMB_imbuf.h"
99 #include "IMB_imbuf_types.h"
100
101 #include "mydevice.h"
102
103 #include "BIF_poseobject.h"
104
105 /* only used in toets.c */
106 /* this function doesn't really belong here */
107 /* ripped from render module */
108 void schrijfplaatje(char *name);
109
110
111 void write_imag(char *name)
112 {
113         /* from file select */
114         char str[256];
115
116         strcpy(str, name);
117         BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
118
119         if(saveover(str)) {
120                 if(BLI_testextensie(str,".blend")) {
121                         error("Wrong filename");
122                         return;
123                 }
124                 waitcursor(1); /* from screen.c */
125                 schrijfplaatje(str);
126                 strcpy(G.ima, name);
127                 waitcursor(0);
128         }
129 }
130
131
132 /* From matrix.h: it's really a [4][4]! */
133 /* originally in initrender... maybe add fileControl thingy? */
134
135 /* should be called write_image(char *name) :-) */
136 void schrijfplaatje(char *name)
137 {
138         struct ImBuf *ibuf=0;
139         unsigned int *temprect=0;
140         char str[FILE_MAXDIR+FILE_MAXFILE];
141
142         /* has RGBA been set? If so: use alpha channel for color zero */
143         IMB_alpha_to_col0(FALSE);
144
145         if(R.r.planes == 32) {
146                 /* everything with less than 50 % alpha -> col 0 */
147                 if(R.r.alphamode == R_ALPHAKEY) IMB_alpha_to_col0(2);
148                 /* only when 0 alpha -> col 0 */
149                 else IMB_alpha_to_col0(1);
150         }
151
152         /* Seems to me this is also superfluous.... */
153         if (R.r.imtype==R_FTYPE) {
154                 strcpy(str, R.r.ftype);
155                 BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
156
157                 ibuf = IMB_loadiffname(str, IB_test);
158                 if(ibuf) {
159                         ibuf->x = R.rectx;
160                         ibuf->y = R.recty;
161                 }
162                 else {
163                         error("Can't find filetype");
164                         G.afbreek= 1;
165                         return;
166                 }
167                 /* setdither(2); */
168         }
169
170         if(ibuf == 0) {
171                 ibuf= IMB_allocImBuf(R.rectx, R.recty, R.r.planes, 0, 0);
172         }
173
174         if(ibuf) {
175                 ibuf->rect= (unsigned int *) R.rectot;
176
177                 if(R.r.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
178
179                 if(R.r.imtype== R_IRIS) {
180                         ibuf->ftype= IMAGIC;
181                 }
182                 else if(R.r.imtype==R_IRIZ) {
183                         ibuf->ftype= IMAGIC;
184                         if (ibuf->zbuf == 0) {
185                                 if (R.rectz) {
186                                         ibuf->zbuf = (int *)R.rectz;
187                                 }
188                                 else printf("no zbuf\n");
189                         }
190                 }
191                 else if(R.r.imtype==R_PNG) {
192                         ibuf->ftype= PNG;
193                 }
194                 else if(R.r.imtype==R_BMP) {
195                         ibuf->ftype= BMP;
196                 }
197                 else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) {
198                         ibuf->ftype= TGA;
199                 }
200                 else if(R.r.imtype==R_RAWTGA) {
201                         ibuf->ftype= RAWTGA;
202                 }
203                 else if(R.r.imtype==R_HAMX) {
204                         /* make copy */
205                         temprect= MEM_dupallocN(R.rectot);
206                         ibuf->ftype= AN_hamx;
207                 }
208                 else if(ELEM5(R.r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) {
209                         if(R.r.quality < 10) R.r.quality= 90;
210
211                         if(R.r.mode & R_FIELDS) ibuf->ftype= JPG_VID|R.r.quality;
212                         else ibuf->ftype= JPG|R.r.quality;
213                 }
214         
215                 RE_make_existing_file(name);
216
217                 if(IMB_saveiff(ibuf, name, IB_rect | IB_zbuf)==0) {
218                         perror(name);
219                         G.afbreek= 1;
220                 }
221
222                 IMB_freeImBuf(ibuf);
223
224                 if (R.r.imtype==R_HAMX) {
225                         MEM_freeN(R.rectot);
226                         R.rectot= temprect;
227                 }
228         }
229         else {
230                 G.afbreek= 1;
231         }
232 }
233
234
235
236 /* ------------------------------------------------------------------------- */
237
238 static int is_an_active_object(void *ob) {
239         Base *base;
240         
241         for (base= FIRSTBASE; base; base= base->next)
242                 if (base->object == ob)
243                         return 1;
244         
245         return 0;
246 }
247
248 void persptoetsen(unsigned short event)
249 {
250         static Object *oldcamera=0;
251         float phi, si, q1[4], vec[3];
252         static int perspo=1;
253         
254         if(event==PADENTER) {
255                 if (G.qual == LR_SHIFTKEY) {
256                         view3d_set_1_to_1_viewborder(G.vd);
257                 } else {
258                         if (G.vd->persp==2) {
259                                 G.vd->camzoom= 0.0;
260                         } else {
261                                 G.vd->dist= 10.0;
262                         }
263                 }
264         }
265         else if((G.qual & (LR_SHIFTKEY | LR_CTRLKEY)) && (event != PAD0)) {
266                 if(event==PAD0) {
267                         /* G.vd->persp= 3; */
268                 }
269                 else if(event==PAD7) {
270                         G.vd->viewquat[0]= 0.0;
271                         G.vd->viewquat[1]= -1.0;
272                         G.vd->viewquat[2]= 0.0;
273                         G.vd->viewquat[3]= 0.0;
274                         G.vd->view= 7;
275                         if(G.vd->persp>=2) G.vd->persp= perspo;
276                 }
277                 else if(event==PAD1) {
278                         G.vd->viewquat[0]= 0.0;
279                         G.vd->viewquat[1]= 0.0;
280                         G.vd->viewquat[2]= (float)-cos(M_PI/4.0);
281                         G.vd->viewquat[3]= (float)-cos(M_PI/4.0);
282                         G.vd->view=1;
283                         if(G.vd->persp>=2) G.vd->persp= perspo;
284                 }
285                 else if(event==PAD3) {
286                         G.vd->viewquat[0]= 0.5;
287                         G.vd->viewquat[1]= -0.5;
288                         G.vd->viewquat[2]= 0.5;
289                         G.vd->viewquat[3]= 0.5;
290                         G.vd->view=3;
291                         if(G.vd->persp>=2) G.vd->persp= perspo;
292                 }
293                 else if(event==PADMINUS) {
294                         /* this min and max is also in viewmove() */
295                         if(G.vd->persp==2) {
296                                         G.vd->camzoom-= 10;
297                                         if(G.vd->camzoom<-30) G.vd->camzoom= -30;
298                                 }
299                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
300                 }
301                 else if(event==PADPLUSKEY) {
302                         if(G.vd->persp==2) {
303                                         G.vd->camzoom+= 10;
304                                         if(G.vd->camzoom>300) G.vd->camzoom= 300;
305                         }
306                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
307                 }
308                 else {
309
310                         initgrabz(0.0, 0.0, 0.0);
311                         
312                         if(event==PAD6) window_to_3d(vec, -32, 0);
313                         else if(event==PAD4) window_to_3d(vec, 32, 0);
314                         else if(event==PAD8) window_to_3d(vec, 0, -25);
315                         else if(event==PAD2) window_to_3d(vec, 0, 25);
316                         G.vd->ofs[0]+= vec[0];
317                         G.vd->ofs[1]+= vec[1];
318                         G.vd->ofs[2]+= vec[2];
319                 }
320         }
321         else {
322
323                 if(event==PAD7) {
324                         G.vd->viewquat[0]= 1.0;
325                         G.vd->viewquat[1]= 0.0;
326                         G.vd->viewquat[2]= 0.0;
327                         G.vd->viewquat[3]= 0.0;
328                         G.vd->view=7;
329                         if(G.vd->persp>=2) G.vd->persp= perspo;
330                 }
331                 else if(event==PAD1) {
332                         G.vd->viewquat[0]= (float)cos(M_PI/4.0);
333                         G.vd->viewquat[1]= (float)-sin(M_PI/4.0);
334                         G.vd->viewquat[2]= 0.0;
335                         G.vd->viewquat[3]= 0.0;
336                         G.vd->view=1;
337                         if(G.vd->persp>=2) G.vd->persp= perspo;
338                 }
339                 else if(event==PAD3) {
340                         G.vd->viewquat[0]= 0.5;
341                         G.vd->viewquat[1]= -0.5;
342                         G.vd->viewquat[2]= -0.5;
343                         G.vd->viewquat[3]= -0.5;
344                         G.vd->view=3;
345                         if(G.vd->persp>=2) G.vd->persp= perspo;
346                 }
347                 else if(event==PADMINUS) {
348                         /* this min and max is also in viewmove() */
349                         if(G.vd->persp==2) {
350                                 G.vd->camzoom= MAX2(-30, G.vd->camzoom-5);
351                         }
352                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
353                 }
354                 else if(event==PADPLUSKEY) {
355                         if(G.vd->persp==2) {
356                                 G.vd->camzoom= MIN2(300, G.vd->camzoom+5);
357                         }
358                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
359                 }
360                 else if(event==PAD5) {
361                         if(G.vd->persp==1) G.vd->persp=0;
362                         else G.vd->persp=1;
363                 }
364                 else if(event==PAD0) {
365                         if(G.qual==LR_ALTKEY) {
366                                 if(oldcamera && is_an_active_object(oldcamera)) {
367                                         G.vd->camera= oldcamera;
368                                 }
369                                 
370                                 handle_view3d_lock();
371                         }
372                         else if(BASACT) {
373                                 if(G.qual==LR_CTRLKEY) {
374                                         if(G.vd->camera != OBACT) {
375                                                 if(G.vd->camera && G.vd->camera->type==OB_CAMERA)
376                                                         oldcamera= G.vd->camera;
377                                                 
378                                                 G.vd->camera= OBACT;
379                                                 handle_view3d_lock();
380                                         }
381                                 }
382                                 else if(G.vd->camera==0 && OBACT->type==OB_CAMERA) {
383                                         G.vd->camera= OBACT;
384                                         handle_view3d_lock();
385                                 }
386                         }
387                         if(G.vd->camera==0) {
388                                 G.vd->camera= scene_find_camera(G.scene);
389                                 handle_view3d_lock();
390                         }
391                         
392                         if(G.vd->camera) {
393                                 G.vd->persp= 2;
394                                 G.vd->view= 0;
395                                 if(G.qual & LR_SHIFTKEY) {
396                                         void setcameratoview3d(void);   // view.c
397                                         setcameratoview3d();
398                                 }                               
399                         }
400                 }
401                 else if(event==PAD9) {
402                         countall();
403                         do_all_ipos();
404                         do_all_keys();
405                         do_all_actions();
406                         do_all_ikas();
407
408                         reset_slowparents();    /* editobject.c */
409                 }
410                 else if(G.vd->persp<2) {
411                         if(event==PAD4 || event==PAD6) {
412                                 /* z-axis */
413                                 phi= (float)(M_PI/24.0);
414                                 if(event==PAD6) phi= -phi;
415                                 si= (float)sin(phi);
416                                 q1[0]= (float)cos(phi);
417                                 q1[1]= q1[2]= 0.0;
418                                 q1[3]= si;
419                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
420                                 G.vd->view= 0;
421                         }
422                         if(event==PAD2 || event==PAD8) {
423                                 
424                                 /* horizontal axis */
425                                 VECCOPY(q1+1, G.vd->viewinv[0]);
426                                 
427                                 Normalise(q1+1);
428                                 phi= (float)(M_PI/24.0);
429                                 if(event==PAD2) phi= -phi;
430                                 si= (float)sin(phi);
431                                 q1[0]= (float)cos(phi);
432                                 q1[1]*= si;
433                                 q1[2]*= si;
434                                 q1[3]*= si;
435                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
436                                 G.vd->view= 0;
437                         }
438                 }
439
440                 if(G.vd->persp<2) perspo= G.vd->persp;
441         }
442         scrarea_queue_redraw(curarea);
443 }
444
445 int untitled(char * name)
446 {
447         if (G.save_over == 0 ) {
448                 char * c= BLI_last_slash(name);
449                 
450                 if (c)
451                         strcpy(&c[1], "untitled.blend");
452                 else
453                         strcpy(name, "untitled.blend");
454                         
455                 return(TRUE);
456         }
457         
458         return(FALSE);
459 }
460
461 int save_image_filesel_str(char *str)
462 {
463         switch(G.scene->r.imtype) {
464         case R_PNG:
465                 strcpy(str, "SAVE PNG"); return 1;
466         case R_BMP:
467                 strcpy(str, "SAVE BMP"); return 1;
468         case R_TARGA:
469                 strcpy(str, "SAVE TARGA"); return 1;
470         case R_RAWTGA:
471                 strcpy(str, "SAVE RAW TARGA"); return 1;
472         case R_IRIS:
473                 strcpy(str, "SAVE IRIS"); return 1;
474         case R_IRIZ:
475                 strcpy(str, "SAVE IRIS"); return 1;
476         case R_HAMX:
477                 strcpy(str, "SAVE HAMX"); return 1;
478         case R_FTYPE:
479                 strcpy(str, "SAVE FTYPE"); return 1;
480         case R_JPEG90:
481                 strcpy(str, "SAVE JPEG"); return 1;
482         default:
483                 strcpy(str, "SAVE IMAGE"); return 0;
484         }       
485 }
486
487 void BIF_save_rendered_image(void)
488 {
489         if(!R.rectot) {
490                 error("No image rendered");
491         } else {
492                 char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
493
494                 if(G.ima[0]==0) {
495                         strcpy(dir, G.sce);
496                         BLI_splitdirstring(dir, str);
497                         strcpy(G.ima, dir);
498                 }
499                 
500                 R.r.imtype= G.scene->r.imtype;
501                 R.r.quality= G.scene->r.quality;
502                 R.r.planes= G.scene->r.planes;
503         
504                 if (!save_image_filesel_str(str)) {
505                         error("Select an image type in DisplayButtons(F10)");
506                 } else {
507                         activate_fileselect(FILE_SPECIAL, str, G.ima, write_imag);
508                 }
509         }
510 }
511
512 int blenderqread(unsigned short event, short val)
513 {
514         /* here do the general keys handling (not screen/window/space) */
515         /* return 0: do not pass on to the other queues */
516         extern int textediting;
517         ScrArea *sa;
518         Object *ob;
519         int textspace=0;
520         /* Changed str and dir size to 160, to make sure there is enough
521          * space for filenames. */
522         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
523         
524         if(val==0) return 1;
525         if(event==MOUSEY || event==MOUSEX) return 1;
526         if (G.flags & G_FLAGS_AUTOPLAY) return 1;
527
528         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
529         else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
530
531         switch(event) {
532
533         case F1KEY:
534                 if(G.qual==0) {
535                         /* this exception because of the '?' button */
536                         if(curarea->spacetype==SPACE_INFO) {
537                                 sa= closest_bigger_area();
538                                 areawinset(sa->win);
539                         }
540                         
541                         activate_fileselect(FILE_BLENDER, "LOAD FILE", G.sce, BIF_read_file);
542                         return 0;
543                 }
544                 else if(G.qual==LR_SHIFTKEY) {
545                         activate_fileselect(FILE_LOADLIB, "LOAD LIBRARY", G.lib, 0);
546                         return 0;
547                 }
548                 break;
549         case F2KEY:
550                 if(G.qual==0) {
551                         strcpy(dir, G.sce);
552                         untitled(dir);
553                         activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
554                         return 0;
555                 }
556                 else if(G.qual==LR_CTRLKEY) {
557                         write_vrml_fs();
558                         return 0;
559                 }
560                 else if(G.qual==LR_SHIFTKEY) {
561                         write_dxf_fs();
562                         return 0;
563                 }
564                 break;
565         case F3KEY:
566                 if(G.qual==0) {
567                         BIF_save_rendered_image();
568                         return 0;
569                 }
570                 else if(G.qual & LR_CTRLKEY) {
571                         /* all alt+ctrl+shift combos are needed here... */
572                         BIF_screendump();
573                 }
574                 break;
575         case F4KEY:
576                 if(G.qual==LR_SHIFTKEY) {
577
578                         memset(str, 0, 16);
579                         ob= OBACT;
580                         if(ob) strcpy(str, ob->id.name);
581
582                         activate_fileselect(FILE_MAIN, "DATA SELECT", str, 0);
583                         return 0;
584                 }
585                 else if(G.qual==0) {
586                         extern_set_butspace(event);
587                 }
588                 break;
589         case F5KEY:
590                 if(G.qual==LR_SHIFTKEY) {
591                         newspace(curarea, SPACE_VIEW3D);
592                         return 0;
593                 }
594                 else if(G.qual==0) {
595                         extern_set_butspace(event);
596                 }
597                 break;
598         case F6KEY:
599                 if(G.qual==LR_SHIFTKEY) {
600                         newspace(curarea, SPACE_IPO);
601                         return 0;
602                 }
603                 else if(G.qual==0) {
604                         extern_set_butspace(event);
605                 }
606                 break;
607         case F7KEY:
608                 if(G.qual==LR_SHIFTKEY) {
609                         newspace(curarea, SPACE_BUTS);
610                         return 0;
611                 }
612                 else if(G.qual==0) {
613                         extern_set_butspace(event);
614                 }
615                 break;
616         case F8KEY:
617                 if(G.qual==LR_SHIFTKEY) {
618                         newspace(curarea, SPACE_SEQ);
619                         return 0;
620                 }
621                 else if(G.qual==0) {
622                         extern_set_butspace(event);
623                 }
624                 break;
625         case F9KEY:
626                 if(G.qual==LR_SHIFTKEY) {
627                         newspace(curarea, SPACE_OOPS);
628                         return 0;
629                 }
630                 else if(G.qual==0) {
631                         extern_set_butspace(event);
632                 }
633                 break;
634         case F10KEY:
635                 if(G.qual==LR_SHIFTKEY) {
636                         newspace(curarea, SPACE_IMAGE);
637                         return 0;
638                 }
639                 else if(G.qual==0) {
640                         extern_set_butspace(event);
641                 }
642                 break;
643         case F11KEY:
644                 if(G.qual==LR_SHIFTKEY) {
645                         newspace(curarea, SPACE_TEXT);
646                         return 0;
647                 }
648                 else if(G.qual==0) {
649                         BIF_toggle_render_display();
650                         return 0;
651                 }
652                 break;
653         case F12KEY:
654                 if(G.qual==LR_SHIFTKEY) {
655                         newspace(curarea, SPACE_ACTION);
656                         return 0;
657                 }
658                 else if (G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
659                         newspace(curarea, SPACE_NLA);
660                         return 0;
661                 }
662                 else {
663                         /* ctrl/alt + f12 should render too, for some macs have f12 assigned to cd eject */
664                         BIF_do_render(0);
665                 }
666                 return 0;
667                 break;
668         
669         case LEFTARROWKEY:
670         case DOWNARROWKEY:
671                 if(textediting==0 && textspace==0) {
672
673 #ifdef _WIN32   // FULLSCREEN
674                         if(event==DOWNARROWKEY){
675                                 if (G.qual==LR_ALTKEY)
676                                         mainwindow_toggle_fullscreen(0);
677                                 else if(G.qual==0)
678                                         CFRA-= 10;
679                         }
680 #else
681                         if((event==DOWNARROWKEY)&&(G.qual==0))
682                                 CFRA-= 10;
683 #endif
684                         else if((event==LEFTARROWKEY)&&(G.qual==0))
685                                 CFRA--;
686                         
687                         if(G.qual==LR_SHIFTKEY)
688                                 CFRA= SFRA;
689                         if(CFRA<1) CFRA=1;
690         
691                         update_for_newframe();
692                         return 0;
693                 }
694                 break;
695
696         case RIGHTARROWKEY:
697         case UPARROWKEY:
698                 if(textediting==0 && textspace==0) {
699
700 #ifdef _WIN32   // FULLSCREEN
701                         if(event==UPARROWKEY){ 
702                                 if(G.qual==LR_ALTKEY)
703                                         mainwindow_toggle_fullscreen(1);
704                                 else if(G.qual==0)
705                                         CFRA+= 10;
706                         }
707 #else
708                         if((event==UPARROWKEY)&&(G.qual==0))
709                                 CFRA+= 10;
710 #endif
711                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
712                                 CFRA++;
713
714                         if(G.qual==LR_SHIFTKEY)
715                                 CFRA= EFRA;
716                         
717                         update_for_newframe();
718                 }
719                 break;
720
721         case ESCKEY:
722                 sound_stop_all_sounds();
723                 break;
724         case TABKEY:
725                 if(G.qual==0) {
726                         if(textspace==0) {
727                                 if(curarea->spacetype==SPACE_IPO)
728                                         set_editflag_editipo();
729                                 else if(curarea->spacetype==SPACE_SEQ)
730                                         enter_meta();
731                                 else if(G.vd) {
732                                         /* also when Alt-E */
733                                         if(G.obedit==0)
734                                                 enter_editmode();
735                                         else
736                                                 exit_editmode(1);
737                                 }
738                                 return 0;
739                         }
740                 }
741                 else if(G.qual==LR_CTRLKEY){
742                         if(G.obpose)
743                                 exit_posemode(1);
744                         else
745                                 enter_posemode();
746                         allqueue(REDRAWHEADERS, 0);     
747                         allqueue(REDRAWBUTSALL, 0);     
748                 }
749                 else if(G.qual==LR_SHIFTKEY) {
750                         if(G.obedit)
751                                 exit_editmode(1);
752                         if(G.f & G_FACESELECT)
753                                 set_faceselect();
754                         if(G.f & G_VERTEXPAINT)
755                                 set_vpaint();
756                         if(G.f & G_WEIGHTPAINT)
757                                 set_wpaint();
758                         if(G.obpose)
759                                 exit_posemode(1);
760                 }
761                 break;
762
763         case BACKSPACEKEY:
764                 break;
765
766         case AKEY:
767                 if(textediting==0 && textspace==0) {
768                         if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)){
769                                 play_anim(1);
770                                 return 0;
771                         }
772                         else if(G.qual==LR_ALTKEY) {
773                                 play_anim(0);
774                                 return 0;
775                         }
776                 }
777                 break;
778         case EKEY:
779                 if(G.qual==LR_ALTKEY) {
780                         if(G.vd && textspace==0) {
781                                 if(G.obedit==0)
782                                         enter_editmode();
783                                 else
784                                         exit_editmode(1);
785                                 return 0;
786                         }                       
787                 }
788                 break;
789         case IKEY:
790                 if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
791                         if(G.qual==0) {
792                                 common_insertkey();
793                                 return 0;
794                         }
795                 }
796                 break;
797         case JKEY:
798                 if(textediting==0 && textspace==0) {
799                         if(R.rectot && G.qual==0) {
800                                 BIF_swap_render_rects();
801                                 return 0;
802                         }
803                 }
804                 break;
805
806         case NKEY:
807                 if(textediting==0 && textspace==0) {
808                         if(G.qual & LR_CTRLKEY);
809                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
810                                 if(curarea->spacetype==SPACE_VIEW3D);           // is new panel, in view3d queue
811                                 else if(curarea->spacetype==SPACE_IPO);                 // is new panel, in ipo queue
812                                 else {
813                                         clever_numbuts();
814                                         return 0;
815                                 }
816                         }
817                 }
818                 break;
819                 
820         case OKEY:
821                 if(textediting==0) {
822                         if(G.qual==LR_CTRLKEY) {
823                                 /* There seem to be crashes here sometimes.... String
824                                  * bound overwrites? I changed dir and str sizes,
825                                  * let's see if this reoccurs. */
826                                 sprintf(str, "Open file: %s", G.sce);
827                         
828                                 if(okee(str)) {
829                                         strcpy(dir, G.sce);
830                                         BIF_read_file(dir);
831                                 }
832                                 return 0;
833                         }
834                 }
835                 break;
836                 
837         case SKEY:
838                 if(G.obpose==0 && G.obedit==0) {
839                         if(G.qual==LR_CTRLKEY) {
840                                 strcpy(dir, G.sce);
841                                 if (untitled(dir)) {
842                                         activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
843                                 } else {
844                                         BIF_write_file(dir);
845                                         free_filesel_spec(dir);
846                                 }
847                                 return 0;
848                         }
849                 }
850                 break;
851         
852         case TKEY:
853                 if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
854                         int a;
855                         double delta, stime;
856
857                         waitcursor(1);
858                         
859                         stime= PIL_check_seconds_timer();
860                         for(a=0; a<100000; a++) {
861                                 scrarea_do_windraw(curarea);
862
863                                 delta= PIL_check_seconds_timer()-stime;
864                                 if (delta>5.0) break;
865                         }
866                         
867                         waitcursor(0);
868                         notice("FPS: %f (%d iterations)", a/delta, a);
869                         return 0;
870                 }
871                 else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
872                         int a;
873                         int event= pupmenu("10 Timer%t|draw|draw+swap|displist");
874                         if(event>0) {
875                                 double stime= PIL_check_seconds_timer();
876                                 char tmpstr[128];
877                                 int time;
878
879                                 waitcursor(1);
880                                 
881                                 for(a=0; a<10; a++) {
882                                         if (event==1) {
883                                                 scrarea_do_windraw(curarea);
884                                         } else if (event==2) {
885                                                 scrarea_do_windraw(curarea);
886                                                 screen_swapbuffers();
887                                         } else if (event==3) {
888                                                 if (OBACT) {
889                                                         makeDispList(OBACT);
890                                                 }
891                                         }
892                                 }
893                         
894                                 time= (PIL_check_seconds_timer()-stime)*1000;
895                                 
896                                 if(event==1) sprintf(tmpstr, "draw %%t|%d ms", time);
897                                 if(event==2) sprintf(tmpstr, "d+sw %%t|%d ms", time);
898                                 if(event==3) sprintf(tmpstr, "displist %%t|%d ms", time);
899                         
900                                 waitcursor(0);
901                                 pupmenu(tmpstr);
902
903                         }
904                         return 0;
905                 }
906                 break;
907                                 
908         case UKEY:
909                 if(textediting==0) {
910                         if(G.qual==LR_CTRLKEY) {
911                                 if(okee("SAVE USER DEFAULTS")) {
912                                         BIF_write_homefile();
913                                 }
914                                 return 0;
915                         }
916                 }
917                 break;
918                 
919         case WKEY:
920                 if(textediting==0) {
921                         if(G.qual==LR_CTRLKEY) {
922                                 strcpy(dir, G.sce);
923                                 if (untitled(dir)) {
924                                         activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
925                                 } else {
926                                         BIF_write_file(dir);
927                                         free_filesel_spec(dir);
928                                 }
929                                 return 0;
930                         }
931                         else if(G.qual==LR_ALTKEY) {
932                                 write_videoscape_fs();
933                         }
934                 }
935                 break;
936                 
937         case XKEY:
938                 if(textspace==0) {
939                         if(G.qual==LR_CTRLKEY) {
940                                 if(okee("ERASE ALL")) {
941                                         if( BIF_read_homefile()==0) error("No file ~/.B.blend");
942                                 }
943                                 return 0;
944                         }
945                 }
946                 break;
947         }
948         
949         return 1;
950 }
951
952 /* eof */