Bring back the game window's pointer image as pointer_image, off by default

#1092's pointer image (runtime/cursor_art.c: a gold arrowhead with a dark edge, a turquoise gem and a soft shadow,
drawn at the window's DPI) was left out of dev because it changed the pointer for every player with no way to keep
the system arrow. It now comes with pointer_image (input section, live, default 0): 0 leaves the window class's arrow
as dev has it, 1 shows the image while the cursor is not captured. Win32 reads the setting at WM_SETCURSOR (the
next mouse move after a change); SDL sets the image or its default cursor when the settings change (input_sdl_idle).
The setting has its row under the mouse rows of the Controls tab, its text in the four menu languages, and
totk.ini.example and docs/controls.md describe it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
itaskaev2andClaude Opus 5.5 committed 2026-11-11 14:48:24 +01:00
1 parent d8a1d14104
commit fc985e690e
10 files changed
+182 -4

No files matched your search

+3 -2
View File
@@ -50,7 +50,7 @@ static const char *const known[] = {
"MEM_RESERVE_MIB", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_AIM_SCALE", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_ASPECT", "MOVIE_HOST", "MOVIE_PACE",
"MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK",
"MV_SURVEY",
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT",
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POINTER_IMAGE",
"PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_BENCH", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES",
"PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", "REFLEX",
"RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS",
@@ -89,7 +89,7 @@ static const struct { const char *key, *section; } sections[] = {
{"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"},
{"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"},
{"STICK_SENS", "input"},
{"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"},
{"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"DIALOGUE_CLICK", "input"}, {"POINTER_IMAGE", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"},
{"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"},
{"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"},
{"BIND_PLUS", "input"}, {"BIND_MINUS", "input"}, {"BIND_LEFT", "input"}, {"BIND_UP", "input"},
@@ -158,6 +158,7 @@ static const CfgMeta metas[] = {
{"MOUSE_SENS", "1", "0..10", LIVE}, {"MOUSE_AIM_SCALE", "1", "0.1..3", LIVE}, {"MENU_CURSOR", "1", "0|1", LIVE},
{"MAP_CLICK", "0", "0|1", LIVE}, // input.c: the left mouse button is A on the Purah Pad's map
{"DIALOGUE_CLICK", "0", "0|1", LIVE}, // menu_cursor.c: in a dialogue box left click is B, right click A
{"POINTER_IMAGE", "0", "0|1", LIVE}, // input_win.c / input_sdl.c: the game window's own pointer (cursor_art.c)
{"WALK_KEY", "none", NULL, LIVE}, {"WALK_SCALE", "0.51", "0.2..0.9", LIVE},
{"MENU_LANG", "", "en|ru|pt-BR|zh-Hans", LIVE},
{"AMIIBO_DIR", "", NULL, LIVE},
+89
View File
@@ -0,0 +1,89 @@
// 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 <math.h>
#include <stdint.h>
#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);
}
+31
View File
@@ -12,6 +12,7 @@
#include <SDL3/SDL.h>
#include "cfg.h"
#include "host.h"
#include "input.h"
#include "input_map.h"
@@ -200,8 +201,37 @@ void ikb_menu_closed(void) {
if (o & CUR_ESC) plat_cas32(&cur_rel, 0, o);
}
// pointer_image = 1: the pointer over the window while the cursor is not captured is cursor_art.c's, sized by the
// window's display scale; 0 (the default) keeps SDL's arrow. Window thread, at the window's creation and whenever the
// settings change (input_sdl_idle), so the menu switches it live. SDL's arrow stays when SDL refuses the image.
static void art_cursor(SDL_Window *w) {
static SDL_Cursor *art;
static int shown = -1, failed;
static unsigned seen = ~0u;
unsigned v = cfg_version();
if (v == seen && shown >= 0) return;
seen = v;
int want = cfg_bool("TOTK_POINTER_IMAGE");
if (want == shown) return;
if (want && !art && !failed) {
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 && s->pitch == size * 4) {
cursor_art(s->pixels, size, &hot);
art = SDL_CreateColorCursor(s, hot, hot);
}
if (s) SDL_DestroySurface(s);
if (!art) failed = 1, rt_log("input: the pointer's image failed (%s); the arrow stays", SDL_GetError());
}
SDL_SetCursor(want && art ? art : SDL_GetDefaultCursor());
shown = want;
}
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
@@ -210,6 +240,7 @@ void input_sdl_window(SDL_Window *w) {
void input_sdl_idle(void) {
if (cur_pending) cursor_apply();
if (win) art_cursor(win);
pointer_apply();
}
+39 -1
View File
@@ -122,6 +122,39 @@ 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) {
@@ -159,7 +192,12 @@ 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 (cur_captured && LOWORD(l) == HTCLIENT) { SetCursor(NULL); *res = TRUE; return 1; }
if (LOWORD(l) == HTCLIENT) {
// pointer_image = 1: the pointer of cursor_art.c in place of the window class's arrow (0, the default:
// the arrow, left to DefWindowProc)
HCURSOR c = cur_captured || !cfg_bool("TOTK_POINTER_IMAGE") ? NULL : art_cursor(h);
if (cur_captured || c) { SetCursor(c); *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; }
+5
View File
@@ -19,5 +19,10 @@ 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
+1
View File
@@ -879,6 +879,7 @@ static void tab_controls(float scale) {
opt_toggle("TOTK_MENU_CURSOR", UI_MENU_MENU_CURSOR, UI_MENU_MENU_CURSOR_DESC);
opt_toggle("TOTK_MAP_CLICK", UI_MENU_MAP_CLICK, UI_MENU_MAP_CLICK_DESC);
opt_toggle("TOTK_DIALOGUE_CLICK", UI_MENU_DIALOGUE_CLICK, UI_MENU_DIALOGUE_CLICK_DESC);
opt_toggle("TOTK_POINTER_IMAGE", UI_MENU_POINTER_IMAGE, UI_MENU_POINTER_IMAGE_DESC);
row_walk_key();
opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f");
// Analog sticks: one dead zone row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With
+8
View File
@@ -297,6 +297,8 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_MAP_CLICK_DESC] = "On the Purah Pad's map, the left mouse button presses A at the map's cursor instead of the button it is bound to (Y by default). Needs Mouse in the game's menus (game 1.4.3).",
[UI_MENU_DIALOGUE_CLICK] = "Clicks in dialogue",
[UI_MENU_DIALOGUE_CLICK_DESC] = "While a dialogue box is open, left click presses B (it continues the text and skips its scroll) and right click presses A, instead of the buttons they are bound to (Y by default, which opens the dialogue log, and ZL). Dialogue choices keep the pointer: left click picks (game 1.4.3).",
[UI_MENU_POINTER_IMAGE] = "Game pointer",
[UI_MENU_POINTER_IMAGE_DESC] = "While the cursor is not captured (the game's menus, this menu, after Esc), the window shows a gold arrowhead of its own instead of the system arrow, sized for the screen's scale.",
[UI_MENU_MOUSE_SENS] = "Mouse camera sensitivity",
[UI_MENU_MOUSE_SENS_DESC] = "How fast the mouse turns the camera.",
[UI_MENU_WALK_KEY] = "Walk key",
@@ -791,6 +793,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_MAP_CLICK_DESC] = "На карте игры левая кнопка мыши нажимает A у курсора карты, а не назначенную ей кнопку (по умолчанию Y). Нужна «Мышь в меню игры» (версия игры 1.4.3).",
[UI_MENU_DIALOGUE_CLICK] = "Щелчки в диалоге",
[UI_MENU_DIALOGUE_CLICK_DESC] = "Пока открыто окно диалога, левый щелчок нажимает B (продолжает текст и пропускает его прокрутку), а правый — A, вместо назначенных им кнопок (по умолчанию Y, она открывает журнал диалога, и ZL). В вариантах ответа по-прежнему работает указатель: левый щелчок выбирает (версия игры 1.4.3).",
[UI_MENU_POINTER_IMAGE] = "Игровой курсор",
[UI_MENU_POINTER_IMAGE_DESC] = "Пока курсор не захвачен (меню игры, это меню, после Esc), окно показывает собственный золотой наконечник вместо системной стрелки, по масштабу экрана.",
[UI_MENU_MOUSE_SENS] = "Чувствительность мыши",
[UI_MENU_MOUSE_SENS_DESC] = "Как быстро мышь поворачивает камеру.",
[UI_MENU_WALK_KEY] = "Клавиша шага",
@@ -1449,6 +1453,8 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_MAP_CLICK_DESC] = "No mapa do jogo, o botão esquerdo do mouse aperta A no cursor do mapa, em vez do botão ao qual está atribuído (Y por padrão). Requer Mouse nos menus do jogo (jogo 1.4.3).",
[UI_MENU_DIALOGUE_CLICK] = "Cliques no diálogo",
[UI_MENU_DIALOGUE_CLICK_DESC] = "Enquanto uma caixa de diálogo está aberta, o clique esquerdo aperta B (continua o texto e pula a rolagem) e o direito aperta A, em vez dos botões aos quais estão atribuídos (Y por padrão, que abre o registro do diálogo, e ZL). As escolhas de diálogo continuam com o ponteiro: o clique esquerdo escolhe (jogo 1.4.3).",
[UI_MENU_POINTER_IMAGE] = "Ponteiro do jogo",
[UI_MENU_POINTER_IMAGE_DESC] = "Enquanto o cursor não está capturado (os menus do jogo, este menu, depois de Esc), a janela mostra uma ponta de flecha dourada própria em vez da seta do sistema, no tamanho da escala da tela.",
[UI_MENU_PROMPTS_MISSING] = "faltam os arquivos dos ícones: execute a instalação de novo",
[UI_MENU_PROMPTS_FAILED] = "arquivos dos ícones danificados: execute a instalação de novo",
[UI_MENU_PROMPTS_RESTART] = "os ícones mudam após reiniciar",
@@ -2092,6 +2098,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_MAP_CLICK_DESC] = "在游戏地图上,鼠标左键在地图光标处按下 A 键,而不是按下它所绑定的按键(默认为 Y)。需要开启“在游戏菜单中使用鼠标”(游戏 1.4.3)。",
[UI_MENU_DIALOGUE_CLICK] = "对话中的鼠标点击",
[UI_MENU_DIALOGUE_CLICK_DESC] = "对话框打开时,鼠标左键按下 B 键(继续对话并跳过文字滚动),右键按下 A 键,而不是它们所绑定的按键(默认为 Y,会打开对话记录;以及 ZL)。对话选项仍使用指针:左键选择(游戏 1.4.3)。",
[UI_MENU_POINTER_IMAGE] = "游戏指针",
[UI_MENU_POINTER_IMAGE_DESC] = "光标未被捕获时(游戏菜单、本菜单、按 Esc 之后),窗口显示自带的金色箭头,而不是系统箭头,大小随屏幕缩放。",
[UI_MENU_PROMPTS_MISSING] = "缺少按键提示文件:请重新运行安装程序",
[UI_MENU_PROMPTS_FAILED] = "按键提示文件已损坏:请重新运行安装程序",
[UI_MENU_PROMPTS_RESTART] = "按键提示重启后生效",
+1
View File
@@ -120,6 +120,7 @@ typedef enum {
UI_MENU_MENU_CURSOR, UI_MENU_MENU_CURSOR_DESC,
UI_MENU_MAP_CLICK, UI_MENU_MAP_CLICK_DESC,
UI_MENU_DIALOGUE_CLICK, UI_MENU_DIALOGUE_CLICK_DESC,
UI_MENU_POINTER_IMAGE, UI_MENU_POINTER_IMAGE_DESC,
UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC,
UI_MENU_WALK_KEY, UI_MENU_WALK_KEY_DESC, UI_MENU_WALK_KEY_TAKEN, UI_MENU_WALK_SCALE, UI_MENU_WALK_SCALE_DESC,