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