YAPOG  0.0.1
Yet Another Pokemon Online Game
BaseSprite.cpp
Go to the documentation of this file.
2 
3 namespace yap
4 {
5  const bool BaseSprite::DEFAULT_VISIBLE_STATE = true;
6  const sf::Color BaseSprite::DEFAULT_COLOR = sf::Color ();
7 
9  : spatialInfo_ ()
10  , isVisible_ (DEFAULT_VISIBLE_STATE)
11  , color_ (DEFAULT_COLOR)
12  {
13  }
14 
16  {
17  }
18 
20  {
21  return spatialInfo_.GetPosition ();
22  }
23 
24  const Vector2& BaseSprite::GetSize () const
25  {
27 
28  return spatialInfo_.GetSize ();
29  }
30 
32  {
33  return spatialInfo_.GetTopLeft ();
34  }
35 
37  {
39  GetSize ();
40 
41  return spatialInfo_.GetBottomRight ();
42  }
43 
45  {
47  GetSize ();
48 
49  return spatialInfo_.GetCenter ();
50  }
51 
53  {
55  GetSize ();
56 
57  return spatialInfo_.GetRectangle ();
58  }
59 
60  void BaseSprite::Move (const Vector2& offset)
61  {
62  spatialInfo_.SetPosition (GetPosition () + offset);
63 
64  HandleMove (offset);
65  }
66 
67  void BaseSprite::Scale (const Vector2& factor)
68  {
70  Vector2 (
71  GetSize ().x * factor.x,
72  GetSize ().y * factor.y));
73 
74  HandleScale (factor);
75  }
76 
77  void BaseSprite::SetPosition (const Vector2& position)
78  {
79  Move (position - GetPosition ());
80  }
81 
82  void BaseSprite::SetSize (const Vector2& size)
83  {
84  Scale (
85  Vector2 (
86  size.x / GetSize ().x,
87  size.y / GetSize ().y));
88  }
89 
91  {
92  if (!isVisible_)
93  return;
94 
95  HandleDraw (context);
96  }
97 
98  bool BaseSprite::IsVisible () const
99  {
100  return isVisible_;
101  }
102 
103  void BaseSprite::Show (bool isVisible)
104  {
105  isVisible_ = isVisible;
106 
107  HandleShow (isVisible);
108  }
109 
110  void BaseSprite::ChangeColor (const sf::Color& color)
111  {
112  color_ = color;
113 
114  HandleChangeColor (color);
115  }
116 
117  void BaseSprite::Update (const Time& dt)
118  {
119  HandleUpdate (dt);
120  }
121 
123  : spatialInfo_ (copy.spatialInfo_)
124  , isVisible_ (copy.isVisible_)
125  , color_ (copy.color_)
126  {
127  }
128 
130  {
131  return spatialInfo_.GetSize ();
132  }
133 } // namespace yap