Tuesday merger of bf-blender into orange branch.
[blender-staging.git] / source / blender / src / space.c
index b1dbc61e9696807bc9bb0c9a31579a07d4cdad52..f2ef4cbd5665fdbe75899f7955f66a43be2b36dc 100644 (file)
 #include "DNA_view3d_types.h"
 
 #include "BKE_blender.h"
+#include "BKE_colortools.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_displist.h"
 #include "BKE_global.h"
 #include "BKE_ipo.h"
 #include "BKE_main.h"
+#include "BKE_node.h"
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
@@ -89,6 +91,7 @@
 #include "BIF_editarmature.h"
 #include "BIF_editconstraint.h"
 #include "BIF_editfont.h"
+#include "BIF_editgroup.h"
 #include "BIF_editkey.h"
 #include "BIF_editlattice.h"
 #include "BIF_editmesh.h"
@@ -580,8 +583,32 @@ static void select_parent(void)    /* Makes parent active and de-selected OBACT */
        }
 }
 
+void select_grouped(short nr)
+{
+       Base *base;
+       
+       if(nr==4) {
+               base= FIRSTBASE;
+               while(base) {
+                       if (base->lay & OBACT->lay) {
+                               base->flag |= SELECT;
+                               base->object->flag |= SELECT;
+                       }
+                       base= base->next;
+               }               
+       }
+       else if(nr==2) select_children(OBACT, 0);
+       else if(nr==1) select_children(OBACT, 1);
+       else if(nr==3) select_parent();
+       
+       countall();
+       allqueue(REDRAWVIEW3D, 0);
+       allqueue(REDRAWBUTSOBJECT, 0);
+       allspace(REMAKEIPO, 0);
+       allqueue(REDRAWIPO, 0);
+}
 
-void select_group_menu(void)
+static void select_grouped_menu(void)
 {
        char *str;
        short nr;
@@ -598,7 +625,7 @@ void select_group_menu(void)
        nr= pupmenu(str);
        MEM_freeN(str);
        
-       select_group(nr);
+       select_grouped(nr);
 }
 
 void join_menu(void)
@@ -622,36 +649,6 @@ void join_menu(void)
        }
 }
 
-void select_group(short nr)
-{
-       Base *base;
-
-       if(nr==4) {
-               base= FIRSTBASE;
-               while(base) {
-                       if (base->lay & OBACT->lay) {
-                               base->flag |= SELECT;
-                               base->object->flag |= SELECT;
-                       }
-                       base= base->next;
-               }               
-       }
-       else if(nr==2) select_children(OBACT, 0);
-       else if(nr==1) select_children(OBACT, 1);
-       else if(nr==3) select_parent();
-       
-       countall();
-       allqueue(REDRAWVIEW3D, 0);
-       allqueue(REDRAWBUTSOBJECT, 0);
-       allspace(REMAKEIPO, 0);
-       allqueue(REDRAWIPO, 0);
-}
-
-
-
-
-
-
 static unsigned short convert_for_nonumpad(unsigned short event)
 {
        if (event>=ZEROKEY && event<=NINEKEY) {
@@ -708,7 +705,10 @@ void BIF_undo(void)
                else if(curarea->spacetype==SPACE_IMAGE && (G.sima->flag & SI_DRAWTOOL));
                else {
                        /* now also in faceselect mode */
-                       if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(1);
+                       if(U.uiflag & USER_GLOBALUNDO) {
+                               BKE_undo_step(1);
+                               sound_initialize_sounds();
+                       }
                }
        }
 }
@@ -726,7 +726,10 @@ void BIF_redo(void)
                        vpaint_undo();
                else {
                        /* includes faceselect now */
-                       if(U.uiflag & USER_GLOBALUNDO) BKE_undo_step(-1);
+                       if(U.uiflag & USER_GLOBALUNDO) {
+                               BKE_undo_step(-1);
+                               sound_initialize_sounds();
+                       }
                }
        }
 }
@@ -1272,6 +1275,11 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                        edge_flip();
                                                else if (G.qual==0)
                                                        addedgeface_mesh();
