ImVec2MouseDelta;// Mouse delta. Note that this is zero if either current or previous position are negative, so a disappearing/reappearing mouse won't have a huge delta for one frame.
ImVec2MousePosPrev;// Previous mouse position temporary storage (nb: not for public use, set to MousePos in NewFrame())
@ -1375,7 +1375,7 @@ struct ImFontConfig
floatSizePixels;// // Size in pixels for rasterizer.
intOversampleH,OversampleV;// 3, 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
boolPixelSnapH;// false // Align every glyph to pixel boundary. Useful e.g. if you are merging a non-pixel aligned font with the default font. If enabled, you can set OversampleH/V to 1.
ImVec2GlyphExtraSpacing;// 0, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now.
ImVec2GlyphExtraSpacing;// 1, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now.
ImVec2GlyphOffset;// 0, 0 // Offset all glyphs from this font input.
constImWchar*GlyphRanges;// NULL // Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE.
boolMergeMode;// false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights.
@ -1389,6 +1389,14 @@ struct ImFontConfig
IMGUI_APIImFontConfig();
};
structImFontGlyph
{
ImWcharCodepoint;// 0x0000..0xFFFF
floatAdvanceX;// Distance to next character (= data from font + ImFontConfig::GlyphExtraSpacing.x baked in)
floatX0,Y0,X1,Y1;// Glyph corners
floatU0,V0,U1,V1;// Texture coordinates
};
// Load and rasterize multiple TTF/OTF 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.
@ -1412,25 +1420,29 @@ struct ImFontAtlas
IMGUI_APIvoidClearFonts();// Clear the ImGui-side font data (glyphs storage, UV coordinates)
IMGUI_APIvoidClear();// Clear all
// 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.
// Build atlas, retrieve pixel data.
// User is in charge of copying the pixels into graphics memory (e.g. create a texture with your engine). Then store your texture handle with SetTexID().
// RGBA32 format is provided for convenience and compatibility, but note that unless you use CustomRect to draw color data, the RGB pixels emitted from Fonts will all be white (~75% of waste).
// Pitch = Width * BytesPerPixels
IMGUI_APIboolBuild();// Build pixels data. This is called automatically for you by the GetTexData*** functions.
// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
// NB: Make sure that your string are UTF-8 and NOT in your local code page. In C++11, you can create UTF-8 string literal using the u8"Hello world" syntax. See FAQ for details.
IMGUI_APIconstImWchar*GetGlyphRangesDefault();// Basic Latin, Extended Latin
IMGUI_APIconstImWchar*GetGlyphRangesKorean();// Default + Korean characters
IMGUI_APIconstImWchar*GetGlyphRangesJapanese();// Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
IMGUI_APIconstImWchar*GetGlyphRangesChinese();// Japanese + full set of about 21000 CJK Unified Ideographs
IMGUI_APIconstImWchar*GetGlyphRangesChinese();// Default + Japanese + full set of about 21000 CJK Unified Ideographs
IMGUI_APIconstImWchar*GetGlyphRangesCyrillic();// Default + about 400 Cyrillic characters
// Helpers to build glyph ranges from text data. Feed all your application strings/characters to it then call BuildRanges().
// Helpers to build glyph ranges from text data. Feed your application strings/characters to it then call BuildRanges().
structGlyphRangesBuilder
{
ImVector<unsignedchar>UsedChars;// Store 1-bit per Unicode code point (0=unused, 1=used)
@ -1443,57 +1455,64 @@ struct ImFontAtlas
IMGUI_APIvoidBuildRanges(ImVector<ImWchar>*out_ranges);// Output new ranges
};
// Members
// (Access texture data via GetTexData*() calls which will setup a default font for you.)
ImTextureIDTexID;// User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure.
unsignedchar*TexPixelsAlpha8;// 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
unsignedint*TexPixelsRGBA32;// 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
intTexWidth;// Texture width calculated during Build().
intTexHeight;// Texture height calculated during Build().
intTexDesiredWidth;// Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height.
intTexGlyphPadding;// Padding between glyphs within texture in pixels. Defaults to 1.
ImVec2TexUvWhitePixel;// Texture coordinates to a white pixel
ImVector<ImFont*>Fonts;// Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font.
//-------------------------------------------
// Custom Rectangles/Glyphs API
//-------------------------------------------
// [Private] User rectangle for packing custom texture data into the atlas.
// You can request arbitrary rectangles to be packed into the atlas, for your own purposes. After calling Build(), you can query the rectangle position and render your pixels.
// You can also request your rectangles to be mapped as font glyph (given a font + Unicode point), so you can render e.g. custom colorful icons and use them as regular glyphs.
structCustomRect
{
unsignedintID;// Input // User ID. <0x10000 for font mapped data (WIP/UNSUPPORTED), >=0x10000 for other texture data
unsignedintID;// Input // User ID. Use <0x10000 to map into a font glyph, >=0x10000 for other/internal/custom texture data.
IMGUI_APIintAddCustomRectRegular(unsignedintid,intwidth,intheight);// Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
IMGUI_APIintAddCustomRectFontGlyph(ImFont*font,ImWcharid,intwidth,intheight,floatadvance_x,constImVec2&offset=ImVec2(0,0));// Id needs to be < 0x10000 to register a rectangle to map into a specific font.
ImTextureIDTexID;// User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure.
intTexDesiredWidth;// Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height.
intTexGlyphPadding;// Padding between glyphs within texture in pixels. Defaults to 1.
// [Internal]
// NB: Access texture data via GetTexData*() calls! Which will setup a default font for you.
unsignedchar*TexPixelsAlpha8;// 1 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight
unsignedint*TexPixelsRGBA32;// 4 component per pixel, each component is unsigned 8-bit. Total size = TexWidth * TexHeight * 4
intTexWidth;// Texture width calculated during Build().
intTexHeight;// Texture height calculated during Build().
ImVec2TexUvWhitePixel;// Texture coordinates to a white pixel
ImVector<ImFont*>Fonts;// Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font.
ImVector<CustomRect>CustomRects;// Rectangles for packing custom texture data into the atlas.
ImVector<ImFontConfig>ConfigData;// Internal data
IMGUI_APIboolBuild();// Build pixels data. This is automatically for you by the GetTexData*** functions.
intCustomRectIds[1];// Identifiers of custom texture rectangle used by ImFontAtlas/ImDrawList
};
// Font runtime data and rendering
// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
structImFont
{
structGlyph
{
ImWcharCodepoint;
floatXAdvance;
floatX0,Y0,X1,Y1;
floatU0,V0,U1,V1;// Texture coordinates
};
// Members: Hot ~62/78 bytes
floatFontSize;// <user set> // Height of characters, set during loading (don't change after loading)
floatScale;// = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
ImVec2DisplayOffset;// = (0.f,1.f) // Offset font rendering by xx pixels
ImVector<Glyph>Glyphs;// // All glyphs.
ImVector<float>IndexXAdvance;// // Sparse. Glyphs->XAdvance in a directly indexable way (more cache-friendly, for CalcTextSize functions which are often bottleneck in large UI).
ImVector<ImFontGlyph>Glyphs;// // All glyphs.
ImVector<float>IndexAdvanceX;// // Sparse. Glyphs->AdvanceX in a directly indexable way (more cache-friendly, for CalcTextSize functions which are often bottleneck in large UI).
ImVector<unsignedshort>IndexLookup;// // Sparse. Index glyphs by Unicode code-point.
IMGUI_APIvoidAddRemapChar(ImWchardst,ImWcharsrc,booloverwrite_dst=true);// Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built.
// Display all glyphs of the fonts in separate pages of 256 characters
constImFont::Glyph*glyph_fallback=font->FallbackGlyph;// Forcefully/dodgily make FindGlyph() return NULL on fallback, which isn't the default behavior.
constImFontGlyph*glyph_fallback=font->FallbackGlyph;// Forcefully/dodgily make FindGlyph() return NULL on fallback, which isn't the default behavior.
font->RenderChar(draw_list,cell_size.x,cell_p1,ImGui::GetColorU32(ImGuiCol_Text),(ImWchar)(base+n));// We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions available to generate a string.
glyph.XAdvance=(pc.xadvance+cfg.GlyphExtraSpacing.x);// Bake spacing into XAdvance
if(cfg.PixelSnapH)
glyph.XAdvance=(float)(int)(glyph.XAdvance+0.5f);
dst_font->MetricsTotalSurface+=(int)((glyph.U1-glyph.U0)*atlas->TexWidth+1.99f)*(int)((glyph.V1-glyph.V0)*atlas->TexHeight+1.99f);// +1 to account for average padding, +0.99 to round
// FIXME-WIP: We should register in the constructor (but cannot because our static instances may not have allocator ready by the time they initialize). This needs to be fixed because we can expose CustomRects.
IM_ASSERT(IndexLookup.Size>0);// Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function.