LMMS
Loading...
Searching...
No Matches
juce_DrawableText.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30 : colour (Colours::black),
31 justification (Justification::centredLeft)
32{
33 setBoundingBox (Parallelogram<float> ({ 0.0f, 0.0f, 50.0f, 20.0f }));
34 setFont (Font (15.0f), true);
35}
36
38 : Drawable (other),
39 bounds (other.bounds),
40 fontHeight (other.fontHeight),
41 fontHScale (other.fontHScale),
42 font (other.font),
43 text (other.text),
44 colour (other.colour),
46{
48}
49
53
54std::unique_ptr<Drawable> DrawableText::createCopy() const
55{
56 return std::make_unique<DrawableText> (*this);
57}
58
59//==============================================================================
60void DrawableText::setText (const String& newText)
61{
62 if (text != newText)
63 {
64 text = newText;
66 }
67}
68
70{
71 if (colour != newColour)
72 {
73 colour = newColour;
74 repaint();
75 }
76}
77
78void DrawableText::setFont (const Font& newFont, bool applySizeAndScale)
79{
80 if (font != newFont)
81 {
82 font = newFont;
83
84 if (applySizeAndScale)
85 {
86 fontHeight = font.getHeight();
87 fontHScale = font.getHorizontalScale();
88 }
89
91 }
92}
93
95{
96 justification = newJustification;
97 repaint();
98}
99
101{
102 if (bounds != newBounds)
103 {
104 bounds = newBounds;
106 }
107}
108
109void DrawableText::setFontHeight (float newHeight)
110{
111 if (fontHeight != newHeight)
112 {
113 fontHeight = newHeight;
115 }
116}
117
119{
120 if (fontHScale != newScale)
121 {
122 fontHScale = newScale;
124 }
125}
126
128{
129 auto w = bounds.getWidth();
130 auto h = bounds.getHeight();
131
132 auto height = jlimit (0.01f, jmax (0.01f, h), fontHeight);
133 auto hscale = jlimit (0.01f, jmax (0.01f, w), fontHScale);
134
136 scaledFont.setHeight (height);
137 scaledFont.setHorizontalScale (hscale);
138
140 repaint();
141}
142
143//==============================================================================
148
150{
152 Point<float> (w, 0), bounds.topRight,
153 Point<float> (0, h), bounds.bottomLeft);
154}
155
157{
159
160 auto w = bounds.getWidth();
161 auto h = bounds.getHeight();
162
163 g.addTransform (getTextTransform (w, h));
164 g.setFont (scaledFont);
165 g.setColour (colour);
166
167 g.drawFittedText (text, getTextArea (w, h), justification, 0x100000);
168}
169
171{
172 return bounds.getBoundingBox();
173}
174
176{
177 auto w = bounds.getWidth();
178 auto h = bounds.getHeight();
179 auto area = getTextArea (w, h).toFloat();
180
183 area.getX(), area.getY(),
184 area.getWidth(), area.getHeight(),
186 0x100000);
187
188 Path pathOfAllGlyphs;
189
190 for (auto& glyph : arr)
191 {
192 Path gylphPath;
193 glyph.createPath (gylphPath);
194 pathOfAllGlyphs.addPath (gylphPath);
195 }
196
197 pathOfAllGlyphs.applyTransform (getTextTransform (w, h).followedBy (getTransform()));
198
199 return pathOfAllGlyphs;
200}
201
202bool DrawableText::replaceColour (Colour originalColour, Colour replacementColour)
203{
204 if (colour != originalColour)
205 return false;
206
207 setColour (replacementColour);
208 return true;
209}
210
211//==============================================================================
212std::unique_ptr<AccessibilityHandler> DrawableText::createAccessibilityHandler()
213{
214 class DrawableTextAccessibilityHandler : public AccessibilityHandler
215 {
216 public:
217 DrawableTextAccessibilityHandler (DrawableText& drawableTextToWrap)
219 drawableText (drawableTextToWrap)
220 {
221 }
222
223 String getTitle() const override { return drawableText.getText(); }
224
225 private:
226 DrawableText& drawableText;
227 };
228
229 return std::make_unique<DrawableTextAccessibilityHandler> (*this);
230}
231
232} // namespace juce
Definition juce_AccessibilityHandler.h:41
Definition juce_AffineTransform.h:43
static AffineTransform fromTargetPoints(float x00, float y00, float x10, float y10, float x01, float y01) noexcept
Definition juce_AffineTransform.cpp:213
Definition juce_Colour.h:38
AffineTransform getTransform() const
Definition juce_Component.cpp:1378
String getTitle() const noexcept
Definition juce_Component.h:2418
void repaint()
Definition juce_Component.cpp:1917
void setBoundsToEnclose(Rectangle< float >)
Definition juce_Drawable.cpp:133
Drawable()
Definition juce_Drawable.cpp:29
void transformContextToCorrectOrigin(Graphics &)
Definition juce_Drawable.cpp:123
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_DrawableText.cpp:212
void setFontHorizontalScale(float newScale)
Definition juce_DrawableText.cpp:118
Justification justification
Definition juce_DrawableText.h:109
Font scaledFont
Definition juce_DrawableText.h:106
Rectangle< float > getDrawableBounds() const override
Definition juce_DrawableText.cpp:170
void setJustification(Justification newJustification)
Definition juce_DrawableText.cpp:94
std::unique_ptr< Drawable > createCopy() const override
Definition juce_DrawableText.cpp:54
float fontHScale
Definition juce_DrawableText.h:105
void setText(const String &newText)
Definition juce_DrawableText.cpp:60
String text
Definition juce_DrawableText.h:107
AffineTransform getTextTransform(float width, float height) const
Definition juce_DrawableText.cpp:149
Rectangle< int > getTextArea(float width, float height) const
Definition juce_DrawableText.cpp:144
bool replaceColour(Colour originalColour, Colour replacementColour) override
Definition juce_DrawableText.cpp:202
Path getOutlineAsPath() const override
Definition juce_DrawableText.cpp:175
void setColour(Colour newColour)
Definition juce_DrawableText.cpp:69
Parallelogram< float > bounds
Definition juce_DrawableText.h:104
void refreshBounds()
Definition juce_DrawableText.cpp:127
~DrawableText() override
Definition juce_DrawableText.cpp:50
float fontHeight
Definition juce_DrawableText.h:105
void setFont(const Font &newFont, bool applySizeAndScale)
Definition juce_DrawableText.cpp:78
void paint(Graphics &) override
Definition juce_DrawableText.cpp:156
DrawableText()
Definition juce_DrawableText.cpp:29
void setFontHeight(float newHeight)
Definition juce_DrawableText.cpp:109
Colour colour
Definition juce_DrawableText.h:108
Font font
Definition juce_DrawableText.h:106
void setBoundingBox(Parallelogram< float > newBounds)
Definition juce_DrawableText.cpp:100
Definition juce_Font.h:42
Definition juce_GlyphArrangement.h:117
void addFittedText(const Font &font, const String &text, float x, float y, float width, float height, Justification layout, int maximumLinesToUse, float minimumHorizontalScale=0.0f)
Definition juce_GlyphArrangement.cpp:310
Definition juce_GraphicsContext.h:45
Definition juce_Justification.h:41
Definition juce_Parallelogram.h:38
Definition juce_Path.h:65
void addPath(const Path &pathToAppend)
Definition juce_Path.cpp:726
void applyTransform(const AffineTransform &transform) noexcept
Definition juce_Path.cpp:821
Definition juce_Point.h:42
Definition juce_Rectangle.h:67
Rectangle< int > getSmallestIntegerContainer() const noexcept
Definition juce_Rectangle.h:840
Definition juce_String.h:53
UINT_D64 w
Definition inflate.c:942
int g
Definition inflate.c:1573
static int int height
Definition pugl.h:1594
Definition juce_Colours.h:38
Definition carla_juce.cpp:31
constexpr Type jmax(Type a, Type b)
Definition juce_MathsFunctions.h:94
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Definition juce_MathsFunctions.h:262
@ staticText
Definition juce_AccessibilityRole.h:45
uch h[RAND_HEAD_LEN]
Definition crypt.c:459