19 unsigned int maxBytes,
20 unsigned int maxStrings
21 ) : fnt(font), maxB(maxBytes), maxS(maxStrings) {
38 std::lock_guard<duds::general::Spinlock> lock(
block);
44 const std::u32string &str,
48 if (str.length() == 1) {
51 return fnt->get(str[0]);
54 std::lock_guard<duds::general::Spinlock> lock(
block);
56 Cache::iterator iter =
cache.find(std::make_tuple(str, flags));
57 if (iter !=
cache.end()) {
59 Cache::index<index_seq>::type::iterator siter =
60 cache.project<index_seq>(iter);
61 Cache::index<index_seq>::type &sidx =
cache.get<index_seq>();
62 sidx.relocate(sidx.end(), siter);
69 unsigned int imgSize = img->data().size();
70 std::lock_guard<duds::general::Spinlock> lock(
block);
72 std::pair<Cache::iterator, bool> res =
80 Cache::index<index_seq>::type &sidx =
cache.get<index_seq>();
82 Cache::index<index_seq>::type::iterator iter = sidx.begin();
87 iter = sidx.erase(iter);
103 return res.first->img;
107 const std::string &str,
110 std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t >
conv;
111 std::u32string cstr = conv.from_bytes(str);
112 return text(cstr, flags);
std::uintptr_t PixelBlock
The type used to hold pixel values, one bit per pixel.
const BppFontSptr & font() const
Returns the font object used by this cache to render 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.
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.
The maximum size of a BppStringCache is zero.
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.
ConstBppImageSptr text(const std::string &str, BppFont::Flags flags=BppFont::AlignLeft)
Returns an image of the requested string either from a pre-rendered item in the cache or by rendering...
std::shared_ptr< BppImage > BppImageSptr
duds::general::Spinlock block
Used for thread safety.
static std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t > conv
String converter; UTF-8 to/from UTF-32.
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.
Cache cache
The cache of rendered strings.
unsigned int maxS
The maximum number of strings the cache may hold.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...