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