Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Mendiola <matias.mendiola@gmail.com>2019-09-05 14:28:42 +0300
committerAntonio Vazquez <blendergit@gmail.com>2019-09-05 14:29:13 +0300
commitd0462dca907177c04e81c098f07f577f7a036918 (patch)
tree606e02fb87187243aa59d738081ca08fef3cb39a /source/blender/editors/gpencil/gpencil_data.c
parent3a0b22b2daea4d255063cbb8f6269b8a764618d4 (diff)
GPencil: New Operator to set the active object material based on the selected stroke material
The operator set as active object material the material used in the selected stroke. Access to the operator were added in the stroke menu and context stroke menu. Reviewers: antoniov, pepeland Tags: #bf_blender, #grease_pencil Differential Revision: https://developer.blender.org/D5692
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_data.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index e763eec1b0d..4565625aefd 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -2920,6 +2920,54 @@ void GPENCIL_OT_color_select(wmOperatorType *ot)
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
+/* ***************** Set selected stroke material the active material ************************ */
+
+static int gpencil_set_active_material_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = CTX_data_active_object(C);
+ bGPdata *gpd = ED_gpencil_data_get_active(C);
+ bool changed = false;
+
+ /* Sanity checks. */
+ if (gpd == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
+ return OPERATOR_CANCELLED;
+ }
+
+ /* Loop all selected strokes. */
+ GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
+ if (gps->flag & GP_STROKE_SELECT) {
+ /* Change Active material. */
+ ob->actcol = gps->mat_nr + 1;
+ changed = true;
+ break;
+ }
+ }
+ GP_EDITABLE_STROKES_END(gpstroke_iter);
+
+ /* notifiers */
+ if (changed) {
+ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_set_active_material(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Set active material";
+ ot->idname = "GPENCIL_OT_set_active_material";
+ ot->description = "Set the selected stroke material as the active material";
+
+ /* callbacks */
+ ot->exec = gpencil_set_active_material_exec;
+ ot->poll = gpencil_active_color_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
/* Parent GPencil object to Lattice */
bool ED_gpencil_add_lattice_modifier(const bContext *C,
ReportList *reports,