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.

154 lines
6.2KB

  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. /** Sets the colour of the text. */
  40. void setColour (const Colour& newColour);
  41. /** Returns the current text colour. */
  42. const Colour& getColour() const noexcept { return colour; }
  43. /** Sets the font to use.
  44. Note that the font height and horizontal scale are actually based upon the position
  45. of the fontSizeAndScaleAnchor parameter to setBounds(). If applySizeAndScale is true, then
  46. the height and scale control point will be moved to match the dimensions of the font supplied;
  47. if it is false, then the new font's height and scale are ignored.
  48. */
  49. void setFont (const Font& newFont, bool applySizeAndScale);
  50. /** Changes the justification of the text within the bounding box. */
  51. void setJustification (const Justification& newJustification);
  52. /** Returns the parallelogram that defines the text bounding box. */
  53. const RelativeParallelogram& getBoundingBox() const noexcept { return bounds; }
  54. /** Sets the bounding box that contains the text. */
  55. void setBoundingBox (const RelativeParallelogram& newBounds);
  56. /** Returns the point within the bounds that defines the font's size and scale. */
  57. const RelativePoint& getFontSizeControlPoint() const noexcept { return fontSizeControlPoint; }
  58. /** Sets the control point that defines the font's height and horizontal scale.
  59. This position is a point within the bounding box parallelogram, whose Y position (relative
  60. to the parallelogram's origin and possibly distorted shape) specifies the font's height,
  61. and its X defines the font's horizontal scale.
  62. */
  63. void setFontSizeControlPoint (const RelativePoint& newPoint);
  64. //==============================================================================
  65. /** @internal */
  66. void paint (Graphics& g);
  67. /** @internal */
  68. Drawable* createCopy() const;
  69. /** @internal */
  70. void refreshFromValueTree (const ValueTree& tree, ComponentBuilder& builder);
  71. /** @internal */
  72. ValueTree createValueTree (ComponentBuilder::ImageProvider* imageProvider) const;
  73. /** @internal */
  74. static const Identifier valueTreeType;
  75. /** @internal */
  76. Rectangle<float> getDrawableBounds() const;
  77. //==============================================================================
  78. /** Internally-used class for wrapping a DrawableText's state into a ValueTree. */
  79. class ValueTreeWrapper : public Drawable::ValueTreeWrapperBase
  80. {
  81. public:
  82. ValueTreeWrapper (const ValueTree& state);
  83. String getText() const;
  84. void setText (const String& newText, UndoManager* undoManager);
  85. Value getTextValue (UndoManager* undoManager);
  86. Colour getColour() const;
  87. void setColour (const Colour& newColour, UndoManager* undoManager);
  88. Justification getJustification() const;
  89. void setJustification (const Justification& newJustification, UndoManager* undoManager);
  90. Font getFont() const;
  91. void setFont (const Font& newFont, UndoManager* undoManager);
  92. Value getFontValue (UndoManager* undoManager);
  93. RelativeParallelogram getBoundingBox() const;
  94. void setBoundingBox (const RelativeParallelogram& newBounds, UndoManager* undoManager);
  95. RelativePoint getFontSizeControlPoint() const;
  96. void setFontSizeControlPoint (const RelativePoint& p, UndoManager* undoManager);
  97. static const Identifier text, colour, font, justification, topLeft, topRight, bottomLeft, fontSizeAnchor;
  98. };
  99. private:
  100. //==============================================================================
  101. RelativeParallelogram bounds;
  102. RelativePoint fontSizeControlPoint;
  103. Point<float> resolvedPoints[3];
  104. Font font, scaledFont;
  105. String text;
  106. Colour colour;
  107. Justification justification;
  108. friend class Drawable::Positioner<DrawableText>;
  109. bool registerCoordinates (RelativeCoordinatePositionerBase&);
  110. void recalculateCoordinates (Expression::Scope*);
  111. void refreshBounds();
  112. const AffineTransform getArrangementAndTransform (GlyphArrangement& glyphs) const;
  113. DrawableText& operator= (const DrawableText&);
  114. JUCE_LEAK_DETECTOR (DrawableText);
  115. };
  116. #endif // __JUCE_DRAWABLETEXT_JUCEHEADER__