Fix another round of squirrel coverity issues
[supertux.git] / src / video / surface.cpp
index 6c55ab1..2214293 100644 (file)
 #include <SDL.h>
 
 #include "video/texture.hpp"
-#include "video/video_systems.hpp"
+#include "video/video_system.hpp"
 
-std::auto_ptr<Surface>
+SurfacePtr
 Surface::create(const std::string& file)
 {
-  return std::auto_ptr<Surface>(new Surface(file));
+  return SurfacePtr(new Surface(file));
 }
 
-std::auto_ptr<Surface> 
-Surface::create(const std::string& file, int x, int y, int w, int h)
+SurfacePtr
+Surface::create(const std::string& file, const Rect& rect)
 {
-  return std::auto_ptr<Surface>(new Surface(file, x, y, w, h));
-}
-
-std::auto_ptr<Surface> 
-Surface::create(const Surface& other)
-{
-  return std::auto_ptr<Surface>(new Surface(other));
+  return SurfacePtr(new Surface(file, rect));
 }
 
 Surface::Surface(const std::string& file) :
-  texture(texture_manager->get(file)),
+  texture(TextureManager::current()->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_data = VideoSystem::current()->new_surface_data(*this);
 }
 
-Surface::Surface(const std::string& file, int x, int y, int w, int h) :
-  texture(texture_manager->get(file)),
+Surface::Surface(const std::string& file, const Rect& rect_) :
+  texture(TextureManager::current()->get(file, rect_)),
   surface_data(),
-  x(x), 
-  y(y),
-  w(w),
-  h(h),
+  rect(0, 0, Size(rect_.get_width(), rect_.get_height())),
   flipx(false)
 {
-  texture->ref();
-  surface_data = new_surface_data(*this);
+  surface_data = VideoSystem::current()->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();
-  surface_data = new_surface_data(*this);
+  surface_data = VideoSystem::current()->new_surface_data(*this);
 }
 
-const Surface& 
-Surface::operator=(const Surface& other)
+Surface::~Surface()
 {
-  other.texture->ref();
-  texture->unref();
-  texture = other.texture;
-  x = other.x;
-  y = other.y;
-  w = other.w;
-  h = other.h;
-  return *this;
+  VideoSystem::current()->free_surface_data(surface_data);
 }
 
-Surface::~Surface()
+SurfacePtr
+Surface::clone() const
 {
-  free_surface_data(surface_data);
-  texture->unref();
+  SurfacePtr surface(new Surface(*this));
+  return surface;
 }
 
 /** flip the surface horizontally */
@@ -112,13 +87,13 @@ bool Surface::get_flipx() const
   return flipx;
 }
 
-Texture
+TexturePtr
 Surface::get_texture() const
 {
   return texture;
 }
 
-void* 
+SurfaceData*
 Surface::get_surface_data() const
 {
   return surface_data;
@@ -127,37 +102,37 @@ 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 
+int
 Surface::get_width() const
 {
-  return w;
+  return rect.get_width();
 }
 
-int 
+int
 Surface::get_height() const
 {
-  return h;
+  return rect.get_height();
 }
 
 Vector
 Surface::get_position() const
 {
-  return Vector(get_x(), get_y()); 
+  return Vector(get_x(), get_y());
 }
 
 Vector
 Surface::get_size() const
 {
-  return Vector(get_width(), get_height()); 
+  return Vector(get_width(), get_height());
 }
 
 /* EOF */