|
OpenTTD Source
14.0-beta3
|
The layouter performs all the layout work. More...
#include <gfx_layout.h>
Data Structures | |
| struct | LineCacheCompare |
| Comparator for std::map. More... | |
| struct | LineCacheItem |
| Item in the linecache. More... | |
| struct | LineCacheKey |
| Key into the linecache. More... | |
| struct | LineCacheQuery |
Public Member Functions | |
| Layouter (std::string_view str, int maxw=INT32_MAX, TextColour colour=TC_FROMSTRING, FontSize fontsize=FS_NORMAL) | |
| Create a new layouter. More... | |
| Dimension | GetBounds () |
| Get the boundaries of this paragraph. More... | |
| Point | GetCharPosition (std::string_view::const_iterator ch) const |
| Get the position of a character in the layout. More... | |
| ptrdiff_t | GetCharAtPosition (int x, size_t line_index) const |
| Get the character that is at a pixel position in the first line of the layouted text. More... | |
Static Public Member Functions | |
| static Font * | GetFont (FontSize size, TextColour colour) |
| Get a static font instance. | |
| static void | Initialize () |
| Perform initialization of layout engine. | |
| static void | ResetFontCache (FontSize size) |
| Reset cached font information. More... | |
| static void | ResetLineCache () |
| Clear line cache. | |
| static void | ReduceLineCache () |
| Reduce the size of linecache if necessary to prevent infinite growth. | |
Private Types | |
| typedef std::map< LineCacheKey, LineCacheItem, LineCacheCompare > | LineCache |
| using | FontColourMap = std::map< TextColour, std::unique_ptr< Font > > |
Static Private Member Functions | |
| static LineCacheItem & | GetCachedParagraphLayout (std::string_view str, const FontState &state) |
| Get reference to cache item. More... | |
Private Attributes | |
| std::string_view | string |
| Pointer to the original string. | |
Static Private Attributes | |
| static LineCache * | linecache |
| Cache of ParagraphLayout lines. | |
| static FontColourMap | fonts [FS_END] |
| Cache of Font instances. | |
The layouter performs all the layout work.
It also accounts for the memory allocations and frees.
Definition at line 125 of file gfx_layout.h.
| Layouter::Layouter | ( | std::string_view | str, |
| int | maxw = INT32_MAX, |
||
| TextColour | colour = TC_FROMSTRING, |
||
| FontSize | fontsize = FS_NORMAL |
||
| ) |
Create a new layouter.
| str | The string to create the layout for. |
| maxw | The maximum width. |
| colour | The colour of the font. |
| fontsize | The size of font to use. |
Definition at line 130 of file gfx_layout.cpp.
References GetCachedParagraphLayout(), Layouter::LineCacheItem::layout, and Layouter::LineCacheItem::state_after.
| Dimension Layouter::GetBounds | ( | ) |
Get the boundaries of this paragraph.
Definition at line 199 of file gfx_layout.cpp.
Referenced by DrawStringMultiLine().
|
staticprivate |
Get reference to cache item.
If the item does not exist yet, it is default constructed.
| str | Source string of the line (including colour and font size codes). |
| state | State of the font at the beginning of the line. |
Definition at line 373 of file gfx_layout.cpp.
References linecache, Layouter::LineCacheKey::state_before, and Layouter::LineCacheKey::str.
Referenced by Layouter().
| ptrdiff_t Layouter::GetCharAtPosition | ( | int | x, |
| size_t | line_index | ||
| ) | const |
Get the character that is at a pixel position in the first line of the layouted text.
| x | Position in the string. |
| line_index | Which line of the layout to search |
Definition at line 288 of file gfx_layout.cpp.
Referenced by TextfileWindow::CheckHyperlinkClick().
| Point Layouter::GetCharPosition | ( | std::string_view::const_iterator | ch | ) | const |
Get the position of a character in the layout.
| ch | Character to get the position of. Must be an iterator of the string passed to the constructor. |
Definition at line 228 of file gfx_layout.cpp.
|
static |
Reset cached font information.
| size | Font size to reset. |
Definition at line 351 of file gfx_layout.cpp.
References fonts, and ResetLineCache().
Referenced by SpriteFontCache::ClearFontCache(), TrueTypeFontCache::ClearFontCache(), and FontCache::~FontCache().