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 | |
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')
-rw-r--r-- | source/blender/blenkernel/BKE_brush.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint_toolslots.c | 13 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_sculpt_paint.c | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_workspace_api.c | 62 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_toolsystem.h | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_toolsystem.c | 76 |
6 files changed, 94 insertions, 73 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index aca734ae709..1a341d0208b 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -126,6 +126,14 @@ void BKE_brush_scale_size( float new_unprojected_radius, float old_unprojected_radius); +/* Accessors */ +#define BKE_brush_tool_get(brush, p) \ + (CHECK_TYPE_ANY(brush, struct Brush *, const struct Brush *), \ + *(const char *)POINTER_OFFSET(brush, (p)->runtime.tool_offset)) +#define BKE_brush_tool_set(brush, p, tool) { \ + CHECK_TYPE_ANY(brush, struct Brush *); \ + *(char *)POINTER_OFFSET(brush, (p)->runtime.tool_offset) = tool; } ((void)0) + /* debugging only */ void BKE_brush_debug_print_state(struct Brush *br); diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c index c0f26c1c9c1..5f6b1d9438d 100644 --- a/source/blender/blenkernel/intern/paint_toolslots.c +++ b/source/blender/blenkernel/intern/paint_toolslots.c @@ -34,6 +34,7 @@ #include "BKE_main.h" #include "BKE_library.h" +#include "BKE_brush.h" #include "BKE_paint.h" void BKE_paint_toolslots_len_ensure(Paint *paint, int len) @@ -51,12 +52,11 @@ static void paint_toolslots_init(Main *bmain, Paint *paint) if (paint == NULL) { return; } - const uint tool_offset = paint->runtime.tool_offset; const eObjectMode ob_mode = paint->runtime.ob_mode; - BLI_assert(tool_offset && ob_mode); + BLI_assert(paint->runtime.tool_offset && ob_mode); for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) { if (brush->ob_mode & ob_mode) { - const int slot_index = *(char *)POINTER_OFFSET(brush, tool_offset); + const int slot_index = BKE_brush_tool_get(brush, paint); BKE_paint_toolslots_len_ensure(paint, slot_index + 1); if (paint->tool_slots[slot_index].brush == NULL) { paint->tool_slots[slot_index].brush = brush; @@ -83,7 +83,7 @@ void BKE_paint_toolslots_brush_update_ex(Paint *paint, Brush *brush) { const uint tool_offset = paint->runtime.tool_offset; BLI_assert(tool_offset != 0); - int slot_index = *(char *)POINTER_OFFSET(brush, tool_offset); + const int slot_index = BKE_brush_tool_get(brush, paint); BKE_paint_toolslots_len_ensure(paint, slot_index + 1); PaintToolSlot *tslot = &paint->tool_slots[slot_index]; id_us_plus(&brush->id); @@ -112,8 +112,9 @@ void BKE_paint_toolslots_brush_validate(Main *bmain, Paint *paint) for (int i = 0; i < paint->tool_slots_len; i++) { PaintToolSlot *tslot = &paint->tool_slots[i]; if (tslot->brush) { - int slot_index = *(char *)POINTER_OFFSET(tslot->brush, tool_offset); - if ((slot_index != i) || (tslot->brush->ob_mode & ob_mode) == 0) { + if ((i != BKE_brush_tool_get(tslot->brush, paint)) || + (tslot->brush->ob_mode & ob_mode) == 0) + { id_us_min(&tslot->brush->id); tslot->brush = NULL; } diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index a97c971e2d3..841a5be1aff 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -44,6 +44,7 @@ #include "BKE_main.h" #include "BKE_material.h" #include "BKE_paint.h" +#include "BKE_brush.h" #include "ED_image.h" @@ -280,9 +281,7 @@ static bool rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value) if (brush->ob_mode & ob_mode) { if (paint->brush) { - const char *tool_a = (const char *)POINTER_OFFSET(paint->brush, tool_offset); - const char *tool_b = (const char *)POINTER_OFFSET(brush, tool_offset); - if (*tool_a == *tool_b) { + if (BKE_brush_tool_get(paint->brush, paint) == BKE_brush_tool_get(brush, paint)) { return true; } } diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c index 4cb74ac1479..fd268c898ff 100644 --- a/source/blender/makesrna/intern/rna_workspace_api.c +++ b/source/blender/makesrna/intern/rna_workspace_api.c @@ -75,67 +75,7 @@ static void rna_WorkspaceTool_refresh_from_context( 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 ((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 = *(char *)POINTER_OFFSET(brush, paint->runtime.tool_offset); - 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); - } - } - } - } - } - } + WM_toolsystem_ref_sync_from_context(bmain, (WorkSpace *)id, tref); } static PointerRNA rna_WorkspaceTool_operator_properties( diff --git a/source/blender/windowmanager/WM_toolsystem.h b/source/blender/windowmanager/WM_toolsystem.h index 9d9278668a9..7410bf4ab09 100644 --- a/source/blender/windowmanager/WM_toolsystem.h +++ b/source/blender/windowmanager/WM_toolsystem.h @@ -77,6 +77,9 @@ void WM_toolsystem_ref_set_from_runtime( struct bContext *C, struct WorkSpace *workspace, struct bToolRef *tref, const struct bToolRef_Runtime *tool, const char *idname); +void WM_toolsystem_ref_sync_from_context( + struct Main *bmain, struct WorkSpace *workspace, struct bToolRef *tref); + void WM_toolsystem_init(struct bContext *C); int WM_toolsystem_mode_from_spacetype( 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); |