Font.h 874 B

123456789101112131415161718192021222324252627282930313233
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include <string>
  10. #include <unordered_map>
  11. #include <SDL/SDL_ttf.h>
  12. #include "Math.h"
  13. class Font
  14. {
  15. public:
  16. Font(class Game* game);
  17. ~Font();
  18. // Load/unload from a file
  19. bool Load(const std::string& fileName);
  20. void Unload();
  21. // Given string and this font, draw to a texture
  22. class Texture* RenderText(const std::string& textKey,
  23. const Vector3& color = Color::White,
  24. int pointSize = 30);
  25. private:
  26. // Map of point sizes to font data
  27. std::unordered_map<int, TTF_Font*> mFontData;
  28. class Game* mGame;
  29. };