From: Ingo Ruhnke Date: Sun, 6 Dec 2009 08:45:57 +0000 (+0000) Subject: Fixed Rect a bit and started to use Rect in Surface class X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=81f5fd86be388e43a0425da0c1408b0e1fe3a39d;p=supertux.git Fixed Rect a bit and started to use Rect in Surface class SVN-Revision: 6182 --- diff --git a/src/math/rect.hpp b/src/math/rect.hpp index 322049539..8e1a50015 100644 --- a/src/math/rect.hpp +++ b/src/math/rect.hpp @@ -23,31 +23,34 @@ class Rect { public: int left; - int right; int top; + int right; int bottom; public: - Rect(int left_, int top_, int right_, int top_) : + Rect() : + left(0), + top(0), + right(0), + bottom(0) + {} + + Rect(int left_, int top_, int right_, int bottom_) : left(left_), top(top_), right(right_), - top(top_) + bottom(bottom_) {} Rect(int left_, int top_, const Size& size) : left(left_), top(top_), right(left_ + size.width), - bottom(bottom_ + size.width) + bottom(top_ + size.height) {} int get_width() const { return right - left; } int get_height() const { return bottom - top; } - -private: - Rect(const Rect&); - Rect& operator=(const Rect&); }; #endif diff --git a/src/supertux/tile.cpp b/src/supertux/tile.cpp index 3a17375d1..936935519 100644 --- a/src/supertux/tile.cpp +++ b/src/supertux/tile.cpp @@ -68,10 +68,10 @@ Tile::load_images() else { surface = new Surface(spec.file, - (int) spec.rect.p1.x, - (int) spec.rect.p1.y, - (int) spec.rect.get_width(), - (int) spec.rect.get_height()); + Rect((int) spec.rect.p1.x, + (int) spec.rect.p1.y, + Size((int) spec.rect.get_width(), + (int) spec.rect.get_height()))); } images.push_back(surface); } diff --git a/src/video/surface.cpp b/src/video/surface.cpp index 0ca60b7ce..926342e7e 100644 --- a/src/video/surface.cpp +++ b/src/video/surface.cpp @@ -30,46 +30,37 @@ Surface::create(const std::string& file) } std::auto_ptr -Surface::create(const std::string& file, int x, int y, int w, int h) +Surface::create(const std::string& file, const Rect& rect) { - return std::auto_ptr(new Surface(file, x, y, w, h)); + return std::auto_ptr(new Surface(file, rect)); } Surface::Surface(const std::string& file) : texture(texture_manager->get(file)), surface_data(), - x(0), - y(0), - w(0), - h(0), + rect(0, 0, + Size(texture->get_image_width(), + texture->get_image_height())), flipx(false) { texture->ref(); - w = texture->get_image_width(); - h = texture->get_image_height(); surface_data = new_surface_data(*this); } -Surface::Surface(const std::string& file, int x, int y, int w, int h) : +Surface::Surface(const std::string& file, const Rect& rect_) : texture(texture_manager->get(file)), surface_data(), - x(x), - y(y), - w(w), - h(h), + rect(rect_), flipx(false) { texture->ref(); surface_data = new_surface_data(*this); } -Surface::Surface(const Surface& other) : - texture(other.texture), +Surface::Surface(const Surface& rhs) : + texture(rhs.texture), surface_data(), - x(other.x), - y(other.y), - w(other.w), - h(other.h), + rect(rhs.rect), flipx(false) { texture->ref(); @@ -77,15 +68,12 @@ Surface::Surface(const Surface& other) : } const Surface& -Surface::operator=(const Surface& other) +Surface::operator=(const Surface& rhs) { - other.texture->ref(); + rhs.texture->ref(); texture->unref(); - texture = other.texture; - x = other.x; - y = other.y; - w = other.w; - h = other.h; + texture = rhs.texture; + rect = rhs.rect; return *this; } @@ -121,25 +109,25 @@ Surface::get_surface_data() const int Surface::get_x() const { - return x; + return rect.left; } int Surface::get_y() const { - return y; + return rect.top; } int Surface::get_width() const { - return w; + return rect.get_width(); } int Surface::get_height() const { - return h; + return rect.get_height(); } Vector diff --git a/src/video/surface.hpp b/src/video/surface.hpp index 894bb6e37..9c84cf830 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -21,6 +21,7 @@ #include #include "math/vector.hpp" +#include "math/rect.hpp" class Texture; @@ -33,20 +34,17 @@ class Surface { public: static std::auto_ptr create(const std::string& file); - static std::auto_ptr create(const std::string& file, int x, int y, int w, int h); + static std::auto_ptr create(const std::string& file, const Rect& rect); private: Texture* texture; void *surface_data; - int x; - int y; - int w; - int h; + Rect rect; bool flipx; public: Surface(const std::string& file); - Surface(const std::string& file, int x, int y, int w, int h); + Surface(const std::string& file, const Rect& rect); Surface(const Surface& other); ~Surface();