+                                               else if ( G.qual == 
+                                                        (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                                       select_linked_flat_faces();
+                                               }
+
                                        }
                                        else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addsegment_nurb();
                                }
@@ -1291,10 +1299,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                                break;
                        case GKEY:
-                               /* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
-                               else if(G.qual & LR_ALTKEY) rem_selected_from_group(); */
-                               if((G.qual==LR_SHIFTKEY))
-                                       select_group_menu();
+                               if(G.qual & LR_CTRLKEY) group_operation_with_menu();
+                               else if((G.qual==LR_SHIFTKEY))
+                                       select_grouped_menu();
                                else if(G.qual==LR_ALTKEY) {
                                        if(okee("Clear location")) {
                                                clear_object('g');
@@ -1484,7 +1491,10 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        mirrormenu();
                                }
                                else if(G.qual==0) {
-                                    movetolayer();
+                                       if(ob && (ob->flag & OB_POSEMODE))
+                                               pose_movetolayer();
+                                       else
+                                               movetolayer();
                                }
                                break;
                        case NKEY:
@@ -1650,7 +1660,9 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                                initTransform(TFM_TOSPHERE, CTX_NONE);
                                                Transform();
                                        }
-                                       
+                                       if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                                               if(G.obedit->type==OB_MESH) select_sharp_edges();
+                                       }
                                }
                                else if(G.qual==LR_ALTKEY) {
                                        if(G.f & G_WEIGHTPAINT)
@@ -2260,7 +2272,7 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
 
        /* main choices pup */
        uiDefButS(block, MENU, B_CHANGE_THEME, "UI and Buttons %x1|%l|3D View %x2|%l|Ipo Curve Editor %x3|Action Editor %x4|"
-               "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Timeline %x15|Audio Window %x8|Text Editor %x9|%l|User Preferences %x10|"
+               "NLA Editor %x5|%l|UV/Image Editor %x6|Video Sequence Editor %x7|Node Editor %x16|Timeline %x15|Audio Window %x8|Text Editor %x9|%l|User Preferences %x10|"
                "Outliner %x11|Buttons Window %x12|%l|File Browser %x13|Image Browser %x14",
                                                                                                        255,y2,200,20, &curmain, 0, 0, 0, 0, "Specify theme for...");
        if(curmain==1) spacetype= 0;
@@ -2278,6 +2290,7 @@ static void info_user_themebuts(uiBlock *block, short y1, short y2, short y3)
        else if(curmain==13) spacetype= SPACE_FILE;
        else if(curmain==14) spacetype= SPACE_IMASEL;
        else if(curmain==15) spacetype= SPACE_TIME;
+       else if(curmain==16) spacetype= SPACE_NODE;
        else return; // only needed while coding... when adding themes for more windows
        
        /* color choices pup */
@@ -2696,10 +2709,15 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                uiDefBut(block, LABEL,0,"Auto keyframe",
                        (xpos+(2*edgsp)+(2*mpref)+midsp),y3label,mpref,buth,
                        0, 0, 0, 0, 0, "");
+
                uiDefButBitI(block, TOG, G_RECORDKEYS, REDRAWTIME, "Action and Object", 
                                        (xpos+edgsp+(2*mpref)+(2*midsp)),y2,mpref, buth,
                                         &(G.flags), 0, 0, 0, 0, "Automatic keyframe insertion in Object and Action Ipo curves");
 
+               uiDefButBitI(block, TOG, USER_KEYINSERTAVAI, REDRAWTIME, "Available", 
+                       (xpos+edgsp+(2*mpref)+(2*midsp)),y1,mpref, buth,
+                       &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in available curves");
+
 //             uiDefButBitS(block, TOG, USER_KEYINSERTACT, 0, "Action",
 //                     (xpos+edgsp+(2*mpref)+(2*midsp)),y2,(spref+edgsp),buth,
 //                     &(U.uiflag), 0, 0, 0, 0, "Automatic keyframe insertion in Action Ipo curve");
@@ -3228,7 +3246,7 @@ static void winqreadbutspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        scrarea_queue_winredraw(curarea);
                        break;
                case RENDERPREVIEW:
-                       BIF_previewrender(sbuts);
+                       BIF_previewrender_buts(sbuts);
                        break;
                
                case HOMEKEY:
@@ -3313,6 +3331,8 @@ static void init_butspace(ScrArea *sa)
        /* set_rects only does defaults, so after reading a file the cur has not changed */
        set_rects_butspace(buts);
        buts->v2d.cur= buts->v2d.tot;
+
+       buts->ri = NULL;
 }
 
 void extern_set_butspace(int fkey)
@@ -3373,11 +3393,12 @@ void extern_set_butspace(int fkey)
                        sbuts->mainb= CONTEXT_SHADING;
                        sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
                }
