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.

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