hx3d  1
2D/3D Simple Game Framework
image.hpp
1 /*
2  32-bit image.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_GRAPHICS_IMAGE
22 #define HX3D_GRAPHICS_IMAGE
23 
24 #include "hx3d/graphics/color.hpp"
25 
26 #include "hx3d/utils/ptr.hpp"
27 
28 namespace hx3d {
29 namespace graphics {
30 
31 class Texture;
32 
36 class Image {
37 public:
38 
43  Image();
44 
51  Image(unsigned int width, unsigned int height);
52  ~Image();
53 
60  void create(unsigned int width, unsigned int height);
61 
69  void set(unsigned int x, unsigned int y, Color color);
70 
80  void setRect(unsigned int x, unsigned int y, unsigned int w, unsigned int h, Color color);
81 
90  Color get(unsigned int x, unsigned int y);
91 
98 
104  unsigned int getWidth();
105 
111  unsigned int getHeight();
112 
116  void buildTexture();
117 
126  void updateTextureZone(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
127 
128  friend class Texture;
129 
130 private:
132  unsigned int _width;
134  unsigned int _height;
136  unsigned char* _buffer;
137 
139  Ptr<Texture> _texture;
140 };
141 
142 } /* graphics */
143 } /* hx3d */
144 
145 #endif
void setRect(unsigned int x, unsigned int y, unsigned int w, unsigned int h, Color color)
Set a rectangle with a color.
Definition: image.cpp:52
Four [0..255] components defined color.
Definition: color.hpp:32
unsigned int getHeight()
Get the image height.
Definition: image.cpp:112
void buildTexture()
Recreate a texture from the image.
Definition: image.cpp:81
hx3d framework namespace
Definition: audio.hpp:26
void updateTextureZone(unsigned int x, unsigned int y, unsigned int w, unsigned int h)
Update an existing texture zone.
Definition: image.cpp:85
unsigned int getWidth()
Get the image width.
Definition: image.cpp:108
Ptr< Texture > getTexture()
Get the texture.
Definition: image.cpp:74
Real-time editable texture.
Definition: image.hpp:36
void create(unsigned int width, unsigned int height)
Initialize an image.
Definition: image.cpp:37
2D/3D texture management.
Definition: texture.hpp:39
Image()
Construct an empty image. Use create to create the image.
Definition: image.cpp:29
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34