Fix T45258, impossible to select brush when removing it from 2d
authorAntony Riakiotakis <kalast@gmail.com>
Mon, 31 Aug 2015 18:37:38 +0000 (21:37 +0300)
committerAntony Riakiotakis <kalast@gmail.com>
Mon, 31 Aug 2015 19:00:30 +0000 (22:00 +0300)
painting.

Also system added a brush every time it found no paint brush in the
system which is not what we would want.

Solution:
* Brush panel stays visible always, regardless of whether there is a
brush or not.
* We search for first available brush when we find no brush in paint
struct instead of always generating a new one.
* Generating and searching for a brush take a mode argument now. Needed
some refactoring to users of BKE_paint_init as well.
* Did some style cleanups for paint mode enums.

Patch is big but it's mostly argument refactoring.

21 files changed:
release/scripts/startup/bl_ui/space_image.py
source/blender/blenkernel/BKE_brush.h
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/paint.c
source/blender/blenloader/intern/versioning_defaults.c
source/blender/editors/include/ED_image.h
source/blender/editors/object/object_edit.c
source/blender/editors/sculpt_paint/paint_cursor.c
source/blender/editors/sculpt_paint/paint_curve.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_ops.c
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/editors/util/ed_util.c
source/blender/makesrna/intern/rna_brush.c
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c

index 80796cdad1be2fd5a1d7c771d52144f24e97fc9e..53209a64848d2ad5d67d1e76b6413710837d0f69 100644 (file)
@@ -705,7 +705,7 @@ class IMAGE_PT_tools_transform_uvs(Panel, UVToolsPanel):
         col.operator("transform.shear")
 
 
-class IMAGE_PT_paint(Panel, BrushButtonsPanel):
+class IMAGE_PT_paint(Panel, ImagePaintPanel):
     bl_label = "Paint"
     bl_category = "Tools"
 
@@ -721,6 +721,11 @@ class IMAGE_PT_paint(Panel, BrushButtonsPanel):
         if brush:
             brush_texpaint_common(self, context, layout, brush, settings)
 
+    @classmethod
+    def poll(cls, context):
+        sima = context.space_data
+        toolsettings = context.tool_settings.image_paint
+        return sima.show_paint
 
 class IMAGE_PT_tools_brush_overlay(BrushButtonsPanel, Panel):
     bl_label = "Overlay"
index 042fba7294ccf59ae0f8ff15000fcfd0759242b2..aff3fb08df66734fb57a551cb483ece40d571f03 100644 (file)
@@ -40,7 +40,8 @@ void BKE_brush_system_init(void);
 void BKE_brush_system_exit(void);
 
 /* datablock functions */
-struct Brush *BKE_brush_add(struct Main *bmain, const char *name);
+struct Brush *BKE_brush_add(struct Main *bmain, const char *name, short ob_mode);
+struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode);
 struct Brush *BKE_brush_copy(struct Brush *brush);
 void BKE_brush_make_local(struct Brush *brush);
 void BKE_brush_free(struct Brush *brush);
index c9192fddec6bcf1dd520f72c02343f8fc680f36b..bf1cfb263eb2568aa90a2bced9b7e38691e00b59 100644 (file)
@@ -66,13 +66,13 @@ extern const char PAINT_CURSOR_WEIGHT_PAINT[3];
 extern const char PAINT_CURSOR_TEXTURE_PAINT[3];
 
 typedef enum PaintMode {
-       PAINT_SCULPT = 0,
-       PAINT_VERTEX = 1,
-       PAINT_WEIGHT = 2,
-       PAINT_TEXTURE_PROJECTIVE = 3,
-       PAINT_TEXTURE_2D = 4,
-       PAINT_SCULPT_UV = 5,
-       PAINT_INVALID = 6
+       ePaintSculpt = 0,
+       ePaintVertex = 1,
+       ePaintWeight = 2,
+       ePaintTextureProjective = 3,
+       ePaintTexture2D = 4,
+       ePaintSculptUV = 5,
+       ePaintInvalid = 6
 } PaintMode;
 
 /* overlay invalidation */
@@ -108,12 +108,14 @@ void                 BKE_palette_clear(struct Palette *palette);
 struct PaintCurve *BKE_paint_curve_add(struct Main *bmain, const char *name);
 void BKE_paint_curve_free(struct PaintCurve *pc);
 
