CBitmapFont.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * CBitmapFont.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../render/IFont.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class ResourceID;
  14. VCMI_LIB_NAMESPACE_END
  15. class CBitmapFont : public IFont
  16. {
  17. using CodePoint = uint32_t;
  18. struct BitmapChar
  19. {
  20. int32_t leftOffset;
  21. uint32_t width;
  22. uint32_t height;
  23. int32_t rightOffset;
  24. std::vector<uint8_t> pixels; // pixels of this character, part of BitmapFont::data
  25. };
  26. std::unordered_map<CodePoint, BitmapChar> chars;
  27. uint32_t maxHeight;
  28. void loadModFont(const std::string & modName, const ResourceID & resource);
  29. void renderCharacter(SDL_Surface * surface, const BitmapChar & character, const SDL_Color & color, int &posX, int &posY) const;
  30. void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const override;
  31. public:
  32. explicit CBitmapFont(const std::string & filename);
  33. size_t getLineHeight() const override;
  34. size_t getGlyphWidth(const char * data) const override;
  35. friend class CBitmapHanFont;
  36. };