mirror of
https://github.com/ocornut/imgui.git
synced 2026-03-20 15:39:57 +00:00
Fonts: packing of shared basic/line/cursor data uses more public API.
This commit is contained in:
@@ -3452,23 +3452,21 @@ void ImFontAtlasBuildRenderBitmapFromString(ImFontAtlas* atlas, int x, int y, in
|
||||
}
|
||||
}
|
||||
|
||||
static void ImFontAtlasBuildUpdateBasicTexData(ImFontAtlas* atlas, bool add_and_draw)
|
||||
static void ImFontAtlasBuildUpdateBasicTexData(ImFontAtlas* atlas)
|
||||
{
|
||||
// Pack and store identifier so we can refresh UV coordinates on texture resize.
|
||||
// FIXME-NEWATLAS: User/custom rects where user code wants to store UV coordinates will need to do the same thing.
|
||||
ImFontAtlasBuilder* builder = atlas->Builder;
|
||||
ImVec2i pack_size = (atlas->Flags & ImFontAtlasFlags_NoMouseCursors) ? ImVec2i(2, 2) : ImVec2i(FONT_ATLAS_DEFAULT_TEX_DATA_W * 2 + 1, FONT_ATLAS_DEFAULT_TEX_DATA_H);
|
||||
|
||||
if (add_and_draw)
|
||||
builder->PackIdMouseCursors = ImFontAtlasPackAddRect(atlas, pack_size.x, pack_size.y);
|
||||
if (builder->PackIdMouseCursors == ImFontAtlasRectId_Invalid)
|
||||
return;
|
||||
ImFontAtlasRect r;
|
||||
atlas->GetCustomRect(builder->PackIdMouseCursors, &r);
|
||||
|
||||
// Draw to texture
|
||||
bool add_and_draw = (atlas->GetCustomRect(builder->PackIdMouseCursors, &r) == false);
|
||||
if (add_and_draw)
|
||||
{
|
||||
builder->PackIdMouseCursors = atlas->AddCustomRect(pack_size.x, pack_size.y, &r);
|
||||
IM_ASSERT(builder->PackIdMouseCursors != ImFontAtlasRectId_Invalid);
|
||||
|
||||
// Draw to texture
|
||||
if (atlas->Flags & ImFontAtlasFlags_NoMouseCursors)
|
||||
{
|
||||
// 2x2 white pixels
|
||||
@@ -3482,14 +3480,13 @@ static void ImFontAtlasBuildUpdateBasicTexData(ImFontAtlas* atlas, bool add_and_
|
||||
ImFontAtlasBuildRenderBitmapFromString(atlas, x_for_white, r.y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.');
|
||||
ImFontAtlasBuildRenderBitmapFromString(atlas, x_for_black, r.y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X');
|
||||
}
|
||||
ImFontAtlasTextureBlockQueueUpload(atlas, atlas->TexData, r.x, r.y, r.w, r.h);
|
||||
}
|
||||
|
||||
// Refresh UV coordinates
|
||||
atlas->TexUvWhitePixel = ImVec2((r.x + 0.5f) * atlas->TexUvScale.x, (r.y + 0.5f) * atlas->TexUvScale.y);
|
||||
}
|
||||
|
||||
static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_draw)
|
||||
static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas)
|
||||
{
|
||||
if (atlas->Flags & ImFontAtlasFlags_NoBakedLines)
|
||||
return;
|
||||
@@ -3497,14 +3494,15 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
|
||||
// Pack and store identifier so we can refresh UV coordinates on texture resize.
|
||||
ImTextureData* tex = atlas->TexData;
|
||||
ImFontAtlasBuilder* builder = atlas->Builder;
|
||||
ImVec2i pack_size = ImVec2i(IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 2, IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1);
|
||||
if (add_and_draw)
|
||||
builder->PackIdLinesTexData = ImFontAtlasPackAddRect(atlas, pack_size.x, pack_size.y);
|
||||
if (builder->PackIdLinesTexData == ImFontAtlasRectId_Invalid)
|
||||
return;
|
||||
|
||||
ImFontAtlasRect r;
|
||||
atlas->GetCustomRect(builder->PackIdLinesTexData, &r);
|
||||
bool add_and_draw = atlas->GetCustomRect(builder->PackIdLinesTexData, &r) == false;
|
||||
if (add_and_draw)
|
||||
{
|
||||
ImVec2i pack_size = ImVec2i(IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 2, IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1);
|
||||
builder->PackIdLinesTexData = atlas->AddCustomRect(pack_size.x, pack_size.y, &r);
|
||||
IM_ASSERT(builder->PackIdLinesTexData != ImFontAtlasRectId_Invalid);
|
||||
}
|
||||
|
||||
// Register texture region for thick lines
|
||||
// The +2 here is to give space for the end caps, whilst height +1 is to accommodate the fact we have a zero-width row
|
||||
@@ -3550,8 +3548,6 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
|
||||
float half_v = (uv0.y + uv1.y) * 0.5f; // Calculate a constant V in the middle of the row to avoid sampling artifacts
|
||||
atlas->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
|
||||
}
|
||||
if (add_and_draw)
|
||||
ImFontAtlasTextureBlockQueueUpload(atlas, tex, r.x, r.y, r.w, r.h);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -4025,8 +4021,8 @@ void ImFontAtlasBuildRepackTexture(ImFontAtlas* atlas, int w, int h)
|
||||
}
|
||||
|
||||
// Update other cached UV
|
||||
ImFontAtlasBuildUpdateLinesTexData(atlas, false);
|
||||
ImFontAtlasBuildUpdateBasicTexData(atlas, false);
|
||||
ImFontAtlasBuildUpdateLinesTexData(atlas);
|
||||
ImFontAtlasBuildUpdateBasicTexData(atlas);
|
||||
|
||||
builder->LockDisableResize = false;
|
||||
ImFontAtlasUpdateDrawListsSharedData(atlas);
|
||||
@@ -4176,8 +4172,8 @@ void ImFontAtlasBuildInit(ImFontAtlas* atlas)
|
||||
ImFontAtlasPackInit(atlas);
|
||||
|
||||
// Add required texture data
|
||||
ImFontAtlasBuildUpdateLinesTexData(atlas, true);
|
||||
ImFontAtlasBuildUpdateBasicTexData(atlas, true);
|
||||
ImFontAtlasBuildUpdateLinesTexData(atlas);
|
||||
ImFontAtlasBuildUpdateBasicTexData(atlas);
|
||||
|
||||
// Register fonts
|
||||
if (builder_is_new)
|
||||
|
||||
Reference in New Issue
Block a user