- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
void Canvas::drawText(const char* text, SDL_Color sdlColor, int x, int y) const noexcept
{
if (!font)
throw std::runtime_error{"TTF_Font* is null"};
SDL_Surface* const sdlSurface =
::TTF_RenderText_Solid(const_cast<TTF_Font*>(font->getTtfFont()), text, sdlColor);
if (!sdlSurface)
throw std::runtime_error{"SDL_Surface* is null"};
SDL_Texture* const sdlTexture =
::SDL_CreateTextureFromSurface(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlSurface);
if (!sdlTexture)
throw std::runtime_error{"SDL_Texture* is null"};
const SDL_Rect srcrect{0, 0, sdlSurface->w, sdlSurface->h};
const SDL_Rect dstrect{x, y, sdlSurface->w, sdlSurface->h};
::SDL_FreeSurface(sdlSurface);
::SDL_RenderCopy(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlTexture,
&srcrect, &dstrect);
::SDL_DestroyTexture(sdlTexture);
}