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