port(EterLib): TextBar/DibBar/BlockTexture for uiTip TipBoard/BigBoard
TextBar and DibBar verbatim over the FreeType GDI shim (+GetTextExtentPoint32A); BlockTexture verbatim except Render, which records the clipped quad as a UI image of the device CPU texture (UIRenderAddImageNamed). Notices now render; port.text_bar covers block split, pixels, colour, ClearBar and TipBoard clip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c7bcb9bbbe
commit
6d2d262de8
@@ -0,0 +1,170 @@
|
||||
// EterLib CTextBar -> CDibBar -> CBlockTexture (40250 uiTip.TipBoard / BigBoard: grp.CreateTextBar):
|
||||
// GDI text into the DIB over platform/Win32Gdi.cpp, the DIB split into power-of-two device textures,
|
||||
// and each block's quad recorded as a UI image (the draw 40250 sends through the device).
|
||||
//
|
||||
// Needs a system Arial or Tahoma; exit 77 (ctest SKIP) without one, unless MT_ASSETS_STRICT=1.
|
||||
#include "EterLib/StdAfx.h"
|
||||
#include "EterLib/TextBar.h"
|
||||
#include "EterLib/GrpBase.h"
|
||||
#include "EterLib/Util.h"
|
||||
#include "../../src/platform/EterLib/UIRenderCommands.h"
|
||||
#include "../../src/platform/EterLib/RecordingDevice.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
static int g_failures = 0;
|
||||
#define CHECK(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::fprintf(stderr, "%s:%d: CHECK(%s)\n", __FILE__, __LINE__, #cond); \
|
||||
++g_failures; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
struct DeviceAccess : CGraphicBase
|
||||
{
|
||||
static void Set(IDirect3DDevice8* device) { ms_lpd3dDevice = device; }
|
||||
};
|
||||
|
||||
static std::vector<UIRenderCommand> images()
|
||||
{
|
||||
std::vector<UIRenderCommand> out;
|
||||
for (const auto& command : UIRenderCommands())
|
||||
if (command.kind == UIRenderCommand::Image)
|
||||
out.push_back(command);
|
||||
return out;
|
||||
}
|
||||
|
||||
static int opaque_pixels(const std::string& name, std::uint32_t* sample)
|
||||
{
|
||||
UIMemoryTexture texture;
|
||||
if (!UIRenderMemoryTexture(name, &texture))
|
||||
return -1;
|
||||
int count = 0;
|
||||
for (std::uint32_t px : texture.argb)
|
||||
{
|
||||
if ((px >> 24) == 0xFF)
|
||||
{
|
||||
++count;
|
||||
*sample = px;
|
||||
}
|
||||
else if (px >> 24)
|
||||
return -2; // InvalidateRect writes either 0 or src | 0xff000000
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static bool near(float a, float b)
|
||||
{
|
||||
return std::fabs(a - b) < 1e-3f;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const bool is_strict = std::getenv("MT_ASSETS_STRICT") && std::string(std::getenv("MT_ASSETS_STRICT")) == "1";
|
||||
if (access("/System/Library/Fonts/Supplemental/Arial.ttf", 0) != 0 && access("/System/Library/Fonts/Supplemental/Tahoma.ttf", 0) != 0)
|
||||
{
|
||||
std::fprintf(stderr, "port_text_bar_test: no system Arial/Tahoma\n");
|
||||
return is_strict ? 1 : 77;
|
||||
}
|
||||
SetDefaultCodePage(1252);
|
||||
IDirect3DDevice8* device = MtCreateRecordingDevice(800, 600);
|
||||
DeviceAccess::Set(device);
|
||||
|
||||
{
|
||||
// uiTip.TipBoard: grp.CreateTextBar(370, 300) -> CTextBar(12, false).
|
||||
CTextBar bar(12, false);
|
||||
CHECK(bar.Create(NULL, 370, 300));
|
||||
|
||||
SIZE size = {};
|
||||
bar.GetTextExtent("Notice", &size);
|
||||
CHECK(size.cx > 20 && size.cx < 60 && size.cy >= 12 && size.cy <= 16);
|
||||
|
||||
bar.TextOut(0, 0, "Notice");
|
||||
UIRenderBeginFrame();
|
||||
bar.Render(10, 20);
|
||||
std::vector<UIRenderCommand> blocks = images();
|
||||
// 370 x 300 = 256 + 114 by 256 + 44: blocks of 256x256, 128x256, 256x64, 128x64 texels.
|
||||
CHECK(blocks.size() == 4);
|
||||
if (blocks.size() == 4)
|
||||
{
|
||||
CHECK(blocks[0].text.compare(0, 8, "mem:cpu_") == 0);
|
||||
// Unclipped: the quad is the full texture from the block origin, shifted +0.5 back.
|
||||
CHECK(near(blocks[0].qx[0], 10.0f) && near(blocks[0].qy[0], 20.0f));
|
||||
CHECK(near(blocks[0].qx[3], 266.0f) && near(blocks[0].qy[3], 276.0f));
|
||||
CHECK(near(blocks[1].qx[0], 266.0f) && near(blocks[1].qx[3], 394.0f));
|
||||
CHECK(near(blocks[2].qy[0], 276.0f) && near(blocks[2].qy[3], 340.0f));
|
||||
CHECK(blocks[0].su == 0.0f && blocks[0].ev == 1.0f);
|
||||
|
||||
std::uint32_t sample = 0;
|
||||
const int lit = opaque_pixels(blocks[0].text, &sample);
|
||||
CHECK(lit > 20);
|
||||
// CGraphicDib::Create sets a white text colour; anti-aliased edges stay grey.
|
||||
CHECK(((sample >> 16) & 0xFF) > 0 && ((sample >> 16) & 0xFF) == (sample & 0xFF));
|
||||
std::uint32_t unused = 0;
|
||||
CHECK(opaque_pixels(blocks[1].text, &unused) == 0);
|
||||
}
|
||||
|
||||
// uiTip.BigBoard colour; ClearBar zeroes the DIB and every block.
|
||||
bar.SetTextColor(242, 231, 193);
|
||||
bar.TextOut(0, 0, "Notice");
|
||||
UIRenderBeginFrame();
|
||||
bar.Render(0, 0);
|
||||
blocks = images();
|
||||
if (!blocks.empty())
|
||||
{
|
||||
std::uint32_t sample = 0;
|
||||
CHECK(opaque_pixels(blocks[0].text, &sample) > 20);
|
||||
}
|
||||
bar.ClearBar();
|
||||
UIRenderBeginFrame();
|
||||
bar.Render(0, 0);
|
||||
blocks = images();
|
||||
if (!blocks.empty())
|
||||
{
|
||||
std::uint32_t sample = 0;
|
||||
CHECK(opaque_pixels(blocks[0].text, &sample) == 0);
|
||||
}
|
||||
|
||||
// TipBoard's SetClipRect(0, y, screen width, y + 18) at textBar position (3, 5 - curPos):
|
||||
// the lower blocks start past the clip bottom and are skipped, the upper ones are cut to 18 rows.
|
||||
RECT clip = {0, 20, 800, 38};
|
||||
bar.SetClipRect(clip);
|
||||
UIRenderBeginFrame();
|
||||
bar.Render(3, 5);
|
||||
blocks = images();
|
||||
CHECK(blocks.size() == 2);
|
||||
if (blocks.size() == 2)
|
||||
{
|
||||
CHECK(near(blocks[0].qy[0], 20.0f) && near(blocks[0].qy[3], 38.0f));
|
||||
CHECK(near(blocks[0].sv, 15.0f / 256.0f) && near(blocks[0].ev, 1.0f - 223.0f / 256.0f));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// uiTip.BigBoard: grp.CreateBigTextBar(500, 300, 18) -> CTextBar(18, true).
|
||||
CTextBar big(18, true);
|
||||
CHECK(big.Create(NULL, 500, 300));
|
||||
SIZE small = {}, large = {};
|
||||
CTextBar normal(12, false);
|
||||
CHECK(normal.Create(NULL, 64, 64));
|
||||
normal.GetTextExtent("Notice", &small);
|
||||
big.GetTextExtent("Notice", &large);
|
||||
CHECK(large.cx > small.cx && large.cy > small.cy);
|
||||
UIRenderBeginFrame();
|
||||
normal.Render(0, 0);
|
||||
CHECK(images().size() == 1); // 64 x 64 fits in one block (count 0, rest 64)
|
||||
}
|
||||
|
||||
DeviceAccess::Set(NULL);
|
||||
device->Release();
|
||||
if (!g_failures)
|
||||
std::printf("ok\n");
|
||||
return g_failures ? 1 : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user