FS#90 - Improve Unicode string classes
Added the sf::String class to replace (and enhance) sf::Unicode::Text FS#138 - Rename sf::String to sf::Text git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1286 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
9f063921c9
commit
78247bd386
@ -318,15 +318,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\Graphics\String.cpp"
|
||||
RelativePath="..\..\src\SFML\Graphics\Text.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\Graphics\String.h"
|
||||
RelativePath="..\..\include\SFML\Graphics\Text.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\Graphics\StringStruct.h"
|
||||
RelativePath="..\..\src\SFML\Graphics\TextStruct.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
@ -313,15 +313,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\Graphics\String.cpp"
|
||||
RelativePath="..\..\src\SFML\Graphics\Text.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\Graphics\String.h"
|
||||
RelativePath="..\..\include\SFML\Graphics\Text.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\Graphics\StringStruct.h"
|
||||
RelativePath="..\..\src\SFML\Graphics\TextStruct.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
@ -59,12 +59,12 @@
|
||||
<Unit filename="..\..\include\SFML\Graphics\Color.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Font.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Image.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Shader.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Rect.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\RenderWindow.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Shader.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Shape.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Sprite.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\String.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Text.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Types.h" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\View.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Color.cpp" />
|
||||
@ -72,19 +72,20 @@
|
||||
<Unit filename="..\..\src\SFML\Graphics\FontStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Image.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\ImageStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Shader.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\ShaderStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Rect.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\RenderImage.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\RenderImageStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\RenderWindow.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\RenderWindowStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Shader.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\ShaderStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Shape.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\ShapeStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Sprite.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\SpriteStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\String.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\StringStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Text.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\TextStruct.h" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\View.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\ViewStruct.h" />
|
||||
<Extensions>
|
||||
|
@ -113,24 +113,24 @@ CSFML_API void sfRenderImage_Display(sfRenderImage* renderImage);
|
||||
/// Draw something on a renderimage
|
||||
///
|
||||
/// \param renderImage : Renderimage to draw in
|
||||
/// \param sprite / string / shape : Object to draw
|
||||
/// \param sprite / text / shape : Object to draw
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfRenderImage_DrawSprite(sfRenderImage* renderImage, sfSprite* sprite);
|
||||
CSFML_API void sfRenderImage_DrawShape (sfRenderImage* renderImage, sfShape* shape);
|
||||
CSFML_API void sfRenderImage_DrawString(sfRenderImage* renderImage, sfString* string);
|
||||
CSFML_API void sfRenderImage_DrawText (sfRenderImage* renderImage, sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Draw something on a renderimage with a shader
|
||||
///
|
||||
/// \param renderImage : Renderimage to draw in
|
||||
/// \param sprite / string / shape : Object to draw
|
||||
/// \param sprite / text / shape : Object to draw
|
||||
/// \param shader : Shader to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfRenderImage_DrawSpriteWithShader(sfRenderImage* renderImage, sfSprite* sprite, sfShader* shader);
|
||||
CSFML_API void sfRenderImage_DrawShapeWithShader (sfRenderImage* renderImage, sfShape* shape, sfShader* shader);
|
||||
CSFML_API void sfRenderImage_DrawStringWithShader(sfRenderImage* renderImage, sfString* string, sfShader* shader);
|
||||
CSFML_API void sfRenderImage_DrawTextWithShader (sfRenderImage* renderImage, sfText* text, sfShader* shader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Clear the renderimage with the given color
|
||||
|
@ -293,24 +293,24 @@ CSFML_API void sfRenderWindow_SetJoystickThreshold(sfRenderWindow* renderWindow,
|
||||
/// Draw something on a renderwindow
|
||||
///
|
||||
/// \param renderWindow : Renderwindow to draw in
|
||||
/// \param sprite / string / shape : Object to draw
|
||||
/// \param sprite / text / shape : Object to draw
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, sfSprite* sprite);
|
||||
CSFML_API void sfRenderWindow_DrawShape (sfRenderWindow* renderWindow, sfShape* shape);
|
||||
CSFML_API void sfRenderWindow_DrawString(sfRenderWindow* renderWindow, sfString* string);
|
||||
CSFML_API void sfRenderWindow_DrawText (sfRenderWindow* renderWindow, sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Draw something on a renderwindow with a shader
|
||||
///
|
||||
/// \param renderWindow : Renderwindow to draw in
|
||||
/// \param sprite / string / shape : Object to draw
|
||||
/// \param sprite / text / shape : Object to draw
|
||||
/// \param shader : Shader to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfRenderWindow_DrawSpriteWithShader(sfRenderWindow* renderWindow, sfSprite* sprite, sfShader* shader);
|
||||
CSFML_API void sfRenderWindow_DrawShapeWithShader (sfRenderWindow* renderWindow, sfShape* shape, sfShader* shader);
|
||||
CSFML_API void sfRenderWindow_DrawStringWithShader(sfRenderWindow* renderWindow, sfString* string, sfShader* shader);
|
||||
CSFML_API void sfRenderWindow_DrawTextWithShader (sfRenderWindow* renderWindow, sfText* text, sfShader* shader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Clear the screen with the given color
|
||||
|
@ -22,8 +22,8 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_STRING_H
|
||||
#define SFML_STRING_H
|
||||
#ifndef SFML_TEXT_H
|
||||
#define SFML_TEXT_H
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
@ -36,389 +36,389 @@
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// sfString styles
|
||||
/// sfText styles
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef enum
|
||||
{
|
||||
sfStringRegular = 0, ///< Regular characters, no style
|
||||
sfStringBold = 1 << 0, ///< Characters are bold
|
||||
sfStringItalic = 1 << 1, ///< Characters are in italic
|
||||
sfStringUnderlined = 1 << 2 ///< Characters are underlined
|
||||
} sfStringStyle;
|
||||
sfTextRegular = 0, ///< Regular characters, no style
|
||||
sfTextBold = 1 << 0, ///< Characters are bold
|
||||
sfTextItalic = 1 << 1, ///< Characters are in italic
|
||||
sfTextUnderlined = 1 << 2 ///< Characters are underlined
|
||||
} sfTextStyle;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new string
|
||||
/// Create a new text
|
||||
///
|
||||
/// \return A new sfString object, or NULL if it failed
|
||||
/// \return A new sfText object, or NULL if it failed
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API sfString* sfString_Create();
|
||||
CSFML_API sfText* sfText_Create();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing string
|
||||
/// Destroy an existing text
|
||||
///
|
||||
/// \param string : String to delete
|
||||
/// \param text : Text to delete
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_Destroy(sfString* string);
|
||||
CSFML_API void sfText_Destroy(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the X position of a string
|
||||
/// Set the X position of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param x : New X coordinate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetX(sfString* string, float x);
|
||||
CSFML_API void sfText_SetX(sfText* text, float x);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the Y position of a string
|
||||
/// Set the Y position of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param y : New Y coordinate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetY(sfString* string, float y);
|
||||
CSFML_API void sfText_SetY(sfText* text, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the position of a string
|
||||
/// Set the position of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param x : New X coordinate
|
||||
/// \param y : New Y coordinate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetPosition(sfString* string, float x, float y);
|
||||
CSFML_API void sfText_SetPosition(sfText* text, float x, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the horizontal scale of a string
|
||||
/// Set the horizontal scale of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param scale : New scale (must be strictly positive)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetScaleX(sfString* string, float scale);
|
||||
CSFML_API void sfText_SetScaleX(sfText* text, float scale);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the vertical scale of a string
|
||||
/// Set the vertical scale of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param scale : New scale (must be strictly positive)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetScaleY(sfString* string, float scale);
|
||||
CSFML_API void sfText_SetScaleY(sfText* text, float scale);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the scale of a string
|
||||
/// Set the scale of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param scaleX : New horizontal scale (must be strictly positive)
|
||||
/// \param scaleY : New vertical scale (must be strictly positive)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetScale(sfString* string, float scaleX, float scaleY);
|
||||
CSFML_API void sfText_SetScale(sfText* text, float scaleX, float scaleY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the orientation of a string
|
||||
/// Set the orientation of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param rotation : Angle of rotation, in degrees
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetRotation(sfString* string, float rotation);
|
||||
CSFML_API void sfText_SetRotation(sfText* text, float rotation);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the local origin of a string, in coordinates
|
||||
/// Set the local origin of a text, in coordinates
|
||||
/// relative to its left-top corner
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param x : X coordinate of the origin
|
||||
/// \param y : Y coordinate of the origin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetOrigin(sfString* string, float x, float y);
|
||||
CSFML_API void sfText_SetOrigin(sfText* text, float x, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the color of a string
|
||||
/// Set the color of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param color : New color
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetColor(sfString* string, sfColor color);
|
||||
CSFML_API void sfText_SetColor(sfText* text, sfColor color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the blending mode for a string
|
||||
/// Set the blending mode for a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param mode : New blending mode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetBlendMode(sfString* string, sfBlendMode mode);
|
||||
CSFML_API void sfText_SetBlendMode(sfText* text, sfBlendMode mode);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of a string
|
||||
/// Get the X position of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current X position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetX(sfString* string);
|
||||
CSFML_API float sfText_GetX(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the top Y of a string
|
||||
/// Get the top Y of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current Y position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetY(sfString* string);
|
||||
CSFML_API float sfText_GetY(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the horizontal scale of a string
|
||||
/// Get the horizontal scale of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current X scale factor (always positive)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetScaleX(sfString* string);
|
||||
CSFML_API float sfText_GetScaleX(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the vertical scale of a string
|
||||
/// Get the vertical scale of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current Y scale factor (always positive)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetScaleY(sfString* string);
|
||||
CSFML_API float sfText_GetScaleY(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the orientation of a string
|
||||
/// Get the orientation of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current rotation, in degrees
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetRotation(sfString* string);
|
||||
CSFML_API float sfText_GetRotation(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of the origin a string
|
||||
/// Get the X position of the origin a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current X origin position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetOriginX(sfString* string);
|
||||
CSFML_API float sfText_GetOriginX(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the top Y of the origin of a string
|
||||
/// Get the top Y of the origin of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current Y origin position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetOriginY(sfString* string);
|
||||
CSFML_API float sfText_GetOriginY(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the color of a string
|
||||
/// Get the color of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current color
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API sfColor sfString_GetColor(sfString* string);
|
||||
CSFML_API sfColor sfText_GetColor(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current blending mode of a string
|
||||
/// Get the current blending mode of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current blending mode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API sfBlendMode sfString_GetBlendMode(sfString* string);
|
||||
CSFML_API sfBlendMode sfText_GetBlendMode(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Move a string
|
||||
/// Move a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param offsetX : Offset on the X axis
|
||||
/// \param offsetY : Offset on the Y axis
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_Move(sfString* string, float offsetX, float offsetY);
|
||||
CSFML_API void sfText_Move(sfText* text, float offsetX, float offsetY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Scale a string
|
||||
/// Scale a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param factorX : Horizontal scaling factor (must be strictly positive)
|
||||
/// \param factorY : Vertical scaling factor (must be strictly positive)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_Scale(sfString* string, float factorX, float factorY);
|
||||
CSFML_API void sfText_Scale(sfText* text, float factorX, float factorY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Rotate a string
|
||||
/// Rotate a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param angle : Angle of rotation, in degrees
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_Rotate(sfString* string, float angle);
|
||||
CSFML_API void sfText_Rotate(sfText* text, float angle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Transform a point from global coordinates into the string's local coordinates
|
||||
/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
///
|
||||
/// \param string : String object
|
||||
/// \param text : String object
|
||||
/// \param pointX : X coordinate of the point to transform
|
||||
/// \param pointY : Y coordinate of the point to transform
|
||||
/// \param x : Value to fill with the X coordinate of the converted point
|
||||
/// \param y : Value to fill with the y coordinate of the converted point
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_TransformToLocal(sfString* string, float pointX, float pointY, float* x, float* y);
|
||||
CSFML_API void sfText_TransformToLocal(sfText* text, float pointX, float pointY, float* x, float* y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Transform a point from the string's local coordinates into global coordinates
|
||||
/// (ie it applies the object's origin, translation, rotation and scale to the point)
|
||||
///
|
||||
/// \param string : String object
|
||||
/// \param text : String object
|
||||
/// \param pointX : X coordinate of the point to transform
|
||||
/// \param pointY : Y coordinate of the point to transform
|
||||
/// \param x : Value to fill with the X coordinate of the converted point
|
||||
/// \param y : Value to fill with the y coordinate of the converted point
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_TransformToGlobal(sfString* string, float pointX, float pointY, float* X, float* y);
|
||||
CSFML_API void sfText_TransformToGlobal(sfText* text, float pointX, float pointY, float* X, float* y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text of a string (from a multibyte string)
|
||||
/// Set the string of a text (from a multibyte string)
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : New text
|
||||
/// \param text : Text to modify
|
||||
/// \param string : New string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetText(sfString* string, const char* text);
|
||||
CSFML_API void sfText_SetString(sfText* text, const char* string);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text of a string (from a unicode string)
|
||||
/// Set the string of a text (from a unicode string)
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : New text
|
||||
/// \param text : Text to modify
|
||||
/// \param string : New string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetUnicodeText(sfString* string, const sfUint32* text);
|
||||
CSFML_API void sfText_SetUnicodeString(sfText* text, const sfUint32* string);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the font of a string
|
||||
/// Set the font of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param font : Font to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetFont(sfString* string, sfFont* font);
|
||||
CSFML_API void sfText_SetFont(sfText* text, sfFont* font);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the size of a string
|
||||
/// Set the size of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param text : String to modify
|
||||
/// \param size : New size, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetSize(sfString* string, float size);
|
||||
CSFML_API void sfText_SetSize(sfText* text, float size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the style of a string
|
||||
/// Set the style of a text
|
||||
///
|
||||
/// \param string : String to modify
|
||||
/// \param style : New style (see sfStringStyle enum)
|
||||
/// \param text : String to modify
|
||||
/// \param style : New style (see sfTextStyle enum)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_SetStyle(sfString* string, unsigned long style);
|
||||
CSFML_API void sfText_SetStyle(sfText* text, unsigned long style);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the text of a string (returns a unicode string)
|
||||
/// Get the string of a text (returns a unicode string)
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Text as UTF-32
|
||||
/// \return String as UTF-32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API const sfUint32* sfString_GetUnicodeText(sfString* string);
|
||||
CSFML_API const sfUint32* sfText_GetUnicodeString(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the text of a string (returns an ANSI string)
|
||||
/// Get the text of a text (returns an ANSI string)
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Text an a locale-dependant ANSI string
|
||||
/// \return String an a locale-dependant ANSI string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API const char* sfString_GetText(sfString* string);
|
||||
CSFML_API const char* sfText_GetString(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the font used by a string
|
||||
/// Get the font used by a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Pointer to the font
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API sfFont* sfString_GetFont(sfString* string);
|
||||
CSFML_API sfFont* sfText_GetFont(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the size of the characters of a string
|
||||
/// Get the size of the characters of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Size of the characters
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API float sfString_GetSize(sfString* string);
|
||||
CSFML_API float sfText_GetSize(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the style of a string
|
||||
/// Get the style of a text
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Current string style (see sfStringStyle enum)
|
||||
/// \return Current string style (see sfTextStyle enum)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API unsigned long sfString_GetStyle(sfString* string);
|
||||
CSFML_API unsigned long sfText_GetStyle(sfText* text);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the visual position of the Index-th character of the string,
|
||||
/// Return the visual position of the Index-th character of the text,
|
||||
/// in coordinates relative to the string
|
||||
/// (note : translation, origin, rotation and scale are not applied)
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
/// \param index : Index of the character
|
||||
/// \param x : Value to fill with the X coordinate of the position
|
||||
/// \param y : Value to fill with the y coordinate of the position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API void sfString_GetCharacterPos(sfString* string, size_t index, float* x, float* y);
|
||||
CSFML_API void sfText_GetCharacterPos(sfText* text, size_t index, float* x, float* y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the bounding rectangle of a string on screen
|
||||
/// Get the bounding rectangle of a text on screen
|
||||
///
|
||||
/// \param string : String to read
|
||||
/// \param text : String to read
|
||||
///
|
||||
/// \return Rectangle contaning the string in screen coordinates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_API sfFloatRect sfString_GetRect(sfString* string);
|
||||
CSFML_API sfFloatRect sfText_GetRect(sfText* text);
|
||||
|
||||
|
||||
#endif // SFML_STRING_H
|
||||
#endif // SFML_TEXT_H
|
@ -33,7 +33,7 @@ typedef struct sfRenderImage sfRenderImage;
|
||||
typedef struct sfRenderWindow sfRenderWindow;
|
||||
typedef struct sfShape sfShape;
|
||||
typedef struct sfSprite sfSprite;
|
||||
typedef struct sfString sfString;
|
||||
typedef struct sfText sfText;
|
||||
typedef struct sfView sfView;
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <SFML/Graphics/ShapeStruct.h>
|
||||
#include <SFML/Graphics/ShaderStruct.h>
|
||||
#include <SFML/Graphics/SpriteStruct.h>
|
||||
#include <SFML/Graphics/StringStruct.h>
|
||||
#include <SFML/Graphics/TextStruct.h>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
@ -128,10 +128,10 @@ void sfRenderImage_DrawShape(sfRenderImage* renderImage, sfShape* shape)
|
||||
CSFML_CHECK(shape);
|
||||
CSFML_CALL(renderImage, Draw(shape->This));
|
||||
}
|
||||
void sfRenderImage_DrawString(sfRenderImage* renderImage, sfString* string)
|
||||
void sfRenderImage_DrawText(sfRenderImage* renderImage, sfText* text)
|
||||
{
|
||||
CSFML_CHECK(string);
|
||||
CSFML_CALL(renderImage, Draw(string->This));
|
||||
CSFML_CHECK(text);
|
||||
CSFML_CALL(renderImage, Draw(text->This));
|
||||
}
|
||||
|
||||
|
||||
@ -150,11 +150,11 @@ void sfRenderImage_DrawShapeWithShader(sfRenderImage* renderImage, sfShape* shap
|
||||
CSFML_CHECK(shader);
|
||||
CSFML_CALL(renderImage, Draw(shape->This, shader->This));
|
||||
}
|
||||
void sfRenderImage_DrawStringWithShader(sfRenderImage* renderImage, sfString* string, sfShader* shader)
|
||||
void sfRenderImage_DrawTextWithShader(sfRenderImage* renderImage, sfText* text, sfShader* shader)
|
||||
{
|
||||
CSFML_CHECK(string);
|
||||
CSFML_CHECK(text);
|
||||
CSFML_CHECK(shader);
|
||||
CSFML_CALL(renderImage, Draw(string->This, shader->This));
|
||||
CSFML_CALL(renderImage, Draw(text->This, shader->This));
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
#include <SFML/Graphics/ShaderStruct.h>
|
||||
#include <SFML/Graphics/ImageStruct.h>
|
||||
#include <SFML/Graphics/SpriteStruct.h>
|
||||
#include <SFML/Graphics/StringStruct.h>
|
||||
#include <SFML/Graphics/TextStruct.h>
|
||||
#include <SFML/Internal.h>
|
||||
#include <SFML/ConvertEvent.h>
|
||||
|
||||
@ -366,10 +366,10 @@ void sfRenderWindow_DrawShape(sfRenderWindow* renderWindow, sfShape* shape)
|
||||
CSFML_CHECK(shape);
|
||||
CSFML_CALL(renderWindow, Draw(shape->This));
|
||||
}
|
||||
void sfRenderWindow_DrawString(sfRenderWindow* renderWindow, sfString* string)
|
||||
void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, sfText* text)
|
||||
{
|
||||
CSFML_CHECK(string);
|
||||
CSFML_CALL(renderWindow, Draw(string->This));
|
||||
CSFML_CHECK(text);
|
||||
CSFML_CALL(renderWindow, Draw(text->This));
|
||||
}
|
||||
|
||||
|
||||
@ -388,11 +388,11 @@ void sfRenderWindow_DrawShapeWithShader(sfRenderWindow* renderWindow, sfShape* s
|
||||
CSFML_CHECK(shader);
|
||||
CSFML_CALL(renderWindow, Draw(shape->This, shader->This));
|
||||
}
|
||||
void sfRenderWindow_DrawStringWithShader(sfRenderWindow* renderWindow, sfString* string, sfShader* shader)
|
||||
void sfRenderWindow_DrawTextWithShader(sfRenderWindow* renderWindow, sfText* text, sfShader* shader)
|
||||
{
|
||||
CSFML_CHECK(string);
|
||||
CSFML_CHECK(text);
|
||||
CSFML_CHECK(shader);
|
||||
CSFML_CALL(renderWindow, Draw(string->This, shader->This));
|
||||
CSFML_CALL(renderWindow, Draw(text->This, shader->This));
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,397 +25,397 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/String.h>
|
||||
#include <SFML/Graphics/StringStruct.h>
|
||||
#include <SFML/Graphics/Text.h>
|
||||
#include <SFML/Graphics/TextStruct.h>
|
||||
#include <SFML/Graphics/Font.h>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new string
|
||||
/// Create a new text
|
||||
////////////////////////////////////////////////////////////
|
||||
sfString* sfString_Create()
|
||||
sfText* sfText_Create()
|
||||
{
|
||||
sfString* string = new sfString;
|
||||
string->Font = sfFont_GetDefaultFont();
|
||||
sfText* text = new sfText;
|
||||
text->Font = sfFont_GetDefaultFont();
|
||||
|
||||
return string;
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing string
|
||||
/// Destroy an existing text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Destroy(sfString* string)
|
||||
void sfText_Destroy(sfText* text)
|
||||
{
|
||||
delete string;
|
||||
delete text;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the X position of a string
|
||||
/// Set the X position of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetX(sfString* string, float x)
|
||||
void sfText_SetX(sfText* text, float x)
|
||||
{
|
||||
CSFML_CALL(string, SetX(x))
|
||||
CSFML_CALL(text, SetX(x))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the Y position of a string
|
||||
/// Set the Y position of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetY(sfString* string, float y)
|
||||
void sfText_SetY(sfText* text, float y)
|
||||
{
|
||||
CSFML_CALL(string, SetY(y))
|
||||
CSFML_CALL(text, SetY(y))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the position of a string
|
||||
/// Set the position of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetPosition(sfString* string, float x, float y)
|
||||
void sfText_SetPosition(sfText* text, float x, float y)
|
||||
{
|
||||
CSFML_CALL(string, SetPosition(sf::Vector2f(x, y)))
|
||||
CSFML_CALL(text, SetPosition(sf::Vector2f(x, y)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the horizontal scale of a string
|
||||
/// Set the horizontal scale of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetScaleX(sfString* string, float scale)
|
||||
void sfText_SetScaleX(sfText* text, float scale)
|
||||
{
|
||||
CSFML_CALL(string, SetScaleX(scale))
|
||||
CSFML_CALL(text, SetScaleX(scale))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the vertical scale of a string
|
||||
/// Set the vertical scale of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetScaleY(sfString* string, float scale)
|
||||
void sfText_SetScaleY(sfText* text, float scale)
|
||||
{
|
||||
CSFML_CALL(string, SetScaleY(scale))
|
||||
CSFML_CALL(text, SetScaleY(scale))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the scale of a string
|
||||
/// Set the scale of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetScale(sfString* string, float scaleX, float scaleY)
|
||||
void sfText_SetScale(sfText* text, float scaleX, float scaleY)
|
||||
{
|
||||
CSFML_CALL(string, SetScale(sf::Vector2f(scaleX, scaleY)))
|
||||
CSFML_CALL(text, SetScale(sf::Vector2f(scaleX, scaleY)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the orientation of a string
|
||||
/// Set the orientation of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetRotation(sfString* string, float rotation)
|
||||
void sfText_SetRotation(sfText* text, float rotation)
|
||||
{
|
||||
CSFML_CALL(string, SetRotation(rotation))
|
||||
CSFML_CALL(text, SetRotation(rotation))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the local origin of a string, in coordinates
|
||||
/// Set the local origin of a text, in coordinates
|
||||
/// relative to its left-top corner
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetOrigin(sfString* string, float x, float y)
|
||||
void sfText_SetOrigin(sfText* text, float x, float y)
|
||||
{
|
||||
CSFML_CALL(string, SetOrigin(sf::Vector2f(x, y)))
|
||||
CSFML_CALL(text, SetOrigin(sf::Vector2f(x, y)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the color of a string
|
||||
/// Set the color of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetColor(sfString* string, sfColor color)
|
||||
void sfText_SetColor(sfText* text, sfColor color)
|
||||
{
|
||||
CSFML_CALL(string, SetColor(sf::Color(color.r, color.g, color.b, color.a)))
|
||||
CSFML_CALL(text, SetColor(sf::Color(color.r, color.g, color.b, color.a)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the blending mode for a string
|
||||
/// Set the blending mode for a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetBlendMode(sfString* string, sfBlendMode mode)
|
||||
void sfText_SetBlendMode(sfText* text, sfBlendMode mode)
|
||||
{
|
||||
CSFML_CALL(string, SetBlendMode(static_cast<sf::Blend::Mode>(mode)))
|
||||
CSFML_CALL(text, SetBlendMode(static_cast<sf::Blend::Mode>(mode)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of a string
|
||||
/// Get the X position of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetX(sfString* string)
|
||||
float sfText_GetX(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetPosition().x, 0.f)
|
||||
CSFML_CALL_RETURN(text, GetPosition().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the Y position of a string
|
||||
/// Get the Y position of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetY(sfString* string)
|
||||
float sfText_GetY(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetPosition().y, 0.f)
|
||||
CSFML_CALL_RETURN(text, GetPosition().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the horizontal scale of a string
|
||||
/// Get the horizontal scale of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetScaleX(sfString* string)
|
||||
float sfText_GetScaleX(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetScale().x, 0.f)
|
||||
CSFML_CALL_RETURN(text, GetScale().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the vertical scale of a string
|
||||
/// Get the vertical scale of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetScaleY(sfString* string)
|
||||
float sfText_GetScaleY(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetScale().y, 0.f)
|
||||
CSFML_CALL_RETURN(text, GetScale().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the orientation of a string
|
||||
/// Get the orientation of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetRotation(sfString* string)
|
||||
float sfText_GetRotation(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetRotation(), 0.f)
|
||||
CSFML_CALL_RETURN(text, GetRotation(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of the origin a string
|
||||
/// Get the X position of the origin a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetOriginX(sfString* string)
|
||||
float sfText_GetOriginX(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetOrigin().x, 0.f)
|
||||
CSFML_CALL_RETURN(text, GetOrigin().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the top Y of the origin of a string
|
||||
/// Get the top Y of the origin of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetOriginY(sfString* string)
|
||||
float sfText_GetOriginY(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetOrigin().y, 0.f)
|
||||
CSFML_CALL_RETURN(text, GetOrigin().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the color of a string
|
||||
/// Get the color of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfString_GetColor(sfString* string)
|
||||
sfColor sfText_GetColor(sfText* text)
|
||||
{
|
||||
sfColor color = {0, 0, 0, 0};
|
||||
CSFML_CHECK_RETURN(string, color)
|
||||
CSFML_CHECK_RETURN(text, color)
|
||||
|
||||
sf::Color SFMLColor = string->This.GetColor();
|
||||
sf::Color SFMLColor = text->This.GetColor();
|
||||
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current blending mode of a string
|
||||
/// Get the current blending mode of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBlendMode sfString_GetBlendMode(sfString* string)
|
||||
sfBlendMode sfText_GetBlendMode(sfText* text)
|
||||
{
|
||||
CSFML_CHECK_RETURN(string, sfBlendNone)
|
||||
CSFML_CHECK_RETURN(text, sfBlendNone)
|
||||
|
||||
return static_cast<sfBlendMode>(string->This.GetBlendMode());
|
||||
return static_cast<sfBlendMode>(text->This.GetBlendMode());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Move a string
|
||||
/// Move a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Move(sfString* string, float offsetX, float offsetY)
|
||||
void sfText_Move(sfText* text, float offsetX, float offsetY)
|
||||
{
|
||||
CSFML_CALL(string, Move(sf::Vector2f(offsetX, offsetY)))
|
||||
CSFML_CALL(text, Move(sf::Vector2f(offsetX, offsetY)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Scale a string
|
||||
/// Scale a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Scale(sfString* string, float factorX, float factorY)
|
||||
void sfText_Scale(sfText* text, float factorX, float factorY)
|
||||
{
|
||||
CSFML_CALL(string, Scale(sf::Vector2f(factorX, factorY)))
|
||||
CSFML_CALL(text, Scale(sf::Vector2f(factorX, factorY)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Rotate a string
|
||||
/// Rotate a text
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Rotate(sfString* string, float angle)
|
||||
void sfText_Rotate(sfText* text, float angle)
|
||||
{
|
||||
CSFML_CALL(string, Rotate(angle))
|
||||
CSFML_CALL(text, Rotate(angle))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Transform a point from global coordinates into the string's local coordinates
|
||||
/// Transform a point from global coordinates into the text's local coordinates
|
||||
/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_TransformToLocal(sfString* string, float pointX, float pointY, float* x, float* y)
|
||||
void sfText_TransformToLocal(sfText* text, float pointX, float pointY, float* x, float* y)
|
||||
{
|
||||
CSFML_CHECK(string)
|
||||
CSFML_CHECK(text)
|
||||
|
||||
sf::Vector2f point = string->This.TransformToLocal(sf::Vector2f(pointX, pointY));
|
||||
sf::Vector2f point = text->This.TransformToLocal(sf::Vector2f(pointX, pointY));
|
||||
if (x) *x = point.x;
|
||||
if (y) *y = point.y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Transform a point from the string's local coordinates into global coordinates
|
||||
/// Transform a point from the text's local coordinates into global coordinates
|
||||
/// (ie it applies the object's origin, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_TransformToGlobal(sfString* string, float pointX, float pointY, float* x, float* y)
|
||||
void sfText_TransformToGlobal(sfText* text, float pointX, float pointY, float* x, float* y)
|
||||
{
|
||||
CSFML_CHECK(string)
|
||||
CSFML_CHECK(text)
|
||||
|
||||
sf::Vector2f point = string->This.TransformToGlobal(sf::Vector2f(pointX, pointY));
|
||||
sf::Vector2f point = text->This.TransformToGlobal(sf::Vector2f(pointX, pointY));
|
||||
if (x) *x = point.x;
|
||||
if (y) *y = point.y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text of a string (from a multibyte string)
|
||||
/// Set the string of a text (from a multibyte string)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetText(sfString* string, const char* text)
|
||||
void sfText_SetString(sfText* text, const char* string)
|
||||
{
|
||||
CSFML_CALL(string, SetText(text))
|
||||
CSFML_CALL(text, SetString(string))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text of a string (from a unicode string)
|
||||
/// Set the string of a text (from a unicode string)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetUnicodeText(sfString* string, const sfUint32* text)
|
||||
void sfText_SetUnicodeString(sfText* text, const sfUint32* string)
|
||||
{
|
||||
sf::Unicode::UTF32String UTF32Text = text;
|
||||
CSFML_CALL(string, SetText(UTF32Text))
|
||||
sf::String UTF32Text = string;
|
||||
CSFML_CALL(text, SetString(UTF32Text))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the font of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetFont(sfString* string, sfFont* font)
|
||||
void sfText_SetFont(sfText* text, sfFont* font)
|
||||
{
|
||||
CSFML_CHECK(font);
|
||||
|
||||
CSFML_CALL(string, SetFont(font->This))
|
||||
string->Font = font;
|
||||
CSFML_CALL(text, SetFont(font->This))
|
||||
text->Font = font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the size of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetSize(sfString* string, float size)
|
||||
void sfText_SetSize(sfText* text, float size)
|
||||
{
|
||||
CSFML_CALL(string, SetSize(size))
|
||||
CSFML_CALL(text, SetSize(size))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the style of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetStyle(sfString* string, unsigned long style)
|
||||
void sfText_SetStyle(sfText* text, unsigned long style)
|
||||
{
|
||||
CSFML_CALL(string, SetStyle(style))
|
||||
CSFML_CALL(text, SetStyle(style))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the text of a string (returns a unicode string)
|
||||
/// Get the string of a text (returns a unicode string)
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfUint32* sfString_GetUnicodeText(sfString* string)
|
||||
const sfUint32* sfText_GetUnicodeString(sfText* text)
|
||||
{
|
||||
CSFML_CHECK_RETURN(string, NULL)
|
||||
CSFML_CHECK_RETURN(text, NULL)
|
||||
|
||||
return static_cast<const sf::Unicode::UTF32String&>(string->This.GetText()).c_str();
|
||||
return text->This.GetString().GetData();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the text of a string (returns an ANSI string)
|
||||
/// Get the string of a text (returns an ANSI string)
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfString_GetText(sfString* string)
|
||||
const char* sfText_GetString(sfText* text)
|
||||
{
|
||||
CSFML_CHECK_RETURN(string, NULL)
|
||||
CSFML_CHECK_RETURN(text, NULL)
|
||||
|
||||
string->Text = string->This.GetText();
|
||||
text->String = text->This.GetString().ToAnsiString();
|
||||
|
||||
return string->Text.c_str();
|
||||
return text->String.c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the font used by a string
|
||||
/// Get the font used by a text
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFont* sfString_GetFont(sfString* string)
|
||||
sfFont* sfText_GetFont(sfText* text)
|
||||
{
|
||||
CSFML_CHECK_RETURN(string, NULL)
|
||||
CSFML_CHECK_RETURN(text, NULL)
|
||||
|
||||
return string->Font;
|
||||
return text->Font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the size of the characters of a string
|
||||
/// Get the size of the characters of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetSize(sfString* string)
|
||||
float sfText_GetSize(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetSize(), 0.f)
|
||||
CSFML_CALL_RETURN(text, GetSize(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the style of a string
|
||||
/// Get the style of a text
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned long sfString_GetStyle(sfString* string)
|
||||
unsigned long sfText_GetStyle(sfText* text)
|
||||
{
|
||||
CSFML_CALL_RETURN(string, GetStyle(), 0)
|
||||
CSFML_CALL_RETURN(text, GetStyle(), 0)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the visual position of the Index-th character of the string,
|
||||
/// in coordinates relative to the string
|
||||
/// Return the visual position of the Index-th character of the text,
|
||||
/// in coordinates relative to the text
|
||||
/// (note : translation, origin, rotation and scale are not applied)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_GetCharacterPos(sfString* string, size_t index, float* x, float* y)
|
||||
void sfText_GetCharacterPos(sfText* text, size_t index, float* x, float* y)
|
||||
{
|
||||
CSFML_CHECK(string);
|
||||
CSFML_CHECK(text);
|
||||
|
||||
sf::Vector2f pos = string->This.GetCharacterPos(index);
|
||||
sf::Vector2f pos = text->This.GetCharacterPos(index);
|
||||
if (x) *x = pos.x;
|
||||
if (y) *y = pos.y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the bounding rectangle of a string on screen
|
||||
/// Get the bounding rectangle of a text on screen
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFloatRect sfString_GetRect(sfString* string)
|
||||
sfFloatRect sfText_GetRect(sfText* text)
|
||||
{
|
||||
sfFloatRect rect = {0.f, 0.f, 0.f, 0.f};
|
||||
CSFML_CHECK_RETURN(string, rect)
|
||||
CSFML_CHECK_RETURN(text, rect)
|
||||
|
||||
sf::FloatRect SFMLRect = string->This.GetRect();
|
||||
string->Rect.Left = SFMLRect.Left;
|
||||
string->Rect.Top = SFMLRect.Top;
|
||||
string->Rect.Right = SFMLRect.Right;
|
||||
string->Rect.Bottom = SFMLRect.Bottom;
|
||||
sf::FloatRect SFMLRect = text->This.GetRect();
|
||||
text->Rect.Left = SFMLRect.Left;
|
||||
text->Rect.Top = SFMLRect.Top;
|
||||
text->Rect.Right = SFMLRect.Right;
|
||||
text->Rect.Bottom = SFMLRect.Bottom;
|
||||
|
||||
return string->Rect;
|
||||
return text->Rect;
|
||||
}
|
@ -22,28 +22,28 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_STRINGSTRUCT_H
|
||||
#define SFML_STRINGSTRUCT_H
|
||||
#ifndef SFML_TEXTSTRUCT_H
|
||||
#define SFML_TEXTSTRUCT_H
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include <SFML/Graphics/FontStruct.h>
|
||||
#include <SFML/Graphics/Rect.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Internal structure of sfMusic
|
||||
// Internal structure of sfText
|
||||
////////////////////////////////////////////////////////////
|
||||
struct sfString
|
||||
struct sfText
|
||||
{
|
||||
sf::String This;
|
||||
std::string Text;
|
||||
sf::Text This;
|
||||
std::string String;
|
||||
sfFont* Font;
|
||||
sfFloatRect Rect;
|
||||
};
|
||||
|
||||
|
||||
#endif // SFML_STRINGSTRUCT_H
|
||||
#endif // SFML_TEXTSTRUCT_H
|
@ -130,44 +130,44 @@ EXPORTS
|
||||
sfFont_Destroy
|
||||
sfFont_GetCharacterSize
|
||||
sfFont_GetDefaultFont
|
||||
sfString_Create
|
||||
sfString_Destroy
|
||||
sfString_SetX
|
||||
sfString_SetY
|
||||
sfString_SetPosition
|
||||
sfString_SetScaleX
|
||||
sfString_SetScaleY
|
||||
sfString_SetScale
|
||||
sfString_SetRotation
|
||||
sfString_SetOrigin
|
||||
sfString_SetColor
|
||||
sfString_SetBlendMode
|
||||
sfString_GetX
|
||||
sfString_GetY
|
||||
sfString_GetScaleX
|
||||
sfString_GetScaleY
|
||||
sfString_GetRotation
|
||||
sfString_GetOriginX
|
||||
sfString_GetOriginY
|
||||
sfString_GetColor
|
||||
sfString_GetBlendMode
|
||||
sfString_Move
|
||||
sfString_Scale
|
||||
sfString_Rotate
|
||||
sfString_TransformToLocal
|
||||
sfString_TransformToGlobal
|
||||
sfString_SetText
|
||||
sfString_SetUnicodeText
|
||||
sfString_SetFont
|
||||
sfString_SetSize
|
||||
sfString_SetStyle
|
||||
sfString_GetUnicodeText
|
||||
sfString_GetText
|
||||
sfString_GetFont
|
||||
sfString_GetSize
|
||||
sfString_GetStyle
|
||||
sfString_GetCharacterPos
|
||||
sfString_GetRect
|
||||
sfText_Create
|
||||
sfText_Destroy
|
||||
sfText_SetX
|
||||
sfText_SetY
|
||||
sfText_SetPosition
|
||||
sfText_SetScaleX
|
||||
sfText_SetScaleY
|
||||
sfText_SetScale
|
||||
sfText_SetRotation
|
||||
sfText_SetOrigin
|
||||
sfText_SetColor
|
||||
sfText_SetBlendMode
|
||||
sfText_GetX
|
||||
sfText_GetY
|
||||
sfText_GetScaleX
|
||||
sfText_GetScaleY
|
||||
sfText_GetRotation
|
||||
sfText_GetOriginX
|
||||
sfText_GetOriginY
|
||||
sfText_GetColor
|
||||
sfText_GetBlendMode
|
||||
sfText_Move
|
||||
sfText_Scale
|
||||
sfText_Rotate
|
||||
sfText_TransformToLocal
|
||||
sfText_TransformToGlobal
|
||||
sfText_SetString
|
||||
sfText_SetUnicodeString
|
||||
sfText_SetFont
|
||||
sfText_SetSize
|
||||
sfText_SetStyle
|
||||
sfText_GetUnicodeString
|
||||
sfText_GetString
|
||||
sfText_GetFont
|
||||
sfText_GetSize
|
||||
sfText_GetStyle
|
||||
sfText_GetCharacterPos
|
||||
sfText_GetRect
|
||||
sfRenderImage_Create
|
||||
sfRenderImage_Destroy
|
||||
sfRenderImage_GetWidth
|
||||
@ -177,10 +177,10 @@ EXPORTS
|
||||
sfRenderImage_Display
|
||||
sfRenderImage_DrawSprite
|
||||
sfRenderImage_DrawShape
|
||||
sfRenderImage_DrawString
|
||||
sfRenderImage_DrawText
|
||||
sfRenderImage_DrawSpriteWithShader
|
||||
sfRenderImage_DrawShapeWithShader
|
||||
sfRenderImage_DrawStringWithShader
|
||||
sfRenderImage_DrawTextWithShader
|
||||
sfRenderImage_Clear
|
||||
sfRenderImage_SetView
|
||||
sfRenderImage_GetView
|
||||
@ -213,10 +213,10 @@ EXPORTS
|
||||
sfRenderWindow_GetFrameTime
|
||||
sfRenderWindow_SetJoystickThreshold
|
||||
sfRenderWindow_DrawSprite
|
||||
sfRenderWindow_DrawString
|
||||
sfRenderWindow_DrawText
|
||||
sfRenderWindow_DrawShape
|
||||
sfRenderWindow_DrawSpriteWithShader
|
||||
sfRenderWindow_DrawStringWithShader
|
||||
sfRenderWindow_DrawTextWithShader
|
||||
sfRenderWindow_DrawShapeWithShader
|
||||
sfRenderWindow_Clear
|
||||
sfRenderWindow_SetView
|
||||
|
@ -130,44 +130,44 @@ EXPORTS
|
||||
sfFont_Destroy
|
||||
sfFont_GetCharacterSize
|
||||
sfFont_GetDefaultFont
|
||||
sfString_Create
|
||||
sfString_Destroy
|
||||
sfString_SetX
|
||||
sfString_SetY
|
||||
sfString_SetPosition
|
||||
sfString_SetScaleX
|
||||
sfString_SetScaleY
|
||||
sfString_SetScale
|
||||
sfString_SetRotation
|
||||
sfString_SetOrigin
|
||||
sfString_SetColor
|
||||
sfString_SetBlendMode
|
||||
sfString_GetX
|
||||
sfString_GetY
|
||||
sfString_GetScaleX
|
||||
sfString_GetScaleY
|
||||
sfString_GetRotation
|
||||
sfString_GetOriginX
|
||||
sfString_GetOriginY
|
||||
sfString_GetColor
|
||||
sfString_GetBlendMode
|
||||
sfString_Move
|
||||
sfString_Scale
|
||||
sfString_Rotate
|
||||
sfString_TransformToLocal
|
||||
sfString_TransformToGlobal
|
||||
sfString_SetText
|
||||
sfString_SetUnicodeText
|
||||
sfString_SetFont
|
||||
sfString_SetSize
|
||||
sfString_SetStyle
|
||||
sfString_GetUnicodeText
|
||||
sfString_GetText
|
||||
sfString_GetFont
|
||||
sfString_GetSize
|
||||
sfString_GetStyle
|
||||
sfString_GetCharacterPos
|
||||
sfString_GetRect
|
||||
sfText_Create
|
||||
sfText_Destroy
|
||||
sfText_SetX
|
||||
sfText_SetY
|
||||
sfText_SetPosition
|
||||
sfText_SetScaleX
|
||||
sfText_SetScaleY
|
||||
sfText_SetScale
|
||||
sfText_SetRotation
|
||||
sfText_SetOrigin
|
||||
sfText_SetColor
|
||||
sfText_SetBlendMode
|
||||
sfText_GetX
|
||||
sfText_GetY
|
||||
sfText_GetScaleX
|
||||
sfText_GetScaleY
|
||||
sfText_GetRotation
|
||||
sfText_GetOriginX
|
||||
sfText_GetOriginY
|
||||
sfText_GetColor
|
||||
sfText_GetBlendMode
|
||||
sfText_Move
|
||||
sfText_Scale
|
||||
sfText_Rotate
|
||||
sfText_TransformToLocal
|
||||
sfText_TransformToGlobal
|
||||
sfText_SetString
|
||||
sfText_SetUnicodeString
|
||||
sfText_SetFont
|
||||
sfText_SetSize
|
||||
sfText_SetStyle
|
||||
sfText_GetUnicodeString
|
||||
sfText_GetString
|
||||
sfText_GetFont
|
||||
sfText_GetSize
|
||||
sfText_GetStyle
|
||||
sfText_GetCharacterPos
|
||||
sfText_GetRect
|
||||
sfRenderImage_Create
|
||||
sfRenderImage_Destroy
|
||||
sfRenderImage_GetWidth
|
||||
@ -177,10 +177,10 @@ EXPORTS
|
||||
sfRenderImage_Display
|
||||
sfRenderImage_DrawSprite
|
||||
sfRenderImage_DrawShape
|
||||
sfRenderImage_DrawString
|
||||
sfRenderImage_DrawText
|
||||
sfRenderImage_DrawSpriteWithShader
|
||||
sfRenderImage_DrawShapeWithShader
|
||||
sfRenderImage_DrawStringWithShader
|
||||
sfRenderImage_DrawTextWithShader
|
||||
sfRenderImage_Clear
|
||||
sfRenderImage_SetView
|
||||
sfRenderImage_GetView
|
||||
@ -215,10 +215,10 @@ EXPORTS
|
||||
sfRenderWindow_GetFrameTime
|
||||
sfRenderWindow_SetJoystickThreshold
|
||||
sfRenderWindow_DrawSprite
|
||||
sfRenderWindow_DrawString
|
||||
sfRenderWindow_DrawText
|
||||
sfRenderWindow_DrawShape
|
||||
sfRenderWindow_DrawSpriteWithShader
|
||||
sfRenderWindow_DrawStringWithShader
|
||||
sfRenderWindow_DrawTextWithShader
|
||||
sfRenderWindow_DrawShapeWithShader
|
||||
sfRenderWindow_Clear
|
||||
sfRenderWindow_SetView
|
||||
|
@ -133,7 +133,7 @@
|
||||
<Unit filename="..\..\include\SFML\Graphics\Shader.hpp" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Shape.hpp" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Sprite.hpp" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\String.hpp" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\Text.hpp" />
|
||||
<Unit filename="..\..\include\SFML\Graphics\View.hpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Batch.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Batch.hpp" />
|
||||
@ -189,7 +189,7 @@
|
||||
<Unit filename="..\..\src\SFML\Graphics\Shader.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Shape.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Sprite.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\String.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Text.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\View.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Win32\RenderImageImplPBuffer.cpp" />
|
||||
<Unit filename="..\..\src\SFML\Graphics\Win32\RenderImageImplPBuffer.hpp" />
|
||||
|
@ -98,12 +98,13 @@
|
||||
<Unit filename="..\..\include\SFML\System\Resource.inl" />
|
||||
<Unit filename="..\..\include\SFML\System\ResourcePtr.inl" />
|
||||
<Unit filename="..\..\include\SFML\System\Sleep.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\String.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\Thread.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\ThreadLocal.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\ThreadLocalPtr.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\ThreadLocalPtr.inl" />
|
||||
<Unit filename="..\..\include\SFML\System\Unicode.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\Unicode.inl" />
|
||||
<Unit filename="..\..\include\SFML\System\Utf.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\Utf.inl" />
|
||||
<Unit filename="..\..\include\SFML\System\Vector2.hpp" />
|
||||
<Unit filename="..\..\include\SFML\System\Vector2.inl" />
|
||||
<Unit filename="..\..\include\SFML\System\Vector3.hpp" />
|
||||
@ -114,9 +115,10 @@
|
||||
<Unit filename="..\..\src\SFML\System\Platform.hpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Randomizer.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Sleep.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\String.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Thread.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\ThreadLocal.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Unicode.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Utf.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Win32\MutexImpl.cpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Win32\MutexImpl.hpp" />
|
||||
<Unit filename="..\..\src\SFML\System\Win32\Platform.cpp" />
|
||||
|
@ -3314,11 +3314,11 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\Graphics\String.cpp"
|
||||
RelativePath="..\..\src\SFML\Graphics\Text.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\Graphics\String.hpp"
|
||||
RelativePath="..\..\include\SFML\Graphics\Text.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
|
@ -470,6 +470,14 @@
|
||||
RelativePath="..\..\include\SFML\System\Sleep.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\String.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\System\String.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\Thread.cpp"
|
||||
>
|
||||
@ -495,15 +503,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\Unicode.cpp"
|
||||
RelativePath="..\..\src\SFML\System\Utf.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\System\Unicode.hpp"
|
||||
RelativePath="..\..\include\SFML\System\Utf.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\System\Unicode.inl"
|
||||
RelativePath="..\..\include\SFML\System\Utf.inl"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
@ -3409,11 +3409,11 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\Graphics\String.cpp"
|
||||
RelativePath="..\..\src\SFML\Graphics\Text.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\Graphics\String.hpp"
|
||||
RelativePath="..\..\include\SFML\Graphics\Text.hpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
|
@ -431,6 +431,14 @@
|
||||
RelativePath="..\..\include\SFML\System\Sleep.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\String.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\System\String.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\Thread.cpp"
|
||||
>
|
||||
@ -456,15 +464,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\SFML\System\Unicode.cpp"
|
||||
RelativePath="..\..\src\SFML\System\Utf.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\System\Unicode.hpp"
|
||||
RelativePath="..\..\include\SFML\System\Utf.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\SFML\System\Unicode.inl"
|
||||
RelativePath="..\..\include\SFML\System\Utf.inl"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -26,7 +26,7 @@ namespace sample_opengl
|
||||
Sprite background = new Sprite(backgroundImage);
|
||||
|
||||
// Create a text to display
|
||||
String2D text = new String2D("SFML / OpenGL demo");
|
||||
Text text = new Text("SFML / OpenGL demo");
|
||||
text.Position = new Vector2(250.0F, 450.0F);
|
||||
text.Color = new Color(255, 255, 255, 170);
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace sample_shader
|
||||
private static ShaderSelector backgroundShader;
|
||||
private static ShaderSelector entityShader;
|
||||
private static ShaderSelector globalShader;
|
||||
private static String2D shaderStr;
|
||||
private static Text shaderText;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
@ -122,22 +122,22 @@ namespace sample_shader
|
||||
shaders["pixelate"].SetTexture("texture", Shader.CurrentTexture);
|
||||
|
||||
// Define a string for displaying current effect description
|
||||
shaderStr = new String2D();
|
||||
shaderStr.Font = font;
|
||||
shaderStr.Size = 20;
|
||||
shaderStr.Position = new Vector2(5.0F, 0.0F);
|
||||
shaderStr.Color = new Color(250, 100, 30);
|
||||
shaderStr.Text = "Background shader: \"" + backgroundShader.Name + "\"\n" +
|
||||
shaderText = new Text();
|
||||
shaderText.Font = font;
|
||||
shaderText.Size = 20;
|
||||
shaderText.Position = new Vector2(5.0F, 0.0F);
|
||||
shaderText.Color = new Color(250, 100, 30);
|
||||
shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
|
||||
"Flower shader: \"" + entityShader.Name + "\"\n" +
|
||||
"Global shader: \"" + globalShader.Name + "\"\n";
|
||||
|
||||
// Define a string for displaying help
|
||||
String2D infoStr = new String2D();
|
||||
infoStr.Font = font;
|
||||
infoStr.Size = 20;
|
||||
infoStr.Position = new Vector2(5.0F, 510.0F);
|
||||
infoStr.Color = new Color(250, 100, 30);
|
||||
infoStr.Text = "Move your mouse to change the shaders' parameters\n" +
|
||||
Text infoText = new Text();
|
||||
infoText.Font = font;
|
||||
infoText.Size = 20;
|
||||
infoText.Position = new Vector2(5.0F, 510.0F);
|
||||
infoText.Color = new Color(250, 100, 30);
|
||||
infoText.DisplayedString = "Move your mouse to change the shaders' parameters\n" +
|
||||
"Press numpad 1 to change the background shader\n" +
|
||||
"Press numpad 2 to change the flower shader\n" +
|
||||
"Press numpad 3 to change the global shader";
|
||||
@ -176,9 +176,9 @@ namespace sample_shader
|
||||
// Draw the contents of the render image to the window
|
||||
window.Draw(new Sprite(image.Image), globalShader.Shader);
|
||||
|
||||
// Draw interface strings
|
||||
window.Draw(shaderStr);
|
||||
window.Draw(infoStr);
|
||||
// Draw interface texts
|
||||
window.Draw(shaderText);
|
||||
window.Draw(infoText);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
window.Display();
|
||||
@ -192,9 +192,9 @@ namespace sample_shader
|
||||
private static void DisplayError(RenderWindow window)
|
||||
{
|
||||
// Define a string for displaying the error message
|
||||
String2D errorStr = new String2D("Sorry, your system doesn't support shaders");
|
||||
errorStr.Position = new Vector2(100.0F, 250.0F);
|
||||
errorStr.Color = new Color(200, 100, 150);
|
||||
Text error = new Text("Sorry, your system doesn't support shaders");
|
||||
error.Position = new Vector2(100.0F, 250.0F);
|
||||
error.Color = new Color(200, 100, 150);
|
||||
|
||||
// Start the game loop
|
||||
while (window.IsOpened())
|
||||
@ -206,7 +206,7 @@ namespace sample_shader
|
||||
window.Clear();
|
||||
|
||||
// Draw the error message
|
||||
window.Draw(errorStr);
|
||||
window.Draw(error);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
window.Display();
|
||||
@ -242,7 +242,7 @@ namespace sample_shader
|
||||
}
|
||||
|
||||
// Update the text
|
||||
shaderStr.Text = "Background shader: \"" + backgroundShader.Name + "\"\n" +
|
||||
shaderText.DisplayedString = "Background shader: \"" + backgroundShader.Name + "\"\n" +
|
||||
"Flower shader: \"" + entityShader.Name + "\"\n" +
|
||||
"Global shader: \"" + globalShader.Name + "\"\n";
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace SFML
|
||||
/// This class defines a graphical 2D text, that can be drawn on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class String2D : Drawable
|
||||
public class Text : Drawable
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
@ -39,46 +39,46 @@ namespace SFML
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D() :
|
||||
public Text() :
|
||||
this("")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the string from a text
|
||||
/// Construct the text from a string
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="str">String to display</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D(string text) :
|
||||
this(text, Font.DefaultFont)
|
||||
public Text(string str) :
|
||||
this(str, Font.DefaultFont)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the string from a text and a font
|
||||
/// Construct the text from a string and a font
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="str">String to display</param>
|
||||
/// <param name="font">Font to use</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D(string text, Font font) :
|
||||
this(text, font, 30)
|
||||
public Text(string str, Font font) :
|
||||
this(str, font, 30)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the string from a text, font and size
|
||||
/// Construct the text from a string, font and size
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="str">String to display</param>
|
||||
/// <param name="font">Font to use</param>
|
||||
/// <param name="size">Base characters size</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D(string text, Font font, uint size) :
|
||||
base(sfString_Create())
|
||||
public Text(string str, Font font, uint size) :
|
||||
base(sfText_Create())
|
||||
{
|
||||
Text = text;
|
||||
DisplayedString = str;
|
||||
Font = font;
|
||||
Size = size;
|
||||
}
|
||||
@ -90,8 +90,8 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Position
|
||||
{
|
||||
get { return new Vector2(sfString_GetX(This), sfString_GetY(This)); }
|
||||
set { sfString_SetPosition(This, value.X, value.Y); }
|
||||
get { return new Vector2(sfText_GetX(This), sfText_GetY(This)); }
|
||||
set { sfText_SetPosition(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -101,8 +101,8 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public override float Rotation
|
||||
{
|
||||
get { return sfString_GetRotation(This); }
|
||||
set { sfString_SetRotation(This, value); }
|
||||
get { return sfText_GetRotation(This); }
|
||||
set { sfText_SetRotation(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -112,8 +112,8 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Scale
|
||||
{
|
||||
get { return new Vector2(sfString_GetScaleX(This), sfString_GetScaleY(This)); }
|
||||
set { sfString_SetScale(This, value.X, value.Y); }
|
||||
get { return new Vector2(sfText_GetScaleX(This), sfText_GetScaleY(This)); }
|
||||
set { sfText_SetScale(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -124,8 +124,8 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Origin
|
||||
{
|
||||
get { return new Vector2(sfString_GetOriginX(This), sfString_GetOriginY(This)); }
|
||||
set { sfString_SetOrigin(This, value.X, value.Y); }
|
||||
get { return new Vector2(sfText_GetOriginX(This), sfText_GetOriginY(This)); }
|
||||
set { sfText_SetOrigin(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -135,8 +135,8 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Color Color
|
||||
{
|
||||
get { return sfString_GetColor(This); }
|
||||
set { sfString_SetColor(This, value); }
|
||||
get { return sfText_GetColor(This); }
|
||||
set { sfText_SetColor(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -146,8 +146,8 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public override BlendMode BlendMode
|
||||
{
|
||||
get { return sfString_GetBlendMode(This); }
|
||||
set { sfString_SetBlendMode(This, value); }
|
||||
get { return sfText_GetBlendMode(This); }
|
||||
set { sfText_SetBlendMode(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -161,7 +161,7 @@ namespace SFML
|
||||
public override Vector2 TransformToLocal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfString_TransformToLocal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
sfText_TransformToLocal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
@ -177,22 +177,22 @@ namespace SFML
|
||||
public override Vector2 TransformToGlobal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfString_TransformToGlobal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
sfText_TransformToGlobal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Text displayed
|
||||
/// String which is displayed
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public string Text
|
||||
public string DisplayedString
|
||||
{
|
||||
// TODO : use unicode functions
|
||||
// (convert from UTF-16 to UTF-32, and find how to marshal System.String as sfUint32*...)
|
||||
get {return sfString_GetText(This);}
|
||||
set {sfString_SetText(This, value);}
|
||||
get {return sfText_GetString(This);}
|
||||
set {sfText_SetString(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -203,7 +203,7 @@ namespace SFML
|
||||
public Font Font
|
||||
{
|
||||
get {return myFont;}
|
||||
set {myFont = value; sfString_SetFont(This, value != null ? value.This : IntPtr.Zero);}
|
||||
set {myFont = value; sfText_SetFont(This, value != null ? value.This : IntPtr.Zero);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -213,8 +213,8 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Size
|
||||
{
|
||||
get {return sfString_GetSize(This);}
|
||||
set {sfString_SetSize(This, value);}
|
||||
get {return sfText_GetSize(This);}
|
||||
set {sfText_SetSize(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -224,34 +224,34 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
public Styles Style
|
||||
{
|
||||
get {return sfString_GetStyle(This);}
|
||||
set {sfString_SetStyle(This, value);}
|
||||
get {return sfText_GetStyle(This);}
|
||||
set {sfText_SetStyle(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the string rectangle on screen
|
||||
/// Get the text rectangle on screen
|
||||
/// </summary>
|
||||
/// <returns>String rectangle in global coordinates (doesn't include rotation)</returns>
|
||||
/// <returns>Text rectangle in global coordinates (doesn't include rotation)</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public FloatRect GetRect()
|
||||
{
|
||||
return sfString_GetRect(This);
|
||||
return sfText_GetRect(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Return the visual position of the Index-th character of the string,
|
||||
/// in coordinates relative to the string
|
||||
/// Return the visual position of the Index-th character of the text,
|
||||
/// in coordinates relative to the text
|
||||
/// (note : translation, origin, rotation and scale are not applied)
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the character</param>
|
||||
/// <returns>Position of the Index-th character (end of string if Index is out of range)</returns>
|
||||
/// <returns>Position of the Index-th character (end of text if Index is out of range)</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2 GetCharacterPos(uint index)
|
||||
{
|
||||
Vector2 Pos;
|
||||
sfString_GetCharacterPos(This, index, out Pos.X, out Pos.Y);
|
||||
sfText_GetCharacterPos(This, index, out Pos.X, out Pos.Y);
|
||||
|
||||
return Pos;
|
||||
}
|
||||
@ -266,9 +266,9 @@ namespace SFML
|
||||
internal override void Render(RenderWindow target, Shader shader)
|
||||
{
|
||||
if (shader == null)
|
||||
sfRenderWindow_DrawString(target.This, This);
|
||||
sfRenderWindow_DrawText(target.This, This);
|
||||
else
|
||||
sfRenderWindow_DrawStringWithShader(target.This, This, shader.This);
|
||||
sfRenderWindow_DrawTextWithShader(target.This, This, shader.This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -281,9 +281,9 @@ namespace SFML
|
||||
internal override void Render(RenderImage target, Shader shader)
|
||||
{
|
||||
if (shader == null)
|
||||
sfRenderImage_DrawString(target.This, This);
|
||||
sfRenderImage_DrawText(target.This, This);
|
||||
else
|
||||
sfRenderImage_DrawStringWithShader(target.This, This, shader.This);
|
||||
sfRenderImage_DrawTextWithShader(target.This, This, shader.This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -294,113 +294,113 @@ namespace SFML
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfString_Destroy(This);
|
||||
sfText_Destroy(This);
|
||||
}
|
||||
|
||||
private Font myFont = Font.DefaultFont;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfString_Create();
|
||||
static extern IntPtr sfText_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_Destroy(IntPtr This);
|
||||
static extern void sfText_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetPosition(IntPtr This, float X, float Y);
|
||||
static extern void sfText_SetPosition(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetX(IntPtr This);
|
||||
static extern float sfText_GetX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetY(IntPtr This);
|
||||
static extern float sfText_GetY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetRotation(IntPtr This, float Rotation);
|
||||
static extern void sfText_SetRotation(IntPtr This, float Rotation);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetRotation(IntPtr This);
|
||||
static extern float sfText_GetRotation(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetScale(IntPtr This, float X, float Y);
|
||||
static extern void sfText_SetScale(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetScaleX(IntPtr This);
|
||||
static extern float sfText_GetScaleX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetScaleY(IntPtr This);
|
||||
static extern float sfText_GetScaleY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetOrigin(IntPtr This, float X, float Y);
|
||||
static extern void sfText_SetOrigin(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetOriginX(IntPtr This);
|
||||
static extern float sfText_GetOriginX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetOriginY(IntPtr This);
|
||||
static extern float sfText_GetOriginY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetColor(IntPtr This, Color Color);
|
||||
static extern void sfText_SetColor(IntPtr This, Color Color);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfString_GetColor(IntPtr This);
|
||||
static extern Color sfText_GetColor(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetBlendMode(IntPtr This, BlendMode Mode);
|
||||
static extern void sfText_SetBlendMode(IntPtr This, BlendMode Mode);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern BlendMode sfString_GetBlendMode(IntPtr This);
|
||||
static extern BlendMode sfText_GetBlendMode(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfString_TransformToLocal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
static extern Vector2 sfText_TransformToLocal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfString_TransformToGlobal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
static extern Vector2 sfText_TransformToGlobal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_DrawString(IntPtr This, IntPtr String);
|
||||
static extern void sfRenderWindow_DrawText(IntPtr This, IntPtr String);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_DrawStringWithShader(IntPtr This, IntPtr String, IntPtr Shader);
|
||||
static extern void sfRenderWindow_DrawTextWithShader(IntPtr This, IntPtr String, IntPtr Shader);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderImage_DrawString(IntPtr This, IntPtr String);
|
||||
static extern void sfRenderImage_DrawText(IntPtr This, IntPtr String);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderImage_DrawStringWithShader(IntPtr This, IntPtr String, IntPtr Shader);
|
||||
static extern void sfRenderImage_DrawTextWithShader(IntPtr This, IntPtr String, IntPtr Shader);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetWidth(IntPtr This);
|
||||
static extern float sfText_GetWidth(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetHeight(IntPtr This);
|
||||
static extern float sfText_GetHeight(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetText(IntPtr This, string Text);
|
||||
static extern void sfText_SetString(IntPtr This, string Text);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetFont(IntPtr This, IntPtr Font);
|
||||
static extern void sfText_SetFont(IntPtr This, IntPtr Font);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetSize(IntPtr This, float Size);
|
||||
static extern void sfText_SetSize(IntPtr This, float Size);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetStyle(IntPtr This, Styles Style);
|
||||
static extern void sfText_SetStyle(IntPtr This, Styles Style);
|
||||
|
||||
[DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
|
||||
static extern string sfString_GetText(IntPtr This);
|
||||
static extern string sfText_GetString(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetSize(IntPtr This);
|
||||
static extern float sfText_GetSize(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Styles sfString_GetStyle(IntPtr This);
|
||||
static extern Styles sfText_GetStyle(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern FloatRect sfString_GetRect(IntPtr This);
|
||||
static extern FloatRect sfText_GetRect(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_GetCharacterPos(IntPtr This, uint Index, out float X, out float Y);
|
||||
static extern void sfText_GetCharacterPos(IntPtr This, uint Index, out float X, out float Y);
|
||||
|
||||
#endregion
|
||||
}
|
@ -60,7 +60,7 @@
|
||||
<Compile Include="Shader.cs" />
|
||||
<Compile Include="Shape.cs" />
|
||||
<Compile Include="Sprite.cs" />
|
||||
<Compile Include="String2D.cs" />
|
||||
<Compile Include="Text.cs" />
|
||||
<Compile Include="Vector2.cs" />
|
||||
<Compile Include="View.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include <SFML/Graphics/View.hpp>
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Resource.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/Unicode.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <SFML/Graphics/Glyph.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
@ -40,16 +40,15 @@
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class String;
|
||||
|
||||
namespace priv
|
||||
{
|
||||
class FontLoader;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Font is the low-level class for loading and
|
||||
/// manipulating character fonts. This class is meant to
|
||||
/// be used by sf::String
|
||||
/// be used by sf::Text
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Font : public Resource<Font>
|
||||
{
|
||||
@ -71,7 +70,7 @@ public :
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool LoadFromFile(const std::string& filename, unsigned int charSize = 30, const Unicode::Text& charset = ourDefaultCharset);
|
||||
bool LoadFromFile(const std::string& filename, unsigned int charSize = 30, String charset = ourDefaultCharset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load the font from a file in memory
|
||||
@ -84,7 +83,7 @@ public :
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize = 30, const Unicode::Text& charset = ourDefaultCharset);
|
||||
bool LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize = 30, String charset = ourDefaultCharset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the base size of characters in the font;
|
||||
|
@ -22,14 +22,14 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_STRING_HPP
|
||||
#define SFML_STRING_HPP
|
||||
#ifndef SFML_TEXT_HPP
|
||||
#define SFML_TEXT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Resource.hpp>
|
||||
#include <SFML/System/Unicode.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
@ -39,9 +39,9 @@
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// String defines a graphical 2D text, that can be drawn on screen
|
||||
/// Text defines a graphical 2D text, that can be drawn on screen
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API String : public Drawable
|
||||
class SFML_API Text : public Drawable
|
||||
{
|
||||
public :
|
||||
|
||||
@ -60,25 +60,25 @@ public :
|
||||
/// Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String();
|
||||
Text();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the string from any kind of text
|
||||
///
|
||||
/// \param text : Text assigned to the string
|
||||
/// \param string : Text assigned to the string
|
||||
/// \param font : Font used to draw the string
|
||||
/// \param size : Characters size
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit String(const Unicode::Text& text, const Font& font = Font::GetDefaultFont(), float size = 30.f);
|
||||
explicit Text(const String& string, const Font& font = Font::GetDefaultFont(), float size = 30.f);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text (from any kind of string)
|
||||
///
|
||||
/// \param text : New text
|
||||
/// \param string : New text
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SetText(const Unicode::Text& text);
|
||||
void SetString(const String& string);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the font of the string
|
||||
@ -112,7 +112,7 @@ public :
|
||||
/// \return String's text
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Unicode::Text& GetText() const;
|
||||
const String& GetString() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the font used by the string
|
||||
@ -177,7 +177,7 @@ private :
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Unicode::Text myText; ///< Text to display
|
||||
String myString; ///< String to display
|
||||
ResourcePtr<Font> myFont; ///< Font used to display the string
|
||||
float mySize; ///< Size of the characters
|
||||
unsigned long myStyle; ///< Text style (see Style enum)
|
||||
@ -188,4 +188,4 @@ private :
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_STRING_HPP
|
||||
#endif // SFML_TEXT_HPP
|
@ -35,10 +35,11 @@
|
||||
#include <SFML/System/Mutex.hpp>
|
||||
#include <SFML/System/Randomizer.hpp>
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <SFML/System/Thread.hpp>
|
||||
#include <SFML/System/ThreadLocal.hpp>
|
||||
#include <SFML/System/ThreadLocalPtr.hpp>
|
||||
#include <SFML/System/Unicode.hpp>
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
|
||||
|
530
include/SFML/System/String.hpp
Normal file
530
include/SFML/System/String.hpp
Normal file
@ -0,0 +1,530 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_STRING_HPP
|
||||
#define SFML_STRING_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility string class that automatically handles
|
||||
/// conversions between types and encodings
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API String
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Types
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::basic_string<Uint32>::iterator Iterator; ///< Iterator type
|
||||
typedef std::basic_string<Uint32>::const_iterator ConstIterator; ///< Constant iterator type
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor creates an empty string.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a null-terminated C-style ANSI string
|
||||
///
|
||||
/// The source string is converted to UTF-32 according
|
||||
/// to the current locale. See the other constructor for
|
||||
/// explicitely passing the locale to use.
|
||||
///
|
||||
/// \param ansiString ANSI string to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const char* ansiString);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from an ANSI string
|
||||
///
|
||||
/// The source string is converted to UTF-32 according
|
||||
/// to the current global locale. See the other constructor for
|
||||
/// explicitely passing the locale to use.
|
||||
///
|
||||
/// \param ansiString ANSI string to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const std::string& ansiString);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a null-terminated C-style ANSI string and a locale
|
||||
///
|
||||
/// The source string is converted to UTF-32 according
|
||||
/// to the given locale. If you want to use the current global
|
||||
/// locale, rather use the other constructor.
|
||||
///
|
||||
/// \param ansiString ANSI string to convert
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const char* ansiString, const std::locale& locale);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from an ANSI string and a locale
|
||||
///
|
||||
/// The source string is converted to UTF-32 according
|
||||
/// to the given locale. If you want to use the current global
|
||||
/// locale, rather use the other constructor.
|
||||
///
|
||||
/// \param ansiString ANSI string to convert
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const std::string& ansiString, const std::locale& locale);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from null-terminated C-style wide string
|
||||
///
|
||||
/// \param wideString Wide string to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const wchar_t* wideString);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a wide string
|
||||
///
|
||||
/// \param wideString Wide string to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const std::wstring& wideString);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from a null-terminated C-style UTF-32 string
|
||||
///
|
||||
/// \param utf32String UTF-32 string to assign
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const Uint32* utf32String);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from an UTF-32 string
|
||||
///
|
||||
/// \param utf32String UTF-32 string to assign
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const std::basic_string<Uint32>& utf32String);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
/// \param other Instance to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const String& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Implicit cast operator to std::string (ANSI string)
|
||||
///
|
||||
/// The current global locale is used for conversion. If you
|
||||
/// want to explicitely specify a locale, see ToAnsiString.
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
/// This operator is defined for convenience, and is equivalent
|
||||
/// to calling ToAnsiString().
|
||||
///
|
||||
/// \return Converted ANSI string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator std::string() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Implicit cast operator to std::wstring (wide string)
|
||||
///
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
/// This operator is defined for convenience, and is equivalent
|
||||
/// to calling ToWideString().
|
||||
///
|
||||
/// \return Converted wide string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator std::wstring() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the unicode string to an ANSI string
|
||||
///
|
||||
/// The current global locale is used for conversion. If you
|
||||
/// want to explicitely specify a locale, see the other overload
|
||||
/// of ToAnsiString.
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
///
|
||||
/// \return Converted ANSI string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string ToAnsiString() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the unicode string to an ANSI string
|
||||
///
|
||||
/// The UTF-32 string is converted to an ANSI string in
|
||||
/// the encoding defined by \a locale. If you want to use
|
||||
/// the current global locale, see the other overload
|
||||
/// of ToAnsiString.
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
///
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Converted ANSI string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string ToAnsiString(const std::locale& locale) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the unicode string to a wide string
|
||||
///
|
||||
/// Characters that do not fit in the target encoding are
|
||||
/// discarded from the returned string.
|
||||
///
|
||||
/// \return Converted wide string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::wstring ToWideString() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String& operator =(const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of += operator to append an ANSI character
|
||||
///
|
||||
/// \param right Character to append
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String& operator +=(char right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of += operator to append a wide character
|
||||
///
|
||||
/// \param right Character to append
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String& operator +=(wchar_t right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of += operator to append an UTF-32 character
|
||||
///
|
||||
/// \param right Character to append
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String& operator +=(Uint32 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of += operator to append an UTF-32 string
|
||||
///
|
||||
/// \param right String to append
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String& operator +=(const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of [] operator to access a character by its position
|
||||
///
|
||||
/// This function provides read-only access to characters.
|
||||
/// Note: this function doesn't throw if \a index is out of range.
|
||||
///
|
||||
/// \param index Index of the character to get
|
||||
///
|
||||
/// \return Character at position \a index
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 operator [](std::size_t index) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of [] operator to access a character by its position
|
||||
///
|
||||
/// This function provides read and write access to characters.
|
||||
/// Note: this function doesn't throw if \a index is out of range.
|
||||
///
|
||||
/// \param index Index of the character to get
|
||||
///
|
||||
/// \return Reference to the character at position \a index
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32& operator [](std::size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Clear the string
|
||||
///
|
||||
/// This function removes all the characters from the string.
|
||||
///
|
||||
/// \see IsEmpty, Erase
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Clear();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the size of the string
|
||||
///
|
||||
/// \return Number of characters in the string
|
||||
///
|
||||
/// \see IsEmpty
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t GetSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check whether the string is empty or not
|
||||
///
|
||||
/// \return True if the string is empty (i.e. contains no character)
|
||||
///
|
||||
/// \see Clear, GetSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool IsEmpty() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Erase one or more characters from the string
|
||||
///
|
||||
/// This function removes a sequence of \a count characters
|
||||
/// starting from \a position.
|
||||
///
|
||||
/// \param position Position of the first character to erase
|
||||
/// \param count Number of characters to erase
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void Erase(std::size_t position, std::size_t count = 1);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a pointer to the C-style array of characters
|
||||
///
|
||||
/// This functions provides a read-only access to a
|
||||
/// null-terminated C-style representation of the string.
|
||||
/// The returned pointer is temporary and is meant only for
|
||||
/// immediate use, thus it is not recommended to store it.
|
||||
///
|
||||
/// \return Read-only pointer to the array of characters
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Uint32* GetData() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the beginning of the string
|
||||
///
|
||||
/// \return Read-write iterator to the beginning of the string characters
|
||||
///
|
||||
/// \see End
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Iterator Begin();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the beginning of the string
|
||||
///
|
||||
/// \return Read-only iterator to the beginning of the string characters
|
||||
///
|
||||
/// \see End
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ConstIterator Begin() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the beginning of the string
|
||||
///
|
||||
/// The end iterator refers to 1 position past the last character;
|
||||
/// thus it represents an invalid character and should never be
|
||||
/// accessed.
|
||||
///
|
||||
/// \return Read-write iterator to the end of the string characters
|
||||
///
|
||||
/// \see Begin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Iterator End();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return an iterator to the beginning of the string
|
||||
///
|
||||
/// The end iterator refers to 1 position past the last character;
|
||||
/// thus it represents an invalid character and should never be
|
||||
/// accessed.
|
||||
///
|
||||
/// \return Read-only iterator to the end of the string characters
|
||||
///
|
||||
/// \see Begin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
ConstIterator End() const;
|
||||
|
||||
private :
|
||||
|
||||
friend SFML_API bool operator ==(const String& left, const String& right);
|
||||
friend SFML_API bool operator <(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
std::basic_string<Uint32> myString; ///< Internal string of UTF-32 characters
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of == operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if both strings are equal
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator ==(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of != operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if both strings are different
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator !=(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of < operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is alphabetically lesser than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator <(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of > operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is alphabetically greater than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator >(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of <= operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is alphabetically lesser or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator <=(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of >= operator to compare two UTF-32 strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return True if \a left is alphabetically greater or equal than \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API bool operator >=(const String& left, const String& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of binary + operator to concatenate a string and an ANSI character
|
||||
///
|
||||
/// \param left Source string
|
||||
/// \param right Character to concatenate
|
||||
///
|
||||
/// \return Concatenated string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API String operator +(const String& left, char right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of binary + operator to concatenate a string and a wide character
|
||||
///
|
||||
/// \param left Source string
|
||||
/// \param right Character to concatenate
|
||||
///
|
||||
/// \return Concatenated string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API String operator +(const String& left, wchar_t right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of binary + operator to concatenate a string and a UTF-32 character
|
||||
///
|
||||
/// \param left Source string
|
||||
/// \param right Character to concatenate
|
||||
///
|
||||
/// \return Concatenated string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API String operator +(const String& left, Uint32 right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of binary + operator to concatenate two strings
|
||||
///
|
||||
/// \param left Left operand (a string)
|
||||
/// \param right Right operand (a string)
|
||||
///
|
||||
/// \return Concatenated string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API String operator +(const String& left, const String& right);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_STRING_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::String
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
@ -1,290 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_UNICODE_HPP
|
||||
#define SFML_UNICODE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <iterator>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Provides utility functions to convert from and to
|
||||
/// any unicode and ASCII encoding
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Unicode
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Define a string type for each encoding
|
||||
/// Warning : in UTF8 and UTF16 strings, one element doesn't
|
||||
/// necessarily maps to one character ; only an UTF32 element
|
||||
/// is wide enough to hold all possible unicode values
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::basic_string<Uint8> UTF8String;
|
||||
typedef std::basic_string<Uint16> UTF16String;
|
||||
typedef std::basic_string<Uint32> UTF32String;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// This class is an abstract definition of a unicode text,
|
||||
/// it can be converted from and to any kind of string
|
||||
/// and encoding
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_API Text
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor (empty text)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Text();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the unicode text from any type of string
|
||||
///
|
||||
/// \param str : String to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Text(const char* str);
|
||||
Text(const wchar_t* str);
|
||||
Text(const Uint8* str);
|
||||
Text(const Uint16* str);
|
||||
Text(const Uint32* str);
|
||||
Text(const std::string& str);
|
||||
Text(const std::wstring& str);
|
||||
Text(const Unicode::UTF8String& str);
|
||||
Text(const Unicode::UTF16String& str);
|
||||
Text(const Unicode::UTF32String& str);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator to cast the text to any type of string
|
||||
///
|
||||
/// \return Converted string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
operator std::string () const;
|
||||
operator std::wstring () const;
|
||||
operator Unicode::UTF8String () const;
|
||||
operator Unicode::UTF16String () const;
|
||||
operator const Unicode::UTF32String&() const;
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Data member
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Unicode::UTF32String myUTF32String; ///< UTF-32 unicode text
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an ANSI characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
/// \param locale : Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF32ToANSI(In begin, In end, Out output, char replacement = '?', const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an ANSI characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale : Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ANSIToUTF32(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF8ToUTF16(In begin, In end, Out output, Uint16 replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF8ToUTF32(In begin, In end, Out output, Uint32 replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF16ToUTF8(In begin, In end, Out output, Uint8 replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF16ToUTF32(In begin, In end, Out output, Uint32 replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF32ToUTF8(In begin, In end, Out output, Uint8 replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
/// \param output : Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out UTF32ToUTF16(In begin, In end, Out output, Uint16 replacement = '?');
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-8 string
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Count of the characters in the string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t GetUTF8Length(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-16 string
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Count of the characters in the string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t GetUTF16Length(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-32 string
|
||||
///
|
||||
/// \param begin : Iterator pointing to the beginning of the input sequence
|
||||
/// \param end : Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Count of the characters in the string
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t GetUTF32Length(In begin, In end);
|
||||
|
||||
private :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the default system locale
|
||||
///
|
||||
/// \return Reference to the default system locale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static const std::locale& GetDefaultLocale();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const int UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence
|
||||
static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions
|
||||
static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences
|
||||
};
|
||||
|
||||
#include <SFML/System/Unicode.inl>
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_UNICODE_HPP
|
@ -1,474 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an ANSI characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF32ToANSI(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
||||
// MinGW has a almost no support for unicode stuff
|
||||
// As a consequence, the MinGW version of this function can only use the default locale
|
||||
// and ignores the one passed as parameter
|
||||
while (begin < end)
|
||||
{
|
||||
char character = 0;
|
||||
if (wctomb(&character, static_cast<wchar_t>(*begin++)) >= 0)
|
||||
*output++ = character;
|
||||
else if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
while (begin < end)
|
||||
*output++ = facet.narrow(static_cast<wchar_t>(*begin++), replacement);
|
||||
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an ANSI characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::ANSIToUTF32(In begin, In end, Out output, const std::locale& locale)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
||||
// MinGW has a almost no support for unicode stuff
|
||||
// As a consequence, the MinGW version of this function can only use the default locale
|
||||
// and ignores the one passed as parameter
|
||||
while (begin < end)
|
||||
{
|
||||
wchar_t character = 0;
|
||||
mbtowc(&character, &*begin, 1);
|
||||
begin++;
|
||||
*output++ = static_cast<Uint32>(character);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
while (begin < end)
|
||||
*output++ = static_cast<Uint32>(facet.widen(*begin++));
|
||||
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF8ToUTF16(In begin, In end, Out output, Uint16 replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 character = 0;
|
||||
int trailingBytes = UTF8TrailingBytes[static_cast<int>(*begin)];
|
||||
if (begin + trailingBytes < end)
|
||||
{
|
||||
// First decode the UTF-8 character
|
||||
switch (trailingBytes)
|
||||
{
|
||||
case 5 : character += *begin++; character <<= 6;
|
||||
case 4 : character += *begin++; character <<= 6;
|
||||
case 3 : character += *begin++; character <<= 6;
|
||||
case 2 : character += *begin++; character <<= 6;
|
||||
case 1 : character += *begin++; character <<= 6;
|
||||
case 0 : character += *begin++;
|
||||
}
|
||||
character -= UTF8Offsets[trailingBytes];
|
||||
|
||||
// Then encode it in UTF-16
|
||||
if (character < 0xFFFF)
|
||||
{
|
||||
// Character can be converted directly to 16 bits, just need to check it's in the valid range
|
||||
if ((character >= 0xD800) && (character <= 0xDFFF))
|
||||
{
|
||||
// Invalid character (this range is reserved)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to 16 bits
|
||||
*output++ = static_cast<Uint16>(character);
|
||||
}
|
||||
}
|
||||
else if (character > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Character will be converted to 2 UTF-16 elements
|
||||
character -= 0x0010000;
|
||||
*output++ = static_cast<Uint16>((character >> 10) + 0xD800);
|
||||
*output++ = static_cast<Uint16>((character & 0x3FFUL) + 0xDC00);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-8 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF8ToUTF32(In begin, In end, Out output, Uint32 replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 character = 0;
|
||||
int trailingBytes = UTF8TrailingBytes[static_cast<int>(*begin)];
|
||||
if (begin + trailingBytes < end)
|
||||
{
|
||||
// First decode the UTF-8 character
|
||||
switch (trailingBytes)
|
||||
{
|
||||
case 5 : character += *begin++; character <<= 6;
|
||||
case 4 : character += *begin++; character <<= 6;
|
||||
case 3 : character += *begin++; character <<= 6;
|
||||
case 2 : character += *begin++; character <<= 6;
|
||||
case 1 : character += *begin++; character <<= 6;
|
||||
case 0 : character += *begin++;
|
||||
}
|
||||
character -= UTF8Offsets[trailingBytes];
|
||||
|
||||
// Then write it if valid
|
||||
if ((character < 0xD800) || (character > 0xDFFF))
|
||||
{
|
||||
// Valid UTF-32 character
|
||||
*output++ = character;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid UTF-32 character
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF16ToUTF8(In begin, In end, Out output, Uint8 replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 character = *begin++;
|
||||
|
||||
// If it's a surrogate pair, first convert to a single UTF-32 character
|
||||
if ((character >= 0xD800) && (character <= 0xDBFF))
|
||||
{
|
||||
if (begin < end)
|
||||
{
|
||||
// The second element is valid : convert the two elements to a UTF-32 character
|
||||
Uint32 d = *begin++;
|
||||
if ((d >= 0xDC00) && (d <= 0xDFFF))
|
||||
character = static_cast<Uint32>(((character - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid second element
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
}
|
||||
|
||||
// Then convert to UTF-8
|
||||
if (character > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character
|
||||
|
||||
// Get number of bytes to write
|
||||
int bytesToWrite = 1;
|
||||
if (character < 0x80) bytesToWrite = 1;
|
||||
else if (character < 0x800) bytesToWrite = 2;
|
||||
else if (character < 0x10000) bytesToWrite = 3;
|
||||
else if (character <= 0x0010FFFF) bytesToWrite = 4;
|
||||
|
||||
// Extract bytes to write
|
||||
Uint8 bytes[4];
|
||||
switch (bytesToWrite)
|
||||
{
|
||||
case 4 : bytes[3] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
|
||||
case 3 : bytes[2] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
|
||||
case 2 : bytes[1] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
|
||||
case 1 : bytes[0] = static_cast<Uint8> (character | UTF8FirstBytes[bytesToWrite]);
|
||||
}
|
||||
|
||||
// Add them to the output
|
||||
const Uint8* currentByte = bytes;
|
||||
switch (bytesToWrite)
|
||||
{
|
||||
case 4 : *output++ = *currentByte++;
|
||||
case 3 : *output++ = *currentByte++;
|
||||
case 2 : *output++ = *currentByte++;
|
||||
case 1 : *output++ = *currentByte++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-16 characters range
|
||||
/// to an UTF-32 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF16ToUTF32(In begin, In end, Out output, Uint32 replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint16 character = *begin++;
|
||||
if ((character >= 0xD800) && (character <= 0xDBFF))
|
||||
{
|
||||
// We have a surrogate pair, ie. a character composed of two elements
|
||||
if (begin < end)
|
||||
{
|
||||
Uint16 d = *begin++;
|
||||
if ((d >= 0xDC00) && (d <= 0xDFFF))
|
||||
{
|
||||
// The second element is valid : convert the two elements to a UTF-32 character
|
||||
*output++ = static_cast<Uint32>(((character - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid second element
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((character >= 0xDC00) && (character <= 0xDFFF))
|
||||
{
|
||||
// Invalid character
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to UTF-32
|
||||
*output++ = static_cast<Uint32>(character);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-8 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF32ToUTF8(In begin, In end, Out output, Uint8 replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 character = *begin++;
|
||||
if (character > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character
|
||||
|
||||
// Get number of bytes to write
|
||||
int bytesToWrite = 1;
|
||||
if (character < 0x80) bytesToWrite = 1;
|
||||
else if (character < 0x800) bytesToWrite = 2;
|
||||
else if (character < 0x10000) bytesToWrite = 3;
|
||||
else if (character <= 0x0010FFFF) bytesToWrite = 4;
|
||||
|
||||
// Extract bytes to write
|
||||
Uint8 bytes[4];
|
||||
switch (bytesToWrite)
|
||||
{
|
||||
case 4 : bytes[3] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
|
||||
case 3 : bytes[2] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
|
||||
case 2 : bytes[1] = static_cast<Uint8>((character | 0x80) & 0xBF); character >>= 6;
|
||||
case 1 : bytes[0] = static_cast<Uint8> (character | UTF8FirstBytes[bytesToWrite]);
|
||||
}
|
||||
|
||||
// Add them to the output
|
||||
const Uint8* currentByte = bytes;
|
||||
switch (bytesToWrite)
|
||||
{
|
||||
case 4 : *output++ = *currentByte++;
|
||||
case 3 : *output++ = *currentByte++;
|
||||
case 2 : *output++ = *currentByte++;
|
||||
case 1 : *output++ = *currentByte++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Generic function to convert an UTF-32 characters range
|
||||
/// to an UTF-16 characters range, using the given locale
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
inline Out Unicode::UTF32ToUTF16(In begin, In end, Out output, Uint16 replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 character = *begin++;
|
||||
if (character < 0xFFFF)
|
||||
{
|
||||
// Character can be converted directly to 16 bits, just need to check it's in the valid range
|
||||
if ((character >= 0xD800) && (character <= 0xDFFF))
|
||||
{
|
||||
// Invalid character (this range is reserved)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to 16 bits
|
||||
*output++ = static_cast<Uint16>(character);
|
||||
}
|
||||
}
|
||||
else if (character > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Character will be converted to 2 UTF-16 elements
|
||||
character -= 0x0010000;
|
||||
*output++ = static_cast<Uint16>((character >> 10) + 0xD800);
|
||||
*output++ = static_cast<Uint16>((character & 0x3FFUL) + 0xDC00);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-8 string
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
inline std::size_t Unicode::GetUTF8Length(In begin, In end)
|
||||
{
|
||||
std::size_t length = 0;
|
||||
while (begin < end)
|
||||
{
|
||||
int nbBytes = UTF8TrailingBytes[static_cast<int>(*begin)];
|
||||
if (begin + nbBytes < end)
|
||||
++length;
|
||||
|
||||
begin += nbBytes + 1;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-16 string
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
inline std::size_t Unicode::GetUTF16Length(In begin, In end)
|
||||
{
|
||||
std::size_t length = 0;
|
||||
while (begin < end)
|
||||
{
|
||||
if ((*begin >= 0xD800) && (*begin <= 0xDBFF))
|
||||
{
|
||||
++begin;
|
||||
if ((begin < end) && ((*begin >= 0xDC00) && (*begin <= 0xDFFF)))
|
||||
{
|
||||
++length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++length;
|
||||
}
|
||||
|
||||
++begin;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of characters composing an UTF-32 string
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
inline std::size_t Unicode::GetUTF32Length(In begin, In end)
|
||||
{
|
||||
return end - begin;
|
||||
}
|
672
include/SFML/System/Utf.hpp
Normal file
672
include/SFML/System/Utf.hpp
Normal file
@ -0,0 +1,672 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_UTF_HPP
|
||||
#define SFML_UTF_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the default system locale
|
||||
///
|
||||
/// \return Reference to the default system locale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_API const std::locale& GetDefaultLocale();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility class providing generic functions for UTF conversions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <unsigned int N>
|
||||
class Utf;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialization of the Utf template for UTF-8
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
class Utf<8>
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single UTF-8 character
|
||||
///
|
||||
/// Decoding a character means finding its unique 32-bits
|
||||
/// code (called the codepoint) in the Unicode standard.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Codepoint of the decoded UTF-8 character
|
||||
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-8 character
|
||||
///
|
||||
/// Encoding a character means converting a unique 32-bits
|
||||
/// code (called the codepoint) in the target encoding, UTF-8.
|
||||
///
|
||||
/// \param input Codepoint to encode as UTF-8
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out Encode(Uint32 input, Out output, Uint8 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Advance to the next UTF-8 character
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In Next(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Count the number of characters of a UTF-8 sequence
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element, thus the
|
||||
/// total size can be different from (begin - end).
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t Count(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an ANSI characters range to UTF-8
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a wide characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-8 characters range to ANSI characters
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-8 characters range to wide characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-8 characters range to UTF-8
|
||||
///
|
||||
/// This functions does nothing more than a direct copy;
|
||||
/// it is defined only to provide the same interface as other
|
||||
/// specializations of the sf::Utf<> template, and allow
|
||||
/// generic code to be written on top of it.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf8(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-8 characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf16(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-8 characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf32(In begin, In end, Out output);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialization of the Utf template for UTF-16
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
class Utf<16>
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single UTF-16 character
|
||||
///
|
||||
/// Decoding a character means finding its unique 32-bits
|
||||
/// code (called the codepoint) in the Unicode standard.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Codepoint of the decoded UTF-16 character
|
||||
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-16 character
|
||||
///
|
||||
/// Encoding a character means converting a unique 32-bits
|
||||
/// code (called the codepoint) in the target encoding, UTF-16.
|
||||
///
|
||||
/// \param input Codepoint to encode as UTF-16
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out Encode(Uint32 input, Out output, Uint16 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Advance to the next UTF-16 character
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In Next(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Count the number of characters of a UTF-16 sequence
|
||||
///
|
||||
/// This function is necessary for multi-elements encodings, as
|
||||
/// a single character may use more than 1 storage element, thus the
|
||||
/// total size can be different from (begin - end).
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t Count(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an ANSI characters range to UTF-16
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a wide characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to ANSI characters
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to wide characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-16 characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf8(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-16 characters range to UTF-16
|
||||
///
|
||||
/// This functions does nothing more than a direct copy;
|
||||
/// it is defined only to provide the same interface as other
|
||||
/// specializations of the sf::Utf<> template, and allow
|
||||
/// generic code to be written on top of it.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf16(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-16 characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf32(In begin, In end, Out output);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialization of the Utf template for UTF-16
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
class Utf<32>
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single UTF-32 character
|
||||
///
|
||||
/// Decoding a character means finding its unique 32-bits
|
||||
/// code (called the codepoint) in the Unicode standard.
|
||||
/// For UTF-32, the character value is the same as the codepoint.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Codepoint of the decoded UTF-32 character
|
||||
/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-32 character
|
||||
///
|
||||
/// Encoding a character means converting a unique 32-bits
|
||||
/// code (called the codepoint) in the target encoding, UTF-32.
|
||||
/// For UTF-32, the codepoint is the same as the character value.
|
||||
///
|
||||
/// \param input Codepoint to encode as UTF-32
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out Encode(Uint32 input, Out output, Uint32 replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Advance to the next UTF-32 character
|
||||
///
|
||||
/// This function is trivial for UTF-32, which can store
|
||||
/// every character in a single storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static In Next(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Count the number of characters of a UTF-32 sequence
|
||||
///
|
||||
/// This function is trivial for UTF-32, which can store
|
||||
/// every character in a single storage element.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
///
|
||||
/// \return Iterator pointing to one past the last read element of the input sequence
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static std::size_t Count(In begin, In end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an ANSI characters range to UTF-32
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a wide characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-32 characters range to ANSI characters
|
||||
///
|
||||
/// The current global locale will be used by default, unless you
|
||||
/// pass a custom one in the \a locale parameter.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-32 characters range to wide characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-32 characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf8(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-32 characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf16(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-32 characters range to UTF-32
|
||||
///
|
||||
/// This functions does nothing more than a direct copy;
|
||||
/// it is defined only to provide the same interface as other
|
||||
/// specializations of the sf::Utf<> template, and allow
|
||||
/// generic code to be written on top of it.
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToUtf32(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single ANSI character to UTF-32
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param input Input ANSI character
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Converted character
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static Uint32 DecodeAnsi(In input, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decode a single wide character to UTF-32
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param input Input wide character
|
||||
///
|
||||
/// \return Converted character
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
static Uint32 DecodeWide(In input);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-32 character to ANSI
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param codepoint Iterator pointing to the beginning of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it)
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Encode a single UTF-32 character to wide
|
||||
///
|
||||
/// This function does not exist in other specializations
|
||||
/// of sf::Utf<>, it is defined for convenience (it is used by
|
||||
/// several other conversion functions).
|
||||
///
|
||||
/// \param codepoint Iterator pointing to the beginning of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0);
|
||||
};
|
||||
|
||||
#include <SFML/System/Utf.inl>
|
||||
|
||||
// Make typedefs to get rid of the template syntax
|
||||
typedef Utf<8> Utf8;
|
||||
typedef Utf<16> Utf16;
|
||||
typedef Utf<32> Utf32;
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_UTF_HPP
|
665
include/SFML/System/Utf.inl
Normal file
665
include/SFML/System/Utf.inl
Normal file
@ -0,0 +1,665 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
{
|
||||
// Some useful precomputed data
|
||||
static const int trailing[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
|
||||
};
|
||||
static const Uint32 offsets[6] =
|
||||
{
|
||||
0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
|
||||
};
|
||||
|
||||
// Decode the character
|
||||
int trailingBytes = trailing[static_cast<int>(*begin)];
|
||||
if (begin + trailingBytes < end)
|
||||
{
|
||||
output = 0;
|
||||
switch (trailingBytes)
|
||||
{
|
||||
case 5 : output += *begin++; output <<= 6;
|
||||
case 4 : output += *begin++; output <<= 6;
|
||||
case 3 : output += *begin++; output <<= 6;
|
||||
case 2 : output += *begin++; output <<= 6;
|
||||
case 1 : output += *begin++; output <<= 6;
|
||||
case 0 : output += *begin++;
|
||||
}
|
||||
output -= offsets[trailingBytes];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Incomplete character
|
||||
begin = end;
|
||||
output = replacement;
|
||||
}
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<8>::Encode(Uint32 input, Out output, Uint8 replacement)
|
||||
{
|
||||
// Some useful precomputed data
|
||||
static const Uint8 firstBytes[7] =
|
||||
{
|
||||
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
|
||||
};
|
||||
|
||||
// Encode the character
|
||||
if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF)))
|
||||
{
|
||||
// Invalid character
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character
|
||||
|
||||
// Get the number of bytes to write
|
||||
int bytesToWrite = 1;
|
||||
if (input < 0x80) bytesToWrite = 1;
|
||||
else if (input < 0x800) bytesToWrite = 2;
|
||||
else if (input < 0x10000) bytesToWrite = 3;
|
||||
else if (input <= 0x0010FFFF) bytesToWrite = 4;
|
||||
|
||||
// Extract the bytes to write
|
||||
Uint8 bytes[4];
|
||||
switch (bytesToWrite)
|
||||
{
|
||||
case 4 : bytes[3] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
|
||||
case 3 : bytes[2] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
|
||||
case 2 : bytes[1] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6;
|
||||
case 1 : bytes[0] = static_cast<Uint8> (input | firstBytes[bytesToWrite]);
|
||||
}
|
||||
|
||||
// Add them to the output
|
||||
const Uint8* currentByte = bytes;
|
||||
switch (bytesToWrite)
|
||||
{
|
||||
case 4 : *output++ = *currentByte++;
|
||||
case 3 : *output++ = *currentByte++;
|
||||
case 2 : *output++ = *currentByte++;
|
||||
case 1 : *output++ = *currentByte++;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<8>::Next(In begin, In end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
return Decode(begin, end, codepoint);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
std::size_t Utf<8>::Count(In begin, In end)
|
||||
{
|
||||
std::size_t length = 0;
|
||||
while (begin < end)
|
||||
{
|
||||
begin = Next(begin, end);
|
||||
++length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::FromAnsi(In begin, In end, Out output, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale);
|
||||
output = Encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::FromWide(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::DecodeWide(*begin++);
|
||||
output = Encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToWide(In begin, In end, Out output, wchar_t replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
output = Utf<32>::EncodeWide(codepoint, output, replacement);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToUtf8(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
*output++ = *begin++;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToUtf16(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
output = Utf<16>::Encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToUtf32(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
*output++ = codepoint;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<16>::Decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
{
|
||||
Uint16 first = *begin++;
|
||||
|
||||
// If it's a surrogate pair, first convert to a single UTF-32 character
|
||||
if ((first >= 0xD800) && (first <= 0xDBFF))
|
||||
{
|
||||
if (begin < end)
|
||||
{
|
||||
Uint32 second = *begin++;
|
||||
if ((second >= 0xDC00) && (second <= 0xDFFF))
|
||||
{
|
||||
// The second element is valid: convert the two elements to a UTF-32 character
|
||||
output = static_cast<Uint32>(((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid character
|
||||
output = replacement;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid character
|
||||
begin = end;
|
||||
output = replacement;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can make a direct copy
|
||||
output = first;
|
||||
}
|
||||
|
||||
return begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<16>::Encode(Uint32 input, Out output, Uint16 replacement)
|
||||
{
|
||||
if (input < 0xFFFF)
|
||||
{
|
||||
// The character can be copied directly, we just need to check if it's in the valid range
|
||||
if ((input >= 0xD800) && (input <= 0xDFFF))
|
||||
{
|
||||
// Invalid character (this range is reserved)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to a single UTF-16 character
|
||||
*output++ = static_cast<Uint16>(input);
|
||||
}
|
||||
}
|
||||
else if (input > 0x0010FFFF)
|
||||
{
|
||||
// Invalid character (greater than the maximum unicode value)
|
||||
if (replacement)
|
||||
*output++ = replacement;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The input character will be converted to two UTF-16 elements
|
||||
input -= 0x0010000;
|
||||
*output++ = static_cast<Uint16>((input >> 10) + 0xD800);
|
||||
*output++ = static_cast<Uint16>((input & 0x3FFUL) + 0xDC00);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<16>::Next(In begin, In end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
return Decode(begin, end, codepoint);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
std::size_t Utf<16>::Count(In begin, In end)
|
||||
{
|
||||
std::size_t length = 0;
|
||||
while (begin < end)
|
||||
{
|
||||
begin = Next(begin, end);
|
||||
++length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::FromAnsi(In begin, In end, Out output, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale);
|
||||
output = Encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::FromWide(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint = Utf<32>::DecodeWide(*begin++);
|
||||
output = Encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToWide(In begin, In end, Out output, wchar_t replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
output = Utf<32>::EncodeWide(codepoint, output, replacement);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToUtf8(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
output = Utf<8>::Encode(codepoint, output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToUtf16(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
*output++ = *begin++;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToUtf32(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
*output++ = codepoint;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<32>::Decode(In begin, In end, Uint32& output, Uint32)
|
||||
{
|
||||
output = *begin++;
|
||||
return begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<32>::Encode(Uint32 input, Out output, Uint32 replacement)
|
||||
{
|
||||
*output++ = input;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
In Utf<32>::Next(In begin, In end)
|
||||
{
|
||||
return ++begin;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
std::size_t Utf<32>::Count(In begin, In end)
|
||||
{
|
||||
return begin - end;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::FromAnsi(In begin, In end, Out output, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
*output++ = DecodeAnsi(*begin++, locale);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::FromWide(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
*output++ = DecodeWide(*begin++);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
while (begin < end)
|
||||
output = EncodeAnsi(*begin++, output, replacement, locale);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToWide(In begin, In end, Out output, wchar_t replacement)
|
||||
{
|
||||
while (begin < end)
|
||||
output = EncodeWide(*begin++, output, replacement);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToUtf8(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
output = Utf<8>::Encode(*begin++, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToUtf16(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
output = Utf<16>::Encode(*begin++, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToUtf32(In begin, In end, Out output)
|
||||
{
|
||||
while (begin < end)
|
||||
*output++ = *begin++;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
Uint32 Utf<32>::DecodeAnsi(In input, const std::locale& locale)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
||||
// MinGW has almost no support for unicode stuff
|
||||
// As a consequence, the MinGW version of this function can only use the default locale
|
||||
// and ignores the one passed as parameter
|
||||
|
||||
wchar_t character = 0;
|
||||
mbtowc(&character, &input, 1);
|
||||
return static_cast<Uint32>(character);
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
return static_cast<Uint32>(facet.widen(input));
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In>
|
||||
Uint32 Utf<32>::DecodeWide(In input)
|
||||
{
|
||||
// The encoding of wide characters is not well defined and is left to the system;
|
||||
// however we can safely assume that it is UCS-2 on Windows and
|
||||
// UCS-4 on Unix systems.
|
||||
// In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4,
|
||||
// and UCS-4 *is* UTF-32).
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<32>::EncodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
|
||||
// MinGW has almost no support for unicode stuff
|
||||
// As a consequence, the MinGW version of this function can only use the default locale
|
||||
// and ignores the one passed as parameter
|
||||
|
||||
char character = 0;
|
||||
if (wctomb(&character, static_cast<wchar_t>(codepoint)) >= 0)
|
||||
*output++ = character;
|
||||
else if (replacement)
|
||||
*output++ = replacement;
|
||||
|
||||
return output;
|
||||
|
||||
#else
|
||||
|
||||
// Get the facet of the locale which deals with character conversion
|
||||
const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale);
|
||||
|
||||
// Use the facet to convert each character of the input string
|
||||
*output++ = facet.narrow(static_cast<wchar_t>(codepoint), replacement);
|
||||
|
||||
return output;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<32>::EncodeWide(Uint32 codepoint, Out output, wchar_t replacement)
|
||||
{
|
||||
// The encoding of wide characters is not well defined and is left to the system;
|
||||
// however we can safely assume that it is UCS-2 on Windows and
|
||||
// UCS-4 on Unix systems.
|
||||
// For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4).
|
||||
// For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32).
|
||||
|
||||
switch (sizeof(wchar_t))
|
||||
{
|
||||
case 4:
|
||||
{
|
||||
*output++ = static_cast<wchar_t>(codepoint);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF)))
|
||||
{
|
||||
*output++ = static_cast<wchar_t>(codepoint);
|
||||
}
|
||||
else if (replacement)
|
||||
{
|
||||
*output++ = replacement;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
@ -141,10 +141,11 @@ int main()
|
||||
glEnd();
|
||||
|
||||
// Draw some text on top of our OpenGL object
|
||||
sf::String text("SFML / OpenGL demo");
|
||||
sf::Text text("SFML / OpenGL demo");
|
||||
text.SetPosition(250.f, 450.f);
|
||||
text.SetColor(sf::Color(255, 255, 255, 170));
|
||||
window.Draw(text);
|
||||
std::wstring s = text.GetString();
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
window.Display();
|
||||
|
@ -45,7 +45,7 @@ int main()
|
||||
return EXIT_FAILURE;
|
||||
|
||||
// Initialize the end text
|
||||
sf::String end;
|
||||
sf::Text end;
|
||||
end.SetFont(font);
|
||||
end.SetSize(60.f);
|
||||
end.Move(150.f, 200.f);
|
||||
@ -125,12 +125,12 @@ int main()
|
||||
if (ball.GetPosition().x < 0.f)
|
||||
{
|
||||
isPlaying = false;
|
||||
end.SetText("You lost !\n(press escape to exit)");
|
||||
end.SetString("You lost !\n(press escape to exit)");
|
||||
}
|
||||
if (ball.GetPosition().x + ball.GetSize().x > window.GetView().GetSize().x)
|
||||
{
|
||||
isPlaying = false;
|
||||
end.SetText("You won !\n(press escape to exit)");
|
||||
end.SetString("You won !\n(press escape to exit)");
|
||||
}
|
||||
if (ball.GetPosition().y < 0.f)
|
||||
{
|
||||
|
@ -142,22 +142,22 @@ int main()
|
||||
shaders["pixelate"].SetTexture("texture", sf::Shader::CurrentTexture);
|
||||
|
||||
// Define a string for displaying the description of the current shader
|
||||
sf::String shaderStr;
|
||||
sf::Text shaderStr;
|
||||
shaderStr.SetFont(font);
|
||||
shaderStr.SetSize(20);
|
||||
shaderStr.SetPosition(5.f, 0.f);
|
||||
shaderStr.SetColor(sf::Color(250, 100, 30));
|
||||
shaderStr.SetText("Background shader: \"" + backgroundShader.GetName() + "\"\n"
|
||||
shaderStr.SetString("Background shader: \"" + backgroundShader.GetName() + "\"\n"
|
||||
"Flower shader: \"" + entityShader.GetName() + "\"\n"
|
||||
"Global shader: \"" + globalShader.GetName() + "\"\n");
|
||||
|
||||
// Define a string for displaying help
|
||||
sf::String infoStr;
|
||||
sf::Text infoStr;
|
||||
infoStr.SetFont(font);
|
||||
infoStr.SetSize(20);
|
||||
infoStr.SetPosition(5.f, 510.f);
|
||||
infoStr.SetColor(sf::Color(250, 100, 30));
|
||||
infoStr.SetText("Move your mouse to change the shaders' parameters\n"
|
||||
infoStr.SetString("Move your mouse to change the shaders' parameters\n"
|
||||
"Press numpad 1/4 to change the background shader\n"
|
||||
"Press numpad 2/5 to change the flower shader\n"
|
||||
"Press numpad 3/6 to change the global shader");
|
||||
@ -195,7 +195,7 @@ int main()
|
||||
}
|
||||
|
||||
// Update the text
|
||||
shaderStr.SetText("Background shader: \"" + backgroundShader.GetName() + "\"\n"
|
||||
shaderStr.SetString("Background shader: \"" + backgroundShader.GetName() + "\"\n"
|
||||
"Entity shader: \"" + entityShader.GetName() + "\"\n"
|
||||
"Global shader: \"" + globalShader.GetName() + "\"\n");
|
||||
}
|
||||
@ -249,7 +249,7 @@ void DisplayError()
|
||||
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
|
||||
|
||||
// Define a string for displaying the error message
|
||||
sf::String error("Sorry, your system doesn't support shaders");
|
||||
sf::Text error("Sorry, your system doesn't support shaders");
|
||||
error.SetPosition(100.f, 250.f);
|
||||
error.SetColor(sf::Color(200, 100, 150));
|
||||
|
||||
|
@ -71,26 +71,25 @@ myCharSize(0)
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load the font from a file
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Font::LoadFromFile(const std::string& filename, unsigned int charSize, const Unicode::Text& charset)
|
||||
bool Font::LoadFromFile(const std::string& filename, unsigned int charSize, String charset)
|
||||
{
|
||||
// Clear the previous character map
|
||||
myGlyphs.clear();
|
||||
|
||||
// Always add these special characters
|
||||
Unicode::UTF32String UTFCharset = charset;
|
||||
if (UTFCharset.find(L' ') != Unicode::UTF32String::npos) UTFCharset += L' ';
|
||||
if (UTFCharset.find(L'\n') != Unicode::UTF32String::npos) UTFCharset += L'\n';
|
||||
if (UTFCharset.find(L'\v') != Unicode::UTF32String::npos) UTFCharset += L'\v';
|
||||
if (UTFCharset.find(L'\t') != Unicode::UTF32String::npos) UTFCharset += L'\t';
|
||||
if (std::find(charset.Begin(), charset.End(), L' ') == charset.End()) charset += L' ';
|
||||
if (std::find(charset.Begin(), charset.End(), L'\n') == charset.End()) charset += L'\n';
|
||||
if (std::find(charset.Begin(), charset.End(), L'\v') == charset.End()) charset += L'\v';
|
||||
if (std::find(charset.Begin(), charset.End(), L'\t') == charset.End()) charset += L'\t';
|
||||
|
||||
return priv::FontLoader::GetInstance().LoadFontFromFile(filename, charSize, UTFCharset, *this);
|
||||
return priv::FontLoader::GetInstance().LoadFontFromFile(filename, charSize, charset, *this);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load the font from a file in memory
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Font::LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::Text& charset)
|
||||
bool Font::LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, String charset)
|
||||
{
|
||||
// Clear the previous character map
|
||||
myGlyphs.clear();
|
||||
@ -103,13 +102,12 @@ bool Font::LoadFromMemory(const char* data, std::size_t sizeInBytes, unsigned in
|
||||
}
|
||||
|
||||
// Always add these special characters
|
||||
Unicode::UTF32String UTFCharset = charset;
|
||||
if (UTFCharset.find(L' ') != Unicode::UTF32String::npos) UTFCharset += L' ';
|
||||
if (UTFCharset.find(L'\n') != Unicode::UTF32String::npos) UTFCharset += L'\n';
|
||||
if (UTFCharset.find(L'\v') != Unicode::UTF32String::npos) UTFCharset += L'\v';
|
||||
if (UTFCharset.find(L'\t') != Unicode::UTF32String::npos) UTFCharset += L'\t';
|
||||
if (std::find(charset.Begin(), charset.End(), L' ') == charset.End()) charset += L' ';
|
||||
if (std::find(charset.Begin(), charset.End(), L'\n') == charset.End()) charset += L'\n';
|
||||
if (std::find(charset.Begin(), charset.End(), L'\v') == charset.End()) charset += L'\v';
|
||||
if (std::find(charset.Begin(), charset.End(), L'\t') == charset.End()) charset += L'\t';
|
||||
|
||||
return priv::FontLoader::GetInstance().LoadFontFromMemory(data, sizeInBytes, charSize, UTFCharset, *this);
|
||||
return priv::FontLoader::GetInstance().LoadFontFromMemory(data, sizeInBytes, charSize, charset, *this);
|
||||
}
|
||||
|
||||
|
||||
@ -158,21 +156,22 @@ const Image& Font::GetImage() const
|
||||
////////////////////////////////////////////////////////////
|
||||
const Font& Font::GetDefaultFont()
|
||||
{
|
||||
static Font defaultFont;
|
||||
static bool defaultFontLoaded = false;
|
||||
static const char defaultFontData[] =
|
||||
static Font font;
|
||||
static bool loaded = false;
|
||||
|
||||
// Load the default font on first call
|
||||
if (!loaded)
|
||||
{
|
||||
static const char data[] =
|
||||
{
|
||||
#include <SFML/Graphics/Arial.hpp>
|
||||
};
|
||||
|
||||
// Load the default font on first call
|
||||
if (!defaultFontLoaded)
|
||||
{
|
||||
defaultFont.LoadFromMemory(defaultFontData, sizeof(defaultFontData), 30);
|
||||
defaultFontLoaded = true;
|
||||
font.LoadFromMemory(data, sizeof(data), 30);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
return defaultFont;
|
||||
return font;
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
@ -98,7 +98,7 @@ FontLoader::~FontLoader()
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load a font from a file
|
||||
////////////////////////////////////////////////////////////
|
||||
bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const Unicode::UTF32String& charset, Font& font)
|
||||
bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const String& charset, Font& font)
|
||||
{
|
||||
// Check if Freetype is correctly initialized
|
||||
if (!myLibrary)
|
||||
@ -131,7 +131,7 @@ bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int char
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load the font from a file in memory
|
||||
////////////////////////////////////////////////////////////
|
||||
bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::UTF32String& charset, Font& font)
|
||||
bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const String& charset, Font& font)
|
||||
{
|
||||
// Check if Freetype is correctly initialized
|
||||
if (!myLibrary)
|
||||
@ -164,12 +164,12 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a bitmap font from a font face and a characters set
|
||||
////////////////////////////////////////////////////////////
|
||||
FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const Unicode::UTF32String& charset, Font& font)
|
||||
FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const String& charset, Font& font)
|
||||
{
|
||||
// Let's find how many characters to put in each row to make them fit into a squared texture
|
||||
GLint maxSize;
|
||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
|
||||
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.length())) * 0.75);
|
||||
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
||||
|
||||
// Clamp the character size to make sure we won't create a texture too big
|
||||
if (nbChars * charSize >= static_cast<unsigned int>(maxSize))
|
||||
@ -198,7 +198,7 @@ FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const
|
||||
// Render all glyphs and sort them by size to optimize texture space
|
||||
typedef std::multimap<FT_BitmapGlyph, Uint32, SizeCompare> GlyphTable;
|
||||
GlyphTable glyphs;
|
||||
for (std::size_t i = 0; i < charset.length(); ++i)
|
||||
for (std::size_t i = 0; i < charset.GetSize(); ++i)
|
||||
{
|
||||
// Load the glyph corresponding to the current character
|
||||
error = FT_Load_Char(face, charset[i], FT_LOAD_TARGET_NORMAL);
|
||||
@ -293,7 +293,7 @@ FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const
|
||||
font.myTexture.LoadFromPixels(texWidth, texHeight, &glyphsBuffer[0]);
|
||||
|
||||
// Now that the texture is created, we can precompute texture coordinates
|
||||
for (std::size_t i = 0; i < charset.size(); ++i)
|
||||
for (std::size_t i = 0; i < charset.GetSize(); ++i)
|
||||
{
|
||||
Uint32 curChar = charset[i];
|
||||
font.myGlyphs[curChar].TexCoords = font.myTexture.GetTexCoords(coords[curChar]);
|
||||
@ -491,7 +491,7 @@ FontLoader::~FontLoader()
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load a font from a file
|
||||
////////////////////////////////////////////////////////////
|
||||
bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const Unicode::UTF32String& charset, Font& font)
|
||||
bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int charSize, const String& charset, Font& font)
|
||||
{
|
||||
// Get the contents of the font file
|
||||
std::ifstream file(filename.c_str(), std::ios_base::binary);
|
||||
@ -511,12 +511,12 @@ bool FontLoader::LoadFontFromFile(const std::string& filename, unsigned int char
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load the font from a file in memory
|
||||
////////////////////////////////////////////////////////////
|
||||
bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::UTF32String& charset, Font& font)
|
||||
bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const String& charset, Font& font)
|
||||
{
|
||||
// Let's find how many characters to put in each row to make them fit into a squared texture
|
||||
GLint maxSize;
|
||||
GLCheck(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
|
||||
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.length())) * 0.75);
|
||||
int nbChars = static_cast<int>(sqrt(static_cast<double>(charset.GetSize())) * 0.75);
|
||||
|
||||
// Clamp the character size to make sure we won't create a texture too big
|
||||
if (nbChars * charSize >= static_cast<unsigned int>(maxSize))
|
||||
@ -544,7 +544,7 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
|
||||
// Render all glyphs and sort them by size to optimize texture space
|
||||
typedef std::multimap<Glyph, Uint32, SizeCompare> GlyphTable;
|
||||
GlyphTable glyphs;
|
||||
for (std::size_t i = 0; i < charset.length(); ++i)
|
||||
for (std::size_t i = 0; i < charset.GetSize(); ++i)
|
||||
{
|
||||
// Load the glyph corresponding to the current character
|
||||
int index = stbtt_FindGlyphIndex(&info, static_cast<int>(charset[i]));
|
||||
@ -636,7 +636,7 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
|
||||
font.myTexture.LoadFromPixels(texWidth, texHeight, &glyphsBuffer[0]);
|
||||
|
||||
// Now that the texture is created, we can precompute texture coordinates
|
||||
for (std::size_t i = 0; i < charset.size(); ++i)
|
||||
for (std::size_t i = 0; i < charset.GetSize(); ++i)
|
||||
{
|
||||
Uint32 curChar = charset[i];
|
||||
font.myGlyphs[curChar].TexCoords = font.myTexture.GetTexCoords(coords[curChar]);
|
||||
@ -652,7 +652,7 @@ bool FontLoader::LoadFontFromMemory(const char* data, std::size_t sizeInBytes, u
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a bitmap font from a font face and a characters set
|
||||
////////////////////////////////////////////////////////////
|
||||
FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const Unicode::UTF32String& charset, Font& font)
|
||||
FT_Error FontLoader::CreateBitmapFont(FT_Face face, unsigned int charSize, const String& charset, Font& font)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/System/Unicode.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include <string>
|
||||
@ -67,7 +67,7 @@ public :
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool LoadFontFromFile(const std::string& filename, unsigned int charSize, const Unicode::UTF32String& charset, Font& font);
|
||||
bool LoadFontFromFile(const std::string& filename, unsigned int charSize, const String& charset, Font& font);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Load the font from a file in memory
|
||||
@ -81,7 +81,7 @@ public :
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const Unicode::UTF32String& charset, Font& font);
|
||||
bool LoadFontFromMemory(const char* data, std::size_t sizeInBytes, unsigned int charSize, const String& charset, Font& font);
|
||||
|
||||
private :
|
||||
|
||||
@ -106,7 +106,7 @@ private :
|
||||
/// \param font : Font object to fill up
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FT_Error CreateBitmapFont(FT_Face face, unsigned int charSize, const Unicode::UTF32String& charset, Font& font);
|
||||
FT_Error CreateBitmapFont(FT_Face face, unsigned int charSize, const String& charset, Font& font);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a description from a FT error code
|
||||
|
@ -25,7 +25,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/RenderQueue.hpp>
|
||||
|
||||
@ -35,7 +35,7 @@ namespace sf
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String() :
|
||||
Text::Text() :
|
||||
myFont (&Font::GetDefaultFont()),
|
||||
mySize (30.f),
|
||||
myStyle (Regular),
|
||||
@ -48,30 +48,30 @@ myNeedRectUpdate(true)
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the string from any kind of text
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const Unicode::Text& text, const Font& font, float size) :
|
||||
Text::Text(const String& string, const Font& font, float size) :
|
||||
myFont (&font),
|
||||
mySize (size),
|
||||
myStyle (Regular),
|
||||
myNeedRectUpdate(true)
|
||||
{
|
||||
SetText(text);
|
||||
SetString(string);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text (from any kind of string)
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::SetText(const Unicode::Text& text)
|
||||
void Text::SetString(const String& string)
|
||||
{
|
||||
myNeedRectUpdate = true;
|
||||
myText = text;
|
||||
myString = string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the font of the string
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::SetFont(const Font& font)
|
||||
void Text::SetFont(const Font& font)
|
||||
{
|
||||
if (myFont != &font)
|
||||
{
|
||||
@ -84,7 +84,7 @@ void String::SetFont(const Font& font)
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the size of the string
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::SetSize(float size)
|
||||
void Text::SetSize(float size)
|
||||
{
|
||||
if (mySize != size)
|
||||
{
|
||||
@ -98,7 +98,7 @@ void String::SetSize(float size)
|
||||
/// Set the style of the text
|
||||
/// The default style is Regular
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::SetStyle(unsigned long style)
|
||||
void Text::SetStyle(unsigned long style)
|
||||
{
|
||||
if (myStyle != style)
|
||||
{
|
||||
@ -111,16 +111,16 @@ void String::SetStyle(unsigned long style)
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the text (the returned text can be converted implicitely to any kind of string)
|
||||
////////////////////////////////////////////////////////////
|
||||
const Unicode::Text& String::GetText() const
|
||||
const String& Text::GetString() const
|
||||
{
|
||||
return myText;
|
||||
return myString;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the font used by the string
|
||||
////////////////////////////////////////////////////////////
|
||||
const Font& String::GetFont() const
|
||||
const Font& Text::GetFont() const
|
||||
{
|
||||
return *myFont;
|
||||
}
|
||||
@ -129,7 +129,7 @@ const Font& String::GetFont() const
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the size of the characters
|
||||
////////////////////////////////////////////////////////////
|
||||
float String::GetSize() const
|
||||
float Text::GetSize() const
|
||||
{
|
||||
return mySize;
|
||||
}
|
||||
@ -138,7 +138,7 @@ float String::GetSize() const
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the style of the text
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned long String::GetStyle() const
|
||||
unsigned long Text::GetStyle() const
|
||||
{
|
||||
return myStyle;
|
||||
}
|
||||
@ -149,14 +149,11 @@ unsigned long String::GetStyle() const
|
||||
/// in coordinates relative to the string
|
||||
/// (note : translation, center, rotation and scale are not applied)
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Vector2f String::GetCharacterPos(std::size_t index) const
|
||||
sf::Vector2f Text::GetCharacterPos(std::size_t index) const
|
||||
{
|
||||
// First get the UTF32 representation of the text
|
||||
const Unicode::UTF32String& text = myText;
|
||||
|
||||
// Adjust the index if it's out of range
|
||||
if (index > text.length())
|
||||
index = text.length();
|
||||
if (index > myString.GetSize())
|
||||
index = myString.GetSize();
|
||||
|
||||
// The final size is based on the text size
|
||||
float factor = mySize / myFont->GetCharacterSize();
|
||||
@ -167,7 +164,7 @@ sf::Vector2f String::GetCharacterPos(std::size_t index) const
|
||||
for (std::size_t i = 0; i < index; ++i)
|
||||
{
|
||||
// Get the current character and its corresponding glyph
|
||||
Uint32 curChar = text[i];
|
||||
Uint32 curChar = myString[i];
|
||||
const Glyph& curGlyph = myFont->GetGlyph(curChar);
|
||||
float advanceX = curGlyph.Advance * factor;
|
||||
|
||||
@ -191,10 +188,10 @@ sf::Vector2f String::GetCharacterPos(std::size_t index) const
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the string rectangle on screen
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect String::GetRect() const
|
||||
FloatRect Text::GetRect() const
|
||||
{
|
||||
if (myNeedRectUpdate)
|
||||
const_cast<String*>(this)->RecomputeRect();
|
||||
const_cast<Text*>(this)->RecomputeRect();
|
||||
|
||||
FloatRect rect;
|
||||
rect.Left = (myBaseRect.Left - GetOrigin().x) * GetScale().x + GetPosition().x;
|
||||
@ -209,13 +206,10 @@ FloatRect String::GetRect() const
|
||||
////////////////////////////////////////////////////////////
|
||||
/// /see sfDrawable::Render
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::Render(RenderTarget&, RenderQueue& queue) const
|
||||
void Text::Render(RenderTarget&, RenderQueue& queue) const
|
||||
{
|
||||
// First get the internal UTF-32 string of the text
|
||||
const Unicode::UTF32String& text = myText;
|
||||
|
||||
// No text, no rendering :)
|
||||
if (text.empty())
|
||||
if (myString.IsEmpty())
|
||||
return;
|
||||
|
||||
// Set the scaling factor to get the actual size
|
||||
@ -239,10 +233,10 @@ void String::Render(RenderTarget&, RenderQueue& queue) const
|
||||
// Draw one quad for each character
|
||||
unsigned int index = 0;
|
||||
queue.BeginBatch();
|
||||
for (std::size_t i = 0; i < text.size(); ++i)
|
||||
for (std::size_t i = 0; i < myString.GetSize(); ++i)
|
||||
{
|
||||
// Get the current character and its corresponding glyph
|
||||
Uint32 curChar = text[i];
|
||||
Uint32 curChar = myString[i];
|
||||
const Glyph& curGlyph = myFont->GetGlyph(curChar);
|
||||
int advance = curGlyph.Advance;
|
||||
const IntRect& rect = curGlyph.Rectangle;
|
||||
@ -294,10 +288,10 @@ void String::Render(RenderTarget&, RenderQueue& queue) const
|
||||
y = charSize;
|
||||
|
||||
queue.BeginBatch();
|
||||
for (std::size_t i = 0; i < text.size(); ++i)
|
||||
for (std::size_t i = 0; i < myString.GetSize(); ++i)
|
||||
{
|
||||
// Get the current character and its corresponding glyph
|
||||
Uint32 curChar = text[i];
|
||||
Uint32 curChar = myString[i];
|
||||
const Glyph& curGlyph = myFont->GetGlyph(curChar);
|
||||
int advance = curGlyph.Advance;
|
||||
const IntRect& rect = curGlyph.Rectangle;
|
||||
@ -360,16 +354,13 @@ void String::Render(RenderTarget&, RenderQueue& queue) const
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Recompute the bounding rectangle of the text
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::RecomputeRect()
|
||||
void Text::RecomputeRect()
|
||||
{
|
||||
// First get the internal UTF-32 string of the text
|
||||
const Unicode::UTF32String& text = myText;
|
||||
|
||||
// Reset the "need update" state
|
||||
myNeedRectUpdate = false;
|
||||
|
||||
// No text, empty box :)
|
||||
if (text.empty())
|
||||
if (myString.IsEmpty())
|
||||
{
|
||||
myBaseRect = FloatRect(0, 0, 0, 0);
|
||||
return;
|
||||
@ -383,10 +374,10 @@ void String::RecomputeRect()
|
||||
float factor = mySize / myFont->GetCharacterSize();
|
||||
|
||||
// Go through each character
|
||||
for (std::size_t i = 0; i < text.size(); ++i)
|
||||
for (std::size_t i = 0; i < myString.GetSize(); ++i)
|
||||
{
|
||||
// Get the current character and its corresponding glyph
|
||||
Uint32 curChar = text[i];
|
||||
Uint32 curChar = myString[i];
|
||||
const Glyph& curGlyph = myFont->GetGlyph(curChar);
|
||||
float advance = curGlyph.Advance * factor;
|
||||
const IntRect& rect = curGlyph.Rectangle;
|
387
src/SFML/System/String.cpp
Normal file
387
src/SFML/System/String.cpp
Normal file
@ -0,0 +1,387 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <iterator>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const char* ansiString)
|
||||
{
|
||||
if (ansiString)
|
||||
{
|
||||
std::size_t length = strlen(ansiString);
|
||||
if (length > 0)
|
||||
{
|
||||
myString.reserve(length + 1);
|
||||
Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(myString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const std::string& ansiString)
|
||||
{
|
||||
myString.reserve(ansiString.length() + 1);
|
||||
Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(myString));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const char* ansiString, const std::locale& locale)
|
||||
{
|
||||
if (ansiString)
|
||||
{
|
||||
std::size_t length = strlen(ansiString);
|
||||
if (length > 0)
|
||||
{
|
||||
myString.reserve(length + 1);
|
||||
Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(myString), locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const std::string& ansiString, const std::locale& locale)
|
||||
{
|
||||
myString.reserve(ansiString.length() + 1);
|
||||
Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(myString), locale);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const wchar_t* wideString)
|
||||
{
|
||||
if (wideString)
|
||||
{
|
||||
std::size_t length = wcslen(wideString);
|
||||
if (length > 0)
|
||||
{
|
||||
myString.reserve(length + 1);
|
||||
Utf32::FromWide(wideString, wideString + length, std::back_inserter(myString));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const std::wstring& wideString)
|
||||
{
|
||||
myString.reserve(wideString.length() + 1);
|
||||
Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(myString));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const Uint32* utf32String)
|
||||
{
|
||||
if (utf32String)
|
||||
myString = utf32String;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const std::basic_string<Uint32>& utf32String) :
|
||||
myString(utf32String)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::String(const String& copy) :
|
||||
myString(copy.myString)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::operator std::string() const
|
||||
{
|
||||
return ToAnsiString();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::operator std::wstring() const
|
||||
{
|
||||
return ToWideString();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string String::ToAnsiString() const
|
||||
{
|
||||
// Prepare the output string
|
||||
std::string output;
|
||||
output.reserve(myString.length() + 1);
|
||||
|
||||
// Convert
|
||||
Utf32::ToAnsi(myString.begin(), myString.end(), std::back_inserter(output), 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::string String::ToAnsiString(const std::locale& locale) const
|
||||
{
|
||||
// Prepare the output string
|
||||
std::string output;
|
||||
output.reserve(myString.length() + 1);
|
||||
|
||||
// Convert
|
||||
Utf32::ToAnsi(myString.begin(), myString.end(), std::back_inserter(output), 0, locale);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::wstring String::ToWideString() const
|
||||
{
|
||||
// Prepare the output string
|
||||
std::wstring output;
|
||||
output.reserve(myString.length() + 1);
|
||||
|
||||
// Convert
|
||||
Utf32::ToWide(myString.begin(), myString.end(), std::back_inserter(output), 0);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String& String::operator =(const String& right)
|
||||
{
|
||||
myString = right.myString;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String& String::operator +=(char right)
|
||||
{
|
||||
myString += Utf32::DecodeAnsi(right);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String& String::operator +=(wchar_t right)
|
||||
{
|
||||
myString += Utf32::DecodeWide(right);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String& String::operator +=(Uint32 right)
|
||||
{
|
||||
myString += right;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String& String::operator +=(const String& right)
|
||||
{
|
||||
myString += right.myString;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 String::operator [](std::size_t index) const
|
||||
{
|
||||
return myString[index];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32& String::operator [](std::size_t index)
|
||||
{
|
||||
return myString[index];
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::Clear()
|
||||
{
|
||||
myString.clear();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t String::GetSize() const
|
||||
{
|
||||
return myString.size();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool String::IsEmpty() const
|
||||
{
|
||||
return myString.empty();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void String::Erase(std::size_t position, std::size_t count)
|
||||
{
|
||||
myString.erase(position, count);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Uint32* String::GetData() const
|
||||
{
|
||||
return myString.c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::Iterator String::Begin()
|
||||
{
|
||||
return myString.begin();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::ConstIterator String::Begin() const
|
||||
{
|
||||
return myString.begin();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::Iterator String::End()
|
||||
{
|
||||
return myString.end();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String::ConstIterator String::End() const
|
||||
{
|
||||
return myString.end();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator ==(const String& left, const String& right)
|
||||
{
|
||||
return left.myString == right.myString;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator !=(const String& left, const String& right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator <(const String& left, const String& right)
|
||||
{
|
||||
return left.myString < right.myString;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator >(const String& left, const String& right)
|
||||
{
|
||||
return right < left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator <=(const String& left, const String& right)
|
||||
{
|
||||
return !(right < left);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator >=(const String& left, const String& right)
|
||||
{
|
||||
return !(left < right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String operator +(const String& left, char right)
|
||||
{
|
||||
String string = left;
|
||||
string += right;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String operator +(const String& left, wchar_t right)
|
||||
{
|
||||
String string = left;
|
||||
string += right;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String operator +(const String& left, Uint32 right)
|
||||
{
|
||||
String string = left;
|
||||
string += right;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String operator +(const String& left, const String& right)
|
||||
{
|
||||
String string = left;
|
||||
string += right;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
} // namespace sf
|
@ -1,300 +0,0 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Unicode.hpp>
|
||||
#include <stdexcept>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// References :
|
||||
//
|
||||
// http://www.unicode.org/
|
||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
|
||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
|
||||
// http://people.w3.org/rishida/scripts/uniview/conversion
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
namespace
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
// Generic utility function to compute the number
|
||||
// of characters in a null-terminated string of any type
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
std::size_t StrLen(const T* Str)
|
||||
{
|
||||
std::size_t Length = 0;
|
||||
while (*Str++) Length++;
|
||||
return Length;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Get the current system locale
|
||||
////////////////////////////////////////////////////////////
|
||||
std::locale GetCurrentLocale()
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::locale("");
|
||||
}
|
||||
catch (std::runtime_error&)
|
||||
{
|
||||
// It seems some implementations don't know the "" locale
|
||||
// (Mac OS, MinGW)
|
||||
|
||||
return std::locale();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
const int Unicode::UTF8TrailingBytes[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5
|
||||
};
|
||||
const Uint32 Unicode::UTF8Offsets[6] =
|
||||
{
|
||||
0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080
|
||||
};
|
||||
const Uint8 Unicode::UTF8FirstBytes[7] =
|
||||
{
|
||||
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Default constructor (empty text)
|
||||
////////////////////////////////////////////////////////////
|
||||
Unicode::Text::Text()
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct the unicode text from any type of string
|
||||
////////////////////////////////////////////////////////////
|
||||
Unicode::Text::Text(const char* Str)
|
||||
{
|
||||
if (Str)
|
||||
{
|
||||
std::size_t Length = StrLen(Str);
|
||||
if (Length > 0)
|
||||
{
|
||||
myUTF32String.reserve(Length + 1);
|
||||
Unicode::ANSIToUTF32(Str, Str + Length, std::back_inserter(myUTF32String));
|
||||
}
|
||||
}
|
||||
}
|
||||
Unicode::Text::Text(const wchar_t* Str)
|
||||
{
|
||||
if (Str)
|
||||
{
|
||||
std::size_t Length = StrLen(Str);
|
||||
if (Length > 0)
|
||||
{
|
||||
// See comments below, in Unicode::Text::Text(const std::wstring&)
|
||||
myUTF32String.reserve(Length + 1);
|
||||
switch (sizeof(wchar_t))
|
||||
{
|
||||
case 2 : Unicode::UTF16ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0); break;
|
||||
case 4 : std::copy(Str, Str + Length, std::back_inserter(myUTF32String)); break;
|
||||
default : break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Unicode::Text::Text(const Uint8* Str)
|
||||
{
|
||||
if (Str)
|
||||
{
|
||||
std::size_t Length = StrLen(Str);
|
||||
if (Length > 0)
|
||||
{
|
||||
myUTF32String.reserve(Length + 1);
|
||||
Unicode::UTF8ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Unicode::Text::Text(const Uint16* Str)
|
||||
{
|
||||
if (Str)
|
||||
{
|
||||
std::size_t Length = StrLen(Str);
|
||||
if (Length > 0)
|
||||
{
|
||||
myUTF32String.reserve(Length+ 1);
|
||||
Unicode::UTF16ToUTF32(Str, Str + Length, std::back_inserter(myUTF32String), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Unicode::Text::Text(const Uint32* Str)
|
||||
{
|
||||
if (Str)
|
||||
myUTF32String = Str;
|
||||
}
|
||||
Unicode::Text::Text(const std::string& Str)
|
||||
{
|
||||
myUTF32String.reserve(Str.length() + 1);
|
||||
Unicode::ANSIToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String));
|
||||
}
|
||||
Unicode::Text::Text(const std::wstring& Str)
|
||||
{
|
||||
// This function assumes that 2-byte large wchar_t are encoded in UTF-16 (Windows), and
|
||||
// 4-byte large wchar_t are encoded using UTF-32 (Unix)
|
||||
// Is that always true ? (some platforms may use JIS Japanese encoding)
|
||||
// The macro __STDC_ISO_10646__ should help identifying UTF-32 compliant implementations
|
||||
|
||||
myUTF32String.reserve(Str.length() + 1);
|
||||
|
||||
// Select the proper function according to the (supposed) wchar_t system encoding
|
||||
switch (sizeof(wchar_t))
|
||||
{
|
||||
// wchar_t uses UTF-16 -- need a conversion
|
||||
case 2 :
|
||||
{
|
||||
Unicode::UTF16ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
// wchar_t uses UTF-32 -- direct copy
|
||||
case 4 :
|
||||
{
|
||||
std::copy(Str.begin(), Str.end(), std::back_inserter(myUTF32String));
|
||||
break;
|
||||
}
|
||||
|
||||
// This should never happen
|
||||
default : break;
|
||||
}
|
||||
}
|
||||
Unicode::Text::Text(const Unicode::UTF8String& Str)
|
||||
{
|
||||
myUTF32String.reserve(Str.length() + 1);
|
||||
Unicode::UTF8ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
|
||||
}
|
||||
Unicode::Text::Text(const Unicode::UTF16String& Str)
|
||||
{
|
||||
myUTF32String.reserve(Str.length() + 1);
|
||||
Unicode::UTF16ToUTF32(Str.begin(), Str.end(), std::back_inserter(myUTF32String), 0);
|
||||
}
|
||||
Unicode::Text::Text(const Unicode::UTF32String& Str)
|
||||
{
|
||||
myUTF32String = Str;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Operator to cast the text to any type of string
|
||||
////////////////////////////////////////////////////////////
|
||||
Unicode::Text::operator std::string() const
|
||||
{
|
||||
std::string Output;
|
||||
Output.reserve(myUTF32String.length() + 1);
|
||||
Unicode::UTF32ToANSI(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0, Unicode::GetDefaultLocale());
|
||||
return Output;
|
||||
}
|
||||
Unicode::Text::operator std::wstring() const
|
||||
{
|
||||
// This function assumes that 2-byte large wchar_t are encoded in UTF-16 (Windows), and
|
||||
// 4-byte large wchar_t are encoded using UTF-32 (Unix)
|
||||
// Is that always true ? (some platforms may use JIS Japanese encoding)
|
||||
// The macro __STDC_ISO_10646__ should help identifying UTF-32 compliant implementations
|
||||
|
||||
std::wstring Output;
|
||||
Output.reserve(myUTF32String.length() + 1);
|
||||
|
||||
// Select the proper function according to the (supposed) wchar_t system encoding
|
||||
switch (sizeof(wchar_t))
|
||||
{
|
||||
// wchar_t uses UTF-16 -- need a conversion
|
||||
case 2 :
|
||||
{
|
||||
UTF32ToUTF16(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
// wchar_t uses UTF-32 -- direct copy
|
||||
case 4 :
|
||||
{
|
||||
std::copy(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output));
|
||||
break;
|
||||
}
|
||||
|
||||
// This should never happen
|
||||
default : break;
|
||||
}
|
||||
return Output;
|
||||
}
|
||||
Unicode::Text::operator sf::Unicode::UTF8String() const
|
||||
{
|
||||
Unicode::UTF8String Output;
|
||||
Output.reserve(myUTF32String.length() * 4 + 1);
|
||||
Unicode::UTF32ToUTF8(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
|
||||
return Output;
|
||||
}
|
||||
Unicode::Text::operator sf::Unicode::UTF16String() const
|
||||
{
|
||||
Unicode::UTF16String Output;
|
||||
Output.reserve(myUTF32String.length() * 2 + 1);
|
||||
Unicode::UTF32ToUTF16(myUTF32String.begin(), myUTF32String.end(), std::back_inserter(Output), 0);
|
||||
return Output;
|
||||
}
|
||||
Unicode::Text::operator const sf::Unicode::UTF32String&() const
|
||||
{
|
||||
return myUTF32String;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the default system locale
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::locale& Unicode::GetDefaultLocale()
|
||||
{
|
||||
// It seems getting the default locale is a very expensive operation,
|
||||
// so we only do it once and then store the locale for reuse.
|
||||
// Warning : this code won't be aware of any change of the default locale during runtime
|
||||
|
||||
static std::locale DefaultLocale = GetCurrentLocale();
|
||||
|
||||
return DefaultLocale;
|
||||
}
|
||||
|
||||
} // namespace sf
|
79
src/SFML/System/Utf.cpp
Normal file
79
src/SFML/System/Utf.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <exception>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// References :
|
||||
//
|
||||
// http://www.unicode.org/
|
||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
|
||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
|
||||
// http://people.w3.org/rishida/scripts/uniview/conversion
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Private data
|
||||
////////////////////////////////////////////////////////////
|
||||
namespace
|
||||
{
|
||||
// Get the current global locale
|
||||
std::locale GetCurrentLocale()
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::locale("");
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
// It seems that some implementations don't know the "" locale (Mac OS X, MinGW)
|
||||
return std::locale();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the default system locale
|
||||
////////////////////////////////////////////////////////////
|
||||
const std::locale& GetDefaultLocale()
|
||||
{
|
||||
// It seems that getting the default locale is a very expensive operation,
|
||||
// so we only do it once and then store the locale for reuse.
|
||||
// Warning: this code won't be aware of any change of the default locale during runtime.
|
||||
|
||||
static std::locale locale = GetCurrentLocale();
|
||||
|
||||
return locale;
|
||||
}
|
||||
|
||||
} // namespace sf
|
@ -698,14 +698,13 @@ bool WindowImplX11::ProcessEvent(XEvent windowEvent)
|
||||
int length = Xutf8LookupString(myInputContext, &windowEvent.xkey, reinterpret_cast<char*>(keyBuffer), sizeof(keyBuffer), NULL, &status);
|
||||
if (length > 0)
|
||||
{
|
||||
Uint32 unicode[2]; // just in case, but 1 character should be enough
|
||||
const Uint32* end = Unicode::UTF8ToUTF32(keyBuffer, keyBuffer + length, unicode);
|
||||
|
||||
if (end > unicode)
|
||||
Uint32 unicode = 0;
|
||||
Utf8::Decode(keyBuffer, keyBuffer + length, unicode, 0);
|
||||
if (unicode != 0)
|
||||
{
|
||||
Event textEvent;
|
||||
textEvent.Type = Event::TextEntered;
|
||||
textEvent.Text.Unicode = unicode[0];
|
||||
textEvent.Text.Unicode = unicode;
|
||||
SendEvent(textEvent);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user