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.

111 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../../core/juce_StandardHeader.h"
  19. BEGIN_JUCE_NAMESPACE
  20. #include "juce_ToolbarButton.h"
  21. #include "../controls/juce_ToolbarItemFactory.h"
  22. #include "../../graphics/imaging/juce_Image.h"
  23. #include "../lookandfeel/juce_LookAndFeel.h"
  24. //==============================================================================
  25. ToolbarButton::ToolbarButton (const int itemId_, const String& buttonText,
  26. Drawable* const normalImage_, Drawable* const toggledOnImage_)
  27. : ToolbarItemComponent (itemId_, buttonText, true),
  28. normalImage (normalImage_),
  29. toggledOnImage (toggledOnImage_),
  30. currentImage (0)
  31. {
  32. jassert (normalImage_ != 0);
  33. }
  34. ToolbarButton::~ToolbarButton()
  35. {
  36. }
  37. //==============================================================================
  38. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth, bool /*isToolbarVertical*/, int& preferredSize, int& minSize, int& maxSize)
  39. {
  40. preferredSize = minSize = maxSize = toolbarDepth;
  41. return true;
  42. }
  43. void ToolbarButton::paintButtonArea (Graphics&, int /*width*/, int /*height*/, bool /*isMouseOver*/, bool /*isMouseDown*/)
  44. {
  45. }
  46. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  47. {
  48. buttonStateChanged();
  49. }
  50. void ToolbarButton::updateDrawable()
  51. {
  52. if (currentImage != 0)
  53. {
  54. currentImage->setTransformToFit (getContentArea().toFloat(), RectanglePlacement::centred);
  55. currentImage->setAlpha (isEnabled() ? 1.0f : 0.5f);
  56. }
  57. }
  58. void ToolbarButton::resized()
  59. {
  60. ToolbarItemComponent::resized();
  61. updateDrawable();
  62. }
  63. void ToolbarButton::enablementChanged()
  64. {
  65. ToolbarItemComponent::enablementChanged();
  66. updateDrawable();
  67. }
  68. void ToolbarButton::buttonStateChanged()
  69. {
  70. Drawable* d = normalImage;
  71. if (getToggleState() && toggledOnImage != 0)
  72. d = toggledOnImage;
  73. if (d != currentImage)
  74. {
  75. removeChildComponent (currentImage);
  76. currentImage = d;
  77. if (d != 0)
  78. {
  79. enablementChanged();
  80. addAndMakeVisible (d);
  81. updateDrawable();
  82. }
  83. }
  84. }
  85. END_JUCE_NAMESPACE