Made weight-painting more bearable :)
[blender.git] / source / blender / src / toets.c
index 81270c9f846eb346dd19b74ded04ec526c964f30..d1b0844647e4c8a65e53736c3ac1df4ecfcac59c 100644 (file)
 #include <string.h>
 #include <math.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifdef WIN32
 #include "BLI_winstuff.h"
 #endif
 #include "DNA_view3d_types.h"
 #include "DNA_userdef_types.h"
 
-#include "BKE_utildefines.h"
-#include "BKE_global.h"
+#include "BKE_action.h"
 #include "BKE_anim.h"
-#include "BKE_scene.h"
+#include "BKE_blender.h"
+#include "BKE_depsgraph.h"
+#include "BKE_displist.h"
+#include "BKE_global.h"
 #include "BKE_ipo.h"
-#include "BKE_action.h"
-#include "BKE_ika.h"
 #include "BKE_key.h"
-#include "BKE_displist.h"
+#include "BKE_scene.h"
+#include "BKE_utildefines.h"
 
-#include "BIF_interface.h"
-#include "BIF_screen.h"
-#include "BIF_space.h"
 #include "BIF_butspace.h"
-#include "BIF_renderwin.h"
-#include "BIF_toolbox.h"
-#include "BIF_toets.h"
 #include "BIF_editseq.h"
 #include "BIF_editsound.h"
+#include "BIF_editmesh.h"
+#include "BIF_interface.h"
 #include "BIF_poseobject.h"
+#include "BIF_renderwin.h"
+#include "BKE_object.h"
+#include "BIF_screen.h"
+#include "BIF_space.h"
+#include "BIF_toets.h"
+#include "BIF_toolbox.h"
 #include "BIF_usiblender.h"
 
 #include "BDR_vpaint.h"
 #include "BSE_edit.h"
 #include "BSE_editipo.h"
 #include "BSE_headerbuttons.h"
+#include "BSE_seqaudio.h"
 
 #include "blendef.h"
-#include "render.h"
+#include "render.h"            // darn schrijfplaatje() (ton)
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
 #include "BIF_poseobject.h"
 
-/* only used in toets.c */
+/* only used in toets.c and initrender.c */
 /* this function doesn't really belong here */
 /* ripped from render module */
 void schrijfplaatje(char *name);
 
 
