Replaced .reset(new Surface()) with a factory method
[supertux.git] / src / video / surface.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_VIDEO_SURFACE_HPP
18 #define HEADER_SUPERTUX_VIDEO_SURFACE_HPP
19
20 #include <string>
21 #include <memory>
22
23 #include "math/vector.hpp"
24
25 class Texture;
26
27 /**
28  * A rectangular image.
29  * The class basically holds a reference to a texture with additional UV
30  * coordinates that specify a rectangular area on this texture
31  */
32 class Surface
33 {
34 public:
35   static std::auto_ptr<Surface> create(const std::string& file);
36   static std::auto_ptr<Surface> create(const std::string& file, int x, int y, int w, int h);
37   static std::auto_ptr<Surface> create(const Surface& other);
38
39 private:
40   Texture* texture;
41   void *surface_data;
42   int x;
43   int y;
44   int w;
45   int h;
46   bool flipx;
47
48 public:
49   Surface(const std::string& file);
50   Surface(const std::string& file, int x, int y, int w, int h);
51   Surface(const Surface& other);
52   ~Surface();
53
54   const Surface& operator= (const Surface& other);
55
56   /** flip the surface horizontally */
57   void hflip();
58   bool get_flipx() const;
59
60   Texture *get_texture() const;
61   void *get_surface_data() const;
62   int get_x() const;
63   int get_y() const;
64   int get_width() const;
65   int get_height() const;
66   Vector get_position() const;
67   /**
68    * returns a vector containing width and height
69    */
70   Vector get_size() const;
71 };
72
73 #endif
74
75 /* EOF */