diff options
author | Hans Goudey <h.goudey@me.com> | 2020-06-23 05:25:55 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-06-23 05:25:55 +0300 |
commit | 6703c7f7f1f68ae59f9ccbf4fcabc3c035d648bf (patch) | |
tree | bf5def93b54ba810bbaef693ecc79d81e97e635b /source/blender/editors | |
parent | 716a8241d387180fd8ad69cdec33633bc7a0f963 (diff) |
Bevel: Refactor profile type input to use an enum
This will allow the easier addition of a constant radius mode in the
future and some changes in the UI to mirror the recent similar change
from "Only Vertices" to the "Affect" enum.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/mesh/editmesh_bevel.c | 104 |
1 files changed, 65 insertions, 39 deletions
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c index 9f80e63eb60..d18f5de357f 100644 --- a/source/blender/editors/mesh/editmesh_bevel.c +++ b/source/blender/editors/mesh/editmesh_bevel.c @@ -121,7 +121,7 @@ enum { BEV_MODAL_MARK_SHARP_TOGGLE, BEV_MODAL_OUTER_MITER_CHANGE, BEV_MODAL_INNER_MITER_CHANGE, - BEV_MODAL_CUSTOM_PROFILE_TOGGLE, + BEV_MODAL_PROFILE_TYPE_CHANGE, BEV_MODAL_VERTEX_MESH_CHANGE, }; @@ -146,7 +146,7 @@ static void edbm_bevel_update_status_text(bContext *C, wmOperator *op) int available_len = sizeof(buf); Scene *sce = CTX_data_scene(C); char offset_str[NUM_STR_REP_LEN]; - const char *mode_str, *omiter_str, *imiter_str, *vmesh_str; + const char *mode_str, *omiter_str, *imiter_str, *vmesh_str, *profile_type_str; PropertyRNA *prop; #define WM_MODALKEY(_id) \ @@ -170,6 +170,9 @@ static void edbm_bevel_update_status_text(bContext *C, wmOperator *op) prop = RNA_struct_find_property(op->ptr, "offset_type"); RNA_property_enum_name_gettexted( C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &mode_str); + prop = RNA_struct_find_property(op->ptr, "profile_type"); + RNA_property_enum_name_gettexted( + C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &profile_type_str); prop = RNA_struct_find_property(op->ptr, "miter_outer"); RNA_property_enum_name_gettexted( C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &omiter_str); @@ -195,7 +198,7 @@ static void edbm_bevel_update_status_text(bContext *C, wmOperator *op) "%s: Harden Normals (%s), " "%s: Mark Seam (%s), " "%s: Mark Sharp (%s), " - "%s: Custom Profile (%s), " + "%s: Profile Type (%s), " "%s: Intersection (%s)"), WM_MODALKEY(BEV_MODAL_CONFIRM), WM_MODALKEY(BEV_MODAL_CANCEL), @@ -221,8 +224,8 @@ static void edbm_bevel_update_status_text(bContext *C, wmOperator *op) WM_bool_as_string(RNA_boolean_get(op->ptr, "mark_seam")), WM_MODALKEY(BEV_MODAL_MARK_SHARP_TOGGLE), WM_bool_as_string(RNA_boolean_get(op->ptr, "mark_sharp")), - WM_MODALKEY(BEV_MODAL_CUSTOM_PROFILE_TOGGLE), - WM_bool_as_string(RNA_boolean_get(op->ptr, "use_custom_profile")), + WM_MODALKEY(BEV_MODAL_PROFILE_TYPE_CHANGE), + profile_type_str, WM_MODALKEY(BEV_MODAL_VERTEX_MESH_CHANGE), vmesh_str); @@ -327,6 +330,7 @@ static bool edbm_bevel_calc(wmOperator *op) const float offset = get_bevel_offset(op); const int offset_type = RNA_enum_get(op->ptr, "offset_type"); + const int profile_type = RNA_enum_get(op->ptr, "profile_type"); const int segments = RNA_int_get(op->ptr, "segments"); const float profile = RNA_float_get(op->ptr, "profile"); const bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only"); @@ -340,7 +344,6 @@ static bool edbm_bevel_calc(wmOperator *op) const int miter_outer = RNA_enum_get(op->ptr, "miter_outer"); const int miter_inner = RNA_enum_get(op->ptr, "miter_inner"); const float spread = RNA_float_get(op->ptr, "spread"); - const bool use_custom_profile = RNA_boolean_get(op->ptr, "use_custom_profile"); const int vmesh_method = RNA_enum_get(op->ptr, "vmesh_method"); for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) { @@ -364,16 +367,17 @@ static bool edbm_bevel_calc(wmOperator *op) EDBM_op_init(em, &bmop, op, - "bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i profile=%f " - "clamp_overlap=%b material=%i loop_slide=%b mark_seam=%b mark_sharp=%b " - "harden_normals=%b face_strength_mode=%i " - "miter_outer=%i miter_inner=%i spread=%f smoothresh=%f use_custom_profile=%b " - "custom_profile=%p vmesh_method=%i", + "bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i " + "profile_type=%i profile=%f clamp_overlap=%b material=%i loop_slide=%b " + "mark_seam=%b mark_sharp=%b harden_normals=%b face_strength_mode=%i " + "miter_outer=%i miter_inner=%i spread=%f smoothresh=%f custom_profile=%p " + "vmesh_method=%i", BM_ELEM_SELECT, offset, segments, vertex_only, offset_type, + profile_type, profile, clamp_overlap, material, @@ -386,7 +390,6 @@ static bool edbm_bevel_calc(wmOperator *op) miter_inner, spread, me->smoothresh, - use_custom_profile, opdata->custom_profile, vmesh_method); @@ -681,7 +684,7 @@ wmKeyMap *bevel_modal_keymap(wmKeyConfig *keyconf) 0, "Change inner miter", "Cycle through inner miter kinds"}, - {BEV_MODAL_CUSTOM_PROFILE_TOGGLE, "CUSTOM_PROFILE_TOGGLE", 0, "Toggle custom profile", ""}, + {BEV_MODAL_PROFILE_TYPE_CHANGE, "PROFILE_TYPE_CHANGE", 0, "Cycle through profile types", ""}, {BEV_MODAL_VERTEX_MESH_CHANGE, "VERTEX_MESH_CHANGE", 0, @@ -892,9 +895,13 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event) break; } - case BEV_MODAL_CUSTOM_PROFILE_TOGGLE: { - bool use_custom_profile = RNA_boolean_get(op->ptr, "use_custom_profile"); - RNA_boolean_set(op->ptr, "use_custom_profile", !use_custom_profile); + case BEV_MODAL_PROFILE_TYPE_CHANGE: { + int profile_type = RNA_enum_get(op->ptr, "profile_type"); + profile_type++; + if (profile_type > BEVEL_PROFILE_CUSTOM) { + profile_type = BEVEL_PROFILE_SUPERELLIPSE; + } + RNA_enum_set(op->ptr, "profile_type", profile_type); edbm_bevel_calc(op); edbm_bevel_update_status_text(C, op); handled = true; @@ -938,21 +945,12 @@ static void edbm_bevel_ui(bContext *C, wmOperator *op) RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); + int profile_type = RNA_enum_get(&ptr, "profile_type"); + if (RNA_enum_get(&ptr, "offset_type") == BEVEL_AMT_PERCENT) { uiItemR(layout, &ptr, "offset_pct", 0, NULL, ICON_NONE); } else { - switch (RNA_enum_get(&ptr, "offset_type")) { - case BEVEL_AMT_DEPTH: - offset_name = "Depth"; - break; - case BEVEL_AMT_WIDTH: - offset_name = "Width"; - break; - case BEVEL_AMT_OFFSET: - offset_name = "Offset"; - break; - } prop = RNA_struct_find_property(op->ptr, "offset_type"); RNA_property_enum_name_gettexted( C, op->ptr, prop, RNA_property_enum_get(op->ptr, prop), &offset_name); @@ -972,7 +970,14 @@ static void edbm_bevel_ui(bContext *C, wmOperator *op) uiItemR(col, &ptr, "harden_normals", 0, NULL, ICON_NONE); uiItemR(layout, &ptr, "segments", 0, NULL, ICON_NONE); - uiItemR(layout, &ptr, "profile", UI_ITEM_R_SLIDER, NULL, ICON_NONE); + if (ELEM(profile_type, BEVEL_PROFILE_SUPERELLIPSE, BEVEL_PROFILE_CUSTOM)) { + uiItemR(layout, + &ptr, + "profile", + UI_ITEM_R_SLIDER, + (profile_type == BEVEL_PROFILE_SUPERELLIPSE) ? IFACE_("Shape") : IFACE_("Miter Shape"), + ICON_NONE); + } uiItemR(layout, &ptr, "material", 0, NULL, ICON_NONE); uiItemL(layout, "Miter Type:", ICON_NONE); @@ -990,9 +995,11 @@ static void edbm_bevel_ui(bContext *C, wmOperator *op) row = uiLayoutRow(layout, true); uiItemR(row, &ptr, "vmesh_method", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - uiItemR(layout, &ptr, "use_custom_profile", 0, NULL, ICON_NONE); - if (RNA_boolean_get(&ptr, "use_custom_profile")) { - /* Get an RNA pointer to ToolSettings to give to the curve profile template code */ + uiItemL(layout, "Profile Type:", ICON_NONE); + row = uiLayoutRow(layout, true); + uiItemR(row, &ptr, "profile_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + if (profile_type == BEVEL_PROFILE_CUSTOM) { + /* Get an RNA pointer to ToolSettings to give to the curve profile template code. */ Scene *scene = CTX_data_scene(C); RNA_pointer_create(&scene->id, &RNA_ToolSettings, scene->toolsettings, &toolsettings_ptr); uiTemplateCurveProfile(layout, &toolsettings_ptr, "custom_bevel_profile_preset"); @@ -1020,6 +1027,20 @@ void MESH_OT_bevel(wmOperatorType *ot) {0, NULL, 0, NULL, NULL}, }; + static const EnumPropertyItem prop_profile_type_items[] = { + {BEVEL_PROFILE_SUPERELLIPSE, + "SUPERELLIPSE", + 0, + "Superellipse", + "The profile can be a concave or convex curve"}, + {BEVEL_PROFILE_CUSTOM, + "CUSTOM", + 0, + "Custom", + "The profile can be any arbitrary path between its endpoints"}, + {0, NULL, 0, NULL, NULL}, + }; + static const EnumPropertyItem face_strength_mode_items[] = { {BEVEL_FACE_STRENGTH_NONE, "NONE", 0, "None", "Do not set face strength"}, {BEVEL_FACE_STRENGTH_NEW, "NEW", 0, "New", "Set face strength on new faces only"}, @@ -1073,13 +1094,24 @@ void MESH_OT_bevel(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_GRAB_CURSOR_XY | OPTYPE_BLOCKING; /* properties */ - RNA_def_enum( - ot->srna, "offset_type", offset_type_items, 0, "Width Type", "What distance Width measures"); + RNA_def_enum(ot->srna, + "offset_type", + offset_type_items, + 0, + "Width Type", + "The method for determining the size of the bevel"); prop = RNA_def_property(ot->srna, "offset", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_range(prop, 0.0, 1e6); RNA_def_property_ui_range(prop, 0.0, 100.0, 1, 3); RNA_def_property_ui_text(prop, "Width", "Bevel amount"); + RNA_def_enum(ot->srna, + "profile_type", + prop_profile_type_items, + 0, + "Profile Type", + "The type of shape used to rebuild a beveled section"); + prop = RNA_def_property(ot->srna, "offset_pct", PROP_FLOAT, PROP_PERCENTAGE); RNA_def_property_range(prop, 0.0, 100); RNA_def_property_ui_text(prop, "Width Percent", "Bevel amount for percentage method"); @@ -1166,12 +1198,6 @@ void MESH_OT_bevel(wmOperatorType *ot) 0.0f, 100.0f); - RNA_def_boolean(ot->srna, - "use_custom_profile", - false, - "Custom Profile", - "Use a custom profile for the bevel"); - RNA_def_enum(ot->srna, "vmesh_method", vmesh_method_items, |