IFont.h 2.1 KB

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