Audio plugin host https://kx.studio/carla
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.

juce_DrawableText.h 6.2KB

7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A drawable object which renders a line of text.
  24. @see Drawable
  25. */
  26. class JUCE_API DrawableText : public Drawable
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates a DrawableText object. */
  31. DrawableText();
  32. DrawableText (const DrawableText&);
  33. /** Destructor. */
  34. ~DrawableText();
  35. //==============================================================================
  36. /** Sets the text to display.*/
  37. void setText (const String& newText);
  38. /** Returns the currently displayed text */
  39. const String& getText() const noexcept { return text;}
  40. /** Sets the colour of the text. */
  41. void setColour (Colour newColour);
  42. /** Returns the current text colour. */
  43. Colour getColour() const noexcept { return colour; }
  44. /** Sets the font to use.
  45. Note that the font height and horizontal scale are set as RelativeCoordinates using
  46. setFontHeight and setFontHorizontalScale. If applySizeAndScale is true, then these height
  47. and scale values will be changed to match the dimensions of the font supplied;
  48. if it is false, then the new font object's height and scale are ignored.
  49. */
  50. void setFont (const Font& newFont, bool applySizeAndScale);
  51. /** Returns the current font. */
  52. const Font& getFont() const noexcept { return font; }
  53. /** Changes the justification of the text within the bounding box. */
  54. void setJustification (Justification newJustification);
  55. /** Returns the current justification. */
  56. Justification getJustification() const noexcept { return justification; }
  57. /** Returns the parallelogram that defines the text bounding box. */
  58. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  59. /** Sets the bounding box that contains the text. */
  60. void setBoundingBox (const RelativeParallelogram& newBounds);
  61. const RelativeCoordinate& getFontHeight() const { return fontHeight; }
  62. void setFontHeight (const RelativeCoordinate& newHeight);
  63. const RelativeCoordinate& getFontHorizontalScale() const { return fontHScale; }
  64. void setFontHorizontalScale (const RelativeCoordinate& newScale);
  65. //==============================================================================
  66. /** @internal */
  67. void paint (Graphics&) override;
  68. /** @internal */
  69. Drawable* createCopy() const override;
  70. /** @internal */
  71. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  72. /** @internal */
  73. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const override;
  74. /** @internal */
  75. static const Identifier valueTreeType;
  76. /** @internal */
  77. Rectangle<float> getDrawableBounds() const override;
  78. /** @internal */
  79. Path getOutlineAsPath() const override;
  80. //==============================================================================
  81. /** Internally-used class for wrapping a DrawableText's state into a ValueTree. */
  82. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  83. {
  84. public:
  85. ValueTreeWrapper (const ValueTree& state);
  86. String getText() const;
  87. void setText (const String& newText, UndoManager* undoManager);
  88. Value getTextValue (UndoManager* undoManager);
  89. Colour getColour() const;
  90. void setColour (Colour newColour, UndoManager* undoManager);
  91. Justification getJustification() const;
  92. void setJustification (Justification newJustification, UndoManager* undoManager);
  93. Font getFont() const;
  94. void setFont (const Font& newFont, UndoManager* undoManager);
  95. Value getFontValue (UndoManager* undoManager);
  96. RelativeParallelogram getBoundingBox() const;
  97. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* undoManager);
  98. RelativeCoordinate getFontHeight() const;
  99. void setFontHeight (const RelativeCoordinate& newHeight, UndoManager* undoManager);
  100. RelativeCoordinate getFontHorizontalScale() const;
  101. void setFontHorizontalScale (const RelativeCoordinate& newScale, UndoManager* undoManager);
  102. static const Identifier text, colour, font, justification, topLeft, topRight, bottomLeft, fontHeight, fontHScale;
  103. };
  104. private:
  105. //==============================================================================
  106. RelativeParallelogram bounds;
  107. RelativeCoordinate fontHeight, fontHScale;
  108. Point<float> resolvedPoints[3];
  109. Font font, scaledFont;
  110. String text;
  111. Colour colour;
  112. Justification justification;
  113. friend class Drawable::Positioner<DrawableText>;
  114. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  115. void recalculateCoordinates (Expression::Scope*);
  116. void refreshBounds();
  117. Rectangle<int> getTextArea (float width, float height) const;
  118. AffineTransform getTextTransform (float width, float height) const;
  119. DrawableText& operator= (const DrawableText&);
  120. JUCE_LEAK_DETECTOR (DrawableText)
  121. };
  122. } // namespace juce