The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. ToolbarButton::ToolbarButton (const int itemId_, const String& buttonText,
  21. Drawable* const normalImage_, Drawable* const toggledOnImage_)
  22. : ToolbarItemComponent (itemId_, buttonText, true),
  23. normalImage (normalImage_),
  24. toggledOnImage (toggledOnImage_),
  25. currentImage (nullptr)
  26. {
  27. jassert (normalImage_ != nullptr);
  28. }
  29. ToolbarButton::~ToolbarButton()
  30. {
  31. }
  32. //==============================================================================
  33. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth, bool /*isToolbarVertical*/, int& preferredSize, int& minSize, int& maxSize)
  34. {
  35. preferredSize = minSize = maxSize = toolbarDepth;
  36. return true;
  37. }
  38. void ToolbarButton::paintButtonArea (Graphics&, int /*width*/, int /*height*/, bool /*isMouseOver*/, bool /*isMouseDown*/)
  39. {
  40. }
  41. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  42. {
  43. buttonStateChanged();
  44. }
  45. void ToolbarButton::updateDrawable()
  46. {
  47. if (currentImage != nullptr)
  48. {
  49. currentImage->setTransformToFit (getContentArea().toFloat(), RectanglePlacement::centred);
  50. currentImage->setAlpha (isEnabled() ? 1.0f : 0.5f);
  51. }
  52. }
  53. void ToolbarButton::resized()
  54. {
  55. ToolbarItemComponent::resized();
  56. updateDrawable();
  57. }
  58. void ToolbarButton::enablementChanged()
  59. {
  60. ToolbarItemComponent::enablementChanged();
  61. updateDrawable();
  62. }
  63. void ToolbarButton::buttonStateChanged()
  64. {
  65. Drawable* d = normalImage;
  66. if (getToggleState() && toggledOnImage != nullptr)
  67. d = toggledOnImage;
  68. if (d != currentImage)
  69. {
  70. removeChildComponent (currentImage);
  71. currentImage = d;
  72. if (d != nullptr)
  73. {
  74. enablementChanged();
  75. addAndMakeVisible (d);
  76. updateDrawable();
  77. }
  78. }
  79. }
  80. END_JUCE_NAMESPACE