2.5/Posemode:
[blender-staging.git] / source / blender / editors / sculpt_paint / paint_vertex.c
index 0c20c0cc1cf91e5eabd7ee0562ef1edfef69910e..bbc68a6bd0a856417ed11295b6b4b554c2d99bc1 100644 (file)
@@ -108,7 +108,9 @@ static void error() {}
 
 static int vp_poll(bContext *C)
 {
-       if(G.f & G_VERTEXPAINT) {
+       Object *ob = CTX_data_active_object(C);
+
+       if(ob && ob->mode & OB_MODE_VERTEX_PAINT) {
                ScrArea *sa= CTX_wm_area(C);
                if(sa->spacetype==SPACE_VIEW3D) {
                        ARegion *ar= CTX_wm_region(C);
@@ -121,7 +123,9 @@ static int vp_poll(bContext *C)
 
 static int wp_poll(bContext *C)
 {
-       if(G.f & G_WEIGHTPAINT) {
+       Object *ob = CTX_data_active_object(C);
+
+       if(ob && ob->mode & OB_MODE_WEIGHT_PAINT) {
                ScrArea *sa= CTX_wm_area(C);
                if(sa->spacetype==SPACE_VIEW3D) {
                        ARegion *ar= CTX_wm_region(C);
@@ -369,12 +373,12 @@ void clear_vpaint(Scene *scene)
        unsigned int *to, paintcol;
        int a;
        
-       if((G.f & G_VERTEXPAINT)==0) return;
-
        ob= OBACT;
        me= get_mesh(ob);
        if(!ob || ob->id.lib) return;
 
+       if(!(ob->mode & OB_MODE_VERTEX_PAINT)) return;
+
        if(me==0 || me->mcol==0 || me->totface==0) return;
 
        paintcol= vpaint_get_current_col(scene->toolsettings->vpaint);
@@ -424,8 +428,9 @@ void clear_vpaint_selectedfaces(Scene *scene)
 /* fills in the selected faces with the current weight and vertex group */
 void clear_wpaint_selectedfaces(Scene *scene)
 {
-       VPaint *wp= scene->toolsettings->wpaint;
-       float paintweight= wp->brush->alpha;
+       ToolSettings *ts= scene->toolsettings;
+       VPaint *wp= ts->wpaint;
+       float paintweight= ts->vgroup_weight;
        Mesh *me;
        MFace *mface;
        Object *ob;
@@ -539,10 +544,10 @@ void vpaint_dogamma(Scene *scene)
        int a, temp;
        unsigned char *cp, gamtab[256];
 
-       if((G.f & G_VERTEXPAINT)==0) return;
-
        ob= OBACT;
        me= get_mesh(ob);
+
+       if(!(ob->mode & OB_MODE_VERTEX_PAINT)) return;
        if(me==0 || me->mcol==0 || me->totface==0) return;
 
        igam= 1.0/vp->gamma;
@@ -909,7 +914,7 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float
 void sample_wpaint(Scene *scene, ARegion *ar, View3D *v3d, int mode)
 {
        ViewContext vc;
-       VPaint *wp= scene->toolsettings->wpaint;
+       ToolSettings *ts= scene->toolsettings;
        Object *ob= OBACT;
        Mesh *me= get_mesh(ob);
        int index;
@@ -1019,20 +1024,20 @@ void sample_wpaint(Scene *scene, ARegion *ar, View3D *v3d, int mode)
                                fac= MIN4(w1, w2, w3, w4);
                                if(w1==fac) {
                                        dw= get_defweight(me->dvert+mface->v1, ob->actdef-1);
-                                       if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f;
+                                       if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
                                }
                                else if(w2==fac) {
                                        dw= get_defweight(me->dvert+mface->v2, ob->actdef-1);
-                                       if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f;
+                                       if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
                                }
                                else if(w3==fac) {
                                        dw= get_defweight(me->dvert+mface->v3, ob->actdef-1);
-                                       if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f;
+                                       if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
                                }
                                else if(w4==fac) {
                                        if(mface->v4) {
                                                dw= get_defweight(me->dvert+mface->v4, ob->actdef-1);
-                                               if(dw) wp->brush->alpha= dw->weight; else wp->brush->alpha= 0.0f;
+                                               if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
                                        }
                                }
                        }
@@ -1087,16 +1092,16 @@ static int set_wpaint(bContext *C, wmOperator *op)              /* toggle */
        Mesh *me;
        
        me= get_mesh(ob);
-       if(ob->id.lib || me==NULL) return OPERATOR_CANCELLED;
+       if(ob->id.lib || me==NULL) return OPERATOR_PASS_THROUGH;
        
        if(me && me->totface>=MAXINDEX) {
                error("Maximum number of faces: %d", MAXINDEX-1);
-               G.f &= ~G_WEIGHTPAINT;
+               ob->mode &= ~OB_MODE_WEIGHT_PAINT;
                return OPERATOR_CANCELLED;
        }
        
-       if(G.f & G_WEIGHTPAINT) G.f &= ~G_WEIGHTPAINT;
-       else G.f |= G_WEIGHTPAINT;
+       if(ob->mode & OB_MODE_WEIGHT_PAINT) ob->mode &= ~OB_MODE_WEIGHT_PAINT;
+       else ob->mode |= OB_MODE_WEIGHT_PAINT;
        
        
        /* Weightpaint works by overriding colors in mesh,
@@ -1106,7 +1111,7 @@ static int set_wpaint(bContext *C, wmOperator *op)                /* toggle */
                */
        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
        
-       if(G.f & G_WEIGHTPAINT) {
+       if(ob->mode & OB_MODE_WEIGHT_PAINT) {
                Object *par;
                
                if(wp==NULL)
@@ -1120,7 +1125,7 @@ static int set_wpaint(bContext *C, wmOperator *op)                /* toggle */
                
                /* verify if active weight group is also active bone */
                par= modifiers_isDeformedByArmature(ob);
-               if(par && (par->flag & OB_POSEMODE)) {
+               if(par && (par->mode & OB_MODE_POSE)) {
                        bPoseChannel *pchan;
                        for(pchan= par->pose->chanbase.first; pchan; pchan= pchan->next)
                                if(pchan->bone->flag & BONE_ACTIVE)
@@ -1224,7 +1229,7 @@ void PAINT_OT_weight_paint_radial_control(wmOperatorType *ot)
        ot->poll= wp_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
 }
 
 void PAINT_OT_vertex_paint_radial_control(wmOperatorType *ot)
@@ -1240,7 +1245,7 @@ void PAINT_OT_vertex_paint_radial_control(wmOperatorType *ot)
        ot->poll= vp_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
 }
 
 /* ************ weight paint operator ********** */
@@ -1274,7 +1279,7 @@ static void wpaint_exit(bContext *C, wmOperator *op)
                for(psys= ob->particlesystem.first; psys; psys= psys->next) {
                        for(i=0; i<PSYS_TOT_VG; i++) {
                                if(psys->vgroup[i]==ob->actdef) {
-                                       psys->recalc |= PSYS_RECALC_HAIR;
+                                       psys->recalc |= PSYS_RECALC_RESET;
                                        break;
                                }
                        }
@@ -1308,7 +1313,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event)
                        Object *ob= vc->obact;
                        Mesh *me= ob->data;
                        float mat[4][4];
-                       float paintweight= wp->brush->alpha;
+                       float paintweight= ts->vgroup_weight;
                        int *indexar= wpd->indexar;
                        int totindex, index, alpha, totw;
                        short mval[2];
@@ -1365,7 +1370,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event)
                        if(wp->mode==VP_BLUR) 
                                paintweight= 0.0f;
                        else
-                               paintweight= wp->brush->alpha;
+                               paintweight= ts->vgroup_weight;
                        
                        for(index=0; index<totindex; index++) {
                                if(indexar[index] && indexar[index]<=me->totface) {
@@ -1464,7 +1469,7 @@ static int wpaint_invoke(bContext *C, wmOperator *op, wmEvent *event)
        // XXX  if(multires_level1_test()) return;
        
        me= get_mesh(ob);
-       if(me==NULL || me->totface==0) return OPERATOR_CANCELLED;
+       if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH;
        
        /* if nothing was added yet, we make dverts and a vertex deform group */
        if (!me->dvert)
@@ -1566,7 +1571,7 @@ void PAINT_OT_weight_paint(wmOperatorType *ot)
        ot->poll= wp_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
        
 }
 
@@ -1583,22 +1588,22 @@ static int set_vpaint(bContext *C, wmOperator *op)              /* toggle */
        me= get_mesh(ob);
        
        if(me==NULL || object_data_is_libdata(ob)) {
-               G.f &= ~G_VERTEXPAINT;
-               return OPERATOR_FINISHED;
+               ob->mode &= ~OB_MODE_VERTEX_PAINT;
+               return OPERATOR_PASS_THROUGH;
        }
        
        if(me && me->totface>=MAXINDEX) {
                error("Maximum number of faces: %d", MAXINDEX-1);
-               G.f &= ~G_VERTEXPAINT;
+               ob->mode &= ~OB_MODE_VERTEX_PAINT;
                return OPERATOR_FINISHED;
        }
        
        if(me && me->mcol==NULL) make_vertexcol(scene, 0);
        
        /* toggle: end vpaint */
-       if(G.f & G_VERTEXPAINT) {
+       if(ob->mode & OB_MODE_VERTEX_PAINT) {
                
-               G.f &= ~G_VERTEXPAINT;
+               ob->mode &= ~OB_MODE_VERTEX_PAINT;
                
                if(vp) {
                        toggle_paint_cursor(C, 0);
@@ -1607,9 +1612,9 @@ static int set_vpaint(bContext *C, wmOperator *op)                /* toggle */
        }
        else {
                
-               G.f |= G_VERTEXPAINT;
+               ob->mode |= OB_MODE_VERTEX_PAINT;
                /* Turn off weight painting */
-               if (G.f & G_WEIGHTPAINT)
+               if (ob->mode & OB_MODE_WEIGHT_PAINT)
                        set_wpaint(C, op);
                
                if(vp==NULL)
@@ -1820,7 +1825,7 @@ static int vpaint_invoke(bContext *C, wmOperator *op, wmEvent *event)
        
        /* context checks could be a poll() */
        me= get_mesh(ob);
-       if(me==NULL || me->totface==0) return OPERATOR_CANCELLED;
+       if(me==NULL || me->totface==0) return OPERATOR_PASS_THROUGH;
        
        if(me->mcol==NULL) make_vertexcol(CTX_data_scene(C), 0);
        if(me->mcol==NULL) return OPERATOR_CANCELLED;
@@ -1863,6 +1868,6 @@ void PAINT_OT_vertex_paint(wmOperatorType *ot)
        ot->poll= vp_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
 }