Codechange: Move GetCharPosInString/GetCharAtPosition to gfx_layout.
These functions are related more to layouting than graphics.
This commit is contained in:
committed by
Peter Nelson
parent
bbbf2b5282
commit
80ddcb9d7d
33
src/gfx.cpp
33
src/gfx.cpp
@@ -895,39 +895,6 @@ Dimension GetStringListBoundingBox(std::span<const StringID> list, FontSize font
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the leading corner of a character in a single-line string relative
|
||||
* to the start of the string.
|
||||
* @param str String containing the character.
|
||||
* @param ch Pointer to the character in the string.
|
||||
* @param start_fontsize Font size to start the text with.
|
||||
* @return Upper left corner of the glyph associated with the character.
|
||||
*/
|
||||
Point GetCharPosInString(std::string_view str, const char *ch, FontSize start_fontsize)
|
||||
{
|
||||
/* Ensure "ch" is inside "str" or at the exact end. */
|
||||
assert(ch >= str.data() && (ch - str.data()) <= static_cast<ptrdiff_t>(str.size()));
|
||||
auto it_ch = str.begin() + (ch - str.data());
|
||||
|
||||
Layouter layout(str, INT32_MAX, start_fontsize);
|
||||
return layout.GetCharPosition(it_ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character from a string that is drawn at a specific position.
|
||||
* @param str String to test.
|
||||
* @param x Position relative to the start of the string.
|
||||
* @param start_fontsize Font size to start the text with.
|
||||
* @return Index of the character position or -1 if there is no character at the position.
|
||||
*/
|
||||
ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize)
|
||||
{
|
||||
if (x < 0) return -1;
|
||||
|
||||
Layouter layout(str, INT32_MAX, start_fontsize);
|
||||
return layout.GetCharAtPosition(x, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw single character horizontally centered around (x,y)
|
||||
* @param c Character (glyph) to draw
|
||||
|
||||
Reference in New Issue
Block a user