CGUIFont.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 __C_GUI_FONT_H_INCLUDED__
  5. #define __C_GUI_FONT_H_INCLUDED__
  6. #include "IrrCompileConfig.h"
  7. #ifdef _IRR_COMPILE_WITH_GUI_
  8. #include "IGUIFontBitmap.h"
  9. #include "irrString.h"
  10. #include "irrMap.h"
  11. #include "IXMLReader.h"
  12. #include "IReadFile.h"
  13. #include "irrArray.h"
  14. namespace irr
  15. {
  16. namespace video
  17. {
  18. class IVideoDriver;
  19. class IImage;
  20. }
  21. namespace gui
  22. {
  23. class IGUIEnvironment;
  24. class CGUIFont : public IGUIFontBitmap
  25. {
  26. public:
  27. //! constructor
  28. CGUIFont(IGUIEnvironment* env, const io::path& filename);
  29. //! destructor
  30. virtual ~CGUIFont();
  31. //! loads a font from a texture file
  32. bool load(const io::path& filename);
  33. //! loads a font from a texture file
  34. bool load(io::IReadFile* file);
  35. //! loads a font from an XML file
  36. bool load(io::IXMLReader* xml);
  37. //! draws an text and clips it to the specified rectangle if wanted
  38. virtual void draw(const core::stringw& text, const core::rect<s32>& position,
  39. video::SColor color, bool hcenter=false,
  40. bool vcenter=false, const core::rect<s32>* clip=0);
  41. //! returns the dimension of a text
  42. virtual core::dimension2d<u32> getDimension(const wchar_t* text) const;
  43. //! Calculates the index of the character in the text which is on a specific position.
  44. virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const;
  45. //! Returns the type of this font
  46. virtual EGUI_FONT_TYPE getType() const { return EGFT_BITMAP; }
  47. //! set an Pixel Offset on Drawing ( scale position on width )
  48. virtual void setKerningWidth (s32 kerning);
  49. virtual void setKerningHeight (s32 kerning);
  50. //! set an Pixel Offset on Drawing ( scale position on width )
  51. virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const;
  52. virtual s32 getKerningHeight() const;
  53. //! gets the sprite bank
  54. virtual IGUISpriteBank* getSpriteBank() const;
  55. //! returns the sprite number from a given character
  56. virtual u32 getSpriteNoFromChar(const wchar_t *c) const;
  57. virtual void setInvisibleCharacters( const wchar_t *s );
  58. private:
  59. struct SFontArea
  60. {
  61. SFontArea() : underhang(0), overhang(0), width(0), spriteno(0) {}
  62. s32 underhang;
  63. s32 overhang;
  64. s32 width;
  65. u32 spriteno;
  66. };
  67. //! load & prepare font from ITexture
  68. bool loadTexture(video::IImage * image, const io::path& name);
  69. void readPositions(video::IImage* texture, s32& lowerRightPositions);
  70. s32 getAreaFromCharacter (const wchar_t c) const;
  71. void setMaxHeight();
  72. core::array<SFontArea> Areas;
  73. core::map<wchar_t, s32> CharacterMap;
  74. video::IVideoDriver* Driver;
  75. IGUISpriteBank* SpriteBank;
  76. IGUIEnvironment* Environment;
  77. u32 WrongCharacter;
  78. s32 MaxHeight;
  79. s32 GlobalKerningWidth, GlobalKerningHeight;
  80. core::stringw Invisible;
  81. };
  82. } // end namespace gui
  83. } // end namespace irr
  84. #endif // _IRR_COMPILE_WITH_GUI_
  85. #endif // __C_GUI_FONT_H_INCLUDED__