testime: allow enabling/disabling text input on individual windows

This commit is contained in:
Sam Lantinga
2025-09-23 09:59:11 -07:00
parent c13e74be6b
commit fe8c080713

View File

@@ -791,7 +791,11 @@ static void RedrawWindow(WindowState *ctx)
break; break;
} }
if (SDL_TextInputActive(ctx->window)) {
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a); SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
} else {
SDL_SetRenderDrawColor(renderer, 0x80, 0x80, 0x80, 0xFF);
}
SDL_RenderFillRect(renderer, &ctx->textRect); SDL_RenderFillRect(renderer, &ctx->textRect);
/* Initialize the drawn text rectangle for the cursor */ /* Initialize the drawn text rectangle for the cursor */
@@ -876,6 +880,7 @@ static void RedrawWindow(WindowState *ctx)
} }
/* Draw the cursor */ /* Draw the cursor */
if (SDL_TextInputActive(ctx->window)) {
Uint64 now = SDL_GetTicks(); Uint64 now = SDL_GetTicks();
if ((now - ctx->last_cursor_change) >= CURSOR_BLINK_INTERVAL_MS) { if ((now - ctx->last_cursor_change) >= CURSOR_BLINK_INTERVAL_MS) {
ctx->cursor_visible = !ctx->cursor_visible; ctx->cursor_visible = !ctx->cursor_visible;
@@ -891,6 +896,7 @@ static void RedrawWindow(WindowState *ctx)
SDL_SetRenderDrawColor(renderer, lineColor.r, lineColor.g, lineColor.b, lineColor.a); SDL_SetRenderDrawColor(renderer, lineColor.r, lineColor.g, lineColor.b, lineColor.a);
SDL_RenderFillRect(renderer, &cursorRect); SDL_RenderFillRect(renderer, &cursorRect);
} }
}
/* Draw the candidates */ /* Draw the candidates */
DrawCandidates(ctx, &cursorRect); DrawCandidates(ctx, &cursorRect);
@@ -912,6 +918,9 @@ static void Redraw(void)
RedrawWindow(&windowstate[i]); RedrawWindow(&windowstate[i]);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderDebugTextFormat(renderer, 4, 4, "Window %d", 1 + i);
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
} }
@@ -1076,6 +1085,19 @@ int main(int argc, char *argv[])
} }
break; break;
default: default:
if ((event.key.mod & SDL_KMOD_CTRL) && (event.key.key >= SDLK_KP_1 && event.key.key <= SDLK_KP_9)) {
int index = (event.key.key - SDLK_KP_1);
if (index < state->num_windows) {
SDL_Window *window = state->windows[index];
if (SDL_TextInputActive(window)) {
SDL_Log("Disabling text input for window %d\n", 1 + index);
SDL_StopTextInput(window);
} else {
SDL_Log("Enabling text input for window %d\n", 1 + index);
SDL_StartTextInput(window);
}
}
}
break; break;
} }