YAPOG  0.0.1
Yet Another Pokemon Online Game
DrawingContext.cpp
Go to the documentation of this file.
2 
3 namespace yap
4 {
6  sf::Color::Black;
7 
8  DrawingContext::DrawingContext (const Vector2& size, const String& name)
9  : window_ (sf::VideoMode (size.x, size.y), name)
10  , currentMode_ ()
11  , defaultMode_ ()
12  , cameras_ ()
13  , targetClearColor_ (DEFAULT_TARGET_CLEAR_COLOR)
14  {
15  }
16 
18  {
19  for (const auto it : cameras_)
20  delete it.second;
21  }
22 
23  void DrawingContext::AddCamera (const CameraMode& mode, ICamera* camera)
24  {
25  bool isEmpty = cameras_.IsEmpty ();
26 
27  cameras_.Add (mode, camera);
28 
29  if (!isEmpty)
30  return;
31 
32  SetCurrentMode (mode);
33  defaultMode_ = mode;
34  }
35 
37  {
38  cameras_.Remove (mode);
39  }
40 
42  {
43  return GetCamera (currentMode_);
44  }
45 
47  {
48  return GetCamera (currentMode_);
49  }
50 
51  const ICamera& DrawingContext::GetCamera (const CameraMode& mode) const
52  {
53  return *cameras_[mode];
54  }
55 
57  {
58  return *cameras_[mode];
59  }
60 
62  {
63  SetCurrentMode (mode);
64  }
65 
67  {
68  defaultMode_ = mode;
69  }
70 
72  {
74  }
75 
76  const sf::RenderTarget& DrawingContext::GetRenderTarget () const
77  {
78  return window_;
79  }
80 
81  sf::RenderTarget& DrawingContext::GetRenderTarget ()
82  {
83  return window_;
84  }
85 
86  void DrawingContext::Draw (const sf::Drawable& drawable)
87  {
88  Draw (drawable, sf::RenderStates::Default);
89  }
90 
92  const sf::Drawable& drawable,
93  const sf::RenderStates& states)
94  {
95  HandleDraw (drawable, states);
96  }
97 
98  const sf::Color& DrawingContext::GetTargetClearColor () const
99  {
100  return targetClearColor_;
101  }
102 
103  void DrawingContext::SetTargetClearColor (const sf::Color& color)
104  {
105  targetClearColor_ = color;
106  }
107 
109  const sf::Drawable& drawable,
110  const sf::RenderStates& states)
111  {
112  GetRenderTarget ().draw (drawable, states);
113  }
114 
116  {
117  currentMode_ = mode;
118 
119  GetRenderTarget ().setView (GetCamera ().GetInnerView ());
120  }
121 
122  sf::RenderWindow& DrawingContext::GetWindow ()
123  {
124  return window_;
125  }
126 
128  {
129  for (auto& modeCameraPair : cameras_)
130  modeCameraPair.second->SetSize (size);
131  }
132 } // namespace yap