examples: updated svg.

revised the logic to align svg images in the center of the grids.

this is the subsequent changes to 3939b61770.
This commit is contained in:
Hermet Park 2022-09-02 12:10:36 +09:00
parent 93b88370ad
commit e2057d10f1

View file

@ -48,8 +48,22 @@ void svgDirCallback(const char* name, const char* path, void* data)
if (picture->load(buf) != tvg::Result::Success) return;
picture->size(SIZE, SIZE);
picture->translate((count % NUM_PER_ROW) * SIZE, (count / NUM_PER_ROW) * (HEIGHT / NUM_PER_COL));
//image scaling preserving its aspect ratio
float scale;
float shiftX = 0.0f, shiftY = 0.0f;
float w, h;
picture->size(&w, &h);
if (w > h) {
scale = SIZE / w;
shiftY = (SIZE - h * scale) * 0.5f;
} else {
scale = SIZE / h;
shiftX = (SIZE - w * scale) * 0.5f;
}
picture->scale(scale);
picture->translate((count % NUM_PER_ROW) * SIZE + shiftX, (count / NUM_PER_ROW) * (HEIGHT / NUM_PER_COL) + shiftY);
pictures.push_back(move(picture));