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.

juce_ToolbarButton.h 3.8KB

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