Audio plugin host https://kx.studio/carla
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.

juce_DrawableRectangle.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. DrawableRectangle::DrawableRectangle() {}
  21. DrawableRectangle::~DrawableRectangle() {}
  22. DrawableRectangle::DrawableRectangle (const DrawableRectangle& other)
  23. : DrawableShape (other),
  24. bounds (other.bounds),
  25. cornerSize (other.cornerSize)
  26. {
  27. rebuildPath();
  28. }
  29. std::unique_ptr<Drawable> DrawableRectangle::createCopy() const
  30. {
  31. return std::make_unique<DrawableRectangle> (*this);
  32. }
  33. //==============================================================================
  34. void DrawableRectangle::setRectangle (Parallelogram<float> newBounds)
  35. {
  36. if (bounds != newBounds)
  37. {
  38. bounds = newBounds;
  39. rebuildPath();
  40. }
  41. }
  42. void DrawableRectangle::setCornerSize (Point<float> newSize)
  43. {
  44. if (cornerSize != newSize)
  45. {
  46. cornerSize = newSize;
  47. rebuildPath();
  48. }
  49. }
  50. void DrawableRectangle::rebuildPath()
  51. {
  52. auto w = bounds.getWidth();
  53. auto h = bounds.getHeight();
  54. Path newPath;
  55. if (cornerSize.x > 0 && cornerSize.y > 0)
  56. newPath.addRoundedRectangle (0, 0, w, h, cornerSize.x, cornerSize.y);
  57. else
  58. newPath.addRectangle (0, 0, w, h);
  59. newPath.applyTransform (AffineTransform::fromTargetPoints (Point<float>(), bounds.topLeft,
  60. Point<float> (w, 0), bounds.topRight,
  61. Point<float> (0, h), bounds.bottomLeft));
  62. if (path != newPath)
  63. {
  64. path.swapWithPath (newPath);
  65. pathChanged();
  66. }
  67. }
  68. } // namespace juce