mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2025-04-21 12:27:27 +03:00
Have Font::write return the width of the drawn text
This avoids having to do separate getTextWidth calls in several places. More getTextWidth calls could be saved by splitting the rendering of the font to an off-screen buffer from the final composition onto the destination surface: the routines that draw text inside a box have to compute the width before they can draw the box and currently the box has to be drawn before the text.
This commit is contained in:
12
src/font.h
12
src/font.h
@@ -38,7 +38,11 @@ public:
|
||||
return lineSpacing;
|
||||
}
|
||||
|
||||
void write(Surface& surface,
|
||||
/**
|
||||
* Draws a text on a surface in this font.
|
||||
* @return The width of the text in pixels.
|
||||
*/
|
||||
int write(Surface& surface,
|
||||
const std::string &text, int x, int y,
|
||||
HAlign halign = HAlignLeft, VAlign valign = VAlignTop);
|
||||
|
||||
@@ -48,7 +52,11 @@ private:
|
||||
std::string wordWrapSingleLine(const std::string &text,
|
||||
size_t start, size_t end, int width);
|
||||
|
||||
void writeLine(Surface& surface, std::string const& text,
|
||||
/**
|
||||
* Draws a single line of text on a surface in this font.
|
||||
* @return The width of the text in pixels.
|
||||
*/
|
||||
int writeLine(Surface& surface, std::string const& text,
|
||||
int x, int y, HAlign halign, VAlign valign);
|
||||
|
||||
TTF_Font *font;
|
||||
|
||||
Reference in New Issue
Block a user