-               
+               BIF_preview_changed(ID_TE);
        }
        else if(fkey==F6KEY) {
                sbuts->mainb= CONTEXT_SHADING;
                sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
+               BIF_preview_changed(ID_TE);
        }
        else if(fkey==F7KEY) {
                /* if it's already in object context, cycle between tabs with the same key */
@@ -3414,7 +3435,6 @@ void extern_set_butspace(int fkey)
 
        scrarea_queue_headredraw(sa);
        scrarea_queue_winredraw(sa);
-       BIF_preview_changed(sbuts);
 }
 
 /* ******************** SPACE: SEQUENCE ********************** */
@@ -3879,8 +3899,16 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                /* Draw tool is inactive */
                switch(event) {
                        case LEFTMOUSE:
-                               if(G.qual & LR_SHIFTKEY) mouseco_to_curtile();
-                               else gesture();
+                               if(G.qual & LR_SHIFTKEY) {
+                                       if(G.sima->image && G.sima->image->tpageflag & IMA_TILES)
+                                               mouseco_to_curtile();
+                                       else
+                                               sima_sample_color();
+                               }
+                               else if(G.f & G_FACESELECT)
+                                       gesture();
+                               else 
+                                       sima_sample_color();
                                break;
                        case RIGHTMOUSE:
                                if(G.f & G_FACESELECT)
@@ -3889,8 +3917,7 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        sample_vpaint();
                                break;
                        case AKEY:
-                               if((G.qual==0))
-                                       select_swap_tface_uv();
+                               select_swap_tface_uv();
                                break;
                        case BKEY:
                                if(G.qual==LR_SHIFTKEY)
@@ -3978,6 +4005,8 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        stitch_uv_tface(0);
                                else if(G.qual==LR_SHIFTKEY)
                                        stitch_uv_tface(1);
+                               else if(G.qual==LR_CTRLKEY)
+                                       minimize_stretch_tface_uv();
                                break;
                        case WKEY:
                                weld_align_menu_tface_uv();
@@ -4441,6 +4470,47 @@ static void init_timespace(ScrArea *sa)
        
 }
 
+/* ******************** SPACE: Time ********************** */
+
+extern void drawnodespace(ScrArea *sa, void *spacedata);
+extern void winqreadnodespace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
+
+static void init_nodespace(ScrArea *sa)
+{
+       SpaceNode *snode;
+       
+       snode= MEM_callocN(sizeof(SpaceNode), "init nodespace");
+       BLI_addhead(&sa->spacedata, snode);
+       
+       snode->spacetype= SPACE_NODE;
+       snode->blockscale= 0.7;
+       
+       snode->v2d.tot.xmin=  -10.0;
+       snode->v2d.tot.ymin=  -10.0;
+       snode->v2d.tot.xmax= (float)sa->winx + 10.0f;
+       snode->v2d.tot.ymax= (float)sa->winy + 10.0f;
+       
+       snode->v2d.cur.xmin=  0.0;
+       snode->v2d.cur.ymin=  0.0;
+       snode->v2d.cur.xmax= (float)sa->winx;
+       snode->v2d.cur.ymax= (float)sa->winy;
+       
+       snode->v2d.min[0]= 1.0;
+       snode->v2d.min[1]= 1.0;
+       
+       snode->v2d.max[0]= 32000.0f;
+       snode->v2d.max[1]= 32000.0f;
+       
+       snode->v2d.minzoom= 0.5f;
+       snode->v2d.maxzoom= 1.21f;
+       
+       snode->v2d.scroll= 0;
+       snode->v2d.keepaspect= 1;
+       snode->v2d.keepzoom= 1;
+       snode->v2d.keeptot= 0;
+}
+
+
 
 /* ******************** SPACE: GENERAL ********************** */
 
