[Bf-blender-cvs] [e20cbe29f92] greasepencil-object: WIP: Convert old palette operators

Antonio Vazquez noreply at git.blender.org
Thu Apr 26 12:35:56 CEST 2018


Commit: e20cbe29f9232f3d8b9b4a82f9c98e715c99a517
Author: Antonio Vazquez
Date:   Thu Apr 26 10:31:28 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBe20cbe29f9232f3d8b9b4a82f9c98e715c99a517

WIP: Convert old palette operators

These operators are used to manage the strokes lock and hide.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_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 1e5656557d9..1c18bd8703b 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -608,6 +608,7 @@ class GPENCIL_MT_gpencil_edit_specials(Menu):
             layout.separator()
             layout.operator("gpencil.reproject")
 
+
 class GPENCIL_MT_gpencil_sculpt_specials(Menu):
     bl_label = "GPencil Specials"
 
@@ -783,41 +784,29 @@ 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_duplicate(Menu):
-    bl_label = "Duplicate"
-
-    def draw(self, context):
-        layout = self.layout
-
-        layout.operator_enum("palette.palettecolor_duplicate", "type")
-
-
-class GPENCIL_MT_palettecolor_specials(Menu):
+class GPENCIL_MT_color_specials(Menu):
     bl_label = "Layer"
 
     def draw(self, context):
         layout = self.layout
 
