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 CBitmapFont : public IFont
  13. {
  14. static const size_t totalChars = 256;
  15. struct BitmapChar
  16. {
  17. si32 leftOffset;
  18. ui32 width;
  19. si32 rightOffset;
  20. ui8 *pixels; // pixels of this character, part of BitmapFont::data
  21. };
  22. const std::pair<std::unique_ptr<ui8[]>, ui64> data;
  23. const std::array<BitmapChar, totalChars> chars;
  24. const ui8 height;
  25. std::array<BitmapChar, totalChars> loadChars() const;
  26. void renderCharacter(SDL_Surface * surface, const BitmapChar & character, const SDL_Color & color, int &posX, int &posY) const;
  27. void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const override;
  28. public:
  29. CBitmapFont(const std::string & filename);
  30. size_t getLineHeight() const override;
  31. size_t getGlyphWidth(const char * data) const override;
  32. friend class CBitmapHanFont;
  33. };