-void write_imag(char *name)
+static void write_imag(char *name)
 {
        /* from file select */
        char str[256];
@@ -175,6 +175,7 @@ void schrijfplaatje(char *name)
 
        if(ibuf) {
                ibuf->rect= (unsigned int *) R.rectot;
+//             ibuf->rect_float = R.rectftot;
 
                if(R.r.planes == 8) IMB_cspace(ibuf, rgb_to_bw);
 
@@ -400,7 +401,7 @@ void persptoetsen(unsigned short event)
                        if(G.vd->camera) {
                                G.vd->persp= 2;
                                G.vd->view= 0;
-                               if(G.qual & LR_SHIFTKEY) {
+                               if(((G.qual & LR_CTRLKEY) && (G.qual & LR_ALTKEY)) || (G.qual & LR_SHIFTKEY)) {
                                        void setcameratoview3d(void);   // view.c
                                        setcameratoview3d();
                                }                               
@@ -408,11 +409,7 @@ void persptoetsen(unsigned short event)
                }
                else if(event==PAD9) {
                        countall();
-                       do_all_ipos();
-                       do_all_keys();
-                       do_all_actions();
-                       do_all_ikas();
-                       test_all_displists();
+                       update_for_newframe();
                        
                        reset_slowparents();    /* editobject.c */
                }
@@ -532,7 +529,7 @@ int blenderqread(unsigned short event, short val)
        
        if(val==0) return 1;
        if(event==MOUSEY || event==MOUSEX) return 1;
-       if (G.flags & G_FLAGS_AUTOPLAY) return 1;
+       if (G.flags & G_FILE_AUTOPLAY) return 1;
 
        if (curarea && curarea->spacetype==SPACE_TEXT) textspace= 1;
        else if (curarea && curarea->spacetype==SPACE_SCRIPT) textspace= 1;
@@ -578,7 +575,7 @@ int blenderqread(unsigned short event, short val)
                }
                else if(G.qual & LR_CTRLKEY) {
                        /* all alt+ctrl+shift combos are needed here... */
-                       BIF_screendump();
+                       BIF_screendump(0);
                }
                break;
        case F4KEY:
@@ -636,6 +633,10 @@ int blenderqread(unsigned short event, short val)
                        newspace(curarea, SPACE_OOPS);
                        return 0;
                }
+               else if(G.qual==(LR_SHIFTKEY|LR_ALTKEY)) {
+                       newspace(curarea, SPACE_OOPS+256);
+                       return 0;
+               }
                else if(G.qual==0) {
                        extern_set_butspace(event);
                }
@@ -679,7 +680,8 @@ int blenderqread(unsigned short event, short val)
        case DOWNARROWKEY:
                if(textediting==0 && textspace==0) {
 
-#ifdef _WIN32  // FULLSCREEN
+#if 0
+//#ifdef _WIN32        // FULLSCREEN
                        if(event==DOWNARROWKEY){
                                if (G.qual==LR_ALTKEY)
                                        mainwindow_toggle_fullscreen(0);
@@ -706,7 +708,8 @@ int blenderqread(unsigned short event, short val)
        case UPARROWKEY:
                if(textediting==0 && textspace==0) {
 
-#ifdef _WIN32  // FULLSCREEN
+#if 0
+//#ifdef _WIN32        // FULLSCREEN
                        if(event==UPARROWKEY){ 
                                if(G.qual==LR_ALTKEY)
                                        mainwindow_toggle_fullscreen(1);
@@ -728,7 +731,13 @@ int blenderqread(unsigned short event, short val)
                break;
 
        case ESCKEY:
-               sound_stop_all_sounds();
+               sound_stop_all_sounds();        // whats this?
+               
+               /* stop playback on ESC always */
+               rem_screenhandler(G.curscreen, SCREEN_HANDLER_ANIM);
+               audiostream_stop();
+               allqueue(REDRAWALL, 0);
+               
                break;
        case TABKEY:
                if(G.qual==0) {
@@ -739,25 +748,32 @@ int blenderqread(unsigned short event, short val)
                                        enter_meta();
                                else if(G.vd) {
                                        /* also when Alt-E */
-                                       if(G.obedit==0)
+                                       if(G.obedit==NULL) {
                                                enter_editmode();
+                                               if(G.obedit) BIF_undo_push("Original"); // here, because all over code enter_editmode is abused
+                                       }
                                        else
-                                               exit_editmode(1);
+                                               exit_editmode(2); // freedata, and undo
                                }
                                return 0;
                        }
                }
                else if(G.qual==LR_CTRLKEY){
-                       if(G.obpose)
-                               exit_posemode(1);
-                       else
-                               enter_posemode();
-                       allqueue(REDRAWHEADERS, 0);     
-                       allqueue(REDRAWBUTSALL, 0);     
+                       Object *ob= OBACT;
+                       if(ob) {
+                               if(ob->type==OB_ARMATURE) {
+                                       if(ob->flag & OB_POSEMODE) exit_posemode();
+                                       else enter_posemode();
+                               }
+                               else if(ob->type==OB_MESH) {
+                                       if(ob==G.obedit) EM_selectmode_menu();
+                                       else set_wpaint();
+                               }
+                       }
                }
-               else if(G.qual==LR_SHIFTKEY) {
+               else if(G.qual==LR_SHIFTKEY) {  // ??
                        if(G.obedit)
-                               exit_editmode(1);
+                               exit_editmode(2); // freedata, and undo
                        if(G.f & G_FACESELECT)
                                set_faceselect();
                        if(G.f & G_VERTEXPAINT)
@@ -769,8 +785,6 @@ int blenderqread(unsigned short event, short val)
                        }
                        if(G.f & G_WEIGHTPAINT)
                                set_wpaint();
-                       if(G.obpose)
-                               exit_posemode(1);
                }
                break;
 
@@ -792,10 +806,12 @@ int blenderqread(unsigned short event, short val)
        case EKEY:
                if(G.qual==LR_ALTKEY) {
                        if(G.vd && textspace==0) {
-                               if(G.obedit==0)
+                               if(G.obedit==0) {
                                        enter_editmode();
+                                       BIF_undo_push("Original");
+                               }
                                else
-                                       exit_editmode(1);
+                                       exit_editmode(2); // freedata, and undo
                                return 0;
                        }                       
                }
@@ -853,7 +869,7 @@ int blenderqread(unsigned short event, short val)
                break;
                
        case SKEY:
-               if(G.obpose==0 && G.obedit==0) {
+               if(G.obedit==NULL) {
                        if(G.qual==LR_CTRLKEY) {
                                strcpy(dir, G.sce);
                                if (untitled(dir)) {
@@ -869,6 +885,8 @@ int blenderqread(unsigned short event, short val)
        
        case TKEY:
                if (G.qual==(LR_SHIFTKEY|LR_ALTKEY|LR_CTRLKEY)) {
+                       Object *ob = OBACT;
+                       int event = pupmenu(ob?"Time%t|draw|recalc ob|recalc data":"Time%t|draw");
                        int a;
                        double delta, stime;
 
@@ -876,19 +894,27 @@ int blenderqread(unsigned short event, short val)
                        
                        stime= PIL_check_seconds_timer();
                        for(a=0; a<100000; a++) {
-                               scrarea_do_windraw(curarea);
+                               if (event==1) {
+                                       scrarea_do_windraw(curarea);
+                               } else if (event==2) {
+                                       ob->recalc |= OB_RECALC_OB;
+                                       object_handle_update(ob);
+                               } else if (event==3) {
+                                       ob->recalc |= OB_RECALC_DATA;
+                                       object_handle_update(ob);
+                               }
 
                                delta= PIL_check_seconds_timer()-stime;
                                if (delta>5.0) break;
                        }
                        
                        waitcursor(0);
-                       notice("FPS: %f (%d iterations)", a/delta, a);
+                       notice("%8.6f s/op - %6.2f ops/s - %d iterations", delta/a, a/delta, a);
                        return 0;
                }
                else if(G.qual==(LR_ALTKEY|LR_CTRLKEY)) {
                        int a;
-                       int event= pupmenu("10 Timer%t|draw|draw+swap|displist|undo");
+                       int event= pupmenu("10 Timer%t|draw|draw+swap|undo");
                        if(event>0) {
                                double stime= PIL_check_seconds_timer();
                                char tmpstr[128];
@@ -902,14 +928,9 @@ int blenderqread(unsigned short event, short val)
                                        } else if (event==2) {
                                                scrarea_do_windraw(curarea);
                                                screen_swapbuffers();
-                                       } else if (event==3) {
-                                               if (OBACT) {
-                                                       makeDispList(OBACT);
-                                               }
                                        }
-                                       else if(event==4) {
-                                               extern void BIF_write_undo(char *name);
-                                               BIF_write_undo("10 timer");
+                                       else if(event==3) {
+                                               BKE_write_undo("10 timer");
                                        }
                                }
                        
@@ -936,6 +957,12 @@ int blenderqread(unsigned short event, short val)
                                }
                                return 0;
                        }
+                       else if(G.qual==LR_ALTKEY) {
+                               if(curarea->spacetype!=SPACE_TEXT) {
+                                       BIF_undo_menu();
+                                       return 0;
+                               }
+                       }
                }
                break;
                
@@ -958,7 +985,7 @@ int blenderqread(unsigned short event, short val)
                break;
                
        case XKEY:
-               if(textspace==0) {
+               if(textspace==0 && textediting==0) {
                        if(G.qual==LR_CTRLKEY) {
                                if(okee("Erase all")) {
                                        if( BIF_read_homefile()==0) error("No file ~/.B.blend");
@@ -967,6 +994,23 @@ int blenderqread(unsigned short event, short val)
                        }
                }
                break;
+       case YKEY:      // redo alternative
+               if(textspace==0) {
+                       if(G.qual==LR_CTRLKEY) {
+                               BIF_redo(); 
+                               return 0;
+                       }
+               }
+               break;
+       case ZKEY:      // undo
+               if(textspace==0) {
+                       if(G.qual & (LR_CTRLKEY|LR_COMMANDKEY)) { // all combos with ctrl/commandkey are accepted
+                               if ELEM(G.qual, LR_CTRLKEY, LR_COMMANDKEY) BIF_undo();
+                               else BIF_redo(); // all combos with ctrl is redo
+                               return 0;
+                       }
+               }
+               break; 
        }
        
        return 1;