X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvideo%2Fsurface.hpp;h=d90494bfd4576de151cac46f28880a3eec39e1b2;hb=472d0ad804844d28811c86f03da74b6d6be53f1b;hp=d7021815d20642e2116e5811d42c6152f33df339;hpb=31ddd3003af65d55f51044a8bf82f6ce999f86f5;p=supertux.git diff --git a/src/video/surface.hpp b/src/video/surface.hpp index d7021815d..d90494bfd 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -20,22 +20,13 @@ #ifndef __SURFACE_HPP__ #define __SURFACE_HPP__ +#include + #include +#include #include "math/vector.hpp" - -class Color; -class Blend; -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 "texture.hpp" +#include "video_systems.hpp" /** * A rectangular image. @@ -45,50 +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, float angle, const Color& color, const Blend& blend, DrawingEffect effect) const; - 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(); + void hflip() + { + flipx = !flipx; + } + + 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; + } + + Texture *get_texture() const + { + return texture; + } + + void *get_surface_data() const + { + return surface_data; + } - const Surface& operator= (const Surface& other); + int get_x() const + { + return x; + } - float get_width() const + int get_y() const { - return width; + return y; } - float get_height() const + int get_width() const { - return height; + 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