imgui.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. // This code is based on:
  6. //
  7. // Copyright (c) 2009-2010 Mikko Mononen [email protected]
  8. //
  9. // This software is provided 'as-is', without any express or implied
  10. // warranty. In no event will the authors be held liable for any damages
  11. // arising from the use of this software.
  12. // Permission is granted to anyone to use this software for any purpose,
  13. // including commercial applications, and to alter it and redistribute it
  14. // freely, subject to the following restrictions:
  15. // 1. The origin of this software must not be misrepresented; you must not
  16. // claim that you wrote the original software. If you use this software
  17. // in a product, an acknowledgment in the product documentation would be
  18. // appreciated but is not required.
  19. // 2. Altered source versions must be plainly marked as such, and must not be
  20. // misrepresented as being the original software.
  21. // 3. This notice may not be removed or altered from any source distribution.
  22. //
  23. // Source altered and distributed from https://github.com/AdrienHerubel/imgui
  24. #ifndef IMGUI_H_HEADER_GUARD
  25. #define IMGUI_H_HEADER_GUARD
  26. #include <bgfx.h>
  27. #define IMGUI_MBUT_LEFT 0x01
  28. #define IMGUI_MBUT_RIGHT 0x02
  29. /// For custom values, define these macros before including imgui.h
  30. #ifndef IMGUI_SCROLL_AREA_R
  31. # define IMGUI_SCROLL_AREA_R 6
  32. #endif //IMGUI_SCROLL_AREA_R
  33. #ifndef IMGUI_SCROLL_BAR_R
  34. # define IMGUI_SCROLL_BAR_R 5
  35. #endif //IMGUI_SCROLL_BAR_R
  36. #ifndef IMGUI_BUTTON_R
  37. # define IMGUI_BUTTON_R 9
  38. #endif //IMGUI_BUTTON_R
  39. #ifndef IMGUI_BUTTON_RGB0
  40. # define IMGUI_BUTTON_RGB0 imguiRGBA(128, 128, 128, 0)
  41. #endif //IMGUI_BUTTON_RGB0
  42. #ifndef IMGUI_INPUT_R
  43. # define IMGUI_INPUT_R 4
  44. #endif //IMGUI_INPUT_R
  45. #ifndef IMGUI_TABS_HEIGHT
  46. # define IMGUI_TABS_HEIGHT 20
  47. #endif //IMGUI_TABS_HEIGHT
  48. #ifndef IMGUI_TABS_R
  49. # define IMGUI_TABS_R 9
  50. #endif //IMGUI_TABS_R
  51. #ifndef IMGUI_INDENT_VALUE
  52. # define IMGUI_INDENT_VALUE 16
  53. #endif //IMGUI_INDENT_VALUE
  54. #ifndef IMGUI_SEPARATOR_VALUE
  55. # define IMGUI_SEPARATOR_VALUE 12
  56. #endif //IMGUI_SEPARATOR_VALUE
  57. struct ImguiTextAlign
  58. {
  59. enum Enum
  60. {
  61. Left,
  62. Center,
  63. Right,
  64. Count
  65. };
  66. };
  67. struct ImguiAlign
  68. {
  69. enum Enum
  70. {
  71. Left,
  72. LeftIndented,
  73. Center,
  74. CenterIndented,
  75. Right,
  76. };
  77. };
  78. struct ImguiBorder
  79. {
  80. enum Enum
  81. {
  82. Left,
  83. Right,
  84. Top,
  85. Bottom
  86. };
  87. };
  88. inline uint32_t imguiRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
  89. {
  90. return 0
  91. | (uint32_t(_r) << 0)
  92. | (uint32_t(_g) << 8)
  93. | (uint32_t(_b) << 16)
  94. | (uint32_t(_a) << 24)
  95. ;
  96. }
  97. BGFX_HANDLE(ImguiFontHandle);
  98. ImguiFontHandle imguiCreateFont(const void* _data, float _fontSize=15.0f);
  99. void imguiSetFont(ImguiFontHandle _handle);
  100. ImguiFontHandle imguiGetCurrentFont();
  101. ImguiFontHandle imguiCreate(const void* _data, float _fontSize=15.0f);
  102. void imguiDestroy();
  103. void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, char _inputChar = 0, uint8_t _view = 31);
  104. void imguiEndFrame();
  105. void imguiDrawText(int _x, int _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb);
  106. void imguiDrawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _argb);
  107. void imguiDrawRoundedRect(float _x, float _y, float _w, float _h, float _r, uint32_t _argb);
  108. void imguiDrawRect(float _x, float _y, float _w, float _h, uint32_t _argb);
  109. /// Notice: this function is not to be called between imguiBeginArea() and imguiEndArea().
  110. bool imguiBorderButton(ImguiBorder::Enum _border, bool _checked, bool _enabled = true);
  111. bool imguiBeginArea(const char* _name, int _x, int _y, int _width, int _height, bool _enabled = true, int32_t _r = IMGUI_SCROLL_AREA_R);
  112. void imguiEndArea();
  113. bool imguiBeginScroll(int32_t _height, int32_t* _scroll, bool _enabled = true);
  114. void imguiEndScroll(int32_t _r = IMGUI_SCROLL_BAR_R);
  115. bool imguiBeginScrollArea(const char* _name, int _x, int _y, int _width, int _height, int* _scroll, bool _enabled = true, int32_t _r = IMGUI_SCROLL_AREA_R);
  116. void imguiEndScrollArea(int32_t _r = IMGUI_SCROLL_BAR_R);
  117. void imguiIndent(uint16_t _width = IMGUI_INDENT_VALUE);
  118. void imguiUnindent(uint16_t _width = IMGUI_INDENT_VALUE);
  119. void imguiSeparator(uint16_t _height = IMGUI_SEPARATOR_VALUE);
  120. void imguiSeparatorLine(uint16_t _height = IMGUI_SEPARATOR_VALUE);
  121. int32_t imguiGetWidgetX();
  122. int32_t imguiGetWidgetY();
  123. int32_t imguiGetWidgetW();
  124. void imguiSetCurrentScissor(); // Call before drawing custom widgets over imgui area.
  125. bool imguiButton(const char* _text, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, uint32_t _rgb0 = IMGUI_BUTTON_RGB0, int32_t _r = IMGUI_BUTTON_R);
  126. bool imguiItem(const char* _text, bool _enabled = true);
  127. bool imguiCheck(const char* _text, bool _checked, bool _enabled = true);
  128. void imguiBool(const char* _text, bool& _flag, bool _enabled = true);
  129. bool imguiCollapse(const char* _text, const char* _subtext, bool _checked, bool _enabled = true);
  130. void imguiLabel(const char* _format, ...);
  131. void imguiLabel(uint32_t _rgba, const char* _format, ...);
  132. void imguiValue(const char* _text);
  133. bool imguiSlider(const char* _text, float& _val, float _vmin, float _vmax, float _vinc, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
  134. bool imguiSlider(const char* _text, int32_t& _val, int32_t _vmin, int32_t _vmax, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
  135. void imguiInput(const char* _label, char* _str, uint32_t _len, bool _enabled = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, int32_t _r = IMGUI_INPUT_R);
  136. /// Usage example:
  137. /// imguiTabs(0, true, ImguiAlign::CenterIndented, 20, 0, 3, 2, "Tab0", "Tab1", "Tab2", true, false);
  138. /// _nTabs - Number of tabs (in the above example, 3, and their labes are 'Tab0', 'Tab1' and 'Tab2'.
  139. /// _nEnabled - Number of specified 'enabled' flags. All other unspecified tabs are considered enabled by default.
  140. /// In the above example, there are 2 enabled flags: 'Tab0' is specified as enabled and 'Tab1' is specified as disabled.
  141. /// Tab2 is unspecified and therefore is treated as enabled.
  142. uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, uint8_t _nEnabled, ...);
  143. uint8_t imguiTabs(uint8_t _selected, bool _enabled, ImguiAlign::Enum _align, int32_t _height, int32_t _r, uint8_t _nTabs, ...);
  144. uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...);
  145. #define imguiChoose(...) imguiChooseUseMacroInstead(__VA_ARGS__, NULL)
  146. void imguiColorWheel(float _rgb[3], bool _respectIndentation = false, float _size = 0.8f, bool _enabled = true);
  147. void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, float _size = 0.8f, bool _enabled = true);
  148. bool imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true, bool _originBottomLeft = false);
  149. bool imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true, bool _originBottomLeft = false);
  150. bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true);
  151. bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true);
  152. bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, bool _cross = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _enabled = true);
  153. float imguiGetTextLength(const char* _text, ImguiFontHandle _handle);
  154. bool imguiMouseOverArea();
  155. #endif // IMGUI_H_HEADER_GUARD