| 66 | } |
| 67 | |
| 68 | void SpectrumBackground::createBackgroundImage() |
| 69 | { |
| 70 | // Get component bounds. |
| 71 | auto bounds = getLocalBounds(); |
| 72 | if (bounds.isEmpty()) |
| 73 | return; |
| 74 | |
| 75 | // Create a new image with the current component size. |
| 76 | cachedBackground = juce::Image(juce::Image::ARGB, |
| 77 | juce::roundToInt(getWidth() * lastDisplayScale), |
| 78 | juce::roundToInt(getHeight() * lastDisplayScale), |
| 79 | true); |
| 80 | // Create a graphics context to draw onto our new image. |
| 81 | juce::Graphics g(cachedBackground); |
| 82 | g.addTransform(juce::AffineTransform::scale(lastDisplayScale)); |
| 83 | |
| 84 | // --- All original painting logic is moved here --- |
| 85 | |
| 86 | // Paint background color onto the image. |
| 87 | g.setColour(COLOUR6); |
| 88 | g.fillAll(); |
| 89 | |
| 90 | // Set a scalable font size for the frequency labels. |
| 91 | g.setFont(12.0f * scale); |
| 92 | |
| 93 | // Paint horizontal lines and frequency numbers. |
| 94 | g.setColour(juce::Colours::lightgrey.withAlpha(0.2f)); |
| 95 | auto horizontalLineY = (float) bounds.getHeight() / 5.0f; |
| 96 | g.drawHorizontalLine((int) horizontalLineY, 0.0f, (float) bounds.getWidth()); |
| 97 | |
| 98 | for (const auto freq : frequenciesForLines) |
| 99 | { |
| 100 | float xPos = transformToLog(freq) * bounds.getWidth(); |
| 101 | g.drawVerticalLine((int) xPos, horizontalLineY, (float) bounds.getHeight()); |
| 102 | } |
| 103 | |
| 104 | // Loop 2: Draw ONLY the text labels using the sparse array. |
| 105 | for (const auto freq : frequenciesForTextLabels) |
| 106 | { |
| 107 | float xPos = transformToLog(freq) * bounds.getWidth(); |
| 108 | |
| 109 | const int scaledWidth = (int) (60 * scale); |
| 110 | const int scaledXOffset = (int) (30 * scale); |
| 111 | |
| 112 | juce::Rectangle<int> textBounds((int) xPos - scaledXOffset, 0, scaledWidth, (int) horizontalLineY); |
| 113 | |
| 114 | juce::String text; |
| 115 | if (freq >= 1000) |
| 116 | text = juce::String(freq / 1000) + "k"; |
| 117 | else |
| 118 | text = juce::String(freq); |
| 119 | |
| 120 | auto justification = juce::Justification::centred; |
| 121 | if (freq == 20) |
| 122 | justification = juce::Justification::right; |
| 123 | else if (freq == 20000) |
| 124 | justification = juce::Justification::left; |
| 125 |
nothing calls this directly
no test coverage detected