diff options
author | Hans Goudey <h.goudey@me.com> | 2020-06-24 18:50:01 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-06-24 18:50:01 +0300 |
commit | baff05ad1c156ca477375c440e2c5b92cad214e9 (patch) | |
tree | b89d9d5a9e9611247d964d5e9b0ccd098bf88c2d /source/blender/editors/interface/interface_templates.c | |
parent | ec7510b458528eb8dcdf2c538a2b805813940447 (diff) |
UI: Add Free Handle Types to CurveProfile Widget
Under the hood the CurveProfile widget (used for bevel custom profiles)
uses a bezier curve, but right now though it only supports two of the
bezier curve handle types, vector and auto. This patch adds support for
free handles and adds all of the logic for editing them.
This is the first step to the ability to import and export curve objects
in the widget.
There's some code cleanup in curveprofile.c. Movement for handles and
control points is abstracted to functions there rather than happening
in interface_handlers.c.
An "Apply Preset" button is also added, which solves a confusing issue
where you apply a preset, then change the number of samples and the
preset doesn't change. The button makes it clear that the preset needs
to be reapplied.
Reviewed By: Severin
Differential Revision: https://developer.blender.org/D6470
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 132 |
1 files changed, 65 insertions, 67 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 16b6b313f69..0d6717c8e12 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -4463,7 +4463,7 @@ static void CurveProfile_presets_dofunc(bContext *C, void *profile_v, int event) profile->preset = event; BKE_curveprofile_reset(profile); - BKE_curveprofile_update(profile, false); + BKE_curveprofile_update(profile, PROF_UPDATE_NONE); ED_undo_push(C, "CurveProfile tools"); ED_region_tag_redraw(CTX_wm_region(C)); @@ -4579,7 +4579,7 @@ static void CurveProfile_tools_dofunc(bContext *C, void *profile_v, int event) switch (event) { case UIPROFILE_FUNC_RESET: /* reset */ BKE_curveprofile_reset(profile); - BKE_curveprofile_update(profile, false); + BKE_curveprofile_update(profile, PROF_UPDATE_NONE); break; case UIPROFILE_FUNC_RESET_VIEW: /* reset view to clipping rect */ profile->view_rect = profile->clip_rect; @@ -4645,7 +4645,7 @@ static void CurveProfile_buttons_zoom_in(bContext *C, void *profile_v, void *UNU CurveProfile *profile = profile_v; float d; - /* we allow 20 times zoom */ + /* Allow a 20x zoom. */ if (BLI_rctf_size_x(&profile->view_rect) > 0.04f * BLI_rctf_size_x(&profile->clip_rect)) { d = 0.1154f * BLI_rctf_size_x(&profile->view_rect); profile->view_rect.xmin += d; @@ -4709,7 +4709,7 @@ static void CurveProfile_clipping_toggle(bContext *C, void *cb_v, void *profile_ profile->flag ^= PROF_USE_CLIP; - BKE_curveprofile_update(profile, false); + BKE_curveprofile_update(profile, PROF_UPDATE_NONE); rna_update_cb(C, cb_v, NULL); } @@ -4718,7 +4718,7 @@ static void CurveProfile_buttons_reverse(bContext *C, void *cb_v, void *profile_ CurveProfile *profile = profile_v; BKE_curveprofile_reverse(profile); - BKE_curveprofile_update(profile, false); + BKE_curveprofile_update(profile, PROF_UPDATE_NONE); rna_update_cb(C, cb_v, NULL); } @@ -4727,35 +4727,23 @@ static void CurveProfile_buttons_delete(bContext *C, void *cb_v, void *profile_v CurveProfile *profile = profile_v; BKE_curveprofile_remove_by_flag(profile, SELECT); - BKE_curveprofile_update(profile, false); - - rna_update_cb(C, cb_v, NULL); -} - -static void CurveProfile_buttons_setsharp(bContext *C, void *cb_v, void *profile_v) -{ - CurveProfile *profile = profile_v; - - BKE_curveprofile_selected_handle_set(profile, HD_VECT, HD_VECT); - BKE_curveprofile_update(profile, false); + BKE_curveprofile_update(profile, PROF_UPDATE_NONE); rna_update_cb(C, cb_v, NULL); } -static void CurveProfile_buttons_setcurved(bContext *C, void *cb_v, void *profile_v) +static void CurveProfile_buttons_update(bContext *C, void *arg1_v, void *profile_v) { CurveProfile *profile = profile_v; - - BKE_curveprofile_selected_handle_set(profile, HD_AUTO, HD_AUTO); - BKE_curveprofile_update(profile, false); - - rna_update_cb(C, cb_v, NULL); + BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); + rna_update_cb(C, arg1_v, NULL); } -static void CurveProfile_buttons_update(bContext *C, void *arg1_v, void *profile_v) +static void CurveProfile_buttons_reset(bContext *C, void *arg1_v, void *profile_v) { CurveProfile *profile = profile_v; - BKE_curveprofile_update(profile, true); + BKE_curveprofile_reset(profile); + BKE_curveprofile_update(profile, PROF_UPDATE_NONE); rna_update_cb(C, arg1_v, NULL); } @@ -4774,7 +4762,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp UI_block_emboss_set(block, UI_EMBOSS); - uiLayoutRow(layout, false); + uiLayoutSetPropSep(layout, false); /* Preset selector */ /* There is probably potential to use simpler "uiItemR" functions here, but automatic updating @@ -4783,6 +4771,29 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp block, CurveProfile_buttons_presets, profile, "Preset", 0, 0, UI_UNIT_X, UI_UNIT_X, ""); UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); + /* Show a "re-apply" preset button when it has been changed from the preset. */ + if (profile->flag & PROF_DIRTY_PRESET) { + /* Only for dynamic presets. */ + if (ELEM(profile->preset, PROF_PRESET_STEPS, PROF_PRESET_SUPPORTS)) { + bt = uiDefIconTextBut(block, + UI_BTYPE_BUT, + 0, + ICON_NONE, + "Apply Preset", + 0, + 0, + UI_UNIT_X, + UI_UNIT_X, + NULL, + 0.0, + 0.0, + 0.0, + 0.0, + "Reapply and update the preset, removing changes"); + UI_but_funcN_set(bt, CurveProfile_buttons_reset, MEM_dupallocN(cb), profile); + } + } + row = uiLayoutRow(layout, false); /* (Left aligned) */ @@ -4890,11 +4901,24 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp ""); /* Position sliders for (first) selected point */ + float *selection_x, *selection_y; for (i = 0; i < profile->path_len; i++) { if (profile->path[i].flag & PROF_SELECT) { point = &profile->path[i]; + selection_x = &point->x; + selection_y = &point->y; break; } + else if (profile->path[i].flag & PROF_H1_SELECT) { + point = &profile->path[i]; + selection_x = &point->h1_loc[0]; + selection_y = &point->h1_loc[1]; + } + else if (profile->path[i].flag & PROF_H2_SELECT) { + point = &profile->path[i]; + selection_x = &point->h2_loc[0]; + selection_y = &point->h2_loc[1]; + } } if (i == 0 || i == profile->path_len - 1) { point_last_or_first = true; @@ -4910,46 +4934,19 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp bounds.xmax = bounds.ymax = 1000.0; } - uiLayoutRow(layout, true); - UI_block_funcN_set(block, CurveProfile_buttons_update, MEM_dupallocN(cb), profile); + row = uiLayoutRow(layout, true); - /* Sharp / Smooth */ - bt = uiDefIconBut(block, - UI_BTYPE_BUT, - 0, - ICON_LINCURVE, - 0, - 0, - UI_UNIT_X, - UI_UNIT_X, - NULL, - 0.0, - 0.0, - 0.0, - 0.0, - TIP_("Set the point's handle type to sharp")); - if (point_last_or_first) { - UI_but_flag_enable(bt, UI_BUT_DISABLED); - } - UI_but_funcN_set(bt, CurveProfile_buttons_setsharp, MEM_dupallocN(cb), profile); - bt = uiDefIconBut(block, - UI_BTYPE_BUT, - 0, - ICON_SMOOTHCURVE, - 0, - 0, - UI_UNIT_X, - UI_UNIT_X, - NULL, - 0.0, - 0.0, - 0.0, - 0.0, - TIP_("Set the point's handle type to smooth")); - UI_but_funcN_set(bt, CurveProfile_buttons_setcurved, MEM_dupallocN(cb), profile); - if (point_last_or_first) { - UI_but_flag_enable(bt, UI_BUT_DISABLED); - } + PointerRNA point_ptr; + RNA_pointer_create(ptr->owner_id, &RNA_CurveProfilePoint, point, &point_ptr); + PropertyRNA *prop_handle_type = RNA_struct_find_property(&point_ptr, "handle_type_1"); + uiItemFullR(row, + &point_ptr, + prop_handle_type, + RNA_NO_INDEX, + 0, + UI_ITEM_R_EXPAND | UI_ITEM_R_ICON_ONLY, + "", + ICON_NONE); /* Position */ bt = uiDefButF(block, @@ -4960,16 +4957,16 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &point->x, + selection_x, bounds.xmin, bounds.xmax, 1, 5, ""); + UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile); if (point_last_or_first) { UI_but_flag_enable(bt, UI_BUT_DISABLED); } - bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4978,12 +4975,13 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &point->y, + selection_y, bounds.ymin, bounds.ymax, 1, 5, ""); + UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile); if (point_last_or_first) { UI_but_flag_enable(bt, UI_BUT_DISABLED); } |