mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 14:03:26 +02:00
some refactoring
This commit is contained in:
@@ -37,33 +37,6 @@ BorderedImage::BorderedImage(TexturePtr texture,
|
||||
const Rect& bottomLeft,
|
||||
const Rect& bottomRight,
|
||||
const Rect& center) : Image(texture)
|
||||
{
|
||||
setTexCoords(left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center);
|
||||
}
|
||||
|
||||
BorderedImage::BorderedImage(const std::string& texture,
|
||||
const Rect& left,
|
||||
const Rect& right,
|
||||
const Rect& top,
|
||||
const Rect& bottom,
|
||||
const Rect& topLeft,
|
||||
const Rect& topRight,
|
||||
const Rect& bottomLeft,
|
||||
const Rect& bottomRight,
|
||||
const Rect& center) : Image(texture)
|
||||
{
|
||||
setTexCoords(left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center);
|
||||
}
|
||||
|
||||
void BorderedImage::setTexCoords(const Rect& left,
|
||||
const Rect& right,
|
||||
const Rect& top,
|
||||
const Rect& bottom,
|
||||
const Rect& topLeft,
|
||||
const Rect& topRight,
|
||||
const Rect& bottomLeft,
|
||||
const Rect& bottomRight,
|
||||
const Rect& center)
|
||||
{
|
||||
m_leftBorderTexCoords = left;
|
||||
m_rightBorderTexCoords = right;
|
||||
@@ -86,6 +59,73 @@ void BorderedImage::setTexCoords(const Rect& left,
|
||||
center.height());
|
||||
}
|
||||
|
||||
BorderedImagePtr BorderedImage::loadFromOTMLNode(OTMLNode* node, TexturePtr defaultTexture)
|
||||
{
|
||||
Rect leftBorder;
|
||||
Rect rightBorder;
|
||||
Rect topBorder;
|
||||
Rect bottomBorder;
|
||||
Rect topLeftCorner;
|
||||
Rect topRightCorner;
|
||||
Rect bottomLeftCorner;
|
||||
Rect bottomRightCorner;
|
||||
Rect center;
|
||||
Rect subRect;
|
||||
int top, bottom, left, right, border;
|
||||
Size size;
|
||||
Point offset;
|
||||
|
||||
TexturePtr texture;
|
||||
std::string textureSource = node->readAt("source", std::string());
|
||||
if(!textureSource.empty())
|
||||
texture = g_textures.get(textureSource);
|
||||
else
|
||||
texture = defaultTexture;
|
||||
|
||||
if(!texture)
|
||||
return BorderedImagePtr();
|
||||
|
||||
size = texture->getSize();
|
||||
size = node->readAt("size", size);
|
||||
offset = node->readAt("offset", offset);
|
||||
subRect = Rect(offset, size);
|
||||
border = node->readAt("border", 0);
|
||||
top = bottom = left = right = border;
|
||||
top = node->readAt("top", top);
|
||||
bottom = node->readAt("bottom", bottom);
|
||||
left = node->readAt("left", left);
|
||||
right = node->readAt("right", right);
|
||||
leftBorder = Rect(subRect.left(), subRect.top() + top, left, subRect.height() - top - bottom);
|
||||
rightBorder = Rect(subRect.right() - right, subRect.top() + top, right, subRect.height() - top - bottom);
|
||||
topBorder = Rect(subRect.left() + left, subRect.top(), subRect.width() - right - left, top);
|
||||
bottomBorder = Rect(subRect.left() + left, subRect.bottom() - bottom, subRect.width() - right - left, bottom);
|
||||
topLeftCorner = Rect(subRect.left(), subRect.top(), left, top);
|
||||
topRightCorner = Rect(subRect.right() - right, subRect.top(), right, top);
|
||||
bottomLeftCorner = Rect(subRect.left(), subRect.bottom() - bottom, left, bottom);
|
||||
bottomRightCorner = Rect(subRect.right() - right, subRect.bottom() - bottom, right, bottom);
|
||||
center = Rect(subRect.left() + left, subRect.top() + top, subRect.width() - right - left, subRect.height() - top - bottom);
|
||||
leftBorder = node->readAt("left border", leftBorder);
|
||||
rightBorder = node->readAt("right border", rightBorder);
|
||||
topBorder = node->readAt("top border", topBorder);
|
||||
bottomBorder = node->readAt("bottom border", bottomBorder);
|
||||
topLeftCorner = node->readAt("top left corner", topLeftCorner);
|
||||
topRightCorner = node->readAt("top right corner", topRightCorner);
|
||||
bottomLeftCorner = node->readAt("bottom left corner", bottomLeftCorner);
|
||||
bottomRightCorner = node->readAt("bottom right corner", bottomRightCorner);
|
||||
center = node->readAt("center", center);
|
||||
|
||||
return BorderedImagePtr(new BorderedImage(texture,
|
||||
leftBorder,
|
||||
rightBorder,
|
||||
topBorder,
|
||||
bottomBorder,
|
||||
topLeftCorner,
|
||||
topRightCorner,
|
||||
bottomLeftCorner,
|
||||
bottomRightCorner,
|
||||
center));
|
||||
}
|
||||
|
||||
void BorderedImage::draw(const Rect& screenCoords)
|
||||
{
|
||||
Rect rectCoords;
|
||||
|
@@ -28,6 +28,10 @@
|
||||
#include <global.h>
|
||||
#include <graphics/image.h>
|
||||
#include <graphics/texture.h>
|
||||
#include <otml/otmlnode.h>
|
||||
|
||||
class BorderedImage;
|
||||
typedef boost::shared_ptr<BorderedImage> BorderedImagePtr;
|
||||
|
||||
class BorderedImage : public Image
|
||||
{
|
||||
@@ -43,31 +47,12 @@ public:
|
||||
const Rect& bottomRight,
|
||||
const Rect& center);
|
||||
|
||||
BorderedImage(const std::string& texture,
|
||||
const Rect& left,
|
||||
const Rect& right,
|
||||
const Rect& top,
|
||||
const Rect& bottom,
|
||||
const Rect& topLeft,
|
||||
const Rect& topRight,
|
||||
const Rect& bottomLeft,
|
||||
const Rect& bottomRight,
|
||||
const Rect& center);
|
||||
|
||||
void setTexCoords(const Rect& left,
|
||||
const Rect& right,
|
||||
const Rect& top,
|
||||
const Rect& bottom,
|
||||
const Rect& topLeft,
|
||||
const Rect& topRight,
|
||||
const Rect& bottomLeft,
|
||||
const Rect& bottomRight,
|
||||
const Rect& center);
|
||||
|
||||
void draw(const Rect& screenCoords);
|
||||
|
||||
Size getDefaultSize() const { return m_defaultSize; }
|
||||
|
||||
static BorderedImagePtr loadFromOTMLNode(OTMLNode *node, TexturePtr defaultTexture = TexturePtr());
|
||||
|
||||
private:
|
||||
Rect m_leftBorderTexCoords;
|
||||
Rect m_rightBorderTexCoords;
|
||||
@@ -85,6 +70,4 @@ private:
|
||||
Size m_defaultSize;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<BorderedImage> BorderedImagePtr;
|
||||
|
||||
#endif // BORDEREDIMAGE_H
|
||||
|
@@ -101,7 +101,7 @@ bool Font::load(const std::string& file)
|
||||
calculateGlyphsWidthsAutomatically(glyphSize);
|
||||
|
||||
// read custom widths
|
||||
if(doc->hasNode("glyph widths")) {
|
||||
if(doc->hasChild("glyph widths")) {
|
||||
std::map<int, int> glyphWidths;
|
||||
doc->readAt("glyph widths", &glyphWidths);
|
||||
foreach(const auto& pair, glyphWidths)
|
||||
|
@@ -37,9 +37,9 @@ void Fonts::init()
|
||||
// load all fonts
|
||||
std::list<std::string> files = g_resources.listDirectoryFiles();
|
||||
foreach(const std::string& file, files) {
|
||||
if(boost::ends_with(file, ".yml")) {
|
||||
if(boost::ends_with(file, ".otml")) {
|
||||
std::string name = file;
|
||||
boost::erase_first(name, ".yml");
|
||||
boost::erase_first(name, ".otml");
|
||||
FontPtr font(new Font(name));
|
||||
if(font->load(file))
|
||||
m_fonts.push_back(font);
|
||||
|
Reference in New Issue
Block a user