diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-05-03 13:51:53 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-05-03 13:54:59 +0400 |
commit | b7f085d9c128f31d576c732c6439b5a71e8922ee (patch) | |
tree | 8a1fdc2e95470f61d9121b18b125dc272e87d536 /source/blender/editors/space_buttons | |
parent | 6ec2d72eca618be05e9bf0723886b10e6d5efa46 (diff) |
Patch D246: Texture Marks for freestyle strokes, written and contributed by Paolo Acampora.
Reviewers: brecht, kjym3, #freestyle
Reviewed By: brecht, kjym3
Differential Revision: https://developer.blender.org/D246
Diffstat (limited to 'source/blender/editors/space_buttons')
-rw-r--r-- | source/blender/editors/space_buttons/buttons_context.c | 79 | ||||
-rw-r--r-- | source/blender/editors/space_buttons/buttons_texture.c | 24 |
2 files changed, 102 insertions, 1 deletions
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 895c38747c1..3f5d7de5cd0 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -45,6 +45,7 @@ #include "DNA_scene_types.h" #include "DNA_world_types.h" #include "DNA_brush_types.h" +#include "DNA_linestyle_types.h" #include "BKE_context.h" #include "BKE_action.h" @@ -139,6 +140,30 @@ static int buttons_context_path_world(ButsContextPath *path) return 0; } +static int buttons_context_path_linestyle(ButsContextPath *path) +{ + Scene *scene; + FreestyleLineStyle *linestyle; + PointerRNA *ptr = &path->ptr[path->len - 1]; + + /* if we already have a (pinned) linestyle, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_FreestyleLineStyle)) { + return 1; + } + /* if we have a scene, use the lineset's linestyle */ + else if (buttons_context_path_scene(path)) { + scene = path->ptr[path->len - 1].data; + linestyle = CTX_data_linestyle_from_scene(scene); + if (linestyle) { + RNA_id_pointer_create(&linestyle->id, &path->ptr[path->len]); + path->len++; + return 1; + } + } + + /* no path to a linestyle possible */ + return 0; +} static int buttons_context_path_object(ButsContextPath *path) { @@ -395,6 +420,8 @@ static int buttons_context_path_texture(ButsContextPath *path, ButsContextTextur buttons_context_path_particle(path); else if (GS(id->name) == ID_OB) buttons_context_path_object(path); + else if (GS(id->name) == ID_LS) + buttons_context_path_linestyle(path); } if (ct->texture) { @@ -410,6 +437,7 @@ static int buttons_context_path_texture(ButsContextPath *path, ButsContextTextur Lamp *la; World *wo; ParticleSystem *psys; + FreestyleLineStyle *ls; Tex *tex; PointerRNA *ptr = &path->ptr[path->len - 1]; @@ -475,12 +503,40 @@ static int buttons_context_path_texture(ButsContextPath *path, ButsContextTextur return 1; } } + /* try linestyle */ + else if ((path->tex_ctx == SB_TEXC_LINESTYLE) && buttons_context_path_linestyle(path)) { + ls = path->ptr[path->len - 1].data; + + if (ls) { + tex = give_current_linestyle_texture(ls); + + RNA_id_pointer_create(&tex->id, &path->ptr[path->len]); + path->len++; + return 1; + } + } } /* no path to a texture possible */ return 0; } +static bool buttons_context_linestyle_pinnable(const bContext *C) +{ + Scene *scene = CTX_data_scene(C); + SpaceButs *sbuts; + + /* if Freestyle is disabled in the scene */ + if ((scene->r.mode & R_EDGE_FRS) == 0) { + return false; + } + /* if the scene has already been pinned */ + sbuts = CTX_wm_space_buts(C); + if (sbuts->pinid && sbuts->pinid == &scene->id) { + return false; + } + return true; +} static int buttons_context_path(const bContext *C, ButsContextPath *path, int mainb, int flag) { @@ -512,7 +568,17 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma switch (mainb) { case BCONTEXT_SCENE: case BCONTEXT_RENDER: + found = buttons_context_path_scene(path); + break; case BCONTEXT_RENDER_LAYER: +#ifdef WITH_FREESTYLE + if (buttons_context_linestyle_pinnable(C)) { + found = buttons_context_path_linestyle(path); + if (found) { + break; + } + } +#endif found = buttons_context_path_scene(path); break; case BCONTEXT_WORLD: @@ -662,7 +728,8 @@ const char *buttons_context_dir[] = { "meta_ball", "lamp", "speaker", "camera", "material", "material_slot", "texture", "texture_user", "texture_user_property", "bone", "edit_bone", "pose_bone", "particle_system", "particle_system_editable", "particle_settings", - "cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint", NULL + "cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint", + "line_style", NULL }; int buttons_context(const bContext *C, const char *member, bContextDataResult *result) @@ -860,6 +927,12 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r if (wo) CTX_data_pointer_set(result, &wo->id, &RNA_WorldTextureSlot, wo->mtex[(int)wo->texact]); } + else if ((ptr = get_pointer_type(path, &RNA_FreestyleLineStyle))) { + FreestyleLineStyle *ls = ptr->data; + + if (ls) + CTX_data_pointer_set(result, &ls->id, &RNA_LineStyleTextureSlot, ls->mtex[(int)ls->texact]); + } return 1; } @@ -972,6 +1045,10 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r return 1; } } + else if (CTX_data_equals(member, "line_style")) { + set_pointer_type(path, result, &RNA_FreestyleLineStyle); + return 1; + } else { return 0; /* not found */ } diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c index 7c42ea9a13b..4ba0ddaed50 100644 --- a/source/blender/editors/space_buttons/buttons_texture.c +++ b/source/blender/editors/space_buttons/buttons_texture.c @@ -51,6 +51,8 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" #include "DNA_world_types.h" +#include "DNA_linestyle_types.h" + #include "BKE_context.h" #include "BKE_material.h" @@ -99,6 +101,13 @@ bool ED_texture_context_check_particles(const bContext *C) return (ob && ob->particlesystem.first); } +bool ED_texture_context_check_linestyle(const bContext *C) +{ + Scene *scene = CTX_data_scene(C); + FreestyleLineStyle *ls = CTX_data_linestyle_from_scene(scene); + return (scene && (scene->r.mode & R_EDGE_FRS) && ls && (ls->flag & LS_TEXTURE)); +} + static void texture_context_check_modifier_foreach(void *userData, Object *UNUSED(ob), ModifierData *UNUSED(md), const char *UNUSED(propname)) { @@ -148,6 +157,7 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) 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); /* this is similar to direct user action, no need to keep "better" ctxt in _prev */ @@ -163,6 +173,9 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) 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; + } else if ((ELEM(sbuts->mainb, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && valid_others) { sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_OTHER; } @@ -172,6 +185,7 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) ((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))) { sbuts->texture_context = sbuts->texture_context_prev; @@ -181,6 +195,7 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) ((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)) { /* this is default fallback, do keep "better" ctxt in _prev */ @@ -194,6 +209,9 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts) else if (valid_particles) { sbuts->texture_context = SB_TEXC_PARTICLES; } + else if (valid_linestyle) { + sbuts->texture_context = SB_TEXC_LINESTYLE; + } else if (valid_world) { sbuts->texture_context = SB_TEXC_WORLD; } @@ -284,6 +302,7 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext * Material *ma = NULL; Lamp *la = NULL; World *wrld = NULL; + FreestyleLineStyle *linestyle = NULL; Brush *brush = NULL; ID *pinid = sbuts->pinid; bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0; @@ -302,6 +321,8 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext * ma = (Material *)pinid; else if (GS(pinid->name) == ID_BR) brush = (Brush *)pinid; + else if (GS(pinid->name) == ID_LS) + linestyle = (FreestyleLineStyle *)pinid; } if (!scene) @@ -311,6 +332,7 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext * ob = (scene->basact) ? scene->basact->object : NULL; wrld = scene->world; brush = BKE_paint_brush(BKE_paint_get_active_from_context(C)); + linestyle = CTX_data_linestyle_from_scene(scene); } if (ob && ob->type == OB_LAMP && !la) @@ -327,6 +349,8 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext * buttons_texture_users_find_nodetree(users, &la->id, la->nodetree, "Lamp"); if (wrld && !limited_mode) buttons_texture_users_find_nodetree(users, &wrld->id, wrld->nodetree, "World"); + if (linestyle && !limited_mode) + buttons_texture_users_find_nodetree(users, &linestyle->id, linestyle->nodetree, "LineStyle"); if (ob) { ParticleSystem *psys = psys_get_current(ob); |