2.5 Paint:
[blender.git] / source / blender / editors / sculpt_paint / paint_vertex.c
index bbc68a6bd0a856417ed11295b6b4b554c2d99bc1..1a548708ec89cd4b3cd4c0c919a1a7acdf98b964 100644 (file)
@@ -76,6 +76,7 @@
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
+#include "BKE_paint.h"
 #include "BKE_utildefines.h"
 
 #include "WM_api.h"
@@ -110,7 +111,8 @@ static int vp_poll(bContext *C)
 {
        Object *ob = CTX_data_active_object(C);
 
-       if(ob && ob->mode & OB_MODE_VERTEX_PAINT) {
+       if(ob && ob->mode & OB_MODE_VERTEX_PAINT &&
+          paint_brush(&CTX_data_tool_settings(C)->vpaint->paint)) {
                ScrArea *sa= CTX_wm_area(C);
                if(sa->spacetype==SPACE_VIEW3D) {
                        ARegion *ar= CTX_wm_region(C);
@@ -125,7 +127,8 @@ static int wp_poll(bContext *C)
 {
        Object *ob = CTX_data_active_object(C);
 
-       if(ob && ob->mode & OB_MODE_WEIGHT_PAINT) {
+       if(ob && ob->mode & OB_MODE_WEIGHT_PAINT &&
+          paint_brush(&CTX_data_tool_settings(C)->wpaint->paint)) {
                ScrArea *sa= CTX_wm_area(C);
                if(sa->spacetype==SPACE_VIEW3D) {
                        ARegion *ar= CTX_wm_region(C);
@@ -140,14 +143,14 @@ static int wp_poll(bContext *C)
 /* Cursors */
 static void vp_drawcursor(bContext *C, int x, int y, void *customdata)
 {
-       ToolSettings *ts= CTX_data_tool_settings(C);
+       Brush *brush = paint_brush(&CTX_data_tool_settings(C)->vpaint->paint);
        
        glTranslatef((float)x, (float)y, 0.0f);
        
        glColor4ub(255, 255, 255, 128);
        glEnable( GL_LINE_SMOOTH );
        glEnable(GL_BLEND);
-       glutil_draw_lined_arc(0.0, M_PI*2.0, ts->vpaint->brush->size, 40);
+       glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40);
        glDisable(GL_BLEND);
        glDisable( GL_LINE_SMOOTH );
        
@@ -156,14 +159,14 @@ static void vp_drawcursor(bContext *C, int x, int y, void *customdata)
 
 static void wp_drawcursor(bContext *C, int x, int y, void *customdata)
 {
-       ToolSettings *ts= CTX_data_tool_settings(C);
-       
+       Brush *brush = paint_brush(&CTX_data_tool_settings(C)->wpaint->paint);
+
        glTranslatef((float)x, (float)y, 0.0f);
        
        glColor4ub(200, 200, 255, 128);
        glEnable( GL_LINE_SMOOTH );
        glEnable(GL_BLEND);
-       glutil_draw_lined_arc(0.0, M_PI*2.0, ts->wpaint->brush->size, 40);
+       glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40);
        glDisable(GL_BLEND);
        glDisable( GL_LINE_SMOOTH );
        
@@ -236,7 +239,8 @@ unsigned int rgba_to_mcol(float r, float g, float b, float a)
 
 static unsigned int vpaint_get_current_col(VPaint *vp)
 {
-       return rgba_to_mcol(vp->brush->rgb[0], vp->brush->rgb[1], vp->brush->rgb[2], 1.0f);
+       Brush *brush = paint_brush(&vp->paint);
+       return rgba_to_mcol(brush->rgb[0], brush->rgb[1], brush->rgb[2], 1.0f);
 }
 
 void do_shared_vertexcol(Mesh *me)
@@ -725,6 +729,7 @@ static unsigned int mcol_darken(unsigned int col1, unsigned int col2, int fac)
 
 static void vpaint_blend(VPaint *vp, unsigned int *col, unsigned int *colorig, unsigned int paintcol, int alpha)
 {
+       Brush *brush = paint_brush(&vp->paint);
 
        if(vp->mode==VP_MIX || vp->mode==VP_BLUR) *col= mcol_blend( *col, paintcol, alpha);
        else if(vp->mode==VP_ADD) *col= mcol_add( *col, paintcol, alpha);
@@ -738,7 +743,7 @@ static void vpaint_blend(VPaint *vp, unsigned int *col, unsigned int *colorig, u
                unsigned int testcol=0, a;
                char *cp, *ct, *co;
                
-               alpha= (int)(255.0*vp->brush->alpha);
+               alpha= (int)(255.0*brush->alpha);
                
                if(vp->mode==VP_MIX || vp->mode==VP_BLUR) testcol= mcol_blend( *colorig, paintcol, alpha);
                else if(vp->mode==VP_ADD) testcol= mcol_add( *colorig, paintcol, alpha);
@@ -804,6 +809,7 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
 
 static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, short *mval)
 {
+       Brush *brush = paint_brush(&vp->paint);
        float fac, dx, dy;
        int alpha;
        short vertco[2];
@@ -814,14 +820,14 @@ static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], floa
                dy= mval[1]-vertco[1];
                
                fac= sqrt(dx*dx + dy*dy);
-               if(fac > vp->brush->size) return 0;
+               if(fac > brush->size) return 0;
                if(vp->flag & VP_HARD)
                        alpha= 255;
                else
-                       alpha= 255.0*vp->brush->alpha*(1.0-fac/vp->brush->size);
+                       alpha= 255.0*brush->alpha*(1.0-fac/brush->size);
        }
        else {
-               alpha= 255.0*vp->brush->alpha;
+               alpha= 255.0*brush->alpha;
        }
 
        if(vp->flag & VP_NORMALS) {
@@ -843,6 +849,7 @@ static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], floa
 
 static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval)
 {
+       Brush *brush = paint_brush(&wp->paint);
        
        if(dw==NULL || uw==NULL) return;
        
@@ -868,7 +875,7 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float
        if((wp->flag & VP_SPRAY)==0) {
                float testw=0.0f;
                
-               alpha= wp->brush->alpha;
+               alpha= brush->alpha;
                if(wp->mode==VP_MIX || wp->mode==VP_BLUR)
                        testw = paintval*alpha + uw->weight*(1.0-alpha);
                else if(wp->mode==VP_ADD)
@@ -1117,8 +1124,8 @@ static int set_wpaint(bContext *C, wmOperator *op)                /* toggle */
                if(wp==NULL)
                        wp= scene->toolsettings->wpaint= new_vpaint(1);
 
-               brush_check_exists(&wp->brush);
-               
+               paint_init(&wp->paint, "Brush");
+
                toggle_paint_cursor(C, 1);
                
                mesh_octree_table(ob, NULL, NULL, 's');
@@ -1178,8 +1185,10 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot)
 
 static int vpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+       Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->vpaint->paint);
+
        toggle_paint_cursor(C, 0);
-       brush_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->vpaint->brush, 1);
+       brush_radial_control_invoke(op, brush, 1);
        return WM_radial_control_invoke(C, op, event);
 }
 
@@ -1193,13 +1202,15 @@ static int vpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve
 
 static int vpaint_radial_control_exec(bContext *C, wmOperator *op)
 {
-       return brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->vpaint->brush, 1);
+       Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->vpaint->paint);
+       return brush_radial_control_exec(op, brush, 1);
 }
 
 static int wpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+       Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->wpaint->paint);
        toggle_paint_cursor(C, 1);
-       brush_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->wpaint->brush, 1);
+       brush_radial_control_invoke(op, brush, 1);
        return WM_radial_control_invoke(C, op, event);
 }
 
