sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
image.h
1#ifndef __IMAGE_H__
2#define __IMAGE_H__
3
4#include "app.h"
5
6namespace sgltk {
7
12class Image {
13 bool free_data;
14 static std::vector<std::string> paths;
15public:
23 EXPORT static void add_path(std::string path);
27 unsigned int width;
31 unsigned int height;
35 unsigned int bytes_per_pixel;
39 void *data;
40
44 SDL_Surface *image;
45
46 EXPORT Image();
50 EXPORT Image(std::string filename);
57 EXPORT Image(unsigned int width,
58 unsigned int height,
59 unsigned int bytes_per_pixel,
60 void *data);
61 EXPORT ~Image();
62
69 EXPORT bool create_empty(unsigned int width,
70 unsigned int height);
71
77 EXPORT bool load(const std::string& filename);
78
88 EXPORT bool load(unsigned int width,
89 unsigned int height,
90 unsigned int bytes_per_pixel,
91 void *data);
92
98 EXPORT bool save(const std::string& filename);
99
100#ifdef HAVE_SDL_TTF_H
108 EXPORT static TTF_Font *open_font_file(const std::string& font_file,
109 unsigned int size);
115 EXPORT static void close_font_file(TTF_Font *font_file);
130 EXPORT bool create_text(const std::string& text,
131 TTF_Font *font,
132 Uint8 r, Uint8 g, Uint8 b, Uint8 a);
144 EXPORT bool create_text(const std::string& text,
145 const std::string& font_file,
146 unsigned int size,
147 Uint8 r, Uint8 g, Uint8 b, Uint8 a);
148#endif //HAVE_SDL_TTF_H
149
156 EXPORT bool copy_from(const Image& src, int x, int y);
162 EXPORT bool copy_from(const Image& src, SDL_Rect& dst_rect);
169 EXPORT bool copy_from(const Image& src, SDL_Rect& dst_rect,
170 const SDL_Rect& src_rect);
171
175 EXPORT void vertical_flip();
176
180 EXPORT void horizontal_flip();
181
189 EXPORT void set_color_key(int r, int g, int b, bool enable = true);
190};
191
192}
193
194#endif
void * data
The pixel data.
Definition image.h:39
bool save(const std::string &filename)
Saves the image as a file.
Definition image.cpp:205
bool copy_from(const Image &src, int x, int y)
Copies an image into the current image.
Definition image.cpp:282
unsigned int height
The width of the image surface.
Definition image.h:31
bool create_empty(unsigned int width, unsigned int height)
Creates an empty image.
Definition image.cpp:56
SDL_Surface * image
The image surface.
Definition image.h:44
void set_color_key(int r, int g, int b, bool enable=true)
Sets a color to be transparent.
Definition image.cpp:370
static void add_path(std::string path)
Adds a path to the list of paths to be searched for image files.
Definition image.cpp:374
void vertical_flip()
Flips the image along its x-axis.
Definition image.cpp:330
bool load(const std::string &filename)
Loads a new image file.
Definition image.cpp:97
void horizontal_flip()
Flips the image along its y-axis.
Definition image.cpp:350
unsigned int bytes_per_pixel
The number of bytes that make up a single pixel.
Definition image.h:35
unsigned int width
The width of the image surface.
Definition image.h:27