From 3a93314753cabe176bde1cdb084afa551323321b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 2 Aug 2018 17:41:11 +1000 Subject: Tool System: initial particle system support --- .../startup/bl_ui/space_toolsystem_toolbar.py | 44 +++++++++++++++++++--- source/blender/makesrna/intern/rna_workspace_api.c | 31 +++++++++++---- .../blender/windowmanager/intern/wm_toolsystem.c | 44 +++++++++++++++------- 3 files changed, 93 insertions(+), 26 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index c1d417ef12d..5ccd3ee123b 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -40,9 +40,6 @@ def generate_from_brushes_ex( brush_category_attr, brush_category_layout, ): - def draw_settings(context, layout, tool): - _defs_gpencil_paint.draw_settings_common(context, layout, tool) - # Categories brush_categories = {} if context.mode != 'GPENCIL_PAINT': @@ -60,6 +57,9 @@ def generate_from_brushes_ex( ) ) else: + def draw_settings(context, layout, tool): + _defs_gpencil_paint.draw_settings_common(context, layout, tool) + for brush_type in brush_category_layout: for brush in context.blend_data.brushes: if getattr(brush, brush_test_attr) and brush.gpencil_settings.gp_icon == brush_type[0]: @@ -141,6 +141,28 @@ def generate_from_brushes_ex( return tool_defs +def generate_from_enum_ex( + context, *, + icon_prefix, + data, + attr, +): + tool_defs = [] + for enum in data.rna_type.properties[attr].enum_items_static: + name = enum.name + identifier = enum.identifier + tool_defs.append( + ToolDef.from_dict( + dict( + text=name, + icon=icon_prefix + identifier.lower(), + data_block=identifier, + ) + ) + ) + return tuple(tool_defs) + + class _defs_view3d_generic: @ToolDef.from_fn def cursor(): @@ -832,6 +854,18 @@ class _defs_pose: ) +class _defs_particle: + + @staticmethod + def generate_from_brushes(context): + return generate_from_enum_ex( + context, + icon_prefix="brush.particle.", + data=context.tool_settings.particle_edit, + attr="tool", + ) + + class _defs_sculpt: @staticmethod @@ -1542,9 +1576,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): _defs_edit_curve.extrude_cursor, ], 'PARTICLE': [ - # TODO(campbell): use cursor click tool to allow paint tools to run, - # we need to integrate particle system tools properly. - _defs_view3d_generic.cursor_click, + _defs_particle.generate_from_brushes, ], 'SCULPT': [ _defs_sculpt.generate_from_brushes, diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c index 4469b88da6d..aac38d05cd8 100644 --- a/source/blender/makesrna/intern/rna_workspace_api.c +++ b/source/blender/makesrna/intern/rna_workspace_api.c @@ -84,14 +84,31 @@ static void rna_WorkspaceTool_refresh_from_context( 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); - Paint *paint = BKE_paint_get_active(scene, view_layer); - if (paint) { - const ID *brush = (ID *)paint->brush; - if (!STREQ(tref_rt->data_block, brush->name + 2)) { - STRNCPY(tref_rt->data_block, brush->name + 2); - STRNCPY(tref->idname, brush->name + 2); - printf("Found\n"); + 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); + } + } } } } diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c index dcb33376f05..0aa5e16a519 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.c +++ b/source/blender/windowmanager/intern/wm_toolsystem.c @@ -49,6 +49,7 @@ #include "BKE_workspace.h" #include "RNA_access.h" +#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" @@ -184,20 +185,37 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre if (tref_rt->data_block[0]) { Main *bmain = CTX_data_main(C); + if ((tref->space_type == SPACE_VIEW3D) && + (tref->mode == CTX_MODE_PARTICLE)) - /* Currently only brush data-blocks supported. */ - struct Brush *brush = (struct Brush *)BKE_libblock_find_name(bmain, ID_BR, tref_rt->data_block); - - if (brush) { - wmWindowManager *wm = bmain->wm.first; - for (wmWindow *win = wm->windows.first; win; win = win->next) { - if (workspace == WM_window_get_active_workspace(win)) { - Scene *scene = WM_window_get_active_scene(win); - ViewLayer *view_layer = WM_window_get_active_view_layer(win); - Paint *paint = BKE_paint_get_active(scene, view_layer); - if (paint) { - if (brush) { - BKE_paint_brush_set(paint, brush); + { + const EnumPropertyItem *items = rna_enum_particle_edit_hair_brush_items; + const int i = RNA_enum_from_identifier(items, tref_rt->data_block); + if (i != -1) { + const int value = items[i].value; + wmWindowManager *wm = bmain->wm.first; + for (wmWindow *win = wm->windows.first; win; win = win->next) { + if (workspace == WM_window_get_active_workspace(win)) { + Scene *scene = WM_window_get_active_scene(win); + ToolSettings *ts = scene->toolsettings; + ts->particle.brushtype = value; + } + } + } + } + else { + struct Brush *brush = (struct Brush *)BKE_libblock_find_name(bmain, ID_BR, tref_rt->data_block); + if (brush) { + wmWindowManager *wm = bmain->wm.first; + for (wmWindow *win = wm->windows.first; win; win = win->next) { + if (workspace == WM_window_get_active_workspace(win)) { + Scene *scene = WM_window_get_active_scene(win); + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + Paint *paint = BKE_paint_get_active(scene, view_layer); + if (paint) { + if (brush) { + BKE_paint_brush_set(paint, brush); + } } } } -- cgit v1.2.3