Browse Source

Add missing GetLineWidth declaration to header

pull/3611/head
Gleb Mazovetskiy 4 years ago committed by Anders Jenbo
parent
commit
1425bec3e4
  1. 124
      Source/engine/render/text_render.hpp

124
Source/engine/render/text_render.hpp

@ -51,62 +51,6 @@ enum text_color : uint8_t {
ColorButtonpushed,
};
extern std::optional<CelSprite> pSPentSpn2Cels;
void UnloadFonts(GameFontTables size, text_color color);
/**
* @brief Calculate pixel width of first line of text, respecting kerning
* @param text Text to check, will read until first eol or terminator
* @param size Font size to use
* @param spacing Extra spacing to add per character
* @param charactersInLine Receives characters read until newline or terminator
* @return Line width in pixels
*/
int GetLineWidth(string_view text, GameFontTables size = GameFont12, int spacing = 1, int *charactersInLine = nullptr);
[[nodiscard]] std::string WordWrapString(string_view text, size_t width, GameFontTables size = GameFont12, int spacing = 1);
/**
* @brief Draws a line of text within a clipping rectangle (positioned relative to the origin of the output buffer).
*
* Specifying a small width (0 to less than two characters wide) should be avoided as this causes issues when laying
* out the text. To wrap based on available space use the overload taking a Point. If the rect passed through has 0
* height then the clipping area is extended to the bottom edge of the output buffer. If the clipping rectangle
* dimensions extend past the edge of the output buffer text wrapping will be calculated using those dimensions (as if
* the text was being rendered off screen). The text will not actually be drawn beyond the bounds of the output
* buffer, this is purely to allow for clipping without wrapping.
*
* @param out The screen buffer to draw on.
* @param text String to be drawn.
* @param rect Clipping region relative to the output buffer describing where to draw the text and when to wrap long lines.
* @param flags A combination of UiFlags to describe font size, color, alignment, etc. See ui_items.h for available options
* @param spacing Additional space to add between characters.
* This value may be adjusted if the flag UIS_FIT_SPACING is passed in the flags parameter.
* @param lineHeight Allows overriding the default line height, useful for multi-line strings.
* @return The number of bytes rendered, including characters "drawn" outside the buffer.
*/
uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect, UiFlags flags = UiFlags::None, int spacing = 1, int lineHeight = -1);
/**
* @brief Draws a line of text at the given position relative to the origin of the output buffer.
*
* This method is provided as a convenience to pass through to DrawString(..., Rectangle, ...) when no explicit
* clipping/wrapping is requested. Note that this will still wrap the rendered string if it would end up being drawn
* beyond the right edge of the output buffer and clip it if it would extend beyond the bottom edge of the buffer.
*
* @param out The screen buffer to draw on.
* @param text String to be drawn.
* @param position Location of the top left corner of the string relative to the top left corner of the output buffer.
* @param flags A combination of UiFlags to describe font size, color, alignment, etc. See ui_items.h for available options
* @param spacing Additional space to add between characters.
* This value may be adjusted if the flag UIS_FIT_SPACING is passed in the flags parameter.
* @param lineHeight Allows overriding the default line height, useful for multi-line strings.
*/
inline void DrawString(const Surface &out, string_view text, const Point &position, UiFlags flags = UiFlags::None, int spacing = 1, int lineHeight = -1)
{
DrawString(out, text, { position, { out.w() - position.x, 0 } }, flags, spacing, lineHeight);
}
/**
* @brief A format argument for `DrawStringWithColors`.
*/
@ -174,6 +118,74 @@ private:
std::string formatted_;
};
extern std::optional<CelSprite> pSPentSpn2Cels;
void UnloadFonts(GameFontTables size, text_color color);
/**
* @brief Calculate pixel width of first line of text, respecting kerning
* @param text Text to check, will read until first eol or terminator
* @param size Font size to use
* @param spacing Extra spacing to add per character
* @param charactersInLine Receives characters read until newline or terminator
* @return Line width in pixels
*/
int GetLineWidth(string_view text, GameFontTables size = GameFont12, int spacing = 1, int *charactersInLine = nullptr);
/**
* @brief Calculate pixel width of first line of text, respecting kerning
* @param fmt An fmt::format string.
* @param args Format arguments.
* @param size Font size to use
* @param spacing Extra spacing to add per character
* @param charactersInLine Receives characters read until newline or terminator
* @return Line width in pixels
*/
int GetLineWidth(string_view fmt, DrawStringFormatArg *args, std::size_t argsLen, GameFontTables size, int spacing, int *charactersInLine = nullptr);
[[nodiscard]] std::string WordWrapString(string_view text, size_t width, GameFontTables size = GameFont12, int spacing = 1);
/**
* @brief Draws a line of text within a clipping rectangle (positioned relative to the origin of the output buffer).
*
* Specifying a small width (0 to less than two characters wide) should be avoided as this causes issues when laying
* out the text. To wrap based on available space use the overload taking a Point. If the rect passed through has 0
* height then the clipping area is extended to the bottom edge of the output buffer. If the clipping rectangle
* dimensions extend past the edge of the output buffer text wrapping will be calculated using those dimensions (as if
* the text was being rendered off screen). The text will not actually be drawn beyond the bounds of the output
* buffer, this is purely to allow for clipping without wrapping.
*
* @param out The screen buffer to draw on.
* @param text String to be drawn.
* @param rect Clipping region relative to the output buffer describing where to draw the text and when to wrap long lines.
* @param flags A combination of UiFlags to describe font size, color, alignment, etc. See ui_items.h for available options
* @param spacing Additional space to add between characters.
* This value may be adjusted if the flag UIS_FIT_SPACING is passed in the flags parameter.
* @param lineHeight Allows overriding the default line height, useful for multi-line strings.
* @return The number of bytes rendered, including characters "drawn" outside the buffer.
*/
uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect, UiFlags flags = UiFlags::None, int spacing = 1, int lineHeight = -1);
/**
* @brief Draws a line of text at the given position relative to the origin of the output buffer.
*
* This method is provided as a convenience to pass through to DrawString(..., Rectangle, ...) when no explicit
* clipping/wrapping is requested. Note that this will still wrap the rendered string if it would end up being drawn
* beyond the right edge of the output buffer and clip it if it would extend beyond the bottom edge of the buffer.
*
* @param out The screen buffer to draw on.
* @param text String to be drawn.
* @param position Location of the top left corner of the string relative to the top left corner of the output buffer.
* @param flags A combination of UiFlags to describe font size, color, alignment, etc. See ui_items.h for available options
* @param spacing Additional space to add between characters.
* This value may be adjusted if the flag UIS_FIT_SPACING is passed in the flags parameter.
* @param lineHeight Allows overriding the default line height, useful for multi-line strings.
*/
inline void DrawString(const Surface &out, string_view text, const Point &position, UiFlags flags = UiFlags::None, int spacing = 1, int lineHeight = -1)
{
DrawString(out, text, { position, { out.w() - position.x, 0 } }, flags, spacing, lineHeight);
}
/**
* @brief Draws a line of text with different colors for certain parts of the text.
*

Loading…
Cancel
Save