Cleanup: Use C++ function callbacks for some UI widgets
Use std::function instead of separately allocated arguments and function pointers. This improves type safety and makes the code less verbose. It also moves us closer to not having two methods of adding button callbacks.
This commit is contained in:
@@ -3374,14 +3374,18 @@ struct RNAUpdateCb {
|
||||
PropertyRNA *prop;
|
||||
};
|
||||
|
||||
static void rna_update_cb(bContext *C, void *arg_cb, void * /*arg*/)
|
||||
static void rna_update_cb(bContext &C, const RNAUpdateCb &cb)
|
||||
{
|
||||
RNAUpdateCb *cb = (RNAUpdateCb *)arg_cb;
|
||||
|
||||
/* we call update here on the pointer property, this way the
|
||||
* owner of the curve mapping can still define its own update
|
||||
* and notifier, even if the CurveMapping struct is shared. */
|
||||
RNA_property_update(C, &cb->ptr, cb->prop);
|
||||
RNA_property_update(&C, &const_cast<PointerRNA &>(cb.ptr), cb.prop);
|
||||
}
|
||||
|
||||
static void rna_update_cb(bContext *C, void *arg_cb, void * /*arg*/)
|
||||
{
|
||||
RNAUpdateCb *cb = (RNAUpdateCb *)arg_cb;
|
||||
rna_update_cb(*C, *cb);
|
||||
}
|
||||
|
||||
enum {
|
||||
@@ -3549,33 +3553,22 @@ static uiBlock *colorband_tools_func(bContext *C, ARegion *region, void *arg_cb)
|
||||
return block;
|
||||
}
|
||||
|
||||
static void colorband_add_cb(bContext *C, void *cb_v, void *coba_v)
|
||||
static void colorband_add(bContext &C, const RNAUpdateCb &cb, ColorBand &coba)
|
||||
{
|
||||
ColorBand *coba = static_cast<ColorBand *>(coba_v);
|
||||
float pos = 0.5f;
|
||||
|
||||
if (coba->tot > 1) {
|
||||
if (coba->cur > 0) {
|
||||
pos = (coba->data[coba->cur - 1].pos + coba->data[coba->cur].pos) * 0.5f;
|
||||
if (coba.tot > 1) {
|
||||
if (coba.cur > 0) {
|
||||
pos = (coba.data[coba.cur - 1].pos + coba.data[coba.cur].pos) * 0.5f;
|
||||
}
|
||||
else {
|
||||
pos = (coba->data[coba->cur + 1].pos + coba->data[coba->cur].pos) * 0.5f;
|
||||
pos = (coba.data[coba.cur + 1].pos + coba.data[coba.cur].pos) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (BKE_colorband_element_add(coba, pos)) {
|
||||
rna_update_cb(C, cb_v, nullptr);
|
||||
ED_undo_push(C, "Add Color Ramp Stop");
|
||||
}
|
||||
}
|
||||
|
||||
static void colorband_del_cb(bContext *C, void *cb_v, void *coba_v)
|
||||
{
|
||||
ColorBand *coba = static_cast<ColorBand *>(coba_v);
|
||||
|
||||
if (BKE_colorband_element_remove(coba, coba->cur)) {
|
||||
ED_undo_push(C, "Delete Color Ramp Stop");
|
||||
rna_update_cb(C, cb_v, nullptr);
|
||||
if (BKE_colorband_element_add(&coba, pos)) {
|
||||
rna_update_cb(C, cb);
|
||||
ED_undo_push(&C, "Add Color Ramp Stop");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3594,7 +3587,7 @@ static void colorband_buttons_layout(uiLayout *layout,
|
||||
uiBlock *block,
|
||||
ColorBand *coba,
|
||||
const rctf *butr,
|
||||
RNAUpdateCb *cb,
|
||||
const RNAUpdateCb &cb,
|
||||
int expand)
|
||||
{
|
||||
uiBut *bt;
|
||||
@@ -3602,7 +3595,7 @@ static void colorband_buttons_layout(uiLayout *layout,
|
||||
const float xs = butr->xmin;
|
||||
const float ys = butr->ymin;
|
||||
|
||||
PointerRNA ptr = RNA_pointer_create(cb->ptr.owner_id, &RNA_ColorRamp, coba);
|
||||
PointerRNA ptr = RNA_pointer_create(cb.ptr.owner_id, &RNA_ColorRamp, coba);
|
||||
|
||||
uiLayout *split = uiLayoutSplit(layout, 0.4f, false);
|
||||
|
||||
@@ -3625,7 +3618,7 @@ static void colorband_buttons_layout(uiLayout *layout,
|
||||
0,
|
||||
0,
|
||||
TIP_("Add a new color stop to the color ramp"));
|
||||
UI_but_funcN_set(bt, colorband_add_cb, MEM_dupallocN(cb), coba);
|
||||
UI_but_func_set(bt, [coba, cb](bContext &C) { colorband_add(C, cb, *coba); });
|
||||
|
||||
bt = uiDefIconTextBut(block,
|
||||
UI_BTYPE_BUT,
|
||||
@@ -3642,9 +3635,14 @@ static void colorband_buttons_layout(uiLayout *layout,
|
||||
0,
|
||||
0,
|
||||
TIP_("Delete the active position"));
|
||||
UI_but_funcN_set(bt, colorband_del_cb, MEM_dupallocN(cb), coba);
|
||||
UI_but_func_set(bt, [coba, cb](bContext &C) {
|
||||
if (BKE_colorband_element_remove(coba, coba->cur)) {
|
||||
rna_update_cb(C, cb);
|
||||
ED_undo_push(&C, "Delete Color Ramp Stop");
|
||||
}
|
||||
});
|
||||
|
||||
RNAUpdateCb *tools_cb = static_cast<RNAUpdateCb *>(MEM_dupallocN(cb));
|
||||
RNAUpdateCb *tools_cb = MEM_new<RNAUpdateCb>(__func__, cb);
|
||||
bt = uiDefIconBlockBut(block,
|
||||
colorband_tools_func,
|
||||
tools_cb,
|
||||
@@ -3688,14 +3686,14 @@ static void colorband_buttons_layout(uiLayout *layout,
|
||||
0,
|
||||
0,
|
||||
"");
|
||||
UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_but_func_set(bt, [cb](bContext &C) { rna_update_cb(C, cb); });
|
||||
|
||||
row = uiLayoutRow(layout, false);
|
||||
|
||||
if (coba->tot) {
|
||||
CBData *cbd = coba->data + coba->cur;
|
||||
|
||||
ptr = RNA_pointer_create(cb->ptr.owner_id, &RNA_ColorRampElement, cbd);
|
||||
ptr = RNA_pointer_create(cb.ptr.owner_id, &RNA_ColorRampElement, cbd);
|
||||
|
||||
if (!expand) {
|
||||
split = uiLayoutSplit(layout, 0.3f, false);
|
||||
@@ -3766,7 +3764,7 @@ static void colorband_buttons_layout(uiLayout *layout,
|
||||
}
|
||||
|
||||
if (STREQ(prop_identifier, "color")) {
|
||||
UI_but_funcN_set(but, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_but_func_set(bt, [cb](bContext &C) { rna_update_cb(C, cb); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3785,10 +3783,6 @@ void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname
|
||||
return;
|
||||
}
|
||||
|
||||
RNAUpdateCb *cb = MEM_cnew<RNAUpdateCb>("RNAUpdateCb");
|
||||
cb->ptr = *ptr;
|
||||
cb->prop = prop;
|
||||
|
||||
rctf rect;
|
||||
rect.xmin = 0;
|
||||
rect.xmax = 10.0f * UI_UNIT_X;
|
||||
@@ -3800,11 +3794,10 @@ void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname
|
||||
ID *id = cptr.owner_id;
|
||||
UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE);
|
||||
|
||||
colorband_buttons_layout(layout, block, static_cast<ColorBand *>(cptr.data), &rect, cb, expand);
|
||||
colorband_buttons_layout(
|
||||
layout, block, static_cast<ColorBand *>(cptr.data), &rect, RNAUpdateCb{*ptr, prop}, expand);
|
||||
|
||||
UI_block_lock_clear(block);
|
||||
|
||||
MEM_freeN(cb);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -4165,10 +4158,8 @@ static bool curvemap_can_zoom_in(CurveMapping *cumap)
|
||||
return BLI_rctf_size_x(&cumap->curr) > CURVE_ZOOM_MAX * BLI_rctf_size_x(&cumap->clipr);
|
||||
}
|
||||
|
||||
static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void * /*arg*/)
|
||||
static void curvemap_buttons_zoom_in(bContext *C, CurveMapping *cumap)
|
||||
{
|
||||
CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v);
|
||||
|
||||
if (curvemap_can_zoom_in(cumap)) {
|
||||
const float dx = 0.1154f * BLI_rctf_size_x(&cumap->curr);
|
||||
cumap->curr.xmin += dx;
|
||||
@@ -4181,9 +4172,8 @@ static void curvemap_buttons_zoom_in(bContext *C, void *cumap_v, void * /*arg*/)
|
||||
ED_region_tag_redraw(CTX_wm_region(C));
|
||||
}
|
||||
|
||||
static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void * /*unused*/)
|
||||
static void curvemap_buttons_zoom_out(bContext *C, CurveMapping *cumap)
|
||||
{
|
||||
CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v);
|
||||
float d, d1;
|
||||
|
||||
if (curvemap_can_zoom_out(cumap)) {
|
||||
@@ -4225,23 +4215,6 @@ static void curvemap_buttons_zoom_out(bContext *C, void *cumap_v, void * /*unuse
|
||||
ED_region_tag_redraw(CTX_wm_region(C));
|
||||
}
|
||||
|
||||
static void curvemap_buttons_setclip(bContext * /*C*/, void *cumap_v, void * /*arg*/)
|
||||
{
|
||||
CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v);
|
||||
|
||||
BKE_curvemapping_changed(cumap, false);
|
||||
}
|
||||
|
||||
static void curvemap_buttons_delete(bContext *C, void *cb_v, void *cumap_v)
|
||||
{
|
||||
CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v);
|
||||
|
||||
BKE_curvemap_remove(cumap->cm + cumap->cur, SELECT);
|
||||
BKE_curvemapping_changed(cumap, false);
|
||||
|
||||
rna_update_cb(C, cb_v, nullptr);
|
||||
}
|
||||
|
||||
/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
|
||||
static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap_v)
|
||||
{
|
||||
@@ -4266,7 +4239,7 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap
|
||||
0.0,
|
||||
0.0,
|
||||
"");
|
||||
UI_but_func_set(bt, curvemap_buttons_setclip, cumap, nullptr);
|
||||
UI_but_func_set(bt, [cumap](bContext & /*C*/) { BKE_curvemapping_changed(cumap, false); });
|
||||
|
||||
UI_block_align_begin(block);
|
||||
bt = uiDefButF(block,
|
||||
@@ -4510,33 +4483,9 @@ static void curvemap_tools_handle_auto_clamped(bContext *C, void *cumap_v, void
|
||||
curvemap_tools_dofunc(C, cumap_v, UICURVE_FUNC_HANDLE_AUTO_ANIM);
|
||||
}
|
||||
|
||||
static void curvemap_buttons_redraw(bContext *C, void * /*arg1*/, void * /*arg2*/)
|
||||
static void curvemap_buttons_redraw(bContext &C)
|
||||
{
|
||||
ED_region_tag_redraw(CTX_wm_region(C));
|
||||
}
|
||||
|
||||
static void curvemap_buttons_update(bContext *C, void *arg1_v, void *cumap_v)
|
||||
{
|
||||
CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v);
|
||||
BKE_curvemapping_changed(cumap, true);
|
||||
rna_update_cb(C, arg1_v, nullptr);
|
||||
}
|
||||
|
||||
static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v)
|
||||
{
|
||||
CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v);
|
||||
cumap->preset = CURVE_PRESET_LINE;
|
||||
for (int a = 0; a < CM_TOT; a++) {
|
||||
BKE_curvemap_reset(cumap->cm + a, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE);
|
||||
}
|
||||
|
||||
cumap->black[0] = cumap->black[1] = cumap->black[2] = 0.0f;
|
||||
cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f;
|
||||
BKE_curvemapping_set_black_white(cumap, nullptr, nullptr);
|
||||
|
||||
BKE_curvemapping_changed(cumap, false);
|
||||
|
||||
rna_update_cb(C, cb_v, nullptr);
|
||||
ED_region_tag_redraw(CTX_wm_region(&C));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4551,7 +4500,7 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
bool brush,
|
||||
bool neg_slope,
|
||||
bool tone,
|
||||
RNAUpdateCb *cb)
|
||||
const RNAUpdateCb &cb)
|
||||
{
|
||||
CurveMapping *cumap = static_cast<CurveMapping *>(ptr->data);
|
||||
CurveMap *cm = &cumap->cm[cumap->cur];
|
||||
@@ -4579,17 +4528,17 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
if (cumap->cm[0].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, "X", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
if (cumap->cm[1].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, "Y", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
if (cumap->cm[2].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, "Z", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
}
|
||||
else if (labeltype == 'c') {
|
||||
@@ -4612,22 +4561,22 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
0.0,
|
||||
0.0,
|
||||
"");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
if (cumap->cm[0].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, IFACE_("R"), 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
if (cumap->cm[1].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, IFACE_("G"), 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
if (cumap->cm[2].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, IFACE_("B"), 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
}
|
||||
else if (labeltype == 'h') {
|
||||
@@ -4638,17 +4587,17 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
if (cumap->cm[0].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, IFACE_("H"), 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
if (cumap->cm[1].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, IFACE_("S"), 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
if (cumap->cm[2].curve) {
|
||||
bt = uiDefButI(
|
||||
block, UI_BTYPE_ROW, 0, IFACE_("V"), 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, 0.0, 0.0, "");
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw, nullptr, nullptr);
|
||||
UI_but_func_set(bt, curvemap_buttons_redraw);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -4679,7 +4628,7 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Zoom in"));
|
||||
UI_but_func_set(bt, curvemap_buttons_zoom_in, cumap, nullptr);
|
||||
UI_but_func_set(bt, [cumap](bContext &C) { curvemap_buttons_zoom_in(&C, cumap); });
|
||||
if (!curvemap_can_zoom_in(cumap)) {
|
||||
UI_but_disable(bt, "");
|
||||
}
|
||||
@@ -4699,7 +4648,7 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Zoom out"));
|
||||
UI_but_func_set(bt, curvemap_buttons_zoom_out, cumap, nullptr);
|
||||
UI_but_func_set(bt, [cumap](bContext &C) { curvemap_buttons_zoom_out(&C, cumap); });
|
||||
if (!curvemap_can_zoom_out(cumap)) {
|
||||
UI_but_disable(bt, "");
|
||||
}
|
||||
@@ -4709,7 +4658,7 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
bt = uiDefIconBlockBut(
|
||||
block, curvemap_clipping_func, cumap, 0, icon, 0, 0, dx, dx, TIP_("Clipping Options"));
|
||||
bt->drawflag &= ~UI_BUT_ICON_LEFT;
|
||||
UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_but_func_set(bt, [cb](bContext &C) { rna_update_cb(C, cb); });
|
||||
|
||||
if (brush && neg_slope) {
|
||||
bt = uiDefIconBlockBut(block,
|
||||
@@ -4735,9 +4684,9 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
bt = uiDefIconBlockBut(
|
||||
block, curvemap_tools_posslope_func, cumap, 0, ICON_NONE, 0, 0, dx, dx, TIP_("Tools"));
|
||||
}
|
||||
UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_but_func_set(bt, [cb](bContext &C) { rna_update_cb(C, cb); });
|
||||
|
||||
UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_block_funcN_set(block, rna_update_cb, MEM_new<RNAUpdateCb>(__func__, cb), nullptr);
|
||||
|
||||
/* Curve itself. */
|
||||
const int size = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X);
|
||||
@@ -4835,7 +4784,10 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
}
|
||||
|
||||
/* Curve handle position */
|
||||
UI_block_funcN_set(block, curvemap_buttons_update, MEM_dupallocN(cb), cumap);
|
||||
UI_but_func_set(bt, [cumap, cb](bContext &C) {
|
||||
BKE_curvemapping_changed(cumap, true);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
bt = uiDefButF(block,
|
||||
UI_BTYPE_NUM,
|
||||
0,
|
||||
@@ -4880,7 +4832,11 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Delete points"));
|
||||
UI_but_funcN_set(bt, curvemap_buttons_delete, MEM_dupallocN(cb), cumap);
|
||||
UI_but_func_set(bt, [cumap, cb](bContext &C) {
|
||||
BKE_curvemap_remove(cumap->cm + cumap->cur, SELECT);
|
||||
BKE_curvemapping_changed(cumap, false);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
if (point_last_or_first) {
|
||||
UI_but_flag_enable(bt, UI_BUT_DISABLED);
|
||||
}
|
||||
@@ -4909,7 +4865,19 @@ static void curvemap_buttons_layout(uiLayout *layout,
|
||||
0,
|
||||
0,
|
||||
TIP_("Reset Black/White point and curves"));
|
||||
UI_but_funcN_set(bt, curvemap_buttons_reset, MEM_dupallocN(cb), cumap);
|
||||
UI_but_func_set(bt, [cumap, cb](bContext &C) {
|
||||
cumap->preset = CURVE_PRESET_LINE;
|
||||
for (int a = 0; a < CM_TOT; a++) {
|
||||
BKE_curvemap_reset(cumap->cm + a, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE);
|
||||
}
|
||||
|
||||
cumap->black[0] = cumap->black[1] = cumap->black[2] = 0.0f;
|
||||
cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f;
|
||||
BKE_curvemapping_set_black_white(cumap, nullptr, nullptr);
|
||||
|
||||
BKE_curvemapping_changed(cumap, false);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
}
|
||||
|
||||
UI_block_funcN_set(block, nullptr, nullptr, nullptr);
|
||||
@@ -4942,18 +4910,13 @@ void uiTemplateCurveMapping(uiLayout *layout,
|
||||
return;
|
||||
}
|
||||
|
||||
RNAUpdateCb *cb = MEM_cnew<RNAUpdateCb>("RNAUpdateCb");
|
||||
cb->ptr = *ptr;
|
||||
cb->prop = prop;
|
||||
|
||||
ID *id = cptr.owner_id;
|
||||
UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE);
|
||||
|
||||
curvemap_buttons_layout(layout, &cptr, type, levels, brush, neg_slope, tone, cb);
|
||||
curvemap_buttons_layout(
|
||||
layout, &cptr, type, levels, brush, neg_slope, tone, RNAUpdateCb{*ptr, prop});
|
||||
|
||||
UI_block_lock_clear(block);
|
||||
|
||||
MEM_freeN(cb);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -5151,10 +5114,8 @@ static bool CurveProfile_can_zoom_out(CurveProfile *profile)
|
||||
return BLI_rctf_size_x(&profile->view_rect) < BLI_rctf_size_x(&profile->clip_rect);
|
||||
}
|
||||
|
||||
static void CurveProfile_buttons_zoom_in(bContext *C, void *profile_v, void * /*arg*/)
|
||||
static void CurveProfile_buttons_zoom_in(bContext *C, CurveProfile *profile)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(profile_v);
|
||||
|
||||
if (CurveProfile_can_zoom_in(profile)) {
|
||||
const float dx = 0.1154f * BLI_rctf_size_x(&profile->view_rect);
|
||||
profile->view_rect.xmin += dx;
|
||||
@@ -5167,10 +5128,8 @@ static void CurveProfile_buttons_zoom_in(bContext *C, void *profile_v, void * /*
|
||||
ED_region_tag_redraw(CTX_wm_region(C));
|
||||
}
|
||||
|
||||
static void CurveProfile_buttons_zoom_out(bContext *C, void *profile_v, void * /*arg*/)
|
||||
static void CurveProfile_buttons_zoom_out(bContext *C, CurveProfile *profile)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(profile_v);
|
||||
|
||||
if (CurveProfile_can_zoom_out(profile)) {
|
||||
float d = 0.15f * BLI_rctf_size_x(&profile->view_rect);
|
||||
float d1 = d;
|
||||
@@ -5211,51 +5170,7 @@ static void CurveProfile_buttons_zoom_out(bContext *C, void *profile_v, void * /
|
||||
ED_region_tag_redraw(CTX_wm_region(C));
|
||||
}
|
||||
|
||||
static void CurveProfile_clipping_toggle(bContext *C, void *cb_v, void *profile_v)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(profile_v);
|
||||
|
||||
profile->flag ^= PROF_USE_CLIP;
|
||||
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
rna_update_cb(C, cb_v, nullptr);
|
||||
}
|
||||
|
||||
static void CurveProfile_buttons_reverse(bContext *C, void *cb_v, void *profile_v)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(profile_v);
|
||||
|
||||
BKE_curveprofile_reverse(profile);
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
rna_update_cb(C, cb_v, nullptr);
|
||||
}
|
||||
|
||||
static void CurveProfile_buttons_delete(bContext *C, void *cb_v, void *profile_v)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(profile_v);
|
||||
|
||||
BKE_curveprofile_remove_by_flag(profile, SELECT);
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
|
||||
rna_update_cb(C, cb_v, nullptr);
|
||||
}
|
||||
|
||||
static void CurveProfile_buttons_update(bContext *C, void *arg1_v, void *profile_v)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(profile_v);
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP);
|
||||
rna_update_cb(C, arg1_v, nullptr);
|
||||
}
|
||||
|
||||
static void CurveProfile_buttons_reset(bContext *C, void *arg1_v, void *profile_v)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(profile_v);
|
||||
BKE_curveprofile_reset(profile);
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
rna_update_cb(C, arg1_v, nullptr);
|
||||
}
|
||||
|
||||
static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUpdateCb *cb)
|
||||
static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const RNAUpdateCb &cb)
|
||||
{
|
||||
CurveProfile *profile = static_cast<CurveProfile *>(ptr->data);
|
||||
uiBut *bt;
|
||||
@@ -5279,7 +5194,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
UI_UNIT_X,
|
||||
UI_UNIT_X,
|
||||
"");
|
||||
UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_but_func_set(bt, [cb](bContext &C) { rna_update_cb(C, cb); });
|
||||
|
||||
/* Show a "re-apply" preset button when it has been changed from the preset. */
|
||||
if (profile->flag & PROF_DIRTY_PRESET) {
|
||||
@@ -5300,7 +5215,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Reapply and update the preset, removing changes"));
|
||||
UI_but_funcN_set(bt, CurveProfile_buttons_reset, MEM_dupallocN(cb), profile);
|
||||
UI_but_func_set(bt, [profile, cb](bContext &C) {
|
||||
BKE_curveprofile_reset(profile);
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5325,7 +5244,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Zoom in"));
|
||||
UI_but_func_set(bt, CurveProfile_buttons_zoom_in, profile, nullptr);
|
||||
UI_but_func_set(bt, [profile](bContext &C) { CurveProfile_buttons_zoom_in(&C, profile); });
|
||||
if (!CurveProfile_can_zoom_in(profile)) {
|
||||
UI_but_disable(bt, "");
|
||||
}
|
||||
@@ -5345,7 +5264,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Zoom out"));
|
||||
UI_but_func_set(bt, CurveProfile_buttons_zoom_out, profile, nullptr);
|
||||
UI_but_func_set(bt, [profile](bContext &C) { CurveProfile_buttons_zoom_out(&C, profile); });
|
||||
if (!CurveProfile_can_zoom_out(profile)) {
|
||||
UI_but_disable(bt, "");
|
||||
}
|
||||
@@ -5369,7 +5288,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Reverse Path"));
|
||||
UI_but_funcN_set(bt, CurveProfile_buttons_reverse, MEM_dupallocN(cb), profile);
|
||||
UI_but_func_set(bt, [profile, cb](bContext &C) {
|
||||
BKE_curveprofile_reverse(profile);
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
|
||||
/* Clipping toggle */
|
||||
const int icon = (profile->flag & PROF_USE_CLIP) ? ICON_CLIPUV_HLT : ICON_CLIPUV_DEHLT;
|
||||
@@ -5387,7 +5310,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Toggle Profile Clipping"));
|
||||
UI_but_funcN_set(bt, CurveProfile_clipping_toggle, MEM_dupallocN(cb), profile);
|
||||
UI_but_func_set(bt, [profile, cb](bContext &C) {
|
||||
profile->flag ^= PROF_USE_CLIP;
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
|
||||
/* Reset view, reset curve */
|
||||
bt = uiDefIconBlockBut(block,
|
||||
@@ -5400,9 +5327,9 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
UI_UNIT_X,
|
||||
UI_UNIT_X,
|
||||
TIP_("Tools"));
|
||||
UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_but_func_set(bt, [cb](bContext &C) { rna_update_cb(C, cb); });
|
||||
|
||||
UI_block_funcN_set(block, rna_update_cb, MEM_dupallocN(cb), nullptr);
|
||||
UI_block_funcN_set(block, rna_update_cb, MEM_new<RNAUpdateCb>(__func__, cb), nullptr);
|
||||
|
||||
/* The path itself */
|
||||
int path_width = max_ii(uiLayoutGetWidth(layout), UI_UNIT_X);
|
||||
@@ -5490,7 +5417,10 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
"");
|
||||
UI_but_number_step_size_set(bt, 1);
|
||||
UI_but_number_precision_set(bt, 5);
|
||||
UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile);
|
||||
UI_but_func_set(bt, [profile, cb](bContext &C) {
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
if (point_last_or_first) {
|
||||
UI_but_flag_enable(bt, UI_BUT_DISABLED);
|
||||
}
|
||||
@@ -5508,7 +5438,10 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
"");
|
||||
UI_but_number_step_size_set(bt, 1);
|
||||
UI_but_number_precision_set(bt, 5);
|
||||
UI_but_funcN_set(bt, CurveProfile_buttons_update, MEM_dupallocN(cb), profile);
|
||||
UI_but_func_set(bt, [profile, cb](bContext &C) {
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
if (point_last_or_first) {
|
||||
UI_but_flag_enable(bt, UI_BUT_DISABLED);
|
||||
}
|
||||
@@ -5528,7 +5461,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, RNAUp
|
||||
0.0,
|
||||
0.0,
|
||||
TIP_("Delete points"));
|
||||
UI_but_funcN_set(bt, CurveProfile_buttons_delete, MEM_dupallocN(cb), profile);
|
||||
UI_but_func_set(bt, [profile, cb](bContext &C) {
|
||||
BKE_curveprofile_remove_by_flag(profile, SELECT);
|
||||
BKE_curveprofile_update(profile, PROF_UPDATE_NONE);
|
||||
rna_update_cb(C, cb);
|
||||
});
|
||||
if (point_last_or_first) {
|
||||
UI_but_flag_enable(bt, UI_BUT_DISABLED);
|
||||
}
|
||||
@@ -5563,19 +5500,12 @@ void uiTemplateCurveProfile(uiLayout *layout, PointerRNA *ptr, const char *propn
|
||||
return;
|
||||
}
|
||||
|
||||
/* Share update functionality with the CurveMapping widget template. */
|
||||
RNAUpdateCb *cb = MEM_cnew<RNAUpdateCb>("RNAUpdateCb");
|
||||
cb->ptr = *ptr;
|
||||
cb->prop = prop;
|
||||
|
||||
ID *id = cptr.owner_id;
|
||||
UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE);
|
||||
|
||||
CurveProfile_buttons_layout(layout, &cptr, cb);
|
||||
CurveProfile_buttons_layout(layout, &cptr, RNAUpdateCb{*ptr, prop});
|
||||
|
||||
UI_block_lock_clear(block);
|
||||
|
||||
MEM_freeN(cb);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user