Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2018-10-15 14:53:14 +0300
committerJacques Lucke <mail@jlucke.com>2018-10-15 14:53:14 +0300
commit2875fb9e7bbc183ae2c40f9e0c8961ace12e767e (patch)
tree8f51e52f177feb60e2688f701685fdf39cd58d55 /source/blender/editors/sculpt_paint/paint_image_proj.c
parentd1145306ec606d8b271eabcb359aaa821c37e688 (diff)
Texture Paint: Don't create material if operation is cancelled
Reviewers: brecht Differential Revision: https://developer.blender.org/D3793
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image_proj.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index b5f9104f023..28a48562264 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5827,46 +5827,57 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
return false;
}
-static int texture_paint_add_texture_paint_slot_exec(bContext *C, wmOperator *op)
+static int get_texture_layer_type(wmOperator *op, const char *prop_name)
{
- if (proj_paint_add_slot(C, op)) {
- return OPERATOR_FINISHED;
- }
- else {
- return OPERATOR_CANCELLED;
- }
+ int type_value = RNA_enum_get(op->ptr, prop_name);
+ int type = RNA_enum_from_value(layer_type_items, type_value);
+ BLI_assert(type != -1);
+ return type;
}
-
-static int texture_paint_add_texture_paint_slot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static Material *get_or_create_current_material(bContext *C, Object *ob)
{
- char imagename[MAX_ID_NAME - 2];
- Main *bmain = CTX_data_main(C);
- Object *ob = ED_object_active_context(C);
Material *ma = give_current_material(ob, ob->actcol);
- int type = RNA_enum_get(op->ptr, "type");
-
if (!ma) {
+ Main *bmain = CTX_data_main(C);
ma = BKE_material_add(bmain, "Material");
- /* no material found, just assign to first slot */
assign_material(bmain, ob, ma, ob->actcol, BKE_MAT_ASSIGN_USERPREF);
}
+ return ma;
+}
- if (!ma->nodetree) {
- ED_node_shader_default(C, &ma->id);
- }
+static int texture_paint_add_texture_paint_slot_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = ED_object_active_context(C);
+ Material *ma = get_or_create_current_material(C, ob);
+ int type = get_texture_layer_type(op, "type");
proj_paint_default_color(op, type, ma);
- type = RNA_enum_from_value(layer_type_items, type);
+ if (proj_paint_add_slot(C, op)) {
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
+}
- /* get the name of the texture layer type */
- BLI_assert(type != -1);
+static void get_default_texture_layer_name_for_object(Object *ob, int texture_type, char *dst, int dst_length)
+{
+ Material *ma = give_current_material(ob, ob->actcol);
+ const char *base_name = ma ? &ma->id.name[2] : &ob->id.name[2];
+ BLI_snprintf(dst, dst_length, "%s %s", base_name, layer_type_items[texture_type].name);
+}
- /* take the second letter to avoid the ID identifier */
- BLI_snprintf(imagename, sizeof(imagename), "%s %s", &ma->id.name[2], layer_type_items[type].name);
+static int texture_paint_add_texture_paint_slot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ Object *ob = ED_object_active_context(C);
+ int type = get_texture_layer_type(op, "type");
+ char imagename[MAX_ID_NAME - 2];
+ get_default_texture_layer_name_for_object(ob, type, (char *)&imagename, sizeof(imagename));
RNA_string_set(op->ptr, "name", imagename);
+
return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y);
}