|
@@ -1,4 +1,4 @@
|
1
|
|
-// ImGui library v1.21 wip
|
|
1
|
+// ImGui library v1.30 wip
|
2
|
2
|
// See .cpp file for commentary.
|
3
|
3
|
// See ImGui::ShowTestWindow() for sample code.
|
4
|
4
|
// Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.
|
|
@@ -8,6 +8,7 @@
|
8
|
8
|
|
9
|
9
|
struct ImDrawList;
|
10
|
10
|
struct ImFont;
|
|
11
|
+struct ImFontAtlas;
|
11
|
12
|
struct ImGuiAabb;
|
12
|
13
|
struct ImGuiIO;
|
13
|
14
|
struct ImGuiStorage;
|
|
@@ -31,8 +32,9 @@ struct ImGuiWindow;
|
31
|
32
|
#endif
|
32
|
33
|
|
33
|
34
|
typedef unsigned int ImU32;
|
34
|
|
-typedef unsigned short ImWchar; // hold a character for display
|
35
|
|
-typedef ImU32 ImGuiID; // hold widget unique ID
|
|
35
|
+typedef unsigned short ImWchar; // character for display
|
|
36
|
+typedef void* ImTextureID; // user data to refer to a texture (e.g. store your texture handle/id)
|
|
37
|
+typedef ImU32 ImGuiID; // unique ID used by widgets (typically hashed from a stack of string)
|
36
|
38
|
typedef int ImGuiCol; // enum ImGuiCol_
|
37
|
39
|
typedef int ImGuiStyleVar; // enum ImGuiStyleVar_
|
38
|
40
|
typedef int ImGuiKey; // enum ImGuiKey_
|
|
@@ -40,7 +42,7 @@ typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_
|
40
|
42
|
typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_
|
41
|
43
|
typedef int ImGuiSetCondition; // enum ImGuiSetCondition_
|
42
|
44
|
typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_
|
43
|
|
-struct ImGuiTextEditCallbackData;
|
|
45
|
+struct ImGuiTextEditCallbackData; // for advanced uses of InputText()
|
44
|
46
|
|
45
|
47
|
struct ImVec2
|
46
|
48
|
{
|
|
@@ -106,10 +108,10 @@ public:
|
106
|
108
|
inline const_iterator begin() const { return Data; }
|
107
|
109
|
inline iterator end() { return Data + Size; }
|
108
|
110
|
inline const_iterator end() const { return Data + Size; }
|
109
|
|
- inline value_type& front() { return at(0); }
|
110
|
|
- inline const value_type& front() const { return at(0); }
|
111
|
|
- inline value_type& back() { IM_ASSERT(Size > 0); return at(Size-1); }
|
112
|
|
- inline const value_type& back() const { IM_ASSERT(Size > 0); return at(Size-1); }
|
|
111
|
+ inline value_type& front() { IM_ASSERT(Size > 0); return Data[0]; }
|
|
112
|
+ inline const value_type& front() const { IM_ASSERT(Size > 0); return Data[0]; }
|
|
113
|
+ inline value_type& back() { IM_ASSERT(Size > 0); return Data[Size-1]; }
|
|
114
|
+ inline const value_type& back() const { IM_ASSERT(Size > 0); return Data[Size-1]; }
|
113
|
115
|
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; }
|
114
|
116
|
|
115
|
117
|
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:
|
129
|
131
|
// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text
|
130
|
132
|
// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually)
|
131
|
133
|
// - struct ImDrawList // Draw command list
|
132
|
|
-// - struct ImFont // Bitmap font loader
|
|
134
|
+// - struct ImFont // TTF font loader, bake glyphs into bitmap
|
133
|
135
|
|
134
|
136
|
// ImGui End-user API
|
135
|
137
|
// 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
|
174
|
176
|
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).
|
175
|
177
|
IMGUI_API ImGuiStorage* GetStateStorage();
|
176
|
178
|
|
177
|
|
- IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width.
|
178
|
|
- IMGUI_API void PopItemWidth();
|
179
|
|
- IMGUI_API float GetItemWidth();
|
180
|
|
- IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
|
181
|
|
- IMGUI_API void PopAllowKeyboardFocus();
|
|
179
|
+ // Parameters stacks (shared)
|
|
180
|
+ IMGUI_API void PushFont(ImFont* font); // use NULL as a shortcut to push default font
|
|
181
|
+ IMGUI_API void PopFont();
|
182
|
182
|
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col);
|
183
|
183
|
IMGUI_API void PopStyleColor(int count = 1);
|
184
|
184
|
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, float val);
|
185
|
185
|
IMGUI_API void PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
|
186
|
186
|
IMGUI_API void PopStyleVar(int count = 1);
|
|
187
|
+
|
|
188
|
+ // Parameters stacks (current window)
|
|
189
|
+ IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width.
|
|
190
|
+ IMGUI_API void PopItemWidth();
|
|
191
|
+ IMGUI_API float GetItemWidth();
|
|
192
|
+ IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
|
|
193
|
+ IMGUI_API void PopAllowKeyboardFocus();
|
187
|
194
|
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.
|
188
|
195
|
IMGUI_API void PopTextWrapPos();
|
189
|
196
|
|
|
@@ -234,8 +241,9 @@ namespace ImGui
|
234
|
241
|
IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args);
|
235
|
242
|
IMGUI_API void BulletText(const char* fmt, ...);
|
236
|
243
|
IMGUI_API void BulletTextV(const char* fmt, va_list args);
|
237
|
|
- IMGUI_API bool Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false);
|
|
244
|
+ IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0), bool repeat_when_held = false);
|
238
|
245
|
IMGUI_API bool SmallButton(const char* label);
|
|
246
|
+ 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);
|
239
|
247
|
IMGUI_API bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false);
|
240
|
248
|
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.
|
241
|
249
|
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);
|
|
@@ -310,7 +318,6 @@ namespace ImGui
|
310
|
318
|
IMGUI_API float GetTime();
|
311
|
319
|
IMGUI_API int GetFrameCount();
|
312
|
320
|
IMGUI_API const char* GetStyleColName(ImGuiCol idx);
|
313
|
|
- IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);
|
314
|
321
|
IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
|
315
|
322
|
|
316
|
323
|
} // namespace ImGui
|
|
@@ -426,7 +433,7 @@ enum ImGuiStyleVar_
|
426
|
433
|
ImGuiStyleVar_FrameRounding, // float
|
427
|
434
|
ImGuiStyleVar_ItemSpacing, // ImVec2
|
428
|
435
|
ImGuiStyleVar_ItemInnerSpacing, // ImVec2
|
429
|
|
- ImGuiStyleVar_TreeNodeSpacing, // float
|
|
436
|
+ ImGuiStyleVar_TreeNodeSpacing // float
|
430
|
437
|
};
|
431
|
438
|
|
432
|
439
|
// Enumeration for ColorEditMode()
|
|
@@ -445,7 +452,7 @@ enum ImGuiSetCondition_
|
445
|
452
|
{
|
446
|
453
|
ImGuiSetCondition_Always = 1 << 0, // Set the variable
|
447
|
454
|
ImGuiSetCondition_FirstUseThisSession = 1 << 1, // Only set the variable on the first call for this window (once per session)
|
448
|
|
- ImGuiSetCondition_FirstUseEver = 1 << 2, // Only set the variable if the window doesn't exist in the .ini file
|
|
455
|
+ ImGuiSetCondition_FirstUseEver = 1 << 2 // Only set the variable if the window doesn't exist in the .ini file
|
449
|
456
|
};
|
450
|
457
|
|
451
|
458
|
struct ImGuiStyle
|
|
@@ -477,20 +484,19 @@ struct ImGuiIO
|
477
|
484
|
// Settings (fill once) // Default value:
|
478
|
485
|
//------------------------------------------------------------------
|
479
|
486
|
|
480
|
|
- ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions.
|
481
|
|
- float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
|
482
|
|
- float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds.
|
483
|
|
- const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving.
|
484
|
|
- const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
|
485
|
|
- float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds.
|
486
|
|
- float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
|
487
|
|
- int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
|
488
|
|
- ImFont* Font; // <auto> // Font (also see 'Settings' fields inside ImFont structure for details)
|
489
|
|
- float FontGlobalScale; // = 1.0f // Global scale all fonts
|
490
|
|
- bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
|
491
|
|
- float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry
|
492
|
|
-
|
493
|
|
- void* UserData; // = NULL // Store your own data for retrieval by callbacks.
|
|
487
|
+ ImVec2 DisplaySize; // <unset> // Display size, in pixels. For clamping windows positions.
|
|
488
|
+ float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
|
|
489
|
+ float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds.
|
|
490
|
+ const char* IniFilename; // = "imgui.ini" // Path to .ini file. NULL to disable .ini saving.
|
|
491
|
+ const char* LogFilename; // = "imgui_log.txt" // Path to .log file (default parameter to ImGui::LogToFile when no file is specified).
|
|
492
|
+ float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds.
|
|
493
|
+ float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
|
|
494
|
+ int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
|
|
495
|
+ void* UserData; // = NULL // Store your own data for retrieval by callbacks.
|
|
496
|
+
|
|
497
|
+ ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
|
|
498
|
+ float FontGlobalScale; // = 1.0f // Global scale all fonts
|
|
499
|
+ bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
|
494
|
500
|
|
495
|
501
|
//------------------------------------------------------------------
|
496
|
502
|
// User Functions
|
|
@@ -548,7 +554,7 @@ struct ImGuiIO
|
548
|
554
|
float MouseDownTime[5];
|
549
|
555
|
float KeysDownTime[512];
|
550
|
556
|
|
551
|
|
- IMGUI_API ImGuiIO();
|
|
557
|
+ IMGUI_API ImGuiIO();
|
552
|
558
|
};
|
553
|
559
|
|
554
|
560
|
//-----------------------------------------------------------------------------
|
|
@@ -673,13 +679,14 @@ struct ImGuiTextEditCallbackData
|
673
|
679
|
|
674
|
680
|
//-----------------------------------------------------------------------------
|
675
|
681
|
// Draw List
|
676
|
|
-// Hold a series of drawing commands. The user provide a renderer for ImDrawList
|
|
682
|
+// Hold a series of drawing commands. The user provides a renderer for ImDrawList
|
677
|
683
|
//-----------------------------------------------------------------------------
|
678
|
684
|
|
679
|
685
|
struct ImDrawCmd
|
680
|
686
|
{
|
681
|
687
|
unsigned int vtx_count;
|
682
|
688
|
ImVec4 clip_rect;
|
|
689
|
+ ImTextureID texture_id; // Copy of user-provided 'TexID' from ImFont or passed to Image*() functions. Ignore if not using images or multiple fonts.
|
683
|
690
|
};
|
684
|
691
|
|
685
|
692
|
#ifndef IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT
|
|
@@ -710,16 +717,22 @@ struct ImDrawList
|
710
|
717
|
ImVector<ImDrawVert> vtx_buffer; // each command consume ImDrawCmd::vtx_count of those
|
711
|
718
|
|
712
|
719
|
// [Internal to ImGui]
|
713
|
|
- ImVector<ImVec4> clip_rect_stack; // [internal] clip rect stack while building the command-list (so text command can perform clipping early on)
|
|
720
|
+ ImVector<ImVec4> clip_rect_stack; // [internal]
|
|
721
|
+ ImVector<ImTextureID> texture_id_stack; // [internal]
|
714
|
722
|
ImDrawVert* vtx_write; // [internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much)
|
715
|
723
|
|
716
|
724
|
ImDrawList() { Clear(); }
|
717
|
725
|
|
718
|
726
|
IMGUI_API void Clear();
|
|
727
|
+ IMGUI_API void SetClipRect(const ImVec4& clip_rect);
|
719
|
728
|
IMGUI_API void PushClipRect(const ImVec4& clip_rect);
|
720
|
729
|
IMGUI_API void PopClipRect();
|
|
730
|
+ IMGUI_API void SetTextureID(const ImTextureID& texture_id);
|
|
731
|
+ IMGUI_API void PushTextureID(const ImTextureID& texture_id);
|
|
732
|
+ IMGUI_API void PopTextureID();
|
721
|
733
|
IMGUI_API void ReserveVertices(unsigned int vtx_count);
|
722
|
734
|
IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col);
|
|
735
|
+ IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv);
|
723
|
736
|
IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col);
|
724
|
737
|
|
725
|
738
|
// Primitives
|
|
@@ -731,99 +744,98 @@ struct ImDrawList
|
731
|
744
|
IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
|
732
|
745
|
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));
|
733
|
746
|
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);
|
|
747
|
+ IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col);
|
734
|
748
|
};
|
735
|
749
|
|
736
|
|
-// Bitmap font data loader & renderer into vertices
|
737
|
|
-// Using the .fnt format exported by BMFont
|
738
|
|
-// - tool: http://www.angelcode.com/products/bmfont
|
739
|
|
-// - file-format: http://www.angelcode.com/products/bmfont/doc/file_format.html
|
740
|
|
-// Assume valid file data (won't handle invalid/malicious data)
|
741
|
|
-// Handle a subset of the options, namely:
|
742
|
|
-// - 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)
|
743
|
|
-struct ImFont
|
|
750
|
+// Load and rasterize multiple TTF fonts into a same texture.
|
|
751
|
+// Sharing a texture for multiple fonts allows us to reduce the number of draw calls during rendering.
|
|
752
|
+// We also add custom graphic data into the texture that serves for ImGui.
|
|
753
|
+// 1. (Optional) Call AddFont*** functions. If you don't call any, the default font will be loaded for you.
|
|
754
|
+// 2. Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data.
|
|
755
|
+// 3. Upload the pixels data into a texture within your graphics system.
|
|
756
|
+// 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.
|
|
757
|
+// 5. Call ClearPixelsData() to free textures memory on the heap.
|
|
758
|
+struct ImFontAtlas
|
744
|
759
|
{
|
745
|
|
- struct FntInfo;
|
746
|
|
- struct FntCommon;
|
747
|
|
- struct FntGlyph;
|
748
|
|
- struct FntKerning;
|
749
|
|
-
|
750
|
|
- // Settings
|
751
|
|
- float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
752
|
|
- ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
753
|
|
- ImVec2 TexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
|
754
|
|
- ImWchar FallbackChar; // = '?' // Replacement glyph is one isn't found.
|
755
|
|
-
|
756
|
|
- // Data
|
757
|
|
- unsigned char* Data; // Raw data, content of .fnt file
|
758
|
|
- size_t DataSize; //
|
759
|
|
- bool DataOwned; //
|
760
|
|
- const FntInfo* Info; // (point into raw data)
|
761
|
|
- const FntCommon* Common; // (point into raw data)
|
762
|
|
- const FntGlyph* Glyphs; // (point into raw data)
|
763
|
|
- size_t GlyphsCount; //
|
764
|
|
- const FntKerning* Kerning; // (point into raw data) - NB: kerning is unsupported
|
765
|
|
- size_t KerningCount; //
|
766
|
|
- ImVector<const char*> Filenames; // (point into raw data)
|
767
|
|
- ImVector<int> IndexLookup; // (built)
|
768
|
|
- const FntGlyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
769
|
|
-
|
770
|
|
- IMGUI_API ImFont();
|
771
|
|
- IMGUI_API ~ImFont() { Clear(); }
|
772
|
|
-
|
773
|
|
- IMGUI_API bool LoadFromMemory(const void* data, size_t data_size);
|
774
|
|
- IMGUI_API bool LoadFromFile(const char* filename);
|
|
760
|
+ IMGUI_API ImFontAtlas();
|
|
761
|
+ IMGUI_API ~ImFontAtlas();
|
|
762
|
+ IMGUI_API ImFont* AddFontDefault();
|
|
763
|
+ IMGUI_API ImFont* AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges = NULL, int font_no = 0);
|
|
764
|
+ 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.
|
|
765
|
+ IMGUI_API void ClearTexData(); // Saves RAM once the texture has been copied to graphics memory.
|
775
|
766
|
IMGUI_API void Clear();
|
776
|
|
- IMGUI_API void BuildLookupTable();
|
777
|
|
- IMGUI_API const FntGlyph* FindGlyph(unsigned short c) const;
|
778
|
|
- IMGUI_API bool IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; }
|
779
|
|
-
|
780
|
|
- // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
781
|
|
- // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
782
|
|
- 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
|
783
|
|
- IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar
|
784
|
|
- 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;
|
785
|
|
-
|
786
|
|
- IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
|
787
|
|
-
|
788
|
|
-#pragma pack(push, 1)
|
789
|
|
- struct FntInfo
|
790
|
|
- {
|
791
|
|
- signed short FontSize;
|
792
|
|
- unsigned char BitField; // bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeight, bits 5-7: reserved
|
793
|
|
- unsigned char CharSet;
|
794
|
|
- unsigned short StretchH;
|
795
|
|
- unsigned char AA;
|
796
|
|
- unsigned char PaddingUp, PaddingRight, PaddingDown, PaddingLeft;
|
797
|
|
- unsigned char SpacingHoriz, SpacingVert, Outline;
|
798
|
|
- //char FontName[];
|
799
|
|
- };
|
800
|
767
|
|
801
|
|
- struct FntCommon
|
802
|
|
- {
|
803
|
|
- unsigned short LineHeight, Base;
|
804
|
|
- unsigned short ScaleW, ScaleH;
|
805
|
|
- unsigned short Pages;
|
806
|
|
- unsigned char BitField;
|
807
|
|
- unsigned char Channels[4];
|
808
|
|
- };
|
|
768
|
+ // Retrieve texture data
|
|
769
|
+ // User is in charge of copying the pixels into graphics memory, then call SetTextureUserID()
|
|
770
|
+ // After loading the texture into your graphic system, store your texture handle in 'TexID' (ignore if you aren't using multiple fonts nor images)
|
|
771
|
+ // RGBA32 format is provided for convenience and high compatibility, but note that all RGB pixels are white, so 75% of the memory is wasted.
|
|
772
|
+ IMGUI_API void GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 1 byte per-pixel
|
|
773
|
+ IMGUI_API void GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel = NULL); // 4 bytes-per-pixel
|
|
774
|
+ IMGUI_API void SetTexID(void* id) { TexID = id; }
|
|
775
|
+
|
|
776
|
+ // Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
|
|
777
|
+ // (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)
|
|
778
|
+ IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
|
|
779
|
+ IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
|
780
|
+ IMGUI_API const ImWchar* GetGlyphRangesChinese(); // Japanese + full set of about 21000 CJK Unified Ideographs
|
|
781
|
+
|
|
782
|
+ // Members
|
|
783
|
+ // (Access texture data via GetTexData*() calls which will setup a default font for you.)
|
|
784
|
+ 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.
|
|
785
|
+ unsigned char* TexPixelsAlpha8; // 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
|
|
786
|
+ unsigned int* TexPixelsRGBA32; // 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
|
|
787
|
+ int TexWidth;
|
|
788
|
+ int TexHeight;
|
|
789
|
+ ImVec2 TexExtraDataPos; // Position of our rectangle where we draw non-font graphics
|
|
790
|
+ ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel (part of the TexExtraData block)
|
|
791
|
+ ImVector<ImFont*> Fonts;
|
|
792
|
+
|
|
793
|
+ // Private
|
|
794
|
+ struct ImFontAtlasData;
|
|
795
|
+ ImVector<ImFontAtlasData*> InputData; // Internal data
|
|
796
|
+ IMGUI_API bool Build(); // Build pixels data. This is automatically for you by the GetTexData*** functions.
|
|
797
|
+ IMGUI_API void ClearInputData(); // Clear the input TTF data.
|
|
798
|
+};
|
809
|
799
|
|
810
|
|
- struct FntGlyph
|
|
800
|
+// TTF font loading and rendering
|
|
801
|
+// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
|
|
802
|
+// Kerning isn't supported. At the moment some ImGui code does per-character CalcTextSize calls, need something more state-ful.
|
|
803
|
+struct ImFont
|
|
804
|
+{
|
|
805
|
+ // Members: Settings
|
|
806
|
+ float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
|
|
807
|
+ float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
|
808
|
+ ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
|
809
|
+ ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found.
|
|
810
|
+
|
|
811
|
+ // Members: Runtime data
|
|
812
|
+ struct Glyph
|
811
|
813
|
{
|
812
|
|
- unsigned int Id;
|
813
|
|
- unsigned short X, Y, Width, Height;
|
814
|
|
- signed short XOffset, YOffset;
|
|
814
|
+ ImWchar Codepoint;
|
815
|
815
|
signed short XAdvance;
|
816
|
|
- unsigned char Page;
|
817
|
|
- unsigned char Channel;
|
|
816
|
+ signed short Width, Height;
|
|
817
|
+ signed short XOffset, YOffset;
|
|
818
|
+ float U0, V0, U1, V1; // Texture coordinates
|
818
|
819
|
};
|
|
820
|
+ ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
|
821
|
+ ImVector<Glyph> Glyphs;
|
|
822
|
+ ImVector<int> IndexLookup; // Index glyphs by Unicode code-point
|
|
823
|
+ const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
819
|
824
|
|
820
|
|
- struct FntKerning
|
821
|
|
- {
|
822
|
|
- unsigned int IdFirst;
|
823
|
|
- unsigned int IdSecond;
|
824
|
|
- signed short Amount;
|
825
|
|
- };
|
826
|
|
-#pragma pack(pop)
|
|
825
|
+ // Methods
|
|
826
|
+ IMGUI_API ImFont();
|
|
827
|
+ IMGUI_API ~ImFont() { Clear(); }
|
|
828
|
+ IMGUI_API void Clear();
|
|
829
|
+ IMGUI_API void BuildLookupTable();
|
|
830
|
+ IMGUI_API const Glyph* FindGlyph(unsigned short c) const;
|
|
831
|
+ IMGUI_API bool IsLoaded() const { return ContainerAtlas != NULL; }
|
|
832
|
+
|
|
833
|
+ // 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
|
|
834
|
+ // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
|
835
|
+ 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
|
|
836
|
+ IMGUI_API ImVec2 CalcTextSizeW(float size, float max_width, const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL) const; // wchar
|
|
837
|
+ 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;
|
|
838
|
+ IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
|
827
|
839
|
};
|
828
|
840
|
|
829
|
841
|
//---- Include imgui_user.h at the end of imgui.h
|