Number5
Visualisierung 2 Project - Florian Schober (0828151, f.schober@live.com), Andreas Walch (0926780, walch.andreas89@gmail.com)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HUD.cpp
Go to the documentation of this file.
1 #include "Application.hpp"
2 
4  : m_app(app)
5  , m_tex(app->getTextures().get("hud1.jpg"))
6  , m_lastMeasure(0)
7  , m_lastSpF(0)
8  , m_font(m_app->getText().getFont("consolab", 12))
9  , m_visiblity(HUDVisibility::All)
10 { }
11 
12 void HUD::update(double time, double timeDelta)
13 {
14  const double updateDelta = 0.3;
15 
16  if (time > (m_lastMeasure + updateDelta))
17  {
18  m_lastMeasure = time;
19  m_lastSpF = timeDelta;
20  }
21 }
22 void HUD::draw(double time, double timeDelta)
23 {
24  auto& wnd = m_app->getWindow().getSize();
25  auto& text = m_app->getText();
26  auto& sprite = m_app->getSprites();
27  auto& picker = m_app->getPicker();
28  auto& fbo = m_app->getSceneFBO();
29  auto& highlight = picker.highlightEffect();
30  auto& ownCursor = m_app->getOwnCursor();
31 
32  auto px = [wnd]
33  (float x, float y)
34  {
35  return vec2(x / wnd.x, y / wnd.y);
36  };
37 
38  sprite.begin2D();
39  {
40  sprite.begin();
41  {
42  fbo.bindSceneTexture();
43 
44  // scene
45  {
46  sprite.draw(vec4(1), vec2(0,0), vec2(1,1), vec2(1,1), HAlign::Left, VAlign::Bottom);
47  }
48 
49 
50  glBlendFunc(GL_ONE, GL_ONE);
51  highlight.bindResultTexutre();
52 
53  // scene
54  {
55  sprite.draw(vec4(1), vec2(0,0), vec2(1,1), vec2(1,1), HAlign::Left, VAlign::Bottom);
56  }
57 
58  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
59  m_tex->bind();
60 
62  {
63  // hover-obj
64  {
65  sprite.draw(vec4(vec3(0.2f), 0.8f), px(0, wnd.y), px(170, 35), vec2(170, 35) / m_tex->getSize(), HAlign::Left, VAlign::Top);
66  }
67 
68  // hover-obj-distance
69  {
70  sprite.draw(vec4(vec3(0.2f), 0.8f), px(200, wnd.y), px(200, 35), vec2(200, 35) / m_tex->getSize(), HAlign::Left, VAlign::Top);
71  }
72 
73  // max-distance
74  {
75  sprite.draw(vec4(vec3(0.2f), 0.8f), px(430, wnd.y), px(190, 35), vec2(190, 35) / m_tex->getSize(), HAlign::Left, VAlign::Top);
76  }
77  // max-distance-info
78  {
79  sprite.draw(vec4(vec3(0.2f), 0.4f), px(430, wnd.y - 35), px(190, 35), vec2(190, 35) / m_tex->getSize(), HAlign::Left, VAlign::Top);
80  }
81 
82  // picker-mode
83  {
84  sprite.draw(vec4(vec3(0.2f), 0.8f), px(660, wnd.y), px(190, 35), vec2(190, 35) / m_tex->getSize(), HAlign::Left, VAlign::Top);
85  }
86  // picker-mode-info
87  {
88  sprite.draw(vec4(vec3(0.2f), 0.4f), px(660, wnd.y - 35), px(190, 35), vec2(190, 35) / m_tex->getSize(), HAlign::Left, VAlign::Top);
89  }
90 
91  // mouse-border-toggle-info
92  {
93  sprite.draw(vec4(vec3(0.2f), 0.4f), px(wnd.x, 0), px(285, 35), vec2(285, 35) / m_tex->getSize(), HAlign::Right, VAlign::Bottom);
94  }
95 
96  // hud-toggle-info
97  {
98  sprite.draw(vec4(vec3(0.2f), 0.4f), px(wnd.x - 40 - 285, 0), px(240, 35), vec2(240, 35) / m_tex->getSize(), HAlign::Right, VAlign::Bottom);
99  }
100 
101  float scenesHeight = (m_font->lineHeight() + 8.0f)*(m_app->getGameLogic().scenes().size()) + m_font->lineHeight() + 10 + 10 * 2;
102  // scenes
103  {
104  sprite.draw(vec4(vec3(0.2f), 0.8f), px(0, wnd.y - 150), px(140, scenesHeight), vec2(140, scenesHeight) / m_tex->getSize(), HAlign::Left, VAlign::Top);
105  }
106  // toggle scenes
107  {
108  sprite.draw(vec4(vec3(0.2f), 0.4f), px(0, wnd.y - 150 - scenesHeight), px(140, 35), vec2(140, 35) / m_tex->getSize(), HAlign::Left, VAlign::Top);
109  }
110 
111  // mouse-border
112  if (m_app->getCamera().sideWayActive())
113  {
114  auto borderAlpha = 0.1f;
115  auto borderWidth = (float)m_app->getCamera().getMouseBorder();
116  // TOP-BAR
117  sprite.draw(vec4(vec3(0.2f), borderAlpha), px(wnd.x / 2, wnd.y), px(wnd.x, borderWidth), vec2(1, 1), HAlign::Center, VAlign::Top);
118  // BOTTOM-BAR
119  sprite.draw(vec4(vec3(0.2f), borderAlpha), px(wnd.x / 2, 0), px(wnd.x, borderWidth), vec2(1, 1), HAlign::Center, VAlign::Bottom);
120  // LEFT-BAR
121  sprite.draw(vec4(vec3(0.2f), borderAlpha), px(0, wnd.y / 2), px(borderWidth, wnd.y - (2 * borderWidth)), vec2(1, 1), HAlign::Left, VAlign::Middle);
122  // RIGHT-BAR
123  sprite.draw(vec4(vec3(0.2f), borderAlpha), px(wnd.x, wnd.y / 2), px(borderWidth, wnd.y - (2 * borderWidth)), vec2(1, 1), HAlign::Right, VAlign::Middle);
124  }
125 
126 
127  // scale-mode
128  {
129  sprite.draw(vec4(vec3(0.2f), 0.8f), px(wnd.x, wnd.y-150), px(160, 35), vec2(160, 35) / m_tex->getSize(), HAlign::Right, VAlign::Top);
130  }
131  // scale-mode-info
132  {
133  sprite.draw(vec4(vec3(0.2f), 0.4f), px(wnd.x, wnd.y-150-35), px(160, 35), vec2(160, 35) / m_tex->getSize(), HAlign::Right, VAlign::Top);
134  }
135  // cursor-icon
136  {
137  sprite.draw(vec4(vec3(0.2f), 0.8f), px(wnd.x, wnd.y-230), px(160, 35), vec2(160, 35) / m_tex->getSize(), HAlign::Right, VAlign::Top);
138  }
139  // toggle-cursor icon
140  {
141  sprite.draw(vec4(vec3(0.2f), 0.4f), px(wnd.x, wnd.y-230-35), px(160, 35), vec2(160, 35) / m_tex->getSize(), HAlign::Right, VAlign::Top);
142  }
143  // cushion-factor
144  {
145  sprite.draw(vec4(vec3(0.2f), 0.8f), px(wnd.x, wnd.y-310), px(160, 35), vec2(160, 35) / m_tex->getSize(), HAlign::Right, VAlign::Top);
146  }
147  // cushion-factor info
148  {
149  sprite.draw(vec4(vec3(0.2f), 0.4f), px(wnd.x, wnd.y-310-35), px(160, 35), vec2(160, 35) / m_tex->getSize(), HAlign::Right, VAlign::Top);
150  }
151  }
152 
154  {
155  // mspf
156  {
157  //sprite.draw(vec4(vec3(0.2f), 0.8f), px(wnd.x, wnd.y), px(100, 35), vec2(100, 35) / m_tex->getSize(), HAlign::Right, VAlign::Top);
158 
159  // mspf AND scale
160  sprite.draw(vec4(vec3(0.2f), 0.8f), px(wnd.x, wnd.y), px(100, 70), vec2(100, 70) / m_tex->getSize(), HAlign::Right, VAlign::Top);
161  }
162  }
163  }
164  sprite.end();
165 
166 
167  text.begin();
168  {
169  string buffer(256, 0);
170 
171  auto color = vec4(1,208.0/255.0,71.0/255.0,1);
172  auto colorFocus = vec4(1,1,200.0/255.0,1);
173 
175  {
176  // hover-obj
177  {
178  if (picker.hasFocusId())
179  sprintf_s(&buffer[0], buffer.size(), "Object in focus: %4d", picker.getFocusId());
180  else
181  sprintf_s(&buffer[0], buffer.size(), "Object in focus: none");
182 
183  m_font->draw(buffer, color, px(10, wnd.y - 10), HAlign::Left, VAlign::Top);
184  }
185 
186  // hover-obj-distance
187  {
188  if (picker.hasFocusId())
189  sprintf_s(&buffer[0], buffer.size(), "Distance to focus-obj: %d", (int)glm::round(picker.getFocusDistance()));
190  else
191  sprintf_s(&buffer[0], buffer.size(), "Distance to focus-obj: -");
192 
193  m_font->draw(buffer, color, px(210, wnd.y - 10), HAlign::Left, VAlign::Top);
194  }
195 
196  // max-distance
197  {
198  sprintf_s(&buffer[0], buffer.size(), "Max-distance: %d", picker.maxDistance());
199 
200  m_font->draw(buffer, color, px(470, wnd.y - 10), HAlign::Left, VAlign::Top);
201  }
202 
203  // max-distance-info
204  {
205  sprintf_s(&buffer[0], buffer.size(), "Change with PAGEUP/-DOWN");
206 
207  m_font->draw(buffer, color, px(440, wnd.y - 45), HAlign::Left, VAlign::Top);
208  }
209 
210  // picker-mode
211  {
212  switch (picker.updateMode())
213  {
215  sprintf_s(&buffer[0], buffer.size(), "Picker-mode: STATIC");
216  break;
217 
219  default:
220  sprintf_s(&buffer[0], buffer.size(), "Picker-mode: DYNAMIC");
221  break;
222  }
223 
224  m_font->draw(buffer, color, px(690, wnd.y - 10), HAlign::Left, VAlign::Top);
225  }
226  // picker-mode-info
227  {
228  sprintf_s(&buffer[0], buffer.size(), "Toggle with F1");
229 
230  m_font->draw(buffer, color, px(710, wnd.y - 45), HAlign::Left, VAlign::Top);
231  }
232 
233  // scale-mode
234  {
235  if(ownCursor.getScaleFunction())
236  {
237  sprintf_s(&buffer[0], buffer.size(), "Scale-mode: LINEAR ");
238  }
239  else
240  {
241  sprintf_s(&buffer[0], buffer.size(), "Scale-mode: INVERSE");
242  }
243 
244  m_font->draw(buffer, color, px(wnd.x-10, wnd.y - 160), HAlign::Right, VAlign::Top);
245  }
246 
247  // scale-mode-info
248  {
249  sprintf_s(&buffer[0], buffer.size(), "Toggle with F5");
250 
251  m_font->draw(buffer, color, px(wnd.x-30, wnd.y - 195), HAlign::Right, VAlign::Top);
252  }
253 
254  // cursor-icon
255  {
256 
257  if(ownCursor.getCursorIcon())
258  {
259  sprintf_s(&buffer[0], buffer.size(), "Cursor-icon: ARROW");
260  }
261  else
262  {
263  sprintf_s(&buffer[0], buffer.size(), "Cursor-icon: HAND ");
264  }
265 
266  m_font->draw(buffer, color, px(wnd.x-20, wnd.y - 240), HAlign::Right, VAlign::Top);
267  }
268 
269  // toogle-cursor-icon
270  {
271  sprintf_s(&buffer[0], buffer.size(), "Toogle with F6");
272 
273  m_font->draw(buffer, color, px(wnd.x-30, wnd.y - 240-35), HAlign::Right, VAlign::Top);
274  }
275 
276 
277  // cushion-factor
278  {
279  sprintf_s(&buffer[0], buffer.size(), "Cushion Factor %1.2f", ownCursor.getCushion());
280 
281  m_font->draw(buffer, color, px(wnd.x-20, wnd.y - 320), HAlign::Right, VAlign::Top);
282  }
283 
284  // cushion-info
285  {
286  sprintf_s(&buffer[0], buffer.size(), "Dec F7 Inc F8");
287 
288  m_font->draw(buffer, color, px(wnd.x-30, wnd.y - 320-35), HAlign::Right, VAlign::Top);
289  }
290 
291  // mouse-border-toggle-info
292  {
293  sprintf_s(&buffer[0], buffer.size(), "Toggle camera-border with SCROLL LOCK");
294 
295  m_font->draw(buffer, color, px(wnd.x - 10, 12), HAlign::Right, VAlign::Bottom);
296  }
297 
298  // hud-toggle-info
299  {
300  sprintf_s(&buffer[0], buffer.size(), "Toggle HUD-visibility with F2");
301 
302  m_font->draw(buffer, color, px(wnd.x - 20 - 40 - 285, 12), HAlign::Right, VAlign::Bottom);
303  }
304 
305  // scenes
306  {
307  sprintf_s(&buffer[0], buffer.size(), "Scenes:");
308 
309  m_font->draw(buffer, color, px(10, wnd.y-150-10), HAlign::Left, VAlign::Top);
310 
311  for (size_t i = 0; i < m_app->getGameLogic().scenes().size(); i++)
312  {
313  auto& scene = m_app->getGameLogic().scenes()[i];
314 
315  if (i == m_app->getGameLogic().activeScene())
316  sprintf_s(&buffer[0], buffer.size(), "> %s", scene.c_str());
317  else
318  sprintf_s(&buffer[0], buffer.size(), " %s", scene.c_str());
319 
320  auto col = &color;
321 
322  if (i == m_app->getGameLogic().activeScene())
323  col = &colorFocus;
324 
325  m_font->draw(buffer, *col, px(20, wnd.y-150-10-(8+m_font->lineHeight())*(1+i)), HAlign::Left, VAlign::Top);
326  }
327  }
328 
329  // toggle scenes
330  {
331  auto y = (m_font->lineHeight() + 8.0f)*(m_app->getGameLogic().scenes().size()) + m_font->lineHeight()+10 + 10*2;
332 
333  sprintf_s(&buffer[0], buffer.size(), "Switch with TAB");
334 
335  m_font->draw(buffer, color, px(18, wnd.y - 150 - y - 10), HAlign::Left, VAlign::Top);
336  }
337  }
338 
340  {
341  // mspf
342  {
343  sprintf_s(&buffer[0], buffer.size(), "%6.2f MSpF", m_lastSpF * 1000);
344  m_font->draw(buffer, color, px(wnd.x - 10, wnd.y - 10), HAlign::Right, VAlign::Top);
345  }
346 
347  // scale
348  {
349  sprintf_s(&buffer[0], buffer.size(), "%1.2f Scale", ownCursor.getScale());
350  m_font->draw(buffer, color, px(wnd.x - 10, wnd.y - 45), HAlign::Right, VAlign::Top);
351  }
352  }
353  }
354  text.end();
355  }
356  sprite.end2D();
357 }
358 void HUD::onKeyStateChanged(int key, bool pressed)
359 {
360  if (!pressed) return;
361 
362  if (key == GLFW_KEY_F2)
363  nextVisibility();
364 }
HUD(Application *app)
Definition: HUD.cpp:3
vector< string > const & scenes() const
Definition: GameLogic.hpp:36
void nextVisibility()
Definition: HUD.hpp:46
double m_lastSpF
Definition: HUD.hpp:25
SceneFBO & getSceneFBO()
Definition: Application.hpp:61
void draw(string const &text, vec4 const &color, vec2 position, HAlign hAlign=HAlign::Left, VAlign vAlign=VAlign::Bottom, vec2 const &scale=vec2(1, 1))
Definition: Font.cpp:185
SpriteRenderer & getSprites()
Definition: Application.hpp:81
Texture * m_tex
Definition: HUD.hpp:23
void update(double time, double timeDelta)
Definition: HUD.cpp:12
int const getMouseBorder()
Definition: Camera.hpp:56
HUDVisibility m_visiblity
Definition: HUD.hpp:30
GameLogic & getGameLogic()
Definition: Application.hpp:96
double m_lastMeasure
Definition: HUD.hpp:26
HUDVisibility
Definition: HUD.hpp:8
Camera & getCamera()
Definition: Application.hpp:76
float lineHeight() const
Definition: Font.hpp:40
Application * m_app
Definition: HUD.hpp:22
uvec2 & getSize()
Definition: Texture.hpp:24
OwnCursor & getOwnCursor()
void draw(double time, double timeDelta)
Definition: HUD.cpp:22
Window & getWindow()
Definition: Application.hpp:41
TextRenderer & getText()
Definition: Application.hpp:86
bool const sideWayActive()
Definition: Camera.hpp:28
vec2 const & getSize() const
Definition: Window.hpp:45
Picker & getPicker()
Definition: Application.hpp:91
uint activeScene() const
Definition: GameLogic.hpp:27
Font * m_font
Definition: HUD.hpp:28
void bind(uint target=0)
Definition: Texture.cpp:54
void onKeyStateChanged(int key, bool pressed)
Definition: HUD.cpp:358