-void BKE_paint_init(struct UnifiedPaintSettings *ups, struct Paint *p, const char col[3]);
+void BKE_paint_init(struct Scene *sce, PaintMode mode, const char col[3]);
 void BKE_paint_free(struct Paint *p);
 void BKE_paint_copy(struct Paint *src, struct Paint *tar);
 
 void BKE_paint_cavity_curve_preset(struct Paint *p, int preset);
 
+short BKE_paint_object_mode_from_paint_mode(PaintMode mode);
+struct Paint *BKE_paint_get_active_from_paintmode(struct Scene *sce, PaintMode mode);
 struct Paint *BKE_paint_get_active(struct Scene *sce);
 struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
 PaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
index c7bb6d4f5cef88222c9402ea11c250f74f4761b4..e0ffd83080493c33ebf933d103e34b8fcf04ee35 100644 (file)
@@ -131,7 +131,7 @@ static void brush_defaults(Brush *brush)
 
 /* Datablock add/copy/free/make_local */
 
-Brush *BKE_brush_add(Main *bmain, const char *name)
+Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
 {
        Brush *brush;
 
@@ -143,6 +143,7 @@ Brush *BKE_brush_add(Main *bmain, const char *name)
        brush_defaults(brush);
 
        brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */
+       brush->ob_mode = ob_mode;
 
        /* the default alpha falloff curve */
        BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
@@ -150,6 +151,17 @@ Brush *BKE_brush_add(Main *bmain, const char *name)
        return brush;
 }
 
+struct Brush *BKE_brush_first_search(struct Main *bmain, short ob_mode)
+{
+       Brush *brush;
+
+       for (brush = bmain->brush.first; brush; brush = brush->id.next) {
+               if (brush->ob_mode & ob_mode)
+                       return brush;
+       }
+       return NULL;
+}
+
 Brush *BKE_brush_copy(Brush *brush)
 {
        Brush *brushn;
index 328731a11a9c13a2f269d50a1dcf57394b0fcbf7..06844b09a9b22d1ee69bb962983c57be722893c3 100644 (file)
@@ -128,6 +128,32 @@ void BKE_paint_reset_overlay_invalid(OverlayControlFlags flag)
        overlay_flags &= ~(flag);
 }
 
+Paint *BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode)
+{
+       if (sce) {
+               ToolSettings *ts = sce->toolsettings;
+
+               switch (mode) {
+                       case ePaintSculpt:
+                               return &ts->sculpt->paint;
+                       case ePaintVertex:
+                               return &ts->vpaint->paint;
+                       case ePaintWeight:
+                               return &ts->wpaint->paint;
+                       case ePaintTexture2D:
+                       case ePaintTextureProjective:
+                               return &ts->imapaint.paint;
+                       case ePaintSculptUV:
+                               return &ts->uvsculpt->paint;
+                       case ePaintInvalid:
+                               return NULL;
+                       default:
+                               return &ts->imapaint.paint;
+               }
+       }
+
+       return NULL;
+}
 
 Paint *BKE_paint_get_active(Scene *sce)
 {
@@ -223,39 +249,39 @@ PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
                if ((sima = CTX_wm_space_image(C)) != NULL) {
                        if (obact && obact->mode == OB_MODE_EDIT) {
                                if (sima->mode == SI_MODE_PAINT)
-                                       return PAINT_TEXTURE_2D;
+                                       return ePaintTexture2D;
                                else if (ts->use_uv_sculpt)
-                                       return PAINT_SCULPT_UV;
+                                       return ePaintSculptUV;
                        }
                        else {
-                               return PAINT_TEXTURE_2D;
+                               return ePaintTexture2D;
                        }
                }
                else if (obact) {
                        switch (obact->mode) {
                                case OB_MODE_SCULPT:
-                                       return PAINT_SCULPT;
+                                       return ePaintSculpt;
                                case OB_MODE_VERTEX_PAINT:
-                                       return PAINT_VERTEX;
+                                       return ePaintVertex;
                                case OB_MODE_WEIGHT_PAINT:
-                                       return PAINT_WEIGHT;
+                                       return ePaintWeight;
                                case OB_MODE_TEXTURE_PAINT:
-                                       return PAINT_TEXTURE_PROJECTIVE;
+                                       return ePaintTextureProjective;
                                case OB_MODE_EDIT:
                                        if (ts->use_uv_sculpt)
-                                               return PAINT_SCULPT_UV;
-                                       return PAINT_TEXTURE_2D;
+                                               return ePaintSculptUV;
+                                       return ePaintTexture2D;
                                default:
-                                       return PAINT_TEXTURE_2D;
+                                       return ePaintTexture2D;
                        }
                }
                else {
                        /* default to image paint */
-                       return PAINT_TEXTURE_2D;
+                       return ePaintTexture2D;
                }
        }
 
