OSX only: the Apple key now is a normal modifier in code, so can be
[blender.git] / source / blender / src / toets.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31
32  *
33  *
34  * General blender hot keys (toets = dutch), special hotkeys are in space.c
35  *
36  */
37
38 #include <string.h>
39 #include <math.h>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 #ifdef WIN32
46 #include "BLI_winstuff.h"
47 #endif
48
49 #include "MEM_guardedalloc.h"
50
51 #include "PIL_time.h"
52
53 #include "nla.h"        /* Only for the #ifdef flag - To be removed later */
54
55 #include "BLI_blenlib.h"
56 #include "BLI_arithb.h"
57
58 #include "DNA_object_types.h"
59 #include "DNA_screen_types.h"
60 #include "DNA_space_types.h"
61 #include "DNA_view3d_types.h"
62 #include "DNA_userdef_types.h"
63
64 #include "BKE_action.h"
65 #include "BKE_anim.h"
66 #include "BKE_blender.h"
67 #include "BKE_displist.h"
68 #include "BKE_global.h"
69 #include "BKE_ipo.h"
70 #include "BKE_ika.h"
71 #include "BKE_key.h"
72 #include "BKE_scene.h"
73 #include "BKE_utildefines.h"
74
75 #include "BIF_interface.h"
76 #include "BIF_screen.h"
77 #include "BIF_space.h"
78 #include "BIF_butspace.h"
79 #include "BIF_renderwin.h"
80 #include "BIF_toolbox.h"
81 #include "BIF_toets.h"
82 #include "BIF_editseq.h"
83 #include "BIF_editsound.h"
84 #include "BIF_poseobject.h"
85 #include "BIF_usiblender.h"
86
87 #include "BDR_vpaint.h"
88 #include "BDR_editobject.h"
89 #include "BDR_editface.h"
90
91 #include "BSE_filesel.h"        /* For activate_fileselect */
92 #include "BSE_drawview.h"       /* For play_anim */
93 #include "BSE_view.h"
94 #include "BSE_edit.h"
95 #include "BSE_editipo.h"
96 #include "BSE_headerbuttons.h"
97
98 #include "blendef.h"
99 #include "render.h"
100
101 #include "IMB_imbuf.h"
102 #include "IMB_imbuf_types.h"
103
104 #include "mydevice.h"
105
106 #include "BIF_poseobject.h"
107
108 /* only used in toets.c */
109 /* this function doesn't really belong here */
110 /* ripped from render module */
111 void schrijfplaatje(char *name);
112
113
114 void write_imag(char *name)
115 {
116         /* from file select */
117         char str[256];
118
119         strcpy(str, name);
120         BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
121
122         if(saveover(str)) {
123                 if(BLI_testextensie(str,".blend")) {
124                         error("Wrong filename");
125                         return;
126                 }
127                 waitcursor(1); /* from screen.c */
128                 schrijfplaatje(str);
129                 strcpy(G.ima, name);
130                 waitcursor(0);
131         }
132 }
133
134
135 /* From matrix.h: it's really a [4][4]! */
136 /* originally in initrender... maybe add fileControl thingy? */
137
138 /* should be called write_image(char *name) :-) */
139 void schrijfplaatje(char *name)
140 {
141         struct ImBuf *ibuf=0;
142         unsigned int *temprect=0;
143         char str[FILE_MAXDIR+FILE_MAXFILE];
144
145         /* has RGBA been set? If so: use alpha channel for color zero */
146         IMB_alpha_to_col0(FALSE);
147
148         if(R.r.planes == 32) {
149                 /* everything with less than 50 % alpha -> col 0 */
150                 if(R.r.alphamode == R_ALPHAKEY) IMB_alpha_to_col0(2);
151                 /* only when 0 alpha -> col 0 */
152                 else IMB_alpha_to_col0(1);
153         }
154
155         /* Seems to me this is also superfluous.... */
156         if (R.r.imtype==R_FTYPE) {
157                 strcpy(str, R.r.ftype);
158                 BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
159
160                 ibuf = IMB_loadiffname(str, IB_test);
161                 if(ibuf) {
162                         ibuf->x = R.rectx;
163                         ibuf->y = R.recty;
164                 }
165                 else {
166                         error("Can't find filetype");
167                         G.afbreek= 1;
168                         return;
169                 }
170                 /* setdither(2); */
171         }
172
173         if(ibuf == 0) {
174                 ibuf= IMB_allocImBuf(R.rectx, R.recty, R.r.planes, 0, 0);
175         }
176
177         if(ibuf) {
178                 ibuf->rect= (unsigned int *) R.rectot;
179
180                 if(R.r.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
181
182                 if(R.r.imtype== R_IRIS) {
183                         ibuf->ftype= IMAGIC;
184                 }
185                 else if(R.r.imtype==R_IRIZ) {
186                         ibuf->ftype= IMAGIC;
187                         if (ibuf->zbuf == 0) {
188                                 if (R.rectz) {
189                                         ibuf->zbuf = (int *)R.rectz;
190                                 }
191                                 else printf("no zbuf\n");
192                         }
193                 }
194                 else if(R.r.imtype==R_PNG) {
195                         ibuf->ftype= PNG;
196                 }
197                 else if(R.r.imtype==R_BMP) {
198                         ibuf->ftype= BMP;
199                 }
200                 else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) {
201                         ibuf->ftype= TGA;
202                 }
203                 else if(R.r.imtype==R_RAWTGA) {
204                         ibuf->ftype= RAWTGA;
205                 }
206                 else if(R.r.imtype==R_HAMX) {
207                         /* make copy */
208                         temprect= MEM_dupallocN(R.rectot);
209                         ibuf->ftype= AN_hamx;
210                 }
211                 else if(ELEM5(R.r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) {
212                         if(R.r.quality < 10) R.r.quality= 90;
213
214                         if(R.r.mode & R_FIELDS) ibuf->ftype= JPG_VID|R.r.quality;
215                         else ibuf->ftype= JPG|R.r.quality;
216                 }
217         
218                 RE_make_existing_file(name);
219
220                 if(IMB_saveiff(ibuf, name, IB_rect | IB_zbuf)==0) {
221                         perror(name);
222                         G.afbreek= 1;
223                 }
224
225                 IMB_freeImBuf(ibuf);
226
227                 if (R.r.imtype==R_HAMX) {
228                         MEM_freeN(R.rectot);
229                         R.rectot= temprect;
230                 }
231         }
232         else {
233                 G.afbreek= 1;
234         }
235 }
236
237
238
239 /* ------------------------------------------------------------------------- */
240
241 static int is_an_active_object(void *ob) {
242         Base *base;
243         
244         for (base= FIRSTBASE; base; base= base->next)
245                 if (base->object == ob)
246                         return 1;
247         
248         return 0;
249 }
250
251 void persptoetsen(unsigned short event)
252 {
253         static Object *oldcamera=0;
254         float phi, si, q1[4], vec[3];
255         static int perspo=1;
256         
257         if(event==PADENTER) {
258                 if (G.qual == LR_SHIFTKEY) {
259                         view3d_set_1_to_1_viewborder(G.vd);
260                 } else {
261                         if (G.vd->persp==2) {
262                                 G.vd->camzoom= 0.0;
263                         } else {
264                                 G.vd->dist= 10.0;
265                         }
266                 }
267         }
268         else if((G.qual & (LR_SHIFTKEY | LR_CTRLKEY)) && (event != PAD0)) {
269                 if(event==PAD0) {
270                         /* G.vd->persp= 3; */
271                 }
272                 else if(event==PAD7) {
273                         G.vd->viewquat[0]= 0.0;
274                         G.vd->viewquat[1]= -1.0;
275                         G.vd->viewquat[2]= 0.0;
276                         G.vd->viewquat[3]= 0.0;
277                         G.vd->view= 7;
278                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; 
279                         else if(G.vd->persp>=2) G.vd->persp= perspo;
280                 }
281                 else if(event==PAD1) {
282                         G.vd->viewquat[0]= 0.0;
283                         G.vd->viewquat[1]= 0.0;
284                         G.vd->viewquat[2]= (float)-cos(M_PI/4.0);
285                         G.vd->viewquat[3]= (float)-cos(M_PI/4.0);
286                         G.vd->view=1;
287                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
288                         else if(G.vd->persp>=2) G.vd->persp= perspo;
289                 }
290                 else if(event==PAD3) {
291                         G.vd->viewquat[0]= 0.5;
292                         G.vd->viewquat[1]= -0.5;
293                         G.vd->viewquat[2]= 0.5;
294                         G.vd->viewquat[3]= 0.5;
295                         G.vd->view=3;
296                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
297                         else if(G.vd->persp>=2) G.vd->persp= perspo;
298                 }
299                 else if(event==PADMINUS) {
300                         /* this min and max is also in viewmove() */
301                         if(G.vd->persp==2) {
302                                         G.vd->camzoom-= 10;
303                                         if(G.vd->camzoom<-30) G.vd->camzoom= -30;
304                                 }
305                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
306                 }
307                 else if(event==PADPLUSKEY) {
308                         if(G.vd->persp==2) {
309                                         G.vd->camzoom+= 10;
310                                         if(G.vd->camzoom>300) G.vd->camzoom= 300;
311                         }
312                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
313                 }
314                 else {
315
316                         initgrabz(0.0, 0.0, 0.0);
317                         
318                         if(event==PAD6) window_to_3d(vec, -32, 0);
319                         else if(event==PAD4) window_to_3d(vec, 32, 0);
320                         else if(event==PAD8) window_to_3d(vec, 0, -25);
321                         else if(event==PAD2) window_to_3d(vec, 0, 25);
322                         G.vd->ofs[0]+= vec[0];
323                         G.vd->ofs[1]+= vec[1];
324                         G.vd->ofs[2]+= vec[2];
325                 }
326         }
327         else {
328
329                 if(event==PAD7) {
330                         G.vd->viewquat[0]= 1.0;
331                         G.vd->viewquat[1]= 0.0;
332                         G.vd->viewquat[2]= 0.0;
333                         G.vd->viewquat[3]= 0.0;
334                         G.vd->view=7;
335                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
336                         else if(G.vd->persp>=2) G.vd->persp= perspo;
337                 }
338                 else if(event==PAD1) {
339                         G.vd->viewquat[0]= (float)cos(M_PI/4.0);
340                         G.vd->viewquat[1]= (float)-sin(M_PI/4.0);
341                         G.vd->viewquat[2]= 0.0;
342                         G.vd->viewquat[3]= 0.0;
343                         G.vd->view=1;
344                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
345                         else if(G.vd->persp>=2) G.vd->persp= perspo;
346                 }
347                 else if(event==PAD3) {
348                         G.vd->viewquat[0]= 0.5;
349                         G.vd->viewquat[1]= -0.5;
350                         G.vd->viewquat[2]= -0.5;
351                         G.vd->viewquat[3]= -0.5;
352                         G.vd->view=3;
353                         if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
354                         else if(G.vd->persp>=2) G.vd->persp= perspo;
355                 }
356                 else if(event==PADMINUS) {
357                         /* this min and max is also in viewmove() */
358                         if(G.vd->persp==2) {
359                                 G.vd->camzoom= MAX2(-30, G.vd->camzoom-5);
360                         }
361                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
362                 }
363                 else if(event==PADPLUSKEY) {
364                         if(G.vd->persp==2) {
365                                 G.vd->camzoom= MIN2(300, G.vd->camzoom+5);
366                         }
367                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
368                 }
369                 else if(event==PAD5) {
370                         if(G.vd->persp==1) G.vd->persp=0;
371                         else G.vd->persp=1;
372                 }
373                 else if(event==PAD0) {
374                         if(G.qual==LR_ALTKEY) {
375                                 if(oldcamera && is_an_active_object(oldcamera)) {
376                                         G.vd->camera= oldcamera;
377                                 }
378                                 
379                                 handle_view3d_lock();
380                         }
381                         else if(BASACT) {
382                                 if(G.qual==LR_CTRLKEY) {
383                                         if(G.vd->camera != OBACT) {
384                                                 if(G.vd->camera && G.vd->camera->type==OB_CAMERA)
385                                                         oldcamera= G.vd->camera;
386                                                 
387                                                 G.vd->camera= OBACT;
388                                                 handle_view3d_lock();
389                                         }
390                                 }
391                                 else if(G.vd->camera==0 && OBACT->type==OB_CAMERA) {
392                                         G.vd->camera= OBACT;
393                                         handle_view3d_lock();
394                                 }
395                         }
396                         if(G.vd->camera==0) {
397                                 G.vd->camera= scene_find_camera(G.scene);
398                                 handle_view3d_lock();
399                         }
400                         
401                         if(G.vd->camera) {
402                                 G.vd->persp= 2;
403                                 G.vd->view= 0;
404                                 if(G.qual & LR_SHIFTKEY) {
405                                         void setcameratoview3d(void);   // view.c
406                                         setcameratoview3d();
407                                 }                               
408                         }
409                 }
410                 else if(event==PAD9) {
411                         countall();
412                         do_all_ipos();
413                         do_all_keys();
414                         do_all_actions();
415                         do_all_ikas();
416                         test_all_displists();
417                         
418                         reset_slowparents();    /* editobject.c */
419                 }
420                 else if(G.vd->persp<2) {
421                         if(event==PAD4 || event==PAD6) {
422                                 /* z-axis */
423                                 phi= (float)(M_PI/24.0);
424                                 if(event==PAD6) phi= -phi;
425                                 si= (float)sin(phi);
426                                 q1[0]= (float)cos(phi);
427                                 q1[1]= q1[2]= 0.0;
428                                 q1[3]= si;
429                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
430                                 G.vd->view= 0;
431                         }
432                         if(event==PAD2 || event==PAD8) {
433                                 
434                                 /* horizontal axis */
435                                 VECCOPY(q1+1, G.vd->viewinv[0]);
436                                 
437                                 Normalise(q1+1);
438                                 phi= (float)(M_PI/24.0);
439                                 if(event==PAD2) phi= -phi;
440                                 si= (float)sin(phi);
441                                 q1[0]= (float)cos(phi);
442                                 q1[1]*= si;
443                                 q1[2]*= si;
444                                 q1[3]*= si;
445                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
446                                 G.vd->view= 0;
447                         }
448                 }
449
450                 if(G.vd->persp<2) perspo= G.vd->persp;
451         }
452         scrarea_queue_redraw(curarea);
453 }
454
455 int untitled(char * name)
456 {
457         if (G.save_over == 0 ) {
458                 char * c= BLI_last_slash(name);
459                 
460                 if (c)
461                         strcpy(&c[1], "untitled.blend");
462                 else
463                         strcpy(name, "untitled.blend");
464                         
465                 return(TRUE);
466         }
467         
468         return(FALSE);
469 }
470
471 int save_image_filesel_str(char *str)
472 {
473         switch(G.scene->r.imtype) {
474         case R_PNG:
475                 strcpy(str, "Save PNG"); return 1;
476         case R_BMP:
477                 strcpy(str, "Save BMP"); return 1;
478         case R_TARGA:
479                 strcpy(str, "Save Targa"); return 1;
480         case R_RAWTGA:
481                 strcpy(str, "Save Raw Targa"); return 1;
482         case R_IRIS:
483                 strcpy(str, "Save IRIS"); return 1;
484         case R_IRIZ:
485                 strcpy(str, "Save IRIS"); return 1;
486         case R_HAMX:
487                 strcpy(str, "Save HAMX"); return 1;
488         case R_FTYPE:
489                 strcpy(str, "Save Ftype"); return 1;
490         case R_JPEG90:
491                 strcpy(str, "Save JPEG"); return 1;
492         default:
493                 strcpy(str, "Save Image"); return 0;
494         }       
495 }
496
497 void BIF_save_rendered_image(void)
498 {
499         if(!R.rectot) {
500                 error("No image rendered");
501         } else {
502                 char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
503
504                 if(G.ima[0]==0) {
505                         strcpy(dir, G.sce);
506                         BLI_splitdirstring(dir, str);
507                         strcpy(G.ima, dir);
508                 }
509                 
510                 R.r.imtype= G.scene->r.imtype;
511                 R.r.quality= G.scene->r.quality;
512                 R.r.planes= G.scene->r.planes;
513         
514                 if (!save_image_filesel_str(str)) {
515                         error("Select an image type in DisplayButtons(F10)");
516                 } else {
517                         activate_fileselect(FILE_SPECIAL, str, G.ima, write_imag);
518                 }
519         }
520 }
521
522 int blenderqread(unsigned short event, short val)
523 {
524         /* here do the general keys handling (not screen/window/space) */
525         /* return 0: do not pass on to the other queues */
526         extern int textediting;
527         ScrArea *sa;
528         Object *ob;
529         int textspace=0;
530         /* Changed str and dir size to 160, to make sure there is enough
531          * space for filenames. */
532         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
533         
534         if(val==0) return 1;
535         if(event==MOUSEY || event==MOUSEX) return 1;
536         if (G.flags & G_FLAGS_AUTOPLAY) return 1;
537
538         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
539         else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
540
541         switch(event) {
542
543         case F1KEY:
544                 if(G.qual==0) {
545                         /* this exception because of the '?' button */
546                         if(curarea->spacetype==SPACE_INFO) {
547                                 sa= closest_bigger_area();
548                                 areawinset(sa->win);
549                         }
550                         
551                         activate_fileselect(FILE_BLENDER, "Open File", G.sce, BIF_read_file);
552                         return 0;
553                 }
554                 else if(G.qual==LR_SHIFTKEY) {
555                         activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
556                         return 0;
557                 }
558                 break;
559         case F2KEY:
560                 if(G.qual==0) {
561                         strcpy(dir, G.sce);
562                         untitled(dir);
563                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
564                         return 0;
565                 }
566                 else if(G.qual==LR_CTRLKEY) {
567                         write_vrml_fs();
568                         return 0;
569                 }
570                 else if(G.qual==LR_SHIFTKEY) {
571                         write_dxf_fs();
572                         return 0;
573                 }
574                 break;
575         case F3KEY:
576                 if(G.qual==0) {
577                         BIF_save_rendered_image();
578                         return 0;
579                 }
580                 else if(G.qual & LR_CTRLKEY) {
581                         /* all alt+ctrl+shift combos are needed here... */
582                         BIF_screendump();
583                 }
584                 break;
585         case F4KEY:
586                 if(G.qual==LR_SHIFTKEY) {
587
588                         memset(str, 0, 16);
589                         ob= OBACT;
590                         if(ob) strcpy(str, ob->id.name);
591
592                         activate_fileselect(FILE_MAIN, "Data Select", str, 0);
593                         return 0;
594                 }
595                 else if(G.qual==0) {
596                         extern_set_butspace(event);
597                 }
598                 break;
599         case F5KEY:
600                 if(G.qual==LR_SHIFTKEY) {
601                         newspace(curarea, SPACE_VIEW3D);
602                         return 0;
603                 }
604                 else if(G.qual==0) {
605                         extern_set_butspace(event);
606                 }
607                 break;
608         case F6KEY:
609                 if(G.qual==LR_SHIFTKEY) {
610                         newspace(curarea, SPACE_IPO);
611                         return 0;
612                 }
613                 else if(G.qual==0) {
614                         extern_set_butspace(event);
615                 }
616                 break;
617         case F7KEY:
618                 if(G.qual==LR_SHIFTKEY) {
619                         newspace(curarea, SPACE_BUTS);
620                         return 0;
621                 }
622                 else if(G.qual==0) {
623                         extern_set_butspace(event);
624                 }
625                 break;
626         case F8KEY:
627                 if(G.qual==LR_SHIFTKEY) {
628                         newspace(curarea, SPACE_SEQ);
629                         return 0;
630                 }
631                 else if(G.qual==0) {
632                         extern_set_butspace(event);
633                 }
634                 break;
635         case F9KEY:
636                 if(G.qual==LR_SHIFTKEY) {
637                         newspace(curarea, SPACE_OOPS);
638                         return 0;
639                 }
640                 else if(G.qual==0) {
641                         extern_set_butspace(event);
642                 }
643                 break;
644         case F10KEY:
645                 if(G.qual==LR_SHIFTKEY) {
646                         newspace(curarea, SPACE_IMAGE);
647                         return 0;
648                 }
649                 else if(G.qual==0) {
650                         extern_set_butspace(event);
651                 }
652                 break;
653         case F11KEY:
654                 if(G.qual==LR_SHIFTKEY) {
655                         newspace(curarea, SPACE_TEXT);
656                         return 0;
657                 }
658                 else if(G.qual==0) {
659                         BIF_toggle_render_display();
660                         return 0;
661                 }
662                 break;
663         case F12KEY:
664                 if(G.qual==LR_SHIFTKEY) {
665                         newspace(curarea, SPACE_ACTION);
666                         return 0;
667                 }
668                 else if (G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
669                         newspace(curarea, SPACE_NLA);
670                         return 0;
671                 }
672                 else {
673                         /* ctrl/alt + f12 should render too, for some macs have f12 assigned to cd eject */
674                         BIF_do_render(0);
675                 }
676                 return 0;
677                 break;
678         
679         case LEFTARROWKEY:
680         case DOWNARROWKEY:
681                 if(textediting==0 && textspace==0) {
682
683 #ifdef _WIN32   // FULLSCREEN
684                         if(event==DOWNARROWKEY){
685                                 if (G.qual==LR_ALTKEY)
686                                         mainwindow_toggle_fullscreen(0);
687                                 else if(G.qual==0)
688                                         CFRA-= 10;
689                         }
690 #else
691                         if((event==DOWNARROWKEY)&&(G.qual==0))
692                                 CFRA-= 10;
693 #endif
694                         else if((event==LEFTARROWKEY)&&(G.qual==0))
695                                 CFRA--;
696                         
697                         if(G.qual==LR_SHIFTKEY)
698                                 CFRA= SFRA;
699                         if(CFRA<1) CFRA=1;
700         
701                         update_for_newframe();
702                         return 0;
703                 }
704                 break;
705
706         case RIGHTARROWKEY:
707         case UPARROWKEY:
708                 if(textediting==0 && textspace==0) {
709
710 #ifdef _WIN32   // FULLSCREEN
711                         if(event==UPARROWKEY){ 
712                                 if(G.qual==LR_ALTKEY)
713                                         mainwindow_toggle_fullscreen(1);
714                                 else if(G.qual==0)
715                                         CFRA+= 10;
716                         }
717 #else
718                         if((event==UPARROWKEY)&&(G.qual==0))
719                                 CFRA+= 10;
720 #endif
721                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
722                                 CFRA++;
723
724                         if(G.qual==LR_SHIFTKEY)
725                                 CFRA= EFRA;
726                         
727                         update_for_newframe();
728                 }
729                 break;
730
731         case ESCKEY:
732                 sound_stop_all_sounds();
733                 break;
734         case TABKEY:
735                 if(G.qual==0) {
736                         if(textspace==0) {
737                                 if(curarea->spacetype==SPACE_IPO)
738                                         set_editflag_editipo();
739                                 else if(curarea->spacetype==SPACE_SEQ)
740                                         enter_meta();
741                                 else if(G.vd) {
742                                         /* also when Alt-E */
743                                         if(G.obedit==0)
744                                                 enter_editmode();
745                                         else
746                                                 exit_editmode(2); // freedata, and undo
747                                 }
748                                 return 0;
749                         }
750                 }
751                 else if(G.qual==LR_CTRLKEY){
752                         if(G.obpose)
753                                 exit_posemode(1);
754                         else
755                                 enter_posemode();
756                         allqueue(REDRAWHEADERS, 0);     
757                         allqueue(REDRAWBUTSALL, 0);     
758                 }
759                 else if(G.qual==LR_SHIFTKEY) {
760                         if(G.obedit)
761                                 exit_editmode(2); // freedata, and undo
762                         if(G.f & G_FACESELECT)
763                                 set_faceselect();
764                         if(G.f & G_VERTEXPAINT)
765                                 set_vpaint();
766                         if(G.f & G_TEXTUREPAINT) {
767                                 G.f &= ~G_TEXTUREPAINT;
768                                 allqueue(REDRAWVIEW3D, 0);
769                                 allqueue(REDRAWBUTSEDIT, 0);
770                         }
771                         if(G.f & G_WEIGHTPAINT)
772                                 set_wpaint();
773                         if(G.obpose)
774                                 exit_posemode(1);
775                 }
776                 break;
777
778         case BACKSPACEKEY:
779                 break;
780
781         case AKEY:
782                 if(textediting==0 && textspace==0) {
783                         if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)){
784                                 play_anim(1);
785                                 return 0;
786                         }
787                         else if(G.qual==LR_ALTKEY) {
788                                 play_anim(0);
789                                 return 0;
790                         }
791                 }
792                 break;
793         case EKEY:
794                 if(G.qual==LR_ALTKEY) {
795                         if(G.vd && textspace==0) {
796                                 if(G.obedit==0)
797                                         enter_editmode();
798                                 else
799                                         exit_editmode(2); // freedata, and undo
800                                 return 0;
801                         }                       
802                 }
803                 break;
804         case IKEY:
805                 if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
806                         if(G.qual==0) {
807                                 common_insertkey();
808                                 return 0;
809                         }
810                 }
811                 break;
812         case JKEY:
813                 if(textediting==0 && textspace==0) {
814                         if(R.rectot && G.qual==0) {
815                                 BIF_swap_render_rects();
816                                 return 0;
817                         }
818                 }
819                 break;
820
821         case NKEY:
822                 if(textediting==0 && textspace==0) {
823                         if(G.qual & LR_CTRLKEY);
824                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
825                                 if(curarea->spacetype==SPACE_VIEW3D);           // is new panel, in view3d queue
826                                 else if(curarea->spacetype==SPACE_IPO);                 // is new panel, in ipo queue
827                                 else if(curarea->spacetype==SPACE_IMAGE);                       // is new panel, in ipo queue
828                                 else if(curarea->spacetype==SPACE_ACTION);                      // is own queue
829                                 else if(curarea->spacetype==SPACE_NLA);                 // is new panel
830                                 else if(curarea->spacetype==SPACE_SEQ);                 // is new panel
831                                 else {
832                                         clever_numbuts();
833                                         return 0;
834                                 }
835                         }
836                 }
837                 break;
838                 
839         case OKEY:
840                 if(textediting==0) {
841                         if(G.qual==LR_CTRLKEY) {
842                                 /* There seem to be crashes here sometimes.... String
843                                  * bound overwrites? I changed dir and str sizes,
844                                  * let's see if this reoccurs. */
845                                 sprintf(str, "Open file: %s", G.sce);
846                         
847                                 if(okee(str)) {
848                                         strcpy(dir, G.sce);
849                                         BIF_read_file(dir);
850                                 }
851                                 return 0;
852                         }
853                 }
854                 break;
855                 
856         case SKEY:
857                 if(G.obpose==0 && G.obedit==0) {
858                         if(G.qual==LR_CTRLKEY) {
859                                 strcpy(dir, G.sce);
860                                 if (untitled(dir)) {
861                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
862                                 } else {
863                                         BIF_write_file(dir);
864                                         free_filesel_spec(dir);
865                                 }
866                                 return 0;
867                         }
868                 }
869                 break;
870         
871         case TKEY:
872                 if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
873                         int a;
874                         double delta, stime;
875
876                         waitcursor(1);
877                         
878                         stime= PIL_check_seconds_timer();
879                         for(a=0; a<100000; a++) {
880                                 scrarea_do_windraw(curarea);
881
882                                 delta= PIL_check_seconds_timer()-stime;
883                                 if (delta>5.0) break;
884                         }
885                         
886                         waitcursor(0);
887                         notice("FPS: %f (%d iterations)", a/delta, a);
888                         return 0;
889                 }
890                 else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
891                         int a;
892                         int event= pupmenu("10 Timer%t|draw|draw+swap|displist|undo");
893                         if(event>0) {
894                                 double stime= PIL_check_seconds_timer();
895                                 char tmpstr[128];
896                                 int time;
897
898                                 waitcursor(1);
899                                 
900                                 for(a=0; a<10; a++) {
901                                         if (event==1) {
902                                                 scrarea_do_windraw(curarea);
903                                         } else if (event==2) {
904                                                 scrarea_do_windraw(curarea);
905                                                 screen_swapbuffers();
906                                         } else if (event==3) {
907                                                 if (OBACT) {
908                                                         makeDispList(OBACT);
909                                                 }
910                                         }
911                                         else if(event==4) {
912                                                 BKE_write_undo("10 timer");
913                                         }
914                                 }
915                         
916                                 time= (PIL_check_seconds_timer()-stime)*1000;
917                                 
918                                 if(event==1) sprintf(tmpstr, "draw %%t|%d ms", time);
919                                 if(event==2) sprintf(tmpstr, "d+sw %%t|%d ms", time);
920                                 if(event==3) sprintf(tmpstr, "displist %%t|%d ms", time);
921                                 if(event==4) sprintf(tmpstr, "undo %%t|%d ms", time);
922                         
923                                 waitcursor(0);
924                                 pupmenu(tmpstr);
925
926                         }
927                         return 0;
928                 }
929                 break;
930                                 
931         case UKEY:
932                 if(textediting==0) {
933                         if(G.qual==LR_CTRLKEY) {
934                                 if(okee("Save user defaults")) {
935                                         BIF_write_homefile();
936                                 }
937                                 return 0;
938                         }
939                 }
940                 break;
941                 
942         case WKEY:
943                 if(textediting==0) {
944                         if(G.qual==LR_CTRLKEY) {
945                                 strcpy(dir, G.sce);
946                                 if (untitled(dir)) {
947                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
948                                 } else {
949                                         BIF_write_file(dir);
950                                         free_filesel_spec(dir);
951                                 }
952                                 return 0;
953                         }
954                         else if(G.qual==LR_ALTKEY) {
955                                 write_videoscape_fs();
956                         }
957                 }
958                 break;
959                 
960         case XKEY:
961                 if(textspace==0) {
962                         if(G.qual==LR_CTRLKEY) {
963                                 if(okee("Erase all")) {
964                                         if( BIF_read_homefile()==0) error("No file ~/.B.blend");
965                                 }
966                                 return 0;
967                         }
968                 }
969                 break;
970         case ZKEY:      // undo
971                 if(G.qual & (LR_CTRLKEY|LR_COMMANDKEY)) { // all combos with ctrl/cammandkey are accepted
972                         if ELEM(G.qual, LR_CTRLKEY, LR_COMMANDKEY) BIF_undo();
973                         else BIF_redo(); // all combos with ctrl is redo
974                         return 0;
975                 }
976                 break; 
977         }
978         
979         return 1;
980 }
981
982 /* eof */