X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvideo%2Fsurface.hpp;h=d90494bfd4576de151cac46f28880a3eec39e1b2;hb=75acd4b141f45e851a492f089aa9ad24a9552409;hp=c1de2993ce80d7c6f8a2a799d8e018ac1d004f75;hpb=07ddaed2a657e4d2a3d038fed223fc5827159caf;p=supertux.git diff --git a/src/video/surface.hpp b/src/video/surface.hpp index c1de2993c..d90494bfd 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux // Copyright (C) 2006 Matthias Braun // @@ -12,7 +12,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -20,19 +20,13 @@ #ifndef __SURFACE_HPP__ #define __SURFACE_HPP__ -#include +#include -class ImageTexture; - -/// bitset for drawing effects -enum DrawingEffect { - /** Don't apply anything */ - NO_EFFECT = 0x0000, - /** Draw the Surface upside down */ - VERTICAL_FLIP = 0x0001, - /** Draw the Surface from left to down */ - HORIZONTAL_FLIP = 0x0002, -}; +#include +#include +#include "math/vector.hpp" +#include "texture.hpp" +#include "video_systems.hpp" /** * A rectangular image. @@ -42,42 +36,112 @@ enum DrawingEffect { class Surface { private: - friend class DrawingContext; - friend class Font; - ImageTexture* texture; - - float uv_left; - float uv_top; - float uv_right; - float uv_bottom; - - void draw(float x, float y, float alpha, DrawingEffect effect) const; - void draw_part(float src_x, float src_y, float dst_x, float dst_y, - float width, float height, - float alpha, DrawingEffect effect) const; - - float width; - float height; + Texture* texture; + void *surface_data; + int x; + int y; + int w; + int h; + bool flipx; + public: - Surface(const std::string& file); - Surface(const std::string& file, int x, int y, int w, int h); - Surface(const Surface& other); - ~Surface(); + Surface(const std::string& file) : + texture(texture_manager->get(file)), + x(0), y(0), w(0), h(0), + flipx(false) + { + texture->ref(); + w = texture->get_image_width(); + h = texture->get_image_height(); + surface_data = new_surface_data(*this); + } + + Surface(const std::string& file, int x, int y, int w, int h) : + texture(texture_manager->get(file)), + x(x), y(y), w(w), h(h), + flipx(false) + { + texture->ref(); + surface_data = new_surface_data(*this); + } + + Surface(const Surface& other) : + texture(other.texture), + x(other.x), y(other.y), + w(other.w), h(other.h), + flipx(false) + { + texture->ref(); + surface_data = new_surface_data(*this); + } + + ~Surface() + { + free_surface_data(surface_data); + texture->unref(); + } /** flip the surface horizontally */ - void hflip(); - - const Surface& operator= (const Surface& other); + void hflip() + { + flipx = !flipx; + } - float get_width() const + bool get_flipx() const { - return width; + return flipx; } - float get_height() const + const Surface& operator= (const Surface& other) { - return height; + other.texture->ref(); + texture->unref(); + texture = other.texture; + x = other.x; + y = other.y; + w = other.w; + h = other.h; + return *this; } + + Texture *get_texture() const + { + return texture; + } + + void *get_surface_data() const + { + return surface_data; + } + + int get_x() const + { + return x; + } + + int get_y() const + { + return y; + } + + int get_width() const + { + return w; + } + + int get_height() const + { + return h; + } + + Vector get_position() const + { return Vector(get_x(), get_y()); } + + /** + * returns a vector containing width and height + */ + Vector get_size() const + { return Vector(get_width(), get_height()); } }; #endif