diff options
Diffstat (limited to 'source/blender/editors/space_buttons')
-rw-r--r-- | source/blender/editors/space_buttons/buttons_context.c | 107 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_texture.c | 50 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/space_buttons.c | 7 |
3 files changed, 162 insertions, 2 deletions
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index a1ecb1c4f5c..da3364d872d 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -46,13 +46,13 @@ #include "DNA_world_types.h" #include "DNA_brush_types.h" #include "DNA_linestyle_types.h" -#include "DNA_object_types.h" #include "BKE_context.h" #include "BKE_action.h" #include "BKE_material.h" #include "BKE_modifier.h" #include "BKE_paint.h" +#include "BKE_particle.h" #include "BKE_screen.h" #include "BKE_texture.h" #include "BKE_linestyle.h" @@ -339,6 +339,34 @@ static int buttons_context_path_pose_bone(ButsContextPath *path) return 0; } + +static int buttons_context_path_particle(ButsContextPath *path) +{ + Object *ob; + ParticleSystem *psys; + PointerRNA *ptr = &path->ptr[path->len - 1]; + + /* if we already have (pinned) particle settings, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_ParticleSettings)) { + return 1; + } + /* if we have an object, get the active particle system */ + if (buttons_context_path_object(path)) { + ob = path->ptr[path->len - 1].data; + + if (ob && ob->type == OB_MESH) { + psys = psys_get_current(ob); + + RNA_pointer_create(&ob->id, &RNA_ParticleSystem, psys, &path->ptr[path->len]); + path->len++; + return 1; + } + } + + /* no path to a particle system possible */ + return 0; +} + static int buttons_context_path_brush(ButsContextPath *path) { Scene *scene; @@ -393,6 +421,8 @@ static int buttons_context_path_texture(ButsContextPath *path, ButsContextTextur buttons_context_path_world(path); else if (GS(id->name) == ID_LA) buttons_context_path_data(path, OB_LAMP); + else if (GS(id->name) == ID_PA) + buttons_context_path_particle(path); else if (GS(id->name) == ID_OB) buttons_context_path_object(path); else if (GS(id->name) == ID_LS) @@ -411,6 +441,7 @@ static int buttons_context_path_texture(ButsContextPath *path, ButsContextTextur Material *ma; Lamp *la; World *wo; + ParticleSystem *psys; FreestyleLineStyle *ls; Tex *tex; PointerRNA *ptr = &path->ptr[path->len - 1]; @@ -431,6 +462,28 @@ static int buttons_context_path_texture(ButsContextPath *path, ButsContextTextur return 1; } } + /* try particles */ + else if ((path->tex_ctx == SB_TEXC_PARTICLES) && buttons_context_path_particle(path)) { + if (path->ptr[path->len - 1].type == &RNA_ParticleSettings) { + ParticleSettings *part = path->ptr[path->len - 1].data; + + tex = give_current_particle_texture(part); + RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); + path->len++; + return 1; + } + else { + psys = path->ptr[path->len - 1].data; + + if (psys && psys->part && GS(psys->part->id.name) == ID_PA) { + tex = give_current_particle_texture(psys->part); + + RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); + path->len++; + return 1; + } + } + } /* try material */ else if ((path->tex_ctx == SB_TEXC_MATERIAL) && buttons_context_path_material(path, true, false)) { ma = path->ptr[path->len - 1].data; @@ -557,6 +610,9 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma case BCONTEXT_DATA: found = buttons_context_path_data(path, -1); break; + case BCONTEXT_PARTICLE: + found = buttons_context_path_particle(path); + break; case BCONTEXT_MATERIAL: found = buttons_context_path_material(path, false, (sbuts->texuser != NULL)); break; @@ -844,7 +900,14 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r ButsContextTexture *ct = sbuts->texuser; PointerRNA *ptr; - if (ct) { + /* Particles slots are used in both old and new textures handling. */ + if ((ptr = get_pointer_type(path, &RNA_ParticleSystem))) { + ParticleSettings *part = ((ParticleSystem *)ptr->data)->part; + + if (part) + CTX_data_pointer_set(result, &part->id, &RNA_ParticleSettingsTextureSlot, part->mtex[(int)part->texact]); + } + else if (ct) { return 0; /* new shading system */ } else if ((ptr = get_pointer_type(path, &RNA_Material))) { @@ -900,6 +963,38 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r set_pointer_type(path, result, &RNA_PoseBone); return 1; } + else if (CTX_data_equals(member, "particle_system")) { + set_pointer_type(path, result, &RNA_ParticleSystem); + return 1; + } + else if (CTX_data_equals(member, "particle_system_editable")) { + if (PE_poll((bContext *)C)) + set_pointer_type(path, result, &RNA_ParticleSystem); + else + CTX_data_pointer_set(result, NULL, &RNA_ParticleSystem, NULL); + return 1; + } + else if (CTX_data_equals(member, "particle_settings")) { + /* only available when pinned */ + PointerRNA *ptr = get_pointer_type(path, &RNA_ParticleSettings); + + if (ptr && ptr->data) { + CTX_data_pointer_set(result, ptr->id.data, &RNA_ParticleSettings, ptr->data); + return 1; + } + else { + /* get settings from active particle system instead */ + ptr = get_pointer_type(path, &RNA_ParticleSystem); + + if (ptr && ptr->data) { + ParticleSettings *part = ((ParticleSystem *)ptr->data)->part; + CTX_data_pointer_set(result, ptr->id.data, &RNA_ParticleSettings, part); + return 1; + } + } + set_pointer_type(path, result, &RNA_ParticleSettings); + return 1; + } else if (CTX_data_equals(member, "cloth")) { PointerRNA *ptr = get_pointer_type(path, &RNA_Object); @@ -1069,6 +1164,14 @@ ID *buttons_context_id_path(const bContext *C) for (a = path->len - 1; a >= 0; a--) { ptr = &path->ptr[a]; + /* pin particle settings instead of system, since only settings are an idblock*/ + if (sbuts->mainb == BCONTEXT_PARTICLE && sbuts->flag & SB_PIN_CONTEXT) { + if (ptr->type == &RNA_ParticleSystem && ptr->data) { + ParticleSystem *psys = (ParticleSystem *)ptr->data; + return &psys->part->id; + } + } + if (ptr->id.data) { return ptr->id.data; } diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c index 87cf0e8c9e3..72de7e5c81c 100644 --- a/source/blender/editors/space_buttons/buttons_texture.c +++ b/source/blender/editors/space_buttons/buttons_texture.c @@ -46,6 +46,7 @@ #include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_object_force.h" +#include "DNA_particle_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" @@ -58,6 +59,7 @@ #include "BKE_modifier.h" #include "BKE_node.h" #include "BKE_paint.h" +#include "BKE_particle.h" #include "BKE_scene.h" #ifdef WITH_FREESTYLE # include "BKE_freestyle.h" @@ -96,6 +98,12 @@ bool ED_texture_context_check_lamp(const bContext *C) return (ob && (ob->type == OB_LAMP)); } +bool ED_texture_context_check_particles(const bContext *C) +{ + Object *ob = CTX_data_active_object(C); + return (ob && ob->particlesystem.first); +} + bool ED_texture_context_check_linestyle(const bContext *C) { #ifdef WITH_FREESTYLE @@ -170,6 +178,7 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) bool valid_world = ED_texture_context_check_world(C); bool valid_material = ED_texture_context_check_material(C); bool valid_lamp = ED_texture_context_check_lamp(C); + bool valid_particles = ED_texture_context_check_particles(C); bool valid_linestyle = ED_texture_context_check_linestyle(C); bool valid_others = ED_texture_context_check_others(C); @@ -183,6 +192,9 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) else if ((sbuts->mainb == BCONTEXT_DATA) && valid_lamp) { sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LAMP; } + else if ((sbuts->mainb == BCONTEXT_PARTICLE) && valid_particles) { + sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_PARTICLES; + } else if ((sbuts->mainb == BCONTEXT_RENDER_LAYER) && valid_linestyle) { sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LINESTYLE; } @@ -194,6 +206,7 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) (((sbuts->texture_context_prev == SB_TEXC_WORLD) && valid_world) || ((sbuts->texture_context_prev == SB_TEXC_MATERIAL) && valid_material) || ((sbuts->texture_context_prev == SB_TEXC_LAMP) && valid_lamp) || + ((sbuts->texture_context_prev == SB_TEXC_PARTICLES) && valid_particles) || ((sbuts->texture_context_prev == SB_TEXC_LINESTYLE) && valid_linestyle) || ((sbuts->texture_context_prev == SB_TEXC_OTHER) && valid_others))) { @@ -203,6 +216,7 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) else if (((sbuts->texture_context == SB_TEXC_WORLD) && !valid_world) || ((sbuts->texture_context == SB_TEXC_MATERIAL) && !valid_material) || ((sbuts->texture_context == SB_TEXC_LAMP) && !valid_lamp) || + ((sbuts->texture_context == SB_TEXC_PARTICLES) && !valid_particles) || ((sbuts->texture_context == SB_TEXC_LINESTYLE) && !valid_linestyle) || ((sbuts->texture_context == SB_TEXC_OTHER) && !valid_others)) { @@ -214,6 +228,9 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) else if (valid_lamp) { sbuts->texture_context = SB_TEXC_LAMP; } + else if (valid_particles) { + sbuts->texture_context = SB_TEXC_PARTICLES; + } else if (valid_linestyle) { sbuts->texture_context = SB_TEXC_LINESTYLE; } @@ -358,9 +375,31 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext * buttons_texture_users_find_nodetree(users, &linestyle->id, linestyle->nodetree, N_("Line Style")); if (ob) { + ParticleSystem *psys = psys_get_current(ob); + MTex *mtex; + int a; + /* modifiers */ modifiers_foreachTexLink(ob, buttons_texture_modifier_foreach, users); + /* particle systems */ + if (psys && !limited_mode) { + for (a = 0; a < MAX_MTEX; a++) { + mtex = psys->part->mtex[a]; + + if (mtex) { + PointerRNA ptr; + PropertyRNA *prop; + + RNA_pointer_create(&psys->part->id, &RNA_ParticleSettingsTextureSlot, mtex, &ptr); + prop = RNA_struct_find_property(&ptr, "texture"); + + buttons_texture_user_property_add(users, &psys->part->id, ptr, prop, N_("Particles"), + RNA_struct_ui_icon(&RNA_ParticleSettings), psys->name); + } + } + } + /* field */ if (ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) { PointerRNA ptr; @@ -490,6 +529,17 @@ static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg) ct->texture = tex; + if (user->ptr.type == &RNA_ParticleSettingsTextureSlot) { + /* stupid exception for particle systems which still uses influence + * from the old texture system, set the active texture slots as well */ + ParticleSettings *part = user->ptr.id.data; + int a; + + for (a = 0; a < MAX_MTEX; a++) + if (user->ptr.data == part->mtex[a]) + part->texact = a; + } + if (sbuts && tex) sbuts->preview = 1; } diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index f91a357504d..e4c23ad74f8 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -159,6 +159,8 @@ static void buttons_main_region_draw(const bContext *C, ARegion *ar) ED_region_panels(C, ar, "material", sbuts->mainb, vertical); else if (sbuts->mainb == BCONTEXT_TEXTURE) ED_region_panels(C, ar, "texture", sbuts->mainb, vertical); + else if (sbuts->mainb == BCONTEXT_PARTICLE) + ED_region_panels(C, ar, "particle", sbuts->mainb, vertical); else if (sbuts->mainb == BCONTEXT_PHYSICS) ED_region_panels(C, ar, "physics", sbuts->mainb, vertical); else if (sbuts->mainb == BCONTEXT_BONE) @@ -279,6 +281,11 @@ static void buttons_area_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier * buttons_area_redraw(sa, BCONTEXT_CONSTRAINT); buttons_area_redraw(sa, BCONTEXT_BONE_CONSTRAINT); break; + case ND_PARTICLE: + if (wmn->action == NA_EDITED) + buttons_area_redraw(sa, BCONTEXT_PARTICLE); + sbuts->preview = 1; + break; case ND_DRAW: buttons_area_redraw(sa, BCONTEXT_OBJECT); buttons_area_redraw(sa, BCONTEXT_DATA); |