| 911 | |
| 912 | namespace { |
| 913 | std::vector<int> FindAdjustedChannelHeights(Track &t) |
| 914 | { |
| 915 | auto channels = t.Channels(); |
| 916 | assert(!channels.empty()); |
| 917 | |
| 918 | // Collect heights, and count affordances |
| 919 | int nAffordances = 0; |
| 920 | int totalHeight = 0; |
| 921 | std::vector<int> oldHeights; |
| 922 | for (auto pChannel : channels) { |
| 923 | auto &view = ChannelView::Get(*pChannel); |
| 924 | const auto height = view.GetHeight(); |
| 925 | totalHeight += height; |
| 926 | oldHeights.push_back(height); |
| 927 | if (view.GetAffordanceControls()) |
| 928 | ++nAffordances; |
| 929 | } |
| 930 | |
| 931 | // Allocate results |
| 932 | auto nChannels = static_cast<int>(oldHeights.size()); |
| 933 | std::vector<int> results; |
| 934 | results.reserve(nChannels); |
| 935 | |
| 936 | // Now reallocate the channel heights for the presence of affordances |
| 937 | // and separators |
| 938 | auto availableHeight = totalHeight |
| 939 | - nAffordances * kAffordancesAreaHeight |
| 940 | - (nChannels - 1) * kChannelSeparatorThickness |
| 941 | - kTrackSeparatorThickness; |
| 942 | int cumulativeOldHeight = 0; |
| 943 | int cumulativeNewHeight = 0; |
| 944 | for (const auto &oldHeight : oldHeights) { |
| 945 | // Preserve the porportions among the stored heights |
| 946 | cumulativeOldHeight += oldHeight; |
| 947 | const auto newHeight = |
| 948 | cumulativeOldHeight * availableHeight / totalHeight |
| 949 | - cumulativeNewHeight; |
| 950 | cumulativeNewHeight += newHeight; |
| 951 | results.push_back(newHeight); |
| 952 | } |
| 953 | |
| 954 | return results; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | void TrackPanel::UpdateVRulers() |