added win32 style ctrl keystrokes for cut/copy/paste/undo/redo
[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  * Algemene toetsen, bijzondere in de space.c
32  */
33
34 #include <string.h>
35 #include <math.h>
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
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 #include "BLI_editVert.h"
54
55 #include "DNA_object_types.h"
56 #include "DNA_screen_types.h"
57 #include "DNA_space_types.h"
58 #include "DNA_view3d_types.h"
59
60 #include "BKE_utildefines.h"
61 #include "BKE_global.h"
62 #include "BKE_anim.h"
63 #include "BKE_scene.h"
64 #include "BKE_ipo.h"
65 #include "BKE_action.h"
66 #include "BKE_ika.h"
67 #include "BKE_key.h"
68
69 #include "BIF_interface.h"
70 #include "BIF_screen.h"
71 #include "BIF_space.h"
72 #include "BIF_buttons.h"
73 #include "BIF_renderwin.h"
74 #include "BIF_toolbox.h"
75 #include "BIF_toets.h"
76 #include "BIF_editseq.h"
77 #include "BIF_editsound.h"
78 #include "BIF_poseobject.h"
79 #include "BIF_usiblender.h"
80
81 #include "BDR_vpaint.h"
82 #include "BDR_editobject.h"
83 #include "BDR_editface.h"
84
85 #include "BSE_filesel.h"        /* For activate_fileselect */
86 #include "BSE_drawview.h"       /* For play_anim */
87 #include "BSE_view.h"
88 #include "BSE_edit.h"
89 #include "BSE_editipo.h"
90 #include "BSE_headerbuttons.h"
91
92 #include "blendef.h"
93 #include "interface.h"
94 #include "render.h"
95 #include "blendertimer.h" /* timer functions */
96
97 #include "IMB_imbuf.h"
98 #include "IMB_imbuf_types.h"
99
100 #include "mydevice.h"
101
102 #include "BIF_poseobject.h"
103
104 /* only used in toets.c */
105 /* this function doesn't really belong here */
106 /* ripped from render module */
107 void schrijfplaatje(char *name);
108
109
110 void write_imag(char *name)
111 {
112         /* vanuit filesel */
113         char str[256];
114
115         strcpy(str, name);
116         BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
117
118         if(saveover(str)) {
119                 if(BLI_testextensie(str,".blend")) {
120                         error("Wrong filename");
121                         return;
122                 }
123                 waitcursor(1); /* from screen.c */
124                 schrijfplaatje(str);
125                 strcpy(G.ima, name);
126                 waitcursor(0);
127         }
128 }
129
130 /* ripped from render module */
131 /*  void schrijfplaatje(char *name); */
132
133
134 /* From matrix.h: it's really a [4][4]! */
135 /* originally in initrender... maybe add fileControl thingy? */
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         /* Staat RGBA aan? Zo ja: gebruik alphakanaal voor kleur 0 */
143         IMB_alpha_to_col0(FALSE);
144
145         if(R.r.planes == 32) {
146                 /* alles met minder dan 50 % alpha -> col 0 */
147                 if(R.r.alphamode == R_ALPHAKEY) IMB_alpha_to_col0(2);
148                 /* uitsluitend met 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
177                 if(R.r.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
178
179                 if(R.r.imtype== R_IRIS) {
180                         ibuf->ftype= IMAGIC;
181                 }
182                 else if(R.r.imtype==R_IRIZ) {
183                         ibuf->ftype= IMAGIC;
184                         if (ibuf->zbuf == 0) {
185                                 if (R.rectz) {
186                                         ibuf->zbuf = (int *)R.rectz;
187                                 }
188                                 else printf("no zbuf\n");
189                         }
190                 }
191                 else if(R.r.imtype==R_PNG) {
192                         ibuf->ftype= PNG;
193                 }
194                 else if((R.r.imtype==R_TARGA) || (R.r.imtype==R_PNG)) {
195                         ibuf->ftype= TGA;
196                 }
197                 else if(R.r.imtype==R_RAWTGA) {
198                         ibuf->ftype= RAWTGA;
199                 }
200                 else if(R.r.imtype==R_HAMX) {
201                         /* kopie maken */
202                         temprect= MEM_dupallocN(R.rectot);
203                         ibuf->ftype= AN_hamx;
204                 }
205                 else if(ELEM5(R.r.imtype, R_MOVIE, R_AVICODEC, R_AVIRAW, R_AVIJPEG, R_JPEG90)) {
206                         if(R.r.quality < 10) R.r.quality= 90;
207
208                         if(R.r.mode & R_FIELDS) ibuf->ftype= JPG_VID|R.r.quality;
209                         else ibuf->ftype= JPG|R.r.quality;
210                 }
211         
212                 RE_make_existing_file(name);
213
214                 if(IMB_saveiff(ibuf, name, IB_rect | IB_zbuf)==0) {
215                         perror(name);
216                         G.afbreek= 1;
217                 }
218
219                 IMB_freeImBuf(ibuf);
220
221                 if (R.r.imtype==R_HAMX) {
222                         MEM_freeN(R.rectot);
223                         R.rectot= temprect;
224                 }
225         }
226         else {
227                 G.afbreek= 1;
228         }
229 }
230
231
232
233 /* ------------------------------------------------------------------------- */
234
235 static int is_an_active_object(void *ob) {
236         Base *base;
237         
238         for (base= FIRSTBASE; base; base= base->next)
239                 if (base->object == ob)
240                         return 1;
241         
242         return 0;
243 }
244
245 void persptoetsen(unsigned short event)
246 {
247         static Object *oldcamera=0;
248         float phi, si, q1[4], vec[3];
249         static int perspo=1;
250         
251         if(event==PADENTER) {
252                 if (G.qual == LR_SHIFTKEY) {
253                         view3d_set_1_to_1_viewborder(G.vd);
254                 } else {
255                         if (G.vd->persp==2) {
256                                 G.vd->camzoom= 0.0;
257                         } else {
258                                 G.vd->dist= 10.0;
259                         }
260                 }
261         }
262         else if((G.qual & (LR_SHIFTKEY | LR_CTRLKEY)) && (event != PAD0)) {
263                 if(event==PAD0) {
264                         /* G.vd->persp= 3; */
265                 }
266                 else if(event==PAD7) {
267                         G.vd->viewquat[0]= 0.0;
268                         G.vd->viewquat[1]= -1.0;
269                         G.vd->viewquat[2]= 0.0;
270                         G.vd->viewquat[3]= 0.0;
271                         G.vd->view= 7;
272                         if(G.vd->persp>=2) G.vd->persp= perspo;
273                 }
274                 else if(event==PAD1) {
275                         G.vd->viewquat[0]= 0.0;
276                         G.vd->viewquat[1]= 0.0;
277                         G.vd->viewquat[2]= (float)-cos(M_PI/4.0);
278                         G.vd->viewquat[3]= (float)-cos(M_PI/4.0);
279                         G.vd->view=1;
280                         if(G.vd->persp>=2) G.vd->persp= perspo;
281                 }
282                 else if(event==PAD3) {
283                         G.vd->viewquat[0]= 0.5;
284                         G.vd->viewquat[1]= -0.5;
285                         G.vd->viewquat[2]= 0.5;
286                         G.vd->viewquat[3]= 0.5;
287                         G.vd->view=3;
288                         if(G.vd->persp>=2) G.vd->persp= perspo;
289                 }
290                 else if(event==PADMINUS) {
291                         /* deze min en max staan ook in viewmove() */
292                         if(G.vd->persp==2) {
293                                         G.vd->camzoom-= 10;
294                                         if(G.vd->camzoom<-30) G.vd->camzoom= -30;
295                                 }
296                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2;
297                 }
298                 else if(event==PADPLUSKEY) {
299                         if(G.vd->persp==2) {
300                                         G.vd->camzoom+= 10;
301                                         if(G.vd->camzoom>300) G.vd->camzoom= 300;
302                         }
303                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333;
304                 }
305                 else {
306
307                         initgrabz(0.0, 0.0, 0.0);
308                         
309                         if(event==PAD6) window_to_3d(vec, -32, 0);
310                         else if(event==PAD4) window_to_3d(vec, 32, 0);
311                         else if(event==PAD8) window_to_3d(vec, 0, -25);
312                         else if(event==PAD2) window_to_3d(vec, 0, 25);
313                         G.vd->ofs[0]+= vec[0];
314                         G.vd->ofs[1]+= vec[1];
315                         G.vd->ofs[2]+= vec[2];
316                 }
317         }
318         else {
319
320                 if(event==PAD7) {
321                         G.vd->viewquat[0]= 1.0;
322                         G.vd->viewquat[1]= 0.0;
323                         G.vd->viewquat[2]= 0.0;
324                         G.vd->viewquat[3]= 0.0;
325                         G.vd->view=7;
326                         if(G.vd->persp>=2) G.vd->persp= perspo;
327                 }
328                 else if(event==PAD1) {
329                         G.vd->viewquat[0]= (float)cos(M_PI/4.0);
330                         G.vd->viewquat[1]= (float)-sin(M_PI/4.0);
331                         G.vd->viewquat[2]= 0.0;
332                         G.vd->viewquat[3]= 0.0;
333                         G.vd->view=1;
334                         if(G.vd->persp>=2) G.vd->persp= perspo;
335                 }
336                 else if(event==PAD3) {
337                         G.vd->viewquat[0]= 0.5;
338                         G.vd->viewquat[1]= -0.5;
339                         G.vd->viewquat[2]= -0.5;
340                         G.vd->viewquat[3]= -0.5;
341                         G.vd->view=3;
342                         if(G.vd->persp>=2) G.vd->persp= perspo;
343                 }
344                 else if(event==PADMINUS) {
345                         /* deze min en max staan ook in viewmove() */
346                         if(G.vd->persp==2) {
347                                 G.vd->camzoom= MAX2(-30, G.vd->camzoom-5);
348                         }
349                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2;
350                 }
351                 else if(event==PADPLUSKEY) {
352                         if(G.vd->persp==2) {
353                                 G.vd->camzoom= MIN2(300, G.vd->camzoom+5);
354                         }
355                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333;
356                 }
357                 else if(event==PAD5) {
358                         if(G.vd->persp==1) G.vd->persp=0;
359                         else G.vd->persp=1;
360                 }
361                 else if(event==PAD0) {
362                         if(G.qual & LR_ALTKEY) {
363                                 if(oldcamera && is_an_active_object(oldcamera)) {
364                                         G.vd->camera= oldcamera;
365                                 }
366                                 
367                                 handle_view3d_lock();
368                         }
369                         else if(BASACT) {
370                                 if(G.qual & LR_CTRLKEY) {
371                                         if(G.vd->camera != OBACT) {
372                                                 if(G.vd->camera && G.vd->camera->type==OB_CAMERA)
373                                                         oldcamera= G.vd->camera;
374                                                 
375                                                 G.vd->camera= OBACT;
376                                                 handle_view3d_lock();
377                                         }
378                                 }
379                                 else if(G.vd->camera==0 && OBACT->type==OB_CAMERA) {
380                                         G.vd->camera= OBACT;
381                                         handle_view3d_lock();
382                                 }
383                         }
384                         if(G.vd->camera==0) {
385                                 G.vd->camera= scene_find_camera(G.scene);
386                                 handle_view3d_lock();
387                         }
388                         
389                         if(G.vd->camera) {
390                                 G.vd->persp= 2;
391                                 G.vd->view= 0;
392                         }
393                         
394                 }
395                 else if(event==PAD9) {
396                         countall();
397                         do_all_ipos();
398                         do_all_keys();
399                         do_all_actions();
400                         do_all_ikas();
401
402                         reset_slowparents();    /* editobject.c */
403                 }
404                 else if(G.vd->persp<2) {
405                         if(event==PAD4 || event==PAD6) {
406                                 /* z-as */
407                                 phi= (float)(M_PI/24.0);
408                                 if(event==PAD6) phi= -phi;
409                                 si= (float)sin(phi);
410                                 q1[0]= (float)cos(phi);
411                                 q1[1]= q1[2]= 0.0;
412                                 q1[3]= si;
413                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
414                                 G.vd->view= 0;
415                         }
416                         if(event==PAD2 || event==PAD8) {
417                                 
418                                 /* liggende as */
419                                 VECCOPY(q1+1, G.vd->viewinv[0]);
420                                 
421                                 Normalise(q1+1);
422                                 phi= (float)(M_PI/24.0);
423                                 if(event==PAD2) phi= -phi;
424                                 si= (float)sin(phi);
425                                 q1[0]= (float)cos(phi);
426                                 q1[1]*= si;
427                                 q1[2]*= si;
428                                 q1[3]*= si;
429                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
430                                 G.vd->view= 0;
431                         }
432                 }
433
434                 if(G.vd->persp<2) perspo= G.vd->persp;
435         }
436         scrarea_queue_redraw(curarea);
437 }
438
439 int untitled(char * name)
440 {
441         if (G.save_over == 0 ) {
442                 char * c= BLI_last_slash(name);
443                 
444                 if (c)
445                         strcpy(&c[1], "untitled.blend");
446                 else
447                         strcpy(name, "untitled.blend");
448                         
449                 return(TRUE);
450         }
451         
452         return(FALSE);
453 }
454
455 int save_image_filesel_str(char *str)
456 {
457         switch(G.scene->r.imtype) {
458         case R_PNG:
459                 strcpy(str, "SAVE PNG"); return 1;
460         case R_TARGA:
461                 strcpy(str, "SAVE TARGA"); return 1;
462         case R_RAWTGA:
463                 strcpy(str, "SAVE RAW TARGA"); return 1;
464         case R_IRIS:
465                 strcpy(str, "SAVE IRIS"); return 1;
466         case R_IRIZ:
467                 strcpy(str, "SAVE IRIS"); return 1;
468         case R_HAMX:
469                 strcpy(str, "SAVE HAMX"); return 1;
470         case R_FTYPE:
471                 strcpy(str, "SAVE FTYPE"); return 1;
472         case R_JPEG90:
473                 strcpy(str, "SAVE JPEG"); return 1;
474         default:
475                 strcpy(str, "SAVE IMAGE"); return 0;
476         }       
477 }
478
479 void BIF_save_rendered_image(void)
480 {
481         if(!R.rectot) {
482                 error("No image rendered");
483         } else {
484                 char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
485
486                 if(G.ima[0]==0) {
487                         strcpy(dir, G.sce);
488                         BLI_splitdirstring(dir, str);
489                         strcpy(G.ima, dir);
490                 }
491                 
492                 R.r.imtype= G.scene->r.imtype;
493                 R.r.quality= G.scene->r.quality;
494                 R.r.planes= G.scene->r.planes;
495         
496                 if (!save_image_filesel_str(str)) {
497                         error("Select an image type in DisplayButtons(F10)");
498                 } else {
499                         activate_fileselect(FILE_SPECIAL, str, G.ima, write_imag);
500                 }
501         }
502 }
503
504 int blenderqread(unsigned short event, short val)
505 {
506         /* hier alle algemene toetsafhandelingen (niet screen/window/space) */
507         /* return 0: niet aan andere queue's doorgeven */
508 /*      extern char videosc_dir[]; */
509         extern int textediting;
510         ScrArea *sa;
511         Object *ob;
512         int textspace=0;
513         /* Changed str and dir size to 160, to make sure there is enough
514          * space for filenames. */
515         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
516         
517         if(val==0) return 1;
518         if(event==MOUSEY || event==MOUSEX) return 1;
519         if (G.flags & G_FLAGS_AUTOPLAY) return 1;
520
521         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
522
523         switch(event) {
524
525         case F1KEY:
526                 if(G.qual==0) {
527                         /* this exception because of the '?' button */
528                         if(curarea->spacetype==SPACE_INFO) {
529                                 sa= closest_bigger_area();
530                                 areawinset(sa->win);
531                         }
532                         
533                         activate_fileselect(FILE_BLENDER, "LOAD FILE", G.sce, BIF_read_file);
534                         return 0;
535                 }
536                 else if(G.qual & LR_SHIFTKEY) {
537                         activate_fileselect(FILE_LOADLIB, "LOAD LIBRARY", G.lib, 0);
538                         return 0;
539                 }
540                 break;
541         case F2KEY:
542                 if(G.qual==0) {
543                         strcpy(dir, G.sce);
544                         untitled(dir);
545                         activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
546                         return 0;
547                 }
548                 else if(G.qual & LR_CTRLKEY) {
549                         write_vrml_fs();
550                         return 0;
551                 }
552                 else if(G.qual & LR_SHIFTKEY) {
553                         write_dxf_fs();
554                         return 0;
555                 }
556                 break;
557         case F3KEY:
558                 if(G.qual==0) {
559                         BIF_save_rendered_image();
560                         return 0;
561                 }
562                 else if(G.qual & LR_CTRLKEY) {
563                         BIF_screendump();
564                 }
565                 break;
566         case F4KEY:
567                 if(G.qual & LR_SHIFTKEY) {
568
569                         memset(str, 0, 16);
570                         ob= OBACT;
571                         if(ob) strcpy(str, ob->id.name);
572
573                         activate_fileselect(FILE_MAIN, "DATA SELECT", str, 0);
574                         return 0;
575                 }
576                 else extern_set_butspace(event);
577                 
578                 break;
579         case F5KEY:
580                 if(G.qual & LR_SHIFTKEY) {
581                         newspace(curarea, SPACE_VIEW3D);
582                         return 0;
583                 }
584                 else extern_set_butspace(event);
585                 break;
586         case F6KEY:
587                 if(G.qual & LR_SHIFTKEY) {
588                         newspace(curarea, SPACE_IPO);
589                         return 0;
590                 }
591                 else extern_set_butspace(event);
592                 break;
593         case F7KEY:
594                 if(G.qual & LR_SHIFTKEY) {
595                         newspace(curarea, SPACE_BUTS);
596                         return 0;
597                 }
598                 else extern_set_butspace(event);
599                 break;
600         case F8KEY:
601                 if(G.qual & LR_SHIFTKEY) {
602                         newspace(curarea, SPACE_SEQ);
603                         return 0;
604                 }
605                 else extern_set_butspace(event);
606                 break;
607         case F9KEY:
608                 if(G.qual & LR_SHIFTKEY) {
609                         newspace(curarea, SPACE_OOPS);
610                         return 0;
611                 }
612                 else extern_set_butspace(event);
613                 break;
614         case F10KEY:
615                 if(G.qual & LR_SHIFTKEY) {
616                         newspace(curarea, SPACE_IMAGE);
617                         return 0;
618                 }
619                 else extern_set_butspace(event);
620                 break;
621         case F11KEY:
622                 if(G.qual & LR_SHIFTKEY) {
623                         newspace(curarea, SPACE_TEXT);
624                         return 0;
625                 }
626                 else BIF_toggle_render_display();
627                 return 0;
628                 break;
629         case F12KEY:
630                 if(G.qual & LR_SHIFTKEY) {
631                         if (G.qual & LR_CTRLKEY){
632                                 newspace(curarea, SPACE_NLA);
633                                 return 0;
634                         }
635                         newspace(curarea, SPACE_ACTION);
636                         return 0;
637                 }
638                 else BIF_do_render(0);
639                 return 0;
640                 break;
641         
642         case LEFTARROWKEY:
643         case DOWNARROWKEY:
644                 if(textediting==0 && textspace==0) {
645                         if(event==DOWNARROWKEY) CFRA-= 10;
646                         else CFRA--;
647                         
648                         if(G.qual & LR_SHIFTKEY) CFRA= SFRA;
649                         if(CFRA<1) CFRA=1;
650         
651                         update_for_newframe();
652                         return 0;
653                 }
654                 break;
655
656         case RIGHTARROWKEY:
657         case UPARROWKEY:
658                 if(textediting==0 && textspace==0) {
659                         if(event==UPARROWKEY) CFRA+= 10;
660                         else CFRA++;
661                         if(G.qual & LR_SHIFTKEY) CFRA= EFRA;
662                         
663                         update_for_newframe();
664                 }
665                 break;
666         
667         case ESCKEY:
668                 sound_stop_all_sounds();
669                 break;
670         case TABKEY:
671                 if(G.qual==0 ) {
672                         if(textspace==0) {
673                                 if(curarea->spacetype==SPACE_IPO) set_editflag_editipo();
674                                 else if(curarea->spacetype==SPACE_SEQ) enter_meta();
675                                 else if(G.vd) {
676                                         /* ook als Alt-E */
677                                         if(G.obedit==0) enter_editmode();
678                                         else exit_editmode(1);
679                                 }
680                                 return 0;
681                         }
682                 }
683                 else if(G.qual & LR_CTRLKEY){
684                         if(G.obpose) exit_posemode(1);
685                         else
686                                 enter_posemode();
687                         allqueue(REDRAWHEADERS, 0);     
688                         
689                 }
690                 else if(G.qual & LR_SHIFTKEY) {
691                         if(G.obedit) exit_editmode(1);
692                         if(G.f & G_FACESELECT) set_faceselect();
693                         if(G.f & G_VERTEXPAINT) set_vpaint();
694                         if(G.f & G_WEIGHTPAINT) set_wpaint();
695                         if(G.obpose) exit_posemode(1);
696                 }
697                 break;
698
699         case BACKSPACEKEY:
700                 break;
701
702         case AKEY:
703                 if(textediting==0 && textspace==0) {
704                         if(G.qual & LR_ALTKEY) {
705                                 if(G.qual & LR_SHIFTKEY) play_anim(1);
706                                 else play_anim(0);
707                                 return 0;
708                         }
709                 }
710                 break;
711         case EKEY:
712                 if(G.qual & LR_ALTKEY) {
713                         if(G.vd && textspace==0) {
714                                 if(G.obedit==0) enter_editmode();
715                                 else exit_editmode(1);
716                                 return 0;
717                         }                       
718                 }
719                 break;
720         case IKEY:
721                 if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
722                         if(G.qual==0) {
723                                 common_insertkey();
724                                 return 0;
725                         }
726                 }
727                 break;
728         case JKEY:
729                 if(textediting==0 && textspace==0) {
730                         if(R.rectot && G.qual==0) {
731                                 BIF_swap_render_rects();
732                                 return 0;
733                         }
734                 }
735                 break;
736
737         case NKEY:
738                 if(textediting==0 && textspace==0 ) {
739                         if(G.qual & LR_CTRLKEY);
740                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
741                                 clever_numbuts();
742                                 return 0;
743                         }
744                 }
745                 break;
746                 
747         case OKEY:
748                 if(textediting==0) {
749                         if(G.qual & LR_CTRLKEY) {
750                                 /* There seem to be crashes here sometimes.... String
751                                  * bound overwrites? I changed dir and str sizes,
752                                  * let's see if this reoccurs. */
753                                 sprintf(str, "Open file: %s", G.sce);
754                         
755                                 if(okee(str)) {
756                                         strcpy(dir, G.sce);
757                                         BIF_read_file(dir);
758                                 }
759                                 return 0;
760                         }
761                 }
762                 break;
763                 
764         case SKEY:
765                 if(G.obpose==0 && G.obedit==0) {
766                         if(G.qual & LR_CTRLKEY) {
767                                 if(G.qual & LR_SHIFTKEY);
768                                 else {
769                                         strcpy(dir, G.sce);
770                                         if (untitled(dir)) {
771                                                 activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
772                                         } else {
773                                                 BIF_write_file(dir);
774                                                 free_filesel_spec(dir);
775                                         }
776                                         return 0;
777                                 }
778                         }
779                 }
780                 break;
781         
782         case TKEY:
783                 if(G.qual & LR_ALTKEY) {
784                 if(G.qual & LR_CTRLKEY) {
785                         int a;
786
787                         if (G.qual & LR_SHIFTKEY) {
788                                 double delta, stime;
789
790                                 waitcursor(1);
791                                 
792                                 stime= PIL_check_seconds_timer();
793                                 for(a=0; a<100000; a++) {
794                                         scrarea_do_windraw(curarea);
795
796                                         delta= PIL_check_seconds_timer()-stime;
797                                         if (delta>5.0) break;
798                                 }
799                                 
800                                 waitcursor(0);
801                                 notice("FPS: %f (%d iterations)", a/delta, a);
802                         } else {
803                                 int event= pupmenu("10 Timer%t|draw|draw+swap");
804                                 if(event>0) {
805                                         double stime= PIL_check_seconds_timer();
806                                         char tmpstr[128];
807                                         int time;
808
809                                         printf("start timer\n");
810                                         waitcursor(1);
811                                                                         
812                                         for(a=0; a<10; a++) {
813                                                 scrarea_do_windraw(curarea);
814                                                 if(event==2) screen_swapbuffers();
815                                         }
816                                 
817                                         time= (PIL_check_seconds_timer()-stime)*1000;
818                                         
819                                         if(event==1) sprintf(tmpstr, "draw %%t|%d", time);
820                                         if(event==2) sprintf(tmpstr, "d+sw %%t|%d", time);
821                                 
822                                         waitcursor(0);
823                                         pupmenu(tmpstr);
824
825                                 }
826                         }
827                         return 0;
828                 }}
829                 break;
830                                 
831         case UKEY:
832                 if(textediting==0) {
833                         if(G.qual & LR_CTRLKEY) {
834                                 if(okee("SAVE USER DEFAULTS")) {
835                                         BIF_write_homefile();
836                                 }
837                                 return 0;
838                         }
839                 }
840                 break;
841                 
842         case WKEY:
843                 if(textediting==0) {
844                         if(G.qual & LR_CTRLKEY) {
845                                 if(G.qual & LR_SHIFTKEY);
846                                 else {
847                                         strcpy(dir, G.sce);
848                                         if (untitled(dir)) {
849                                                 activate_fileselect(FILE_BLENDER, "SAVE FILE", dir, BIF_write_file);
850                                         } else {
851                                                 BIF_write_file(dir);
852                                                 free_filesel_spec(dir);
853                                         }
854                                         return 0;
855                                 }
856                         }
857                         else if(G.qual & LR_ALTKEY) {
858                                 write_videoscape_fs();
859                         }
860                 }
861                 break;
862                 
863         case XKEY:
864                 if(textspace==0) {
865                         if(G.qual & LR_CTRLKEY) {
866                                 if(okee("ERASE ALL")) {
867                                         if( BIF_read_homefile()==0) error("No file ~/.B.blend");
868                                 }
869                                 return 0;
870                         }
871                 }
872                 break;
873         }
874         
875         return 1;
876 }
877
878 /* eof */