Synchronized with trunk

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1087 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-05-06 20:06:14 +00:00
commit 635f92d98d
22 changed files with 1421 additions and 148 deletions

View file

@ -49,12 +49,11 @@ myIsFlippedY(false)
////////////////////////////////////////////////////////////
Sprite::Sprite(const Image& Img, const Vector2f& Position, const Vector2f& Scale, float Rotation, const Color& Col) :
Drawable (Position, Scale, Rotation, Col),
myImage (&Img),
mySubRect (0, 0, Img.GetWidth(), Img.GetHeight()),
mySubRect (0, 0, 1, 1),
myIsFlippedX(false),
myIsFlippedY(false)
{
SetImage(Img);
}
@ -63,9 +62,11 @@ myIsFlippedY(false)
////////////////////////////////////////////////////////////
void Sprite::SetImage(const Image& Img)
{
// If there was no source image before, adjust the rectangle
if (!myImage)
// If there was no source image before and the new image is valid, adjust the source rectangle
if (!myImage && (Img.GetWidth() > 0) && (Img.GetHeight() > 0))
{
SetSubRect(IntRect(0, 0, Img.GetWidth(), Img.GetHeight()));
}
// Assign the new image
myImage = &Img;
@ -87,10 +88,11 @@ void Sprite::SetSubRect(const IntRect& SubRect)
////////////////////////////////////////////////////////////
void Sprite::Resize(float Width, float Height)
{
if ((mySubRect.GetWidth() > 0) && (mySubRect.GetHeight() > 0))
{
SetScale(Width / mySubRect.GetWidth(), Height / mySubRect.GetHeight());
}
int LocalWidth = mySubRect.GetWidth();
int LocalHeight = mySubRect.GetHeight();
if ((LocalWidth > 0) && (LocalHeight > 0))
SetScale(Width / LocalWidth, Height / LocalHeight);
}
@ -182,9 +184,9 @@ void Sprite::Render(RenderTarget&) const
float Height = static_cast<float>(mySubRect.GetHeight());
// Check if the image is valid
if (myImage)
if (myImage && (myImage->GetWidth() > 0) && (myImage->GetHeight() > 0))
{
// Set the texture
// Bind the texture
myImage->Bind();
// Calculate the texture coordinates

View file

@ -205,31 +205,17 @@ IPAddress IPAddress::GetPublicAddress(float Timeout)
{
// The trick here is more complicated, because the only way
// to get our public IP address is to get it from a distant computer.
// Here we get the web page from http://www.whatismyip.org
// Here we get the web page from http://www.sfml-dev.org/ip-provider.php
// and parse the result to extract our IP address
// (not very hard : the web page contains only our IP address).
// If the server is not responding, we use a fallback server which
// is stored on the SFML website.
// First try: www.whatismyip.org
{
Http Server("www.whatismyip.org");
Http::Request Request(Http::Request::Get, "/");
Http::Response Page = Server.SendRequest(Request, Timeout / 2);
if (Page.GetStatus() == Http::Response::Ok)
return IPAddress(Page.GetBody());
}
Http Server("www.sfml-dev.org");
Http::Request Request(Http::Request::Get, "/ip-provider.php");
Http::Response Page = Server.SendRequest(Request, Timeout);
if (Page.GetStatus() == Http::Response::Ok)
return IPAddress(Page.GetBody());
// Fallback: www.sfml-dev.org/ip-provider.php
{
Http Server("www.sfml-dev.org");
Http::Request Request(Http::Request::Get, "/ip-provider.php");
Http::Response Page = Server.SendRequest(Request, Timeout / 2);
if (Page.GetStatus() == Http::Response::Ok)
return IPAddress(Page.GetBody());
}
// Everything failed: return an invalid address
// Something failed: return an invalid address
return IPAddress();
}