From 01541fecf4f98e5681c56813f0b4e85b8374f8f1 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Thu, 4 Apr 2024 14:12:48 +0800 Subject: [PATCH 01/15] 4.4 Store all selected point with Vector --- .../templates/interface_templates.cc | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index 0716fd6e8a6..162b28fe49b 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4558,20 +4558,19 @@ static void curvemap_buttons_layout(uiLayout *layout, curve_but->gradient_type = bg; /* Sliders for selected curve point. */ - int i; - CurveMapPoint *cmp = nullptr; + Vector cmps{}; bool point_last_or_first = false; - for (i = 0; i < cm->totpoint; i++) { - if (cm->curve[i].flag & CUMA_SELECT) { - cmp = &cm->curve[i]; - break; + for (int i = 0; i < cm->totpoint; i++) { + const bool selected = cm->curve[i].flag & CUMA_SELECT; + if (selected) { + cmps.append(&cm->curve[i]); + } + if (ELEM(i, 0, cm->totpoint - 1) && selected) { + point_last_or_first = true; } } - if (ELEM(i, 0, cm->totpoint - 1)) { - point_last_or_first = true; - } - if (cmp) { + if (cmps.size() == 1) { rctf bounds; if (cumap->flag & CUMA_DO_CLIP) { bounds = cumap->clipr; @@ -4604,8 +4603,8 @@ static void curvemap_buttons_layout(uiLayout *layout, BKE_curvemapping_changed(cumap, false); rna_update_cb(C, cb); }); - if (((cmp->flag & CUMA_HANDLE_AUTO_ANIM) == false) && - ((cmp->flag & CUMA_HANDLE_VECTOR) == false)) + if (((cmps[0]->flag & CUMA_HANDLE_AUTO_ANIM) == false) && + ((cmps[0]->flag & CUMA_HANDLE_VECTOR) == false)) { bt->flag |= UI_SELECT_DRAW; } @@ -4628,7 +4627,7 @@ static void curvemap_buttons_layout(uiLayout *layout, BKE_curvemapping_changed(cumap, false); rna_update_cb(C, cb); }); - if (cmp->flag & CUMA_HANDLE_VECTOR) { + if (cmps[0]->flag & CUMA_HANDLE_VECTOR) { bt->flag |= UI_SELECT_DRAW; } @@ -4650,7 +4649,7 @@ static void curvemap_buttons_layout(uiLayout *layout, BKE_curvemapping_changed(cumap, false); rna_update_cb(C, cb); }); - if (cmp->flag & CUMA_HANDLE_AUTO_ANIM) { + if (cmps[0]->flag & CUMA_HANDLE_AUTO_ANIM) { bt->flag |= UI_SELECT_DRAW; } @@ -4663,7 +4662,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &cmp->x, + &cmps[0]->x, bounds.xmin, bounds.xmax, ""); @@ -4682,7 +4681,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &cmp->y, + &cmps[0]->y, bounds.ymin, bounds.ymax, ""); -- 2.30.2 From 06b57d1a857cbabe4991578501bafeb00ae63c3e Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Thu, 4 Apr 2024 15:38:43 +0800 Subject: [PATCH 02/15] 4.4 Shift point positions from center --- source/blender/blenkernel/BKE_colortools.hh | 4 +++ .../blender/blenkernel/intern/colortools.cc | 28 +++++++++++++++++++ .../templates/interface_templates.cc | 20 ++++++++++--- source/blender/makesdna/DNA_color_types.h | 2 ++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/BKE_colortools.hh b/source/blender/blenkernel/BKE_colortools.hh index e086209d67c..b661d8b03c6 100644 --- a/source/blender/blenkernel/BKE_colortools.hh +++ b/source/blender/blenkernel/BKE_colortools.hh @@ -59,6 +59,10 @@ void BKE_curvemap_remove(CurveMap *cuma, short flag); */ bool BKE_curvemap_remove_point(CurveMap *cuma, CurveMapPoint *cmp); CurveMapPoint *BKE_curvemap_insert(CurveMap *cuma, float x, float y); +/** + * Shift specified point from center. + */ +void BKE_curvemap_shift(CurveMapping *cumap); /** * \param type: #eBezTriple_Handle */ diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index 593c8f70054..9570e93e88d 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -930,6 +930,34 @@ void BKE_curvemapping_premultiply(CurveMapping *cumap, bool restore) } /* ************************ more CurveMapping calls *************** */ +void BKE_curvemap_shift(CurveMapping *cumap) +{ + CurveMap *cuma = cumap->cm + cumap->cur; + CurveMapPoint *cmp = cuma->curve; + + /* unmodified center */ + float center_x_pre = 0.0f; + float center_y_pre = 0.0f; + int n = 0; + for (int i = 0; i < cuma->totpoint; i++) { + if (cmp[i].flag & CUMA_SELECT) { + center_x_pre += cmp[i].x; + center_y_pre += cmp[i].y; + n++; + } + } + if (n > 0) { + center_x_pre /= n; + center_y_pre /= n; + } + + for (int i = 0; i < cuma->totpoint; i++) { + if (cmp[i].flag & CUMA_SELECT) { + cmp[i].x += cuma->center_x - center_x_pre; + cmp[i].y += cuma->center_y - center_y_pre; + } + } +} void BKE_curvemapping_changed(CurveMapping *cumap, const bool rem_doubles) { diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index 162b28fe49b..f98db81a88d 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4558,7 +4558,7 @@ static void curvemap_buttons_layout(uiLayout *layout, curve_but->gradient_type = bg; /* Sliders for selected curve point. */ - Vector cmps{}; + Vector cmps{}; bool point_last_or_first = false; for (int i = 0; i < cm->totpoint; i++) { const bool selected = cm->curve[i].flag & CUMA_SELECT; @@ -4570,7 +4570,9 @@ static void curvemap_buttons_layout(uiLayout *layout, } } - if (cmps.size() == 1) { + if (!cmps.is_empty()) { + CurveMap *active_cm = cumap->cm + cumap->cur; + rctf bounds; if (cumap->flag & CUMA_DO_CLIP) { bounds = cumap->clipr; @@ -4654,6 +4656,10 @@ static void curvemap_buttons_layout(uiLayout *layout, } /* Curve handle position */ + active_cm->center_x = 0.0f; + for (auto cmp : cmps) + active_cm->center_x += cmp->x; + active_cm->center_x /= cmps.size(); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4662,17 +4668,22 @@ static void curvemap_buttons_layout(uiLayout *layout, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &cmps[0]->x, + &active_cm->center_x, bounds.xmin, bounds.xmax, ""); UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { + BKE_curvemap_shift(cumap); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); + active_cm->center_y = 0.0f; + for (auto cmp : cmps) + active_cm->center_y += cmp->y; + active_cm->center_y /= cmps.size(); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4681,13 +4692,14 @@ static void curvemap_buttons_layout(uiLayout *layout, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &cmps[0]->y, + &active_cm->center_y, bounds.ymin, bounds.ymax, ""); UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { + BKE_curvemap_shift(cumap); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); diff --git a/source/blender/makesdna/DNA_color_types.h b/source/blender/makesdna/DNA_color_types.h index 54ac42d220f..0f3207a3d1d 100644 --- a/source/blender/makesdna/DNA_color_types.h +++ b/source/blender/makesdna/DNA_color_types.h @@ -48,6 +48,8 @@ typedef struct CurveMap { float ext_in[2], ext_out[2]; /** Actual curve. */ CurveMapPoint *curve; + /** Center of selected points */ + float center_x, center_y; /** Display and evaluate table. */ CurveMapPoint *table; -- 2.30.2 From 128f56fb2d0b8e05ed8fbe3c241e5f943d339382 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Thu, 4 Apr 2024 16:05:15 +0800 Subject: [PATCH 03/15] 4.4 flags --- .../templates/interface_templates.cc | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index f98db81a88d..b424a019469 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4605,10 +4605,12 @@ static void curvemap_buttons_layout(uiLayout *layout, BKE_curvemapping_changed(cumap, false); rna_update_cb(C, cb); }); - if (((cmps[0]->flag & CUMA_HANDLE_AUTO_ANIM) == false) && - ((cmps[0]->flag & CUMA_HANDLE_VECTOR) == false)) - { - bt->flag |= UI_SELECT_DRAW; + + bool select_draw = true; + for (CurveMapPoint *cmp : cmps) { + const bool auto_anim_vec = ((cmp->flag & CUMA_HANDLE_AUTO_ANIM) == false) && + ((cmp->flag & CUMA_HANDLE_VECTOR) == false); + bt->flag |= UI_SELECT_DRAW && auto_anim_vec; } bt = uiDefIconBut(block, @@ -4629,8 +4631,10 @@ static void curvemap_buttons_layout(uiLayout *layout, BKE_curvemapping_changed(cumap, false); rna_update_cb(C, cb); }); - if (cmps[0]->flag & CUMA_HANDLE_VECTOR) { - bt->flag |= UI_SELECT_DRAW; + + for (CurveMapPoint *cmp : cmps) { + const bool vec = (cmp->flag & CUMA_HANDLE_VECTOR); + bt->flag |= UI_SELECT_DRAW && vec; } bt = uiDefIconBut(block, @@ -4651,13 +4655,14 @@ static void curvemap_buttons_layout(uiLayout *layout, BKE_curvemapping_changed(cumap, false); rna_update_cb(C, cb); }); - if (cmps[0]->flag & CUMA_HANDLE_AUTO_ANIM) { - bt->flag |= UI_SELECT_DRAW; + + for (CurveMapPoint *cmp : cmps) { + const bool auto_anim = (cmp->flag & CUMA_HANDLE_AUTO_ANIM); + bt->flag |= UI_SELECT_DRAW && auto_anim; } /* Curve handle position */ active_cm->center_x = 0.0f; - for (auto cmp : cmps) active_cm->center_x += cmp->x; active_cm->center_x /= cmps.size(); bt = uiDefButF(block, @@ -4681,7 +4686,7 @@ static void curvemap_buttons_layout(uiLayout *layout, }); active_cm->center_y = 0.0f; - for (auto cmp : cmps) + for (CurveMapPoint *cmp : cmps) active_cm->center_y += cmp->y; active_cm->center_y /= cmps.size(); bt = uiDefButF(block, -- 2.30.2 From 8a6cabd4bffc74e770a7d5edddf7cccdd29cd02c Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Thu, 4 Apr 2024 16:06:19 +0800 Subject: [PATCH 04/15] Update interface_templates.cc --- .../blender/editors/interface/templates/interface_templates.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index b424a019469..b64cd80e06e 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4663,6 +4663,7 @@ static void curvemap_buttons_layout(uiLayout *layout, /* Curve handle position */ active_cm->center_x = 0.0f; + for (CurveMapPoint *cmp : cmps) active_cm->center_x += cmp->x; active_cm->center_x /= cmps.size(); bt = uiDefButF(block, -- 2.30.2 From a92176468cb6b6d9db64435db3781a4213b0cff9 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Thu, 4 Apr 2024 16:25:17 +0800 Subject: [PATCH 05/15] unused variable removed --- .../blender/editors/interface/templates/interface_templates.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index b64cd80e06e..533688f68a8 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4606,7 +4606,6 @@ static void curvemap_buttons_layout(uiLayout *layout, rna_update_cb(C, cb); }); - bool select_draw = true; for (CurveMapPoint *cmp : cmps) { const bool auto_anim_vec = ((cmp->flag & CUMA_HANDLE_AUTO_ANIM) == false) && ((cmp->flag & CUMA_HANDLE_VECTOR) == false); -- 2.30.2 From a6c21ff00eb476750c9abb539a6abfa2e0fcbaaa Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Fri, 5 Apr 2024 08:36:07 +0800 Subject: [PATCH 06/15] 4.5 C++ code style --- .../editors/interface/templates/interface_templates.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index 533688f68a8..e6a6e76dfe9 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4558,7 +4558,7 @@ static void curvemap_buttons_layout(uiLayout *layout, curve_but->gradient_type = bg; /* Sliders for selected curve point. */ - Vector cmps{}; + Vector cmps; bool point_last_or_first = false; for (int i = 0; i < cm->totpoint; i++) { const bool selected = cm->curve[i].flag & CUMA_SELECT; @@ -4662,8 +4662,9 @@ static void curvemap_buttons_layout(uiLayout *layout, /* Curve handle position */ active_cm->center_x = 0.0f; - for (CurveMapPoint *cmp : cmps) + for (const CurveMapPoint* cmp : cmps) { active_cm->center_x += cmp->x; + } active_cm->center_x /= cmps.size(); bt = uiDefButF(block, UI_BTYPE_NUM, @@ -4686,8 +4687,9 @@ static void curvemap_buttons_layout(uiLayout *layout, }); active_cm->center_y = 0.0f; - for (CurveMapPoint *cmp : cmps) + for (const CurveMapPoint* cmp : cmps) { active_cm->center_y += cmp->y; + } active_cm->center_y /= cmps.size(); bt = uiDefButF(block, UI_BTYPE_NUM, -- 2.30.2 From 5362ce8c59be9c63140af51ee9a9ebc7afe272c5 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Sun, 7 Apr 2024 18:19:48 +0800 Subject: [PATCH 07/15] 4.7 runtime storage --- .../blender/blenkernel/intern/colortools.cc | 16 +++++++++++++-- source/blender/blenkernel/intern/node.cc | 6 ++++++ .../templates/interface_templates.cc | 20 +++++++++---------- source/blender/makesdna/DNA_color_types.h | 10 ++++++++-- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index 9570e93e88d..f49c2453a1c 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -80,6 +80,9 @@ void BKE_curvemapping_set_defaults(CurveMapping *cumap, cumap->cm[a].curve[1].x = maxx; cumap->cm[a].curve[1].y = maxy; cumap->cm[a].curve[1].flag |= default_handle_type; + + cumap->cm[a].runtime = static_cast( + MEM_callocN(sizeof(CurveMapRuntime), "curve runtime")); } cumap->changed_timestamp = 0; @@ -113,6 +116,10 @@ void BKE_curvemapping_free_data(CurveMapping *cumap) MEM_freeN(cumap->cm[a].premultable); cumap->cm[a].premultable = nullptr; } +// if (cumap->cm[a].runtime) { +// MEM_freeN(cumap->cm[a].runtime); +// cumap->cm[a].runtime = nullptr; +// } } } @@ -953,8 +960,8 @@ void BKE_curvemap_shift(CurveMapping *cumap) for (int i = 0; i < cuma->totpoint; i++) { if (cmp[i].flag & CUMA_SELECT) { - cmp[i].x += cuma->center_x - center_x_pre; - cmp[i].y += cuma->center_y - center_y_pre; + cmp[i].x += cuma->runtime->center_x - center_x_pre; + cmp[i].y += cuma->runtime->center_y - center_y_pre; } } } @@ -1353,6 +1360,10 @@ void BKE_curvemapping_init(CurveMapping *cumap) if (cumap->cm[a].table == nullptr) { curvemap_make_table(cumap, cumap->cm + a); } + if (cumap->cm[a].runtime == nullptr) { + cumap->cm[a].runtime = static_cast( + MEM_callocN(sizeof(CurveMapRuntime), "curve runtime")); + } } } @@ -1415,6 +1426,7 @@ void BKE_curvemapping_blend_read(BlendDataReader *reader, CurveMapping *cumap) BLO_read_data_address(reader, &cumap->cm[a].curve); cumap->cm[a].table = nullptr; cumap->cm[a].premultable = nullptr; + cumap->cm[a].runtime = nullptr; } } diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index a6476374667..4205c4c64b6 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -1067,6 +1067,12 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) case TEX_NODE_CURVE_RGB: case TEX_NODE_CURVE_TIME: { BKE_curvemapping_blend_read(reader, static_cast(node->storage)); + for (int i = 0; i < 4; i++) { + auto runtime = static_cast(node->storage)->cm[i].runtime; + if(runtime == nullptr) + static_cast(node->storage)->cm[i].runtime = static_cast( + MEM_callocN(sizeof(CurveMapRuntime), "curve runtime")); + } break; } case SH_NODE_SCRIPT: { diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index e6a6e76dfe9..ff59b53bf7f 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4661,11 +4661,11 @@ static void curvemap_buttons_layout(uiLayout *layout, } /* Curve handle position */ - active_cm->center_x = 0.0f; - for (const CurveMapPoint* cmp : cmps) { - active_cm->center_x += cmp->x; + active_cm->runtime->center_x = 0.0f; + for (const CurveMapPoint *cmp : cmps) { + active_cm->runtime->center_x += cmp->x; } - active_cm->center_x /= cmps.size(); + active_cm->runtime->center_x /= cmps.size(); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4674,7 +4674,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &active_cm->center_x, + &active_cm->runtime->center_x, bounds.xmin, bounds.xmax, ""); @@ -4686,11 +4686,11 @@ static void curvemap_buttons_layout(uiLayout *layout, rna_update_cb(C, cb); }); - active_cm->center_y = 0.0f; - for (const CurveMapPoint* cmp : cmps) { - active_cm->center_y += cmp->y; + active_cm->runtime->center_y = 0.0f; + for (const CurveMapPoint *cmp : cmps) { + active_cm->runtime->center_y += cmp->y; } - active_cm->center_y /= cmps.size(); + active_cm->runtime->center_y /= cmps.size(); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4699,7 +4699,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &active_cm->center_y, + &active_cm->runtime->center_y, bounds.ymin, bounds.ymax, ""); diff --git a/source/blender/makesdna/DNA_color_types.h b/source/blender/makesdna/DNA_color_types.h index 0f3207a3d1d..34e78332639 100644 --- a/source/blender/makesdna/DNA_color_types.h +++ b/source/blender/makesdna/DNA_color_types.h @@ -27,6 +27,12 @@ typedef struct CurveMapPoint { short flag, shorty; } CurveMapPoint; +typedef struct CurveMapRuntime { + /** Temp storage for multiple selections operation. */ + /** Center of selected points */ + float center_x, center_y; +} CurveMapRuntime; + /** #CurveMapPoint.flag */ enum { CUMA_SELECT = (1 << 0), @@ -48,8 +54,6 @@ typedef struct CurveMap { float ext_in[2], ext_out[2]; /** Actual curve. */ CurveMapPoint *curve; - /** Center of selected points */ - float center_x, center_y; /** Display and evaluate table. */ CurveMapPoint *table; @@ -60,6 +64,8 @@ typedef struct CurveMap { float premul_ext_out[2]; short default_handle_type; char _pad[6]; + + CurveMapRuntime *runtime; } CurveMap; typedef struct CurveMapping { -- 2.30.2 From d2606602df0bf3a706d30d764a58a74d7dc5c744 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Mon, 8 Apr 2024 00:18:45 +0800 Subject: [PATCH 08/15] 4.8 hue correct requires 3 curvemap --- .../blender/nodes/composite/nodes/node_composite_huecorrect.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc b/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc index 06dbded2c3f..87af74b0174 100644 --- a/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc +++ b/source/blender/nodes/composite/nodes/node_composite_huecorrect.cc @@ -32,7 +32,7 @@ static void cmp_node_huecorrect_declare(NodeDeclarationBuilder &b) static void node_composit_init_huecorrect(bNodeTree * /*ntree*/, bNode *node) { - node->storage = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + node->storage = BKE_curvemapping_add(3, 0.0f, 0.0f, 1.0f, 1.0f); CurveMapping *cumapping = (CurveMapping *)node->storage; -- 2.30.2 From dd8a6e296325c01145a269b8a68ae82554ba01b5 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Mon, 8 Apr 2024 00:19:07 +0800 Subject: [PATCH 09/15] 4.8 initializations and simplification --- .../blender/blenkernel/intern/colortools.cc | 20 ++++++++++++---- source/blender/blenkernel/intern/node.cc | 6 ----- .../templates/interface_templates.cc | 23 +++++++++++-------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index f49c2453a1c..a5dd5204c20 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -116,10 +116,10 @@ void BKE_curvemapping_free_data(CurveMapping *cumap) MEM_freeN(cumap->cm[a].premultable); cumap->cm[a].premultable = nullptr; } -// if (cumap->cm[a].runtime) { -// MEM_freeN(cumap->cm[a].runtime); -// cumap->cm[a].runtime = nullptr; -// } + // if (cumap->cm[a].runtime) { + // MEM_freeN(cumap->cm[a].runtime); + // cumap->cm[a].runtime = nullptr; + // } } } @@ -1360,6 +1360,16 @@ void BKE_curvemapping_init(CurveMapping *cumap) if (cumap->cm[a].table == nullptr) { curvemap_make_table(cumap, cumap->cm + a); } + } +} + +static void bke_curvemapping_runtime_init(CurveMapping *cumap) +{ + if (cumap == nullptr) { + return; + } + + for (int a = 0; a < CM_TOT; a++) { if (cumap->cm[a].runtime == nullptr) { cumap->cm[a].runtime = static_cast( MEM_callocN(sizeof(CurveMapRuntime), "curve runtime")); @@ -1428,6 +1438,8 @@ void BKE_curvemapping_blend_read(BlendDataReader *reader, CurveMapping *cumap) cumap->cm[a].premultable = nullptr; cumap->cm[a].runtime = nullptr; } + + bke_curvemapping_runtime_init(cumap); } /* ***************** Histogram **************** */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 4205c4c64b6..a6476374667 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -1067,12 +1067,6 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree) case TEX_NODE_CURVE_RGB: case TEX_NODE_CURVE_TIME: { BKE_curvemapping_blend_read(reader, static_cast(node->storage)); - for (int i = 0; i < 4; i++) { - auto runtime = static_cast(node->storage)->cm[i].runtime; - if(runtime == nullptr) - static_cast(node->storage)->cm[i].runtime = static_cast( - MEM_callocN(sizeof(CurveMapRuntime), "curve runtime")); - } break; } case SH_NODE_SCRIPT: { diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index ff59b53bf7f..4aa62aa9668 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4382,6 +4382,18 @@ static void curvemap_buttons_redraw(bContext &C) ED_region_tag_redraw(CTX_wm_region(&C)); } +static void curvemap_runtime_update(CurveMap *cm, const Vector &cmps) +{ + cm->runtime->center_x = 0.0f; + cm->runtime->center_y = 0.0f; + for (const CurveMapPoint *cmp : cmps) { + cm->runtime->center_x += cmp->x; + cm->runtime->center_y += cmp->y; + } + cm->runtime->center_x /= cmps.size(); + cm->runtime->center_y /= cmps.size(); +} + /** * \note Still unsure how this call evolves. * @@ -4661,11 +4673,7 @@ static void curvemap_buttons_layout(uiLayout *layout, } /* Curve handle position */ - active_cm->runtime->center_x = 0.0f; - for (const CurveMapPoint *cmp : cmps) { - active_cm->runtime->center_x += cmp->x; - } - active_cm->runtime->center_x /= cmps.size(); + curvemap_runtime_update(active_cm, cmps); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4686,11 +4694,6 @@ static void curvemap_buttons_layout(uiLayout *layout, rna_update_cb(C, cb); }); - active_cm->runtime->center_y = 0.0f; - for (const CurveMapPoint *cmp : cmps) { - active_cm->runtime->center_y += cmp->y; - } - active_cm->runtime->center_y /= cmps.size(); bt = uiDefButF(block, UI_BTYPE_NUM, 0, -- 2.30.2 From 294ccde79f84b267fe31c18683872406babeb4ee Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Mon, 8 Apr 2024 12:37:00 +0800 Subject: [PATCH 10/15] no pointers --- .../blender/blenkernel/intern/colortools.cc | 28 ++----------------- .../templates/interface_templates.cc | 16 +++++------ source/blender/makesdna/DNA_color_types.h | 6 ++-- 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index a5dd5204c20..8915c29fa1b 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -80,9 +80,6 @@ void BKE_curvemapping_set_defaults(CurveMapping *cumap, cumap->cm[a].curve[1].x = maxx; cumap->cm[a].curve[1].y = maxy; cumap->cm[a].curve[1].flag |= default_handle_type; - - cumap->cm[a].runtime = static_cast( - MEM_callocN(sizeof(CurveMapRuntime), "curve runtime")); } cumap->changed_timestamp = 0; @@ -116,10 +113,6 @@ void BKE_curvemapping_free_data(CurveMapping *cumap) MEM_freeN(cumap->cm[a].premultable); cumap->cm[a].premultable = nullptr; } - // if (cumap->cm[a].runtime) { - // MEM_freeN(cumap->cm[a].runtime); - // cumap->cm[a].runtime = nullptr; - // } } } @@ -960,8 +953,8 @@ void BKE_curvemap_shift(CurveMapping *cumap) for (int i = 0; i < cuma->totpoint; i++) { if (cmp[i].flag & CUMA_SELECT) { - cmp[i].x += cuma->runtime->center_x - center_x_pre; - cmp[i].y += cuma->runtime->center_y - center_y_pre; + cmp[i].x += cuma->runtime.center_x - center_x_pre; + cmp[i].y += cuma->runtime.center_y - center_y_pre; } } } @@ -1363,20 +1356,6 @@ void BKE_curvemapping_init(CurveMapping *cumap) } } -static void bke_curvemapping_runtime_init(CurveMapping *cumap) -{ - if (cumap == nullptr) { - return; - } - - for (int a = 0; a < CM_TOT; a++) { - if (cumap->cm[a].runtime == nullptr) { - cumap->cm[a].runtime = static_cast( - MEM_callocN(sizeof(CurveMapRuntime), "curve runtime")); - } - } -} - void BKE_curvemapping_table_F(const CurveMapping *cumap, float **array, int *size) { int a; @@ -1436,10 +1415,7 @@ void BKE_curvemapping_blend_read(BlendDataReader *reader, CurveMapping *cumap) BLO_read_data_address(reader, &cumap->cm[a].curve); cumap->cm[a].table = nullptr; cumap->cm[a].premultable = nullptr; - cumap->cm[a].runtime = nullptr; } - - bke_curvemapping_runtime_init(cumap); } /* ***************** Histogram **************** */ diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index 4aa62aa9668..f7288f7be54 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4384,14 +4384,14 @@ static void curvemap_buttons_redraw(bContext &C) static void curvemap_runtime_update(CurveMap *cm, const Vector &cmps) { - cm->runtime->center_x = 0.0f; - cm->runtime->center_y = 0.0f; + cm->runtime.center_x = 0.0f; + cm->runtime.center_y = 0.0f; for (const CurveMapPoint *cmp : cmps) { - cm->runtime->center_x += cmp->x; - cm->runtime->center_y += cmp->y; + cm->runtime.center_x += cmp->x; + cm->runtime.center_y += cmp->y; } - cm->runtime->center_x /= cmps.size(); - cm->runtime->center_y /= cmps.size(); + cm->runtime.center_x /= cmps.size(); + cm->runtime.center_y /= cmps.size(); } /** @@ -4682,7 +4682,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &active_cm->runtime->center_x, + &active_cm->runtime.center_x, bounds.xmin, bounds.xmax, ""); @@ -4702,7 +4702,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &active_cm->runtime->center_y, + &active_cm->runtime.center_y, bounds.ymin, bounds.ymax, ""); diff --git a/source/blender/makesdna/DNA_color_types.h b/source/blender/makesdna/DNA_color_types.h index 34e78332639..d5b652fa37c 100644 --- a/source/blender/makesdna/DNA_color_types.h +++ b/source/blender/makesdna/DNA_color_types.h @@ -27,11 +27,11 @@ typedef struct CurveMapPoint { short flag, shorty; } CurveMapPoint; -typedef struct CurveMapRuntime { +typedef struct CurveMap_Runtime { /** Temp storage for multiple selections operation. */ /** Center of selected points */ float center_x, center_y; -} CurveMapRuntime; +} CurveMap_Runtime; /** #CurveMapPoint.flag */ enum { @@ -65,7 +65,7 @@ typedef struct CurveMap { short default_handle_type; char _pad[6]; - CurveMapRuntime *runtime; + CurveMap_Runtime runtime; } CurveMap; typedef struct CurveMapping { -- 2.30.2 From daabfbb8575a81db5ac8312e7af57bb17abe36af Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Mon, 8 Apr 2024 19:32:00 +0800 Subject: [PATCH 11/15] 4.8 CurveProfile --- source/blender/blenkernel/BKE_colortools.hh | 6 +- source/blender/blenkernel/BKE_curveprofile.h | 12 ++++ .../blender/blenkernel/intern/colortools.cc | 47 +++++++++---- .../blender/blenkernel/intern/curveprofile.cc | 70 +++++++++++++++++++ .../templates/interface_templates.cc | 64 ++++++----------- .../blender/makesdna/DNA_curveprofile_types.h | 8 +++ 6 files changed, 148 insertions(+), 59 deletions(-) diff --git a/source/blender/blenkernel/BKE_colortools.hh b/source/blender/blenkernel/BKE_colortools.hh index b661d8b03c6..3da6a842631 100644 --- a/source/blender/blenkernel/BKE_colortools.hh +++ b/source/blender/blenkernel/BKE_colortools.hh @@ -62,12 +62,16 @@ CurveMapPoint *BKE_curvemap_insert(CurveMap *cuma, float x, float y); /** * Shift specified point from center. */ -void BKE_curvemap_shift(CurveMapping *cumap); +void BKE_translate_selection(CurveMap *cuma, const float delta_x, const float delta_y); +void BKE_curvemap_shift_center(CurveMapping *cumap); /** * \param type: #eBezTriple_Handle */ void BKE_curvemap_handle_set(CurveMap *cuma, int type); +void BKE_curvemap_runtime_update(CurveMap *cuma); +void BKE_curvemap_get_selection_center(CurveMap *cuma, float *center_x_out, float *center_y_out); + /** * \note only does current curvemap!. */ diff --git a/source/blender/blenkernel/BKE_curveprofile.h b/source/blender/blenkernel/BKE_curveprofile.h index 746279283cc..97dd2838563 100644 --- a/source/blender/blenkernel/BKE_curveprofile.h +++ b/source/blender/blenkernel/BKE_curveprofile.h @@ -64,6 +64,10 @@ bool BKE_curveprofile_move_point(struct CurveProfile *profile, bool snap, const float delta[2]); +void BKE_curveprofile_translate_selection(struct CurveProfile *profile, + const float delta_x, + const float delta_y); + /** * Removes a specific point from the path of control points. * \note Requires #BKE_curveprofile_update call after. @@ -113,6 +117,10 @@ void BKE_curveprofile_reset_view(struct CurveProfile *profile); * \note Requires #BKE_curveprofile_update call after. */ void BKE_curveprofile_reset(struct CurveProfile *profile); +/** + * Shift specified point from center. + */ +void BKE_curveprofile_shift_center(struct CurveProfile *profile); int BKE_curveprofile_table_size(const struct CurveProfile *profile); @@ -137,6 +145,7 @@ enum { * Controls removing doubles and clipping. */ void BKE_curveprofile_update(struct CurveProfile *profile, int update_flags); +void BKE_curveprofile_runtime_update(struct CurveProfile *profile); /** * Does a single evaluation along the profile's path. @@ -150,6 +159,9 @@ void BKE_curveprofile_evaluate_length_portion(const struct CurveProfile *profile float length_portion, float *x_out, float *y_out); +void BKE_curveprofile_get_selection_center(const struct CurveProfile *profile, + float *center_x_out, + float *center_y_out); void BKE_curveprofile_blend_write(struct BlendWriter *writer, const struct CurveProfile *profile); /** diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index 8915c29fa1b..d19e0c630eb 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -930,35 +930,54 @@ void BKE_curvemapping_premultiply(CurveMapping *cumap, bool restore) } /* ************************ more CurveMapping calls *************** */ -void BKE_curvemap_shift(CurveMapping *cumap) +void BKE_curvemap_runtime_update(CurveMap *cuma) { - CurveMap *cuma = cumap->cm + cumap->cur; - CurveMapPoint *cmp = cuma->curve; + BKE_curvemap_get_selection_center(cuma, &cuma->runtime.center_x, &cuma->runtime.center_y); +} - /* unmodified center */ - float center_x_pre = 0.0f; - float center_y_pre = 0.0f; +void BKE_curvemap_get_selection_center(CurveMap *cuma, float *center_x_out, float *center_y_out) +{ int n = 0; + *center_x_out = 0.0f; + *center_y_out = 0.0f; + for (int i = 0; i < cuma->totpoint; i++) { - if (cmp[i].flag & CUMA_SELECT) { - center_x_pre += cmp[i].x; - center_y_pre += cmp[i].y; + CurveMapPoint *pt = &cuma->curve[i]; + if (pt->flag & CUMA_SELECT) { + *center_x_out += pt->x; + *center_y_out += pt->y; n++; } } if (n > 0) { - center_x_pre /= n; - center_y_pre /= n; + *center_x_out /= n; + *center_y_out /= n; } +} +void BKE_translate_selection(CurveMap *cuma, const float delta_x, const float delta_y) +{ for (int i = 0; i < cuma->totpoint; i++) { - if (cmp[i].flag & CUMA_SELECT) { - cmp[i].x += cuma->runtime.center_x - center_x_pre; - cmp[i].y += cuma->runtime.center_y - center_y_pre; + CurveMapPoint *pt = &cuma->curve[i]; + if (pt->flag & CUMA_SELECT) { + pt->x += delta_x; + pt->y += delta_y; } } } +void BKE_curvemap_shift_center(CurveMapping *cumap) +{ + CurveMap *cuma = cumap->cm + cumap->cur; + + /* unmodified center */ + float center_x_pre = 0.0f; + float center_y_pre = 0.0f; + BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); + BKE_translate_selection( + cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); +} + void BKE_curvemapping_changed(CurveMapping *cumap, const bool rem_doubles) { CurveMap *cuma = cumap->cm + cumap->cur; diff --git a/source/blender/blenkernel/intern/curveprofile.cc b/source/blender/blenkernel/intern/curveprofile.cc index 93445222f79..b19be94c16f 100644 --- a/source/blender/blenkernel/intern/curveprofile.cc +++ b/source/blender/blenkernel/intern/curveprofile.cc @@ -194,6 +194,37 @@ bool BKE_curveprofile_move_point(CurveProfile *profile, return false; } +void BKE_curveprofile_translate_selection(struct CurveProfile *profile, + const float delta_x, + const float delta_y) +{ + for (int i = 0; i < profile->path_len; i++) { + CurveProfilePoint *pt = &profile->path[i]; + if (pt->flag & PROF_SELECT) { + pt->x += delta_x; + pt->y += delta_y; + } + if (pt->flag & PROF_H1_SELECT) { + pt->h1_loc[0] += delta_x; + pt->h1_loc[1] += delta_y; + } + if (pt->flag & PROF_H2_SELECT) { + pt->h2_loc[0] += delta_x; + pt->h2_loc[1] += delta_y; + } + } +} + +void BKE_curveprofile_shift_center(CurveProfile *profile) +{ + /* unmodified center */ + float center_x_pre = 0.0f; + float center_y_pre = 0.0f; + BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); + BKE_curveprofile_translate_selection( + profile, profile->runtime.center_x - center_x_pre, profile->runtime.center_y - center_y_pre); +} + bool BKE_curveprofile_remove_point(CurveProfile *profile, CurveProfilePoint *point) { /* Must have 2 points minimum. */ @@ -1020,6 +1051,45 @@ void BKE_curveprofile_update(CurveProfile *profile, const int update_flags) } } +void BKE_curveprofile_runtime_update(struct CurveProfile *profile) +{ + BKE_curveprofile_get_selection_center( + profile, &profile->runtime.center_x, &profile->runtime.center_y); +} + +void BKE_curveprofile_get_selection_center(const struct CurveProfile *profile, + float *center_x_out, + float *center_y_out) +{ + int n = 0; + *center_x_out = 0.0f; + *center_y_out = 0.0f; + + for (int i = 0; i < profile->path_len; i++) { + CurveProfilePoint *pt = &profile->path[i]; + if (pt->flag & PROF_SELECT) { + *center_x_out += pt->x; + *center_y_out += pt->y; + n++; + } + if (pt->flag & PROF_H1_SELECT) { + *center_x_out += pt->h1_loc[0]; + *center_y_out += pt->h1_loc[1]; + n++; + } + if (pt->flag & PROF_H2_SELECT) { + *center_x_out += pt->h2_loc[0]; + *center_y_out += pt->h2_loc[1]; + n++; + } + } + + if (n > 0) { + *center_x_out /= n; + *center_y_out /= n; + } +} + void BKE_curveprofile_evaluate_length_portion(const CurveProfile *profile, float length_portion, float *x_out, diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index f7288f7be54..0fcc38cec1d 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4382,18 +4382,6 @@ static void curvemap_buttons_redraw(bContext &C) ED_region_tag_redraw(CTX_wm_region(&C)); } -static void curvemap_runtime_update(CurveMap *cm, const Vector &cmps) -{ - cm->runtime.center_x = 0.0f; - cm->runtime.center_y = 0.0f; - for (const CurveMapPoint *cmp : cmps) { - cm->runtime.center_x += cmp->x; - cm->runtime.center_y += cmp->y; - } - cm->runtime.center_x /= cmps.size(); - cm->runtime.center_y /= cmps.size(); -} - /** * \note Still unsure how this call evolves. * @@ -4673,7 +4661,7 @@ static void curvemap_buttons_layout(uiLayout *layout, } /* Curve handle position */ - curvemap_runtime_update(active_cm, cmps); + BKE_curvemap_runtime_update(active_cm); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4689,7 +4677,7 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { - BKE_curvemap_shift(cumap); + BKE_curvemap_shift_center(cumap); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -4709,7 +4697,7 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { - BKE_curvemap_shift(cumap); + BKE_curvemap_shift_center(cumap); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -5153,36 +5141,21 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const 1.0f, ""); - /* Position sliders for (first) selected point */ - int i; - float *selection_x, *selection_y; + /* Position sliders for all selected points */ + Vector cfps; bool point_last_or_first = false; - CurveProfilePoint *point = nullptr; - 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; + for (int i = 0; i < profile->path_len; i++) { + if (profile->path[i].flag & (PROF_SELECT | PROF_H1_SELECT | PROF_H2_SELECT)) { + cfps.append(&profile->path[i]); + if (ELEM(i, 0, profile->path_len - 1) && profile->path[i].flag & PROF_SELECT) { + point_last_or_first = true; + } } - 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 (ELEM(i, 0, profile->path_len - 1)) { - point_last_or_first = true; } - /* Selected point data */ - rctf bounds; - if (point) { + /* Selected points data */ + if (!cfps.is_empty()) { + rctf bounds; if (profile->flag & PROF_USE_CLIP) { bounds = profile->clip_rect; } @@ -5193,7 +5166,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const row = uiLayoutRow(layout, true); - PointerRNA point_ptr = RNA_pointer_create(ptr->owner_id, &RNA_CurveProfilePoint, point); + PointerRNA point_ptr = RNA_pointer_create(ptr->owner_id, &RNA_CurveProfilePoint, cfps[0]); PropertyRNA *prop_handle_type = RNA_struct_find_property(&point_ptr, "handle_type_1"); uiItemFullR(row, &point_ptr, @@ -5205,6 +5178,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const ICON_NONE); /* Position */ + BKE_curveprofile_runtime_update(profile); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -5213,13 +5187,14 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - selection_x, + &profile->runtime.center_x, bounds.xmin, bounds.xmax, ""); UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [profile, cb](bContext &C) { + BKE_curveprofile_shift_center(profile); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); @@ -5234,13 +5209,14 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - selection_y, + &profile->runtime.center_y, bounds.ymin, bounds.ymax, ""); UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [profile, cb](bContext &C) { + BKE_curveprofile_shift_center(profile); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); diff --git a/source/blender/makesdna/DNA_curveprofile_types.h b/source/blender/makesdna/DNA_curveprofile_types.h index 260441762fa..47dd3719ef1 100644 --- a/source/blender/makesdna/DNA_curveprofile_types.h +++ b/source/blender/makesdna/DNA_curveprofile_types.h @@ -31,6 +31,12 @@ typedef struct CurveProfilePoint { struct CurveProfile *profile; } CurveProfilePoint; +typedef struct CurveProfile_Runtime { + /** Temp storage for multiple selections operation. */ + /** Center of selected points */ + float center_x, center_y; +} CurveProfile_Runtime; + /** #CurveProfilePoint.flag */ enum { PROF_SELECT = (1 << 0), @@ -58,6 +64,8 @@ typedef struct CurveProfile { int changed_timestamp; /** Widget's current view, and clipping rect (is default rect too). */ rctf view_rect, clip_rect; + + CurveProfile_Runtime runtime; } CurveProfile; /** #CurveProfile.flag */ -- 2.30.2 From 6ee90308669fe902824b059087b697a413c55862 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Mon, 8 Apr 2024 19:56:28 +0800 Subject: [PATCH 12/15] Update interface_templates.cc --- .../editors/interface/templates/interface_templates.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index 0fcc38cec1d..90cf692d52e 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4606,7 +4606,7 @@ static void curvemap_buttons_layout(uiLayout *layout, rna_update_cb(C, cb); }); - for (CurveMapPoint *cmp : cmps) { + for (const CurveMapPoint *cmp : cmps) { const bool auto_anim_vec = ((cmp->flag & CUMA_HANDLE_AUTO_ANIM) == false) && ((cmp->flag & CUMA_HANDLE_VECTOR) == false); bt->flag |= UI_SELECT_DRAW && auto_anim_vec; @@ -4631,7 +4631,7 @@ static void curvemap_buttons_layout(uiLayout *layout, rna_update_cb(C, cb); }); - for (CurveMapPoint *cmp : cmps) { + for (const CurveMapPoint *cmp : cmps) { const bool vec = (cmp->flag & CUMA_HANDLE_VECTOR); bt->flag |= UI_SELECT_DRAW && vec; } @@ -4655,7 +4655,7 @@ static void curvemap_buttons_layout(uiLayout *layout, rna_update_cb(C, cb); }); - for (CurveMapPoint *cmp : cmps) { + for (const CurveMapPoint *cmp : cmps) { const bool auto_anim = (cmp->flag & CUMA_HANDLE_AUTO_ANIM); bt->flag |= UI_SELECT_DRAW && auto_anim; } @@ -5166,6 +5166,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const row = uiLayoutRow(layout, true); + /* TODO: Buttons for multiple selections */ PointerRNA point_ptr = RNA_pointer_create(ptr->owner_id, &RNA_CurveProfilePoint, cfps[0]); PropertyRNA *prop_handle_type = RNA_struct_find_property(&point_ptr, "handle_type_1"); uiItemFullR(row, -- 2.30.2 From 5f4a83e26cdb71d3bb42c094936425ace9ec7055 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Wed, 10 Apr 2024 15:07:25 +0800 Subject: [PATCH 13/15] 4.10 unnecessary code reuse --- source/blender/blenkernel/BKE_colortools.hh | 1 - source/blender/blenkernel/BKE_curveprofile.h | 4 --- .../blender/blenkernel/intern/colortools.cc | 12 --------- .../blender/blenkernel/intern/curveprofile.cc | 10 ------- .../templates/interface_templates.cc | 26 ++++++++++++++++--- 5 files changed, 22 insertions(+), 31 deletions(-) diff --git a/source/blender/blenkernel/BKE_colortools.hh b/source/blender/blenkernel/BKE_colortools.hh index 3da6a842631..864eb0e00de 100644 --- a/source/blender/blenkernel/BKE_colortools.hh +++ b/source/blender/blenkernel/BKE_colortools.hh @@ -63,7 +63,6 @@ CurveMapPoint *BKE_curvemap_insert(CurveMap *cuma, float x, float y); * Shift specified point from center. */ void BKE_translate_selection(CurveMap *cuma, const float delta_x, const float delta_y); -void BKE_curvemap_shift_center(CurveMapping *cumap); /** * \param type: #eBezTriple_Handle */ diff --git a/source/blender/blenkernel/BKE_curveprofile.h b/source/blender/blenkernel/BKE_curveprofile.h index 97dd2838563..19e3b2f303d 100644 --- a/source/blender/blenkernel/BKE_curveprofile.h +++ b/source/blender/blenkernel/BKE_curveprofile.h @@ -117,10 +117,6 @@ void BKE_curveprofile_reset_view(struct CurveProfile *profile); * \note Requires #BKE_curveprofile_update call after. */ void BKE_curveprofile_reset(struct CurveProfile *profile); -/** - * Shift specified point from center. - */ -void BKE_curveprofile_shift_center(struct CurveProfile *profile); int BKE_curveprofile_table_size(const struct CurveProfile *profile); diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index d19e0c630eb..538ea008e53 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -966,18 +966,6 @@ void BKE_translate_selection(CurveMap *cuma, const float delta_x, const float de } } -void BKE_curvemap_shift_center(CurveMapping *cumap) -{ - CurveMap *cuma = cumap->cm + cumap->cur; - - /* unmodified center */ - float center_x_pre = 0.0f; - float center_y_pre = 0.0f; - BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); - BKE_translate_selection( - cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); -} - void BKE_curvemapping_changed(CurveMapping *cumap, const bool rem_doubles) { CurveMap *cuma = cumap->cm + cumap->cur; diff --git a/source/blender/blenkernel/intern/curveprofile.cc b/source/blender/blenkernel/intern/curveprofile.cc index b19be94c16f..b644522ad22 100644 --- a/source/blender/blenkernel/intern/curveprofile.cc +++ b/source/blender/blenkernel/intern/curveprofile.cc @@ -215,16 +215,6 @@ void BKE_curveprofile_translate_selection(struct CurveProfile *profile, } } -void BKE_curveprofile_shift_center(CurveProfile *profile) -{ - /* unmodified center */ - float center_x_pre = 0.0f; - float center_y_pre = 0.0f; - BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); - BKE_curveprofile_translate_selection( - profile, profile->runtime.center_x - center_x_pre, profile->runtime.center_y - center_y_pre); -} - bool BKE_curveprofile_remove_point(CurveProfile *profile, CurveProfilePoint *point) { /* Must have 2 points minimum. */ diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index 90cf692d52e..efc70038e7f 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4677,7 +4677,12 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { - BKE_curvemap_shift_center(cumap); + CurveMap* cuma = cumap->cm + cumap->cur; + float center_x_pre = 0.0f; + float center_y_pre = 0.0f; + BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); + BKE_translate_selection( + cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -4697,7 +4702,12 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { - BKE_curvemap_shift_center(cumap); + CurveMap* cuma = cumap->cm + cumap->cur; + float center_x_pre = 0.0f; + float center_y_pre = 0.0f; + BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); + BKE_translate_selection( + cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -5195,7 +5205,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [profile, cb](bContext &C) { - BKE_curveprofile_shift_center(profile); + float center_x_pre = 0.0f; + float center_y_pre = 0.0f; + BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); + BKE_curveprofile_translate_selection( + profile, profile->runtime.center_x - center_x_pre, profile->runtime.center_y - center_y_pre); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); @@ -5217,7 +5231,11 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [profile, cb](bContext &C) { - BKE_curveprofile_shift_center(profile); + float center_x_pre = 0.0f; + float center_y_pre = 0.0f; + BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); + BKE_curveprofile_translate_selection( + profile, profile->runtime.center_x - center_x_pre, profile->runtime.center_y - center_y_pre); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); -- 2.30.2 From 77f7a5ed298f5216da68e5dc163e74bac553c8e4 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Sun, 14 Apr 2024 19:27:43 +0800 Subject: [PATCH 14/15] 4.14 formating --- source/blender/blenkernel/BKE_colortools.hh | 1 - source/blender/blenkernel/BKE_curveprofile.h | 1 - .../blender/blenkernel/intern/colortools.cc | 5 ---- .../blender/blenkernel/intern/curveprofile.cc | 6 ----- .../templates/interface_templates.cc | 24 +++++++++++-------- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/source/blender/blenkernel/BKE_colortools.hh b/source/blender/blenkernel/BKE_colortools.hh index 864eb0e00de..5ffaad2162d 100644 --- a/source/blender/blenkernel/BKE_colortools.hh +++ b/source/blender/blenkernel/BKE_colortools.hh @@ -68,7 +68,6 @@ void BKE_translate_selection(CurveMap *cuma, const float delta_x, const float de */ void BKE_curvemap_handle_set(CurveMap *cuma, int type); -void BKE_curvemap_runtime_update(CurveMap *cuma); void BKE_curvemap_get_selection_center(CurveMap *cuma, float *center_x_out, float *center_y_out); /** diff --git a/source/blender/blenkernel/BKE_curveprofile.h b/source/blender/blenkernel/BKE_curveprofile.h index 19e3b2f303d..045f11b736e 100644 --- a/source/blender/blenkernel/BKE_curveprofile.h +++ b/source/blender/blenkernel/BKE_curveprofile.h @@ -141,7 +141,6 @@ enum { * Controls removing doubles and clipping. */ void BKE_curveprofile_update(struct CurveProfile *profile, int update_flags); -void BKE_curveprofile_runtime_update(struct CurveProfile *profile); /** * Does a single evaluation along the profile's path. diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index 538ea008e53..bf4b77aa4c1 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -930,11 +930,6 @@ void BKE_curvemapping_premultiply(CurveMapping *cumap, bool restore) } /* ************************ more CurveMapping calls *************** */ -void BKE_curvemap_runtime_update(CurveMap *cuma) -{ - BKE_curvemap_get_selection_center(cuma, &cuma->runtime.center_x, &cuma->runtime.center_y); -} - void BKE_curvemap_get_selection_center(CurveMap *cuma, float *center_x_out, float *center_y_out) { int n = 0; diff --git a/source/blender/blenkernel/intern/curveprofile.cc b/source/blender/blenkernel/intern/curveprofile.cc index b644522ad22..b0cfe1758db 100644 --- a/source/blender/blenkernel/intern/curveprofile.cc +++ b/source/blender/blenkernel/intern/curveprofile.cc @@ -1041,12 +1041,6 @@ void BKE_curveprofile_update(CurveProfile *profile, const int update_flags) } } -void BKE_curveprofile_runtime_update(struct CurveProfile *profile) -{ - BKE_curveprofile_get_selection_center( - profile, &profile->runtime.center_x, &profile->runtime.center_y); -} - void BKE_curveprofile_get_selection_center(const struct CurveProfile *profile, float *center_x_out, float *center_y_out) diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index efc70038e7f..2a24b9f31e6 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -4661,7 +4661,8 @@ static void curvemap_buttons_layout(uiLayout *layout, } /* Curve handle position */ - BKE_curvemap_runtime_update(active_cm); + BKE_curvemap_get_selection_center( + active_cm, &active_cm->runtime.center_x, &active_cm->runtime.center_y); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4677,12 +4678,12 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { - CurveMap* cuma = cumap->cm + cumap->cur; + CurveMap *cuma = cumap->cm + cumap->cur; float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); BKE_translate_selection( - cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); + cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -4702,12 +4703,12 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { - CurveMap* cuma = cumap->cm + cumap->cur; + CurveMap *cuma = cumap->cm + cumap->cur; float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); BKE_translate_selection( - cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); + cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -5189,7 +5190,8 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const ICON_NONE); /* Position */ - BKE_curveprofile_runtime_update(profile); + BKE_curveprofile_get_selection_center( + profile, &profile->runtime.center_x, &profile->runtime.center_y); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -5208,8 +5210,9 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); - BKE_curveprofile_translate_selection( - profile, profile->runtime.center_x - center_x_pre, profile->runtime.center_y - center_y_pre); + BKE_curveprofile_translate_selection(profile, + profile->runtime.center_x - center_x_pre, + profile->runtime.center_y - center_y_pre); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); @@ -5234,8 +5237,9 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); - BKE_curveprofile_translate_selection( - profile, profile->runtime.center_x - center_x_pre, profile->runtime.center_y - center_y_pre); + BKE_curveprofile_translate_selection(profile, + profile->runtime.center_x - center_x_pre, + profile->runtime.center_y - center_y_pre); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); -- 2.30.2 From dc5f2fe6af00a64b1677596ed115da550bb7aa31 Mon Sep 17 00:00:00 2001 From: XDzZyq Date: Wed, 24 Apr 2024 15:29:54 +0800 Subject: [PATCH 15/15] 4.24 runtime_storage --- .../blender/blenkernel/intern/colortools.cc | 8 ++ .../blender/blenkernel/intern/curveprofile.cc | 6 ++ .../templates/interface_templates.cc | 79 ++++++++++++++----- source/blender/makesdna/DNA_color_types.h | 4 +- .../blender/makesdna/DNA_curveprofile_types.h | 4 +- 5 files changed, 77 insertions(+), 24 deletions(-) diff --git a/source/blender/blenkernel/intern/colortools.cc b/source/blender/blenkernel/intern/colortools.cc index bf4b77aa4c1..2a800a19a35 100644 --- a/source/blender/blenkernel/intern/colortools.cc +++ b/source/blender/blenkernel/intern/colortools.cc @@ -113,6 +113,9 @@ void BKE_curvemapping_free_data(CurveMapping *cumap) MEM_freeN(cumap->cm[a].premultable); cumap->cm[a].premultable = nullptr; } + if (cumap->cm[a].runtime.runtime_storage) { + cumap->cm[a].runtime.runtime_storage_free(cumap->cm[a].runtime.runtime_storage); + } } } @@ -141,6 +144,9 @@ void BKE_curvemapping_copy_data(CurveMapping *target, const CurveMapping *cumap) target->cm[a].premultable = static_cast( MEM_dupallocN(cumap->cm[a].premultable)); } + if (cumap->cm[a].runtime.runtime_storage) { + target->cm[a].runtime.runtime_storage = MEM_dupallocN(cumap->cm[a].runtime.runtime_storage); + } } } @@ -1417,6 +1423,8 @@ void BKE_curvemapping_blend_read(BlendDataReader *reader, CurveMapping *cumap) BLO_read_data_address(reader, &cumap->cm[a].curve); cumap->cm[a].table = nullptr; cumap->cm[a].premultable = nullptr; + cumap->cm[a].runtime.runtime_storage = nullptr; + cumap->cm[a].runtime.runtime_storage_free = nullptr; } } diff --git a/source/blender/blenkernel/intern/curveprofile.cc b/source/blender/blenkernel/intern/curveprofile.cc index b0cfe1758db..72e12a741b5 100644 --- a/source/blender/blenkernel/intern/curveprofile.cc +++ b/source/blender/blenkernel/intern/curveprofile.cc @@ -47,6 +47,9 @@ void BKE_curveprofile_free_data(CurveProfile *profile) MEM_SAFE_FREE(profile->path); MEM_SAFE_FREE(profile->table); MEM_SAFE_FREE(profile->segments); + if (profile->runtime.runtime_storage) { + profile->runtime.runtime_storage_free(profile->runtime.runtime_storage); + } } void BKE_curveprofile_free(CurveProfile *profile) @@ -64,6 +67,7 @@ void BKE_curveprofile_copy_data(CurveProfile *target, const CurveProfile *profil target->path = (CurveProfilePoint *)MEM_dupallocN(profile->path); target->table = (CurveProfilePoint *)MEM_dupallocN(profile->table); target->segments = (CurveProfilePoint *)MEM_dupallocN(profile->segments); + target->runtime.runtime_storage = MEM_dupallocN(profile->runtime.runtime_storage); /* Update the reference the points have to the profile. */ for (int i = 0; i < target->path_len; i++) { @@ -92,6 +96,8 @@ void BKE_curveprofile_blend_read(BlendDataReader *reader, CurveProfile *profile) BLO_read_data_address(reader, &profile->path); profile->table = nullptr; profile->segments = nullptr; + profile->runtime.runtime_storage = nullptr; + profile->runtime.runtime_storage_free = nullptr; /* Reset the points' pointers to the profile. */ for (int i = 0; i < profile->path_len; i++) { diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index 2a24b9f31e6..e9cdeade6fe 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -107,6 +107,13 @@ using blender::Vector; #define TEMPLATE_SEARCH_TEXTBUT_MIN_WIDTH (UI_UNIT_X * 4) #define TEMPLATE_SEARCH_TEXTBUT_HEIGHT UI_UNIT_Y +/* temporary struct for storing curvemap/curveprofile properties */ + +struct CurveRuntimeProperties { + float center_x; + float center_y; +}; + /* -------------------------------------------------------------------- */ /** \name Header Template * \{ */ @@ -4382,6 +4389,24 @@ static void curvemap_buttons_redraw(bContext &C) ED_region_tag_redraw(CTX_wm_region(&C)); } +static CurveRuntimeProperties *curvemap_runtime_props_ensure(CurveMap *cum) +{ + if (cum->runtime.runtime_storage == nullptr) { + CurveRuntimeProperties *crp = static_cast( + MEM_callocN(sizeof(CurveRuntimeProperties), "CurveRuntimeProperties")); + /* Construct C++ structures in otherwise zero initialized struct. */ + new (crp) CurveRuntimeProperties(); + + cum->runtime.runtime_storage = crp; + cum->runtime.runtime_storage_free = [](void *properties_storage) { + CurveRuntimeProperties *tar = static_cast(properties_storage); + + MEM_delete(tar); + }; + } + return static_cast(cum->runtime.runtime_storage); +} + /** * \note Still unsure how this call evolves. * @@ -4572,6 +4597,7 @@ static void curvemap_buttons_layout(uiLayout *layout, if (!cmps.is_empty()) { CurveMap *active_cm = cumap->cm + cumap->cur; + CurveRuntimeProperties *crp = curvemap_runtime_props_ensure(active_cm); rctf bounds; if (cumap->flag & CUMA_DO_CLIP) { @@ -4661,8 +4687,7 @@ static void curvemap_buttons_layout(uiLayout *layout, } /* Curve handle position */ - BKE_curvemap_get_selection_center( - active_cm, &active_cm->runtime.center_x, &active_cm->runtime.center_y); + BKE_curvemap_get_selection_center(active_cm, &crp->center_x, &crp->center_y); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -4671,7 +4696,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &active_cm->runtime.center_x, + &crp->center_x, bounds.xmin, bounds.xmax, ""); @@ -4679,11 +4704,11 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { CurveMap *cuma = cumap->cm + cumap->cur; + CurveRuntimeProperties *crp = curvemap_runtime_props_ensure(cuma); float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); - BKE_translate_selection( - cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); + BKE_translate_selection(cuma, crp->center_x - center_x_pre, crp->center_y - center_y_pre); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -4696,7 +4721,7 @@ static void curvemap_buttons_layout(uiLayout *layout, 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &active_cm->runtime.center_y, + &crp->center_y, bounds.ymin, bounds.ymax, ""); @@ -4704,11 +4729,11 @@ static void curvemap_buttons_layout(uiLayout *layout, UI_but_number_precision_set(bt, 5); UI_but_func_set(bt, [cumap, cb](bContext &C) { CurveMap *cuma = cumap->cm + cumap->cur; + CurveRuntimeProperties *crp = curvemap_runtime_props_ensure(cuma); float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curvemap_get_selection_center(cuma, ¢er_x_pre, ¢er_y_pre); - BKE_translate_selection( - cuma, cuma->runtime.center_x - center_x_pre, cuma->runtime.center_y - center_y_pre); + BKE_translate_selection(cuma, crp->center_x - center_x_pre, crp->center_y - center_y_pre); BKE_curvemapping_changed(cumap, true); rna_update_cb(C, cb); }); @@ -4921,6 +4946,22 @@ static bool curve_profile_can_zoom_out(CurveProfile *profile) return BLI_rctf_size_x(&profile->view_rect) < BLI_rctf_size_x(&profile->clip_rect); } +static CurveRuntimeProperties *curve_profile_runtime_props_ensure(CurveProfile *profile) +{ + if (profile->runtime.runtime_storage == nullptr) { + CurveRuntimeProperties *crp = static_cast( + MEM_callocN(sizeof(CurveRuntimeProperties), "CurveRuntimeProperties")); + /* Construct C++ structures in otherwise zero initialized struct. */ + new (crp) CurveRuntimeProperties(); + + profile->runtime.runtime_storage = crp; + profile->runtime.runtime_storage_free = [](void *properties_storage) { + MEM_delete(static_cast(properties_storage)); + }; + } + return static_cast(profile->runtime.runtime_storage); +} + static void curve_profile_zoom_in(bContext *C, CurveProfile *profile) { if (curve_profile_can_zoom_in(profile)) { @@ -4980,6 +5021,7 @@ static void curve_profile_zoom_out(bContext *C, CurveProfile *profile) static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const RNAUpdateCb &cb) { CurveProfile *profile = static_cast(ptr->data); + CurveRuntimeProperties *crp = curve_profile_runtime_props_ensure(profile); uiBut *bt; uiBlock *block = uiLayoutGetBlock(layout); @@ -5190,8 +5232,7 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const ICON_NONE); /* Position */ - BKE_curveprofile_get_selection_center( - profile, &profile->runtime.center_x, &profile->runtime.center_y); + BKE_curveprofile_get_selection_center(profile, &crp->center_x, &crp->center_y); bt = uiDefButF(block, UI_BTYPE_NUM, 0, @@ -5200,19 +5241,18 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const 2 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &profile->runtime.center_x, + &crp->center_x, bounds.xmin, bounds.xmax, ""); UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); - UI_but_func_set(bt, [profile, cb](bContext &C) { + UI_but_func_set(bt, [profile, crp, cb](bContext &C) { float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); - BKE_curveprofile_translate_selection(profile, - profile->runtime.center_x - center_x_pre, - profile->runtime.center_y - center_y_pre); + BKE_curveprofile_translate_selection( + profile, crp->center_x - center_x_pre, crp->center_y - center_y_pre); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); @@ -5227,19 +5267,18 @@ static void CurveProfile_buttons_layout(uiLayout *layout, PointerRNA *ptr, const 1 * UI_UNIT_Y, UI_UNIT_X * 10, UI_UNIT_Y, - &profile->runtime.center_y, + &crp->center_y, bounds.ymin, bounds.ymax, ""); UI_but_number_step_size_set(bt, 1); UI_but_number_precision_set(bt, 5); - UI_but_func_set(bt, [profile, cb](bContext &C) { + UI_but_func_set(bt, [profile, crp, cb](bContext &C) { float center_x_pre = 0.0f; float center_y_pre = 0.0f; BKE_curveprofile_get_selection_center(profile, ¢er_x_pre, ¢er_y_pre); - BKE_curveprofile_translate_selection(profile, - profile->runtime.center_x - center_x_pre, - profile->runtime.center_y - center_y_pre); + BKE_curveprofile_translate_selection( + profile, crp->center_x - center_x_pre, crp->center_y - center_y_pre); BKE_curveprofile_update(profile, PROF_UPDATE_REMOVE_DOUBLES | PROF_UPDATE_CLIP); rna_update_cb(C, cb); }); diff --git a/source/blender/makesdna/DNA_color_types.h b/source/blender/makesdna/DNA_color_types.h index d5b652fa37c..9da2a592163 100644 --- a/source/blender/makesdna/DNA_color_types.h +++ b/source/blender/makesdna/DNA_color_types.h @@ -29,8 +29,8 @@ typedef struct CurveMapPoint { typedef struct CurveMap_Runtime { /** Temp storage for multiple selections operation. */ - /** Center of selected points */ - float center_x, center_y; + void *runtime_storage; + void (*runtime_storage_free)(void *properties_storage); } CurveMap_Runtime; /** #CurveMapPoint.flag */ diff --git a/source/blender/makesdna/DNA_curveprofile_types.h b/source/blender/makesdna/DNA_curveprofile_types.h index 47dd3719ef1..3d9ca11e56a 100644 --- a/source/blender/makesdna/DNA_curveprofile_types.h +++ b/source/blender/makesdna/DNA_curveprofile_types.h @@ -33,8 +33,8 @@ typedef struct CurveProfilePoint { typedef struct CurveProfile_Runtime { /** Temp storage for multiple selections operation. */ - /** Center of selected points */ - float center_x, center_y; + void *runtime_storage; + void (*runtime_storage_free)(void *properties_storage); } CurveProfile_Runtime; /** #CurveProfilePoint.flag */ -- 2.30.2