Move screen height detection inside CImageLoaderSVG::loadImage

This commit is contained in:
Benau 2022-04-07 08:51:25 +08:00
parent 1655c243b7
commit 4c4daf9698
4 changed files with 2 additions and 19 deletions

View File

@ -45,8 +45,6 @@ public:
virtual IImage* loadImage(io::IReadFile* file, bool skip_checking = false) const = 0; virtual IImage* loadImage(io::IReadFile* file, bool skip_checking = false) const = 0;
virtual core::dimension2du getImageSize(io::IReadFile* file) const { return core::dimension2du(0, 0); } virtual core::dimension2du getImageSize(io::IReadFile* file) const { return core::dimension2du(0, 0); }
virtual bool supportThreadedLoading() const { return false; } virtual bool supportThreadedLoading() const { return false; }
virtual void setScreenSize(const core::dimension2d<u32> &screen_size) {};
}; };

View File

@ -13,6 +13,7 @@
#include "os.h" #include "os.h"
#include "irrString.h" #include "irrString.h"
#include "CNullDriver.h" #include "CNullDriver.h"
#include "ge_main.hpp"
namespace irr namespace irr
{ {
@ -25,12 +26,6 @@ CImageLoaderSVG::CImageLoaderSVG()
{ {
} }
//! set the screen size
void CImageLoaderSVG::setScreenSize(const core::dimension2d<u32> &screen_size)
{
ScreenSize = screen_size;
}
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga") //! based on the file extension (e.g. ".tga")
bool CImageLoaderSVG::isALoadableFileExtension(const io::path& filename) const bool CImageLoaderSVG::isALoadableFileExtension(const io::path& filename) const
@ -109,7 +104,7 @@ IImage* CImageLoaderSVG::loadImage(io::IReadFile* file, bool skip_checking) cons
if ( strstr(file->getFileName().c_str(),"gui/icons/") ) if ( strstr(file->getFileName().c_str(),"gui/icons/") )
{ {
// determine scaling based on screen size // determine scaling based on screen size
float screen_height = ScreenSize.Height; float screen_height = (float)GE::getDriver()->getCurrentRenderTargetSize().Height;
float desired_icon_size = 0.21*screen_height + 30.0f; // phenomenological float desired_icon_size = 0.21*screen_height + 30.0f; // phenomenological
scale = desired_icon_size/img->height; scale = desired_icon_size/img->height;
} }

View File

@ -38,9 +38,6 @@ public:
//! constructor //! constructor
CImageLoaderSVG(); CImageLoaderSVG();
// set the screen size, used to determine scaling
virtual void setScreenSize(const core::dimension2d<u32> &screen_size);
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".tga") //! based on the file extension (e.g. ".tga")
virtual bool isALoadableFileExtension(const io::path& filename) const; virtual bool isALoadableFileExtension(const io::path& filename) const;
@ -51,9 +48,6 @@ public:
//! creates a surface from the file //! creates a surface from the file
virtual IImage* loadImage(io::IReadFile* file, bool skip_checking = false) const; virtual IImage* loadImage(io::IReadFile* file, bool skip_checking = false) const;
private:
core::dimension2d<u32> ScreenSize;
}; };

View File

@ -1303,8 +1303,6 @@ IImage* CNullDriver::createImageFromFile(io::IReadFile* file, video::IImageLoade
*loader = SurfaceLoader[i]; *loader = SurfaceLoader[i];
return 0; return 0;
} }
// pass screen size to ImageLoaderSVG. For other formats (BMP,JPG,PNG), setScreenSize() does nothing
SurfaceLoader[i]->setScreenSize(getCurrentRenderTargetSize());
// reset file position which might have changed due to previous loadImage calls // reset file position which might have changed due to previous loadImage calls
file->seek(0); file->seek(0);
image = SurfaceLoader[i]->loadImage(file); image = SurfaceLoader[i]->loadImage(file);
@ -1325,8 +1323,6 @@ IImage* CNullDriver::createImageFromFile(io::IReadFile* file, video::IImageLoade
*loader = SurfaceLoader[i]; *loader = SurfaceLoader[i];
return 0; return 0;
} }
// pass screen size to ImageLoaderSVG. For other formats (BMP,JPG,PNG), setScreenSize() does nothing
SurfaceLoader[i]->setScreenSize(getCurrentRenderTargetSize());
file->seek(0); file->seek(0);
image = SurfaceLoader[i]->loadImage(file); image = SurfaceLoader[i]->loadImage(file);
if (image) if (image)