-// $Id: surface.h 2175 2004-11-24 19:02:49Z sik0fewl $
-//
// SuperTux
-// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// 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
-// 02111-1307, USA.
-#ifndef SUPERTUX_TEXTURE_H
-#define SUPERTUX_TEXTURE_H
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include <string>
-#include <list>
+#ifndef HEADER_SUPERTUX_VIDEO_SURFACE_HPP
+#define HEADER_SUPERTUX_VIDEO_SURFACE_HPP
-#include <SDL.h>
-#include <GL/gl.h>
+#include <string>
+#include <memory>
#include "math/vector.hpp"
-#include "video/screen.hpp"
-
-void apply_filter_to_surface(SDL_Surface *surface, int filter, int value);
-SDL_Surface* sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf);
-SDL_Surface* sdl_surface_from_nothing();
+#include "math/rect.hpp"
+#include "video/surface_ptr.hpp"
+#include "video/texture_ptr.hpp"
-class SurfaceImpl;
-class SurfaceOpenGL;
-class DrawingContext;
-
-/// bitset for drawing effects
-enum {
- /** Don't apply anything */
- NONE_EFFECT = 0x0000,
- /** Draw the Surface upside down */
- VERTICAL_FLIP = 0x0001,
- /** Draw the Surface from left to down */
- HORIZONTAL_FLIP = 0x0002,
- /** Draw the Surface with alpha equal to 128 */
- SEMI_TRANSPARENT = 0x0004
-};
-
-/// types of filters
-enum {
- HORIZONTAL_FLIP_FILTER,
- MASK_FILTER,
- NONE_FILTER
-};
+class SurfaceData;
-/** This class holds all the data necessary to construct a surface */
-class SurfaceData
+/** 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
{
public:
- enum ConstructorType { LOAD, LOAD_PART, SURFACE, GRADIENT };
- ConstructorType type;
- SDL_Surface* surface;
- std::string file;
-
- struct Filter { int type; Color color; };
- std::vector<Filter> applied_filters;
-
- bool use_alpha;
- int x;
- int y;
- int w;
- int h;
- Color top_gradient;
- Color bottom_gradient;
-
- SurfaceData(SDL_Surface* surf, bool use_alpha_);
- SurfaceData(const std::string& file_, bool use_alpha_);
- SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_);
- SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_);
- ~SurfaceData();
-
- SurfaceOpenGL* create_SurfaceOpenGL();
- SurfaceImpl* create();
-};
+ static SurfacePtr create(const std::string& file);
+ static SurfacePtr create(const std::string& file, const Rect& rect);
+private:
+ TexturePtr texture;
+ SurfaceData* surface_data;
+ Rect rect;
+ bool flipx;
+
+private:
+ Surface(const std::string& file);
+ Surface(const std::string& file, const Rect& rect);
+ Surface(const Surface&);
-/** Container class that holds a surface, necessary so that we can
- * switch Surface implementations (OpenGL, SDL) on the fly
- */
-class Surface
-{
-public:
- SurfaceImpl* impl;
- SurfaceData data;
- int w;
- int h;
-
- typedef std::list<Surface*> Surfaces;
- static Surfaces surfaces;
public:
- static void reload_all();
- static void debug_check();
-
- Surface(SDL_Surface* surf, bool use_alpha);
- Surface(const std::string& file, bool use_alpha);
- Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha);
- Surface(Color top_gradient, Color bottom_gradient, int w_, int h_);
~Surface();
-
- /** Reload the surface, which is necesarry in case of a mode swich */
- void reload();
-
- void apply_filter(int filter, Color color = Color(0,0,0));
-};
-/** Surface implementation, all implementation have to inherit from
- this class */
-class SurfaceImpl
-{
-protected:
- SDL_Surface* sdl_surface;
-
-public:
- int w;
- int h;
-
-public:
- SurfaceImpl();
- virtual ~SurfaceImpl();
-
- /** Return 0 on success, -2 if surface needs to be reloaded */
- virtual int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0;
- virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0;
- virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT) = 0;
-
-
- SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function
-
- virtual void apply_filter(int filter, Color color = Color(0,0,0)) = 0;
-};
+ SurfacePtr clone() const;
+
+ /** flip the surface horizontally */
+ void hflip();
+ bool get_flipx() const;
+
+ TexturePtr get_texture() const;
+ SurfaceData* get_surface_data() const;
+ int get_x() const;
+ int get_y() const;
+ int get_width() const;
+ int get_height() const;
+ Vector get_position() const;
+
+ /** returns a vector containing width and height */
+ Vector get_size() const;
-class SurfaceOpenGL : public SurfaceImpl
-{
-public:
- GLuint gl_texture;
-
-public:
- SurfaceOpenGL(SDL_Surface* surf);
- SurfaceOpenGL(const std::string& file);
- SurfaceOpenGL(const std::string& file, int x, int y, int w, int h);
- SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h);
-
- virtual ~SurfaceOpenGL();
-
- int draw(float x, float y, Uint8 alpha, Uint32 effect = NONE_EFFECT);
- int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect = NONE_EFFECT);
- int draw_stretched(float x, float y, int w, int h, Uint8 alpha, Uint32 effect = NONE_EFFECT);
-
- void apply_filter(int filter, Color color);
-
private:
- void create_gl(SDL_Surface * surf, GLuint * tex);
+ Surface& operator=(const Surface&);
};
#endif
+
+/* EOF */