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.

110 lines
4.8KB

  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. #ifndef __JUCE_RELATIVERECTANGLE_JUCEHEADER__
  19. #define __JUCE_RELATIVERECTANGLE_JUCEHEADER__
  20. #include "juce_RelativeCoordinate.h"
  21. class Component;
  22. //==============================================================================
  23. /**
  24. An rectangle stored as a set of RelativeCoordinate values.
  25. The rectangle's top, left, bottom and right edge positions are each stored as a RelativeCoordinate.
  26. @see RelativeCoordinate, RelativePoint
  27. */
  28. class JUCE_API RelativeRectangle
  29. {
  30. public:
  31. //==============================================================================
  32. /** Creates a zero-size rectangle at the origin. */
  33. RelativeRectangle();
  34. /** Creates an absolute rectangle, relative to the origin. */
  35. explicit RelativeRectangle (const Rectangle<float>& rect);
  36. /** Creates a rectangle from four coordinates. */
  37. RelativeRectangle (const RelativeCoordinate& left, const RelativeCoordinate& right,
  38. const RelativeCoordinate& top, const RelativeCoordinate& bottom);
  39. /** Creates a rectangle from a stringified representation.
  40. The string must contain a sequence of 4 coordinates, separated by commas, in the order
  41. left, top, right, bottom. The syntax for the coordinate strings is explained in the
  42. RelativeCoordinate class.
  43. @see toString
  44. */
  45. explicit RelativeRectangle (const String& stringVersion);
  46. bool operator== (const RelativeRectangle& other) const noexcept;
  47. bool operator!= (const RelativeRectangle& other) const noexcept;
  48. //==============================================================================
  49. /** Calculates the absolute position of this rectangle.
  50. You'll need to provide a suitable Expression::Scope for looking up any coordinates that may
  51. be needed to calculate the result.
  52. */
  53. const Rectangle<float> resolve (const Expression::Scope* scope) const;
  54. /** Changes the values of this rectangle's coordinates to make it resolve to the specified position.
  55. Calling this will leave any anchor points unchanged, but will set any absolute
  56. or relative positions to whatever values are necessary to make the resultant position
  57. match the position that is provided.
  58. */
  59. void moveToAbsolute (const Rectangle<float>& newPos, const Expression::Scope* scope);
  60. /** Returns true if this rectangle depends on any external symbols for its position.
  61. Coordinates that refer to symbols based on "this" are assumed not to be dynamic.
  62. */
  63. bool isDynamic() const;
  64. /** Returns a string which represents this point.
  65. This returns a comma-separated list of coordinates, in the order left, top, right, bottom. For details of
  66. the string syntax used by the coordinates, see the RelativeCoordinate constructor notes.
  67. The string that is returned can be passed to the RelativeRectangle constructor to recreate the rectangle.
  68. */
  69. String toString() const;
  70. /** Renames a symbol if it is used by any of the coordinates.
  71. This calls Expression::withRenamedSymbol() on the rectangle's coordinates.
  72. */
  73. void renameSymbol (const Expression::Symbol& oldSymbol, const String& newName, const Expression::Scope& scope);
  74. /** Creates and sets an appropriate Component::Positioner object for the given component, which will
  75. keep it positioned with this rectangle.
  76. */
  77. void applyToComponent (Component& component) const;
  78. //==============================================================================
  79. // The actual rectangle coords...
  80. RelativeCoordinate left, right, top, bottom;
  81. };
  82. #endif // __JUCE_RELATIVERECTANGLE_JUCEHEADER__