[Bf-blender-cvs] [18701c19fa9] master: GPencil: Add link and copy functions for shaderfx

Nathan Craddock noreply at git.blender.org
Tue Sep 15 23:35:59 CEST 2020


Commit: 18701c19fa91572cb44643de31853335a6737925
Author: Nathan Craddock
Date:   Tue Sep 15 14:50:21 2020 -0600
Branches: master
https://developer.blender.org/rB18701c19fa91572cb44643de31853335a6737925

GPencil: Add link and copy functions for shaderfx

Adds two functions: one to copy a shaderfx between two gpencil objects,
and another to link all shaderfx between two gpencil objects. Added in
preparation for outliner shaderfx drag and drop.

Differential Revision: https://developer.blender.org/D8642

===================================================================

M	source/blender/blenkernel/BKE_shader_fx.h
M	source/blender/blenkernel/intern/shader_fx.c
M	source/blender/editors/include/ED_object.h
M	source/blender/editors/object/object_shader_fx.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_shader_fx.h b/source/blender/blenkernel/BKE_shader_fx.h
index 805b974b673..be57521a17c 100644
--- a/source/blender/blenkernel/BKE_shader_fx.h
+++ b/source/blender/blenkernel/BKE_shader_fx.h
@@ -181,6 +181,7 @@ void BKE_shaderfx_copydata(struct ShaderFxData *fx, struct ShaderFxData *target)
 void BKE_shaderfx_copydata_ex(struct ShaderFxData *fx,
                               struct ShaderFxData *target,
                               const int flag);
+void BKE_shaderfx_copy(struct ListBase *dst, const struct ListBase *src);
 void BKE_shaderfx_foreach_ID_link(struct Object *ob, ShaderFxIDWalkFunc walk, void *userData);
 
 bool BKE_shaderfx_has_gpencil(struct Object *ob);
diff --git a/source/blender/blenkernel/intern/shader_fx.c b/source/blender/blenkernel/intern/shader_fx.c
index b3d350f5ccd..4ad67a1dd32 100644
--- a/source/blender/blenkernel/intern/shader_fx.c
+++ b/source/blender/blenkernel/intern/shader_fx.c
@@ -234,6 +234,19 @@ void BKE_shaderfx_copydata(ShaderFxData *fx, ShaderFxData *target)
   BKE_shaderfx_copydata_ex(fx, target, 0);
 }
 
+void BKE_shaderfx_copy(ListBase *dst, const ListBase *src)
+{
+  ShaderFxData *fx;
+  ShaderFxData *srcfx;
+
+  BLI_listbase_clear(dst);
+  BLI_duplicatelist(dst, src);
+
+  for (srcfx = src->first, fx = dst->first; srcfx && fx; srcfx = srcfx->next, fx = fx->next) {
+    BKE_shaderfx_copydata(srcfx, fx);
+  }
+}
+
 ShaderFxData *BKE_shaderfx_findby_type(Object *ob, ShaderFxType type)
 {
   ShaderFxData *fx = ob->shader_fx.first;
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h
index b0ef22575ee..8762ac6d0bb 100644
--- a/source/blender/editors/include/ED_object.h
+++ b/source/blender/editors/include/ED_object.h
@@ -477,6 +477,8 @@ bool ED_object_shaderfx_move_to_index(struct ReportList *reports,
                                       struct Object *ob,
                                       struct ShaderFxData *fx,
                                       const int index);
+void ED_object_shaderfx_link(struct Object *dst, struct Object *src);
+void ED_object_shaderfx_copy(struct Object *dst, struct ShaderFxData *fx);
 
 /* object_select.c */
 void ED_object_select_linked_by_id(struct bContext *C, struct ID *id);
diff --git a/source/blender/editors/object/object_shader_fx.c b/source/blender/editors/object/object_shader_fx.c
index e2a30c4ce98..2dbde095e39 100644
--- a/source/blender/editors/object/object_shader_fx.c
+++ b/source/blender/editors/object/object_shader_fx.c
@@ -34,6 +34,7 @@
 #include "DNA_shader_fx_types.h"
 
 #include "BLI_listbase.h"
+#include "BLI_string.h"
 #include "BLI_string_utf8.h"
 #include "BLI_utildefines.h"
 
@@ -237,6 +238,26 @@ bool ED_object_shaderfx_move_to_index(ReportList *reports,
   return true;
 }
 
+void ED_object_shaderfx_link(Object *dst, Object *src)
+{
+  BLI_freelistN(&dst->shader_fx);
+  BKE_shaderfx_copy(&dst->shader_fx, &src->shader_fx);
+
+  DEG_id_tag_update(&dst->id, ID_RECALC_GEOMETRY);
+  WM_main_add_notifier(NC_OBJECT | ND_SHADERFX, dst);
+}
+
+void ED_object_shaderfx_copy(Object *dst, ShaderFxData *fx)
+{
+  ShaderFxData *nfx = BKE_shaderfx_new(fx->type);
+  BLI_strncpy(nfx->name, fx->name, sizeof(nfx->name));
+  BKE_shaderfx_copydata(fx, nfx);
+  BLI_addtail(&dst->shader_fx, nfx);
+
+  DEG_id_tag_update(&dst->id, ID_RECALC_GEOMETRY);
+  WM_main_add_notifier(NC_OBJECT | ND_SHADERFX, dst);
+}
+
 /************************ add effect operator *********************/
 
 static int shaderfx_add_exec(bContext *C, wmOperator *op)



More information about the Bf-blender-cvs mailing list