diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-29 14:34:09 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-29 14:34:09 +0400 |
commit | 291ad172a1aacea96a460387cc420d96c8d63e63 (patch) | |
tree | 896aa3412487d6167bf6374e2ccc0eb91c692958 /source/blender/editors/sculpt_paint/paint_image.c | |
parent | 1b8da326ba36caeb79fd5ebdc9e93283ab0cc648 (diff) |
follow up on r59628, setting modes now ensures that other modes exit first,
this was only done in some cases before and it was possible to enable weightpaint+sculpt at the same time when enabling sculpt by directly running the mode switching operator.
add generic function to ensure a compatible mode before entering the new mode (added to each operators exec function)
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index fcf00d4ab2c..feff02fa121 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -82,6 +82,7 @@ #include "UI_view2d.h" #include "ED_image.h" +#include "ED_object.h" #include "ED_screen.h" #include "ED_sculpt.h" #include "ED_uvedit.h" @@ -1006,9 +1007,12 @@ void PAINT_OT_sample_color(wmOperatorType *ot) static int texture_paint_toggle_poll(bContext *C) { - if (CTX_data_edit_object(C)) + Object *ob = CTX_data_active_object(C); + if (ob == NULL || ob->type != OB_MESH) return 0; - if (CTX_data_active_object(C) == NULL) + if (!ob->data || ((ID *)ob->data)->lib) + return 0; + if (CTX_data_edit_object(C)) return 0; return 1; @@ -1018,25 +1022,20 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); - Mesh *me = NULL; - - if (ob == NULL) - return OPERATOR_CANCELLED; - - if (BKE_object_obdata_is_libdata(ob)) { - BKE_report(op->reports, RPT_ERROR, "Cannot edit external libdata"); - return OPERATOR_CANCELLED; + const int mode_flag = OB_MODE_TEXTURE_PAINT; + const bool is_mode_set = (ob->mode & mode_flag) != 0; + Mesh *me; + + if (!is_mode_set) { + if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) { + return OPERATOR_CANCELLED; + } } me = BKE_mesh_from_object(ob); - if (!(ob->mode & OB_MODE_TEXTURE_PAINT) && !me) { - BKE_report(op->reports, RPT_ERROR, "Can only enter texture paint mode for mesh objects"); - return OPERATOR_CANCELLED; - } - - if (ob->mode & OB_MODE_TEXTURE_PAINT) { - ob->mode &= ~OB_MODE_TEXTURE_PAINT; + if (ob->mode & mode_flag) { + ob->mode &= ~mode_flag; if (U.glreslimit != 0) GPU_free_images(); @@ -1045,7 +1044,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) toggle_paint_cursor(C, 0); } else { - ob->mode |= OB_MODE_TEXTURE_PAINT; + ob->mode |= mode_flag; if (me->mtface == NULL) me->mtface = CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, |