6 #ifndef TB_BITMAP_FRAGMENT_H
7 #define TB_BITMAP_FRAGMENT_H
10 #include "tb_geometry.h"
11 #include "tb_hashtable.h"
14 #include "tb_linklist.h"
18 class TBBitmapFragment;
38 virtual int Width() = 0;
45 virtual uint32_t *
Data() = 0;
60 : m_available_space(available_space) { }
74 Space *GetSmallestAvailableSpace(
int needed_w);
75 int m_available_space;
112 bool Init(
int bitmap_w,
int bitmap_h);
126 bool ValidateBitmap();
128 void CopyData(
TBBitmapFragment *frag,
int data_stride, uint32_t *frag_data,
int border);
130 int m_bitmap_w, m_bitmap_h;
131 uint32_t *m_bitmap_data;
134 int m_allocated_pixels;
144 int Width()
const {
return m_rect.w; }
186 bool GetAddBorder()
const {
return m_add_border; }
191 TBBitmapFragment *
GetFragmentFromFile(
const TBStr & filename,
bool dedicated_map,
float dpi);
194 TBBitmapFragment *
GetFragment(
const TBID &
id)
const;
204 int data_w,
int data_h,
int data_stride,
226 int GetNumMaps()
const {
return m_fragment_maps.GetNumItems(); }
239 #ifdef TB_RUNTIME_DEBUG_INFO
246 int m_num_maps_limit;
254 #endif // TB_BITMAP_FRAGMENT_H
void DeleteBitmaps()
Delete all bitmaps in all fragment maps in this manager.
Definition: tb_bitmap_fragment.cpp:521
TBBitmapFragmentManager manages loading bitmaps of arbitrary size, pack as many of them into as few T...
Definition: tb_bitmap_fragment.h:177
int GetNumMaps() const
Get number of fragment maps that is currently used.
Definition: tb_bitmap_fragment.h:226
TBBitmapFragment * GetFragmentFromFile(const TBStr &filename, bool dedicated_map, float dpi)
Get the fragment with the given image filename.
Definition: tb_bitmap_fragment.cpp:416
bool Init(int bitmap_w, int bitmap_h)
Initialize the map with the given size.
Definition: tb_bitmap_fragment.cpp:172
Space * AllocSpace(int needed_w)
Allocate the given space and return the Space, or nullptr on error.
Definition: tb_bitmap_fragment.cpp:37
int GetAllocatedHeight() const
Return the height allocated to this fragment.
Definition: tb_bitmap_fragment.h:157
TBBitmapFragment * GetFragment(const TBID &id) const
Get the fragment with the given id, or nullptr if it doesn't exist.
Definition: tb_bitmap_fragment.cpp:501
static TBImageLoader * CreateFromFile(const TBStr &filename, float dpi)
Static method used to create an image loader.
Allocates space for TBBitmapFragment in a row (used in TBBitmapFragmentMap).
Definition: tb_bitmap_fragment.h:81
TBImageloader is a class used to load skin images.
Definition: tb_bitmap_fragment.h:28
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...
Definition: tb_bitmap_fragment.h:185
virtual int Width()=0
Return the width of the loaded bitmap.
TB_VALIDATE_TYPE
Specify when the bitmap should be validated when calling TBBitmapFragmentMap::GetBitmap.
Definition: tb_bitmap_fragment.h:91
int GetUseRatio() const
Get the amount (in percent) of space that is currently occupied by all maps in this fragment manager...
Definition: tb_bitmap_fragment.cpp:540
void Clear()
Clear all loaded bitmaps and all created bitmap fragments and maps.
Definition: tb_bitmap_fragment.cpp:506
TBID is a wrapper for a uint32_t to be used as ID.
Definition: tb_id.h:18
void FreeFragment(TBBitmapFragment *frag)
Delete the given fragment and free the space it used in its map, so that other fragments can take its...
Definition: tb_bitmap_fragment.cpp:485
Allocator of space out of a given available space.
Definition: tb_bitmap_fragment.h:49
Only validate if the bitmap does not yet exist (Make sure there is a valid bitmap pointer...
Definition: tb_bitmap_fragment.h:98
TBBitmapFragmentMap is used to pack multiple bitmaps into a single TBBitmap.
Definition: tb_bitmap_fragment.h:104
Always validate the bitmap (The bitmap is updated if needed)
Definition: tb_bitmap_fragment.h:94
TBBitmap * GetBitmap(TB_VALIDATE_TYPE validate_type=TB_VALIDATE_ALWAYS)
Return the bitmap for this fragment.
Definition: tb_bitmap_fragment.h:151
TBBitmapFragment represents a sub part of a TBBitmap.
Definition: tb_bitmap_fragment.h:140
virtual uint32_t * Data()=0
Return the data of the loaded bitmap.
TBBitmap is a minimal interface for bitmap to be painted by TBRenderer.
Definition: tb_renderer.h:36
TBListAutoDeleteOf is a list (array) of pointers to the specified object type.
Definition: tb_list.h:118
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.
Definition: tb_bitmap_fragment.cpp:436
TBHashTableOf is a TBHashTable with the given class type as content.
Definition: tb_hashtable.h:99
void SetDefaultMapSize(int w, int h)
Set the default size of new fragment maps.
Definition: tb_bitmap_fragment.cpp:532
TBListOf is a list (array) of pointers to the specified object type.
Definition: tb_list.h:47
TBBitmapFragment * CreateNewFragment(int frag_w, int frag_h, int data_stride, uint32_t *frag_data, bool add_border)
Create a new fragment with the given size and data in this map.
Definition: tb_bitmap_fragment.cpp:190
TBStr is a simple string class.
Definition: tb_str.h:62
Simple rectangle class.
Definition: tb_geometry.h:25
virtual int Height()=0
Return the height of the loaded bitmap.
uint32_t m_batch_id
This uint32_t is reserved for batching renderer backends.
Definition: tb_bitmap_fragment.h:168
void SetNumMapsLimit(int num_maps_limit)
Set the number of maps (TBBitmaps) this manager should be allowed to create.
Definition: tb_bitmap_fragment.cpp:527
TBLinkListAutoDeleteOf is a double linked linklist that deletes all links on destruction.
Definition: tb_linklist.h:194
Definition: tb_linklist.h:83
bool ValidateBitmaps()
Validate bitmaps on fragment maps that has changed.
Definition: tb_bitmap_fragment.cpp:512
A chunk of space.
Definition: tb_bitmap_fragment.h:53
bool HasSpace(int needed_w) const
Return true if the given width is currently available.
Definition: tb_bitmap_fragment.cpp:23
void FreeFragmentSpace(TBBitmapFragment *frag)
Free up the space used by the given fragment, so that other fragments can take its place...
Definition: tb_bitmap_fragment.cpp:289
int Width() const
Return the width of the bitmap fragment.
Definition: tb_bitmap_fragment.h:144
bool IsAllAvailable() const
Return true if no allocations are currently live using this allocator.
Definition: tb_bitmap_fragment.h:63
TBBitmap * GetBitmap(TB_VALIDATE_TYPE validate_type=TB_VALIDATE_ALWAYS)
Return the bitmap for this map.
Definition: tb_bitmap_fragment.cpp:370
int TBGetNearestPowerOfTwo(int val)
Return the nearest power of two from val.
Definition: tb_bitmap_fragment.cpp:12
void FreeSpace(Space *space)
Free the given space so it is available for new allocations.
Definition: tb_bitmap_fragment.cpp:89
int Height() const
Return the height of the bitmap fragment.
Definition: tb_bitmap_fragment.h:147