Adjust bitmap size to the wxPropertyGrid cell size
Bitmap inserted into the wxPG cell should be automatically rescaled while drawing to let us using bitmaps of any size.
This commit is contained in:
@@ -1149,8 +1149,7 @@ void FormMain::PopulateWithStandardItems ()
|
||||
// Set test information for cells in columns 3 and 4
|
||||
// (reserve column 2 for displaying units)
|
||||
wxPropertyGridIterator it;
|
||||
int bmpH = pg->GetGrid()->GetRowHeight() - 2;
|
||||
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_FOLDER, wxART_OTHER, wxSize(bmpH, bmpH));
|
||||
wxBitmap bmp = wxArtProvider::GetBitmap(wxART_FOLDER);
|
||||
|
||||
for ( it = pg->GetGrid()->GetIterator();
|
||||
!it.AtEnd();
|
||||
|
@@ -150,16 +150,28 @@ int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell&
|
||||
dc.SetFont(font);
|
||||
|
||||
const wxBitmap& bmp = cell.GetBitmap();
|
||||
if ( bmp.IsOk() &&
|
||||
// Do not draw oversized bitmap outside choice popup
|
||||
((flags & ChoicePopup) || bmp.GetHeight() < rect.height )
|
||||
)
|
||||
if ( bmp.IsOk() )
|
||||
{
|
||||
dc.DrawBitmap( bmp,
|
||||
int hMax = rect.height - wxPG_CUSTOM_IMAGE_SPACINGY;
|
||||
wxBitmap scaledBmp;
|
||||
int yOfs;
|
||||
if ( bmp.GetHeight() <= hMax )
|
||||
{
|
||||
scaledBmp = bmp;
|
||||
yOfs = (hMax - bmp.GetHeight()) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
double scale = (double)hMax / bmp.GetHeight();
|
||||
scaledBmp = wxPropertyGrid::RescaleBitmap(bmp, scale, scale);
|
||||
yOfs = 0;
|
||||
}
|
||||
|
||||
dc.DrawBitmap( scaledBmp,
|
||||
rect.x + wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1,
|
||||
rect.y + wxPG_CUSTOM_IMAGE_SPACINGY,
|
||||
rect.y + wxPG_CUSTOM_IMAGE_SPACINGY + yOfs,
|
||||
true );
|
||||
imageWidth = bmp.GetWidth();
|
||||
imageWidth = scaledBmp.GetWidth();
|
||||
}
|
||||
|
||||
return imageWidth;
|
||||
|
Reference in New Issue
Block a user