YAPOG  0.0.1
Yet Another Pokemon Online Game
TextureManager.cpp
Go to the documentation of this file.
5 
6 
7 namespace yap
8 {
10  {
11  }
12 
14  : spatialInfo_ ()
15  , isEnable_ (true)
16  , color_ (sf::Color ())
17  , textures_ ()
18  , isVisble_ (true)
19  , width_ (w)
20  , height_ (h)
21  , baseTexture_ (&base)
22  {
23  base.SetPosition (GetPosition ());
24  }
25 
26  void TextureManager::GetLimits (int& width, int& height)
27  {
28  Texture* base = baseTexture_;
29 
30  if (base->GetSize () == Vector2 (1, 1))
31  return;
32 
33  width = width_ / base->GetSize ().x;
34  height = height_ / base->GetSize ().y;
35 
36  if (width == 0)
37  width = 1;
38  if (height == 0)
39  height = 1;
40  }
41 
43  {
44  Texture* base = baseTexture_;
45 
46  if (base->GetSize () == Vector2 (1, 1))
47  return;
48 
49  int widthIt = 0;
50  int heightIt = 0;
51 
52  GetLimits (widthIt, heightIt);
53 
54  for (int i = 0; i < widthIt; i++)
55  {
56  for (int j = 0; j < heightIt; j++)
57  {
58  Texture* current = base->Clone ();
59  textures_.Add (current);
60  }
61  }
62  UpdatePosition ();
63  }
64 
66  {
67  Texture* base = baseTexture_;
68 
69  if (base->GetSize () == Vector2 (1, 1))
70  return;
71 
72  int widthIt = 0;
73  int heightIt = 0;
74 
75  GetLimits (widthIt, heightIt);
76 
77  int currentWidth = GetPosition ().x;
78  int currentHeight = GetPosition ().y;
79 
80  for (int i = 0; i < heightIt; i++)
81  {
82  for (int j = 0; j < widthIt; j++)
83  {
84  textures_[j + i * widthIt]->SetPosition (
85  Vector2 (currentWidth, currentHeight));
86 
87  currentWidth += base->GetSize ().x;
88  }
89  currentHeight += base->GetSize ().y;
90  currentWidth = GetPosition ().x;
91  }
92  }
93 
95  {
96  }
97 
99  {
100  return spatialInfo_.GetPosition ();
101  }
102 
104  {
105  Vector2 size (width_, height_);
106 
107  spatialInfo_.SetSize (size);
108 
109  return spatialInfo_.GetSize ();
110  }
111 
113  {
114  return spatialInfo_.GetTopLeft ();
115  }
116 
118  {
119  return spatialInfo_.GetBottomRight ();
120  }
121 
123  {
124  return spatialInfo_.GetCenter ();
125  }
126 
128  {
129  return spatialInfo_.GetRectangle ();
130  }
131 
132  void TextureManager::Move (const Vector2& offset)
133  {
134  for (Texture* child : textures_)
135  {
136  child->Move (offset);
137  }
138  spatialInfo_.SetPosition (GetPosition () + offset);
139  }
140 
141  void TextureManager::Scale (const Vector2& factor)
142  {
143  for (Texture* child : textures_)
144  child->Scale (factor);
145 
146  UpdatePosition ();
148  Vector2 (
149  GetSize ().x * factor.x,
150  GetSize ().y * factor.y));
151  }
152 
153  void TextureManager::SetPosition (const Vector2& position)
154  {
155  Move (position - GetPosition ());
156  }
157 
158  void TextureManager::SetSize (const Vector2& size)
159  {
160  for (Texture* child : textures_)
161  {
162  child->SetSize (size);
163  }
164  UpdatePosition ();
165  Scale (
166  Vector2 (
167  size.x / GetSize ().x,
168  size.y / GetSize ().y));
169  }
170 
172  {
173  if (!isVisble_)
174  return;
175 
176  for (Texture* child : textures_)
177  {
178  child->Draw (context);
179  }
180  }
181 
183  {
184  return isVisble_;
185  }
186 
187  void TextureManager::Show (bool isVisible)
188  {
189  for (Texture* child : textures_)
190  {
191  child->Show (isVisible);
192  }
193 
194  isVisble_ = isVisible;
195  }
196 
197  void TextureManager::ChangeColor (const sf::Color& color)
198  {
199  for (Texture* child : textures_)
200  {
201  child->ChangeColor (color);
202  }
203 
204  color_ = color;
205  }
206 
207 } //namespace yap