Browse Source

Added a version of Graphics::drawText that uses float coords.

tags/2021-05-28
jules 11 years ago
parent
commit
6b43ebfafc
2 changed files with 27 additions and 11 deletions
  1. +13
    -11
      modules/juce_graphics/contexts/juce_GraphicsContext.cpp
  2. +14
    -0
      modules/juce_graphics/contexts/juce_GraphicsContext.h

+ 13
- 11
modules/juce_graphics/contexts/juce_GraphicsContext.cpp View File

@@ -281,28 +281,30 @@ void Graphics::drawMultiLineText (const String& text, const int startX,
} }
} }
void Graphics::drawText (const String& text, const Rectangle<int>& area,
Justification justificationType,
const bool useEllipsesIfTooBig) const
void Graphics::drawText (const String& text, const Rectangle<float>& area,
Justification justificationType, bool useEllipsesIfTooBig) const
{ {
if (text.isNotEmpty() && context.clipRegionIntersects (area))
if (text.isNotEmpty() && context.clipRegionIntersects (area.getSmallestIntegerContainer()))
{ {
GlyphArrangement arr; GlyphArrangement arr;
arr.addCurtailedLineOfText (context.getFont(), text,
0.0f, 0.0f, (float) area.getWidth(),
useEllipsesIfTooBig);
arr.addCurtailedLineOfText (context.getFont(), text, 0.0f, 0.0f,
area.getWidth(), useEllipsesIfTooBig);
arr.justifyGlyphs (0, arr.getNumGlyphs(), arr.justifyGlyphs (0, arr.getNumGlyphs(),
(float) area.getX(), (float) area.getY(),
(float) area.getWidth(), (float) area.getHeight(),
area.getX(), area.getY(), area.getWidth(), area.getHeight(),
justificationType); justificationType);
arr.draw (*this); arr.draw (*this);
} }
} }
void Graphics::drawText (const String& text, const Rectangle<int>& area,
Justification justificationType, bool useEllipsesIfTooBig) const
{
drawText (text, area.toFloat(), justificationType, useEllipsesIfTooBig);
}
void Graphics::drawText (const String& text, const int x, const int y, const int width, const int height, void Graphics::drawText (const String& text, const int x, const int y, const int width, const int height,
Justification justificationType,
const bool useEllipsesIfTooBig) const
Justification justificationType, const bool useEllipsesIfTooBig) const
{ {
drawText (text, Rectangle<int> (x, y, width, height), justificationType, useEllipsesIfTooBig); drawText (text, Rectangle<int> (x, y, width, height), justificationType, useEllipsesIfTooBig);
} }


+ 14
- 0
modules/juce_graphics/contexts/juce_GraphicsContext.h View File

@@ -174,6 +174,20 @@ public:
Justification justificationType, Justification justificationType,
bool useEllipsesIfTooBig) const; bool useEllipsesIfTooBig) const;
/** Draws a line of text within a specified rectangle.
The text will be positioned within the rectangle based on the justification
flags passed-in. If the string is too long to fit inside the rectangle, it will
either be truncated or will have ellipsis added to its end (if the useEllipsesIfTooBig
flag is true).
@see drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText
*/
void drawText (const String& text,
const Rectangle<float>& area,
Justification justificationType,
bool useEllipsesIfTooBig) const;
/** Tries to draw a text string inside a given space. /** Tries to draw a text string inside a given space.
This does its best to make the given text readable within the specified rectangle, This does its best to make the given text readable within the specified rectangle,


Loading…
Cancel
Save