Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

imgui.h 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. // ImGui library v1.15 wip
  2. // See .cpp file for commentary.
  3. // See ImGui::ShowTestWindow() for sample code.
  4. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
  5. // Get latest version at https://github.com/ocornut/imgui
  6. #pragma once
  7. struct ImDrawList;
  8. struct ImBitmapFont;
  9. struct ImGuiAabb;
  10. struct ImGuiIO;
  11. struct ImGuiStorage;
  12. struct ImGuiStyle;
  13. struct ImGuiWindow;
  14. #include "imconfig.h"
  15. #include <float.h> // FLT_MAX
  16. #include <stdarg.h> // va_list
  17. #include <stddef.h> // ptrdiff_t
  18. #include <stdlib.h> // NULL, malloc
  19. #ifndef IM_ASSERT
  20. #include <assert.h>
  21. #define IM_ASSERT(_EXPR) assert(_EXPR)
  22. #endif
  23. typedef unsigned int ImU32;
  24. typedef unsigned short ImWchar;
  25. typedef ImU32 ImGuiID;
  26. typedef int ImGuiCol; // enum ImGuiCol_
  27. typedef int ImGuiKey; // enum ImGuiKey_
  28. typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_
  29. typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_
  30. typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
  31. typedef ImBitmapFont* ImFont;
  32. struct ImVec2
  33. {
  34. float x, y;
  35. ImVec2() {}
  36. ImVec2(float _x, float _y) { x = _x; y = _y; }
  37. #ifdef IM_VEC2_CLASS_EXTRA
  38. IM_VEC2_CLASS_EXTRA
  39. #endif
  40. };
  41. struct ImVec4
  42. {
  43. float x, y, z, w;
  44. ImVec4() {}
  45. ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }
  46. #ifdef IM_VEC4_CLASS_EXTRA
  47. IM_VEC4_CLASS_EXTRA
  48. #endif
  49. };
  50. namespace ImGui
  51. {
  52. // Proxy functions to access the MemAllocFn/MemFreeFn/MemReallocFn pointers in ImGui::GetIO(). The only reason they exist here is to allow ImVector<> to compile inline.
  53. void* MemAlloc(size_t sz);
  54. void MemFree(void* ptr);
  55. void* MemRealloc(void* ptr, size_t sz);
  56. }
  57. // std::vector<> like class to avoid dragging dependencies (also: windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug).
  58. // Use '#define ImVector std::vector' if you want to use the STL type or your own type.
  59. // Our implementation does NOT call c++ constructors! because the data types we use don't need them (but that could be added as well). Only provide the minimum functionalities we need.
  60. #ifndef ImVector
  61. template<typename T>
  62. class ImVector
  63. {
  64. private:
  65. size_t Size;
  66. size_t Capacity;
  67. T* Data;
  68. public:
  69. typedef T value_type;
  70. typedef value_type* iterator;
  71. typedef const value_type* const_iterator;
  72. ImVector() { Size = Capacity = 0; Data = NULL; }
  73. ~ImVector() { if (Data) ImGui::MemFree(Data); }
  74. inline bool empty() const { return Size == 0; }
  75. inline size_t size() const { return Size; }
  76. inline size_t capacity() const { return Capacity; }
  77. inline value_type& at(size_t i) { IM_ASSERT(i < Size); return Data[i]; }
  78. inline const value_type& at(size_t i) const { IM_ASSERT(i < Size); return Data[i]; }
  79. inline value_type& operator[](size_t i) { IM_ASSERT(i < Size); return Data[i]; }
  80. inline const value_type& operator[](size_t i) const { IM_ASSERT(i < Size); return Data[i]; }
  81. inline void clear() { if (Data) { Size = Capacity = 0; ImGui::MemFree(Data); Data = NULL; } }
  82. inline iterator begin() { return Data; }
  83. inline const_iterator begin() const { return Data; }
  84. inline iterator end() { return Data + Size; }
  85. inline const_iterator end() const { return Data + Size; }
  86. inline value_type& front() { return at(0); }
  87. inline const value_type& front() const { return at(0); }
  88. inline value_type& back() { IM_ASSERT(Size > 0); return at(Size-1); }
  89. inline const value_type& back() const { IM_ASSERT(Size > 0); return at(Size-1); }
  90. inline void swap(ImVector<T>& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; }
  91. inline void reserve(size_t new_capacity) { Data = (value_type*)ImGui::MemRealloc(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; }
  92. inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; }
  93. inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; }
  94. inline void pop_back() { IM_ASSERT(Size > 0); Size--; }
  95. inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const ptrdiff_t off = it - begin(); memmove(Data + off, Data + off + 1, (Size - off - 1) * sizeof(value_type)); Size--; return Data + off; }
  96. inline void insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const ptrdiff_t off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - off) * sizeof(value_type)); Data[off] = v; Size++; }
  97. };
  98. #endif // #ifndef ImVector
  99. // Helpers at bottom of the file:
  100. // - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only
  101. // - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  102. // - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
  103. // - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
  104. // - struct ImDrawList // Draw command list
  105. // - struct ImBitmapFont // Bitmap font loader
  106. // ImGui End-user API
  107. // In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types)
  108. namespace ImGui
  109. {
  110. // Main
  111. ImGuiIO& GetIO();
  112. ImGuiStyle& GetStyle();
  113. void NewFrame();
  114. void Render();
  115. void Shutdown();
  116. void ShowUserGuide();
  117. void ShowStyleEditor(ImGuiStyle* ref = NULL);
  118. void ShowTestWindow(bool* open = NULL);
  119. // Window
  120. bool Begin(const char* name = "Debug", bool* open = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0); // return false when window is collapsed, so you can early out in your code.
  121. void End();
  122. void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0);
  123. void EndChild();
  124. bool GetWindowIsFocused();
  125. ImVec2 GetWindowSize();
  126. float GetWindowWidth();
  127. void SetWindowSize(const ImVec2& size); // set to ImVec2(0,0) to force an auto-fit
  128. ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing.
  129. void SetWindowPos(const ImVec2& pos); // set current window pos.
  130. ImVec2 GetWindowContentRegionMin();
  131. ImVec2 GetWindowContentRegionMax();
  132. ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
  133. ImFont GetWindowFont();
  134. float GetWindowFontSize();
  135. void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together.
  136. void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
  137. void SetKeyboardFocusHere(int offset = 0); // focus keyboard on the next widget. Use 'offset' to access sub components of a multiple component widget.
  138. void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
  139. ImGuiStorage* GetTreeStateStorage();
  140. void PushItemWidth(float item_width);
  141. void PopItemWidth();
  142. float GetItemWidth();
  143. void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
  144. void PopAllowKeyboardFocus();
  145. void PushStyleColor(ImGuiCol idx, const ImVec4& col);
  146. void PopStyleColor();
  147. // Tooltip
  148. void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins.
  149. void SetTooltipV(const char* fmt, va_list args);
  150. void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text.
  151. void EndTooltip();
  152. // Layout
  153. void Separator(); // horizontal line
  154. void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally
  155. void Spacing();
  156. void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns
  157. void NextColumn(); // next column
  158. float GetColumnOffset(int column_index = -1);
  159. void SetColumnOffset(int column_index, float offset);
  160. float GetColumnWidth(int column_index = -1);
  161. ImVec2 GetCursorPos(); // cursor position is relative to window position
  162. void SetCursorPos(const ImVec2& pos); // "
  163. void SetCursorPosX(float x); // "
  164. void SetCursorPosY(float y); // "
  165. ImVec2 GetCursorScreenPos(); // cursor position in screen space
  166. void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets.
  167. float GetTextLineSpacing();
  168. float GetTextLineHeight();
  169. // ID scopes
  170. void PushID(const char* str_id);
  171. void PushID(const void* ptr_id);
  172. void PushID(const int int_id);
  173. void PopID();
  174. // Widgets
  175. void Text(const char* fmt, ...);
  176. void TextV(const char* fmt, va_list args);
  177. void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut to doing PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
  178. void TextColoredV(const ImVec4& col, const char* fmt, va_list args);
  179. void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, better for long chunks of text.
  180. void LabelText(const char* label, const char* fmt, ...);
  181. void LabelTextV(const char* label, const char* fmt, va_list args);
  182. void BulletText(const char* fmt, ...);
  183. void BulletTextV(const char* fmt, va_list args);
  184. bool Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false);
  185. bool SmallButton(const char* label);
  186. bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
  187. bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders.
  188. bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
  189. bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
  190. bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
  191. bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians
  192. bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f");
  193. void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
  194. void PlotLines(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
  195. void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float));
  196. void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0));
  197. bool Checkbox(const char* label, bool* v);
  198. bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
  199. bool RadioButton(const char* label, bool active);
  200. bool RadioButton(const char* label, int* v, int v_button);
  201. bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0);
  202. bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0);
  203. bool InputFloat2(const char* label, float v[2], int decimal_precision = -1);
  204. bool InputFloat3(const char* label, float v[3], int decimal_precision = -1);
  205. bool InputFloat4(const char* label, float v[4], int decimal_precision = -1);
  206. bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0);
  207. bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7);
  208. bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7); // Separate items with \0, end item-list with \0\0
  209. bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7);
  210. bool ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true);
  211. bool ColorEdit3(const char* label, float col[3]);
  212. bool ColorEdit4(const char* label, float col[4], bool show_alpha = true);
  213. void ColorEditMode(ImGuiColorEditMode mode);
  214. bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop
  215. bool TreeNode(const char* str_id, const char* fmt, ...); // "
  216. bool TreeNode(const void* ptr_id, const char* fmt, ...); // "
  217. bool TreeNodeV(const char* str_id, const char* fmt, va_list args); // "
  218. bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // "
  219. void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
  220. void TreePush(const void* ptr_id = NULL); // "
  221. void TreePop();
  222. void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader
  223. // Value helper output "name: value"
  224. // Freely declare your own in the ImGui namespace.
  225. void Value(const char* prefix, bool b);
  226. void Value(const char* prefix, int v);
  227. void Value(const char* prefix, unsigned int v);
  228. void Value(const char* prefix, float v, const char* float_format = NULL);
  229. void Color(const char* prefix, const ImVec4& v);
  230. void Color(const char* prefix, unsigned int v);
  231. // Logging
  232. void LogButtons();
  233. void LogToTTY(int max_depth = -1);
  234. void LogToFile(int max_depth = -1, const char* filename = NULL);
  235. void LogToClipboard(int max_depth = -1);
  236. // Utilities
  237. void SetNewWindowDefaultPos(const ImVec2& pos); // set position of window that do
  238. bool IsHovered(); // was the last item active area hovered by mouse?
  239. ImVec2 GetItemBoxMin(); // get bounding box of last item
  240. ImVec2 GetItemBoxMax(); // get bounding box of last item
  241. bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimisation)
  242. bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry
  243. bool IsMouseClicked(int button, bool repeat = false);
  244. bool IsMouseDoubleClicked(int button);
  245. bool IsMouseHoveringWindow(); // is mouse hovering current window ("window" in API names always refer to current window)
  246. bool IsMouseHoveringAnyWindow(); // is mouse hovering any active imgui window
  247. bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max); // is mouse hovering given bounding box
  248. bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window
  249. ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
  250. float GetTime();
  251. int GetFrameCount();
  252. const char* GetStyleColorName(ImGuiCol idx);
  253. void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
  254. ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true);
  255. } // namespace ImGui
  256. // Flags for ImGui::Begin()
  257. enum ImGuiWindowFlags_
  258. {
  259. // Default: 0
  260. ImGuiWindowFlags_ShowBorders = 1 << 0,
  261. ImGuiWindowFlags_NoTitleBar = 1 << 1,
  262. ImGuiWindowFlags_NoResize = 1 << 2,
  263. ImGuiWindowFlags_NoMove = 1 << 3,
  264. ImGuiWindowFlags_NoScrollbar = 1 << 4,
  265. ImGuiWindowFlags_ChildWindow = 1 << 5, // For internal use by BeginChild()
  266. ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 6, // For internal use by BeginChild()
  267. ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 7, // For internal use by BeginChild()
  268. ImGuiWindowFlags_ComboBox = 1 << 8, // For internal use by ComboBox()
  269. ImGuiWindowFlags_Tooltip = 1 << 9, // For internal use by Render() when using Tooltip
  270. };
  271. // Flags for ImGui::InputText()
  272. enum ImGuiInputTextFlags_
  273. {
  274. // Default: 0
  275. ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/
  276. ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef
  277. ImGuiInputTextFlags_AutoSelectAll = 1 << 2, // Select entire text when first taking focus
  278. ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
  279. //ImGuiInputTextFlags_AlignCenter = 1 << 3,
  280. };
  281. // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array
  282. enum ImGuiKey_
  283. {
  284. ImGuiKey_Tab,
  285. ImGuiKey_LeftArrow,
  286. ImGuiKey_RightArrow,
  287. ImGuiKey_UpArrow,
  288. ImGuiKey_DownArrow,
  289. ImGuiKey_Home,
  290. ImGuiKey_End,
  291. ImGuiKey_Delete,
  292. ImGuiKey_Backspace,
  293. ImGuiKey_Enter,
  294. ImGuiKey_Escape,
  295. ImGuiKey_A, // for CTRL+A: select all
  296. ImGuiKey_C, // for CTRL+C: copy
  297. ImGuiKey_V, // for CTRL+V: paste
  298. ImGuiKey_X, // for CTRL+X: cut
  299. ImGuiKey_Y, // for CTRL+Y: redo
  300. ImGuiKey_Z, // for CTRL+Z: undo
  301. ImGuiKey_COUNT,
  302. };
  303. enum ImGuiCol_
  304. {
  305. ImGuiCol_Text,
  306. ImGuiCol_WindowBg,
  307. ImGuiCol_Border,
  308. ImGuiCol_BorderShadow,
  309. ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input
  310. ImGuiCol_TitleBg,
  311. ImGuiCol_TitleBgCollapsed,
  312. ImGuiCol_ScrollbarBg,
  313. ImGuiCol_ScrollbarGrab,
  314. ImGuiCol_ScrollbarGrabHovered,
  315. ImGuiCol_ScrollbarGrabActive,
  316. ImGuiCol_ComboBg,
  317. ImGuiCol_CheckHovered,
  318. ImGuiCol_CheckActive,
  319. ImGuiCol_SliderGrab,
  320. ImGuiCol_SliderGrabActive,
  321. ImGuiCol_Button,
  322. ImGuiCol_ButtonHovered,
  323. ImGuiCol_ButtonActive,
  324. ImGuiCol_Header,
  325. ImGuiCol_HeaderHovered,
  326. ImGuiCol_HeaderActive,
  327. ImGuiCol_Column,
  328. ImGuiCol_ColumnHovered,
  329. ImGuiCol_ColumnActive,
  330. ImGuiCol_ResizeGrip,
  331. ImGuiCol_ResizeGripHovered,
  332. ImGuiCol_ResizeGripActive,
  333. ImGuiCol_CloseButton,
  334. ImGuiCol_CloseButtonHovered,
  335. ImGuiCol_CloseButtonActive,
  336. ImGuiCol_PlotLines,
  337. ImGuiCol_PlotLinesHovered,
  338. ImGuiCol_PlotHistogram,
  339. ImGuiCol_PlotHistogramHovered,
  340. ImGuiCol_TextSelectedBg,
  341. ImGuiCol_TooltipBg,
  342. ImGuiCol_COUNT,
  343. };
  344. enum ImGuiColorEditMode_
  345. {
  346. ImGuiColorEditMode_UserSelect = -1,
  347. ImGuiColorEditMode_RGB = 0,
  348. ImGuiColorEditMode_HSV = 1,
  349. ImGuiColorEditMode_HEX = 2,
  350. };
  351. struct ImGuiStyle
  352. {
  353. float Alpha; // Global alpha applies to everything in ImGui
  354. ImVec2 WindowPadding; // Padding within a window
  355. ImVec2 WindowMinSize; // Minimum window size
  356. ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets)
  357. ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines
  358. ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
  359. ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much!
  360. ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip)
  361. float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin()
  362. float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
  363. float TreeNodeSpacing; // Horizontal spacing when entering a tree node
  364. float ColumnsMinSpacing; // Minimum horizontal spacing between two columns
  365. float ScrollBarWidth; // Width of the vertical scroll bar
  366. ImVec4 Colors[ImGuiCol_COUNT];
  367. ImGuiStyle();
  368. };
  369. // This is where your app communicate with ImGui. Call ImGui::GetIO() to access.
  370. // Read 'Programmer guide' section in .cpp file for general usage.
  371. struct ImGuiIO
  372. {
  373. //------------------------------------------------------------------
  374. // Settings (fill once) // Default value:
  375. //------------------------------------------------------------------
  376. ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions.
  377. float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
  378. float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds. Set to a negative value to disable .ini saving.
  379. const char* IniFilename; // = "imgui.ini" // Absolute path to .ini file.
  380. const char* LogFilename; // = "imgui_log.txt" // Absolute path to .log file.
  381. float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds.
  382. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
  383. int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
  384. ImFont Font; // <auto> // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
  385. float FontYOffset; // = 0.0f // Offset font rendering by xx pixels in Y axis.
  386. ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
  387. float FontBaseScale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
  388. bool FontAllowUserScaling; // = false // Set to allow scaling text with CTRL+Wheel.
  389. ImWchar FontFallbackGlyph; // = '?' // Replacement glyph is one isn't found.
  390. float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry
  391. void* UserData; // = NULL // Store your own data for retrieval by callbacks.
  392. //------------------------------------------------------------------
  393. // User Functions
  394. //------------------------------------------------------------------
  395. // REQUIRED: rendering function.
  396. // See example code if you are unsure of how to implement this.
  397. void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
  398. // Optional: access OS clipboard (default to use native Win32 clipboard on Windows, otherwise use a ImGui private clipboard)
  399. // Override to access OS clipboard on other architectures.
  400. const char* (*GetClipboardTextFn)();
  401. void (*SetClipboardTextFn)(const char* text);
  402. // Optional: override memory allocations (default to posix malloc/realloc/free)
  403. void* (*MemAllocFn)(size_t sz);
  404. void* (*MemReallocFn)(void* ptr, size_t sz);
  405. void (*MemFreeFn)(void* ptr);
  406. // Optional: notify OS Input Method Editor of text input position (e.g. when using Japanese/Chinese inputs, otherwise this isn't needed)
  407. void (*ImeSetInputScreenPosFn)(int x, int y);
  408. //------------------------------------------------------------------
  409. // Input - Fill before calling NewFrame()
  410. //------------------------------------------------------------------
  411. ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
  412. bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
  413. int MouseWheel; // Mouse wheel: -1,0,+1
  414. bool KeyCtrl; // Keyboard modifier pressed: Control
  415. bool KeyShift; // Keyboard modifier pressed: Shift
  416. bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
  417. ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper.
  418. // Function
  419. void AddInputCharacter(ImWchar); // Helper to add a new character into InputCharacters[]
  420. //------------------------------------------------------------------
  421. // Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application
  422. //------------------------------------------------------------------
  423. bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input)
  424. bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input)
  425. //------------------------------------------------------------------
  426. // [Internal] ImGui will maintain those fields for you
  427. //------------------------------------------------------------------
  428. ImVec2 MousePosPrev;
  429. ImVec2 MouseDelta;
  430. bool MouseClicked[5];
  431. ImVec2 MouseClickedPos[5];
  432. float MouseClickedTime[5];
  433. bool MouseDoubleClicked[5];
  434. float MouseDownTime[5];
  435. float KeysDownTime[512];
  436. ImGuiIO();
  437. };
  438. //-----------------------------------------------------------------------------
  439. // Helpers
  440. //-----------------------------------------------------------------------------
  441. // Helper: execute a block of code once a frame only
  442. // Usage: if (IMGUI_ONCE_UPON_A_FRAME) {/*do something once a frame*/)
  443. #define IMGUI_ONCE_UPON_A_FRAME static ImGuiOncePerFrame im = ImGuiOncePerFrame()
  444. struct ImGuiOncePerFrame
  445. {
  446. ImGuiOncePerFrame() : LastFrame(-1) {}
  447. operator bool() const { return TryIsNewFrame(); }
  448. private:
  449. mutable int LastFrame;
  450. bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; }
  451. };
  452. // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
  453. struct ImGuiTextFilter
  454. {
  455. struct TextRange
  456. {
  457. const char* b;
  458. const char* e;
  459. TextRange() { b = e = NULL; }
  460. TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
  461. const char* begin() const { return b; }
  462. const char* end() const { return e; }
  463. bool empty() const { return b == e; }
  464. char front() const { return *b; }
  465. static bool isblank(char c) { return c == ' ' || c == '\t'; }
  466. void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; }
  467. void split(char separator, ImVector<TextRange>& out);
  468. };
  469. char InputBuf[256];
  470. ImVector<TextRange> Filters;
  471. int CountGrep;
  472. ImGuiTextFilter();
  473. void Clear() { InputBuf[0] = 0; Build(); }
  474. void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build
  475. bool PassFilter(const char* val) const;
  476. bool IsActive() const { return !Filters.empty(); }
  477. void Build();
  478. };
  479. // Helper: Text buffer for logging/accumulating text
  480. struct ImGuiTextBuffer
  481. {
  482. ImVector<char> Buf;
  483. ImGuiTextBuffer() { Buf.push_back(0); }
  484. const char* begin() const { return Buf.begin(); }
  485. const char* end() const { return Buf.end()-1; }
  486. size_t size() const { return Buf.size()-1; }
  487. bool empty() { return Buf.empty(); }
  488. void clear() { Buf.clear(); Buf.push_back(0); }
  489. void append(const char* fmt, ...);
  490. };
  491. // Helper: Key->value storage
  492. // - Store collapse state for a tree
  493. // - Store color edit options, etc.
  494. // Typically you don't have to worry about this since a storage is held within each Window.
  495. // Declare your own storage if you want to manipulate the open/close state of a particular sub-tree in your interface.
  496. struct ImGuiStorage
  497. {
  498. struct Pair { ImU32 key; int val; };
  499. ImVector<Pair> Data;
  500. void Clear();
  501. int GetInt(ImU32 key, int default_val = 0);
  502. void SetInt(ImU32 key, int val);
  503. void SetAllInt(int val);
  504. int* Find(ImU32 key);
  505. void Insert(ImU32 key, int val);
  506. };
  507. //-----------------------------------------------------------------------------
  508. // Draw List
  509. // Hold a series of drawing commands. The user provide a renderer for ImDrawList
  510. //-----------------------------------------------------------------------------
  511. struct ImDrawCmd
  512. {
  513. unsigned int vtx_count;
  514. ImVec4 clip_rect;
  515. };
  516. struct ImDrawVert
  517. {
  518. ImVec2 pos;
  519. ImVec2 uv;
  520. ImU32 col;
  521. };
  522. // Draw command list
  523. // This is the low-level list of polygon that ImGui:: functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
  524. // Each ImGui window contains its own ImDrawList.
  525. // If you want to add custom rendering within a window, you can use ImGui::GetWindowDrawList() to access the current draw list and add your own primitives.
  526. // You can interleave normal ImGui:: calls and adding primitives to the current draw list.
  527. // Note that this only gives you access to rendering polygons. If your intent is to create custom widgets and the publicly exposed functions/data aren't sufficient, you can add code in imgui_user.inl
  528. struct ImDrawList
  529. {
  530. // This is what you have to render
  531. ImVector<ImDrawCmd> commands; // commands
  532. ImVector<ImDrawVert> vtx_buffer; // each command consume ImDrawCmd::vtx_count of those
  533. // [Internal to ImGui]
  534. ImVector<ImVec4> clip_rect_stack; // [internal] clip rect stack while building the command-list (so text command can perform clipping early on)
  535. ImDrawVert* vtx_write; // [internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
  536. ImDrawList() { Clear(); }
  537. void Clear();
  538. void PushClipRect(const ImVec4& clip_rect);
  539. void PopClipRect();
  540. void ReserveVertices(unsigned int vtx_count);
  541. void AddVtx(const ImVec2& pos, ImU32 col);
  542. void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
  543. // Primitives
  544. void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);
  545. void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
  546. void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
  547. void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
  548. void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
  549. void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
  550. void AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris=false, const ImVec2& third_point_offset = ImVec2(0,0));
  551. void AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end);
  552. };
  553. // Optional bitmap font data loader & renderer into vertices
  554. // #define ImFont to ImBitmapFont to use
  555. // Using the .fnt format exported by BMFont
  556. // - tool: http://www.angelcode.com/products/bmfont
  557. // - file-format: http://www.angelcode.com/products/bmfont/doc/file_format.html
  558. // Assume valid file data (won't handle invalid/malicious data)
  559. // Handle a subset of parameters.
  560. // - kerning pair are not supported (because ImGui code does per-character CalcTextSize calls, need to turn it into something more stateful to allow kerning)
  561. struct ImBitmapFont
  562. {
  563. #pragma pack(push, 1)
  564. struct FntInfo
  565. {
  566. signed short FontSize;
  567. unsigned char BitField; // bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeight, bits 5-7: reserved
  568. unsigned char CharSet;
  569. unsigned short StretchH;
  570. unsigned char AA;
  571. unsigned char PaddingUp, PaddingRight, PaddingDown, PaddingLeft;
  572. unsigned char SpacingHoriz, SpacingVert;
  573. unsigned char Outline;
  574. //char FontName[];
  575. };
  576. struct FntCommon
  577. {
  578. unsigned short LineHeight;
  579. unsigned short Base;
  580. unsigned short ScaleW, ScaleH;
  581. unsigned short Pages;
  582. unsigned char BitField;
  583. unsigned char Channels[4];
  584. };
  585. struct FntGlyph
  586. {
  587. unsigned int Id;
  588. unsigned short X, Y;
  589. unsigned short Width, Height;
  590. signed short XOffset, YOffset;
  591. signed short XAdvance;
  592. unsigned char Page;
  593. unsigned char Channel;
  594. };
  595. struct FntKerning
  596. {
  597. unsigned int IdFirst;
  598. unsigned int IdSecond;
  599. signed short Amount;
  600. };
  601. #pragma pack(pop)
  602. unsigned char* Data; // Raw data, content of .fnt file
  603. size_t DataSize; //
  604. bool DataOwned; //
  605. const FntInfo* Info; // (point into raw data)
  606. const FntCommon* Common; // (point into raw data)
  607. const FntGlyph* Glyphs; // (point into raw data)
  608. size_t GlyphsCount; //
  609. const FntKerning* Kerning; // (point into raw data)
  610. size_t KerningCount; //
  611. int TabCount; // FIXME: mishandled (add fixed amount instead of aligning to column)
  612. ImVector<const char*> Filenames; // (point into raw data)
  613. ImVector<int> IndexLookup; // (built)
  614. ImBitmapFont();
  615. ~ImBitmapFont() { Clear(); }
  616. bool LoadFromMemory(const void* data, size_t data_size);
  617. bool LoadFromFile(const char* filename);
  618. void Clear();
  619. void BuildLookupTable();
  620. const FntGlyph * FindGlyph(unsigned short c) const;
  621. float GetFontSize() const { return (float)Info->FontSize; }
  622. bool IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; }
  623. ImVec2 CalcTextSizeA(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const; // utf8
  624. ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar
  625. void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const;
  626. };