From 7d7074e9f6a103d8b1e991ea4e63b98271d14a03 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 7 Dec 2017 23:00:36 +1100 Subject: [PATCH] [host/test] center text in the window --- host/sync-test/main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/host/sync-test/main.c b/host/sync-test/main.c index f31582f3..56e93724 100644 --- a/host/sync-test/main.c +++ b/host/sync-test/main.c @@ -17,14 +17,15 @@ int main(int argc, char * argv[]) bool running = true; unsigned int frameCount = 0; Uint32 fpsFrame = 0; - Uint32 fpsStart = SDL_GetTicks(); + Uint32 fpsStart = SDL_GetTicks(); float fps = 0.0f; TTF_Font * fpsFont = NULL; SDL_Rect fpsTextRect = {5, 5}; SDL_Texture * fpsText = NULL; - int boxX = 100; - int boxY = 100; + int width = 1000; + int boxX = 100; + int boxY = 100; fpsFont = TTF_OpenFont("C:\\Windows\\Fonts\\cour.ttf", 24); @@ -53,8 +54,9 @@ int main(int argc, char * argv[]) switch (event.window.event) { case SDL_WINDOWEVENT_RESIZED: - boxX = event.window.data1 / 10; - boxY = (event.window.data2 - 40) / 10; + width = event.window.data1; + boxX = event.window.data1 / 10; + boxY = (event.window.data2 - 40) / 10; break; } } @@ -90,6 +92,7 @@ int main(int argc, char * argv[]) if (fpsText) SDL_DestroyTexture(fpsText); fpsText = SDL_CreateTextureFromSurface(renderer, fpsSurf); + fpsTextRect.x = width / 2 - fpsSurf->w / 2; fpsTextRect.w = fpsSurf->w; fpsTextRect.h = fpsSurf->h; SDL_FreeSurface(fpsSurf);