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.9KB

  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. #pragma once
  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. */
  28. class JUCE_API ToolbarButton : public ToolbarItemComponent
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a ToolbarButton.
  33. @param itemId the ID for this toolbar item type. This is passed through to the
  34. ToolbarItemComponent constructor
  35. @param labelText the text to display on the button (if the toolbar is using a style
  36. that shows text labels). This is passed through to the
  37. ToolbarItemComponent constructor
  38. @param normalImage a drawable object that the button should use as its icon. The object
  39. that is passed-in here will be kept by this object and will be
  40. deleted when no longer needed or when this button is deleted.
  41. @param toggledOnImage a drawable object that the button can use as its icon if the button
  42. is in a toggled-on state (see the Button::getToggleState() method). If
  43. nullptr is passed-in here, then the normal image will be used instead,
  44. regardless of the toggle state. The object that is passed-in here will be
  45. owned by this object and will be deleted when no longer needed or when
  46. this button is deleted.
  47. */
  48. ToolbarButton (int itemId,
  49. const String& labelText,
  50. Drawable* normalImage,
  51. Drawable* toggledOnImage);
  52. /** Destructor. */
  53. ~ToolbarButton();
  54. //==============================================================================
  55. /** @internal */
  56. bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize,
  57. int& minSize, int& maxSize) override;
  58. /** @internal */
  59. void paintButtonArea (Graphics&, int width, int height, bool isMouseOver, bool isMouseDown) override;
  60. /** @internal */
  61. void contentAreaChanged (const Rectangle<int>&) override;
  62. /** @internal */
  63. void buttonStateChanged() override;
  64. /** @internal */
  65. void resized() override;
  66. /** @internal */
  67. void enablementChanged() override;
  68. private:
  69. //==============================================================================
  70. ScopedPointer<Drawable> normalImage, toggledOnImage;
  71. Drawable* currentImage;
  72. void updateDrawable();
  73. Drawable* getImageToUse() const;
  74. void setCurrentImage (Drawable*);
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToolbarButton)
  76. };