* Add Airship (regular above-ground theme) and Battle (castle/boss theme) music court...
[supertux.git] / src / video / surface.hpp
index d702181..d90494b 100644 (file)
 #ifndef __SURFACE_HPP__
 #define __SURFACE_HPP__
 
+#include <config.h>
+
 #include <string>
+#include <SDL.h>
 #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