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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_DRAWABLETEXT_H_INCLUDED
  18. #define JUCE_DRAWABLETEXT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A drawable object which renders a line of text.
  22. @see Drawable
  23. */
  24. class JUCE_API DrawableText : public Drawable
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a DrawableText object. */
  29. DrawableText();
  30. DrawableText (const DrawableText&);
  31. /** Destructor. */
  32. ~DrawableText();
  33. //==============================================================================
  34. /** Sets the text to display.*/
  35. void setText (const String& newText);
  36. /** Returns the currently displayed text */
  37. const String& getText() const noexcept { return text;}
  38. /** Sets the colour of the text. */
  39. void setColour (Colour newColour);
  40. /** Returns the current text colour. */
  41. Colour getColour() const noexcept { return colour; }
  42. /** Sets the font to use.
  43. Note that the font height and horizontal scale are set as RelativeCoordinates using
  44. setFontHeight and setFontHorizontalScale. If applySizeAndScale is true, then these height
  45. and scale values will be changed to match the dimensions of the font supplied;
  46. if it is false, then the new font object's height and scale are ignored.
  47. */
  48. void setFont (const Font& newFont, bool applySizeAndScale);
  49. /** Returns the current font. */
  50. const Font& getFont() const noexcept { return font; }
  51. /** Changes the justification of the text within the bounding box. */
  52. void setJustification (Justification newJustification);
  53. /** Returns the current justification. */
  54. Justification getJustification() const noexcept { return justification; }
  55. /** Returns the parallelogram that defines the text bounding box. */
  56. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  57. /** Sets the bounding box that contains the text. */
  58. void setBoundingBox (const RelativeParallelogram& newBounds);
  59. const RelativeCoordinate& getFontHeight() const { return fontHeight; }
  60. void setFontHeight (const RelativeCoordinate& newHeight);
  61. const RelativeCoordinate& getFontHorizontalScale() const { return fontHScale; }
  62. void setFontHorizontalScale (const RelativeCoordinate& newScale);
  63. //==============================================================================
  64. /** @internal */
  65. void paint (Graphics&) override;
  66. /** @internal */
  67. Drawable* createCopy() const override;
  68. /** @internal */
  69. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  70. /** @internal */
  71. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const override;
  72. /** @internal */
  73. static const Identifier valueTreeType;
  74. /** @internal */
  75. Rectangle<float> getDrawableBounds() const override;
  76. //==============================================================================
  77. /** Internally-used class for wrapping a DrawableText's state into a ValueTree. */
  78. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  79. {
  80. public:
  81. ValueTreeWrapper (const ValueTree& state);
  82. String getText() const;
  83. void setText (const String& newText, UndoManager* undoManager);
  84. Value getTextValue (UndoManager* undoManager);
  85. Colour getColour() const;
  86. void setColour (Colour newColour, UndoManager* undoManager);
  87. Justification getJustification() const;
  88. void setJustification (Justification newJustification, UndoManager* undoManager);
  89. Font getFont() const;
  90. void setFont (const Font& newFont, UndoManager* undoManager);
  91. Value getFontValue (UndoManager* undoManager);
  92. RelativeParallelogram getBoundingBox() const;
  93. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* undoManager);
  94. RelativeCoordinate getFontHeight() const;
  95. void setFontHeight (const RelativeCoordinate& newHeight, UndoManager* undoManager);
  96. RelativeCoordinate getFontHorizontalScale() const;
  97. void setFontHorizontalScale (const RelativeCoordinate& newScale, UndoManager* undoManager);
  98. static const Identifier text, colour, font, justification, topLeft, topRight, bottomLeft, fontHeight, fontHScale;
  99. };
  100. private:
  101. //==============================================================================
  102. RelativeParallelogram bounds;
  103. RelativeCoordinate fontHeight, fontHScale;
  104. Point<float> resolvedPoints[3];
  105. Font font, scaledFont;
  106. String text;
  107. Colour colour;
  108. Justification justification;
  109. friend class Drawable::Positioner<DrawableText>;
  110. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  111. void recalculateCoordinates (Expression::Scope*);
  112. void refreshBounds();
  113. DrawableText& operator= (const DrawableText&);
  114. JUCE_LEAK_DETECTOR (DrawableText)
  115. };
  116. #endif // JUCE_DRAWABLETEXT_H_INCLUDED