IGUIFont.h 3.8 KB

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