Audio plugin host https://kx.studio/carla
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.

99 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A type of button designed to go on a toolbar.
  23. This simple button can have two Drawable objects specified - one for normal
  24. use and another one (optionally) for the button's "on" state if it's a
  25. toggle button.
  26. @see Toolbar, ToolbarItemFactory, ToolbarItemComponent, Drawable, Button
  27. @tags{GUI}
  28. */
  29. class JUCE_API ToolbarButton : public ToolbarItemComponent
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates a ToolbarButton.
  34. @param itemId the ID for this toolbar item type. This is passed through to the
  35. ToolbarItemComponent constructor
  36. @param labelText the text to display on the button (if the toolbar is using a style
  37. that shows text labels). This is passed through to the
  38. ToolbarItemComponent constructor
  39. @param normalImage a drawable object that the button should use as its icon. The object
  40. that is passed-in here will be kept by this object and will be
  41. deleted when no longer needed or when this button is deleted.
  42. @param toggledOnImage a drawable object that the button can use as its icon if the button
  43. is in a toggled-on state (see the Button::getToggleState() method). If
  44. nullptr is passed-in here, then the normal image will be used instead,
  45. regardless of the toggle state. The object that is passed-in here will be
  46. owned by this object and will be deleted when no longer needed or when
  47. this button is deleted.
  48. */
  49. ToolbarButton (int itemId,
  50. const String& labelText,
  51. std::unique_ptr<Drawable> normalImage,
  52. std::unique_ptr<Drawable> toggledOnImage);
  53. /** Destructor. */
  54. ~ToolbarButton() override;
  55. //==============================================================================
  56. /** @internal */
  57. bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize,
  58. int& minSize, int& maxSize) override;
  59. /** @internal */
  60. void paintButtonArea (Graphics&, int width, int height, bool isMouseOver, bool isMouseDown) override;
  61. /** @internal */
  62. void contentAreaChanged (const Rectangle<int>&) override;
  63. /** @internal */
  64. void buttonStateChanged() override;
  65. /** @internal */
  66. void resized() override;
  67. /** @internal */
  68. void enablementChanged() override;
  69. private:
  70. //==============================================================================
  71. std::unique_ptr<Drawable> normalImage, toggledOnImage;
  72. Drawable* currentImage = nullptr;
  73. void updateDrawable();
  74. Drawable* getImageToUse() const;
  75. void setCurrentImage (Drawable*);
  76. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarButton)
  77. };
  78. } // namespace juce