From 5db950e860b2f64078cfc8cf00cb4f430b8a1baf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 9 Feb 2018 22:14:17 +1100 Subject: Cleanup: use workspace for object_mode when possible --- source/blender/editors/sculpt_paint/paint_curve.c | 6 ++-- source/blender/editors/sculpt_paint/paint_image.c | 38 +++++++++------------- .../editors/sculpt_paint/paint_image_proj.c | 5 ++- source/blender/editors/sculpt_paint/paint_ops.c | 11 +++---- source/blender/editors/sculpt_paint/paint_vertex.c | 15 ++++----- .../editors/sculpt_paint/paint_vertex_color_ops.c | 6 ++-- .../editors/sculpt_paint/paint_vertex_weight_ops.c | 5 ++- source/blender/editors/sculpt_paint/sculpt.c | 5 ++- 8 files changed, 39 insertions(+), 52 deletions(-) (limited to 'source/blender/editors/sculpt_paint') diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c index 9170c8b361a..c9ad4a46a13 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.c +++ b/source/blender/editors/sculpt_paint/paint_curve.c @@ -32,6 +32,7 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_view3d_types.h" +#include "DNA_workspace_types.h" #include "BLI_math_vector.h" #include "BLI_string.h" @@ -61,14 +62,13 @@ int paint_curve_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); Paint *p; RegionView3D *rv3d = CTX_wm_region_view3d(C); SpaceImage *sima; - if (rv3d && !(ob && ((eval_ctx.object_mode & OB_MODE_ALL_PAINT) != 0))) + if (rv3d && !(ob && ((workspace->object_mode & OB_MODE_ALL_PAINT) != 0))) return false; 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 662485bf4f7..d42bbfdc43a 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -588,15 +588,15 @@ static Brush *image_paint_brush(bContext *C) static int image_paint_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); Object *obact; if (!image_paint_brush(C)) { return 0; } + + const WorkSpace *workspace = CTX_wm_workspace(C); obact = CTX_data_active_object(C); - if ((obact && eval_ctx.object_mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { + if ((obact && workspace->object_mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { return 1; } else { @@ -1472,13 +1472,12 @@ void PAINT_OT_texture_paint_toggle(wmOperatorType *ot) static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op)) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; - Brush *br; + WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - if (!(ob && (eval_ctx.object_mode & OB_MODE_VERTEX_PAINT))) { + Brush *br; + if (!(ob && (workspace->object_mode & OB_MODE_VERTEX_PAINT))) { br = image_paint_brush(C); } else { @@ -1510,9 +1509,8 @@ static int brush_colors_flip_poll(bContext *C) else { Object *ob = CTX_data_active_object(C); if (ob) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - if (eval_ctx.object_mode & OB_MODE_VERTEX_PAINT) { + WorkSpace *workspace = CTX_wm_workspace(C); + if (workspace->object_mode & OB_MODE_VERTEX_PAINT) { return 1; } } @@ -1555,9 +1553,8 @@ void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op) static int texture_paint_poll(bContext *C) { if (texture_paint_toggle_poll(C)) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - if (eval_ctx.object_mode & OB_MODE_TEXTURE_PAINT) { + WorkSpace *workspace = CTX_wm_workspace(C); + if (workspace->object_mode & OB_MODE_TEXTURE_PAINT) { return 1; } } @@ -1571,22 +1568,19 @@ int image_texture_paint_poll(bContext *C) int facemask_paint_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - return BKE_paint_select_face_test(&eval_ctx, CTX_data_active_object(C)); + const WorkSpace *workspace = CTX_wm_workspace(C); + return BKE_paint_select_face_test(CTX_data_active_object(C), workspace->object_mode); } int vert_paint_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - return BKE_paint_select_vert_test(&eval_ctx, CTX_data_active_object(C)); + const WorkSpace *workspace = CTX_wm_workspace(C); + return BKE_paint_select_vert_test(CTX_data_active_object(C), workspace->object_mode); } int mask_paint_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - return BKE_paint_select_elem_test(&eval_ctx, CTX_data_active_object(C)); + const WorkSpace *workspace = CTX_wm_workspace(C); + return BKE_paint_select_elem_test(CTX_data_active_object(C), workspace->object_mode); } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 1343ab13999..e339a4c13b6 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -5941,10 +5941,9 @@ static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op)) static int add_simple_uvs_poll(bContext *C) { + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - if (!ob || (ob->type != OB_MESH) || (eval_ctx.object_mode != OB_MODE_TEXTURE_PAINT)) { + if (!ob || (ob->type != OB_MESH) || (workspace->object_mode != OB_MODE_TEXTURE_PAINT)) { return false; } return true; diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 214b260250d..c031a733630 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -262,9 +262,9 @@ static void PALETTE_OT_color_delete(wmOperatorType *ot) } static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op)) + { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Paint *paint = BKE_paint_get_active_from_context(C); Brush *brush = BKE_paint_brush(paint); Object *ob = CTX_data_active_object(C); @@ -272,7 +272,7 @@ static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op)) if (!ob || !brush) return OPERATOR_CANCELLED; /* TODO: other modes */ - if (eval_ctx.object_mode & OB_MODE_SCULPT) { + if (workspace->object_mode & OB_MODE_SCULPT) { BKE_brush_sculpt_reset(brush); } else { @@ -405,8 +405,7 @@ static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, static int brush_select_exec(bContext *C, wmOperator *op) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + WorkSpace *workspace = CTX_wm_workspace(C); Main *bmain = CTX_data_main(C); ToolSettings *toolsettings = CTX_data_tool_settings(C); Paint *paint = NULL; @@ -420,7 +419,7 @@ static int brush_select_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); if (ob) { /* select current paint mode */ - paint_mode = eval_ctx.object_mode & OB_MODE_ALL_PAINT; + paint_mode = workspace->object_mode & OB_MODE_ALL_PAINT; } else { return OPERATOR_CANCELLED; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 3a20973c465..4fc6ba40fdc 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -199,13 +199,12 @@ static void paint_last_stroke_update(Scene *scene, ARegion *ar, const float mval /* Returns true if vertex paint mode is active */ int vertex_paint_mode_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); return (ob && (ob->type == OB_MESH) && ((Mesh *)ob->data)->totpoly && - (eval_ctx.object_mode & OB_MODE_VERTEX_PAINT)); + (workspace->object_mode & OB_MODE_VERTEX_PAINT)); } int vertex_paint_poll(bContext *C) @@ -225,24 +224,22 @@ int vertex_paint_poll(bContext *C) int weight_paint_mode_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); return (ob && (ob->type == OB_MESH) && ((Mesh *)ob->data)->totpoly && - (eval_ctx.object_mode == OB_MODE_WEIGHT_PAINT)); + (workspace->object_mode == OB_MODE_WEIGHT_PAINT)); } int weight_paint_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); ScrArea *sa; if ((ob != NULL) && - (eval_ctx.object_mode & OB_MODE_WEIGHT_PAINT) && + (workspace->object_mode & OB_MODE_WEIGHT_PAINT) && (BKE_paint_brush(&CTX_data_tool_settings(C)->wpaint->paint) != NULL) && (sa = CTX_wm_area(C)) && (sa->spacetype == SPACE_VIEW3D)) diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c index 83407ba6765..f442c12cbe9 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c @@ -28,6 +28,7 @@ #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_workspace_types.h" #include "BLI_math_base.h" #include "BLI_math_color.h" @@ -51,11 +52,10 @@ static int vertex_weight_paint_mode_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); Mesh *me = BKE_mesh_from_object(ob); - return (ob && ELEM(eval_ctx.object_mode, OB_MODE_VERTEX_PAINT, OB_MODE_WEIGHT_PAINT)) && + return (ob && ELEM(workspace->object_mode, OB_MODE_VERTEX_PAINT, OB_MODE_WEIGHT_PAINT)) && (me && me->totpoly && me->dvert); } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index b5d3a452d83..72e2e7b323d 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -118,11 +118,10 @@ static void wpaint_prev_destroy(struct WPaintPrev *wpp) static int weight_from_bones_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - return (ob && (eval_ctx.object_mode & OB_MODE_WEIGHT_PAINT) && modifiers_isDeformedByArmature(ob)); + return (ob && (workspace->object_mode & OB_MODE_WEIGHT_PAINT) && modifiers_isDeformedByArmature(ob)); } static int weight_from_bones_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 06705f6715d..02404ef2d8e 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -4082,10 +4082,9 @@ static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) int sculpt_mode_poll(bContext *C) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); + const WorkSpace *workspace = CTX_wm_workspace(C); Object *ob = CTX_data_active_object(C); - return ob && eval_ctx.object_mode & OB_MODE_SCULPT; + return ob && workspace->object_mode & OB_MODE_SCULPT; } int sculpt_mode_poll_view3d(bContext *C) -- cgit v1.2.3