Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152// UI framework smoke test: the extracted bitmap font loads with sane metrics and proportional widths,// and a dialog renders its Win95 chrome (face colour + text) into a framebuffer. Skips if the font// assets aren't extracted yet (run extract_assets.py / extract_font.py).#include "sc2k/render/asset_loader.hpp"#include "sc2k/ui/dialog.hpp"#include "sc2k/ui/font.hpp"#include "sc2k/ui/menu.hpp"#include "sc2k/ui/toolbar.hpp"#include "sc2k/ui/resources.hpp"#include <cstdio>#include <string>
#include "test_harness.hpp"#include "test_paths.hpp"
int main() { using namespace sc2k; const std::string adir = render::assets_dir(); if (!exists(adir + "/fonts/system.bmp") || !exists(adir + "/fonts/system.txt")) { std::printf("ui: SKIP (no font under %s/fonts — run extract_assets.py)\n", adir.c_str()); return 0; }
ui::Font font(adir + "/fonts/system.bmp", adir + "/fonts/system.txt"); CHECK(font.height() > 4 && font.height() < 64); CHECK(font.avg_width() > 2); CHECK(font.text_width("OK") > 0); CHECK(font.text_width("WWW") > font.text_width("iii")); // proportional font
// Render a small dialog into a framebuffer and confirm the chrome + text drew. render::Framebuffer fb(400, 300); fb.clear(render::Rgba{0, 100, 0, 0xFF}); // green desktop, distinct from UI greys ui::Dialog d; d.w_dlu = 120; d.h_dlu = 70; d.title = "Test"; d.controls = {{1, "BUTTON", 0, 70, 50, 40, 14, "OK"}, {2, "STATIC", 0, 6, 6, 100, 10, "Hello"}}; d.draw(fb, font, 80, 70);
long face = 0, black = 0; for (int y = 0; y < fb.height(); ++y) for (int x = 0; x < fb.width(); ++x) { const render::Rgba p = fb.at(x, y); if (p.r == ui::theme::kFace.r && p.g == ui::theme::kFace.g && p.b == ui::theme::kFace.b) ++face; if (p.r == 0 && p.g == 0 && p.b == 0) ++black; // text/edge ink } std::printf("ui: font h=%d avg=%d; dialog face px=%ld ink px=%ld\n", font.height(), font.avg_width(), face, black); CHECK(face > 2000); // the dialog face panel painted CHECK(black > 50); // title/button/label text rendered
// Hit-testing: a click on the OK button finds it; a click in an empty corner finds nothing. { const int bx = font.avg_width(), by = font.height(); const int cx = 80 + 70 * bx / 4, cy = 70 + 50 * by / 8; const ui::Control* hb = d.hit_test(font, 80, 70, cx + 3, cy + 3); CHECK(hb != nullptr && hb->id == 1); CHECK(d.hit_test(font, 80, 70, 2, 2) == nullptr); }
// The extracted dialog set loads, and a known dialog (125, Schools budget) has its real controls. if (exists(adir + "/ui/dialogs.txt")) { ui::DialogSet set; set.load(adir + "/ui/dialogs.txt"); CHECK(set.size() > 20); const ui::Dialog* d125 = set.get(125); CHECK(d125 != nullptr); if (d125) { CHECK(d125->controls.size() > 10); CHECK(d125->w_dlu == 228); } std::printf("ui: loaded %zu dialogs from template data\n", set.size()); }
if (exists(adir + "/ui/menus.txt")) { ui::MenuBar menu; menu.load(adir + "/ui/menus.txt", 3); menu.layout(font); CHECK(menu.height(font) > 0); const ui::MenuBar::Click r = menu.click(font, 1000, 4, 4); // open the first top CHECK(r.consumed);
// Rewards menu: the earned reward buildings are appended to the Newspaper menu (top index 5, // logical submenu 5, faithful to the original). set_reward_items keeps the 2 base items, then a // divider + the reward items (or nothing when the reward set is empty). if (menu.tops().size() > 5) { const std::size_t base = menu.tops()[5].items.size(); // Subscription / Extra!!! / separator menu.set_reward_items(5, 2, {{"Mayor's House", "", 32845, false, 0}, {"City Hall", "", 32846, false, 0}}); const auto& np = menu.tops()[5].items; CHECK(np.size() == 5); // 2 base + divider + 2 rewards CHECK(np[3].cmd == 32845 && np[4].cmd == 32846); // the two gifts, in order CHECK(np[2].separator); // divider between base and gifts menu.set_reward_items(5, 2, {}); // no rewards → just the 2 base items CHECK(menu.tops()[5].items.size() == 2); (void)base; } }
if (exists(adir + "/ui/bmp_2.bmp")) { ui::ToolPalette palette; palette.build(render::load_ui_bitmap(2)); CHECK(palette.ready()); CHECK(palette.width() > 100 && palette.height() > 300); // tall, narrow floating panel // The first tool button (Bulldoze, index 0) sits at the grid's top-left cell. int x, y, w, h; CHECK(palette.button_rect(0, x, y, w, h)); CHECK(palette.button_at(x + w / 2, y + h / 2) == 0); // Verified button->action map, re-checked 2026-06-23 against the binary — the cases // that were previously WRONG (16/17/18 were Sign-list/Undo/Redo; 28-32 opened a dialog) are now // locked down: Query, the two rotate buttons, the Centering tool, and the five layer toggles. CHECK(ui::tb_action(0).kind == ui::TbKind::Tool && ui::tb_action(0).arg == 0); CHECK(ui::tb_action(15).kind == ui::TbKind::Sign); // Sign tool CHECK(ui::tb_action(16).kind == ui::TbKind::Query); // Query tool (mode 23) CHECK(ui::tb_action(17).kind == ui::TbKind::RotateCCW); CHECK(ui::tb_action(18).kind == ui::TbKind::RotateCW); CHECK(ui::tb_action(19).kind == ui::TbKind::ZoomOut && ui::tb_action(20).kind == ui::TbKind::ZoomIn); CHECK(ui::tb_action(21).kind == ui::TbKind::Center); // Centering TOOL (mode 11) CHECK(ui::tb_action(27).kind == ui::TbKind::Window && ui::tb_action(27).arg == 102); // Budget CHECK(ui::tb_action(23).kind == ui::TbKind::Window && ui::tb_action(23).arg == 128); // Population for (int i = 28; i <= 32; ++i) // 5 show/hide toggles CHECK(ui::tb_action(i).kind == ui::TbKind::Toggle && ui::tb_action(i).arg == i - 28); CHECK(ui::tb_action(33).kind == ui::TbKind::Help);
// A toggle button must VISIBLY toggle: drawing it sunken (bit set in the mask) differs from drawing // it raised, within that button's own rect — so the user can see a layer's on/off state. (The bevel // flips and the icon nudges in; this asserts the rect's pixels actually change.) render::Framebuffer raised(palette.width() + 16, palette.height() + 16); render::Framebuffer sunk(palette.width() + 16, palette.height() + 16); palette.draw(raised, 8, 8, /*sunkenMask*/ 0ull); palette.draw(sunk, 8, 8, /*sunkenMask*/ (1ull << 28)); // Buildings toggle pressed-in int br, bx2, by2, bw2, bh2; CHECK(palette.button_rect(28, bx2, by2, bw2, bh2)); (void)br; long btnDiff = 0; for (int yy = by2; yy < by2 + bh2; ++yy) for (int xx = bx2; xx < bx2 + bw2; ++xx) { const render::Rgba p = raised.at(8 + xx, 8 + yy), q = sunk.at(8 + xx, 8 + yy); if (p.r != q.r || p.g != q.g || p.b != q.b) ++btnDiff; } CHECK(btnDiff > 8); // the pressed-in state is visibly different std::printf("ui: tool palette %dx%d, actions verified, toggle-draw diff=%ld px\n", palette.width(), palette.height(), btnDiff); }
if (failures == 0) { std::printf("ui: all checks passed\n"); return 0; } std::printf("ui: %d failure(s)\n", failures); return 1;}