-       return PAINT_INVALID;
+       return ePaintInvalid;
 }
 
 Brush *BKE_paint_brush(Paint *p)
@@ -418,23 +444,51 @@ void BKE_paint_cavity_curve_preset(Paint *p, int preset)
        curvemapping_changed(p->cavity_curve, false);
 }
 
-void BKE_paint_init(UnifiedPaintSettings *ups, Paint *p, const char col[3])
+short BKE_paint_object_mode_from_paint_mode(PaintMode mode)
 {
+       switch (mode) {
+               case ePaintSculpt:
+                       return OB_MODE_SCULPT;
+               case ePaintVertex:
+                       return OB_MODE_VERTEX_PAINT;
+               case ePaintWeight:
+                       return OB_MODE_WEIGHT_PAINT;
+               case ePaintTextureProjective:
+                       return OB_MODE_TEXTURE_PAINT;
+               case ePaintTexture2D:
+                       return OB_MODE_TEXTURE_PAINT;
+               case ePaintSculptUV:
+                       return OB_MODE_EDIT;
+               case ePaintInvalid:
+               default:
+                       return 0;
+       }
+}
+
+void BKE_paint_init(Scene *sce, PaintMode mode, const char col[3])
+{
+       UnifiedPaintSettings *ups = &sce->toolsettings->unified_paint_settings;
        Brush *brush;
+       Paint *paint = BKE_paint_get_active_from_paintmode(sce, mode);
 
        /* If there's no brush, create one */
-       brush = BKE_paint_brush(p);
-       if (brush == NULL)
-               brush = BKE_brush_add(G.main, "Brush");
-       BKE_paint_brush_set(p, brush);
+       brush = BKE_paint_brush(paint);
+       if (brush == NULL) {
+               short ob_mode = BKE_paint_object_mode_from_paint_mode(mode);
+               brush = BKE_brush_first_search(G.main, ob_mode);
+
+               if (!brush)
+                       brush = BKE_brush_add(G.main, "Brush", ob_mode);
+               BKE_paint_brush_set(paint, brush);
+       }
 
-       memcpy(p->paint_cursor_col, col, 3);
-       p->paint_cursor_col[3] = 128;
+       memcpy(paint->paint_cursor_col, col, 3);
+       paint->paint_cursor_col[3] = 128;
        ups->last_stroke_valid = false;
        zero_v3(ups->average_stroke_accum);
        ups->average_stroke_counter = 0;
-       if (!p->cavity_curve)
-               BKE_paint_cavity_curve_preset(p, CURVE_PRESET_LINE);
+       if (!paint->cavity_curve)
+               BKE_paint_cavity_curve_preset(paint, CURVE_PRESET_LINE);
 }
 
 void BKE_paint_free(Paint *paint)
index 0e8e6e9d144f33d5139472fcb476f7e9f181baae..01af11e78d17f8188b2859f246273ca4c9df761d 100644 (file)
@@ -151,7 +151,7 @@ void BLO_update_defaults_startup_blend(Main *bmain)
 
                br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
                if (!br) {
-                       br = BKE_brush_add(bmain, "Fill");
+                       br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
                        br->imagepaint_tool = PAINT_TOOL_FILL;
                        br->ob_mode = OB_MODE_TEXTURE_PAINT;
                }
index f49d4b508c6803b3032d98c768c7b895f41d246a..4c4cec2ee2974d479cb1013afedd6c7f7b9ef86e 100644 (file)
@@ -59,8 +59,8 @@ void ED_space_image_get_uv_aspect(struct SpaceImage *sima, float *aspx, float *a
 
 void ED_space_image_scopes_update(const struct bContext *C, struct SpaceImage *sima, struct ImBuf *ibuf, bool use_view_settings);
 
-void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings);
-void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings);
+void ED_space_image_paint_update(struct wmWindowManager *wm, struct Scene *scene);
+void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct Scene *scene);
 
 void ED_image_get_uv_aspect(struct Image *ima, struct ImageUser *iuser, float *aspx, float *aspy);
 void ED_image_mouse_pos(struct SpaceImage *sima, struct ARegion *ar, const int mval[2], float co[2]);
