Skip to content

Commit 2a16883

Browse files
committed
WIP - Fonts: internal rendering uses higher level functions.
1 parent 6828437 commit 2a16883

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

imgui_draw.cpp

+19-17
Original file line numberDiff line numberDiff line change
@@ -3467,27 +3467,28 @@ static void ImFontAtlasBuildUpdateBasicTexData(ImFontAtlas* atlas, bool add_and_
34673467
builder->PackIdMouseCursors = ImFontAtlasPackAddRect(atlas, pack_size.x, pack_size.y);
34683468
if (builder->PackIdMouseCursors == ImFontAtlasRectId_Invalid)
34693469
return;
3470-
ImTextureRect* r = ImFontAtlasPackGetRect(atlas, builder->PackIdMouseCursors);
3470+
ImFontAtlasRect r;
3471+
atlas->GetCustomRect(builder->PackIdMouseCursors, &r);
34713472

34723473
// Draw to texture
34733474
if (add_and_draw)
34743475
{
34753476
if (atlas->Flags & ImFontAtlasFlags_NoMouseCursors)
34763477
{
34773478
// 2x2 white pixels
3478-
ImFontAtlasBuildRenderBitmapFromString(atlas, r->x, r->y, 2, 2, "XX" "XX", 'X');
3479+
ImFontAtlasBuildRenderBitmapFromString(atlas, r.x, r.y, 2, 2, "XX" "XX", 'X');
34793480
}
34803481
else
34813482
{
34823483
// 2x2 white pixels + mouse cursors
3483-
const int x_for_white = r->x;
3484-
const int x_for_black = r->x + FONT_ATLAS_DEFAULT_TEX_DATA_W + 1;
3485-
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, '.');
3486-
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');
3484+
const int x_for_white = r.x;
3485+
const int x_for_black = r.x + FONT_ATLAS_DEFAULT_TEX_DATA_W + 1;
3486+
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, '.');
3487+
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');
34873488
}
34883489
}
3489-
ImFontAtlasTextureBlockQueueUpload(atlas, atlas->TexData, r->x, r->y, r->w, r->h);
3490-
atlas->TexUvWhitePixel = ImVec2((r->x + 0.5f) * atlas->TexUvScale.x, (r->y + 0.5f) * atlas->TexUvScale.y);
3490+
ImFontAtlasTextureBlockQueueUpload(atlas, atlas->TexData, r.x, r.y, r.w, r.h);
3491+
atlas->TexUvWhitePixel = ImVec2((r.x + 0.5f) * atlas->TexUvScale.x, (r.y + 0.5f) * atlas->TexUvScale.y);
34913492
}
34923493

34933494
static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_draw)
@@ -3503,7 +3504,8 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
35033504
builder->PackIdLinesTexData = ImFontAtlasPackAddRect(atlas, pack_size.x, pack_size.y);
35043505
if (builder->PackIdLinesTexData == ImFontAtlasRectId_Invalid)
35053506
return;
3506-
ImTextureRect* r = ImFontAtlasPackGetRect(atlas, builder->PackIdLinesTexData);
3507+
ImFontAtlasRect r;
3508+
atlas->GetCustomRect(builder->PackIdLinesTexData, &r);
35073509

35083510
// Register texture region for thick lines
35093511
// 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
@@ -3514,18 +3516,18 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
35143516
// Each line consists of at least two empty pixels at the ends, with a line of solid pixels in the middle
35153517
int y = n;
35163518
int line_width = n;
3517-
int pad_left = (r->w - line_width) / 2;
3518-
int pad_right = r->w - (pad_left + line_width);
3519+
int pad_left = (r.w - line_width) / 2;
3520+
int pad_right = r.w - (pad_left + line_width);
35193521

35203522
// Write each slice
3521-
IM_ASSERT(pad_left + line_width + pad_right == r->w && y < r->h); // Make sure we're inside the texture bounds before we start writing pixels
3523+
IM_ASSERT(pad_left + line_width + pad_right == r.w && y < r.h); // Make sure we're inside the texture bounds before we start writing pixels
35223524
if (add_and_draw)
35233525
{
35243526
switch (tex->Format)
35253527
{
35263528
case ImTextureFormat_Alpha8:
35273529
{
3528-
ImU8* write_ptr = (ImU8*)tex->GetPixelsAt(r->x, r->y + y);
3530+
ImU8* write_ptr = (ImU8*)tex->GetPixelsAt(r.x, r.y + y);
35293531
for (int i = 0; i < pad_left; i++)
35303532
*(write_ptr + i) = 0x00;
35313533

@@ -3538,7 +3540,7 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
35383540
}
35393541
case ImTextureFormat_RGBA32:
35403542
{
3541-
ImU32* write_ptr = (ImU32*)(void*)tex->GetPixelsAt(r->x, r->y + y);
3543+
ImU32* write_ptr = (ImU32*)(void*)tex->GetPixelsAt(r.x, r.y + y);
35423544
for (int i = 0; i < pad_left; i++)
35433545
*(write_ptr + i) = IM_COL32(255, 255, 255, 0);
35443546

@@ -3553,12 +3555,12 @@ static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas, bool add_and_
35533555
}
35543556

35553557
// Calculate UVs for this line
3556-
ImVec2 uv0 = ImVec2((float)(r->x + pad_left - 1), (float)(r->y + y)) * atlas->TexUvScale;
3557-
ImVec2 uv1 = ImVec2((float)(r->x + pad_left + line_width + 1), (float)(r->y + y + 1)) * atlas->TexUvScale;
3558+
ImVec2 uv0 = ImVec2((float)(r.x + pad_left - 1), (float)(r.y + y)) * atlas->TexUvScale;
3559+
ImVec2 uv1 = ImVec2((float)(r.x + pad_left + line_width + 1), (float)(r.y + y + 1)) * atlas->TexUvScale;
35583560
float half_v = (uv0.y + uv1.y) * 0.5f; // Calculate a constant V in the middle of the row to avoid sampling artifacts
35593561
atlas->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v);
35603562
}
3561-
ImFontAtlasTextureBlockQueueUpload(atlas, tex, r->x, r->y, r->w, r->h);
3563+
ImFontAtlasTextureBlockQueueUpload(atlas, tex, r.x, r.y, r.w, r.h);
35623564
}
35633565

35643566
//-----------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)