GPv3: Layer group color tags

Reused the collection color theme option for the layer group.
Introduced new operator change the icon color it can be accessed from
layer group context menu.

Part of #121390.

Pull Request: https://projects.blender.org/blender/blender/pulls/122873
This commit is contained in:
Pratik Borhade
2024-06-11 18:25:01 +02:00
committed by Falk David
parent 165a929196
commit cea18e62c5
7 changed files with 126 additions and 1 deletions

View File

@@ -207,6 +207,10 @@ class GREASE_PENCIL_MT_group_context_menu(Menu):
layout.operator("grease_pencil.layer_group_remove", text="Delete Group").keep_children = False
layout.operator("grease_pencil.layer_group_remove", text="Ungroup").keep_children = True
layout.separator()
row = layout.row(align=True)
row.operator_enum("grease_pencil.layer_group_color_tag", "color_tag", icon_only=True)
class DATA_PT_grease_pencil_layers(DataButtonsPanel, Panel):
bl_label = "Layers"

View File

@@ -1362,6 +1362,7 @@ LayerGroup::LayerGroup()
new (&this->base) TreeNode(GP_LAYER_TREE_GROUP);
BLI_listbase_clear(&this->children);
this->color_tag = LAYERGROUP_COLOR_NONE;
this->runtime = MEM_new<LayerGroupRuntime>(__func__);
}

View File

@@ -18,6 +18,7 @@
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "UI_interface.hh"
#include "DNA_scene_types.h"
@@ -741,6 +742,47 @@ static void GREASE_PENCIL_OT_layer_mask_reorder(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "direction", enum_direction, 0, "Direction", "");
}
const EnumPropertyItem enum_layergroup_color_items[] = {
{LAYERGROUP_COLOR_NONE, "NONE", ICON_X, "Set Default icon", ""},
{LAYERGROUP_COLOR_01, "COLOR1", ICON_LAYERGROUP_COLOR_01, "Color tag 1", ""},
{LAYERGROUP_COLOR_02, "COLOR2", ICON_LAYERGROUP_COLOR_02, "Color tag 2", ""},
{LAYERGROUP_COLOR_03, "COLOR3", ICON_LAYERGROUP_COLOR_03, "Color tag 3", ""},
{LAYERGROUP_COLOR_04, "COLOR4", ICON_LAYERGROUP_COLOR_04, "Color tag 4", ""},
{LAYERGROUP_COLOR_05, "COLOR5", ICON_LAYERGROUP_COLOR_05, "Color tag 5", ""},
{LAYERGROUP_COLOR_06, "COLOR6", ICON_LAYERGROUP_COLOR_06, "Color tag 6", ""},
{LAYERGROUP_COLOR_07, "COLOR7", ICON_LAYERGROUP_COLOR_07, "Color tag 7", ""},
{LAYERGROUP_COLOR_08, "COLOR8", ICON_LAYERGROUP_COLOR_08, "Color tag 8", ""},
{0, NULL, 0, NULL, NULL},
};
static int grease_pencil_layer_group_color_tag_exec(bContext *C, wmOperator *op)
{
using namespace ::blender::bke::greasepencil;
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
const int color_tag = RNA_enum_get(op->ptr, "color_tag");
LayerGroup *active_group = grease_pencil.get_active_group();
active_group->color_tag = color_tag;
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_SELECTED, &grease_pencil);
return OPERATOR_FINISHED;
}
static void GREASE_PENCIL_OT_layer_group_color_tag(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Grease Pencil group color tag";
ot->idname = "GREASE_PENCIL_OT_layer_group_color_tag";
ot->description = "Change layer group icon";
ot->exec = grease_pencil_layer_group_color_tag_exec;
ot->poll = active_grease_pencil_poll;
ot->prop = RNA_def_enum(ot->srna, "color_tag", enum_layergroup_color_items, 0, "color tag", "");
}
} // namespace blender::ed::greasepencil
void ED_operatortypes_grease_pencil_layers()
@@ -762,4 +804,5 @@ void ED_operatortypes_grease_pencil_layers()
WM_operatortype_append(GREASE_PENCIL_OT_layer_mask_add);
WM_operatortype_append(GREASE_PENCIL_OT_layer_mask_remove);
WM_operatortype_append(GREASE_PENCIL_OT_layer_mask_reorder);
WM_operatortype_append(GREASE_PENCIL_OT_layer_group_color_tag);
}

View File

@@ -1000,6 +1000,15 @@ DEF_ICON_VECTOR(SEQUENCE_COLOR_09)
DEF_ICON_VECTOR(LIBRARY_DATA_INDIRECT)
DEF_ICON_VECTOR(LIBRARY_DATA_OVERRIDE_NONEDITABLE)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_01)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_02)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_03)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_04)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_05)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_06)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_07)
DEF_ICON_VECTOR(LAYERGROUP_COLOR_08)
/* Events. */
DEF_ICON_COLOR(EVENT_A)
DEF_ICON_COLOR(EVENT_B)

View File

