4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 #ifndef __SURFACE_HPP__
21 #define __SURFACE_HPP__
27 #include "math/vector.hpp"
28 #include "texture.hpp"
31 * A rectangular image.
32 * The class basically holds a reference to a texture with additional UV
33 * coordinates that specify a rectangular area on this texture
46 Surface(const std::string& file) :
47 texture(texture_manager->get(file)),
48 x(0), y(0), w(0), h(0),
52 w = texture->get_image_width();
53 h = texture->get_image_height();
56 Surface(const std::string& file, int x, int y, int w, int h) :
57 texture(texture_manager->get(file)),
58 x(x), y(y), w(w), h(h),
64 Surface(const Surface& other) :
65 texture(other.texture),
66 x(other.x), y(other.y),
67 w(other.w), h(other.h),
78 /** flip the surface horizontally */
84 bool get_flipx() const
89 const Surface& operator= (const Surface& other)
93 texture = other.texture;
101 Texture *get_texture() const
116 int get_width() const
121 int get_height() const
126 Vector get_position() const
127 { return Vector(get_x(), get_y()); }
130 * returns a vector containing width and height
132 Vector get_size() const
133 { return Vector(get_width(), get_height()); }
135 float get_uv_left() const
137 return (float) (x + (flipx ? w : 0)) / texture->get_texture_width();
140 float get_uv_top() const
142 return (float) y / texture->get_texture_height();
145 float get_uv_right() const
147 return (float) (x + (flipx ? 0 : w)) / texture->get_texture_width();
150 float get_uv_bottom() const
152 return (float) (y + h) / texture->get_texture_height();
155 //void draw_part(float src_x, float src_y, float dst_x, float dst_y,
156 // float width, float height, float alpha,
157 // DrawingEffect effect) const;