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