Two in one:
[blender.git] / source / blender / src / toets.c
index 9c3957a6fab7f5960b8532549558f01b7a79ea2e..355a1535f42dac2242a6241bf76e74cf9f431199 100644 (file)
@@ -79,6 +79,7 @@
 #include "BIF_poseobject.h"
 #include "BIF_previewrender.h"
 #include "BIF_renderwin.h"
+#include "BIF_retopo.h"
 #include "BIF_screen.h"
 #include "BIF_space.h"
 #include "BIF_toets.h"
@@ -86,6 +87,7 @@
 #include "BIF_usiblender.h"
 #include "BIF_writeimage.h"
 
+#include "BDR_sculptmode.h"
 #include "BDR_vpaint.h"
 #include "BDR_editobject.h"
 #include "BDR_editface.h"
@@ -138,6 +140,12 @@ void persptoetsen(unsigned short event)
                }
        }
        else if((G.qual & (LR_SHIFTKEY | LR_CTRLKEY)) && (event != PAD0)) {
+               
+               /* Indicate that this view is inverted,
+                * but only if it actually _was_ inverted (jobbe) */
+               if (event==PAD7 || event == PAD1 || event == PAD3)
+                       G.vd->flag2 |= V3D_OPP_DIRECTION_NAME;
+               
                if(event==PAD0) {
                        /* G.vd->persp= 3; */
                }
@@ -197,6 +205,11 @@ void persptoetsen(unsigned short event)
                }
        }
        else {
+               /* Indicate that this view is not inverted.
+                * Don't do this for PADMINUS/PADPLUSKEY, though. (jobbe)*/
+               if (event != PADMINUS && event != PADPLUSKEY)
+                       G.vd->flag2 &= ~V3D_OPP_DIRECTION_NAME;
+               
 
                if(event==PAD7) {
                        G.vd->viewquat[0]= 1.0;
@@ -253,8 +266,9 @@ void persptoetsen(unsigned short event)
                                handle_view3d_lock();
                        }
                        else if(BASACT) {
+                               /* check both G.vd as G.scene cameras */
                                if(G.qual==LR_CTRLKEY) {
-                                       if(G.vd->camera != OBACT) {
+                                       if(G.vd->camera != OBACT || G.scene->camera != OBACT) {
                                                if(G.vd->camera && G.vd->camera->type==OB_CAMERA)
                                                        oldcamera= G.vd->camera;
                                                
@@ -262,7 +276,7 @@ void persptoetsen(unsigned short event)
                                                handle_view3d_lock();
                                        }
                                }
-                               else if(G.vd->camera==0 && OBACT->type==OB_CAMERA) {
+                               else if((G.vd->camera==NULL || G.scene->camera==NULL) && OBACT->type==OB_CAMERA) {
                                        G.vd->camera= OBACT;
                                        handle_view3d_lock();
                                }
@@ -279,6 +293,7 @@ void persptoetsen(unsigned short event)
                                        void setcameratoview3d(void);   // view.c
                                        setcameratoview3d();
                                        DAG_object_flush_update(G.scene, G.scene->camera, OB_RECALC_OB);
+                                       BIF_undo_push("View to Camera position");
                                        allqueue(REDRAWVIEW3D, 0);
                                }                               
                        }
@@ -292,7 +307,7 @@ void persptoetsen(unsigned short event)
                else if(G.vd->persp<2) {
                        if(event==PAD4 || event==PAD6) {
                                /* z-axis */
-                               phi= (float)(M_PI/24.0);
+                               phi= (float)(M_PI/360.0)*U.pad_rot_angle;
                                if(event==PAD6) phi= -phi;
                                si= (float)sin(phi);
                                q1[0]= (float)cos(phi);
@@ -307,7 +322,7 @@ void persptoetsen(unsigned short event)
                                VECCOPY(q1+1, G.vd->viewinv[0]);
                                
                                Normalise(q1+1);
-                               phi= (float)(M_PI/24.0);
+                               phi= (float)(M_PI/360.0)*U.pad_rot_angle;
                                if(event==PAD2) phi= -phi;
                                si= (float)sin(phi);
                                q1[0]= (float)cos(phi);
@@ -321,6 +336,8 @@ void persptoetsen(unsigned short event)
 
                if(G.vd->persp<2) perspo= G.vd->persp;
        }
+
+       retopo_force_update();
        
        if(preview3d_event) 
                BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
@@ -346,6 +363,35 @@ int untitled(char * name)
        return(FALSE);
 }
 
+char *recent_filelist(void)
+{
+       struct RecentFile *recent;
+       int event, i, ofs;
+       char pup[2048], *p;
+
+       p= pup + sprintf(pup, "Open Recent%%t");
+       
+       if (G.sce[0]) {
+               p+= sprintf(p, "|%s %%x%d", G.sce, 1);
+               ofs = 1;
+       } else ofs = 0;
+
+       for (recent = G.recent_files.first, i=0; (i<10) && (recent); recent = recent->next, i++) {
+               if (strcmp(recent->filename, G.sce)) {
+                       p+= sprintf(p, "|%s %%x%d", recent->filename, i+ofs+1);
+               }
+       }
+       event= pupmenu(pup);
+       if(event>0) {
+               if (ofs && (event==1))
+                       return(G.sce);
+               else
+                       recent = BLI_findlink(&(G.recent_files), event-1-ofs);
+                       if(recent) return(recent->filename);
+       }
+       
+       return(NULL);
+}
 
 int blenderqread(unsigned short event, short val)
 {
@@ -359,6 +405,7 @@ int blenderqread(unsigned short event, short val)
        /* Changed str and dir size to 160, to make sure there is enough
         * space for filenames. */
        char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
+       char *recentfile;
        
        if(val==0) return 1;
        if(event==MOUSEY || event==MOUSEX) return 1;
@@ -406,8 +453,11 @@ int blenderqread(unsigned short event, short val)
                        BIF_save_rendered_image_fs();
                        return 0;
                }
+               else if(G.qual==LR_SHIFTKEY) {
+                       newspace(curarea, SPACE_NODE);
+                       return 0;
+               }
                else if(G.qual & LR_CTRLKEY) {
-                       /* all alt+ctrl+shift combos are needed here... */
                        BIF_screendump(0);
                }
                break;
@@ -418,11 +468,11 @@ int blenderqread(unsigned short event, short val)
                        ob= OBACT;
                        if(ob) strcpy(str, ob->id.name);
 
-                       activate_fileselect(FILE_MAIN, "Data Select", str, 0);
+                       activate_fileselect(FILE_MAIN, "Data Select", str, NULL);
                        return 0;
                }
                else if(G.qual==0) {
-                       extern_set_butspace(event);
+                       extern_set_butspace(event, 1);
                }
                break;
        case F5KEY:
@@ -431,7 +481,7 @@ int blenderqread(unsigned short event, short val)
                        return 0;
                }
                else if(G.qual==0) {
-                       extern_set_butspace(event);
+                       extern_set_butspace(event, 1);
                }
                break;
        case F6KEY:
