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.

113 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. A drawable object which renders a line of text.
  18. @see Drawable
  19. @tags{GUI}
  20. */
  21. class JUCE_API DrawableText : public Drawable
  22. {
  23. public:
  24. //==============================================================================
  25. /** Creates a DrawableText object. */
  26. DrawableText();
  27. DrawableText (const DrawableText&);
  28. /** Destructor. */
  29. ~DrawableText() override;
  30. //==============================================================================
  31. /** Sets the text to display.*/
  32. void setText (const String& newText);
  33. /** Returns the currently displayed text */
  34. const String& getText() const noexcept { return text;}
  35. /** Sets the colour of the text. */
  36. void setColour (Colour newColour);
  37. /** Returns the current text colour. */
  38. Colour getColour() const noexcept { return colour; }
  39. /** Sets the font to use.
  40. Note that the font height and horizontal scale are set using setFontHeight() and
  41. setFontHorizontalScale(). If applySizeAndScale is true, then these height
  42. and scale values will be changed to match the dimensions of the font supplied;
  43. if it is false, then the new font object's height and scale are ignored.
  44. */
  45. void setFont (const Font& newFont, bool applySizeAndScale);
  46. /** Returns the current font. */
  47. const Font& getFont() const noexcept { return font; }
  48. /** Changes the justification of the text within the bounding box. */
  49. void setJustification (Justification newJustification);
  50. /** Returns the current justification. */
  51. Justification getJustification() const noexcept { return justification; }
  52. /** Returns the parallelogram that defines the text bounding box. */
  53. Parallelogram<float> getBoundingBox() const noexcept { return bounds; }
  54. /** Sets the bounding box that contains the text. */
  55. void setBoundingBox (Parallelogram<float> newBounds);
  56. float getFontHeight() const noexcept { return fontHeight; }
  57. void setFontHeight (float newHeight);
  58. float getFontHorizontalScale() const noexcept { return fontHScale; }
  59. void setFontHorizontalScale (float newScale);
  60. //==============================================================================
  61. /** @internal */
  62. void paint (Graphics&) override;
  63. /** @internal */
  64. std::unique_ptr<Drawable> createCopy() const override;
  65. /** @internal */
  66. Rectangle<float> getDrawableBounds() const override;
  67. /** @internal */
  68. Path getOutlineAsPath() const override;
  69. /** @internal */
  70. bool replaceColour (Colour originalColour, Colour replacementColour) override;
  71. private:
  72. //==============================================================================
  73. Parallelogram<float> bounds;
  74. float fontHeight, fontHScale;
  75. Font font, scaledFont;
  76. String text;
  77. Colour colour;
  78. Justification justification;
  79. void refreshBounds();
  80. Rectangle<int> getTextArea (float width, float height) const;
  81. AffineTransform getTextTransform (float width, float height) const;
  82. DrawableText& operator= (const DrawableText&);
  83. JUCE_LEAK_DETECTOR (DrawableText)
  84. };
  85. } // namespace juce