X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvideo%2Fsurface.hpp;h=d90494bfd4576de151cac46f28880a3eec39e1b2;hb=472d0ad804844d28811c86f03da74b6d6be53f1b;hp=a5ba955582a1b3fcc303dda9104e4fa221336bfc;hpb=86181b0a14d89cf45daf97199c3556c4dd1ee7b7;p=supertux.git diff --git a/src/video/surface.hpp b/src/video/surface.hpp index a5ba95558..d90494bfd 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -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,66 +20,128 @@ #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" /** - * Container class that holds a surface, necessary so that we can - * reload Surface implementations on the fly + * A rectangular image. + * The class basically holds a reference to a texture with additional UV + * coordinates that specify a rectangular area on this texture */ 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(); - - /** Reload the surface, which is necesarry in case of a mode swich */ - void reload(); + void hflip() + { + flipx = !flipx; + } - const Surface& operator= (const Surface& other); + bool get_flipx() const + { + return flipx; + } + + const Surface& operator= (const Surface& other) + { + other.texture->ref(); + texture->unref(); + texture = other.texture; + x = other.x; + y = other.y; + w = other.w; + h = other.h; + return *this; + } - float get_width() const + Texture *get_texture() const { - return width; + return texture; } - float get_height() const + void *get_surface_data() const { - return height; + 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