]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIFont.h
4cf93b8971590f9b479d49f5e5dff0742056e427
[irrlicht.git] / source / Irrlicht / CGUIFont.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_GUI_FONT_H_INCLUDED__\r
6 #define __C_GUI_FONT_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 #ifdef _IRR_COMPILE_WITH_GUI_\r
10 \r
11 #include "IGUIFontBitmap.h"\r
12 #include "irrString.h"\r
13 #include "IReadFile.h"\r
14 #include "irrArray.h"\r
15 #include <map>\r
16 \r
17 namespace irr\r
18 {\r
19 \r
20 namespace video\r
21 {\r
22         class IVideoDriver;\r
23         class IImage;\r
24 }\r
25 \r
26 namespace gui\r
27 {\r
28 \r
29         class IGUIEnvironment;\r
30 \r
31 class CGUIFont : public IGUIFontBitmap\r
32 {\r
33 public:\r
34 \r
35         //! constructor\r
36         CGUIFont(IGUIEnvironment* env, const io::path& filename);\r
37 \r
38         //! destructor\r
39         virtual ~CGUIFont();\r
40 \r
41         //! loads a font from a texture file\r
42         bool load(const io::path& filename);\r
43 \r
44         //! loads a font from a texture file\r
45         bool load(io::IReadFile* file);\r
46 \r
47         //! draws an text and clips it to the specified rectangle if wanted\r
48         virtual void draw(const core::stringw& text, const core::rect<s32>& position,\r
49                         video::SColor color, bool hcenter=false,\r
50                         bool vcenter=false, const core::rect<s32>* clip=0) override;\r
51 \r
52         //! returns the dimension of a text\r
53         core::dimension2d<u32> getDimension(const wchar_t* text) const override;\r
54 \r
55         //! Calculates the index of the character in the text which is on a specific position.\r
56         s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const override;\r
57 \r
58         //! Returns the type of this font\r
59         EGUI_FONT_TYPE getType() const override { return EGFT_BITMAP; }\r
60 \r
61         //! set an Pixel Offset on Drawing ( scale position on width )\r
62         void setKerningWidth (s32 kerning) override;\r
63         void setKerningHeight (s32 kerning) override;\r
64 \r
65         //! set an Pixel Offset on Drawing ( scale position on width )\r
66         s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const override;\r
67         s32 getKerningHeight() const override;\r
68 \r
69         //! gets the sprite bank\r
70         IGUISpriteBank* getSpriteBank() const override;\r
71 \r
72         //! returns the sprite number from a given character\r
73         u32 getSpriteNoFromChar(const wchar_t *c) const override;\r
74 \r
75         void setInvisibleCharacters( const wchar_t *s ) override;\r
76 \r
77 private:\r
78 \r
79         struct SFontArea\r
80         {\r
81                 SFontArea() : underhang(0), overhang(0), width(0), spriteno(0) {}\r
82                 s32                             underhang;\r
83                 s32                             overhang;\r
84                 s32                             width;\r
85                 u32                             spriteno;\r
86         };\r
87 \r
88         //! load & prepare font from ITexture\r
89         bool loadTexture(video::IImage * image, const io::path& name);\r
90 \r
91         void readPositions(video::IImage* texture, s32& lowerRightPositions);\r
92 \r
93         s32 getAreaFromCharacter (const wchar_t c) const;\r
94         void setMaxHeight();\r
95 \r
96         void pushTextureCreationFlags(bool(&flags)[3]);\r
97         void popTextureCreationFlags(const bool(&flags)[3]);\r
98 \r
99         core::array<SFontArea>          Areas;\r
100         std::map<wchar_t, s32>          CharacterMap;\r
101         video::IVideoDriver*            Driver;\r
102         IGUISpriteBank*                 SpriteBank;\r
103         IGUIEnvironment*                Environment;\r
104         u32                             WrongCharacter;\r
105         s32                             MaxHeight;\r
106         s32                             GlobalKerningWidth, GlobalKerningHeight;\r
107 \r
108         core::stringw Invisible;\r
109 };\r
110 \r
111 } // end namespace gui\r
112 } // end namespace irr\r
113 \r
114 #endif // _IRR_COMPILE_WITH_GUI_\r
115 \r
116 #endif // __C_GUI_FONT_H_INCLUDED__\r
117 \r