00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "video/surface.hpp"
00018
00019 #include <config.h>
00020
00021 #include <SDL.h>
00022
00023 #include "video/texture.hpp"
00024 #include "video/video_systems.hpp"
00025
00026 SurfacePtr
00027 Surface::create(const std::string& file)
00028 {
00029 return SurfacePtr(new Surface(file));
00030 }
00031
00032 SurfacePtr
00033 Surface::create(const std::string& file, const Rect& rect)
00034 {
00035 return SurfacePtr(new Surface(file, rect));
00036 }
00037
00038 Surface::Surface(const std::string& file) :
00039 texture(texture_manager->get(file)),
00040 surface_data(),
00041 rect(0, 0,
00042 Size(texture->get_image_width(),
00043 texture->get_image_height())),
00044 flipx(false)
00045 {
00046 surface_data = VideoSystem::new_surface_data(*this);
00047 }
00048
00049 Surface::Surface(const std::string& file, const Rect& rect_) :
00050 texture(texture_manager->get(file, rect_)),
00051 surface_data(),
00052 rect(0, 0, Size(rect_.get_width(), rect_.get_height())),
00053 flipx(false)
00054 {
00055 surface_data = VideoSystem::new_surface_data(*this);
00056 }
00057
00058 Surface::Surface(const Surface& rhs) :
00059 texture(rhs.texture),
00060 surface_data(),
00061 rect(rhs.rect),
00062 flipx(false)
00063 {
00064 surface_data = VideoSystem::new_surface_data(*this);
00065 }
00066
00067 Surface::~Surface()
00068 {
00069 VideoSystem::free_surface_data(surface_data);
00070 }
00071
00072 SurfacePtr
00073 Surface::clone() const
00074 {
00075 SurfacePtr surface(new Surface(*this));
00076 return surface;
00077 }
00078
00080 void Surface::hflip()
00081 {
00082 flipx = !flipx;
00083 }
00084
00085 bool Surface::get_flipx() const
00086 {
00087 return flipx;
00088 }
00089
00090 TexturePtr
00091 Surface::get_texture() const
00092 {
00093 return texture;
00094 }
00095
00096 SurfaceData*
00097 Surface::get_surface_data() const
00098 {
00099 return surface_data;
00100 }
00101
00102 int
00103 Surface::get_x() const
00104 {
00105 return rect.left;
00106 }
00107
00108 int
00109 Surface::get_y() const
00110 {
00111 return rect.top;
00112 }
00113
00114 int
00115 Surface::get_width() const
00116 {
00117 return rect.get_width();
00118 }
00119
00120 int
00121 Surface::get_height() const
00122 {
00123 return rect.get_height();
00124 }
00125
00126 Vector
00127 Surface::get_position() const
00128 {
00129 return Vector(get_x(), get_y());
00130 }
00131
00132 Vector
00133 Surface::get_size() const
00134 {
00135 return Vector(get_width(), get_height());
00136 }
00137
00138