Adjust scale of bitmaps returned by wxBitmapBundle::GetBitmap()
Bitmaps returned from this function must have the appropriate scale
factor, e.g. 2 in standard high DPI case, in order to be drawn at
correct size in the ports where logical pixels are different from the
physical ones, such as wxOSX and wxGTK3.
Notably, this allows wxGenericStaticBitmap to work correctly in high DPI
in these ports too.
This also allows to undo some of the changes done in 399b0ff9ae
(Use
wxBitmapBundle instead of bitmap scale factor in wxGtkImage, 2021-10-16)
to wxGtkImage code and keep using the same code that had been used
before.
This commit is contained in:
@@ -384,7 +384,16 @@ wxBitmap wxBitmapBundle::GetBitmap(const wxSize& size) const
|
||||
if ( !m_impl )
|
||||
return wxBitmap();
|
||||
|
||||
return m_impl->GetBitmap(size == wxDefaultSize ? GetDefaultSize() : size);
|
||||
const wxSize sizeDef = GetDefaultSize();
|
||||
|
||||
wxBitmap bmp = m_impl->GetBitmap(size == wxDefaultSize ? sizeDef : size);
|
||||
|
||||
// Ensure that the returned bitmap uses the scale factor such that it takes
|
||||
// the same space, in logical pixels, as the bitmap in the default size.
|
||||
if ( size != wxDefaultSize )
|
||||
bmp.SetScaleFactor(static_cast<double>(size.y)/sizeDef.y);
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@@ -155,24 +155,13 @@ static gboolean wxGtkImageDraw(GtkWidget* widget, GdkEventExpose* event)
|
||||
#endif
|
||||
}
|
||||
|
||||
const double scaleFactor = image->m_provider->GetScale();
|
||||
|
||||
GtkAllocation alloc;
|
||||
gtk_widget_get_allocation(widget, &alloc);
|
||||
int x = (alloc.width - int(bitmap.GetWidth() /scaleFactor)) / 2;
|
||||
int y = (alloc.height - int(bitmap.GetHeight()/scaleFactor)) / 2;
|
||||
int x = (alloc.width - int(bitmap.GetScaledWidth() )) / 2;
|
||||
int y = (alloc.height - int(bitmap.GetScaledHeight())) / 2;
|
||||
#ifdef __WXGTK3__
|
||||
gtk_render_background(gtk_widget_get_style_context(widget),
|
||||
cr, 0, 0, alloc.width, alloc.height);
|
||||
|
||||
if (!wxIsSameDouble(scaleFactor, 1))
|
||||
{
|
||||
cairo_translate(cr, x, y);
|
||||
const double scale = 1 / scaleFactor;
|
||||
cairo_scale(cr, scale, scale);
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
bitmap.Draw(cr, x, y);
|
||||
#else
|
||||
x += alloc.x;
|
||||
|
Reference in New Issue
Block a user