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.

161 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 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 __JUCE_DRAWABLETEXT_JUCEHEADER__
  19. #define __JUCE_DRAWABLETEXT_JUCEHEADER__
  20. #include "juce_Drawable.h"
  21. #include "../positioning/juce_RelativeParallelogram.h"
  22. //==============================================================================
  23. /**
  24. A drawable object which renders a line of text.
  25. @see Drawable
  26. */
  27. class JUCE_API DrawableText : public Drawable
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a DrawableText object. */
  32. DrawableText();
  33. DrawableText (const DrawableText& other);
  34. /** Destructor. */
  35. ~DrawableText();
  36. //==============================================================================
  37. /** Sets the text to display.*/
  38. void setText (const String& newText);
  39. /** Returns the currently displayed text */
  40. const String& getText() const noexcept { return text;}
  41. /** Sets the colour of the text. */
  42. void setColour (const Colour& newColour);
  43. /** Returns the current text colour. */
  44. const Colour& getColour() const noexcept { return colour; }
  45. /** Sets the font to use.
  46. Note that the font height and horizontal scale are set as RelativeCoordinates using
  47. setFontHeight and setFontHorizontalScale. If applySizeAndScale is true, then these height
  48. and scale values will be changed to match the dimensions of the font supplied;
  49. if it is false, then the new font object's height and scale are ignored.
  50. */
  51. void setFont (const Font& newFont, bool applySizeAndScale);
  52. /** Returns the current font. */
  53. const Font& getFont() const noexcept { return font; }
  54. /** Changes the justification of the text within the bounding box. */
  55. void setJustification (const Justification& newJustification);
  56. /** Returns the current justification. */
  57. const Justification& getJustification() const noexcept { return justification; }
  58. /** Returns the parallelogram that defines the text bounding box. */
  59. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  60. /** Sets the bounding box that contains the text. */
  61. void setBoundingBox (const RelativeParallelogram& newBounds);
  62. const RelativeCoordinate& getFontHeight() const { return fontHeight; }
  63. void setFontHeight (const RelativeCoordinate& newHeight);
  64. const RelativeCoordinate& getFontHorizontalScale() const { return fontHScale; }
  65. void setFontHorizontalScale (const RelativeCoordinate& newScale);
  66. //==============================================================================
  67. /** @internal */
  68. void paint (Graphics& g);
  69. /** @internal */
  70. Drawable* createCopy() const;
  71. /** @internal */
  72. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  73. /** @internal */
  74. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
  75. /** @internal */
  76. static const Identifier valueTreeType;
  77. /** @internal */
  78. Rectangle<float> getDrawableBounds() const;
  79. //==============================================================================
  80. /** Internally-used class for wrapping a DrawableText's state into a ValueTree. */
  81. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  82. {
  83. public:
  84. ValueTreeWrapper (const ValueTree& state);
  85. String getText() const;
  86. void setText (const String& newText, UndoManager* undoManager);
  87. Value getTextValue (UndoManager* undoManager);
  88. Colour getColour() const;
  89. void setColour (const Colour& newColour, UndoManager* undoManager);
  90. Justification getJustification() const;
  91. void setJustification (const Justification& newJustification, UndoManager* undoManager);
  92. Font getFont() const;
  93. void setFont (const Font& newFont, UndoManager* undoManager);
  94. Value getFontValue (UndoManager* undoManager);
  95. RelativeParallelogram getBoundingBox() const;
  96. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* undoManager);
  97. RelativeCoordinate getFontHeight() const;
  98. void setFontHeight (const RelativeCoordinate& newHeight, UndoManager* undoManager);
  99. RelativeCoordinate getFontHorizontalScale() const;
  100. void setFontHorizontalScale (const RelativeCoordinate& newScale, UndoManager* undoManager);
  101. static const Identifier text, colour, font, justification, topLeft, topRight, bottomLeft, fontHeight, fontHScale;
  102. };
  103. private:
  104. //==============================================================================
  105. RelativeParallelogram bounds;
  106. RelativeCoordinate fontHeight, fontHScale;
  107. Point<float> resolvedPoints[3];
  108. Font font, scaledFont;
  109. String text;
  110. Colour colour;
  111. Justification justification;
  112. friend class Drawable::Positioner<DrawableText>;
  113. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  114. void recalculateCoordinates (Expression::Scope*);
  115. void refreshBounds();
  116. const AffineTransform getArrangementAndTransform (GlyphArrangement& glyphs) const;
  117. DrawableText& operator= (const DrawableText&);
  118. JUCE_LEAK_DETECTOR (DrawableText);
  119. };
  120. #endif // __JUCE_DRAWABLETEXT_JUCEHEADER__