From 6b43ebfafce42706e3bdec16a2396b877ae8bae8 Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 7 Feb 2014 19:27:27 +0000 Subject: [PATCH] Added a version of Graphics::drawText that uses float coords. --- .../contexts/juce_GraphicsContext.cpp | 24 ++++++++++--------- .../contexts/juce_GraphicsContext.h | 14 +++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index e43cf79bbb..3442b1d40b 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -281,28 +281,30 @@ void Graphics::drawMultiLineText (const String& text, const int startX, } } -void Graphics::drawText (const String& text, const Rectangle& area, - Justification justificationType, - const bool useEllipsesIfTooBig) const +void Graphics::drawText (const String& text, const Rectangle& area, + Justification justificationType, bool useEllipsesIfTooBig) const { - if (text.isNotEmpty() && context.clipRegionIntersects (area)) + if (text.isNotEmpty() && context.clipRegionIntersects (area.getSmallestIntegerContainer())) { 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(), - (float) area.getX(), (float) area.getY(), - (float) area.getWidth(), (float) area.getHeight(), + area.getX(), area.getY(), area.getWidth(), area.getHeight(), justificationType); arr.draw (*this); } } +void Graphics::drawText (const String& text, const Rectangle& 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, - Justification justificationType, - const bool useEllipsesIfTooBig) const + Justification justificationType, const bool useEllipsesIfTooBig) const { drawText (text, Rectangle (x, y, width, height), justificationType, useEllipsesIfTooBig); } diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index 221cfcb5c6..d59bcd2ba8 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -174,6 +174,20 @@ public: Justification justificationType, 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& area, + Justification justificationType, + bool useEllipsesIfTooBig) const; + /** Tries to draw a text string inside a given space. This does its best to make the given text readable within the specified rectangle,