index 67edf0db2d793432ff9facfbba1acc7fad3f535c..c87eeaeb4a3e5c993f0a2291da73d0f493a6dd82 100644 (file)
@@ -575,7 +575,7 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op)
 {
        const int mode_flag = OB_MODE_EDIT;
        const bool is_mode_set = (CTX_data_edit_object(C) != NULL);
-       ToolSettings *toolsettings =  CTX_data_tool_settings(C);
+       Scene *scene =  CTX_data_scene(C);
 
        if (!is_mode_set) {
                Object *ob = CTX_data_active_object(C);
@@ -589,7 +589,7 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op)
        else
                ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR);  /* had EM_DO_UNDO but op flag calls undo too [#24685] */
        
-       ED_space_image_uv_sculpt_update(CTX_wm_manager(C), toolsettings);
+       ED_space_image_uv_sculpt_update(CTX_wm_manager(C), scene);
 
        return OPERATOR_FINISHED;
 }
index e4cad389004e42d04b22ea6e13be350502877815..f34e42fbc7ce05f73e1132d8849500bcfb0f9c65 100644 (file)
@@ -756,7 +756,7 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
                                      ViewContext *vc, int x, int y, float zoom, PaintMode mode)
 {
        /* color means that primary brush texture is colured and secondary is used for alpha/mask control */
-       bool col = ELEM(mode, PAINT_TEXTURE_PROJECTIVE, PAINT_TEXTURE_2D, PAINT_VERTEX) ? true : false;
+       bool col = ELEM(mode, ePaintTextureProjective, ePaintTexture2D, ePaintVertex) ? true : false;
        OverlayControlFlags flags = BKE_paint_get_overlay_flags();
        /* save lots of GL state
         * TODO: check on whether all of these are needed? */
@@ -782,7 +782,7 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
                        paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom);
        }
        else {
-               if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY) && (mode != PAINT_WEIGHT))
+               if (!(flags & PAINT_OVERLAY_OVERRIDE_PRIMARY) && (mode != ePaintWeight))
                        paint_draw_tex_overlay(ups, brush, vc, x, y, zoom, false, true);
                if (!(flags & PAINT_OVERLAY_OVERRIDE_CURSOR))
                        paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom);
