Replace multiple RescaleBitmap() with wxBitmap::Rescale()
Define a single function and use it in both wxArtProvider and (the generic implementation of) wxSearchCtrl instead of repeating the same code elsewhere. Note that another, but slightly different, version of RescaleBitmap() still remains in wxPropertyGrid. Deprecate undocumented wxArtProvider::RescaleBitmap() which is completely useless now. No real changes, this is just a refactoring.
This commit is contained in:
@@ -189,8 +189,10 @@ 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).
|
#if WXWIN_COMPATIBILITY_3_0
|
||||||
|
wxDEPRECATED_MSG("use wxBitmap::Rescale() instead.")
|
||||||
static void RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded);
|
static void RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded);
|
||||||
|
#endif // WXWIN_COMPATIBILITY_3_0
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class wxArtProviderModule;
|
friend class wxArtProviderModule;
|
||||||
|
@@ -97,6 +97,9 @@ class WXDLLIMPEXP_CORE wxBitmapHelpers
|
|||||||
public:
|
public:
|
||||||
// Create a new wxBitmap from the PNG data in the given buffer.
|
// Create a new wxBitmap from the PNG data in the given buffer.
|
||||||
static wxBitmap NewFromPNGData(const void* data, size_t size);
|
static wxBitmap NewFromPNGData(const void* data, size_t size);
|
||||||
|
|
||||||
|
// Rescale the given bitmap to the requested size.
|
||||||
|
static void Rescale(wxBitmap& bmp, const wxSize& sizeNeeded);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -682,6 +682,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool RemoveHandler(const wxString& name);
|
static bool RemoveHandler(const wxString& name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Rescale the given bitmap to the requested size.
|
||||||
|
|
||||||
|
This function uses wxImage::Rescale() to resize the given @a bmp to the
|
||||||
|
requested size. Both the bitmap itself and size must be valid.
|
||||||
|
|
||||||
|
@since 3.1.6
|
||||||
|
*/
|
||||||
|
static void Rescale(wxBitmap& bmp, const wxSize& sizeNeeded);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Saves a bitmap in the named file.
|
Saves a bitmap in the named file.
|
||||||
|
|
||||||
|
@@ -209,31 +209,12 @@ wxArtProvider::~wxArtProvider()
|
|||||||
// wxArtProvider: retrieving bitmaps/icons
|
// wxArtProvider: retrieving bitmaps/icons
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if WXWIN_COMPATIBILITY_3_0
|
||||||
void wxArtProvider::RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded)
|
void wxArtProvider::RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded)
|
||||||
{
|
{
|
||||||
wxCHECK_RET( sizeNeeded.IsFullySpecified(), wxS("New size must be given") );
|
return wxBitmap::Rescale(bmp, sizeNeeded);
|
||||||
|
|
||||||
#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, bmp.GetDepth());
|
|
||||||
#if defined(__WXMSW__) || defined(__WXOSX__)
|
|
||||||
// wxBitmap::UseAlpha() is used only on wxMSW and wxOSX.
|
|
||||||
newBmp.UseAlpha(bmp.HasAlpha());
|
|
||||||
#endif // __WXMSW__ || __WXOSX__
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
#endif // WXWIN_COMPATIBILITY_3_0
|
||||||
|
|
||||||
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
|
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
|
||||||
const wxArtClient& client,
|
const wxArtClient& client,
|
||||||
@@ -283,7 +264,7 @@ void wxArtProvider::RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded)
|
|||||||
{
|
{
|
||||||
if ( bmp.GetSize() != sizeNeeded )
|
if ( bmp.GetSize() != sizeNeeded )
|
||||||
{
|
{
|
||||||
RescaleBitmap(bmp, sizeNeeded);
|
wxBitmap::Rescale(bmp, sizeNeeded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,6 +64,33 @@ wxBitmap wxBitmapHelpers::NewFromPNGData(const void* data, size_t size)
|
|||||||
|
|
||||||
#endif // !__WXOSX__
|
#endif // !__WXOSX__
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
void wxBitmapHelpers::Rescale(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, bmp.GetDepth());
|
||||||
|
#if defined(__WXMSW__) || defined(__WXOSX__)
|
||||||
|
// wxBitmap::UseAlpha() is used only on wxMSW and wxOSX.
|
||||||
|
newBmp.UseAlpha(bmp.HasAlpha());
|
||||||
|
#endif // __WXMSW__ || __WXOSX__
|
||||||
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxBitmapBase
|
// wxBitmapBase
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -937,32 +937,6 @@ static int GetMultiplier()
|
|||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void 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, bmp.GetDepth());
|
|
||||||
#if defined(__WXMSW__) || defined(__WXOSX__)
|
|
||||||
// wxBitmap::UseAlpha() is used only on wxMSW and wxOSX.
|
|
||||||
newBmp.UseAlpha(bmp.HasAlpha());
|
|
||||||
#endif // __WXMSW__ || __WXOSX__
|
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
wxBitmap wxSearchCtrl::RenderSearchBitmap( int x, int y, bool renderDrop )
|
wxBitmap wxSearchCtrl::RenderSearchBitmap( int x, int y, bool renderDrop )
|
||||||
{
|
{
|
||||||
wxColour bg = GetBackgroundColour();
|
wxColour bg = GetBackgroundColour();
|
||||||
@@ -1055,7 +1029,7 @@ wxBitmap wxSearchCtrl::RenderSearchBitmap( int x, int y, bool renderDrop )
|
|||||||
|
|
||||||
if ( multiplier != 1 )
|
if ( multiplier != 1 )
|
||||||
{
|
{
|
||||||
RescaleBitmap(bitmap, wxSize(x, y));
|
wxBitmap::Rescale(bitmap, wxSize(x, y));
|
||||||
}
|
}
|
||||||
if ( !renderDrop )
|
if ( !renderDrop )
|
||||||
{
|
{
|
||||||
@@ -1137,7 +1111,7 @@ wxBitmap wxSearchCtrl::RenderCancelBitmap( int x, int y )
|
|||||||
};
|
};
|
||||||
mem.DrawPolygon(WXSIZEOF(handlePolygon2),handlePolygon2,multiplier*lineStartBase,multiplier*(x-lineStartBase));
|
mem.DrawPolygon(WXSIZEOF(handlePolygon2),handlePolygon2,multiplier*lineStartBase,multiplier*(x-lineStartBase));
|
||||||
|
|
||||||
// Stop drawing on the bitmap before possibly calling RescaleBitmap()
|
// Stop drawing on the bitmap before possibly calling wxBitmap::Rescale()
|
||||||
// below.
|
// below.
|
||||||
mem.SelectObject(wxNullBitmap);
|
mem.SelectObject(wxNullBitmap);
|
||||||
|
|
||||||
@@ -1147,7 +1121,7 @@ wxBitmap wxSearchCtrl::RenderCancelBitmap( int x, int y )
|
|||||||
|
|
||||||
if ( multiplier != 1 )
|
if ( multiplier != 1 )
|
||||||
{
|
{
|
||||||
RescaleBitmap(bitmap, wxSize(x, y));
|
wxBitmap::Rescale(bitmap, wxSize(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
@@ -218,7 +218,7 @@ static wxBitmap CreateFromStdIcon(const char *iconName,
|
|||||||
const wxSize size = wxArtProvider::GetNativeSizeHint(client);
|
const wxSize size = wxArtProvider::GetNativeSizeHint(client);
|
||||||
if ( size != wxDefaultSize )
|
if ( size != wxDefaultSize )
|
||||||
{
|
{
|
||||||
wxArtProvider::RescaleBitmap(bmp, size);
|
wxBitmap::Rescale(bmp, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ wxBitmap wxWindowsArtProvider::CreateBitmap(const wxArtID& id,
|
|||||||
{
|
{
|
||||||
if ( bitmap.GetSize() != sizeNeeded )
|
if ( bitmap.GetSize() != sizeNeeded )
|
||||||
{
|
{
|
||||||
wxArtProvider::RescaleBitmap(bitmap, sizeNeeded);
|
wxBitmap::Rescale(bitmap, sizeNeeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
|
Reference in New Issue
Block a user