@@ -440,7 +490,7 @@ int blenderqread(unsigned short event, short val)
                        return 0;
                }
                else if(G.qual==0) {
-                       extern_set_butspace(event);
+                       extern_set_butspace(event, 1);
                }
                break;
        case F7KEY:
@@ -449,7 +499,7 @@ int blenderqread(unsigned short event, short val)
                        return 0;
                }
                else if(G.qual==0) {
-                       extern_set_butspace(event);
+                       extern_set_butspace(event, 1);
                }
                break;
        case F8KEY:
@@ -458,7 +508,7 @@ int blenderqread(unsigned short event, short val)
                        return 0;
                }
                else if(G.qual==0) {
-                       extern_set_butspace(event);
+                       extern_set_butspace(event, 1);
                }
                break;
        case F9KEY:
@@ -471,7 +521,7 @@ int blenderqread(unsigned short event, short val)
                        return 0;
                }
                else if(G.qual==0) {
-                       extern_set_butspace(event);
+                       extern_set_butspace(event, 1);
                }
                break;
        case F10KEY:
@@ -480,7 +530,7 @@ int blenderqread(unsigned short event, short val)
                        return 0;
                }
                else if(G.qual==0) {
-                       extern_set_butspace(event);
+                       extern_set_butspace(event, 1);
                }
                break;
        case F11KEY:
@@ -542,11 +592,11 @@ int blenderqread(unsigned short event, short val)
                                if (G.qual==LR_ALTKEY)
                                        mainwindow_toggle_fullscreen(0);
                                else if(G.qual==0)
-                                       CFRA-= 10;
+                                       CFRA-= G.scene->jumpframe;
                        }
 #else
                        if((event==DOWNARROWKEY)&&(G.qual==0))
-                               CFRA-= 10;
+                               CFRA-= G.scene->jumpframe;
 #endif
                        else if((event==LEFTARROWKEY)&&(G.qual==0))
                                CFRA--;
@@ -570,11 +620,11 @@ int blenderqread(unsigned short event, short val)
                                if(G.qual==LR_ALTKEY)
                                        mainwindow_toggle_fullscreen(1);
                                else if(G.qual==0)
