2.5/Posemode:
[blender-staging.git] / source / blender / editors / sculpt_paint / paint_vertex.c
index 74b5d5a4206fcd541a80006dd63ff9753cb245c7..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);
@@ -540,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;
@@ -1088,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,
@@ -1107,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)
@@ -1121,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)
@@ -1225,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)
@@ -1241,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 ********** */
@@ -1465,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)
@@ -1567,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;
        
 }
 
@@ -1584,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);
@@ -1608,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)
@@ -1821,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;
@@ -1864,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;
 }