migrating to the latest JUCE version

This commit is contained in:
2022-11-04 23:11:33 +01:00
committed by Nikolai Rodionov
parent 4257a0f8ba
commit faf8f18333
2796 changed files with 888518 additions and 784244 deletions

View File

@@ -1,51 +1,51 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ArrowButton::ArrowButton (const String& name, float arrowDirectionInRadians, Colour arrowColour)
: Button (name), colour (arrowColour)
{
path.addTriangle (0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f);
path.applyTransform (AffineTransform::rotation (MathConstants<float>::twoPi * arrowDirectionInRadians, 0.5f, 0.5f));
}
ArrowButton::~ArrowButton() {}
void ArrowButton::paintButton (Graphics& g, bool /*shouldDrawButtonAsHighlighted*/, bool shouldDrawButtonAsDown)
{
Path p (path);
const float offset = shouldDrawButtonAsDown ? 1.0f : 0.0f;
p.applyTransform (path.getTransformToScaleToFit (offset, offset, (float) getWidth() - 3.0f, (float) getHeight() - 3.0f, false));
DropShadow (Colours::black.withAlpha (0.3f), shouldDrawButtonAsDown ? 2 : 4, Point<int>()).drawForPath (g, p);
g.setColour (colour);
g.fillPath (p);
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ArrowButton::ArrowButton (const String& name, float arrowDirectionInRadians, Colour arrowColour)
: Button (name), colour (arrowColour)
{
path.addTriangle (0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f);
path.applyTransform (AffineTransform::rotation (MathConstants<float>::twoPi * arrowDirectionInRadians, 0.5f, 0.5f));
}
ArrowButton::~ArrowButton() {}
void ArrowButton::paintButton (Graphics& g, bool /*shouldDrawButtonAsHighlighted*/, bool shouldDrawButtonAsDown)
{
Path p (path);
const float offset = shouldDrawButtonAsDown ? 1.0f : 0.0f;
p.applyTransform (path.getTransformToScaleToFit (offset, offset, (float) getWidth() - 3.0f, (float) getHeight() - 3.0f, false));
DropShadow (Colours::black.withAlpha (0.3f), shouldDrawButtonAsDown ? 2 : 4, Point<int>()).drawForPath (g, p);
g.setColour (colour);
g.fillPath (p);
}
} // namespace juce

View File

