VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_gui_basics / buttons / juce_ToolbarButton.cpp
blob27c94dd9fbd4e9d4ed2326b0d115540f39b3d3d8
1 /*
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
8 licensing.
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
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
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;
47 return true;
50 void ToolbarButton::paintButtonArea (Graphics&, int /*width*/, int /*height*/, bool /*isMouseOver*/, bool /*isMouseDown*/)
54 void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
56 buttonStateChanged();
59 void ToolbarButton::setCurrentImage (Drawable* const newImage)
61 if (newImage != currentImage)
63 removeChildComponent (currentImage);
64 currentImage = newImage;
66 if (currentImage != nullptr)
68 enablementChanged();
69 addAndMakeVisible (currentImage);
70 updateDrawable();
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();
88 updateDrawable();
91 void ToolbarButton::enablementChanged()
93 ToolbarItemComponent::enablementChanged();
94 updateDrawable();
97 Drawable* ToolbarButton::getImageToUse() const
99 if (getStyle() == Toolbar::textOnly)
100 return nullptr;
102 if (getToggleState() && toggledOnImage != nullptr)
103 return toggledOnImage.get();
105 return normalImage.get();
108 void ToolbarButton::buttonStateChanged()
110 setCurrentImage (getImageToUse());
113 } // namespace juce