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.

136 lines
5.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. RelativeParallelogram::RelativeParallelogram()
  19. {
  20. }
  21. RelativeParallelogram::RelativeParallelogram (const Rectangle<float>& r)
  22. : topLeft (r.getTopLeft()), topRight (r.getTopRight()), bottomLeft (r.getBottomLeft())
  23. {
  24. }
  25. RelativeParallelogram::RelativeParallelogram (const RelativePoint& topLeft_, const RelativePoint& topRight_, const RelativePoint& bottomLeft_)
  26. : topLeft (topLeft_), topRight (topRight_), bottomLeft (bottomLeft_)
  27. {
  28. }
  29. RelativeParallelogram::RelativeParallelogram (const String& topLeft_, const String& topRight_, const String& bottomLeft_)
  30. : topLeft (topLeft_), topRight (topRight_), bottomLeft (bottomLeft_)
  31. {
  32. }
  33. RelativeParallelogram::~RelativeParallelogram()
  34. {
  35. }
  36. void RelativeParallelogram::resolveThreePoints (Point<float>* points, Expression::Scope* const scope) const
  37. {
  38. points[0] = topLeft.resolve (scope);
  39. points[1] = topRight.resolve (scope);
  40. points[2] = bottomLeft.resolve (scope);
  41. }
  42. void RelativeParallelogram::resolveFourCorners (Point<float>* points, Expression::Scope* const scope) const
  43. {
  44. resolveThreePoints (points, scope);
  45. points[3] = points[1] + (points[2] - points[0]);
  46. }
  47. const Rectangle<float> RelativeParallelogram::getBounds (Expression::Scope* const scope) const
  48. {
  49. Point<float> points[4];
  50. resolveFourCorners (points, scope);
  51. return Rectangle<float>::findAreaContainingPoints (points, 4);
  52. }
  53. void RelativeParallelogram::getPath (Path& path, Expression::Scope* const scope) const
  54. {
  55. Point<float> points[4];
  56. resolveFourCorners (points, scope);
  57. path.startNewSubPath (points[0]);
  58. path.lineTo (points[1]);
  59. path.lineTo (points[3]);
  60. path.lineTo (points[2]);
  61. path.closeSubPath();
  62. }
  63. const AffineTransform RelativeParallelogram::resetToPerpendicular (Expression::Scope* const scope)
  64. {
  65. Point<float> corners[3];
  66. resolveThreePoints (corners, scope);
  67. const Line<float> top (corners[0], corners[1]);
  68. const Line<float> left (corners[0], corners[2]);
  69. const Point<float> newTopRight (corners[0] + Point<float> (top.getLength(), 0.0f));
  70. const Point<float> newBottomLeft (corners[0] + Point<float> (0.0f, left.getLength()));
  71. topRight.moveToAbsolute (newTopRight, scope);
  72. bottomLeft.moveToAbsolute (newBottomLeft, scope);
  73. return AffineTransform::fromTargetPoints (corners[0].x, corners[0].y, corners[0].x, corners[0].y,
  74. corners[1].x, corners[1].y, newTopRight.x, newTopRight.y,
  75. corners[2].x, corners[2].y, newBottomLeft.x, newBottomLeft.y);
  76. }
  77. bool RelativeParallelogram::isDynamic() const
  78. {
  79. return topLeft.isDynamic() || topRight.isDynamic() || bottomLeft.isDynamic();
  80. }
  81. bool RelativeParallelogram::operator== (const RelativeParallelogram& other) const noexcept
  82. {
  83. return topLeft == other.topLeft && topRight == other.topRight && bottomLeft == other.bottomLeft;
  84. }
  85. bool RelativeParallelogram::operator!= (const RelativeParallelogram& other) const noexcept
  86. {
  87. return ! operator== (other);
  88. }
  89. const Point<float> RelativeParallelogram::getInternalCoordForPoint (const Point<float>* const corners, Point<float> target) noexcept
  90. {
  91. const Point<float> tr (corners[1] - corners[0]);
  92. const Point<float> bl (corners[2] - corners[0]);
  93. target -= corners[0];
  94. return Point<float> (Line<float> (Point<float>(), tr).getIntersection (Line<float> (target, target - bl)).getDistanceFromOrigin(),
  95. Line<float> (Point<float>(), bl).getIntersection (Line<float> (target, target - tr)).getDistanceFromOrigin());
  96. }
  97. const Point<float> RelativeParallelogram::getPointForInternalCoord (const Point<float>* const corners, const Point<float>& point) noexcept
  98. {
  99. return corners[0]
  100. + Line<float> (Point<float>(), corners[1] - corners[0]).getPointAlongLine (point.x)
  101. + Line<float> (Point<float>(), corners[2] - corners[0]).getPointAlongLine (point.y);
  102. }
  103. const Rectangle<float> RelativeParallelogram::getBoundingBox (const Point<float>* const p) noexcept
  104. {
  105. const Point<float> points[] = { p[0], p[1], p[2], p[1] + (p[2] - p[0]) };
  106. return Rectangle<float>::findAreaContainingPoints (points, 4);
  107. }