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