Skip to content

Commit b5a3158

Browse files
committed
Update alert window layout and icon colors
1 parent 88e1f5f commit b5a3158

3 files changed

Lines changed: 112 additions & 7 deletions

File tree

Source/UI/ControlPanel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
587587
playButton->setToggleState (false, dontSendNotification);
588588
recordButton->setToggleState (false, dontSendNotification);
589589

590-
String errorMsg = "No output device found. Unable to start acquisition!";
590+
String errorMsg = "No output device found. Unable to start acquisition.";
591591
LOGE (errorMsg);
592592

593593
if (! isConsoleApp)
@@ -597,7 +597,7 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
597597
"and ensure there is an output device selected.";
598598

599599
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
600-
"Acquisition Error!",
600+
"Acquisition Error",
601601
errorMsg);
602602
}
603603

@@ -609,7 +609,7 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
609609
playButton->setToggleState (false, dontSendNotification);
610610
recordButton->setToggleState (false, dontSendNotification);
611611

612-
String errorMsg = "Sample rate too low. Unable to start acquisition!";
612+
String errorMsg = "Sample rate too low. Unable to start acquisition.";
613613
LOGE (errorMsg);
614614

615615
if (! isConsoleApp)
@@ -619,7 +619,7 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
619619
"to a value of 44.1 kHz or higher. If no such option is available, try changing the output device type.";
620620

621621
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
622-
"Acquisition Error!",
622+
"Acquisition Error",
623623
errorMsg);
624624
}
625625

