diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-02 01:10:23 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-02 11:40:39 +0300 |
commit | ac8d7873278c47e8e282b7f83888108e2720a451 (patch) | |
tree | 902a404882e4ab22b8d7a153fbfc2e306747b083 /source/blender/blenkernel | |
parent | 5bd3f3e64b7eba34e6c1676b82eec5b3c7d49d97 (diff) |
Tool System: brushes are now categorized by tool
The toolbar now shows brush types, the brush selector now
only shows brushes matching the current tool type.
Details:
- Add's Paint.tool_slots (used by the toolbar).
- Removed custom grease pencil brush tool code.
- Bumped subversion.
See T57526 for details.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_blender_version.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 20 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library_query.c | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint_toolslots.c | 126 |
7 files changed, 155 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index b95e2e504d0..b695132416e 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -28,7 +28,7 @@ * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 280 -#define BLENDER_SUBVERSION 29 +#define BLENDER_SUBVERSION 30 /* Several breakages with 280, e.g. collections vs layers */ #define BLENDER_MINVERSION 280 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 3782d26fc1b..b8938c87275 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -168,6 +168,13 @@ void paint_update_brush_rake_rotation(struct UnifiedPaintSettings *ups, struct B void BKE_paint_stroke_get_average(struct Scene *scene, struct Object *ob, float stroke[3]); + +/* Tool slot API. */ +void BKE_paint_toolslots_init_from_main(struct Main *bmain); +void BKE_paint_toolslots_len_ensure(struct Paint *paint, int len); +void BKE_paint_toolslots_brush_update_ex(struct Scene *scene, struct Paint *paint, struct Brush *brush); +void BKE_paint_toolslots_brush_update(struct Scene *scene, struct Paint *paint); + /* Used for both vertex color and weight paint */ struct SculptVertexPaintGeomMap { int *vert_map_mem; diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 77c9df12428..f2e2c0406af 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -168,6 +168,7 @@ set(SRC intern/outliner_treehash.c intern/packedFile.c intern/paint.c + intern/paint_toolslots.c intern/particle.c intern/particle_child.c intern/particle_distribute.c diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 13087877d5d..94ff7f3f2e5 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -304,7 +304,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->gpencil_settings->draw_subdivide = 1; brush->gpencil_settings->draw_random_sub = 0.0f; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_PENCIL; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_DRAW; + brush->gpencil_tool = GPAINT_TOOL_DRAW; brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS; brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR; @@ -336,7 +336,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->gpencil_settings->thick_smoothlvl = 3; brush->gpencil_settings->draw_random_sub = 0.0f; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_PEN; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_DRAW; + brush->gpencil_tool = GPAINT_TOOL_DRAW; brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS; brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR; @@ -365,7 +365,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->gpencil_settings->draw_subdivide = 1; brush->gpencil_settings->draw_random_sub = 0.0f; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_INK; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_DRAW; + brush->gpencil_tool = GPAINT_TOOL_DRAW; brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS; brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR; @@ -402,7 +402,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->gpencil_settings->draw_subdivide = 1; brush->gpencil_settings->draw_random_sub = 0.0f; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_INKNOISE; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_DRAW; + brush->gpencil_tool = GPAINT_TOOL_DRAW; brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS; brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR; @@ -438,7 +438,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->gpencil_settings->draw_subdivide = 0; brush->gpencil_settings->draw_random_sub = 0; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_BLOCK; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_DRAW; + brush->gpencil_tool = GPAINT_TOOL_DRAW; brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS; brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR; @@ -469,7 +469,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->gpencil_settings->draw_subdivide = 1; brush->gpencil_settings->draw_random_sub = 0.0f; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_MARKER; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_DRAW; + brush->gpencil_tool = GPAINT_TOOL_DRAW; brush->smooth_stroke_radius = SMOOTH_STROKE_RADIUS; brush->smooth_stroke_factor = SMOOTH_STROKE_FACTOR; @@ -483,7 +483,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->gpencil_settings->fill_threshold = 0.1f; brush->gpencil_settings->fill_simplylvl = 1; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_FILL; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_FILL; + brush->gpencil_tool = GPAINT_TOOL_FILL; brush->gpencil_settings->draw_smoothfac = 0.1f; brush->gpencil_settings->draw_smoothlvl = 1; @@ -501,7 +501,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->size = 30.0f; brush->gpencil_settings->flag |= (GP_BRUSH_ENABLE_CURSOR | GP_BRUSH_DEFAULT_ERASER); brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_SOFT; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_ERASE; + brush->gpencil_tool = GPAINT_TOOL_ERASE; brush->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_SOFT; brush->gpencil_settings->era_strength_f = 100.0f; brush->gpencil_settings->era_thickness_f = 0.10f; @@ -511,7 +511,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->size = 30.0f; brush->gpencil_settings->flag |= GP_BRUSH_ENABLE_CURSOR; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_HARD; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_ERASE; + brush->gpencil_tool = GPAINT_TOOL_ERASE; brush->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_HARD; /* Stroke Eraser brush */ @@ -519,7 +519,7 @@ void BKE_brush_gpencil_presets(bContext *C) brush->size = 30.0f; brush->gpencil_settings->flag |= GP_BRUSH_ENABLE_CURSOR; brush->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_STROKE; - brush->gpencil_settings->brush_type = GP_BRUSH_TYPE_ERASE; + brush->gpencil_tool = GPAINT_TOOL_ERASE; brush->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_STROKE; /* set default brush */ diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index e82e1cf2d6b..ea1b35e4c1e 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -280,6 +280,9 @@ static void library_foreach_mtex(LibraryForeachIDData *data, MTex *mtex) static void library_foreach_paint(LibraryForeachIDData *data, Paint *paint) { FOREACH_CALLBACK_INVOKE(data, paint->brush, IDWALK_CB_USER); + for (int i = 0; i < paint->tool_slots_len; i++) { + FOREACH_CALLBACK_INVOKE(data, paint->tool_slots[i].brush, IDWALK_CB_USER); + } FOREACH_CALLBACK_INVOKE(data, paint->palette, IDWALK_CB_USER); FOREACH_FINALIZE_VOID; diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 545581e65ec..93b54fcb132 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -549,6 +549,7 @@ void BKE_paint_init(Main *bmain, Scene *sce, ePaintMode mode, const char col[3]) void BKE_paint_free(Paint *paint) { curvemapping_free(paint->cavity_curve); + MEM_SAFE_FREE(paint->tool_slots); } /* called when copying scene settings, so even if 'src' and 'tar' are the same @@ -559,10 +560,16 @@ void BKE_paint_copy(Paint *src, Paint *tar, const int flag) { tar->brush = src->brush; tar->cavity_curve = curvemapping_copy(src->cavity_curve); + tar->tool_slots = MEM_dupallocN(src->tool_slots); if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id_us_plus((ID *)tar->brush); id_us_plus((ID *)tar->palette); + if (src->tool_slots != NULL) { + for (int i = 0; i < tar->tool_slots_len; i++) { + id_us_plus((ID *)tar->tool_slots[i].brush); + } + } } } diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c new file mode 100644 index 00000000000..bdafe217276 --- /dev/null +++ b/source/blender/blenkernel/intern/paint_toolslots.c @@ -0,0 +1,126 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/paint_toolslots.c + * \ingroup bke + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_modifier_types.h" +#include "DNA_scene_types.h" +#include "DNA_brush_types.h" + +#include "BLI_utildefines.h" + +#include "BKE_main.h" +#include "BKE_library.h" +#include "BKE_paint.h" + +void BKE_paint_toolslots_len_ensure(Paint *paint, int len) +{ + if (paint->tool_slots_len < len) { + paint->tool_slots = MEM_recallocN(paint->tool_slots, sizeof(*paint->tool_slots) * len); + paint->tool_slots_len = len; + } +} + +typedef bool (*BrushCompatFn)(const Brush *brush); +typedef char (*BrushToolFn)(const Brush *brush); + +static void paint_toolslots_init_paint( + Main *bmain, + Paint *paint, + BrushCompatFn brush_compat_fn, BrushToolFn brush_tool_fn) +{ + for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) { + if (brush_compat_fn(brush)) { + uint slot_index = brush_tool_fn(brush); + BKE_paint_toolslots_len_ensure(paint, slot_index + 1); + if (paint->tool_slots[slot_index].brush == NULL) { + paint->tool_slots[slot_index].brush = brush; + id_us_plus(&brush->id); + } + } + } +} + +/* Image paint. */ +static bool brush_compat_from_imagepaint(const Brush *brush) { return brush->ob_mode & OB_MODE_TEXTURE_PAINT; } +static char brush_tool_from_imagepaint(const Brush *brush) { return brush->imagepaint_tool; } +/* Sculpt. */ +static bool brush_compat_from_sculpt(const Brush *brush) { return brush->ob_mode & OB_MODE_SCULPT; } +static char brush_tool_from_sculpt(const Brush *brush) { return brush->sculpt_tool; } +/* Vertex Paint. */ +static bool brush_compat_from_vertexpaint(const Brush *brush) { return brush->ob_mode & OB_MODE_VERTEX_PAINT; } +static char brush_tool_from_vertexpaint(const Brush *brush) { return brush->vertexpaint_tool; } +/* Weight Paint. */ +static bool brush_compat_from_weightpaint(const Brush *brush) { return brush->ob_mode & OB_MODE_WEIGHT_PAINT; } +static char brush_tool_from_weightpaint(const Brush *brush) { return brush->vertexpaint_tool; } +/* Grease Pencil. */ +static bool brush_compat_from_gpencil(const Brush *brush) { return brush->ob_mode & OB_MODE_GPENCIL_PAINT; } +static char brush_tool_from_gpencil(const Brush *brush) { return brush->gpencil_tool; } + +void BKE_paint_toolslots_init_from_main(struct Main *bmain) +{ + for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { + ToolSettings *ts = scene->toolsettings; + paint_toolslots_init_paint(bmain, &ts->imapaint.paint, brush_compat_from_imagepaint, brush_tool_from_imagepaint); + paint_toolslots_init_paint(bmain, &ts->sculpt->paint, brush_compat_from_sculpt, brush_tool_from_sculpt); + paint_toolslots_init_paint(bmain, &ts->vpaint->paint, brush_compat_from_vertexpaint, brush_tool_from_vertexpaint); + paint_toolslots_init_paint(bmain, &ts->wpaint->paint, brush_compat_from_weightpaint, brush_tool_from_weightpaint); + paint_toolslots_init_paint(bmain, &ts->gp_paint->paint, brush_compat_from_gpencil, brush_tool_from_gpencil); + } +} + + +void BKE_paint_toolslots_brush_update_ex(Scene *scene, Paint *paint, Brush *brush) +{ + ToolSettings *ts = scene->toolsettings; + int slot_index; + if (paint == &ts->imapaint.paint) { + slot_index = brush->imagepaint_tool; + } + else if (paint == &ts->sculpt->paint) { + slot_index = brush->sculpt_tool; + } + else if (paint == &ts->vpaint->paint) { + slot_index = brush->vertexpaint_tool; + } + else if (paint == &ts->wpaint->paint) { + slot_index = brush->vertexpaint_tool; + } + else if (paint == &ts->gp_paint->paint) { + slot_index = brush->gpencil_tool; + } + BKE_paint_toolslots_len_ensure(paint, slot_index + 1); + PaintToolSlot *tslot = &paint->tool_slots[slot_index]; + id_us_plus(&brush->id); + id_us_min(&tslot->brush->id); + tslot->brush = brush; +} + +void BKE_paint_toolslots_brush_update(Scene *scene, Paint *paint) +{ + if (paint->brush == NULL) { + return; + } + BKE_paint_toolslots_brush_update_ex(scene, paint, paint->brush); +} |