-                                       CFRA+= 10;
+                                       CFRA+= G.scene->jumpframe;
                        }
 #else
                        if((event==UPARROWKEY)&&(G.qual==0))
-                               CFRA+= 10;
+                               CFRA+= G.scene->jumpframe;
 #endif
                        else if((event==RIGHTARROWKEY)&&(G.qual==0))
                                CFRA++;
@@ -607,11 +657,11 @@ int blenderqread(unsigned short event, short val)
                                else if(G.vd) {
                                        /* also when Alt-E */
                                        if(G.obedit==NULL) {
-                                               enter_editmode();
+                                               enter_editmode(EM_WAITCURSOR);
                                                if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
                                        }
                                        else
-                                               exit_editmode(2); // freedata, and undo
+                                               exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); // freedata, and undo
                                }
                                return 0;
                        }
@@ -625,25 +675,12 @@ int blenderqread(unsigned short event, short val)
                                }
                                else if(ob->type==OB_MESH) {
                                        if(ob==G.obedit) EM_selectmode_menu();
+                                       else if(G.f & G_SCULPTMODE)
+                                               sculptmode_selectbrush_menu();
                                        else set_wpaint();
                                }
                        }
                }
-               else if(G.qual==LR_SHIFTKEY) {  // ??
-                       if(G.obedit)
-                               exit_editmode(2); // freedata, and undo
-                       if(G.f & G_FACESELECT)
-                               set_faceselect();
-                       if(G.f & G_VERTEXPAINT)
-                               set_vpaint();
-                       if(G.f & G_TEXTUREPAINT) {
-                               G.f &= ~G_TEXTUREPAINT;
-                               allqueue(REDRAWVIEW3D, 0);
-                               allqueue(REDRAWBUTSEDIT, 0);
-                       }
-                       if(G.f & G_WEIGHTPAINT)
-                               set_wpaint();
-               }
                break;
 
        case BACKSPACEKEY:
@@ -665,18 +702,19 @@ int blenderqread(unsigned short event, short val)
                if(G.qual==LR_ALTKEY) {
                        if(G.vd && textspace==0) {
                                if(G.obedit==0) {
-                                       enter_editmode();
+                                       enter_editmode(EM_WAITCURSOR);
                                        BIF_undo_push("Original");
                                }
                                else
-                                       exit_editmode(2); // freedata, and undo
+                                       exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); // freedata, and undo
                                return 0;
                        }                       
                }
                break;
        case IKEY:
-               if(textediting==0 && textspace==0 && curarea->spacetype!=SPACE_FILE && curarea->spacetype!=SPACE_IMASEL) {
-                       if(G.qual==0) {
+               if(textediting==0 && textspace==0 && !ELEM3(curarea->spacetype, SPACE_FILE, SPACE_IMASEL, SPACE_NODE)) {
+                       if(G.f & G_SCULPTMODE) return 1;
+                       else if(G.qual==0) {
                                common_insertkey();
                                return 0;
                        }
@@ -684,7 +722,6 @@ int blenderqread(unsigned short event, short val)
                break;
        case JKEY:
                if(textediting==0 && textspace==0) {
-                       /* NEED CHECK FOR RENDER WINDOW HERE */
                        if (G.qual==0) {
                                BIF_swap_render_rects();
                                return 0;
@@ -713,14 +750,9 @@ int blenderqread(unsigned short event, short val)
        case OKEY:
                if(textediting==0) {
                        if(G.qual==LR_CTRLKEY) {
-                               /* There seem to be crashes here sometimes.... String
-                                * bound overwrites? I changed dir and str sizes,
-                                * let's see if this reoccurs. */
-                               sprintf(str, "Open file: %s", G.sce);
-                       
-                               if(okee(str)) {
-                                       strcpy(dir, G.sce);
-                                       BIF_read_file(dir);
+                               recentfile = recent_filelist();
+                               if(recentfile) {
+                                       BIF_read_file(recentfile);
                                }
                                return 0;
                        }
@@ -749,6 +781,8 @@ int blenderqread(unsigned short event, short val)
                        int a;
                        double delta, stime;
 
+                       if (event < 0) return 0; /* cancelled by user */
+
                        waitcursor(1);
                        
                        stime= PIL_check_seconds_timer();
@@ -839,6 +873,7 @@ int blenderqread(unsigned short event, short val)
                        }
                        else if(G.qual==LR_ALTKEY) {
                                write_videoscape_fs();
+                               return 0;
                        }
                }
                break;