IGUIFont.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IReferenceCounted.h"
  6. #include "SColor.h"
  7. #include "rect.h"
  8. #include "irrString.h"
  9. namespace irr
  10. {
  11. namespace gui
  12. {
  13. //! An enum for the different types of GUI font.
  14. enum EGUI_FONT_TYPE
  15. {
  16. //! Bitmap fonts loaded from an XML file or a texture.
  17. EGFT_BITMAP = 0,
  18. //! Scalable vector fonts loaded from an XML file.
  19. /** These fonts reside in system memory and use no video memory
  20. until they are displayed. These are slower than bitmap fonts
  21. but can be easily scaled and rotated. */
  22. EGFT_VECTOR,
  23. //! A font which uses a the native API provided by the operating system.
  24. /** Currently not used. */
  25. EGFT_OS,
  26. //! An external font type provided by the user.
  27. EGFT_CUSTOM
  28. };
  29. //! Font interface.
  30. class IGUIFont : public virtual IReferenceCounted
  31. {
  32. public:
  33. //! Draws some text and clips it to the specified rectangle if wanted.
  34. /** \param text: Text to draw
  35. \param position: Rectangle specifying position where to draw the text.
  36. \param color: Color of the text
  37. \param hcenter: Specifies if the text should be centered horizontally into the rectangle.
  38. \param vcenter: Specifies if the text should be centered vertically into the rectangle.
  39. \param clip: Optional pointer to a rectangle against which the text will be clipped.
  40. If the pointer is null, no clipping will be done. */
  41. virtual void draw(const core::stringw &text, const core::rect<s32> &position,
  42. video::SColor color, bool hcenter = false, bool vcenter = false,
  43. const core::rect<s32> *clip = 0) = 0;
  44. //! Calculates the width and height of a given string of text.
  45. /** \return Returns width and height of the area covered by the text if
  46. it would be drawn. */
  47. virtual core::dimension2d<u32> getDimension(const wchar_t *text) const = 0;
  48. //! Calculates the index of the character in the text which is on a specific position.
  49. /** \param text: Text string.
  50. \param pixel_x: X pixel position of which the index of the character will be returned.
  51. \return Returns zero based index of the character in the text, and -1 if no no character
  52. is on this position. (=the text is too short). */
  53. virtual s32 getCharacterFromPos(const wchar_t *text, s32 pixel_x) const = 0;
  54. //! Returns the type of this font
  55. virtual EGUI_FONT_TYPE getType() const { return EGFT_CUSTOM; }
  56. //! Sets global kerning width for the font.
  57. virtual void setKerningWidth(s32 kerning) = 0;
  58. //! Sets global kerning height for the font.
  59. virtual void setKerningHeight(s32 kerning) = 0;
  60. //! Gets kerning values (distance between letters) for the font. If no parameters are provided,
  61. /** the global kerning distance is returned.
  62. \param thisLetter: If this parameter is provided, the left side kerning
  63. for this letter is added to the global kerning value. For example, a
  64. space might only be one pixel wide, but it may be displayed as several
  65. pixels.
  66. \param previousLetter: If provided, kerning is calculated for both
  67. letters and added to the global kerning value. For example, in a font
  68. which supports kerning pairs a string such as 'Wo' may have the 'o'
  69. tucked neatly under the 'W'.
  70. */
  71. virtual s32 getKerningWidth(const wchar_t *thisLetter = 0, const wchar_t *previousLetter = 0) const = 0;
  72. //! Returns the distance between letters
  73. virtual s32 getKerningHeight() const = 0;
  74. //! Define which characters should not be drawn by the font.
  75. /** For example " " would not draw any space which is usually blank in
  76. most fonts.
  77. \param s String of symbols which are not send down to the videodriver
  78. */
  79. virtual void setInvisibleCharacters(const wchar_t *s) = 0;
  80. };
  81. } // end namespace gui
  82. } // end namespace irr