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.

162 lines
6.8KB

  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. #ifndef __JUCE_DRAWABLETEXT_JUCEHEADER__
  19. #define __JUCE_DRAWABLETEXT_JUCEHEADER__
  20. #include "juce_Drawable.h"
  21. #include "../fonts/juce_GlyphArrangement.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 throw() { 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. /** Sets the bounding box and the control point that controls the font size.
  53. The three bounding box points define the parallelogram within which the text will be
  54. placed. The fontSizeAndScaleAnchor specifies a position within that parallelogram, whose
  55. Y position (relative to the parallelogram's origin and possibly distorted shape) specifies
  56. the font's height, and its X defines the font's horizontal scale.
  57. */
  58. void setBounds (const RelativePoint& boundingBoxTopLeft,
  59. const RelativePoint& boundingBoxTopRight,
  60. const RelativePoint& boundingBoxBottomLeft,
  61. const RelativePoint& fontSizeAndScaleAnchor);
  62. /** Returns the origin of the text bounding box. */
  63. const RelativePoint& getBoundingBoxTopLeft() const throw() { return controlPoints[0]; }
  64. /** Returns the top-right of the text bounding box. */
  65. const RelativePoint& getBoundingBoxTopRight() const throw() { return controlPoints[1]; }
  66. /** Returns the bottom-left of the text bounding box. */
  67. const RelativePoint& getBoundingBoxBottomLeft() const throw() { return controlPoints[2]; }
  68. /** Returns the point within the text bounding box which defines the size and scale of the font. */
  69. const RelativePoint& getFontSizeAndScaleAnchor() const throw() { return controlPoints[3]; }
  70. //==============================================================================
  71. /** @internal */
  72. void render (const Drawable::RenderingContext& context) const;
  73. /** @internal */
  74. const Rectangle<float> getBounds() const;
  75. /** @internal */
  76. bool hitTest (float x, float y) const;
  77. /** @internal */
  78. Drawable* createCopy() const;
  79. /** @internal */
  80. void invalidatePoints();
  81. /** @internal */
  82. const Rectangle<float> refreshFromValueTree (const ValueTree& tree, ImageProvider* imageProvider);
  83. /** @internal */
  84. const ValueTree createValueTree (ImageProvider* imageProvider) const;
  85. /** @internal */
  86. static const Identifier valueTreeType;
  87. /** @internal */
  88. const Identifier getValueTreeType() const { return valueTreeType; }
  89. //==============================================================================
  90. /** Internally-used class for wrapping a DrawableText's state into a ValueTree. */
  91. class ValueTreeWrapper : public ValueTreeWrapperBase
  92. {
  93. public:
  94. ValueTreeWrapper (const ValueTree& state);
  95. const String getText() const;
  96. void setText (const String& newText, UndoManager* undoManager);
  97. const Colour getColour() const;
  98. void setColour (const Colour& newColour, UndoManager* undoManager);
  99. const Justification getJustification() const;
  100. void setJustification (const Justification& newJustification, UndoManager* undoManager);
  101. const Font getFont() const;
  102. void setFont (const Font& newFont, UndoManager* undoManager);
  103. const RelativePoint getBoundingBoxTopLeft() const;
  104. void setBoundingBoxTopLeft (const RelativePoint& p, UndoManager* undoManager);
  105. const RelativePoint getBoundingBoxTopRight() const;
  106. void setBoundingBoxTopRight (const RelativePoint& p, UndoManager* undoManager);
  107. const RelativePoint getBoundingBoxBottomLeft() const;
  108. void setBoundingBoxBottomLeft (const RelativePoint& p, UndoManager* undoManager);
  109. const RelativePoint getFontSizeAndScaleAnchor() const;
  110. void setFontSizeAndScaleAnchor (const RelativePoint& p, UndoManager* undoManager);
  111. static const Identifier text, colour, font, justification, topLeft, topRight, bottomLeft, fontSizeAnchor;
  112. };
  113. //==============================================================================
  114. juce_UseDebuggingNewOperator
  115. private:
  116. RelativePoint controlPoints[4];
  117. Font font;
  118. String text;
  119. Colour colour;
  120. Justification justification;
  121. void resolveCorners (Point<float>* corners) const;
  122. DrawableText& operator= (const DrawableText&);
  123. };
  124. #endif // __JUCE_DRAWABLETEXT_JUCEHEADER__