[Bf-blender-cvs] [87c7d4d2a30] greasepencil-object: New options to copy colors attenuated

Antonio Vazquez noreply at git.blender.org
Tue Aug 15 19:06:18 CEST 2017


Commit: 87c7d4d2a308830e792974f1f41e7b22a31ee398
Author: Antonio Vazquez
Date:   Tue Aug 15 19:06:08 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB87c7d4d2a308830e792974f1f41e7b22a31ee398

New options to copy colors attenuated

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

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

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 37f25b337e8..dd8ed4186d7 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -933,6 +933,14 @@ class GPENCIL_MT_brush_specials(Menu):
         layout.operator("gpencil.brush_presets_create", icon='HELP', text="Create a set of predefined brushes")
 
 
+class GPENCIL_MT_palettecolor_copy(Menu):
+    bl_label = "Layer"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator_enum("palette.palettecolor_copy", "type")
+
 class GPENCIL_MT_palettecolor_specials(Menu):
     bl_label = "Layer"
 
@@ -946,7 +954,9 @@ class GPENCIL_MT_palettecolor_specials(Menu):
 
         layout.operator("palette.palettecolor_lock_all", icon='LOCKED', text="Lock All")
         layout.operator("palette.palettecolor_unlock_all", icon='UNLOCKED', text="UnLock All")
-        layout.operator("palette.palettecolor_copy", icon='PASTEDOWN', text="Copy Color")
+
+        layout.separator()
+        layout.menu("GPENCIL_MT_palettecolor_copy", icon='PASTEDOWN', text="Copy")
 
         layout.separator()
 
@@ -1588,6 +1598,7 @@ classes = (
     GPENCIL_MT_layer_specials,
     GPENCIL_MT_brush_specials,
     GPENCIL_MT_palettecolor_specials,
+    GPENCIL_MT_palettecolor_copy,
     GPENCIL_UL_vgroups
 )
 
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index f1925818695..3e89b29e97f 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -29,6 +29,7 @@
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 #include "BLI_math_vector.h"
+#include "BLI_math_color.h"
 
 #include "DNA_customdata_types.h"
 #include "DNA_object_types.h"
@@ -725,19 +726,36 @@ static void PALETTE_OT_palettecolor_select(wmOperatorType *ot)
 }
 
 /* ***************** Copy Palette color ************************ */
-static int palettecolor_copy_exec(bContext *C, wmOperator *UNUSED(op))
+static int palettecolor_copy_exec(bContext *C, wmOperator *op)
 {
 	Palette *palette = BKE_palette_get_active_from_context(C);
 	PaletteColor *palcolor = BKE_palette_color_get_active(palette);
 	PaletteColor *newcolor;
+	float hsv_s[3], hsv_f[3];
+
+	/* attenuation factors 10%, 25%, 50%, 75% */
+	float factors[4] = { 0.9f, 0.75f, 0.5f, 0.25f };
+
+	int mode = RNA_enum_get(op->ptr, "type");
 
 	/* sanity checks */
 	if (ELEM(NULL, palette, palcolor))
 		return OPERATOR_CANCELLED;
-
+	
 	/* create a new color and duplicate data */
 	newcolor = BKE_palette_color_copy(palette, palcolor);
 
+	/* attenuate color */
+	if (mode > 0) {
+		rgb_to_hsv_v(newcolor->rgb, hsv_s);
+		rgb_to_hsv_v(newcolor->fill, hsv_f);
+		hsv_s[2] *= factors[mode - 1];
+		hsv_f[2] *= factors[mode - 1];
+		
+		hsv_to_rgb_v(hsv_s, newcolor->rgb);
+		hsv_to_rgb_v(hsv_f, newcolor->fill);
+	}
+
 	/* notifiers */
 	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 
@@ -746,6 +764,15 @@ static int palettecolor_copy_exec(bContext *C, wmOperator *UNUSED(op))
 
 static void PALETTE_OT_palettecolor_copy(wmOperatorType *ot)
 {
+	static EnumPropertyItem prop_palettecolor_copy_types[] = {
+		{ 0, "COPY", ICON_PASTEDOWN, "Copy Color", "Copy current palette color" },
+		{ 1, "COPY10", ICON_PASTEDOWN, "Copy Color 10%", "Copy an attenuate version of the selected color" },
+		{ 2, "COPY25", ICON_PASTEDOWN, "Copy Color 25%", "Copy an attenuate version of the selected color" },
+		{ 3, "COPY50", ICON_PASTEDOWN, "Copy Color 50%", "Copy an attenuate version of the selected color" },
+		{ 4, "COPY75", ICON_PASTEDOWN, "Copy Color 75%", "Copy an attenuate version of the selected color" },
+		{ 0, NULL, 0, NULL, NULL }
+	};
+
 	/* identifiers */
 	ot->name = "Copy Color";
 	ot->idname = "PALETTE_OT_palettecolor_copy";
@@ -757,6 +784,9 @@ static void PALETTE_OT_palettecolor_copy(wmOperatorType *ot)
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* props */
+	ot->prop = RNA_def_enum(ot->srna, "type", prop_palettecolor_copy_types, 0, "Type", "Method used for copying colors");
 }




More information about the Bf-blender-cvs mailing list