diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_workspace_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_workspace_api.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c index 98e84f60b33..aac38d05cd8 100644 --- a/source/blender/makesrna/intern/rna_workspace_api.c +++ b/source/blender/makesrna/intern/rna_workspace_api.c @@ -41,6 +41,8 @@ #ifdef RNA_RUNTIME +#include "BKE_paint.h" + #include "ED_screen.h" static void rna_WorkspaceTool_setup( @@ -68,6 +70,51 @@ static void rna_WorkspaceTool_setup( WM_toolsystem_ref_set_from_runtime(C, (WorkSpace *)id, tref, &tref_rt, name); } +static void rna_WorkspaceTool_refresh_from_context( + ID *id, + bToolRef *tref, + Main *bmain) +{ + bToolRef_Runtime *tref_rt = tref->runtime; + if ((tref_rt == NULL) || (tref_rt->data_block[0] == '\0')) { + return; + } + wmWindowManager *wm = bmain->wm.first; + for (wmWindow *win = wm->windows.first; win; win = win->next) { + WorkSpace *workspace = WM_window_get_active_workspace(win); + if (&workspace->id == id) { + Scene *scene = WM_window_get_active_scene(win); + ToolSettings *ts = scene->toolsettings; + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + Object *ob = OBACT(view_layer); + if (ob == NULL) { + /* pass */ + } + else if (ob->mode & OB_MODE_PARTICLE_EDIT) { + const EnumPropertyItem *items = rna_enum_particle_edit_hair_brush_items; + const int i = RNA_enum_from_value(items, ts->particle.brushtype); + const EnumPropertyItem *item = &items[i]; + if (!STREQ(tref_rt->data_block, item->identifier)) { + STRNCPY(tref_rt->data_block, item->identifier); + STRNCPY(tref->idname, item->name); + } + } + else { + Paint *paint = BKE_paint_get_active(scene, view_layer); + if (paint) { + const ID *brush = (ID *)paint->brush; + if (brush) { + if (!STREQ(tref_rt->data_block, brush->name + 2)) { + STRNCPY(tref_rt->data_block, brush->name + 2); + STRNCPY(tref->idname, brush->name + 2); + } + } + } + } + } + } +} + static PointerRNA rna_WorkspaceTool_operator_properties( bToolRef *tref, const char *idname) @@ -124,6 +171,8 @@ void RNA_api_workspace_tool(StructRNA *srna) RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR); RNA_def_function_return(func, parm); + func = RNA_def_function(srna, "refresh_from_context", "rna_WorkspaceTool_refresh_from_context"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN); } #endif |