@@ -1,65 +1,65 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button with an arrow in it.
@see Button
@tags{GUI}
*/
class JUCE_API ArrowButton : public Button
{
public:
//==============================================================================
/** Creates an ArrowButton.
@param buttonName the name to give the button
@param arrowDirection the direction the arrow should point in, where 0.0 is
pointing right, 0.25 is down, 0.5 is left, 0.75 is up
@param arrowColour the colour to use for the arrow
*/
ArrowButton (const String& buttonName,
float arrowDirection,
Colour arrowColour);
/** Destructor. */
~ArrowButton() override;
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
Colour colour;
Path path;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ArrowButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button with an arrow in it.
@see Button
@tags{GUI}
*/
class JUCE_API ArrowButton : public Button
{
public:
//==============================================================================
/** Creates an ArrowButton.
@param buttonName the name to give the button
@param arrowDirection the direction the arrow should point in, where 0.0 is
pointing right, 0.25 is down, 0.5 is left, 0.75 is up
@param arrowColour the colour to use for the arrow
*/
ArrowButton (const String& buttonName,
float arrowDirection,
Colour arrowColour);
/** Destructor. */
~ArrowButton() override;
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
Colour colour;
Path path;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ArrowButton)
};
} // namespace juce

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,253 +1,241 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
DrawableButton::DrawableButton (const String& name, const DrawableButton::ButtonStyle buttonStyle)
: Button (name), style (buttonStyle)
{
}
DrawableButton::~DrawableButton()
{
}
//==============================================================================
static std::unique_ptr<Drawable> copyDrawableIfNotNull (const Drawable* const d)
{
if (d != nullptr)
return d->createCopy();
return {};
}
void DrawableButton::setImages (const Drawable* normal,
const Drawable* over,
const Drawable* down,
const Drawable* disabled,
const Drawable* normalOn,
const Drawable* overOn,
const Drawable* downOn,
const Drawable* disabledOn)
{
jassert (normal != nullptr); // you really need to give it at least a normal image..
normalImage = copyDrawableIfNotNull (normal);
overImage = copyDrawableIfNotNull (over);
downImage = copyDrawableIfNotNull (down);
disabledImage = copyDrawableIfNotNull (disabled);
normalImageOn = copyDrawableIfNotNull (normalOn);
overImageOn = copyDrawableIfNotNull (overOn);
downImageOn = copyDrawableIfNotNull (downOn);
disabledImageOn = copyDrawableIfNotNull (disabledOn);
currentImage = nullptr;
buttonStateChanged();
}
//==============================================================================
void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
{
if (style != newStyle)
{
style = newStyle;
buttonStateChanged();
}
}
void DrawableButton::setEdgeIndent (const int numPixelsIndent)
{
edgeIndent = numPixelsIndent;
repaint();
resized();
}
Rectangle<float> DrawableButton::getImageBounds() const
{
auto r = getLocalBounds();
if (style != ImageStretched)
{
auto indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
auto indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
if (shouldDrawButtonBackground())
{
indentX = jmax (getWidth() / 4, indentX);
indentY = jmax (getHeight() / 4, indentY);
}
else if (style == ImageAboveTextLabel)
{
r = r.withTrimmedBottom (jmin (16, proportionOfHeight (0.25f)));
}
else if (getStyle() == ImageBelowTextLabel)
{
r = r.withTrimmedTop (jmin (14, proportionOfHeight (0.25f)));
}
else if (getStyle() == ImageLeftOfTextLabel)
{
r = r.withTrimmedRight (proportionOfWidth (0.5f));
}
else if (getStyle() == ImageRightOfTextLabel)
{
r = r.withTrimmedLeft (proportionOfWidth (0.5f));
}
r = r.reduced (indentX, indentY);
}
return r.toFloat();
}
void DrawableButton::resized()
{
Button::resized();
if (currentImage != nullptr)
{
if (style != ImageRaw)
{
int transformFlags = 0;
if (style == ImageStretched)
{
transformFlags |= RectanglePlacement::stretchToFit;
}
else
{
transformFlags |= RectanglePlacement::centred;
if (style == ImageOnButtonBackgroundOriginalSize)
transformFlags |= RectanglePlacement::doNotResize;
}
currentImage->setTransformToFit (getImageBounds(), transformFlags);
}
}
}
void DrawableButton::buttonStateChanged()
{
repaint();
Drawable* imageToDraw = nullptr;
float opacity = 1.0f;
if (isEnabled())
{
imageToDraw = getCurrentImage();
}
else
{
imageToDraw = getToggleState() ? disabledImageOn.get()
: disabledImage.get();
if (imageToDraw == nullptr)
{
opacity = 0.4f;
imageToDraw = getNormalImage();
}
}
if (imageToDraw != currentImage)
{
removeChildComponent (currentImage);
currentImage = imageToDraw;
if (currentImage != nullptr)
{
currentImage->setInterceptsMouseClicks (false, false);
currentImage->setAccessible(false);
addAndMakeVisible (currentImage);
resized();
}
}
if (currentImage != nullptr)
currentImage->setAlpha (opacity);
}
void DrawableButton::enablementChanged()
{
Button::enablementChanged();
buttonStateChanged();
}
void DrawableButton::colourChanged()
{
repaint();
}
void DrawableButton::paintButton (Graphics& g,
const bool shouldDrawButtonAsHighlighted,
const bool shouldDrawButtonAsDown)
{
auto& lf = getLookAndFeel();
if (shouldDrawButtonBackground())
lf.drawButtonBackground (g, *this,
findColour (getToggleState() ? TextButton::buttonOnColourId
: TextButton::buttonColourId),
shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
else
lf.drawDrawableButton (g, *this, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
}
//==============================================================================
Drawable* DrawableButton::getCurrentImage() const noexcept
{
if (isDown()) return getDownImage();
if (isOver()) return getOverImage();
return getNormalImage();
}
Drawable* DrawableButton::getNormalImage() const noexcept
{
return (getToggleState() && normalImageOn != nullptr) ? normalImageOn.get()
: normalImage.get();
}
Drawable* DrawableButton::getOverImage() const noexcept
{
if (getToggleState())
{
if (overImageOn != nullptr) return overImageOn.get();
if (normalImageOn != nullptr) return normalImageOn.get();
}
return overImage != nullptr ? overImage.get() : normalImage.get();
}
Drawable* DrawableButton::getDownImage() const noexcept
{
if (auto* d = getToggleState() ? downImageOn.get() : downImage.get())
return d;
return getOverImage();
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
DrawableButton::DrawableButton (const String& name, const DrawableButton::ButtonStyle buttonStyle)
: Button (name), style (buttonStyle)
{
}
DrawableButton::~DrawableButton()
{
}
//==============================================================================
static std::unique_ptr<Drawable> copyDrawableIfNotNull (const Drawable* const d)
{
if (d != nullptr)
return d->createCopy();
return {};
}
void DrawableButton::setImages (const Drawable* normal,
const Drawable* over,
const Drawable* down,
const Drawable* disabled,
const Drawable* normalOn,
const Drawable* overOn,
const Drawable* downOn,
const Drawable* disabledOn)
{
jassert (normal != nullptr); // you really need to give it at least a normal image..
normalImage = copyDrawableIfNotNull (normal);
overImage = copyDrawableIfNotNull (over);
downImage = copyDrawableIfNotNull (down);
disabledImage = copyDrawableIfNotNull (disabled);
normalImageOn = copyDrawableIfNotNull (normalOn);
overImageOn = copyDrawableIfNotNull (overOn);
downImageOn = copyDrawableIfNotNull (downOn);
disabledImageOn = copyDrawableIfNotNull (disabledOn);
currentImage = nullptr;
buttonStateChanged();
}
//==============================================================================
void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
{
if (style != newStyle)
{
style = newStyle;
buttonStateChanged();
}
}
void DrawableButton::setEdgeIndent (const int numPixelsIndent)
{
edgeIndent = numPixelsIndent;
repaint();
resized();
}
Rectangle<float> DrawableButton::getImageBounds() const
{
auto r = getLocalBounds();
if (style != ImageStretched)
{
auto indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
auto indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
if (shouldDrawButtonBackground())
{
indentX = jmax (getWidth() / 4, indentX);
indentY = jmax (getHeight() / 4, indentY);
}
else if (style == ImageAboveTextLabel)
{
r = r.withTrimmedBottom (jmin (16, proportionOfHeight (0.25f)));
}
r = r.reduced (indentX, indentY);
}
return r.toFloat();
}
void DrawableButton::resized()
{
Button::resized();
if (currentImage != nullptr)
{
if (style != ImageRaw)
{
int transformFlags = 0;
if (style == ImageStretched)
{
transformFlags |= RectanglePlacement::stretchToFit;
}
else
{
transformFlags |= RectanglePlacement::centred;
if (style == ImageOnButtonBackgroundOriginalSize)
transformFlags |= RectanglePlacement::doNotResize;
}
currentImage->setTransformToFit (getImageBounds(), transformFlags);
}
}
}
void DrawableButton::buttonStateChanged()
{
repaint();
Drawable* imageToDraw = nullptr;
float opacity = 1.0f;
if (isEnabled())
{
imageToDraw = getCurrentImage();
}
else
{
imageToDraw = getToggleState() ? disabledImageOn.get()
: disabledImage.get();
if (imageToDraw == nullptr)
{
opacity = 0.4f;
imageToDraw = getNormalImage();
}
}
if (imageToDraw != currentImage)
{
removeChildComponent (currentImage);
currentImage = imageToDraw;
if (currentImage != nullptr)
{
currentImage->setInterceptsMouseClicks (false, false);
addAndMakeVisible (currentImage);
resized();
}
}
if (currentImage != nullptr)
currentImage->setAlpha (opacity);
}
void DrawableButton::enablementChanged()
{
Button::enablementChanged();
buttonStateChanged();
}
void DrawableButton::colourChanged()
{
repaint();
}
void DrawableButton::paintButton (Graphics& g,
const bool shouldDrawButtonAsHighlighted,
const bool shouldDrawButtonAsDown)
{
auto& lf = getLookAndFeel();
if (shouldDrawButtonBackground())
lf.drawButtonBackground (g, *this,
findColour (getToggleState() ? TextButton::buttonOnColourId
: TextButton::buttonColourId),
shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
else
lf.drawDrawableButton (g, *this, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
}
//==============================================================================
Drawable* DrawableButton::getCurrentImage() const noexcept
{
if (isDown()) return getDownImage();
if (isOver()) return getOverImage();
return getNormalImage();
}
Drawable* DrawableButton::getNormalImage() const noexcept
{
return (getToggleState() && normalImageOn != nullptr) ? normalImageOn.get()
: normalImage.get();
}
Drawable* DrawableButton::getOverImage() const noexcept
{
if (getToggleState())
{
if (overImageOn != nullptr) return overImageOn.get();
if (normalImageOn != nullptr) return normalImageOn.get();
}
return overImage != nullptr ? overImage.get() : normalImage.get();
}
Drawable* DrawableButton::getDownImage() const noexcept
{
if (auto* d = getToggleState() ? downImageOn.get() : downImage.get())
return d;
return getOverImage();
}
} // namespace juce

View File

@@ -1,200 +1,197 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that displays a Drawable.
Up to three Drawable objects can be given to this button, to represent the
'normal', 'over' and 'down' states.
@see Button
@tags{GUI}
*/
class JUCE_API DrawableButton : public Button
{
public:
//==============================================================================
enum ButtonStyle
{
ImageFitted, /**< The button will just display the images, but will resize and centre them to fit inside it. */
ImageRaw, /**< The button will just display the images in their normal size and position.
This leaves it up to the caller to make sure the images are the correct size and position for the button. */
ImageAboveTextLabel, /**< Draws the button as a text label across the bottom with the image resized and scaled to fit above it. */
ImageOnButtonBackground, /**< Draws the button as a standard rounded-rectangle button with the image on top. The image will be resized
to match the button's proportions.
Note that if you use this style, the colour IDs that control the button colour are
TextButton::buttonColourId and TextButton::buttonOnColourId. */
ImageOnButtonBackgroundOriginalSize, /** Same as ImageOnButtonBackground, but keeps the original image size. */
ImageStretched, /**< Fills the button with a stretched version of the image. */
ImageBelowTextLabel, /**< Draws the button as a text label across the top with the image resized and scaled to fit below it. */
ImageLeftOfTextLabel, /**< Draws the button as a text label on the right with the image resized and scaled to fit beside it. */
ImageRightOfTextLabel /**< Draws the button as a text label on the left with the image resized and scaled to fit beside it. */
};
//==============================================================================
/** Creates a DrawableButton.
After creating one of these, use setImages() to specify the drawables to use.
@param buttonName the name to give the component
@param buttonStyle the layout to use
@see ButtonStyle, setButtonStyle, setImages
*/
DrawableButton (const String& buttonName,
ButtonStyle buttonStyle);
/** Destructor. */
~DrawableButton() override;
//==============================================================================
/** Sets up the images to draw for the various button states.
The button will keep its own internal copies of these drawables.
@param normalImage the thing to draw for the button's 'normal' state. An internal copy
will be made of the object passed-in if it is non-null.
@param overImage the thing to draw for the button's 'over' state - if this is
null, the button's normal image will be used when the mouse is
over it. An internal copy will be made of the object passed-in
if it is non-null.
@param downImage the thing to draw for the button's 'down' state - if this is
null, the 'over' image will be used instead (or the normal image
as a last resort). An internal copy will be made of the object
passed-in if it is non-null.
@param disabledImage an image to draw when the button is disabled. If this is null,
the normal image will be drawn with a reduced opacity instead.
An internal copy will be made of the object passed-in if it is
non-null.
@param normalImageOn same as the normalImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the normal image is used instead
@param overImageOn same as the overImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the normalImageOn is drawn instead
@param downImageOn same as the downImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the overImageOn is drawn instead
@param disabledImageOn same as the disabledImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the normal image will be drawn instead
with a reduced opacity
*/
void setImages (const Drawable* normalImage,
const Drawable* overImage = nullptr,
const Drawable* downImage = nullptr,
const Drawable* disabledImage = nullptr,
const Drawable* normalImageOn = nullptr,
const Drawable* overImageOn = nullptr,
const Drawable* downImageOn = nullptr,
const Drawable* disabledImageOn = nullptr);
//==============================================================================
/** Changes the button's style.
@see ButtonStyle
*/
void setButtonStyle (ButtonStyle newStyle);
/** Returns the current style. */
ButtonStyle getStyle() const noexcept { return style; }
//==============================================================================
/** Gives the button an optional amount of space around the edge of the drawable.
By default there's a gap of about 3 pixels.
*/
void setEdgeIndent (int numPixelsIndent);
/** Returns the current edge indent size. */
int getEdgeIndent() const noexcept { return edgeIndent; }
//==============================================================================
/** Returns the image that the button is currently displaying. */
Drawable* getCurrentImage() const noexcept;
/** Returns the image that the button will use for its normal state. */
Drawable* getNormalImage() const noexcept;
/** Returns the image that the button will use when the mouse is over it. */
Drawable* getOverImage() const noexcept;
/** Returns the image that the button will use when the mouse is held down on it. */
Drawable* getDownImage() const noexcept;
/** Can be overridden to specify a custom position for the image within the button. */
virtual Rectangle<float> getImageBounds() const;
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the link.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
Note that when the ImageOnButtonBackground style is used, the colour IDs that control
the button colour are TextButton::buttonColourId and TextButton::buttonOnColourId.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1004010, /**< The colour to use for the button's text label. */
textColourOnId = 0x1004013, /**< The colour to use for the button's text when the button's toggle state is "on". */
backgroundColourId = 0x1004011, /**< The colour used to fill the button's background (when
the button is toggled 'off'). Note that if you use the
ImageOnButtonBackground style, you should use TextButton::buttonColourId
to change the button's colour. */
backgroundOnColourId = 0x1004012, /**< The colour used to fill the button's background (when
the button is toggled 'on'). Note that if you use the
ImageOnButtonBackground style, you should use TextButton::buttonOnColourId
to change the button's colour. */
};
//==============================================================================
/** @internal */
void paintButton (Graphics&, bool, bool) override;
/** @internal */
void buttonStateChanged() override;
/** @internal */
void resized() override;
/** @internal */
void enablementChanged() override;
/** @internal */
void colourChanged() override;
private:
//==============================================================================
bool shouldDrawButtonBackground() const { return style == ImageOnButtonBackground || style == ImageOnButtonBackgroundOriginalSize; }
//==============================================================================
ButtonStyle style;
std::unique_ptr<Drawable> normalImage, overImage, downImage, disabledImage,
normalImageOn, overImageOn, downImageOn, disabledImageOn;
Drawable* currentImage = nullptr;
int edgeIndent = 3;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DrawableButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that displays a Drawable.
Up to three Drawable objects can be given to this button, to represent the
'normal', 'over' and 'down' states.
@see Button
@tags{GUI}
*/
class JUCE_API DrawableButton : public Button
{
public:
//==============================================================================
enum ButtonStyle
{
ImageFitted, /**< The button will just display the images, but will resize and centre them to fit inside it. */
ImageRaw, /**< The button will just display the images in their normal size and position.
This leaves it up to the caller to make sure the images are the correct size and position for the button. */
ImageAboveTextLabel, /**< Draws the button as a text label across the bottom with the image resized and scaled to fit above it. */
ImageOnButtonBackground, /**< Draws the button as a standard rounded-rectangle button with the image on top. The image will be resized
to match the button's proportions.
Note that if you use this style, the colour IDs that control the button colour are
TextButton::buttonColourId and TextButton::buttonOnColourId. */
ImageOnButtonBackgroundOriginalSize, /** Same as ImageOnButtonBackground, but keeps the original image size. */
ImageStretched /**< Fills the button with a stretched version of the image. */
};
//==============================================================================
/** Creates a DrawableButton.
After creating one of these, use setImages() to specify the drawables to use.
@param buttonName the name to give the component
@param buttonStyle the layout to use
@see ButtonStyle, setButtonStyle, setImages
*/
DrawableButton (const String& buttonName,
ButtonStyle buttonStyle);
/** Destructor. */
~DrawableButton() override;
//==============================================================================
/** Sets up the images to draw for the various button states.
The button will keep its own internal copies of these drawables.
@param normalImage the thing to draw for the button's 'normal' state. An internal copy
will be made of the object passed-in if it is non-null.
@param overImage the thing to draw for the button's 'over' state - if this is
null, the button's normal image will be used when the mouse is
over it. An internal copy will be made of the object passed-in
if it is non-null.
@param downImage the thing to draw for the button's 'down' state - if this is
null, the 'over' image will be used instead (or the normal image
as a last resort). An internal copy will be made of the object
passed-in if it is non-null.
@param disabledImage an image to draw when the button is disabled. If this is null,
the normal image will be drawn with a reduced opacity instead.
An internal copy will be made of the object passed-in if it is
non-null.
@param normalImageOn same as the normalImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the normal image is used instead
@param overImageOn same as the overImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the normalImageOn is drawn instead
@param downImageOn same as the downImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the overImageOn is drawn instead
@param disabledImageOn same as the disabledImage, but this is used when the button's toggle
state is 'on'. If this is nullptr, the normal image will be drawn instead
with a reduced opacity
*/
void setImages (const Drawable* normalImage,
const Drawable* overImage = nullptr,
const Drawable* downImage = nullptr,
const Drawable* disabledImage = nullptr,
const Drawable* normalImageOn = nullptr,
const Drawable* overImageOn = nullptr,
const Drawable* downImageOn = nullptr,
const Drawable* disabledImageOn = nullptr);
//==============================================================================
/** Changes the button's style.
@see ButtonStyle
*/
void setButtonStyle (ButtonStyle newStyle);
/** Returns the current style. */
ButtonStyle getStyle() const noexcept { return style; }
//==============================================================================
/** Gives the button an optional amount of space around the edge of the drawable.
By default there's a gap of about 3 pixels.
*/
void setEdgeIndent (int numPixelsIndent);
/** Returns the current edge indent size. */
int getEdgeIndent() const noexcept { return edgeIndent; }
//==============================================================================
/** Returns the image that the button is currently displaying. */
Drawable* getCurrentImage() const noexcept;
/** Returns the image that the button will use for its normal state. */
Drawable* getNormalImage() const noexcept;
/** Returns the image that the button will use when the mouse is over it. */
Drawable* getOverImage() const noexcept;
/** Returns the image that the button will use when the mouse is held down on it. */
Drawable* getDownImage() const noexcept;
/** Can be overridden to specify a custom position for the image within the button. */
virtual Rectangle<float> getImageBounds() const;
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the link.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
Note that when the ImageOnButtonBackground style is used, the colour IDs that control
the button colour are TextButton::buttonColourId and TextButton::buttonOnColourId.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1004010, /**< The colour to use for the button's text label. */
textColourOnId = 0x1004013, /**< The colour to use for the button's text when the button's toggle state is "on". */
backgroundColourId = 0x1004011, /**< The colour used to fill the button's background (when
the button is toggled 'off'). Note that if you use the
ImageOnButtonBackground style, you should use TextButton::buttonColourId
to change the button's colour. */
backgroundOnColourId = 0x1004012, /**< The colour used to fill the button's background (when
the button is toggled 'on'). Note that if you use the
ImageOnButtonBackground style, you should use TextButton::buttonOnColourId
to change the button's colour. */
};
//==============================================================================
/** @internal */
void paintButton (Graphics&, bool, bool) override;
/** @internal */
void buttonStateChanged() override;
/** @internal */
void resized() override;
/** @internal */
void enablementChanged() override;
/** @internal */
void colourChanged() override;
private:
//==============================================================================
bool shouldDrawButtonBackground() const { return style == ImageOnButtonBackground || style == ImageOnButtonBackgroundOriginalSize; }
//==============================================================================
ButtonStyle style;
std::unique_ptr<Drawable> normalImage, overImage, downImage, disabledImage,
normalImageOn, overImageOn, downImageOn, disabledImageOn;
Drawable* currentImage = nullptr;
int edgeIndent = 3;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DrawableButton)
};
} // namespace juce

View File

@@ -1,124 +1,129 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
HyperlinkButton::HyperlinkButton (const String& linkText,
const URL& linkURL)
: Button (linkText),
url (linkURL),
font (14.0f, Font::underlined),
resizeFont (true),
justification (Justification::centred)
{
setMouseCursor (MouseCursor::PointingHandCursor);
setTooltip (linkURL.toString (false));
}
HyperlinkButton::HyperlinkButton()
: Button (String()),
font (14.0f, Font::underlined),
resizeFont (true),
justification (Justification::centred)
{
setMouseCursor (MouseCursor::PointingHandCursor);
}
HyperlinkButton::~HyperlinkButton()
{
}
//==============================================================================
void HyperlinkButton::setFont (const Font& newFont,
const bool resizeToMatchComponentHeight,
Justification justificationType)
{
font = newFont;
resizeFont = resizeToMatchComponentHeight;
justification = justificationType;
repaint();
}
void HyperlinkButton::setURL (const URL& newURL) noexcept
{
url = newURL;
setTooltip (newURL.toString (false));
}
Font HyperlinkButton::getFontToUse() const
{
if (resizeFont)
return font.withHeight ((float) getHeight() * 0.7f);
return font;
}
void HyperlinkButton::changeWidthToFitText()
{
setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
}
void HyperlinkButton::setJustificationType (Justification newJustification)
{
if (justification != newJustification)
{
justification = newJustification;
repaint();
}
}
void HyperlinkButton::colourChanged()
{
repaint();
}
//==============================================================================
void HyperlinkButton::clicked()
{
if (url.isWellFormed())
url.launchInDefaultBrowser();
}
void HyperlinkButton::paintButton (Graphics& g,
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown)
{
const Colour textColour (findColour (textColourId));
if (isEnabled())
g.setColour ((shouldDrawButtonAsHighlighted) ? textColour.darker ((shouldDrawButtonAsDown) ? 1.3f : 0.4f)
: textColour);
else
g.setColour (textColour.withMultipliedAlpha (0.4f));
g.setFont (getFontToUse());
g.drawText (getButtonText(), getLocalBounds().reduced (1, 0),
justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
true);
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
HyperlinkButton::HyperlinkButton (const String& linkText,
const URL& linkURL)
: Button (linkText),
url (linkURL),
font (14.0f, Font::underlined),
resizeFont (true),
justification (Justification::centred)
{
setMouseCursor (MouseCursor::PointingHandCursor);
setTooltip (linkURL.toString (false));
}
HyperlinkButton::HyperlinkButton()
: Button (String()),
font (14.0f, Font::underlined),
resizeFont (true),
justification (Justification::centred)
{
setMouseCursor (MouseCursor::PointingHandCursor);
}
HyperlinkButton::~HyperlinkButton()
{
}
//==============================================================================
void HyperlinkButton::setFont (const Font& newFont,
const bool resizeToMatchComponentHeight,
Justification justificationType)
{
font = newFont;
resizeFont = resizeToMatchComponentHeight;
justification = justificationType;
repaint();
}
void HyperlinkButton::setURL (const URL& newURL) noexcept
{
url = newURL;
setTooltip (newURL.toString (false));
}
Font HyperlinkButton::getFontToUse() const
{
if (resizeFont)
return font.withHeight ((float) getHeight() * 0.7f);
return font;
}
void HyperlinkButton::changeWidthToFitText()
{
setSize (getFontToUse().getStringWidth (getButtonText()) + 6, getHeight());
}
void HyperlinkButton::setJustificationType (Justification newJustification)
{
if (justification != newJustification)
{
justification = newJustification;
repaint();
}
}
void HyperlinkButton::colourChanged()
{
repaint();
}
//==============================================================================
void HyperlinkButton::clicked()
{
if (url.isWellFormed())
url.launchInDefaultBrowser();
}
void HyperlinkButton::paintButton (Graphics& g,
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown)
{
const Colour textColour (findColour (textColourId));
if (isEnabled())
g.setColour ((shouldDrawButtonAsHighlighted) ? textColour.darker ((shouldDrawButtonAsDown) ? 1.3f : 0.4f)
: textColour);
else
g.setColour (textColour.withMultipliedAlpha (0.4f));
g.setFont (getFontToUse());
g.drawText (getButtonText(), getLocalBounds().reduced (1, 0),
justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
true);
}
std::unique_ptr<AccessibilityHandler> HyperlinkButton::createAccessibilityHandler()
{
return std::make_unique<ButtonAccessibilityHandler> (*this, AccessibilityRole::hyperlink);
}
} // namespace juce

View File

@@ -1,127 +1,129 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button showing an underlined weblink, that will launch the link
when it's clicked.
@see Button
@tags{GUI}
*/
class JUCE_API HyperlinkButton : public Button
{
public:
//==============================================================================
/** Creates a HyperlinkButton.
@param linkText the text that will be displayed in the button - this is
also set as the Component's name, but the text can be
changed later with the Button::setButtonText() method
@param linkURL the URL to launch when the user clicks the button
*/
HyperlinkButton (const String& linkText,
const URL& linkURL);
/** Creates a HyperlinkButton. */
HyperlinkButton();
/** Destructor. */
~HyperlinkButton() override;
//==============================================================================
/** Changes the font to use for the text.
If resizeToMatchComponentHeight is true, the font's height will be adjusted
to match the size of the component.
*/
void setFont (const Font& newFont,
bool resizeToMatchComponentHeight,
Justification justificationType = Justification::horizontallyCentred);
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the link.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1001f00, /**< The colour to use for the URL text. */
};
//==============================================================================
/** Changes the URL that the button will trigger. */
void setURL (const URL& newURL) noexcept;
/** Returns the URL that the button will trigger. */
const URL& getURL() const noexcept { return url; }
//==============================================================================
/** Resizes the button horizontally to fit snugly around the text.
This won't affect the button's height.
*/
void changeWidthToFitText();
//==============================================================================
/** Sets the style of justification to be used for positioning the text.
(The default is Justification::centred)
*/
void setJustificationType (Justification justification);
/** Returns the type of justification, as set in setJustificationType(). */
Justification getJustificationType() const noexcept { return justification; }
protected:
//==============================================================================
/** @internal */
void clicked() override;
/** @internal */
void colourChanged() override;
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
//==============================================================================
using Button::clicked;
Font getFontToUse() const;
//==============================================================================
URL url;
Font font;
bool resizeFont;
Justification justification;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HyperlinkButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button showing an underlined weblink, that will launch the link
when it's clicked.
@see Button
@tags{GUI}
*/
class JUCE_API HyperlinkButton : public Button
{
public:
//==============================================================================
/** Creates a HyperlinkButton.
@param linkText the text that will be displayed in the button - this is
also set as the Component's name, but the text can be
changed later with the Button::setButtonText() method
@param linkURL the URL to launch when the user clicks the button
*/
HyperlinkButton (const String& linkText,
const URL& linkURL);
/** Creates a HyperlinkButton. */
HyperlinkButton();
/** Destructor. */
~HyperlinkButton() override;
//==============================================================================
/** Changes the font to use for the text.
If resizeToMatchComponentHeight is true, the font's height will be adjusted
to match the size of the component.
*/
void setFont (const Font& newFont,
bool resizeToMatchComponentHeight,
Justification justificationType = Justification::horizontallyCentred);
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the link.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1001f00, /**< The colour to use for the URL text. */
};
//==============================================================================
/** Changes the URL that the button will trigger. */
void setURL (const URL& newURL) noexcept;
/** Returns the URL that the button will trigger. */
const URL& getURL() const noexcept { return url; }
//==============================================================================
/** Resizes the button horizontally to fit snugly around the text.
This won't affect the button's height.
*/
void changeWidthToFitText();
//==============================================================================
/** Sets the style of justification to be used for positioning the text.
(The default is Justification::centred)
*/
void setJustificationType (Justification justification);
/** Returns the type of justification, as set in setJustificationType(). */
Justification getJustificationType() const noexcept { return justification; }
protected:
//==============================================================================
/** @internal */
void clicked() override;
/** @internal */
void colourChanged() override;
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
//==============================================================================
using Button::clicked;
Font getFontToUse() const;
//==============================================================================
URL url;
Font font;
bool resizeFont;
Justification justification;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HyperlinkButton)
};
} // namespace juce

