juce_DrawableText.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. @tags{GUI}
  26. */
  27. class JUCE_API DrawableText : public Drawable
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a DrawableText object. */
  32. DrawableText();
  33. DrawableText (const DrawableText&);
  34. /** Destructor. */
  35. ~DrawableText() override;
  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 (Colour newColour);
  43. /** Returns the current text colour. */
  44. Colour getColour() const noexcept { return colour; }
  45. /** Sets the font to use.
  46. Note that the font height and horizontal scale are set using setFontHeight() and
  47. 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 (Justification newJustification);
  56. /** Returns the current justification. */
  57. Justification getJustification() const noexcept { return justification; }
  58. /** Returns the parallelogram that defines the text bounding box. */
  59. Parallelogram<float> getBoundingBox() const noexcept { return bounds; }
  60. /** Sets the bounding box that contains the text. */
  61. void setBoundingBox (Parallelogram<float> newBounds);
  62. float getFontHeight() const noexcept { return fontHeight; }
  63. void setFontHeight (float newHeight);
  64. float getFontHorizontalScale() const noexcept { return fontHScale; }
  65. void setFontHorizontalScale (float newScale);
  66. //==============================================================================
  67. /** @internal */
  68. void paint (Graphics&) override;
  69. /** @internal */
  70. std::unique_ptr<Drawable> createCopy() const override;
  71. /** @internal */
  72. Rectangle<float> getDrawableBounds() const override;
  73. /** @internal */
  74. Path getOutlineAsPath() const override;
  75. /** @internal */
  76. bool replaceColour (Colour originalColour, Colour replacementColour) override;
  77. private:
  78. //==============================================================================
  79. Parallelogram<float> bounds;
  80. float fontHeight, fontHScale;
  81. Font font, scaledFont;
  82. String text;
  83. Colour colour;
  84. Justification justification;
  85. void refreshBounds();
  86. Rectangle<int> getTextArea (float width, float height) const;
  87. AffineTransform getTextTransform (float width, float height) const;
  88. DrawableText& operator= (const DrawableText&);
  89. JUCE_LEAK_DETECTOR (DrawableText)
  90. };
  91. } // namespace juce