Factor out duplicated code for bitmap scaling in wxArtProvider.
Move duplicated code responsible for rescaling bitmaps in wxArtProvider to the shared wxArtPrvider::RescaleBitmap() method. Additionally, make this new method work even in wxUSE_IMAGE==0 case. See #17071. See https://github.com/wxWidgets/wxWidgets/pull/64.
This commit is contained in:
committed by
Vadim Zeitlin
parent
09e8876c0c
commit
244ec264af
@@ -188,6 +188,9 @@ public:
|
|||||||
// the topmost provider if platform_dependent = false
|
// the topmost provider if platform_dependent = false
|
||||||
static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false);
|
static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false);
|
||||||
|
|
||||||
|
// Rescale bitmap (used internally if requested size is other than the available).
|
||||||
|
static void RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class wxArtProviderModule;
|
friend class wxArtProviderModule;
|
||||||
#if wxUSE_ARTPROVIDER_STD
|
#if wxUSE_ARTPROVIDER_STD
|
||||||
|
@@ -212,6 +212,29 @@ wxArtProvider::~wxArtProvider()
|
|||||||
// wxArtProvider: retrieving bitmaps/icons
|
// wxArtProvider: retrieving bitmaps/icons
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void wxArtProvider::RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded)
|
||||||
|
{
|
||||||
|
wxCHECK_RET( sizeNeeded.IsFullySpecified(), wxS("New size must be given") );
|
||||||
|
|
||||||
|
#if wxUSE_IMAGE
|
||||||
|
wxImage img = bmp.ConvertToImage();
|
||||||
|
img.Rescale(sizeNeeded.x, sizeNeeded.y);
|
||||||
|
bmp = wxBitmap(img);
|
||||||
|
#else // !wxUSE_IMAGE
|
||||||
|
// Fallback method of scaling the bitmap
|
||||||
|
wxBitmap newBmp(sizeNeeded);
|
||||||
|
newBmp.UseAlpha(bmp.HasAlpha());
|
||||||
|
{
|
||||||
|
wxMemoryDC dc(newBmp);
|
||||||
|
double scX = (double)sizeNeeded.GetWidth() / bmp.GetWidth();
|
||||||
|
double scY = (double)sizeNeeded.GetHeight() / bmp.GetHeight();
|
||||||
|
dc.SetUserScale(scX, scY);
|
||||||
|
dc.DrawBitmap(bmp, 0, 0);
|
||||||
|
}
|
||||||
|
bmp = newBmp;
|
||||||
|
#endif // wxUSE_IMAGE/!wxUSE_IMAGE
|
||||||
|
}
|
||||||
|
|
||||||
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
|
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
|
||||||
const wxArtClient& client,
|
const wxArtClient& client,
|
||||||
const wxSize& size)
|
const wxSize& size)
|
||||||
@@ -256,17 +279,13 @@ wxArtProvider::~wxArtProvider()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we didn't get the correct size, resize the bitmap
|
// if we didn't get the correct size, resize the bitmap
|
||||||
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
|
|
||||||
if ( bmp.IsOk() && sizeNeeded != wxDefaultSize )
|
if ( bmp.IsOk() && sizeNeeded != wxDefaultSize )
|
||||||
{
|
{
|
||||||
if ( bmp.GetSize() != sizeNeeded )
|
if ( bmp.GetSize() != sizeNeeded )
|
||||||
{
|
{
|
||||||
wxImage img = bmp.ConvertToImage();
|
RescaleBitmap(bmp, sizeNeeded);
|
||||||
img.Rescale(sizeNeeded.x, sizeNeeded.y);
|
|
||||||
bmp = wxBitmap(img);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // wxUSE_IMAGE
|
|
||||||
|
|
||||||
sm_cache->PutBitmap(hashId, bmp);
|
sm_cache->PutBitmap(hashId, bmp);
|
||||||
}
|
}
|
||||||
|
@@ -570,7 +570,7 @@ public:
|
|||||||
void Resort();
|
void Resort();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDataViewMainWindow *m_window;
|
wxDataViewMainWindow * const m_window;
|
||||||
wxDataViewTreeNode *m_parent;
|
wxDataViewTreeNode *m_parent;
|
||||||
|
|
||||||
// Corresponding model item.
|
// Corresponding model item.
|
||||||
|
@@ -150,7 +150,6 @@ static wxBitmap CreateFromStdIcon(const char *iconName,
|
|||||||
wxBitmap bmp;
|
wxBitmap bmp;
|
||||||
bmp.CopyFromIcon(icon);
|
bmp.CopyFromIcon(icon);
|
||||||
|
|
||||||
#if wxUSE_IMAGE
|
|
||||||
// The standard native message box icons are in message box size (32x32).
|
// The standard native message box icons are in message box size (32x32).
|
||||||
// If they are requested in any size other than the default or message
|
// If they are requested in any size other than the default or message
|
||||||
// box size, they must be rescaled first.
|
// box size, they must be rescaled first.
|
||||||
@@ -159,12 +158,9 @@ static wxBitmap CreateFromStdIcon(const char *iconName,
|
|||||||
const wxSize size = wxArtProvider::GetNativeSizeHint(client);
|
const wxSize size = wxArtProvider::GetNativeSizeHint(client);
|
||||||
if ( size != wxDefaultSize )
|
if ( size != wxDefaultSize )
|
||||||
{
|
{
|
||||||
wxImage img = bmp.ConvertToImage();
|
wxArtProvider::RescaleBitmap(bmp, size);
|
||||||
img.Rescale(size.x, size.y);
|
|
||||||
bmp = wxBitmap(img);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // wxUSE_IMAGE
|
|
||||||
|
|
||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user