|
|
@@ -1,4 +1,4 @@
|
|
|
-// ImGui library v1.21 wip
|
|
|
+// ImGui library v1.30 wip
|
|
|
// See .cpp file for commentary.
|
|
|
// See ImGui::ShowTestWindow() for sample code.
|
|
|
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
|
|
@@ -8,6 +8,7 @@
|
|
|
|
|
|
struct ImDrawList;
|
|
|
struct ImFont;
|
|
|
+struct ImFontAtlas;
|
|
|
struct ImGuiAabb;
|
|
|
struct ImGuiIO;
|
|
|
struct ImGuiStorage;
|
|
|
@@ -31,8 +32,9 @@ struct ImGuiWindow;
|
|
|
#endif
|
|
|
|
|
|
typedef unsigned int ImU32;
|
|
|
-typedef unsigned short ImWchar; // hold a character for display
|
|
|
-typedef ImU32 ImGuiID; // hold widget unique ID
|
|
|
+typedef unsigned short ImWchar; // character for display
|
|
|
+typedef void* ImTextureID; // user data to refer to a texture (e.g. store your texture handle/id)
|
|
|
+typedef ImU32 ImGuiID; // unique ID used by widgets (typically hashed from a stack of string)
|
|
|
typedef int ImGuiCol; // enum ImGuiCol_
|
|
|
typedef int ImGuiStyleVar; // enum ImGuiStyleVar_
|
|
|
typedef int ImGuiKey; // enum ImGuiKey_
|
|
|
@@ -40,7 +42,7 @@ typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_
|
|
|
typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_
|
|
|
typedef int ImGuiSetCondition; // enum ImGuiSetCondition_
|
|
|
typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
|
|
|
-struct ImGuiTextEditCallbackData;
|
|
|
+struct ImGuiTextEditCallbackData; // for advanced uses of InputText()
|
|
|
|
|
|
struct ImVec2
|
|
|
{
|
|
|
@@ -72,7 +74,7 @@ namespace ImGui
|
|
|
IMGUI_API void* MemRealloc(void* ptr, size_t sz);
|
|
|
}
|
|
|
|
|
|
-// 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).
|
|
|
+// 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).
|
|
|
// Use '#define ImVector std::vector' if you want to use the STL type or your own type.
|
|
|
// 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.
|
|
|
#ifndef ImVector
|
|
|
@@ -106,10 +108,10 @@ public:
|
|
|
inline const_iterator begin() const { return Data; }
|
|
|
inline iterator end() { return Data + Size; }
|
|
|
inline const_iterator end() const { return Data + Size; }
|
|
|
- inline value_type& front() { return at(0); }
|
|
|
- inline const value_type& front() const { return at(0); }
|
|
|
- inline value_type& back() { IM_ASSERT(Size > 0); return at(Size-1); }
|
|
|
- inline const value_type& back() const { IM_ASSERT(Size > 0); return at(Size-1); }
|
|
|
+ inline value_type& front() { IM_ASSERT(Size > 0); return Data[0]; }
|
|
|
+ inline const value_type& front() const { IM_ASSERT(Size > 0); return Data[0]; }
|
|
|
+ inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size-1]; }
|
|
|
+ inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; }
|
|
|
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; }
|
|
|
|
|
|
inline void reserve(size_t new_capacity) { Data = (value_type*)ImGui::MemRealloc(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; }
|
|
|
@@ -129,7 +131,7 @@ public:
|
|
|
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
|
|
|
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
|
|
|
// - struct ImDrawList // Draw command list
|
|
|
-// - struct ImFont // Bitmap font loader
|
|
|
+// - struct ImFont // TTF font loader, bake glyphs into bitmap
|
|
|
|
|
|
// ImGui End-user API
|
|
|
// In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types)
|
|
|
@@ -174,16 +176,21 @@ namespace ImGui
|
|
|
IMGUI_API void SetStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
|
|
|
IMGUI_API ImGuiStorage* GetStateStorage();
|
|
|
|
|
|
- IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width.
|
|
|
- IMGUI_API void PopItemWidth();
|
|
|
- IMGUI_API float GetItemWidth();
|
|
|
- IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
|
|
|
- IMGUI_API void PopAllowKeyboardFocus();
|
|
|
+ // Parameters stacks (shared)
|
|
|
+ IMGUI_API void PushFont(ImFont* font); // use NULL as a shortcut to push default font
|
|
|
+ IMGUI_API void PopFont();
|
|
|
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col);
|
|
|
IMGUI_API void PopStyleColor(int count = 1);
|
|
|
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val);
|
|
|
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
|
|
|
IMGUI_API void PopStyleVar(int count = 1);
|
|
|
+
|
|
|
+ // Parameters stacks (current window)
|
|
|
+ IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width.
|
|
|
+ IMGUI_API void PopItemWidth();
|
|
|
+ IMGUI_API float GetItemWidth();
|
|
|
+ IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
|
|
|
+ IMGUI_API void PopAllowKeyboardFocus();
|
|
|
IMGUI_API void PushTextWrapPos(float wrap_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space.
|
|
|
IMGUI_API void PopTextWrapPos();
|
|
|
|
|
|
@@ -230,12 +237,14 @@ namespace ImGui
|
|
|
IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();
|
|
|
IMGUI_API void TextWrappedV(const char* fmt, va_list args);
|
|
|
IMGUI_API 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, recommended for long chunks of text.
|
|
|
- IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets
|
|
|
+ IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets
|
|
|
IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args);
|
|
|
IMGUI_API void BulletText(const char* fmt, ...);
|
|
|
IMGUI_API void BulletTextV(const char* fmt, va_list args);
|
|
|
- IMGUI_API bool Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false);
|
|
|
+ IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false);
|
|
|
IMGUI_API bool SmallButton(const char* label);
|
|
|
+ IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size);
|
|
|
+ IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), ImU32 tint_col = 0xFFFFFFFF, ImU32 border_col = 0x00000000);
|
|
|
IMGUI_API bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
|
|
|
IMGUI_API 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.
|
|
|
IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f);
|
|
|
@@ -294,8 +303,8 @@ namespace ImGui
|
|
|
IMGUI_API void LogText(const char* fmt, ...); // pass text data straight to log (without being displayed)
|
|
|
|
|
|
// Utilities
|
|
|
- IMGUI_API bool IsItemHovered(); // was the last item active area hovered by mouse?
|
|
|
- IMGUI_API bool IsItemFocused(); // was the last item focused for keyboard input?
|
|
|
+ IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse?
|
|
|
+ IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false)
|
|
|
IMGUI_API ImVec2 GetItemBoxMin(); // get bounding box of last item
|
|
|
IMGUI_API ImVec2 GetItemBoxMax(); // get bounding box of last item
|
|
|
IMGUI_API bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimization)
|
|
|
@@ -310,9 +319,11 @@ namespace ImGui
|
|
|
IMGUI_API float GetTime();
|
|
|
IMGUI_API int GetFrameCount();
|
|
|
IMGUI_API const char* GetStyleColName(ImGuiCol idx);
|
|
|
- IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
|
|
|
IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
|
|
|
|
|
|
+ // Obsolete (will be removed)
|
|
|
+ IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
|
|
|
+
|
|
|
} // namespace ImGui
|
|
|
|
|
|
// Flags for ImGui::Begin()
|
|
|
@@ -426,7 +437,7 @@ enum ImGuiStyleVar_
|
|
|
ImGuiStyleVar_FrameRounding, // float
|
|
|
ImGuiStyleVar_ItemSpacing, // ImVec2
|
|
|
ImGuiStyleVar_ItemInnerSpacing, // ImVec2
|
|
|
- ImGuiStyleVar_TreeNodeSpacing, // float
|
|
|
+ ImGuiStyleVar_TreeNodeSpacing // float
|
|
|
};
|
|
|
|
|
|
// Enumeration for ColorEditMode()
|
|
|
@@ -445,7 +456,7 @@ enum ImGuiSetCondition_
|
|
|
{
|
|
|
ImGuiSetCondition_Always = 1 << 0, // Set the variable
|
|
|
ImGuiSetCondition_FirstUseThisSession = 1 << 1, // Only set the variable on the first call for this window (once per session)
|
|
|
- ImGuiSetCondition_FirstUseEver = 1 << 2, // Only set the variable if the window doesn't exist in the .ini file
|
|
|
+ ImGuiSetCondition_FirstUseEver = 1 << 2 // Only set the variable if the window doesn't exist in the .ini file
|
|
|
};
|
|
|
|
|
|
struct ImGuiStyle
|
|
|
@@ -477,28 +488,27 @@ struct ImGuiIO
|
|
|
// Settings (fill once) // Default value:
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
- ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions.
|
|
|
- float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
|
|
|
- float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds.
|
|
|
- const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving.
|
|
|
- const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
|
|
|
- float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds.
|
|
|
- float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
|
|
|
- int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
|
|
|
- ImFont* Font; // <auto> // Font (also see 'Settings' fields inside ImFont structure for details)
|
|
|
- float FontGlobalScale; // = 1.0f // Global scale all fonts
|
|
|
- bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
|
|
|
- float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry
|
|
|
-
|
|
|
- void* UserData; // = NULL // Store your own data for retrieval by callbacks.
|
|
|
+ ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions.
|
|
|
+ float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
|
|
|
+ float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds.
|
|
|
+ const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving.
|
|
|
+ const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
|
|
|
+ float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds.
|
|
|
+ float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
|
|
|
+ int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
|
|
|
+ void* UserData; // = NULL // Store your own data for retrieval by callbacks.
|
|
|
+
|
|
|
+ ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
|
|
|
+ float FontGlobalScale; // = 1.0f // Global scale all fonts
|
|
|
+ bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
// User Functions
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
- // REQUIRED: rendering function.
|
|
|
+ // REQUIRED: rendering function.
|
|
|
// See example code if you are unsure of how to implement this.
|
|
|
- void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
|
|
|
+ void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count);
|
|
|
|
|
|
// Optional: access OS clipboard (default to use native Win32 clipboard on Windows, otherwise use a ImGui private clipboard)
|
|
|
// Override to access OS clipboard on other architectures.
|
|
|
@@ -519,7 +529,7 @@ struct ImGuiIO
|
|
|
|
|
|
ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
|
|
|
bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience.
|
|
|
- float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text.
|
|
|
+ float MouseWheel; // Mouse wheel: 1 unit scrolls about 5 lines text.
|
|
|
bool KeyCtrl; // Keyboard modifier pressed: Control
|
|
|
bool KeyShift; // Keyboard modifier pressed: Shift
|
|
|
bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data)
|
|
|
@@ -548,7 +558,7 @@ struct ImGuiIO
|
|
|
float MouseDownTime[5];
|
|
|
float KeysDownTime[512];
|
|
|
|
|
|
- IMGUI_API ImGuiIO();
|
|
|
+ IMGUI_API ImGuiIO();
|
|
|
};
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@@ -628,18 +638,18 @@ struct ImGuiTextBuffer
|
|
|
// - You want to store custom debug data easily without adding or editing structures in your code.
|
|
|
struct ImGuiStorage
|
|
|
{
|
|
|
- struct Pair
|
|
|
- {
|
|
|
- ImGuiID key;
|
|
|
- union { int val_i; float val_f; };
|
|
|
- Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
|
|
|
- Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
|
|
|
+ struct Pair
|
|
|
+ {
|
|
|
+ ImGuiID key;
|
|
|
+ union { int val_i; float val_f; };
|
|
|
+ Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
|
|
|
+ Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
|
|
|
};
|
|
|
ImVector<Pair> Data;
|
|
|
|
|
|
// - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
|
|
|
// - Set***() functions find pair, insertion on demand if missing.
|
|
|
- // - Get***Ptr() functions find pair, insertion on demand if missing, return pointer. Useful if you intend to do Get+Set.
|
|
|
+ // - Get***Ptr() functions find pair, insertion on demand if missing, return pointer. Useful if you intend to do Get+Set.
|
|
|
// A typical use case where this is very convenient:
|
|
|
// float* pvar = ImGui::GetIntPtr(key); ImGui::SliderInt("var", pvar, 0, 100); some_var += *pvar;
|
|
|
// - Sorted insertion is costly but should amortize. A typical frame shouldn't need to insert any new pair.
|
|
|
@@ -656,7 +666,7 @@ struct ImGuiStorage
|
|
|
// Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used.
|
|
|
struct ImGuiTextEditCallbackData
|
|
|
{
|
|
|
- ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only
|
|
|
+ ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only
|
|
|
char* Buf; // Current text // Read-write (pointed data only)
|
|
|
size_t BufSize; // // Read-only
|
|
|
bool BufDirty; // Set if you modify Buf directly // Write
|
|
|
@@ -673,13 +683,14 @@ struct ImGuiTextEditCallbackData
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
// Draw List
|
|
|
-// Hold a series of drawing commands. The user provide a renderer for ImDrawList
|
|
|
+// Hold a series of drawing commands. The user provides a renderer for ImDrawList
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
struct ImDrawCmd
|
|
|
{
|
|
|
unsigned int vtx_count;
|
|
|
ImVec4 clip_rect;
|
|
|
+ ImTextureID texture_id; // Copy of user-provided 'TexID' from ImFont or passed to Image*() functions. Ignore if not using images or multiple fonts.
|
|
|
};
|
|
|
|
|
|
#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
|
|
|
@@ -710,19 +721,25 @@ struct ImDrawList
|
|
|
ImVector<ImDrawVert> vtx_buffer; // each command consume ImDrawCmd::vtx_count of those
|
|
|
|
|
|
// [Internal to ImGui]
|
|
|
- ImVector<ImVec4> clip_rect_stack; // [internal] clip rect stack while building the command-list (so text command can perform clipping early on)
|
|
|
+ ImVector<ImVec4> clip_rect_stack; // [internal]
|
|
|
+ ImVector<ImTextureID> texture_id_stack; // [internal]
|
|
|
ImDrawVert* vtx_write; // [internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
|
|
|
|
|
|
ImDrawList() { Clear(); }
|
|
|
|
|
|
IMGUI_API void Clear();
|
|
|
+ IMGUI_API void SetClipRect(const ImVec4& clip_rect);
|
|
|
IMGUI_API void PushClipRect(const ImVec4& clip_rect);
|
|
|
IMGUI_API void PopClipRect();
|
|
|
+ IMGUI_API void SetTextureID(const ImTextureID& texture_id);
|
|
|
+ IMGUI_API void PushTextureID(const ImTextureID& texture_id);
|
|
|
+ IMGUI_API void PopTextureID();
|
|
|
IMGUI_API void ReserveVertices(unsigned int vtx_count);
|
|
|
IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col);
|
|
|
+ IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv);
|
|
|
IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
|
|
|
|
|
|
- // Primitives
|
|
|
+ // Primitives
|
|
|
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col);
|
|
|
IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
|
|
|
IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F);
|
|
|
@@ -731,99 +748,99 @@ struct ImDrawList
|
|
|
IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
|
|
|
IMGUI_API 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));
|
|
|
IMGUI_API void AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f);
|
|
|
+ IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col);
|
|
|
};
|
|
|
|
|
|
-// Bitmap font data loader & renderer into vertices
|
|
|
-// Using the .fnt format exported by BMFont
|
|
|
-// - tool: http://www.angelcode.com/products/bmfont
|
|
|
-// - file-format: http://www.angelcode.com/products/bmfont/doc/file_format.html
|
|
|
-// Assume valid file data (won't handle invalid/malicious data)
|
|
|
-// Handle a subset of the options, namely:
|
|
|
-// - kerning pair are not supported (because some ImGui code does per-character CalcTextSize calls, need to turn it into something more state-ful to allow for kerning)
|
|
|
-struct ImFont
|
|
|
+// Load and rasterize multiple TTF fonts into a same texture.
|
|
|
+// Sharing a texture for multiple fonts allows us to reduce the number of draw calls during rendering.
|
|
|
+// We also add custom graphic data into the texture that serves for ImGui.
|
|
|
+// 1. (Optional) Call AddFont*** functions. If you don't call any, the default font will be loaded for you.
|
|
|
+// 2. Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data.
|
|
|
+// 3. Upload the pixels data into a texture within your graphics system.
|
|
|
+// 4. Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture. This value will be passed back to you during rendering to identify the texture.
|
|
|
+// 5. Call ClearPixelsData() to free textures memory on the heap.
|
|
|
+struct ImFontAtlas
|
|
|
{
|
|
|
- struct FntInfo;
|
|
|
- struct FntCommon;
|
|
|
- struct FntGlyph;
|
|
|
- struct FntKerning;
|
|
|
-
|
|
|
- // Settings
|
|
|
- float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
|
|
- ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
|
|
- ImVec2 TexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
|
|
|
- ImWchar FallbackChar; // = '?' // Replacement glyph is one isn't found.
|
|
|
-
|
|
|
- // Data
|
|
|
- unsigned char* Data; // Raw data, content of .fnt file
|
|
|
- size_t DataSize; //
|
|
|
- bool DataOwned; //
|
|
|
- const FntInfo* Info; // (point into raw data)
|
|
|
- const FntCommon* Common; // (point into raw data)
|
|
|
- const FntGlyph* Glyphs; // (point into raw data)
|
|
|
- size_t GlyphsCount; //
|
|
|
- const FntKerning* Kerning; // (point into raw data) - NB: kerning is unsupported
|
|
|
- size_t KerningCount; //
|
|
|
- ImVector<const char*> Filenames; // (point into raw data)
|
|
|
- ImVector<int> IndexLookup; // (built)
|
|
|
- const FntGlyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
|
|
-
|
|
|
- IMGUI_API ImFont();
|
|
|
- IMGUI_API ~ImFont() { Clear(); }
|
|
|
-
|
|
|
- IMGUI_API bool LoadFromMemory(const void* data, size_t data_size);
|
|
|
- IMGUI_API bool LoadFromFile(const char* filename);
|
|
|
+ IMGUI_API ImFontAtlas();
|
|
|
+ IMGUI_API ~ImFontAtlas();
|
|
|
+ IMGUI_API ImFont* AddFontDefault();
|
|
|
+ IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0);
|
|
|
+ IMGUI_API ImFont* AddFontFromMemoryTTF(void* in_ttf_data, size_t in_ttf_data_size, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0); // Pass ownership of 'in_ttf_data' memory.
|
|
|
+ IMGUI_API void ClearTexData(); // Saves RAM once the texture has been copied to graphics memory.
|
|
|
IMGUI_API void Clear();
|
|
|
- IMGUI_API void BuildLookupTable();
|
|
|
- IMGUI_API const FntGlyph* FindGlyph(unsigned short c) const;
|
|
|
- IMGUI_API bool IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; }
|
|
|
|
|
|
- // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
|
|
- // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
|
|
- IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8
|
|
|
- IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar
|
|
|
- IMGUI_API void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width = 0.0f) const;
|
|
|
-
|
|
|
- IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
|
|
|
-
|
|
|
-#pragma pack(push, 1)
|
|
|
- struct FntInfo
|
|
|
- {
|
|
|
- signed short FontSize;
|
|
|
- unsigned char BitField; // bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeight, bits 5-7: reserved
|
|
|
- unsigned char CharSet;
|
|
|
- unsigned short StretchH;
|
|
|
- unsigned char AA;
|
|
|
- unsigned char PaddingUp, PaddingRight, PaddingDown, PaddingLeft;
|
|
|
- unsigned char SpacingHoriz, SpacingVert, Outline;
|
|
|
- //char FontName[];
|
|
|
- };
|
|
|
-
|
|
|
- struct FntCommon
|
|
|
- {
|
|
|
- unsigned short LineHeight, Base;
|
|
|
- unsigned short ScaleW, ScaleH;
|
|
|
- unsigned short Pages;
|
|
|
- unsigned char BitField;
|
|
|
- unsigned char Channels[4];
|
|
|
- };
|
|
|
+ // Retrieve texture data
|
|
|
+ // User is in charge of copying the pixels into graphics memory, then call SetTextureUserID()
|
|
|
+ // After loading the texture into your graphic system, store your texture handle in 'TexID' (ignore if you aren't using multiple fonts nor images)
|
|
|
+ // RGBA32 format is provided for convenience and high compatibility, but note that all RGB pixels are white, so 75% of the memory is wasted.
|
|
|
+ // Pitch = Width * BytesPerPixels
|
|
|
+ IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel
|
|
|
+ IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel
|
|
|
+ IMGUI_API void SetTexID(void* id) { TexID = id; }
|
|
|
+
|
|
|
+ // Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
|
|
|
+ // (Those functions could be static, aren't so simple use case doesn't have to refer to the ImFontAtlas:: type ever if in their code)
|
|
|
+ IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
|
|
|
+ IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
|
|
+ IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs
|
|
|
+
|
|
|
+ // Members
|
|
|
+ // (Access texture data via GetTexData*() calls which will setup a default font for you.)
|
|
|
+ void* TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It ia passed back to you during rendering.
|
|
|
+ unsigned char* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
|
|
|
+ unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
|
|
|
+ int TexWidth;
|
|
|
+ int TexHeight;
|
|
|
+ ImVec2 TexExtraDataPos; // Position of our rectangle where we draw non-font graphics
|
|
|
+ ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block)
|
|
|
+ ImVector<ImFont*> Fonts;
|
|
|
+
|
|
|
+ // Private
|
|
|
+ struct ImFontAtlasData;
|
|
|
+ ImVector<ImFontAtlasData*> InputData; // Internal data
|
|
|
+ IMGUI_API bool Build(); // Build pixels data. This is automatically for you by the GetTexData*** functions.
|
|
|
+ IMGUI_API void ClearInputData(); // Clear the input TTF data.
|
|
|
+};
|
|
|
|
|
|
- struct FntGlyph
|
|
|
+// TTF font loading and rendering
|
|
|
+// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
|
|
|
+// Kerning isn't supported. At the moment some ImGui code does per-character CalcTextSize calls, need something more state-ful.
|
|
|
+struct ImFont
|
|
|
+{
|
|
|
+ // Members: Settings
|
|
|
+ float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
|
|
|
+ float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
|
|
+ ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
|
|
+ ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found.
|
|
|
+
|
|
|
+ // Members: Runtime data
|
|
|
+ struct Glyph
|
|
|
{
|
|
|
- unsigned int Id;
|
|
|
- unsigned short X, Y, Width, Height;
|
|
|
- signed short XOffset, YOffset;
|
|
|
+ ImWchar Codepoint;
|
|
|
signed short XAdvance;
|
|
|
- unsigned char Page;
|
|
|
- unsigned char Channel;
|
|
|
+ signed short Width, Height;
|
|
|
+ signed short XOffset, YOffset;
|
|
|
+ float U0, V0, U1, V1; // Texture coordinates
|
|
|
};
|
|
|
+ ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
|
|
+ ImVector<Glyph> Glyphs;
|
|
|
+ ImVector<int> IndexLookup; // Index glyphs by Unicode code-point
|
|
|
+ const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
|
|
|
|
|
- struct FntKerning
|
|
|
- {
|
|
|
- unsigned int IdFirst;
|
|
|
- unsigned int IdSecond;
|
|
|
- signed short Amount;
|
|
|
- };
|
|
|
-#pragma pack(pop)
|
|
|
+ // Methods
|
|
|
+ IMGUI_API ImFont();
|
|
|
+ IMGUI_API ~ImFont() { Clear(); }
|
|
|
+ IMGUI_API void Clear();
|
|
|
+ IMGUI_API void BuildLookupTable();
|
|
|
+ IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
|
|
|
+ IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; }
|
|
|
+
|
|
|
+ // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
|
|
+ // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
|
|
+ IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8
|
|
|
+ IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar
|
|
|
+ IMGUI_API void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices, float wrap_width = 0.0f) const;
|
|
|
+ IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
|
|
|
};
|
|
|
|
|
|
//---- Include imgui_user.h at the end of imgui.h
|