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