Source/UI/LookAndFeel/CustomLookAndFeel.cpp

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ void CustomLookAndFeel::drawMenuBarBackground (Graphics& g, int width, int heigh
727727

728728
if (menuBar.getName().equalsIgnoreCase ("MainMenu"))
729729
{
730-
g.setColour (findColour (ThemeColours::defaultText));
730+
g.setColour (findColour (ThemeColours::defaultText).withAlpha (menuBar.isEnabled() ? 1.0f : 0.5f));
731731
String ver = "v" + String (ProjectInfo::versionString);
732732
g.setFont (getCommonMenuFont());
733733
int verStrWidth = GlyphArrangement::getStringWidthInt (getCommonMenuFont(), ver);
@@ -960,7 +960,7 @@ class CustomDocumentWindowButton : public Button
960960

961961
void paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
962962
{
963-
auto pathColour = findColour (ThemeColours::controlPanelText);
963+
auto pathColour = findColour (ThemeColours::controlPanelText).withAlpha (isEnabled() ? 1.0f : 0.5f);
964964

965965
// g.fillAll (background);
966966

@@ -1117,6 +1117,110 @@ void CustomLookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window, Grap
11171117
g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
11181118
}
11191119

1120+
//==================================================================
1121+
// ALERT WINDOW METHODS :
1122+
//==================================================================
1123+
1124+
AlertWindow* CustomLookAndFeel::createAlertWindow (const String& title,
1125+
const String& message,
1126+
const String& button1,
1127+
const String& button2,
1128+
const String& button3,
1129+
MessageBoxIconType iconType,
1130+
int numButtons,
1131+
Component* associatedComponent)
1132+
{
1133+
auto boundsOffset = 20;
1134+
1135+
auto* aw = LookAndFeel_V2::createAlertWindow (title, message, button1, button2, button3, iconType, numButtons, associatedComponent);
1136+
1137+
auto bounds = aw->getBounds();
1138+
bounds = bounds.withSizeKeepingCentre (bounds.getWidth() + boundsOffset, bounds.getHeight() + boundsOffset);
1139+
aw->setBounds (bounds);
1140+
1141+
for (auto* child : aw->getChildren())
1142+
if (auto* button = dynamic_cast<TextButton*> (child))
1143+
button->setBounds (button->getBounds() + Point<int> (10, 10));
1144+
1145+
return aw;
1146+
}
1147+
1148+
void CustomLookAndFeel::drawAlertBox (Graphics& g, AlertWindow& alert, const Rectangle<int>& textArea, TextLayout& textLayout)
1149+
{
1150+
auto cornerSize = 0.0f;
1151+
1152+
g.setColour (alert.findColour (AlertWindow::outlineColourId));
1153+
g.drawRoundedRectangle (alert.getLocalBounds().toFloat(), cornerSize, 2.0f);
1154+
1155+
auto bounds = alert.getLocalBounds().reduced (1);
1156+
g.reduceClipRegion (bounds);
1157+
1158+
g.setColour (alert.findColour (AlertWindow::backgroundColourId));
1159+
g.fillRoundedRectangle (bounds.toFloat(), cornerSize);
1160+
1161+
auto iconSpaceUsed = 0;
1162+
1163+
auto iconWidth = 50;
1164+
auto iconSize = jmin (iconWidth, bounds.getHeight());
1165+
1166+
if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
1167+
iconSize = jmin (iconSize, textArea.getHeight() + 50);
1168+
1169+
juce::Rectangle<int> iconRect (10, 30, iconSize, iconSize);
1170+
1171+
if (alert.getAlertType() != MessageBoxIconType::NoIcon)
1172+
{
1173+
Path icon;
1174+
char character;
1175+
Colour colour;
1176+
1177+
if (alert.getAlertType() == MessageBoxIconType::WarningIcon)
1178+
{
1179+
character = '!';
1180+
1181+
icon.addTriangle ((float) iconRect.getX() + (float) iconRect.getWidth() * 0.5f,
1182+
(float) iconRect.getY(),
1183+
static_cast<float> (iconRect.getRight()),
1184+
static_cast<float> (iconRect.getBottom()),
1185+
static_cast<float> (iconRect.getX()),
1186+
static_cast<float> (iconRect.getBottom()));
1187+
1188+
icon = icon.createPathWithRoundedCorners (5.0f);
1189+
colour = findColour (ProcessorColour::SOURCE_COLOUR);
1190+
}
1191+
else
1192+
{
1193+
colour = findColour (ProcessorColour::FILTER_COLOUR);
1194+
character = alert.getAlertType() == MessageBoxIconType::InfoIcon ? 'i' : '?';
1195+
1196+
icon.addEllipse (iconRect.toFloat());
1197+
}
1198+
1199+
GlyphArrangement ga;
1200+
ga.addFittedText (withDefaultMetrics (FontOptions { (float) iconRect.getHeight() * 0.9f, Font::bold }),
1201+
String::charToString ((juce_wchar) (uint8) character),
1202+
static_cast<float> (iconRect.getX()),
1203+
static_cast<float> (iconRect.getY()),
1204+
static_cast<float> (iconRect.getWidth()),
1205+
static_cast<float> (iconRect.getHeight()),
1206+
Justification::centred,
1207+
1);
1208+
1209+
g.setColour (Colour (colour));
1210+
g.fillPath (icon);
1211+
1212+
g.setColour (Colours::white);
1213+
ga.draw (g);
1214+
1215+
iconSpaceUsed = iconWidth + 20;
1216+
}
1217+
1218+
juce::Rectangle<int> alertBounds (bounds.getX() + iconSpaceUsed, 30, bounds.getWidth() - iconSpaceUsed, bounds.getHeight() - getAlertWindowButtonHeight() - 50);
1219+
1220+
g.setColour (alert.findColour (AlertWindow::textColourId));
1221+
textLayout.draw (g, alertBounds.toFloat());
1222+
}
1223+
11201224
int CustomLookAndFeel::getAlertWindowButtonHeight() { return 30; }
11211225
Font CustomLookAndFeel::getAlertWindowTitleFont() { return FontOptions { "Inter", "Bold", 20.f }; }
11221226
Font CustomLookAndFeel::getAlertWindowMessageFont() { return FontOptions { "Inter", "Medium", 18.f }; }

Source/UI/LookAndFeel/CustomLookAndFeel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,14 @@ class TESTABLE CustomLookAndFeel : public LookAndFeel_V4
183183
void drawDocumentWindowTitleBar (DocumentWindow&, Graphics&, int, int, int, int, const Image*, bool) override;
184184

185185
// ========= custom Alert Window methods: ===========================
186+
AlertWindow* createAlertWindow (const String& title, const String& message, const String& button1, const String& button2, const String& button3, MessageBoxIconType iconType, int numButtons, Component* associatedComponent) override;
187+
void drawAlertBox (Graphics&, AlertWindow&, const juce::Rectangle<int>& textArea, TextLayout&) override;
186188
int getAlertWindowButtonHeight() override;
187189
Font getAlertWindowTitleFont() override;
188190
Font getAlertWindowMessageFont() override;
189191
Font getAlertWindowFont() override;
190192

191193
// ======== custom TabButton methods: ================================
192-
193194
int getTabButtonSpaceAroundImage() override;
194195
int getTabButtonOverlap (int tabDepth) override;
195196
int getTabButtonBestWidth (TabBarButton&, int tabDepth) override;

0 commit comments

Comments
 (0)