Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FontManager.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*!
  2. * \file src/FontManager.cpp
  3. * \brief SDL Font implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "utils/strings.h"
  9. #include "FontManager.h"
  10. #include "Font.h"
  11. #include "FontSDL.h"
  12. #include "FontTRLE.h"
  13. FontManager::FontManager() {
  14. add(new FontTRLE(), ".pc");
  15. #ifdef USING_SDL_FONT
  16. add(new FontSDL(), ".ttf");
  17. #endif
  18. font = -1;
  19. tempText.text = new char[256];
  20. tempText.color[0] = 0xFF;
  21. tempText.color[1] = 0xFF;
  22. tempText.color[2] = 0xFF;
  23. tempText.color[3] = 0xFF;
  24. tempText.scale = 1.2f;
  25. tempText.w = 0;
  26. tempText.h = 0;
  27. }
  28. FontManager::~FontManager() {
  29. while (!fonts.empty()) {
  30. delete fonts.back();
  31. fonts.pop_back();
  32. }
  33. }
  34. void FontManager::add(Font *f, const char *e) {
  35. fonts.push_back(f);
  36. extensions.push_back(e);
  37. }
  38. int FontManager::initialize() {
  39. for (unsigned int i = 0; i < fonts.size(); i++) {
  40. if (stringEndsWith(mFontName, extensions.at(i))) {
  41. font = i;
  42. break;
  43. }
  44. }
  45. if (font == -1)
  46. return -1;
  47. fonts.at(font)->setFont(mFontName);
  48. return fonts.at(font)->initialize();
  49. }
  50. void FontManager::writeString(FontString &s) {
  51. assert(font != -1);
  52. fonts.at(font)->writeString(s);
  53. }