[Bf-blender-cvs] [38aba90e7bd] greasepencil-object: GPencil: New operator to Join Palettes

Antonio Vazquez noreply at git.blender.org
Sun Nov 17 13:33:11 CET 2019


Commit: 38aba90e7bd7e4575dccdd7c7d3bc365cc552a58
Author: Antonio Vazquez
Date:   Sun Nov 17 13:33:03 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB38aba90e7bd7e4575dccdd7c7d3bc365cc552a58

GPencil: New operator to Join Palettes

Still need to define final Menu options and location.

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/sculpt_paint/paint_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index f683df05c79..b69ec2e9f91 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2770,6 +2770,42 @@ class VIEW3D_MT_paint_vertex(Menu):
         layout.operator("paint.vertex_color_brightness_contrast", text="Bright/Contrast")
 
 
+class VIEW3D_MT_join_palette(Menu):
+    bl_label = "Join Palette"
+
+    @classmethod
+    def poll(cls, context):
+        if bpy.data.palettes > 1:
+            return True
+        
+        return False
+
+    def draw(self, context):
+        layout = self.layout
+        tool_settings = context.tool_settings
+        settings = None
+
+        if context.mode == 'PAINT_GPENCIL':
+            settings = tool_settings.gpencil_paint
+        elif context.mode == 'VERTEX_GPENCIL':
+            settings = tool_settings.gpencil_vertex_paint
+        elif context.sculpt_object:
+            settings = tool_settings.sculpt
+        elif context.vertex_paint_object:
+            settings = tool_settings.vertex_paint
+        elif context.weight_paint_object:
+            settings = tool_settings.weight_paint
+        elif context.image_paint_object:
+            if (tool_settings.image_paint and tool_settings.image_paint.detect_data()):
+                settings = tool_settings.image_paint
+
+        if settings:
+            pal_active = settings.palette
+            for pal in bpy.data.palettes:
+                if pal.name != pal_active.name and len(pal.colors) > 0:
+                    layout.operator("palette.join", text=pal.name).palette = pal.name
+
+
 class VIEW3D_MT_hook(Menu):
     bl_label = "Hooks"
 
@@ -4757,6 +4793,9 @@ class VIEW3D_MT_vertex_gpencil(Menu):
         layout.operator("gpencil.vertex_color_hsv", text="Hue Saturation Value")
         layout.operator("gpencil.vertex_color_brightness_contrast", text="Bright/Contrast")
 
+        layout.separator()
+        layout.menu("VIEW3D_MT_join_palette")
+
 
 class VIEW3D_MT_gpencil_animation(Menu):
     bl_label = "Animation"
@@ -6989,6 +7028,7 @@ classes = (
     VIEW3D_MT_make_links,
     VIEW3D_MT_brush_paint_modes,
     VIEW3D_MT_paint_vertex,
+    VIEW3D_MT_join_palette,
     VIEW3D_MT_hook,
     VIEW3D_MT_vertex_group,
     VIEW3D_MT_gpencil_vertex_group,
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 7626552dc26..4caaf00c90a 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -479,6 +479,79 @@ void PALETTE_OT_sort(wmOperatorType *ot)
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* Join Palette swatches. */
+static bool palette_join_poll(bContext *C)
+{
+  Paint *paint = BKE_paint_get_active_from_context(C);
+  Palette *palette = paint->palette;
+  if (palette) {
+    return true;
+  }
+
+  return false;
+}
+
+static int palette_join_exec(bContext *C, wmOperator *op)
+{
+  Main *bmain = CTX_data_main(C);
+  Paint *paint = BKE_paint_get_active_from_context(C);
+  Palette *palette = paint->palette;
+  Palette *palette_join = NULL;
+  bool done = false;
+
+  char name[MAX_ID_NAME - 2];
+  RNA_string_get(op->ptr, "palette", name);
+
+  if ((palette == NULL) || (name[0] == '\0')) {
+    return OPERATOR_CANCELLED;
+  }
+
+  palette_join = (Palette *)BKE_libblock_find_name(bmain, ID_PAL, name);
+  if (palette_join == NULL) {
+    return OPERATOR_CANCELLED;
+  }
+
+  const int totcol = BLI_listbase_count(&palette_join->colors);
+
+  if (totcol > 0) {
+    for (PaletteColor *color = palette_join->colors.first; color; color = color->next) {
+      PaletteColor *palcol = BKE_palette_color_add(palette);
+      if (palcol) {
+        copy_v3_v3(palcol->rgb, color->rgb);
+        done = true;
+      }
+    }
+  }
+
+  if (done) {
+    /* Delete old palette. */
+    BKE_palette_free(palette_join);
+
+    /* Notifier. */
+    WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, NULL);
+  }
+
+  return OPERATOR_FINISHED;
+}
+
+void PALETTE_OT_join(wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Join Palette Swatches";
+  ot->idname = "PALETTE_OT_join";
+  ot->description = "Join Palette Swatches";
+
+  /* api callbacks */
+  ot->exec = palette_join_exec;
+  ot->poll = palette_join_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+  /* properties */
+  RNA_def_string(ot->srna, "palette", NULL, MAX_ID_NAME - 2, "Palette", "Name of the Palette");
+}
+
 static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
 {
   Paint *paint = BKE_paint_get_active_from_context(C);
@@ -1154,6 +1227,7 @@ void ED_operatortypes_paint(void)
 
   WM_operatortype_append(PALETTE_OT_extract_from_image);
   WM_operatortype_append(PALETTE_OT_sort);
+  WM_operatortype_append(PALETTE_OT_join);
 
   /* paint curve */
   WM_operatortype_append(PAINTCURVE_OT_new);



More information about the Bf-blender-cvs mailing list