UiFont.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreString.h>
  17. /**
  18. * Character data for UI elements.
  19. */
  20. struct UiCharData{
  21. /**
  22. * The character code.
  23. */
  24. int char_code;
  25. /**
  26. * The character X position in the font image.
  27. */
  28. int x;
  29. /**
  30. * The character Y position in the font image.
  31. */
  32. int y;
  33. /**
  34. * The character width.
  35. */
  36. int width;
  37. /**
  38. * The character height.
  39. */
  40. int height;
  41. /**
  42. * @todo Understand and document.
  43. */
  44. int pre;
  45. /**
  46. * @todo Understand and document.
  47. */
  48. int post;
  49. };
  50. /**
  51. * The UI widgets font.
  52. */
  53. class UiFont{
  54. public:
  55. /**
  56. * Constructor.
  57. *
  58. * @param name[in] The font name.
  59. * @param language[in] The font language.
  60. */
  61. UiFont(const Ogre::String& name, const Ogre::String& language);
  62. /**
  63. * Destructor.
  64. */
  65. virtual ~UiFont();
  66. /**
  67. * Retrieves the font name.
  68. *
  69. * @return The font name.
  70. */
  71. const Ogre::String& GetName() const;
  72. /**
  73. * Retrieves the font language.
  74. *
  75. * @return The font language.
  76. */
  77. const Ogre::String& GetLanguage() const;
  78. /**
  79. * Sets an image for the font.
  80. *
  81. * The image is a character map.
  82. *
  83. * @param image[in] Path to the font image, relative to data/fonts.
  84. * @param width[in] Image width.
  85. * @param height[in] Image height.
  86. */
  87. void SetImage(
  88. const Ogre::String& image, const int width, const int height
  89. );
  90. /**
  91. * Retrieves the font image file name.
  92. *
  93. * @return The font image file name.
  94. */
  95. const Ogre::String& GetImageName() const;
  96. /**
  97. * Retrieves the font image width.
  98. *
  99. * @return The font image height.
  100. */
  101. int GetImageWidth() const;
  102. /**
  103. * Retrieves the font image height.
  104. *
  105. * @return The font image height.
  106. */
  107. int GetImageHeight() const;
  108. /**
  109. * Sets the character height for the font.
  110. *
  111. * @param height[in] Character height.
  112. */
  113. void SetHeight(const int height);
  114. /**
  115. * Retrieves the character height of the font.
  116. *
  117. * @return The character height.
  118. */
  119. int GetHeight() const;
  120. /**
  121. * Adds data for a character.
  122. *
  123. * @param data[in] The character data to add.
  124. */
  125. void AddCharData(const UiCharData& data);
  126. /**
  127. * Retrieves character data from a char code.
  128. *
  129. * @param char_code[in] The code of the character to retrieve data
  130. * about.
  131. * @return Character data associated to the char code. A default {@see
  132. * UiCharData} structure wil be returnd if there is no data for the
  133. * char code.
  134. */
  135. UiCharData GetCharData(const int char_code) const;
  136. private:
  137. /**
  138. * The font name.
  139. */
  140. Ogre::String name_;
  141. /**
  142. * The font language.
  143. */
  144. Ogre::String language_;
  145. /**
  146. * The font image file name.
  147. */
  148. Ogre::String image_name_;
  149. /**
  150. * The font image file width.
  151. */
  152. int image_width_;
  153. /**
  154. * The font image file height.
  155. */
  156. int image_height_;
  157. /**
  158. * The height of the font characters.
  159. */
  160. int height_;
  161. /**
  162. * List of character data for the font.
  163. */
  164. std::vector<UiCharData> char_data_;
  165. };