Version: 3.2.2
wxBitmapBundleImpl Class Referenceabstract

#include <wx/bmpbndl.h>

+ Inheritance diagram for wxBitmapBundleImpl:

Detailed Description

Base class for custom implementations of wxBitmapBundle.

This class shouldn't be used directly in the application code, but may be derived from to implement custom bitmap bundles.

Example of use:

class MyCustomBitmapBundleImpl : public wxBitmapBundleImpl
{
public:
MyCustomBitmapBundleImpl()
{
}
{
... determine the minimum/default size for bitmap to use ...
}
{
// If it's ok to scale the bitmap, just use the standard size
// at the given scale:
return GetDefaultSize()*scale;
... otherwise, an existing bitmap of the size closest to the
one above would need to be found and its size returned,
possibly by letting DoGetPreferredSize() choose it ...
}
{
... get the bitmap of the requested size from somewhere and
cache it if necessary, i.e. if getting it is expensive ...
}
};
toolBar->AddTool(wxID_OPEN, wxBitmapBundle::FromImpl(new MyCustomBitmapBundleImpl());
static wxBitmapBundle FromImpl(wxBitmapBundleImpl *impl)
Create a bundle from a custom bitmap bundle implementation.
Base class for custom implementations of wxBitmapBundle.
Definition: bmpbndl.h:492
wxSize DoGetPreferredSize(double scale) const
Helper for implementing GetPreferredBitmapSizeAtScale() in the derived classes.
virtual wxSize GetDefaultSize() const =0
Return the size of the bitmaps represented by this bundle in the default DPI.
virtual wxBitmap GetBitmap(const wxSize &size)=0
Retrieve the bitmap of exactly the given size.
virtual wxSize GetPreferredBitmapSizeAtScale(double scale) const =0
Return the preferred size that should be used at the given scale.
This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or co...
Definition: bitmap.h:212
A wxSize is a useful data structure for graphics operations.
Definition: gdicmn.h:940
@ wxID_OPEN
Definition: defs.h:606
#define wxOVERRIDE
wxOVERRIDE expands to the C++11 override keyword if it's supported by the compiler or nothing otherwi...
Definition: defs.h:1831

Full (but still very simple) example of using it can be found in the toolbar sample code.

Library:  wxCore
Category:  Graphics Device Interface (GDI)
Since
3.1.6

Public Member Functions

virtual wxSize GetDefaultSize () const =0
 Return the size of the bitmaps represented by this bundle in the default DPI. More...
 
virtual wxSize GetPreferredBitmapSizeAtScale (double scale) const =0
 Return the preferred size that should be used at the given scale. More...
 
virtual wxBitmap GetBitmap (const wxSize &size)=0
 Retrieve the bitmap of exactly the given size. More...
 
- Public Member Functions inherited from wxRefCounter
 wxRefCounter ()
 Default constructor. More...
 
void DecRef ()
 Decrements the reference count associated with this shared data and, if it reaches zero, destroys this instance of wxRefCounter releasing its memory. More...
 
int GetRefCount () const
 Returns the reference count associated with this shared data. More...
 
void IncRef ()
 Increments the reference count associated with this shared data. More...
 

Protected Member Functions

wxSize DoGetPreferredSize (double scale) const
 Helper for implementing GetPreferredBitmapSizeAtScale() in the derived classes. More...
 
size_t GetIndexToUpscale (const wxSize &size) const
 Return the index of the available scale most suitable to be upscaled to the given size. More...
 
virtual double GetNextAvailableScale (size_t &i) const
 Return information about the available bitmaps. More...
 
- Protected Member Functions inherited from wxRefCounter
virtual ~wxRefCounter ()
 Destructor. More...
 

Member Function Documentation

◆ DoGetPreferredSize()

wxSize wxBitmapBundleImpl::DoGetPreferredSize ( double  scale) const
protected

Helper for implementing GetPreferredBitmapSizeAtScale() in the derived classes.

This function implements the standard algorithm used inside wxWidgets itself and tries to find the scale closest to the given one, while also trying to choose one of the available scales, to avoid actually rescaling the bitmaps.

It relies on GetNextAvailableScale() to get information about the available bitmaps, so that function must be overridden if this one is used.

Typically this function is used in the derived classes implementation to forward GetPreferredBitmapSizeAtScale() to it and when this is done, GetBitmap() may also use GetIndexToUpscale() to choose the bitmap to upscale if necessary:

class MyCustomBitmapBundleImpl : public wxBitmapBundleImpl
{
public:
{
return wxSize(32, 32);
}
{
return DoGetPreferredSize(scale);
}
{
// For consistency with GetNextAvailableScale(), we must have
// bitmap variants for 32, 48 and 64px sizes.
const wxSize availableSizes[] = { 32, 48, 64 };
if ( size.y <= 64 )
{
... get the bitmap from somewhere ...
}
else
{
size_t n = GetIndexToUpscale(size);
bitmap = ... get bitmap for availableSizes[n] ...;
wxBitmap::Rescale(bitmap, size);
}
return bitmap;
}
protected:
double GetNextAvailableScale(size_t& i) const wxOVERRIDE
{
const double availableScales[] = { 1, 1.5, 2, 0 };
// We can rely on not being called again once we return 0.
return availableScales[i++];
}
...
};
size_t GetIndexToUpscale(const wxSize &size) const
Return the index of the available scale most suitable to be upscaled to the given size.
virtual double GetNextAvailableScale(size_t &i) const
Return information about the available bitmaps.
static void Rescale(wxBitmap &bmp, const wxSize &sizeNeeded)
Rescale the given bitmap to the requested size.
Parameters
scaleThe required scale, typically the same one as passed to GetPreferredBitmapSizeAtScale().
Since
3.1.7

◆ GetBitmap()

virtual wxBitmap wxBitmapBundleImpl::GetBitmap ( const wxSize size)
pure virtual

Retrieve the bitmap of exactly the given size.

Note that this function is non-const because it may generate the bitmap on demand and cache it.

◆ GetDefaultSize()

virtual wxSize wxBitmapBundleImpl::GetDefaultSize ( ) const
pure virtual

Return the size of the bitmaps represented by this bundle in the default DPI.

Must always return a valid size.

◆ GetIndexToUpscale()

size_t wxBitmapBundleImpl::GetIndexToUpscale ( const wxSize size) const
protected

Return the index of the available scale most suitable to be upscaled to the given size.

See DoGetPreferredSize() for an example of using this function.

Parameters
sizeThe required size, typically the same one as passed to GetBitmap()
Since
3.1.7

◆ GetNextAvailableScale()

virtual double wxBitmapBundleImpl::GetNextAvailableScale ( size_t &  i) const
protectedvirtual

Return information about the available bitmaps.

Overriding this function is optional and only needs to be done if either DoGetPreferredSize() or GetIndexToUpscale() are called. If you do override it, this function must return the next available scale or 0.0 if there are no more.

The returned scales must be in ascending order and the first returned scale, for the initial i value of 0, should be 1. The function must change i, but the values of this index don't have to be consecutive and it's only used by this function itself, the caller only initializes it to 0 before the first call.

See DoGetPreferredSize() for an example of implementing this function.

Since
3.1.7

◆ GetPreferredBitmapSizeAtScale()

virtual wxSize wxBitmapBundleImpl::GetPreferredBitmapSizeAtScale ( double  scale) const
pure virtual

Return the preferred size that should be used at the given scale.

Must always return a valid size.