diff options
author | YimingWu <xp8110@outlook.com> | 2021-05-14 17:40:47 +0300 |
---|---|---|
committer | YimingWu <xp8110@outlook.com> | 2021-05-14 17:40:47 +0300 |
commit | d19d79c5a644914564902c685f32e94e1b6449bb (patch) | |
tree | 526df581c637b8a070526d12c84e7e5f15c0a15a /source/blender/editors/object | |
parent | 16bcf7dc8e70890b8ad75c84f8699a4507477668 (diff) |
LineArt: Custom UI for adding GP object.
This allows extra options (in-front and stroke order) to be shown when adding line art kind of grease pencil object.
Reviewed by: Antonio Vazquez (antoniov)
Diff: https://developer.blender.org/D11130
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r-- | source/blender/editors/object/object_add.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index fbb68542645..4c28b24b8d9 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -1310,6 +1310,8 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op) bGPdata *gpd = (ob && (ob->type == OB_GPENCIL)) ? ob->data : NULL; const int type = RNA_enum_get(op->ptr, "type"); + const bool use_in_front = RNA_boolean_get(op->ptr, "use_in_front"); + const int stroke_depth_order = RNA_enum_get(op->ptr, "stroke_depth_order"); ushort local_view_bits; float loc[3], rot[3]; @@ -1421,7 +1423,16 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op) } /* Stroke object is drawn in front of meshes by default. */ - ob->dtx |= OB_DRAW_IN_FRONT; + if (use_in_front) { + ob->dtx |= OB_DRAW_IN_FRONT; + } + else { + if (stroke_depth_order == GP_DRAWMODE_3D) { + gpd->draw_mode = GP_DRAWMODE_3D; + } + } + + break; } case GP_EMPTY: /* do nothing */ @@ -1443,6 +1454,38 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static void object_add_ui(bContext *UNUSED(C), wmOperator *op) +{ + uiLayout *layout = op->layout; + + uiLayoutSetPropSep(layout, true); + + uiItemR(layout, op->ptr, "radius", 0, NULL, ICON_NONE); + uiItemR(layout, op->ptr, "align", 0, NULL, ICON_NONE); + uiItemR(layout, op->ptr, "location", 0, NULL, ICON_NONE); + uiItemR(layout, op->ptr, "rotation", 0, NULL, ICON_NONE); + uiItemR(layout, op->ptr, "type", 0, NULL, ICON_NONE); + + int type = RNA_enum_get(op->ptr, "type"); + if (type == GP_LRT_COLLECTION || type == GP_LRT_OBJECT || type == GP_LRT_SCENE) { + uiItemR(layout, op->ptr, "use_in_front", 0, NULL, ICON_NONE); + bool in_front = RNA_boolean_get(op->ptr, "use_in_front"); + uiLayout *row = uiLayoutRow(layout, false); + uiLayoutSetActive(row, !in_front); + uiItemR(row, op->ptr, "stroke_depth_order", 0, NULL, ICON_NONE); + } +} + +static EnumPropertyItem rna_enum_gpencil_add_stroke_depth_order_items[] = { + {GP_DRAWMODE_2D, + "2D", + 0, + "2D Layers", + "Display strokes using grease pencil layers to define order"}, + {GP_DRAWMODE_3D, "3D", 0, "3D Location", "Display strokes using real 3D position in 3D space"}, + {0, NULL, 0, NULL, NULL}, +}; + void OBJECT_OT_gpencil_add(wmOperatorType *ot) { /* identifiers */ @@ -1458,11 +1501,26 @@ void OBJECT_OT_gpencil_add(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + /* ui */ + ot->ui = object_add_ui; + /* properties */ ED_object_add_unit_props_radius(ot); ED_object_add_generic_props(ot, false); ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_object_gpencil_type_items, 0, "Type", ""); + RNA_def_boolean(ot->srna, + "use_in_front", + false, + "In Front", + "Show line art grease pencil in front of everything"); + RNA_def_enum( + ot->srna, + "stroke_depth_order", + rna_enum_gpencil_add_stroke_depth_order_items, + GP_DRAWMODE_3D, + "Stroke Depth Order", + "Defines how the strokes are ordered in 3D space for objects not displayed 'In Front'"); } /** \} */ |