View File

@@ -1,208 +1,198 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ImageButton::ImageButton (const String& text_)
: Button (text_),
scaleImageToFit (true),
preserveProportions (true),
alphaThreshold (0)
{
}
ImageButton::~ImageButton()
{
}
void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
const bool rescaleImagesWhenButtonSizeChanges,
const bool preserveImageProportions,
const Image& normalImage_,
const float imageOpacityWhenNormal,
Colour overlayColourWhenNormal,
const Image& overImage_,
const float imageOpacityWhenOver,
Colour overlayColourWhenOver,
const Image& downImage_,
const float imageOpacityWhenDown,
Colour overlayColourWhenDown,
const float hitTestAlphaThreshold)
{
normalImage = normalImage_;
overImage = overImage_;
downImage = downImage_;
if (resizeButtonNowToFitThisImage && normalImage.isValid())
{
imageBounds.setSize (normalImage.getWidth(),
normalImage.getHeight());
setSize (imageBounds.getWidth(), imageBounds.getHeight());
}
scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
preserveProportions = preserveImageProportions;
normalOpacity = imageOpacityWhenNormal;
normalOverlay = overlayColourWhenNormal;
overOpacity = imageOpacityWhenOver;
overOverlay = overlayColourWhenOver;
downOpacity = imageOpacityWhenDown;
downOverlay = overlayColourWhenDown;
alphaThreshold = (uint8) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
repaint();
}
void ImageButton::setHitTestAlphaThreshold(float thresh)
{
alphaThreshold = (uint8) jlimit (0, 0xff, roundToInt (255.0f * thresh));
}
float ImageButton::getHitTestAlphaThreshold() const
{
return alphaThreshold / 255.0f;
}
Image ImageButton::getCurrentImage() const
{
if (isDown() || getToggleState())
return getDownImage();
if (isOver())
return getOverImage();
return getNormalImage();
}
Image ImageButton::getNormalImage() const
{
return normalImage;
}
Image ImageButton::getOverImage() const
{
return overImage.isValid() ? overImage
: normalImage;
}
Image ImageButton::getDownImage() const
{
return downImage.isValid() ? downImage
: getOverImage();
}
void ImageButton::paintButton (Graphics& g,
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown)
{
if (! isEnabled())
{
shouldDrawButtonAsHighlighted = false;
shouldDrawButtonAsDown = false;
}
Image im (getCurrentImage());
if (im.isValid())
{
const int iw = im.getWidth();
const int ih = im.getHeight();
int w = getWidth();
int h = getHeight();
int x = (w - iw) / 2;
int y = (h - ih) / 2;
if (scaleImageToFit)
{
if (preserveProportions)
{
int newW, newH;
const float imRatio = (float) ih / (float) iw;
const float destRatio = (float) h / (float) w;
if (imRatio > destRatio)
{
newW = roundToInt ((float) h / imRatio);
newH = h;
}
else
{
newW = w;
newH = roundToInt ((float) w * imRatio);
}
x = (w - newW) / 2;
y = (h - newH) / 2;
w = newW;
h = newH;
}
else
{
x = 0;
y = 0;
}
}
if (! scaleImageToFit)
{
w = iw;
h = ih;
}
imageBounds.setBounds (x, y, w, h);
const bool useDownImage = shouldDrawButtonAsDown || getToggleState();
getLookAndFeel().drawImageButton (g, &im, x, y, w, h,
useDownImage ? downOverlay
: (shouldDrawButtonAsHighlighted ? overOverlay
: normalOverlay),
useDownImage ? downOpacity
: (shouldDrawButtonAsHighlighted ? overOpacity
: normalOpacity),
*this);
}
}
bool ImageButton::hitTest (int x, int y)
{
if (! Component::hitTest (x, y)) // handle setInterceptsMouseClicks
return false;
if (alphaThreshold == 0)
return true;
Image im (getCurrentImage());
return im.isNull() || ((! imageBounds.isEmpty())
&& alphaThreshold < im.getPixelAt (((x - imageBounds.getX()) * im.getWidth()) / imageBounds.getWidth(),
((y - imageBounds.getY()) * im.getHeight()) / imageBounds.getHeight()).getAlpha());
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ImageButton::ImageButton (const String& text_)
: Button (text_),
scaleImageToFit (true),
preserveProportions (true),
alphaThreshold (0)
{
}
ImageButton::~ImageButton()
{
}
void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
const bool rescaleImagesWhenButtonSizeChanges,
const bool preserveImageProportions,
const Image& normalImage_,
const float imageOpacityWhenNormal,
Colour overlayColourWhenNormal,
const Image& overImage_,
const float imageOpacityWhenOver,
Colour overlayColourWhenOver,
const Image& downImage_,
const float imageOpacityWhenDown,
Colour overlayColourWhenDown,
const float hitTestAlphaThreshold)
{
normalImage = normalImage_;
overImage = overImage_;
downImage = downImage_;
if (resizeButtonNowToFitThisImage && normalImage.isValid())
{
imageBounds.setSize (normalImage.getWidth(),
normalImage.getHeight());
setSize (imageBounds.getWidth(), imageBounds.getHeight());
}
scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
preserveProportions = preserveImageProportions;
normalOpacity = imageOpacityWhenNormal;
normalOverlay = overlayColourWhenNormal;
overOpacity = imageOpacityWhenOver;
overOverlay = overlayColourWhenOver;
downOpacity = imageOpacityWhenDown;
downOverlay = overlayColourWhenDown;
alphaThreshold = (uint8) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
repaint();
}
Image ImageButton::getCurrentImage() const
{
if (isDown() || getToggleState())
return getDownImage();
if (isOver())
return getOverImage();
return getNormalImage();
}
Image ImageButton::getNormalImage() const
{
return normalImage;
}
Image ImageButton::getOverImage() const
{
return overImage.isValid() ? overImage
: normalImage;
}
Image ImageButton::getDownImage() const
{
return downImage.isValid() ? downImage
: getOverImage();
}
void ImageButton::paintButton (Graphics& g,
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown)
{
if (! isEnabled())
{
shouldDrawButtonAsHighlighted = false;
shouldDrawButtonAsDown = false;
}
Image im (getCurrentImage());
if (im.isValid())
{
const int iw = im.getWidth();
const int ih = im.getHeight();
int w = getWidth();
int h = getHeight();
int x = (w - iw) / 2;
int y = (h - ih) / 2;
if (scaleImageToFit)
{
if (preserveProportions)
{
int newW, newH;
const float imRatio = (float) ih / (float) iw;
const float destRatio = (float) h / (float) w;
if (imRatio > destRatio)
{
newW = roundToInt ((float) h / imRatio);
newH = h;
}
else
{
newW = w;
newH = roundToInt ((float) w * imRatio);
}
x = (w - newW) / 2;
y = (h - newH) / 2;
w = newW;
h = newH;
}
else
{
x = 0;
y = 0;
}
}
if (! scaleImageToFit)
{
w = iw;
h = ih;
}
imageBounds.setBounds (x, y, w, h);
const bool useDownImage = shouldDrawButtonAsDown || getToggleState();
getLookAndFeel().drawImageButton (g, &im, x, y, w, h,
useDownImage ? downOverlay
: (shouldDrawButtonAsHighlighted ? overOverlay
: normalOverlay),
useDownImage ? downOpacity
: (shouldDrawButtonAsHighlighted ? overOpacity
: normalOpacity),
*this);
}
}
bool ImageButton::hitTest (int x, int y)
{
if (! Component::hitTest (x, y)) // handle setInterceptsMouseClicks
return false;
if (alphaThreshold == 0)
return true;
Image im (getCurrentImage());
return im.isNull() || ((! imageBounds.isEmpty())
&& alphaThreshold < im.getPixelAt (((x - imageBounds.getX()) * im.getWidth()) / imageBounds.getWidth(),
((y - imageBounds.getY()) * im.getHeight()) / imageBounds.getHeight()).getAlpha());
}
} // namespace juce

