diff options
-rw-r--r-- | release/ui/buttons_material.py | 9 | ||||
-rw-r--r-- | release/ui/buttons_texture.py | 32 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_brush.c | 44 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_lamp.c | 34 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_material.c | 37 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 27 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_world.c | 35 |
7 files changed, 118 insertions, 100 deletions
diff --git a/release/ui/buttons_material.py b/release/ui/buttons_material.py index 30f7f7122dc..66eca1a14b8 100644 --- a/release/ui/buttons_material.py +++ b/release/ui/buttons_material.py @@ -52,10 +52,13 @@ class MATERIAL_PT_context_material(MaterialButtonsPanel): split = layout.split(percentage=0.65) - if ob and slot: - split.template_ID(slot, "material", new="material.new") + if ob: + split.template_ID(ob, "active_material", new="material.new") row = split.row() - row.itemR(slot, "link", expand=True) + if slot: + row.itemR(slot, "link", expand=True) + else: + row.itemL() elif mat: split.template_ID(space, "pin_id") split.itemS() diff --git a/release/ui/buttons_texture.py b/release/ui/buttons_texture.py index df409d3c524..d638d1356f9 100644 --- a/release/ui/buttons_texture.py +++ b/release/ui/buttons_texture.py @@ -48,26 +48,26 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel): wo = context.world br = context.brush space = context.space_data - slot = context.texture_slot - if ma or la or wo or br: + if ma: + id = ma + elif la: + id = la + elif wo: + id = wo + elif br: + id = br + else: + id = None + + if id: row = layout.row() - if ma: - row.template_list(ma, "textures", ma, "active_texture_index", type="ICONS") - elif la: - row.template_list(la, "textures", la, "active_texture_index", type="ICONS") - elif wo: - row.template_list(wo, "textures", wo, "active_texture_index", type="ICONS") - elif br: - row.template_list(br, "textures", br, "active_texture_index", type="ICONS") + row.template_list(id, "textures", id, "active_texture_index", type="ICONS") split = layout.split(percentage=0.65) - if ma or la or wo or br: - if slot: - split.template_ID(slot, "texture", new="texture.new") - else: - split.itemS() + if id: + split.template_ID(id, "active_texture", new="texture.new") elif tex: split.template_ID(space, "pin_id") @@ -75,8 +75,6 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel): (context.sculpt_object or context.vertex_paint_object or \ context.weight_paint_object or context.texture_paint_object): split.itemR(space, "brush_texture", text="Brush", toggle=True) - else: - split.itemS() layout.itemS() diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index e064fd7f935..2bb4333365b 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -46,29 +46,32 @@ static void rna_Brush_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *p static PointerRNA rna_Brush_active_texture_get(PointerRNA *ptr) { - Brush *brush= (Brush*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, brush->mtex[(int)brush->texact]); + Brush *br= (Brush*)ptr->data; + Tex *tex; + + tex= (br->mtex[(int)br->texact])? br->mtex[(int)br->texact]->tex: NULL; + return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex); } -static void rna_Brush_active_texture_index_set(PointerRNA *ptr, int value) +static void rna_Brush_active_texture_set(PointerRNA *ptr, PointerRNA value) { - Brush *brush= (Brush*)ptr->data; - int act= brush->texact; - - if(value == act || value < 0 || value >= MAX_MTEX) - return; - - /* auto create/free mtex on activate/deactive, so we can edit - * the texture pointer in the buttons UI. */ - if(brush->mtex[act] && !brush->mtex[act]->tex) { - MEM_freeN(brush->mtex[act]); - brush->mtex[act]= NULL; + Brush *br= (Brush*)ptr->data; + int act= br->texact; + + if(br->mtex[act] && br->mtex[act]->tex) + id_us_min(&br->mtex[act]->tex->id); + + if(value.data) { + if(!br->mtex[act]) + br->mtex[act]= add_mtex(); + + br->mtex[act]->tex= value.data; + id_us_plus(&br->mtex[act]->tex->id); + } + else if(br->mtex[act]) { + MEM_freeN(br->mtex[act]); + br->mtex[act]= NULL; } - - brush->texact= value; - - if(!brush->mtex[value]) - brush->mtex[value]= add_mtex(); } static float rna_Brush_rotation_get(PointerRNA *ptr) @@ -224,7 +227,8 @@ void rna_def_brush(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Curve", "Editable falloff curve."); /* texture */ - rna_def_mtex_common(srna, "rna_Brush_mtex_begin", "rna_Brush_active_texture_get", "rna_Brush_active_texture_index_set", "TextureSlot"); + rna_def_mtex_common(srna, "rna_Brush_mtex_begin", "rna_Brush_active_texture_get", + "rna_Brush_active_texture_set", "TextureSlot"); /* clone tool */ prop= RNA_def_property(srna, "clone_image", PROP_POINTER, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_lamp.c b/source/blender/makesrna/intern/rna_lamp.c index b8150ee3c7d..299bd37496b 100644 --- a/source/blender/makesrna/intern/rna_lamp.c +++ b/source/blender/makesrna/intern/rna_lamp.c @@ -64,30 +64,33 @@ static void rna_Lamp_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *pt static PointerRNA rna_Lamp_active_texture_get(PointerRNA *ptr) { Lamp *la= (Lamp*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, la->mtex[(int)la->texact]); + Tex *tex; + + tex= (la->mtex[(int)la->texact])? la->mtex[(int)la->texact]->tex: NULL; + return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex); } -static void rna_Lamp_active_texture_index_set(PointerRNA *ptr, int value) +static void rna_Lamp_active_texture_set(PointerRNA *ptr, PointerRNA value) { Lamp *la= (Lamp*)ptr->data; int act= la->texact; - if(value == act || value < 0 || value >= MAX_MTEX) - return; + if(la->mtex[act] && la->mtex[act]->tex) + id_us_min(&la->mtex[act]->tex->id); - /* auto create/free mtex on activate/deactive, so we can edit - * the texture pointer in the buttons UI. */ - if(la->mtex[act] && !la->mtex[act]->tex) { + if(value.data) { + if(!la->mtex[act]) { + la->mtex[act]= add_mtex(); + la->mtex[act]->texco= TEXCO_GLOB; + } + + la->mtex[act]->tex= value.data; + id_us_plus(&la->mtex[act]->tex->id); + } + else if(la->mtex[act]) { MEM_freeN(la->mtex[act]); la->mtex[act]= NULL; } - - la->texact= value; - - if(!la->mtex[value]) { - la->mtex[value]= add_mtex(); - la->mtex[value]->texco= TEXCO_GLOB; - } } static StructRNA* rna_Lamp_refine(struct PointerRNA *ptr) @@ -349,7 +352,8 @@ static void rna_def_lamp(BlenderRNA *brna) RNA_def_property_update(prop, NC_LAMP|ND_LIGHTING, NULL); /* textures */ - rna_def_mtex_common(srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get", "rna_Lamp_active_texture_index_set", "LampTextureSlot"); + rna_def_mtex_common(srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get", + "rna_Lamp_active_texture_set", "LampTextureSlot"); } static void rna_def_lamp_falloff(StructRNA *srna) diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index f8cead563ff..d7c677d05f3 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -85,28 +85,31 @@ static void rna_Material_mtex_begin(CollectionPropertyIterator *iter, PointerRNA static PointerRNA rna_Material_active_texture_get(PointerRNA *ptr) { Material *ma= (Material*)ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, ma->mtex[(int)ma->texact]); + Tex *tex; + + tex= (ma->mtex[(int)ma->texact])? ma->mtex[(int)ma->texact]->tex: NULL; + return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex); } -static void rna_Material_active_texture_index_set(PointerRNA *ptr, int value) +static void rna_Material_active_texture_set(PointerRNA *ptr, PointerRNA value) { Material *ma= (Material*)ptr->data; int act= ma->texact; - if(value == act || value < 0 || value >= MAX_MTEX) - return; + if(ma->mtex[act] && ma->mtex[act]->tex) + id_us_min(&ma->mtex[act]->tex->id); - /* auto create/free mtex on activate/deactive, so we can edit - * the texture pointer in the buttons UI. */ - if(ma->mtex[act] && !ma->mtex[act]->tex) { + if(value.data) { + if(!ma->mtex[act]) + ma->mtex[act]= add_mtex(); + + ma->mtex[act]->tex= value.data; + id_us_plus(&ma->mtex[act]->tex->id); + } + else if(ma->mtex[act]) { MEM_freeN(ma->mtex[act]); ma->mtex[act]= NULL; } - - ma->texact= value; - - if(!ma->mtex[value]) - ma->mtex[value]= add_mtex(); } static void rna_MaterialStrand_start_size_range(PointerRNA *ptr, float *min, float *max) @@ -1276,7 +1279,8 @@ void RNA_def_material(BlenderRNA *brna) /* common */ rna_def_animdata_common(srna); - rna_def_mtex_common(srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get", "rna_Material_active_texture_index_set", "MaterialTextureSlot"); + rna_def_mtex_common(srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get", + "rna_Material_active_texture_set", "MaterialTextureSlot"); rna_def_material_colors(srna); rna_def_material_diffuse(srna); @@ -1302,14 +1306,13 @@ void rna_def_mtex_common(StructRNA *srna, const char *begin, const char *activeg RNA_def_property_ui_text(prop, "Textures", "Texture slots defining the mapping and influence of textures."); prop= RNA_def_property(srna, "active_texture", PROP_POINTER, PROP_NONE); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_struct_type(prop, structname); - RNA_def_property_pointer_funcs(prop, activeget, NULL, NULL); + RNA_def_property_struct_type(prop, "Texture"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, activeget, activeset, NULL); RNA_def_property_ui_text(prop, "Active Texture", "Active texture slot being displayed."); prop= RNA_def_property(srna, "active_texture_index", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "texact"); - RNA_def_property_int_funcs(prop, NULL, activeset, NULL); RNA_def_property_range(prop, 0, MAX_MTEX-1); RNA_def_property_ui_text(prop, "Active Texture Index", "Index of active texture slot."); } diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 8c6f77a1e83..53a73e0b03e 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -377,7 +377,17 @@ static void rna_Object_active_material_index_range(PointerRNA *ptr, int *min, in static PointerRNA rna_Object_active_material_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; - return rna_pointer_inherit_refine(ptr, &RNA_MaterialSlot, ob->mat+ob->actcol); + Material *ma; + + ma= (ob->totcol)? give_current_material(ob, ob->actcol): NULL; + return rna_pointer_inherit_refine(ptr, &RNA_Material, ma); +} + +static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value) +{ + Object *ob= (Object*)ptr->id.data; + + assign_material(ob, value.data, ob->actcol); } static void rna_Object_active_particle_system_index_range(PointerRNA *ptr, int *min, int *max) @@ -400,15 +410,6 @@ static void rna_Object_active_particle_system_index_set(struct PointerRNA *ptr, psys_set_current_num(ob, value); } -#if 0 -static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value) -{ - Object *ob= (Object*)ptr->id.data; - - assign_material(ob, value.data, ob->actcol); -} -#endif - static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; @@ -1027,9 +1028,11 @@ static void rna_def_object(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Materials", "Material slots in the object."); prop= RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE); - RNA_def_property_struct_type(prop, "MaterialSlot"); - RNA_def_property_pointer_funcs(prop, "rna_Object_active_material_get", NULL, NULL); + RNA_def_property_struct_type(prop, "Material"); + RNA_def_property_pointer_funcs(prop, "rna_Object_active_material_get", "rna_Object_active_material_set", NULL); + RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed."); + RNA_def_property_update(prop, NC_OBJECT|ND_SHADING, "rna_Object_update"); prop= RNA_def_property(srna, "active_material_index", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "actcol"); diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c index 8beaa855201..f23b893539d 100644 --- a/source/blender/makesrna/intern/rna_world.c +++ b/source/blender/makesrna/intern/rna_world.c @@ -66,31 +66,33 @@ static void rna_World_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *p static PointerRNA rna_World_active_texture_get(PointerRNA *ptr) { World *wo= (World*)ptr->data; + Tex *tex; - return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, wo->mtex[(int)wo->texact]); + tex= (wo->mtex[(int)wo->texact])? wo->mtex[(int)wo->texact]->tex: NULL; + return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex); } -static void rna_World_active_texture_index_set(PointerRNA *ptr, int value) +static void rna_World_active_texture_set(PointerRNA *ptr, PointerRNA value) { World *wo= (World*)ptr->data; int act= wo->texact; - if(value == act || value < 0 || value >= MAX_MTEX) - return; - - /* auto create/free mtex on activate/deactive, so we can edit - * the texture pointer in the buttons UI. */ - if(wo->mtex[act] && !wo->mtex[act]->tex) { + if(wo->mtex[act] && wo->mtex[act]->tex) + id_us_min(&wo->mtex[act]->tex->id); + + if(value.data) { + if(!wo->mtex[act]) { + wo->mtex[act]= add_mtex(); + wo->mtex[act]->texco= TEXCO_VIEW; + } + + wo->mtex[act]->tex= value.data; + id_us_plus(&wo->mtex[act]->tex->id); + } + else if(wo->mtex[act]) { MEM_freeN(wo->mtex[act]); wo->mtex[act]= NULL; } - - wo->texact= value; - - if(!wo->mtex[value]) { - wo->mtex[value]= add_mtex(); - wo->mtex[value]->texco= TEXCO_VIEW; - } } #else @@ -407,7 +409,8 @@ void RNA_def_world(BlenderRNA *brna) RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA); rna_def_animdata_common(srna); - rna_def_mtex_common(srna, "rna_World_mtex_begin", "rna_World_active_texture_get", "rna_World_active_texture_index_set", "WorldTextureSlot"); + rna_def_mtex_common(srna, "rna_World_mtex_begin", "rna_World_active_texture_get", + "rna_World_active_texture_set", "WorldTextureSlot"); /* colors */ prop= RNA_def_property(srna, "horizon_color", PROP_FLOAT, PROP_COLOR); |