Initial commit for new text object.
[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 #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                         do_all_ipos();
412                         do_all_keys();
413                         do_all_actions(NULL);
414                         do_all_ikas();
415                         test_all_displists();
416                         
417                         reset_slowparents();    /* editobject.c */
418                 }
419                 else if(G.vd->persp<2) {
420                         if(event==PAD4 || event==PAD6) {
421                                 /* z-axis */
422                                 phi= (float)(M_PI/24.0);
423                                 if(event==PAD6) phi= -phi;
424                                 si= (float)sin(phi);
425                                 q1[0]= (float)cos(phi);
426                                 q1[1]= q1[2]= 0.0;
427                                 q1[3]= si;
428                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
429                                 G.vd->view= 0;
430                         }
431                         if(event==PAD2 || event==PAD8) {
432                                 
433                                 /* horizontal axis */
434                                 VECCOPY(q1+1, G.vd->viewinv[0]);
435                                 
436                                 Normalise(q1+1);
437                                 phi= (float)(M_PI/24.0);
438                                 if(event==PAD2) phi= -phi;
439                                 si= (float)sin(phi);
440                                 q1[0]= (float)cos(phi);
441                                 q1[1]*= si;
442                                 q1[2]*= si;
443                                 q1[3]*= si;
444                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
445                                 G.vd->view= 0;
446                         }
447                 }
448
449                 if(G.vd->persp<2) perspo= G.vd->persp;
450         }
451         scrarea_queue_redraw(curarea);
452 }
453
454 int untitled(char * name)
455 {
456         if (G.save_over == 0 ) {
457                 char * c= BLI_last_slash(name);
458                 
459                 if (c)
460                         strcpy(&c[1], "untitled.blend");
461                 else
462                         strcpy(name, "untitled.blend");
463                         
464                 return(TRUE);
465         }
466         
467         return(FALSE);
468 }
469
470 int save_image_filesel_str(char *str)
471 {
472         switch(G.scene->r.imtype) {
473         case R_PNG:
474                 strcpy(str, "Save PNG"); return 1;
475         case R_BMP:
476                 strcpy(str, "Save BMP"); return 1;
477         case R_TARGA:
478                 strcpy(str, "Save Targa"); return 1;
479         case R_RAWTGA:
480                 strcpy(str, "Save Raw Targa"); return 1;
481         case R_IRIS:
482                 strcpy(str, "Save IRIS"); return 1;
483         case R_IRIZ:
484                 strcpy(str, "Save IRIS"); return 1;
485         case R_HAMX:
486                 strcpy(str, "Save HAMX"); return 1;
487         case R_FTYPE:
488                 strcpy(str, "Save Ftype"); return 1;
489         case R_JPEG90:
490                 strcpy(str, "Save JPEG"); return 1;
491         default:
492                 strcpy(str, "Save Image"); return 0;
493         }       
494 }
495
496 void BIF_save_rendered_image(void)
497 {
498         if(!R.rectot) {
499                 error("No image rendered");
500         } else {
501                 char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
502
503                 if(G.ima[0]==0) {
504                         strcpy(dir, G.sce);
505                         BLI_splitdirstring(dir, str);
506                         strcpy(G.ima, dir);
507                 }
508                 
509                 R.r.imtype= G.scene->r.imtype;
510                 R.r.quality= G.scene->r.quality;
511                 R.r.planes= G.scene->r.planes;
512         
513                 if (!save_image_filesel_str(str)) {
514                         error("Select an image type in DisplayButtons(F10)");
515                 } else {
516                         activate_fileselect(FILE_SPECIAL, str, G.ima, write_imag);
517                 }
518         }
519 }
520
521 int blenderqread(unsigned short event, short val)
522 {
523         /* here do the general keys handling (not screen/window/space) */
524         /* return 0: do not pass on to the other queues */
525         extern int textediting;
526         ScrArea *sa;
527         Object *ob;
528         int textspace=0;
529         /* Changed str and dir size to 160, to make sure there is enough
530          * space for filenames. */
531         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
532         
533         if(val==0) return 1;
534         if(event==MOUSEY || event==MOUSEX) return 1;
535         if (G.flags & G_FLAGS_AUTOPLAY) return 1;
536
537         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
538         else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
539
540         switch(event) {
541
542         case F1KEY:
543                 if(G.qual==0) {
544                         /* this exception because of the '?' button */
545                         if(curarea->spacetype==SPACE_INFO) {
546                                 sa= closest_bigger_area();
547                                 areawinset(sa->win);
548                         }
549                         
550                         activate_fileselect(FILE_BLENDER, "Open File", G.sce, BIF_read_file);
551                         return 0;
552                 }
553                 else if(G.qual==LR_SHIFTKEY) {
554                         activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
555                         return 0;
556                 }
557                 break;
558         case F2KEY:
559                 if(G.qual==0) {
560                         strcpy(dir, G.sce);
561                         untitled(dir);
562                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
563                         return 0;
564                 }
565                 else if(G.qual==LR_CTRLKEY) {
566                         write_vrml_fs();
567                         return 0;
568                 }
569                 else if(G.qual==LR_SHIFTKEY) {
570                         write_dxf_fs();
571                         return 0;
572                 }
573                 break;
574         case F3KEY:
575                 if(G.qual==0) {
576                         BIF_save_rendered_image();
577                         return 0;
578                 }
579                 else if(G.qual & LR_CTRLKEY) {
580                         /* all alt+ctrl+shift combos are needed here... */
581                         BIF_screendump(0);
582                 }
583                 break;
584         case F4KEY:
585                 if(G.qual==LR_SHIFTKEY) {
586
587                         memset(str, 0, 16);
588                         ob= OBACT;
589                         if(ob) strcpy(str, ob->id.name);
590
591                         activate_fileselect(FILE_MAIN, "Data Select", str, 0);
592                         return 0;
593                 }
594                 else if(G.qual==0) {
595                         extern_set_butspace(event);
596                 }
597                 break;
598         case F5KEY:
599                 if(G.qual==LR_SHIFTKEY) {
600                         newspace(curarea, SPACE_VIEW3D);
601                         return 0;
602                 }
603                 else if(G.qual==0) {
604                         extern_set_butspace(event);
605                 }
606                 break;
607         case F6KEY:
608                 if(G.qual==LR_SHIFTKEY) {
609                         newspace(curarea, SPACE_IPO);
610                         return 0;
611                 }
612                 else if(G.qual==0) {
613                         extern_set_butspace(event);
614                 }
615                 break;
616         case F7KEY:
617                 if(G.qual==LR_SHIFTKEY) {
618                         newspace(curarea, SPACE_BUTS);
619                         return 0;
620                 }
621                 else if(G.qual==0) {
622                         extern_set_butspace(event);
623                 }
624                 break;
625         case F8KEY:
626                 if(G.qual==LR_SHIFTKEY) {
627                         newspace(curarea, SPACE_SEQ);
628                         return 0;
629                 }
630                 else if(G.qual==0) {
631                         extern_set_butspace(event);
632                 }
633                 break;
634         case F9KEY:
635                 if(G.qual==LR_SHIFTKEY) {
636                         newspace(curarea, SPACE_OOPS);
637                         return 0;
638                 }
639                 else if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)) {
640                         newspace(curarea, SPACE_OOPS+256);
641                         return 0;
642                 }
643                 else if(G.qual==0) {
644                         extern_set_butspace(event);
645                 }
646                 break;
647         case F10KEY:
648                 if(G.qual==LR_SHIFTKEY) {
649                         newspace(curarea, SPACE_IMAGE);
650                         return 0;
651                 }
652                 else if(G.qual==0) {
653                         extern_set_butspace(event);
654                 }
655                 break;
656         case F11KEY:
657                 if(G.qual==LR_SHIFTKEY) {
658                         newspace(curarea, SPACE_TEXT);
659                         return 0;
660                 }
661                 else if(G.qual==0) {
662                         BIF_toggle_render_display();
663                         return 0;
664                 }
665                 break;
666         case F12KEY:
667                 if(G.qual==LR_SHIFTKEY) {
668                         newspace(curarea, SPACE_ACTION);
669                         return 0;
670                 }
671                 else if (G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
672                         newspace(curarea, SPACE_NLA);
673                         return 0;
674                 }
675                 else {
676                         /* ctrl/alt + f12 should render too, for some macs have f12 assigned to cd eject */
677                         BIF_do_render(0);
678                 }
679                 return 0;
680                 break;
681         
682         case LEFTARROWKEY:
683         case DOWNARROWKEY:
684                 if(textediting==0 && textspace==0) {
685
686 #if 0
687 //#ifdef _WIN32 // FULLSCREEN
688                         if(event==DOWNARROWKEY){
689                                 if (G.qual==LR_ALTKEY)
690                                         mainwindow_toggle_fullscreen(0);
691                                 else if(G.qual==0)
692                                         CFRA-= 10;
693                         }
694 #else
695                         if((event==DOWNARROWKEY)&&(G.qual==0))
696                                 CFRA-= 10;
697 #endif
698                         else if((event==LEFTARROWKEY)&&(G.qual==0))
699                                 CFRA--;
700                         
701                         if(G.qual==LR_SHIFTKEY)
702                                 CFRA= SFRA;
703                         if(CFRA<1) CFRA=1;
704         
705                         update_for_newframe();
706                         return 0;
707                 }
708                 break;
709
710         case RIGHTARROWKEY:
711         case UPARROWKEY:
712                 if(textediting==0 && textspace==0) {
713
714 #if 0
715 //#ifdef _WIN32 // FULLSCREEN
716                         if(event==UPARROWKEY){ 
717                                 if(G.qual==LR_ALTKEY)
718                                         mainwindow_toggle_fullscreen(1);
719                                 else if(G.qual==0)
720                                         CFRA+= 10;
721                         }
722 #else
723                         if((event==UPARROWKEY)&&(G.qual==0))
724                                 CFRA+= 10;
725 #endif
726                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
727                                 CFRA++;
728
729                         if(G.qual==LR_SHIFTKEY)
730                                 CFRA= EFRA;
731                         
732                         update_for_newframe();
733                 }
734                 break;
735
736         case ESCKEY:
737                 sound_stop_all_sounds();        // whats this?
738                 
739                 /* stop playback on ESC always */
740                 rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
741                 audiostream_stop();
742                 allqueue(REDRAWALL, 0);
743                 
744                 break;
745         case TABKEY:
746                 if(G.qual==0) {
747                         if(textspace==0) {
748                                 if(curarea->spacetype==SPACE_IPO)
749                                         set_editflag_editipo();
750                                 else if(curarea->spacetype==SPACE_SEQ)
751                                         enter_meta();
752                                 else if(G.vd) {
753                                         /* also when Alt-E */
754                                         if(G.obedit==NULL) {
755                                                 enter_editmode();
756                                                 if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
757                                         }
758                                         else
759                                                 exit_editmode(2); // freedata, and undo
760                                 }
761                                 return 0;
762                         }
763                 }
764                 else if(G.qual==LR_CTRLKEY){
765                         Object *ob= OBACT;
766                         if(ob) {
767                                 if(ob->type==OB_ARMATURE) {
768                                         if(G.obpose) exit_posemode(1);
769                                         else enter_posemode();
770                                 }
771                                 else if(ob->type==OB_MESH) {
772                                         if(ob==G.obedit) EM_selectmode_menu();
773                                 }
774                         }
775                 }
776                 else if(G.qual==LR_SHIFTKEY) {
777                         if(G.obedit)
778                                 exit_editmode(2); // freedata, and undo
779                         if(G.f & G_FACESELECT)
780                                 set_faceselect();
781                         if(G.f & G_VERTEXPAINT)
782                                 set_vpaint();
783                         if(G.f & G_TEXTUREPAINT) {
784                                 G.f &= ~G_TEXTUREPAINT;
785                                 allqueue(REDRAWVIEW3D, 0);
786                                 allqueue(REDRAWBUTSEDIT, 0);
787                         }
788                         if(G.f & G_WEIGHTPAINT)
789                                 set_wpaint();
790                         if(G.obpose)
791                                 exit_posemode(1);
792                 }
793                 break;
794
795         case BACKSPACEKEY:
796                 break;
797
798         case AKEY:
799                 if(textediting==0 && textspace==0) {
800                         if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)){
801                                 play_anim(1);
802                                 return 0;
803                         }
804                         else if(G.qual==LR_ALTKEY) {
805                                 play_anim(0);
806                                 return 0;
807                         }
808                 }
809                 break;
810         case EKEY:
811                 if(G.qual==LR_ALTKEY) {
812                         if(G.vd && textspace==0) {
813                                 if(G.obedit==0) {
814                                         enter_editmode();
815                                         BIF_undo_push("Original");
816                                 }
817                                 else
818                                         exit_editmode(2); // freedata, and undo
819                                 return 0;
820                         }                       
821                 }
822                 break;
823         case IKEY:
824                 if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
825                         if(G.qual==0) {
826                                 common_insertkey();
827                                 return 0;
828                         }
829                 }
830                 break;
831         case JKEY:
832                 if(textediting==0 && textspace==0) {
833                         if(R.rectot && G.qual==0) {
834                                 BIF_swap_render_rects();
835                                 return 0;
836                         }
837                 }
838                 break;
839
840         case NKEY:
841                 if(textediting==0 && textspace==0) {
842                         if(G.qual & LR_CTRLKEY);
843                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
844                                 if(curarea->spacetype==SPACE_VIEW3D);           // is new panel, in view3d queue
845                                 else if(curarea->spacetype==SPACE_IPO);                 // is new panel, in ipo queue
846                                 else if(curarea->spacetype==SPACE_IMAGE);                       // is new panel, in ipo queue
847                                 else if(curarea->spacetype==SPACE_ACTION);                      // is own queue
848                                 else if(curarea->spacetype==SPACE_NLA);                 // is new panel
849                                 else if(curarea->spacetype==SPACE_SEQ);                 // is new panel
850                                 else {
851                                         clever_numbuts();
852                                         return 0;
853                                 }
854                         }
855                 }
856                 break;
857                 
858         case OKEY:
859                 if(textediting==0) {
860                         if(G.qual==LR_CTRLKEY) {
861                                 /* There seem to be crashes here sometimes.... String
862                                  * bound overwrites? I changed dir and str sizes,
863                                  * let's see if this reoccurs. */
864                                 sprintf(str, "Open file: %s", G.sce);
865                         
866                                 if(okee(str)) {
867                                         strcpy(dir, G.sce);
868                                         BIF_read_file(dir);
869                                 }
870                                 return 0;
871                         }
872                 }
873                 break;
874                 
875         case SKEY:
876                 if(G.obpose==0 && G.obedit==0) {
877                         if(G.qual==LR_CTRLKEY) {
878                                 strcpy(dir, G.sce);
879                                 if (untitled(dir)) {
880                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
881                                 } else {
882                                         BIF_write_file(dir);
883                                         free_filesel_spec(dir);
884                                 }
885                                 return 0;
886                         }
887                 }
888                 break;
889         
890         case TKEY:
891                 if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
892                         int a;
893                         double delta, stime;
894
895                         waitcursor(1);
896                         
897                         stime= PIL_check_seconds_timer();
898                         for(a=0; a<100000; a++) {
899                                 scrarea_do_windraw(curarea);
900
901                                 delta= PIL_check_seconds_timer()-stime;
902                                 if (delta>5.0) break;
903                         }
904                         
905                         waitcursor(0);
906                         notice("FPS: %f (%d iterations)", a/delta, a);
907                         return 0;
908                 }
909                 else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
910                         int a;
911                         int event= pupmenu("10 Timer%t|draw|draw+swap|displist|undo");
912                         if(event>0) {
913                                 double stime= PIL_check_seconds_timer();
914                                 char tmpstr[128];
915                                 int time;
916
917                                 waitcursor(1);
918                                 
919                                 for(a=0; a<10; a++) {
920                                         if (event==1) {
921                                                 scrarea_do_windraw(curarea);
922                                         } else if (event==2) {
923                                                 scrarea_do_windraw(curarea);
924                                                 screen_swapbuffers();
925                                         } else if (event==3) {
926                                                 if (OBACT) {
927                                                         makeDispList(OBACT);
928                                                 }
929                                         }
930                                         else if(event==4) {
931                                                 BKE_write_undo("10 timer");
932                                         }
933                                 }
934                         
935                                 time= (PIL_check_seconds_timer()-stime)*1000;
936                                 
937                                 if(event==1) sprintf(tmpstr, "draw %%t|%d ms", time);
938                                 if(event==2) sprintf(tmpstr, "d+sw %%t|%d ms", time);
939                                 if(event==3) sprintf(tmpstr, "displist %%t|%d ms", time);
940                                 if(event==4) sprintf(tmpstr, "undo %%t|%d ms", time);
941                         
942                                 waitcursor(0);
943                                 pupmenu(tmpstr);
944
945                         }
946                         return 0;
947                 }
948                 break;
949                                 
950         case UKEY:
951                 if(textediting==0) {
952                         if(G.qual==LR_CTRLKEY) {
953                                 if(okee("Save user defaults")) {
954                                         BIF_write_homefile();
955                                 }
956                                 return 0;
957                         }
958                         else if(G.qual==LR_ALTKEY) {
959                                 if(curarea->spacetype!=SPACE_TEXT) {
960                                         BIF_undo_menu();
961                                         return 0;
962                                 }
963                         }
964                 }
965                 break;
966                 
967         case WKEY:
968                 if(textediting==0) {
969                         if(G.qual==LR_CTRLKEY) {
970                                 strcpy(dir, G.sce);
971                                 if (untitled(dir)) {
972                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
973                                 } else {
974                                         BIF_write_file(dir);
975                                         free_filesel_spec(dir);
976                                 }
977                                 return 0;
978                         }
979                         else if(G.qual==LR_ALTKEY) {
980                                 write_videoscape_fs();
981                         }
982                 }
983                 break;
984                 
985         case XKEY:
986                 if(textspace==0 && textediting==0) {
987                         if(G.qual==LR_CTRLKEY) {
988                                 if(okee("Erase all")) {
989                                         strcpy(G.sce, BLI_gethome());
990                                         strcat(G.sce, "/untitled.blend");
991                                         BLI_clean(G.sce);
992                                         if( BIF_read_homefile()==0) error("No file ~/.B.blend");
993                                 }
994                                 return 0;
995                         }
996                 }
997                 break;
998         case YKEY:      // redo alternative
999                 if(textspace==0) {
1000                         if(G.qual==LR_CTRLKEY) {
1001                                 BIF_redo(); 
1002                                 return 0;
1003                         }
1004                 }
1005                 break;
1006         case ZKEY:      // undo
1007                 if(textspace==0) {
1008                         if(G.qual & (LR_CTRLKEY|LR_COMMANDKEY)) { // all combos with ctrl/commandkey are accepted
1009                                 if ELEM(G.qual, LR_CTRLKEY, LR_COMMANDKEY) BIF_undo();
1010                                 else BIF_redo(); // all combos with ctrl is redo
1011                                 return 0;
1012                         }
1013                 }
1014                 break; 
1015         }
1016         
1017         return 1;
1018 }
1019
1020 /* eof */