@@ -119,37 +119,39 @@ namespace noodle {
119119
120120 struct GraphPinLayout
121121 {
122- static const float k_height;
123- static const float k_width;
122+ inline constexpr static float k_height () { return 20 . f ; }
123+ inline constexpr static float k_width () { return 20 . f ; }
124124
125- ImVec2 node_origin_cs = { 0 , 0 };
125+ vec2 node_origin_cs = { 0 , 0 };
126126 float pos_y_cs = 0 .f;
127127 float column_number = 0 ;
128- ImVec2 ul_ws (Canvas& canvas) const
128+ vec2 ul_ws (Canvas& canvas) const
129129 {
130130 float x = column_number * GraphNodeLayout::k_column_width;
131- ImVec2 res = (node_origin_cs + ImVec2{ x, pos_y_cs }) * canvas.scale ;
131+ ImVec2 no = { node_origin_cs.x , node_origin_cs.y };
132+ ImVec2 res = (no + ImVec2{ x, pos_y_cs }) * canvas.scale ;
132133 ImVec2 o_off = { canvas.origin_offset_ws .x , canvas.origin_offset_ws .y };
133134 ImVec2 w_off = { canvas.window_origin_offset_ws .x , canvas.window_origin_offset_ws .y };
134- return res + o_off + w_off;
135+ res = res + o_off + w_off;
136+ return { res.x , res.y };
135137 }
136138 bool pin_contains_cs_point (Canvas& canvas, float x, float y) const
137139 {
138- ImVec2 ul = (node_origin_cs + ImVec2{ column_number * GraphNodeLayout::k_column_width, pos_y_cs });
139- ImVec2 lr = { ul.x + k_width, ul.y + k_height };
140+ 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 + k_width (), ul.y + k_height () };
140143 return x >= ul.x && x <= lr.x && y >= ul.y && y <= lr.y ;
141144 }
142145 bool label_contains_cs_point (Canvas& canvas, float x, float y) const
143146 {
144- ImVec2 ul = (node_origin_cs + ImVec2{ column_number * GraphNodeLayout::k_column_width, pos_y_cs });
145- ImVec2 lr = { ul.x + GraphNodeLayout::k_column_width, ul.y + k_height };
146- ul.x += k_width;
147+ ImVec2 no = { node_origin_cs.x , node_origin_cs.y };
148+ ImVec2 ul = (no + ImVec2{ column_number * GraphNodeLayout::k_column_width, pos_y_cs });
149+ ImVec2 lr = { ul.x + GraphNodeLayout::k_column_width, ul.y + k_height () };
150+ ul.x += k_width ();
147151 // 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);
148152 return x >= ul.x && x <= lr.x && y >= ul.y && y <= lr.y ;
149153 }
150154 };
151- const float GraphPinLayout::k_height = 20 .f;
152- const float GraphPinLayout::k_width = 20 .f;
153155
154156 struct MouseState
155157 {
@@ -415,7 +417,7 @@ namespace noodle {
415417 registry.emplace <GraphNodeLayout>(new_node,
416418 GraphNodeLayout{ nullptr , Channel::Groups,
417419 { canvas_pos.x , canvas_pos.y },
418- { canvas_pos.x + GraphNodeLayout::k_column_width * 2 , canvas_pos.y + GraphPinLayout::k_height * 8 },
420+ { canvas_pos.x + GraphNodeLayout::k_column_width * 2 , canvas_pos.y + GraphPinLayout::k_height () * 8 },
419421 true });
420422
421423 provider._canvasNodes [new_ln_node] = CanvasGroup{};
@@ -1088,7 +1090,7 @@ namespace noodle {
10881090 registry.emplace <GraphPinLayout>(entity.id , GraphPinLayout{});
10891091
10901092 GraphPinLayout& pnl = registry.get <GraphPinLayout>(entity.id );
1091- pnl.node_origin_cs = node_pos;
1093+ pnl.node_origin_cs = { node_pos. x , node_pos. y } ;
10921094
10931095 switch (pin.kind )
10941096 {
@@ -1114,7 +1116,7 @@ namespace noodle {
11141116 height = gnl.out_height ;
11151117
11161118 float width = GraphNodeLayout::k_column_width * gnl.column_count ;
1117- gnl.lr_cs = node_pos + ImVec2{ width, GraphPinLayout::k_height * (1 .5f + (float )height) };
1119+ gnl.lr_cs = node_pos + ImVec2{ width, GraphPinLayout::k_height () * (1 .5f + (float )height) };
11181120
11191121 gnl.in_height = 0 ;
11201122 gnl.mid_height = 0 ;
@@ -1136,22 +1138,22 @@ namespace noodle {
11361138 {
11371139 case NoodlePin::Kind::BusIn:
11381140 pnl.column_number = 0 ;
1139- pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height * static_cast <float >(gnl.in_height );
1141+ pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height () * static_cast <float >(gnl.in_height );
11401142 gnl.in_height += 1 ;
11411143 break ;
11421144 case NoodlePin::Kind::BusOut:
11431145 pnl.column_number = static_cast <float >(gnl.column_count );
1144- pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height * static_cast <float >(gnl.out_height );
1146+ pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height () * static_cast <float >(gnl.out_height );
11451147 gnl.out_height += 1 ;
11461148 break ;
11471149 case NoodlePin::Kind::Param:
11481150 pnl.column_number = 0 ;
1149- pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height * static_cast <float >(gnl.in_height );
1151+ pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height () * static_cast <float >(gnl.in_height );
11501152 gnl.in_height += 1 ;
11511153 break ;
11521154 case NoodlePin::Kind::Setting:
11531155 pnl.column_number = 1 ;
1154- pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height * static_cast <float >(gnl.mid_height );
1156+ pnl.pos_y_cs = style_padding_y + GraphPinLayout::k_height () * static_cast <float >(gnl.mid_height );
11551157 gnl.mid_height += 1 ;
11561158 break ;
11571159 }
@@ -1243,7 +1245,7 @@ namespace noodle {
12431245 GraphNodeLayout& gnl = registry.get <GraphNodeLayout>(entity);
12441246 ImVec2 ul = gnl.ul_cs ;
12451247 ImVec2 lr = gnl.lr_cs ;
1246- 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 )
1248+ 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 )
12471249 {
12481250 // traditional UI heuristic:
12491251 // always pick the box with least area in the case of overlaps
@@ -1318,8 +1320,14 @@ namespace noodle {
13181320
13191321 GraphPinLayout& from_gpl = registry.get <GraphPinLayout>(from_pin.id );
13201322 GraphPinLayout& to_gpl = registry.get <GraphPinLayout>(to_pin.id );
1321- ImVec2 from_pos = from_gpl.ul_ws (root.canvas ) + ImVec2 (style_padding_y, style_padding_x) * root.canvas .scale ;
1322- ImVec2 to_pos = to_gpl.ul_ws (root.canvas ) + ImVec2 (0 , style_padding_x) * root.canvas .scale ;
1323+
1324+ vec2 ul_ = from_gpl.ul_ws (root.canvas );
1325+ ImVec2 ul = { ul_.x , ul_.y };
1326+ ImVec2 from_pos = ul + ImVec2 (style_padding_y, style_padding_x) * root.canvas .scale ;
1327+
1328+ ul_ = to_gpl.ul_ws (root.canvas );
1329+ ul = { ul_.x , ul_.y };
1330+ ImVec2 to_pos = ul + ImVec2 (0 , style_padding_x) * root.canvas .scale ;
13231331
13241332 ImVec2 p0 = from_pos;
13251333 ImVec2 p3 = to_pos;
@@ -1725,8 +1733,14 @@ namespace noodle {
17251733
17261734 GraphPinLayout& from_gpl = registry.get <GraphPinLayout>(from_pin.id );
17271735 GraphPinLayout& to_gpl = registry.get <GraphPinLayout>(to_pin.id );
1728- ImVec2 from_pos = from_gpl.ul_ws (root.canvas ) + ImVec2 (style_padding_y, style_padding_x) * root.canvas .scale ;
1729- ImVec2 to_pos = to_gpl.ul_ws (root.canvas ) + ImVec2 (0 , style_padding_x) * root.canvas .scale ;
1736+ vec2 ul_ = from_gpl.ul_ws (root.canvas );
1737+ ImVec2 ul = { ul_.x , ul_.y };
1738+ ImVec2 from_pos = ul + ImVec2 (style_padding_y, style_padding_x) * root.canvas .scale ;
1739+
1740+ ul_ = to_gpl.ul_ws (root.canvas );
1741+ ul = { ul_.x , ul_.y };
1742+
1743+ ImVec2 to_pos = ul + ImVec2 (0 , style_padding_x) * root.canvas .scale ;
17301744
17311745 ImVec2 p0 = from_pos;
17321746 ImVec2 p3 = to_pos;
@@ -1739,7 +1753,11 @@ namespace noodle {
17391753 if (mouse.dragging_wire )
17401754 {
17411755 GraphPinLayout& from_gpl = registry.get <GraphPinLayout>(hover.originating_pin_id .id );
1742- ImVec2 p0 = from_gpl.ul_ws (root.canvas ) + ImVec2 (style_padding_y, style_padding_x) * root.canvas .scale ;
1756+
1757+ vec2 ul_ = from_gpl.ul_ws (root.canvas );
1758+ ImVec2 ul = { ul_.x , ul_.y };
1759+
1760+ ImVec2 p0 = ul + ImVec2 (style_padding_y, style_padding_x) * root.canvas .scale ;
17431761 ImVec2 p3 = mouse.mouse_ws + woff;
17441762 ImVec2 p1, p2;
17451763 noodle_bezier (p0, p1, p2, p3, root.canvas .scale );
@@ -1888,12 +1906,14 @@ namespace noodle {
18881906 }
18891907
18901908 GraphPinLayout& pin_gpl = registry.get <GraphPinLayout>(j.id );
1891- ImVec2 pin_ul = pin_gpl.ul_ws (root.canvas );
1909+
1910+ vec2 ul_ = pin_gpl.ul_ws (root.canvas );
1911+ ImVec2 pin_ul = { ul_.x , ul_.y };
18921912 uint32_t fill = (j.id == hover.pin_id .id || j.id == hover.originating_pin_id .id ) ? 0xffffff : 0x000000 ;
18931913 fill |= (uint32_t )(128 + 128 * sinf (pulse * 8 )) << 24 ;
18941914
18951915 DrawIcon (drawList, pin_ul,
1896- ImVec2{ pin_ul.x + GraphPinLayout::k_width * root.canvas .scale , pin_ul.y + GraphPinLayout::k_height * root.canvas .scale },
1916+ ImVec2{ pin_ul.x + GraphPinLayout::k_width () * root.canvas .scale , pin_ul.y + GraphPinLayout::k_height () * root.canvas .scale },
18971917 icon_type, false , color, fill);
18981918
18991919 // Only draw text if we can likely see it
0 commit comments