1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\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
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
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
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_STRING_HPP
\r
26 #define SFML_STRING_HPP
\r
28 ////////////////////////////////////////////////////////////
\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
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
48 ////////////////////////////////////////////////////////////
\r
49 /// Enumerate the string drawing styles
\r
50 ////////////////////////////////////////////////////////////
\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
59 ////////////////////////////////////////////////////////////
\r
60 /// Default constructor
\r
62 ////////////////////////////////////////////////////////////
\r
65 ////////////////////////////////////////////////////////////
\r
66 /// Construct the string from any kind of text
\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
72 ////////////////////////////////////////////////////////////
\r
73 explicit String(const Unicode::Text& Text, const Font& CharFont = Font::GetDefaultFont(), float Size = 30.f);
\r
75 ////////////////////////////////////////////////////////////
\r
76 /// Set the text (from any kind of string)
\r
78 /// \param Text : New text
\r
80 ////////////////////////////////////////////////////////////
\r
81 void SetText(const Unicode::Text& Text);
\r
83 ////////////////////////////////////////////////////////////
\r
84 /// Set the font of the string
\r
86 /// \param Font : Font to use
\r
88 ////////////////////////////////////////////////////////////
\r
89 void SetFont(const Font& CharFont);
\r
91 ////////////////////////////////////////////////////////////
\r
92 /// Set the size of the string
\r
93 /// The default size is 30
\r
95 /// \param Size : New size, in pixels
\r
97 ////////////////////////////////////////////////////////////
\r
98 void SetSize(float Size);
\r
100 ////////////////////////////////////////////////////////////
\r
101 /// Set the style of the text
\r
102 /// The default style is Regular
\r
104 /// \param TextStyle : New text style, (combination of Style enum values)
\r
106 ////////////////////////////////////////////////////////////
\r
107 void SetStyle(unsigned long TextStyle);
\r
109 ////////////////////////////////////////////////////////////
\r
110 /// Get the text (the returned text can be converted implicitely to any kind of string)
\r
112 /// \return String's text
\r
114 ////////////////////////////////////////////////////////////
\r
115 const Unicode::Text& GetText() const;
\r
117 ////////////////////////////////////////////////////////////
\r
118 /// Get the font used by the string
\r
120 /// \return Font used
\r
122 ////////////////////////////////////////////////////////////
\r
123 const Font& GetFont() const;
\r
125 ////////////////////////////////////////////////////////////
\r
126 /// Get the size of the characters
\r
128 /// \return Size of the characters
\r
130 ////////////////////////////////////////////////////////////
\r
131 float GetSize() const;
\r
133 ////////////////////////////////////////////////////////////
\r
134 /// Get the style of the text
\r
136 /// \return Current string style (combination of Style enum values)
\r
138 ////////////////////////////////////////////////////////////
\r
139 unsigned long GetStyle() const;
\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
146 /// \param Index : Index of the character
\r
148 /// \return Position of the Index-th character (end of string if Index is out of range)
\r
150 ////////////////////////////////////////////////////////////
\r
151 sf::Vector2f GetCharacterPos(std::size_t Index) const;
\r
153 ////////////////////////////////////////////////////////////
\r
154 /// Get the string rectangle on screen
\r
156 /// \return Rectangle contaning the string in screen coordinates
\r
158 ////////////////////////////////////////////////////////////
\r
159 FloatRect GetRect() const;
\r
163 ////////////////////////////////////////////////////////////
\r
164 /// /see Drawable::Render
\r
166 ////////////////////////////////////////////////////////////
\r
167 virtual void Render(RenderTarget& Target) const;
\r
171 ////////////////////////////////////////////////////////////
\r
172 /// Recompute the bounding rectangle of the text
\r
174 ////////////////////////////////////////////////////////////
\r
175 void RecomputeRect();
\r
177 ////////////////////////////////////////////////////////////
\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
191 #endif // SFML_STRING_HPP
\r