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.

100 lines
4.0KB

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