diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2015-08-31 21:37:38 +0300 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2015-08-31 22:00:30 +0300 |
commit | 333feea6e9450379f5314f327cf1ac1aef6d8a07 (patch) | |
tree | 733c5da53fbae58268a4c1d68beb2fc383ad5187 /source/blender/editors | |
parent | 0018483dfaf96af569fad40bed6f47389ef3358f (diff) |
Fix T45258, impossible to select brush when removing it from 2d
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.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_image.h | 4 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_cursor.c | 8 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_curve.c | 18 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 15 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 10 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 16 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 6 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_uv.c | 5 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util.c | 2 |
11 files changed, 47 insertions, 45 deletions
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index f49d4b508c6..4c4cec2ee29 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -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]); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 67edf0db2d7..c87eeaeb4a3 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -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; } diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index e4cad389004..f34e42fbc7c 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -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; diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index ebe5268ec5c..2f27db835f5 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -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); diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 64e0aa822df..f0c9c023876 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -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(); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index eebd49895ef..05eda4da63b 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -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; } diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index b78916da818..6fa5f62177f 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -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; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 23f388d2a58..2a1b324be02 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -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 */ diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 3800271e0cb..4cedf522cbc 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -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); } diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index e01d8a6bd17..405ac3f6808 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -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); diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index 802c4e796dd..f727f48e993 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -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); |