OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ShaderMove.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom 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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OPENXCOM_SHADERMOVE_H
21 #define OPENXCOM_SHADERMOVE_H
22 
23 #include "ShaderDraw.h"
24 
25 namespace OpenXcom
26 {
27 
28 
29 template<typename Pixel>
30 class ShaderMove : public helper::ShaderBase<Pixel>
31 {
32  int _move_x;
33  int _move_y;
34 
35 public:
37  friend struct helper::controler<ShaderMove<Pixel> >;
38 
39  inline ShaderMove(Surface* s):
40  _base(s),
41  _move_x(s->getX()), _move_y(s->getY())
42  {
43 
44  }
45 
46  inline ShaderMove(Surface* s, int move_x, int move_y):
47  _base(s),
48  _move_x(move_x), _move_y(move_y)
49  {
50 
51  }
52 
53  inline ShaderMove(const ShaderMove& f):
54  _base(f),
55  _move_x(f._move_x), _move_y(f._move_y)
56  {
57 
58  }
59 
60  inline ShaderMove(std::vector<Pixel>& f, int max_x, int max_y):
61  _base(f, max_x, max_y),
62  _move_x(), _move_y()
63  {
64 
65  }
66 
67  inline ShaderMove(std::vector<Pixel>& f, int max_x, int max_y, int move_x, int move_y):
68  _base(f, max_x, max_y),
69  _move_x(move_x), _move_y(move_y)
70  {
71 
72  }
73 
74  inline GraphSubset getImage() const
75  {
76  return _base::_range_domain.offset(_move_x, _move_y);
77  }
78 
79  inline void setMove(int x, int y)
80  {
81  _move_x = x;
82  _move_y = y;
83  }
84  inline void addMove(int x, int y)
85  {
86  _move_x += x;
87  _move_y += y;
88  }
89 };
90 
91 
92 
93 namespace helper
94 {
95 
96 template<typename Pixel>
97 struct controler<ShaderMove<Pixel> > : public controler_base<typename ShaderMove<Pixel>::PixelPtr, typename ShaderMove<Pixel>::PixelRef>
98 {
99  typedef typename ShaderMove<Pixel>::PixelPtr PixelPtr;
100  typedef typename ShaderMove<Pixel>::PixelRef PixelRef;
101 
103 
104  controler(const ShaderMove<Pixel>& f) : base_type(f.ptr(), f.getDomain(), f.getImage(), std::make_pair(1, f.pitch()))
105  {
106 
107  }
108 
109 };
110 
111 }//namespace helper
112 
119 {
120  return ShaderMove<Uint8>(s);
121 }
122 
130 inline ShaderMove<Uint8> ShaderSurface(Surface* s, int x, int y)
131 {
132  return ShaderMove<Uint8>(s, x, y);
133 }
134 
142 inline ShaderMove<Uint8> ShaderCrop(Surface* s, int x, int y)
143 {
144  ShaderMove<Uint8> ret(s, x, y);
145  SDL_Rect* s_crop = s->getCrop();
146  if(s_crop->w && s_crop->h)
147  {
148  GraphSubset crop(std::make_pair(s_crop->x, s_crop->x + s_crop->w), std::make_pair(s_crop->y, s_crop->y + s_crop->h));
149  ret.setDomain(crop);
150  ret.addMove(-s_crop->x, -s_crop->y);
151  }
152  return ret;
153 }
154 
161 {
162  return ShaderCrop(s, s->getX(), s->getY());
163 }
164 
165 }//namespace OpenXcom
166 
167 #endif /* OPENXCOM_SHADERMOVE_H */
168 
Definition: ShaderMove.h:30
helper class for handling implementation differences in different surfaces types Used in function Sha...
Definition: ShaderDrawHelper.h:419
ShaderMove< Uint8 > ShaderSurface(Surface *s)
Create warper from Surface.
Definition: ShaderMove.h:118
int getY() const
Returns the position of the surface in the Y axis.
Definition: Surface.h:121
SDL_Rect * getCrop()
Gets the cropping rectangle for the surface.
Definition: Surface.cpp:685
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
Definition: GraphSubset.h:31
int getX() const
Returns the position of the surface in the X axis.
Definition: Surface.h:111
This is surface argument to ShaderDraw.
Definition: ShaderDrawHelper.h:63
ShaderMove< Uint8 > ShaderCrop(Surface *s, int x, int y)
Create warper from cropped Surface and provided offset.
Definition: ShaderMove.h:142
Definition: ShaderDrawHelper.h:565