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.

126 lines
5.1KB

  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. #ifndef JUCE_SHAPEBUTTON_H_INCLUDED
  18. #define JUCE_SHAPEBUTTON_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A button that contains a filled shape.
  22. @see Button, ImageButton, TextButton, ArrowButton
  23. */
  24. class JUCE_API ShapeButton : public Button
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a ShapeButton.
  29. @param name a name to give the component - see Component::setName()
  30. @param normalColour the colour to fill the shape with when the mouse isn't over
  31. @param overColour the colour to use when the mouse is over the shape
  32. @param downColour the colour to use when the button is in the pressed-down state
  33. */
  34. ShapeButton (const String& name,
  35. Colour normalColour,
  36. Colour overColour,
  37. Colour downColour);
  38. /** Destructor. */
  39. ~ShapeButton();
  40. //==============================================================================
  41. /** Sets the shape to use.
  42. @param newShape the shape to use
  43. @param resizeNowToFitThisShape if true, the button will be resized to fit the shape's bounds
  44. @param maintainShapeProportions if true, the shape's proportions will be kept fixed when
  45. the button is resized
  46. @param hasDropShadow if true, the button will be given a drop-shadow effect
  47. */
  48. void setShape (const Path& newShape,
  49. bool resizeNowToFitThisShape,
  50. bool maintainShapeProportions,
  51. bool hasDropShadow);
  52. /** Set the colours to use for drawing the shape.
  53. @param normalColour the colour to fill the shape with when the mouse isn't over
  54. @param overColour the colour to use when the mouse is over the shape
  55. @param downColour the colour to use when the button is in the pressed-down state
  56. */
  57. void setColours (Colour normalColour,
  58. Colour overColour,
  59. Colour downColour);
  60. /** Sets the colours to use for drawing the shape when the button's toggle state is 'on'. To enable this behaviour, use the
  61. shouldUseOnColours() method.
  62. @param normalColour the colour to fill the shape with when the mouse isn't over and the button's toggle state is 'on'
  63. @param overColour the colour to use when the mouse is over the shape and the button's toggle state is 'on'
  64. @param downColour the colour to use when the button is in the pressed-down state and the button's toggle state is 'on'
  65. */
  66. void setOnColours (Colour normalColourOn,
  67. Colour overColourOn,
  68. Colour downColourOn);
  69. /** Set whether the button should use the 'on' set of colours when its toggle state is 'on'.
  70. By default these will be the same as the normal colours but the setOnColours method can be
  71. used to provide a different set of colours.
  72. */
  73. void shouldUseOnColours (bool shouldUse);
  74. /** Sets up an outline to draw around the shape.
  75. @param outlineColour the colour to use
  76. @param outlineStrokeWidth the thickness of line to draw
  77. */
  78. void setOutline (Colour outlineColour, float outlineStrokeWidth);
  79. /** This lets you specify a border to be left around the edge of the button when
  80. drawing the shape.
  81. */
  82. void setBorderSize (BorderSize<int> border);
  83. /** @internal */
  84. void paintButton (Graphics&, bool isMouseOverButton, bool isButtonDown) override;
  85. private:
  86. //==============================================================================
  87. Colour normalColour, overColour, downColour,
  88. normalColourOn, overColourOn, downColourOn, outlineColour;
  89. bool useOnColours;
  90. DropShadowEffect shadow;
  91. Path shape;
  92. BorderSize<int> border;
  93. bool maintainShapeProportions;
  94. float outlineWidth;
  95. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ShapeButton)
  96. };
  97. #endif // JUCE_SHAPEBUTTON_H_INCLUDED