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.

224 lines
9.1KB

  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. //==============================================================================
  19. int64 calculateStreamHashCode (InputStream& stream);
  20. int64 calculateFileHashCode (const File& file);
  21. bool areFilesIdentical (const File& file1, const File& file2);
  22. bool overwriteFileWithNewDataIfDifferent (const File& file, const char* data, int numBytes);
  23. bool overwriteFileWithNewDataIfDifferent (const File& file, const MemoryOutputStream& newData);
  24. bool overwriteFileWithNewDataIfDifferent (const File& file, const String& newData);
  25. bool containsAnyNonHiddenFiles (const File& folder);
  26. //==============================================================================
  27. // String::hashCode64 actually hit some dupes, so this is a more powerful version.
  28. const int64 hashCode64 (const String& s);
  29. const String randomHexString (Random& random, int numChars);
  30. const String hexString8Digits (int value);
  31. const String createAlphaNumericUID();
  32. const String createGUID (const String& seed); // Turns a seed into a windows GUID
  33. const String unixStylePath (const String& path);
  34. const String windowsStylePath (const String& path);
  35. bool shouldPathsBeRelative (String path1, String path2);
  36. //==============================================================================
  37. bool isJuceFolder (const File& folder);
  38. const File findParentJuceFolder (const File& file);
  39. const File findDefaultJuceFolder();
  40. //==============================================================================
  41. const String createIncludeStatement (const File& includeFile, const File& targetFile);
  42. const String makeHeaderGuardName (const File& file);
  43. const String replaceCEscapeChars (const String& s);
  44. const String makeValidCppIdentifier (String s,
  45. const bool capitalise,
  46. const bool removeColons,
  47. const bool allowTemplates);
  48. //==============================================================================
  49. const String boolToCode (const bool b);
  50. const String floatToCode (const float v);
  51. const String doubleToCode (const double v);
  52. const String colourToCode (const Colour& col);
  53. const String justificationToCode (const Justification& justification);
  54. const String castToFloat (const String& expression);
  55. //==============================================================================
  56. const String indentCode (const String& code, const int numSpaces);
  57. int indexOfLineStartingWith (const StringArray& lines, const String& text, int startIndex);
  58. //==============================================================================
  59. class FileModificationDetector
  60. {
  61. public:
  62. FileModificationDetector (const File& file_)
  63. : file (file_)
  64. {
  65. }
  66. const File& getFile() const { return file; }
  67. bool hasBeenModified() const
  68. {
  69. return fileModificationTime != file.getLastModificationTime()
  70. && (fileSize != file.getSize()
  71. || calculateFileHashCode (file) != fileHashCode);
  72. }
  73. void updateHash()
  74. {
  75. fileModificationTime = file.getLastModificationTime();
  76. fileSize = file.getSize();
  77. fileHashCode = calculateFileHashCode (file);
  78. }
  79. private:
  80. File file;
  81. Time fileModificationTime;
  82. int64 fileHashCode, fileSize;
  83. };
  84. //==============================================================================
  85. /**
  86. Holds a co-ordinate along the x or y axis, expressed either as an absolute
  87. position, or relative to other named marker positions.
  88. */
  89. class Coordinate
  90. {
  91. public:
  92. //==============================================================================
  93. /** Creates a zero coordinate. */
  94. Coordinate (bool isHorizontal);
  95. /** Recreates a coordinate from its stringified version. */
  96. explicit Coordinate (const String& stringVersion, bool isHorizontal);
  97. /** Creates an absolute position from the parent origin. */
  98. explicit Coordinate (double absoluteDistanceFromOrigin, bool isHorizontal);
  99. /** Creates an absolute position relative to a named marker. */
  100. Coordinate (double absolutePosition, const String& relativeToMarker, bool isHorizontal);
  101. /** Creates a relative position between two named markers. */
  102. Coordinate (double relativePosition, const String& marker1, const String& marker2, bool isHorizontal);
  103. /** Destructor. */
  104. ~Coordinate();
  105. //==============================================================================
  106. /**
  107. Provides an interface for looking up the position of a named marker.
  108. */
  109. class MarkerResolver
  110. {
  111. public:
  112. virtual ~MarkerResolver() {}
  113. virtual const Coordinate findMarker (const String& name, bool isHorizontal) = 0;
  114. };
  115. /** Calculates the absolute position of this co-ordinate. */
  116. double resolve (MarkerResolver& markerResolver) const;
  117. /** Returns true if this co-ordinate is expressed in terms of markers that form a recursive loop. */
  118. bool isRecursive (MarkerResolver& markerResolver) const;
  119. /** Changes the value of this marker to make it resolve to the specified position. */
  120. void moveToAbsolute (double newPos, MarkerResolver& markerResolver);
  121. const Coordinate getAnchorPoint1() const;
  122. const Coordinate getAnchorPoint2() const;
  123. //==============================================================================
  124. /*
  125. Position string formats:
  126. 123 = absolute pixels from parent origin
  127. marker
  128. marker + 123
  129. marker - 123
  130. 50% = percentage between parent origin and parent extent
  131. 50% * marker = percentage between parent origin and marker
  132. 50% * marker1 -> marker2 = percentage between two markers
  133. standard marker names:
  134. "origin" = parent origin
  135. "size" = parent right or bottom
  136. "top", "left", "bottom", "right" = refer to the component's own left, right, top and bottom.
  137. */
  138. const String toString() const;
  139. //==============================================================================
  140. static const char* parentLeftMarkerName;
  141. static const char* parentRightMarkerName;
  142. static const char* parentTopMarkerName;
  143. static const char* parentBottomMarkerName;
  144. private:
  145. //==============================================================================
  146. String anchor1, anchor2;
  147. double value;
  148. bool isProportion, isHorizontal;
  149. double resolve (MarkerResolver& markerResolver, int recursionCounter) const;
  150. double getPosition (const String& name, MarkerResolver& markerResolver, int recursionCounter) const;
  151. const String checkName (const String& name) const;
  152. const String getOriginMarkerName() const;
  153. const String getExtentMarkerName() const;
  154. static bool isOrigin (const String& name);
  155. static void skipWhitespace (const String& s, int& i);
  156. static const String readMarkerName (const String& s, int& i);
  157. static double readNumber (const String& s, int& i);
  158. };
  159. //==============================================================================
  160. /**
  161. Describes a rectangle as a set of Coordinate values.
  162. */
  163. class RectangleCoordinates
  164. {
  165. public:
  166. //==============================================================================
  167. RectangleCoordinates();
  168. explicit RectangleCoordinates (const Rectangle<int>& rect);
  169. explicit RectangleCoordinates (const String& stringVersion);
  170. //==============================================================================
  171. const Rectangle<int> resolve (Coordinate::MarkerResolver& markerResolver) const;
  172. bool isRecursive (Coordinate::MarkerResolver& markerResolver) const;
  173. void moveToAbsolute (const Rectangle<int>& newPos, Coordinate::MarkerResolver& markerResolver);
  174. const String toString() const;
  175. Coordinate left, right, top, bottom;
  176. };