| 1134 | } |
| 1135 | |
| 1136 | auto CellularPanel::FindCell(int mouseX, int mouseY) -> FoundCell |
| 1137 | { |
| 1138 | auto rect = this->GetClientRect(); |
| 1139 | auto node = Root(); |
| 1140 | while (node) { |
| 1141 | if ( auto pCell = std::dynamic_pointer_cast< TrackPanelCell >( node ) ) |
| 1142 | // Found the bottom of the hierarchy |
| 1143 | return { pCell, rect }; |
| 1144 | else if ( auto pGroup = dynamic_cast< TrackPanelGroup* >( node.get() ) ) { |
| 1145 | // Ask node for its subdivision |
| 1146 | const auto results = pGroup->Children( rect ); |
| 1147 | const bool divideX = results.first == TrackPanelGroup::Axis::X; |
| 1148 | const auto &children = results.second; |
| 1149 | |
| 1150 | // Find the correct child |
| 1151 | const auto begin = children.begin(), end = children.end(); |
| 1152 | auto iter = std::upper_bound( begin, end, |
| 1153 | (divideX ? mouseX : mouseY), |
| 1154 | [&]( wxCoord coord, const TrackPanelGroup::Child &child ) { |
| 1155 | return coord < child.first; |
| 1156 | } |
| 1157 | ); |
| 1158 | if (iter == begin) |
| 1159 | break; |
| 1160 | --iter; |
| 1161 | |
| 1162 | // Descend the hierarchy of nodes |
| 1163 | rect = Subdivide(rect, divideX, children, iter); |
| 1164 | node = iter->second; |
| 1165 | } |
| 1166 | else |
| 1167 | // Nulls in the array of children are allowed, to define a void with |
| 1168 | // no cell |
| 1169 | break; |
| 1170 | } |
| 1171 | |
| 1172 | return { {}, {} }; |
| 1173 | } |
| 1174 | |
| 1175 | wxRect CellularPanel::FindRect( const TrackPanelCell &cell ) |
| 1176 | { |