View File

@@ -1,164 +1,161 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
As the title suggests, this is a button containing an image.
The colour and transparency of the image can be set to vary when the
button state changes.
@see Button, ShapeButton, TextButton
@tags{GUI}
*/
class JUCE_API ImageButton : public Button
{
public:
//==============================================================================
/** Creates an ImageButton.
Use setImage() to specify the image to use. The colours and opacities that
are specified here can be changed later using setImages().
@param name the name to give the component
*/
explicit ImageButton (const String& name = String());
/** Destructor. */
~ImageButton() override;
//==============================================================================
/** Sets up the images to draw in various states.
@param resizeButtonNowToFitThisImage if true, the button will be immediately
resized to the same dimensions as the normal image
@param rescaleImagesWhenButtonSizeChanges if true, the image will be rescaled to fit the
button when the button's size changes
@param preserveImageProportions if true then any rescaling of the image to fit
the button will keep the image's x and y proportions
correct - i.e. it won't distort its shape, although
this might create gaps around the edges
@param normalImage the image to use when the button is in its normal state.
button no longer needs it.
@param imageOpacityWhenNormal the opacity to use when drawing the normal image.
@param overlayColourWhenNormal an overlay colour to use to fill the alpha channel of the
normal image - if this colour is transparent, no overlay
will be drawn. The overlay will be drawn over the top of the
image, so you can basically add a solid or semi-transparent
colour to the image to brighten or darken it
@param overImage the image to use when the mouse is over the button. If
you want to use the same image as was set in the normalImage
parameter, this value can be a null image.
@param imageOpacityWhenOver the opacity to use when drawing the image when the mouse
is over the button
@param overlayColourWhenOver an overlay colour to use to fill the alpha channel of the
image when the mouse is over - if this colour is transparent,
no overlay will be drawn
@param downImage an image to use when the button is pressed down. If set
to a null image, the 'over' image will be drawn instead (or the
normal image if there isn't an 'over' image either).
@param imageOpacityWhenDown the opacity to use when drawing the image when the button
is pressed
@param overlayColourWhenDown an overlay colour to use to fill the alpha channel of the
image when the button is pressed down - if this colour is
transparent, no overlay will be drawn
@param hitTestAlphaThreshold if set to zero, the mouse is considered to be over the button
whenever it's inside the button's bounding rectangle. If
set to values higher than 0, the mouse will only be
considered to be over the image when the value of the
image's alpha channel at that position is greater than
this level.
*/
void setImages (bool resizeButtonNowToFitThisImage,
bool rescaleImagesWhenButtonSizeChanges,
bool preserveImageProportions,
const Image& normalImage,
float imageOpacityWhenNormal,
Colour overlayColourWhenNormal,
const Image& overImage,
float imageOpacityWhenOver,
Colour overlayColourWhenOver,
const Image& downImage,
float imageOpacityWhenDown,
Colour overlayColourWhenDown,
float hitTestAlphaThreshold = 0.0f);
/** Returns the currently set 'normal' image. */
Image getNormalImage() const;
/** Returns the image that's drawn when the mouse is over the button.
If a valid 'over' image has been set, this will return it; otherwise it'll
just return the normal image.
*/
Image getOverImage() const;
/** Returns the image that's drawn when the button is held down.
If a valid 'down' image has been set, this will return it; otherwise it'll
return the 'over' image or normal image, depending on what's available.
*/
Image getDownImage() const;
void setHitTestAlphaThreshold(float thresh);
float getHitTestAlphaThreshold() const;
//==============================================================================
/** This abstract base class is implemented by LookAndFeel classes. */
struct JUCE_API LookAndFeelMethods
{
virtual ~LookAndFeelMethods() = default;
virtual void drawImageButton (Graphics&, Image*,
int imageX, int imageY, int imageW, int imageH,
const Colour& overlayColour, float imageOpacity, ImageButton&) = 0;
};
protected:
//==============================================================================
/** @internal */
bool hitTest (int x, int y) override;
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
//==============================================================================
bool scaleImageToFit, preserveProportions;
uint8 alphaThreshold;
Rectangle<int> imageBounds;
Image normalImage, overImage, downImage;
float normalOpacity, overOpacity, downOpacity;
Colour normalOverlay, overOverlay, downOverlay;
Image getCurrentImage() const;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ImageButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
As the title suggests, this is a button containing an image.
The colour and transparency of the image can be set to vary when the
button state changes.
@see Button, ShapeButton, TextButton
@tags{GUI}
*/
class JUCE_API ImageButton : public Button
{
public:
//==============================================================================
/** Creates an ImageButton.
Use setImage() to specify the image to use. The colours and opacities that
are specified here can be changed later using setImages().
@param name the name to give the component
*/
explicit ImageButton (const String& name = String());
/** Destructor. */
~ImageButton() override;
//==============================================================================
/** Sets up the images to draw in various states.
@param resizeButtonNowToFitThisImage if true, the button will be immediately
resized to the same dimensions as the normal image
@param rescaleImagesWhenButtonSizeChanges if true, the image will be rescaled to fit the
button when the button's size changes
@param preserveImageProportions if true then any rescaling of the image to fit
the button will keep the image's x and y proportions
correct - i.e. it won't distort its shape, although
this might create gaps around the edges
@param normalImage the image to use when the button is in its normal state.
button no longer needs it.
@param imageOpacityWhenNormal the opacity to use when drawing the normal image.
@param overlayColourWhenNormal an overlay colour to use to fill the alpha channel of the
normal image - if this colour is transparent, no overlay
will be drawn. The overlay will be drawn over the top of the
image, so you can basically add a solid or semi-transparent
colour to the image to brighten or darken it
@param overImage the image to use when the mouse is over the button. If
you want to use the same image as was set in the normalImage
parameter, this value can be a null image.
@param imageOpacityWhenOver the opacity to use when drawing the image when the mouse
is over the button
@param overlayColourWhenOver an overlay colour to use to fill the alpha channel of the
image when the mouse is over - if this colour is transparent,
no overlay will be drawn
@param downImage an image to use when the button is pressed down. If set
to a null image, the 'over' image will be drawn instead (or the
normal image if there isn't an 'over' image either).
@param imageOpacityWhenDown the opacity to use when drawing the image when the button
is pressed
@param overlayColourWhenDown an overlay colour to use to fill the alpha channel of the
image when the button is pressed down - if this colour is
transparent, no overlay will be drawn
@param hitTestAlphaThreshold if set to zero, the mouse is considered to be over the button
whenever it's inside the button's bounding rectangle. If
set to values higher than 0, the mouse will only be
considered to be over the image when the value of the
image's alpha channel at that position is greater than
this level.
*/
void setImages (bool resizeButtonNowToFitThisImage,
bool rescaleImagesWhenButtonSizeChanges,
bool preserveImageProportions,
const Image& normalImage,
float imageOpacityWhenNormal,
Colour overlayColourWhenNormal,
const Image& overImage,
float imageOpacityWhenOver,
Colour overlayColourWhenOver,
const Image& downImage,
float imageOpacityWhenDown,
Colour overlayColourWhenDown,
float hitTestAlphaThreshold = 0.0f);
/** Returns the currently set 'normal' image. */
Image getNormalImage() const;
/** Returns the image that's drawn when the mouse is over the button.
If a valid 'over' image has been set, this will return it; otherwise it'll
just return the normal image.
*/
Image getOverImage() const;
/** Returns the image that's drawn when the button is held down.
If a valid 'down' image has been set, this will return it; otherwise it'll
return the 'over' image or normal image, depending on what's available.
*/
Image getDownImage() const;
//==============================================================================
/** This abstract base class is implemented by LookAndFeel classes. */
struct JUCE_API LookAndFeelMethods
{
virtual ~LookAndFeelMethods() = default;
virtual void drawImageButton (Graphics&, Image*,
int imageX, int imageY, int imageW, int imageH,
const Colour& overlayColour, float imageOpacity, ImageButton&) = 0;
};
protected:
//==============================================================================
/** @internal */
bool hitTest (int x, int y) override;
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
//==============================================================================
bool scaleImageToFit, preserveProportions;
uint8 alphaThreshold;
Rectangle<int> imageBounds;
Image normalImage, overImage, downImage;
float normalOpacity, overOpacity, downOpacity;
Colour normalOverlay, overOverlay, downOverlay;
Image getCurrentImage() const;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ImageButton)
};
} // namespace juce

