mirror of
https://github.com/edubart/otclient.git
synced 2025-05-03 11:09:20 +02:00
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include "image.h"
|
|
#include "texture.h"
|
|
#include "graphics.h"
|
|
#include "texturemanager.h"
|
|
|
|
#include <framework/otml/otml.h>
|
|
|
|
Image::Image(TexturePtr texture, Rect textureCoords)
|
|
{
|
|
m_texture = texture;
|
|
if(!textureCoords.isValid())
|
|
m_textureCoords = Rect(0, 0, m_texture->getSize());
|
|
else
|
|
m_textureCoords = textureCoords;
|
|
}
|
|
|
|
ImagePtr Image::loadFromOTML(const OTMLNodePtr& imageNode)
|
|
{
|
|
// load configs from otml node
|
|
std::string source = imageNode->hasValue() ? imageNode->value() : imageNode->valueAt("source");
|
|
bool smooth = imageNode->valueAt("smooth", false);
|
|
Rect textureCoords = imageNode->valueAt("coords", Rect());
|
|
|
|
// load texture
|
|
TexturePtr texture = g_textures.getTexture(source);
|
|
if(!texture)
|
|
throw OTMLException(imageNode, "could not load image texture");
|
|
|
|
// enable texture bilinear filter
|
|
if(smooth)
|
|
texture->enableBilinearFilter();
|
|
|
|
// create image
|
|
return ImagePtr(new Image(texture, textureCoords));
|
|
}
|
|
|
|
void Image::draw(const Rect& screenCoords)
|
|
{
|
|
if(m_texture)
|
|
g_graphics.drawTexturedRect(screenCoords, m_texture, m_textureCoords);
|
|
}
|