[Bf-blender-cvs] [98174d2fa46] greasepencil-object: New color selection in draw specials menu

Antonio Vazquez noreply at git.blender.org
Tue Jan 2 13:35:25 CET 2018


Commit: 98174d2fa468a5cac895765d7ee41548e83b35c6
Author: Antonio Vazquez
Date:   Tue Jan 2 12:17:30 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB98174d2fa468a5cac895765d7ee41548e83b35c6

New color selection in draw specials menu

A quick color selection in draw special menu. In the future it would be good to add a small icon with the color, but now is not working in the menu

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

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 12ec81e5657..175a4259486 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -1006,6 +1006,15 @@ class GPENCIL_MT_gpencil_draw_specials(Menu):
         layout.operator("gpencil.primitive", text="Rectangle", icon='UV_FACESEL').type = 'BOX'
         layout.operator("gpencil.primitive", text="Circle", icon='ANTIALIASED').type = 'CIRCLE'
 
+        # colors
+        layout.separator()
+        palette = context.active_gpencil_palette
+        i = 0
+        for palcolor in palette.colors:
+            layout.operator("palette.palettecolor_choose", text=palcolor.name).index=i
+            i += 1
+
+
 
 class GPENCIL_MT_gpencil_vertex_group(Menu):
     bl_label = "GP Vertex Groups"
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 6f89ac133ef..d29257c5381 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -745,6 +745,47 @@ static void PALETTE_OT_palettecolor_select(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* ***************** Choose Palette color by index ************************ */
+static int palettecolor_choose_exec(bContext *C, wmOperator *op)
+{
+	const int index = RNA_int_get(op->ptr, "index");
+
+	Palette *palette = BKE_palette_get_active_from_context(C);
+
+	/* sanity checks */
+	if (ELEM(NULL, palette))
+		return OPERATOR_CANCELLED;
+
+	int totcolors = BLI_listbase_count(&palette->colors);
+	if ((index >= 0) && (index < totcolors)) {
+		palette->active_color = index;
+	}
+
+	/* notifiers */
+	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+
+	return OPERATOR_FINISHED;
+}
+
+static void PALETTE_OT_palettecolor_choose(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Choose Color";
+	ot->idname = "PALETTE_OT_palettecolor_choose";
+	ot->description = "Active a palette color";
+
+	/* callbacks */
+	ot->exec = palettecolor_choose_exec;
+	ot->poll = palette_active_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	/* properties */
+	RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Index of Color", 0, INT_MAX);
+}
+
+
 /* ***************** Duplicate Palette color ************************ */
 
 static int palettecolor_duplicate_exec(bContext *C, wmOperator *op)
@@ -1565,6 +1606,7 @@ void ED_operatortypes_paint(void)
 	WM_operatortype_append(PALETTE_OT_palettecolor_move);
 	WM_operatortype_append(PALETTE_OT_palettecolor_select);
 	WM_operatortype_append(PALETTE_OT_palettecolor_duplicate);
+	WM_operatortype_append(PALETTE_OT_palettecolor_choose);
 
 	/* paint curve */
 	WM_operatortype_append(PAINTCURVE_OT_new);



More information about the Bf-blender-cvs mailing list