Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef IMAGE_MODIFICATIONS_HPP_INCLUDED
00019 #define IMAGE_MODIFICATIONS_HPP_INCLUDED
00020
00021 #include "sdl_utils.hpp"
00022 #include <queue>
00023
00024 namespace image {
00025
00026 class modification;
00027 struct mod_ptr_comparator_;
00028
00029 typedef std::priority_queue<modification*,
00030 std::vector<modification*>,
00031 mod_ptr_comparator_> modification_queue;
00032
00033
00034 class modification
00035 {
00036 public:
00037
00038
00039 struct texception
00040 : public tlua_jailbreak_exception
00041 {
00042
00043
00044
00045
00046
00047
00048
00049
00050 texception(const std::stringstream& message_stream);
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 texception(const std::string& message);
00061
00062 ~texception() throw() {}
00063
00064
00065 const std::string message;
00066
00067 private:
00068
00069 IMPLEMENT_LUA_JAILBREAK_EXCEPTION(texception)
00070 };
00071
00072
00073 static modification_queue decode(const std::string&);
00074
00075 virtual ~modification() {}
00076
00077
00078 virtual surface operator()(const surface& src) const = 0;
00079
00080
00081 virtual int priority() const { return 0; }
00082 };
00083
00084
00085 struct mod_ptr_comparator_
00086 {
00087
00088 bool operator()(const modification* a, const modification* b) const;
00089 };
00090
00091
00092
00093
00094
00095
00096
00097 class rc_modification : public modification
00098 {
00099 public:
00100
00101
00102
00103 rc_modification()
00104 : rc_map_()
00105 {}
00106
00107
00108
00109
00110 rc_modification(const std::map<Uint32, Uint32>& recolor_map)
00111 : rc_map_(recolor_map)
00112 {}
00113 virtual surface operator()(const surface& src) const;
00114
00115
00116 virtual int priority() const { return 1; }
00117
00118 bool no_op() const { return rc_map_.empty(); }
00119
00120 const std::map<Uint32, Uint32>& map() const { return rc_map_;}
00121 std::map<Uint32, Uint32>& map() { return rc_map_;}
00122
00123 private:
00124 std::map<Uint32, Uint32> rc_map_;
00125 };
00126
00127
00128
00129
00130 class fl_modification : public modification
00131 {
00132 public:
00133
00134
00135
00136
00137
00138 fl_modification(bool horiz = false, bool vert = false)
00139 : horiz_(horiz)
00140 , vert_(vert)
00141 {}
00142 virtual surface operator()(const surface& src) const;
00143
00144 void set_horiz(bool val) { horiz_ = val; }
00145 void set_vert(bool val) { vert_ = val; }
00146 bool get_horiz() const { return horiz_; }
00147 bool get_vert() const { return vert_; }
00148
00149
00150 bool toggle_horiz() { return((horiz_ = !horiz_)); }
00151
00152
00153 bool toggle_vert() { return((vert_ = !vert_)); }
00154
00155 bool no_op() const { return ((!horiz_) && (!vert_)); }
00156
00157 private:
00158 bool horiz_;
00159 bool vert_;
00160 };
00161
00162
00163
00164
00165 class rotate_modification : public modification
00166 {
00167 public:
00168
00169
00170
00171
00172
00173
00174 rotate_modification(int degrees = 90)
00175 : degrees_(degrees)
00176 {}
00177 virtual surface operator()(const surface& src) const;
00178
00179 bool no_op() const { return degrees_ % 360 == 0; }
00180
00181 private:
00182 int degrees_;
00183 };
00184
00185
00186
00187
00188 class gs_modification : public modification
00189 {
00190 public:
00191 virtual surface operator()(const surface& src) const;
00192 };
00193
00194
00195
00196
00197 class crop_modification : public modification
00198 {
00199 public:
00200 crop_modification(const SDL_Rect& slice)
00201 : slice_(slice)
00202 {}
00203 virtual surface operator()(const surface& src) const;
00204
00205 const SDL_Rect& get_slice() const;
00206
00207 private:
00208 SDL_Rect slice_;
00209 };
00210
00211
00212
00213
00214
00215 class blit_modification : public modification
00216 {
00217 public:
00218 blit_modification(const surface& surf, int x, int y)
00219 : surf_(surf), x_(x), y_(y)
00220 {}
00221 virtual surface operator()(const surface& src) const;
00222
00223 const surface& get_surface() const;
00224 int get_x() const;
00225 int get_y() const;
00226
00227 private:
00228 surface surf_;
00229 int x_;
00230 int y_;
00231 };
00232
00233
00234
00235
00236
00237 class mask_modification : public modification
00238 {
00239 public:
00240 mask_modification(const surface& mask, int x, int y)
00241 : mask_(mask), x_(x), y_(y)
00242 {}
00243 virtual surface operator()(const surface& src) const;
00244
00245 const surface& get_mask() const;
00246 int get_x() const;
00247 int get_y() const;
00248
00249 private:
00250 surface mask_;
00251 int x_;
00252 int y_;
00253 };
00254
00255
00256
00257
00258
00259 class light_modification : public modification
00260 {
00261 public:
00262 light_modification(const surface& surf)
00263 : surf_(surf)
00264 {}
00265 virtual surface operator()(const surface& src) const;
00266
00267 const surface& get_surface() const;
00268
00269 private:
00270 surface surf_;
00271 };
00272
00273
00274
00275
00276 class scale_modification : public modification
00277 {
00278 public:
00279 scale_modification(int width, int height)
00280 : w_(width), h_(height)
00281 {}
00282 virtual surface operator()(const surface& src) const;
00283 int get_w() const;
00284 int get_h() const;
00285
00286 private:
00287 int w_, h_;
00288 };
00289
00290
00291
00292
00293 class o_modification : public modification
00294 {
00295 public:
00296 o_modification(float opacity)
00297 : opacity_(opacity)
00298 {}
00299 virtual surface operator()(const surface& src) const;
00300 float get_opacity() const;
00301
00302 private:
00303 float opacity_;
00304 };
00305
00306
00307
00308
00309 class cs_modification : public modification
00310 {
00311 public:
00312 cs_modification(int r, int g, int b)
00313 : r_(r), g_(g), b_(b)
00314 {}
00315 virtual surface operator()(const surface& src) const;
00316 int get_r() const;
00317 int get_g() const;
00318 int get_b() const;
00319
00320 private:
00321 int r_, g_, b_;
00322 };
00323
00324
00325
00326
00327 class blend_modification : public modification
00328 {
00329 public:
00330 blend_modification(int r, int g, int b, float a)
00331 : r_(r), g_(g), b_(b), a_(a)
00332 {}
00333 virtual surface operator()(const surface& src) const;
00334 int get_r() const;
00335 int get_g() const;
00336 int get_b() const;
00337 float get_a() const;
00338
00339 private:
00340 int r_, g_, b_;
00341 float a_;
00342 };
00343
00344
00345
00346
00347 class bl_modification : public modification
00348 {
00349 public:
00350 bl_modification(int depth)
00351 : depth_(depth)
00352 {}
00353 virtual surface operator()(const surface& src) const;
00354 int get_depth() const;
00355
00356 private:
00357 int depth_;
00358 };
00359
00360
00361
00362
00363 struct brighten_modification : modification
00364 {
00365 virtual surface operator()(const surface &src) const;
00366 };
00367
00368
00369
00370
00371 struct darken_modification : modification
00372 {
00373 virtual surface operator()(const surface &src) const;
00374 };
00375
00376
00377
00378
00379 struct background_modification : modification
00380 {
00381 background_modification(SDL_Color const &c): color_(c) {}
00382 virtual surface operator()(const surface &src) const;
00383 const SDL_Color& get_color() const;
00384
00385 private:
00386 SDL_Color color_;
00387 };
00388
00389 }
00390
00391 #endif