Rescale wxPGProperty bitmap while drawing
Property bitmap should be stored in its original size and rescaling to the required size should be done only while drawing the property. This way bitmap size will always fit to the actual wxPG line height.
This commit is contained in:
@@ -1313,7 +1313,20 @@ bool wxPGProperty::SetValueFromInt( long number, int argFlags )
|
|||||||
wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const
|
wxSize wxPGProperty::OnMeasureImage( int WXUNUSED(item) ) const
|
||||||
{
|
{
|
||||||
if ( m_valueBitmap )
|
if ( m_valueBitmap )
|
||||||
return wxSize(m_valueBitmap->GetWidth(), wxDefaultCoord);
|
{
|
||||||
|
wxPropertyGrid* pg = GetGrid();
|
||||||
|
double scale = 1.0;
|
||||||
|
if ( pg )
|
||||||
|
{
|
||||||
|
int hMax = pg->GetImageSize().GetHeight();
|
||||||
|
if ( m_valueBitmap->GetHeight() > hMax )
|
||||||
|
{
|
||||||
|
scale = (double)hMax / m_valueBitmap->GetHeight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxSize(wxRound(scale*m_valueBitmap->GetWidth()), wxDefaultCoord);
|
||||||
|
}
|
||||||
|
|
||||||
return wxSize(0,0);
|
return wxSize(0,0);
|
||||||
}
|
}
|
||||||
@@ -1343,11 +1356,23 @@ void wxPGProperty::OnCustomPaint( wxDC& dc,
|
|||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
wxPGPaintData& )
|
wxPGPaintData& )
|
||||||
{
|
{
|
||||||
wxBitmap* bmp = m_valueBitmap;
|
wxCHECK_RET( m_valueBitmap && m_valueBitmap->IsOk(), wxS("invalid bitmap") );
|
||||||
|
|
||||||
wxCHECK_RET( bmp && bmp->IsOk(), wxS("invalid bitmap") );
|
wxBitmap scaledBmp;
|
||||||
|
int yOfs;
|
||||||
|
if ( m_valueBitmap->GetHeight() <= rect.height )
|
||||||
|
{
|
||||||
|
scaledBmp = *m_valueBitmap;
|
||||||
|
yOfs = (rect.height - m_valueBitmap->GetHeight()) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double scale = (double)rect.height / m_valueBitmap->GetHeight();
|
||||||
|
scaledBmp = wxPropertyGrid::RescaleBitmap(*m_valueBitmap, scale, scale);
|
||||||
|
yOfs = 0;
|
||||||
|
}
|
||||||
|
|
||||||
dc.DrawBitmap(*bmp,rect.x,rect.y);
|
dc.DrawBitmap(scaledBmp,rect.x, rect.y + yOfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxPGEditor* wxPGProperty::DoGetEditorClass() const
|
const wxPGEditor* wxPGProperty::DoGetEditorClass() const
|
||||||
@@ -2160,7 +2185,6 @@ bool wxPGProperty::RecreateEditor()
|
|||||||
|
|
||||||
void wxPGProperty::SetValueImage( wxBitmap& bmp )
|
void wxPGProperty::SetValueImage( wxBitmap& bmp )
|
||||||
{
|
{
|
||||||
// We need PG to obtain default image size
|
|
||||||
wxCHECK_RET( GetGrid(),
|
wxCHECK_RET( GetGrid(),
|
||||||
wxS("Cannot set image for detached property") );
|
wxS("Cannot set image for detached property") );
|
||||||
|
|
||||||
@@ -2168,20 +2192,7 @@ void wxPGProperty::SetValueImage( wxBitmap& bmp )
|
|||||||
|
|
||||||
if ( bmp.IsOk() )
|
if ( bmp.IsOk() )
|
||||||
{
|
{
|
||||||
// Resize the image
|
m_valueBitmap = new wxBitmap(bmp);
|
||||||
wxSize maxSz = GetGrid()->GetImageSize();
|
|
||||||
wxSize imSz = bmp.GetSize();
|
|
||||||
|
|
||||||
if ( imSz.y != maxSz.y )
|
|
||||||
{
|
|
||||||
double scaleY = (double)maxSz.y / (double)imSz.y;
|
|
||||||
m_valueBitmap = new wxBitmap(wxPropertyGrid::RescaleBitmap(bmp, scaleY, scaleY));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_valueBitmap = new wxBitmap(bmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_flags |= wxPG_PROP_CUSTOMIMAGE;
|
m_flags |= wxPG_PROP_CUSTOMIMAGE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user