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

BubbleComponent: allow customisable effects

Rename look-and-feel method and update docs
This commit is contained in:
Anthony Nicholls 2023-03-22 14:12:59 +00:00
parent 2a7391b0be
commit e637073228
4 changed files with 34 additions and 5 deletions

View file

@ -206,6 +206,8 @@ LookAndFeel_V2::LookAndFeel_V2()
for (int i = 0; i < numElementsInArray (standardColours); i += 2)
setColour ((int) standardColours [i], Colour ((uint32) standardColours [i + 1]));
bubbleShadow.setShadowProperties (DropShadow (Colours::black.withAlpha (0.35f), 5, {}));
}
LookAndFeel_V2::~LookAndFeel_V2() {}
@ -839,6 +841,10 @@ void LookAndFeel_V2::drawBubble (Graphics& g, BubbleComponent& comp,
g.strokePath (p, PathStrokeType (1.0f));
}
void LookAndFeel_V2::setComponentEffectForBubbleComponent (BubbleComponent& bubbleComponent)
{
bubbleComponent.setComponentEffect (&bubbleShadow);
}
//==============================================================================
Font LookAndFeel_V2::getPopupMenuFont()

View file

@ -150,6 +150,7 @@ public:
//==============================================================================
void drawBubble (Graphics&, BubbleComponent&, const Point<float>& tip, const Rectangle<float>& body) override;
void setComponentEffectForBubbleComponent (BubbleComponent& bubbleComponent) override;
void drawLasso (Graphics&, Component&) override;
@ -412,6 +413,7 @@ public:
private:
//==============================================================================
std::unique_ptr<Drawable> folderImage, documentImage;
DropShadowEffect bubbleShadow;
void drawShinyButtonShape (Graphics&,
float x, float y, float w, float h, float maxCornerSize,

View file

@ -30,14 +30,17 @@ BubbleComponent::BubbleComponent()
: allowablePlacements (above | below | left | right)
{
setInterceptsMouseClicks (false, false);
shadow.setShadowProperties (DropShadow (Colours::black.withAlpha (0.35f), 5, Point<int>()));
setComponentEffect (&shadow);
lookAndFeelChanged();
}
BubbleComponent::~BubbleComponent() {}
//==============================================================================
void BubbleComponent::lookAndFeelChanged()
{
getLookAndFeel().setComponentEffectForBubbleComponent (*this);
}
void BubbleComponent::paint (Graphics& g)
{
getLookAndFeel().drawBubble (g, *this, arrowTip.toFloat(), content.toFloat());

View file

@ -151,14 +151,33 @@ public:
{
virtual ~LookAndFeelMethods() = default;
virtual void drawBubble (Graphics&, BubbleComponent&,
/** Override this method to draw a speech-bubble pointing at a specific location on
the screen.
*/
virtual void drawBubble (Graphics& g,
BubbleComponent& bubbleComponent,
const Point<float>& positionOfTip,
const Rectangle<float>& body) = 0;
/** Override this method to set effects, such as a drop-shadow, on a
BubbleComponent.
This will be called whenever a BubbleComponent is constructed or its
look-and-feel changes.
If you need to trigger this callback to update an effect, call
sendLookAndFeelChange() on the component.
@see Component::setComponentEffect, Component::sendLookAndFeelChange
*/
virtual void setComponentEffectForBubbleComponent (BubbleComponent& bubbleComponent) = 0;
};
//==============================================================================
/** @internal */
void paint (Graphics&) override;
/** @internal */
void lookAndFeelChanged() override;
protected:
//==============================================================================
@ -178,7 +197,6 @@ private:
Rectangle<int> content;
Point<int> arrowTip;
int allowablePlacements;
DropShadowEffect shadow;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BubbleComponent)
};