TextRenderer.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #pragma once
  23. #include "Types.h"
  24. #include "Str.h"
  25. #include "Color4.h"
  26. #include "Vec2.h"
  27. #include "Font.h"
  28. #include "Point2.h"
  29. namespace crown
  30. {
  31. enum TextAlignment
  32. {
  33. TA_LEFT = 0,
  34. TA_CENTER = 1,
  35. TA_RIGHT = 2
  36. };
  37. class TextRenderer
  38. {
  39. public:
  40. TextRenderer();
  41. ~TextRenderer();
  42. void BeginDraw();
  43. void EndDraw();
  44. void Draw(const Str& string, int x, int y, Font* font);
  45. //! Returns the sizes in pixels of the given string, when rendered with the current font
  46. void GetStrDimensions(const Str& string, uint start, uint end, int& width, int& height);
  47. //! Returns the character index of the character at the given position
  48. int GetStrIndexFromDimensions(const Str& string, uint start, const Point2& position, Point2& charPosition);
  49. //! Returns the max height of the text in the current font
  50. int GetMaxTextHeight();
  51. void GetStrDimensions(const Str& string, int& width, int& height)
  52. {
  53. GetStrDimensions(string, 0, -1, width, height);
  54. }
  55. void GetStrDimensions(const Str& string, uint start, int& width, int& height)
  56. {
  57. GetStrDimensions(string, start, -1, width, height);
  58. }
  59. private:
  60. };
  61. } // namespace crown