tibia-client/src/framework/graphics/image.cpp

42 lines
1.1 KiB
C++
Raw Normal View History

2011-08-14 04:09:11 +02:00
#include "image.h"
#include "texture.h"
#include "graphics.h"
#include "texturemanager.h"
2011-04-08 20:29:59 +02:00
2011-08-15 16:06:15 +02:00
#include <framework/otml/otml.h>
2011-04-08 20:29:59 +02:00
2011-08-14 04:09:11 +02:00
Image::Image(TexturePtr texture, Rect textureCoords)
2011-04-08 20:29:59 +02:00
{
2011-08-14 04:09:11 +02:00
m_texture = texture;
if(!textureCoords.isValid())
m_textureCoords = Rect(0, 0, m_texture->getSize());
else
m_textureCoords = textureCoords;
2011-04-08 20:29:59 +02:00
}
2011-08-14 04:09:11 +02:00
ImagePtr Image::loadFromOTML(const OTMLNodePtr& imageNode)
2011-04-08 20:29:59 +02:00
{
2011-08-14 04:09:11 +02:00
// 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());
2011-08-14 04:09:11 +02:00
// 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));
2011-04-08 20:29:59 +02:00
}
void Image::draw(const Rect& screenCoords)
{
2011-04-24 01:23:52 +02:00
if(m_texture)
g_graphics.drawTexturedRect(screenCoords, m_texture, m_textureCoords);
2011-04-08 20:29:59 +02:00
}