The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
image.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef SDL_IMAGE_HPP_INCLUDED
16 #define SDL_IMAGE_HPP_INCLUDED
17 
18 /**
19  * @file
20  * Contains a wrapper class for the @ref GPU_Image class.
21  */
22 
23 #ifdef SDL_GPU
24 #include "gpu.hpp"
25 #include <string>
26 
27 struct surface;
28 class CVideo;
29 
30 namespace sdl
31 {
32 
33 class timage
34 {
35 public:
36  /**
37  * Creates a texture with the given width and height.
38  *
39  * @param w Width.
40  * @param h Height.
41  */
42  timage(Uint16 w, Uint16 h);
43 
44  /**
45  * Loads a texture from an image file.
46  *
47  * @param file Full path of the file.
48  */
49  timage(const std::string &file);
50 
51  /**
52  * Creates a texture from an SDL surface.
53  *
54  * @param source Pointer to the surface.
55  */
56  timage( SDL_Surface *source);
57 
58  /**
59  * Creates a texture from an SDL surface.
60  *
61  * @param source The surface.
62  */
63  timage(const surface &source);
64 
65  timage();
66 
67  ~timage();
68 
69  timage(const timage &texture);
70 
71  timage &operator=(const timage &texture);
72 
73  /**
74  * Render the texture on a specified target, with respect to the previously
75  * set rotation, coloring etc.
76  *
77  * @param video The target to draw onto.
78  * @param x Where to draw (x coordinate).
79  * @param y Where to draw (y coordinate).
80  */
81  void draw(CVideo &video, const int x, const int y);
82 
83  /**
84  * Rotates the texture by a given angle.
85  *
86  * @param rotation The angle in degrees.
87  */
88  void set_rotation(float rotation);
89 
90  /**
91  * Returns the angle by which the texture is rotated.
92  */
93  float rotation() const;
94 
95  /**
96  * Scales the surface horizontally by a given factor.
97  *
98  * @param factor Scaling ratio.
99  */
100  void set_hscale(float factor);
101 
102  /**
103  * Scales the surface vertically by a given factor.
104  *
105  * @param factor Scaling ratio.
106  */
107  void set_vscale(float factor);
108 
109  /**
110  * Scales the surface by a given factor.
111  *
112  * @param hfactor Horizontal scaling factor.
113  * @param vfactor Vertical scaling factor.
114  */
115  void set_scale(float hfactor, float vfactor);
116 
117  /**
118  * Returns the horizontal scaling factor.
119  */
120  float hscale() const;
121 
122  /**
123  * Returns the vertical scaling factor.
124  */
125  float vscale() const;
126 
127  /**
128  * Tell the renderer which scaling algorithm to use.
129  *
130  * @param use_smooth True to use bilinear scaling.
131  */
132  void set_smooth_scaling(bool use_smooth);
133 
134  /**
135  * Returns true if bilinear scaling is enabled.
136  */
137  bool smooth_scaling() const;
138 
139  /**
140  * Returns the width of the texture after scaling and clipping applied.
141  */
142  int width() const;
143 
144  /**
145  * Returns the height of the texture after scaling and clipping applied.
146  */
147  int height() const;
148 
149  /**
150  * Returns the width of the texture before scaling.
151  */
152  Uint16 base_width() const;
153 
154  /**
155  * Returns the height of the texture before scaling.
156  */
157  Uint16 base_height() const;
158 
159  /**
160  * Set the area of the texture that should be displayed when drawing.
161  * Clipping is performed before drawing. The clip area can be larger than
162  * the texture itself, if this happens, extra pixels will be filled
163  * according the configured wrap mode.
164  *
165  * @param rect The clip area.
166  */
167  void set_clip(const SDL_Rect &rect);
168 
169  /**
170  * Returns the current clip area.
171  */
172  SDL_Rect clip() const;
173 
174  /**
175  * Sets the alpha of the texture.
176  *
177  * @param alpha Alpha value.
178  */
179  void set_alpha(int alpha);
180 
181  /**
182  * Returns the alpha of the texture.
183  */
184  int alpha() const;
185 
186  /**
187  * Set color modulation.
188  *
189  * @param r Red modulation.
190  * @param g Green modulation.
191  * @param b Blue modulation.
192  */
193  void set_color_mod(int r, int g, int b);
194 
195  /**
196  * Returns red modulation.
197  */
198  int red_mod() const;
199 
200  /**
201  * Returns green modulation.
202  */
203  int green_mod() const;
204 
205  /**
206  * Returns blue modulation.
207  */
208  int blue_mod() const;
209 
210  /**
211  * Set horizontal wrap mode.
212  *
213  * @param mode Wrap mode.
214  */
215  void set_hwrap(GPU_WrapEnum mode);
216 
217  /**
218  * Set vertical wrap mode.
219  *
220  * @param mode Wrap mode.
221  */
222  void set_vwrap(GPU_WrapEnum mode);
223 
224  /**
225  * Set wrap mode.
226  *
227  * @param hmode Horizontal wrap mode.
228  * @param vmode Vertical wrap mode.
229  */
230  void set_wrap(GPU_WrapEnum hmode, GPU_WrapEnum vmode);
231 
232  /**
233  * Returns the horizontal wrap policy of the texture.
234  */
235  GPU_WrapEnum hwrap() const;
236 
237  /**
238  * Returns the vertical wrap policy of the texture.
239  */
240  GPU_WrapEnum vwrap( )const;
241 
242  void set_submerge(double val);
243 
244  double submerge() const;
245 
246  void set_effects(int effects);
247 
248  int effects() const;
249 
250  /**
251  * Returns true if the managed texture is nullptr.
252  */
253  bool nullptr() const;
254 
255  timage clone() const;
256 
257  GPU_Image *raw() const;
258 
259 private:
260  /** The texture itself. */
261  GPU_Image *image_;
262 
263  /** How much will it be rotated. */
264  float rotation_;
265 
266  /** How much will it be scaled horizontally. */
267  float hscale_;
268 
269  /** How much will it be scaled vertically. */
270  float vscale_;
271 
272  /** Which part of the texture should be displayed. */
273  GPU_Rect clip_;
274 
275  /** Color mod. */
276  int red_mod_, green_mod_, blue_mod_, alpha_mod_;
277 
278  /** Wrap policy. */
279  GPU_WrapEnum hwrap_, vwrap_;
280 
281  /** Smooth scaling. */
282  bool smooth_;
283 
284  /** Submerge. */
285  double submerge_;
286 
287  /** Shader effects (flip, flop, grayscale). */
288  int effects_;
289 };
290 }
291 #endif
292 
293 #endif
Definition: video.hpp:58
surface image_
The image is cached in this surface.
Definition: canvas.cpp:961
GLuint const GLfloat * val
Definition: glew.h:2614
GLenum GLenum GLuint texture
Definition: glew.h:3453
GLboolean GLboolean g
Definition: glew.h:7319
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
GLenum mode
Definition: glew.h:2390
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1488
void draw(surface screen)
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
GPU_WrapEnum
Definition: SDL_gpu.h:143
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
GLsizei const GLcharARB ** string
Definition: glew.h:4503
GLsizei GLsizei GLchar * source
Definition: glew.h:1800