svn merge -r 12937:13095 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender-staging.git] / source / blender / src / toets.c
1 /**
2  *
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
31  *
32  *
33  * General blender hot keys (toets = dutch), special hotkeys are in space.c
34  *
35  */
36
37 #include <string.h>
38 #include <math.h>
39
40 #ifdef WIN32
41 #include "BLI_winstuff.h"
42 #endif
43
44 #include "MEM_guardedalloc.h"
45
46 #include "PIL_time.h"
47
48 #include "nla.h"        /* Only for the #ifdef flag - To be removed later */
49
50 #include "BLI_blenlib.h"
51 #include "BLI_arithb.h"
52
53 #include "DNA_object_types.h"
54 #include "DNA_screen_types.h"
55 #include "DNA_scene_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_image.h"
67 #include "BKE_ipo.h"
68 #include "BKE_key.h"
69 #include "BKE_scene.h"
70 #include "BKE_utildefines.h"
71
72 #include "BIF_butspace.h"
73 #include "BIF_editseq.h"
74 #include "BIF_editsound.h"
75 #include "BIF_editmesh.h"
76 #include "BIF_imasel.h"
77 #include "BIF_editparticle.h"
78 #include "BIF_interface.h"
79 #include "BKE_object.h"
80 #include "BIF_poseobject.h"
81 #include "BIF_previewrender.h"
82 #include "BIF_renderwin.h"
83 #include "BIF_retopo.h"
84 #include "BIF_screen.h"
85 #include "BIF_space.h"
86 #include "BIF_toets.h"
87 #include "BIF_toolbox.h"
88 #include "BIF_usiblender.h"
89 #include "BIF_writeimage.h"
90
91 #include "BDR_sculptmode.h"
92 #include "BDR_vpaint.h"
93 #include "BDR_editobject.h"
94 #include "BDR_editface.h"
95
96 #include "BSE_filesel.h"        /* For activate_fileselect */
97 #include "BSE_drawview.h"       /* For play_anim */
98 #include "BSE_view.h"
99 #include "BSE_edit.h"
100 #include "BSE_editipo.h"
101 #include "BSE_headerbuttons.h"
102 #include "BSE_seqaudio.h"
103
104 #include "blendef.h"
105
106 #include "IMB_imbuf.h"
107 #include "IMB_imbuf_types.h"
108
109 #include "mydevice.h"
110
111 #include "BIF_poseobject.h"
112
113 #define VIEW_ZOOM_OUT_FACTOR (1.15f)
114 #define VIEW_ZOOM_IN_FACTOR (1.0f/VIEW_ZOOM_OUT_FACTOR)
115
116 /* ------------------------------------------------------------------------- */
117
118 static int is_an_active_object(void *ob) {
119         Base *base;
120         
121         for (base= FIRSTBASE; base; base= base->next)
122                 if (base->object == ob)
123                         return 1;
124         
125         return 0;
126 }
127
128 /* run when pressing 1,3 or 7 */
129 static void axis_set_view(float q1, float q2, float q3, float q4, short view, int perspo)
130 {
131         float new_quat[4];
132         new_quat[0]= q1; new_quat[1]= q2;
133         new_quat[2]= q3; new_quat[3]= q4;
134         G.vd->view=0;
135         
136         if (G.vd->persp==2 && G.vd->camera) {
137                 /* Is this switching from a camera view ? */
138                 float orig_ofs[3];
139                 float orig_lens= G.vd->lens;
140                 VECCOPY(orig_ofs, G.vd->ofs);
141                 view_settings_from_ob(G.vd->camera, G.vd->ofs, G.vd->viewquat, &G.vd->dist, &G.vd->lens);
142                 
143                 if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
144                 else if(G.vd->persp>=2) G.vd->persp= perspo;
145                 
146                 smooth_view(G.vd, orig_ofs, new_quat, NULL, &orig_lens);
147         } else {
148                 
149                 if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0;
150                 else if(G.vd->persp>=2) G.vd->persp= perspo;
151                 
152                 smooth_view(G.vd, NULL, new_quat, NULL, NULL);
153         }
154         G.vd->view= view;
155 }
156
157 void persptoetsen(unsigned short event)
158 {
159         static Object *oldcamera=0;
160         float phi, si, q1[4], vec[3];
161         static int perspo=1;
162         int preview3d_event= 1;
163         short mouseloc[2];
164         
165         float new_dist, orig_ofs[3];
166         
167         /* Use this to test if we started out with a camera */
168         Object *act_cam_orig=NULL;
169         if (G.vd->persp == 2)
170                 act_cam_orig = G.vd->camera;
171         
172         if(event==PADENTER) {
173                 if (G.qual == LR_SHIFTKEY) {
174                         view3d_set_1_to_1_viewborder(G.vd);
175                 } else {
176                         if (G.vd->persp==2) {
177                                 G.vd->camzoom= 0;
178                         } else {
179                                 new_dist = 10.0;
180                                 smooth_view(G.vd, NULL, NULL, &new_dist, NULL);
181                         }
182                 }
183         }
184         else if((G.qual & (LR_SHIFTKEY | LR_CTRLKEY)) && (event != PAD0)) {
185                 
186                 /* Indicate that this view is inverted,
187                  * but only if it actually _was_ inverted (jobbe) */
188                 if (event==PAD7 || event == PAD1 || event == PAD3)
189                         G.vd->flag2 |= V3D_OPP_DIRECTION_NAME;
190                 
191                 if(event==PAD0) {
192                         /* G.vd->persp= 3; */
193                 }
194                 else if(event==PAD7) {
195                         axis_set_view(0.0, -1.0, 0.0, 0.0, 7, perspo);
196                 }
197                 else if(event==PAD1) {
198                         axis_set_view(0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), 1, perspo);
199                 }
200                 else if(event==PAD3) {
201                         axis_set_view(0.5, -0.5, 0.5, 0.5, 3, perspo);
202                 }
203                 else if(event==PADMINUS) {
204                         /* this min and max is also in viewmove() */
205                         if(G.vd->persp==2) {
206                                 G.vd->camzoom-= 10;
207                                 if(G.vd->camzoom<-30) G.vd->camzoom= -30;
208                         }
209                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
210                 }
211                 else if(event==PADPLUSKEY) {
212                         if(G.vd->persp==2) {
213                                 G.vd->camzoom+= 10;
214                                 if(G.vd->camzoom>300) G.vd->camzoom= 300;
215                         }
216                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
217                 }
218                 else {
219
220                         initgrabz(0.0, 0.0, 0.0);
221                         
222                         if(event==PAD6) window_to_3d(vec, -32, 0);
223                         else if(event==PAD4) window_to_3d(vec, 32, 0);
224                         else if(event==PAD8) window_to_3d(vec, 0, -25);
225                         else if(event==PAD2) window_to_3d(vec, 0, 25);
226                         G.vd->ofs[0]+= vec[0];
227                         G.vd->ofs[1]+= vec[1];
228                         G.vd->ofs[2]+= vec[2];
229                 }
230         }
231         else {
232                 /* Indicate that this view is not inverted.
233                  * Don't do this for PADMINUS/PADPLUSKEY, though. (jobbe)*/
234                 if (event != PADMINUS && event != PADPLUSKEY)
235                         G.vd->flag2 &= ~V3D_OPP_DIRECTION_NAME;
236                 
237
238                 if(event==PAD7) {
239                         axis_set_view(1.0, 0.0, 0.0, 0.0, 7, perspo);
240                 }
241                 else if(event==PAD1) {
242                         axis_set_view((float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, 1, perspo);
243                 }
244                 else if(event==PAD3) {
245                         axis_set_view(0.5, -0.5, -0.5, -0.5, 3, perspo);
246                 }
247                 else if(event==PADMINUS) {
248                         /* this min and max is also in viewmove() */
249                         if(G.vd->persp==2) {
250                                 G.vd->camzoom= MAX2(-30, G.vd->camzoom-5);
251                         }
252                         else if(G.vd->dist<10.0*G.vd->far) {
253                                 getmouseco_areawin(mouseloc);
254                                 view_zoom_mouseloc(VIEW_ZOOM_OUT_FACTOR, mouseloc);
255                         }
256                         if(G.vd->persp!=1) preview3d_event= 0;
257                 }
258                 else if(event==PADPLUSKEY) {
259                         if(G.vd->persp==2) {
260                                 G.vd->camzoom= MIN2(300, G.vd->camzoom+5);
261                         }
262                         else if(G.vd->dist> 0.001*G.vd->grid) {
263                                 getmouseco_areawin(mouseloc);
264                                 view_zoom_mouseloc(VIEW_ZOOM_IN_FACTOR, mouseloc);
265                         }
266                         if(G.vd->persp!=1) preview3d_event= 0;
267                 }
268                 else if(event==PAD5) {
269                         if (U.smooth_viewtx) {
270                                 if(G.vd->persp==1) { G.vd->persp=0;
271                                 } else if (act_cam_orig) {
272                                         /* were from a camera view */
273                                         float orig_dist= G.vd->dist;
274                                         float orig_lens= G.vd->lens;
275                                         VECCOPY(orig_ofs, G.vd->ofs);
276
277                                         G.vd->persp=1;
278                                         G.vd->dist= 0.0;
279
280                                         view_settings_from_ob(act_cam_orig, G.vd->ofs, NULL, NULL, &G.vd->lens);
281                                         
282                                         smooth_view(G.vd, orig_ofs, NULL, &orig_dist, &orig_lens);
283                                         
284                                 } else {
285                                         G.vd->persp=1;
286                                 }
287                         } else {
288                                 if(G.vd->persp==1) G.vd->persp=0;
289                                 else G.vd->persp=1;
290                         }
291                 }
292                 else if(event==PAD0) {
293                         if(G.qual==LR_ALTKEY) {
294                                 if(oldcamera && is_an_active_object(oldcamera)) {
295                                         G.vd->camera= oldcamera;
296                                 }
297                                 handle_view3d_lock();
298                         }
299                         else if(BASACT) {
300                                 /* check both G.vd as G.scene cameras */
301                                 if(G.qual==LR_CTRLKEY) {
302                                         if(G.vd->camera != OBACT || G.scene->camera != OBACT) {
303                                                 if(G.vd->camera && G.vd->camera->type==OB_CAMERA)
304                                                         oldcamera= G.vd->camera;
305                                                 
306                                                 G.vd->camera= OBACT;
307                                                 handle_view3d_lock();
308                                         }
309                                 }
310                                 else if((G.vd->camera==NULL || G.scene->camera==NULL) && OBACT->type==OB_CAMERA) {
311                                         G.vd->camera= OBACT;
312                                         handle_view3d_lock();
313                                 }
314                         }
315                         if(G.vd->camera==0) {
316                                 G.vd->camera= scene_find_camera(G.scene);
317                                 handle_view3d_lock();
318                         }
319                         
320                         if(G.vd->camera && (G.vd->camera != act_cam_orig)) {
321                                 G.vd->persp= 2;
322                                 G.vd->view= 0;
323                                 
324                                 if(((G.qual & LR_CTRLKEY) && (G.qual & LR_ALTKEY)) || (G.qual & LR_SHIFTKEY)) {
325                                         void setcameratoview3d(void);   // view.c
326                                         setcameratoview3d();
327                                         DAG_object_flush_update(G.scene, G.scene->camera, OB_RECALC_OB);
328                                         BIF_undo_push("View to Camera position");
329                                         allqueue(REDRAWVIEW3D, 0);
330                                 
331                                 } else if (U.smooth_viewtx) {
332                                         /* move 3d view to camera view */
333                                         float orig_lens = G.vd->lens;
334                                         VECCOPY(orig_ofs, G.vd->ofs);
335                                         
336                                         if (act_cam_orig)
337                                                 view_settings_from_ob(act_cam_orig, G.vd->ofs, G.vd->viewquat, &G.vd->dist, &G.vd->lens);
338                                         
339                                         smooth_view_to_camera(G.vd);
340                                         VECCOPY(G.vd->ofs, orig_ofs);
341                                         G.vd->lens = orig_lens;
342                                 }
343                                 
344                         
345                         }
346                 }
347                 else if(event==PAD9) {
348                         countall();
349                         update_for_newframe();
350                         
351                         reset_slowparents();    /* editobject.c */
352                 }
353                 else if(G.vd->persp<2) {
354                         if(event==PAD4 || event==PAD6) {
355                                 /* z-axis */
356                                 phi= (float)(M_PI/360.0)*U.pad_rot_angle;
357                                 if(event==PAD6) phi= -phi;
358                                 si= (float)sin(phi);
359                                 q1[0]= (float)cos(phi);
360                                 q1[1]= q1[2]= 0.0;
361                                 q1[3]= si;
362                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
363                                 G.vd->view= 0;
364                         }
365                         if(event==PAD2 || event==PAD8) {
366                                 /* horizontal axis */
367                                 VECCOPY(q1+1, G.vd->viewinv[0]);
368                                 
369                                 Normalize(q1+1);
370                                 phi= (float)(M_PI/360.0)*U.pad_rot_angle;
371                                 if(event==PAD2) phi= -phi;
372                                 si= (float)sin(phi);
373                                 q1[0]= (float)cos(phi);
374                                 q1[1]*= si;
375                                 q1[2]*= si;
376                                 q1[3]*= si;
377                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
378                                 G.vd->view= 0;
379                         }
380                 }
381
382                 if(G.vd->persp<2) perspo= G.vd->persp;
383         }
384
385         if(G.vd->depths) G.vd->depths->damaged= 1;
386         retopo_queue_updates(G.vd);
387         
388         if(preview3d_event) 
389                 BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
390         else
391                 BIF_view3d_previewrender_signal(curarea, PR_PROJECTED);
392
393         scrarea_queue_redraw(curarea);
394 }
395
396 int untitled(char * name)
397 {
398         if (G.save_over == 0 ) {
399                 char * c= BLI_last_slash(name);
400                 
401                 if (c)
402                         strcpy(&c[1], "untitled.blend");
403                 else
404                         strcpy(name, "untitled.blend");
405                         
406                 return(TRUE);
407         }
408         
409         return(FALSE);
410 }
411
412 char *recent_filelist(void)
413 {
414         struct RecentFile *recent;
415         int event, i, ofs;
416         char pup[2048], *p;
417
418         p= pup + sprintf(pup, "Open Recent%%t");
419         
420         if (G.sce[0]) {
421                 p+= sprintf(p, "|%s %%x%d", G.sce, 1);
422                 ofs = 1;
423         } else ofs = 0;
424
425         for (recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++) {
426                 if (strcmp(recent->filename, G.sce)) {
427                         p+= sprintf(p, "|%s %%x%d", recent->filename, i+ofs+1);
428                 }
429         }
430         event= pupmenu(pup);
431         if(event>0) {
432                 if (ofs && (event==1))
433                         return(G.sce);
434                 else
435                         recent = BLI_findlink(&(G.recent_files), event-1-ofs);
436                         if(recent) return(recent->filename);
437         }
438         
439         return(NULL);
440 }
441
442 int blenderqread(unsigned short event, short val)
443 {
444         /* here do the general keys handling (not screen/window/space) */
445         /* return 0: do not pass on to the other queues */
446         extern int textediting;
447         extern void playback_anim();
448         ScrArea *sa;
449         Object *ob;
450         int textspace=0;
451         /* Changed str and dir size to 160, to make sure there is enough
452          * space for filenames. */
453         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
454         char *recentfile;
455         
456         if(val==0) return 1;
457         if(event==MOUSEY || event==MOUSEX) return 1;
458         if (G.flags & G_FILE_AUTOPLAY) return 1;
459
460         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
461         else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
462
463         switch(event) {
464
465         case F1KEY:
466                 if(G.qual==0) {
467                         /* this exception because of the '?' button */
468                         if(curarea->spacetype==SPACE_INFO) {
469                                 sa= closest_bigger_area();
470                                 areawinset(sa->win);
471                         }
472                         
473                         activate_fileselect(FILE_BLENDER, "Open File", G.sce, BIF_read_file);
474                         return 0;
475                 }
476                 else if(G.qual==LR_SHIFTKEY) {
477                         activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
478                         return 0;
479                 }
480                 else if(G.qual==LR_CTRLKEY) {
481                         activate_imageselect(FILE_LOADLIB, "Load Library", G.lib, 0);
482                         return 0;
483                 }
484                 break;
485         case F2KEY:
486                 if(G.qual==0) {
487                         strcpy(dir, G.sce);
488                         untitled(dir);
489                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
490                         return 0;
491                 }
492                 else if(G.qual==LR_CTRLKEY) {
493                         write_vrml_fs();
494                         return 0;
495                 }
496                 else if(G.qual==LR_SHIFTKEY) {
497                         write_dxf_fs();
498                         return 0;
499                 }
500                 break;
501         case F3KEY:
502                 if(G.qual==0) {
503                         BIF_save_rendered_image_fs();
504                         return 0;
505                 }
506                 else if(G.qual==LR_SHIFTKEY) {
507                         newspace(curarea, SPACE_NODE);
508                         return 0;
509                 }
510                 else if(G.qual & LR_CTRLKEY) {
511                         BIF_screendump(0);
512                 }
513                 break;
514         case F4KEY:
515                 if(G.qual==LR_SHIFTKEY) {
516
517                         memset(str, 0, 16);
518                         ob= OBACT;
519                         if(ob) strcpy(str, ob->id.name);
520
521                         activate_fileselect(FILE_MAIN, "Data Select", str, NULL);
522                         return 0;
523                 }
524                 else if(G.qual==LR_CTRLKEY) {
525
526                         memset(str, 0, 16);
527                         ob= OBACT;
528                         if(ob) strcpy(str, ob->id.name);
529
530                         activate_imageselect(FILE_MAIN, "Data Select", str, 0);
531                         return 0;
532                 }
533                 else if(G.qual==0) {
534                         extern_set_butspace(event, 1);
535                 }
536                 break;
537         case F5KEY:
538                 if(G.qual==LR_SHIFTKEY) {
539                         newspace(curarea, SPACE_VIEW3D);
540                         return 0;
541                 }
542                 else if(G.qual==0) {
543                         extern_set_butspace(event, 1);
544                 }
545                 break;
546         case F6KEY:
547                 if(G.qual==LR_SHIFTKEY) {
548                         newspace(curarea, SPACE_IPO);
549                         return 0;
550                 }
551                 else if(G.qual==0) {
552                         extern_set_butspace(event, 1);
553                 }
554                 break;
555         case F7KEY:
556                 if(G.qual==LR_SHIFTKEY) {
557                         newspace(curarea, SPACE_BUTS);
558                         return 0;
559                 }
560                 else if(G.qual==0) {
561                         extern_set_butspace(event, 1);
562                 }
563                 break;
564         case F8KEY:
565                 if(G.qual==LR_SHIFTKEY) {
566                         newspace(curarea, SPACE_SEQ);
567                         return 0;
568                 }
569                 else if(G.qual==0) {
570                         extern_set_butspace(event, 1);
571                 }
572                 break;
573         case F9KEY:
574                 if(G.qual==LR_SHIFTKEY) {
575                         newspace(curarea, SPACE_OOPS);
576                         return 0;
577                 }
578                 else if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)) {
579                         newspace(curarea, SPACE_OOPS+256);
580                         return 0;
581                 }
582                 else if(G.qual==0) {
583                         extern_set_butspace(event, 1);
584                 }
585                 break;
586         case F10KEY:
587                 if(G.qual==LR_SHIFTKEY) {
588                         newspace(curarea, SPACE_IMAGE);
589                         return 0;
590                 }
591                 else if(G.qual==0) {
592                         extern_set_butspace(event, 1);
593                 }
594                 break;
595         case F11KEY:
596                 if(G.qual==LR_SHIFTKEY) {
597                         newspace(curarea, SPACE_TEXT);
598                         return 0;
599                 }
600                 else if (G.qual==LR_CTRLKEY) {
601                         playback_anim();
602                 }
603                 else if(G.qual==0) {
604                         BIF_toggle_render_display();
605                         return 0;
606                 }
607                 break;
608         case F12KEY:
609                 if(G.qual==LR_SHIFTKEY) {
610                         newspace(curarea, SPACE_ACTION);
611                         return 0;
612                 }
613                 else if (G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
614                         newspace(curarea, SPACE_NLA);
615                         return 0;
616                 }
617                 else if (G.qual==LR_CTRLKEY) {
618                         BIF_do_render(1);
619                 }
620                 else {
621                         /* ctrl/alt + f12 should render too, for some macs have f12 assigned to cd eject */
622                         BIF_do_render(0);
623                 }
624                 return 0;
625                 break;
626         
627         case WHEELUPMOUSE:
628                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
629                         if(CFRA>1) {
630                                 CFRA--;
631                                 update_for_newframe();
632                         }
633                         return 0;
634                 }
635                 break;
636         case WHEELDOWNMOUSE:
637                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
638                         CFRA++;
639                         update_for_newframe();
640                         return 0;
641                 }
642                 break;
643                 
644         case LEFTARROWKEY:
645         case DOWNARROWKEY:
646                 if(textediting==0 && textspace==0) {
647
648 #if 0
649 //#ifdef _WIN32 // FULLSCREEN
650                         if(event==DOWNARROWKEY){
651                                 if (G.qual==LR_ALTKEY)
652                                         mainwindow_toggle_fullscreen(0);
653                                 else if(G.qual==0)
654                                         CFRA-= G.scene->jumpframe;
655                         }
656 #else
657                         if((event==DOWNARROWKEY)&&(G.qual==0))
658                                 CFRA-= G.scene->jumpframe;
659 #endif
660                         else if((event==LEFTARROWKEY)&&(G.qual==0))
661                                 CFRA--;
662                         
663                         if(G.qual==LR_SHIFTKEY)
664                                 CFRA= PSFRA;
665                         if(CFRA<1) CFRA=1;
666         
667                         update_for_newframe();
668                         return 0;
669                 }
670                 break;
671
672         case RIGHTARROWKEY:
673         case UPARROWKEY:
674                 if(textediting==0 && textspace==0) {
675
676 #if 0
677 //#ifdef _WIN32 // FULLSCREEN
678                         if(event==UPARROWKEY){ 
679                                 if(G.qual==LR_ALTKEY)
680                                         mainwindow_toggle_fullscreen(1);
681                                 else if(G.qual==0)
682                                         CFRA+= G.scene->jumpframe;
683                         }
684 #else
685                         if((event==UPARROWKEY)&&(G.qual==0))
686                                 CFRA+= G.scene->jumpframe;
687 #endif
688                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
689                                 CFRA++;
690
691                         if(G.qual==LR_SHIFTKEY)
692                                 CFRA= PEFRA;
693                         
694                         update_for_newframe();
695                 }
696                 break;
697
698         case ESCKEY:
699                 sound_stop_all_sounds();        // whats this?
700                 
701                 /* stop playback on ESC always */
702                 rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
703                 audiostream_stop();
704                 allqueue(REDRAWALL, 0);
705                 
706                 break;
707         case TABKEY:
708                 if(G.qual==0) {
709                         if(textspace==0) {
710                                 if(curarea->spacetype==SPACE_IPO)
711                                         set_editflag_editipo();
712                                 else if(curarea->spacetype==SPACE_SEQ)
713                                         enter_meta();
714                                 else if(curarea->spacetype==SPACE_NODE)
715                                         return 1;
716                                 else if(G.vd) {
717                                         /* also when Alt-E */
718                                         if(G.obedit==NULL) {
719                                                 enter_editmode(EM_WAITCURSOR);
720                                                 if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
721                                         }
722                                         else
723                                                 exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); // freedata, and undo
724                                 }
725                                 return 0;
726                         }
727                 }
728                 else if(G.qual==LR_CTRLKEY){
729                         Object *ob= OBACT;
730                         if(ob) {
731                                 if(ob->type==OB_ARMATURE) {
732                                         if(ob->flag & OB_POSEMODE) exit_posemode();
733                                         else enter_posemode();
734                                 }
735                                 else if(ob->type==OB_MESH) {
736                                         if(ob==G.obedit) EM_selectmode_menu();
737                                         else if(G.f & G_PARTICLEEDIT)
738                                                 PE_selectbrush_menu();
739                                         else if(G.f & G_SCULPTMODE)
740                                                 sculptmode_selectbrush_menu();
741                                         else set_wpaint();
742                                 }
743                         }
744                 }
745                 else if(G.qual&LR_CTRLKEY && G.qual&LR_SHIFTKEY){
746                         PE_set_particle_edit();
747                 }
748                 break;
749
750         case BACKSPACEKEY:
751                 break;
752         case SPACEKEY:
753                 if (curarea && curarea->spacetype==SPACE_SEQ) {
754                         SpaceSeq *sseq= curarea->spacedata.first;
755                         if (G.qual==0 && sseq->mainb) {
756                                 play_anim(1);
757                                 return 0;
758                         }
759                 }
760                 break;
761         case AKEY:
762                 if(textediting==0 && textspace==0) {
763                         if ((G.qual==LR_ALTKEY) && (curarea && curarea->spacetype==SPACE_VIEW3D)) {
764                                 play_anim(0);
765                                 return 0;
766                         }
767                         else if ((G.qual==LR_ALTKEY) || (G.qual==(LR_ALTKEY|LR_SHIFTKEY))){
768                                 play_anim(1);
769                                 return 0;
770                         }
771                 }
772                 break;
773         case EKEY:
774                 if(G.qual==LR_ALTKEY) {
775                         if(G.vd && textspace==0) {
776                                 if(G.obedit==0) {
777                                         enter_editmode(EM_WAITCURSOR);
778                                         BIF_undo_push("Original");
779                                 }
780                                 else
781                                         exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); // freedata, and undo
782                                 return 0;
783                         }                       
784                 }
785                 break;
786         case IKEY:
787                 if(textediting==0 && textspace==0 && !ELEM3(curarea->spacetype, SPACE_FILE, SPACE_IMASEL, SPACE_NODE)) {
788                         if(G.f & G_SCULPTMODE) return 1;
789                         else if(G.qual==0) {
790                                 common_insertkey();
791                                 return 0;
792                         }
793                 }
794                 break;
795         case JKEY:
796                 if(textediting==0 && textspace==0) {
797                         if (G.qual==0) {
798                                 BIF_swap_render_rects();
799                                 return 0;
800                         }
801                 }
802                 break;
803
804         case NKEY:
805                 if(textediting==0 && textspace==0) {
806                         if(G.qual & LR_CTRLKEY);
807                         else if(G.qual==0 || (G.qual & LR_SHIFTKEY)) {
808                                 if(curarea->spacetype==SPACE_VIEW3D);           // is new panel, in view3d queue
809                                 else if(curarea->spacetype==SPACE_IPO);                 // is new panel, in ipo queue
810                                 else if(curarea->spacetype==SPACE_IMAGE);                       // is new panel, in ipo queue
811                                 else if(curarea->spacetype==SPACE_ACTION);                      // is own queue
812                                 else if(curarea->spacetype==SPACE_NLA);                 // is new panel
813                                 else if(curarea->spacetype==SPACE_SEQ);                 // is new panel
814                                 else {
815                                         clever_numbuts();
816                                         return 0;
817                                 }
818                         }
819                 }
820                 break;
821                 
822         case OKEY:
823                 if(textediting==0) {
824                         if(G.qual==LR_CTRLKEY) {
825                                 recentfile = recent_filelist();
826                                 if(recentfile) {
827                                         BIF_read_file(recentfile);
828                                 }
829                                 return 0;
830                         }
831                 }
832                 break;
833                 
834         case SKEY:
835                 if(G.obedit==NULL) {
836                         if(G.qual==LR_CTRLKEY) {
837                                 strcpy(dir, G.sce);
838                                 if (untitled(dir)) {
839                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
840                                 } else {
841                                         /* do NOT ask everytime for overwriting... */
842                                         G.save_over = 1;
843                                         BIF_write_file(dir);
844                                         free_filesel_spec(dir);
845                                 }
846                                 return 0;
847                         }
848                 }
849                 break;
850         
851         case TKEY:
852                 if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
853                         Object *ob = OBACT;
854                         int event = pupmenu(ob?"Time%t|draw|recalc ob|recalc data":"Time%t|draw");
855                         int a;
856                         double delta, stime;
857
858                         if (event < 0) return 0; /* cancelled by user */
859
860                         waitcursor(1);
861                         
862                         stime= PIL_check_seconds_timer();
863                         for(a=0; a<100000; a++) {
864                                 if (event==1) {
865                                         scrarea_do_windraw(curarea);
866                                 } else if (event==2) {
867                                         ob->recalc |= OB_RECALC_OB;
868                                         object_handle_update(ob);
869                                 } else if (event==3) {
870                                         ob->recalc |= OB_RECALC_DATA;
871                                         object_handle_update(ob);
872                                 }
873
874                                 delta= PIL_check_seconds_timer()-stime;
875                                 if (delta>5.0) break;
876                         }
877                         
878                         waitcursor(0);
879                         notice("%8.6f s/op - %6.2f ops/s - %d iterations", delta/a, a/delta, a);
880                         return 0;
881                 }
882                 else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
883                         int a;
884                         int event= pupmenu("10 Timer%t|draw|draw+swap|undo");
885                         if(event>0) {
886                                 double stime= PIL_check_seconds_timer();
887                                 char tmpstr[128];
888                                 int time;
889
890                                 waitcursor(1);
891                                 
892                                 for(a=0; a<10; a++) {
893                                         if (event==1) {
894                                                 scrarea_do_windraw(curarea);
895                                         } else if (event==2) {
896                                                 scrarea_do_windraw(curarea);
897                                                 screen_swapbuffers();
898                                         }
899                                         else if(event==3) {
900                                                 BIF_undo();
901                                                 BIF_redo();
902                                         }
903                                 }
904                         
905                                 time= (int) ((PIL_check_seconds_timer()-stime)*1000);
906                                 
907                                 if(event==1) sprintf(tmpstr, "draw %%t|%d ms", time);
908                                 if(event==2) sprintf(tmpstr, "d+sw %%t|%d ms", time);
909                                 if(event==3) sprintf(tmpstr, "undo %%t|%d ms", time);
910                         
911                                 waitcursor(0);
912                                 pupmenu(tmpstr);
913
914                         }
915                         return 0;
916                 }
917                 break;
918                                 
919         case UKEY:
920                 if(textediting==0) {
921                         if(G.qual==LR_CTRLKEY) {
922                                 if(okee("Save user defaults")) {
923                                         BIF_write_homefile();
924                                 }
925                                 return 0;
926                         }
927                         else if(G.qual==LR_ALTKEY) {
928                                 if(curarea->spacetype!=SPACE_TEXT) {
929                                         BIF_undo_menu();
930                                         return 0;
931                                 }
932                         }
933                 }
934                 break;
935                 
936         case WKEY:
937                 if(textediting==0) {
938                         if(G.qual==LR_CTRLKEY) {
939                                 strcpy(dir, G.sce);
940                                 if (untitled(dir)) {
941                                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
942                                 } else {
943                                         /* do NOT ask everytime for overwriting... */
944                                         G.save_over = 1;
945                                         BIF_write_file(dir);
946                                         free_filesel_spec(dir);
947                                 }
948                                 return 0;
949                         }
950                         /* Python specials? ;)
951                         else if(G.qual==LR_ALTKEY) {
952                                 write_videoscape_fs();
953                                 return 0;
954                         }*/ 
955                 }
956                 break;
957                 
958         case XKEY:
959                 if(textspace==0 && textediting==0) {
960                         if(G.qual==LR_CTRLKEY) {
961                                 if(okee("Erase all")) {
962                                         if( BIF_read_homefile(0)==0) error("No file ~/.B.blend");
963                                         
964                                         /* Reset lights
965                                          * This isn't done when reading userdef, do it now
966                                          *  */
967                                         default_gl_light(); 
968                                 }
969                                 return 0;
970                         }
971                 }
972                 break;
973         case YKEY:      // redo alternative
974                 if(textspace==0) {
975                         if(G.qual==LR_CTRLKEY) {
976                                 BIF_redo(); 
977                                 return 0;
978                         }
979                 }
980                 break;
981         case ZKEY:      // undo
982                 if(textspace==0) {
983                         if(G.qual & (LR_CTRLKEY|LR_COMMANDKEY)) { // all combos with ctrl/commandkey are accepted
984                                 if ELEM(G.qual, LR_CTRLKEY, LR_COMMANDKEY) BIF_undo();
985                                 else BIF_redo(); // all combos with ctrl is redo
986                                 return 0;
987                         }
988                 }
989                 break; 
990         }
991         
992         return 1;
993 }
994
995 /* eof */