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.

122 lines
5.0KB

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