diff --git a/docs/controls.md b/docs/controls.md index 200e01f8..58e8f7cf 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -201,7 +201,7 @@ The stick direction bits (`StickLLeft` to `StickRDown`) are derived from the sti ## Mouse in the game's menus -On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. A focus gap of up to 300 ms (a tab switch, a popup opening: the game drops the focus box for a frame or two) keeps the pointer where it is instead of capturing and centring it again. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The middle and side mouse buttons keep their bindings (bound to L and R they turn the tabs), and T presses Y (sort). The scroll wheel moves the focus up and down, one step a notch (a full-tilt push of the left stick for 70 ms with 50 ms of neutral after it, up for a turn away from you), so a long list of items scrolls without moving the pointer; `menu_cursor = 0` turns this off with the pointer. The keys and the pad keep working, and the focus moves with the pointer only when the pointer moves: after the wheel, a key or the pad moved the focus off the pointer's item, the pointer takes it back once it has moved 6 layout units (the menus' 1280 x 720: about 9 window pixels at 1080p, 18 at 4K) from where it was then (`DEAD_ZONE` in `runtime/menu_cursor.c`), so a hand resting on the mouse does not undo a scroll; a click acts at once. While the cursor is not captured the game window shows a pointer of its own, a gold arrowhead drawn at the window's DPI (`runtime/cursor_art.c`), in place of the system arrow. This happens only while the keyboard and mouse are the device used last: after a gamepad button press or a stick pushed past half way the menus are as on the console, with no pointer, until the mouse moves or a key is pressed (`input_kbm_last` in `runtime/input.c`). The ability wheel, the d-pad strips, Autobuild and the Purah Pad's camera stay gameplay: the mouse keeps the camera there. The map has no focus box; it is found in `eui::ScreenMgr`'s list of open screens (every 100 ms: the Purah Pad's frame `AppMenuOverlay_00` with `AppMap_00` and the menu background `AppMenuBG_00`), and there the mouse moves the map's cursor as the left stick does, with the cursor still captured, and the scroll wheel zooms: each notch is a full-tilt push of the right stick (the map's zoom) for 100 ms with 50 ms of neutral after it, up (in) for a turn away from you; a fast scroll's notches wait their turn (at most four), a turn the other way drops them. The Scope opens the same map screen without the menu background and keeps the mouse camera. The Purah Pad's camera (the ability wheel's camera) opens the frame and its pointer `CameraPointer_00` without `AppMap_00` (the Scope has it); there the scroll wheel zooms as the camera's guide shows: each notch is a press of the d-pad's up (in, for a turn away from you) or down for 100 ms with 50 ms of release after it (`menu_cursor_camera`). The Scope itself has no zoom; the wheel does nothing there. When the menu closes the cursor is captured again. +On game 1.4.3, while one of the game's menus has its focus box (the frame the d-pad moves: the title, the save list, the inventory and its System tab, Options, shops, dialogue choices), the cursor is released from the mouse camera and shown in the middle of the window. A focus gap of up to 300 ms (a tab switch, a popup opening: the game drops the focus box for a frame or two) keeps the pointer where it is instead of capturing and centring it again. The item under the pointer takes the focus as if the d-pad had moved there, with the game's highlight, sound and description; a left click is A on it, a right click is B. The middle and side mouse buttons keep their bindings (bound to L and R they turn the tabs), and T presses Y (sort). The scroll wheel moves the focus up and down, one step a notch (a full-tilt push of the left stick for 70 ms with 50 ms of neutral after it, up for a turn away from you), so a long list of items scrolls without moving the pointer; `menu_cursor = 0` turns this off with the pointer. The keys and the pad keep working, and the focus moves with the pointer only when the pointer moves: after the wheel, a key or the pad moved the focus off the pointer's item, the pointer takes it back once it has moved 6 layout units (the menus' 1280 x 720: about 9 window pixels at 1080p, 18 at 4K) from where it was then (`DEAD_ZONE` in `runtime/menu_cursor.c`), so a hand resting on the mouse does not undo a scroll; a click acts at once. This happens only while the keyboard and mouse are the device used last: after a gamepad button press or a stick pushed past half way the menus are as on the console, with no pointer, until the mouse moves or a key is pressed (`input_kbm_last` in `runtime/input.c`). The ability wheel, the d-pad strips, Autobuild and the Purah Pad's camera stay gameplay: the mouse keeps the camera there. The map has no focus box; it is found in `eui::ScreenMgr`'s list of open screens (every 100 ms: the Purah Pad's frame `AppMenuOverlay_00` with `AppMap_00` and the menu background `AppMenuBG_00`), and there the mouse moves the map's cursor as the left stick does, with the cursor still captured, and the scroll wheel zooms: each notch is a full-tilt push of the right stick (the map's zoom) for 100 ms with 50 ms of neutral after it, up (in) for a turn away from you; a fast scroll's notches wait their turn (at most four), a turn the other way drops them. The Scope opens the same map screen without the menu background and keeps the mouse camera. The Purah Pad's camera (the ability wheel's camera) opens the frame and its pointer `CameraPointer_00` without `AppMap_00` (the Scope has it); there the scroll wheel zooms as the camera's guide shows: each notch is a press of the d-pad's up (in, for a turn away from you) or down for 100 ms with 50 ms of release after it (`menu_cursor_camera`). The Scope itself has no zoom; the wheel does nothing there. When the menu closes the cursor is captured again. `runtime/menu_cursor.c` reads eui's screens at each pad read and moves the focus with the writes `eui::BoxCursorMgr::moveBoxCursor` makes, so no game code is called. `menu_cursor = 0` (`TOTK_MENU_CURSOR=0`, live; the *Mouse in the game's menus* row of the Controls tab) turns it off; `TOTK_MENU_CURSOR_LOG=1` logs every screen it reads (by default the first six), with the layout size, the node count and the hit panes it uses. diff --git a/runtime/cursor_art.c b/runtime/cursor_art.c deleted file mode 100644 index 3a9278f6..00000000 --- a/runtime/cursor_art.c +++ /dev/null @@ -1,89 +0,0 @@ -// The mouse pointer's image in the game window while the cursor is not captured (the game's menus, the settings menu): -// a gold arrowhead with a notched back, a dark outline, a turquoise gem and a soft shadow, drawn here at the size the -// window's DPI asks for instead of the Windows arrow. input_win.c and input_sdl.c make the system cursor from it. -// Nothing comes from the game's files. -#include -#include - -#include "input_wsys.h" - -typedef struct { float x, y; } V; - -// In units of a 32-pixel cursor: the tip at the top left (the hotspot), the wings to the right and below, the notch -// between them -static const V SHAPE[] = {{1.5f, 1.5f}, {25.0f, 10.5f}, {14.5f, 14.5f}, {10.5f, 25.0f}}; -static const V GEM[] = {{10.4f, 7.6f}, {13.0f, 10.2f}, {10.4f, 12.8f}, {7.8f, 10.2f}}; -#define OUTLINE 1.7f // the dark edge's width -#define SHADOW 1.6f // the shadow's offset to the bottom right - -static float seg_dist(V p, V a, V b) { - float dx = b.x - a.x, dy = b.y - a.y, t = ((p.x - a.x) * dx + (p.y - a.y) * dy) / (dx * dx + dy * dy); - t = t < 0 ? 0 : t > 1 ? 1 : t; - float ex = a.x + t * dx - p.x, ey = a.y + t * dy - p.y; - return sqrtf(ex * ex + ey * ey); -} - -// Distance to the polygon's edge, negative inside (even-odd: the shapes are simple) -static float poly_sdf(V p, const V *v, int n) { - float d = 1e9f; - int in = 0; - for (int i = 0, j = n - 1; i < n; j = i++) { - float e = seg_dist(p, v[j], v[i]); - if (e < d) d = e; - if ((v[i].y > p.y) != (v[j].y > p.y) && p.x < (v[j].x - v[i].x) * (p.y - v[i].y) / (v[j].y - v[i].y) + v[i].x) - in = !in; - } - return in ? -d : d; -} - -// One sample's colour (straight r, g, b in 0..1) and coverage -static float sample(V p, float *r, float *g, float *b) { - float d = poly_sdf(p, SHAPE, 4); - if (d < 0) { - if (-d < OUTLINE) { *r = 0.17f, *g = 0.11f, *b = 0.04f; return 1; } - if (poly_sdf(p, GEM, 4) < 0) { // the gem, lighter towards its top left - float t = (p.x + p.y - 20.4f) / 5.2f + 0.5f; - t = t < 0 ? 0 : t > 1 ? 1 : t; - *r = 0.62f - 0.42f * t, *g = 0.98f - 0.22f * t, *b = 0.92f - 0.12f * t; - return 1; - } - // gold, pale at the tip and deeper at the wings; a thin light line inside the outline - float t = (p.x + p.y) / 34.0f; - t = t < 0 ? 0 : t > 1 ? 1 : t; - float rim = -d < OUTLINE + 1.0f ? 0.12f : 0; - *r = fminf(1, 1.00f - 0.12f * t + rim), *g = fminf(1, 0.93f - 0.32f * t + rim), - *b = fminf(1, 0.70f - 0.52f * t + rim); - return 1; - } - V s = {p.x - SHADOW, p.y - SHADOW}; - float ds = poly_sdf(s, SHAPE, 4); - if (ds < 0.8f) { // the shadow, soft at its edge - *r = *g = *b = 0; - float a = ds < -0.8f ? 1 : (0.8f - ds) / 1.6f; - return 0.38f * a; - } - return 0; -} - -void cursor_art(uint32_t *argb, int size, int *hot) { - float k = 32.0f / (float)size; - enum { SS = 4 }; // 4 x 4 samples a pixel - for (int y = 0; y < size; y++) - for (int x = 0; x < size; x++) { - float r = 0, g = 0, b = 0, a = 0; - for (int sy = 0; sy < SS; sy++) - for (int sx = 0; sx < SS; sx++) { - V p = {(x + (sx + 0.5f) / SS) * k, (y + (sy + 0.5f) / SS) * k}; - float sr, sg, sb, c = sample(p, &sr, &sg, &sb); - r += sr * c, g += sg * c, b += sb * c, a += c; - } - uint32_t px = 0; - if (a > 0) { // straight alpha, as Windows and SDL take it - r /= a, g /= a, b /= a, a /= SS * SS; - px = (uint32_t)lrintf(a * 255) << 24 | (uint32_t)lrintf(r * 255) << 16 | - (uint32_t)lrintf(g * 255) << 8 | (uint32_t)lrintf(b * 255); - } - argb[y * size + x] = px; - } - *hot = (int)(1.5f / k); -} diff --git a/runtime/input_sdl.c b/runtime/input_sdl.c index 05aadacc..1f7383bd 100644 --- a/runtime/input_sdl.c +++ b/runtime/input_sdl.c @@ -200,26 +200,8 @@ void ikb_menu_closed(void) { if (o & CUR_ESC) plat_cas32(&cur_rel, 0, o); } -// The pointer over the window while the cursor is not captured (cursor_art.c), sized by the window's display scale. -// The default arrow stays when SDL refuses it. -static void art_cursor(SDL_Window *w) { - float scale = SDL_GetWindowDisplayScale(w); - int size = (int)lrintf(32 * (scale > 0 ? scale : 1)), hot; - size = size < 32 ? 32 : size > 128 ? 128 : size; - SDL_Surface *s = SDL_CreateSurface(size, size, SDL_PIXELFORMAT_ARGB8888); - if (!s) return; - if (s->pitch == size * 4) { - cursor_art(s->pixels, size, &hot); - SDL_Cursor *c = SDL_CreateColorCursor(s, hot, hot); - if (c) SDL_SetCursor(c); - else rt_log("input: the pointer's image failed (%s); the arrow stays", SDL_GetError()); - } - SDL_DestroySurface(s); -} - void input_sdl_window(SDL_Window *w) { win = w; - art_cursor(w); wake_event = SDL_RegisterEvents(1); plat_xchg32(&focused, (SDL_GetWindowFlags(w) & SDL_WINDOW_INPUT_FOCUS) != 0); __atomic_store_n(&ptr_have, 0, __ATOMIC_RELEASE); // the pointer's place is unknown until it enters or moves diff --git a/runtime/input_win.c b/runtime/input_win.c index 11c660b4..56ed7437 100644 --- a/runtime/input_win.c +++ b/runtime/input_win.c @@ -122,39 +122,6 @@ static void cursor_update(HWND h) { ReleaseSRWLockExclusive(&cur_lock); } -// The pointer shown over the client area while the cursor is not captured (cursor_art.c), 32 pixels at 96 DPI and -// larger with the window's DPI; made again when the DPI changes. Window thread. NULL when Windows refuses it: the -// window class's arrow stays. -static HCURSOR art_cursor(HWND h) { - static HCURSOR cur; - static UINT made_dpi; - UINT dpi = GetDpiForWindow(h); - if (!dpi) dpi = USER_DEFAULT_SCREEN_DPI; - if (cur && dpi == made_dpi) return cur; - int size = MulDiv(32, (int)dpi, USER_DEFAULT_SCREEN_DPI), hot; - size = size < 32 ? 32 : size > 128 ? 128 : size; - BITMAPV5HEADER bh = {.bV5Size = sizeof bh, .bV5Width = size, .bV5Height = -size, .bV5Planes = 1, .bV5BitCount = 32, - .bV5Compression = BI_BITFIELDS, .bV5RedMask = 0xff0000, .bV5GreenMask = 0xff00, - .bV5BlueMask = 0xff, .bV5AlphaMask = 0xff000000u}; - void *bits = NULL; - HDC dc = GetDC(NULL); - HBITMAP color = CreateDIBSection(dc, (BITMAPINFO *)&bh, DIB_RGB_COLORS, &bits, NULL, 0); - ReleaseDC(NULL, dc); - HBITMAP mask = CreateBitmap(size, size, 1, 1, NULL); - HCURSOR made = NULL; - if (color && mask && bits) { - cursor_art(bits, size, &hot); - ICONINFO ii = {.fIcon = FALSE, .xHotspot = (DWORD)hot, .yHotspot = (DWORD)hot, .hbmMask = mask, - .hbmColor = color}; - made = (HCURSOR)CreateIconIndirect(&ii); - } - if (color) DeleteObject(color); - if (mask) DeleteObject(mask); - if (!made) return cur; // the old size, or NULL - cur = made, made_dpi = dpi; // the old one may still be on screen: kept (a DPI change is rare) - return cur; -} - int input_cursor_released(void) { return (cur_rel & CUR_REL) != 0; } void input_cursor_suspend(int on) { @@ -192,10 +159,7 @@ int input_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) { break; // DefWindowProc must see WM_INPUT for cleanup } case WM_SETCURSOR: - if (LOWORD(l) == HTCLIENT) { - HCURSOR c = cur_captured ? NULL : art_cursor(h); - if (cur_captured || c) { SetCursor(c); *res = TRUE; return 1; } - } + if (cur_captured && LOWORD(l) == HTCLIENT) { SetCursor(NULL); *res = TRUE; return 1; } break; case WM_SYSCOMMAND: // Alt pressed alone would enter the window menu loop, which stalls the game: Alt is a game key if ((w & 0xFFF0) == SC_KEYMENU && l == 0) { *res = 0; return 1; } diff --git a/runtime/input_wsys.h b/runtime/input_wsys.h index 24fcdc04..0460595a 100644 --- a/runtime/input_wsys.h +++ b/runtime/input_wsys.h @@ -19,10 +19,5 @@ int32_t ikb_wheel_take(void); // whole wheel notches turned sinc void ikb_cursor_update(void); // what input_cursor_allowed says may have changed void ikb_menu_closed(void); // the menu closed: a capture that Esc gave up comes back -// ---- shared by the back ends -// cursor_art.c: the pointer's image at size x size pixels (0xAARRGGBB, straight alpha, rows from the top) and its -// hotspot (*hot, the same in x and y). Pure. -void cursor_art(uint32_t *argb, int size, int *hot); - // ---- what input.c provides the back end int input_cursor_allowed(void); // no text entry or menu open, the mouse camera on, input not disabled