I am making a grid of buttons using svg images
The grids needs to be resizable
Buttons are rendering slightly trapezoidal.
MyRelativeRectangle presetButtonSize = { juce::Rectangle<int>(700, 18 , 110, 34), 1200, 700 };
MyRelativeRectangle presetButtonPadding = { juce::Rectangle<int>(700, 18 , 7, 8), 1200, 700 };
MyRelativeRectangle presetSelectorBox = { juce::Rectangle<int>(701, 71 , 482, 178), 1200, 700 };
MyRelativeRectangle presetSelectorFirst = { juce::Rectangle<int>(711, 82 , 482, 178), 1200, 700 };
in construtor:
// Create the three SVG drawable instances
normalImage = juce::Drawable::createFromImageData(BinaryData::btn_preset_normal_svg, BinaryData::btn_preset_normal_svgSize);
hoverImage = juce::Drawable::createFromImageData(BinaryData::btn_preset_hover_svg, BinaryData::btn_preset_hover_svgSize);
clickImage = juce::Drawable::createFromImageData(BinaryData::btn_preset_active_svg, BinaryData::btn_preset_active_svgSize);
// Create the buttons and add them to the array
for (int i = 0; i < 16; ++i)
{
std::unique_ptr<juce::DrawableButton> button = std::make_unique<juce::DrawableButton>("Button " + juce::String(i + 1), DrawableButton::ButtonStyle::ImageStretched);
button->setImages(normalImage.get(), hoverImage.get(), clickImage.get(), nullptr, nullptr, nullptr);
presetSelectionButtons.push_back(std::move(button));
addAndMakeVisible(presetSelectionButtons.back().get());
presetSelectionButtons.back()->addListener(this);
}
in resized()
DBG("Get Width : " << getWidth());
float actualButtonWidth = presetButtonSize.relativeRectangle.getWidth() * getWidth();
float actualButtonHeight = actualButtonWidth * ((presetButtonSize.relativeRectangle.getHeight() * getHeight())/(presetButtonSize.relativeRectangle.getWidth() * getWidth()));
DBG("Actual Button Width : " << actualButtonWidth);
float actualButtonPaddingX = presetButtonPadding.relativeRectangle.getWidth() * getWidth();
float actualButtonPaddingY = presetButtonPadding.relativeRectangle.getHeight() * getHeight();
float actualBoxWidth = presetSelectorBox.relativeRectangle.getWidth() * getWidth();
float actualx = presetSelectorFirst.relativeRectangle.getX() * getWidth();
float actualy = presetSelectorFirst.relativeRectangle.getY() * getHeight();
// Position the buttons within the component
int buttonWidth = round(actualButtonWidth);
int buttonHeight = round(actualButtonHeight);
int spacingX = round(actualButtonPaddingX);
int spacingY = round(actualButtonPaddingY);
int boxWidth = round(actualBoxWidth);
int x = actualx;
int y = actualy;
int count = 0;
int columns = 4;
DBG("buttonWidth :" << buttonWidth);
DBG("buttonHeight :" << buttonHeight);
for (const auto& buttonPtr : presetSelectionButtons)
{
juce::DrawableButton* button = buttonPtr.get();
button->setBounds(x + ((spacingX+buttonWidth) * (count%columns)),
y+ (buttonHeight+spacingY)*(count/columns), buttonWidth, buttonHeight);
++count;
}
All 3 svg's have the same dimenions