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.

96 lines
3.1KB

  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_,
  26. const String& buttonText,
  27. Drawable* const normalImage_,
  28. Drawable* const toggledOnImage_)
  29. : ToolbarItemComponent (itemId_, buttonText, true),
  30. normalImage (normalImage_),
  31. toggledOnImage (toggledOnImage_)
  32. {
  33. jassert (normalImage_ != 0);
  34. }
  35. ToolbarButton::~ToolbarButton()
  36. {
  37. }
  38. //==============================================================================
  39. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  40. bool /*isToolbarVertical*/,
  41. int& preferredSize,
  42. int& minSize, int& maxSize)
  43. {
  44. preferredSize = minSize = maxSize = toolbarDepth;
  45. return true;
  46. }
  47. void ToolbarButton::paintButtonArea (Graphics& g,
  48. int width, int height,
  49. bool /*isMouseOver*/,
  50. bool /*isMouseDown*/)
  51. {
  52. Drawable* d = normalImage;
  53. if (getToggleState() && toggledOnImage != 0)
  54. d = toggledOnImage;
  55. if (! isEnabled())
  56. {
  57. Image im (Image::ARGB, width, height, true);
  58. {
  59. Graphics g2 (im);
  60. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  61. }
  62. im.desaturate();
  63. g.drawImageAt (im, 0, 0);
  64. }
  65. else
  66. {
  67. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  68. }
  69. }
  70. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  71. {
  72. }
  73. END_JUCE_NAMESPACE