IFont.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * IFont.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. VCMI_LIB_NAMESPACE_BEGIN
  12. class Point;
  13. VCMI_LIB_NAMESPACE_END
  14. struct SDL_Surface;
  15. struct SDL_Color;
  16. class IFont
  17. {
  18. protected:
  19. /// Internal function to render font, see renderTextLeft
  20. virtual void renderText(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const = 0;
  21. public:
  22. virtual ~IFont()
  23. {}
  24. /// Returns height of font
  25. virtual size_t getLineHeight() const = 0;
  26. /// Returns width, in pixels of a character glyph. Pointer must contain at least characterSize valid bytes
  27. virtual size_t getGlyphWidth(const char * data) const = 0;
  28. /// Return width of the string
  29. virtual size_t getStringWidth(const std::string & data) const;
  30. /**
  31. * @param surface - destination to print text on
  32. * @param data - string to print
  33. * @param color - font color
  34. * @param pos - position of rendered font
  35. */
  36. /// pos = topleft corner of the text
  37. void renderTextLeft(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const;
  38. /// pos = center of the text
  39. void renderTextRight(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const;
  40. /// pos = bottomright corner of the text
  41. void renderTextCenter(SDL_Surface * surface, const std::string & data, const SDL_Color & color, const Point & pos) const;
  42. /// pos = topleft corner of the text
  43. void renderTextLinesLeft(SDL_Surface * surface, const std::vector<std::string> & data, const SDL_Color & color, const Point & pos) const;
  44. /// pos = center of the text
  45. void renderTextLinesRight(SDL_Surface * surface, const std::vector<std::string> & data, const SDL_Color & color, const Point & pos) const;
  46. /// pos = bottomright corner of the text
  47. void renderTextLinesCenter(SDL_Surface * surface, const std::vector<std::string> & data, const SDL_Color & color, const Point & pos) const;
  48. };