Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ Colour LookAndFeel::findColour (int colourID) const noexcept
return Colours::black;
}

Colour LookAndFeel::findColour (int colourId, Component* targetComponent) const noexcept
{
if (targetComponent)
return targetComponent->findColour (colourId);

return findColour (colourId);
}

void LookAndFeel::setColour (int colourID, Colour newColour) noexcept
{
const ColourSetting c = { colourID, newColour };
Expand Down
9 changes: 9 additions & 0 deletions modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ class JUCE_API LookAndFeel : public ScrollBar::LookAndFeelMethods,
*/
Colour findColour (int colourId) const noexcept;

/** Looks for a colour that has been registered with the given colour ID number.

If a targetComponent is given (e.g. for a PopupMenu), the colour will be looked up.
Otherwise the normal findColour() method will be used.

@see Component::findColour()
*/
Colour findColour (int colourId, Component* targetComponent) const noexcept;

/** Registers a colour to be used for a particular purpose.
For more details, see the comments for findColour().
@see findColour, Component::findColour, Component::setColour
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ ImageEffectFilter* LookAndFeel_V1::getScrollbarEffect()


//==============================================================================
void LookAndFeel_V1::drawPopupMenuBackground (Graphics& g, int width, int height)
void LookAndFeel_V1::drawPopupMenuBackground (Graphics& g, int width, int height, Component* targetComponent)
{
g.fillAll (findColour (PopupMenu::backgroundColourId));
g.fillAll (findColour (PopupMenu::backgroundColourId, targetComponent));

g.setColour (Colours::black.withAlpha (0.6f));
g.drawRect (0, 0, width, height);
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class JUCE_API LookAndFeel_V1 : public LookAndFeel_V2
void drawTextEditorOutline (Graphics&, int width, int height, TextEditor&) override;

//==============================================================================
void drawPopupMenuBackground (Graphics&, int width, int height) override;
void drawPopupMenuBackground (Graphics&, int width, int height, Component* targetComponent) override;
void drawMenuBarBackground (Graphics&, int width, int height, bool isMouseOverBar, MenuBarComponent&) override;

//==============================================================================
Expand Down
25 changes: 13 additions & 12 deletions modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,9 @@ void LookAndFeel_V2::getIdealPopupMenuItemSize (const String& text, const bool i
}
}

void LookAndFeel_V2::drawPopupMenuBackground (Graphics& g, int width, int height)
void LookAndFeel_V2::drawPopupMenuBackground (Graphics& g, int width, int height, Component* targetComponent)
{
auto background = findColour (PopupMenu::backgroundColourId);
auto background = findColour (PopupMenu::backgroundColourId, targetComponent);

g.fillAll (background);
g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
Expand All @@ -899,14 +899,14 @@ void LookAndFeel_V2::drawPopupMenuBackground (Graphics& g, int width, int height
g.fillRect (0, i, width, 1);

#if ! JUCE_MAC
g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
g.setColour (findColour (PopupMenu::textColourId, targetComponent).withAlpha (0.6f));
g.drawRect (0, 0, width, height);
#endif
}

void LookAndFeel_V2::drawPopupMenuUpDownArrow (Graphics& g, int width, int height, bool isScrollUpArrow)
void LookAndFeel_V2::drawPopupMenuUpDownArrow (Graphics& g, int width, int height, bool isScrollUpArrow, Component* targetComponent)
{
auto background = findColour (PopupMenu::backgroundColourId);
auto background = findColour (PopupMenu::backgroundColourId, targetComponent);

g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
background.withAlpha (0.0f),
Expand All @@ -925,7 +925,7 @@ void LookAndFeel_V2::drawPopupMenuUpDownArrow (Graphics& g, int width, int heigh
hw + arrowW, y1,
hw, y2);

g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
g.setColour (findColour (PopupMenu::textColourId, targetComponent).withAlpha (0.5f));
g.fillPath (p);
}

Expand All @@ -934,7 +934,8 @@ void LookAndFeel_V2::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,
const bool isHighlighted, const bool isTicked,
const bool hasSubMenu, const String& text,
const String& shortcutKeyText,
const Drawable* icon, const Colour* const textColourToUse)
const Drawable* icon, const Colour* const textColourToUse,
Component* targetComponent)
{
if (isSeparator)
{
Expand All @@ -949,7 +950,7 @@ void LookAndFeel_V2::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,
}
else
{
auto textColour = findColour (PopupMenu::textColourId);
auto textColour = findColour (PopupMenu::textColourId, targetComponent);

if (textColourToUse != nullptr)
textColour = *textColourToUse;
Expand All @@ -958,10 +959,10 @@ void LookAndFeel_V2::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,

if (isHighlighted)
{
g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
g.setColour (findColour (PopupMenu::highlightedBackgroundColourId, targetComponent));
g.fillRect (r);

g.setColour (findColour (PopupMenu::highlightedTextColourId));
g.setColour (findColour (PopupMenu::highlightedTextColourId, targetComponent));
}
else
{
Expand Down Expand Up @@ -1022,10 +1023,10 @@ void LookAndFeel_V2::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,
}
}

void LookAndFeel_V2::drawPopupMenuSectionHeader (Graphics& g, const Rectangle<int>& area, const String& sectionName)
void LookAndFeel_V2::drawPopupMenuSectionHeader (Graphics& g, const Rectangle<int>& area, const String& sectionName, Component* targetComponent)
{
g.setFont (getPopupMenuFont().boldened());
g.setColour (findColour (PopupMenu::headerTextColourId));
g.setColour (findColour (PopupMenu::headerTextColourId, targetComponent));

g.drawFittedText (sectionName,
area.getX() + 12, area.getY(), area.getWidth() - 16, (int) (area.getHeight() * 0.8f),
Expand Down
8 changes: 4 additions & 4 deletions modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V2.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ class JUCE_API LookAndFeel_V2 : public LookAndFeel
void drawLasso (Graphics&, Component&) override;

//==============================================================================
void drawPopupMenuBackground (Graphics&, int width, int height) override;
void drawPopupMenuBackground (Graphics&, int width, int height, Component* targetComponent) override;

void drawPopupMenuItem (Graphics&, const Rectangle<int>& area,
bool isSeparator, bool isActive, bool isHighlighted, bool isTicked, bool hasSubMenu,
const String& text, const String& shortcutKeyText,
const Drawable* icon, const Colour* textColour) override;
const Drawable* icon, const Colour* textColour, Component* targetComponent) override;

void drawPopupMenuSectionHeader (Graphics&, const Rectangle<int>& area,
const String& sectionName) override;
const String& sectionName, Component* targetComponent) override;

Font getPopupMenuFont() override;

void drawPopupMenuUpDownArrow (Graphics&, int width, int height, bool isScrollUpArrow) override;
void drawPopupMenuUpDownArrow (Graphics&, int width, int height, bool isScrollUpArrow, Component* targetComponent) override;

void getIdealPopupMenuItemSize (const String& text, bool isSeparator, int standardMenuItemHeight,
int& idealWidth, int& idealHeight) override;
Expand Down
4 changes: 2 additions & 2 deletions modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ void LookAndFeel_V3::drawLinearSliderBackground (Graphics& g, int x, int y, int
g.strokePath (indent, PathStrokeType (0.5f));
}

void LookAndFeel_V3::drawPopupMenuBackground (Graphics& g, int width, int height)
void LookAndFeel_V3::drawPopupMenuBackground (Graphics& g, int width, int height, Component* targetComponent)
{
g.fillAll (findColour (PopupMenu::backgroundColourId));
g.fillAll (findColour (PopupMenu::backgroundColourId, targetComponent));
ignoreUnused (width, height);

#if ! JUCE_MAC
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V3.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class JUCE_API LookAndFeel_V3 : public LookAndFeel_V2

void drawKeymapChangeButton (Graphics&, int width, int height, Button& button, const String& keyDescription) override;

void drawPopupMenuBackground (Graphics&, int width, int height) override;
void drawPopupMenuBackground (Graphics&, int width, int height, Component* targetComponent) override;
void drawMenuBarBackground (Graphics&, int width, int height, bool, MenuBarComponent&) override;

int getTabButtonOverlap (int tabDepth) override;
Expand Down
11 changes: 6 additions & 5 deletions modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,29 +766,30 @@ void LookAndFeel_V4::drawPopupMenuItem (Graphics& g, const Rectangle<int>& area,
const bool isHighlighted, const bool isTicked,
const bool hasSubMenu, const String& text,
const String& shortcutKeyText,
const Drawable* icon, const Colour* const textColourToUse)
const Drawable* icon, const Colour* const textColourToUse,
Component* targetComponent)
{
if (isSeparator)
{
auto r = area.reduced (5, 0);
r.removeFromTop (roundToInt ((r.getHeight() * 0.5f) - 0.5f));

g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.3f));
g.setColour (findColour (PopupMenu::textColourId, targetComponent).withAlpha (0.3f));
g.fillRect (r.removeFromTop (1));
}
else
{
auto textColour = (textColourToUse == nullptr ? findColour (PopupMenu::textColourId)
auto textColour = (textColourToUse == nullptr ? findColour (PopupMenu::textColourId, targetComponent)
: *textColourToUse);

auto r = area.reduced (1);

if (isHighlighted && isActive)
{
g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
g.setColour (findColour (PopupMenu::highlightedBackgroundColourId, targetComponent));
g.fillRect (r);

g.setColour (findColour (PopupMenu::highlightedTextColourId));
g.setColour (findColour (PopupMenu::highlightedTextColourId, targetComponent));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_gui_basics/lookandfeel/juce_LookAndFeel_V4.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class JUCE_API LookAndFeel_V4 : public LookAndFeel_V3
void drawPopupMenuItem (Graphics&, const Rectangle<int>& area,
bool isSeparator, bool isActive, bool isHighlighted, bool isTicked, bool hasSubMenu,
const String& text, const String& shortcutKeyText,
const Drawable* icon, const Colour* textColour) override;
const Drawable* icon, const Colour* textColour, Component* targetComponent) override;

void getIdealPopupMenuItemSize (const String& text, bool isSeparator, int standardMenuItemHeight,
int& idealWidth, int& idealHeight) override;
Expand Down
7 changes: 4 additions & 3 deletions modules/juce_gui_basics/menus/juce_BurgerMenuComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int BurgerMenuComponent::getNumRows()

void BurgerMenuComponent::paint (Graphics& g)
{
getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight(), nullptr);
}

void BurgerMenuComponent::paintListBoxItem (int rowIndex, Graphics& g, int w, int h, bool highlight)
Expand All @@ -163,7 +163,7 @@ void BurgerMenuComponent::paintListBoxItem (int rowIndex, Graphics& g, int w, in

if (row.isMenuHeader)
{
lf.drawPopupMenuSectionHeader (g, r.reduced (20, 0), row.item.text);
lf.drawPopupMenuSectionHeader (g, r.reduced (20, 0), row.item.text, nullptr);
g.setColour (Colours::grey);
g.fillRect (r.withHeight (1));
}
Expand All @@ -182,7 +182,8 @@ void BurgerMenuComponent::paintListBoxItem (int rowIndex, Graphics& g, int w, in
item.text,
item.shortcutKeyDescription,
item.image.get(),
colour);
colour,
nullptr);
}
}

Expand Down
22 changes: 15 additions & 7 deletions modules/juce_gui_basics/menus/juce_PopupMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ static bool hasSubMenu (const PopupMenu::Item& item) noexcept { retur
//==============================================================================
struct HeaderItemComponent : public PopupMenu::CustomComponent
{
HeaderItemComponent (const String& name) : PopupMenu::CustomComponent (false)
HeaderItemComponent (const String& name, Component* targetComponentToUse)
: PopupMenu::CustomComponent (false),
targetComponent (targetComponentToUse)
{
setName (name);
}

void paint (Graphics& g) override
{
getLookAndFeel().drawPopupMenuSectionHeader (g, getLocalBounds(), getName());
getLookAndFeel().drawPopupMenuSectionHeader (g, getLocalBounds(), getName(), targetComponent);
}

void getIdealSize (int& idealWidth, int& idealHeight) override
Expand All @@ -67,6 +69,8 @@ struct HeaderItemComponent : public PopupMenu::CustomComponent
idealWidth += idealWidth / 4;
}

Component::SafePointer<Component> targetComponent;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HeaderItemComponent)
};

Expand All @@ -77,7 +81,7 @@ struct ItemComponent : public Component
: item (i), customComp (i.customComponent)
{
if (item.isSectionHeader)
customComp = *new HeaderItemComponent (item.text);
customComp = *new HeaderItemComponent (item.text, parent.options.getTargetComponent());

if (customComp != nullptr)
{
Expand All @@ -87,6 +91,8 @@ struct ItemComponent : public Component

parent.addAndMakeVisible (this);

targetComponent = parent.options.getTargetComponent();

updateShortcutKeyDescription();

int itemW = 80;
Expand Down Expand Up @@ -128,7 +134,8 @@ struct ItemComponent : public Component
item.text,
item.shortcutKeyDescription,
item.image.get(),
getColour (item));
getColour (item),
targetComponent);
}

void resized() override
Expand Down Expand Up @@ -158,6 +165,7 @@ struct ItemComponent : public Component
// NB: we use a copy of the one from the item info in case we're using our own section comp
ReferenceCountedObjectPtr<CustomComponent> customComp;
bool isHighlighted = false;
Component::SafePointer<Component> targetComponent;

void updateShortcutKeyDescription()
{
Expand Down Expand Up @@ -287,7 +295,7 @@ struct MenuWindow : public Component
if (isOpaque())
g.fillAll (Colours::white);

getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight(), options.getTargetComponent());
}

void paintOverChildren (Graphics& g) override
Expand All @@ -301,12 +309,12 @@ struct MenuWindow : public Component
if (canScroll())
{
if (isTopScrollZoneActive())
lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true, options.getTargetComponent());

if (isBottomScrollZoneActive())
{
g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false, options.getTargetComponent());
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions modules/juce_gui_basics/menus/juce_PopupMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ class JUCE_API PopupMenu
virtual ~LookAndFeelMethods() = default;

/** Fills the background of a popup menu component. */
virtual void drawPopupMenuBackground (Graphics&, int width, int height) = 0;
virtual void drawPopupMenuBackground (Graphics&, int width, int height, Component* targetComponent) = 0;

/** Draws one of the items in a popup menu. */
virtual void drawPopupMenuItem (Graphics&, const Rectangle<int>& area,
Expand All @@ -763,17 +763,20 @@ class JUCE_API PopupMenu
const String& text,
const String& shortcutKeyText,
const Drawable* icon,
const Colour* textColour) = 0;
const Colour* textColour,
Component* targetComponent) = 0;

virtual void drawPopupMenuSectionHeader (Graphics&, const Rectangle<int>& area,
const String& sectionName) = 0;
const String& sectionName,
Component* targetComponent) = 0;

/** Returns the size and style of font to use in popup menus. */
virtual Font getPopupMenuFont() = 0;

virtual void drawPopupMenuUpDownArrow (Graphics&,
int width, int height,
bool isScrollUpArrow) = 0;
bool isScrollUpArrow,
Component* targetComponent) = 0;

/** Finds the best size for an item in a popup menu. */
virtual void getIdealPopupMenuItemSize (const String& text,
Expand Down