GSOC 2013 paint
[blender-staging.git] / source / blender / editors / sculpt_paint / paint_vertex.c
index 969c5a09a828adc0134cf3d32301063ce78ec600..2929a96db29ed4260dcace6a05b3ed3ef4b48a6e 100644 (file)
@@ -197,11 +197,11 @@ static int *get_indexarray(Mesh *me)
        return MEM_mallocN(sizeof(int) * (me->totpoly + 1), "vertexpaint");
 }
 
-unsigned int vpaint_get_current_col(VPaint *vp)
+unsigned int vpaint_get_current_col(Scene *scene, VPaint *vp)
 {
        Brush *brush = BKE_paint_brush(&vp->paint);
        unsigned char col[4];
-       rgb_float_to_uchar(col, brush->rgb);
+       rgb_float_to_uchar(col, BKE_brush_color_get(scene, brush));
        col[3] = 255; /* alpha isn't used, could even be removed to speedup paint a little */
        return *(unsigned int *)col;
 }
@@ -2547,14 +2547,17 @@ static int wpaint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
        int retval;
 
-       op->customdata = paint_stroke_new(C, NULL, wpaint_stroke_test_start,
+       op->customdata = paint_stroke_new(C, op, NULL, wpaint_stroke_test_start,
                                          wpaint_stroke_update_step, NULL,
                                          wpaint_stroke_done, event->type);
        
+       if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
+               paint_stroke_data_free(op);
+               return OPERATOR_FINISHED;
+       }
        /* add modal handler */
        WM_event_add_modal_handler(C, op);
 
-       retval = op->type->modal(C, op, event);
        OPERATOR_RETVAL_CHECK(retval);
        BLI_assert(retval == OPERATOR_RUNNING_MODAL);
        
@@ -2563,7 +2566,7 @@ static int wpaint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 static int wpaint_exec(bContext *C, wmOperator *op)
 {
-       op->customdata = paint_stroke_new(C, NULL, wpaint_stroke_test_start,
+       op->customdata = paint_stroke_new(C, op, NULL, wpaint_stroke_test_start,
                                          wpaint_stroke_update_step, NULL,
                                          wpaint_stroke_done, 0);
 
@@ -2778,7 +2781,8 @@ static void vpaint_build_poly_facemap(struct VPaintData *vd, Mesh *me)
 
 static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const float UNUSED(mouse[2]))
 {
-       ToolSettings *ts = CTX_data_tool_settings(C);
+       Scene *scene = CTX_data_scene(C);
+       ToolSettings *ts = scene->toolsettings;
        struct PaintStroke *stroke = op->customdata;
        VPaint *vp = ts->vpaint;
        Brush *brush = BKE_paint_brush(&vp->paint);
@@ -2810,7 +2814,7 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f
        vpd->vp_handle = ED_vpaint_proj_handle_create(vpd->vc.scene, ob, &vpd->vertexcosnos);
 
        vpd->indexar = get_indexarray(me);
-       vpd->paintcol = vpaint_get_current_col(vp);
+       vpd->paintcol = vpaint_get_current_col(scene, vp);
 
        vpd->is_texbrush = !(brush->vertexpaint_tool == PAINT_BLEND_BLUR) &&
                           brush->mtex.tex;
@@ -3062,14 +3066,18 @@ static int vpaint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
        int retval;
 
-       op->customdata = paint_stroke_new(C, NULL, vpaint_stroke_test_start,
+       op->customdata = paint_stroke_new(C, op, NULL, vpaint_stroke_test_start,
                                          vpaint_stroke_update_step, NULL,
                                          vpaint_stroke_done, event->type);
        
+       if ((retval = op->type->modal(C, op, event)) == OPERATOR_FINISHED) {
+               paint_stroke_data_free(op);
+               return OPERATOR_FINISHED;
+       }
+
        /* add modal handler */
        WM_event_add_modal_handler(C, op);
 
-       retval = op->type->modal(C, op, event);
        OPERATOR_RETVAL_CHECK(retval);
        BLI_assert(retval == OPERATOR_RUNNING_MODAL);
        
@@ -3078,7 +3086,7 @@ static int vpaint_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 static int vpaint_exec(bContext *C, wmOperator *op)
 {
-       op->customdata = paint_stroke_new(C, NULL, vpaint_stroke_test_start,
+       op->customdata = paint_stroke_new(C, op, NULL, vpaint_stroke_test_start,
                                          vpaint_stroke_update_step, NULL,
                                          vpaint_stroke_done, 0);