dbgui.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /** @addtogroup Debug
  2. @{*/
  3. /**
  4. * \defgroup DebugUI Debug UI API
  5. \brief Immediate mode debug UI API
  6. * @{
  7. Per frame usage example:
  8. @code
  9. bool m_ShowDbgUI = false;
  10. int m_DbgListSelection = 0;
  11. float m_DbgSliderValue = 0.0;
  12. autoptr array<string> m_DbgOptions = {"jedna", "dva", "tri"};
  13. void OnUpdate(float timeslice)
  14. {
  15. DbgUI.Begin("Test");
  16. DbgUI.Check("Show DbgUI", m_ShowDbgUI);
  17. if (m_ShowDbgUI)
  18. {
  19. DbgUI.Text("DbgUI Test");
  20. string name = "";
  21. DbgUI.InputText("name", name);
  22. if (DbgUI.Button("Print name"))
  23. {
  24. Print(name);
  25. }
  26. DbgUI.List("test list", m_DbgListSelection, m_DbgOptions);
  27. DbgUI.Text("Choice = " + m_DbgListSelection.ToString());
  28. DbgUI.Spacer(10);
  29. DbgUI.SliderFloat("slider", m_DbgSliderValue, 0, 100);
  30. DbgUI.Text("Slider value = " + ftoa(m_DbgSliderValue));
  31. }
  32. DbgUI.End();
  33. }
  34. @endcode
  35. For non-per frame usage example:
  36. @code
  37. int m_DbgEventCount = 0;
  38. void OnEvent(EventType eventTypeId, Param params)
  39. {
  40. m_DbgEventCount++;
  41. DbgUI.BeginCleanupScope();
  42. DbgUI.Begin("events", 300, 0);
  43. DbgUI.Text("Events count = " + m_DbgEventCount.ToString());
  44. DbgUI.End();
  45. DbgUI.EndCleanupScope();
  46. }
  47. @endcode
  48. */
  49. class DbgUI
  50. {
  51. private void DbgUI() {}
  52. private void ~DbgUI() {}
  53. static proto native void DoUnitTest(); ///< Creates all possible DbgUI widgets. Just for the testing purposes.
  54. static proto native void Text(string label);
  55. static proto native void ColoredText(int color, string label);
  56. static proto void Check(string label, out bool checked);
  57. static proto void Combo(string label, out int selection, TStringArray elems);
  58. static proto void List(string label, out int selection, TStringArray elems);
  59. static proto void SliderFloat(string label, out float value, float min, float max, int pxWidth = 150);
  60. static proto native void Spacer(int height);
  61. static proto native void Panel(string label, int width, int height, int color = 0xaa555555);
  62. static proto native bool Button(string txt, int minWidth = 0);
  63. static proto void InputText(string txt, out string value, int pxWidth = 150);
  64. static proto void InputInt(string txt, out int value, int pxWidth = 150);
  65. static proto void InputFloat(string txt, out float value, int pxWidth = 150);
  66. static proto native void PlotLive(string label, int sizeX, int sizeY, float val, int timeStep = 100, int historySize = 30, int color = 0xFFFFFFFF);
  67. static proto native void SameLine();
  68. static proto native void SameSpot();
  69. static proto native void PushID_Int(int int_id);
  70. static proto native void PushID_Str(string str_id);
  71. static proto native void PopID();
  72. static proto void BeginCleanupScope();
  73. static proto native void EndCleanupScope();
  74. static proto native void Begin(string windowTitle, float x = 0, float y = 0);
  75. static proto native void End();
  76. //! Draw an "override" checkbox that unrolls into a slider in provided range when checked
  77. static bool FloatOverride(string id, inout float value, float min, float max, int precision = 1000, bool sameLine = true)
  78. {
  79. if (sameLine)
  80. DbgUI.SameLine();
  81. bool enable;
  82. DbgUI.PushID_Str(id+"_override");
  83. DbgUI.Check("override", enable);
  84. DbgUI.PopID();
  85. if (enable)
  86. {
  87. DbgUI.SameLine();
  88. float tmp = value * (float)precision;
  89. DbgUI.PushID_Str(id+"_slider");
  90. DbgUI.SliderFloat("", tmp, min * (float)precision, max * (float)precision);
  91. DbgUI.PopID();
  92. tmp = tmp / (float)precision;
  93. DbgUI.SameSpot();
  94. DbgUI.PushID_Str(id+"_slider_text");
  95. DbgUI.Text(tmp.ToString());
  96. DbgUI.PopID();
  97. value = tmp;
  98. return true;
  99. }
  100. return false;
  101. }
  102. };
  103. //@}
  104. //@}