Improve macOS Retina UI clarity and bundle HD assets
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#include "../../src/host/ui_quality.h"
|
||||
#include "../../src/host/hd_ui_archive.h"
|
||||
#include <unistd.h>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
int failures=0;
|
||||
auto check=[&](bool ok,const char* message) { if (!ok) { std::fprintf(stderr,"FAIL %s\n",message); ++failures; } };
|
||||
using namespace mt_host;
|
||||
check(font_raster_scale(1)==1 && font_raster_scale(2)==2 && font_raster_scale(2.01f)==3,
|
||||
"fractional density uses enough glyph texels");
|
||||
float x[]={0.25f,32.25f,0.25f,32.25f}, y[]={0.125f,0.125f,32.125f,32.125f};
|
||||
check(align_ui_quad(x,y,2,2),"axis aligned icon snaps");
|
||||
check(x[0]*2==std::round(x[0]*2) && y[0]*2==std::round(y[0]*2) && x[1]-x[0]==32,
|
||||
"physical origin aligns without resizing");
|
||||
x[2]+=1;
|
||||
check(!align_ui_quad(x,y,2,2),"rotated quad remains unchanged");
|
||||
check(ui_texels_match_pixels(64,64,64,64),"2x HD icon at 1:1 uses point sampling");
|
||||
check(!ui_texels_match_pixels(64,64,32,32) && !ui_texels_match_pixels(48,48,64,64),
|
||||
"upsized original art and downsized HD retain linear filtering");
|
||||
|
||||
char path[]="/tmp/metin2-hd-archive-XXXXXX";
|
||||
const int fd=mkstemp(path);
|
||||
check(fd>=0,"archive test fixture");
|
||||
if (fd<0) return 1;
|
||||
close(fd);
|
||||
std::vector<unsigned char> data={'M','T','H','D',1,0,0,0,1,0,0,0,3,0,'f','o','o',25,0,0,0,4,0,0,0,1,2,3,4};
|
||||
auto save=[&] { auto* f=std::fopen(path,"wb"); std::fwrite(data.data(),1,data.size(),f); std::fclose(f); };
|
||||
save();
|
||||
{ HdUiArchive archive; std::vector<std::uint8_t> out;
|
||||
check(archive.open(path) && archive.size()==1 && archive.read("foo",out) && out==std::vector<std::uint8_t>({1,2,3,4}),
|
||||
"valid resource archive payload");
|
||||
check(!archive.read("missing",out),"uncovered asset falls back"); }
|
||||
data[21]=200; save();
|
||||
{ HdUiArchive archive; check(!archive.open(path) && archive.size()==0,"invalid payload range rejected"); }
|
||||
data.resize(20); save();
|
||||
{ HdUiArchive archive; check(!archive.open(path),"truncated index rejected"); }
|
||||
unlink(path);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
@@ -132,6 +132,45 @@ int main()
|
||||
}
|
||||
CHECK(inked);
|
||||
|
||||
// PORT: changing monitors must rebuild glyph rasters, not text layout. Existing
|
||||
// CGraphicTextInstance objects retain pointers into the character-info map.
|
||||
auto* font = text->GetFontTexturePointer();
|
||||
auto* glyph = font->GetCharacterInfomation(1252, L'H');
|
||||
const auto original_glyph = *glyph;
|
||||
int page_width = 0, page_height = 0;
|
||||
for (const auto& command : UIRenderCommands()) {
|
||||
UIMemoryTexture page;
|
||||
if (UIRenderMemoryTexture(command.text, &page)) {
|
||||
page_width = page.width; page_height = page.height; break;
|
||||
}
|
||||
}
|
||||
CHECK(page_width > 0);
|
||||
for (int scale : {2, 3, 1, 2}) {
|
||||
UISetFontOversample(scale);
|
||||
CHECK(UIFontOversample() == scale);
|
||||
CHECK(font->GetCharacterInfomation(1252, L'H') == glyph);
|
||||
CHECK(glyph->width == original_glyph.width && glyph->height == original_glyph.height &&
|
||||
glyph->advance == original_glyph.advance);
|
||||
UIRenderBeginFrame();
|
||||
instance.Render(); // use the already cached glyph pointers
|
||||
CHECK(glyph_quads(&left, &right) == 5);
|
||||
int new_width = 0, new_height = 0;
|
||||
instance.GetTextSize(&new_width, &new_height);
|
||||
CHECK(new_width == width && new_height == height);
|
||||
bool sized = false, fine_coverage = false;
|
||||
for (const auto& command : UIRenderCommands()) {
|
||||
UIMemoryTexture page;
|
||||
if (!UIRenderMemoryTexture(command.text, &page)) continue;
|
||||
sized |= page.width == page_width * scale && page.height == page_height * scale;
|
||||
for (auto argb : page.argb) {
|
||||
const auto alpha = argb >> 24;
|
||||
fine_coverage |= alpha > 0 && alpha < 255 && alpha % 17 != 0;
|
||||
}
|
||||
}
|
||||
CHECK(sized);
|
||||
if (scale > 1) CHECK(fine_coverage); // 8-bit alpha, not the old 4-bit quantisation
|
||||
}
|
||||
|
||||
instance.Destroy();
|
||||
text->Release();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user