Bug fix #2411
[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(NULL);
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 #if 0
686 //#ifdef _WIN32 // FULLSCREEN
687                         if(event==DOWNARROWKEY){
688                                 if (G.qual==LR_ALTKEY)
689                                         mainwindow_toggle_fullscreen(0);
690                                 else if(G.qual==0)
691                                         CFRA-= 10;
692                         }
693 #else
694                         if((event==DOWNARROWKEY)&&(G.qual==0))
695                                 CFRA-= 10;
696 #endif
697                         else if((event==LEFTARROWKEY)&&(G.qual==0))
698                                 CFRA--;
699                         
700                         if(G.qual==LR_SHIFTKEY)
701                                 CFRA= SFRA;
702                         if(CFRA<1) CFRA=1;
703         
704                         update_for_newframe();
705                         return 0;
706                 }
707                 break;
708
709         case RIGHTARROWKEY:
710         case UPARROWKEY:
711                 if(textediting==0 && textspace==0) {
712
713 #if 0
714 //#ifdef _WIN32 // FULLSCREEN
715                         if(event==UPARROWKEY){ 
716                                 if(G.qual==LR_ALTKEY)
717                                         mainwindow_toggle_fullscreen(1);
718                                 else if(G.qual==0)
719                                         CFRA+= 10;
720                         }
721 #else
722                         if((event==UPARROWKEY)&&(G.qual==0))
723                                 CFRA+= 10;
724 #endif
725                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
726                                 CFRA++;
727
728                         if(G.qual==LR_SHIFTKEY)
729                                 CFRA= EFRA;
730                         
731                         update_for_newframe();
732                 }
733                 break;
734
735         case ESCKEY:
736                 sound_stop_all_sounds();
737                 break;
738         case TABKEY:
739                 if(G.qual==0) {
740                         if(textspace==0) {
741                                 if(curarea->spacetype==SPACE_IPO)
742                                         set_editflag_editipo();
743                                 else if(curarea->spacetype==SPACE_SEQ)
744                                         enter_meta();
745                                 else if(G.vd) {
746                                         /* also when Alt-E */
747                                         if(G.obedit==NULL) {
748                                                 enter_editmode();
749                                                 if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
750                                         }
751                                         else
752                                                 exit_editmode(2); // freedata, and undo
753                                 }
754                                 return 0;
755                         }
756                 }
757                 else if(G.qual==LR_CTRLKEY){
758                         Object *ob= OBACT;
759                         if(ob) {
760                                 if(ob->type==OB_ARMATURE) {
761                                         if(G.obpose) exit_posemode(1);
762                                         else enter_posemode();
763                                 }
764                                 else if(ob->type==OB_MESH) {
765                                         if(ob==G.obedit) EM_selectmode_menu();
766                                 }
767                         }
768                 }
769                 else if(G.qual==LR_SHIFTKEY) {
770                         if(G.obedit)
771                                 exit_editmode(2); // freedata, and undo
772                         if(G.f & G_FACESELECT)
773                                 set_faceselect();
774                         if(G.f & G_VERTEXPAINT)
775                                 set_vpaint();
776                         if(G.f & G_TEXTUREPAINT) {
777                                 G.f &= ~G_TEXTUREPAINT;
778                                 allqueue(REDRAWVIEW3D, 0);
779                                 allqueue(REDRAWBUTSEDIT, 0);
780                         }
781                         if(G.f & G_WEIGHTPAINT)
782                                 set_wpaint();
783                         if(G.obpose)
784                                 exit_posemode(1);
785                 }
786                 break;
787
788         case BACKSPACEKEY:
789                 break;
790
791         case AKEY:
792                 if(textediting==0 && textspace==0) {
793                         if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)){
794                                 play_anim(1);
795                                 return 0;
796                         }
797                         else if(G.qual==LR_ALTKEY) {
798                                 play_anim(0);
799                                 return 0;
800                         }
801                 }
802                 break;
803         case EKEY:
804                 if(G.qual==LR_ALTKEY) {
805                         if(G.vd && textspace==0) {
806                                 if(G.obedit==0) {
807                                         enter_editmode();
808                                         BIF_undo_push("Original");
809                                 }
810                                 else
811                                         exit_editmode(2); // freedata, and undo
812                                 return 0;
813                         }                       
814                 }
815                 break;
816         case IKEY:
817                 if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
818                         if(G.qual==0) {
819                                 common_insertkey();
820                                 return 0;
821                         }
822                 }
823                 break;
824         case JKEY:
825                 if(textediting==0 && textspace==0) {
826                         if(R.rectot && G.qual==0) {
827                                 BIF_swap_render_rects();
828                                 return 0;
829                         }
830                 }
831                 break;
832
833         case NKEY:
834                 if(textediting==0 && textspace==0) {
835                         if(G.qual & LR_CTRLKEY);
836                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
837                                 if(curarea->spacetype==SPACE_VIEW3D);           // is new panel, in view3d queue
838                                 else if(curarea->spacetype==SPACE_IPO);                 // is new panel, in ipo queue
839                                 else if(curarea->spacetype==SPACE_IMAGE);                       // is new panel, in ipo queue
840                                 else if(curarea->spacetype==SPACE_ACTION);                      // is own queue
841                                 else if(curarea->spacetype==SPACE_NLA);                 // is new panel
842                                 else if(curarea->spacetype==SPACE_SEQ);                 // is new panel
843                                 else {
844                                         clever_numbuts();
845                                         return 0;
846                                 }
847                         }
848                 }
849                 break;
850                 
851         case OKEY:
852                 if(textediting==0) {
853                         if(G.qual==LR_CTRLKEY) {
854                                 /* There seem to be crashes here sometimes.... String
855                                  * bound overwrites? I changed dir and str sizes,
856                                  * let's see if this reoccurs. */
857                                 sprintf(str, "Open file: %s", G.sce);
858                         
859                                 if(okee(str)) {
860                                         strcpy(dir, G.sce);
861                                         BIF_read_file(dir);
862                                 }
863                                 return 0;
864                         }
865                 }
866                 break;
867                 
868         case SKEY:
869                 if(G.obpose==0 && G.obedit==0) {
870                         if(G.qual==LR_CTRLKEY) {
871                                 strcpy(dir, G.sce);
872                                 if (untitled(dir)) {
873                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
874                                 } else {
875                                         BIF_write_file(dir);
876                                         free_filesel_spec(dir);
877                                 }
878                                 return 0;
879                         }
880                 }
881                 break;
882         
883         case TKEY:
884                 if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
885                         int a;
886                         double delta, stime;
887
888                         waitcursor(1);
889                         
890                         stime= PIL_check_seconds_timer();
891                         for(a=0; a<100000; a++) {
892                                 scrarea_do_windraw(curarea);
893
894                                 delta= PIL_check_seconds_timer()-stime;
895                                 if (delta>5.0) break;
896                         }
897                         
898                         waitcursor(0);
899                         notice("FPS: %f (%d iterations)", a/delta, a);
900                         return 0;
901                 }
902                 else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
903                         int a;
904                         int event= pupmenu("10 Timer%t|draw|draw+swap|displist|undo");
905                         if(event>0) {
906                                 double stime= PIL_check_seconds_timer();
907                                 char tmpstr[128];
908                                 int time;
909
910                                 waitcursor(1);
911                                 
912                                 for(a=0; a<10; a++) {
913                                         if (event==1) {
914                                                 scrarea_do_windraw(curarea);
915                                         } else if (event==2) {
916                                                 scrarea_do_windraw(curarea);
917                                                 screen_swapbuffers();
918                                         } else if (event==3) {
919                                                 if (OBACT) {
920                                                         makeDispList(OBACT);
921                                                 }
922                                         }
923                                         else if(event==4) {
924                                                 BKE_write_undo("10 timer");
925                                         }
926                                 }
927                         
928                                 time= (PIL_check_seconds_timer()-stime)*1000;
929                                 
930                                 if(event==1) sprintf(tmpstr, "draw %%t|%d ms", time);
931                                 if(event==2) sprintf(tmpstr, "d+sw %%t|%d ms", time);
932                                 if(event==3) sprintf(tmpstr, "displist %%t|%d ms", time);
933                                 if(event==4) sprintf(tmpstr, "undo %%t|%d ms", time);
934                         
935                                 waitcursor(0);
936                                 pupmenu(tmpstr);
937
938                         }
939                         return 0;
940                 }
941                 break;
942                                 
943         case UKEY:
944                 if(textediting==0) {
945                         if(G.qual==LR_CTRLKEY) {
946                                 if(okee("Save user defaults")) {
947                                         BIF_write_homefile();
948                                 }
949                                 return 0;
950                         }
951                         else if(G.qual==LR_ALTKEY) {
952                                 if(curarea->spacetype!=SPACE_TEXT) {
953                                         BIF_undo_menu();
954                                         return 0;
955                                 }
956                         }
957                 }
958                 break;
959                 
960         case WKEY:
961                 if(textediting==0) {
962                         if(G.qual==LR_CTRLKEY) {
963                                 strcpy(dir, G.sce);
964                                 if (untitled(dir)) {
965                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
966                                 } else {
967                                         BIF_write_file(dir);
968                                         free_filesel_spec(dir);
969                                 }
970                                 return 0;
971                         }
972                         else if(G.qual==LR_ALTKEY) {
973                                 write_videoscape_fs();
974                         }
975                 }
976                 break;
977                 
978         case XKEY:
979                 if(textspace==0) {
980                         if(G.qual==LR_CTRLKEY) {
981                                 if(okee("Erase all")) {
982                                         if( BIF_read_homefile()==0) error("No file ~/.B.blend");
983                                 }
984                                 return 0;
985                         }
986                 }
987                 break;
988         case YKEY:      // redo alternative
989                 if(textspace==0) {
990                         if(G.qual==LR_CTRLKEY) {
991                                 BIF_redo(); 
992                                 return 0;
993                         }
994                 }
995                 break;
996         case ZKEY:      // undo
997                 if(textspace==0) {
998                         if(G.qual & (LR_CTRLKEY|LR_COMMANDKEY)) { // all combos with ctrl/commandkey are accepted
999                                 if ELEM(G.qual, LR_CTRLKEY, LR_COMMANDKEY) BIF_undo();
1000                                 else BIF_redo(); // all combos with ctrl is redo
1001                                 return 0;
1002                         }
1003                 }
1004                 break; 
1005         }
1006         
1007         return 1;
1008 }
1009
1010 /* eof */