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