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.

162 lines
6.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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 __JUCER_COORDINATE_H_EF56ACFA__
  19. #define __JUCER_COORDINATE_H_EF56ACFA__
  20. #include "../jucer_Headers.h"
  21. //==============================================================================
  22. /**
  23. Holds a co-ordinate along the x or y axis, expressed either as an absolute
  24. position, or relative to other named marker positions.
  25. */
  26. class Coordinate
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a zero coordinate. */
  31. explicit Coordinate (bool isHorizontal);
  32. /** Recreates a coordinate from its stringified version. */
  33. Coordinate (const String& stringVersion, bool isHorizontal);
  34. /** Creates an absolute position from the parent origin. */
  35. Coordinate (double absoluteDistanceFromOrigin, bool isHorizontal);
  36. /** Creates an absolute position relative to a named marker. */
  37. Coordinate (double absolutePosition, const String& relativeToMarker, bool isHorizontal);
  38. /** Creates a relative position between two named markers. */
  39. Coordinate (double relativePosition, const String& marker1, const String& marker2, bool isHorizontal);
  40. /** Destructor. */
  41. ~Coordinate();
  42. //==============================================================================
  43. /**
  44. Provides an interface for looking up the position of a named marker.
  45. */
  46. class MarkerResolver
  47. {
  48. public:
  49. virtual ~MarkerResolver() {}
  50. virtual const Coordinate findMarker (const String& name, bool isHorizontal) const = 0;
  51. };
  52. /** Calculates the absolute position of this co-ordinate. */
  53. double resolve (const MarkerResolver& markerResolver) const;
  54. /** Returns true if this co-ordinate is expressed directly in terms of the specified marker. */
  55. bool referencesDirectly (const String& markerName) const;
  56. /** Returns true if this co-ordinate is expressed in terms of the specified marker at any
  57. level in its evaluation. */
  58. bool referencesIndirectly (const String& markerName, const MarkerResolver& markerResolver) const;
  59. /** Changes the value of this marker to make it resolve to the specified position. */
  60. void moveToAbsolute (double newPos, const MarkerResolver& markerResolver);
  61. const Coordinate getAnchorPoint1() const;
  62. const Coordinate getAnchorPoint2() const;
  63. const double getEditableValue() const;
  64. void setEditableValue (const double newValue);
  65. bool isHorizontal() const throw() { return horizontal; }
  66. bool isProportional() const throw() { return isProportion; }
  67. void toggleProportionality (const MarkerResolver& markerResolver);
  68. const String getAnchor1() const { return checkName (anchor1); }
  69. void changeAnchor1 (const String& newMarkerName, const MarkerResolver& markerResolver);
  70. const String getAnchor2() const { return checkName (anchor2); }
  71. void changeAnchor2 (const String& newMarkerName, const MarkerResolver& markerResolver);
  72. //==============================================================================
  73. /*
  74. Position string formats:
  75. 123 = absolute pixels from parent origin
  76. marker
  77. marker + 123
  78. marker - 123
  79. 50% = percentage between parent origin and parent extent
  80. 50% * marker = percentage between parent origin and marker
  81. 50% * marker1 -> marker2 = percentage between two markers
  82. standard marker names:
  83. "parent.top", "parent.left", "parent.bottom", "parent.right"
  84. "componentName.top", "componentName.left", "componentName.bottom", "componentName.right"
  85. */
  86. const String toString() const;
  87. //==============================================================================
  88. static const char* parentLeftMarkerName;
  89. static const char* parentRightMarkerName;
  90. static const char* parentTopMarkerName;
  91. static const char* parentBottomMarkerName;
  92. private:
  93. //==============================================================================
  94. String anchor1, anchor2;
  95. double value;
  96. bool isProportion, horizontal;
  97. double resolve (const MarkerResolver& markerResolver, int recursionCounter) const;
  98. double getPosition (const String& name, const MarkerResolver& markerResolver, int recursionCounter) const;
  99. const String checkName (const String& name) const;
  100. const String getOriginMarkerName() const;
  101. const String getExtentMarkerName() const;
  102. static bool isOrigin (const String& name);
  103. static void skipWhitespace (const String& s, int& i);
  104. static const String readMarkerName (const String& s, int& i);
  105. static double readNumber (const String& s, int& i);
  106. };
  107. //==============================================================================
  108. /**
  109. Describes a rectangle as a set of Coordinate values.
  110. */
  111. class RectangleCoordinates
  112. {
  113. public:
  114. //==============================================================================
  115. RectangleCoordinates();
  116. explicit RectangleCoordinates (const Rectangle<int>& rect, const String& componentName);
  117. explicit RectangleCoordinates (const String& stringVersion);
  118. //==============================================================================
  119. const Rectangle<int> resolve (const Coordinate::MarkerResolver& markerResolver) const;
  120. void moveToAbsolute (const Rectangle<int>& newPos, const Coordinate::MarkerResolver& markerResolver);
  121. const String toString() const;
  122. Coordinate left, right, top, bottom;
  123. };
  124. #endif // __JUCER_COORDINATE_H_EF56ACFA__