Fix snapshots on retina displays.

This commit is contained in:
Christian Speckner 2020-03-31 00:46:20 +02:00
parent 6e5a162a18
commit 4d99bca2cd
3 changed files with 20 additions and 3 deletions

View File

@ -137,12 +137,12 @@ class FrameBufferSDL2 : public FrameBuffer
/** /**
Transform from window to renderer coordinates, x direction Transform from window to renderer coordinates, x direction
*/ */
int scaleX(int x) const { return (x * myRenderW) / myWindowW; } int scaleX(int x) const override { return (x * myRenderW) / myWindowW; }
/** /**
Transform from window to renderer coordinates, y direction Transform from window to renderer coordinates, y direction
*/ */
int scaleY(int y) const { return (y * myRenderH) / myWindowH; } int scaleY(int y) const override { return (y * myRenderH) / myWindowH; }
protected: protected:
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@
#include "TIASurface.hxx" #include "TIASurface.hxx"
#include "Version.hxx" #include "Version.hxx"
#include "PNGLibrary.hxx" #include "PNGLibrary.hxx"
#include "Rect.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PNGLibrary::PNGLibrary(OSystem& osystem) PNGLibrary::PNGLibrary(OSystem& osystem)
@ -129,7 +130,13 @@ void PNGLibrary::saveImage(const string& filename, const VariantList& comments)
throw runtime_error("ERROR: Couldn't create snapshot file"); throw runtime_error("ERROR: Couldn't create snapshot file");
const FrameBuffer& fb = myOSystem.frameBuffer(); const FrameBuffer& fb = myOSystem.frameBuffer();
const Common::Rect& rect = fb.imageRect();
const Common::Rect& rectUnscaled = fb.imageRect();
const Common::Rect rect(
Common::Point(fb.scaleX(rectUnscaled.x()), fb.scaleY(rectUnscaled.y())),
fb.scaleX(rectUnscaled.w()), fb.scaleY(rectUnscaled.h())
);
png_uint_32 width = rect.w(), height = rect.h(); png_uint_32 width = rect.w(), height = rect.h();
// Get framebuffer pixel data (we get ABGR format) // Get framebuffer pixel data (we get ABGR format)

View File

@ -381,6 +381,16 @@ class FrameBuffer
*/ */
virtual void clear() = 0; virtual void clear() = 0;
/**
Transform from window to renderer coordinates, x direction
*/
virtual int scaleX(int x) const { return x; }
/**
Transform from window to renderer coordinates, y direction
*/
virtual int scaleY(int y) const { return y; }
protected: protected:
/** /**
This method is called to query and initialize the video hardware This method is called to query and initialize the video hardware