View File

@@ -1,137 +1,137 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ShapeButton::ShapeButton (const String& t, Colour n, Colour o, Colour d)
: Button (t),
normalColour (n), overColour (o), downColour (d),
normalColourOn (n), overColourOn (o), downColourOn (d),
useOnColours(false),
maintainShapeProportions (false),
outlineWidth (0.0f)
{
}
ShapeButton::~ShapeButton() {}
void ShapeButton::setColours (Colour newNormalColour, Colour newOverColour, Colour newDownColour)
{
normalColour = newNormalColour;
overColour = newOverColour;
downColour = newDownColour;
}
void ShapeButton::setOnColours (Colour newNormalColourOn, Colour newOverColourOn, Colour newDownColourOn)
{
normalColourOn = newNormalColourOn;
overColourOn = newOverColourOn;
downColourOn = newDownColourOn;
}
void ShapeButton::shouldUseOnColours (bool shouldUse)
{
useOnColours = shouldUse;
}
void ShapeButton::setOutline (Colour newOutlineColour, const float newOutlineWidth)
{
outlineColour = newOutlineColour;
outlineWidth = newOutlineWidth;
}
void ShapeButton::setBorderSize (BorderSize<int> newBorder)
{
border = newBorder;
}
void ShapeButton::setShape (const Path& newShape,
const bool resizeNowToFitThisShape,
const bool maintainShapeProportions_,
const bool hasShadow)
{
shape = newShape;
maintainShapeProportions = maintainShapeProportions_;
shadow.setShadowProperties (DropShadow (Colours::black.withAlpha (0.5f), 3, Point<int>()));
setComponentEffect (hasShadow ? &shadow : nullptr);
if (resizeNowToFitThisShape)
{
auto newBounds = shape.getBounds();
if (hasShadow)
newBounds = newBounds.expanded (4.0f);
shape.applyTransform (AffineTransform::translation (-newBounds.getX(),
-newBounds.getY()));
setSize (1 + (int) (newBounds.getWidth() + outlineWidth) + border.getLeftAndRight(),
1 + (int) (newBounds.getHeight() + outlineWidth) + border.getTopAndBottom());
}
repaint();
}
void ShapeButton::paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
if (! isEnabled())
{
shouldDrawButtonAsHighlighted = false;
shouldDrawButtonAsDown = false;
}
auto r = border.subtractedFrom (getLocalBounds())
.toFloat()
.reduced (outlineWidth * 0.5f);
if (getComponentEffect() != nullptr)
r = r.reduced (2.0f);
if (shouldDrawButtonAsDown)
{
const float sizeReductionWhenPressed = 0.04f;
r = r.reduced (sizeReductionWhenPressed * r.getWidth(),
sizeReductionWhenPressed * r.getHeight());
}
auto trans = shape.getTransformToScaleToFit (r, maintainShapeProportions);
if (shouldDrawButtonAsDown) g.setColour (getToggleState() && useOnColours ? downColourOn : downColour);
else if (shouldDrawButtonAsHighlighted) g.setColour (getToggleState() && useOnColours ? overColourOn : overColour);
else g.setColour (getToggleState() && useOnColours ? normalColourOn : normalColour);
g.fillPath (shape, trans);
if (outlineWidth > 0.0f)
{
g.setColour (outlineColour);
g.strokePath (shape, PathStrokeType (outlineWidth), trans);
}
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ShapeButton::ShapeButton (const String& t, Colour n, Colour o, Colour d)
: Button (t),
normalColour (n), overColour (o), downColour (d),
normalColourOn (n), overColourOn (o), downColourOn (d),
useOnColours(false),
maintainShapeProportions (false),
outlineWidth (0.0f)
{
}
ShapeButton::~ShapeButton() {}
void ShapeButton::setColours (Colour newNormalColour, Colour newOverColour, Colour newDownColour)
{
normalColour = newNormalColour;
overColour = newOverColour;
downColour = newDownColour;
}
void ShapeButton::setOnColours (Colour newNormalColourOn, Colour newOverColourOn, Colour newDownColourOn)
{
normalColourOn = newNormalColourOn;
overColourOn = newOverColourOn;
downColourOn = newDownColourOn;
}
void ShapeButton::shouldUseOnColours (bool shouldUse)
{
useOnColours = shouldUse;
}
void ShapeButton::setOutline (Colour newOutlineColour, const float newOutlineWidth)
{
outlineColour = newOutlineColour;
outlineWidth = newOutlineWidth;
}
void ShapeButton::setBorderSize (BorderSize<int> newBorder)
{
border = newBorder;
}
void ShapeButton::setShape (const Path& newShape,
const bool resizeNowToFitThisShape,
const bool maintainShapeProportions_,
const bool hasShadow)
{
shape = newShape;
maintainShapeProportions = maintainShapeProportions_;
shadow.setShadowProperties (DropShadow (Colours::black.withAlpha (0.5f), 3, Point<int>()));
setComponentEffect (hasShadow ? &shadow : nullptr);
if (resizeNowToFitThisShape)
{
auto newBounds = shape.getBounds();
if (hasShadow)
newBounds = newBounds.expanded (4.0f);
shape.applyTransform (AffineTransform::translation (-newBounds.getX(),
-newBounds.getY()));
setSize (1 + (int) (newBounds.getWidth() + outlineWidth) + border.getLeftAndRight(),
1 + (int) (newBounds.getHeight() + outlineWidth) + border.getTopAndBottom());
}
repaint();
}
void ShapeButton::paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
if (! isEnabled())
{
shouldDrawButtonAsHighlighted = false;
shouldDrawButtonAsDown = false;
}
auto r = border.subtractedFrom (getLocalBounds())
.toFloat()
.reduced (outlineWidth * 0.5f);
if (getComponentEffect() != nullptr)
r = r.reduced (2.0f);
if (shouldDrawButtonAsDown)
{
const float sizeReductionWhenPressed = 0.04f;
r = r.reduced (sizeReductionWhenPressed * r.getWidth(),
sizeReductionWhenPressed * r.getHeight());
}
auto trans = shape.getTransformToScaleToFit (r, maintainShapeProportions);
if (shouldDrawButtonAsDown) g.setColour (getToggleState() && useOnColours ? downColourOn : downColour);
else if (shouldDrawButtonAsHighlighted) g.setColour (getToggleState() && useOnColours ? overColourOn : overColour);
else g.setColour (getToggleState() && useOnColours ? normalColourOn : normalColour);
g.fillPath (shape, trans);
if (outlineWidth > 0.0f)
{
g.setColour (outlineColour);
g.strokePath (shape, PathStrokeType (outlineWidth), trans);
}
}
} // namespace juce