@@ -1213,7 +1224,8 @@ static int wpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve
 
 static int wpaint_radial_control_exec(bContext *C, wmOperator *op)
 {
-       return brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->wpaint->brush, 1);
+       Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->wpaint->paint);
+       return brush_radial_control_exec(op, brush, 1);
 }
 
 void PAINT_OT_weight_paint_radial_control(wmOperatorType *ot)
@@ -1297,6 +1309,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
        ToolSettings *ts= CTX_data_tool_settings(C);
        VPaint *wp= ts->wpaint;
+       Brush *brush = paint_brush(&wp->paint);
        
        switch(event->type) {
                case LEFTMOUSE:
@@ -1332,7 +1345,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event)
                        
                        /* which faces are involved */
                        if(wp->flag & VP_AREA) {
-                               totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], wp->brush->size);
+                               totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size);
                        }
                        else {
                                indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]);
@@ -1611,7 +1624,6 @@ static int set_vpaint(bContext *C, wmOperator *op)                /* toggle */
                }
        }
        else {
-               
                ob->mode |= OB_MODE_VERTEX_PAINT;
                /* Turn off weight painting */
                if (ob->mode & OB_MODE_WEIGHT_PAINT)
@@ -1621,7 +1633,8 @@ static int set_vpaint(bContext *C, wmOperator *op)                /* toggle */
                        vp= scene->toolsettings->vpaint= new_vpaint(0);
                
                toggle_paint_cursor(C, 0);
-               brush_check_exists(&scene->toolsettings->vpaint->brush);
+
+               paint_init(&vp->paint, "Brush");
        }
        
        if (me)
@@ -1700,6 +1713,7 @@ static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
        ToolSettings *ts= CTX_data_tool_settings(C);
        VPaint *vp= ts->vpaint;
+       Brush *brush = paint_brush(&vp->paint);
        
        switch(event->type) {
                case LEFTMOUSE:
@@ -1732,7 +1746,7 @@ static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event)
                                
                        /* which faces are involved */
                        if(vp->flag & VP_AREA) {
-                               totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], vp->brush->size);
+                               totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size);
                        }
                        else {
                                indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]);