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.

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