Hasty Badger
Small UI library (a branch of Turbo Badger)
|
TBBitmapFragmentManager manages loading bitmaps of arbitrary size, pack as many of them into as few TBBitmap as possible. More...
#include <tb_bitmap_fragment.h>
Public Member Functions | |
void | SetAddBorder (bool add_border) |
Set to true if a 1px border should be added to new fragments so stretched drawing won't get filtering artifacts at the edges (default is disabled). More... | |
bool | GetAddBorder () const |
TBBitmapFragment * | GetFragmentFromFile (const TBStr &filename, bool dedicated_map, float dpi) |
Get the fragment with the given image filename. More... | |
TBBitmapFragment * | GetFragment (const TBID &id) const |
Get the fragment with the given id, or nullptr if it doesn't exist. More... | |
TBBitmapFragment * | CreateNewFragment (const TBID &id, bool dedicated_map, int data_w, int data_h, int data_stride, uint32_t *data) |
Create a new fragment from the given data. More... | |
void | FreeFragment (TBBitmapFragment *frag) |
Delete the given fragment and free the space it used in its map, so that other fragments can take its place. More... | |
void | Clear () |
Clear all loaded bitmaps and all created bitmap fragments and maps. More... | |
bool | ValidateBitmaps () |
Validate bitmaps on fragment maps that has changed. More... | |
void | DeleteBitmaps () |
Delete all bitmaps in all fragment maps in this manager. More... | |
int | GetNumMaps () const |
Get number of fragment maps that is currently used. More... | |
void | SetNumMapsLimit (int num_maps_limit) |
Set the number of maps (TBBitmaps) this manager should be allowed to create. More... | |
void | SetDefaultMapSize (int w, int h) |
Set the default size of new fragment maps. More... | |
int | GetUseRatio () const |
Get the amount (in percent) of space that is currently occupied by all maps in this fragment manager. More... | |
TBBitmapFragmentManager manages loading bitmaps of arbitrary size, pack as many of them into as few TBBitmap as possible.
It also makes sure that only one instance of each file is loaded, so f.ex loading "foo.png" many times still load and allocate one TBBitmapFragment.
void tb::TBBitmapFragmentManager::Clear | ( | ) |
Clear all loaded bitmaps and all created bitmap fragments and maps.
After this call, do not keep any pointers to any TBBitmapFragment created by this fragment manager.
TBBitmapFragment * tb::TBBitmapFragmentManager::CreateNewFragment | ( | const TBID & | id, |
bool | dedicated_map, | ||
int | data_w, | ||
int | data_h, | ||
int | data_stride, | ||
uint32_t * | data | ||
) |
Create a new fragment from the given data.
id | The id that should be used to identify the fragment. |
dedicated_map | if true, it will get a dedicated map. |
data_w | the width of the data. |
data_h | the height of the data. |
data_stride | the number of pixels in a row of the input data. |
data | pointer to the data in BGRA32 format. |
void tb::TBBitmapFragmentManager::DeleteBitmaps | ( | ) |
Delete all bitmaps in all fragment maps in this manager.
The bitmaps will be recreated automatically when needed, or when calling ValidateBitmaps. You do not need to call this, except when the context is lost and all bitmaps must be forgotten.
void tb::TBBitmapFragmentManager::FreeFragment | ( | TBBitmapFragment * | frag | ) |
Delete the given fragment and free the space it used in its map, so that other fragments can take its place.
TBBitmapFragment * tb::TBBitmapFragmentManager::GetFragment | ( | const TBID & | id | ) | const |
Get the fragment with the given id, or nullptr if it doesn't exist.
TBBitmapFragment * tb::TBBitmapFragmentManager::GetFragmentFromFile | ( | const TBStr & | filename, |
bool | dedicated_map, | ||
float | dpi | ||
) |
Get the fragment with the given image filename.
If it's not already loaded, it will be loaded into a new fragment with the filename as id. returns nullptr on fail.
|
inline |
Get number of fragment maps that is currently used.
int tb::TBBitmapFragmentManager::GetUseRatio | ( | ) | const |
Get the amount (in percent) of space that is currently occupied by all maps in this fragment manager.
|
inline |
Set to true if a 1px border should be added to new fragments so stretched drawing won't get filtering artifacts at the edges (default is disabled).
void tb::TBBitmapFragmentManager::SetDefaultMapSize | ( | int | w, |
int | h | ||
) |
Set the default size of new fragment maps.
These must be power of two.
void tb::TBBitmapFragmentManager::SetNumMapsLimit | ( | int | num_maps_limit | ) |
Set the number of maps (TBBitmaps) this manager should be allowed to create.
If a new fragment can't fit into any existing bitmap and the limit is reached, the fragment creation will fail. Set to 0 for unlimited (default).
bool tb::TBBitmapFragmentManager::ValidateBitmaps | ( | ) |
Validate bitmaps on fragment maps that has changed.