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