// Unit test for the host->game mouse coordinate mapping (letterbox inverse + // client-offset handling for WGC-of-decorated-window vs hooked/borderless). #include #include "inject/mkb_map.hpp" using namespace coop; namespace { int g_failures = 0; void check(bool cond, const char* what) { if (!cond) { std::printf("FAIL: %s\n", what); ++g_failures; } } } // namespace int main() { // --- Hooked / borderless: frame == client, no offset. dst exactly matches src // (no letterbox), so the mapping is the identity. { MkbMapInput in; in.dst_w = in.src_w = in.client_w = 1920; in.dst_h = in.src_h = in.client_h = 1080; int gx = 0, gy = 0; check(map_host_to_game_client(in, gx, gy) && gx == 0 && gy == 0, "identity: top-left"); in.host_x = 960; in.host_y = 540; check(map_host_to_game_client(in, gx, gy) && gx == 960 && gy == 540, "identity: center"); } // --- Letterbox: a 1600x900 (16:9) frame fit into a 1000x1000 host window. Scale // = 1000/1600 = 0.625, vertical bars of (1000 - 562.5)/2 = 218.75 px. { MkbMapInput in; in.dst_w = 1000; in.dst_h = 1000; in.src_w = in.client_w = 1600; in.src_h = in.client_h = 900; int gx = 0, gy = 0; // A click in the top letterbox bar is rejected. in.host_x = 500; in.host_y = 10; check(!map_host_to_game_client(in, gx, gy), "letterbox: top bar rejected"); // Center of the host window maps to center of the game frame. in.host_x = 500; in.host_y = 500; check(map_host_to_game_client(in, gx, gy) && gx == 800 && gy == 450, "letterbox: center maps to game center"); // Just inside the image at the top edge (y = 218.75 -> 219) maps near client top. in.host_x = 500; in.host_y = 219; check(map_host_to_game_client(in, gx, gy) && gy >= 0 && gy <= 2, "letterbox: top edge maps near 0"); } // --- WGC of a decorated window: frame is the whole window (1608x939) with the // client area (1600x900) offset by an 8 px left border / 31 px title bar. No // host letterbox here (dst matches the window frame). { MkbMapInput in; in.dst_w = in.src_w = 1608; in.dst_h = in.src_h = 939; in.client_off_x = 8; in.client_off_y = 31; in.client_w = 1600; in.client_h = 900; int gx = 0, gy = 0; // A click on the title bar (above the client area) is rejected. in.host_x = 800; in.host_y = 10; check(!map_host_to_game_client(in, gx, gy), "decorated: title bar rejected"); // Client top-left corner. in.host_x = 8; in.host_y = 31; check(map_host_to_game_client(in, gx, gy) && gx == 0 && gy == 0, "decorated: client origin"); // A point inside the client area subtracts the decoration offset. in.host_x = 108; in.host_y = 131; check(map_host_to_game_client(in, gx, gy) && gx == 100 && gy == 100, "decorated: client interior"); } if (g_failures == 0) { std::printf("PASS: mkb_map_test\n"); return 0; } std::printf("FAIL: %d checks failed\n", g_failures); return 1; }