View File

@@ -1,126 +1,126 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that contains a filled shape.
@see Button, ImageButton, TextButton, ArrowButton
@tags{GUI}
*/
class JUCE_API ShapeButton : public Button
{
public:
//==============================================================================
/** Creates a ShapeButton.
@param name a name to give the component - see Component::setName()
@param normalColour the colour to fill the shape with when the mouse isn't over
@param overColour the colour to use when the mouse is over the shape
@param downColour the colour to use when the button is in the pressed-down state
*/
ShapeButton (const String& name,
Colour normalColour,
Colour overColour,
Colour downColour);
/** Destructor. */
~ShapeButton() override;
//==============================================================================
/** Sets the shape to use.
@param newShape the shape to use
@param resizeNowToFitThisShape if true, the button will be resized to fit the shape's bounds
@param maintainShapeProportions if true, the shape's proportions will be kept fixed when
the button is resized
@param hasDropShadow if true, the button will be given a drop-shadow effect
*/
void setShape (const Path& newShape,
bool resizeNowToFitThisShape,
bool maintainShapeProportions,
bool hasDropShadow);
/** Set the colours to use for drawing the shape.
@param normalColour the colour to fill the shape with when the mouse isn't over
@param overColour the colour to use when the mouse is over the shape
@param downColour the colour to use when the button is in the pressed-down state
*/
void setColours (Colour normalColour,
Colour overColour,
Colour downColour);
/** Sets the colours to use for drawing the shape when the button's toggle state is 'on'. To enable this behaviour, use the
shouldUseOnColours() method.
@param normalColourOn the colour to fill the shape with when the mouse isn't over and the button's toggle state is 'on'
@param overColourOn the colour to use when the mouse is over the shape and the button's toggle state is 'on'
@param downColourOn the colour to use when the button is in the pressed-down state and the button's toggle state is 'on'
*/
void setOnColours (Colour normalColourOn,
Colour overColourOn,
Colour downColourOn);
/** Set whether the button should use the 'on' set of colours when its toggle state is 'on'.
By default these will be the same as the normal colours but the setOnColours method can be
used to provide a different set of colours.
*/
void shouldUseOnColours (bool shouldUse);
/** Sets up an outline to draw around the shape.
@param outlineColour the colour to use
@param outlineStrokeWidth the thickness of line to draw
*/
void setOutline (Colour outlineColour, float outlineStrokeWidth);
/** This lets you specify a border to be left around the edge of the button when
drawing the shape.
*/
void setBorderSize (BorderSize<int> border);
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
//==============================================================================
Colour normalColour, overColour, downColour,
normalColourOn, overColourOn, downColourOn, outlineColour;
bool useOnColours;
DropShadowEffect shadow;
Path shape;
BorderSize<int> border;
bool maintainShapeProportions;
float outlineWidth;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ShapeButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that contains a filled shape.
@see Button, ImageButton, TextButton, ArrowButton
@tags{GUI}
*/
class JUCE_API ShapeButton : public Button
{
public:
//==============================================================================
/** Creates a ShapeButton.
@param name a name to give the component - see Component::setName()
@param normalColour the colour to fill the shape with when the mouse isn't over
@param overColour the colour to use when the mouse is over the shape
@param downColour the colour to use when the button is in the pressed-down state
*/
ShapeButton (const String& name,
Colour normalColour,
Colour overColour,
Colour downColour);
/** Destructor. */
~ShapeButton() override;
//==============================================================================
/** Sets the shape to use.
@param newShape the shape to use
@param resizeNowToFitThisShape if true, the button will be resized to fit the shape's bounds
@param maintainShapeProportions if true, the shape's proportions will be kept fixed when
the button is resized
@param hasDropShadow if true, the button will be given a drop-shadow effect
*/
void setShape (const Path& newShape,
bool resizeNowToFitThisShape,
bool maintainShapeProportions,
bool hasDropShadow);
/** Set the colours to use for drawing the shape.
@param normalColour the colour to fill the shape with when the mouse isn't over
@param overColour the colour to use when the mouse is over the shape
@param downColour the colour to use when the button is in the pressed-down state
*/
void setColours (Colour normalColour,
Colour overColour,
Colour downColour);
/** Sets the colours to use for drawing the shape when the button's toggle state is 'on'. To enable this behaviour, use the
shouldUseOnColours() method.
@param normalColourOn the colour to fill the shape with when the mouse isn't over and the button's toggle state is 'on'
@param overColourOn the colour to use when the mouse is over the shape and the button's toggle state is 'on'
@param downColourOn the colour to use when the button is in the pressed-down state and the button's toggle state is 'on'
*/
void setOnColours (Colour normalColourOn,
Colour overColourOn,
Colour downColourOn);
/** Set whether the button should use the 'on' set of colours when its toggle state is 'on'.
By default these will be the same as the normal colours but the setOnColours method can be
used to provide a different set of colours.
*/
void shouldUseOnColours (bool shouldUse);
/** Sets up an outline to draw around the shape.
@param outlineColour the colour to use
@param outlineStrokeWidth the thickness of line to draw
*/
void setOutline (Colour outlineColour, float outlineStrokeWidth);
/** This lets you specify a border to be left around the edge of the button when
drawing the shape.
*/
void setBorderSize (BorderSize<int> border);
/** @internal */
void paintButton (Graphics&, bool, bool) override;
private:
//==============================================================================
Colour normalColour, overColour, downColour,
normalColourOn, overColourOn, downColourOn, outlineColour;
bool useOnColours;
DropShadowEffect shadow;
Path shape;
BorderSize<int> border;
bool maintainShapeProportions;
float outlineWidth;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ShapeButton)
};
} // namespace juce

