1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

GUI Basics: Refactor juce_gui_basics file structure

- Created a new detail namespace
- Moved shared module implementation details into the detail namespace
- Split dependencies so source files only rely on details in the detail namespace
- Removed all code from the juce_gui_basics.cpp file
This commit is contained in:
Anthony Nicholls 2023-03-03 10:17:48 +00:00
parent 8942f22a9b
commit cff722a4af
129 changed files with 4458 additions and 2318 deletions

View file

@ -26,37 +26,6 @@
namespace juce
{
namespace LookAndFeelHelpers
{
static Colour createBaseColour (Colour buttonColour,
bool hasKeyboardFocus,
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown) noexcept
{
const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
if (shouldDrawButtonAsDown) return baseColour.contrasting (0.2f);
if (shouldDrawButtonAsHighlighted) return baseColour.contrasting (0.1f);
return baseColour;
}
static TextLayout layoutTooltipText (const String& text, Colour colour) noexcept
{
const float tooltipFontSize = 13.0f;
const int maxToolTipWidth = 400;
AttributedString s;
s.setJustification (Justification::centred);
s.append (text, Font (tooltipFontSize, Font::bold), colour);
TextLayout tl;
tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth);
return tl;
}
}
//==============================================================================
LookAndFeel_V2::LookAndFeel_V2()
{
@ -259,10 +228,10 @@ void LookAndFeel_V2::drawButtonBackground (Graphics& g,
const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
const Colour baseColour (LookAndFeelHelpers::createBaseColour (backgroundColour,
button.hasKeyboardFocus (true),
shouldDrawButtonAsHighlighted,
shouldDrawButtonAsDown)
const Colour baseColour (detail::LookAndFeelHelpers::createBaseColour (backgroundColour,
button.hasKeyboardFocus (true),
shouldDrawButtonAsHighlighted,
shouldDrawButtonAsDown)
.withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
drawGlassLozenge (g,
@ -320,9 +289,9 @@ void LookAndFeel_V2::drawTickBox (Graphics& g, Component& component,
const float boxSize = w * 0.7f;
drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
LookAndFeelHelpers::createBaseColour (component.findColour (TextButton::buttonColourId)
.withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
true, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown),
detail::LookAndFeelHelpers::createBaseColour (component.findColour (TextButton::buttonColourId)
.withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
true, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown),
isEnabled ? ((shouldDrawButtonAsDown || shouldDrawButtonAsHighlighted) ? 1.1f : 0.5f) : 0.3f);
if (ticked)
@ -1110,8 +1079,8 @@ int LookAndFeel_V2::getMenuWindowFlags()
void LookAndFeel_V2::drawMenuBarBackground (Graphics& g, int width, int height, bool, MenuBarComponent& menuBar)
{
auto baseColour = LookAndFeelHelpers::createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId),
false, false, false);
auto baseColour = detail::LookAndFeelHelpers::createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId),
false, false, false);
if (menuBar.isEnabled())
drawShinyButtonShape (g, -4.0f, 0.0f, (float) width + 8.0f, (float) height,
@ -1237,9 +1206,9 @@ void LookAndFeel_V2::drawComboBox (Graphics& g, int width, int height, const boo
auto outlineThickness = box.isEnabled() ? (isMouseButtonDown ? 1.2f : 0.5f) : 0.3f;
auto baseColour = LookAndFeelHelpers::createBaseColour (box.findColour (ComboBox::buttonColourId),
box.hasKeyboardFocus (true),
false, isMouseButtonDown)
auto baseColour = detail::LookAndFeelHelpers::createBaseColour (box.findColour (ComboBox::buttonColourId),
box.hasKeyboardFocus (true),
false, isMouseButtonDown)
.withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f);
drawGlassLozenge (g,
@ -1404,10 +1373,10 @@ void LookAndFeel_V2::drawLinearSliderThumb (Graphics& g, int x, int y, int width
{
auto sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
auto knobColour = LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId),
slider.hasKeyboardFocus (false) && slider.isEnabled(),
slider.isMouseOverOrDragging() && slider.isEnabled(),
slider.isMouseButtonDown() && slider.isEnabled());
auto knobColour = detail::LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId),
slider.hasKeyboardFocus (false) && slider.isEnabled(),
slider.isMouseOverOrDragging() && slider.isEnabled(),
slider.isMouseButtonDown() && slider.isEnabled());
const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
@ -1496,10 +1465,10 @@ void LookAndFeel_V2::drawLinearSlider (Graphics& g, int x, int y, int width, int
{
const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
auto baseColour = LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId)
.withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
false, isMouseOver,
isMouseOver || slider.isMouseButtonDown());
auto baseColour = detail::LookAndFeelHelpers::createBaseColour (slider.findColour (Slider::thumbColourId)
.withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
false, isMouseOver,
isMouseOver || slider.isMouseButtonDown());
drawShinyButtonShape (g,
(float) x,
@ -1726,7 +1695,7 @@ Slider::SliderLayout LookAndFeel_V2::getSliderLayout (Slider& slider)
//==============================================================================
Rectangle<int> LookAndFeel_V2::getTooltipBounds (const String& tipText, Point<int> screenPos, Rectangle<int> parentArea)
{
const TextLayout tl (LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black));
const TextLayout tl (detail::LookAndFeelHelpers::layoutTooltipText (tipText, Colours::black));
auto w = (int) (tl.getWidth() + 14.0f);
auto h = (int) (tl.getHeight() + 6.0f);
@ -1746,7 +1715,7 @@ void LookAndFeel_V2::drawTooltip (Graphics& g, const String& text, int width, in
g.drawRect (0, 0, width, height, 1);
#endif
LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
detail::LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
.draw (g, Rectangle<float> ((float) width, (float) height));
}

View file

@ -1133,8 +1133,8 @@ void LookAndFeel_V4::drawTooltip (Graphics& g, const String& text, int width, in
g.setColour (findColour (TooltipWindow::outlineColourId));
g.drawRoundedRectangle (bounds.toFloat().reduced (0.5f, 0.5f), cornerSize, 1.0f);
LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
.draw (g, { static_cast<float> (width), static_cast<float> (height) });
detail::LookAndFeelHelpers::layoutTooltipText (text, findColour (TooltipWindow::textColourId))
.draw (g, { static_cast<float> (width), static_cast<float> (height) });
}
//==============================================================================