OpenTTD
|
The layouter performs all the layout work. More...
#include <gfx_layout.h>
Data Structures | |
struct | LineCacheItem |
Item in the linecache. More... | |
struct | LineCacheKey |
Key into the linecache. More... |
Public Member Functions | |
Layouter (const char *str, int maxw=INT32_MAX, TextColour colour=TC_FROMSTRING, FontSize fontsize=FS_NORMAL) | |
Create a new layouter. | |
Dimension | GetBounds () |
Get the boundaries of this paragraph. | |
Point | GetCharPosition (const char *ch) const |
Get the position of a character in the layout. | |
const char * | GetCharAtPosition (int x) const |
Get the character that is at a position. | |
![]() | |
void | Clear () |
Remove all items from the list. | |
![]() | |
SmallVector (const SmallVector &other) | |
Copy constructor. | |
SmallVector (const SmallVector< const ParagraphLayouter::Line *, X > &other) | |
Generic copy constructor. | |
SmallVector & | operator= (const SmallVector &other) |
Assignment. | |
SmallVector & | operator= (const SmallVector< const ParagraphLayouter::Line *, X > &other) |
Generic assignment. | |
void | Assign (const SmallVector< const ParagraphLayouter::Line *, X > &other) |
Assign items from other vector. | |
void | Reset () |
Remove all items from the list and free allocated memory. | |
void | Compact () |
Compact the list down to the smallest block size boundary. | |
const ParagraphLayouter::Line ** | Append (uint to_add=1) |
Append an item and return it. | |
void | Resize (uint num_items) |
Set the size of the vector, effectively truncating items from the end or appending uninitialised ones. | |
const const ParagraphLayouter::Line ** | Find (const const ParagraphLayouter::Line *&item) const |
Search for the first occurrence of an item. | |
const ParagraphLayouter::Line ** | Find (const const ParagraphLayouter::Line *&item) |
Search for the first occurrence of an item. | |
int | FindIndex (const const ParagraphLayouter::Line *&item) const |
Search for the first occurrence of an item. | |
bool | Contains (const const ParagraphLayouter::Line *&item) const |
Tests whether a item is present in the vector. | |
void | Erase (const ParagraphLayouter::Line **item) |
Removes given item from this vector. | |
void | ErasePreservingOrder (uint pos, uint count=1) |
Remove items from the vector while preserving the order of other items. | |
bool | Include (const const ParagraphLayouter::Line *&item) |
Tests whether a item is present in the vector, and appends it to the end if not. | |
uint | Length () const |
Get the number of items in the list. | |
const const ParagraphLayouter::Line ** | Begin () const |
Get the pointer to the first item (const) | |
const ParagraphLayouter::Line ** | Begin () |
Get the pointer to the first item. | |
const const ParagraphLayouter::Line ** | End () const |
Get the pointer behind the last valid item (const) | |
const ParagraphLayouter::Line ** | End () |
Get the pointer behind the last valid item. | |
const const ParagraphLayouter::Line ** | Get (uint index) const |
Get the pointer to item "number" (const) | |
const ParagraphLayouter::Line ** | Get (uint index) |
Get the pointer to item "number". | |
const const ParagraphLayouter::Line *& | operator[] (uint index) const |
Get item "number" (const) | |
const ParagraphLayouter::Line *& | operator[] (uint index) |
Get item "number". |
Static Public Member Functions | |
static Font * | GetFont (FontSize size, TextColour colour) |
Get a static font instance. | |
static void | ResetFontCache (FontSize size) |
Reset cached font information. | |
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 > | LineCache |
typedef SmallMap< TextColour, Font * > | FontColourMap |
Static Private Member Functions | |
static LineCacheItem & | GetCachedParagraphLayout (const char *str, size_t len, const FontState &state) |
Get reference to cache item. |
Private Attributes | |
const char * | 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. |
Additional Inherited Members | |
![]() | |
const ParagraphLayouter::Line ** | data |
The pointer to the first item. | |
uint | items |
The number of items stored. | |
uint | capacity |
The available space for storing items. |
The layouter performs all the layout work.
It also accounts for the memory allocations and frees.
Definition at line 139 of file gfx_layout.h.
Layouter::Layouter | ( | const char * | 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 635 of file gfx_layout.cpp.
References SmallVector< const ParagraphLayouter::Line *, S >::Append(), DEBUG, GetCachedParagraphLayout(), Layouter::LineCacheItem::layout, Layouter::LineCacheItem::state_after, and Utf8Decode().
Dimension Layouter::GetBounds | ( | ) |
Get the boundaries of this paragraph.
Definition at line 691 of file gfx_layout.cpp.
References SmallVector< const ParagraphLayouter::Line *, S >::Begin(), and SmallVector< const ParagraphLayouter::Line *, S >::End().
Referenced by DrawStringMultiLine(), GetStringBoundingBox(), and GetStringHeight().
|
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). |
len | Length of str in bytes (no termination). |
state | State of the font at the beginning of the line. |
Definition at line 822 of file gfx_layout.cpp.
References linecache, Layouter::LineCacheKey::state_before, and Layouter::LineCacheKey::str.
Referenced by Layouter().
const char * Layouter::GetCharAtPosition | ( | int | x | ) | const |
Get the character that is at a position.
x | Position in the string. |
Definition at line 754 of file gfx_layout.cpp.
References SmallVector< const ParagraphLayouter::Line *, S >::Begin(), and IsInsideMM().
Referenced by GetCharAtPosition().
Point Layouter::GetCharPosition | ( | const char * | ch | ) | const |
Get the position of a character in the layout.
ch | Character to get the position of. |
Definition at line 707 of file gfx_layout.cpp.
References SmallVector< const ParagraphLayouter::Line *, S >::Begin(), string, and Utf8Decode().
Referenced by GetCharPosInString().
|
static |
Reset cached font information.
size | Font size to reset. |
Definition at line 803 of file gfx_layout.cpp.
References SmallVector< const ParagraphLayouter::Line *, S >::Begin(), SmallVector< T, S >::Clear(), SmallVector< T, S >::End(), fonts, and ResetLineCache().
Referenced by SpriteFontCache::ClearFontCache(), FreeTypeFontCache::ClearFontCache(), FontCache::FontCache(), and FontCache::~FontCache().
|
staticprivate |
Cache of Font instances.
Definition at line 176 of file gfx_layout.h.
Referenced by GetFont(), and ResetFontCache().
|
staticprivate |
Cache of ParagraphLayout lines.
Definition at line 171 of file gfx_layout.h.
Referenced by GetCachedParagraphLayout(), ReduceLineCache(), and ResetLineCache().