Removed trailing whitespace from all *.?pp files
[supertux.git] / src / video / surface.cpp
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 #include "video/surface.hpp"
18
19 #include <config.h>
20
21 #include <SDL.h>
22
23 #include "video/texture.hpp"
24 #include "video/video_systems.hpp"
25
26 SurfacePtr
27 Surface::create(const std::string& file)
28 {
29   return SurfacePtr(new Surface(file));
30 }
31
32 SurfacePtr
33 Surface::create(const std::string& file, const Rect& rect)
34 {
35   return SurfacePtr(new Surface(file, rect));
36 }
37
38 Surface::Surface(const std::string& file) :
39   texture(texture_manager->get(file)),
40   surface_data(),
41   rect(0, 0,
42       Size(texture->get_image_width(),
43            texture->get_image_height())),
44   flipx(false)
45 {
46   surface_data = VideoSystem::new_surface_data(*this);
47 }
48
49 Surface::Surface(const std::string& file, const Rect& rect_) :
50   texture(texture_manager->get(file, rect_)),
51   surface_data(),
52   rect(0, 0, Size(rect_.get_width(), rect_.get_height())),
53   flipx(false)
54 {
55   surface_data = VideoSystem::new_surface_data(*this);
56 }
57
58 Surface::Surface(const Surface& rhs) :
59   texture(rhs.texture),
60   surface_data(),
61   rect(rhs.rect),
62   flipx(false)
63 {
64   surface_data = VideoSystem::new_surface_data(*this);
65 }
66
67 Surface::~Surface()
68 {
69   VideoSystem::free_surface_data(surface_data);
70 }
71
72 SurfacePtr
73 Surface::clone() const
74 {
75   SurfacePtr surface(new Surface(*this));
76   return surface;
77 }
78
79 /** flip the surface horizontally */
80 void Surface::hflip()
81 {
82   flipx = !flipx;
83 }
84
85 bool Surface::get_flipx() const
86 {
87   return flipx;
88 }
89
90 TexturePtr
91 Surface::get_texture() const
92 {
93   return texture;
94 }
95
96 SurfaceData*
97 Surface::get_surface_data() const
98 {
99   return surface_data;
100 }
101
102 int
103 Surface::get_x() const
104 {
105   return rect.left;
106 }
107
108 int
109 Surface::get_y() const
110 {
111   return rect.top;
112 }
113
114 int
115 Surface::get_width() const
116 {
117   return rect.get_width();
118 }
119
120 int
121 Surface::get_height() const
122 {
123   return rect.get_height();
124 }
125
126 Vector
127 Surface::get_position() const
128 {
129   return Vector(get_x(), get_y());
130 }
131
132 Vector
133 Surface::get_size() const
134 {
135   return Vector(get_width(), get_height());
136 }
137
138 /* EOF */