@@ -89,38 +89,10 @@ namespace noodle {
8989 }
9090
9191
92- // ImGui channels for layering the graphics
93- enum class Channel : int {
94- Content = 0 ,
95- Grid = 1 ,
96- Groups = 2 ,
97- Nodes = 3 ,
98- Count = 4
99- };
100-
101- struct GraphNodeLayout
102- {
103- static const float k_column_width;
104-
105- // position and shape
106-
107- CanvasGroup* parent_canvas = nullptr ;
108- Channel channel = Channel::Nodes;
109- ImVec2 ul_cs = { 0 , 0 };
110- ImVec2 lr_cs = { 0 , 0 };
111- bool group = false ;
112- int in_height = 0 , mid_height = 0 , out_height = 0 ;
113- int column_count = 1 ;
114-
115- // interaction
116- ImVec2 initial_pos_cs = { 0 , 0 };
117- };
118- const float GraphNodeLayout::k_column_width = 180 .f;
119-
12092
12193 vec2 GraphPinLayout::ul_ws (Canvas& canvas) const
12294 {
123- float x = column_number * GraphNodeLayout::k_column_width;
95+ float x = column_number * GraphNodeLayout::k_column_width () ;
12496 ImVec2 no = { node_origin_cs.x , node_origin_cs.y };
12597 ImVec2 res = (no + ImVec2{ x, pos_y_cs }) * canvas.scale ;
12698 ImVec2 o_off = { canvas.origin_offset_ws .x , canvas.origin_offset_ws .y };
@@ -131,15 +103,15 @@ namespace noodle {
131103 bool GraphPinLayout::pin_contains_cs_point (Canvas& canvas, float x, float y) const
132104 {
133105 ImVec2 no = { node_origin_cs.x , node_origin_cs.y };
134- ImVec2 ul = (no + ImVec2{ column_number * GraphNodeLayout::k_column_width, pos_y_cs });
106+ ImVec2 ul = (no + ImVec2{ column_number * GraphNodeLayout::k_column_width () , pos_y_cs });
135107 ImVec2 lr = { ul.x + k_width (), ul.y + k_height () };
136108 return x >= ul.x && x <= lr.x && y >= ul.y && y <= lr.y ;
137109 }
138110 bool GraphPinLayout::label_contains_cs_point (Canvas& canvas, float x, float y) const
139111 {
140112 ImVec2 no = { node_origin_cs.x , node_origin_cs.y };
141- ImVec2 ul = (no + ImVec2{ column_number * GraphNodeLayout::k_column_width, pos_y_cs });
142- ImVec2 lr = { ul.x + GraphNodeLayout::k_column_width, ul.y + k_height () };
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 () };
143115 ul.x += k_width ();
144116 // 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);
145117 return x >= ul.x && x <= lr.x && y >= ul.y && y <= lr.y ;
@@ -356,7 +328,7 @@ namespace noodle {
356328
357329 provider.create_runtime_context (edit._device_node );
358330 registry.emplace <GraphNodeLayout>(edit._device_node .id ,
359- GraphNodeLayout{ nullptr , Channel ::Nodes, { canvas_pos.x , canvas_pos.y } });
331+ GraphNodeLayout{ nullptr , NoodleGraphicLayer ::Nodes, { canvas_pos.x , canvas_pos.y } });
360332
361333 provider.associate (edit._device_node , conformed_name);
362334
@@ -378,7 +350,7 @@ namespace noodle {
378350 }
379351
380352 registry.emplace <GraphNodeLayout>(new_node.id ,
381- GraphNodeLayout{cn, Channel ::Nodes, { canvas_pos.x , canvas_pos.y } });
353+ GraphNodeLayout{cn, NoodleGraphicLayer ::Nodes, { canvas_pos.x , canvas_pos.y } });
382354
383355 provider.associate (new_node, conformed_name);
384356
@@ -408,9 +380,9 @@ namespace noodle {
408380 ln_Node new_ln_node = { new_node, true };
409381 provider._noodleNodes [new_ln_node] = NoodleNode (kind, conformed_name, new_ln_node);
410382 registry.emplace <GraphNodeLayout>(new_node,
411- GraphNodeLayout{ nullptr , Channel ::Groups,
383+ GraphNodeLayout{ nullptr , NoodleGraphicLayer ::Groups,
412384 { canvas_pos.x , canvas_pos.y },
413- { canvas_pos.x + GraphNodeLayout::k_column_width * 2 , canvas_pos.y + GraphPinLayout::k_height () * 8 },
385+ { canvas_pos.x + GraphNodeLayout::k_column_width () * 2 , canvas_pos.y + GraphPinLayout::k_height () * 8 },
414386 true });
415387
416388 provider._canvasNodes [new_ln_node] = CanvasGroup{};
@@ -1066,7 +1038,7 @@ namespace noodle {
10661038 gnl.out_height = 0 ;
10671039 gnl.column_count = 1 ;
10681040
1069- ImVec2 node_pos = gnl.ul_cs ;
1041+ ImVec2 node_pos = { gnl.ul_cs . x , gnl. ul_cs . y } ;
10701042
10711043 // calculate column heights
10721044 for (const ln_Pin& entity : node.second .pins )
@@ -1110,8 +1082,9 @@ namespace noodle {
11101082 if (gnl.out_height > height)
11111083 height = gnl.out_height ;
11121084
1113- float width = GraphNodeLayout::k_column_width * gnl.column_count ;
1114- gnl.lr_cs = node_pos + ImVec2{ width, GraphPinLayout::k_height () * (1 .5f + (float )height) };
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) };
1087+ gnl.lr_cs = { new_node_pos.x , new_node_pos.y };
11151088
11161089 gnl.in_height = 0 ;
11171090 gnl.mid_height = 0 ;
@@ -1236,8 +1209,8 @@ namespace noodle {
12361209 {
12371210 entt::entity entity = node.second .id .id ;
12381211 GraphNodeLayout& gnl = registry.get <GraphNodeLayout>(entity);
1239- ImVec2 ul = gnl.ul_cs ;
1240- ImVec2 lr = gnl.lr_cs ;
1212+ ImVec2 ul = { gnl.ul_cs . x , gnl. ul_cs . y } ;
1213+ ImVec2 lr = { gnl.lr_cs . x , gnl. lr_cs . y } ;
12411214 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 )
12421215 {
12431216 // traditional UI heuristic:
@@ -1386,10 +1359,10 @@ namespace noodle {
13861359 // draw the grid on the canvas
13871360
13881361 ImDrawList* drawList = ImGui::GetWindowDrawList ();
1389- drawList->ChannelsSplit ((int ) Channel ::Count);
1390- drawList->ChannelsSetCurrent ((int ) Channel ::Content);
1362+ drawList->ChannelsSplit ((int ) NoodleGraphicLayer ::Count);
1363+ drawList->ChannelsSetCurrent ((int ) NoodleGraphicLayer ::Content);
13911364 {
1392- drawList->ChannelsSetCurrent ((int ) Channel ::Grid);
1365+ drawList->ChannelsSetCurrent ((int ) NoodleGraphicLayer ::Grid);
13931366
13941367 const float grid_step_x = 100 .0f * root.canvas .scale ;
13951368 const float grid_step_y = 100 .0f * root.canvas .scale ;
@@ -1407,7 +1380,7 @@ namespace noodle {
14071380 drawList->AddLine (ImVec2 (0 .0f , y) + grid_origin, ImVec2 (grid_size.x , y) + grid_origin, grid_line_color);
14081381 }
14091382 }
1410- drawList->ChannelsSetCurrent ((int ) Channel ::Content);
1383+ drawList->ChannelsSetCurrent ((int ) NoodleGraphicLayer ::Content);
14111384
14121385 // ---------------------------------------------------------------------
14131386 // run the Imgui portion of the UI
@@ -1575,7 +1548,7 @@ namespace noodle {
15751548 if (hover.originating_pin_id .id == ln_Pin_null ().id )
15761549 hover.originating_pin_id = hover.pin_id ;
15771550 GraphNodeLayout& gnl = registry.get <GraphNodeLayout>(hover.node_id .id );
1578- gnl.initial_pos_cs = mouse.mouse_cs ;
1551+ gnl.initial_pos_cs = { mouse.mouse_cs . x , mouse. mouse_cs . y } ;
15791552 }
15801553 else if (hover.pin_label_id .id != ln_Pin_null ().id )
15811554 {
@@ -1632,10 +1605,11 @@ namespace noodle {
16321605 ImVec2 delta = mouse.mouse_cs - mouse.canvas_clickpos_cs ;
16331606
16341607 GraphNodeLayout& gnl = registry.get <GraphNodeLayout>(hover.node_id .id );
1635- ImVec2 sz = gnl.lr_cs - gnl.ul_cs ;
1636- ImVec2 new_pos = gnl.initial_pos_cs + delta;
1637- gnl.ul_cs = new_pos;
1638- gnl.lr_cs = new_pos + sz;
1608+ ImVec2 sz = ImVec2{ gnl.lr_cs .x , gnl.lr_cs .y } - ImVec2{ gnl.ul_cs .x , gnl.ul_cs .y };
1609+ ImVec2 new_pos = ImVec2{ gnl.initial_pos_cs .x , gnl.initial_pos_cs .y } + delta;
1610+ gnl.ul_cs = { new_pos.x , new_pos.y };
1611+ new_pos = new_pos + sz;
1612+ gnl.lr_cs = { new_pos.x , new_pos.y };
16391613
16401614 // / @TODO force the color to be highlighting
16411615
@@ -1646,10 +1620,11 @@ namespace noodle {
16461620 for (ln_Node i : cg->second .nodes )
16471621 {
16481622 GraphNodeLayout& gnl = registry.get <GraphNodeLayout>(i.id );
1649- ImVec2 sz = gnl.lr_cs - gnl.ul_cs ;
1650- ImVec2 new_pos = gnl.initial_pos_cs + delta;
1651- gnl.ul_cs = new_pos;
1652- gnl.lr_cs = new_pos + sz;
1623+ ImVec2 sz = ImVec2{ gnl.lr_cs .x , gnl.lr_cs .y } - ImVec2{ gnl.ul_cs .x , gnl.ul_cs .y };
1624+ ImVec2 new_pos = ImVec2{ gnl.initial_pos_cs .x , gnl.initial_pos_cs .y } + delta;
1625+ gnl.ul_cs = { new_pos.x , new_pos.y };
1626+ new_pos = new_pos + sz;
1627+ gnl.lr_cs = { new_pos.x , new_pos.y };
16531628 }
16541629 }
16551630 }
@@ -1659,8 +1634,8 @@ namespace noodle {
16591634 ImVec2 delta = mouse.mouse_cs - mouse.canvas_clickpos_cs ;
16601635
16611636 GraphNodeLayout& gnl = registry.get <GraphNodeLayout>(hover.node_id .id );
1662- ImVec2 new_pos = gnl.initial_pos_cs + delta;
1663- gnl.lr_cs = new_pos;
1637+ ImVec2 new_pos = ImVec2{ gnl.initial_pos_cs . x , gnl. initial_pos_cs . y } + delta;
1638+ gnl.lr_cs = { new_pos. x , new_pos. y } ;
16641639 gnl.lr_cs .x = std::max (gnl.ul_cs .x + 100 , gnl.lr_cs .x );
16651640 gnl.lr_cs .y = std::max (gnl.ul_cs .y + 50 , gnl.lr_cs .y );
16661641 }
@@ -1715,7 +1690,7 @@ namespace noodle {
17151690 // Noodles Bezier Lines Curves Pulled //
17161691 // /////////////////////////////////////////
17171692
1718- drawList->ChannelsSetCurrent ((int ) Channel ::Nodes);
1693+ drawList->ChannelsSetCurrent ((int ) NoodleGraphicLayer ::Nodes);
17191694
17201695 for (const auto & i : provider._connections )
17211696 {
@@ -1782,8 +1757,8 @@ namespace noodle {
17821757 GraphNodeLayout& gnl = registry.get <GraphNodeLayout>(entity);
17831758 drawList->ChannelsSetCurrent ((int )gnl.channel );
17841759
1785- ImVec2 ul_ws = gnl.ul_cs ;
1786- ImVec2 lr_ws = gnl.lr_cs ;
1760+ ImVec2 ul_ws = { gnl.ul_cs . x , gnl. ul_cs . y } ;
1761+ ImVec2 lr_ws = { gnl.lr_cs . x , gnl. lr_cs . y } ;
17871762
17881763 ul_ws = woff + ul_ws * root.canvas .scale + ooff;
17891764 lr_ws = woff + lr_ws * root.canvas .scale + ooff;
0 commit comments