-        layout.operator("palette.palettecolor_reveal", icon='RESTRICT_VIEW_OFF', text="Show All")
-        layout.operator("palette.palettecolor_hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True
+        layout.operator("gpencil.color_reveal", icon='RESTRICT_VIEW_OFF', text="Show All")
+        layout.operator("gpencil.color_hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True
 
         layout.separator()
 
-        layout.operator("palette.palettecolor_lock_all", icon='LOCKED', text="Lock All")
-        layout.operator("palette.palettecolor_unlock_all", icon='UNLOCKED', text="UnLock All")
-
-        layout.separator()
-        layout.menu("GPENCIL_MT_palettecolor_duplicate", icon='PASTEDOWN', text="Duplicate")
+        layout.operator("gpencil.color_lock_all", icon='LOCKED', text="Lock All")
+        layout.operator("gpencil.color_unlock_all", icon='UNLOCKED', text="UnLock All")
 
         layout.separator()
 
-        layout.operator("palette.palettecolor_select", icon='COLOR', text="Select Strokes")
+        layout.operator("gpencil.color_select", icon='COLOR', text="Select Strokes")
         layout.operator("gpencil.stroke_change_color", icon='MAN_TRANS', text="Move to Color")
 
         layout.separator()
 
         layout.operator("gpencil.stroke_lock_color", icon='BORDER_RECT', text="Lock Unselected")
-        layout.operator("palette.lock_layer", icon='COLOR', text="Lock Unused")
+        layout.operator("gpencil.lock_layer", icon='COLOR', text="Lock Unused")
 
 
 class GreasePencilDataPanel:
@@ -1126,8 +1115,7 @@ classes = (
     GPENCIL_UL_layer,
     GPENCIL_MT_layer_specials,
     GPENCIL_MT_brush_specials,
-    GPENCIL_MT_palettecolor_specials,
-    GPENCIL_MT_palettecolor_duplicate,
+    GPENCIL_MT_color_specials,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index 67ab780bd55..55ba2246532 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -89,7 +89,7 @@ class MATERIAL_PT_gpencil_slots(Panel):
             col.operator("object.material_slot_add", icon='ZOOMIN', text="")
             col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
 
-            col.menu("GPENCIL_MT_palettecolor_specials", icon='DOWNARROW_HLT', text="")
+            col.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="")
 
             if is_sortable:
                 col.separator()
@@ -100,8 +100,8 @@ class MATERIAL_PT_gpencil_slots(Panel):
                 col.separator()
 
                 sub = col.column(align=True)
-                sub.operator("palette.palettecolor_isolate", icon='LOCKED', text="").affect_visibility = False
-                sub.operator("palette.palettecolor_isolate", icon='RESTRICT_VIEW_OFF', text="").affect_visibility = True
+                sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
+                sub.operator("gpencil.color_isolate", icon='RESTRICT_VIEW_OFF', text="").affect_visibility = True
 
         split = layout.split(percentage=0.65)
 
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 1c99ce59df5..b6958df6471 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -2079,10 +2079,7 @@ class VIEW3D_PT_tools_grease_pencil_brush(Panel):
                 row.prop(brush, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
 
                 row = layout.row(align=True)
-                row.template_ID(brush, "palette")
-                if brush.palette:
-                    row = layout.row(align=True)
-                    row.prop_search(brush, "colorname", brush.palette, "colors", text="Color", icon="LAYER_ACTIVE")
+                row.template_ID(brush, "material")
 
             if brush.gpencil_brush_type == 'FILL':
                 col = layout.column(align=True)
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index da41acd998e..d6596037913 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1171,7 +1171,7 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op))
 		return OPERATOR_CANCELLED;
 
 	/* first lock all colors */
-	for (int i = 0; i < totcol; i++) {
+	for (short i = 0; i < *totcol; i++) {
 		Material *tmp = (*matar)[i];
 		tmp->gpcolor->flag |= GPC_COLOR_LOCKED;
 
@@ -1966,3 +1966,443 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
 	return OPERATOR_FINISHED;
 }
 
+/* Color Handle operator */
+static int gpencil_active_color_poll(bContext *C)
+{
+	Object *ob = CTX_data_active_object(C);
+	short *totcolp;
+	if (ob) {
+		totcolp = give_totcolp(ob);
+	}
+	return ((ED_gpencil_data_get_active(C) != NULL) && (totcolp > 0));
+}
+
+
+/* ******************* Lock and hide any color non used in current layer ************************** */
+static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	Object *ob = CTX_data_active_object(C);
+	GpencilColorData *gpcolor = NULL;
+
+	/* sanity checks */
+	if (ELEM(NULL, gpd))
+		return OPERATOR_CANCELLED;
+
+	/* first lock and hide all colors */
+	Material *mat = NULL;
+	Material ***matar = give_matarar(ob);
+	short *totcol = give_totcolp(ob);
+	if ((totcol == 0) || (matar == NULL))
+		return OPERATOR_CANCELLED;
+
+	for (short i = 0; i < *totcol; i++) {
+		mat = (*matar)[i];
+		gpcolor = mat->gpcolor;
+		gpcolor->flag |= GPC_COLOR_LOCKED;
+		gpcolor->flag |= GPC_COLOR_HIDE;
+	}
+
+	/* loop all selected strokes and unlock any color used in active layer */
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		/* only editable and visible layers are considered */
+		if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL) && (gpl->flag & GP_LAYER_ACTIVE)) {
+			for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) {
+				/* skip strokes that are invalid for current view */
+				if (ED_gpencil_stroke_can_use(C, gps) == false)
+					continue;
+
+				gpcolor = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
+				/* unlock/unhide color if not unlocked before */
+				if (gpcolor != NULL) {
+					gpcolor->flag &= ~GPC_COLOR_LOCKED;
+					gpcolor->flag &= ~GPC_COLOR_HIDE;
+				}
+			}
+		}
+	}
+	/* notifiers */
+	BKE_gpencil_batch_cache_dirty(gpd);
+	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_lock_layer(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Disable Unused Layer Colors";
+	ot->idname = "GPENCIL_OT_lock_layer";
+	ot->description = "Lock and hide any color not used in any layer";
+
+	/* api callbacks */
+	ot->exec = gpencil_lock_layer_exec;
+	ot->poll = gp_active_layer_poll;
+}
+
+/* ********************** Isolate gpencil_ color **************************** */
+
+static int gpencil_color_isolate_exec(bContext *C, wmOperator *op)
+{
+	bGPdata *gpd = ED_gpencil_data_get_active(C);
+	Object *ob = CTX_data_active_object(C);
+	Material *active_mat = give_current_material(ob, ob->actcol + 1);
+	GpencilColorData *active_color = BKE_material_gpencil_settings_get(ob, ob->actcol + 1);
+	GpencilColorData *gpcolor;
+
+	int flags = GPC_COLOR_LOCKED;
+	bool isolate = false;
+
+	if (RNA_boolean_get(op->ptr, "affect_visibility"))
+		flags |= GPC_COLOR_HIDE;
+
+	if (ELEM(NULL, gpd, active_color)) {
+		BKE_report(op->reports, RPT_ERROR, "No active color to isolate");
+		return OPERATOR_CANCELLED;
+	}
+
+	/* Test whether to isolate or clear all flags */
+	Material *mat = NULL;
+	Material ***matar = give_matarar(ob);
+	short *totcol = give_totcolp(ob);
+	for (short i = 0; i < *totcol; i++) {
+		mat = (*matar)[i];
+		/* Skip if this is the active one */
+		if (mat == active_mat)
+			continue;
+
+		/* If the flags aren't set, that means that the color is
+		* not alone, so we have some colors to isolate still
+		*/
+		gpcolor = mat->gpcolor;
+		if ((gpcolor->flag & flags) == 0) {
+			isolate = true;
+			break;
+		}
+	}
+
+	/* Set/Clear flags as appropriate */
+	if (isolate) {
+		/* Set flags on all "other" colors */
+		for (short i = 0; i < *totcol; i++) {
+			mat = (*matar)[i];
+			gpcolor = mat->gpcolor;
+			if (gpcolor == active_color)
+				continue;
+			else
+				gpcolor->flag |= flags;
+		}
+	}
+	else {
+		/* Clear flags - Restore everything else */
+		for (short i = 0; i < *totcol; i++) {
+			mat = (*matar)[i];
+			gpcolor = mat->gpcolor;
+			gpcolor->flag &= ~flags;
+		}
+	}
+
+	/* notifiers */
+	DEG_id_tag_update(&gpd->id, OB_RECALC_DATA);
+	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+
+	return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_color_isolate(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Isolate C

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list