// ```c #include #include #include #include #include const char* font_family = "helvetica"; int font_size_to_fit(const char *s, int w, int h); void handle_events(bool *running); int main(int argc, char **argv) { if (argc < 2) { printf("usage: %s string [colour]\n", argv[0]); return 1; } const char *s = argv[1]; const char *c = argc > 2 ? argv[2] : NULL; if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("SDL_Init Error: %s\n", SDL_GetError()); return 1; } TTF_Init(); SDL_DisplayMode DM; SDL_GetCurrentDisplayMode(0, &DM); int w = DM.w; int h = DM.h; SDL_Window *win = SDL_CreateWindow("Banner Message", 0, 0, w, h, SDL_WINDOW_FULLSCREEN_DESKTOP); if (win == NULL) { printf("SDL_CreateWindow Error: %s\n", SDL_GetError()); return 1; } SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (ren == NULL) { printf("SDL_CreateRenderer Error: %s\n", SDL_GetError()); return 1; } int font_size = font_size_to_fit(s, w, h); TTF_Font *font = TTF_OpenFont("path/to/your/font", font_size); SDL_Surface *surface = TTF_RenderText_Solid(font, s, c == NULL ? (SDL_Color) {255, 255, 255} : (SDL_Color) {c[0], c[1], c[2]}); SDL_Texture *texture = SDL_CreateTextureFromSurface(ren, surface); SDL_Rect dest_rect; dest_rect.x = (w - surface->w) / 2; dest_rect.y = (h - surface->h) / 2; dest_rect.w = surface->w; dest_rect.h = surface->h; bool running = true; while (running) { SDL_RenderCopy(ren, texture, NULL, &dest_rect); SDL_RenderPresent(ren); handle_events(&running); } SDL_DestroyTexture(texture); SDL_FreeSurface(surface); TTF_CloseFont(font); SDL_DestroyRenderer(ren); SDL_DestroyWindow(win); TTF_Quit(); SDL_Quit(); return 0; } int font_size_to_fit(const char *s, int w, int h) { int font_size = 200; // Initialize a dummy font to get text size TTF_Font *font = TTF_OpenFont("path/to/your/font", font_size); int tw, th; TTF_SizeText(font, s, &tw, &th); int fsw = (int) (font_size * w / tw * 0.90); int fsh = (int) (font_size * h / th * 0.90); int fs = fsw < fsh ? fsw : fsh; TTF_CloseFont(font); return fs; } void handle_events(bool *running) { SDL_Event e; while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { *running = false; } else if (e.type == SDL_KEYDOWN) { if (e.key.keysym.sym == SDLK_q) { *running = false; } } } } // ``` // // Replace "path/to/your/font" with the path to a font file (for example a .ttf file) corresponding to the font family you want to use. In this example, I used "helvetica" as specified in the original script, but you can use any font file that's available on your system. // // You will also need to install SDL2 and SDL2_ttf libraries to compile and run this code.