CBitmapFont.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. class ResourceID;
  13. class CBitmapFont : public IFont
  14. {
  15. using CodePoint = uint32_t;
  16. struct BitmapChar
  17. {
  18. int32_t leftOffset;
  19. uint32_t width;
  20. uint32_t height;
  21. int32_t rightOffset;
  22. std::vector<uint8_t> pixels; // pixels of this character, part of BitmapFont::data
  23. };
  24. std::unordered_map<CodePoint, BitmapChar> chars;
  25. uint32_t maxHeight;
  26. void loadModFont(const std::string & modName, const ResourceID & resource);
  27. void renderCharacter(SDL_Surface * surface, const BitmapChar & character, const SDL_Color & color, int &posX, int &posY) const;
  28. void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const override;
  29. public:
  30. explicit CBitmapFont(const std::string & filename);
  31. size_t getLineHeight() const override;
  32. size_t getGlyphWidth(const char * data) const override;
  33. friend class CBitmapHanFont;
  34. };