Hi everyone
I am using a lot on custom look and feels in my project for things like sliders, comboboxes etc. and all is good but i tried to use a custom lookAndFeel on my alertWindow which doesn’t seem to work, i am wondering what am i doing wrong. Here is a snippet of my code that creates the alertWindow
// PluginEditor.cpp
void myAudioProcessorEditor::myAlertWindow()
{
AlertWindowLookAndFeel alertWindowLookAndFeel;
AlertWindow::showMessageBoxAsync(AlertWindow::NoIcon,
"Title",
"this is an alert window",
"ok",
this,
ModalCallbackFunction::create([this](int result) {}));
setLookAndFeel(&alertWindowLookAndFeel);
}
On my lookAndFeel class, i copied most on the juce code and modified it. I need to changes things like the background colour of the alertWindow and corner sizes.
AlertWindow* AlertWindowLookAndFeel::createAlertWindow (const String& title, const String& message,
const String& button1, const String& button2, const String& button3,
MessageBoxIconType iconType,
int numButtons, Component* associatedComponent)
{
auto boundsOffset = 50;
auto* aw = LookAndFeel_V2::createAlertWindow (title, message, button1, button2, button3,
iconType, numButtons, associatedComponent);
auto bounds = aw->getBounds();
bounds = bounds.withSizeKeepingCentre (bounds.getWidth() + boundsOffset, bounds.getHeight() + boundsOffset);
aw->setBounds (bounds);
for (auto* child : aw->getChildren())
if (auto* button = dynamic_cast<TextButton*> (child))
button->setBounds (button->getBounds() + Point<int> (25, 40));
return aw;
}
void AlertWindowLookAndFeel::drawAlertBox (Graphics& g, AlertWindow& alert,
const Rectangle& textArea, TextLayout& textLayout)
{
auto cornerSize = 4.0f;
g.setColour (Colours::red);
g.drawRoundedRectangle (alert.getLocalBounds().toFloat(), cornerSize, 2.0f);
auto bounds = alert.getLocalBounds().reduced (1);
g.reduceClipRegion (bounds);
g.setColour (Colours::blue);
g.fillRoundedRectangle (bounds.toFloat(), cornerSize);
auto iconSpaceUsed = 0;
auto iconWidth = 80;
auto iconSize = jmin (iconWidth + 50, bounds.getHeight() + 20);
if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
iconSize = jmin (iconSize, textArea.getHeight() + 50);
Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
iconSize, iconSize);
if (alert.getAlertType() != MessageBoxIconType::NoIcon)
{
Path icon;
char character;
uint32 colour;
if (alert.getAlertType() == MessageBoxIconType::WarningIcon)
{
character = '!';
icon.addTriangle ((float) iconRect.getX() + (float) iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
static_cast<float> (iconRect.getRight()), static_cast<float> (iconRect.getBottom()),
static_cast<float> (iconRect.getX()), static_cast<float> (iconRect.getBottom()));
icon = icon.createPathWithRoundedCorners (5.0f);
colour = 0x66ff2a00;
}
else
{
colour = Colour (0xff00b0b9).withAlpha (0.4f).getARGB();
character = alert.getAlertType() == MessageBoxIconType::InfoIcon ? 'i' : '?';
icon.addEllipse (iconRect.toFloat());
}
GlyphArrangement ga;
ga.addFittedText ({ (float) iconRect.getHeight() * 0.9f, Font::bold },
String::charToString ((juce_wchar) (uint8) character),
static_cast<float> (iconRect.getX()), static_cast<float> (iconRect.getY()),
static_cast<float> (iconRect.getWidth()), static_cast<float> (iconRect.getHeight()),
Justification::centred, false);
ga.createPath (icon);
icon.setUsingNonZeroWinding (false);
g.setColour (Colour (colour));
g.fillPath (icon);
iconSpaceUsed = iconWidth;
}
g.setColour (Colours::green);
Rectangle<int> alertBounds (bounds.getX() + iconSpaceUsed, 30,
bounds.getWidth(), bounds.getHeight() - getAlertWindowButtonHeight() - 20);
textLayout.draw (g, alertBounds.toFloat());
}
What am i missing here.