OpenXcom  1.0
Open-source clone of the original X-Com
ShaderMove.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "ShaderDraw.h"
21 
22 namespace OpenXcom
23 {
24 
25 
26 template<typename Pixel>
27 class ShaderMove : public helper::ShaderBase<Pixel>
28 {
29  int _move_x;
30  int _move_y;
31 
32 public:
34  friend struct helper::controler<ShaderMove<Pixel> >;
35 
36  inline ShaderMove(Surface* s):
37  _base(s),
38  _move_x(s->getX()), _move_y(s->getY())
39  {
40 
41  }
42 
43  inline ShaderMove(Surface* s, int move_x, int move_y):
44  _base(s),
45  _move_x(move_x), _move_y(move_y)
46  {
47 
48  }
49 
50  inline ShaderMove(const ShaderMove& f):
51  _base(f),
52  _move_x(f._move_x), _move_y(f._move_y)
53  {
54 
55  }
56 
57  inline ShaderMove(std::vector<Pixel>& f, int max_x, int max_y):
58  _base(f, max_x, max_y),
59  _move_x(), _move_y()
60  {
61 
62  }
63 
64  inline ShaderMove(std::vector<Pixel>& f, int max_x, int max_y, int move_x, int move_y):
65  _base(f, max_x, max_y),
66  _move_x(move_x), _move_y(move_y)
67  {
68 
69  }
70 
71  inline GraphSubset getImage() const
72  {
73  return _base::_range_domain.offset(_move_x, _move_y);
74  }
75 
76  inline void setMove(int x, int y)
77  {
78  _move_x = x;
79  _move_y = y;
80  }
81  inline void addMove(int x, int y)
82  {
83  _move_x += x;
84  _move_y += y;
85  }
86 };
87 
88 
89 
90 namespace helper
91 {
92 
93 template<typename Pixel>
94 struct controler<ShaderMove<Pixel> > : public controler_base<typename ShaderMove<Pixel>::PixelPtr, typename ShaderMove<Pixel>::PixelRef>
95 {
96  typedef typename ShaderMove<Pixel>::PixelPtr PixelPtr;
97  typedef typename ShaderMove<Pixel>::PixelRef PixelRef;
98 
100 
101  controler(const ShaderMove<Pixel>& f) : base_type(f.ptr(), f.getDomain(), f.getImage(), std::make_pair(1, f.pitch()))
102  {
103 
104  }
105 
106 };
107 
108 }//namespace helper
109 
115 inline ShaderMove<Uint8> ShaderSurface(Surface* s)
116 {
117  return ShaderMove<Uint8>(s);
118 }
119 
127 inline ShaderMove<Uint8> ShaderSurface(Surface* s, int x, int y)
128 {
129  return ShaderMove<Uint8>(s, x, y);
130 }
131 
139 inline ShaderMove<Uint8> ShaderCrop(Surface* s, int x, int y)
140 {
141  ShaderMove<Uint8> ret(s, x, y);
142  SDL_Rect* s_crop = s->getCrop();
143  if (s_crop->w && s_crop->h)
144  {
145  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));
146  ret.setDomain(crop);
147  ret.addMove(-s_crop->x, -s_crop->y);
148  }
149  return ret;
150 }
151 
157 inline ShaderMove<Uint8> ShaderCrop(Surface* s)
158 {
159  return ShaderCrop(s, s->getX(), s->getY());
160 }
161 
162 }//namespace OpenXcom
Definition: ShaderMove.h:27
helper class for handling implementation differences in different surfaces types Used in function Sha...
Definition: ShaderDrawHelper.h:416
int getY() const
Returns the position of the surface in the Y axis.
Definition: Surface.h:130
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
int getX() const
Returns the position of the surface in the X axis.
Definition: Surface.h:120
Definition: GraphSubset.h:32
This is surface argument to ShaderDraw.
Definition: ShaderDrawHelper.h:60
Definition: ShaderDrawHelper.h:562
Definition: BaseInfoState.cpp:40