diff options
Diffstat (limited to 'source/blender/editors/mesh/mesh_data.c')
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 73b3fb9724e..b2379610f65 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -482,8 +482,34 @@ bool ED_mesh_color_remove_named(Mesh *me, const char *name) return false; } +/*********************** General poll ************************/ + +static bool layers_poll(bContext *C) +{ + Object *ob = ED_object_context(C); + ID *data = (ob) ? ob->data : NULL; + return (ob && !ID_IS_LINKED(ob) && ob->type == OB_MESH && data && !ID_IS_LINKED(data)); +} + /*********************** Sculpt Vertex colors operators ************************/ +static bool sculpt_vertex_color_remove_poll(bContext *C) +{ + if (!layers_poll(C)) { + return false; + } + + Object *ob = ED_object_context(C); + Mesh *me = ob->data; + CustomData *vdata = GET_CD_DATA(me, vdata); + const int active = CustomData_get_active_layer(vdata, CD_PROP_COLOR); + if (active != -1) { + return true; + } + + return false; +} + /* NOTE: keep in sync with #ED_mesh_uv_texture_add. */ int ED_mesh_sculpt_color_add(Mesh *me, const char *name, const bool active_set, const bool do_init) { @@ -591,11 +617,21 @@ bool ED_mesh_sculpt_color_remove_named(Mesh *me, const char *name) /*********************** UV texture operators ************************/ -static bool layers_poll(bContext *C) +static bool uv_texture_remove_poll(bContext *C) { + if (!layers_poll(C)) { + return false; + } + Object *ob = ED_object_context(C); - ID *data = (ob) ? ob->data : NULL; - return (ob && !ID_IS_LINKED(ob) && ob->type == OB_MESH && data && !ID_IS_LINKED(data)); + Mesh *me = ob->data; + CustomData *ldata = GET_CD_DATA(me, ldata); + const int active = CustomData_get_active_layer(ldata, CD_MLOOPUV); + if (active != -1) { + return true; + } + + return false; } static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op)) @@ -657,7 +693,7 @@ void MESH_OT_uv_texture_remove(wmOperatorType *ot) ot->idname = "MESH_OT_uv_texture_remove"; /* api callbacks */ - ot->poll = layers_poll; + ot->poll = uv_texture_remove_poll; ot->exec = mesh_uv_texture_remove_exec; /* flags */ @@ -666,6 +702,23 @@ void MESH_OT_uv_texture_remove(wmOperatorType *ot) /*********************** vertex color operators ************************/ +static bool vertex_color_remove_poll(bContext *C) +{ + if (!layers_poll(C)) { + return false; + } + + Object *ob = ED_object_context(C); + Mesh *me = ob->data; + CustomData *ldata = GET_CD_DATA(me, ldata); + const int active = CustomData_get_active_layer(ldata, CD_MLOOPCOL); + if (active != -1) { + return true; + } + + return false; +} + static int mesh_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); @@ -714,7 +767,7 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot) /* api callbacks */ ot->exec = mesh_vertex_color_remove_exec; - ot->poll = layers_poll; + ot->poll = vertex_color_remove_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -770,7 +823,7 @@ void MESH_OT_sculpt_vertex_color_remove(wmOperatorType *ot) /* api callbacks */ ot->exec = mesh_sculpt_vertex_color_remove_exec; - ot->poll = layers_poll; + ot->poll = sculpt_vertex_color_remove_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; |