2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
23 ==============================================================================
29 ToolbarButton::ToolbarButton (const int iid
, const String
& buttonText
,
30 std::unique_ptr
<Drawable
> normalIm
,
31 std::unique_ptr
<Drawable
> toggledOnIm
)
32 : ToolbarItemComponent (iid
, buttonText
, true),
33 normalImage (std::move (normalIm
)),
34 toggledOnImage (std::move (toggledOnIm
))
36 jassert (normalImage
!= nullptr);
39 ToolbarButton::~ToolbarButton()
43 //==============================================================================
44 bool ToolbarButton::getToolbarItemSizes (int toolbarDepth
, bool /*isToolbarVertical*/, int& preferredSize
, int& minSize
, int& maxSize
)
46 preferredSize
= minSize
= maxSize
= toolbarDepth
;
50 void ToolbarButton::paintButtonArea (Graphics
&, int /*width*/, int /*height*/, bool /*isMouseOver*/, bool /*isMouseDown*/)
54 void ToolbarButton::contentAreaChanged (const Rectangle
<int>&)
59 void ToolbarButton::setCurrentImage (Drawable
* const newImage
)
61 if (newImage
!= currentImage
)
63 removeChildComponent (currentImage
);
64 currentImage
= newImage
;
66 if (currentImage
!= nullptr)
69 addAndMakeVisible (currentImage
);
75 void ToolbarButton::updateDrawable()
77 if (currentImage
!= nullptr)
79 currentImage
->setInterceptsMouseClicks (false, false);
80 currentImage
->setTransformToFit (getContentArea().toFloat(), RectanglePlacement::centred
);
81 currentImage
->setAlpha (isEnabled() ? 1.0f
: 0.5f
);
85 void ToolbarButton::resized()
87 ToolbarItemComponent::resized();
91 void ToolbarButton::enablementChanged()
93 ToolbarItemComponent::enablementChanged();
97 Drawable
* ToolbarButton::getImageToUse() const
99 if (getStyle() == Toolbar::textOnly
)
102 if (getToggleState() && toggledOnImage
!= nullptr)
103 return toggledOnImage
.get();
105 return normalImage
.get();
108 void ToolbarButton::buttonStateChanged()
110 setCurrentImage (getImageToUse());