bugfix for view naming, pressing numpad5 would clear the V3D_OPP_DIRECTION_NAME flag...
[blender.git] / source / blender / src / toets.c
1 /**
2  *
3  * ***** BEGIN GPL 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.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27
28  *
29  *
30  * General blender hot keys (toets = dutch), special hotkeys are in space.c
31  *
32  */
33
34 #include <string.h>
35 #include <math.h>
36
37 #ifdef WIN32
38 #include "BLI_winstuff.h"
39 #endif
40
41 #include "MEM_guardedalloc.h"
42
43 #include "PIL_time.h"
44
45 #include "nla.h"        /* Only for the #ifdef flag - To be removed later */
46
47 #include "BLI_blenlib.h"
48 #include "BLI_arithb.h"
49
50 #include "DNA_object_types.h"
51 #include "DNA_screen_types.h"
52 #include "DNA_scene_types.h"
53 #include "DNA_space_types.h"
54 #include "DNA_view3d_types.h"
55 #include "DNA_userdef_types.h"
56
57 #include "BKE_action.h"
58 #include "BKE_anim.h"
59 #include "BKE_blender.h"
60 #include "BKE_depsgraph.h"
61 #include "BKE_displist.h"
62 #include "BKE_global.h"
63 #include "BKE_image.h"
64 #include "BKE_ipo.h"
65 #include "BKE_key.h"
66 #include "BKE_object.h"
67 #include "BKE_pointcache.h"
68 #include "BKE_scene.h"
69 #include "BKE_utildefines.h"
70
71 #include "BIF_butspace.h"
72 #include "BIF_editseq.h"
73 #include "BIF_editsound.h"
74 #include "BIF_editmesh.h"
75 #include "BIF_imasel.h"
76 #include "BIF_editparticle.h"
77 #include "BIF_interface.h"
78 #include "BIF_poseobject.h"
79 #include "BIF_previewrender.h"
80 #include "BIF_renderwin.h"
81 #include "BIF_retopo.h"
82 #include "BIF_screen.h"
83 #include "BIF_space.h"
84 #include "BIF_toets.h"
85 #include "BIF_toolbox.h"
86 #include "BIF_usiblender.h"
87 #include "BIF_writeimage.h"
88
89 #include "BDR_sculptmode.h"
90 #include "BDR_vpaint.h"
91 #include "BDR_editobject.h"
92 #include "BDR_editface.h"
93
94 #include "BSE_filesel.h"        /* For activate_fileselect */
95 #include "BSE_drawview.h"       /* For play_anim */
96 #include "BSE_view.h"
97 #include "BSE_edit.h"
98 #include "BSE_editipo.h"
99 #include "BSE_headerbuttons.h"
100 #include "BSE_seqaudio.h"
101
102 #include "blendef.h"
103
104 #include "IMB_imbuf.h"
105 #include "IMB_imbuf_types.h"
106
107 #include "mydevice.h"
108
109 #include "transform.h"
110
111 #define VIEW_ZOOM_OUT_FACTOR (1.15f)
112 #define VIEW_ZOOM_IN_FACTOR (1.0f/VIEW_ZOOM_OUT_FACTOR)
113
114 /* ------------------------------------------------------------------------- */
115
116 static int is_an_active_object(void *ob) {
117         Base *base;
118         
119         for (base= FIRSTBASE; base; base= base->next)
120                 if (base->object == ob)
121                         return 1;
122         
123         return 0;
124 }
125
126 /* run when pressing 1,3 or 7 */
127 static void axis_set_view(float q1, float q2, float q3, float q4, short view, int perspo)
128 {
129         float new_quat[4];
130         new_quat[0]= q1; new_quat[1]= q2;
131         new_quat[2]= q3; new_quat[3]= q4;
132         G.vd->view=0;
133         
134         if (G.vd->persp==V3D_CAMOB && G.vd->camera) {
135                 /* Is this switching from a camera view ? */
136                 float orig_ofs[3];
137                 float orig_lens= G.vd->lens;
138                 VECCOPY(orig_ofs, G.vd->ofs);
139                 view_settings_from_ob(G.vd->camera, G.vd->ofs, G.vd->viewquat, &G.vd->dist, &G.vd->lens);
140                 
141                 if (U.uiflag & USER_AUTOPERSP) G.vd->persp= V3D_ORTHO;
142                 else if(G.vd->persp==V3D_CAMOB) G.vd->persp= perspo;
143                 
144                 smooth_view(G.vd, orig_ofs, new_quat, NULL, &orig_lens);
145         } else {
146                 
147                 if (U.uiflag & USER_AUTOPERSP) G.vd->persp= V3D_ORTHO;
148                 else if(G.vd->persp==V3D_CAMOB) G.vd->persp= perspo;
149                 
150                 smooth_view(G.vd, NULL, new_quat, NULL, NULL);
151         }
152         G.vd->view= view;
153 }
154
155 void persptoetsen(unsigned short event)
156 {
157         static Object *oldcamera=0;
158         float phi, si, q1[4], vec[3];
159         static int perspo=V3D_PERSP;
160         int preview3d_event= 1;
161         short mouseloc[2];
162         
163         float new_dist, orig_ofs[3];
164         
165         /* Use this to test if we started out with a camera */
166         Object *act_cam_orig=NULL;
167         if (G.vd->persp == V3D_CAMOB)
168                 act_cam_orig = G.vd->camera;
169         
170         if(event==PADENTER) {
171                 if (G.qual == LR_SHIFTKEY) {
172                         view3d_set_1_to_1_viewborder(G.vd);
173                 } else {
174                         if (G.vd->persp==V3D_CAMOB) {
175                                 G.vd->camzoom= 0;
176                         } else {
177                                 new_dist = 10.0;
178                                 smooth_view(G.vd, NULL, NULL, &new_dist, NULL);
179                         }
180                 }
181         }
182         else if((G.qual & (LR_SHIFTKEY | LR_CTRLKEY)) && (event != PAD0)) {
183                 
184                 /* Indicate that this view is inverted,
185                  * but only if it actually _was_ inverted (jobbe) */
186                 if (event==PAD7 || event == PAD1 || event == PAD3)
187                         G.vd->flag2 |= V3D_OPP_DIRECTION_NAME;
188                 
189                 if(event==PAD0) {
190                         /* G.vd->persp= 3; */
191                 }
192                 else if(event==PAD7) {
193                         axis_set_view(0.0, -1.0, 0.0, 0.0, 7, perspo);
194                 }
195                 else if(event==PAD1) {
196                         axis_set_view(0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), 1, perspo);
197                 }
198                 else if(event==PAD3) {
199                         axis_set_view(0.5, -0.5, 0.5, 0.5, 3, perspo);
200                 }
201                 else if(event==PADMINUS) {
202                         /* this min and max is also in viewmove() */
203                         if(G.vd->persp==V3D_CAMOB) {
204                                 G.vd->camzoom-= 10;
205                                 if(G.vd->camzoom<-30) G.vd->camzoom= -30;
206                         }
207                         else if(G.vd->dist<10.0*G.vd->far) G.vd->dist*=1.2f;
208                 }
209                 else if(event==PADPLUSKEY) {
210                         if(G.vd->persp==V3D_CAMOB) {
211                                 G.vd->camzoom+= 10;
212                                 if(G.vd->camzoom>300) G.vd->camzoom= 300;
213                         }
214                         else if(G.vd->dist> 0.001*G.vd->grid) G.vd->dist*=.83333f;
215                 }
216                 else {
217
218                         initgrabz(0.0, 0.0, 0.0);
219                         
220                         if(event==PAD6) window_to_3d(vec, -32, 0);
221                         else if(event==PAD4) window_to_3d(vec, 32, 0);
222                         else if(event==PAD8) window_to_3d(vec, 0, -25);
223                         else if(event==PAD2) window_to_3d(vec, 0, 25);
224                         G.vd->ofs[0]+= vec[0];
225                         G.vd->ofs[1]+= vec[1];
226                         G.vd->ofs[2]+= vec[2];
227                 }
228         }
229         else {
230                 /* Indicate that this view is not inverted.
231                  * Don't do this for PADMINUS/PADPLUSKEY/PAD5, though. (jobbe)*/
232                 if (! ELEM3(event, PADMINUS, PADPLUSKEY, PAD5) )
233                         G.vd->flag2 &= ~V3D_OPP_DIRECTION_NAME;
234                 
235
236                 if(event==PAD7) {
237                         axis_set_view(1.0, 0.0, 0.0, 0.0, 7, perspo);
238                 }
239                 else if(event==PAD1) {
240                         axis_set_view((float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, 1, perspo);
241                 }
242                 else if(event==PAD3) {
243                         axis_set_view(0.5, -0.5, -0.5, -0.5, 3, perspo);
244                 }
245                 else if(event==PADMINUS) {
246                         /* this min and max is also in viewmove() */
247                         if(G.vd->persp==V3D_CAMOB) {
248                                 G.vd->camzoom= MAX2(-30, G.vd->camzoom-5);
249                         }
250                         else if(G.vd->dist<10.0*G.vd->far) {
251                                 getmouseco_areawin(mouseloc);
252                                 view_zoom_mouseloc(VIEW_ZOOM_OUT_FACTOR, mouseloc);
253                         }
254                         if(G.vd->persp!=V3D_PERSP) preview3d_event= 0;
255                 }
256                 else if(event==PADPLUSKEY) {
257                         if(G.vd->persp==V3D_CAMOB) {
258                                 G.vd->camzoom= MIN2(300, G.vd->camzoom+5);
259                         }
260                         else if(G.vd->dist> 0.001*G.vd->grid) {
261                                 getmouseco_areawin(mouseloc);
262                                 view_zoom_mouseloc(VIEW_ZOOM_IN_FACTOR, mouseloc);
263                         }
264                         if(G.vd->persp!=V3D_PERSP) preview3d_event= 0;
265                 }
266                 else if(event==PAD5) {
267                         if (U.smooth_viewtx) {
268                                 if(G.vd->persp==V3D_PERSP) { G.vd->persp=V3D_ORTHO;
269                                 } else if (act_cam_orig) {
270                                         /* were from a camera view */
271                                         float orig_dist= G.vd->dist;
272                                         float orig_lens= G.vd->lens;
273                                         VECCOPY(orig_ofs, G.vd->ofs);
274
275                                         G.vd->persp=V3D_PERSP;
276                                         G.vd->dist= 0.0;
277
278                                         view_settings_from_ob(act_cam_orig, G.vd->ofs, NULL, NULL, &G.vd->lens);
279                                         
280                                         smooth_view(G.vd, orig_ofs, NULL, &orig_dist, &orig_lens);
281                                         
282                                 } else {
283                                         G.vd->persp=V3D_PERSP;
284                                 }
285                         } else {
286                                 if(G.vd->persp==V3D_PERSP) G.vd->persp=V3D_ORTHO;
287                                 else G.vd->persp=V3D_PERSP;
288                         }
289                 }
290                 else if(event==PAD0) {
291                         if(G.qual==LR_ALTKEY) {
292                                 if(oldcamera && is_an_active_object(oldcamera)) {
293                                         G.vd->camera= oldcamera;
294                                 }
295                                 handle_view3d_lock();
296                         }
297                         else if(BASACT) {
298                                 /* check both G.vd as G.scene cameras */
299                                 if(G.qual==LR_CTRLKEY) {
300                                         if(G.vd->camera != OBACT || G.scene->camera != OBACT) {
301                                                 if(G.vd->camera && G.vd->camera->type==OB_CAMERA)
302                                                         oldcamera= G.vd->camera;
303                                                 
304                                                 G.vd->camera= OBACT;
305                                                 handle_view3d_lock();
306                                         }
307                                 }
308                                 else if((G.vd->camera==NULL || G.scene->camera==NULL) && OBACT->type==OB_CAMERA) {
309                                         G.vd->camera= OBACT;
310                                         handle_view3d_lock();
311                                 }
312                         }
313                         if(G.vd->camera==0) {
314                                 G.vd->camera= scene_find_camera(G.scene);
315                                 handle_view3d_lock();
316                         }
317                         
318                         if(G.vd->camera && (G.vd->camera != act_cam_orig)) {
319                                 G.vd->persp= V3D_CAMOB;
320                                 G.vd->view= 0;
321                                 
322                                 if(((G.qual & LR_CTRLKEY) && (G.qual & LR_ALTKEY)) || (G.qual & LR_SHIFTKEY)) {
323                                         void setcameratoview3d(void);   // view.c
324                                         setcameratoview3d();
325                                         autokeyframe_ob_cb_func(G.scene->camera, TFM_TRANSLATION|TFM_ROTATION);
326                                         DAG_object_flush_update(G.scene, G.scene->camera, OB_RECALC_OB);
327                                         BIF_undo_push("View to Camera position");
328                                         allqueue(REDRAWVIEW3D, 0);
329                                 
330                                 } else if (U.smooth_viewtx) {
331                                         /* move 3d view to camera view */
332                                         float orig_lens = G.vd->lens;
333                                         VECCOPY(orig_ofs, G.vd->ofs);
334                                         
335                                         if (act_cam_orig)
336                                                 view_settings_from_ob(act_cam_orig, G.vd->ofs, G.vd->viewquat, &G.vd->dist, &G.vd->lens);
337                                         
338                                         smooth_view_to_camera(G.vd);
339                                         VECCOPY(G.vd->ofs, orig_ofs);
340                                         G.vd->lens = orig_lens;
341                                 }
342                                 
343                         
344                         }
345                 }
346                 else if(event==PAD9) {
347                         countall();
348                         update_for_newframe();
349                         
350                         reset_slowparents();    /* editobject.c */
351                 }
352                 else if(G.vd->persp != V3D_CAMOB) {
353                         if(event==PAD4 || event==PAD6) {
354                                 /* z-axis */
355                                 phi= (float)(M_PI/360.0)*U.pad_rot_angle;
356                                 if(event==PAD6) phi= -phi;
357                                 si= (float)sin(phi);
358                                 q1[0]= (float)cos(phi);
359                                 q1[1]= q1[2]= 0.0;
360                                 q1[3]= si;
361                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
362                                 G.vd->view= 0;
363                         }
364                         if(event==PAD2 || event==PAD8) {
365                                 /* horizontal axis */
366                                 VECCOPY(q1+1, G.vd->viewinv[0]);
367                                 
368                                 Normalize(q1+1);
369                                 phi= (float)(M_PI/360.0)*U.pad_rot_angle;
370                                 if(event==PAD2) phi= -phi;
371                                 si= (float)sin(phi);
372                                 q1[0]= (float)cos(phi);
373                                 q1[1]*= si;
374                                 q1[2]*= si;
375                                 q1[3]*= si;
376                                 QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
377                                 G.vd->view= 0;
378                         }
379                 }
380
381                 if(G.vd->persp != V3D_CAMOB) perspo= G.vd->persp;
382         }
383
384         if(G.vd->depths) G.vd->depths->damaged= 1;
385         retopo_queue_updates(G.vd);
386         
387         if(preview3d_event) 
388                 BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
389         else
390                 BIF_view3d_previewrender_signal(curarea, PR_PROJECTED);
391
392         scrarea_queue_redraw(curarea);
393 }
394
395 int untitled(char * name)
396 {
397         if (G.save_over == 0 ) {
398                 char * c= BLI_last_slash(name);
399                 
400                 if (c)
401                         strcpy(&c[1], "untitled.blend");
402                 else
403                         strcpy(name, "untitled.blend");
404                         
405                 return(TRUE);
406         }
407         
408         return(FALSE);
409 }
410
411 char *recent_filelist(void)
412 {
413         struct RecentFile *recent;
414         int event, i, ofs;
415         char pup[2048], *p;
416
417         p= pup + sprintf(pup, "Open Recent%%t");
418         
419         if (G.sce[0]) {
420                 p+= sprintf(p, "|%s %%x%d", G.sce, 1);
421                 ofs = 1;
422         } else ofs = 0;
423
424         for (recent = G.recent_files.first, i=0; (i<U.recent_files) && (recent); recent = recent->next, i++) {
425                 if (strcmp(recent->filename, G.sce)) {
426                         p+= sprintf(p, "|%s %%x%d", recent->filename, i+ofs+1);
427                 }
428         }
429         event= pupmenu(pup);
430         if(event>0) {
431                 if (ofs && (event==1))
432                         return(G.sce);
433                 else
434                         recent = BLI_findlink(&(G.recent_files), event-1-ofs);
435                         if(recent) return(recent->filename);
436         }
437         
438         return(NULL);
439 }
440
441 int blenderqread(unsigned short event, short val)
442 {
443         /* here do the general keys handling (not screen/window/space) */
444         /* return 0: do not pass on to the other queues */
445         extern int textediting;
446         extern void playback_anim();
447         ScrArea *sa;
448         Object *ob;
449         int textspace=0;
450         /* Changed str and dir size to 160, to make sure there is enough
451          * space for filenames. */
452         char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
453         char *recentfile;
454         
455         if(val==0) return 1;
456         if(event==MOUSEY || event==MOUSEX) return 1;
457         if (G.flags & G_FILE_AUTOPLAY) return 1;
458
459         if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
460         else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
461
462         switch(event) {
463
464         case F1KEY:
465                 if(G.qual==0) {
466                         /* this exception because of the '?' button */
467                         if(curarea->spacetype==SPACE_INFO) {
468                                 sa= closest_bigger_area();
469                                 areawinset(sa->win);
470                         }
471                         
472                         activate_fileselect(FILE_BLENDER, "Open File", G.sce, BIF_read_file);
473                         return 0;
474                 }
475                 else if(G.qual==LR_SHIFTKEY) {
476                         activate_fileselect(FILE_LOADLIB, "Load Library", G.lib, 0);
477                         return 0;
478                 }
479                 else if(G.qual==LR_CTRLKEY) {
480                         activate_imageselect(FILE_LOADLIB, "Load Library", G.lib, 0);
481                         return 0;
482                 }
483                 break;
484         case F2KEY:
485                 if(G.qual==0) {
486                         strcpy(dir, G.sce);
487                         untitled(dir);
488                         activate_fileselect(FILE_BLENDER, "Save File", dir, BIF_write_file);
489                         return 0;
490                 }
491                 else if(G.qual==LR_CTRLKEY) {
492                         write_vrml_fs();
493                         return 0;
494                 }
495                 else if(G.qual==LR_SHIFTKEY) {
496                         write_dxf_fs();
497                         return 0;
498                 }
499                 break;
500         case F3KEY:
501                 if(G.qual==0) {
502                         BIF_save_rendered_image_fs();
503                         return 0;
504                 }
505                 else if(G.qual==LR_SHIFTKEY) {
506                         newspace(curarea, SPACE_NODE);
507                         return 0;
508                 }
509                 else if(G.qual & LR_CTRLKEY) {
510                         BIF_screendump(0);
511                 }
512                 break;
513         case F4KEY:
514                 if(G.qual==LR_SHIFTKEY) {
515
516                         memset(str, 0, 16);
517                         ob= OBACT;
518                         if(ob) strcpy(str, ob->id.name);
519
520                         activate_fileselect(FILE_MAIN, "Data Select", str, NULL);
521                         return 0;
522                 }
523                 else if(G.qual==LR_CTRLKEY) {
524
525                         memset(str, 0, 16);
526                         ob= OBACT;
527                         if(ob) strcpy(str, ob->id.name);
528
529                         activate_imageselect(FILE_MAIN, "Data Select", str, 0);
530                         return 0;
531                 }
532                 else if(G.qual==0) {
533                         extern_set_butspace(event, 1);
534                 }
535                 break;
536         case F5KEY:
537                 if(G.qual==LR_SHIFTKEY) {
538                         newspace(curarea, SPACE_VIEW3D);
539                         return 0;
540                 }
541                 else if(G.qual==0) {
542                         extern_set_butspace(event, 1);
543                 }
544                 break;
545         case F6KEY:
546                 if(G.qual==LR_SHIFTKEY) {
547                         newspace(curarea, SPACE_IPO);
548                         return 0;
549                 }
550                 else if(G.qual==0) {
551                         extern_set_butspace(event, 1);
552                 }
553                 break;
554         case F7KEY:
555                 if(G.qual==LR_SHIFTKEY) {
556                         newspace(curarea, SPACE_BUTS);
557                         return 0;
558                 }
559                 else if(G.qual==0) {
560                         extern_set_butspace(event, 1);
561                 }
562                 break;
563         case F8KEY:
564                 if(G.qual==LR_SHIFTKEY) {
565                         newspace(curarea, SPACE_SEQ);
566                         return 0;
567                 }
568                 else if(G.qual==0) {
569                         extern_set_butspace(event, 1);
570                 }
571                 break;
572         case F9KEY:
573                 if(G.qual==LR_SHIFTKEY) {
574                         newspace(curarea, SPACE_OOPS);
575                         return 0;
576                 }
577                 else if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)) {
578                         newspace(curarea, SPACE_OOPS+256);
579                         return 0;
580                 }
581                 else if(G.qual==0) {
582                         extern_set_butspace(event, 1);
583                 }
584                 break;
585         case F10KEY:
586                 if(G.qual==LR_SHIFTKEY) {
587                         newspace(curarea, SPACE_IMAGE);
588                         return 0;
589                 }
590                 else if(G.qual==0) {
591                         extern_set_butspace(event, 1);
592                 }
593                 break;
594         case F11KEY:
595                 if(G.qual==LR_SHIFTKEY) {
596                         newspace(curarea, SPACE_TEXT);
597                         return 0;
598                 }
599                 else if (G.qual==LR_CTRLKEY) {
600                         playback_anim();
601                 }
602                 else if(G.qual==0) {
603                         BIF_toggle_render_display();
604                         return 0;
605                 }
606                 break;
607         case F12KEY:
608                 if(G.qual==LR_SHIFTKEY) {
609                         newspace(curarea, SPACE_ACTION);
610                         return 0;
611                 }
612                 else if (G.qual==(LR_SHIFTKEY|LR_CTRLKEY)) {
613                         newspace(curarea, SPACE_NLA);
614                         return 0;
615                 }
616                 else if (G.qual==LR_CTRLKEY) {
617                         BIF_do_render(1);
618                 }
619                 else {
620                         /* ctrl/alt + f12 should render too, for some macs have f12 assigned to cd eject */
621                         BIF_do_render(0);
622                 }
623                 return 0;
624                 break;
625         
626         case WHEELUPMOUSE:
627                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
628                         if(CFRA>1) {
629                                 CFRA--;
630                                 update_for_newframe();
631                         }
632                         return 0;
633                 }
634                 break;
635         case WHEELDOWNMOUSE:
636                 if(G.qual==LR_ALTKEY || G.qual==LR_COMMANDKEY) {
637                         CFRA++;
638                         update_for_newframe();
639                         return 0;
640                 }
641                 break;
642                 
643         case LEFTARROWKEY:
644         case DOWNARROWKEY:
645                 if(textediting==0 && textspace==0) {
646
647 #if 0
648 //#ifdef _WIN32 // FULLSCREEN
649                         if(event==DOWNARROWKEY){
650                                 if (G.qual==LR_ALTKEY)
651                                         mainwindow_toggle_fullscreen(0);
652                                 else if(G.qual==0)
653                                         CFRA-= G.scene->jumpframe;
654                         }
655 #else
656                         if((event==DOWNARROWKEY)&&(G.qual==0))
657                                 CFRA-= G.scene->jumpframe;
658 #endif
659                         else if((event==LEFTARROWKEY)&&(G.qual==0))
660                                 CFRA--;
661                         
662                         if(G.qual==LR_SHIFTKEY)
663                                 CFRA= PSFRA;
664                         if(CFRA<1) CFRA=1;
665         
666                         update_for_newframe();
667                         return 0;
668                 }
669                 break;
670
671         case RIGHTARROWKEY:
672         case UPARROWKEY:
673                 if(textediting==0 && textspace==0) {
674
675 #if 0
676 //#ifdef _WIN32 // FULLSCREEN
677                         if(event==UPARROWKEY){ 
678                                 if(G.qual==LR_ALTKEY)
679                                         mainwindow_toggle_fullscreen(1);
680                                 else if(G.qual==0)
681                                         CFRA+= G.scene->jumpframe;
682                         }
683 #else
684                         if((event==UPARROWKEY)&&(G.qual==0))
685                                 CFRA+= G.scene->jumpframe;
686 #endif
687                         else if((event==RIGHTARROWKEY)&&(G.qual==0))
688                                 CFRA++;
689
690                         if(G.qual==LR_SHIFTKEY)
691                                 CFRA= PEFRA;
692                         
693                         update_for_newframe();
694                 }
695                 break;
696
697         case ESCKEY:
698                 sound_stop_all_sounds();        // whats this?
699                 
700                 /* stop playback on ESC always */
701                 rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
702                 audiostream_stop();
703                 BKE_ptcache_set_continue_physics(0);
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                         if(!(G.f & G_PARTICLEEDIT))
747                                 exit_paint_modes();
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 */