View File

@@ -1,77 +1,77 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
TextButton::TextButton() : Button (String())
{
}
TextButton::TextButton (const String& name) : Button (name)
{
}
TextButton::TextButton (const String& name, const String& toolTip) : Button (name)
{
setTooltip (toolTip);
}
TextButton::~TextButton()
{
}
void TextButton::paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
auto& lf = getLookAndFeel();
lf.drawButtonBackground (g, *this,
findColour (getToggleState() ? buttonOnColourId : buttonColourId),
shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
lf.drawButtonText (g, *this, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
}
void TextButton::colourChanged()
{
repaint();
}
void TextButton::changeWidthToFitText()
{
changeWidthToFitText (getHeight());
}
void TextButton::changeWidthToFitText (const int newHeight)
{
setSize (getBestWidthForHeight (newHeight), newHeight);
}
int TextButton::getBestWidthForHeight (int buttonHeight)
{
return getLookAndFeel().getTextButtonWidthToFitText (*this, buttonHeight);
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
TextButton::TextButton() : Button (String())
{
}
TextButton::TextButton (const String& name) : Button (name)
{
}
TextButton::TextButton (const String& name, const String& toolTip) : Button (name)
{
setTooltip (toolTip);
}
TextButton::~TextButton()
{
}
void TextButton::paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
auto& lf = getLookAndFeel();
lf.drawButtonBackground (g, *this,
findColour (getToggleState() ? buttonOnColourId : buttonColourId),
shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
lf.drawButtonText (g, *this, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
}
void TextButton::colourChanged()
{
repaint();
}
void TextButton::changeWidthToFitText()
{
changeWidthToFitText (getHeight());
}
void TextButton::changeWidthToFitText (const int newHeight)
{
setSize (getBestWidthForHeight (newHeight), newHeight);
}
int TextButton::getBestWidthForHeight (int buttonHeight)
{
return getLookAndFeel().getTextButtonWidthToFitText (*this, buttonHeight);
}
} // namespace juce

View File

@@ -1,109 +1,109 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that uses the standard lozenge-shaped background with a line of
text on it.
@see Button, DrawableButton
@tags{GUI}
*/
class JUCE_API TextButton : public Button
{
public:
//==============================================================================
/** Creates a TextButton. */
TextButton();
/** Creates a TextButton.
@param buttonName the text to put in the button (the component's name is also
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
*/
explicit TextButton (const String& buttonName);
/** Creates a TextButton.
@param buttonName the text to put in the button (the component's name is also
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
@param toolTip an optional string to use as a tooltip
*/
TextButton (const String& buttonName, const String& toolTip);
/** Destructor. */
~TextButton() override;
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the button.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
buttonColourId = 0x1000100, /**< The colour used to fill the button shape (when the button is toggled
'off'). The look-and-feel class might re-interpret this to add
effects, etc. */
buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled
'on'). The look-and-feel class might re-interpret this to add
effects, etc. */
textColourOffId = 0x1000102, /**< The colour to use for the button's text when the button's toggle state is "off". */
textColourOnId = 0x1000103 /**< The colour to use for the button's text.when the button's toggle state is "on". */
};
//==============================================================================
/** Changes this button's width to fit neatly around its current text, without
changing its height.
*/
void changeWidthToFitText();
/** Resizes the button's width to fit neatly around its current text, and gives it
the specified height.
*/
void changeWidthToFitText (int newHeight);
/** Returns the width that the LookAndFeel suggests would be best for this button if it
had the given height.
*/
int getBestWidthForHeight (int buttonHeight);
//==============================================================================
/** @internal */
void paintButton (Graphics&, bool, bool) override;
/** @internal */
void colourChanged() override;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that uses the standard lozenge-shaped background with a line of
text on it.
@see Button, DrawableButton
@tags{GUI}
*/
class JUCE_API TextButton : public Button
{
public:
//==============================================================================
/** Creates a TextButton. */
TextButton();
/** Creates a TextButton.
@param buttonName the text to put in the button (the component's name is also
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
*/
explicit TextButton (const String& buttonName);
/** Creates a TextButton.
@param buttonName the text to put in the button (the component's name is also
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
@param toolTip an optional string to use as a tooltip
*/
TextButton (const String& buttonName, const String& toolTip);
/** Destructor. */
~TextButton() override;
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the button.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
buttonColourId = 0x1000100, /**< The colour used to fill the button shape (when the button is toggled
'off'). The look-and-feel class might re-interpret this to add
effects, etc. */
buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled
'on'). The look-and-feel class might re-interpret this to add
effects, etc. */
textColourOffId = 0x1000102, /**< The colour to use for the button's text when the button's toggle state is "off". */
textColourOnId = 0x1000103 /**< The colour to use for the button's text.when the button's toggle state is "on". */
};
//==============================================================================
/** Changes this button's width to fit neatly around its current text, without
changing its height.
*/
void changeWidthToFitText();
/** Resizes the button's width to fit neatly around its current text, and gives it
the specified height.
*/
void changeWidthToFitText (int newHeight);
/** Returns the width that the LookAndFeel suggests would be best for this button if it
had the given height.
*/
int getBestWidthForHeight (int buttonHeight);
//==============================================================================
/** @internal */
void paintButton (Graphics&, bool, bool) override;
/** @internal */
void colourChanged() override;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextButton)
};
} // namespace juce

View File

@@ -1,65 +1,65 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ToggleButton::ToggleButton()
: Button (String())
{
setClickingTogglesState (true);
}
ToggleButton::ToggleButton (const String& buttonText)
: Button (buttonText)
{
setClickingTogglesState (true);
}
ToggleButton::~ToggleButton()
{
}
void ToggleButton::paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
getLookAndFeel().drawToggleButton (g, *this, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
}
void ToggleButton::changeWidthToFitText()
{
getLookAndFeel().changeToggleButtonWidthToFitText (*this);
}
void ToggleButton::colourChanged()
{
repaint();
}
std::unique_ptr<AccessibilityHandler> ToggleButton::createAccessibilityHandler()
{
return std::make_unique<ButtonAccessibilityHandler> (*this, AccessibilityRole::toggleButton);
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ToggleButton::ToggleButton()
: Button (String())
{
setClickingTogglesState (true);
}
ToggleButton::ToggleButton (const String& buttonText)
: Button (buttonText)
{
setClickingTogglesState (true);
}
ToggleButton::~ToggleButton()
{
}
void ToggleButton::paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
getLookAndFeel().drawToggleButton (g, *this, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
}
void ToggleButton::changeWidthToFitText()
{
getLookAndFeel().changeToggleButtonWidthToFitText (*this);
}
void ToggleButton::colourChanged()
{
repaint();
}
std::unique_ptr<AccessibilityHandler> ToggleButton::createAccessibilityHandler()
{
return std::make_unique<ButtonAccessibilityHandler> (*this, AccessibilityRole::toggleButton);
}
} // namespace juce

View File

