Skip to content

Commit 358ae13

Browse files
committed
Store node render with node, not registry
1 parent 9fd7aa3 commit 358ae13

File tree

3 files changed

+84
-88
lines changed

3 files changed

+84
-88
lines changed

src/LabSoundInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ void CreateEntities(shared_ptr<lab::AudioNode> audio_node, lab::noodle::NoodleNo
123123
if (nullptr != dynamic_cast<lab::AnalyserNode*>(audio_node.get()))
124124
{
125125
g_audio_context->addAutomaticPullNode(audio_node);
126-
registry.emplace<lab::noodle::NodeRender>(audio_node_id.id,
126+
node.render =
127127
lab::noodle::NodeRender{
128128
[](ln_Node id, lab::noodle::vec2 ul_ws, lab::noodle::vec2 lr_ws, float scale, void* drawList) {
129129
DrawSpectrum(id.id, {ul_ws.x, ul_ws.y}, {lr_ws.x, lr_ws.y}, scale, reinterpret_cast<ImDrawList*>(drawList));
130130
}
131-
});
131+
};
132132
}
133133

134134
//---------- inputs

src/lab_noodle.cpp

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,28 @@ namespace noodle {
9090

9191

9292

93-
vec2 GraphPinLayout::ul_ws(Canvas& canvas) const
93+
vec2 NoodlePinGraphic::ul_ws(Canvas& canvas) const
9494
{
95-
float x = column_number * GraphNodeLayout::k_column_width();
95+
float x = column_number * NoodleNodeGraphic::k_column_width();
9696
ImVec2 no = { node_origin_cs.x, node_origin_cs.y };
9797
ImVec2 res = (no + ImVec2{ x, pos_y_cs }) * canvas.scale;
9898
ImVec2 o_off = { canvas.origin_offset_ws.x, canvas.origin_offset_ws.y };
9999
ImVec2 w_off = { canvas.window_origin_offset_ws.x, canvas.window_origin_offset_ws.y };
100100
res = res + o_off + w_off;
101101
return { res.x, res.y };
102102
}
103-
bool GraphPinLayout::pin_contains_cs_point(Canvas& canvas, float x, float y) const
103+
bool NoodlePinGraphic::pin_contains_cs_point(Canvas& canvas, float x, float y) const
104104
{
105105
ImVec2 no = { node_origin_cs.x, node_origin_cs.y };
106-
ImVec2 ul = (no + ImVec2{ column_number * GraphNodeLayout::k_column_width(), pos_y_cs });
106+
ImVec2 ul = (no + ImVec2{ column_number * NoodleNodeGraphic::k_column_width(), pos_y_cs });
107107
ImVec2 lr = { ul.x + k_width(), ul.y + k_height() };
108108
return x >= ul.x && x <= lr.x && y >= ul.y && y <= lr.y;
109109
}
110-
bool GraphPinLayout::label_contains_cs_point(Canvas& canvas, float x, float y) const
110+
bool NoodlePinGraphic::label_contains_cs_point(Canvas& canvas, float x, float y) const
111111
{
112112
ImVec2 no = { node_origin_cs.x, node_origin_cs.y };
113-
ImVec2 ul = (no + ImVec2{ column_number * GraphNodeLayout::k_column_width(), pos_y_cs });
114-
ImVec2 lr = { ul.x + GraphNodeLayout::k_column_width(), ul.y + k_height() };
113+
ImVec2 ul = (no + ImVec2{ column_number * NoodleNodeGraphic::k_column_width(), pos_y_cs });
114+
ImVec2 lr = { ul.x + NoodleNodeGraphic::k_column_width(), ul.y + k_height() };
115115
ul.x += k_width();
116116
//printf("m(%0.1f, %0.1f) ul(%0.1f, %0.1f) lr(%01.f, %0.1f)\n", x, y, ul.x, ul.y, lr.x, lr.y);
117117
return x >= ul.x && x <= lr.x && y >= ul.y && y <= lr.y;
@@ -327,8 +327,8 @@ namespace noodle {
327327
provider._noodleNodes[edit._device_node] = NoodleNode("Device", conformed_name, edit._device_node);
328328

329329
provider.create_runtime_context(edit._device_node);
330-
registry.emplace<GraphNodeLayout>(edit._device_node.id,
331-
GraphNodeLayout{ nullptr, NoodleGraphicLayer::Nodes, { canvas_pos.x, canvas_pos.y } });
330+
registry.emplace<NoodleNodeGraphic>(edit._device_node.id,
331+
NoodleNodeGraphic{ nullptr, NoodleGraphicLayer::Nodes, { canvas_pos.x, canvas_pos.y } });
332332

333333
provider.associate(edit._device_node, conformed_name);
334334

@@ -349,8 +349,8 @@ namespace noodle {
349349
cn = &it->second;
350350
}
351351

352-
registry.emplace<GraphNodeLayout>(new_node.id,
353-
GraphNodeLayout{cn, NoodleGraphicLayer::Nodes, { canvas_pos.x, canvas_pos.y } });
352+
registry.emplace<NoodleNodeGraphic>(new_node.id,
353+
NoodleNodeGraphic{cn, NoodleGraphicLayer::Nodes, { canvas_pos.x, canvas_pos.y } });
354354

355355
provider.associate(new_node, conformed_name);
356356

@@ -379,10 +379,10 @@ namespace noodle {
379379
entt::entity new_node = provider.registry().create();
380380
ln_Node new_ln_node = { new_node, true };
381381
provider._noodleNodes[new_ln_node] = NoodleNode(kind, conformed_name, new_ln_node);
382-
registry.emplace<GraphNodeLayout>(new_node,
383-
GraphNodeLayout{ nullptr, NoodleGraphicLayer::Groups,
382+
registry.emplace<NoodleNodeGraphic>(new_node,
383+
NoodleNodeGraphic{ nullptr, NoodleGraphicLayer::Groups,
384384
{ canvas_pos.x, canvas_pos.y },
385-
{ canvas_pos.x + GraphNodeLayout::k_column_width() * 2, canvas_pos.y + GraphPinLayout::k_height() * 8},
385+
{ canvas_pos.x + NoodleNodeGraphic::k_column_width() * 2, canvas_pos.y + NoodlePinGraphic::k_height() * 8},
386386
true });
387387

388388
provider._canvasNodes[new_ln_node] = CanvasGroup{};
@@ -563,7 +563,7 @@ namespace noodle {
563563
}
564564
else
565565
{
566-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(input_node.id);
566+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(input_node.id);
567567
if (gnl.parent_canvas)
568568
{
569569
auto it = gnl.parent_canvas->nodes.find(input_node);
@@ -603,7 +603,7 @@ namespace noodle {
603603
}
604604
else
605605
{
606-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(en);
606+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(en);
607607
if (gnl.parent_canvas)
608608
{
609609
auto it = gnl.parent_canvas->nodes.find(noodleNode.second.id);
@@ -1029,7 +1029,7 @@ namespace noodle {
10291029
if (!registry.valid(en))
10301030
continue;
10311031

1032-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(en);
1032+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(en);
10331033
if (gnl.group)
10341034
continue;
10351035

@@ -1053,7 +1053,7 @@ namespace noodle {
10531053
// lazily create the layouts on demand.
10541054
auto pnl = provider._pinLayouts.find(entity);
10551055
if (pnl == provider._pinLayouts.end()) {
1056-
provider._pinLayouts[entity] = GraphPinLayout{};
1056+
provider._pinLayouts[entity] = NoodlePinGraphic{};
10571057
pnl = provider._pinLayouts.find(entity);
10581058
}
10591059

@@ -1082,8 +1082,8 @@ namespace noodle {
10821082
if (gnl.out_height > height)
10831083
height = gnl.out_height;
10841084

1085-
float width = GraphNodeLayout::k_column_width() * gnl.column_count;
1086-
ImVec2 new_node_pos = node_pos + ImVec2{ width, GraphPinLayout::k_height() * (1.5f + (float)height) };
1085+
float width = NoodleNodeGraphic::k_column_width() * gnl.column_count;
1086+
ImVec2 new_node_pos = node_pos + ImVec2{ width, NoodlePinGraphic::k_height() * (1.5f + (float)height) };
10871087
gnl.lr_cs = { new_node_pos.x, new_node_pos.y };
10881088

10891089
gnl.in_height = 0;
@@ -1106,22 +1106,22 @@ namespace noodle {
11061106
{
11071107
case NoodlePin::Kind::BusIn:
11081108
pnl->second.column_number = 0;
1109-
pnl->second.pos_y_cs = style_padding_y + GraphPinLayout::k_height() * static_cast<float>(gnl.in_height);
1109+
pnl->second.pos_y_cs = style_padding_y + NoodlePinGraphic::k_height() * static_cast<float>(gnl.in_height);
11101110
gnl.in_height += 1;
11111111
break;
11121112
case NoodlePin::Kind::BusOut:
11131113
pnl->second.column_number = static_cast<float>(gnl.column_count);
1114-
pnl->second.pos_y_cs = style_padding_y + GraphPinLayout::k_height() * static_cast<float>(gnl.out_height);
1114+
pnl->second.pos_y_cs = style_padding_y + NoodlePinGraphic::k_height() * static_cast<float>(gnl.out_height);
11151115
gnl.out_height += 1;
11161116
break;
11171117
case NoodlePin::Kind::Param:
11181118
pnl->second.column_number = 0;
1119-
pnl->second.pos_y_cs = style_padding_y + GraphPinLayout::k_height() * static_cast<float>(gnl.in_height);
1119+
pnl->second.pos_y_cs = style_padding_y + NoodlePinGraphic::k_height() * static_cast<float>(gnl.in_height);
11201120
gnl.in_height += 1;
11211121
break;
11221122
case NoodlePin::Kind::Setting:
11231123
pnl->second.column_number = 1;
1124-
pnl->second.pos_y_cs = style_padding_y + GraphPinLayout::k_height() * static_cast<float>(gnl.mid_height);
1124+
pnl->second.pos_y_cs = style_padding_y + NoodlePinGraphic::k_height() * static_cast<float>(gnl.mid_height);
11251125
gnl.mid_height += 1;
11261126
break;
11271127
}
@@ -1208,10 +1208,10 @@ namespace noodle {
12081208
for (auto const& node : provider._noodleNodes)
12091209
{
12101210
entt::entity entity = node.second.id.id;
1211-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(entity);
1211+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(entity);
12121212
ImVec2 ul = { gnl.ul_cs.x, gnl.ul_cs.y };
12131213
ImVec2 lr = { gnl.lr_cs.x, gnl.lr_cs.y };
1214-
if (mouse_x_cs >= ul.x && mouse_x_cs <= (lr.x + GraphPinLayout::k_width()) && mouse_y_cs >= (ul.y - 20) && mouse_y_cs <= lr.y)
1214+
if (mouse_x_cs >= ul.x && mouse_x_cs <= (lr.x + NoodlePinGraphic::k_width()) && mouse_y_cs >= (ul.y - 20) && mouse_y_cs <= lr.y)
12151215
{
12161216
// traditional UI heuristic:
12171217
// always pick the box with least area in the case of overlaps
@@ -1547,7 +1547,7 @@ namespace noodle {
15471547
mouse.dragging_node = false;
15481548
if (hover.originating_pin_id.id == ln_Pin_null().id)
15491549
hover.originating_pin_id = hover.pin_id;
1550-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(hover.node_id.id);
1550+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(hover.node_id.id);
15511551
gnl.initial_pos_cs = { mouse.mouse_cs.x, mouse.mouse_cs.y };
15521552
}
15531553
else if (hover.pin_label_id.id != ln_Pin_null().id)
@@ -1573,7 +1573,7 @@ namespace noodle {
15731573
mouse.dragging_wire = false;
15741574
mouse.dragging_node = false;
15751575
mouse.resizing_node = true;
1576-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(hover.node_id.id);
1576+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(hover.node_id.id);
15771577
gnl.initial_pos_cs = gnl.lr_cs;
15781578
}
15791579
else
@@ -1582,7 +1582,7 @@ namespace noodle {
15821582
mouse.resizing_node = false;
15831583
mouse.dragging_node = true;
15841584

1585-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(hover.node_id.id);
1585+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(hover.node_id.id);
15861586
gnl.initial_pos_cs = gnl.ul_cs;
15871587

15881588
// set up initials for group dragging
@@ -1592,7 +1592,7 @@ namespace noodle {
15921592
if (cg != provider._canvasNodes.end()) {
15931593
for (auto en : cg->second.nodes)
15941594
{
1595-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(en.id);
1595+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(en.id);
15961596
gnl.initial_pos_cs = gnl.ul_cs;
15971597
}
15981598
}
@@ -1604,7 +1604,7 @@ namespace noodle {
16041604
{
16051605
ImVec2 delta = mouse.mouse_cs - mouse.canvas_clickpos_cs;
16061606

1607-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(hover.node_id.id);
1607+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(hover.node_id.id);
16081608
ImVec2 sz = ImVec2{ gnl.lr_cs.x, gnl.lr_cs.y } - ImVec2{ gnl.ul_cs.x, gnl.ul_cs.y };
16091609
ImVec2 new_pos = ImVec2{ gnl.initial_pos_cs.x, gnl.initial_pos_cs.y } + delta;
16101610
gnl.ul_cs = { new_pos.x, new_pos.y };
@@ -1619,7 +1619,7 @@ namespace noodle {
16191619
if (cg != provider._canvasNodes.end()) {
16201620
for (ln_Node i : cg->second.nodes)
16211621
{
1622-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(i.id);
1622+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(i.id);
16231623
ImVec2 sz = ImVec2{ gnl.lr_cs.x, gnl.lr_cs.y } - ImVec2{ gnl.ul_cs.x, gnl.ul_cs.y };
16241624
ImVec2 new_pos = ImVec2{ gnl.initial_pos_cs.x, gnl.initial_pos_cs.y } + delta;
16251625
gnl.ul_cs = { new_pos.x, new_pos.y };
@@ -1633,7 +1633,7 @@ namespace noodle {
16331633
{
16341634
ImVec2 delta = mouse.mouse_cs - mouse.canvas_clickpos_cs;
16351635

1636-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(hover.node_id.id);
1636+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(hover.node_id.id);
16371637
ImVec2 new_pos = ImVec2{ gnl.initial_pos_cs.x, gnl.initial_pos_cs.y } + delta;
16381638
gnl.lr_cs = { new_pos.x, new_pos.y };
16391639
gnl.lr_cs.x = std::max(gnl.ul_cs.x + 100, gnl.lr_cs.x);
@@ -1754,7 +1754,7 @@ namespace noodle {
17541754
profiler_data[profile_idx].endTime = profiler_data[profile_idx].startTime + provider.node_get_self_timing(edit._device_node);
17551755
profile_idx = (profile_idx + 1) % profiler_data.size();
17561756

1757-
GraphNodeLayout& gnl = registry.get<GraphNodeLayout>(entity);
1757+
NoodleNodeGraphic& gnl = registry.get<NoodleNodeGraphic>(entity);
17581758
drawList->ChannelsSetCurrent((int)gnl.channel);
17591759

17601760
ImVec2 ul_ws = { gnl.ul_cs.x, gnl.ul_cs.y };
@@ -1783,11 +1783,11 @@ namespace noodle {
17831783
drawList->AddRectFilled(p1, p2, ImColor(255, 255, 255, 128));
17841784
}
17851785

1786-
if (registry.any<NodeRender>(entity))
1786+
if (node.second.render.render)
17871787
{
1788-
NodeRender& render = registry.get<NodeRender>(entity);
1789-
if (render.render)
1790-
render.render(node.second.id, { ul_ws.x, ul_ws.y }, { lr_ws.x, lr_ws.y }, root.canvas.scale, drawList);
1788+
node.second.render.render(node.second.id,
1789+
{ ul_ws.x, ul_ws.y }, { lr_ws.x, lr_ws.y },
1790+
root.canvas.scale, drawList);
17911791
}
17921792

17931793
///////////////////////////////////////////
@@ -1881,7 +1881,7 @@ namespace noodle {
18811881
fill |= (uint32_t)(128 + 128 * sinf(pulse * 8)) << 24;
18821882

18831883
DrawIcon(drawList, pin_ul,
1884-
ImVec2{ pin_ul.x + GraphPinLayout::k_width() * root.canvas.scale, pin_ul.y + GraphPinLayout::k_height() * root.canvas.scale },
1884+
ImVec2{ pin_ul.x + NoodlePinGraphic::k_width() * root.canvas.scale, pin_ul.y + NoodlePinGraphic::k_height() * root.canvas.scale },
18851885
icon_type, false, color, fill);
18861886

18871887
// Only draw text if we can likely see it
@@ -2057,9 +2057,9 @@ void create_graph(lab::AudioContext& ctx)
20572057
file << " std::shared_ptr<" << node.second.kind << "Node> "
20582058
<< node_name_clean << " = std::make_shared<" << node.second.kind << "Node>(ac);\n";
20592059

2060-
if (reg.any<GraphNodeLayout>(node_entity))
2060+
if (reg.any<NoodleNodeGraphic>(node_entity))
20612061
{
2062-
GraphNodeLayout& gnl = reg.get<GraphNodeLayout>(node_entity);
2062+
NoodleNodeGraphic& gnl = reg.get<NoodleNodeGraphic>(node_entity);
20632063
file << " // position: " << gnl.ul_cs.x << ", " << gnl.ul_cs.y << "\n\n";
20642064
}
20652065

@@ -2168,9 +2168,9 @@ void create_graph(lab::AudioContext& ctx)
21682168

21692169
file << "node: " << node.second.kind << " name: " << node.second.name << "\n";
21702170

2171-
if (reg.any<GraphNodeLayout>(node_entity))
2171+
if (reg.any<NoodleNodeGraphic>(node_entity))
21722172
{
2173-
GraphNodeLayout& gnl = reg.get<GraphNodeLayout>(node_entity);
2173+
NoodleNodeGraphic& gnl = reg.get<NoodleNodeGraphic>(node_entity);
21742174
file << " pos: " << gnl.ul_cs.x << " " << gnl.ul_cs.y << "\n";
21752175
}
21762176

@@ -2271,9 +2271,9 @@ void create_graph(lab::AudioContext& ctx)
22712271
writer.Key("kind");
22722272
writer.String(node.second.kind.c_str());
22732273

2274-
if (reg.any<GraphNodeLayout>(node_entity))
2274+
if (reg.any<NoodleNodeGraphic>(node_entity))
22752275
{
2276-
GraphNodeLayout& gnl = reg.get<GraphNodeLayout>(node_entity);
2276+
NoodleNodeGraphic& gnl = reg.get<NoodleNodeGraphic>(node_entity);
22772277
writer.Key("pos");
22782278
writer.StartArray();
22792279
writer.Double(gnl.ul_cs.x);

0 commit comments

Comments
 (0)