String.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00026 // Headers
00028 #include <SFML/Graphics/String.h>
00029 #include <SFML/Graphics/String.hpp>
00030 #include <SFML/Graphics/Color.hpp>
00031 #include <SFML/Graphics/Rect.hpp>
00032 #include <SFML/Internal.h>
00033 
00034 
00035 struct sfString
00036 {
00037     sf::String  This;
00038     std::string Text;
00039 };
00040 
00041 
00042 
00046 sfString* sfString_Create()
00047 {
00048     return new sfString;
00049 }
00050 
00051 
00055 void sfString_Destroy(sfString* String)
00056 {
00057     delete String;
00058 }
00059 
00060 
00064 void sfString_SetLeft(sfString* String, float Left)
00065 {
00066     CSFML_CALL(String, SetLeft(Left))
00067 }
00068 
00069 
00072 void sfString_SetTop(sfString* String, float Top)
00073 {
00074     CSFML_CALL(String, SetTop(Top))
00075 }
00076 
00077 
00081 void sfString_SetPosition(sfString* String, float Left, float Top)
00082 {
00083     CSFML_CALL(String, SetPosition(Left, Top))
00084 }
00085 
00086 
00090 void sfString_SetScaleX(sfString* String, float Scale)
00091 {
00092     CSFML_CALL(String, SetScaleX(Scale))
00093 }
00094 
00095 
00099 void sfString_SetScaleY(sfString* String, float Scale)
00100 {
00101     CSFML_CALL(String, SetScaleY(Scale))
00102 }
00103 
00104 
00108 void sfString_SetScale(sfString* String, float ScaleX, float ScaleY)
00109 {
00110     CSFML_CALL(String, SetScale(ScaleX, ScaleY))
00111 }
00112 
00113 
00117 void sfString_SetRotation(sfString* String, float Rotation)
00118 {
00119     CSFML_CALL(String, SetRotation(Rotation))
00120 }
00121 
00122 
00127 void sfString_SetRotationCenter(sfString* String, float X, float Y)
00128 {
00129     CSFML_CALL(String, SetRotationCenter(X, Y))
00130 }
00131 
00132 
00136 void sfString_SetColor(sfString* String, sfColor Color)
00137 {
00138     CSFML_CALL(String, SetColor(sf::Color(Color.r, Color.g, Color.b, Color.a)))
00139 }
00140 
00141 
00145 void sfString_SetBlendMode(sfString* String, sfBlendMode Mode)
00146 {
00147     CSFML_CALL(String, SetBlendMode(static_cast<sf::Blend::Mode>(Mode)))
00148 }
00149 
00150 
00154 float sfString_GetLeft(sfString* String)
00155 {
00156     CSFML_CALL_RETURN(String, GetLeft(), 0.f)
00157 }
00158 
00159 
00163 float sfString_GetTop(sfString* String)
00164 {
00165     CSFML_CALL_RETURN(String, GetTop(), 0.f)
00166 }
00167 
00168 
00172 float sfString_GetScaleX(sfString* String)
00173 {
00174     CSFML_CALL_RETURN(String, GetScaleX(), 0.f)
00175 }
00176 
00177 
00181 float sfString_GetScaleY(sfString* String)
00182 {
00183     CSFML_CALL_RETURN(String, GetScaleY(), 0.f)
00184 }
00185 
00186 
00190 float sfString_GetRotation(sfString* String)
00191 {
00192     CSFML_CALL_RETURN(String, GetRotation(), 0.f)
00193 }
00194 
00195 
00199 sfColor sfString_GetColor(sfString* String)
00200 {
00201     sfColor Color = {0, 0, 0, 0};
00202     CSFML_CHECK_RETURN(String, Color)
00203 
00204     sf::Color SFMLColor = String->This.GetColor();
00205     return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
00206 }
00207 
00208 
00212 sfBlendMode sfString_GetBlendMode(sfString* String)
00213 {
00214     CSFML_CHECK_RETURN(String, sfBlendNone)
00215 
00216     return static_cast<sfBlendMode>(String->This.GetBlendMode());
00217 }
00218 
00219 
00223 void sfString_Move(sfString* String, float OffsetX, float OffsetY)
00224 {
00225     CSFML_CALL(String, Move(OffsetX, OffsetY))
00226 }
00227 
00228 
00232 void sfString_Scale(sfString* String, float FactorX, float FactorY)
00233 {
00234     CSFML_CALL(String, Scale(FactorX, FactorY))
00235 }
00236 
00237 
00241 void sfString_Rotate(sfString* String, float Angle)
00242 {
00243     CSFML_CALL(String, Rotate(Angle))
00244 }
00245 
00249 void sfString_PreloadFont(const char* Font, float Size, const wchar_t* Charset)
00250 {
00251     if (!Charset)
00252         Charset = L"";
00253 
00254     sf::String::PreloadFont(Font, Size, Charset);
00255 }
00256 
00257 
00261 void sfString_SetText(sfString* String, const char* Text)
00262 {
00263     CSFML_CALL(String, SetText(Text))
00264 }
00265 
00266 
00270 void sfString_SetUnicodeText(sfString* String, const wchar_t* Text)
00271 {
00272     CSFML_CALL(String, SetText(Text))
00273 }
00274 
00275 
00279 void sfString_SetFont(sfString* String, const char* Font)
00280 {
00281     CSFML_CALL(String, SetFont(Font))
00282 }
00283 
00284 
00288 void sfString_SetSize(sfString* String, float Size)
00289 {
00290     CSFML_CALL(String, SetSize(Size))
00291 }
00292 
00293 
00297 const wchar_t* sfString_GetUnicodeText(sfString* String)
00298 {
00299     CSFML_CHECK_RETURN(String, NULL)
00300 
00301     return String->This.GetUnicodeText().c_str();
00302 }
00303 
00304 
00308 const char* sfString_GetText(sfString* String)
00309 {
00310     CSFML_CHECK_RETURN(String, NULL)
00311 
00312     String->Text = String->This.GetText();
00313 
00314     return String->Text.c_str();
00315 }
00316 
00317 
00321 const char* sfString_GetFont(sfString* String)
00322 {
00323     CSFML_CHECK_RETURN(String, NULL)
00324 
00325     return String->This.GetFont().c_str();
00326 }
00327 
00328 
00332 float sfString_GetSize(sfString* String)
00333 {
00334     CSFML_CALL_RETURN(String, GetSize(), 0.f)
00335 }
00336 
00337 
00341 sfFloatRect sfString_GetRect(sfString* String)
00342 {
00343     sfFloatRect EmptyRect = {0, 0, 0, 0};
00344     CSFML_CHECK_RETURN(String, EmptyRect)
00345 
00346     sf::FloatRect SFMLRect = String->This.GetRect();
00347     sfFloatRect Rect = {SFMLRect.Left, SFMLRect.Top, SFMLRect.Right, SFMLRect.Bottom};
00348 
00349     return Rect;
00350 }