diff --git a/scripts/startup/bl_ui/properties_material_gpencil.py b/scripts/startup/bl_ui/properties_material_gpencil.py index 64bfcb6836f..4c17caead80 100644 --- a/scripts/startup/bl_ui/properties_material_gpencil.py +++ b/scripts/startup/bl_ui/properties_material_gpencil.py @@ -15,33 +15,36 @@ from bl_ui.properties_grease_pencil_common import ( class GPENCIL_MT_material_context_menu(Menu): bl_label = "Material Specials" - def draw(self, _context): + def draw(self, context): layout = self.layout + if context.preferences.experimental.use_grease_pencil_version3: + layout.operator("grease_pencil.material_reveal", icon='RESTRICT_VIEW_OFF', text="Show All") + else: + layout.operator("gpencil.material_reveal", icon='RESTRICT_VIEW_OFF', text="Show All") + layout.operator("gpencil.material_hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True - layout.operator("gpencil.material_reveal", icon='RESTRICT_VIEW_OFF', text="Show All") - layout.operator("gpencil.material_hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True + layout.separator() - layout.separator() + layout.operator("gpencil.material_lock_all", icon='LOCKED', text="Lock All") + layout.operator("gpencil.material_unlock_all", icon='UNLOCKED', text="Unlock All") - layout.operator("gpencil.material_lock_all", icon='LOCKED', text="Lock All") - layout.operator("gpencil.material_unlock_all", icon='UNLOCKED', text="Unlock All") + layout.operator("gpencil.material_lock_unused", text="Lock Unselected") + layout.operator("gpencil.lock_layer", text="Lock Unused") - layout.operator("gpencil.material_lock_unused", text="Lock Unselected") - layout.operator("gpencil.lock_layer", text="Lock Unused") + layout.separator() - layout.separator() + layout.operator("gpencil.material_to_vertex_color", text="Convert Materials to Color Attribute") + layout.operator("gpencil.extract_palette_vertex", text="Extract Palette from Color Attribute") - layout.operator("gpencil.material_to_vertex_color", text="Convert Materials to Color Attribute") - layout.operator("gpencil.extract_palette_vertex", text="Extract Palette from Color Attribute") + layout.separator() - layout.separator() + layout.operator("gpencil.materials_copy_to_object", text="Copy Material to Selected").only_active = True + layout.operator("gpencil.materials_copy_to_object", text="Copy All Materials to Selected").only_active = False - layout.operator("gpencil.materials_copy_to_object", text="Copy Material to Selected").only_active = True - layout.operator("gpencil.materials_copy_to_object", text="Copy All Materials to Selected").only_active = False + layout.separator() - layout.separator() + layout.operator("gpencil.stroke_merge_material", text="Merge Similar") - layout.operator("gpencil.stroke_merge_material", text="Merge Similar") layout.operator("object.material_slot_remove_unused") diff --git a/source/blender/editors/grease_pencil/CMakeLists.txt b/source/blender/editors/grease_pencil/CMakeLists.txt index 0b21eafd02b..449004ae11d 100644 --- a/source/blender/editors/grease_pencil/CMakeLists.txt +++ b/source/blender/editors/grease_pencil/CMakeLists.txt @@ -26,6 +26,7 @@ set(SRC intern/grease_pencil_frames.cc intern/grease_pencil_geom.cc intern/grease_pencil_layers.cc + intern/grease_pencil_material.cc intern/grease_pencil_ops.cc intern/grease_pencil_select.cc intern/grease_pencil_utils.cc diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_material.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_material.cc new file mode 100644 index 00000000000..c08ee0d4443 --- /dev/null +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_material.cc @@ -0,0 +1,72 @@ +/* SPDX-FileCopyrightText: 2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup edgreasepencil + */ + +#include "DNA_material_types.h" + +#include "BKE_context.hh" +#include "BKE_grease_pencil.hh" +#include "BKE_material.h" + +#include "DEG_depsgraph.hh" + +#include "ED_grease_pencil.hh" + +#include "WM_api.hh" + +namespace blender::ed::greasepencil { + +/* -------------------------------------------------------------------- */ +/** \name Show All Materials Operator + * \{ */ + +static int grease_pencil_material_reveal_exec(bContext *C, wmOperator * /*op*/) +{ + Object *object = CTX_data_active_object(C); + GreasePencil &grease_pencil = *static_cast(object->data); + + bool changed = false; + for (const int i : IndexRange(object->totcol)) { + if (Material *ma = BKE_gpencil_material(object, i + 1)) { + MaterialGPencilStyle *gp_style = ma->gp_style; + gp_style->flag &= ~GP_MATERIAL_HIDE; + DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE); + changed = true; + } + } + + if (changed) { + DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY); + WM_event_add_notifier(C, NC_GEOM | ND_DATA | NA_EDITED, &grease_pencil); + } + + return OPERATOR_FINISHED; +} + +static void GREASE_PENCIL_OT_material_reveal(wmOperatorType *ot) +{ + /* Identifiers. */ + ot->name = "Show All Materials"; + ot->idname = "GREASE_PENCIL_OT_material_reveal"; + ot->description = "Unhide all hidden Grease Pencil materials"; + + /* Callbacks. */ + ot->exec = grease_pencil_material_reveal_exec; + ot->poll = active_grease_pencil_poll; + + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/** \} */ + +} // namespace blender::ed::greasepencil + +void ED_operatortypes_grease_pencil_material() +{ + using namespace blender::ed::greasepencil; + WM_operatortype_append(GREASE_PENCIL_OT_material_reveal); +} diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc index 2f69bd8b064..698d004c02e 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc @@ -15,4 +15,5 @@ void ED_operatortypes_grease_pencil() ED_operatortypes_grease_pencil_layers(); ED_operatortypes_grease_pencil_select(); ED_operatortypes_grease_pencil_edit(); + ED_operatortypes_grease_pencil_material(); } diff --git a/source/blender/editors/include/ED_grease_pencil.hh b/source/blender/editors/include/ED_grease_pencil.hh index 7430fc9662e..f00b4830549 100644 --- a/source/blender/editors/include/ED_grease_pencil.hh +++ b/source/blender/editors/include/ED_grease_pencil.hh @@ -39,6 +39,7 @@ void ED_operatortypes_grease_pencil_frames(); void ED_operatortypes_grease_pencil_layers(); void ED_operatortypes_grease_pencil_select(); void ED_operatortypes_grease_pencil_edit(); +void ED_operatortypes_grease_pencil_material(); void ED_keymap_grease_pencil(wmKeyConfig *keyconf); /** * Get the selection mode for Grease Pencil selection operators: point, stroke, segment. diff --git a/source/blender/makesrna/intern/rna_material.cc b/source/blender/makesrna/intern/rna_material.cc index 3cb57bd17ad..91525b77648 100644 --- a/source/blender/makesrna/intern/rna_material.cc +++ b/source/blender/makesrna/intern/rna_material.cc @@ -68,6 +68,7 @@ const EnumPropertyItem rna_enum_ramp_blend_items[] = { # include "BKE_colorband.h" # include "BKE_context.hh" # include "BKE_gpencil_legacy.h" +# include "BKE_grease_pencil.hh" # include "BKE_main.h" # include "BKE_material.h" # include "BKE_node.h" @@ -112,6 +113,10 @@ static void rna_MaterialGpencil_update(Main *bmain, Scene *scene, PointerRNA *pt bGPdata *gpd = (bGPdata *)ob->data; DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY); } + if (ob->type == OB_GREASE_PENCIL) { + GreasePencil &grease_pencil = *static_cast(ob->data); + DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY); + } } WM_main_add_notifier(NC_GPENCIL | ND_DATA, ma);