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.

274 lines
8.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. // String::hashCode64 actually hit some dupes, so this is a more powerful version.
  20. const int64 hashCode64 (const String& s);
  21. const String randomHexString (Random& random, int numChars);
  22. const String hexString8Digits (int value);
  23. const String createAlphaNumericUID();
  24. const String createGUID (const String& seed); // Turns a seed into a windows GUID
  25. const StringPairArray parsePreprocessorDefs (const String& defs);
  26. const StringPairArray mergePreprocessorDefs (StringPairArray inheritedDefs, const StringPairArray& overridingDefs);
  27. const String replacePreprocessorDefs (const StringPairArray& definitions, String sourceString);
  28. //==============================================================================
  29. int indexOfLineStartingWith (const StringArray& lines, const String& text, int startIndex);
  30. void autoScrollForMouseEvent (const MouseEvent& e, bool scrollX = true, bool scrollY = true);
  31. void drawComponentPlaceholder (Graphics& g, int w, int h, const String& text);
  32. void drawRecessedShadows (Graphics& g, int w, int h, int shadowSize);
  33. //==============================================================================
  34. class PropertyPanelWithTooltips : public Component,
  35. public Timer
  36. {
  37. public:
  38. PropertyPanelWithTooltips();
  39. ~PropertyPanelWithTooltips();
  40. PropertyPanel* getPanel() const { return panel; }
  41. void paint (Graphics& g);
  42. void resized();
  43. void timerCallback();
  44. private:
  45. PropertyPanel* panel;
  46. TextLayout layout;
  47. Component* lastComp;
  48. String lastTip;
  49. const String findTip (Component* c);
  50. };
  51. //==============================================================================
  52. class FloatingLabelComponent : public Component
  53. {
  54. public:
  55. FloatingLabelComponent();
  56. void remove();
  57. void update (Component* parent, const String& text, const Colour& textColour, int x, int y, bool toRight, bool below);
  58. void paint (Graphics& g);
  59. private:
  60. Font font;
  61. Colour colour;
  62. GlyphArrangement glyphs;
  63. };
  64. //==============================================================================
  65. class JucerToolbarButton : public ToolbarItemComponent
  66. {
  67. public:
  68. //==============================================================================
  69. JucerToolbarButton (int itemId_, const String& labelText)
  70. : ToolbarItemComponent (itemId_, labelText, true)
  71. {
  72. setClickingTogglesState (false);
  73. }
  74. ~JucerToolbarButton()
  75. {
  76. }
  77. //==============================================================================
  78. bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize, int& minSize, int& maxSize)
  79. {
  80. preferredSize = minSize = maxSize = 50;
  81. return true;
  82. }
  83. void paintButton (Graphics& g, bool over, bool down)
  84. {
  85. Path p;
  86. p.addRoundedRectangle (1.5f, 2.5f, getWidth() - 3.0f, getHeight() - 5.0f, 3.0f);
  87. if (getToggleState())
  88. {
  89. g.setColour (Colours::grey.withAlpha (0.5f));
  90. g.fillPath (p);
  91. }
  92. g.setColour (Colours::darkgrey.withAlpha (0.3f));
  93. g.strokePath (p, PathStrokeType (1.0f));
  94. g.setFont (11.0f);
  95. g.setColour (Colours::black.withAlpha ((over || down) ? 1.0f : 0.7f));
  96. g.drawFittedText (getButtonText(), 2, 2, getWidth() - 4, getHeight() - 4, Justification::centred, 2);
  97. }
  98. void paintButtonArea (Graphics& g, int width, int height, bool isMouseOver, bool isMouseDown)
  99. {
  100. }
  101. void contentAreaChanged (const Rectangle<int>& newBounds)
  102. {
  103. }
  104. juce_UseDebuggingNewOperator
  105. private:
  106. JucerToolbarButton (const JucerToolbarButton&);
  107. JucerToolbarButton& operator= (const JucerToolbarButton&);
  108. };
  109. //==============================================================================
  110. class DrawableComponent : public Component,
  111. public ValueTree::Listener
  112. {
  113. public:
  114. DrawableComponent (const ValueTree& drawable_)
  115. {
  116. setDrawable (drawable_);
  117. }
  118. ~DrawableComponent()
  119. {
  120. }
  121. void setDrawable (const ValueTree& newDrawable)
  122. {
  123. drawable.removeListener (this);
  124. drawable = newDrawable;
  125. drawable.addListener (this);
  126. drawableObject = Drawable::createFromValueTree (drawable, 0); // xxx image provider missing
  127. resized();
  128. repaint();
  129. }
  130. void paint (Graphics& g)
  131. {
  132. if (drawableObject != 0)
  133. drawableObject->drawAt (g, 0, 0, 1.0f);
  134. }
  135. void resized()
  136. {
  137. DrawableComposite* dc = dynamic_cast <DrawableComposite*> (static_cast <Drawable*> (drawableObject));
  138. if (dc != 0)
  139. {
  140. const RelativeCoordinate origin, right (getWidth()), bottom (getHeight());
  141. dc->setContentArea (RelativeRectangle (origin, right, origin, bottom));
  142. dc->resetBoundingBoxToContentArea();
  143. }
  144. }
  145. void valueTreePropertyChanged (ValueTree&, const Identifier&) { updateGraphics(); }
  146. void valueTreeChildrenChanged (ValueTree&) { updateGraphics(); }
  147. void valueTreeParentChanged (ValueTree&) { updateGraphics(); }
  148. private:
  149. ValueTree drawable;
  150. ScopedPointer<Drawable> drawableObject;
  151. void updateGraphics()
  152. {
  153. if (drawableObject != 0)
  154. {
  155. const Rectangle<float> dirtyArea (drawableObject->refreshFromValueTree (drawable, 0));
  156. repaint (dirtyArea.getSmallestIntegerContainer());
  157. }
  158. }
  159. };
  160. //==============================================================================
  161. /**
  162. */
  163. class RelativeRectangleLayoutManager : public ComponentListener,
  164. public Expression::EvaluationContext,
  165. public AsyncUpdater
  166. {
  167. public:
  168. //==============================================================================
  169. /**
  170. */
  171. RelativeRectangleLayoutManager (Component* parentComponent);
  172. /** Destructor. */
  173. ~RelativeRectangleLayoutManager();
  174. //==============================================================================
  175. /**
  176. */
  177. void setMarker (const String& name, const RelativeCoordinate& coord);
  178. /**
  179. */
  180. void setComponentBounds (Component* component, const String& componentName, const RelativeRectangle& bounds);
  181. /**
  182. */
  183. void applyLayout();
  184. //==============================================================================
  185. /** @internal */
  186. const Expression getSymbolValue (const String& symbol, const String& member) const;
  187. /** @internal */
  188. void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
  189. /** @internal */
  190. void componentBeingDeleted (Component& component);
  191. /** @internal */
  192. void handleAsyncUpdate();
  193. juce_UseDebuggingNewOperator
  194. private:
  195. //==============================================================================
  196. struct ComponentPosition
  197. {
  198. ComponentPosition (Component* component, const String& name, const RelativeRectangle& coords);
  199. Component* component;
  200. String name;
  201. RelativeRectangle coords;
  202. };
  203. struct MarkerPosition
  204. {
  205. MarkerPosition (const String& name, const RelativeCoordinate& coord);
  206. String markerName;
  207. RelativeCoordinate position;
  208. };
  209. Component* parent;
  210. OwnedArray <ComponentPosition> components;
  211. OwnedArray <MarkerPosition> markers;
  212. RelativeRectangleLayoutManager (const RelativeRectangleLayoutManager&);
  213. RelativeRectangleLayoutManager& operator= (const RelativeRectangleLayoutManager&);
  214. };