Fix wxSearchCtrl (generic) compilation when wxUSE_IMAGE==0

Implemented function to rescale a bitmap even if rescaling using wxImage is not possible.
This commit is contained in:
Artur Wieczorek
2016-02-25 23:48:56 +01:00
parent 2ea39a23e7
commit 08f800ab16

View File

@@ -935,6 +935,32 @@ 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);
#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();
@@ -1027,9 +1053,7 @@ wxBitmap wxSearchCtrl::RenderSearchBitmap( int x, int y, bool renderDrop )
if ( multiplier != 1 ) if ( multiplier != 1 )
{ {
wxImage image = bitmap.ConvertToImage(); RescaleBitmap(bitmap, wxSize(x, y));
image.Rescale(x,y);
bitmap = wxBitmap( image );
} }
if ( !renderDrop ) if ( !renderDrop )
{ {
@@ -1117,9 +1141,7 @@ wxBitmap wxSearchCtrl::RenderCancelBitmap( int x, int y )
if ( multiplier != 1 ) if ( multiplier != 1 )
{ {
wxImage image = bitmap.ConvertToImage(); RescaleBitmap(bitmap, wxSize(x, y));
image.Rescale(x,y);
bitmap = wxBitmap( image );
} }
return bitmap; return bitmap;