mirror of
https://github.com/edubart/otclient.git
synced 2025-12-25 09:17:11 +01:00
merge total remake
This commit is contained in:
@@ -1,48 +1,37 @@
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include "image.h"
|
||||
#include "texture.h"
|
||||
#include "graphics.h"
|
||||
#include "texturemanager.h"
|
||||
|
||||
#include <otml/otml.h>
|
||||
|
||||
#include <global.h>
|
||||
#include <graphics/image.h>
|
||||
#include <graphics/graphics.h>
|
||||
#include <graphics/textures.h>
|
||||
|
||||
Image::Image(TexturePtr texture)
|
||||
: m_texture(texture)
|
||||
Image::Image(TexturePtr texture, Rect textureCoords)
|
||||
{
|
||||
m_textureCoords = Rect(0, 0, m_texture->getSize());
|
||||
m_texture = texture;
|
||||
if(!textureCoords.isValid())
|
||||
m_textureCoords = Rect(0, 0, m_texture->getSize());
|
||||
else
|
||||
m_textureCoords = textureCoords;
|
||||
}
|
||||
|
||||
Image::Image(const std::string& texture)
|
||||
ImagePtr Image::loadFromOTML(const OTMLNodePtr& imageNode)
|
||||
{
|
||||
m_texture = g_textures.get(texture);
|
||||
m_textureCoords = Rect(0, 0, m_texture->getSize());
|
||||
}
|
||||
// load configs from otml node
|
||||
std::string source = imageNode->hasValue() ? imageNode->read<std::string>() : imageNode->readAt<std::string>("source");
|
||||
bool smooth = imageNode->readAt("smooth", false);
|
||||
Rect textureCoords = imageNode->readAt("coords", Rect());
|
||||
|
||||
Image::Image(const std::string& texture, Rect textureCoords) :
|
||||
m_textureCoords(textureCoords)
|
||||
{
|
||||
m_texture = g_textures.get(texture);
|
||||
// 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)
|
||||
@@ -50,5 +39,3 @@ void Image::draw(const Rect& screenCoords)
|
||||
if(m_texture)
|
||||
g_graphics.drawTexturedRect(screenCoords, m_texture, m_textureCoords);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user