10 #ifndef BPPSTRINGCACHE_HPP 11 #define BPPSTRINGCACHE_HPP 13 #include <boost/multi_index_container.hpp> 14 #include <boost/multi_index/hashed_index.hpp> 15 #include <boost/multi_index/sequenced_index.hpp> 16 #include <boost/multi_index/member.hpp> 17 #include <boost/multi_index/composite_key.hpp> 58 typedef boost::multi_index::multi_index_container<
60 boost::multi_index::indexed_by<
61 boost::multi_index::hashed_non_unique<
62 boost::multi_index::tag<struct index_text>,
63 boost::multi_index::composite_key<
65 boost::multi_index::member<
70 boost::multi_index::member<
77 boost::multi_index::sequenced<
78 boost::multi_index::tag<struct index_seq>
164 const std::string &path,
180 static std::shared_ptr<BppStringCache>
make(
200 static std::shared_ptr<BppStringCache>
make(
205 return std::make_shared<BppStringCache>(
236 static std::shared_ptr<BppStringCache>
make(
237 const std::string &path,
241 return std::make_shared<BppStringCache>(
298 const std::string &str,
320 const std::u32string &str,
332 #endif // #ifndef BPPSTRINGCACHE_HPP std::shared_ptr< BppStringCache > BppStringCacheSptr
A std::shared_ptr to a BppStringCache object.
const BppFontSptr & font() const
Returns the font object used by this cache to render text.
ConstBppImageSptr img
The rendered image of the text.
std::shared_ptr< BppFont > BppFontSptr
unsigned int maxStrings() const
Returns the maximum number of cached images.
Stores an image and the data used to create it using the font.
boost::multi_index::multi_index_container< BppString, boost::multi_index::indexed_by< boost::multi_index::hashed_non_unique< boost::multi_index::tag< struct index_text >, boost::multi_index::composite_key< BppString, boost::multi_index::member< BppString, std::u32string, &BppString::text >, boost::multi_index::member< BppString, BppFont::Flags, &BppString::flags > > >, boost::multi_index::sequenced< boost::multi_index::tag< struct index_seq > > > > Cache
The container type for the rendered strings.
std::shared_ptr< const BppImage > ConstBppImageSptr
unsigned int maxBytes() const
Returns the maximum size of the cached images in bytes.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
BppStringCache(const BppFontSptr &font, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1)
Creates a cache of rendered strings made using the given font.
unsigned int curB
The current size of all rendered text images in the cache.
void clear()
Clears all text images from the cache.
duds::general::Spinlock block
Used for thread safety.
static std::shared_ptr< BppFont > make()
Returns a shared pointer to a new BppFont object.
unsigned int strings() const
Returns the number of currently stored cached strings.
BppStringCache(const std::string &path, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1)
Creates a cache of rendered strings made using a font created from the given image archive path...
static std::shared_ptr< BppStringCache > make(BppFontSptr &&font, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1)
Creates a cache of rendered strings made using the given font.
static std::shared_ptr< BppStringCache > make(const std::string &path, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1)
Creates a cache of rendered strings made using a font created from the given image archive path...
unsigned int bytes() const
Returns the total size in bytes of all the cached images.
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
duds::general::BitFlags< struct BppFontRenderingFlags > Flags
Option flags that affect how text is rendered.
BppFont::Flags flags
The font rendering flags.
unsigned int maxB
The maximum size of rendered text images, in bytes, the cache may hold.
BppFontSptr fnt
The font to use for rendering.
General graphics related code.
std::u32string text
The text rendered into img.
static constexpr Flags AlignLeft
Align each line to the left.
Cache cache
The cache of rendered strings.
unsigned int maxS
The maximum number of strings the cache may hold.
static std::shared_ptr< BppStringCache > make(const BppFontSptr &font, unsigned int maxBytes=256 *1024, unsigned int maxStrings=-1)
Creates a cache of rendered strings made using the given font.
Maintains a cache for rendered strings that helps avoid re-rendering strings that may need to be show...
Renders strings using a font made of BppImage objects for glyphs.