]> git.sesse.net Git - casparcg/blob - SFML-1.6/include/SFML/Graphics/String.hpp
(no commit message)
[casparcg] / SFML-1.6 / include / SFML / Graphics / String.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_STRING_HPP\r
26 #define SFML_STRING_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/System/Resource.hpp>\r
32 #include <SFML/System/Unicode.hpp>\r
33 #include <SFML/Graphics/Drawable.hpp>\r
34 #include <SFML/Graphics/Font.hpp>\r
35 #include <SFML/Graphics/Rect.hpp>\r
36 #include <string>\r
37 \r
38 \r
39 namespace sf\r
40 {\r
41 ////////////////////////////////////////////////////////////\r
42 /// String defines a graphical 2D text, that can be drawn on screen\r
43 ////////////////////////////////////////////////////////////\r
44 class SFML_API String : public Drawable\r
45 {\r
46 public :\r
47 \r
48     ////////////////////////////////////////////////////////////\r
49     /// Enumerate the string drawing styles\r
50     ////////////////////////////////////////////////////////////\r
51     enum Style\r
52     {\r
53         Regular    = 0,      ///< Regular characters, no style\r
54         Bold       = 1 << 0, ///< Characters are bold\r
55         Italic     = 1 << 1, ///< Characters are in italic\r
56         Underlined = 1 << 2  ///< Characters are underlined\r
57     };\r
58 \r
59     ////////////////////////////////////////////////////////////\r
60     /// Default constructor\r
61     ///\r
62     ////////////////////////////////////////////////////////////\r
63     String();\r
64 \r
65     ////////////////////////////////////////////////////////////\r
66     /// Construct the string from any kind of text\r
67     ///\r
68     /// \param Text : Text assigned to the string\r
69     /// \param Font : Font used to draw the string (SFML built-in font by default)\r
70     /// \param Size : Characters size (30 by default)\r
71     ///\r
72     ////////////////////////////////////////////////////////////\r
73     explicit String(const Unicode::Text& Text, const Font& CharFont = Font::GetDefaultFont(), float Size = 30.f);\r
74 \r
75     ////////////////////////////////////////////////////////////\r
76     /// Set the text (from any kind of string)\r
77     ///\r
78     /// \param Text : New text\r
79     ///\r
80     ////////////////////////////////////////////////////////////\r
81     void SetText(const Unicode::Text& Text);\r
82 \r
83     ////////////////////////////////////////////////////////////\r
84     /// Set the font of the string\r
85     ///\r
86     /// \param Font : Font to use\r
87     ///\r
88     ////////////////////////////////////////////////////////////\r
89     void SetFont(const Font& CharFont);\r
90 \r
91     ////////////////////////////////////////////////////////////\r
92     /// Set the size of the string\r
93     /// The default size is 30\r
94     ///\r
95     /// \param Size : New size, in pixels\r
96     ///\r
97     ////////////////////////////////////////////////////////////\r
98     void SetSize(float Size);\r
99 \r
100     ////////////////////////////////////////////////////////////\r
101     /// Set the style of the text\r
102     /// The default style is Regular\r
103     ///\r
104     /// \param TextStyle : New text style, (combination of Style enum values)\r
105     ///\r
106     ////////////////////////////////////////////////////////////\r
107     void SetStyle(unsigned long TextStyle);\r
108 \r
109     ////////////////////////////////////////////////////////////\r
110     /// Get the text (the returned text can be converted implicitely to any kind of string)\r
111     ///\r
112     /// \return String's text\r
113     ///\r
114     ////////////////////////////////////////////////////////////\r
115     const Unicode::Text& GetText() const;\r
116 \r
117     ////////////////////////////////////////////////////////////\r
118     /// Get the font used by the string\r
119     ///\r
120     /// \return Font used\r
121     ///\r
122     ////////////////////////////////////////////////////////////\r
123     const Font& GetFont() const;\r
124 \r
125     ////////////////////////////////////////////////////////////\r
126     /// Get the size of the characters\r
127     ///\r
128     /// \return Size of the characters\r
129     ///\r
130     ////////////////////////////////////////////////////////////\r
131     float GetSize() const;\r
132 \r
133     ////////////////////////////////////////////////////////////\r
134     /// Get the style of the text\r
135     ///\r
136     /// \return Current string style (combination of Style enum values)\r
137     ///\r
138     ////////////////////////////////////////////////////////////\r
139     unsigned long GetStyle() const;\r
140 \r
141     ////////////////////////////////////////////////////////////\r
142     /// Return the visual position of the Index-th character of the string,\r
143     /// in coordinates relative to the string\r
144     /// (note : translation, center, rotation and scale are not applied)\r
145     ///\r
146     /// \param Index : Index of the character\r
147     ///\r
148     /// \return Position of the Index-th character (end of string if Index is out of range)\r
149     ///\r
150     ////////////////////////////////////////////////////////////\r
151     sf::Vector2f GetCharacterPos(std::size_t Index) const;\r
152 \r
153     ////////////////////////////////////////////////////////////\r
154     /// Get the string rectangle on screen\r
155     ///\r
156     /// \return Rectangle contaning the string in screen coordinates\r
157     ///\r
158     ////////////////////////////////////////////////////////////\r
159     FloatRect GetRect() const;\r
160 \r
161 protected :\r
162 \r
163     ////////////////////////////////////////////////////////////\r
164     /// /see Drawable::Render\r
165     ///\r
166     ////////////////////////////////////////////////////////////\r
167     virtual void Render(RenderTarget& Target) const;\r
168 \r
169 private :\r
170 \r
171     ////////////////////////////////////////////////////////////\r
172     /// Recompute the bounding rectangle of the text\r
173     ///\r
174     ////////////////////////////////////////////////////////////\r
175     void RecomputeRect();\r
176 \r
177     ////////////////////////////////////////////////////////////\r
178     // Member data\r
179     ////////////////////////////////////////////////////////////\r
180     Unicode::Text     myText;           ///< Text to display\r
181     ResourcePtr<Font> myFont;           ///< Font used to display the string\r
182     float             mySize;           ///< Size of the characters\r
183     unsigned long     myStyle;          ///< Text style (see Style enum)\r
184     FloatRect         myBaseRect;       ///< Bounding rectangle of the text in object coordinates\r
185     bool              myNeedRectUpdate; ///< Does the bounding rect need an update ?\r
186 };\r
187 \r
188 } // namespace sf\r
189 \r
190 \r
191 #endif // SFML_STRING_HPP\r