From e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 17 Apr 2019 06:17:24 +0200 Subject: ClangFormat: apply to source, most of intern Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat --- .../blender/editors/space_buttons/CMakeLists.txt | 36 +- .../editors/space_buttons/buttons_context.c | 2001 ++++++++++---------- .../blender/editors/space_buttons/buttons_intern.h | 40 +- source/blender/editors/space_buttons/buttons_ops.c | 408 ++-- .../editors/space_buttons/buttons_texture.c | 867 +++++---- .../blender/editors/space_buttons/space_buttons.c | 1175 ++++++------ 6 files changed, 2335 insertions(+), 2192 deletions(-) (limited to 'source/blender/editors/space_buttons') diff --git a/source/blender/editors/space_buttons/CMakeLists.txt b/source/blender/editors/space_buttons/CMakeLists.txt index 5ec2041c1dc..ce08b62e8ef 100644 --- a/source/blender/editors/space_buttons/CMakeLists.txt +++ b/source/blender/editors/space_buttons/CMakeLists.txt @@ -16,42 +16,42 @@ # ***** END GPL LICENSE BLOCK ***** set(INC - ../include - ../../blenkernel - ../../blenlib - ../../blentranslation - ../../gpu - ../../makesdna - ../../makesrna - ../../windowmanager - ../../../../intern/guardedalloc - ../../../../intern/glew-mx + ../include + ../../blenkernel + ../../blenlib + ../../blentranslation + ../../gpu + ../../makesdna + ../../makesrna + ../../windowmanager + ../../../../intern/guardedalloc + ../../../../intern/glew-mx ) set(INC_SYS - ${GLEW_INCLUDE_PATH} + ${GLEW_INCLUDE_PATH} ) set(SRC - buttons_context.c - buttons_ops.c - buttons_texture.c - space_buttons.c + buttons_context.c + buttons_ops.c + buttons_texture.c + space_buttons.c - buttons_intern.h + buttons_intern.h ) set(LIB ) if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) + add_definitions(-DWITH_INTERNATIONAL) endif() add_definitions(${GL_DEFINITIONS}) if(WITH_FREESTYLE) - add_definitions(-DWITH_FREESTYLE) + add_definitions(-DWITH_FREESTYLE) endif() blender_add_lib(bf_editor_space_buttons "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 0579e20bb5a..607c3ddbb10 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -21,7 +21,6 @@ * \ingroup spbuttons */ - #include #include @@ -66,1058 +65,1120 @@ #include "WM_api.h" -#include "buttons_intern.h" // own include +#include "buttons_intern.h" // own include static int set_pointer_type(ButsContextPath *path, bContextDataResult *result, StructRNA *type) { - PointerRNA *ptr; - int a; + PointerRNA *ptr; + int a; - for (a = 0; a < path->len; a++) { - ptr = &path->ptr[a]; + for (a = 0; a < path->len; a++) { + ptr = &path->ptr[a]; - if (RNA_struct_is_a(ptr->type, type)) { - CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data); - return 1; - } - } + if (RNA_struct_is_a(ptr->type, type)) { + CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data); + return 1; + } + } - return 0; + return 0; } static PointerRNA *get_pointer_type(ButsContextPath *path, StructRNA *type) { - PointerRNA *ptr; - int a; + PointerRNA *ptr; + int a; - for (a = 0; a < path->len; a++) { - ptr = &path->ptr[a]; + for (a = 0; a < path->len; a++) { + ptr = &path->ptr[a]; - if (RNA_struct_is_a(ptr->type, type)) { - return ptr; - } - } + if (RNA_struct_is_a(ptr->type, type)) { + return ptr; + } + } - return NULL; + return NULL; } /************************* Creating the Path ************************/ static int buttons_context_path_scene(ButsContextPath *path) { - PointerRNA *ptr = &path->ptr[path->len - 1]; + PointerRNA *ptr = &path->ptr[path->len - 1]; - /* this one just verifies */ - return RNA_struct_is_a(ptr->type, &RNA_Scene); + /* this one just verifies */ + return RNA_struct_is_a(ptr->type, &RNA_Scene); } static int buttons_context_path_view_layer(ButsContextPath *path, wmWindow *win) { - PointerRNA *ptr = &path->ptr[path->len - 1]; - - /* View Layer may have already been resolved in a previous call - * (e.g. in buttons_context_path_linestyle). */ - if (RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) { - return 1; - } - - if (buttons_context_path_scene(path)) { - Scene *scene = path->ptr[path->len - 1].data; - ViewLayer *view_layer = (win->scene == scene) ? - WM_window_get_active_view_layer(win) : - BKE_view_layer_default_view(scene); - - RNA_pointer_create(&scene->id, &RNA_ViewLayer, view_layer, &path->ptr[path->len]); - path->len++; - return 1; - } - - return 0; + PointerRNA *ptr = &path->ptr[path->len - 1]; + + /* View Layer may have already been resolved in a previous call + * (e.g. in buttons_context_path_linestyle). */ + if (RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) { + return 1; + } + + if (buttons_context_path_scene(path)) { + Scene *scene = path->ptr[path->len - 1].data; + ViewLayer *view_layer = (win->scene == scene) ? WM_window_get_active_view_layer(win) : + BKE_view_layer_default_view(scene); + + RNA_pointer_create(&scene->id, &RNA_ViewLayer, view_layer, &path->ptr[path->len]); + path->len++; + return 1; + } + + return 0; } /* note: this function can return 1 without adding a world to the path * so the buttons stay visible, but be sure to check the ID type if a ID_WO */ static int buttons_context_path_world(ButsContextPath *path) { - Scene *scene; - World *world; - PointerRNA *ptr = &path->ptr[path->len - 1]; - - /* if we already have a (pinned) world, we're done */ - if (RNA_struct_is_a(ptr->type, &RNA_World)) { - return 1; - } - /* if we have a scene, use the scene's world */ - else if (buttons_context_path_scene(path)) { - scene = path->ptr[path->len - 1].data; - world = scene->world; - - if (world) { - RNA_id_pointer_create(&scene->world->id, &path->ptr[path->len]); - path->len++; - return 1; - } - else { - return 1; - } - } - - /* no path to a world possible */ - return 0; + Scene *scene; + World *world; + PointerRNA *ptr = &path->ptr[path->len - 1]; + + /* if we already have a (pinned) world, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_World)) { + return 1; + } + /* if we have a scene, use the scene's world */ + else if (buttons_context_path_scene(path)) { + scene = path->ptr[path->len - 1].data; + world = scene->world; + + if (world) { + RNA_id_pointer_create(&scene->world->id, &path->ptr[path->len]); + path->len++; + return 1; + } + else { + return 1; + } + } + + /* no path to a world possible */ + return 0; } static int buttons_context_path_linestyle(ButsContextPath *path, wmWindow *window) { - 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 view layer, use the lineset's linestyle */ - else if (buttons_context_path_view_layer(path, window)) { - ViewLayer *view_layer = path->ptr[path->len - 1].data; - linestyle = BKE_linestyle_active_from_view_layer(view_layer); - if (linestyle) { - RNA_id_pointer_create(&linestyle->id, &path->ptr[path->len]); - path->len++; - return 1; - } - } - - /* no path to a linestyle possible */ - return 0; + 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 view layer, use the lineset's linestyle */ + else if (buttons_context_path_view_layer(path, window)) { + ViewLayer *view_layer = path->ptr[path->len - 1].data; + linestyle = BKE_linestyle_active_from_view_layer(view_layer); + 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) { - PointerRNA *ptr = &path->ptr[path->len - 1]; + PointerRNA *ptr = &path->ptr[path->len - 1]; - /* if we already have a (pinned) object, we're done */ - if (RNA_struct_is_a(ptr->type, &RNA_Object)) { - return 1; - } - if (!RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) { - return 0; - } + /* if we already have a (pinned) object, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_Object)) { + return 1; + } + if (!RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) { + return 0; + } - ViewLayer *view_layer = ptr->data; - Object *ob = (view_layer->basact) ? view_layer->basact->object : NULL; + ViewLayer *view_layer = ptr->data; + Object *ob = (view_layer->basact) ? view_layer->basact->object : NULL; - if (ob) { - RNA_id_pointer_create(&ob->id, &path->ptr[path->len]); - path->len++; + if (ob) { + RNA_id_pointer_create(&ob->id, &path->ptr[path->len]); + path->len++; - return 1; - } + return 1; + } - /* no path to a object possible */ - return 0; + /* no path to a object possible */ + return 0; } static int buttons_context_path_data(ButsContextPath *path, int type) { - Object *ob; - PointerRNA *ptr = &path->ptr[path->len - 1]; - - /* if we already have a data, we're done */ - if (RNA_struct_is_a(ptr->type, &RNA_Mesh) && (type == -1 || type == OB_MESH)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_Curve) && (type == -1 || ELEM(type, OB_CURVE, OB_SURF, OB_FONT))) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_Armature) && (type == -1 || type == OB_ARMATURE)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_MetaBall) && (type == -1 || type == OB_MBALL)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_Lattice) && (type == -1 || type == OB_LATTICE)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_Camera) && (type == -1 || type == OB_CAMERA)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_Light) && (type == -1 || type == OB_LAMP)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_Speaker) && (type == -1 || type == OB_SPEAKER)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_LightProbe) && (type == -1 || type == OB_LIGHTPROBE)) { - return 1; - } - else if (RNA_struct_is_a(ptr->type, &RNA_GreasePencil) && (type == -1 || type == OB_GPENCIL)) { - return 1; - } - /* try to get an object in the path, no pinning supported here */ - else if (buttons_context_path_object(path)) { - ob = path->ptr[path->len - 1].data; - - if (ob && (type == -1 || type == ob->type)) { - RNA_id_pointer_create(ob->data, &path->ptr[path->len]); - path->len++; - - return 1; - } - } - - /* no path to data possible */ - return 0; + Object *ob; + PointerRNA *ptr = &path->ptr[path->len - 1]; + + /* if we already have a data, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_Mesh) && (type == -1 || type == OB_MESH)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_Curve) && + (type == -1 || ELEM(type, OB_CURVE, OB_SURF, OB_FONT))) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_Armature) && (type == -1 || type == OB_ARMATURE)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_MetaBall) && (type == -1 || type == OB_MBALL)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_Lattice) && (type == -1 || type == OB_LATTICE)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_Camera) && (type == -1 || type == OB_CAMERA)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_Light) && (type == -1 || type == OB_LAMP)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_Speaker) && (type == -1 || type == OB_SPEAKER)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_LightProbe) && (type == -1 || type == OB_LIGHTPROBE)) { + return 1; + } + else if (RNA_struct_is_a(ptr->type, &RNA_GreasePencil) && (type == -1 || type == OB_GPENCIL)) { + return 1; + } + /* try to get an object in the path, no pinning supported here */ + else if (buttons_context_path_object(path)) { + ob = path->ptr[path->len - 1].data; + + if (ob && (type == -1 || type == ob->type)) { + RNA_id_pointer_create(ob->data, &path->ptr[path->len]); + path->len++; + + return 1; + } + } + + /* no path to data possible */ + return 0; } static int buttons_context_path_modifier(ButsContextPath *path) { - Object *ob; + Object *ob; - if (buttons_context_path_object(path)) { - ob = path->ptr[path->len - 1].data; + if (buttons_context_path_object(path)) { + ob = path->ptr[path->len - 1].data; - if (ob && ELEM(ob->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_LATTICE, OB_GPENCIL)) { - return 1; - } - } + if (ob && ELEM(ob->type, OB_MESH, OB_CURVE, OB_FONT, OB_SURF, OB_LATTICE, OB_GPENCIL)) { + return 1; + } + } - return 0; + return 0; } static int buttons_context_path_shaderfx(ButsContextPath *path) { - Object *ob; + Object *ob; - if (buttons_context_path_object(path)) { - ob = path->ptr[path->len - 1].data; + if (buttons_context_path_object(path)) { + ob = path->ptr[path->len - 1].data; - if (ob && ELEM(ob->type, OB_GPENCIL)) { - return 1; - } - } + if (ob && ELEM(ob->type, OB_GPENCIL)) { + return 1; + } + } - return 0; + return 0; } static int buttons_context_path_material(ButsContextPath *path) { - Object *ob; - PointerRNA *ptr = &path->ptr[path->len - 1]; - Material *ma; - - /* if we already have a (pinned) material, we're done */ - if (RNA_struct_is_a(ptr->type, &RNA_Material)) { - return 1; - } - /* if we have an object, use the object material slot */ - else if (buttons_context_path_object(path)) { - ob = path->ptr[path->len - 1].data; - - if (ob && OB_TYPE_SUPPORT_MATERIAL(ob->type)) { - ma = give_current_material(ob, ob->actcol); - RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); - path->len++; - return 1; - } - } - - /* no path to a material possible */ - return 0; + Object *ob; + PointerRNA *ptr = &path->ptr[path->len - 1]; + Material *ma; + + /* if we already have a (pinned) material, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_Material)) { + return 1; + } + /* if we have an object, use the object material slot */ + else if (buttons_context_path_object(path)) { + ob = path->ptr[path->len - 1].data; + + if (ob && OB_TYPE_SUPPORT_MATERIAL(ob->type)) { + ma = give_current_material(ob, ob->actcol); + RNA_id_pointer_create(&ma->id, &path->ptr[path->len]); + path->len++; + return 1; + } + } + + /* no path to a material possible */ + return 0; } static int buttons_context_path_bone(ButsContextPath *path) { - bArmature *arm; - EditBone *edbo; - - /* if we have an armature, get the active bone */ - if (buttons_context_path_data(path, OB_ARMATURE)) { - arm = path->ptr[path->len - 1].data; - - if (arm->edbo) { - if (arm->act_edbone) { - edbo = arm->act_edbone; - RNA_pointer_create(&arm->id, &RNA_EditBone, edbo, &path->ptr[path->len]); - path->len++; - return 1; - } - } - else { - if (arm->act_bone) { - RNA_pointer_create(&arm->id, &RNA_Bone, arm->act_bone, &path->ptr[path->len]); - path->len++; - return 1; - } - } - } - - /* no path to a bone possible */ - return 0; + bArmature *arm; + EditBone *edbo; + + /* if we have an armature, get the active bone */ + if (buttons_context_path_data(path, OB_ARMATURE)) { + arm = path->ptr[path->len - 1].data; + + if (arm->edbo) { + if (arm->act_edbone) { + edbo = arm->act_edbone; + RNA_pointer_create(&arm->id, &RNA_EditBone, edbo, &path->ptr[path->len]); + path->len++; + return 1; + } + } + else { + if (arm->act_bone) { + RNA_pointer_create(&arm->id, &RNA_Bone, arm->act_bone, &path->ptr[path->len]); + path->len++; + return 1; + } + } + } + + /* no path to a bone possible */ + return 0; } static int buttons_context_path_pose_bone(ButsContextPath *path) { - PointerRNA *ptr = &path->ptr[path->len - 1]; - - /* if we already have a (pinned) PoseBone, we're done */ - if (RNA_struct_is_a(ptr->type, &RNA_PoseBone)) { - return 1; - } - - /* if we have an armature, get the active bone */ - if (buttons_context_path_object(path)) { - Object *ob = path->ptr[path->len - 1].data; - bArmature *arm = ob->data; /* path->ptr[path->len-1].data - works too */ - - if (ob->type != OB_ARMATURE || arm->edbo) { - return 0; - } - else { - if (arm->act_bone) { - bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, arm->act_bone->name); - if (pchan) { - RNA_pointer_create(&ob->id, &RNA_PoseBone, pchan, &path->ptr[path->len]); - path->len++; - return 1; - } - } - } - } - - /* no path to a bone possible */ - return 0; + PointerRNA *ptr = &path->ptr[path->len - 1]; + + /* if we already have a (pinned) PoseBone, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_PoseBone)) { + return 1; + } + + /* if we have an armature, get the active bone */ + if (buttons_context_path_object(path)) { + Object *ob = path->ptr[path->len - 1].data; + bArmature *arm = ob->data; /* path->ptr[path->len-1].data - works too */ + + if (ob->type != OB_ARMATURE || arm->edbo) { + return 0; + } + else { + if (arm->act_bone) { + bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, arm->act_bone->name); + if (pchan) { + RNA_pointer_create(&ob->id, &RNA_PoseBone, pchan, &path->ptr[path->len]); + path->len++; + return 1; + } + } + } + } + + /* no path to a bone possible */ + 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; + 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(const bContext *C, ButsContextPath *path) { - Scene *scene; - Brush *br = NULL; - PointerRNA *ptr = &path->ptr[path->len - 1]; - - /* if we already have a (pinned) brush, we're done */ - if (RNA_struct_is_a(ptr->type, &RNA_Brush)) { - return 1; - } - /* if we have a scene, use the toolsettings brushes */ - else if (buttons_context_path_scene(path)) { - scene = path->ptr[path->len - 1].data; - - if (scene) { - wmWindow *window = CTX_wm_window(C); - ViewLayer *view_layer = WM_window_get_active_view_layer(window); - br = BKE_paint_brush(BKE_paint_get_active(scene, view_layer)); - } - - if (br) { - RNA_id_pointer_create((ID *)br, &path->ptr[path->len]); - path->len++; - - return 1; - } - } - - /* no path to a brush possible */ - return 0; + Scene *scene; + Brush *br = NULL; + PointerRNA *ptr = &path->ptr[path->len - 1]; + + /* if we already have a (pinned) brush, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_Brush)) { + return 1; + } + /* if we have a scene, use the toolsettings brushes */ + else if (buttons_context_path_scene(path)) { + scene = path->ptr[path->len - 1].data; + + if (scene) { + wmWindow *window = CTX_wm_window(C); + ViewLayer *view_layer = WM_window_get_active_view_layer(window); + br = BKE_paint_brush(BKE_paint_get_active(scene, view_layer)); + } + + if (br) { + RNA_id_pointer_create((ID *)br, &path->ptr[path->len]); + path->len++; + + return 1; + } + } + + /* no path to a brush possible */ + return 0; } -static int buttons_context_path_texture(const bContext *C, ButsContextPath *path, ButsContextTexture *ct) +static int buttons_context_path_texture(const bContext *C, + ButsContextPath *path, + ButsContextTexture *ct) { - PointerRNA *ptr = &path->ptr[path->len - 1]; - ID *id; - - if (!ct) { - return 0; - } - - /* if we already have a (pinned) texture, we're done */ - if (RNA_struct_is_a(ptr->type, &RNA_Texture)) { - return 1; - } - - if (!ct->user) { - return 0; - } - - id = ct->user->id; - - if (id) { - if (GS(id->name) == ID_BR) { - buttons_context_path_brush(C, path); - } - 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) { - buttons_context_path_linestyle(path, CTX_wm_window(C)); - } - } - - if (ct->texture) { - RNA_id_pointer_create(&ct->texture->id, &path->ptr[path->len]); - path->len++; - } - - return 1; + PointerRNA *ptr = &path->ptr[path->len - 1]; + ID *id; + + if (!ct) { + return 0; + } + + /* if we already have a (pinned) texture, we're done */ + if (RNA_struct_is_a(ptr->type, &RNA_Texture)) { + return 1; + } + + if (!ct->user) { + return 0; + } + + id = ct->user->id; + + if (id) { + if (GS(id->name) == ID_BR) { + buttons_context_path_brush(C, path); + } + 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) { + buttons_context_path_linestyle(path, CTX_wm_window(C)); + } + } + + if (ct->texture) { + RNA_id_pointer_create(&ct->texture->id, &path->ptr[path->len]); + path->len++; + } + + return 1; } #ifdef WITH_FREESTYLE static bool buttons_context_linestyle_pinnable(const bContext *C, ViewLayer *view_layer) { - wmWindow *window = CTX_wm_window(C); - Scene *scene = WM_window_get_active_scene(window); - FreestyleConfig *config; - SpaceProperties *sbuts; - - /* if Freestyle is disabled in the scene */ - if ((scene->r.mode & R_EDGE_FRS) == 0) { - return false; - } - /* if Freestyle is not in the Parameter Editor mode */ - config = &view_layer->freestyle_config; - if (config->mode != FREESTYLE_CONTROL_EDITOR_MODE) { - return false; - } - /* if the scene has already been pinned */ - sbuts = CTX_wm_space_properties(C); - if (sbuts->pinid && sbuts->pinid == &scene->id) { - return false; - } - return true; + wmWindow *window = CTX_wm_window(C); + Scene *scene = WM_window_get_active_scene(window); + FreestyleConfig *config; + SpaceProperties *sbuts; + + /* if Freestyle is disabled in the scene */ + if ((scene->r.mode & R_EDGE_FRS) == 0) { + return false; + } + /* if Freestyle is not in the Parameter Editor mode */ + config = &view_layer->freestyle_config; + if (config->mode != FREESTYLE_CONTROL_EDITOR_MODE) { + return false; + } + /* if the scene has already been pinned */ + sbuts = CTX_wm_space_properties(C); + if (sbuts->pinid && sbuts->pinid == &scene->id) { + return false; + } + return true; } #endif static int buttons_context_path(const bContext *C, ButsContextPath *path, int mainb, int flag) { - /* Note we don't use CTX_data here, instead we get it from the window. - * Otherwise there is a loop reading the context that we are setting. */ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - wmWindow *window = CTX_wm_window(C); - Scene *scene = WM_window_get_active_scene(window); - ViewLayer *view_layer = WM_window_get_active_view_layer(window); - ID *id; - int found; - - memset(path, 0, sizeof(*path)); - path->flag = flag; - - /* If some ID datablock is pinned, set the root pointer. */ - if (sbuts->pinid) { - id = sbuts->pinid; - - RNA_id_pointer_create(id, &path->ptr[0]); - path->len++; - } - /* No pinned root, use scene as initial root. */ - else if (mainb != BCONTEXT_TOOL) { - RNA_id_pointer_create(&scene->id, &path->ptr[0]); - path->len++; - - if (!ELEM(mainb, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_OUTPUT, BCONTEXT_VIEW_LAYER, BCONTEXT_WORLD)) { - RNA_pointer_create(NULL, &RNA_ViewLayer, view_layer, &path->ptr[path->len]); - path->len++; - } - } - - /* now for each buttons context type, we try to construct a path, - * tracing back recursively */ - switch (mainb) { - case BCONTEXT_SCENE: - case BCONTEXT_RENDER: - case BCONTEXT_OUTPUT: - found = buttons_context_path_scene(path); - break; - case BCONTEXT_VIEW_LAYER: + /* Note we don't use CTX_data here, instead we get it from the window. + * Otherwise there is a loop reading the context that we are setting. */ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + wmWindow *window = CTX_wm_window(C); + Scene *scene = WM_window_get_active_scene(window); + ViewLayer *view_layer = WM_window_get_active_view_layer(window); + ID *id; + int found; + + memset(path, 0, sizeof(*path)); + path->flag = flag; + + /* If some ID datablock is pinned, set the root pointer. */ + if (sbuts->pinid) { + id = sbuts->pinid; + + RNA_id_pointer_create(id, &path->ptr[0]); + path->len++; + } + /* No pinned root, use scene as initial root. */ + else if (mainb != BCONTEXT_TOOL) { + RNA_id_pointer_create(&scene->id, &path->ptr[0]); + path->len++; + + if (!ELEM(mainb, + BCONTEXT_SCENE, + BCONTEXT_RENDER, + BCONTEXT_OUTPUT, + BCONTEXT_VIEW_LAYER, + BCONTEXT_WORLD)) { + RNA_pointer_create(NULL, &RNA_ViewLayer, view_layer, &path->ptr[path->len]); + path->len++; + } + } + + /* now for each buttons context type, we try to construct a path, + * tracing back recursively */ + switch (mainb) { + case BCONTEXT_SCENE: + case BCONTEXT_RENDER: + case BCONTEXT_OUTPUT: + found = buttons_context_path_scene(path); + break; + case BCONTEXT_VIEW_LAYER: #ifdef WITH_FREESTYLE - if (buttons_context_linestyle_pinnable(C, view_layer)) { - found = buttons_context_path_linestyle(path, window); - if (found) { - break; - } - } + if (buttons_context_linestyle_pinnable(C, view_layer)) { + found = buttons_context_path_linestyle(path, window); + if (found) { + break; + } + } #endif - found = buttons_context_path_view_layer(path, window); - break; - case BCONTEXT_WORLD: - found = buttons_context_path_world(path); - break; - case BCONTEXT_TOOL: - found = true; - break; - case BCONTEXT_OBJECT: - case BCONTEXT_PHYSICS: - case BCONTEXT_CONSTRAINT: - found = buttons_context_path_object(path); - break; - case BCONTEXT_MODIFIER: - found = buttons_context_path_modifier(path); - break; - case BCONTEXT_SHADERFX: - found = buttons_context_path_shaderfx(path); - break; - 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); - break; - case BCONTEXT_TEXTURE: - found = buttons_context_path_texture(C, path, sbuts->texuser); - break; - case BCONTEXT_BONE: - found = buttons_context_path_bone(path); - if (!found) { - found = buttons_context_path_data(path, OB_ARMATURE); - } - break; - case BCONTEXT_BONE_CONSTRAINT: - found = buttons_context_path_pose_bone(path); - break; - default: - found = 0; - break; - } - - return found; + found = buttons_context_path_view_layer(path, window); + break; + case BCONTEXT_WORLD: + found = buttons_context_path_world(path); + break; + case BCONTEXT_TOOL: + found = true; + break; + case BCONTEXT_OBJECT: + case BCONTEXT_PHYSICS: + case BCONTEXT_CONSTRAINT: + found = buttons_context_path_object(path); + break; + case BCONTEXT_MODIFIER: + found = buttons_context_path_modifier(path); + break; + case BCONTEXT_SHADERFX: + found = buttons_context_path_shaderfx(path); + break; + 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); + break; + case BCONTEXT_TEXTURE: + found = buttons_context_path_texture(C, path, sbuts->texuser); + break; + case BCONTEXT_BONE: + found = buttons_context_path_bone(path); + if (!found) { + found = buttons_context_path_data(path, OB_ARMATURE); + } + break; + case BCONTEXT_BONE_CONSTRAINT: + found = buttons_context_path_pose_bone(path); + break; + default: + found = 0; + break; + } + + return found; } static int buttons_shading_context(const bContext *C, int mainb) { - wmWindow *window = CTX_wm_window(C); - ViewLayer *view_layer = WM_window_get_active_view_layer(window); - Object *ob = OBACT(view_layer); - - if (ELEM(mainb, BCONTEXT_MATERIAL, BCONTEXT_WORLD, BCONTEXT_TEXTURE)) { - return 1; - } - if (mainb == BCONTEXT_DATA && ob && ELEM(ob->type, OB_LAMP, OB_CAMERA)) { - return 1; - } - - return 0; + wmWindow *window = CTX_wm_window(C); + ViewLayer *view_layer = WM_window_get_active_view_layer(window); + Object *ob = OBACT(view_layer); + + if (ELEM(mainb, BCONTEXT_MATERIAL, BCONTEXT_WORLD, BCONTEXT_TEXTURE)) { + return 1; + } + if (mainb == BCONTEXT_DATA && ob && ELEM(ob->type, OB_LAMP, OB_CAMERA)) { + return 1; + } + + return 0; } static int buttons_shading_new_context(const bContext *C, int flag) { - wmWindow *window = CTX_wm_window(C); - ViewLayer *view_layer = WM_window_get_active_view_layer(window); - Object *ob = OBACT(view_layer); - - if (flag & (1 << BCONTEXT_MATERIAL)) { - return BCONTEXT_MATERIAL; - } - else if (ob && ELEM(ob->type, OB_LAMP, OB_CAMERA) && (flag & (1 << BCONTEXT_DATA))) { - return BCONTEXT_DATA; - } - else if (flag & (1 << BCONTEXT_WORLD)) { - return BCONTEXT_WORLD; - } - - return BCONTEXT_RENDER; + wmWindow *window = CTX_wm_window(C); + ViewLayer *view_layer = WM_window_get_active_view_layer(window); + Object *ob = OBACT(view_layer); + + if (flag & (1 << BCONTEXT_MATERIAL)) { + return BCONTEXT_MATERIAL; + } + else if (ob && ELEM(ob->type, OB_LAMP, OB_CAMERA) && (flag & (1 << BCONTEXT_DATA))) { + return BCONTEXT_DATA; + } + else if (flag & (1 << BCONTEXT_WORLD)) { + return BCONTEXT_WORLD; + } + + return BCONTEXT_RENDER; } void buttons_context_compute(const bContext *C, SpaceProperties *sbuts) { - ButsContextPath *path; - PointerRNA *ptr; - int a, pflag = 0, flag = 0; - - if (!sbuts->path) { - sbuts->path = MEM_callocN(sizeof(ButsContextPath), "ButsContextPath"); - } - - path = sbuts->path; - - /* Set scene path. */ - buttons_context_path(C, path, BCONTEXT_SCENE, pflag); - - buttons_texture_context_compute(C, sbuts); - - /* for each context, see if we can compute a valid path to it, if - * this is the case, we know we have to display the button */ - for (a = 0; a < BCONTEXT_TOT; a++) { - if (buttons_context_path(C, path, a, pflag)) { - flag |= (1 << a); - - /* setting icon for data context */ - if (a == BCONTEXT_DATA) { - ptr = &path->ptr[path->len - 1]; - - if (ptr->type) { - if (RNA_struct_is_a(ptr->type, &RNA_Light)) { - sbuts->dataicon = ICON_OUTLINER_DATA_LIGHT; - } - else { - sbuts->dataicon = RNA_struct_ui_icon(ptr->type); - } - } - else { - sbuts->dataicon = ICON_EMPTY_DATA; - } - } - } - } - - /* always try to use the tab that was explicitly - * set to the user, so that once that context comes - * back, the tab is activated again */ - sbuts->mainb = sbuts->mainbuser; - - /* in case something becomes invalid, change */ - if ((flag & (1 << sbuts->mainb)) == 0) { - if (sbuts->flag & SB_SHADING_CONTEXT) { - /* try to keep showing shading related buttons */ - sbuts->mainb = buttons_shading_new_context(C, flag); - } - else if (flag & BCONTEXT_OBJECT) { - sbuts->mainb = BCONTEXT_OBJECT; - } - else { - for (a = 0; a < BCONTEXT_TOT; a++) { - if (flag & (1 << a)) { - sbuts->mainb = a; - break; - } - } - } - } - - buttons_context_path(C, path, sbuts->mainb, pflag); - - if (!(flag & (1 << sbuts->mainb))) { - if (flag & (1 << BCONTEXT_OBJECT)) { - sbuts->mainb = BCONTEXT_OBJECT; - } - else { - sbuts->mainb = BCONTEXT_SCENE; - } - } - - if (buttons_shading_context(C, sbuts->mainb)) { - sbuts->flag |= SB_SHADING_CONTEXT; - } - else { - sbuts->flag &= ~SB_SHADING_CONTEXT; - } - - sbuts->pathflag = flag; + ButsContextPath *path; + PointerRNA *ptr; + int a, pflag = 0, flag = 0; + + if (!sbuts->path) { + sbuts->path = MEM_callocN(sizeof(ButsContextPath), "ButsContextPath"); + } + + path = sbuts->path; + + /* Set scene path. */ + buttons_context_path(C, path, BCONTEXT_SCENE, pflag); + + buttons_texture_context_compute(C, sbuts); + + /* for each context, see if we can compute a valid path to it, if + * this is the case, we know we have to display the button */ + for (a = 0; a < BCONTEXT_TOT; a++) { + if (buttons_context_path(C, path, a, pflag)) { + flag |= (1 << a); + + /* setting icon for data context */ + if (a == BCONTEXT_DATA) { + ptr = &path->ptr[path->len - 1]; + + if (ptr->type) { + if (RNA_struct_is_a(ptr->type, &RNA_Light)) { + sbuts->dataicon = ICON_OUTLINER_DATA_LIGHT; + } + else { + sbuts->dataicon = RNA_struct_ui_icon(ptr->type); + } + } + else { + sbuts->dataicon = ICON_EMPTY_DATA; + } + } + } + } + + /* always try to use the tab that was explicitly + * set to the user, so that once that context comes + * back, the tab is activated again */ + sbuts->mainb = sbuts->mainbuser; + + /* in case something becomes invalid, change */ + if ((flag & (1 << sbuts->mainb)) == 0) { + if (sbuts->flag & SB_SHADING_CONTEXT) { + /* try to keep showing shading related buttons */ + sbuts->mainb = buttons_shading_new_context(C, flag); + } + else if (flag & BCONTEXT_OBJECT) { + sbuts->mainb = BCONTEXT_OBJECT; + } + else { + for (a = 0; a < BCONTEXT_TOT; a++) { + if (flag & (1 << a)) { + sbuts->mainb = a; + break; + } + } + } + } + + buttons_context_path(C, path, sbuts->mainb, pflag); + + if (!(flag & (1 << sbuts->mainb))) { + if (flag & (1 << BCONTEXT_OBJECT)) { + sbuts->mainb = BCONTEXT_OBJECT; + } + else { + sbuts->mainb = BCONTEXT_SCENE; + } + } + + if (buttons_shading_context(C, sbuts->mainb)) { + sbuts->flag |= SB_SHADING_CONTEXT; + } + else { + sbuts->flag &= ~SB_SHADING_CONTEXT; + } + + sbuts->pathflag = flag; } /************************* Context Callback ************************/ const char *buttons_context_dir[] = { - "texture_slot", "scene", "world", "object", "mesh", "armature", "lattice", "curve", - "meta_ball", "light", "speaker", "lightprobe", "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", - "line_style", "collection", "gpencil", NULL, + "texture_slot", + "scene", + "world", + "object", + "mesh", + "armature", + "lattice", + "curve", + "meta_ball", + "light", + "speaker", + "lightprobe", + "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", + "line_style", + "collection", + "gpencil", + NULL, }; int buttons_context(const bContext *C, const char *member, bContextDataResult *result) { - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextPath *path = sbuts ? sbuts->path : NULL; - - if (!path) { - return 0; - } - - /* here we handle context, getting data from precomputed path */ - if (CTX_data_dir(member)) { - /* in case of new shading system we skip texture_slot, complex python - * UI script logic depends on checking if this is available */ - if (sbuts->texuser) { - CTX_data_dir_set(result, buttons_context_dir + 1); - } - else { - CTX_data_dir_set(result, buttons_context_dir); - } - return 1; - } - else if (CTX_data_equals(member, "scene")) { - /* Do not return one here if scene not found in path, - * in this case we want to get default context scene! */ - return set_pointer_type(path, result, &RNA_Scene); - } - else if (CTX_data_equals(member, "world")) { - set_pointer_type(path, result, &RNA_World); - return 1; - } - else if (CTX_data_equals(member, "object")) { - set_pointer_type(path, result, &RNA_Object); - return 1; - } - else if (CTX_data_equals(member, "mesh")) { - set_pointer_type(path, result, &RNA_Mesh); - return 1; - } - else if (CTX_data_equals(member, "armature")) { - set_pointer_type(path, result, &RNA_Armature); - return 1; - } - else if (CTX_data_equals(member, "lattice")) { - set_pointer_type(path, result, &RNA_Lattice); - return 1; - } - else if (CTX_data_equals(member, "curve")) { - set_pointer_type(path, result, &RNA_Curve); - return 1; - } - else if (CTX_data_equals(member, "meta_ball")) { - set_pointer_type(path, result, &RNA_MetaBall); - return 1; - } - else if (CTX_data_equals(member, "light")) { - set_pointer_type(path, result, &RNA_Light); - return 1; - } - else if (CTX_data_equals(member, "camera")) { - set_pointer_type(path, result, &RNA_Camera); - return 1; - } - else if (CTX_data_equals(member, "speaker")) { - set_pointer_type(path, result, &RNA_Speaker); - return 1; - } - else if (CTX_data_equals(member, "lightprobe")) { - set_pointer_type(path, result, &RNA_LightProbe); - return 1; - } - else if (CTX_data_equals(member, "material")) { - set_pointer_type(path, result, &RNA_Material); - return 1; - } - else if (CTX_data_equals(member, "texture")) { - ButsContextTexture *ct = sbuts->texuser; - - if (ct) { - CTX_data_pointer_set(result, &ct->texture->id, &RNA_Texture, ct->texture); - } - - return 1; - } - else if (CTX_data_equals(member, "material_slot")) { - PointerRNA *ptr = get_pointer_type(path, &RNA_Object); - - if (ptr) { - Object *ob = ptr->data; - - if (ob && OB_TYPE_SUPPORT_MATERIAL(ob->type) && ob->totcol) { - /* a valid actcol isn't ensured [#27526] */ - int matnr = ob->actcol - 1; - if (matnr < 0) { - matnr = 0; - } - CTX_data_pointer_set(result, &ob->id, &RNA_MaterialSlot, &ob->mat[matnr]); - } - } - - return 1; - } - else if (CTX_data_equals(member, "texture_user")) { - ButsContextTexture *ct = sbuts->texuser; - - if (!ct) { - return -1; - } - - if (ct->user && ct->user->ptr.data) { - ButsTextureUser *user = ct->user; - CTX_data_pointer_set(result, user->ptr.id.data, user->ptr.type, user->ptr.data); - } - - return 1; - } - else if (CTX_data_equals(member, "texture_user_property")) { - ButsContextTexture *ct = sbuts->texuser; - - if (!ct) { - return -1; - } - - if (ct->user && ct->user->ptr.data) { - ButsTextureUser *user = ct->user; - CTX_data_pointer_set(result, NULL, &RNA_Property, user->prop); - } - - return 1; - } - else if (CTX_data_equals(member, "texture_node")) { - ButsContextTexture *ct = sbuts->texuser; - - if (ct) { - /* new shading system */ - if (ct->user && ct->user->node) { - CTX_data_pointer_set(result, &ct->user->ntree->id, &RNA_Node, ct->user->node); - } - - return 1; - } - } - else if (CTX_data_equals(member, "texture_slot")) { - ButsContextTexture *ct = sbuts->texuser; - PointerRNA *ptr; - - /* 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_FreestyleLineStyle))) { - FreestyleLineStyle *ls = ptr->data; - - if (ls) { - CTX_data_pointer_set(result, &ls->id, &RNA_LineStyleTextureSlot, ls->mtex[(int)ls->texact]); - } - } - - return 1; - } - else if (CTX_data_equals(member, "bone")) { - set_pointer_type(path, result, &RNA_Bone); - return 1; - } - else if (CTX_data_equals(member, "edit_bone")) { - set_pointer_type(path, result, &RNA_EditBone); - return 1; - } - else if (CTX_data_equals(member, "pose_bone")) { - 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); - - if (ptr && ptr->data) { - Object *ob = ptr->data; - ModifierData *md = modifiers_findByType(ob, eModifierType_Cloth); - CTX_data_pointer_set(result, &ob->id, &RNA_ClothModifier, md); - return 1; - } - } - else if (CTX_data_equals(member, "soft_body")) { - PointerRNA *ptr = get_pointer_type(path, &RNA_Object); - - if (ptr && ptr->data) { - Object *ob = ptr->data; - ModifierData *md = modifiers_findByType(ob, eModifierType_Softbody); - CTX_data_pointer_set(result, &ob->id, &RNA_SoftBodyModifier, md); - return 1; - } - } - else if (CTX_data_equals(member, "fluid")) { - PointerRNA *ptr = get_pointer_type(path, &RNA_Object); - - if (ptr && ptr->data) { - Object *ob = ptr->data; - ModifierData *md = modifiers_findByType(ob, eModifierType_Fluidsim); - CTX_data_pointer_set(result, &ob->id, &RNA_FluidSimulationModifier, md); - return 1; - } - } - - else if (CTX_data_equals(member, "smoke")) { - PointerRNA *ptr = get_pointer_type(path, &RNA_Object); - - if (ptr && ptr->data) { - Object *ob = ptr->data; - ModifierData *md = modifiers_findByType(ob, eModifierType_Smoke); - CTX_data_pointer_set(result, &ob->id, &RNA_SmokeModifier, md); - return 1; - } - } - else if (CTX_data_equals(member, "collision")) { - PointerRNA *ptr = get_pointer_type(path, &RNA_Object); - - if (ptr && ptr->data) { - Object *ob = ptr->data; - ModifierData *md = modifiers_findByType(ob, eModifierType_Collision); - CTX_data_pointer_set(result, &ob->id, &RNA_CollisionModifier, md); - return 1; - } - } - else if (CTX_data_equals(member, "brush")) { - set_pointer_type(path, result, &RNA_Brush); - return 1; - } - else if (CTX_data_equals(member, "dynamic_paint")) { - PointerRNA *ptr = get_pointer_type(path, &RNA_Object); - - if (ptr && ptr->data) { - Object *ob = ptr->data; - ModifierData *md = modifiers_findByType(ob, eModifierType_DynamicPaint); - CTX_data_pointer_set(result, &ob->id, &RNA_DynamicPaintModifier, md); - return 1; - } - } - else if (CTX_data_equals(member, "line_style")) { - set_pointer_type(path, result, &RNA_FreestyleLineStyle); - return 1; - } - else if (CTX_data_equals(member, "gpencil")) { - set_pointer_type(path, result, &RNA_GreasePencil); - return 1; - } - else { - return 0; /* not found */ - } - - return -1; /* found but not available */ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextPath *path = sbuts ? sbuts->path : NULL; + + if (!path) { + return 0; + } + + /* here we handle context, getting data from precomputed path */ + if (CTX_data_dir(member)) { + /* in case of new shading system we skip texture_slot, complex python + * UI script logic depends on checking if this is available */ + if (sbuts->texuser) { + CTX_data_dir_set(result, buttons_context_dir + 1); + } + else { + CTX_data_dir_set(result, buttons_context_dir); + } + return 1; + } + else if (CTX_data_equals(member, "scene")) { + /* Do not return one here if scene not found in path, + * in this case we want to get default context scene! */ + return set_pointer_type(path, result, &RNA_Scene); + } + else if (CTX_data_equals(member, "world")) { + set_pointer_type(path, result, &RNA_World); + return 1; + } + else if (CTX_data_equals(member, "object")) { + set_pointer_type(path, result, &RNA_Object); + return 1; + } + else if (CTX_data_equals(member, "mesh")) { + set_pointer_type(path, result, &RNA_Mesh); + return 1; + } + else if (CTX_data_equals(member, "armature")) { + set_pointer_type(path, result, &RNA_Armature); + return 1; + } + else if (CTX_data_equals(member, "lattice")) { + set_pointer_type(path, result, &RNA_Lattice); + return 1; + } + else if (CTX_data_equals(member, "curve")) { + set_pointer_type(path, result, &RNA_Curve); + return 1; + } + else if (CTX_data_equals(member, "meta_ball")) { + set_pointer_type(path, result, &RNA_MetaBall); + return 1; + } + else if (CTX_data_equals(member, "light")) { + set_pointer_type(path, result, &RNA_Light); + return 1; + } + else if (CTX_data_equals(member, "camera")) { + set_pointer_type(path, result, &RNA_Camera); + return 1; + } + else if (CTX_data_equals(member, "speaker")) { + set_pointer_type(path, result, &RNA_Speaker); + return 1; + } + else if (CTX_data_equals(member, "lightprobe")) { + set_pointer_type(path, result, &RNA_LightProbe); + return 1; + } + else if (CTX_data_equals(member, "material")) { + set_pointer_type(path, result, &RNA_Material); + return 1; + } + else if (CTX_data_equals(member, "texture")) { + ButsContextTexture *ct = sbuts->texuser; + + if (ct) { + CTX_data_pointer_set(result, &ct->texture->id, &RNA_Texture, ct->texture); + } + + return 1; + } + else if (CTX_data_equals(member, "material_slot")) { + PointerRNA *ptr = get_pointer_type(path, &RNA_Object); + + if (ptr) { + Object *ob = ptr->data; + + if (ob && OB_TYPE_SUPPORT_MATERIAL(ob->type) && ob->totcol) { + /* a valid actcol isn't ensured [#27526] */ + int matnr = ob->actcol - 1; + if (matnr < 0) { + matnr = 0; + } + CTX_data_pointer_set(result, &ob->id, &RNA_MaterialSlot, &ob->mat[matnr]); + } + } + + return 1; + } + else if (CTX_data_equals(member, "texture_user")) { + ButsContextTexture *ct = sbuts->texuser; + + if (!ct) { + return -1; + } + + if (ct->user && ct->user->ptr.data) { + ButsTextureUser *user = ct->user; + CTX_data_pointer_set(result, user->ptr.id.data, user->ptr.type, user->ptr.data); + } + + return 1; + } + else if (CTX_data_equals(member, "texture_user_property")) { + ButsContextTexture *ct = sbuts->texuser; + + if (!ct) { + return -1; + } + + if (ct->user && ct->user->ptr.data) { + ButsTextureUser *user = ct->user; + CTX_data_pointer_set(result, NULL, &RNA_Property, user->prop); + } + + return 1; + } + else if (CTX_data_equals(member, "texture_node")) { + ButsContextTexture *ct = sbuts->texuser; + + if (ct) { + /* new shading system */ + if (ct->user && ct->user->node) { + CTX_data_pointer_set(result, &ct->user->ntree->id, &RNA_Node, ct->user->node); + } + + return 1; + } + } + else if (CTX_data_equals(member, "texture_slot")) { + ButsContextTexture *ct = sbuts->texuser; + PointerRNA *ptr; + + /* 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_FreestyleLineStyle))) { + FreestyleLineStyle *ls = ptr->data; + + if (ls) { + CTX_data_pointer_set( + result, &ls->id, &RNA_LineStyleTextureSlot, ls->mtex[(int)ls->texact]); + } + } + + return 1; + } + else if (CTX_data_equals(member, "bone")) { + set_pointer_type(path, result, &RNA_Bone); + return 1; + } + else if (CTX_data_equals(member, "edit_bone")) { + set_pointer_type(path, result, &RNA_EditBone); + return 1; + } + else if (CTX_data_equals(member, "pose_bone")) { + 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); + + if (ptr && ptr->data) { + Object *ob = ptr->data; + ModifierData *md = modifiers_findByType(ob, eModifierType_Cloth); + CTX_data_pointer_set(result, &ob->id, &RNA_ClothModifier, md); + return 1; + } + } + else if (CTX_data_equals(member, "soft_body")) { + PointerRNA *ptr = get_pointer_type(path, &RNA_Object); + + if (ptr && ptr->data) { + Object *ob = ptr->data; + ModifierData *md = modifiers_findByType(ob, eModifierType_Softbody); + CTX_data_pointer_set(result, &ob->id, &RNA_SoftBodyModifier, md); + return 1; + } + } + else if (CTX_data_equals(member, "fluid")) { + PointerRNA *ptr = get_pointer_type(path, &RNA_Object); + + if (ptr && ptr->data) { + Object *ob = ptr->data; + ModifierData *md = modifiers_findByType(ob, eModifierType_Fluidsim); + CTX_data_pointer_set(result, &ob->id, &RNA_FluidSimulationModifier, md); + return 1; + } + } + + else if (CTX_data_equals(member, "smoke")) { + PointerRNA *ptr = get_pointer_type(path, &RNA_Object); + + if (ptr && ptr->data) { + Object *ob = ptr->data; + ModifierData *md = modifiers_findByType(ob, eModifierType_Smoke); + CTX_data_pointer_set(result, &ob->id, &RNA_SmokeModifier, md); + return 1; + } + } + else if (CTX_data_equals(member, "collision")) { + PointerRNA *ptr = get_pointer_type(path, &RNA_Object); + + if (ptr && ptr->data) { + Object *ob = ptr->data; + ModifierData *md = modifiers_findByType(ob, eModifierType_Collision); + CTX_data_pointer_set(result, &ob->id, &RNA_CollisionModifier, md); + return 1; + } + } + else if (CTX_data_equals(member, "brush")) { + set_pointer_type(path, result, &RNA_Brush); + return 1; + } + else if (CTX_data_equals(member, "dynamic_paint")) { + PointerRNA *ptr = get_pointer_type(path, &RNA_Object); + + if (ptr && ptr->data) { + Object *ob = ptr->data; + ModifierData *md = modifiers_findByType(ob, eModifierType_DynamicPaint); + CTX_data_pointer_set(result, &ob->id, &RNA_DynamicPaintModifier, md); + return 1; + } + } + else if (CTX_data_equals(member, "line_style")) { + set_pointer_type(path, result, &RNA_FreestyleLineStyle); + return 1; + } + else if (CTX_data_equals(member, "gpencil")) { + set_pointer_type(path, result, &RNA_GreasePencil); + return 1; + } + else { + return 0; /* not found */ + } + + return -1; /* found but not available */ } /************************* Drawing the Path ************************/ static void pin_cb(bContext *C, void *UNUSED(arg1), void *UNUSED(arg2)) { - SpaceProperties *sbuts = CTX_wm_space_properties(C); + SpaceProperties *sbuts = CTX_wm_space_properties(C); - if (sbuts->flag & SB_PIN_CONTEXT) { - sbuts->pinid = buttons_context_id_path(C); - } - else { - sbuts->pinid = NULL; - } + if (sbuts->flag & SB_PIN_CONTEXT) { + sbuts->pinid = buttons_context_id_path(C); + } + else { + sbuts->pinid = NULL; + } - ED_area_tag_redraw(CTX_wm_area(C)); + ED_area_tag_redraw(CTX_wm_area(C)); } void buttons_context_draw(const bContext *C, uiLayout *layout) { - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextPath *path = sbuts->path; - uiLayout *row; - uiBlock *block; - uiBut *but; - PointerRNA *ptr; - char namebuf[128], *name; - int a, icon; - bool first = true; - - if (!path) { - return; - } - - row = uiLayoutRow(layout, true); - uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); - - for (a = 0; a < path->len; a++) { - ptr = &path->ptr[a]; - - /* Skip scene and view layer to save space. */ - if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_OUTPUT, BCONTEXT_SCENE, BCONTEXT_VIEW_LAYER, BCONTEXT_WORLD) && ptr->type == &RNA_Scene)) { - continue; - } - else if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_OUTPUT, BCONTEXT_SCENE, BCONTEXT_VIEW_LAYER, BCONTEXT_WORLD) && ptr->type == &RNA_ViewLayer)) { - continue; - } - - /* Add > triangle. */ - if (!first) { - uiItemL(row, "", ICON_SMALL_TRI_RIGHT_VEC); - } - else { - first = false; - } - - /* Add icon + name .*/ - if (ptr->data) { - icon = RNA_struct_ui_icon(ptr->type); - name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL); - - if (name) { - uiItemLDrag(row, ptr, name, icon); - - if (name != namebuf) { - MEM_freeN(name); - } - } - else { - uiItemL(row, "", icon); - } - } - } - - uiItemSpacer(row); - - block = uiLayoutGetBlock(row); - UI_block_emboss_set(block, UI_EMBOSS_NONE); - but = uiDefIconButBitC(block, UI_BTYPE_ICON_TOGGLE, SB_PIN_CONTEXT, 0, ICON_UNPINNED, 0, 0, UI_UNIT_X, UI_UNIT_Y, &sbuts->flag, - 0, 0, 0, 0, TIP_("Follow context or keep fixed data-block displayed")); - UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */ - UI_but_func_set(but, pin_cb, NULL, NULL); + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextPath *path = sbuts->path; + uiLayout *row; + uiBlock *block; + uiBut *but; + PointerRNA *ptr; + char namebuf[128], *name; + int a, icon; + bool first = true; + + if (!path) { + return; + } + + row = uiLayoutRow(layout, true); + uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_LEFT); + + for (a = 0; a < path->len; a++) { + ptr = &path->ptr[a]; + + /* Skip scene and view layer to save space. */ + if ((!ELEM(sbuts->mainb, + BCONTEXT_RENDER, + BCONTEXT_OUTPUT, + BCONTEXT_SCENE, + BCONTEXT_VIEW_LAYER, + BCONTEXT_WORLD) && + ptr->type == &RNA_Scene)) { + continue; + } + else if ((!ELEM(sbuts->mainb, + BCONTEXT_RENDER, + BCONTEXT_OUTPUT, + BCONTEXT_SCENE, + BCONTEXT_VIEW_LAYER, + BCONTEXT_WORLD) && + ptr->type == &RNA_ViewLayer)) { + continue; + } + + /* Add > triangle. */ + if (!first) { + uiItemL(row, "", ICON_SMALL_TRI_RIGHT_VEC); + } + else { + first = false; + } + + /* Add icon + name .*/ + if (ptr->data) { + icon = RNA_struct_ui_icon(ptr->type); + name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL); + + if (name) { + uiItemLDrag(row, ptr, name, icon); + + if (name != namebuf) { + MEM_freeN(name); + } + } + else { + uiItemL(row, "", icon); + } + } + } + + uiItemSpacer(row); + + block = uiLayoutGetBlock(row); + UI_block_emboss_set(block, UI_EMBOSS_NONE); + but = uiDefIconButBitC(block, + UI_BTYPE_ICON_TOGGLE, + SB_PIN_CONTEXT, + 0, + ICON_UNPINNED, + 0, + 0, + UI_UNIT_X, + UI_UNIT_Y, + &sbuts->flag, + 0, + 0, + 0, + 0, + TIP_("Follow context or keep fixed data-block displayed")); + UI_but_flag_disable(but, UI_BUT_UNDO); /* skip undo on screen buttons */ + UI_but_func_set(but, pin_cb, NULL, NULL); } #ifdef USE_HEADER_CONTEXT_PATH @@ -1126,8 +1187,8 @@ static bool buttons_header_context_poll(const bContext *C, HeaderType *UNUSED(ht static bool buttons_panel_context_poll(const bContext *C, PanelType *UNUSED(pt)) #endif { - SpaceProperties *sbuts = CTX_wm_space_properties(C); - return (sbuts->mainb != BCONTEXT_TOOL); + SpaceProperties *sbuts = CTX_wm_space_properties(C); + return (sbuts->mainb != BCONTEXT_TOOL); } #ifdef USE_HEADER_CONTEXT_PATH @@ -1136,59 +1197,59 @@ static void buttons_header_context_draw(const bContext *C, Header *ptr) static void buttons_panel_context_draw(const bContext *C, Panel *ptr) #endif { - buttons_context_draw(C, ptr->layout); + buttons_context_draw(C, ptr->layout); } void buttons_context_register(ARegionType *art) { #ifdef USE_HEADER_CONTEXT_PATH - HeaderType *ht; - - ht = MEM_callocN(sizeof(HeaderType), "spacetype buttons context header"); - strcpy(ht->idname, "BUTTONS_HT_context"); - ht->space_type = SPACE_PROPERTIES; - ht->region_type = art->regionid; - ht->poll = buttons_header_context_poll; - ht->draw = buttons_header_context_draw; - BLI_addtail(&art->headertypes, ht); + HeaderType *ht; + + ht = MEM_callocN(sizeof(HeaderType), "spacetype buttons context header"); + strcpy(ht->idname, "BUTTONS_HT_context"); + ht->space_type = SPACE_PROPERTIES; + ht->region_type = art->regionid; + ht->poll = buttons_header_context_poll; + ht->draw = buttons_header_context_draw; + BLI_addtail(&art->headertypes, ht); #else - PanelType *pt; - - pt = MEM_callocN(sizeof(PanelType), "spacetype buttons panel context"); - strcpy(pt->idname, "BUTTONS_PT_context"); - strcpy(pt->label, N_("Context")); /* XXX C panels unavailable through RNA bpy.types! */ - strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); - pt->poll = buttons_panel_context_poll; - pt->draw = buttons_panel_context_draw; - pt->flag = PNL_NO_HEADER; - BLI_addtail(&art->paneltypes, pt); + PanelType *pt; + + pt = MEM_callocN(sizeof(PanelType), "spacetype buttons panel context"); + strcpy(pt->idname, "BUTTONS_PT_context"); + strcpy(pt->label, N_("Context")); /* XXX C panels unavailable through RNA bpy.types! */ + strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); + pt->poll = buttons_panel_context_poll; + pt->draw = buttons_panel_context_draw; + pt->flag = PNL_NO_HEADER; + BLI_addtail(&art->paneltypes, pt); #endif } ID *buttons_context_id_path(const bContext *C) { - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextPath *path = sbuts->path; - PointerRNA *ptr; - int a; - - if (path->len) { - 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; - } - } - } - - return NULL; + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextPath *path = sbuts->path; + PointerRNA *ptr; + int a; + + if (path->len) { + 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; + } + } + } + + return NULL; } diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h index fa7f0408e15..64166f15ea3 100644 --- a/source/blender/editors/space_buttons/buttons_intern.h +++ b/source/blender/editors/space_buttons/buttons_intern.h @@ -44,44 +44,46 @@ struct wmOperatorType; /* context data */ typedef struct ButsContextPath { - PointerRNA ptr[8]; - int len; - int flag; - int collection_ctx; + PointerRNA ptr[8]; + int len; + int flag; + int collection_ctx; } ButsContextPath; typedef struct ButsTextureUser { - struct ButsTextureUser *next, *prev; + struct ButsTextureUser *next, *prev; - struct ID *id; + struct ID *id; - PointerRNA ptr; - PropertyRNA *prop; + PointerRNA ptr; + PropertyRNA *prop; - struct bNodeTree *ntree; - struct bNode *node; + struct bNodeTree *ntree; + struct bNode *node; - const char *category; - int icon; - const char *name; + const char *category; + int icon; + const char *name; - int index; + int index; } ButsTextureUser; typedef struct ButsContextTexture { - ListBase users; + ListBase users; - struct Tex *texture; + struct Tex *texture; - struct ButsTextureUser *user; - int index; + struct ButsTextureUser *user; + int index; } ButsContextTexture; /* internal exports only */ /* buttons_context.c */ void buttons_context_compute(const struct bContext *C, struct SpaceProperties *sbuts); -int buttons_context(const struct bContext *C, const char *member, struct bContextDataResult *result); +int buttons_context(const struct bContext *C, + const char *member, + struct bContextDataResult *result); void buttons_context_draw(const struct bContext *C, struct uiLayout *layout); void buttons_context_register(struct ARegionType *art); struct ID *buttons_context_id_path(const struct bContext *C); diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index 3ae88f9cc78..fe4ed0209bf 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -21,7 +21,6 @@ * \ingroup spbuttons */ - #include #include @@ -51,240 +50,251 @@ #include "UI_interface.h" #include "UI_resources.h" -#include "buttons_intern.h" /* own include */ +#include "buttons_intern.h" /* own include */ /********************** context_menu operator *********************/ static int context_menu_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) { - const ARegion *ar = CTX_wm_region(C); - uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Context Menu"), ICON_NONE); - uiLayout *layout = UI_popup_menu_layout(pup); + const ARegion *ar = CTX_wm_region(C); + uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("Context Menu"), ICON_NONE); + uiLayout *layout = UI_popup_menu_layout(pup); - uiItemM(layout, "INFO_MT_area", NULL, ICON_NONE); - if (ar->regiontype == RGN_TYPE_NAV_BAR) { - ED_screens_navigation_bar_tools_menu_create(C, layout, NULL); - } + uiItemM(layout, "INFO_MT_area", NULL, ICON_NONE); + if (ar->regiontype == RGN_TYPE_NAV_BAR) { + ED_screens_navigation_bar_tools_menu_create(C, layout, NULL); + } - UI_popup_menu_end(C, pup); + UI_popup_menu_end(C, pup); - return OPERATOR_INTERFACE; + return OPERATOR_INTERFACE; } void BUTTONS_OT_context_menu(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Context Menu"; - ot->description = "Display properties editor context_menu"; - ot->idname = "BUTTONS_OT_context_menu"; - - /* api callbacks */ - ot->invoke = context_menu_invoke; - ot->poll = ED_operator_buttons_active; + /* identifiers */ + ot->name = "Context Menu"; + ot->description = "Display properties editor context_menu"; + ot->idname = "BUTTONS_OT_context_menu"; + + /* api callbacks */ + ot->invoke = context_menu_invoke; + ot->poll = ED_operator_buttons_active; } /********************** filebrowse operator *********************/ typedef struct FileBrowseOp { - PointerRNA ptr; - PropertyRNA *prop; - bool is_undo; + PointerRNA ptr; + PropertyRNA *prop; + bool is_undo; } FileBrowseOp; static int file_browse_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - FileBrowseOp *fbo = op->customdata; - ID *id; - char *str, path[FILE_MAX]; - const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath"; - - if (RNA_struct_property_is_set(op->ptr, path_prop) == 0 || fbo == NULL) { - return OPERATOR_CANCELLED; - } - - str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0); - - /* add slash for directories, important for some properties */ - if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) { - const bool is_relative = RNA_boolean_get(op->ptr, "relative_path"); - id = fbo->ptr.id.data; - - BLI_strncpy(path, str, FILE_MAX); - BLI_path_abs(path, id ? ID_BLEND_PATH(bmain, id) : BKE_main_blendfile_path(bmain)); - - if (BLI_is_dir(path)) { - /* do this first so '//' isnt converted to '//\' on windows */ - BLI_add_slash(path); - if (is_relative) { - BLI_strncpy(path, str, FILE_MAX); - BLI_path_rel(path, BKE_main_blendfile_path(bmain)); - str = MEM_reallocN(str, strlen(path) + 2); - BLI_strncpy(str, path, FILE_MAX); - } - else { - str = MEM_reallocN(str, strlen(str) + 2); - } - } - else { - char * const lslash = (char *)BLI_last_slash(str); - if (lslash) { - lslash[1] = '\0'; - } - } - } - - RNA_property_string_set(&fbo->ptr, fbo->prop, str); - RNA_property_update(C, &fbo->ptr, fbo->prop); - MEM_freeN(str); - - if (fbo->is_undo) { - const char *undostr = RNA_property_identifier(fbo->prop); - ED_undo_push(C, undostr); - } - - /* special, annoying exception, filesel on redo panel [#26618] */ - { - wmOperator *redo_op = WM_operator_last_redo(C); - if (redo_op) { - if (fbo->ptr.data == redo_op->ptr->data) { - ED_undo_operator_repeat(C, redo_op); - } - } - } - - MEM_freeN(op->customdata); - - return OPERATOR_FINISHED; + Main *bmain = CTX_data_main(C); + FileBrowseOp *fbo = op->customdata; + ID *id; + char *str, path[FILE_MAX]; + const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : + "filepath"; + + if (RNA_struct_property_is_set(op->ptr, path_prop) == 0 || fbo == NULL) { + return OPERATOR_CANCELLED; + } + + str = RNA_string_get_alloc(op->ptr, path_prop, NULL, 0); + + /* add slash for directories, important for some properties */ + if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) { + const bool is_relative = RNA_boolean_get(op->ptr, "relative_path"); + id = fbo->ptr.id.data; + + BLI_strncpy(path, str, FILE_MAX); + BLI_path_abs(path, id ? ID_BLEND_PATH(bmain, id) : BKE_main_blendfile_path(bmain)); + + if (BLI_is_dir(path)) { + /* do this first so '//' isnt converted to '//\' on windows */ + BLI_add_slash(path); + if (is_relative) { + BLI_strncpy(path, str, FILE_MAX); + BLI_path_rel(path, BKE_main_blendfile_path(bmain)); + str = MEM_reallocN(str, strlen(path) + 2); + BLI_strncpy(str, path, FILE_MAX); + } + else { + str = MEM_reallocN(str, strlen(str) + 2); + } + } + else { + char *const lslash = (char *)BLI_last_slash(str); + if (lslash) { + lslash[1] = '\0'; + } + } + } + + RNA_property_string_set(&fbo->ptr, fbo->prop, str); + RNA_property_update(C, &fbo->ptr, fbo->prop); + MEM_freeN(str); + + if (fbo->is_undo) { + const char *undostr = RNA_property_identifier(fbo->prop); + ED_undo_push(C, undostr); + } + + /* special, annoying exception, filesel on redo panel [#26618] */ + { + wmOperator *redo_op = WM_operator_last_redo(C); + if (redo_op) { + if (fbo->ptr.data == redo_op->ptr->data) { + ED_undo_operator_repeat(C, redo_op); + } + } + } + + MEM_freeN(op->customdata); + + return OPERATOR_FINISHED; } static void file_browse_cancel(bContext *UNUSED(C), wmOperator *op) { - MEM_freeN(op->customdata); - op->customdata = NULL; + MEM_freeN(op->customdata); + op->customdata = NULL; } static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - PointerRNA ptr; - PropertyRNA *prop; - bool is_undo; - FileBrowseOp *fbo; - char *str; - - if (CTX_wm_space_file(C)) { - BKE_report(op->reports, RPT_ERROR, "Cannot activate a file selector, one already open"); - return OPERATOR_CANCELLED; - } - - UI_context_active_but_prop_get_filebrowser(C, &ptr, &prop, &is_undo); - - if (!prop) { - return OPERATOR_CANCELLED; - } - - str = RNA_property_string_get_alloc(&ptr, prop, NULL, 0, NULL); - - /* useful yet irritating feature, Shift+Click to open the file - * Alt+Click to browse a folder in the OS's browser */ - if (event->shift || event->alt) { - wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true); - PointerRNA props_ptr; - - if (event->alt) { - char *lslash = (char *)BLI_last_slash(str); - if (lslash) { - *lslash = '\0'; - } - } - - - WM_operator_properties_create_ptr(&props_ptr, ot); - RNA_string_set(&props_ptr, "filepath", str); - WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr); - WM_operator_properties_free(&props_ptr); - - MEM_freeN(str); - return OPERATOR_CANCELLED; - } - else { - PropertyRNA *prop_relpath; - const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath"; - fbo = MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp"); - fbo->ptr = ptr; - fbo->prop = prop; - fbo->is_undo = is_undo; - op->customdata = fbo; - - /* normally ED_fileselect_get_params would handle this but we need to because of stupid - * user-prefs exception - campbell */ - if ((prop_relpath = RNA_struct_find_property(op->ptr, "relative_path"))) { - if (!RNA_property_is_set(op->ptr, prop_relpath)) { - bool is_relative = (U.flag & USER_RELPATHS) != 0; - - /* while we want to follow the defaults, - * we better not switch existing paths relative/absolute state. */ - if (str[0]) { - is_relative = BLI_path_is_rel(str); - } - - if (UNLIKELY(ptr.data == &U)) { - is_relative = false; - } - - /* annoying exception!, if were dealing with the user prefs, default relative to be off */ - RNA_property_boolean_set(op->ptr, prop_relpath, is_relative); - } - } - - RNA_string_set(op->ptr, path_prop, str); - MEM_freeN(str); - - WM_event_add_fileselect(C, op); - - return OPERATOR_RUNNING_MODAL; - } + PointerRNA ptr; + PropertyRNA *prop; + bool is_undo; + FileBrowseOp *fbo; + char *str; + + if (CTX_wm_space_file(C)) { + BKE_report(op->reports, RPT_ERROR, "Cannot activate a file selector, one already open"); + return OPERATOR_CANCELLED; + } + + UI_context_active_but_prop_get_filebrowser(C, &ptr, &prop, &is_undo); + + if (!prop) { + return OPERATOR_CANCELLED; + } + + str = RNA_property_string_get_alloc(&ptr, prop, NULL, 0, NULL); + + /* useful yet irritating feature, Shift+Click to open the file + * Alt+Click to browse a folder in the OS's browser */ + if (event->shift || event->alt) { + wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true); + PointerRNA props_ptr; + + if (event->alt) { + char *lslash = (char *)BLI_last_slash(str); + if (lslash) { + *lslash = '\0'; + } + } + + WM_operator_properties_create_ptr(&props_ptr, ot); + RNA_string_set(&props_ptr, "filepath", str); + WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr); + WM_operator_properties_free(&props_ptr); + + MEM_freeN(str); + return OPERATOR_CANCELLED; + } + else { + PropertyRNA *prop_relpath; + const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : + "filepath"; + fbo = MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp"); + fbo->ptr = ptr; + fbo->prop = prop; + fbo->is_undo = is_undo; + op->customdata = fbo; + + /* normally ED_fileselect_get_params would handle this but we need to because of stupid + * user-prefs exception - campbell */ + if ((prop_relpath = RNA_struct_find_property(op->ptr, "relative_path"))) { + if (!RNA_property_is_set(op->ptr, prop_relpath)) { + bool is_relative = (U.flag & USER_RELPATHS) != 0; + + /* while we want to follow the defaults, + * we better not switch existing paths relative/absolute state. */ + if (str[0]) { + is_relative = BLI_path_is_rel(str); + } + + if (UNLIKELY(ptr.data == &U)) { + is_relative = false; + } + + /* annoying exception!, if were dealing with the user prefs, default relative to be off */ + RNA_property_boolean_set(op->ptr, prop_relpath, is_relative); + } + } + + RNA_string_set(op->ptr, path_prop, str); + MEM_freeN(str); + + WM_event_add_fileselect(C, op); + + return OPERATOR_RUNNING_MODAL; + } } void BUTTONS_OT_file_browse(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Accept"; - ot->description = "Open a file browser, Hold Shift to open the file, Alt to browse containing directory"; - ot->idname = "BUTTONS_OT_file_browse"; - - /* api callbacks */ - ot->invoke = file_browse_invoke; - ot->exec = file_browse_exec; - ot->cancel = file_browse_cancel; - - /* conditional undo based on button flag */ - ot->flag = 0; - - /* properties */ - WM_operator_properties_filesel( - ot, 0, FILE_SPECIAL, FILE_OPENFILE, - WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); + /* identifiers */ + ot->name = "Accept"; + ot->description = + "Open a file browser, Hold Shift to open the file, Alt to browse containing directory"; + ot->idname = "BUTTONS_OT_file_browse"; + + /* api callbacks */ + ot->invoke = file_browse_invoke; + ot->exec = file_browse_exec; + ot->cancel = file_browse_cancel; + + /* conditional undo based on button flag */ + ot->flag = 0; + + /* properties */ + WM_operator_properties_filesel(ot, + 0, + FILE_SPECIAL, + FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); } /* second operator, only difference from BUTTONS_OT_file_browse is WM_FILESEL_DIRECTORY */ void BUTTONS_OT_directory_browse(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Accept"; - ot->description = "Open a directory browser, Hold Shift to open the file, Alt to browse containing directory"; - ot->idname = "BUTTONS_OT_directory_browse"; - - /* api callbacks */ - ot->invoke = file_browse_invoke; - ot->exec = file_browse_exec; - ot->cancel = file_browse_cancel; - - /* conditional undo based on button flag */ - ot->flag = 0; - - /* properties */ - WM_operator_properties_filesel( - ot, 0, FILE_SPECIAL, FILE_OPENFILE, - WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA); + /* identifiers */ + ot->name = "Accept"; + ot->description = + "Open a directory browser, Hold Shift to open the file, Alt to browse containing directory"; + ot->idname = "BUTTONS_OT_directory_browse"; + + /* api callbacks */ + ot->invoke = file_browse_invoke; + ot->exec = file_browse_exec; + ot->cancel = file_browse_cancel; + + /* conditional undo based on button flag */ + ot->flag = 0; + + /* properties */ + WM_operator_properties_filesel(ot, + 0, + FILE_SPECIAL, + FILE_OPENFILE, + WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); } diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c index 7c1355b6b3c..b9b83abf670 100644 --- a/source/blender/editors/space_buttons/buttons_texture.c +++ b/source/blender/editors/space_buttons/buttons_texture.c @@ -21,7 +21,6 @@ * \ingroup spbuttons */ - #include #include @@ -72,458 +71,518 @@ #include "../interface/interface_intern.h" -#include "buttons_intern.h" // own include +#include "buttons_intern.h" // own include /************************* Texture User **************************/ -static void buttons_texture_user_property_add(ListBase *users, ID *id, - PointerRNA ptr, PropertyRNA *prop, - const char *category, int icon, const char *name) +static void buttons_texture_user_property_add(ListBase *users, + ID *id, + PointerRNA ptr, + PropertyRNA *prop, + const char *category, + int icon, + const char *name) { - ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser"); + ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser"); - user->id = id; - user->ptr = ptr; - user->prop = prop; - user->category = category; - user->icon = icon; - user->name = name; - user->index = BLI_listbase_count(users); + user->id = id; + user->ptr = ptr; + user->prop = prop; + user->category = category; + user->icon = icon; + user->name = name; + user->index = BLI_listbase_count(users); - BLI_addtail(users, user); + BLI_addtail(users, user); } -static void buttons_texture_user_node_add(ListBase *users, ID *id, - bNodeTree *ntree, bNode *node, - const char *category, int icon, const char *name) +static void buttons_texture_user_node_add(ListBase *users, + ID *id, + bNodeTree *ntree, + bNode *node, + const char *category, + int icon, + const char *name) { - ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser"); + ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser"); - user->id = id; - user->ntree = ntree; - user->node = node; - user->category = category; - user->icon = icon; - user->name = name; - user->index = BLI_listbase_count(users); + user->id = id; + user->ntree = ntree; + user->node = node; + user->category = category; + user->icon = icon; + user->name = name; + user->index = BLI_listbase_count(users); - BLI_addtail(users, user); + BLI_addtail(users, user); } -static void buttons_texture_users_find_nodetree(ListBase *users, ID *id, - bNodeTree *ntree, const char *category) +static void buttons_texture_users_find_nodetree(ListBase *users, + ID *id, + bNodeTree *ntree, + const char *category) { - bNode *node; - - if (ntree) { - for (node = ntree->nodes.first; node; node = node->next) { - if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { - PointerRNA ptr; - /* PropertyRNA *prop; */ /* UNUSED */ - - RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); - /* prop = RNA_struct_find_property(&ptr, "texture"); */ /* UNUSED */ - - buttons_texture_user_node_add(users, id, ntree, node, - category, RNA_struct_ui_icon(ptr.type), node->name); - } - else if (node->type == NODE_GROUP && node->id) { - buttons_texture_users_find_nodetree(users, id, (bNodeTree *)node->id, category); - } - } - } + bNode *node; + + if (ntree) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { + PointerRNA ptr; + /* PropertyRNA *prop; */ /* UNUSED */ + + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); + /* prop = RNA_struct_find_property(&ptr, "texture"); */ /* UNUSED */ + + buttons_texture_user_node_add( + users, id, ntree, node, category, RNA_struct_ui_icon(ptr.type), node->name); + } + else if (node->type == NODE_GROUP && node->id) { + buttons_texture_users_find_nodetree(users, id, (bNodeTree *)node->id, category); + } + } + } } -static void buttons_texture_modifier_foreach(void *userData, Object *ob, ModifierData *md, const char *propname) +static void buttons_texture_modifier_foreach(void *userData, + Object *ob, + ModifierData *md, + const char *propname) { - PointerRNA ptr; - PropertyRNA *prop; - ListBase *users = userData; + PointerRNA ptr; + PropertyRNA *prop; + ListBase *users = userData; - RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); - prop = RNA_struct_find_property(&ptr, propname); + RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); + prop = RNA_struct_find_property(&ptr, propname); - buttons_texture_user_property_add(users, &ob->id, ptr, prop, - N_("Modifiers"), RNA_struct_ui_icon(ptr.type), md->name); + buttons_texture_user_property_add( + users, &ob->id, ptr, prop, N_("Modifiers"), RNA_struct_ui_icon(ptr.type), md->name); } -static void buttons_texture_modifier_gpencil_foreach(void *userData, Object *ob, GpencilModifierData *md, const char *propname) +static void buttons_texture_modifier_gpencil_foreach(void *userData, + Object *ob, + GpencilModifierData *md, + const char *propname) { - PointerRNA ptr; - PropertyRNA *prop; - ListBase *users = userData; - - RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr); - prop = RNA_struct_find_property(&ptr, propname); - - buttons_texture_user_property_add( - users, &ob->id, ptr, prop, - N_("Grease Pencil Modifiers"), RNA_struct_ui_icon(ptr.type), md->name); + PointerRNA ptr; + PropertyRNA *prop; + ListBase *users = userData; + + RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr); + prop = RNA_struct_find_property(&ptr, propname); + + buttons_texture_user_property_add(users, + &ob->id, + ptr, + prop, + N_("Grease Pencil Modifiers"), + RNA_struct_ui_icon(ptr.type), + md->name); } -static void buttons_texture_users_from_context(ListBase *users, const bContext *C, SpaceProperties *sbuts) +static void buttons_texture_users_from_context(ListBase *users, + const bContext *C, + SpaceProperties *sbuts) { - Scene *scene = NULL; - Object *ob = NULL; - FreestyleLineStyle *linestyle = NULL; - Brush *brush = NULL; - ID *pinid = sbuts->pinid; - bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0; - - /* get data from context */ - if (pinid) { - if (GS(pinid->name) == ID_SCE) { - scene = (Scene *)pinid; - } - else if (GS(pinid->name) == ID_OB) { - ob = (Object *)pinid; - } - else if (GS(pinid->name) == ID_BR) { - brush = (Brush *)pinid; - } - else if (GS(pinid->name) == ID_LS) { - linestyle = (FreestyleLineStyle *)pinid; - } - } - - if (!scene) { - scene = CTX_data_scene(C); - } - - const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1; - if (!pinid || id_type == ID_SCE) { - wmWindow *win = CTX_wm_window(C); - ViewLayer *view_layer = (win->scene == scene) ? - WM_window_get_active_view_layer(win) : - BKE_view_layer_default_view(scene); - - brush = BKE_paint_brush(BKE_paint_get_active_from_context(C)); - linestyle = BKE_linestyle_active_from_view_layer(view_layer); - ob = OBACT(view_layer); - } - - /* fill users */ - BLI_listbase_clear(users); - - if (linestyle && !limited_mode) { - 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); - - /* grease pencil modifiers */ - BKE_gpencil_modifiers_foreachTexLink(ob, buttons_texture_modifier_gpencil_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; - PropertyRNA *prop; - - RNA_pointer_create(&ob->id, &RNA_FieldSettings, ob->pd, &ptr); - prop = RNA_struct_find_property(&ptr, "texture"); - - buttons_texture_user_property_add(users, &ob->id, ptr, prop, - N_("Fields"), ICON_FORCE_TEXTURE, IFACE_("Texture Field")); - } - } - - /* brush */ - if (brush) { - PointerRNA ptr; - PropertyRNA *prop; - - /* texture */ - RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mtex, &ptr); - prop = RNA_struct_find_property(&ptr, "texture"); - - buttons_texture_user_property_add(users, &brush->id, ptr, prop, - N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush")); - - /* mask texture */ - RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mask_mtex, &ptr); - prop = RNA_struct_find_property(&ptr, "texture"); - - buttons_texture_user_property_add(users, &brush->id, ptr, prop, - N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush Mask")); - } + Scene *scene = NULL; + Object *ob = NULL; + FreestyleLineStyle *linestyle = NULL; + Brush *brush = NULL; + ID *pinid = sbuts->pinid; + bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0; + + /* get data from context */ + if (pinid) { + if (GS(pinid->name) == ID_SCE) { + scene = (Scene *)pinid; + } + else if (GS(pinid->name) == ID_OB) { + ob = (Object *)pinid; + } + else if (GS(pinid->name) == ID_BR) { + brush = (Brush *)pinid; + } + else if (GS(pinid->name) == ID_LS) { + linestyle = (FreestyleLineStyle *)pinid; + } + } + + if (!scene) { + scene = CTX_data_scene(C); + } + + const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1; + if (!pinid || id_type == ID_SCE) { + wmWindow *win = CTX_wm_window(C); + ViewLayer *view_layer = (win->scene == scene) ? WM_window_get_active_view_layer(win) : + BKE_view_layer_default_view(scene); + + brush = BKE_paint_brush(BKE_paint_get_active_from_context(C)); + linestyle = BKE_linestyle_active_from_view_layer(view_layer); + ob = OBACT(view_layer); + } + + /* fill users */ + BLI_listbase_clear(users); + + if (linestyle && !limited_mode) { + 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); + + /* grease pencil modifiers */ + BKE_gpencil_modifiers_foreachTexLink(ob, buttons_texture_modifier_gpencil_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; + PropertyRNA *prop; + + RNA_pointer_create(&ob->id, &RNA_FieldSettings, ob->pd, &ptr); + prop = RNA_struct_find_property(&ptr, "texture"); + + buttons_texture_user_property_add( + users, &ob->id, ptr, prop, N_("Fields"), ICON_FORCE_TEXTURE, IFACE_("Texture Field")); + } + } + + /* brush */ + if (brush) { + PointerRNA ptr; + PropertyRNA *prop; + + /* texture */ + RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mtex, &ptr); + prop = RNA_struct_find_property(&ptr, "texture"); + + buttons_texture_user_property_add( + users, &brush->id, ptr, prop, N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush")); + + /* mask texture */ + RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mask_mtex, &ptr); + prop = RNA_struct_find_property(&ptr, "texture"); + + buttons_texture_user_property_add( + users, &brush->id, ptr, prop, N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush Mask")); + } } void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts) { - /* gather available texture users in context. runs on every draw of - * properties editor, before the buttons are created. */ - ButsContextTexture *ct = sbuts->texuser; - ID *pinid = sbuts->pinid; - - if (!ct) { - ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture"); - sbuts->texuser = ct; - } - else { - BLI_freelistN(&ct->users); - } - - buttons_texture_users_from_context(&ct->users, C, sbuts); - - if (pinid && GS(pinid->name) == ID_TE) { - ct->user = NULL; - ct->texture = (Tex *)pinid; - } - else { - /* set one user as active based on active index */ - if (ct->index >= BLI_listbase_count_at_most(&ct->users, ct->index + 1)) { - ct->index = 0; - } - - ct->user = BLI_findlink(&ct->users, ct->index); - ct->texture = NULL; - - if (ct->user) { - if (ct->user->ptr.data) { - PointerRNA texptr; - Tex *tex; - - /* get texture datablock pointer if it's a property */ - texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop); - tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL; - - ct->texture = tex; - } - else if (ct->user->node && !(ct->user->node->flag & NODE_ACTIVE_TEXTURE)) { - ButsTextureUser *user; - - /* detect change of active texture node in same node tree, in that - * case we also automatically switch to the other node */ - for (user = ct->users.first; user; user = user->next) { - if (user->ntree == ct->user->ntree && user->node != ct->user->node) { - if (user->node->flag & NODE_ACTIVE_TEXTURE) { - ct->user = user; - ct->index = BLI_findindex(&ct->users, user); - break; - } - } - } - } - } - } + /* gather available texture users in context. runs on every draw of + * properties editor, before the buttons are created. */ + ButsContextTexture *ct = sbuts->texuser; + ID *pinid = sbuts->pinid; + + if (!ct) { + ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture"); + sbuts->texuser = ct; + } + else { + BLI_freelistN(&ct->users); + } + + buttons_texture_users_from_context(&ct->users, C, sbuts); + + if (pinid && GS(pinid->name) == ID_TE) { + ct->user = NULL; + ct->texture = (Tex *)pinid; + } + else { + /* set one user as active based on active index */ + if (ct->index >= BLI_listbase_count_at_most(&ct->users, ct->index + 1)) { + ct->index = 0; + } + + ct->user = BLI_findlink(&ct->users, ct->index); + ct->texture = NULL; + + if (ct->user) { + if (ct->user->ptr.data) { + PointerRNA texptr; + Tex *tex; + + /* get texture datablock pointer if it's a property */ + texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop); + tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL; + + ct->texture = tex; + } + else if (ct->user->node && !(ct->user->node->flag & NODE_ACTIVE_TEXTURE)) { + ButsTextureUser *user; + + /* detect change of active texture node in same node tree, in that + * case we also automatically switch to the other node */ + for (user = ct->users.first; user; user = user->next) { + if (user->ntree == ct->user->ntree && user->node != ct->user->node) { + if (user->node->flag & NODE_ACTIVE_TEXTURE) { + ct->user = user; + ct->index = BLI_findindex(&ct->users, user); + break; + } + } + } + } + } + } } static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) { - /* callback when selecting a texture user in the menu */ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; - ButsTextureUser *user = (ButsTextureUser *)user_p; - PointerRNA texptr; - Tex *tex; - - if (!ct) { - return; - } - - /* set user as active */ - if (user->node) { - ED_node_set_active(CTX_data_main(C), user->ntree, user->node); - ct->texture = NULL; - } - else { - texptr = RNA_property_pointer_get(&user->ptr, user->prop); - tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL; - - 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; - } - } - - ct->user = user; - ct->index = user->index; + /* callback when selecting a texture user in the menu */ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; + ButsTextureUser *user = (ButsTextureUser *)user_p; + PointerRNA texptr; + Tex *tex; + + if (!ct) { + return; + } + + /* set user as active */ + if (user->node) { + ED_node_set_active(CTX_data_main(C), user->ntree, user->node); + ct->texture = NULL; + } + else { + texptr = RNA_property_pointer_get(&user->ptr, user->prop); + tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL; + + 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; + } + } + + ct->user = user; + ct->index = user->index; } static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUSED(arg)) { - /* callback when opening texture user selection menu, to create buttons. */ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextTexture *ct = sbuts->texuser; - ButsTextureUser *user; - uiBlock *block = uiLayoutGetBlock(layout); - const char *last_category = NULL; - - for (user = ct->users.first; user; user = user->next) { - uiBut *but; - char name[UI_MAX_NAME_STR]; - - /* add label per category */ - if (!last_category || !STREQ(last_category, user->category)) { - uiItemL(layout, IFACE_(user->category), ICON_NONE); - but = block->buttons.last; - but->drawflag = UI_BUT_TEXT_LEFT; - } - - /* create button */ - if (user->prop) { - PointerRNA texptr = RNA_property_pointer_get(&user->ptr, user->prop); - Tex *tex = texptr.data; - - if (tex) { - BLI_snprintf(name, UI_MAX_NAME_STR, " %s - %s", user->name, tex->id.name + 2); - } - else { - BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); - } - } - else { - BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); - } - - but = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, user->icon, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, - NULL, 0.0, 0.0, 0.0, 0.0, ""); - UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), NULL); - - last_category = user->category; - } - - UI_block_flag_enable(block, UI_BLOCK_NO_FLIP); + /* callback when opening texture user selection menu, to create buttons. */ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextTexture *ct = sbuts->texuser; + ButsTextureUser *user; + uiBlock *block = uiLayoutGetBlock(layout); + const char *last_category = NULL; + + for (user = ct->users.first; user; user = user->next) { + uiBut *but; + char name[UI_MAX_NAME_STR]; + + /* add label per category */ + if (!last_category || !STREQ(last_category, user->category)) { + uiItemL(layout, IFACE_(user->category), ICON_NONE); + but = block->buttons.last; + but->drawflag = UI_BUT_TEXT_LEFT; + } + + /* create button */ + if (user->prop) { + PointerRNA texptr = RNA_property_pointer_get(&user->ptr, user->prop); + Tex *tex = texptr.data; + + if (tex) { + BLI_snprintf(name, UI_MAX_NAME_STR, " %s - %s", user->name, tex->id.name + 2); + } + else { + BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); + } + } + else { + BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); + } + + but = uiDefIconTextBut(block, + UI_BTYPE_BUT, + 0, + user->icon, + name, + 0, + 0, + UI_UNIT_X * 4, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + ""); + UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), NULL); + + last_category = user->category; + } + + UI_block_flag_enable(block, UI_BLOCK_NO_FLIP); } void uiTemplateTextureUser(uiLayout *layout, bContext *C) { - /* texture user selection dropdown menu. the available users have been - * gathered before drawing in ButsContextTexture, we merely need to - * display the current item. */ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; - uiBlock *block = uiLayoutGetBlock(layout); - uiBut *but; - ButsTextureUser *user; - char name[UI_MAX_NAME_STR]; - - if (!ct) { - return; - } - - /* get current user */ - user = ct->user; - - if (!user) { - uiItemL(layout, IFACE_("No textures in context"), ICON_NONE); - return; - } - - /* create button */ - BLI_strncpy(name, user->name, UI_MAX_NAME_STR); - - if (user->icon) { - but = uiDefIconTextMenuBut(block, template_texture_user_menu, NULL, - user->icon, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); - } - else { - but = uiDefMenuBut(block, template_texture_user_menu, NULL, - name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); - } - - /* some cosmetic tweaks */ - UI_but_type_set_menu_from_pulldown(but); - - but->flag &= ~UI_BUT_ICON_SUBMENU; + /* texture user selection dropdown menu. the available users have been + * gathered before drawing in ButsContextTexture, we merely need to + * display the current item. */ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; + uiBlock *block = uiLayoutGetBlock(layout); + uiBut *but; + ButsTextureUser *user; + char name[UI_MAX_NAME_STR]; + + if (!ct) { + return; + } + + /* get current user */ + user = ct->user; + + if (!user) { + uiItemL(layout, IFACE_("No textures in context"), ICON_NONE); + return; + } + + /* create button */ + BLI_strncpy(name, user->name, UI_MAX_NAME_STR); + + if (user->icon) { + but = uiDefIconTextMenuBut(block, + template_texture_user_menu, + NULL, + user->icon, + name, + 0, + 0, + UI_UNIT_X * 4, + UI_UNIT_Y, + ""); + } + else { + but = uiDefMenuBut( + block, template_texture_user_menu, NULL, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); + } + + /* some cosmetic tweaks */ + UI_but_type_set_menu_from_pulldown(but); + + but->flag &= ~UI_BUT_ICON_SUBMENU; } /************************* Texture Show **************************/ static void template_texture_show(bContext *C, void *data_p, void *prop_p) { - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; - ButsTextureUser *user; - - if (!ct) { - return; - } - - for (user = ct->users.first; user; user = user->next) { - if (user->ptr.data == data_p && user->prop == prop_p) { - break; - } - } - - if (user) { - /* select texture */ - template_texture_select(C, user, NULL); - - /* change context */ - sbuts->mainb = BCONTEXT_TEXTURE; - sbuts->mainbuser = sbuts->mainb; - sbuts->preview = 1; - - /* redraw editor */ - ED_area_tag_redraw(CTX_wm_area(C)); - } + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; + ButsTextureUser *user; + + if (!ct) { + return; + } + + for (user = ct->users.first; user; user = user->next) { + if (user->ptr.data == data_p && user->prop == prop_p) { + break; + } + } + + if (user) { + /* select texture */ + template_texture_select(C, user, NULL); + + /* change context */ + sbuts->mainb = BCONTEXT_TEXTURE; + sbuts->mainbuser = sbuts->mainb; + sbuts->preview = 1; + + /* redraw editor */ + ED_area_tag_redraw(CTX_wm_area(C)); + } } void uiTemplateTextureShow(uiLayout *layout, bContext *C, PointerRNA *ptr, PropertyRNA *prop) { - /* button to quickly show texture in texture tab */ - SpaceProperties *sbuts = CTX_wm_space_properties(C); - ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; - ButsTextureUser *user; - - /* only show button in other tabs in properties editor */ - if (!ct || sbuts->mainb == BCONTEXT_TEXTURE) { - return; - } - - /* find corresponding texture user */ - for (user = ct->users.first; user; user = user->next) { - if (user->ptr.data == ptr->data && user->prop == prop) { - break; - } - } - - /* draw button */ - if (user) { - uiBlock *block = uiLayoutGetBlock(layout); - uiBut *but; - - but = uiDefIconBut(block, UI_BTYPE_BUT, 0, ICON_PROPERTIES, 0, 0, UI_UNIT_X, UI_UNIT_Y, - NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Show texture in texture tab")); - UI_but_func_set(but, template_texture_show, user->ptr.data, user->prop); - } + /* button to quickly show texture in texture tab */ + SpaceProperties *sbuts = CTX_wm_space_properties(C); + ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; + ButsTextureUser *user; + + /* only show button in other tabs in properties editor */ + if (!ct || sbuts->mainb == BCONTEXT_TEXTURE) { + return; + } + + /* find corresponding texture user */ + for (user = ct->users.first; user; user = user->next) { + if (user->ptr.data == ptr->data && user->prop == prop) { + break; + } + } + + /* draw button */ + if (user) { + uiBlock *block = uiLayoutGetBlock(layout); + uiBut *but; + + but = uiDefIconBut(block, + UI_BTYPE_BUT, + 0, + ICON_PROPERTIES, + 0, + 0, + UI_UNIT_X, + UI_UNIT_Y, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + TIP_("Show texture in texture tab")); + UI_but_func_set(but, template_texture_show, user->ptr.data, user->prop); + } } diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 3bf2d632a12..1b1c3bf6d13 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -47,65 +47,65 @@ #include "GPU_glew.h" -#include "buttons_intern.h" /* own include */ +#include "buttons_intern.h" /* own include */ /* ******************** default callbacks for buttons space ***************** */ static SpaceLink *buttons_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) { - ARegion *ar; - SpaceProperties *sbuts; + ARegion *ar; + SpaceProperties *sbuts; - sbuts = MEM_callocN(sizeof(SpaceProperties), "initbuts"); - sbuts->spacetype = SPACE_PROPERTIES; + sbuts = MEM_callocN(sizeof(SpaceProperties), "initbuts"); + sbuts->spacetype = SPACE_PROPERTIES; - sbuts->mainb = sbuts->mainbuser = BCONTEXT_OBJECT; + sbuts->mainb = sbuts->mainbuser = BCONTEXT_OBJECT; - /* header */ - ar = MEM_callocN(sizeof(ARegion), "header for buts"); + /* header */ + ar = MEM_callocN(sizeof(ARegion), "header for buts"); - BLI_addtail(&sbuts->regionbase, ar); - ar->regiontype = RGN_TYPE_HEADER; - ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; + BLI_addtail(&sbuts->regionbase, ar); + ar->regiontype = RGN_TYPE_HEADER; + ar->alignment = (U.uiflag & USER_HEADER_BOTTOM) ? RGN_ALIGN_BOTTOM : RGN_ALIGN_TOP; - /* navigation bar */ - ar = MEM_callocN(sizeof(ARegion), "navigation bar for buts"); + /* navigation bar */ + ar = MEM_callocN(sizeof(ARegion), "navigation bar for buts"); - BLI_addtail(&sbuts->regionbase, ar); - ar->regiontype = RGN_TYPE_NAV_BAR; - ar->alignment = RGN_ALIGN_LEFT; + BLI_addtail(&sbuts->regionbase, ar); + ar->regiontype = RGN_TYPE_NAV_BAR; + ar->alignment = RGN_ALIGN_LEFT; #if 0 - /* context region */ - ar = MEM_callocN(sizeof(ARegion), "context region for buts"); - BLI_addtail(&sbuts->regionbase, ar); - ar->regiontype = RGN_TYPE_CHANNELS; - ar->alignment = RGN_ALIGN_TOP; + /* context region */ + ar = MEM_callocN(sizeof(ARegion), "context region for buts"); + BLI_addtail(&sbuts->regionbase, ar); + ar->regiontype = RGN_TYPE_CHANNELS; + ar->alignment = RGN_ALIGN_TOP; #endif - /* main region */ - ar = MEM_callocN(sizeof(ARegion), "main region for buts"); + /* main region */ + ar = MEM_callocN(sizeof(ARegion), "main region for buts"); - BLI_addtail(&sbuts->regionbase, ar); - ar->regiontype = RGN_TYPE_WINDOW; + BLI_addtail(&sbuts->regionbase, ar); + ar->regiontype = RGN_TYPE_WINDOW; - return (SpaceLink *)sbuts; + return (SpaceLink *)sbuts; } /* not spacelink itself */ static void buttons_free(SpaceLink *sl) { - SpaceProperties *sbuts = (SpaceProperties *) sl; + SpaceProperties *sbuts = (SpaceProperties *)sl; - if (sbuts->path) { - MEM_freeN(sbuts->path); - } + if (sbuts->path) { + MEM_freeN(sbuts->path); + } - if (sbuts->texuser) { - ButsContextTexture *ct = sbuts->texuser; - BLI_freelistN(&ct->users); - MEM_freeN(ct); - } + if (sbuts->texuser) { + ButsContextTexture *ct = sbuts->texuser; + BLI_freelistN(&ct->users); + MEM_freeN(ct); + } } /* spacetype; init callback */ @@ -115,650 +115,661 @@ static void buttons_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa) static SpaceLink *buttons_duplicate(SpaceLink *sl) { - SpaceProperties *sbutsn = MEM_dupallocN(sl); + SpaceProperties *sbutsn = MEM_dupallocN(sl); - /* clear or remove stuff from old */ - sbutsn->path = NULL; - sbutsn->texuser = NULL; + /* clear or remove stuff from old */ + sbutsn->path = NULL; + sbutsn->texuser = NULL; - return (SpaceLink *)sbutsn; + return (SpaceLink *)sbutsn; } /* add handlers, stuff you only do once or on area/region changes */ static void buttons_main_region_init(wmWindowManager *wm, ARegion *ar) { - wmKeyMap *keymap; + wmKeyMap *keymap; - ED_region_panels_init(wm, ar); + ED_region_panels_init(wm, ar); - keymap = WM_keymap_ensure(wm->defaultconf, "Property Editor", SPACE_PROPERTIES, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); + keymap = WM_keymap_ensure(wm->defaultconf, "Property Editor", SPACE_PROPERTIES, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); } -static void buttons_main_region_layout_properties(const bContext *C, SpaceProperties *sbuts, ARegion *ar) +static void buttons_main_region_layout_properties(const bContext *C, + SpaceProperties *sbuts, + ARegion *ar) { - buttons_context_compute(C, sbuts); - - const char *contexts[2] = {NULL, NULL}; - - switch (sbuts->mainb) { - case BCONTEXT_SCENE: - contexts[0] = "scene"; - break; - case BCONTEXT_RENDER: - contexts[0] = "render"; - break; - case BCONTEXT_OUTPUT: - contexts[0] = "output"; - break; - case BCONTEXT_VIEW_LAYER: - contexts[0] = "view_layer"; - break; - case BCONTEXT_WORLD: - contexts[0] = "world"; - break; - case BCONTEXT_OBJECT: - contexts[0] = "object"; - break; - case BCONTEXT_DATA: - contexts[0] = "data"; - break; - case BCONTEXT_MATERIAL: - contexts[0] = "material"; - break; - case BCONTEXT_TEXTURE: - contexts[0] = "texture"; - break; - case BCONTEXT_PARTICLE: - contexts[0] = "particle"; - break; - case BCONTEXT_PHYSICS: - contexts[0] = "physics"; - break; - case BCONTEXT_BONE: - contexts[0] = "bone"; - break; - case BCONTEXT_MODIFIER: - contexts[0] = "modifier"; - break; - case BCONTEXT_SHADERFX: - contexts[0] = "shaderfx"; - break; - case BCONTEXT_CONSTRAINT: - contexts[0] = "constraint"; - break; - case BCONTEXT_BONE_CONSTRAINT: - contexts[0] = "bone_constraint"; - break; - case BCONTEXT_TOOL: - contexts[0] = "tool"; - break; - } - - const bool vertical = true; - ED_region_panels_layout_ex(C, ar, contexts, sbuts->mainb, vertical); + buttons_context_compute(C, sbuts); + + const char *contexts[2] = {NULL, NULL}; + + switch (sbuts->mainb) { + case BCONTEXT_SCENE: + contexts[0] = "scene"; + break; + case BCONTEXT_RENDER: + contexts[0] = "render"; + break; + case BCONTEXT_OUTPUT: + contexts[0] = "output"; + break; + case BCONTEXT_VIEW_LAYER: + contexts[0] = "view_layer"; + break; + case BCONTEXT_WORLD: + contexts[0] = "world"; + break; + case BCONTEXT_OBJECT: + contexts[0] = "object"; + break; + case BCONTEXT_DATA: + contexts[0] = "data"; + break; + case BCONTEXT_MATERIAL: + contexts[0] = "material"; + break; + case BCONTEXT_TEXTURE: + contexts[0] = "texture"; + break; + case BCONTEXT_PARTICLE: + contexts[0] = "particle"; + break; + case BCONTEXT_PHYSICS: + contexts[0] = "physics"; + break; + case BCONTEXT_BONE: + contexts[0] = "bone"; + break; + case BCONTEXT_MODIFIER: + contexts[0] = "modifier"; + break; + case BCONTEXT_SHADERFX: + contexts[0] = "shaderfx"; + break; + case BCONTEXT_CONSTRAINT: + contexts[0] = "constraint"; + break; + case BCONTEXT_BONE_CONSTRAINT: + contexts[0] = "bone_constraint"; + break; + case BCONTEXT_TOOL: + contexts[0] = "tool"; + break; + } + + const bool vertical = true; + ED_region_panels_layout_ex(C, ar, contexts, sbuts->mainb, vertical); } static void buttons_main_region_layout_tool(const bContext *C, ARegion *ar) { - const WorkSpace *workspace = CTX_wm_workspace(C); - const enum eContextObjectMode mode = CTX_data_mode_enum(C); - - const char *contexts_base[5] = {NULL}; - contexts_base[0] = ".active_tool"; - const char **contexts = &contexts_base[1]; - - if (workspace->tools_space_type == SPACE_VIEW3D) { - switch (mode) { - case CTX_MODE_EDIT_MESH: - ARRAY_SET_ITEMS(contexts, ".mesh_edit"); - break; - case CTX_MODE_EDIT_CURVE: - ARRAY_SET_ITEMS(contexts, ".curve_edit"); - break; - case CTX_MODE_EDIT_SURFACE: - ARRAY_SET_ITEMS(contexts, ".curve_edit"); - break; - case CTX_MODE_EDIT_TEXT: - ARRAY_SET_ITEMS(contexts, ".text_edit"); - break; - case CTX_MODE_EDIT_ARMATURE: - ARRAY_SET_ITEMS(contexts, ".armature_edit"); - break; - case CTX_MODE_EDIT_METABALL: - ARRAY_SET_ITEMS(contexts, ".mball_edit"); - break; - case CTX_MODE_EDIT_LATTICE: - ARRAY_SET_ITEMS(contexts, ".lattice_edit"); - break; - case CTX_MODE_POSE: - ARRAY_SET_ITEMS(contexts, ".posemode"); - break; - case CTX_MODE_SCULPT: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".sculpt_mode"); - break; - case CTX_MODE_PAINT_WEIGHT: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".weightpaint"); - break; - case CTX_MODE_PAINT_VERTEX: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".vertexpaint"); - break; - case CTX_MODE_PAINT_TEXTURE: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".imagepaint"); - break; - case CTX_MODE_PARTICLE: - ARRAY_SET_ITEMS(contexts, ".paint_common", ".particlemode"); - break; - case CTX_MODE_OBJECT: - ARRAY_SET_ITEMS(contexts, ".objectmode"); - break; - case CTX_MODE_PAINT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); - break; - case CTX_MODE_SCULPT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); - break; - case CTX_MODE_WEIGHT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); - break; - default: - break; - } - } - else if (workspace->tools_space_type == SPACE_IMAGE) { - switch (workspace->tools_mode) { - case SI_MODE_VIEW: - break; - case SI_MODE_PAINT: - ARRAY_SET_ITEMS(contexts, ".paint_common_2d", ".imagepaint_2d"); - break; - case SI_MODE_MASK: - break; - case SI_MODE_UV: - if (mode == CTX_MODE_EDIT_MESH) { - ARRAY_SET_ITEMS(contexts, ".uv_sculpt"); - } - break; - } - } - - /* for grease pencil we don't use tool system yet, so we need check outside - * workspace->tools_space_type because this value is not available - */ - switch (mode) { - case CTX_MODE_PAINT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); - break; - case CTX_MODE_SCULPT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); - break; - case CTX_MODE_WEIGHT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); - break; - case CTX_MODE_EDIT_GPENCIL: - ARRAY_SET_ITEMS(contexts, ".greasepencil_edit"); - break; - default: - break; - } - - int i = 0; - while (contexts_base[i]) { - i++; - } - BLI_assert(i < ARRAY_SIZE(contexts_base)); - contexts_base[i] = ".workspace"; - - const bool vertical = true; - ED_region_panels_layout_ex(C, ar, contexts_base, -1, vertical); + const WorkSpace *workspace = CTX_wm_workspace(C); + const enum eContextObjectMode mode = CTX_data_mode_enum(C); + + const char *contexts_base[5] = {NULL}; + contexts_base[0] = ".active_tool"; + const char **contexts = &contexts_base[1]; + + if (workspace->tools_space_type == SPACE_VIEW3D) { + switch (mode) { + case CTX_MODE_EDIT_MESH: + ARRAY_SET_ITEMS(contexts, ".mesh_edit"); + break; + case CTX_MODE_EDIT_CURVE: + ARRAY_SET_ITEMS(contexts, ".curve_edit"); + break; + case CTX_MODE_EDIT_SURFACE: + ARRAY_SET_ITEMS(contexts, ".curve_edit"); + break; + case CTX_MODE_EDIT_TEXT: + ARRAY_SET_ITEMS(contexts, ".text_edit"); + break; + case CTX_MODE_EDIT_ARMATURE: + ARRAY_SET_ITEMS(contexts, ".armature_edit"); + break; + case CTX_MODE_EDIT_METABALL: + ARRAY_SET_ITEMS(contexts, ".mball_edit"); + break; + case CTX_MODE_EDIT_LATTICE: + ARRAY_SET_ITEMS(contexts, ".lattice_edit"); + break; + case CTX_MODE_POSE: + ARRAY_SET_ITEMS(contexts, ".posemode"); + break; + case CTX_MODE_SCULPT: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".sculpt_mode"); + break; + case CTX_MODE_PAINT_WEIGHT: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".weightpaint"); + break; + case CTX_MODE_PAINT_VERTEX: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".vertexpaint"); + break; + case CTX_MODE_PAINT_TEXTURE: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".imagepaint"); + break; + case CTX_MODE_PARTICLE: + ARRAY_SET_ITEMS(contexts, ".paint_common", ".particlemode"); + break; + case CTX_MODE_OBJECT: + ARRAY_SET_ITEMS(contexts, ".objectmode"); + break; + case CTX_MODE_PAINT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); + break; + case CTX_MODE_SCULPT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); + break; + case CTX_MODE_WEIGHT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); + break; + default: + break; + } + } + else if (workspace->tools_space_type == SPACE_IMAGE) { + switch (workspace->tools_mode) { + case SI_MODE_VIEW: + break; + case SI_MODE_PAINT: + ARRAY_SET_ITEMS(contexts, ".paint_common_2d", ".imagepaint_2d"); + break; + case SI_MODE_MASK: + break; + case SI_MODE_UV: + if (mode == CTX_MODE_EDIT_MESH) { + ARRAY_SET_ITEMS(contexts, ".uv_sculpt"); + } + break; + } + } + + /* for grease pencil we don't use tool system yet, so we need check outside + * workspace->tools_space_type because this value is not available + */ + switch (mode) { + case CTX_MODE_PAINT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_paint"); + break; + case CTX_MODE_SCULPT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_sculpt"); + break; + case CTX_MODE_WEIGHT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_weight"); + break; + case CTX_MODE_EDIT_GPENCIL: + ARRAY_SET_ITEMS(contexts, ".greasepencil_edit"); + break; + default: + break; + } + + int i = 0; + while (contexts_base[i]) { + i++; + } + BLI_assert(i < ARRAY_SIZE(contexts_base)); + contexts_base[i] = ".workspace"; + + const bool vertical = true; + ED_region_panels_layout_ex(C, ar, contexts_base, -1, vertical); } static void buttons_main_region_layout(const bContext *C, ARegion *ar) { - /* draw entirely, view changes should be handled here */ - SpaceProperties *sbuts = CTX_wm_space_properties(C); + /* draw entirely, view changes should be handled here */ + SpaceProperties *sbuts = CTX_wm_space_properties(C); - if (sbuts->mainb == BCONTEXT_TOOL) { - buttons_main_region_layout_tool(C, ar); - } - else { - buttons_main_region_layout_properties(C, sbuts, ar); - } + if (sbuts->mainb == BCONTEXT_TOOL) { + buttons_main_region_layout_tool(C, ar); + } + else { + buttons_main_region_layout_properties(C, sbuts, ar); + } - sbuts->mainbo = sbuts->mainb; + sbuts->mainbo = sbuts->mainb; } -static void buttons_main_region_listener( - wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn, - const Scene *UNUSED(scene)) +static void buttons_main_region_listener(wmWindow *UNUSED(win), + ScrArea *UNUSED(sa), + ARegion *ar, + wmNotifier *wmn, + const Scene *UNUSED(scene)) { - /* context changes */ - switch (wmn->category) { - case NC_SCREEN: - if (ELEM(wmn->data, ND_LAYER)) { - ED_region_tag_redraw(ar); - } - break; - } + /* context changes */ + switch (wmn->category) { + case NC_SCREEN: + if (ELEM(wmn->data, ND_LAYER)) { + ED_region_tag_redraw(ar); + } + break; + } } static void buttons_operatortypes(void) { - WM_operatortype_append(BUTTONS_OT_context_menu); - WM_operatortype_append(BUTTONS_OT_file_browse); - WM_operatortype_append(BUTTONS_OT_directory_browse); + WM_operatortype_append(BUTTONS_OT_context_menu); + WM_operatortype_append(BUTTONS_OT_file_browse); + WM_operatortype_append(BUTTONS_OT_directory_browse); } static void buttons_keymap(struct wmKeyConfig *keyconf) { - WM_keymap_ensure(keyconf, "Property Editor", SPACE_PROPERTIES, 0); + WM_keymap_ensure(keyconf, "Property Editor", SPACE_PROPERTIES, 0); } /* add handlers, stuff you only do once or on area/region changes */ static void buttons_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar) { #ifdef USE_HEADER_CONTEXT_PATH - /* Reinsert context buttons header-type at the end of the list so it's drawn last. */ - HeaderType *context_ht = BLI_findstring(&ar->type->headertypes, "BUTTONS_HT_context", offsetof(HeaderType, idname)); - BLI_remlink(&ar->type->headertypes, context_ht); - BLI_addtail(&ar->type->headertypes, context_ht); + /* Reinsert context buttons header-type at the end of the list so it's drawn last. */ + HeaderType *context_ht = BLI_findstring( + &ar->type->headertypes, "BUTTONS_HT_context", offsetof(HeaderType, idname)); + BLI_remlink(&ar->type->headertypes, context_ht); + BLI_addtail(&ar->type->headertypes, context_ht); #endif - ED_region_header_init(ar); + ED_region_header_init(ar); } static void buttons_header_region_draw(const bContext *C, ARegion *ar) { - SpaceProperties *sbuts = CTX_wm_space_properties(C); + SpaceProperties *sbuts = CTX_wm_space_properties(C); - /* Needed for RNA to get the good values! */ - buttons_context_compute(C, sbuts); + /* Needed for RNA to get the good values! */ + buttons_context_compute(C, sbuts); - ED_region_header(C, ar); + ED_region_header(C, ar); } -static void buttons_header_region_message_subscribe( - const bContext *UNUSED(C), - WorkSpace *UNUSED(workspace), Scene *UNUSED(scene), - bScreen *UNUSED(screen), ScrArea *sa, ARegion *ar, - struct wmMsgBus *mbus) +static void buttons_header_region_message_subscribe(const bContext *UNUSED(C), + WorkSpace *UNUSED(workspace), + Scene *UNUSED(scene), + bScreen *UNUSED(screen), + ScrArea *sa, + ARegion *ar, + struct wmMsgBus *mbus) { - SpaceProperties *sbuts = sa->spacedata.first; - wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { - .owner = ar, - .user_data = ar, - .notify = ED_region_do_msg_notify_tag_redraw, - }; + SpaceProperties *sbuts = sa->spacedata.first; + wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { + .owner = ar, + .user_data = ar, + .notify = ED_region_do_msg_notify_tag_redraw, + }; - /* Don't check for SpaceProperties.mainb here, we may toggle between view-layers - * where one has no active object, so that available contexts changes. */ - WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw); + /* Don't check for SpaceProperties.mainb here, we may toggle between view-layers + * where one has no active object, so that available contexts changes. */ + WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw); - if (!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_OUTPUT, BCONTEXT_SCENE, BCONTEXT_WORLD)) { - WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw); - } + if (!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_OUTPUT, BCONTEXT_SCENE, BCONTEXT_WORLD)) { + WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw); + } - if (sbuts->mainb == BCONTEXT_TOOL) { - WM_msg_subscribe_rna_anon_prop(mbus, WorkSpace, tools, &msg_sub_value_region_tag_redraw); - } + if (sbuts->mainb == BCONTEXT_TOOL) { + WM_msg_subscribe_rna_anon_prop(mbus, WorkSpace, tools, &msg_sub_value_region_tag_redraw); + } #ifdef USE_HEADER_CONTEXT_PATH - WM_msg_subscribe_rna_anon_prop(mbus, SpaceProperties, context, &msg_sub_value_region_tag_redraw); + WM_msg_subscribe_rna_anon_prop(mbus, SpaceProperties, context, &msg_sub_value_region_tag_redraw); #endif } static void buttons_navigation_bar_region_init(wmWindowManager *wm, ARegion *ar) { - wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Property Editor", SPACE_PROPERTIES, 0); - WM_event_add_keymap_handler(&ar->handlers, keymap); + wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "Property Editor", SPACE_PROPERTIES, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); - ar->flag |= RGN_FLAG_PREFSIZE_OR_HIDDEN; + ar->flag |= RGN_FLAG_PREFSIZE_OR_HIDDEN; - ED_region_panels_init(wm, ar); - ar->v2d.keepzoom |= V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y; + ED_region_panels_init(wm, ar); + ar->v2d.keepzoom |= V2D_LOCKZOOM_X | V2D_LOCKZOOM_Y; } static void buttons_navigation_bar_region_draw(const bContext *C, ARegion *ar) { - for (PanelType *pt = ar->type->paneltypes.first; pt; pt = pt->next) { - pt->flag |= PNL_LAYOUT_VERT_BAR; - } - - ED_region_panels_layout(C, ar); - /* ED_region_panels_layout adds vertical scrollbars, we don't want them. */ - ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL; - ED_region_panels_draw(C, ar); + for (PanelType *pt = ar->type->paneltypes.first; pt; pt = pt->next) { + pt->flag |= PNL_LAYOUT_VERT_BAR; + } + + ED_region_panels_layout(C, ar); + /* ED_region_panels_layout adds vertical scrollbars, we don't want them. */ + ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL; + ED_region_panels_draw(C, ar); } -static void buttons_navigation_bar_region_message_subscribe( - const bContext *UNUSED(C), - WorkSpace *UNUSED(workspace), Scene *UNUSED(scene), - bScreen *UNUSED(screen), ScrArea *UNUSED(sa), ARegion *ar, - struct wmMsgBus *mbus) +static void buttons_navigation_bar_region_message_subscribe(const bContext *UNUSED(C), + WorkSpace *UNUSED(workspace), + Scene *UNUSED(scene), + bScreen *UNUSED(screen), + ScrArea *UNUSED(sa), + ARegion *ar, + struct wmMsgBus *mbus) { - wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { - .owner = ar, - .user_data = ar, - .notify = ED_region_do_msg_notify_tag_redraw, - }; + wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { + .owner = ar, + .user_data = ar, + .notify = ED_region_do_msg_notify_tag_redraw, + }; - WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw); + WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw); } /* draw a certain button set only if properties area is currently * showing that button set, to reduce unnecessary drawing. */ static void buttons_area_redraw(ScrArea *sa, short buttons) { - SpaceProperties *sbuts = sa->spacedata.first; + SpaceProperties *sbuts = sa->spacedata.first; - /* if the area's current button set is equal to the one to redraw */ - if (sbuts->mainb == buttons) { - ED_area_tag_redraw(sa); - } + /* if the area's current button set is equal to the one to redraw */ + if (sbuts->mainb == buttons) { + ED_area_tag_redraw(sa); + } } /* reused! */ -static void buttons_area_listener( - wmWindow *UNUSED(win), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene)) +static void buttons_area_listener(wmWindow *UNUSED(win), + ScrArea *sa, + wmNotifier *wmn, + Scene *UNUSED(scene)) { - SpaceProperties *sbuts = sa->spacedata.first; - - /* context changes */ - switch (wmn->category) { - case NC_SCENE: - switch (wmn->data) { - case ND_RENDER_OPTIONS: - buttons_area_redraw(sa, BCONTEXT_RENDER); - buttons_area_redraw(sa, BCONTEXT_VIEW_LAYER); - break; - case ND_WORLD: - buttons_area_redraw(sa, BCONTEXT_WORLD); - sbuts->preview = 1; - break; - case ND_FRAME: - /* any buttons area can have animated properties so redraw all */ - ED_area_tag_redraw(sa); - sbuts->preview = 1; - break; - case ND_OB_ACTIVE: - ED_area_tag_redraw(sa); - sbuts->preview = 1; - break; - case ND_KEYINGSET: - buttons_area_redraw(sa, BCONTEXT_SCENE); - break; - case ND_RENDER_RESULT: - break; - case ND_MODE: - case ND_LAYER: - default: - ED_area_tag_redraw(sa); - break; - } - break; - case NC_OBJECT: - switch (wmn->data) { - case ND_TRANSFORM: - buttons_area_redraw(sa, BCONTEXT_OBJECT); - buttons_area_redraw(sa, BCONTEXT_DATA); /* autotexpace flag */ - break; - case ND_POSE: - buttons_area_redraw(sa, BCONTEXT_DATA); - break; - case ND_BONE_ACTIVE: - case ND_BONE_SELECT: - buttons_area_redraw(sa, BCONTEXT_BONE); - buttons_area_redraw(sa, BCONTEXT_BONE_CONSTRAINT); - buttons_area_redraw(sa, BCONTEXT_DATA); - break; - case ND_MODIFIER: - if (wmn->action == NA_RENAME) { - ED_area_tag_redraw(sa); - } - else { - buttons_area_redraw(sa, BCONTEXT_MODIFIER); - } - buttons_area_redraw(sa, BCONTEXT_PHYSICS); - break; - case ND_CONSTRAINT: - 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); - buttons_area_redraw(sa, BCONTEXT_PHYSICS); - break; - case ND_SHADING: - case ND_SHADING_DRAW: - case ND_SHADING_LINKS: - case ND_SHADING_PREVIEW: - /* currently works by redraws... if preview is set, it (re)starts job */ - sbuts->preview = 1; - break; - default: - /* Not all object RNA props have a ND_ notifier (yet) */ - ED_area_tag_redraw(sa); - break; - } - break; - case NC_GEOM: - switch (wmn->data) { - case ND_SELECT: - case ND_DATA: - case ND_VERTEX_GROUP: - ED_area_tag_redraw(sa); - break; - } - break; - case NC_MATERIAL: - ED_area_tag_redraw(sa); - switch (wmn->data) { - case ND_SHADING: - case ND_SHADING_DRAW: - case ND_SHADING_LINKS: - case ND_SHADING_PREVIEW: - case ND_NODES: - /* currently works by redraws... if preview is set, it (re)starts job */ - sbuts->preview = 1; - break; - } - break; - case NC_WORLD: - buttons_area_redraw(sa, BCONTEXT_WORLD); - sbuts->preview = 1; - break; - case NC_LAMP: - buttons_area_redraw(sa, BCONTEXT_DATA); - sbuts->preview = 1; - break; - case NC_GROUP: - buttons_area_redraw(sa, BCONTEXT_OBJECT); - break; - case NC_BRUSH: - buttons_area_redraw(sa, BCONTEXT_TEXTURE); - buttons_area_redraw(sa, BCONTEXT_TOOL); - sbuts->preview = 1; - break; - case NC_TEXTURE: - case NC_IMAGE: - if (wmn->action != NA_PAINTING) { - ED_area_tag_redraw(sa); - sbuts->preview = 1; - } - break; - case NC_SPACE: - if (wmn->data == ND_SPACE_PROPERTIES) { - ED_area_tag_redraw(sa); - } - break; - case NC_ID: - if (wmn->action == NA_RENAME) { - ED_area_tag_redraw(sa); - } - break; - case NC_ANIMATION: - switch (wmn->data) { - case ND_KEYFRAME: - if (ELEM(wmn->action, NA_EDITED, NA_ADDED, NA_REMOVED)) { - ED_area_tag_redraw(sa); - } - break; - } - break; - case NC_GPENCIL: - switch (wmn->data) { - case ND_DATA: - if (ELEM(wmn->action, NA_EDITED, NA_ADDED, NA_REMOVED)) { - ED_area_tag_redraw(sa); - } - break; - } - break; - case NC_NODE: - if (wmn->action == NA_SELECTED) { - ED_area_tag_redraw(sa); - /* new active node, update texture preview */ - if (sbuts->mainb == BCONTEXT_TEXTURE) { - sbuts->preview = 1; - } - } - break; - /* Listener for preview render, when doing an global undo. */ - case NC_WM: - if (wmn->data == ND_UNDO) { - ED_area_tag_redraw(sa); - sbuts->preview = 1; - } - break; + SpaceProperties *sbuts = sa->spacedata.first; + + /* context changes */ + switch (wmn->category) { + case NC_SCENE: + switch (wmn->data) { + case ND_RENDER_OPTIONS: + buttons_area_redraw(sa, BCONTEXT_RENDER); + buttons_area_redraw(sa, BCONTEXT_VIEW_LAYER); + break; + case ND_WORLD: + buttons_area_redraw(sa, BCONTEXT_WORLD); + sbuts->preview = 1; + break; + case ND_FRAME: + /* any buttons area can have animated properties so redraw all */ + ED_area_tag_redraw(sa); + sbuts->preview = 1; + break; + case ND_OB_ACTIVE: + ED_area_tag_redraw(sa); + sbuts->preview = 1; + break; + case ND_KEYINGSET: + buttons_area_redraw(sa, BCONTEXT_SCENE); + break; + case ND_RENDER_RESULT: + break; + case ND_MODE: + case ND_LAYER: + default: + ED_area_tag_redraw(sa); + break; + } + break; + case NC_OBJECT: + switch (wmn->data) { + case ND_TRANSFORM: + buttons_area_redraw(sa, BCONTEXT_OBJECT); + buttons_area_redraw(sa, BCONTEXT_DATA); /* autotexpace flag */ + break; + case ND_POSE: + buttons_area_redraw(sa, BCONTEXT_DATA); + break; + case ND_BONE_ACTIVE: + case ND_BONE_SELECT: + buttons_area_redraw(sa, BCONTEXT_BONE); + buttons_area_redraw(sa, BCONTEXT_BONE_CONSTRAINT); + buttons_area_redraw(sa, BCONTEXT_DATA); + break; + case ND_MODIFIER: + if (wmn->action == NA_RENAME) { + ED_area_tag_redraw(sa); + } + else { + buttons_area_redraw(sa, BCONTEXT_MODIFIER); + } + buttons_area_redraw(sa, BCONTEXT_PHYSICS); + break; + case ND_CONSTRAINT: + 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); + buttons_area_redraw(sa, BCONTEXT_PHYSICS); + break; + case ND_SHADING: + case ND_SHADING_DRAW: + case ND_SHADING_LINKS: + case ND_SHADING_PREVIEW: + /* currently works by redraws... if preview is set, it (re)starts job */ + sbuts->preview = 1; + break; + default: + /* Not all object RNA props have a ND_ notifier (yet) */ + ED_area_tag_redraw(sa); + break; + } + break; + case NC_GEOM: + switch (wmn->data) { + case ND_SELECT: + case ND_DATA: + case ND_VERTEX_GROUP: + ED_area_tag_redraw(sa); + break; + } + break; + case NC_MATERIAL: + ED_area_tag_redraw(sa); + switch (wmn->data) { + case ND_SHADING: + case ND_SHADING_DRAW: + case ND_SHADING_LINKS: + case ND_SHADING_PREVIEW: + case ND_NODES: + /* currently works by redraws... if preview is set, it (re)starts job */ + sbuts->preview = 1; + break; + } + break; + case NC_WORLD: + buttons_area_redraw(sa, BCONTEXT_WORLD); + sbuts->preview = 1; + break; + case NC_LAMP: + buttons_area_redraw(sa, BCONTEXT_DATA); + sbuts->preview = 1; + break; + case NC_GROUP: + buttons_area_redraw(sa, BCONTEXT_OBJECT); + break; + case NC_BRUSH: + buttons_area_redraw(sa, BCONTEXT_TEXTURE); + buttons_area_redraw(sa, BCONTEXT_TOOL); + sbuts->preview = 1; + break; + case NC_TEXTURE: + case NC_IMAGE: + if (wmn->action != NA_PAINTING) { + ED_area_tag_redraw(sa); + sbuts->preview = 1; + } + break; + case NC_SPACE: + if (wmn->data == ND_SPACE_PROPERTIES) { + ED_area_tag_redraw(sa); + } + break; + case NC_ID: + if (wmn->action == NA_RENAME) { + ED_area_tag_redraw(sa); + } + break; + case NC_ANIMATION: + switch (wmn->data) { + case ND_KEYFRAME: + if (ELEM(wmn->action, NA_EDITED, NA_ADDED, NA_REMOVED)) { + ED_area_tag_redraw(sa); + } + break; + } + break; + case NC_GPENCIL: + switch (wmn->data) { + case ND_DATA: + if (ELEM(wmn->action, NA_EDITED, NA_ADDED, NA_REMOVED)) { + ED_area_tag_redraw(sa); + } + break; + } + break; + case NC_NODE: + if (wmn->action == NA_SELECTED) { + ED_area_tag_redraw(sa); + /* new active node, update texture preview */ + if (sbuts->mainb == BCONTEXT_TEXTURE) { + sbuts->preview = 1; + } + } + break; + /* Listener for preview render, when doing an global undo. */ + case NC_WM: + if (wmn->data == ND_UNDO) { + ED_area_tag_redraw(sa); + sbuts->preview = 1; + } + break; #ifdef WITH_FREESTYLE - case NC_LINESTYLE: - ED_area_tag_redraw(sa); - sbuts->preview = 1; - break; + case NC_LINESTYLE: + ED_area_tag_redraw(sa); + sbuts->preview = 1; + break; #endif - } + } - if (wmn->data == ND_KEYS) { - ED_area_tag_redraw(sa); - } + if (wmn->data == ND_KEYS) { + ED_area_tag_redraw(sa); + } } static void buttons_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id) { - SpaceProperties *sbuts = (SpaceProperties *)slink; - - if (sbuts->pinid == old_id) { - sbuts->pinid = new_id; - if (new_id == NULL) { - sbuts->flag &= ~SB_PIN_CONTEXT; - } - } - - if (sbuts->path) { - ButsContextPath *path = sbuts->path; - int i; - - for (i = 0; i < path->len; i++) { - if (path->ptr[i].id.data == old_id) { - break; - } - } - - if (i == path->len) { - /* pass */ - } - else if (new_id == NULL) { - if (i == 0) { - MEM_SAFE_FREE(sbuts->path); - } - else { - memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i)); - path->len = i; - } - } - else { - RNA_id_pointer_create(new_id, &path->ptr[i]); - /* There is no easy way to check/make path downwards valid, just nullify it. - * Next redraw will rebuild this anyway. */ - i++; - memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i)); - path->len = i; - } - } - - if (sbuts->texuser) { - ButsContextTexture *ct = sbuts->texuser; - if ((ID *)ct->texture == old_id) { - ct->texture = (Tex *)new_id; - } - BLI_freelistN(&ct->users); - ct->user = NULL; - } + SpaceProperties *sbuts = (SpaceProperties *)slink; + + if (sbuts->pinid == old_id) { + sbuts->pinid = new_id; + if (new_id == NULL) { + sbuts->flag &= ~SB_PIN_CONTEXT; + } + } + + if (sbuts->path) { + ButsContextPath *path = sbuts->path; + int i; + + for (i = 0; i < path->len; i++) { + if (path->ptr[i].id.data == old_id) { + break; + } + } + + if (i == path->len) { + /* pass */ + } + else if (new_id == NULL) { + if (i == 0) { + MEM_SAFE_FREE(sbuts->path); + } + else { + memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i)); + path->len = i; + } + } + else { + RNA_id_pointer_create(new_id, &path->ptr[i]); + /* There is no easy way to check/make path downwards valid, just nullify it. + * Next redraw will rebuild this anyway. */ + i++; + memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i)); + path->len = i; + } + } + + if (sbuts->texuser) { + ButsContextTexture *ct = sbuts->texuser; + if ((ID *)ct->texture == old_id) { + ct->texture = (Tex *)new_id; + } + BLI_freelistN(&ct->users); + ct->user = NULL; + } } /* only called once, from space/spacetypes.c */ void ED_spacetype_buttons(void) { - SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype buttons"); - ARegionType *art; - - st->spaceid = SPACE_PROPERTIES; - strncpy(st->name, "Buttons", BKE_ST_MAXNAME); - - st->new = buttons_new; - st->free = buttons_free; - st->init = buttons_init; - st->duplicate = buttons_duplicate; - st->operatortypes = buttons_operatortypes; - st->keymap = buttons_keymap; - st->listener = buttons_area_listener; - st->context = buttons_context; - st->id_remap = buttons_id_remap; - - /* regions: main window */ - art = MEM_callocN(sizeof(ARegionType), "spacetype buttons region"); - art->regionid = RGN_TYPE_WINDOW; - art->init = buttons_main_region_init; - art->layout = buttons_main_region_layout; - art->draw = ED_region_panels_draw; - art->listener = buttons_main_region_listener; - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; + SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype buttons"); + ARegionType *art; + + st->spaceid = SPACE_PROPERTIES; + strncpy(st->name, "Buttons", BKE_ST_MAXNAME); + + st->new = buttons_new; + st->free = buttons_free; + st->init = buttons_init; + st->duplicate = buttons_duplicate; + st->operatortypes = buttons_operatortypes; + st->keymap = buttons_keymap; + st->listener = buttons_area_listener; + st->context = buttons_context; + st->id_remap = buttons_id_remap; + + /* regions: main window */ + art = MEM_callocN(sizeof(ARegionType), "spacetype buttons region"); + art->regionid = RGN_TYPE_WINDOW; + art->init = buttons_main_region_init; + art->layout = buttons_main_region_layout; + art->draw = ED_region_panels_draw; + art->listener = buttons_main_region_listener; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; #ifndef USE_HEADER_CONTEXT_PATH - buttons_context_register(art); + buttons_context_register(art); #endif - BLI_addhead(&st->regiontypes, art); + BLI_addhead(&st->regiontypes, art); - /* regions: header */ - art = MEM_callocN(sizeof(ARegionType), "spacetype buttons region"); - art->regionid = RGN_TYPE_HEADER; - art->prefsizey = HEADERY; - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; + /* regions: header */ + art = MEM_callocN(sizeof(ARegionType), "spacetype buttons region"); + art->regionid = RGN_TYPE_HEADER; + art->prefsizey = HEADERY; + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; - art->init = buttons_header_region_init; - art->draw = buttons_header_region_draw; - art->message_subscribe = buttons_header_region_message_subscribe; + art->init = buttons_header_region_init; + art->draw = buttons_header_region_draw; + art->message_subscribe = buttons_header_region_message_subscribe; #ifdef USE_HEADER_CONTEXT_PATH - buttons_context_register(art); + buttons_context_register(art); #endif - BLI_addhead(&st->regiontypes, art); - - /* regions: navigation bar */ - art = MEM_callocN(sizeof(ARegionType), "spacetype nav buttons region"); - art->regionid = RGN_TYPE_NAV_BAR; - art->prefsizex = AREAMINX - 3; /* XXX Works and looks best, - * should we update AREAMINX accordingly? */ - art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; - art->init = buttons_navigation_bar_region_init; - art->draw = buttons_navigation_bar_region_draw; - art->message_subscribe = buttons_navigation_bar_region_message_subscribe; - BLI_addhead(&st->regiontypes, art); - - BKE_spacetype_register(st); + BLI_addhead(&st->regiontypes, art); + + /* regions: navigation bar */ + art = MEM_callocN(sizeof(ARegionType), "spacetype nav buttons region"); + art->regionid = RGN_TYPE_NAV_BAR; + art->prefsizex = AREAMINX - 3; /* XXX Works and looks best, + * should we update AREAMINX accordingly? */ + art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; + art->init = buttons_navigation_bar_region_init; + art->draw = buttons_navigation_bar_region_draw; + art->message_subscribe = buttons_navigation_bar_region_message_subscribe; + BLI_addhead(&st->regiontypes, art); + + BKE_spacetype_register(st); } -- cgit v1.2.3