1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00
JUCE/examples/ComponentTutorialExample/Source/ToggleLightComponent.h

49 lines
1.1 KiB
C++

/*
==============================================================================
ToggleLightComponent.h
Created: 11 Feb 2015 9:56:51am
Author: Felix Faire
==============================================================================
*/
#pragma once
/**
This class represents one of the individual lights in our grid.
*/
class ToggleLightComponent : public Component
{
public:
ToggleLightComponent (String name = "light")
: Component (name),
isOn (false)
{
}
void paint (Graphics& g) override
{
g.fillAll (Colours::black);
// Only shows the red ellipse when the button is on.
if (isOn)
{
g.setColour (Colours::red);
g.fillEllipse (getLocalBounds().toFloat());
}
}
void mouseEnter (const MouseEvent&) override
{
// button toggles state on mouse over.
isOn = ! isOn;
repaint();
}
private:
// member variables for the Component
bool isOn;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleLightComponent)
};