@@ -32,6 +32,7 @@
#include "DNA_curve_types.h"
#include "DNA_dynamicpaint_types.h"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_grease_pencil_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_sequence_types.h"
@@ -521,6 +522,41 @@ static void vicon_strip_color_draw_library_data_override_noneditable(
UI_NO_ICON_OVERLAY_TEXT);
}
static void vicon_layergroup_color_draw(
short color_tag, int x, int y, int w, int /*h*/, float /*alpha*/)
{
bTheme *btheme = UI_GetTheme();
const ThemeCollectionColor *layergroup_color = &btheme->collection_color[color_tag];
const float aspect = float(ICON_DEFAULT_WIDTH) / float(w);
UI_icon_draw_ex(x,
y,
ICON_FILE_FOLDER,
aspect,
1.0f,
0.0f,
layergroup_color->color,
true,
UI_NO_ICON_OVERLAY_TEXT);
}
# define DEF_ICON_LAYERGROUP_COLOR_DRAW(index, color) \
static void vicon_layergroup_color_draw_##index(int x, int y, int w, int h, float alpha) \
{ \
vicon_layergroup_color_draw(color, x, y, w, h, alpha); \
}
DEF_ICON_LAYERGROUP_COLOR_DRAW(01, LAYERGROUP_COLOR_01);
DEF_ICON_LAYERGROUP_COLOR_DRAW(02, LAYERGROUP_COLOR_02);
DEF_ICON_LAYERGROUP_COLOR_DRAW(03, LAYERGROUP_COLOR_03);
DEF_ICON_LAYERGROUP_COLOR_DRAW(04, LAYERGROUP_COLOR_04);
DEF_ICON_LAYERGROUP_COLOR_DRAW(05, LAYERGROUP_COLOR_05);
DEF_ICON_LAYERGROUP_COLOR_DRAW(06, LAYERGROUP_COLOR_06);
DEF_ICON_LAYERGROUP_COLOR_DRAW(07, LAYERGROUP_COLOR_07);
DEF_ICON_LAYERGROUP_COLOR_DRAW(08, LAYERGROUP_COLOR_08);
# undef DEF_ICON_LAYERGROUP_COLOR_DRAW
/* Dynamically render icon instead of rendering a plain color to a texture/buffer
* This is not strictly a "vicon", as it needs access to icon->obj to get the color info,
* but it works in a very similar way.
@@ -1174,6 +1210,15 @@ static void init_internal_icons()
def_internal_vicon(ICON_LIBRARY_DATA_INDIRECT, vicon_strip_color_draw_library_data_indirect);
def_internal_vicon(ICON_LIBRARY_DATA_OVERRIDE_NONEDITABLE,
vicon_strip_color_draw_library_data_override_noneditable);
def_internal_vicon(ICON_LAYERGROUP_COLOR_01, vicon_layergroup_color_draw_01);
def_internal_vicon(ICON_LAYERGROUP_COLOR_02, vicon_layergroup_color_draw_02);
def_internal_vicon(ICON_LAYERGROUP_COLOR_03, vicon_layergroup_color_draw_03);
def_internal_vicon(ICON_LAYERGROUP_COLOR_04, vicon_layergroup_color_draw_04);
def_internal_vicon(ICON_LAYERGROUP_COLOR_05, vicon_layergroup_color_draw_05);
def_internal_vicon(ICON_LAYERGROUP_COLOR_06, vicon_layergroup_color_draw_06);
def_internal_vicon(ICON_LAYERGROUP_COLOR_07, vicon_layergroup_color_draw_07);
def_internal_vicon(ICON_LAYERGROUP_COLOR_08, vicon_layergroup_color_draw_08);
}
static void init_iconfile_list(ListBase *list)

View File

@@ -383,7 +383,13 @@ class LayerGroupViewItem : public AbstractTreeViewItem {
void build_layer_group_name(uiLayout &row)
{
uiItemS_ex(&row, 0.8f);
uiBut *but = uiItemL_ex(&row, group_.name().c_str(), ICON_FILE_FOLDER, false, false);
short icon = ICON_FILE_FOLDER;
if (group_.color_tag != LAYERGROUP_COLOR_NONE) {
icon = ICON_LAYERGROUP_COLOR_01 + group_.color_tag;
}
uiBut *but = uiItemL_ex(&row, group_.name().c_str(), icon, false, false);
if (!group_.is_editable()) {
UI_but_disable(but, "Layer Group is locked or not visible");
}

View File

@@ -325,12 +325,29 @@ typedef struct GreasePencilLayer {
#endif
} GreasePencilLayer;
typedef enum GroupColorTag {
LAYERGROUP_COLOR_NONE = -1,
LAYERGROUP_COLOR_01,
LAYERGROUP_COLOR_02,
LAYERGROUP_COLOR_03,
LAYERGROUP_COLOR_04,
LAYERGROUP_COLOR_05,
LAYERGROUP_COLOR_06,
LAYERGROUP_COLOR_07,
LAYERGROUP_COLOR_08,
};
typedef struct GreasePencilLayerTreeGroup {
GreasePencilLayerTreeNode base;
/**
* List of `GreasePencilLayerTreeNode`.
*/
ListBase children;
/**
* Icon color tag.
*/
int8_t color_tag;
char _pad[7];
/**
* Runtime struct pointer.
*/