Open Source Tomb Raider Engine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

imgui.h 37KB

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