diff options
| author | Arslaan Pathan <[email protected]> | 2025-06-12 20:22:40 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2025-06-12 20:22:40 +1200 |
| commit | 8c7dfa2167ca737e33947b98ed6c077351f6a2b6 (patch) | |
| tree | d14247b1256c3183536d53b96f8f1b8a5948ad35 /src/main.cpp | |
| parent | 444e8e362dd5aad6f620f7b9bbd79d40a6393314 (diff) | |
| download | showdownofthesticks-8c7dfa2167ca737e33947b98ed6c077351f6a2b6.tar.xz showdownofthesticks-8c7dfa2167ca737e33947b98ed6c077351f6a2b6.zip | |
Button is work, very very nice
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index e4dadc0..ee291a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -230,6 +230,18 @@ int main() { SDL_SetWindowTitle(window, "Showdown of the Sticks"); SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + if (TTF_Init() == -1) { + std::cerr << "TTF_Init failed: " << TTF_GetError() << std::endl; + return 1; + } + + globalFont = TTF_OpenFont("assets/fonts/OpenSans-Regular.ttf", 24); + if (!globalFont) { + std::cerr << "Failed to load font: " << TTF_GetError() << std::endl; + return 1; + } + + if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) { std::cerr << "Failed to initialize SDL_image: " << IMG_GetError() << std::endl; return 1; @@ -265,7 +277,7 @@ int main() { } else { lua_pop(L, 1); } - + SDL_Delay(25); } } } @@ -302,6 +314,25 @@ int main() { for (const auto& button: buttonList) { SDL_SetRenderDrawColor(renderer, 252, 210, 77, 255); SDL_RenderFillRect(renderer, &button.rect); + if (globalFont) { + SDL_Color white = {255, 255, 255, 255}; + SDL_Surface* textSurface = TTF_RenderText_Blended(globalFont, button.text.c_str(), white); + if (textSurface) { + SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface); + SDL_Rect textRect; + textRect.w = textSurface->w; + textRect.h = textSurface->h; + textRect.x = button.rect.x + (button.rect.w - textRect.w) / 2; + textRect.y = button.rect.y + (button.rect.h - textRect.h) / 2; + + SDL_FreeSurface(textSurface); + + if (textTexture) { + SDL_RenderCopy(renderer, textTexture, nullptr, &textRect); + SDL_DestroyTexture(textTexture); + } + } + } } |
