*important* sf::Rect now uses Width/Height instead of Right/Bottom
Removed Offset, GetSize and GetCenter functions from sf::Rect Added a sf::Rect constructor taking two Vector2 parameters Updated the API documentation of the sf::Rect class git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1503 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
ae2ae15e12
commit
082a928555
11 changed files with 205 additions and 196 deletions
|
@ -369,8 +369,8 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||
// Compute the glyph's bounding box
|
||||
glyph.Bounds.Left = bitmapGlyph->left - padding;
|
||||
glyph.Bounds.Top = -bitmapGlyph->top - padding;
|
||||
glyph.Bounds.Right = bitmapGlyph->left + width + padding;
|
||||
glyph.Bounds.Bottom = -bitmapGlyph->top + height + padding;
|
||||
glyph.Bounds.Width = width + 2 * padding;
|
||||
glyph.Bounds.Height = height + 2 * padding;
|
||||
|
||||
// Extract the glyph's pixels from the bitmap
|
||||
myPixelBuffer.resize(width * height * 4, 255);
|
||||
|
@ -408,8 +408,8 @@ Glyph Font::LoadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
|||
IntRect subrect = glyph.SubRect;
|
||||
subrect.Left += padding;
|
||||
subrect.Top += padding;
|
||||
subrect.Right -= padding;
|
||||
subrect.Bottom -= padding;
|
||||
subrect.Width -= 2 * padding;
|
||||
subrect.Height -= 2 * padding;
|
||||
page.Texture.UpdatePixels(&myPixelBuffer[0], subrect);
|
||||
}
|
||||
|
||||
|
@ -481,7 +481,7 @@ IntRect Font::FindGlyphRect(Page& page, unsigned int width, unsigned int height)
|
|||
}
|
||||
|
||||
// Find the glyph's rectangle on the selected row
|
||||
IntRect rect(row->Width, row->Top, row->Width + width, row->Top + height);
|
||||
IntRect rect(row->Width, row->Top, width, height);
|
||||
|
||||
// Update the row informations
|
||||
row->Width += width;
|
||||
|
|
|
@ -272,24 +272,24 @@ void Image::Copy(const Image& source, unsigned int destX, unsigned int destY, co
|
|||
|
||||
// Adjust the source rectangle
|
||||
IntRect srcRect = sourceRect;
|
||||
if (srcRect.GetSize().x == 0 || (srcRect.GetSize().y == 0))
|
||||
if (srcRect.Width == 0 || (srcRect.Height == 0))
|
||||
{
|
||||
srcRect.Left = 0;
|
||||
srcRect.Top = 0;
|
||||
srcRect.Right = source.myWidth;
|
||||
srcRect.Bottom = source.myHeight;
|
||||
srcRect.Width = source.myWidth;
|
||||
srcRect.Height = source.myHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (srcRect.Left < 0) srcRect.Left = 0;
|
||||
if (srcRect.Top < 0) srcRect.Top = 0;
|
||||
if (srcRect.Right > static_cast<int>(source.myWidth)) srcRect.Right = source.myWidth;
|
||||
if (srcRect.Bottom > static_cast<int>(source.myHeight)) srcRect.Bottom = source.myHeight;
|
||||
if (srcRect.Width > static_cast<int>(source.myWidth)) srcRect.Width = source.myWidth;
|
||||
if (srcRect.Height > static_cast<int>(source.myHeight)) srcRect.Height = source.myHeight;
|
||||
}
|
||||
|
||||
// Then find the valid bounds of the destination rectangle
|
||||
int width = srcRect.GetSize().x;
|
||||
int height = srcRect.GetSize().y;
|
||||
int width = srcRect.Width;
|
||||
int height = srcRect.Height;
|
||||
if (destX + width > myWidth) width = myWidth - destX;
|
||||
if (destY + height > myHeight) height = myHeight - destY;
|
||||
|
||||
|
@ -353,24 +353,24 @@ bool Image::CopyScreen(RenderWindow& window, const IntRect& sourceRect)
|
|||
{
|
||||
// Adjust the source rectangle
|
||||
IntRect srcRect = sourceRect;
|
||||
if (srcRect.GetSize().x == 0 || (srcRect.GetSize().y == 0))
|
||||
if (srcRect.Width == 0 || (srcRect.Height == 0))
|
||||
{
|
||||
srcRect.Left = 0;
|
||||
srcRect.Top = 0;
|
||||
srcRect.Right = window.GetWidth();
|
||||
srcRect.Bottom = window.GetHeight();
|
||||
srcRect.Width = window.GetWidth();
|
||||
srcRect.Height = window.GetHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (srcRect.Left < 0) srcRect.Left = 0;
|
||||
if (srcRect.Top < 0) srcRect.Top = 0;
|
||||
if (srcRect.Right > static_cast<int>(window.GetWidth())) srcRect.Right = window.GetWidth();
|
||||
if (srcRect.Bottom > static_cast<int>(window.GetHeight())) srcRect.Bottom = window.GetHeight();
|
||||
if (srcRect.Width > static_cast<int>(window.GetWidth())) srcRect.Width = window.GetWidth();
|
||||
if (srcRect.Height > static_cast<int>(window.GetHeight())) srcRect.Height = window.GetHeight();
|
||||
}
|
||||
|
||||
// Store the texture dimensions
|
||||
myWidth = srcRect.GetSize().x;
|
||||
myHeight = srcRect.GetSize().y;
|
||||
myWidth = srcRect.Width;
|
||||
myHeight = srcRect.Height;
|
||||
|
||||
// We can then create the texture
|
||||
if (window.SetActive() && CreateTexture())
|
||||
|
@ -486,7 +486,7 @@ void Image::UpdatePixels(const Uint8* pixels, const IntRect& rectangle)
|
|||
|
||||
// Update the texture from the array of pixels
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, myTexture));
|
||||
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, rectangle.Left, rectangle.Top, rectangle.GetSize().x, rectangle.GetSize().y, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
|
||||
|
||||
GLCheck(glBindTexture(GL_TEXTURE_2D, previous));
|
||||
|
||||
|
@ -573,16 +573,16 @@ FloatRect Image::GetTexCoords(const IntRect& rect) const
|
|||
if (myPixelsFlipped)
|
||||
{
|
||||
return FloatRect(rect.Left / width,
|
||||
rect.Bottom / height,
|
||||
rect.Right / width,
|
||||
rect.Height / height,
|
||||
rect.Width / width,
|
||||
rect.Top / height);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FloatRect(rect.Left / width,
|
||||
rect.Top / height,
|
||||
rect.Right / width,
|
||||
rect.Bottom / height);
|
||||
rect.Width / width,
|
||||
rect.Height / height);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -153,8 +153,8 @@ IntRect RenderTarget::GetViewport(const View& view) const
|
|||
|
||||
return IntRect(static_cast<int>(0.5f + width * viewport.Left),
|
||||
static_cast<int>(0.5f + height * viewport.Top),
|
||||
static_cast<int>(0.5f + width * viewport.Right),
|
||||
static_cast<int>(0.5f + height * viewport.Bottom));
|
||||
static_cast<int>(width * viewport.Width),
|
||||
static_cast<int>(height * viewport.Height));
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,8 +171,8 @@ Vector2f RenderTarget::ConvertCoords(unsigned int x, unsigned int y, const View&
|
|||
// First, convert from viewport coordinates to homogeneous coordinates
|
||||
Vector2f coords;
|
||||
IntRect viewport = GetViewport(view);
|
||||
coords.x = -1.f + 2.f * (static_cast<int>(x) - viewport.Left) / viewport.GetSize().x;
|
||||
coords.y = 1.f - 2.f * (static_cast<int>(y) - viewport.Top) / viewport.GetSize().y;
|
||||
coords.x = -1.f + 2.f * (static_cast<int>(x) - viewport.Left) / viewport.Width;
|
||||
coords.y = 1.f - 2.f * (static_cast<int>(y) - viewport.Top) / viewport.Height;
|
||||
|
||||
// Then transform by the inverse of the view matrix
|
||||
return view.GetInverseMatrix().Transform(coords);
|
||||
|
|
|
@ -173,12 +173,15 @@ void Renderer::ApplyColor(const Color& color)
|
|||
////////////////////////////////////////////////////////////
|
||||
void Renderer::SetViewport(const IntRect& viewport)
|
||||
{
|
||||
if ((viewport.Left != myViewport.Left) || (viewport.Right != myViewport.Right) ||
|
||||
(viewport.Top != myViewport.Top) || (viewport.Bottom != myViewport.Bottom) ||
|
||||
if ((viewport.Left != myViewport.Left) || (viewport.Width != myViewport.Width) ||
|
||||
(viewport.Top != myViewport.Top) || (viewport.Height != myViewport.Height) ||
|
||||
!myViewportIsValid)
|
||||
{
|
||||
// Apply the new viewport -- revert Y axis to match the OpenGL convention
|
||||
GLCheck(glViewport(viewport.Left, myTarget.GetHeight() - viewport.Bottom, viewport.GetSize().x, viewport.GetSize().y));
|
||||
// Revert the Y axis to match the OpenGL convention
|
||||
int top = myTarget.GetHeight() - (viewport.Top + viewport.Height);
|
||||
|
||||
// Apply the new viewport
|
||||
GLCheck(glViewport(viewport.Left, top, viewport.Width, viewport.Height));
|
||||
|
||||
// Store it
|
||||
myViewport = viewport;
|
||||
|
|
|
@ -93,11 +93,8 @@ void Sprite::SetSubRect(const IntRect& rectangle)
|
|||
////////////////////////////////////////////////////////////
|
||||
void Sprite::Resize(float width, float height)
|
||||
{
|
||||
int localWidth = mySubRect.GetSize().x;
|
||||
int localHeight = mySubRect.GetSize().y;
|
||||
|
||||
if ((localWidth > 0) && (localHeight > 0))
|
||||
SetScale(width / localWidth, height / localHeight);
|
||||
if ((mySubRect.Width > 0) && (mySubRect.Height > 0))
|
||||
SetScale(width / mySubRect.Width, height / mySubRect.Height);
|
||||
}
|
||||
|
||||
|
||||
|
@ -152,7 +149,7 @@ const IntRect& Sprite::GetSubRect() const
|
|||
////////////////////////////////////////////////////////////
|
||||
Vector2f Sprite::GetSize() const
|
||||
{
|
||||
return Vector2f(mySubRect.GetSize().x * GetScale().x, mySubRect.GetSize().y * GetScale().y);
|
||||
return Vector2f(mySubRect.Width * GetScale().x, mySubRect.Height * GetScale().y);
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,8 +164,8 @@ Color Sprite::GetPixel(unsigned int x, unsigned int y) const
|
|||
unsigned int imageX = mySubRect.Left + x;
|
||||
unsigned int imageY = mySubRect.Top + y;
|
||||
|
||||
if (myIsFlippedX) imageX = mySubRect.GetSize().x - imageX - 1;
|
||||
if (myIsFlippedY) imageY = mySubRect.GetSize().y - imageY - 1;
|
||||
if (myIsFlippedX) imageX = mySubRect.Width - imageX - 1;
|
||||
if (myIsFlippedY) imageY = mySubRect.Height - imageY - 1;
|
||||
|
||||
return myImage->GetPixel(imageX, imageY) * GetColor();
|
||||
}
|
||||
|
@ -185,27 +182,29 @@ Color Sprite::GetPixel(unsigned int x, unsigned int y) const
|
|||
void Sprite::Render(RenderTarget&, Renderer& renderer) const
|
||||
{
|
||||
// Get the sprite size
|
||||
float width = static_cast<float>(mySubRect.GetSize().x);
|
||||
float height = static_cast<float>(mySubRect.GetSize().y);
|
||||
float width = static_cast<float>(mySubRect.Width);
|
||||
float height = static_cast<float>(mySubRect.Height);
|
||||
|
||||
// Check if the image is valid, and calculate the texture coordinates
|
||||
FloatRect coords;
|
||||
if (myImage)
|
||||
{
|
||||
coords = myImage->GetTexCoords(mySubRect);
|
||||
if (myIsFlippedX) std::swap(coords.Left, coords.Right);
|
||||
if (myIsFlippedY) std::swap(coords.Top, coords.Bottom);
|
||||
if (myIsFlippedX) coords.Width = -coords.Width;
|
||||
if (myIsFlippedY) coords.Height = -coords.Height;
|
||||
}
|
||||
|
||||
// Bind the texture
|
||||
renderer.SetTexture(myImage);
|
||||
|
||||
// Draw the sprite's geometry
|
||||
float right = coords.Left + coords.Width;
|
||||
float bottom = coords.Top + coords.Height;
|
||||
renderer.Begin(Renderer::TriangleStrip);
|
||||
renderer.AddVertex(0, 0, coords.Left, coords.Top);
|
||||
renderer.AddVertex(width, 0, coords.Right, coords.Top);
|
||||
renderer.AddVertex(0, height, coords.Left, coords.Bottom);
|
||||
renderer.AddVertex(width, height, coords.Right, coords.Bottom);
|
||||
renderer.AddVertex(0, 0, coords.Left, coords.Top);
|
||||
renderer.AddVertex(width, 0, right, coords.Top);
|
||||
renderer.AddVertex(0, height, coords.Left, bottom);
|
||||
renderer.AddVertex(width, height, right, bottom);
|
||||
renderer.End();
|
||||
}
|
||||
|
||||
|
|
|
@ -202,8 +202,8 @@ FloatRect Text::GetRect() const
|
|||
FloatRect rect;
|
||||
rect.Left = (myBaseRect.Left - GetOrigin().x) * GetScale().x + GetPosition().x;
|
||||
rect.Top = (myBaseRect.Top - GetOrigin().y) * GetScale().y + GetPosition().y;
|
||||
rect.Right = (myBaseRect.Right - GetOrigin().x) * GetScale().x + GetPosition().x;
|
||||
rect.Bottom = (myBaseRect.Bottom - GetOrigin().y) * GetScale().y + GetPosition().y;
|
||||
rect.Width = myBaseRect.Width * GetScale().x;
|
||||
rect.Height = myBaseRect.Height * GetScale().y;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
@ -229,6 +229,10 @@ void Text::Render(RenderTarget&, Renderer& renderer) const
|
|||
float underlineOffset = myCharacterSize * 0.1f;
|
||||
float underlineThickness = myCharacterSize * (bold ? 0.1f : 0.07f);
|
||||
FloatRect underlineCoords = texture.GetTexCoords(IntRect(1, 1, 1, 1));
|
||||
float underlineLeft = underlineCoords.Left;
|
||||
float underlineTop = underlineCoords.Top;
|
||||
float underlineRight = underlineCoords.Left + underlineCoords.Width;
|
||||
float underlineBottom = underlineCoords.Top + underlineCoords.Height;
|
||||
|
||||
// Initialize the rendering coordinates
|
||||
float space = static_cast<float>(myFont->GetGlyph(L' ', myCharacterSize, bold).Advance);
|
||||
|
@ -257,10 +261,10 @@ void Text::Render(RenderTarget&, Renderer& renderer) const
|
|||
float bottom = top + underlineThickness;
|
||||
|
||||
renderer.Begin(Renderer::QuadList);
|
||||
renderer.AddVertex(0, top, underlineCoords.Left, underlineCoords.Top);
|
||||
renderer.AddVertex(x, top, underlineCoords.Right, underlineCoords.Top);
|
||||
renderer.AddVertex(x, bottom, underlineCoords.Right, underlineCoords.Bottom);
|
||||
renderer.AddVertex(0, bottom, underlineCoords.Left, underlineCoords.Bottom);
|
||||
renderer.AddVertex(0, top, underlineLeft, underlineTop);
|
||||
renderer.AddVertex(x, top, underlineRight, underlineTop);
|
||||
renderer.AddVertex(x, bottom, underlineRight, underlineBottom);
|
||||
renderer.AddVertex(0, bottom, underlineLeft, underlineBottom);
|
||||
renderer.End();
|
||||
}
|
||||
|
||||
|
@ -279,12 +283,17 @@ void Text::Render(RenderTarget&, Renderer& renderer) const
|
|||
const IntRect& bounds = glyph.Bounds;
|
||||
const FloatRect& coords = texture.GetTexCoords(glyph.SubRect);
|
||||
|
||||
int boundsRight = bounds.Left + bounds.Width;
|
||||
int boundsBottom = bounds.Top + bounds.Height;
|
||||
float coordsRight = coords.Left + coords.Width;
|
||||
float coordsBottom = coords.Top + coords.Height;
|
||||
|
||||
// Draw a textured quad for the current character
|
||||
renderer.Begin(Renderer::QuadList);
|
||||
renderer.AddVertex(x + bounds.Left - italicCoeff * bounds.Top, y + bounds.Top, coords.Left, coords.Top);
|
||||
renderer.AddVertex(x + bounds.Right - italicCoeff * bounds.Top, y + bounds.Top, coords.Right, coords.Top);
|
||||
renderer.AddVertex(x + bounds.Right - italicCoeff * bounds.Bottom, y + bounds.Bottom, coords.Right, coords.Bottom);
|
||||
renderer.AddVertex(x + bounds.Left - italicCoeff * bounds.Bottom, y + bounds.Bottom, coords.Left, coords.Bottom);
|
||||
renderer.AddVertex(x + bounds.Left - italicCoeff * bounds.Top, y + bounds.Top, coords.Left, coords.Top);
|
||||
renderer.AddVertex(x + boundsRight - italicCoeff * bounds.Top, y + bounds.Top, coordsRight, coords.Top);
|
||||
renderer.AddVertex(x + boundsRight - italicCoeff * boundsBottom, y + boundsBottom, coordsRight, coordsBottom);
|
||||
renderer.AddVertex(x + bounds.Left - italicCoeff * boundsBottom, y + boundsBottom, coords.Left, coordsBottom);
|
||||
renderer.End();
|
||||
|
||||
// Advance to the next character
|
||||
|
@ -298,10 +307,10 @@ void Text::Render(RenderTarget&, Renderer& renderer) const
|
|||
float bottom = top + underlineThickness;
|
||||
|
||||
renderer.Begin(Renderer::QuadList);
|
||||
renderer.AddVertex(0, top, underlineCoords.Left, underlineCoords.Top);
|
||||
renderer.AddVertex(x, top, underlineCoords.Right, underlineCoords.Top);
|
||||
renderer.AddVertex(x, bottom, underlineCoords.Right, underlineCoords.Bottom);
|
||||
renderer.AddVertex(0, bottom, underlineCoords.Left, underlineCoords.Bottom);
|
||||
renderer.AddVertex(0, top, underlineLeft, underlineTop);
|
||||
renderer.AddVertex(x, top, underlineRight, underlineTop);
|
||||
renderer.AddVertex(x, bottom, underlineRight, underlineBottom);
|
||||
renderer.AddVertex(0, bottom, underlineLeft, underlineBottom);
|
||||
renderer.End();
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +384,7 @@ void Text::UpdateRect() const
|
|||
curWidth += static_cast<float>(curGlyph.Advance);
|
||||
|
||||
// Update the maximum height
|
||||
float charHeight = charSize + curGlyph.Bounds.Bottom;
|
||||
float charHeight = charSize + curGlyph.Bounds.Top + curGlyph.Bounds.Height;
|
||||
if (charHeight > curHeight)
|
||||
curHeight = charHeight;
|
||||
}
|
||||
|
@ -404,8 +413,8 @@ void Text::UpdateRect() const
|
|||
// Finally update the rectangle
|
||||
myBaseRect.Left = 0;
|
||||
myBaseRect.Top = 0;
|
||||
myBaseRect.Right = width;
|
||||
myBaseRect.Bottom = height;
|
||||
myBaseRect.Width = width;
|
||||
myBaseRect.Height = height;
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -126,8 +126,10 @@ void View::SetViewport(const FloatRect& viewport)
|
|||
////////////////////////////////////////////////////////////
|
||||
void View::Reset(const FloatRect& rectangle)
|
||||
{
|
||||
myCenter = rectangle.GetCenter();
|
||||
mySize = rectangle.GetSize();
|
||||
myCenter.x = (rectangle.Left + rectangle.Width) / 2.f;
|
||||
myCenter.y = (rectangle.Top + rectangle.Height) / 2.f;
|
||||
mySize.x = rectangle.Width;
|
||||
mySize.y = rectangle.Height;
|
||||
myRotation = 0;
|
||||
|
||||
myMatrixUpdated = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue