Please consider the following PIP:
/*******************************************************************************
The block below describes the properties of this PIP. A PIP is a short snippet
of code that can be read by the Projucer and used to generate a JUCE project.
BEGIN_JUCE_PIP_METADATA
name: TimedComponentPIP
dependencies: juce_core, juce_events, juce_graphics, juce_gui_basics
exporters: xcode_mac
moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
type: Component
mainClass: ParentComponent
END_JUCE_PIP_METADATA
*******************************************************************************/
#pragma once
#include <memory>
class TimedComponent : public Component, private Timer {
public:
TimedComponent() { startTimer(1); }
void timerCallback() override { repaint(); }
void paint(Graphics &g) override {
g.setColour(Colours::white);
g.drawRect(getLocalBounds());
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TimedComponent)
};
class ParentComponent : public Component {
public:
ParentComponent() : label_(std::make_unique<Label>()),
timedComp_(std::make_unique<TimedComponent>()) {
label_->setText("TimedComponent Bug", dontSendNotification);
label_->setFont(24.f);
addAndMakeVisible(label_.get());
addAndMakeVisible(timedComp_.get());
addMouseListener(this, true);
setSize(600, 400);
}
~ParentComponent() {}
void paint(Graphics &g) override {
g.fillAll(Colours::black);
if (isMouseOver(true)) {
g.fillAll(Colours::grey);
}
}
void mouseEnter(const MouseEvent &event) override { repaint(); }
void mouseExit(const MouseEvent &event) override { repaint(); }
void resized() override {
label_->setBounds(getLocalBounds().removeFromTop(50).withTrimmedLeft(50));
timedComp_->setBounds(getLocalBounds().reduced(50, 50));
}
private:
std::unique_ptr<Label> label_;
std::unique_ptr<TimedComponent> timedComp_;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ParentComponent)
};
We have a Component whose Timer triggers the repaint
method. The background of this component is transparent. The background of the parent component is either grey (if the mouse if over the component) or black (if it is not). Mostly this works as expected, but sometimes – if the mouse is moved in or out of the child component – the child component incorrectly shows the black background.
Any idea how to fix this? Thanks!