9#include "sml/graphics_wrapper/renderer.h"
14 Image::Image(
const char* filename, ImageFormat format)
15 : m_Format(format), m_Texture(new Sml::Texture())
17 m_Texture->loadFromImage(filename);
18 assert(m_Texture->getWidth() > 0);
19 assert(m_Texture->getHeight() > 0);
22 Image::Image(
const Sml::Texture* texture)
23 : m_Format(ImageFormat::INVALID), m_Texture(texture->copy()) {}
25 int32_t Image::getWidth()
const {
return m_Texture->getWidth(); }
26 int32_t Image::getHeight()
const {
return m_Texture->getHeight(); }
27 ImageFormat Image::getFormat()
const {
return m_Format; }
28 const Sml::Texture* Image::getTexture()
const {
return m_Texture; }
30 void renderImage(
const Image* image,
const Sml::Rectangle<int32_t>& targetRegion)
33 assert(image->getTexture());
35 image->getTexture()->copyTo(Sml::Renderer::getInstance().getTarget(), &targetRegion,
nullptr);
38 void renderImage(
const Image* image,
const Sml::Rectangle<int32_t>& targetRegion,
39 int32_t scaledWidth, int32_t scaledHeight)
42 assert(image->getTexture());
44 if (scaledWidth <= 0 || scaledHeight <= 0) {
return; }
46 Sml::Rectangle<int32_t> scaledRegion{targetRegion.pos, scaledWidth, scaledHeight};
47 image->getTexture()->copyTo(Sml::Renderer::getInstance().getTarget(), &scaledRegion,
nullptr);