As nobody else ever felt like doing it, and I work too much with official
[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 WIN32
42 #include "BLI_winstuff.h"
43 #endif
44
45 #include "MEM_guardedalloc.h"
46
47 #include "PIL_time.h"
48
49 #include "nla.h"        /* Only for the #ifdef flag - To be removed later */
50
51 #include "BLI_blenlib.h"
52 #include "BLI_arithb.h"
53
54 #include "DNA_object_types.h"
55 #include "DNA_screen_types.h"
56 #include "DNA_scene_types.h"
57 #include "DNA_space_types.h"
58 #include "DNA_view3d_types.h"
59 #include "DNA_userdef_types.h"
60
61 #include "BKE_action.h"
62 #include "BKE_anim.h"
63 #include "BKE_blender.h"
64 #include "BKE_depsgraph.h"
65 #include "BKE_displist.h"
66 #include "BKE_global.h"
67 #include "BKE_image.h"
68 #include "BKE_ipo.h"
69 #include "BKE_key.h"
70 #include "BKE_scene.h"
71 #include "BKE_utildefines.h"
72
73 #include "BIF_butspace.h"
74 #include "BIF_editseq.h"
75 #include "BIF_editsound.h"
76 #include "BIF_editmesh.h"
77 #include "BIF_interface.h"
78 #include "BKE_object.h"
79 #include "BIF_poseobject.h"
80 #include "BIF_previewrender.h"
81 #include "BIF_renderwin.h"
82 #include "BIF_screen.h"
83 #include "BIF_space.h"
84 #include "BIF_toets.h"
85 #include "BIF_toolbox.h"
86 #include "BIF_usiblender.h"
87 #include "BIF_writeimage.h"
88
89 #include "BDR_vpaint.h"
90 #include "BDR_editobject.h"
91 #include "BDR_editface.h"
92
93 #include "BSE_filesel.h"        /* For activate_fileselect */
94 #include "BSE_drawview.h"       /* For play_anim */
95 #include "BSE_view.h"
96 #include "BSE_edit.h"
97 #include "BSE_editipo.h"
98 #include "BSE_headerbuttons.h"
99 #include "BSE_seqaudio.h"
100
101 #include "blendef.h"
102
103 #include "IMB_imbuf.h"
104 #include "IMB_imbuf_types.h"
105
106 #include "mydevice.h"
107
108 #include "BIF_poseobject.h"
109
110 /* ------------------------------------------------------------------------- */
111
112 static int is_an_active_object(void *ob) {
113         Base *base;
114         
115         for (base= FIRSTBASE; base; base= base->next)
116                 if (base->object == ob)
117                         return 1;
118         
119         return 0;
120 }
121
122 void persptoetsen(unsigned short event)
123 {
124         static Object *oldcamera=0;
125         float phi, si, q1[4], vec[3];
126         static int perspo=1;
127         int preview3d_event= 1;
128         
129         if(event==PADENTER) {
130                 if (G.qual == LR_SHIFTKEY) {
131                         view3d_set_1_to_1_viewborder(G.vd);
132                 } else {
133                         if (G.vd->persp==2) {
134                                 G.vd->camzoom= 0;
135                         } else {
136                                 G.vd->dist= 10.0;
137                         }
138                 }
139         }
140         else if((G.qual & (LR_SHIFTKEY | LR_CTRLKEY)) && (event != PAD0)) {
141                 
142                 /* indicate that this view is inverted */
143                 G.vd->flag2 |= V3D_OPP_DIRECTION_NAME;
144                 
145                 if(event==PAD0) {
146                         /* G.vd->persp= 3; */
147                 }
148                 else if(event==PAD7) {
149                         G.vd->viewquat[0]= 0.0;
150                         G.vd->viewquat[1]= -1.0;
151                         G.vd->viewquat[2]= 0.0;
152                         G.vd->viewquat[3]= 0.0;
153                         G.vd->view= 7;
154                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; 
155                         else if(G.vd->persp>=2) G.vd->persp= perspo;
156                 }
157                 else if(event==PAD1) {
158                         G.vd->viewquat[0]= 0.0;
159                         G.vd->viewquat[1]= 0.0;
160                         G.vd->viewquat[2]= (float)-cos(M_PI/4.0);
161                         G.vd->viewquat[3]= (float)-cos(M_PI/4.0);
162                         G.vd->view=1;
163                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
164                         else if(G.vd->persp>=2) G.vd->persp= perspo;
165                 }
166                 else if(event==PAD3) {
167                         G.vd->viewquat[0]= 0.5;
168                         G.vd->viewquat[1]= -0.5;
169                         G.vd->viewquat[2]= 0.5;
170                         G.vd->viewquat[3]= 0.5;
171                         G.vd->view=3;
172                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
173                         else if(G.vd->persp>=2) G.vd->persp= perspo;
174                 }
175                 else if(event==PADMINUS) {
176                         /* this min and max is also in viewmove() */
177                         if(G.vd->persp==2) {
178                                 G.vd->camzoom-= 10;
179                                 if(G.vd->camzoom<-30) G.vd->camzoom= -30;
180                         }
181                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
182                 }
183                 else if(event==PADPLUSKEY) {
184                         if(G.vd->persp==2) {
185                                 G.vd->camzoom+= 10;
186                                 if(G.vd->camzoom>300) G.vd->camzoom= 300;
187                         }
188                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
189                 }
190                 else {
191
192                         initgrabz(0.0, 0.0, 0.0);
193                         
194                         if(event==PAD6) window_to_3d(vec, -32, 0);
195                         else if(event==PAD4) window_to_3d(vec, 32, 0);
196                         else if(event==PAD8) window_to_3d(vec, 0, -25);
197                         else if(event==PAD2) window_to_3d(vec, 0, 25);
198                         G.vd->ofs[0]+= vec[0];
199                         G.vd->ofs[1]+= vec[1];
200                         G.vd->ofs[2]+= vec[2];
201                 }
202         }
203         else {
204                 /* indicate that this view is not inverted */
205                 G.vd->flag2 &= ~V3D_OPP_DIRECTION_NAME;
206
207                 if(event==PAD7) {
208                         G.vd->viewquat[0]= 1.0;
209                         G.vd->viewquat[1]= 0.0;
210                         G.vd->viewquat[2]= 0.0;
211                         G.vd->viewquat[3]= 0.0;
212                         G.vd->view=7;
213                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
214                         else if(G.vd->persp>=2) G.vd->persp= perspo;
215                 }
216                 else if(event==PAD1) {
217                         G.vd->viewquat[0]= (float)cos(M_PI/4.0);
218                         G.vd->viewquat[1]= (float)-sin(M_PI/4.0);
219                         G.vd->viewquat[2]= 0.0;
220                         G.vd->viewquat[3]= 0.0;
221                         G.vd->view=1;
222                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
223                         else if(G.vd->persp>=2) G.vd->persp= perspo;
224                 }
225                 else if(event==PAD3) {
226                         G.vd->viewquat[0]= 0.5;
227                         G.vd->viewquat[1]= -0.5;
228                         G.vd->viewquat[2]= -0.5;
229                         G.vd->viewquat[3]= -0.5;
230                         G.vd->view=3;
231                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
232                         else if(G.vd->persp>=2) G.vd->persp= perspo;
233                 }
234                 else if(event==PADMINUS) {
235                         /* this min and max is also in viewmove() */
236                         if(G.vd->persp==2) {
237                                 G.vd->camzoom= MAX2(-30, G.vd->camzoom-5);
238                         }
239                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
240                         if(G.vd->persp!=1) preview3d_event= 0;
241                 }
242                 else if(event==PADPLUSKEY) {
243                         if(G.vd->persp==2) {
244                                 G.vd->camzoom= MIN2(300, G.vd->camzoom+5);
245                         }
246                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
247                         if(G.vd->persp!=1) preview3d_event= 0;
248                 }
249                 else if(event==PAD5) {
250                         if(G.vd->persp==1) G.vd->persp=0;
251                         else G.vd->persp=1;
252                 }
253                 else if(event==PAD0) {
254                         if(G.qual==LR_ALTKEY) {
255                                 if(oldcamera && is_an_active_object(oldcamera)) {
256                                         G.vd->camera= oldcamera;
257                                 }
258                                 
259                                 handle_view3d_lock();
260                         }
261                         else if(BASACT) {
262                                 if(G.qual==LR_CTRLKEY) {
263                                         if(G.vd->camera != OBACT) {
264                                                 if(G.vd->camera && G.vd->camera->type==OB_CAMERA)
265                                                         oldcamera= G.vd->camera;
266                                                 
267                                                 G.vd->camera= OBACT;
268                                                 handle_view3d_lock();
269                                         }
270                                 }
271                                 else if(G.vd->camera==0 && OBACT->type==OB_CAMERA) {
272                                         G.vd->camera= OBACT;
273                                         handle_view3d_lock();
274                                 }
275                         }
276                         if(G.vd->camera==0) {
277                                 G.vd->camera= scene_find_camera(G.scene);
278                                 handle_view3d_lock();
279                         }
280                         
281                         if(G.vd->camera) {
282                                 G.vd->persp= 2;
283                                 G.vd->view= 0;
284                                 if(((G.qual & LR_CTRLKEY) && (G.qual & LR_ALTKEY)) || (G.qual & LR_SHIFTKEY)) {
285                                         void setcameratoview3d(void);   // view.c
286                                         setcameratoview3d();
287                                         DAG_object_flush_update(G.scene, G.scene->camera, OB_RECALC_OB);
288                                         allqueue(REDRAWVIEW3D, 0);
289                                 }                               
290                         }
291                 }
292                 else if(event==PAD9) {
293                         countall();
294                         update_for_newframe();
295                         
296                         reset_slowparents();    /* editobject.c */
297                 }
298                 else if(G.vd->persp<2) {
299                         if(event==PAD4 || event==PAD6) {
300                                 /* z-axis */
301                                 phi= (float)(M_PI/24.0);
302                                 if(event==PAD6) phi= -phi;
303                                 si= (float)sin(phi);
304                                 q1[0]= (float)cos(phi);
305                                 q1[1]= q1[2]= 0.0;
306                                 q1[3]= si;
307                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
308                                 G.vd->view= 0;
309                         }
310                         if(event==PAD2 || event==PAD8) {
311                                 
312                                 /* horizontal axis */
313                                 VECCOPY(q1+1, G.vd->viewinv[0]);
314                                 
315                                 Normalise(q1+1);
316                                 phi= (float)(M_PI/24.0);
317                                 if(event==PAD2) phi= -phi;
318                                 si= (float)sin(phi);
319                                 q1[0]= (float)cos(phi);
320                                 q1[1]*= si;
321                                 q1[2]*= si;
322                                 q1[3]*= si;
323                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
324                                 G.vd->view= 0;
325                         }
326                 }
327
328                 if(G.vd->persp<2) perspo= G.vd->persp;
329         }
330         
331         if(preview3d_event) 
332                 BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
333         else
334                 BIF_view3d_previewrender_signal(curarea, PR_PROJECTED);
335
336         scrarea_queue_redraw(curarea);
337 }
338
339 int untitled(char * name)
340 {
341         if (G.save_over == 0 ) {
342                 char * c= BLI_last_slash(name);
343                 
344                 if (c)
345                         strcpy(&c[1], "untitled.blend");
346                 else
347                         strcpy(name, "untitled.blend");
348                         
349                 return(TRUE);
350         }
351         
352         return(FALSE);
353 }
354
355 char *recent_filelist(void)
356 {
357         int event, i, ofs;
358         char pup[2048], *p;
359
360         p= pup + sprintf(pup, "Open recent%%t");
361         
362         if (G.sce[0]) {
363                 p+= sprintf(p, "|%s %%x%d", G.sce, 1);
364                 ofs = 1;
365         } else ofs = 0;
366         for (i=0; i<10 && (G.recent[i][0]); i++) {
367                 if (strcmp(G.recent[i], G.sce)) {
368                         p+= sprintf(p, "|%s %%x%d", G.recent[i], i+ofs+1);
369                 }
370         }
371         event= pupmenu(pup);
372         if(event>0) {
373                 if (ofs && (event==1))
374                         return(G.sce);
375                 else 
376                         return(G.recent[event-1-ofs]);
377         }
378         else
379                 return(NULL);
380 }
381
382 int blenderqread(unsigned short event, short val)
383 {
384         /* here do the general keys handling (not screen/window/space) */
385         /* return 0: do not pass on to the other queues */
386         extern int textediting;
387         extern void playback_anim();
388         ScrArea *sa;
389         Object *ob;
390         int textspace=0;
391         /* Changed str and dir size to 160, to make sure there is enough
392          * space for filenames. */
393         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
394         char *recentfile;
395         
396         if(val==0) return 1;
397         if(event==MOUSEY || event==MOUSEX) return 1;
398         if (G.flags & G_FILE_AUTOPLAY) return 1;
399
400         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
401         else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
402
403         switch(event) {
404
405         case F1KEY:
406                 if(G.qual==0) {
407                         /* this exception because of the '?' button */
408                         if(curarea->spacetype==SPACE_INFO) {
409                                 sa= closest_bigger_area();
410                                 areawinset(sa->win);
411                         }
412                         
413                         activate_fileselect(FILE_BLENDER, "Open File", G.sce, BIF_read_file);
414                         return 0;
415                 }
416                 else if(G.qual==LR_SHIFTKEY) {
417                         activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
418                         return 0;
419                 }
420                 break;
421         case F2KEY:
422                 if(G.qual==0) {
423                         strcpy(dir, G.sce);
424                         untitled(dir);
425                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
426                         return 0;
427                 }
428                 else if(G.qual==LR_CTRLKEY) {
429                         write_vrml_fs();
430                         return 0;
431                 }
432                 else if(G.qual==LR_SHIFTKEY) {
433                         write_dxf_fs();
434                         return 0;
435                 }
436                 break;
437         case F3KEY:
438                 if(G.qual==0) {
439                         BIF_save_rendered_image_fs(0);
440                         return 0;
441                 }
442                 else if(G.qual & LR_CTRLKEY) {
443                         BIF_screendump(0);
444                 }
445                 else if(G.qual & LR_SHIFTKEY) {
446                         BIF_save_rendered_image_fs(1);
447                 }
448                 break;
449         case F4KEY:
450                 if(G.qual==LR_SHIFTKEY) {
451
452                         memset(str, 0, 16);
453                         ob= OBACT;
454                         if(ob) strcpy(str, ob->id.name);
455
456                         activate_fileselect(FILE_MAIN, "Data Select", str, 0);
457                         return 0;
458                 }
459                 else if(G.qual==0) {
460                         extern_set_butspace(event);
461                 }
462                 break;
463         case F5KEY:
464                 if(G.qual==LR_SHIFTKEY) {
465                         newspace(curarea, SPACE_VIEW3D);
466                         return 0;
467                 }
468                 else if(G.qual==0) {
469                         extern_set_butspace(event);
470                 }
471                 break;
472         case F6KEY:
473                 if(G.qual==LR_SHIFTKEY) {
474                         newspace(curarea, SPACE_IPO);
475                         return 0;
476                 }
477                 else if(G.qual==0) {
478                         extern_set_butspace(event);
479                 }
480                 break;
481         case F7KEY:
482                 if(G.qual==LR_SHIFTKEY) {
483                         newspace(curarea, SPACE_BUTS);
484                         return 0;
485                 }
486                 else if(G.qual==0) {
487                         extern_set_butspace(event);
488                 }
489                 break;
490         case F8KEY:
491                 if(G.qual==LR_SHIFTKEY) {
492                         newspace(curarea, SPACE_SEQ);
493                         return 0;
494                 }
495                 else if(G.qual==0) {
496                         extern_set_butspace(event);
497                 }
498                 break;
499         case F9KEY:
500                 if(G.qual==LR_SHIFTKEY) {
501                         newspace(curarea, SPACE_OOPS);
502                         return 0;
503                 }
504                 else if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)) {
505                         newspace(curarea, SPACE_OOPS+256);
506                         return 0;
507                 }
508                 else if(G.qual==0) {
509                         extern_set_butspace(event);
510                 }
511                 break;
512         case F10KEY:
513                 if(G.qual==LR_SHIFTKEY) {
514                         newspace(curarea, SPACE_IMAGE);
515                         return 0;
516                 }
517                 else if(G.qual==0) {
518                         extern_set_butspace(event);
519                 }
520                 break;
521         case F11KEY:
522                 if(G.qual==LR_SHIFTKEY) {
523                         newspace(curarea, SPACE_TEXT);
524                         return 0;
525                 }
526                 else if (G.qual==LR_CTRLKEY) {
527                         playback_anim();
528                 }
529                 else if(G.qual==0) {
530                         BIF_toggle_render_display();
531                         return 0;
532                 }
533                 break;
534         case F12KEY:
535                 if(G.qual==LR_SHIFTKEY) {
536                         newspace(curarea, SPACE_ACTION);
537                         return 0;
538                 }
539                 else if (G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
540                         newspace(curarea, SPACE_NLA);
541                         return 0;
542                 }
543                 else if (G.qual==LR_CTRLKEY) {
544                         BIF_do_render(1);
545                 }
546                 else {
547                         /* ctrl/alt + f12 should render too, for some macs have f12 assigned to cd eject */
548                         BIF_do_render(0);
549                 }
550                 return 0;
551                 break;
552         
553         case WHEELUPMOUSE:
554                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
555                         if(CFRA>1) {
556                                 CFRA--;
557                                 update_for_newframe();
558                         }
559                         return 0;
560                 }
561                 break;
562         case WHEELDOWNMOUSE:
563                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
564                         CFRA++;
565                         update_for_newframe();
566                         return 0;
567                 }
568                 break;
569                 
570         case LEFTARROWKEY:
571         case DOWNARROWKEY:
572                 if(textediting==0 && textspace==0) {
573
574 #if 0
575 //#ifdef _WIN32 // FULLSCREEN
576                         if(event==DOWNARROWKEY){
577                                 if (G.qual==LR_ALTKEY)
578                                         mainwindow_toggle_fullscreen(0);
579                                 else if(G.qual==0)
580                                         CFRA-= G.scene->jumpframe;
581                         }
582 #else
583                         if((event==DOWNARROWKEY)&&(G.qual==0))
584                                 CFRA-= G.scene->jumpframe;
585 #endif
586                         else if((event==LEFTARROWKEY)&&(G.qual==0))
587                                 CFRA--;
588                         
589                         if(G.qual==LR_SHIFTKEY)
590                                 CFRA= SFRA;
591                         if(CFRA<1) CFRA=1;
592         
593                         update_for_newframe();
594                         return 0;
595                 }
596                 break;
597
598         case RIGHTARROWKEY:
599         case UPARROWKEY:
600                 if(textediting==0 && textspace==0) {
601
602 #if 0
603 //#ifdef _WIN32 // FULLSCREEN
604                         if(event==UPARROWKEY){ 
605                                 if(G.qual==LR_ALTKEY)
606                                         mainwindow_toggle_fullscreen(1);
607                                 else if(G.qual==0)
608                                         CFRA+= G.scene->jumpframe;
609                         }
610 #else
611                         if((event==UPARROWKEY)&&(G.qual==0))
612                                 CFRA+= G.scene->jumpframe;
613 #endif
614                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
615                                 CFRA++;
616
617                         if(G.qual==LR_SHIFTKEY)
618                                 CFRA= EFRA;
619                         
620                         update_for_newframe();
621                 }
622                 break;
623
624         case ESCKEY:
625                 sound_stop_all_sounds();        // whats this?
626                 
627                 /* stop playback on ESC always */
628                 rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
629                 audiostream_stop();
630                 allqueue(REDRAWALL, 0);
631                 
632                 break;
633         case TABKEY:
634                 if(G.qual==0) {
635                         if(textspace==0) {
636                                 if(curarea->spacetype==SPACE_IPO)
637                                         set_editflag_editipo();
638                                 else if(curarea->spacetype==SPACE_SEQ)
639                                         enter_meta();
640                                 else if(curarea->spacetype==SPACE_NODE)
641                                         return 1;
642                                 else if(G.vd) {
643                                         /* also when Alt-E */
644                                         if(G.obedit==NULL) {
645                                                 enter_editmode();
646                                                 if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
647                                         }
648                                         else
649                                                 exit_editmode(2); // freedata, and undo
650                                 }
651                                 return 0;
652                         }
653                 }
654                 else if(G.qual==LR_CTRLKEY){
655                         Object *ob= OBACT;
656                         if(ob) {
657                                 if(ob->type==OB_ARMATURE) {
658                                         if(ob->flag & OB_POSEMODE) exit_posemode();
659                                         else enter_posemode();
660                                 }
661                                 else if(ob->type==OB_MESH) {
662                                         if(ob==G.obedit) EM_selectmode_menu();
663                                         else set_wpaint();
664                                 }
665                         }
666                 }
667                 else if(G.qual==LR_SHIFTKEY) {  // ??
668                         if(G.obedit)
669                                 exit_editmode(2); // freedata, and undo
670                         if(G.f & G_FACESELECT)
671                                 set_faceselect();
672                         if(G.f & G_VERTEXPAINT)
673                                 set_vpaint();
674                         if(G.f & G_TEXTUREPAINT) {
675                                 G.f &= ~G_TEXTUREPAINT;
676                                 allqueue(REDRAWVIEW3D, 0);
677                                 allqueue(REDRAWBUTSEDIT, 0);
678                         }
679                         if(G.f & G_WEIGHTPAINT)
680                                 set_wpaint();
681                 }
682                 break;
683
684         case BACKSPACEKEY:
685                 break;
686
687         case AKEY:
688                 if(textediting==0 && textspace==0) {
689                         if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)){
690                                 play_anim(1);
691                                 return 0;
692                         }
693                         else if(G.qual==LR_ALTKEY) {
694                                 play_anim(0);
695                                 return 0;
696                         }
697                 }
698                 break;
699         case EKEY:
700                 if(G.qual==LR_ALTKEY) {
701                         if(G.vd && textspace==0) {
702                                 if(G.obedit==0) {
703                                         enter_editmode();
704                                         BIF_undo_push("Original");
705                                 }
706                                 else
707                                         exit_editmode(2); // freedata, and undo
708                                 return 0;
709                         }                       
710                 }
711                 break;
712         case IKEY:
713                 if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
714                         if(G.qual==0) {
715                                 common_insertkey();
716                                 return 0;
717                         }
718                 }
719                 break;
720         case JKEY:
721                 if(textediting==0 && textspace==0) {
722                         if (G.qual==0) {
723                                 BIF_swap_render_rects();
724                                 return 0;
725                         }
726                 }
727                 break;
728
729         case NKEY:
730                 if(textediting==0 && textspace==0) {
731                         if(G.qual & LR_CTRLKEY);
732                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
733                                 if(curarea->spacetype==SPACE_VIEW3D);           // is new panel, in view3d queue
734                                 else if(curarea->spacetype==SPACE_IPO);                 // is new panel, in ipo queue
735                                 else if(curarea->spacetype==SPACE_IMAGE);                       // is new panel, in ipo queue
736                                 else if(curarea->spacetype==SPACE_ACTION);                      // is own queue
737                                 else if(curarea->spacetype==SPACE_NLA);                 // is new panel
738                                 else if(curarea->spacetype==SPACE_SEQ);                 // is new panel
739                                 else {
740                                         clever_numbuts();
741                                         return 0;
742                                 }
743                         }
744                 }
745                 break;
746                 
747         case OKEY:
748                 if(textediting==0) {
749                         if(G.qual==LR_CTRLKEY) {
750                                 recentfile = recent_filelist();
751                                 if(recentfile) {
752                                         BIF_read_file(recentfile);
753                                 }
754                                 return 0;
755                         }
756                 }
757                 break;
758                 
759         case SKEY:
760                 if(G.obedit==NULL) {
761                         if(G.qual==LR_CTRLKEY) {
762                                 strcpy(dir, G.sce);
763                                 if (untitled(dir)) {
764                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
765                                 } else {
766                                         BIF_write_file(dir);
767                                         free_filesel_spec(dir);
768                                 }
769                                 return 0;
770                         }
771                 }
772                 break;
773         
774         case TKEY:
775                 if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
776                         Object *ob = OBACT;
777                         int event = pupmenu(ob?"Time%t|draw|recalc ob|recalc data":"Time%t|draw");
778                         int a;
779                         double delta, stime;
780
781                         waitcursor(1);
782                         
783                         stime= PIL_check_seconds_timer();
784                         for(a=0; a<100000; a++) {
785                                 if (event==1) {
786                                         scrarea_do_windraw(curarea);
787                                 } else if (event==2) {
788                                         ob->recalc |= OB_RECALC_OB;
789                                         object_handle_update(ob);
790                                 } else if (event==3) {
791                                         ob->recalc |= OB_RECALC_DATA;
792                                         object_handle_update(ob);
793                                 }
794
795                                 delta= PIL_check_seconds_timer()-stime;
796                                 if (delta>5.0) break;
797                         }
798                         
799                         waitcursor(0);
800                         notice("%8.6f s/op - %6.2f ops/s - %d iterations", delta/a, a/delta, a);
801                         return 0;
802                 }
803                 else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
804                         int a;
805                         int event= pupmenu("10 Timer%t|draw|draw+swap|undo");
806                         if(event>0) {
807                                 double stime= PIL_check_seconds_timer();
808                                 char tmpstr[128];
809                                 int time;
810
811                                 waitcursor(1);
812                                 
813                                 for(a=0; a<10; a++) {
814                                         if (event==1) {
815                                                 scrarea_do_windraw(curarea);
816                                         } else if (event==2) {
817                                                 scrarea_do_windraw(curarea);
818                                                 screen_swapbuffers();
819                                         }
820                                         else if(event==3) {
821                                                 BIF_undo();
822                                                 BIF_redo();
823                                         }
824                                 }
825                         
826                                 time= (int) ((PIL_check_seconds_timer()-stime)*1000);
827                                 
828                                 if(event==1) sprintf(tmpstr, "draw %%t|%d ms", time);
829                                 if(event==2) sprintf(tmpstr, "d+sw %%t|%d ms", time);
830                                 if(event==3) sprintf(tmpstr, "undo %%t|%d ms", time);
831                         
832                                 waitcursor(0);
833                                 pupmenu(tmpstr);
834
835                         }
836                         return 0;
837                 }
838                 break;
839                                 
840         case UKEY:
841                 if(textediting==0) {
842                         if(G.qual==LR_CTRLKEY) {
843                                 if(okee("Save user defaults")) {
844                                         BIF_write_homefile();
845                                 }
846                                 return 0;
847                         }
848                         else if(G.qual==LR_ALTKEY) {
849                                 if(curarea->spacetype!=SPACE_TEXT) {
850                                         BIF_undo_menu();
851                                         return 0;
852                                 }
853                         }
854                 }
855                 break;
856                 
857         case WKEY:
858                 if(textediting==0) {
859                         if(G.qual==LR_CTRLKEY) {
860                                 strcpy(dir, G.sce);
861                                 if (untitled(dir)) {
862                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
863                                 } else {
864                                         BIF_write_file(dir);
865                                         free_filesel_spec(dir);
866                                 }
867                                 return 0;
868                         }
869                         else if(G.qual==LR_ALTKEY) {
870                                 write_videoscape_fs();
871                         }
872                 }
873                 break;
874                 
875         case XKEY:
876                 if(textspace==0 && textediting==0) {
877                         if(G.qual==LR_CTRLKEY) {
878                                 if(okee("Erase all")) {
879                                         if( BIF_read_homefile()==0) error("No file ~/.B.blend");
880                                 }
881                                 return 0;
882                         }
883                 }
884                 break;
885         case YKEY:      // redo alternative
886                 if(textspace==0) {
887                         if(G.qual==LR_CTRLKEY) {
888                                 BIF_redo(); 
889                                 return 0;
890                         }
891                 }
892                 break;
893         case ZKEY:      // undo
894                 if(textspace==0) {
895                         if(G.qual & (LR_CTRLKEY|LR_COMMANDKEY)) { // all combos with ctrl/commandkey are accepted
896                                 if ELEM(G.qual, LR_CTRLKEY, LR_COMMANDKEY) BIF_undo();
897                                 else BIF_redo(); // all combos with ctrl is redo
898                                 return 0;
899                         }
900                 }
901                 break; 
902         }
903         
904         return 1;
905 }
906
907 /* eof */