@@ -4508,6 +4578,8 @@ void newspace(ScrArea *sa, int type)
                                        init_nlaspace(sa);
                                else if(type==SPACE_TIME)
                                        init_timespace(sa);
+                               else if(type==SPACE_NODE)
+                                       init_nodespace(sa);
 
                                sl= sa->spacedata.first;
                                sl->area= sa;
@@ -4561,7 +4633,10 @@ void freespacelist(ListBase *lb)
                }
                else if(sl->spacetype==SPACE_BUTS) {
                        SpaceButs *buts= (SpaceButs*) sl;
-                       if(buts->rect) MEM_freeN(buts->rect);
+                       if(buts->ri) { 
+                               if (buts->ri->rect) MEM_freeN(buts->ri->rect);
+                               MEM_freeN(buts->ri);
+                       }
                        if(G.buts==buts) G.buts= NULL;
                }
                else if(sl->spacetype==SPACE_IPO) {
@@ -4602,6 +4677,14 @@ void freespacelist(ListBase *lb)
                else if(sl->spacetype==SPACE_SOUND) {
                        free_soundspace((SpaceSound *)sl);
                }
+               else if(sl->spacetype==SPACE_IMAGE) {
+                       SpaceImage *sima= (SpaceImage *)sl;
+                       if(sima->cumap)
+                               curvemapping_free(sima->cumap);
+               }
+               else if(sl->spacetype==SPACE_NODE) {
+/*                     SpaceNode *snode= (SpaceNode *)sl; */
+               }
        }
 
        BLI_freelistN(lb);
@@ -4631,7 +4714,9 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                else if(sl->spacetype==SPACE_IMASEL) {
                        check_imasel_copy((SpaceImaSel *) sl);
                }
-               else if(sl->spacetype==SPACE_TEXT) {
+               else if(sl->spacetype==SPACE_NODE) {
+                       SpaceNode *snode= (SpaceNode *)sl;
+                       snode->nodetree= NULL;
                }
                /* __PINFAKE */
 /*             else if(sfile->spacetype==SPACE_ACTION) {
@@ -4652,7 +4737,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
 
                if(sl->spacetype==SPACE_BUTS) {
                        SpaceButs *buts= (SpaceButs *)sl;
-                       buts->rect= NULL;
+                       buts->ri= NULL;
                }
                else if(sl->spacetype==SPACE_IPO) {
                        SpaceIpo *si= (SpaceIpo *)sl;
@@ -4668,6 +4753,11 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2)
                        }
                        vd->clipbb= MEM_dupallocN(vd->clipbb);
                }
+               else if(sl->spacetype==SPACE_IMAGE) {
+                       SpaceImage *sima= (SpaceImage *)sl;
+                       if(sima->cumap)
+                               sima->cumap= curvemapping_copy(sima->cumap);
+               }
                sl= sl->next;
        }
 
@@ -4888,6 +4978,12 @@ void allqueue(unsigned short event, short val)
                                        scrarea_queue_winredraw(sa);
                                }
                                break;
+                       case REDRAWNODE:
+                               if(sa->spacetype==SPACE_NODE) {
+                                       scrarea_queue_headredraw(sa);
+                                       scrarea_queue_winredraw(sa);
+                               }
+                               break;
                        case REDRAWANIM:
                                if ELEM6(sa->spacetype, SPACE_IPO, SPACE_SOUND, SPACE_TIME, SPACE_NLA, SPACE_ACTION, SPACE_SEQ) {
                                        scrarea_queue_winredraw(sa);
@@ -5195,3 +5291,15 @@ SpaceType *spacetime_get_type(void)
        
        return st;
 }
+
+SpaceType *spacenode_get_type(void)
+{
+       static SpaceType *st= NULL;
+       
+       if (!st) {
+               st= spacetype_new("Node");
+               spacetype_set_winfuncs(st, drawnodespace, changeview2dspace, winqreadnodespace);
+       }
+       
+       return st;
+}