Cleanup: Use enums instead of numbers for Glare node

This commit is contained in:
Omar Emara
2024-03-05 11:51:52 +02:00
parent db4ef876c6
commit d6b1d00a0f
5 changed files with 21 additions and 19 deletions

View File

@@ -798,10 +798,10 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
/* Not in undo case. */
if (!BLO_write_is_undo(writer)) {
switch (ndg->type) {
case 2: /* Grrrr! magic numbers :( */
case CMP_NODE_GLARE_STREAKS:
ndg->angle = ndg->streaks;
break;
case 0:
case CMP_NODE_GLARE_SIMPLE_STAR:
ndg->angle = ndg->star_45;
break;
default:

View File

@@ -1464,10 +1464,10 @@ void blo_do_versions_270(FileData *fd, Library * /*lib*/, Main *bmain)
if (node->type == CMP_NODE_GLARE) {
NodeGlare *ndg = static_cast<NodeGlare *>(node->storage);
switch (ndg->type) {
case 2: /* Grrrr! magic numbers :( */
case CMP_NODE_GLARE_STREAKS:
ndg->streaks = ndg->angle;
break;
case 0:
case CMP_NODE_GLARE_SIMPLE_STAR:
ndg->star_45 = ndg->angle != 0;
break;
default:

View File

@@ -27,16 +27,16 @@ void GlareNode::convert_to_operations(NodeConverter &converter,
GlareBaseOperation *glareoperation = nullptr;
switch (glare->type) {
default:
case 3:
case CMP_NODE_GLARE_GHOST:
glareoperation = new GlareGhostOperation();
break;
case 2: /* Streaks. */
case CMP_NODE_GLARE_STREAKS:
glareoperation = new GlareStreaksOperation();
break;
case 1: /* Fog glow. */
case CMP_NODE_GLARE_FOG_GLOW:
glareoperation = new GlareFogGlowOperation();
break;
case 0: /* Simple star. */
case CMP_NODE_GLARE_SIMPLE_STAR:
glareoperation = new GlareSimpleStarOperation();
break;
}

View File

@@ -7333,10 +7333,10 @@ static void def_cmp_glare(StructRNA *srna)
PropertyRNA *prop;
static const EnumPropertyItem type_items[] = {
{3, "GHOSTS", 0, "Ghosts", ""},
{2, "STREAKS", 0, "Streaks", ""},
{1, "FOG_GLOW", 0, "Fog Glow", ""},
{0, "SIMPLE_STAR", 0, "Simple Star", ""},
{CMP_NODE_GLARE_GHOST, "GHOSTS", 0, "Ghosts", ""},
{CMP_NODE_GLARE_STREAKS, "STREAKS", 0, "Streaks", ""},
{CMP_NODE_GLARE_FOG_GLOW, "FOG_GLOW", 0, "Fog Glow", ""},
{CMP_NODE_GLARE_SIMPLE_STAR, "SIMPLE_STAR", 0, "Simple Star", ""},
{0, nullptr, 0, nullptr, nullptr},
};

View File

@@ -53,7 +53,7 @@ static void node_composit_init_glare(bNodeTree * /*ntree*/, bNode *node)
{
NodeGlare *ndg = MEM_cnew<NodeGlare>(__func__);
ndg->quality = 1;
ndg->type = 2;
ndg->type = CMP_NODE_GLARE_STREAKS;
ndg->iter = 3;
ndg->colmod = 0.25;
ndg->mix = 0;
@@ -71,10 +71,10 @@ static void node_composit_buts_glare(uiLayout *layout, bContext * /*C*/, Pointer
uiItemR(layout, ptr, "glare_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
uiItemR(layout, ptr, "quality", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
if (RNA_enum_get(ptr, "glare_type") != 1) {
if (RNA_enum_get(ptr, "glare_type") != CMP_NODE_GLARE_FOG_GLOW) {
uiItemR(layout, ptr, "iterations", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
if (RNA_enum_get(ptr, "glare_type") != 0) {
if (RNA_enum_get(ptr, "glare_type") != CMP_NODE_GLARE_SIMPLE_STAR) {
uiItemR(layout,
ptr,
"color_modulation",
@@ -87,19 +87,21 @@ static void node_composit_buts_glare(uiLayout *layout, bContext * /*C*/, Pointer
uiItemR(layout, ptr, "mix", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "threshold", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
if (RNA_enum_get(ptr, "glare_type") == 2) {
if (RNA_enum_get(ptr, "glare_type") == CMP_NODE_GLARE_STREAKS) {
uiItemR(layout, ptr, "streaks", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
uiItemR(layout, ptr, "angle_offset", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
if (RNA_enum_get(ptr, "glare_type") == 0 || RNA_enum_get(ptr, "glare_type") == 2) {
if (RNA_enum_get(ptr, "glare_type") == CMP_NODE_GLARE_SIMPLE_STAR ||
RNA_enum_get(ptr, "glare_type") == CMP_NODE_GLARE_STREAKS)
{
uiItemR(
layout, ptr, "fade", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
if (RNA_enum_get(ptr, "glare_type") == 0) {
if (RNA_enum_get(ptr, "glare_type") == CMP_NODE_GLARE_SIMPLE_STAR) {
uiItemR(layout, ptr, "use_rotate_45", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
}
if (RNA_enum_get(ptr, "glare_type") == 1) {
if (RNA_enum_get(ptr, "glare_type") == CMP_NODE_GLARE_FOG_GLOW) {
uiItemR(layout, ptr, "size", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
}
}