JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ToolbarButton.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
33 normalImage (std::move (normalIm)),
34 toggledOnImage (std::move (toggledOnIm))
35{
36 jassert (normalImage != nullptr);
37}
38
42
43//==============================================================================
44bool ToolbarButton::getToolbarItemSizes (int toolbarDepth, bool /*isToolbarVertical*/, int& preferredSize, int& minSize, int& maxSize)
45{
46 preferredSize = minSize = maxSize = toolbarDepth;
47 return true;
48}
49
50void ToolbarButton::paintButtonArea (Graphics&, int /*width*/, int /*height*/, bool /*isMouseOver*/, bool /*isMouseDown*/)
51{
52}
53
58
59void ToolbarButton::setCurrentImage (Drawable* const newImage)
60{
61 if (newImage != currentImage)
62 {
63 removeChildComponent (currentImage);
64 currentImage = newImage;
65
66 if (currentImage != nullptr)
67 {
69 addAndMakeVisible (currentImage);
70 updateDrawable();
71 }
72 }
73}
74
75void ToolbarButton::updateDrawable()
76{
77 if (currentImage != nullptr)
78 {
79 currentImage->setInterceptsMouseClicks (false, false);
81 currentImage->setAlpha (isEnabled() ? 1.0f : 0.5f);
82 }
83}
84
86{
88 updateDrawable();
89}
90
96
97Drawable* ToolbarButton::getImageToUse() const
98{
100 return nullptr;
101
102 if (getToggleState() && toggledOnImage != nullptr)
103 return toggledOnImage.get();
104
105 return normalImage.get();
106}
107
109{
110 setCurrentImage (getImageToUse());
111}
112
113} // namespace juce
bool getToggleState() const noexcept
Returns true if the button is 'on'.
void enablementChanged() override
Callback to indicate that this component has been enabled or disabled.
void setInterceptsMouseClicks(bool allowClicksOnThisComponent, bool allowClicksOnChildComponents) noexcept
Changes the default return value for the hitTest() method.
void setAlpha(float newAlpha)
Changes the transparency of this component.
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
void removeChildComponent(Component *childToRemove)
Removes one of this component's child-components.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
The base class for objects which can draw themselves, e.g.
void setTransformToFit(const Rectangle< float > &areaInParent, RectanglePlacement placement)
Sets a transform for this drawable that will position it within the specified area of its parent comp...
A graphics context, used for drawing a component or image.
@ centred
A shorthand value that is equivalent to (xMid | yMid).
Manages a rectangle and allows geometric operations to be performed on it.
The JUCE String class!
Definition juce_String.h:53
void buttonStateChanged() override
Called when the button's up/down/over state changes.
void resized() override
Called when this component's size has been changed.
void paintButtonArea(Graphics &, int width, int height, bool isMouseOver, bool isMouseDown) override
Your subclass should use this method to draw its content area.
ToolbarButton(int itemId, const String &labelText, std::unique_ptr< Drawable > normalImage, std::unique_ptr< Drawable > toggledOnImage)
Creates a ToolbarButton.
~ToolbarButton() override
Destructor.
void contentAreaChanged(const Rectangle< int > &) override
Callback to indicate that the content area of this item has changed.
void enablementChanged() override
Callback to indicate that this component has been enabled or disabled.
bool getToolbarItemSizes(int toolbarDepth, bool isToolbarVertical, int &preferredSize, int &minSize, int &maxSize) override
This method must return the size criteria for this item, based on a given toolbar size and orientatio...
A component that can be used as one of the items in a Toolbar.
Rectangle< int > getContentArea() const noexcept
Returns the area of the component that should be used to display the button image or other contents o...
Toolbar::ToolbarItemStyle getStyle() const noexcept
Returns the current style setting of this item.
void resized() override
Called when this component's size has been changed.
@ textOnly
Means that the toolbar only display text labels for each item.
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88