@@ -958,7 +958,7 @@ static void paint_cursor_on_hit(UnifiedPaintSettings *ups, Brush *brush, ViewCon
 static bool ommit_cursor_drawing(Paint *paint, PaintMode mode, Brush *brush)
 {
        if (paint->flags & PAINT_SHOW_BRUSH) {
-               if (ELEM(mode, PAINT_TEXTURE_2D, PAINT_TEXTURE_PROJECTIVE) && brush->imagepaint_tool == PAINT_TOOL_FILL) {
+               if (ELEM(mode, ePaintTexture2D, ePaintTextureProjective) && brush->imagepaint_tool == PAINT_TOOL_FILL) {
                        return true;
                }
                return false;
@@ -1014,7 +1014,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
 
        /* TODO: as sculpt and other paint modes are unified, this
         * special mode of drawing will go away */
-       if ((mode == PAINT_SCULPT) && vc.obact->sculpt) {
+       if ((mode == ePaintSculpt) && vc.obact->sculpt) {
                float location[3];
                int pixel_radius;
                bool hit;
index ebe5268ec5cc6ecb9e5ffbd31d6c27f8833aa4b2..2f27db835f577c08bf9ebdc44d4f34304ee48580 100644 (file)
@@ -134,12 +134,12 @@ static void paintcurve_undo_begin(bContext *C, wmOperator *op, PaintCurve *pc)
        UndoCurve *uc;
 
        switch (mode) {
-               case PAINT_TEXTURE_2D:
-               case PAINT_TEXTURE_PROJECTIVE:
+               case ePaintTexture2D:
+               case ePaintTextureProjective:
                        undo_stack_id = UNDO_PAINT_IMAGE;
                        break;
 
-               case PAINT_SCULPT:
+               case ePaintSculpt:
                        undo_stack_id = UNDO_PAINT_MESH;
                        break;
 
@@ -737,17 +737,17 @@ static int paintcurve_draw_exec(bContext *C, wmOperator *UNUSED(op))
        const char *name;
 
        switch (mode) {
-               case PAINT_TEXTURE_2D:
-               case PAINT_TEXTURE_PROJECTIVE:
+               case ePaintTexture2D:
+               case ePaintTextureProjective:
                        name = "PAINT_OT_image_paint";
                        break;
-               case PAINT_WEIGHT:
+               case ePaintWeight:
                        name = "PAINT_OT_weight_paint";
                        break;
-               case PAINT_VERTEX:
+               case ePaintVertex:
                        name = "PAINT_OT_vertex_paint";
                        break;
-               case PAINT_SCULPT:
+               case ePaintSculpt:
                        name = "SCULPT_OT_brush_stroke";
                        break;
                default:
@@ -777,7 +777,7 @@ static int paintcurve_cursor_invoke(bContext *C, wmOperator *UNUSED(op), const w
        PaintMode mode = BKE_paintmode_get_active_from_context(C);
        
        switch (mode) {
-               case PAINT_TEXTURE_2D:
+               case ePaintTexture2D:
                {
                        ARegion *ar = CTX_wm_region(C);
                        SpaceImage *sima = CTX_wm_space_image(C);
index 64e0aa822dfd82c0d460e9168e08deb6d867b5ba..f0c9c023876b249c23e937e506bfe8d90ee2b7b9 100644 (file)
@@ -1045,8 +1045,9 @@ static void toggle_paint_cursor(bContext *C, int enable)
  * purpose is to make sure the paint cursor is shown if paint
  * mode is enabled in the image editor. the paint poll will
  * ensure that the cursor is hidden when not in paint mode */
-void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings)
+void ED_space_image_paint_update(wmWindowManager *wm, Scene *scene)
 {
+       ToolSettings *settings = scene->toolsettings;
        wmWindow *win;
        ScrArea *sa;
        ImagePaintSettings *imapaint = &settings->imapaint;
@@ -1059,7 +1060,7 @@ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings)
                                        enabled = true;
 
        if (enabled) {
-               BKE_paint_init(&settings->unified_paint_settings, &imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT);
+               BKE_paint_init(scene, ePaintTexture2D, PAINT_CURSOR_TEXTURE_PAINT);
 
                paint_cursor_start_explicit(&imapaint->paint, wm, image_paint_poll);
        }
@@ -1212,7 +1213,7 @@ static int sample_color_exec(bContext *C, wmOperator *op)
        RNA_int_get_array(op->ptr, "location", location);
        use_palette = RNA_boolean_get(op->ptr, "palette");
 
-       paint_sample_color(C, ar, location[0], location[1], mode == PAINT_TEXTURE_PROJECTIVE, use_palette);
+       paint_sample_color(C, ar, location[0], location[1], mode == ePaintTextureProjective, use_palette);
 
        if (show_cursor) {
                paint->flags |= PAINT_SHOW_BRUSH;
@@ -1250,7 +1251,7 @@ static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event
 
        RNA_int_set_array(op->ptr, "location", event->mval);
 
-       paint_sample_color(C, ar, event->mval[0], event->mval[1], mode == PAINT_TEXTURE_PROJECTIVE, false);
+       paint_sample_color(C, ar, event->mval[0], event->mval[1], mode == ePaintTextureProjective, false);
        WM_cursor_modal_set(win, BC_EYEDROPPER_CURSOR);
 
        WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
@@ -1289,7 +1290,7 @@ static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
                {
                        ARegion *ar = CTX_wm_region(C);
                        RNA_int_set_array(op->ptr, "location", event->mval);
-                       paint_sample_color(C, ar, event->mval[0], event->mval[1], mode == PAINT_TEXTURE_PROJECTIVE, false);
+                       paint_sample_color(C, ar, event->mval[0], event->mval[1], mode == ePaintTextureProjective, false);
                        WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
                        break;
                }
@@ -1298,7 +1299,7 @@ static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
                        if (event->val == KM_PRESS) {
                                ARegion *ar = CTX_wm_region(C);
                                RNA_int_set_array(op->ptr, "location", event->mval);
-                               paint_sample_color(C, ar, event->mval[0], event->mval[1], mode == PAINT_TEXTURE_PROJECTIVE, true);
+                               paint_sample_color(C, ar, event->mval[0], event->mval[1], mode == ePaintTextureProjective, true);
                                if (!data->sample_palette) {
                                        data->sample_palette = true;
                                        sample_color_update_header(data, C);
@@ -1416,7 +1417,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
                
                ob->mode |= mode_flag;
 
-               BKE_paint_init(&scene->toolsettings->unified_paint_settings, &imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT);
+               BKE_paint_init(scene, ePaintTextureProjective, PAINT_CURSOR_TEXTURE_PAINT);
 
                if (U.glreslimit != 0)
                        GPU_free_images();
index eebd49895ef3c9f2768823c559c949b603e42f2e..05eda4da63b436f7e307221d2604a96cbfa9acaa 100644 (file)
@@ -66,11 +66,12 @@ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
        Paint *paint = BKE_paint_get_active_from_context(C);
        Brush *br = BKE_paint_brush(paint);
        Main *bmain = CTX_data_main(C);
+       PaintMode mode = BKE_paintmode_get_active_from_context(C);
 
        if (br)
                br = BKE_brush_copy(br);
        else
-               br = BKE_brush_add(bmain, "Brush");
+               br = BKE_brush_add(bmain, "Brush", BKE_paint_object_mode_from_paint_mode(mode));
 
        BKE_paint_brush_set(paint, br);
 
@@ -201,11 +202,11 @@ static int palette_color_add_exec(bContext *C, wmOperator *UNUSED(op))
        color = BKE_palette_color_add(palette);
        palette->active_color = BLI_listbase_count(&palette->colors) - 1;
 
-       if (ELEM(mode, PAINT_TEXTURE_PROJECTIVE, PAINT_TEXTURE_2D, PAINT_VERTEX)) {
+       if (ELEM(mode, ePaintTextureProjective, ePaintTexture2D, ePaintVertex)) {
                copy_v3_v3(color->rgb, BKE_brush_color_get(scene, brush));
                color->value = 0.0;
        }
-       else if (mode == PAINT_WEIGHT) {
+       else if (mode == ePaintWeight) {
                zero_v3(color->rgb);
                color->value = brush->weight;
        }
@@ -431,9 +432,8 @@ static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool,
                brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
 
        if (!brush && brush_tool(brush_orig, tool_offset) != tool && create_missing) {
-               brush = BKE_brush_add(bmain, tool_name);
+               brush = BKE_brush_add(bmain, tool_name, ob_mode);
                brush_tool_set(brush, tool_offset, tool);
-               brush->ob_mode = ob_mode;
                brush->toggle_brush = brush_orig;
        }
 
index b78916da818e08b7a8c8997df8c90443538dc661..6fa5f62177f1753f4924f813c540c1e841fc0be9 100644 (file)
@@ -194,7 +194,7 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata)
 static bool paint_tool_require_location(Brush *brush, PaintMode mode)
 {
        switch (mode) {
-               case PAINT_SCULPT:
+               case ePaintSculpt:
                        if (ELEM(brush->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE,
                                                     SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB))
                        {
@@ -388,7 +388,7 @@ static bool paint_stroke_use_jitter(PaintMode mode, Brush *brush, bool invert)
        /* jitter-ed brush gives weird and unpredictable result for this
         * kinds of stroke, so manually disable jitter usage (sergey) */
        use_jitter &= (brush->flag & (BRUSH_DRAG_DOT | BRUSH_ANCHORED)) == 0;
-       use_jitter &= (!ELEM(mode, PAINT_TEXTURE_2D, PAINT_TEXTURE_PROJECTIVE) ||
+       use_jitter &= (!ELEM(mode, ePaintTexture2D, ePaintTextureProjective) ||
                       !(invert && brush->imagepaint_tool == PAINT_TOOL_CLONE));
 
 
@@ -759,13 +759,13 @@ bool paint_supports_dynamic_size(Brush *br, PaintMode mode)
                return false;
 
        switch (mode) {
-               case PAINT_SCULPT:
+               case ePaintSculpt:
                        if (sculpt_is_grab_tool(br))
                                return false;
                        break;
 
-               case PAINT_TEXTURE_2D: /* fall through */
-               case PAINT_TEXTURE_PROJECTIVE:
+               case ePaintTexture2D: /* fall through */
+               case ePaintTextureProjective:
                        if ((br->imagepaint_tool == PAINT_TOOL_FILL) &&
                            (br->flag & BRUSH_USE_GRADIENT))
                        {
@@ -788,7 +788,7 @@ bool paint_supports_smooth_stroke(Brush *br, PaintMode mode)
        }
 
        switch (mode) {
-               case PAINT_SCULPT:
+               case ePaintSculpt:
                        if (sculpt_is_grab_tool(br))
                                return false;
                        break;
@@ -801,7 +801,7 @@ bool paint_supports_smooth_stroke(Brush *br, PaintMode mode)
 bool paint_supports_texture(PaintMode mode)
 {
        /* omit: PAINT_WEIGHT, PAINT_SCULPT_UV, PAINT_INVALID */
-       return ELEM(mode, PAINT_SCULPT, PAINT_VERTEX, PAINT_TEXTURE_PROJECTIVE, PAINT_TEXTURE_2D);
+       return ELEM(mode, ePaintSculpt, ePaintVertex, ePaintTextureProjective, ePaintTexture2D);
 }
 
 /* return true if the brush size can change during paint (normally used for pressure) */
@@ -811,7 +811,7 @@ bool paint_supports_dynamic_tex_coords(Brush *br, PaintMode mode)
                return false;
 
        switch (mode) {
-               case PAINT_SCULPT:
+               case ePaintSculpt:
                        if (sculpt_is_grab_tool(br))
                                return false;
                        break;
index 23f388d2a5896c5dda4b75f7f4e162d5a726fe1b..2a1b324be02f188dab7157fd6b3aeb6e003b91b5 100644 (file)
@@ -1956,7 +1956,7 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
 
                paint_cursor_start(C, weight_paint_poll);
 
-               BKE_paint_init(&scene->toolsettings->unified_paint_settings, &wp->paint, PAINT_CURSOR_WEIGHT_PAINT);
+               BKE_paint_init(scene, ePaintWeight, PAINT_CURSOR_WEIGHT_PAINT);
 
                /* weight paint specific */
                ED_mesh_mirror_spatial_table(ob, NULL, NULL, 's');
@@ -2564,7 +2564,7 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
                
                paint_cursor_start(C, vertex_paint_poll);
 
-               BKE_paint_init(&scene->toolsettings->unified_paint_settings, &vp->paint, PAINT_CURSOR_VERTEX_PAINT);
+               BKE_paint_init(scene, ePaintVertex, PAINT_CURSOR_VERTEX_PAINT);
        }
        
        /* update modifier stack for mapping requirements */
index 3800271e0cb605f47e2174224e2a6d040f047af0..4cedf522cbc5735ccda3eac315d3e9610015e162 100644 (file)
@@ -4062,7 +4062,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob,
         *      brush coord/pressure/etc.
         *      It's more an events design issue, which doesn't split coordinate/pressure/angle
         *      changing events. We should avoid this after events system re-design */
-       if (paint_supports_dynamic_size(brush, PAINT_SCULPT) || cache->first_time) {
+       if (paint_supports_dynamic_size(brush, ePaintSculpt) || cache->first_time) {
                cache->pressure = RNA_float_get(ptr, "pressure");
        }
 
@@ -4079,7 +4079,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob,
                }
        }
 
-       if (BKE_brush_use_size_pressure(scene, brush) && paint_supports_dynamic_size(brush, PAINT_SCULPT)) {
+       if (BKE_brush_use_size_pressure(scene, brush) && paint_supports_dynamic_size(brush, ePaintSculpt)) {
                cache->radius = cache->initial_radius * cache->pressure;
        }
        else {
@@ -5141,7 +5141,7 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
                                   "Object has negative scale, sculpting may be unpredictable");
                }
 
-               BKE_paint_init(&ts->unified_paint_settings, &ts->sculpt->paint, PAINT_CURSOR_SCULPT);
+               BKE_paint_init(scene, ePaintSculpt, PAINT_CURSOR_SCULPT);
 
                paint_cursor_start(C, sculpt_poll_view3d);
        }
index e01d8a6bd17dcc2b17f4ce6cf0699d205971b4ab..405ac3f68081ab35f48670b4be3d5427f0cadc7c 100644 (file)
@@ -224,8 +224,9 @@ static void brush_drawcursor_uvsculpt(bContext *C, int x, int y, void *UNUSED(cu
 }
 
 
-void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings)
+void ED_space_image_uv_sculpt_update(wmWindowManager *wm, Scene *scene)
 {
+       ToolSettings *settings = scene->toolsettings;
        if (settings->use_uv_sculpt) {
                if (!settings->uvsculpt) {
                        settings->uvsculpt = MEM_callocN(sizeof(*settings->uvsculpt), "UV Smooth paint");
@@ -236,7 +237,7 @@ void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings
                        settings->uvsculpt->paint.flags |= PAINT_SHOW_BRUSH;
                }
 
-               BKE_paint_init(&settings->unified_paint_settings, &settings->uvsculpt->paint, PAINT_CURSOR_SCULPT);
+               BKE_paint_init(scene, ePaintSculptUV, PAINT_CURSOR_SCULPT);
 
                settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate(wm, uv_sculpt_brush_poll,
                                                                                  brush_drawcursor_uvsculpt, NULL);
index 802c4e796dd9a2761c9af388d382a4485b7784ca..f727f48e99304f3039307bd392ee2643da0f1fb7 100644 (file)
@@ -111,7 +111,7 @@ void ED_editors_init(bContext *C)
 
        /* image editor paint mode */
        if (sce) {
-               ED_space_image_paint_update(wm, sce->toolsettings);
+               ED_space_image_paint_update(wm, sce);
        }
 
        SWAP(int, reports->flag, reports_flag_prev);
index 2c69331f50aafa849efec1b42193545c114da979..93cbd5fa2463ccb35ac40f56d9efe367d5183805 100644 (file)
@@ -510,7 +510,7 @@ static EnumPropertyItem *rna_Brush_direction_itemf(bContext *C, PointerRNA *ptr,
        Brush *me = (Brush *)(ptr->data);
 
        switch (mode) {
-               case PAINT_SCULPT:
+               case ePaintSculpt:
                        switch (me->sculpt_tool) {
                                case SCULPT_TOOL_DRAW:
                                case SCULPT_TOOL_CREASE:
@@ -550,8 +550,8 @@ static EnumPropertyItem *rna_Brush_direction_itemf(bContext *C, PointerRNA *ptr,
                        }
                        break;
 
-               case PAINT_TEXTURE_2D:
-               case PAINT_TEXTURE_PROJECTIVE:
+               case ePaintTexture2D:
+               case ePaintTextureProjective:
                        switch (me->imagepaint_tool) {
                                case PAINT_TOOL_SOFTEN:
                                        return prop_soften_sharpen_items;
@@ -581,9 +581,9 @@ static EnumPropertyItem *rna_Brush_stroke_itemf(bContext *C, PointerRNA *UNUSED(
        };
 
        switch (mode) {
-               case PAINT_SCULPT:
-               case PAINT_TEXTURE_2D:
-               case PAINT_TEXTURE_PROJECTIVE:
+               case ePaintSculpt:
+               case ePaintTexture2D:
+               case ePaintTextureProjective:
                        return sculpt_stroke_method_items;
 
                default:
index 9ccff3eb1fa7d20c048a5662173abdef981501ea..b38f4fa67b6eab9d9ba47b704dc2de7396ece124 100644 (file)
@@ -36,6 +36,7 @@
 #include "DNA_ID.h"
 #include "DNA_modifier_types.h"
 #include "DNA_space_types.h"
+#include "DNA_object_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_path_util.h"
@@ -88,7 +89,6 @@
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
-#include "DNA_object_types.h"
 #include "DNA_speaker_types.h"
 #include "DNA_sound_types.h"
 #include "DNA_text_types.h"
@@ -483,12 +483,13 @@ static void rna_Main_textures_remove(Main *bmain, ReportList *reports, PointerRN
        }
 }
 
-static Brush *rna_Main_brushes_new(Main *bmain, const char *name)
+static Brush *rna_Main_brushes_new(Main *bmain, const char *name, int mode)
 {
-       Brush *brush = BKE_brush_add(bmain, name);
+       Brush *brush = BKE_brush_add(bmain, name, mode);
        id_us_min(&brush->id);
        return brush;
 }
+
 static void rna_Main_brushes_remove(Main *bmain, ReportList *reports, PointerRNA *brush_ptr)
 {
        Brush *brush = brush_ptr->data;
@@ -1422,6 +1423,7 @@ void RNA_def_main_brushes(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_function_ui_description(func, "Add a new brush to the main database");
        parm = RNA_def_string(func, "name", "Brush", 0, "", "New name for the datablock");
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm = RNA_def_enum(func, "mode", object_mode_items, OB_MODE_TEXTURE_PAINT, "", "Paint Mode for the new brush");
        /* return type */
        parm = RNA_def_pointer(func, "brush", "Brush", "", "New brush datablock");
        RNA_def_function_return(func, parm);
index 4d7a2c13c1cd9f9facb3c36756929f88daf51a9b..22e6741b5f63ff2ec4740e2856508678177ce75c 100644 (file)
@@ -432,7 +432,7 @@ EnumPropertyItem stereo3d_interlace_type_items[] = {
 
 static void rna_SpaceImageEditor_uv_sculpt_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
 {
-       ED_space_image_uv_sculpt_update(bmain->wm.first, scene->toolsettings);
+       ED_space_image_uv_sculpt_update(bmain->wm.first, scene);
 }
 
 static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
index 186efff1280a27bad326451f10de0a427d04ea4a..cee98261e231c6d0f3deff82fbd552e13c11e1a8 100644 (file)
@@ -730,7 +730,7 @@ static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr)
 
 static void rna_SpaceImageEditor_mode_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
 {
-       ED_space_image_paint_update(bmain->wm.first, scene->toolsettings);
+       ED_space_image_paint_update(bmain->wm.first, scene);
 }