NTrace
GPU ray tracing framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CommonControls.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2011, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "gui/CommonControls.hpp"
29 #include "gpu/GLContext.hpp"
30 #include "gui/Image.hpp"
31 #include "io/File.hpp"
32 #include "io/StateDump.hpp"
33 
34 #include <stdio.h>
35 
36 using namespace FW;
37 
38 //------------------------------------------------------------------------
39 
40 static const F32 s_highlightFadeDuration = 3.0f;
41 static const F32 s_highlightFadeSpeed = 3.0f;
42 static const F32 s_initFrameTime = 1.0f / 60.0f;
43 
44 //------------------------------------------------------------------------
45 
47 : m_features (features),
48  m_window (NULL),
49 
50  m_showControls (true),
51  m_showFPS (false),
52 
53  m_sliderStackBegun (false),
54  m_sliderStackEmpty (false),
55  m_controlVisibility (true),
56 
57  m_viewSize (1.0f),
58  m_fontHeight (1.0f),
59  m_rightX (0.0f),
60 
61  m_dragging (false),
62  m_avgFrameTime (s_initFrameTime),
63  m_screenshot (false)
64 {
65  clearActive();
66 
67  // Query executable path and file name.
68 
69  char moduleFullName[256];
70  GetModuleFileName(GetModuleHandle(NULL), moduleFullName, sizeof(moduleFullName) - 1);
71  moduleFullName[sizeof(moduleFullName) - 1] = '\0';
72 
73  // Strip path and extension.
74 
75  const char* moduleShortName = moduleFullName;
76  for (int i = 0; moduleFullName[i]; i++)
77  if (moduleFullName[i] == '/' || moduleFullName[i] == '\\')
78  moduleShortName = &moduleFullName[i + 1];
79  else if (moduleFullName[i] == '.')
80  moduleFullName[i] = '\0';
81 
82  // Initialize file prefixes.
83 
84  m_stateFilePrefix = sprintf("state_%s_", moduleShortName);
85  m_screenshotFilePrefix = sprintf("screenshot_%s_", moduleShortName);
86 }
87 
88 //------------------------------------------------------------------------
89 
91 {
92  resetControls();
93 }
94 
95 //------------------------------------------------------------------------
96 
98 {
99  FW_ASSERT(m_window == ev.window || ev.type == Window::EventType_AddListener);
100  bool stopPropagation = false;
101 
102  switch (ev.type)
103  {
105  FW_ASSERT(!m_window);
106  m_window = ev.window;
107  m_timer.unstart();
108  m_dragging = false;
109  m_avgFrameTime = s_initFrameTime;
110  m_screenshot = false;
111  m_window->repaint();
112  return false;
113 
115  m_window->repaint();
116  m_window = NULL;
117  return false;
118 
120  {
121  if (ev.key == FW_KEY_ESCAPE && hasFeature(Feature_CloseOnEsc))
122  {
123  m_window->requestClose();
124  }
125  else if (ev.key == FW_KEY_F4 && m_window->isKeyDown(FW_KEY_ALT) && hasFeature(Feature_CloseOnAltF4))
126  {
127  m_window->requestClose();
128  }
129  else if (ev.key == FW_KEY_F5 && hasFeature(Feature_RepaintOnF5))
130  {
131  m_window->repaint();
132  }
133  else if (ev.key == FW_KEY_F9 && hasFeature(Feature_ShowFPSOnF9))
134  {
135  m_showFPS = (!m_showFPS);
136  m_avgFrameTime = s_initFrameTime;
137  m_window->repaint();
138  }
139  else if (ev.key == FW_KEY_F10 && hasFeature(Feature_HideControlsOnF10))
140  {
141  m_showControls = (!m_showControls);
142  m_dragging = false;
143  m_window->repaint();
144  }
145  else if (ev.key == FW_KEY_F11 && hasFeature(Feature_FullScreenOnF11))
146  {
147  m_window->toggleFullScreen();
148  }
149  else if (ev.key == FW_KEY_MOUSE_LEFT && (m_activeSlider != -1 || m_activeToggle != -1))
150  {
151  m_dragging = true;
152  stopPropagation = true;
153  if (m_activeToggle != -1)
154  selectToggle(m_toggles[m_activeToggle]);
155  }
156  else if (ev.key == FW_KEY_MOUSE_MIDDLE && m_activeSlider != -1 && !m_dragging)
157  {
158  stopPropagation = true;
159  enterSliderValue(m_sliders[m_activeSlider]);
160  }
161  else if (ev.keyUnicode >= '0' && ev.keyUnicode <= '9')
162  {
163  int idx = ev.keyUnicode - '0';
164  if (!m_window->isKeyDown(FW_KEY_ALT) && hasFeature(Feature_LoadStateOnNum) && m_stateObjs.getSize())
165  {
166  if (idx == 0)
167  loadStateDialog();
168  else
170  }
171  else if (m_window->isKeyDown(FW_KEY_ALT) && hasFeature(Feature_SaveStateOnAltNum) && m_stateObjs.getSize())
172  {
173  if (idx == 0)
174  saveStateDialog();
175  else
177  }
178  }
179 
180  // Handle toggles.
181 
182  const Key* key = getKey(ev.key);
183  for (int i = 0; i < key->toggles.getSize(); i++)
184  {
185  selectToggle(key->toggles[i]);
186  key->toggles[i]->highlightTime = FW_F32_MAX;
187  }
188 
189  // Handle sliders.
190 
191  for (int i = 0; i < key->sliderIncrease.getSize(); i++)
192  sliderKeyDown(key->sliderIncrease[i], 1);
193  for (int i = 0; i < key->sliderDecrease.getSize(); i++)
194  sliderKeyDown(key->sliderDecrease[i], -1);
195  if (key->sliderIncrease.getSize() || key->sliderDecrease.getSize())
196  m_window->repaint();
197  }
198  break;
199 
201  if (ev.key == FW_KEY_PRINT_SCREEN && hasFeature(Feature_ScreenshotOnPrtScn))
202  {
203  m_screenshot = true;
204  m_window->repaint();
205  }
206  else if (ev.key == FW_KEY_MOUSE_LEFT && m_dragging)
207  {
208  m_dragging = false;
209  stopPropagation = true;
210  }
211  break;
212 
214  if (m_dragging && m_activeSlider != -1)
215  {
216  Slider* s = m_sliders[m_activeSlider];
217  setSliderY(s, getSliderY(s, true) - ev.mouseDelta.y);
218  }
219  break;
220 
221  default:
222  break;
223  }
224 
225  GLContext* gl = NULL;
226  if (ev.type == Window::EventType_Paint)
227  {
228  gl = m_window->getGL();
229  layout(gl->getViewSize(), (F32)gl->getFontHeight());
230  }
231 
232  if (!m_dragging)
233  {
234  clearActive();
235  if (m_showControls && ev.mouseKnown && !ev.mouseDragging)
236  updateActive(Vec2f((F32)ev.mousePos.x, m_viewSize.y - (F32)ev.mousePos.y - 1.0f));
237  }
238  if (m_activeSlider != -1)
239  {
240  m_sliders[m_activeSlider]->highlightTime = FW_F32_MAX;
241  if (m_showControls)
242  m_window->repaint();
243  }
244  if (m_activeToggle != -1)
245  {
246  m_toggles[m_activeToggle]->highlightTime = FW_F32_MAX;
247  if (m_showControls)
248  m_window->repaint();
249  }
250 
251  if (ev.type == Window::EventType_Paint)
252  render(gl);
253  return stopPropagation;
254 }
255 
256 //------------------------------------------------------------------------
257 
258 void CommonControls::message(const String& str, const String& volatileID, U32 abgr)
259 {
260  if (volatileID.getLength())
261  for (int i = 0; i < m_messages.getSize(); i++)
262  if (m_messages[i].volatileID == volatileID)
263  {
264  m_messages.remove(i);
265  break;
266  }
267 
268  if (!str.getLength())
269  return;
270 
271  Message msg;
272  msg.string = str;
273  msg.highlightTime = FW_F32_MAX;
274  msg.volatileID = volatileID;
275  msg.abgr = abgr;
276  m_messages.insert(0, msg);
277 
278  if (m_window)
279  m_window->repaint();
280 }
281 
282 //------------------------------------------------------------------------
283 
285 {
286  FW_ASSERT(target);
287 
288  for (int i = 0; i < m_toggles.getSize(); i++)
289  {
290  Toggle* t = m_toggles[i];
291  if (t->boolTarget != target && t->enumTarget != target)
292  continue;
293 
294  t->key->toggles.removeItem(t);
295  delete m_toggles.remove(i--);
296  }
297 
298  for (int i = 0; i < m_sliders.getSize(); i++)
299  {
300  Slider* s = m_sliders[i];
301  if (s->floatTarget != target && s->intTarget != target)
302  continue;
303 
304  if (!s->stackWithPrevious && i < m_sliders.getSize() - 1)
305  m_sliders[i + 1]->stackWithPrevious = false;
306 
307  s->increaseKey->sliderIncrease.removeItem(s);
308  s->decreaseKey->sliderDecrease.removeItem(s);
309  delete m_sliders.remove(i--);
310  }
311 }
312 
313 //------------------------------------------------------------------------
314 
316 {
317  for (int i = 0; i < m_toggles.getSize(); i++)
318  delete m_toggles[i];
319  m_toggles.clear();
320 
321  for (int i = 0; i < m_sliders.getSize(); i++)
322  delete m_sliders[i];
323  m_sliders.clear();
324 
325  for (int slot = m_keyHash.firstSlot(); slot != -1; slot = m_keyHash.nextSlot(slot))
326  delete m_keyHash.getSlot(slot).value;
327  m_keyHash.clear();
328 
329  clearActive();
330 // m_dragging = false;
331 }
332 
333 //------------------------------------------------------------------------
334 
336 {
337  SYSTEMTIME st;
338  FILETIME ft;
339  GetSystemTime(&st);
340  SystemTimeToFileTime(&st, &ft);
341  U64 stamp = *(const U64*)&ft;
342 
343  String name = m_screenshotFilePrefix;
344  for (int i = 60; i >= 0; i -= 4)
345  name += (char)('a' + ((stamp >> i) & 15));
346  name += ".png";
347  return name;
348 }
349 
350 //------------------------------------------------------------------------
351 
352 bool CommonControls::loadState(const String& fileName)
353 {
354  String oldError = clearError();
355  StateDump dump;
356 
357  // Read file.
358  {
359  File file(fileName, File::Read);
360  char tag[9];
361  file.readFully(tag, 8);
362  tag[8] = 0;
363  if (String(tag) != "FWState ")
364  setError("Invalid state file!");
365  if (!hasError())
366  file >> dump;
367  }
368 
369  // Decode state.
370 
371  if (!hasError())
372  {
373  for (int i = 0; i < m_stateObjs.getSize(); i++)
374  m_stateObjs[i]->readState(dump);
375  }
376 
377  // Display status.
378 
379  if (hasError())
380  message(sprintf("Unable to load state: %s", getError().getPtr()), "StateIO");
381  else
382  message(sprintf("Loaded state from '%s'", fileName.getPtr()), "StateIO");
383  return (!restoreError(oldError));
384 }
385 
386 //------------------------------------------------------------------------
387 
389 {
390  if (!m_window)
391  return false;
392 
393  String name = m_window->showFileLoadDialog("Load state", "dat:State", ".");
394  if (!name.getLength())
395  return false;
396 
397  return loadState(name);
398 }
399 
400 //------------------------------------------------------------------------
401 
403 {
404  if (!m_window)
405  return false;
406 
407  String name = m_window->showFileSaveDialog("Save state", "dat:State", ".");
408  if (!name.getLength())
409  return false;
410 
411  return saveState(name);
412 }
413 
414 //------------------------------------------------------------------------
415 
416 bool CommonControls::saveState(const String& fileName)
417 {
418  String oldError = clearError();
419 
420  // Encode state.
421 
422  StateDump dump;
423  for (int i = 0; i < m_stateObjs.getSize(); i++)
424  m_stateObjs[i]->writeState(dump);
425 
426  // Write file.
427 
428  if (!hasError())
429  {
430  File file(fileName, File::Create);
431  file.write("FWState ", 8);
432  file << dump;
433  }
434 
435  // Display status.
436 
437  if (hasError())
438  message(sprintf("Unable to save state: %s", getError().getPtr()), "StateIO");
439  else
440  message(sprintf("Saved state to '%s'", fileName.getPtr()), "StateIO");
441  return (!restoreError(oldError));
442 }
443 
444 //------------------------------------------------------------------------
445 
447 {
448  F32 boost = 1.0f;
449  if (m_window)
450  {
451  if (m_window->isKeyDown(FW_KEY_SPACE))
452  boost *= 5.0f;
453  if (m_window->isKeyDown(FW_KEY_CONTROL))
454  boost /= 5.0f;
455  }
456  return boost;
457 }
458 
459 //------------------------------------------------------------------------
460 
462 {
463  for (int i = 0; i < m_toggles.getSize(); i++)
464  m_toggles[i]->highlightTime = FW_F32_MAX;
465  if (m_window)
466  m_window->repaint();
467 }
468 
469 //------------------------------------------------------------------------
470 
471 void CommonControls::render(GLContext* gl)
472 {
473  FW_ASSERT(gl);
474  Mat4f oldVGXform = gl->setVGXform(gl->xformMatchPixels());
475  glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
476  glDisable(GL_DEPTH_TEST);
477  glDisable(GL_CULL_FACE);
478  glEnable(GL_BLEND);
479  glBlendEquation(GL_FUNC_ADD);
480  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
481 
482  bool showControls = m_showControls;
483  bool repaint = false;
484 
485  // Screenshot requested => execute.
486 
487  if (m_screenshot)
488  {
489  // Capture image.
490 
491  const Vec2i& size = gl->getViewSize();
493  glUseProgram(0);
494  glWindowPos2i(0, 0);
495  glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.getMutablePtr());
496 
497  // Display the captured image immediately.
498 
499  for (int i = 0; i < 3; i++)
500  {
501  glDrawPixels(size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPtr());
502  gl->swapBuffers();
503  }
504  glDrawPixels(size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPtr());
505  showControls = false;
506  repaint = true;
507 
508  // Export.
509 
511  image.flipY();
512  exportImage(name, &image);
513  message(sprintf("Saved screenshot to '%s'", name.getPtr()));
514  m_screenshot = false;
515  }
516 
517  // Advace time.
518 
519  F32 timeDelta = m_timer.end();
520 
521  // Draw toggles.
522 
523  for (int i = 0; i < m_toggles.getSize(); i++)
524  {
525  Toggle* t = m_toggles[i];
526  F32 fade = updateHighlightFade(&t->highlightTime);
527  bool down = (!t->isButton || (m_activeToggle == i && m_dragging));
528  if (!showControls || !t->visible || t->isSeparator)
529  continue;
530 
531  drawPanel(gl, t->pos + t->size * 0.5f, t->size,
532  0x80808080, (down) ? 0x80000000 : 0x80FFFFFF, (down) ? 0x80FFFFFF : 0x80000000);
533 
534  if (t->isButton)
535  drawPanel(gl, t->pos + t->size * 0.5f, t->size - 2.0f,
536  0x80808080, (down) ? 0xFF000000 : 0xFFFFFFFF, (down) ? 0xFFFFFFFF : 0xFF000000);
537 
538  if (!t->isButton)
539  {
540  if ((t->boolTarget && *t->boolTarget) ||
541  (t->enumTarget && *t->enumTarget == t->enumValue))
542  {
543  drawPanel(gl, t->pos + t->size * 0.5f, t->size - 4.0f,
544  0x80808080, 0xFFFFFFFF, 0xFF000000);
545  }
546  }
547 
548  if (fade < 1.0f && m_activeToggle != i)
549  {
550  gl->drawLabel(t->title,
551  t->pos + Vec2f(-5.0f, t->size.y * 0.5f), Vec2f(1.0f, 0.5f),
552  fadeABGR(0xFFFFFFFF, fade));
553 
554  repaint = true;
555  }
556  }
557 
558  // Draw sliders.
559 
560  for (int i = 0; i < m_sliders.getSize(); i++)
561  {
562  Slider* s = m_sliders[i];
563  F32 delta = 0.0f;
564  if (m_window->isKeyDown(s->increaseKey->id))
565  delta += 1.0f;
566  if (m_window->isKeyDown(s->decreaseKey->id))
567  delta -= 1.0f;
568  delta *= getKeyBoost();
569 
570  if (delta != 0.0f)
571  {
572  setSliderValue(s, getSliderValue(s, true) + delta * timeDelta * s->speed);
573  s->highlightTime = FW_F32_MAX;
574  repaint = true;
575  }
576 
577  F32 fade = updateHighlightFade(&s->highlightTime);
578  bool down = (m_activeSlider == i && m_dragging);
579  if (!showControls || !s->visible)
580  continue;
581 
582  drawPanel(gl, s->pos + s->size * 0.5f, s->size,
583  0x80808080, 0x80000000, 0x80FFFFFF);
584 
585  drawPanel(gl, s->blockPos + s->blockSize * 0.5f, s->blockSize,
586  0x80808080, (down) ? 0xFF000000 : 0xFFFFFFFF, (down) ? 0xFFFFFFFF : 0xFF000000);
587 
588  if (fade < 1.0f && m_activeSlider != i)
589  {
590  gl->drawLabel(getSliderLabel(s),
591  Vec2f(s->pos.x - 4.0f, s->blockPos.y + s->blockSize.y * 0.5f),
592  Vec2f(1.0f, 0.5f), fadeABGR(0xFFFFFFFF, fade));
593  repaint = true;
594  }
595  }
596 
597  // Update and draw FPS counter.
598 
599  if (m_showFPS)
600  {
601  m_avgFrameTime = lerp(timeDelta, m_avgFrameTime, exp2(-timeDelta / 0.3f));
602  if (showControls)
603  gl->drawLabel(sprintf("%.2f FPS", 1.0f / m_avgFrameTime),
604  Vec2f(m_rightX - 4.0f, m_viewSize.y - 2.0f),
605  Vec2f(1.0f, 1.0f), 0xFFFFFFFF);
606  repaint = true;
607  }
608 
609  // Draw messages.
610 
611  F32 messageY = 2.0f;
612  for (int i = 0; i < m_messages.getSize(); i++)
613  {
614  Message& msg = m_messages[i];
615  F32 fade = updateHighlightFade(&msg.highlightTime);
616 
617  if (fade >= 1.0f || (i && messageY >= m_viewSize.y))
618  {
619  m_messages.resize(i);
620  break;
621  }
622 
623  if (showControls)
624  gl->drawLabel(msg.string, Vec2f(4.0f, messageY), 0.0f, fadeABGR(msg.abgr, fade));
625  repaint = true;
626  messageY += m_fontHeight;
627  }
628 
629  // Draw active controls.
630 
631  if (showControls)
632  {
633  if (m_activeToggle != -1)
634  {
635  Toggle* t = m_toggles[m_activeToggle];
636  if (t->visible)
637  {
638  gl->drawLabel(t->title,
639  t->pos + Vec2f(-5.0f, t->size.y * 0.5f), Vec2f(1.0f, 0.5f), 0xFFFFFFFF);
640  repaint = true;
641  }
642  }
643  if (m_activeSlider != -1)
644  {
645  Slider* s = m_sliders[m_activeSlider];
646  if (s->visible)
647  {
648  gl->drawLabel(getSliderLabel(s),
649  Vec2f(s->pos.x - 4.0f, s->blockPos.y + s->blockSize.y * 0.5f), Vec2f(1.0f, 0.5f), 0xFFFFFFFF);
650  repaint = true;
651  }
652  }
653  }
654 
655  // Finish up.
656 
657  gl->setVGXform(oldVGXform);
658  glPopAttrib();
659  if (repaint)
660  m_window->repaint();
661  else
662  m_timer.unstart();
663 }
664 
665 //------------------------------------------------------------------------
666 
667 void CommonControls::addToggle(bool* boolTarget, S32* enumTarget, S32 enumValue, bool isButton, const String& key, const String& title, bool* dirtyNotify)
668 {
669  Toggle* t = new Toggle;
670  t->boolTarget = boolTarget;
671  t->enumTarget = enumTarget;
672  t->enumValue = enumValue;
673  t->dirtyNotify = dirtyNotify;
674 
675  t->isButton = isButton;
676  t->isSeparator = (!boolTarget && !enumTarget);
677  t->key = getKey(key);
678  t->title = title;
679  t->highlightTime = -FW_F32_MAX;
680 
681  t->visible = m_controlVisibility;
682  t->pos = Vec2f(0.0f);
683  t->size = Vec2f(0.0f);
684 
685  m_toggles.add(t);
686  t->key->toggles.add(t);
687 
688  if (m_showControls && m_window)
689  m_window->repaint();
690 }
691 
692 //------------------------------------------------------------------------
693 
694 void CommonControls::addSlider(F32* floatTarget, S32* intTarget, F32 minValue, F32 maxValue, bool isExponential, const String& increaseKey, const String& decreaseKey, const String& format, F32 speed, bool* dirtyNotify)
695 {
696  FW_ASSERT(floatTarget || intTarget);
697 
698  Slider* s = new Slider;
699  s->floatTarget = floatTarget;
700  s->intTarget = intTarget;
701  s->dirtyNotify = dirtyNotify;
702 
703  s->slack = 0.0f;
704  s->minValue = minValue;
705  s->maxValue = maxValue;
706  s->isExponential = isExponential;
707  s->increaseKey = getKey(increaseKey);
708  s->decreaseKey = getKey(decreaseKey);
709  s->format = format;
710  s->speed = speed;
711  s->highlightTime = -FW_F32_MAX;
712 
713  s->visible = m_controlVisibility;
714  s->stackWithPrevious = (m_sliderStackBegun && !m_sliderStackEmpty);
715  s->pos = Vec2f(0.0f);
716  s->size = Vec2f(0.0f);
717  s->blockPos = Vec2f(0.0f);
718  s->blockSize = Vec2f(0.0f);
719 
720  m_sliders.add(s);
721  s->increaseKey->sliderIncrease.add(s);
722  s->decreaseKey->sliderDecrease.add(s);
723 
724  m_sliderStackEmpty = false;
725 
726  if (m_showControls && m_window)
727  m_window->repaint();
728 }
729 
730 //------------------------------------------------------------------------
731 
732 CommonControls::Key* CommonControls::getKey(const String& id)
733 {
734  Key** found = m_keyHash.search(id);
735  if (found)
736  return *found;
737 
738  Key* key = new Key;
739  key->id = id;
740  m_keyHash.add(id, key);
741  return key;
742 }
743 
744 //------------------------------------------------------------------------
745 
746 void CommonControls::layout(const Vec2f& viewSize, F32 fontHeight)
747 {
748  // Setup metrics.
749 
750  m_viewSize = viewSize;
751  m_fontHeight = fontHeight;
752  m_rightX = m_viewSize.x;
753 
754  // Layout sliders.
755 
756  F32 sliderW = m_fontHeight;
757  for (int startSlider = m_sliders.getSize() - 1; startSlider >= 0; startSlider--)
758  {
759  int endSlider = startSlider + 1;
760  while (startSlider && m_sliders[startSlider]->stackWithPrevious)
761  startSlider--;
762 
763  int numVisible = 0;
764  for (int i = startSlider; i < endSlider; i++)
765  if (m_sliders[i]->visible)
766  numVisible++;
767  if (!numVisible)
768  continue;
769 
770  m_rightX -= sliderW;
771  F32 sliderY = 0.0f;
772  for (int i = endSlider - 1; i >= startSlider; i--)
773  {
774  Slider* s = m_sliders[i];
775  if (!s->visible)
776  continue;
777 
778  s->size = Vec2f(sliderW, max(floor((viewSize.y - sliderY) / (F32)numVisible + 0.5f), 4.0f));
779  s->pos = Vec2f(m_rightX, sliderY);
780  s->blockSize = Vec2f(sliderW - 2.0f, min((m_fontHeight - 2.0f) * 2.0f, s->size.y * 0.25f));
781  s->blockPos = Vec2f(m_rightX + 1.0f, getSliderY(s, false));
782  sliderY += s->size.y;
783  numVisible--;
784  }
785  }
786 
787  // Layout toggles.
788 
789  Vec2f toggleSize = Vec2f(m_fontHeight + 2.0f);
790  int maxInCol = max((int)(viewSize.y / toggleSize.y), 1);
791  int numInCol = 0;
792  int endIdx = m_toggles.getSize();
793 
794  while (endIdx > 0)
795  {
796  while (endIdx > 0 && (!m_toggles[endIdx - 1]->visible || m_toggles[endIdx - 1]->isSeparator))
797  endIdx--;
798 
799  int startIdx;
800  int numInStrip = 0;
801  for (startIdx = endIdx; startIdx > 0; startIdx--)
802  {
803  const Toggle* t = m_toggles[startIdx - 1];
804  if (!t->visible)
805  continue;
806  if (t->isSeparator)
807  break;
808 
809  numInStrip++;
810  if (numInCol + numInStrip > maxInCol)
811  {
812  numInCol = 0;
813  if (numInStrip > maxInCol)
814  break;
815  }
816  }
817 
818  for (int i = endIdx - 1; i >= startIdx; i--)
819  {
820  Toggle* t = m_toggles[i];
821  if (!t->visible)
822  continue;
823 
824  if (!numInCol)
825  m_rightX -= toggleSize.x;
826  t->pos = Vec2f(m_rightX, numInCol * toggleSize.y);
827  t->size = toggleSize;
828  numInCol++;
829  }
830  endIdx = startIdx;
831  numInCol++;
832  }
833 }
834 
835 //------------------------------------------------------------------------
836 
837 void CommonControls::clearActive(void)
838 {
839  m_activeToggle = -1;
840  m_activeSlider = -1;
841 }
842 
843 //------------------------------------------------------------------------
844 
845 void CommonControls::updateActive(const Vec2f& mousePos)
846 {
847  clearActive();
848 
849  for (int i = 0; i < m_toggles.getSize(); i++)
850  {
851  Toggle* t = m_toggles[i];
852  if (t->visible && !t->isSeparator &&
853  mousePos.x >= t->pos.x && mousePos.x < t->pos.x + t->size.x &&
854  mousePos.y >= t->pos.y && mousePos.y < t->pos.y + t->size.y)
855  {
856  m_activeToggle = i;
857  return;
858  }
859  }
860 
861  for (int i = 0; i < m_sliders.getSize(); i++)
862  {
863  Slider* s = m_sliders[i];
864  if (s->visible &&
865  mousePos.x >= s->blockPos.x && mousePos.x < s->blockPos.x + s->blockSize.x &&
866  mousePos.y >= s->blockPos.y && mousePos.y < s->blockPos.y + s->blockSize.y)
867  {
868  m_activeSlider = i;
869  return;
870  }
871  }
872 }
873 
874 //------------------------------------------------------------------------
875 
876 F32 CommonControls::updateHighlightFade(F32* highlightTime)
877 {
878  *highlightTime = min(*highlightTime, m_timer.getTotal());
879  return (m_timer.getTotal() - *highlightTime) / s_highlightFadeDuration;
880 }
881 
882 //------------------------------------------------------------------------
883 
884 U32 CommonControls::fadeABGR(U32 abgr, F32 fade)
885 {
886  Vec4f color = Vec4f::fromABGR(abgr);
887  color.w *= min((1.0f - fade) * s_highlightFadeSpeed, 1.0f);
888  return color.toABGR();
889 }
890 
891 //------------------------------------------------------------------------
892 
893 void CommonControls::selectToggle(Toggle* t)
894 {
895  FW_ASSERT(t);
896 
897  if (t->boolTarget)
898  *t->boolTarget = (!*t->boolTarget);
899 
900  if (t->enumTarget)
901  {
902  if (*t->enumTarget == t->enumValue)
903  return;
904  *t->enumTarget = t->enumValue;
905  }
906 
907  if (t->dirtyNotify)
908  *t->dirtyNotify = true;
909 }
910 
911 //------------------------------------------------------------------------
912 
913 F32 CommonControls::getSliderY(const Slider* s, bool applySlack) const
914 {
915  return getSliderValue(s, applySlack) * (s->size.y - s->blockSize.y - 3.0f) + s->pos.y + 2.0f;
916 }
917 
918 //------------------------------------------------------------------------
919 
920 void CommonControls::setSliderY(Slider* s, F32 y)
921 {
922  setSliderValue(s, (y - s->pos.y - 2.0f) / (s->size.y - s->blockSize.y - 3.0f));
923 }
924 
925 //------------------------------------------------------------------------
926 
927 F32 CommonControls::getSliderValue(const Slider* s, bool applySlack)
928 {
929  FW_ASSERT(s);
930  F32 raw = (s->floatTarget) ? *s->floatTarget : (F32)*s->intTarget;
931  F32 slacked = raw + ((applySlack) ? s->slack : 0.0f);
932 
933  F32 relative = (s->isExponential) ?
934  (log(slacked) - log(s->minValue)) / (log(s->maxValue) - log(s->minValue)) :
935  (slacked - s->minValue) / (s->maxValue - s->minValue);
936 
937  return clamp(relative, 0.0f, 1.0f);
938 }
939 
940 //------------------------------------------------------------------------
941 
942 void CommonControls::setSliderValue(Slider* s, F32 v)
943 {
944  FW_ASSERT(s);
945  F32 clamped = clamp(v, 0.0f, 1.0f);
946 
947  F32 raw = (s->isExponential) ?
948  exp(lerp(log(s->minValue), log(s->maxValue), clamped)) :
949  lerp(s->minValue, s->maxValue, clamped);
950 
951  bool dirty;
952  if (s->floatTarget)
953  {
954  dirty = (*s->floatTarget != raw);
955  *s->floatTarget = raw;
956  s->slack = 0.0f;
957  }
958  else
959  {
960  S32 rounded = (S32)(raw + ((raw >= 0.0f) ? 0.5f : -0.5f));
961  dirty = (*s->intTarget != rounded);
962  *s->intTarget = rounded;
963  s->slack = raw - (F32)rounded;
964  }
965 
966  if (dirty && s->dirtyNotify)
967  *s->dirtyNotify = true;
968 }
969 
970 //------------------------------------------------------------------------
971 
972 String CommonControls::getSliderLabel(const Slider* s)
973 {
974  FW_ASSERT(s);
975  if (s->floatTarget)
976  return sprintf(s->format.getPtr(), *s->floatTarget);
977  return sprintf(s->format.getPtr(), *s->intTarget);
978 }
979 
980 //------------------------------------------------------------------------
981 
982 void CommonControls::sliderKeyDown(Slider* s, int dir)
983 {
984  FW_ASSERT(s);
985  if (!s->intTarget)
986  return;
987 
988  S32 oldValue = *s->intTarget;
989  *s->intTarget = clamp(*s->intTarget + dir, (S32)s->minValue, (S32)s->maxValue);
990  s->slack = 0.0f;
991 
992  if (*s->intTarget != oldValue && s->dirtyNotify)
993  *s->dirtyNotify = true;
994 }
995 
996 //------------------------------------------------------------------------
997 
998 void CommonControls::enterSliderValue(Slider* s)
999 {
1000  FW_ASSERT(s);
1001  m_window->setVisible(false);
1002  //m_window.showModalMessage(sprintf("Please enter in text window: %s", s->getSliderLabel().getPtr()));
1003  printf(sprintf("\nEnter %s:\n", getSliderLabel(s).getPtr()).getPtr());
1004 
1005  // Much like setSliderValue()
1006  // (FIXME Annoying thing about scanf, if you just hit Enter, it keeps reading)
1007  bool dirty = false;
1008  if (s->floatTarget)
1009  {
1010  float fval;
1011  if (scanf_s("%g", &fval))
1012  {
1013  dirty = (*s->floatTarget != fval);
1014  *s->floatTarget = fval;
1015  s->slack = 0.0f;
1016  }
1017  else
1018  {
1019  printf("No value entered.\n");
1020  scanf_s("%*s"); // flush line
1021  }
1022  }
1023  else
1024  {
1025  int ival;
1026  if (scanf_s("%d", &ival))
1027  {
1028  dirty = (*s->intTarget != ival);
1029  *s->intTarget = ival;
1030  s->slack = 0.0f;
1031  }
1032  else
1033  {
1034  printf("No value entered.\n");
1035  scanf_s("%*s"); // flush line
1036  }
1037  }
1038 
1039  if (dirty && s->dirtyNotify)
1040  *s->dirtyNotify = true;
1041 
1042  m_window->setVisible(true); // FIXME pause if error msg
1043 }
1044 
1045 //------------------------------------------------------------------------
1046 
1047 void CommonControls::drawPanel(GLContext* gl, const Vec2f& pos, const Vec2f& size, U32 interiorABGR, U32 topLeftABGR, U32 bottomRightABGR)
1048 {
1049  // Setup vertex attributes.
1050 
1051  Vec2f p = gl->getViewScale();
1052  Vec2f c = pos * p - 1.0f;
1053  Vec2f r = (size * 0.5f - 1.0f) * p;
1054  Vec2f px(p.x, 0.0f);
1055  Vec2f py(0.0f, p.y);
1056  Vec2f rx(r.x, 0.0f);
1057  Vec2f ry(0.0f, r.y);
1058 
1059  Vec2f posAttrib[] =
1060  {
1061  c + r, c - rx + ry, c + rx - ry, c - r,
1062  c - r, c - r - py, c + rx - ry, c + rx - ry + px - py, c + r, c + r + px,
1063  c + r + px, c + r + p, c - rx + ry, c - rx + ry - px + py, c - r - py, c - r - p,
1064  };
1065 
1066  Vec4f in = Vec4f::fromABGR(interiorABGR);
1067  Vec4f tl = Vec4f::fromABGR(topLeftABGR);
1068  Vec4f br = Vec4f::fromABGR(bottomRightABGR);
1069 
1070  Vec4f colorAttrib[] =
1071  {
1072  in, in, in, in,
1073  br, br, br, br, br, br,
1074  tl, tl, tl, tl, tl, tl,
1075  };
1076 
1077  // Create program.
1078 
1079  static const char* progId = "CommonControls::drawPanel";
1080  GLContext::Program* prog = gl->getProgram(progId);
1081  if (!prog)
1082  {
1083  prog = new GLContext::Program(
1085  attribute vec2 posAttrib;
1086  attribute vec4 colorAttrib;
1087  varying vec4 colorVarying;
1088  void main()
1089  {
1090  gl_Position = vec4(posAttrib, 0.0, 1.0);
1091  colorVarying = colorAttrib;
1092  }
1093  ),
1095  varying vec4 colorVarying;
1096  void main()
1097  {
1098  gl_FragColor = colorVarying;
1099  }
1100  ));
1101  gl->setProgram(progId, prog);
1102  }
1103 
1104  // Draw.
1105 
1106  prog->use();
1107  gl->setAttrib(prog->getAttribLoc("posAttrib"), 2, GL_FLOAT, 0, posAttrib);
1108  gl->setAttrib(prog->getAttribLoc("colorAttrib"), 4, GL_FLOAT, 0, colorAttrib);
1109  glDrawArrays(GL_TRIANGLE_STRIP, 0, FW_ARRAY_SIZE(posAttrib));
1110  gl->resetAttribs();
1111 }
1112 
1113 //------------------------------------------------------------------------
void exportImage(const String &fileName, const Image *image)
Definition: Image.cpp:1069
bool saveStateDialog(void)
F32 getTotal(void) const
Definition: Timer.hpp:47
#define NULL
Definition: Defs.hpp:39
#define FW_F32_MAX
Definition: Defs.hpp:118
int getFontHeight(void) const
Definition: GLContext.hpp:190
const char * getPtr(void) const
Definition: String.hpp:51
virtual ~CommonControls(void)
Mat4f setVGXform(const Mat4f &m)
Definition: GLContext.hpp:171
FW_CUDA_FUNC F64 exp(F64 a)
Definition: Math.hpp:46
void showControls(bool show)
#define GL_FUNC_ADD
Definition: DLLImports.hpp:162
const char * name
Definition: DLLImports.cpp:42
void swapBuffers(void)
Definition: GLContext.cpp:276
void setError(const char *fmt,...)
Definition: Defs.cpp:253
bool loadStateDialog(void)
Vec2i drawLabel(const String &str, const Vec4f &pos, const Vec2f &align, U32 fgABGR, U32 bgABGR)
Definition: GLContext.cpp:704
void unstart(void)
Definition: Timer.hpp:43
String clearError(void)
Definition: Defs.cpp:269
void addToggle(bool *target, const String &key, const String &title, bool *dirtyNotify=NULL)
unsigned __int64 U64
Definition: Defs.hpp:97
void addSlider(F32 *target, F32 minValue, F32 maxValue, bool isExponential, const String &increaseKey, const String &decreaseKey, const String &format, F32 speed=0.25f, bool *dirtyNotify=NULL)
U32 toABGR(void) const
Definition: Math.cpp:45
Vec2i mouseDelta
Definition: Window.hpp:75
CommonControls(U32 features=Feature_Default)
F32 getKeyBoost(void) const
FW_CUDA_FUNC F32 floor(F32 a)
Definition: Math.hpp:59
void setProgram(const String &id, Program *prog)
Definition: GLContext.cpp:875
bool mouseDragging
Definition: Window.hpp:76
Window * window
Definition: Window.hpp:79
void clear(void)
Definition: Array.hpp:359
bool loadState(const String &fileName)
#define FW_KEY_CONTROL
Definition: Keys.hpp:70
#define FW_KEY_PRINT_SCREEN
Definition: Keys.hpp:140
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum target
Definition: DLLImports.inl:315
bool restoreError(const String &old)
Definition: Defs.cpp:278
void toggleFullScreen(void)
Definition: Window.hpp:108
void repaint(void)
Definition: Window.cpp:216
String getScreenshotFileName(void) const
float F32
Definition: Defs.hpp:89
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat y
Definition: DLLImports.inl:363
#define FW_KEY_F5
Definition: Keys.hpp:85
Program * getProgram(const String &id) const
Definition: GLContext.cpp:867
bool removeItem(const T &item)
Definition: Array.hpp:577
int main(int argc, char *argv[])
Definition: Main.cpp:51
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v
Definition: DLLImports.inl:329
GLint getAttribLoc(const String &name) const
Definition: GLContext.cpp:88
const String & getError(void)
Definition: Defs.cpp:296
void setAttrib(int loc, int size, GLenum type, int stride, Buffer *buffer, const void *pointer)
Definition: GLContext.cpp:310
#define FW_KEY_ESCAPE
Definition: Keys.hpp:160
void readFully(void *ptr, int size)
Definition: Stream.cpp:36
FW_CUDA_FUNC T min(const VectorBase< T, L, S > &v)
Definition: Math.hpp:461
void setVisible(bool visible)
Definition: Window.cpp:138
FW_CUDA_FUNC T max(const VectorBase< T, L, S > &v)
Definition: Math.hpp:462
#define FW_KEY_MOUSE_MIDDLE
Definition: Keys.hpp:40
#define FW_KEY_F4
Definition: Keys.hpp:84
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value glUseProgram
Definition: DLLImports.inl:361
#define FW_ASSERT(X)
Definition: Defs.hpp:67
String showFileSaveDialog(const String &title, const String &filters="", const String &initialDir="", bool forceInitialDir=false)
Definition: Window.hpp:136
signed int S32
Definition: Defs.hpp:88
int getLength(void) const
Definition: String.hpp:49
String showFileLoadDialog(const String &title, const String &filters="", const String &initialDir="", bool forceInitialDir=false)
Definition: Window.hpp:135
F32 end(void)
Definition: Timer.hpp:69
#define FW_KEY_SPACE
Definition: Keys.hpp:161
bool isKeyDown(const String &key) const
Definition: Window.hpp:128
Mat4f xformMatchPixels(void) const
Definition: GLContext.hpp:152
T & add(void)
Definition: Array.hpp:384
String sprintf(const char *fmt,...)
Definition: Defs.cpp:241
void resetAttribs(void)
Definition: GLContext.cpp:323
GLContext * getGL(void)
Definition: Window.cpp:203
F32 exp2(F32 a)
Definition: Math.hpp:87
#define FW_KEY_ALT
Definition: Keys.hpp:55
unsigned int U32
Definition: Defs.hpp:85
bool hasError(void)
Definition: Defs.cpp:289
T & insert(S idx)
Definition: Array.hpp:419
String getStateFileName(int idx) const
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction f
Definition: DLLImports.inl:88
#define FW_KEY_F11
Definition: Keys.hpp:91
#define FW_KEY_F10
Definition: Keys.hpp:90
void printf(const char *fmt,...)
Definition: Defs.cpp:225
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: DLLImports.inl:349
virtual void write(const void *ptr, int size)
Definition: File.cpp:278
void flashButtonTitles(void)
#define FW_ARRAY_SIZE(X)
Definition: Defs.hpp:79
FW_CUDA_FUNC F64 log(F64 a)
Definition: Math.hpp:47
#define FW_KEY_MOUSE_LEFT
Definition: Keys.hpp:38
static Vec4f fromABGR(U32 abgr)
Definition: Math.cpp:34
EventType type
Definition: Window.hpp:69
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void * p
Definition: DLLImports.inl:66
const Vec2i & getViewSize(void) const
Definition: GLContext.hpp:148
const Vec2f & getViewScale(void) const
Definition: GLContext.hpp:149
#define FW_GL_SHADER_SOURCE(CODE)
Definition: GLContext.hpp:43
virtual bool handleEvent(const Window::Event &ev)
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void * image
Definition: DLLImports.inl:60
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr size
Definition: DLLImports.inl:319
void removeControl(const void *target)
#define FW_KEY_F9
Definition: Keys.hpp:89
void resize(S size)
Definition: Array.hpp:366
bool saveState(const String &fileName)
S getSize(void) const
Definition: Array.hpp:188
T remove(S idx)
Definition: Array.hpp:449
void requestClose(void)
Definition: Window.cpp:261
FW_CUDA_FUNC A lerp(const A &a, const A &b, const B &t)
Definition: Math.hpp:115
CUdevice int ordinal char int CUdevice dev CUdevprop CUdevice dev CUcontext ctx CUcontext ctx CUcontext pctx CUmodule const void image CUmodule const void fatCubin CUfunction CUmodule const char name void p CUfunction unsigned int bytes CUtexref pTexRef CUtexref CUarray unsigned int Flags CUtexref int CUaddress_mode am CUtexref unsigned int Flags CUaddress_mode CUtexref int dim CUarray_format int CUtexref hTexRef CUfunction unsigned int numbytes CUfunction int float value CUfunction int CUtexref hTexRef CUfunction int int grid_height CUevent unsigned int Flags CUevent hEvent CUevent hEvent CUstream unsigned int Flags CUstream hStream GLuint bufferobj unsigned int CUdevice dev CUdeviceptr unsigned int CUmodule const char name CUdeviceptr unsigned int bytesize CUdeviceptr dptr void unsigned int bytesize void CUdeviceptr unsigned int ByteCount CUarray unsigned int CUdeviceptr unsigned int ByteCount CUarray unsigned int const void unsigned int ByteCount CUarray unsigned int CUarray unsigned int unsigned int ByteCount void CUarray unsigned int unsigned int CUstream hStream const CUDA_MEMCPY2D pCopy CUdeviceptr const void unsigned int CUstream hStream const CUDA_MEMCPY2D CUstream hStream CUdeviceptr unsigned char unsigned int N CUdeviceptr unsigned int unsigned int N CUdeviceptr unsigned int unsigned short unsigned int unsigned int Height CUarray const CUDA_ARRAY_DESCRIPTOR pAllocateArray CUarray const CUDA_ARRAY3D_DESCRIPTOR pAllocateArray unsigned int CUtexref CUdeviceptr unsigned int bytes CUcontext unsigned int CUdevice device GLenum texture GLenum GLuint buffer GLenum GLuint renderbuffer GLenum GLsizeiptr const GLvoid GLenum usage GLuint shader GLenum type GLsizei const GLuint framebuffers GLsizei const GLuint renderbuffers GLuint v GLuint v GLenum GLenum GLenum GLuint GLint level GLsizei GLuint framebuffers GLuint const GLchar name GLenum GLintptr GLsizeiptr GLvoid data GLuint GLenum GLint param GLuint GLenum GLint param GLhandleARB programObj GLenum GLenum GLsizei GLsizei height GLenum GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid pixels GLint GLsizei const GLfloat value GLint GLfloat GLfloat v1 GLint GLfloat GLfloat GLfloat v2 GLint GLsizei const GLfloat value GLint GLsizei GLboolean const GLfloat value GLuint program GLuint GLfloat GLfloat GLfloat z GLuint GLint GLenum GLboolean GLsizei const GLvoid pointer GLuint GLuint color
Definition: DLLImports.inl:367
void message(const String &str, const String &volatileID="", U32 abgr=0xffffffffu)