[Bf-blender-cvs] [117b284f8a3] greasepencil-object: GPencil: New Set Vertex Color operator
Antonio Vazquez
noreply at git.blender.org
Tue Nov 12 17:16:00 CET 2019
Commit: 117b284f8a3db64515ba6e248b6dbcadbd0fbf8e
Author: Antonio Vazquez
Date: Tue Nov 12 16:59:25 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB117b284f8a3db64515ba6e248b6dbcadbd0fbf8e
GPencil: New Set Vertex Color operator
===================================================================
M release/scripts/startup/bl_ui/space_view3d.py
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_ops.c
M source/blender/editors/gpencil/gpencil_vertex_ops.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 3a6d5523916..78194ec9744 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4732,6 +4732,8 @@ class VIEW3D_MT_vertex_gpencil(Menu):
def draw(self, _context):
layout = self.layout
+ layout.operator("gpencil.vertex_color_set", text="Set Vertex Colors")
+ layout.separator()
layout.operator("gpencil.vertex_color_invert", text="Invert")
layout.operator("gpencil.vertex_color_levels", text="Levels")
layout.operator("gpencil.vertex_color_hsv", text="Hue Saturation Value")
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 96cabab51ac..5842ae490d4 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -372,6 +372,7 @@ void GPENCIL_OT_vertex_color_brightness_contrast(struct wmOperatorType *ot);
void GPENCIL_OT_vertex_color_hsv(struct wmOperatorType *ot);
void GPENCIL_OT_vertex_color_invert(struct wmOperatorType *ot);
void GPENCIL_OT_vertex_color_levels(struct wmOperatorType *ot);
+void GPENCIL_OT_vertex_color_set(struct wmOperatorType *ot);
/* Guides ----------------------- */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index d242c4682f6..15cabf9778f 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -352,6 +352,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_vertex_color_hsv);
WM_operatortype_append(GPENCIL_OT_vertex_color_invert);
WM_operatortype_append(GPENCIL_OT_vertex_color_levels);
+ WM_operatortype_append(GPENCIL_OT_vertex_color_set);
/* Guides ----------------------- */
diff --git a/source/blender/editors/gpencil/gpencil_vertex_ops.c b/source/blender/editors/gpencil/gpencil_vertex_ops.c
index ffc0e69d408..4efeec51b8f 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_ops.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_ops.c
@@ -424,3 +424,71 @@ void GPENCIL_OT_vertex_color_levels(wmOperatorType *ot)
RNA_def_float(
ot->srna, "gain", 1.0f, 0.0f, FLT_MAX, "Gain", "Value to multiply colors by", 0.0f, 10.0f);
}
+
+static int gp_vertexpaint_set_exec(bContext *C, wmOperator *op)
+{
+ ToolSettings *ts = CTX_data_tool_settings(C);
+ Object *ob = CTX_data_active_object(C);
+ bGPdata *gpd = (bGPdata *)ob->data;
+ Paint *paint = &ts->gp_vertexpaint->paint;
+ Brush *brush = brush = paint->brush;
+
+ bool changed = false;
+ int i;
+ bGPDspoint *pt;
+
+ const int mode = RNA_enum_get(op->ptr, "mode");
+ float factor = RNA_float_get(op->ptr, "factor");
+
+ /* Loop all selected strokes. */
+ GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
+
+ /* Fill color. */
+ if (gps->flag & GP_STROKE_SELECT) {
+ changed = true;
+ if (mode != GP_PAINT_VERTEX_STROKE) {
+ copy_v3_v3(gps->mix_color_fill, brush->rgb);
+ gps->mix_color_fill[3] = factor;
+ }
+ }
+
+ /* Stroke points. */
+ if (mode != GP_PAINT_VERTEX_FILL) {
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ if (pt->flag & GP_SPOINT_SELECT) {
+ copy_v3_v3(pt->mix_color, brush->rgb);
+ pt->mix_color[3] = factor;
+ }
+ }
+ }
+ }
+ GP_EDITABLE_STROKES_END(gpstroke_iter);
+
+ /* notifiers */
+ if (changed) {
+ DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_vertex_color_set(wmOperatorType *ot)
+{
+
+ /* identifiers */
+ ot->name = "Vertex Paint Set Color";
+ ot->idname = "GPENCIL_OT_vertex_color_set";
+ ot->description = "Set active color to all selected vertex";
+
+ /* api callbacks */
+ ot->exec = gp_vertexpaint_set_exec;
+ ot->poll = gp_vertexpaint_mode_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* params */
+ ot->prop = RNA_def_enum(ot->srna, "mode", gpencil_modesEnumPropertyItem_mode, 0, "Mode", "");
+ RNA_def_float(ot->srna, "factor", 1.0f, 0.001f, 1.0f, "Factor", "Mix Factor", 0.001f, 1.0f);
+}
More information about the Bf-blender-cvs
mailing list