Sprite.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/Sprite.h>
00029 #include <SFML/Graphics/Sprite.hpp>
00030 #include <SFML/Graphics/Color.hpp>
00031 #include <SFML/Graphics/Image.hpp>
00032 #include <SFML/Internal.h>
00033 
00034 
00035 // WARNING : this structure must always be the SAME as in Graphics/Image.h
00036 struct sfImage
00037 {
00038     sf::Image This;
00039 };
00040 struct sfSprite
00041 {
00042     sf::Sprite This;
00043     sfImage*   Image;
00044     sfIntRect  SubRect;
00045 };
00046 
00047 
00051 sfSprite* sfSprite_Create()
00052 {
00053     sfSprite* Sprite        = new sfSprite;
00054     Sprite->Image          = NULL;
00055     Sprite->SubRect.Left   = Sprite->This.GetSubRect().Left;
00056     Sprite->SubRect.Top    = Sprite->This.GetSubRect().Top;
00057     Sprite->SubRect.Right  = Sprite->This.GetSubRect().Right;
00058     Sprite->SubRect.Bottom = Sprite->This.GetSubRect().Bottom;
00059 
00060     return Sprite;
00061 }
00062 
00063 
00067 void sfSprite_Destroy(sfSprite* Sprite)
00068 {
00069     delete Sprite;
00070 }
00071 
00072 
00076 void sfSprite_SetLeft(sfSprite* Sprite, float Left)
00077 {
00078     CSFML_CALL(Sprite, SetLeft(Left))
00079 }
00080 
00081 
00084 void sfSprite_SetTop(sfSprite* Sprite, float Top)
00085 {
00086     CSFML_CALL(Sprite, SetTop(Top))
00087 }
00088 
00089 
00093 void sfSprite_SetPosition(sfSprite* Sprite, float Left, float Top)
00094 {
00095     CSFML_CALL(Sprite, SetPosition(Left, Top))
00096 }
00097 
00098 
00102 void sfSprite_SetScaleX(sfSprite* Sprite, float Scale)
00103 {
00104     CSFML_CALL(Sprite, SetScaleX(Scale))
00105 }
00106 
00107 
00111 void sfSprite_SetScaleY(sfSprite* Sprite, float Scale)
00112 {
00113     CSFML_CALL(Sprite, SetScaleY(Scale))
00114 }
00115 
00116 
00120 void sfSprite_SetScale(sfSprite* Sprite, float ScaleX, float ScaleY)
00121 {
00122     CSFML_CALL(Sprite, SetScale(ScaleX, ScaleY))
00123 }
00124 
00125 
00129 void sfSprite_SetRotation(sfSprite* Sprite, float Rotation)
00130 {
00131     CSFML_CALL(Sprite, SetRotation(Rotation))
00132 }
00133 
00134 
00139 void sfSprite_SetRotationCenter(sfSprite* Sprite, float X, float Y)
00140 {
00141     CSFML_CALL(Sprite, SetRotationCenter(X, Y))
00142 }
00143 
00144 
00148 void sfSprite_SetColor(sfSprite* Sprite, sfColor Color)
00149 {
00150     CSFML_CALL(Sprite, SetColor(sf::Color(Color.r, Color.g, Color.b, Color.a)))
00151 }
00152 
00153 
00157 void sfSprite_SetBlendMode(sfSprite* Sprite, sfBlendMode Mode)
00158 {
00159     CSFML_CALL(Sprite, SetBlendMode(static_cast<sf::Blend::Mode>(Mode)))
00160 }
00161 
00162 
00166 float sfSprite_GetLeft(sfSprite* Sprite)
00167 {
00168     CSFML_CALL_RETURN(Sprite, GetLeft(), 0.f)
00169 }
00170 
00171 
00175 float sfSprite_GetTop(sfSprite* Sprite)
00176 {
00177     CSFML_CALL_RETURN(Sprite, GetTop(), 0.f)
00178 }
00179 
00180 
00184 float sfSprite_GetScaleX(sfSprite* Sprite)
00185 {
00186     CSFML_CALL_RETURN(Sprite, GetScaleX(), 0.f)
00187 }
00188 
00189 
00193 float sfSprite_GetScaleY(sfSprite* Sprite)
00194 {
00195     CSFML_CALL_RETURN(Sprite, GetScaleY(), 0.f)
00196 }
00197 
00198 
00202 float sfSprite_GetRotation(sfSprite* Sprite)
00203 {
00204     CSFML_CALL_RETURN(Sprite, GetRotation(), 0.f)
00205 }
00206 
00207 
00211 sfColor sfSprite_GetColor(sfSprite* Sprite)
00212 {
00213     sfColor Color = {0, 0, 0, 0};
00214     CSFML_CHECK_RETURN(Sprite, Color)
00215 
00216     sf::Color SFMLColor = Sprite->This.GetColor();
00217     return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
00218 }
00219 
00220 
00224 sfBlendMode sfSprite_GetBlendMode(sfSprite* Sprite)
00225 {
00226     CSFML_CHECK_RETURN(Sprite, sfBlendNone)
00227 
00228     return static_cast<sfBlendMode>(Sprite->This.GetBlendMode());
00229 }
00230 
00231 
00235 void sfSprite_Move(sfSprite* Sprite, float OffsetX, float OffsetY)
00236 {
00237     CSFML_CALL(Sprite, Move(OffsetX, OffsetY))
00238 }
00239 
00240 
00244 void sfSprite_Scale(sfSprite* Sprite, float FactorX, float FactorY)
00245 {
00246     CSFML_CALL(Sprite, Scale(FactorX, FactorY))
00247 }
00248 
00249 
00253 void sfSprite_Rotate(sfSprite* Sprite, float Angle)
00254 {
00255     CSFML_CALL(Sprite, Rotate(Angle))
00256 }
00257 
00258 
00262 void sfSprite_SetImage(sfSprite* Sprite, sfImage* Image)
00263 {
00264     if (Image)
00265     {
00266         CSFML_CALL(Sprite, SetImage(Image->This))
00267         Sprite->Image = Image;
00268     }
00269 }
00270 
00271 
00275 void sfSprite_SetSubRect(sfSprite* Sprite, const sfIntRect* SubRect)
00276 {
00277     if (SubRect)
00278     {
00279         CSFML_CALL(Sprite, SetSubRect(sf::IntRect(SubRect->Left, SubRect->Top, SubRect->Right, SubRect->Bottom)))
00280         Sprite->SubRect = *SubRect;
00281     }
00282 }
00283 
00284 
00288 void sfSprite_Resize(sfSprite* Sprite, float Width, float Height)
00289 {
00290     CSFML_CALL(Sprite, Resize(Width, Height))
00291 }
00292 
00293 
00297 void sfSprite_FlipX(sfSprite* Sprite, sfBool Flipped)
00298 {
00299     CSFML_CALL(Sprite, FlipX(Flipped == sfTrue))
00300 }
00301 
00302 
00306 void sfSprite_FlipY(sfSprite* Sprite, sfBool Flipped)
00307 {
00308     CSFML_CALL(Sprite, FlipY(Flipped == sfTrue))
00309 }
00310 
00311 
00315 sfImage* sfSprite_GetImage(sfSprite* Sprite)
00316 {
00317     CSFML_CHECK_RETURN(Sprite, NULL)
00318 
00319     return Sprite->Image;
00320 }
00321 
00322 
00326 sfIntRect* sfSprite_GetSubRect(sfSprite* Sprite)
00327 {
00328     CSFML_CHECK_RETURN(Sprite, NULL)
00329 
00330     return &Sprite->SubRect;
00331 }
00332 
00333 
00337 float sfSprite_GetWidth(sfSprite* Sprite)
00338 {
00339     CSFML_CALL_RETURN(Sprite, GetWidth(), 0.f)
00340 }
00341 
00342 
00346 float sfSprite_GetHeight(sfSprite* Sprite)
00347 {
00348     CSFML_CALL_RETURN(Sprite, GetHeight(), 0.f)
00349 }
00350 
00351 
00355 sfColor sfSprite_GetPixel(sfSprite* Sprite, unsigned int X, unsigned int Y)
00356 {
00357     sfColor Color = {0, 0, 0, 0};
00358     CSFML_CHECK_RETURN(Sprite, Color)
00359 
00360     sf::Color SFMLColor = Sprite->This.GetPixel(X, Y);
00361     return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
00362 }