Bugfix:
[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         struct RecentFile *recent;
358         int event, i, ofs;
359         char pup[2048], *p;
360
361         p= pup + sprintf(pup, "Open recent%%t");
362         
363         if (G.sce[0]) {
364                 p+= sprintf(p, "|%s %%x%d", G.sce, 1);
365                 ofs = 1;
366         } else ofs = 0;
367
368         for (recent = G.recent_files.first, i=0; (i<10) && (recent); recent = recent->next, i++) {
369                 if (strcmp(recent->filename, G.sce)) {
370                         p+= sprintf(p, "|%s %%x%d", recent->filename, i+ofs+1);
371                 }
372         }
373         event= pupmenu(pup);
374         if(event>0) {
375                 if (ofs && (event==1))
376                         return(G.sce);
377                 else
378                         recent = BLI_findlink(&(G.recent_files), event-1-ofs);
379                         if(recent) return(recent->filename);
380         }
381         else
382                 return(NULL);
383 }
384
385 int blenderqread(unsigned short event, short val)
386 {
387         /* here do the general keys handling (not screen/window/space) */
388         /* return 0: do not pass on to the other queues */
389         extern int textediting;
390         extern void playback_anim();
391         ScrArea *sa;
392         Object *ob;
393         int textspace=0;
394         /* Changed str and dir size to 160, to make sure there is enough
395          * space for filenames. */
396         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
397         char *recentfile;
398         
399         if(val==0) return 1;
400         if(event==MOUSEY || event==MOUSEX) return 1;
401         if (G.flags & G_FILE_AUTOPLAY) return 1;
402
403         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
404         else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
405
406         switch(event) {
407
408         case F1KEY:
409                 if(G.qual==0) {
410                         /* this exception because of the '?' button */
411                         if(curarea->spacetype==SPACE_INFO) {
412                                 sa= closest_bigger_area();
413                                 areawinset(sa->win);
414                         }
415                         
416                         activate_fileselect(FILE_BLENDER, "Open File", G.sce, BIF_read_file);
417                         return 0;
418                 }
419                 else if(G.qual==LR_SHIFTKEY) {
420                         activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
421                         return 0;
422                 }
423                 break;
424         case F2KEY:
425                 if(G.qual==0) {
426                         strcpy(dir, G.sce);
427                         untitled(dir);
428                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
429                         return 0;
430                 }
431                 else if(G.qual==LR_CTRLKEY) {
432                         write_vrml_fs();
433                         return 0;
434                 }
435                 else if(G.qual==LR_SHIFTKEY) {
436                         write_dxf_fs();
437                         return 0;
438                 }
439                 break;
440         case F3KEY:
441                 if(G.qual==0) {
442                         BIF_save_rendered_image_fs(0);
443                         return 0;
444                 }
445                 else if(G.qual & LR_CTRLKEY) {
446                         BIF_screendump(0);
447                 }
448                 else if(G.qual & LR_SHIFTKEY) {
449                         BIF_save_rendered_image_fs(1);
450                 }
451                 break;
452         case F4KEY:
453                 if(G.qual==LR_SHIFTKEY) {
454
455                         memset(str, 0, 16);
456                         ob= OBACT;
457                         if(ob) strcpy(str, ob->id.name);
458
459                         activate_fileselect(FILE_MAIN, "Data Select", str, 0);
460                         return 0;
461                 }
462                 else if(G.qual==0) {
463                         extern_set_butspace(event);
464                 }
465                 break;
466         case F5KEY:
467                 if(G.qual==LR_SHIFTKEY) {
468                         newspace(curarea, SPACE_VIEW3D);
469                         return 0;
470                 }
471                 else if(G.qual==0) {
472                         extern_set_butspace(event);
473                 }
474                 break;
475         case F6KEY:
476                 if(G.qual==LR_SHIFTKEY) {
477                         newspace(curarea, SPACE_IPO);
478                         return 0;
479                 }
480                 else if(G.qual==0) {
481                         extern_set_butspace(event);
482                 }
483                 break;
484         case F7KEY:
485                 if(G.qual==LR_SHIFTKEY) {
486                         newspace(curarea, SPACE_BUTS);
487                         return 0;
488                 }
489                 else if(G.qual==0) {
490                         extern_set_butspace(event);
491                 }
492                 break;
493         case F8KEY:
494                 if(G.qual==LR_SHIFTKEY) {
495                         newspace(curarea, SPACE_SEQ);
496                         return 0;
497                 }
498                 else if(G.qual==0) {
499                         extern_set_butspace(event);
500                 }
501                 break;
502         case F9KEY:
503                 if(G.qual==LR_SHIFTKEY) {
504                         newspace(curarea, SPACE_OOPS);
505                         return 0;
506                 }
507                 else if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)) {
508                         newspace(curarea, SPACE_OOPS+256);
509                         return 0;
510                 }
511                 else if(G.qual==0) {
512                         extern_set_butspace(event);
513                 }
514                 break;
515         case F10KEY:
516                 if(G.qual==LR_SHIFTKEY) {
517                         newspace(curarea, SPACE_IMAGE);
518                         return 0;
519                 }
520                 else if(G.qual==0) {
521                         extern_set_butspace(event);
522                 }
523                 break;
524         case F11KEY:
525                 if(G.qual==LR_SHIFTKEY) {
526                         newspace(curarea, SPACE_TEXT);
527                         return 0;
528                 }
529                 else if (G.qual==LR_CTRLKEY) {
530                         playback_anim();
531                 }
532                 else if(G.qual==0) {
533                         BIF_toggle_render_display();
534                         return 0;
535                 }
536                 break;
537         case F12KEY:
538                 if(G.qual==LR_SHIFTKEY) {
539                         newspace(curarea, SPACE_ACTION);
540                         return 0;
541                 }
542                 else if (G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
543                         newspace(curarea, SPACE_NLA);
544                         return 0;
545                 }
546                 else if (G.qual==LR_CTRLKEY) {
547                         BIF_do_render(1);
548                 }
549                 else {
550                         /* ctrl/alt + f12 should render too, for some macs have f12 assigned to cd eject */
551                         BIF_do_render(0);
552                 }
553                 return 0;
554                 break;
555         
556         case WHEELUPMOUSE:
557                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
558                         if(CFRA>1) {
559                                 CFRA--;
560                                 update_for_newframe();
561                         }
562                         return 0;
563                 }
564                 break;
565         case WHEELDOWNMOUSE:
566                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
567                         CFRA++;
568                         update_for_newframe();
569                         return 0;
570                 }
571                 break;
572                 
573         case LEFTARROWKEY:
574         case DOWNARROWKEY:
575                 if(textediting==0 && textspace==0) {
576
577 #if 0
578 //#ifdef _WIN32 // FULLSCREEN
579                         if(event==DOWNARROWKEY){
580                                 if (G.qual==LR_ALTKEY)
581                                         mainwindow_toggle_fullscreen(0);
582                                 else if(G.qual==0)
583                                         CFRA-= G.scene->jumpframe;
584                         }
585 #else
586                         if((event==DOWNARROWKEY)&&(G.qual==0))
587                                 CFRA-= G.scene->jumpframe;
588 #endif
589                         else if((event==LEFTARROWKEY)&&(G.qual==0))
590                                 CFRA--;
591                         
592                         if(G.qual==LR_SHIFTKEY)
593                                 CFRA= SFRA;
594                         if(CFRA<1) CFRA=1;
595         
596                         update_for_newframe();
597                         return 0;
598                 }
599                 break;
600
601         case RIGHTARROWKEY:
602         case UPARROWKEY:
603                 if(textediting==0 && textspace==0) {
604
605 #if 0
606 //#ifdef _WIN32 // FULLSCREEN
607                         if(event==UPARROWKEY){ 
608                                 if(G.qual==LR_ALTKEY)
609                                         mainwindow_toggle_fullscreen(1);
610                                 else if(G.qual==0)
611                                         CFRA+= G.scene->jumpframe;
612                         }
613 #else
614                         if((event==UPARROWKEY)&&(G.qual==0))
615                                 CFRA+= G.scene->jumpframe;
616 #endif
617                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
618                                 CFRA++;
619
620                         if(G.qual==LR_SHIFTKEY)
621                                 CFRA= EFRA;
622                         
623                         update_for_newframe();
624                 }
625                 break;
626
627         case ESCKEY:
628                 sound_stop_all_sounds();        // whats this?
629                 
630                 /* stop playback on ESC always */
631                 rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
632                 audiostream_stop();
633                 allqueue(REDRAWALL, 0);
634                 
635                 break;
636         case TABKEY:
637                 if(G.qual==0) {
638                         if(textspace==0) {
639                                 if(curarea->spacetype==SPACE_IPO)
640                                         set_editflag_editipo();
641                                 else if(curarea->spacetype==SPACE_SEQ)
642                                         enter_meta();
643                                 else if(curarea->spacetype==SPACE_NODE)
644                                         return 1;
645                                 else if(G.vd) {
646                                         /* also when Alt-E */
647                                         if(G.obedit==NULL) {
648                                                 enter_editmode();
649                                                 if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
650                                         }
651                                         else
652                                                 exit_editmode(2); // freedata, and undo
653                                 }
654                                 return 0;
655                         }
656                 }
657                 else if(G.qual==LR_CTRLKEY){
658                         Object *ob= OBACT;
659                         if(ob) {
660                                 if(ob->type==OB_ARMATURE) {
661                                         if(ob->flag & OB_POSEMODE) exit_posemode();
662                                         else enter_posemode();
663                                 }
664                                 else if(ob->type==OB_MESH) {
665                                         if(ob==G.obedit) EM_selectmode_menu();
666                                         else set_wpaint();
667                                 }
668                         }
669                 }
670                 else if(G.qual==LR_SHIFTKEY) {  // ??
671                         if(G.obedit)
672                                 exit_editmode(2); // freedata, and undo
673                         if(G.f & G_FACESELECT)
674                                 set_faceselect();
675                         if(G.f & G_VERTEXPAINT)
676                                 set_vpaint();
677                         if(G.f & G_TEXTUREPAINT) {
678                                 G.f &= ~G_TEXTUREPAINT;
679                                 allqueue(REDRAWVIEW3D, 0);
680                                 allqueue(REDRAWBUTSEDIT, 0);
681                         }
682                         if(G.f & G_WEIGHTPAINT)
683                                 set_wpaint();
684                 }
685                 break;
686
687         case BACKSPACEKEY:
688                 break;
689
690         case AKEY:
691                 if(textediting==0 && textspace==0) {
692                         if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)){
693                                 play_anim(1);
694                                 return 0;
695                         }
696                         else if(G.qual==LR_ALTKEY) {
697                                 play_anim(0);
698                                 return 0;
699                         }
700                 }
701                 break;
702         case EKEY:
703                 if(G.qual==LR_ALTKEY) {
704                         if(G.vd && textspace==0) {
705                                 if(G.obedit==0) {
706                                         enter_editmode();
707                                         BIF_undo_push("Original");
708                                 }
709                                 else
710                                         exit_editmode(2); // freedata, and undo
711                                 return 0;
712                         }                       
713                 }
714                 break;
715         case IKEY:
716                 if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
717                         if(G.qual==0) {
718                                 common_insertkey();
719                                 return 0;
720                         }
721                 }
722                 break;
723         case JKEY:
724                 if(textediting==0 && textspace==0) {
725                         if (G.qual==0) {
726                                 BIF_swap_render_rects();
727                                 return 0;
728                         }
729                 }
730                 break;
731
732         case NKEY:
733                 if(textediting==0 && textspace==0) {
734                         if(G.qual & LR_CTRLKEY);
735                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
736                                 if(curarea->spacetype==SPACE_VIEW3D);           // is new panel, in view3d queue
737                                 else if(curarea->spacetype==SPACE_IPO);                 // is new panel, in ipo queue
738                                 else if(curarea->spacetype==SPACE_IMAGE);                       // is new panel, in ipo queue
739                                 else if(curarea->spacetype==SPACE_ACTION);                      // is own queue
740                                 else if(curarea->spacetype==SPACE_NLA);                 // is new panel
741                                 else if(curarea->spacetype==SPACE_SEQ);                 // is new panel
742                                 else {
743                                         clever_numbuts();
744                                         return 0;
745                                 }
746                         }
747                 }
748                 break;
749                 
750         case OKEY:
751                 if(textediting==0) {
752                         if(G.qual==LR_CTRLKEY) {
753                                 recentfile = recent_filelist();
754                                 if(recentfile) {
755                                         BIF_read_file(recentfile);
756                                 }
757                                 return 0;
758                         }
759                 }
760                 break;
761                 
762         case SKEY:
763                 if(G.obedit==NULL) {
764                         if(G.qual==LR_CTRLKEY) {
765                                 strcpy(dir, G.sce);
766                                 if (untitled(dir)) {
767                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
768                                 } else {
769                                         BIF_write_file(dir);
770                                         free_filesel_spec(dir);
771                                 }
772                                 return 0;
773                         }
774                 }
775                 break;
776         
777         case TKEY:
778                 if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
779                         Object *ob = OBACT;
780                         int event = pupmenu(ob?"Time%t|draw|recalc ob|recalc data":"Time%t|draw");
781                         int a;
782                         double delta, stime;
783
784                         waitcursor(1);
785                         
786                         stime= PIL_check_seconds_timer();
787                         for(a=0; a<100000; a++) {
788                                 if (event==1) {
789                                         scrarea_do_windraw(curarea);
790                                 } else if (event==2) {
791                                         ob->recalc |= OB_RECALC_OB;
792                                         object_handle_update(ob);
793                                 } else if (event==3) {
794                                         ob->recalc |= OB_RECALC_DATA;
795                                         object_handle_update(ob);
796                                 }
797
798                                 delta= PIL_check_seconds_timer()-stime;
799                                 if (delta>5.0) break;
800                         }
801                         
802                         waitcursor(0);
803                         notice("%8.6f s/op - %6.2f ops/s - %d iterations", delta/a, a/delta, a);
804                         return 0;
805                 }
806                 else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
807                         int a;
808                         int event= pupmenu("10 Timer%t|draw|draw+swap|undo");
809                         if(event>0) {
810                                 double stime= PIL_check_seconds_timer();
811                                 char tmpstr[128];
812                                 int time;
813
814                                 waitcursor(1);
815                                 
816                                 for(a=0; a<10; a++) {
817                                         if (event==1) {
818                                                 scrarea_do_windraw(curarea);
819                                         } else if (event==2) {
820                                                 scrarea_do_windraw(curarea);
821                                                 screen_swapbuffers();
822                                         }
823                                         else if(event==3) {
824                                                 BIF_undo();
825                                                 BIF_redo();
826                                         }
827                                 }
828                         
829                                 time= (int) ((PIL_check_seconds_timer()-stime)*1000);
830                                 
831                                 if(event==1) sprintf(tmpstr, "draw %%t|%d ms", time);
832                                 if(event==2) sprintf(tmpstr, "d+sw %%t|%d ms", time);
833                                 if(event==3) sprintf(tmpstr, "undo %%t|%d ms", time);
834                         
835                                 waitcursor(0);
836                                 pupmenu(tmpstr);
837
838                         }
839                         return 0;
840                 }
841                 break;
842                                 
843         case UKEY:
844                 if(textediting==0) {
845                         if(G.qual==LR_CTRLKEY) {
846                                 if(okee("Save user defaults")) {
847                                         BIF_write_homefile();
848                                 }
849                                 return 0;
850                         }
851                         else if(G.qual==LR_ALTKEY) {
852                                 if(curarea->spacetype!=SPACE_TEXT) {
853                                         BIF_undo_menu();
854                                         return 0;
855                                 }
856                         }
857                 }
858                 break;
859                 
860         case WKEY:
861                 if(textediting==0) {
862                         if(G.qual==LR_CTRLKEY) {
863                                 strcpy(dir, G.sce);
864                                 if (untitled(dir)) {
865                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
866                                 } else {
867                                         BIF_write_file(dir);
868                                         free_filesel_spec(dir);
869                                 }
870                                 return 0;
871                         }
872                         else if(G.qual==LR_ALTKEY) {
873                                 write_videoscape_fs();
874                         }
875                 }
876                 break;
877                 
878         case XKEY:
879                 if(textspace==0 && textediting==0) {
880                         if(G.qual==LR_CTRLKEY) {
881                                 if(okee("Erase all")) {
882                                         if( BIF_read_homefile()==0) error("No file ~/.B.blend");
883                                 }
884                                 return 0;
885                         }
886                 }
887                 break;
888         case YKEY:      // redo alternative
889                 if(textspace==0) {
890                         if(G.qual==LR_CTRLKEY) {
891                                 BIF_redo(); 
892                                 return 0;
893                         }
894                 }
895                 break;
896         case ZKEY:      // undo
897                 if(textspace==0) {
898                         if(G.qual & (LR_CTRLKEY|LR_COMMANDKEY)) { // all combos with ctrl/commandkey are accepted
899                                 if ELEM(G.qual, LR_CTRLKEY, LR_COMMANDKEY) BIF_undo();
900                                 else BIF_redo(); // all combos with ctrl is redo
901                                 return 0;
902                         }
903                 }
904                 break; 
905         }
906         
907         return 1;
908 }
909
910 /* eof */