From 99da2acd014bab8e2aa4c1a5d8cc0e955006846f Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sat, 13 Oct 2012 12:54:09 +0200 Subject: [PATCH] Allowed Sprite size to be optionally set in code (for Cover). --- source/abstract/Physical.cpp | 6 ++++-- source/abstract/Physical.h | 2 +- source/abstract/Sprite.cpp | 4 ++-- source/abstract/Sprite.h | 2 +- source/sprite/Cover.cpp | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/abstract/Physical.cpp b/source/abstract/Physical.cpp index 4039ed0..61478c8 100755 --- a/source/abstract/Physical.cpp +++ b/source/abstract/Physical.cpp @@ -18,9 +18,11 @@ const String Physical::KEY_SIZE = "size"; * * @param data Data needed for construction. */ -Physical::Physical(const PhysicalData& data, const Yaml& config) : +Physical::Physical(const PhysicalData& data, const Yaml& config, const Vector2i& pSize) : mDelete(false) { - Vector2i size = config.get(KEY_SIZE); + Vector2i size = (pSize == Vector2i()) + ? config.get(KEY_SIZE) + : pSize; assert(size != Vector2i()); b2BodyDef bodyDef; diff --git a/source/abstract/Physical.h b/source/abstract/Physical.h index c4c2dcd..5055a8c 100755 --- a/source/abstract/Physical.h +++ b/source/abstract/Physical.h @@ -73,7 +73,7 @@ public: // Public functions. public: - Physical(const PhysicalData& data, const Yaml& config); + Physical(const PhysicalData& data, const Yaml& config, const Vector2i& pSize = Vector2i()); virtual ~Physical() = 0; Vector2f getPosition() const; diff --git a/source/abstract/Sprite.cpp b/source/abstract/Sprite.cpp index 3366ed3..27927e1 100644 --- a/source/abstract/Sprite.cpp +++ b/source/abstract/Sprite.cpp @@ -17,8 +17,8 @@ const String Sprite::KEY_TEXTURE = "texture"; * * @param texturePath Relative path to the texture file in the resource folder. */ -Sprite::Sprite(const Yaml& config, const PhysicalData& data) : - Physical(data, config), +Sprite::Sprite(const Yaml& config, const PhysicalData& data, const Vector2i& size) : + Physical(data, config, size), mTexture(ResourceManager::i().acquire(Loader::i() .fromFile(config.get(KEY_TEXTURE)))), mSize(Vector2i(getSize())) { diff --git a/source/abstract/Sprite.h b/source/abstract/Sprite.h index b7bdd7e..531731d 100644 --- a/source/abstract/Sprite.h +++ b/source/abstract/Sprite.h @@ -28,7 +28,7 @@ class Yaml; class Sprite : public sf::Drawable, public Physical { // Public functions. public: - Sprite(const Yaml& config, const PhysicalData& data); + Sprite(const Yaml& config, const PhysicalData& data, const Vector2i& size = Vector2i()); Sprite(const std::shared_ptr& texture, const PhysicalData& data); virtual ~Sprite() = 0; diff --git a/source/sprite/Cover.cpp b/source/sprite/Cover.cpp index bd08f1b..9257b76 100755 --- a/source/sprite/Cover.cpp +++ b/source/sprite/Cover.cpp @@ -8,6 +8,6 @@ #include "Cover.h" Cover::Cover(const Vector2f& position, const Vector2i& size, b2World& world, const Yaml& config) : - Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false)) { + Sprite(config, PhysicalData(position, world, CATEGORY_WORLD, MASK_ALL, false), size) { }