Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/brush.c')
-rw-r--r--source/blender/blenkernel/intern/brush.c71
1 files changed, 44 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index e0ffd830804..31dac038e43 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -131,22 +131,30 @@ static void brush_defaults(Brush *brush)
/* Datablock add/copy/free/make_local */
-Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
+void BKE_brush_init(Brush *brush)
{
- Brush *brush;
-
- brush = BKE_libblock_alloc(bmain, ID_BR, name);
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id));
/* enable fake user by default */
- brush->id.flag |= LIB_FAKEUSER;
+ id_fake_user_set(&brush->id);
brush_defaults(brush);
brush->sculpt_tool = SCULPT_TOOL_DRAW; /* sculpting defaults to the draw tool for new brushes */
- brush->ob_mode = ob_mode;
/* the default alpha falloff curve */
BKE_brush_curve_preset(brush, CURVE_PRESET_SMOOTH);
+}
+
+Brush *BKE_brush_add(Main *bmain, const char *name, short ob_mode)
+{
+ Brush *brush;
+
+ brush = BKE_libblock_alloc(bmain, ID_BR, name);
+
+ BKE_brush_init(brush);
+
+ brush->ob_mode = ob_mode;
return brush;
}
@@ -185,11 +193,8 @@ Brush *BKE_brush_copy(Brush *brush)
brushn->curve = curvemapping_copy(brush->curve);
/* enable fake user by default */
- if (!(brushn->id.flag & LIB_FAKEUSER)) {
- brushn->id.flag |= LIB_FAKEUSER;
- brushn->id.us++;
- }
-
+ id_fake_user_set(&brush->id);
+
if (brush->id.lib) {
BKE_id_lib_local_paths(G.main, brush->id.lib, &brushn->id);
}
@@ -215,11 +220,27 @@ void BKE_brush_free(Brush *brush)
MEM_freeN(brush->gradient);
}
+/**
+ * \note Currently users don't remove brushes from the UI (as is done for scene, text... etc)
+ * This is only used by RNA, which can remove brushes.
+ */
+void BKE_brush_unlink(Main *bmain, Brush *brush)
+{
+ Brush *brush_iter;
+
+ for (brush_iter = bmain->brush.first; brush_iter; brush_iter = brush_iter->id.next) {
+ if (brush_iter->toggle_brush == brush) {
+ brush_iter->toggle_brush = NULL;
+ }
+ }
+}
+
static void extern_local_brush(Brush *brush)
{
id_lib_extern((ID *)brush->mtex.tex);
id_lib_extern((ID *)brush->mask_mtex.tex);
id_lib_extern((ID *)brush->clone.image);
+ id_lib_extern((ID *)brush->toggle_brush);
id_lib_extern((ID *)brush->paint_curve);
}
@@ -256,15 +277,11 @@ void BKE_brush_make_local(Brush *brush)
extern_local_brush(brush);
/* enable fake user by default */
- if (!(brush->id.flag & LIB_FAKEUSER)) {
- brush->id.flag |= LIB_FAKEUSER;
- brush->id.us++;
- }
+ id_fake_user_set(&brush->id);
}
else if (is_local && is_lib) {
- Brush *brush_new = BKE_brush_copy(brush);
- brush_new->id.us = 1; /* only keep fake user */
- brush_new->id.flag |= LIB_FAKEUSER;
+ Brush *brush_new = BKE_brush_copy(brush); /* Ensures FAKE_USER is set */
+ id_us_min(&brush_new->id); /* Remove user added by standard BKE_libblock_copy(). */
/* Remap paths of new ID using old library as base. */
BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id);
@@ -481,7 +498,7 @@ int BKE_brush_texture_set_nr(Brush *brush, int nr)
if (idtest == NULL) { /* new tex */
if (id) idtest = (ID *)BKE_texture_copy((Tex *)id);
else idtest = (ID *)BKE_texture_add(G.main, "Tex");
- idtest->us--;
+ id_us_min(idtest);
}
if (idtest != id) {
BKE_brush_texture_delete(brush);
@@ -498,7 +515,7 @@ int BKE_brush_texture_set_nr(Brush *brush, int nr)
int BKE_brush_texture_delete(Brush *brush)
{
if (brush->mtex.tex)
- brush->mtex.tex->id.us--;
+ id_us_min(&brush->mtex.tex->id);
return 1;
}
@@ -524,7 +541,7 @@ int BKE_brush_clone_image_set_nr(Brush *brush, int nr)
int BKE_brush_clone_image_delete(Brush *brush)
{
if (brush && brush->clone.image) {
- brush->clone.image->id.us--;
+ id_us_min(&brush->clone.image->id);
brush->clone.image = NULL;
return 1;
}
@@ -553,7 +570,7 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
/* Get strength by feeding the vertex
* location directly into a texture */
hasrgb = externtex(mtex, point, &intensity,
- rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false);
+ rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
}
else if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
float rotation = -mtex->rot;
@@ -584,7 +601,7 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
co[2] = 0.0f;
hasrgb = externtex(mtex, co, &intensity,
- rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false);
+ rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
}
else {
float rotation = -mtex->rot;
@@ -641,7 +658,7 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
co[2] = 0.0f;
hasrgb = externtex(mtex, co, &intensity,
- rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false);
+ rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
}
intensity += br->texture_sample_bias;
@@ -701,7 +718,7 @@ float BKE_brush_sample_masktex(const Scene *scene, Brush *br,
co[2] = 0.0f;
externtex(mtex, co, &intensity,
- rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false);
+ rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
}
else {
float rotation = -mtex->rot;
@@ -758,7 +775,7 @@ float BKE_brush_sample_masktex(const Scene *scene, Brush *br,
co[2] = 0.0f;
externtex(mtex, co, &intensity,
- rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false);
+ rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool, false, false);
}
CLAMP(intensity, 0.0f, 1.0f);
@@ -1031,7 +1048,7 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side, bool use_sec
/* This is copied from displace modifier code */
/* TODO(sergey): brush are always cacheing with CM enabled for now. */
externtex(mtex, co, &intensity,
- rgba, rgba + 1, rgba + 2, rgba + 3, 0, NULL, false);
+ rgba, rgba + 1, rgba + 2, rgba + 3, 0, NULL, false, false);
((char *)texcache)[(iy * side + ix) * 4] =
((char *)texcache)[(iy * side + ix) * 4 + 1] =