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