// $Id$
-//
+//
// SuperTux
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// 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
#ifndef __SURFACE_HPP__
#define __SURFACE_HPP__
-#include <string>
+#include <config.h>
-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 <string>
+#include <SDL.h>
+#include "math/vector.hpp"
+#include "texture.hpp"
+#include "video_systems.hpp"
/**
* A rectangular image.
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