diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-07 00:42:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-07 00:43:56 +0300 |
commit | fb932bb52a65c147689f5940aa0f347066ba0547 (patch) | |
tree | 700b721559370d073ca83324400bc2415f91b797 /source/blender/windowmanager/intern/wm_toolsystem.c | |
parent | 150864dfb95c7b39dfd491805156599609ab3e2a (diff) |
Cleanup: use BKE_brush_tool_get/set macros
Also add API call WM_toolsystem_ref_sync_from_context
(was in rna_workspace_api.c)
Diffstat (limited to 'source/blender/windowmanager/intern/wm_toolsystem.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_toolsystem.c | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c index 8cf8eac5145..3e95bdc49ea 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.c +++ b/source/blender/windowmanager/intern/wm_toolsystem.c @@ -260,13 +260,12 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre if (brush == NULL) { /* Could make into a function. */ brush = (struct Brush *)BKE_libblock_find_name(bmain, ID_BR, items[i].name); - if (brush && slot_index == *(char *)POINTER_OFFSET(brush, paint->runtime.tool_offset)) { + if (brush && slot_index == BKE_brush_tool_get(brush, paint)) { /* pass */ } else { brush = BKE_brush_add(bmain, items[i].name, paint->runtime.ob_mode); - char *tool_type = (char *)POINTER_OFFSET(brush, paint->runtime.tool_offset); - *tool_type = slot_index; + BKE_brush_tool_set(brush, paint, slot_index); } BKE_paint_brush_set(paint, brush); } @@ -408,6 +407,77 @@ void WM_toolsystem_ref_set_from_runtime( } } +/** + * Sync the internal active state of a tool back into the tool system, + * this is needed for active brushes where the real active state is not stored in the tool system. + */ +void WM_toolsystem_ref_sync_from_context( + Main *bmain, WorkSpace *workspace, bToolRef *tref) +{ + 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) { + if (workspace != WM_window_get_active_workspace(win)) { + continue; + } + + 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 ((tref->space_type == SPACE_VIEW3D) && + (tref->mode == CTX_MODE_PARTICLE) && + (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 if ((tref->space_type == SPACE_IMAGE) && + (tref->mode == SI_MODE_UV) && + (ob->mode & + OB_MODE_EDIT)) + { + const EnumPropertyItem *items = rna_enum_uv_sculpt_tool_items; + const int i = RNA_enum_from_value(items, ts->uv_sculpt_tool); + 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 { + const ePaintMode paint_mode = BKE_paintmode_get_from_tool(tref); + Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); + const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); + if (paint && paint->brush && items) { + const ID *brush = (ID *)paint->brush; + const char tool_type = BKE_brush_tool_get((struct Brush *)brush, paint); + const int i = RNA_enum_from_value(items, tool_type); + /* Possible when loading files from the future. */ + if (i != -1) { + const char *name = items[i].name; + const char *identifier = items[i].identifier; + if (!STREQ(tref_rt->data_block, identifier)) { + STRNCPY(tref_rt->data_block, identifier); + STRNCPY(tref->idname, name); + } + } + } + } + } +} + void WM_toolsystem_init(bContext *C) { Main *bmain = CTX_data_main(C); |