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.

94 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A type of button designed to go on a toolbar.
  21. This simple button can have two Drawable objects specified - one for normal
  22. use and another one (optionally) for the button's "on" state if it's a
  23. toggle button.
  24. @see Toolbar, ToolbarItemFactory, ToolbarItemComponent, Drawable, Button
  25. */
  26. class JUCE_API ToolbarButton : public ToolbarItemComponent
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a ToolbarButton.
  31. @param itemId the ID for this toolbar item type. This is passed through to the
  32. ToolbarItemComponent constructor
  33. @param labelText the text to display on the button (if the toolbar is using a style
  34. that shows text labels). This is passed through to the
  35. ToolbarItemComponent constructor
  36. @param normalImage a drawable object that the button should use as its icon. The object
  37. that is passed-in here will be kept by this object and will be
  38. deleted when no longer needed or when this button is deleted.
  39. @param toggledOnImage a drawable object that the button can use as its icon if the button
  40. is in a toggled-on state (see the Button::getToggleState() method). If
  41. nullptr is passed-in here, then the normal image will be used instead,
  42. regardless of the toggle state. The object that is passed-in here will be
  43. owned by this object and will be deleted when no longer needed or when
  44. this button is deleted.
  45. */
  46. ToolbarButton (int itemId,
  47. const String& labelText,
  48. Drawable* normalImage,
  49. Drawable* toggledOnImage);
  50. /** Destructor. */
  51. ~ToolbarButton();
  52. //==============================================================================
  53. /** @internal */
  54. bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize,
  55. int& minSize, int& maxSize) override;
  56. /** @internal */
  57. void paintButtonArea (Graphics&, int width, int height, bool isMouseOver, bool isMouseDown) override;
  58. /** @internal */
  59. void contentAreaChanged (const Rectangle<int>&) override;
  60. /** @internal */
  61. void buttonStateChanged() override;
  62. /** @internal */
  63. void resized() override;
  64. /** @internal */
  65. void enablementChanged() override;
  66. private:
  67. //==============================================================================
  68. ScopedPointer<Drawable> normalImage, toggledOnImage;
  69. Drawable* currentImage;
  70. void updateDrawable();
  71. Drawable* getImageToUse() const;
  72. void setCurrentImage (Drawable*);
  73. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarButton)
  74. };