@@ -1,92 +1,92 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that can be toggled on/off.
All buttons can be toggle buttons, but this lets you create one of the
standard ones which has a tick-box and a text label next to it.
@see Button, DrawableButton, TextButton
@tags{GUI}
*/
class JUCE_API ToggleButton : public Button
{
public:
//==============================================================================
/** Creates a ToggleButton. */
ToggleButton();
/** Creates a ToggleButton.
@param buttonText the text to put in the button (the component's name is also
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
*/
explicit ToggleButton (const String& buttonText);
/** Destructor. */
~ToggleButton() override;
//==============================================================================
/** Resizes the button to fit neatly around its current text.
The button's height won't be affected, only its width.
*/
void changeWidthToFitText();
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the button.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1006501, /**< The colour to use for the button's text. */
tickColourId = 0x1006502, /**< The colour to use for the tick mark. */
tickDisabledColourId = 0x1006503 /**< The colour to use for the disabled tick mark and/or outline. */
};
protected:
//==============================================================================
/** @internal */
void paintButton (Graphics&, bool, bool) override;
/** @internal */
void colourChanged() override;
private:
std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A button that can be toggled on/off.
All buttons can be toggle buttons, but this lets you create one of the
standard ones which has a tick-box and a text label next to it.
@see Button, DrawableButton, TextButton
@tags{GUI}
*/
class JUCE_API ToggleButton : public Button
{
public:
//==============================================================================
/** Creates a ToggleButton. */
ToggleButton();
/** Creates a ToggleButton.
@param buttonText the text to put in the button (the component's name is also
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
*/
explicit ToggleButton (const String& buttonText);
/** Destructor. */
~ToggleButton() override;
//==============================================================================
/** Resizes the button to fit neatly around its current text.
The button's height won't be affected, only its width.
*/
void changeWidthToFitText();
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the button.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1006501, /**< The colour to use for the button's text. */
tickColourId = 0x1006502, /**< The colour to use for the tick mark. */
tickDisabledColourId = 0x1006503 /**< The colour to use for the disabled tick mark and/or outline. */
};
protected:
//==============================================================================
/** @internal */
void paintButton (Graphics&, bool, bool) override;
/** @internal */
void colourChanged() override;
private:
std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleButton)
};
} // namespace juce

View File

@@ -1,113 +1,113 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ToolbarButton::ToolbarButton (const int iid, const String& buttonText,
std::unique_ptr<Drawable> normalIm,
std::unique_ptr<Drawable> toggledOnIm)
: ToolbarItemComponent (iid, buttonText, true),
normalImage (std::move (normalIm)),
toggledOnImage (std::move (toggledOnIm))
{
jassert (normalImage != nullptr);
}
ToolbarButton::~ToolbarButton()
{
}
//==============================================================================
bool ToolbarButton::getToolbarItemSizes (int toolbarDepth, bool /*isToolbarVertical*/, int& preferredSize, int& minSize, int& maxSize)
{
preferredSize = minSize = maxSize = toolbarDepth;
return true;
}
void ToolbarButton::paintButtonArea (Graphics&, int /*width*/, int /*height*/, bool /*isMouseOver*/, bool /*isMouseDown*/)
{
}
void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
{
buttonStateChanged();
}
void ToolbarButton::setCurrentImage (Drawable* const newImage)
{
if (newImage != currentImage)
{
removeChildComponent (currentImage);
currentImage = newImage;
if (currentImage != nullptr)
{
enablementChanged();
addAndMakeVisible (currentImage);
updateDrawable();
}
}
}
void ToolbarButton::updateDrawable()
{
if (currentImage != nullptr)
{
currentImage->setInterceptsMouseClicks (false, false);
currentImage->setTransformToFit (getContentArea().toFloat(), RectanglePlacement::centred);
currentImage->setAlpha (isEnabled() ? 1.0f : 0.5f);
}
}
void ToolbarButton::resized()
{
ToolbarItemComponent::resized();
updateDrawable();
}
void ToolbarButton::enablementChanged()
{
ToolbarItemComponent::enablementChanged();
updateDrawable();
}
Drawable* ToolbarButton::getImageToUse() const
{
if (getStyle() == Toolbar::textOnly)
return nullptr;
if (getToggleState() && toggledOnImage != nullptr)
return toggledOnImage.get();
return normalImage.get();
}
void ToolbarButton::buttonStateChanged()
{
setCurrentImage (getImageToUse());
}
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
ToolbarButton::ToolbarButton (const int iid, const String& buttonText,
std::unique_ptr<Drawable> normalIm,
std::unique_ptr<Drawable> toggledOnIm)
: ToolbarItemComponent (iid, buttonText, true),
normalImage (std::move (normalIm)),
toggledOnImage (std::move (toggledOnIm))
{
jassert (normalImage != nullptr);
}
ToolbarButton::~ToolbarButton()
{
}
//==============================================================================
bool ToolbarButton::getToolbarItemSizes (int toolbarDepth, bool /*isToolbarVertical*/, int& preferredSize, int& minSize, int& maxSize)
{
preferredSize = minSize = maxSize = toolbarDepth;
return true;
}
void ToolbarButton::paintButtonArea (Graphics&, int /*width*/, int /*height*/, bool /*isMouseOver*/, bool /*isMouseDown*/)
{
}
void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
{
buttonStateChanged();
}
void ToolbarButton::setCurrentImage (Drawable* const newImage)
{
if (newImage != currentImage)
{
removeChildComponent (currentImage);
currentImage = newImage;
if (currentImage != nullptr)
{
enablementChanged();
addAndMakeVisible (currentImage);
updateDrawable();
}
}
}
void ToolbarButton::updateDrawable()
{
if (currentImage != nullptr)
{
currentImage->setInterceptsMouseClicks (false, false);
currentImage->setTransformToFit (getContentArea().toFloat(), RectanglePlacement::centred);
currentImage->setAlpha (isEnabled() ? 1.0f : 0.5f);
}
}
void ToolbarButton::resized()
{
ToolbarItemComponent::resized();
updateDrawable();
}
void ToolbarButton::enablementChanged()
{
ToolbarItemComponent::enablementChanged();
updateDrawable();
}
Drawable* ToolbarButton::getImageToUse() const
{
if (getStyle() == Toolbar::textOnly)
return nullptr;
if (getToggleState() && toggledOnImage != nullptr)
return toggledOnImage.get();
return normalImage.get();
}
void ToolbarButton::buttonStateChanged()
{
setCurrentImage (getImageToUse());
}
} // namespace juce

View File

@@ -1,98 +1,98 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A type of button designed to go on a toolbar.
This simple button can have two Drawable objects specified - one for normal
use and another one (optionally) for the button's "on" state if it's a
toggle button.
@see Toolbar, ToolbarItemFactory, ToolbarItemComponent, Drawable, Button
@tags{GUI}
*/
class JUCE_API ToolbarButton : public ToolbarItemComponent
{
public:
//==============================================================================
/** Creates a ToolbarButton.
@param itemId the ID for this toolbar item type. This is passed through to the
ToolbarItemComponent constructor
@param labelText the text to display on the button (if the toolbar is using a style
that shows text labels). This is passed through to the
ToolbarItemComponent constructor
@param normalImage a drawable object that the button should use as its icon. The object
that is passed-in here will be kept by this object and will be
deleted when no longer needed or when this button is deleted.
@param toggledOnImage a drawable object that the button can use as its icon if the button
is in a toggled-on state (see the Button::getToggleState() method). If
nullptr is passed-in here, then the normal image will be used instead,
regardless of the toggle state. The object that is passed-in here will be
owned by this object and will be deleted when no longer needed or when
this button is deleted.
*/
ToolbarButton (int itemId,
const String& labelText,
std::unique_ptr<Drawable> normalImage,
std::unique_ptr<Drawable> toggledOnImage);
/** Destructor. */
~ToolbarButton() override;
//==============================================================================
/** @internal */
bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize,
int& minSize, int& maxSize) override;
/** @internal */
void paintButtonArea (Graphics&, int width, int height, bool isMouseOver, bool isMouseDown) override;
/** @internal */
void contentAreaChanged (const Rectangle<int>&) override;
/** @internal */
void buttonStateChanged() override;
/** @internal */
void resized() override;
/** @internal */
void enablementChanged() override;
private:
//==============================================================================
std::unique_ptr<Drawable> normalImage, toggledOnImage;
Drawable* currentImage = nullptr;
void updateDrawable();
Drawable* getImageToUse() const;
void setCurrentImage (Drawable*);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarButton)
};
} // namespace juce
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A type of button designed to go on a toolbar.
This simple button can have two Drawable objects specified - one for normal
use and another one (optionally) for the button's "on" state if it's a
toggle button.
@see Toolbar, ToolbarItemFactory, ToolbarItemComponent, Drawable, Button
@tags{GUI}
*/
class JUCE_API ToolbarButton : public ToolbarItemComponent
{
public:
//==============================================================================
/** Creates a ToolbarButton.
@param itemId the ID for this toolbar item type. This is passed through to the
ToolbarItemComponent constructor
@param labelText the text to display on the button (if the toolbar is using a style
that shows text labels). This is passed through to the
ToolbarItemComponent constructor
@param normalImage a drawable object that the button should use as its icon. The object
that is passed-in here will be kept by this object and will be
deleted when no longer needed or when this button is deleted.
@param toggledOnImage a drawable object that the button can use as its icon if the button
is in a toggled-on state (see the Button::getToggleState() method). If
nullptr is passed-in here, then the normal image will be used instead,
regardless of the toggle state. The object that is passed-in here will be
owned by this object and will be deleted when no longer needed or when
this button is deleted.
*/
ToolbarButton (int itemId,
const String& labelText,
std::unique_ptr<Drawable> normalImage,
std::unique_ptr<Drawable> toggledOnImage);
/** Destructor. */
~ToolbarButton() override;
//==============================================================================
/** @internal */
bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize,
int& minSize, int& maxSize) override;
/** @internal */
void paintButtonArea (Graphics&, int width, int height, bool isMouseOver, bool isMouseDown) override;
/** @internal */
void contentAreaChanged (const Rectangle<int>&) override;
/** @internal */
void buttonStateChanged() override;
/** @internal */
void resized() override;
/** @internal */
void enablementChanged() override;
private:
//==============================================================================
std::unique_ptr<Drawable> normalImage, toggledOnImage;
Drawable* currentImage = nullptr;
void updateDrawable();
Drawable* getImageToUse() const;
void setCurrentImage (Drawable*);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarButton)
};
} // namespace juce