Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-01-28 16:18:34 +00:00
commit 2f524481c1
974 changed files with 295448 additions and 0 deletions

View file

@ -0,0 +1,147 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_COLOR_HPP
#define SFML_COLOR_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// Color is an utility class for manipulating
/// 32-bits RGBA colors
////////////////////////////////////////////////////////////
class SFML_API Color
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Color();
////////////////////////////////////////////////////////////
/// Construct the color from its 4 RGBA components
///
/// \param R : Red component (0 .. 255)
/// \param G : Green component (0 .. 255)
/// \param B : Blue component (0 .. 255)
/// \param A : Alpha component (0 .. 255) (255 by default)
///
////////////////////////////////////////////////////////////
Color(Uint8 R, Uint8 G, Uint8 B, Uint8 A = 255);
////////////////////////////////////////////////////////////
/// Operator += overload to add a color
///
/// \param Other : Color to add
///
/// \return Component-wise saturated addition of the two colors
///
////////////////////////////////////////////////////////////
Color& operator +=(const Color& Other);
////////////////////////////////////////////////////////////
/// Operator *= overload to modulate a color
///
/// \param Other : Color to modulate
///
/// \return Component-wise multiplication of the two colors
///
////////////////////////////////////////////////////////////
Color& operator *=(const Color& Other);
////////////////////////////////////////////////////////////
/// Compare two colors (for equality)
///
/// \param Other : Color to compare
///
/// \return True if colors are equal
///
////////////////////////////////////////////////////////////
bool operator ==(const Color& Other) const;
////////////////////////////////////////////////////////////
/// Compare two colors (for difference)
///
/// \param Other : Color to compare
///
/// \return True if colors are different
///
////////////////////////////////////////////////////////////
bool operator !=(const Color& Other) const;
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static const Color Black; ///< Black predefined color
static const Color White; ///< White predefined color
static const Color Red; ///< Red predefined color
static const Color Green; ///< Green predefined color
static const Color Blue; ///< Blue predefined color
static const Color Yellow; ///< Yellow predefined color
static const Color Magenta; ///< Magenta predefined color
static const Color Cyan; ///< Cyan predefined color
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Uint8 r; ///< Red component
Uint8 g; ///< Green component
Uint8 b; ///< Blue component
Uint8 a; ///< Alpha (transparency) component
};
////////////////////////////////////////////////////////////
/// Operator + overload to add two colors
///
/// \param Color1 : First color
/// \param Color2 : Second color
///
/// \return Component-wise saturated addition of the two colors
///
////////////////////////////////////////////////////////////
SFML_API Color operator +(const Color& Color1, const Color& Color2);
////////////////////////////////////////////////////////////
/// Operator * overload to modulate two colors
///
/// \param Color1 : First color
/// \param Color2 : Second color
///
/// \return Component-wise multiplication of the two colors
///
////////////////////////////////////////////////////////////
SFML_API Color operator *(const Color& Color1, const Color& Color2);
} // namespace sf
#endif // SFML_COLOR_HPP

View file

@ -0,0 +1,361 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_DRAWABLE_HPP
#define SFML_DRAWABLE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Matrix3.hpp>
namespace sf
{
class RenderTarget;
////////////////////////////////////////////////////////////
/// Enumerate the blending modes for drawable objects
////////////////////////////////////////////////////////////
namespace Blend
{
enum Mode
{
Alpha, ///< Pixel = Src * a + Dest * (1 - a)
Add, ///< Pixel = Src + Dest
Multiply, ///< Pixel = Src * Dest
None ///< No blending
};
}
////////////////////////////////////////////////////////////
/// Abstract base class for every object that can be drawn
/// into a render window
////////////////////////////////////////////////////////////
class SFML_API Drawable
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
/// \param Position : Position of the object (0, 0 by default)
/// \param Scale : Scale factor (1, 1 by default)
/// \param Rotation : Orientation, in degrees (0 by default)
/// \param Col : Color of the object (white by default)
///
////////////////////////////////////////////////////////////
Drawable(const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));
////////////////////////////////////////////////////////////
/// Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~Drawable();
////////////////////////////////////////////////////////////
/// Set the position of the object (take 2 values)
///
/// \param X : New X coordinate
/// \param Y : New Y coordinate
///
////////////////////////////////////////////////////////////
void SetPosition(float X, float Y);
////////////////////////////////////////////////////////////
/// Set the position of the object (take a 2D vector)
///
/// \param Position : New position
///
////////////////////////////////////////////////////////////
void SetPosition(const Vector2f& Position);
////////////////////////////////////////////////////////////
/// Set the X position of the object
///
/// \param X : New X coordinate
///
////////////////////////////////////////////////////////////
void SetX(float X);
////////////////////////////////////////////////////////////
/// Set the Y position of the object
///
/// \param Y : New Y coordinate
///
////////////////////////////////////////////////////////////
void SetY(float Y);
////////////////////////////////////////////////////////////
/// Set the scale of the object (take 2 values)
///
/// \param ScaleX : New horizontal scale (must be strictly positive)
/// \param ScaleY : New vertical scale (must be strictly positive)
///
////////////////////////////////////////////////////////////
void SetScale(float ScaleX, float ScaleY);
////////////////////////////////////////////////////////////
/// Set the scale of the object (take a 2D vector)
///
/// \param Scale : New scale (both values must be strictly positive)
///
////////////////////////////////////////////////////////////
void SetScale(const Vector2f& Scale);
////////////////////////////////////////////////////////////
/// Set the X scale factor of the object
///
/// \param X : New X scale factor
///
////////////////////////////////////////////////////////////
void SetScaleX(float FactorX);
////////////////////////////////////////////////////////////
/// Set the Y scale factor of the object
///
/// \param Y : New Y scale factor
///
////////////////////////////////////////////////////////////
void SetScaleY(float FactorY);
////////////////////////////////////////////////////////////
/// Set the center of the object, in coordinates relative to the
/// top-left of the object (take 2 values).
/// The default center is (0, 0)
///
/// \param CenterX : X coordinate of the center
/// \param CenterY : Y coordinate of the center
///
////////////////////////////////////////////////////////////
void SetCenter(float CenterX, float CenterY);
////////////////////////////////////////////////////////////
/// Set the center of the object, in coordinates relative to the
/// top-left of the object (take a 2D vector).
/// The default center is (0, 0)
///
/// \param Center : New center
///
////////////////////////////////////////////////////////////
void SetCenter(const Vector2f& Center);
////////////////////////////////////////////////////////////
/// Set the orientation of the object
///
/// \param Rotation : Angle of rotation, in degrees
///
////////////////////////////////////////////////////////////
void SetRotation(float Rotation);
////////////////////////////////////////////////////////////
/// Set the color of the object.
/// The default color is white
///
/// \param Col : New color
///
////////////////////////////////////////////////////////////
void SetColor(const Color& Col);
////////////////////////////////////////////////////////////
/// Set the blending mode for the object.
/// The default blend mode is Blend::Alpha
///
/// \param Mode : New blending mode
///
////////////////////////////////////////////////////////////
void SetBlendMode(Blend::Mode Mode);
////////////////////////////////////////////////////////////
/// Get the position of the object
///
/// \return Current position
///
////////////////////////////////////////////////////////////
const Vector2f& GetPosition() const;
////////////////////////////////////////////////////////////
/// Get the current scale of the object
///
/// \return Current scale factor (always positive)
///
////////////////////////////////////////////////////////////
const Vector2f& GetScale() const;
////////////////////////////////////////////////////////////
/// Get the center of the object
///
/// \return Current position of the center
///
////////////////////////////////////////////////////////////
const Vector2f& GetCenter() const;
////////////////////////////////////////////////////////////
/// Get the orientation of the object.
/// Rotation is always in the range [0, 360]
///
/// \return Current rotation, in degrees
///
////////////////////////////////////////////////////////////
float GetRotation() const;
////////////////////////////////////////////////////////////
/// Get the color of the object
///
/// \return Current color
///
////////////////////////////////////////////////////////////
const Color& GetColor() const;
////////////////////////////////////////////////////////////
/// Get the current blending mode
///
/// \return Current blending mode
///
////////////////////////////////////////////////////////////
Blend::Mode GetBlendMode() const;
////////////////////////////////////////////////////////////
/// Move the object of a given offset (take 2 values)
///
/// \param OffsetX : X offset
/// \param OffsetY : Y offset
///
////////////////////////////////////////////////////////////
void Move(float OffsetX, float OffsetY);
////////////////////////////////////////////////////////////
/// Move the object of a given offset (take a 2D vector)
///
/// \param Offset : Amount of units to move the object of
///
////////////////////////////////////////////////////////////
void Move(const Vector2f& Offset);
////////////////////////////////////////////////////////////
/// Scale the object (take 2 values)
///
/// \param FactorX : Scaling factor on X (must be strictly positive)
/// \param FactorY : Scaling factor on Y (must be strictly positive)
///
////////////////////////////////////////////////////////////
void Scale(float FactorX, float FactorY);
////////////////////////////////////////////////////////////
/// Scale the object (take a 2D vector)
///
/// \param Factor : Scaling factors (both values must be strictly positive)
///
////////////////////////////////////////////////////////////
void Scale(const Vector2f& Factor);
////////////////////////////////////////////////////////////
/// Rotate the object
///
/// \param Angle : Angle of rotation, in degrees
///
////////////////////////////////////////////////////////////
void Rotate(float Angle);
////////////////////////////////////////////////////////////
/// Transform a point from global coordinates into local coordinates
/// (ie it applies the inverse of object's center, translation, rotation and scale to the point)
///
/// \param Point : Point to transform
///
/// \return Transformed point
///
////////////////////////////////////////////////////////////
sf::Vector2f TransformToLocal(const sf::Vector2f& Point) const;
////////////////////////////////////////////////////////////
/// Transform a point from local coordinates into global coordinates
/// (ie it applies the object's center, translation, rotation and scale to the point)
///
/// \param Point : Point to transform
///
/// \return Transformed point
///
////////////////////////////////////////////////////////////
sf::Vector2f TransformToGlobal(const sf::Vector2f& Point) const;
protected :
////////////////////////////////////////////////////////////
/// Get the transform matrix of the drawable
///
/// \return Transform matrix
///
////////////////////////////////////////////////////////////
const Matrix3& GetMatrix() const;
////////////////////////////////////////////////////////////
/// Get the inverse transform matrix of the drawable
///
/// \return Inverse transform matrix
///
////////////////////////////////////////////////////////////
const Matrix3& GetInverseMatrix() const;
private :
friend class RenderTarget;
////////////////////////////////////////////////////////////
/// Draw the object into the specified window
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
void Draw(RenderTarget& Target) const;
////////////////////////////////////////////////////////////
/// Render the specific geometry of the object
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const = 0;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Vector2f myPosition; ///< Position of the object on screen
Vector2f myScale; ///< Scale of the object
Vector2f myCenter; ///< Origin of translation / rotation / scaling of the object
float myRotation; ///< Orientation of the object, in degrees
Color myColor; ///< Overlay color of the object
Blend::Mode myBlendMode; ///< Blending mode
mutable bool myNeedUpdate; ///< Do we need to recompute the transform matrix ?
mutable bool myInvNeedUpdate; ///< Do we need to recompute the inverse transform matrix ?
mutable Matrix3 myMatrix; ///< Precomputed transform matrix gathering the translation / rotation / scale / center
mutable Matrix3 myInvMatrix; ///< Precomputed inverse transform matrix gathering the translation / rotation / scale / center
};
} // namespace sf
#endif // SFML_DRAWABLE_HPP

View file

@ -0,0 +1,145 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_FONT_HPP
#define SFML_FONT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/System/Unicode.hpp>
#include <SFML/Graphics/Glyph.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <map>
#include <string>
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
////////////////////////////////////////////////////////////
class SFML_API Font : public Resource<Font>
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Font();
////////////////////////////////////////////////////////////
/// Load the font from a file
///
/// \param Filename : Font file to load
/// \param CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)
/// \param Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters)
///
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool LoadFromFile(const std::string& Filename, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);
////////////////////////////////////////////////////////////
/// Load the font from a file in memory
///
/// \param Data : Pointer to the data to load
/// \param SizeInBytes : Size of the data, in bytes
/// \param CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)
/// \param Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters)
///
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);
////////////////////////////////////////////////////////////
/// Get the base size of characters in the font;
/// All glyphs dimensions are based on this value
///
/// \return Base size of characters
///
////////////////////////////////////////////////////////////
unsigned int GetCharacterSize() const;
////////////////////////////////////////////////////////////
/// Get the description of a glyph (character)
/// given by its unicode value
///
/// \param CodePoint : Unicode value of the character to get
///
/// \return Glyph's visual settings, or an invalid glyph if character not found
///
////////////////////////////////////////////////////////////
const Glyph& GetGlyph(Uint32 CodePoint) const;
////////////////////////////////////////////////////////////
/// Get the image containing the rendered characters (glyphs)
///
/// \return Image containing glyphs
///
////////////////////////////////////////////////////////////
const Image& GetImage() const;
////////////////////////////////////////////////////////////
/// Get the SFML default built-in font (Arial)
///
/// \return Instance of the default font
///
////////////////////////////////////////////////////////////
static const Font& GetDefaultFont();
private :
friend class priv::FontLoader;
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static Uint32 ourDefaultCharset[]; ///< The default charset (all printable ISO-8859-1 characters)
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Image myTexture; ///< Texture holding the bitmap font
unsigned int myCharSize; ///< Size of characters in the bitmap font
std::map<Uint32, Glyph> myGlyphs; ///< Rendering settings of each character (glyph)
};
} // namespace sf
#endif // SFML_FONT_HPP

View file

@ -0,0 +1,61 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_GLYPH_HPP
#define SFML_GLYPH_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/Graphics/Rect.hpp>
namespace sf
{
////////////////////////////////////////////////////////////
/// Structure describing a glyph (a visual character)
////////////////////////////////////////////////////////////
class SFML_API Glyph
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Glyph() : Advance(0) {}
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
int Advance; ///< Offset to move horizontically to the next character
IntRect Rectangle; ///< Bounding rectangle of the glyph, in relative coordinates
FloatRect TexCoords; ///< Texture coordinates of the glyph inside the bitmap font
};
} // namespace sf
#endif // SFML_GLYPH_HPP

View file

@ -0,0 +1,335 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_IMAGE_HPP
#define SFML_IMAGE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <string>
#include <vector>
namespace sf
{
class RenderImage;
class RenderWindow;
////////////////////////////////////////////////////////////
/// Image is the low-level class for loading and
/// manipulating images
////////////////////////////////////////////////////////////
class SFML_API Image : public Resource<Image>
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Image();
////////////////////////////////////////////////////////////
/// Copy constructor
///
/// \param Copy : instance to copy
///
////////////////////////////////////////////////////////////
Image(const Image& Copy);
////////////////////////////////////////////////////////////
/// Construct an empty image
///
/// \param Width : Image width
/// \param Height : Image height
/// \param Col : Image color (black by default)
///
////////////////////////////////////////////////////////////
Image(unsigned int Width, unsigned int Height, const Color& Col = Color(0, 0, 0, 255));
////////////////////////////////////////////////////////////
/// Construct the image from pixels in memory
///
/// \param Width : Image width
/// \param Height : Image height
/// \param Data : Pointer to the pixels in memory (assumed format is RGBA)
///
////////////////////////////////////////////////////////////
Image(unsigned int Width, unsigned int Height, const Uint8* Data);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
~Image();
////////////////////////////////////////////////////////////
/// Load the image from a file
///
/// \param Filename : Path of the image file to load
///
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool LoadFromFile(const std::string& Filename);
////////////////////////////////////////////////////////////
/// Load the image from a file in memory
///
/// \param Data : Pointer to the file data in memory
/// \param SizeInBytes : Size of the data to load, in bytes
///
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
////////////////////////////////////////////////////////////
/// Load the image directly from an array of pixels
///
/// \param Width : Image width
/// \param Height : Image height
/// \param Data : Pointer to the pixels in memory (assumed format is RGBA)
///
/// \return True if loading was successful
///
////////////////////////////////////////////////////////////
bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8* Data);
////////////////////////////////////////////////////////////
/// Save the content of the image to a file
///
/// \param Filename : Path of the file to save (overwritten if already exist)
///
/// \return True if saving was successful
///
////////////////////////////////////////////////////////////
bool SaveToFile(const std::string& Filename) const;
////////////////////////////////////////////////////////////
/// Create an empty image
///
/// \param Width : Image width
/// \param Height : Image height
/// \param Col : Image color (black by default)
///
/// \return True if creation was successful
///
////////////////////////////////////////////////////////////
bool Create(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255));
////////////////////////////////////////////////////////////
/// Create transparency mask from a specified colorkey
///
/// \param ColorKey : Color to become transparent
/// \param Alpha : Alpha value to use for transparent pixels (0 by default)
///
////////////////////////////////////////////////////////////
void CreateMaskFromColor(Color ColorKey, Uint8 Alpha = 0);
////////////////////////////////////////////////////////////
/// Copy pixels from another image onto this one.
/// This function does a slow pixel copy and should only
/// be used at initialization time
///
/// \param Source : Source image to copy
/// \param DestX : X coordinate of the destination position
/// \param DestY : Y coordinate of the destination position
/// \param SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)
///
////////////////////////////////////////////////////////////
void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
////////////////////////////////////////////////////////////
/// Create the image from the current contents of the
/// given window
///
/// \param Window : Window to capture
/// \param SourceRect : Sub-rectangle of the screen to copy (empty by default - entire image)
///
/// \return True if copy was successful
///
////////////////////////////////////////////////////////////
bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
////////////////////////////////////////////////////////////
/// Change the color of a pixel
///
/// \param X : X coordinate of pixel in the image
/// \param Y : Y coordinate of pixel in the image
/// \param Col : New color for pixel (X, Y)
///
////////////////////////////////////////////////////////////
void SetPixel(unsigned int X, unsigned int Y, const Color& Col);
////////////////////////////////////////////////////////////
/// Get a pixel from the image
///
/// \param X : X coordinate of pixel in the image
/// \param Y : Y coordinate of pixel in the image
///
/// \return Color of pixel (X, Y)
///
////////////////////////////////////////////////////////////
const Color& GetPixel(unsigned int X, unsigned int Y) const;
////////////////////////////////////////////////////////////
/// Get a read-only pointer to the array of pixels (RGBA 8 bits integers components)
/// Array size is GetWidth() x GetHeight() x 4
/// This pointer becomes invalid if you reload or resize the image
///
/// \return Const pointer to the array of pixels
///
////////////////////////////////////////////////////////////
const Uint8* GetPixelsPtr() const;
////////////////////////////////////////////////////////////
/// Bind the image for rendering
///
////////////////////////////////////////////////////////////
void Bind() const;
////////////////////////////////////////////////////////////
/// Enable or disable image smooth filter.
/// This parameter is enabled by default
///
/// \param Smooth : True to enable smoothing filter, false to disable it
///
////////////////////////////////////////////////////////////
void SetSmooth(bool Smooth);
////////////////////////////////////////////////////////////
/// Return the width of the image
///
/// \return Width in pixels
///
////////////////////////////////////////////////////////////
unsigned int GetWidth() const;
////////////////////////////////////////////////////////////
/// Return the height of the image
///
/// \return Height in pixels
///
////////////////////////////////////////////////////////////
unsigned int GetHeight() const;
////////////////////////////////////////////////////////////
/// Tells whether the smooth filtering is enabled or not
///
/// \return True if image smoothing is enabled
///
////////////////////////////////////////////////////////////
bool IsSmooth() const;
////////////////////////////////////////////////////////////
/// Convert a subrect expressed in pixels, into float
/// texture coordinates
///
/// \param Rect : Sub-rectangle of image to convert
/// \param Adjust : Pass true to apply the half-texel adjustment
///
/// \return Texture coordinates corresponding to the sub-rectangle
///
////////////////////////////////////////////////////////////
FloatRect GetTexCoords(const IntRect& Rect, bool Adjust = true) const;
////////////////////////////////////////////////////////////
/// Get a valid texture size according to hardware support
///
/// \param Size : Size to convert
///
/// \return Valid nearest size (greater than or equal to specified size)
///
////////////////////////////////////////////////////////////
static unsigned int GetValidTextureSize(unsigned int Size);
////////////////////////////////////////////////////////////
/// Assignment operator
///
/// \param Other : instance to assign
///
/// \return Reference to the image
///
////////////////////////////////////////////////////////////
Image& operator =(const Image& Other);
private :
friend class RenderImage;
////////////////////////////////////////////////////////////
/// Create the OpenGL texture
///
/// \return True if texture has been successfully created
///
////////////////////////////////////////////////////////////
bool CreateTexture();
////////////////////////////////////////////////////////////
/// Make sure the texture in video memory is updated with the
/// array of pixels
////////////////////////////////////////////////////////////
void EnsureTextureUpdate() const;
////////////////////////////////////////////////////////////
/// Make sure the array of pixels is updated with the
/// texture in video memory
////////////////////////////////////////////////////////////
void EnsureArrayUpdate() const;
////////////////////////////////////////////////////////////
/// Reset the image attributes
///
////////////////////////////////////////////////////////////
void Reset();
////////////////////////////////////////////////////////////
/// Destroy the OpenGL texture
///
////////////////////////////////////////////////////////////
void DestroyTexture();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int myWidth; ///< Image width
unsigned int myHeight; ///< Image Height
unsigned int myTextureWidth; ///< Actual texture width (can be greater than image width because of padding)
unsigned int myTextureHeight; ///< Actual texture height (can be greater than image height because of padding)
unsigned int myTexture; ///< Internal texture identifier
bool myIsSmooth; ///< Status of the smooth filter
mutable std::vector<Color> myPixels; ///< Pixels of the image
mutable bool myNeedTextureUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory
mutable bool myNeedArrayUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory
};
} // namespace sf
#endif // SFML_IMAGE_HPP

View file

@ -0,0 +1,148 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_MATRIX3_HPP
#define SFML_MATRIX3_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/System/Vector2.hpp>
#include <math.h>
namespace sf
{
////////////////////////////////////////////////////////////
/// Utility class to manipulate 3x3 matrices representing
/// 2D transformations
////////////////////////////////////////////////////////////
class SFML_API Matrix3
{
public :
////////////////////////////////////////////////////////////
/// Default constructor (builds an identity matrix)
///
////////////////////////////////////////////////////////////
Matrix3();
////////////////////////////////////////////////////////////
/// Construct a matrix from its 9 elements
///
////////////////////////////////////////////////////////////
Matrix3(float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22);
////////////////////////////////////////////////////////////
/// Build a matrix from a set of transformations
///
/// \param Center : Origin for the transformations
/// \param Translation : Translation offset
/// \param Rotation : Rotation angle in degrees
/// \param Scale : Scaling factors
///
////////////////////////////////////////////////////////////
void SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale);
////////////////////////////////////////////////////////////
/// Transform a point by the matrix
///
/// \param Point : Point to transform
///
/// \return Transformed point
///
////////////////////////////////////////////////////////////
Vector2f Transform(const Vector2f& Point) const;
////////////////////////////////////////////////////////////
/// Return the inverse of the matrix
///
/// \return A new matrix which is the inverse of this
///
////////////////////////////////////////////////////////////
Matrix3 GetInverse() const;
////////////////////////////////////////////////////////////
/// Return the elements of the matrix as a 4x4,
/// in an array of 16 floats
///
/// \return Pointer to the 4x4 matrix elements
///
////////////////////////////////////////////////////////////
const float* Get4x4Elements() const;
////////////////////////////////////////////////////////////
/// Operator () overloads to access the matrix elements
///
/// \param Row : Element row (0 based)
/// \param Col : Element column (0 based)
///
/// \return Matrix element (Row, Col)
///
////////////////////////////////////////////////////////////
float operator ()(unsigned int Row, unsigned int Col) const;
float& operator ()(unsigned int Row, unsigned int Col);
////////////////////////////////////////////////////////////
/// Operator * overload to multiply two matrices
///
/// \param Mat : Matrix to multiply
///
/// \return this * Mat
///
////////////////////////////////////////////////////////////
Matrix3 operator *(const Matrix3& Mat) const;
////////////////////////////////////////////////////////////
/// Operator *= overload to multiply-assign two matrices
///
/// \param Mat : Matrix to multiply
///
/// \return this * Mat
///
////////////////////////////////////////////////////////////
Matrix3& operator *=(const Matrix3& Mat);
////////////////////////////////////////////////////////////
// Static member data
////////////////////////////////////////////////////////////
static const Matrix3 Identity; ///< Identity matrix
private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
float myData[16]; /// Matrix elements (we directly store it as a 4x4 matrix for optimization purpose)
};
#include <SFML/Graphics/Matrix3.inl>
} // namespace sf
#endif // SFML_MATRIX3_HPP

View file

@ -0,0 +1,186 @@
////////////////////////////////////////////////////////////
//
// SFGE - Simple and Fast Game Engine
// Copyright (C) 2007-2008 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.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// Default constructor (builds an identity matrix)
////////////////////////////////////////////////////////////
inline Matrix3::Matrix3()
{
myData[0] = 1.f; myData[4] = 0.f; myData[8] = 0.f; myData[12] = 0.f;
myData[1] = 0.f; myData[5] = 1.f; myData[9] = 0.f; myData[13] = 0.f;
myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;
myData[3] = 0.f; myData[7] = 0.f; myData[11] = 0.f; myData[15] = 1.f;
}
////////////////////////////////////////////////////////////
/// Construct a matrix from its 9 elements
////////////////////////////////////////////////////////////
inline Matrix3::Matrix3(float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22)
{
myData[0] = a00; myData[4] = a01; myData[8] = 0.f; myData[12] = a02;
myData[1] = a10; myData[5] = a11; myData[9] = 0.f; myData[13] = a12;
myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;
myData[3] = a20; myData[7] = a21; myData[11] = 0.f; myData[15] = a22;
}
////////////////////////////////////////////////////////////
/// Build a matrix from a set of transformations
////////////////////////////////////////////////////////////
inline void Matrix3::SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale)
{
float Angle = Rotation * 3.141592654f / 180.f;
float Cos = static_cast<float>(cos(Angle));
float Sin = static_cast<float>(sin(Angle));
float SxCos = Scale.x * Cos;
float SyCos = Scale.y * Cos;
float SxSin = Scale.x * Sin;
float SySin = Scale.y * Sin;
float Tx = -Center.x * SxCos - Center.y * SySin + Translation.x;
float Ty = Center.x * SxSin - Center.y * SyCos + Translation.y;
myData[0] = SxCos; myData[4] = SySin; myData[8] = 0.f; myData[12] = Tx;
myData[1] = -SxSin; myData[5] = SyCos; myData[9] = 0.f; myData[13] = Ty;
myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;
myData[3] = 0.f; myData[7] = 0.f; myData[11] = 0.f; myData[15] = 1.f;
}
////////////////////////////////////////////////////////////
/// Transform a point by the matrix
////////////////////////////////////////////////////////////
inline Vector2f Matrix3::Transform(const Vector2f& Point) const
{
return Vector2f(myData[0] * Point.x + myData[4] * Point.y + myData[12],
myData[1] * Point.x + myData[5] * Point.y + myData[13]);
}
////////////////////////////////////////////////////////////
/// Return the inverse of the matrix
////////////////////////////////////////////////////////////
inline Matrix3 Matrix3::GetInverse() const
{
// Compute the determinant
float Det = myData[0] * (myData[15] * myData[5] - myData[7] * myData[13]) -
myData[1] * (myData[15] * myData[4] - myData[7] * myData[12]) +
myData[3] * (myData[13] * myData[4] - myData[5] * myData[12]);
// Compute the inverse if determinant is not zero
if ((Det < -1E-7f) || (Det > 1E-7f))
{
return Matrix3( (myData[15] * myData[5] - myData[7] * myData[13]) / Det,
-(myData[15] * myData[4] - myData[7] * myData[12]) / Det,
(myData[13] * myData[4] - myData[5] * myData[12]) / Det,
-(myData[15] * myData[1] - myData[3] * myData[13]) / Det,
(myData[15] * myData[0] - myData[3] * myData[12]) / Det,
-(myData[13] * myData[0] - myData[1] * myData[12]) / Det,
(myData[7] * myData[1] - myData[3] * myData[5]) / Det,
-(myData[7] * myData[0] - myData[3] * myData[4]) / Det,
(myData[5] * myData[0] - myData[1] * myData[4]) / Det);
}
else
{
return Identity;
}
}
////////////////////////////////////////////////////////////
/// Return the elements of the matrix as a 4x4,
/// in an array of 16 floats
////////////////////////////////////////////////////////////
inline const float* Matrix3::Get4x4Elements() const
{
return myData;
}
////////////////////////////////////////////////////////////
/// Operator () overloads to access the matrix elements
////////////////////////////////////////////////////////////
inline float Matrix3::operator ()(unsigned int Row, unsigned int Col) const
{
switch (Row + Col * 3)
{
case 0 : return myData[0];
case 1 : return myData[1];
case 2 : return myData[3];
case 3 : return myData[4];
case 4 : return myData[5];
case 5 : return myData[7];
case 6 : return myData[12];
case 7 : return myData[13];
case 8 : return myData[15];
default : return myData[0];
}
}
inline float& Matrix3::operator ()(unsigned int Row, unsigned int Col)
{
switch (Row + Col * 3)
{
case 0 : return myData[0];
case 1 : return myData[1];
case 2 : return myData[3];
case 3 : return myData[4];
case 4 : return myData[5];
case 5 : return myData[7];
case 6 : return myData[12];
case 7 : return myData[13];
case 8 : return myData[15];
default : return myData[0];
}
}
////////////////////////////////////////////////////////////
/// Operator * overload to multiply two matrices
////////////////////////////////////////////////////////////
inline Matrix3 Matrix3::operator *(const Matrix3& Mat) const
{
return Matrix3(myData[0] * Mat.myData[0] + myData[4] * Mat.myData[1] + myData[12] * Mat.myData[3],
myData[0] * Mat.myData[4] + myData[4] * Mat.myData[5] + myData[12] * Mat.myData[7],
myData[0] * Mat.myData[12] + myData[4] * Mat.myData[13] + myData[12] * Mat.myData[15],
myData[1] * Mat.myData[0] + myData[5] * Mat.myData[1] + myData[13] * Mat.myData[3],
myData[1] * Mat.myData[4] + myData[5] * Mat.myData[5] + myData[13] * Mat.myData[7],
myData[1] * Mat.myData[12] + myData[5] * Mat.myData[13] + myData[13] * Mat.myData[15],
myData[3] * Mat.myData[0] + myData[7] * Mat.myData[1] + myData[15] * Mat.myData[3],
myData[3] * Mat.myData[4] + myData[7] * Mat.myData[5] + myData[15] * Mat.myData[7],
myData[3] * Mat.myData[12] + myData[7] * Mat.myData[13] + myData[15] * Mat.myData[15]);
}
////////////////////////////////////////////////////////////
/// Operator *= overload to multiply-assign two matrices
////////////////////////////////////////////////////////////
inline Matrix3& Matrix3::operator *=(const Matrix3& Mat)
{
return *this = *this * Mat;
}

View file

@ -0,0 +1,194 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_POSTFX_HPP
#define SFML_POSTFX_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Image.hpp>
#include <istream>
#include <map>
#include <string>
namespace sf
{
////////////////////////////////////////////////////////////
/// PostFX is used to apply a post effect to a window
////////////////////////////////////////////////////////////
class SFML_API PostFX : public Drawable
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
PostFX();
////////////////////////////////////////////////////////////
/// Copy constructor
///
/// \param Copy : Instance to copy
///
////////////////////////////////////////////////////////////
PostFX(const PostFX& Copy);
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
~PostFX();
////////////////////////////////////////////////////////////
/// Load the effect from a file
///
/// \param Filename : Path of the effect file to load
///
/// \return True on success
///
////////////////////////////////////////////////////////////
bool LoadFromFile(const std::string& Filename);
////////////////////////////////////////////////////////////
/// Load the effect from a text in memory
///
/// \param Effect : String containing the effect code
///
/// \return True on success
///
////////////////////////////////////////////////////////////
bool LoadFromMemory(const std::string& Effect);
////////////////////////////////////////////////////////////
/// Change a parameter of the effect (1 float)
///
/// \param Name : Parameter name in the effect
/// \param X : Value to assign
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& Name, float X);
////////////////////////////////////////////////////////////
/// Change a parameter of the effect (2 floats)
///
/// \param Name : Parameter name in the effect
/// \param X, Y : Values to assign
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& Name, float X, float Y);
////////////////////////////////////////////////////////////
/// Change a parameter of the effect (3 floats)
///
/// \param Name : Parameter name in the effect
/// \param X, Y, Z : Values to assign
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& Name, float X, float Y, float Z);
////////////////////////////////////////////////////////////
/// Change a parameter of the effect (4 floats)
///
/// \param Name : Parameter name in the effect
/// \param X, Y, Z, W : Values to assign
///
////////////////////////////////////////////////////////////
void SetParameter(const std::string& Name, float X, float Y, float Z, float W);
////////////////////////////////////////////////////////////
/// Set a texture parameter
///
/// \param Name : Texture name in the effect
/// \param Texture : Image to set (pass NULL to use content of current framebuffer)
///
////////////////////////////////////////////////////////////
void SetTexture(const std::string& Name, Image* Texture);
////////////////////////////////////////////////////////////
/// Assignment operator
///
/// \param Other : Instance to assign
///
/// \return Reference to the post-effect
///
////////////////////////////////////////////////////////////
PostFX& operator =(const PostFX& Other);
////////////////////////////////////////////////////////////
/// Tell whether or not the system supports post-effects
///
/// \return True if the system can use post-effects
///
////////////////////////////////////////////////////////////
static bool CanUsePostFX();
protected :
////////////////////////////////////////////////////////////
/// /see Drawable::Render
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const;
private :
////////////////////////////////////////////////////////////
/// Preprocess a SFML effect file
/// to convert it to a valid GLSL fragment shader
///
/// \param File : Stream containing the code to process
///
/// \return Valid fragment shader source code
///
////////////////////////////////////////////////////////////
static std::string PreprocessEffect(std::istream& File);
////////////////////////////////////////////////////////////
/// Create the program and attach the shaders
///
////////////////////////////////////////////////////////////
void CreateProgram();
////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////
typedef std::map<std::string, const Image*> TextureTable;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
unsigned int myShaderProgram; ///< OpenGL identifier for the program
TextureTable myTextures; ///< Texture variables in the effect
std::string myFragmentShader; ///< Fragment shader source code
mutable Image myFrameBuffer; ///< Texture containing the current frame buffer
};
} // namespace sf
#endif // SFML_POSTFX_HPP

View file

@ -0,0 +1,127 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_RECT_HPP
#define SFML_RECT_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <algorithm>
namespace sf
{
////////////////////////////////////////////////////////////
/// Rect is an utility class for manipulating rectangles.
/// Template parameter defines the type of coordinates (integer, float, ...)
////////////////////////////////////////////////////////////
template <typename T>
class Rect
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Rect();
////////////////////////////////////////////////////////////
/// Construct the rectangle from its coordinates
///
/// \param LeftCoord : Left coordinate of the rectangle
/// \param TopCoord : Top coordinate of the rectangle
/// \param RightCoord : Right coordinate of the rectangle
/// \param BottomCoord : Bottom coordinate of the rectangle
///
////////////////////////////////////////////////////////////
Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord);
////////////////////////////////////////////////////////////
/// Get the width of the rectangle
///
/// \return Width of rectangle
///
////////////////////////////////////////////////////////////
T GetWidth() const;
////////////////////////////////////////////////////////////
/// Get the height of the rectangle
///
/// \return Height of rectangle
///
////////////////////////////////////////////////////////////
T GetHeight() const;
////////////////////////////////////////////////////////////
/// Move the whole rectangle by the given offset
///
/// \param OffsetX : Horizontal offset
/// \param OffsetY : Vertical offset
///
////////////////////////////////////////////////////////////
void Offset(T OffsetX, T OffsetY);
////////////////////////////////////////////////////////////
/// Check if a point is inside the rectangle's area
///
/// \param X : X coordinate of the point to test
/// \param Y : Y coordinate of the point to test
///
/// \return True if the point is inside
///
////////////////////////////////////////////////////////////
bool Contains(T X, T Y) const;
////////////////////////////////////////////////////////////
/// Check intersection between two rectangles
///
/// \param Rectangle : Rectangle to test
/// \param OverlappingRect : Rectangle to be filled with overlapping rect (NULL by default)
///
/// \return True if rectangles overlap
///
////////////////////////////////////////////////////////////
bool Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect = NULL) const;
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
T Left; ///< Left coordinate of the rectangle
T Top; ///< Top coordinate of the rectangle
T Right; ///< Right coordinate of the rectangle
T Bottom; ///< Bottom coordinate of the rectangle
};
#include <SFML/Graphics/Rect.inl>
// Define the most common types
typedef Rect<int> IntRect;
typedef Rect<float> FloatRect;
} // namespace sf
#endif // SFML_RECT_HPP

View file

@ -0,0 +1,122 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// Default constructor
////////////////////////////////////////////////////////////
template <typename T>
Rect<T>::Rect() :
Left (0),
Top (0),
Right (0),
Bottom(0)
{
}
////////////////////////////////////////////////////////////
/// Construct the color from its coordinates
////////////////////////////////////////////////////////////
template <typename T>
Rect<T>::Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord) :
Left (LeftCoord),
Top (TopCoord),
Right (RightCoord),
Bottom(BottomCoord)
{
}
////////////////////////////////////////////////////////////
/// Get the width of the rectangle
////////////////////////////////////////////////////////////
template <typename T>
T Rect<T>::GetWidth() const
{
return Right - Left;
}
////////////////////////////////////////////////////////////
/// Get the height of the rectangle
////////////////////////////////////////////////////////////
template <typename T>
T Rect<T>::GetHeight() const
{
return Bottom - Top;
}
////////////////////////////////////////////////////////////
/// Move the whole rectangle by the given offset
////////////////////////////////////////////////////////////
template <typename T>
void Rect<T>::Offset(T OffsetX, T OffsetY)
{
Left += OffsetX;
Right += OffsetX;
Top += OffsetY;
Bottom += OffsetY;
}
////////////////////////////////////////////////////////////
/// Check if a point is inside the rectangle's area
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::Contains(T X, T Y) const
{
return (X >= Left) && (X <= Right) && (Y >= Top) && (Y <= Bottom);
}
////////////////////////////////////////////////////////////
/// Check intersection between two rectangles
////////////////////////////////////////////////////////////
template <typename T>
bool Rect<T>::Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect) const
{
// Compute overlapping rect
Rect Overlapping(std::max(Left, Rectangle.Left),
std::max(Top, Rectangle.Top),
std::min(Right, Rectangle.Right),
std::min(Bottom, Rectangle.Bottom));
// If overlapping rect is valid, then there is intersection
if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom))
{
if (OverlappingRect)
*OverlappingRect = Overlapping;
return true;
}
else
{
if (OverlappingRect)
*OverlappingRect = Rect(0, 0, 0, 0);
return false;
}
}

View file

@ -0,0 +1,166 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_RENDERTARGET_HPP
#define SFML_RENDERTARGET_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/View.hpp>
#include <SFML/Graphics/Rect.hpp>
namespace sf
{
class Drawable;
////////////////////////////////////////////////////////////
/// Base class for all render targets (window, image, ...)
////////////////////////////////////////////////////////////
class SFML_API RenderTarget
{
public :
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
virtual ~RenderTarget();
////////////////////////////////////////////////////////////
/// Clear the entire target with a single color
///
/// \param FillColor : Color to use to clear the render target
///
////////////////////////////////////////////////////////////
void Clear(const Color& FillColor = Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Draw something into the target
///
/// \param Object : Object to draw
///
////////////////////////////////////////////////////////////
virtual void Draw(const Drawable& Object);
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of the target
///
/// \return Width in pixels
///
////////////////////////////////////////////////////////////
virtual unsigned int GetWidth() const = 0;
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of the target
///
/// \return Height in pixels
///
////////////////////////////////////////////////////////////
virtual unsigned int GetHeight() const = 0;
////////////////////////////////////////////////////////////
/// Change the current active view.
///
/// \param NewView : New view to use (pass GetDefaultView() to set the default view)
///
////////////////////////////////////////////////////////////
void SetView(const View& NewView);
////////////////////////////////////////////////////////////
/// Get the current view
///
/// \return Current view active in the window
///
////////////////////////////////////////////////////////////
const View& GetView() const;
////////////////////////////////////////////////////////////
/// Get the default view of the window for read / write
///
/// \return Default view
///
////////////////////////////////////////////////////////////
View& GetDefaultView();
////////////////////////////////////////////////////////////
/// Tell SFML to preserve external OpenGL states, at the expense of
/// more CPU charge. Use this function if you don't want SFML
/// to mess up your own OpenGL states (if any).
/// Don't enable state preservation if not needed, as it will allow
/// SFML to do internal optimizations and improve performances.
/// This parameter is false by default
///
/// \param Preserve : True to preserve OpenGL states, false to let SFML optimize
///
////////////////////////////////////////////////////////////
void PreserveOpenGLStates(bool Preserve);
protected :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
RenderTarget();
////////////////////////////////////////////////////////////
/// Called by the derived class when it's ready to be initialized
///
////////////////////////////////////////////////////////////
void Initialize();
private :
////////////////////////////////////////////////////////////
/// Activate the target for rendering
///
/// \param Active : True to activate rendering, false to deactivate
///
/// \return True if activation succeeded
///
////////////////////////////////////////////////////////////
virtual bool Activate(bool Active) = 0;
////////////////////////////////////////////////////////////
/// Set the OpenGL render states needed for the SFML rendering
///
////////////////////////////////////////////////////////////
void SetRenderStates();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
View myDefaultView; ///< Default view
const View* myCurrentView; ///< Current active view
bool myPreserveStates; ///< Should we preserve external OpenGL states ?
bool myIsDrawing; ///< True when Draw is called from inside, to allow some renderstates optimizations
};
} // namespace sf
#endif // SFML_RENDERTARGET_HPP

View file

@ -0,0 +1,135 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_RENDERWINDOW_HPP
#define SFML_RENDERWINDOW_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Window/Window.hpp>
#include <string>
namespace sf
{
class Drawable;
////////////////////////////////////////////////////////////
/// Simple wrapper for sf::Window that allows easy
/// 2D rendering
////////////////////////////////////////////////////////////
class SFML_API RenderWindow : public Window, public RenderTarget
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
RenderWindow();
////////////////////////////////////////////////////////////
/// Construct the window
///
/// \param Mode : Video mode to use
/// \param Title : Title of the window
/// \param WindowStyle : Window style (Resize | Close by default)
/// \param Params : Creation parameters (see default constructor for default values)
///
////////////////////////////////////////////////////////////
RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
////////////////////////////////////////////////////////////
/// Construct the window from an existing control
///
/// \param Handle : Platform-specific handle of the control
/// \param Params : Creation parameters (see default constructor for default values)
///
////////////////////////////////////////////////////////////
RenderWindow(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
////////////////////////////////////////////////////////////
/// Destructor
///
////////////////////////////////////////////////////////////
virtual ~RenderWindow();
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of the window
///
/// \return Width in pixels
///
////////////////////////////////////////////////////////////
virtual unsigned int GetWidth() const;
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of the window
///
/// \return Height in pixels
///
////////////////////////////////////////////////////////////
virtual unsigned int GetHeight() const;
////////////////////////////////////////////////////////////
/// Save the content of the window to an image
///
/// \return Image instance containing the contents of the screen
///
////////////////////////////////////////////////////////////
Image Capture() const;
////////////////////////////////////////////////////////////
/// Convert a point in window coordinates into view coordinates
///
/// \param WindowX : X coordinate of the point to convert, relative to the window
/// \param WindowY : Y coordinate of the point to convert, relative to the window
/// \param TargetView : Target view to convert the point to (NULL by default -- uses the current view)
///
/// \return Converted point
///
////////////////////////////////////////////////////////////
sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View* TargetView = NULL) const;
private :
////////////////////////////////////////////////////////////
/// /see Window::OnCreate
///
////////////////////////////////////////////////////////////
virtual void OnCreate();
////////////////////////////////////////////////////////////
/// /see RenderTarget::Activate
///
////////////////////////////////////////////////////////////
virtual bool Activate(bool Active);
};
} // namespace sf
#endif // SFML_RENDERWINDOW_HPP

View file

@ -0,0 +1,310 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_SHAPE_HPP
#define SFML_SHAPE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/System/Vector2.hpp>
#include <vector>
namespace sf
{
////////////////////////////////////////////////////////////
/// Shape defines a drawable convex shape ; it also defines
/// helper functions to draw simple shapes like
/// lines, rectangles, circles, etc.
////////////////////////////////////////////////////////////
class SFML_API Shape : public sf::Drawable
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Shape();
////////////////////////////////////////////////////////////
/// Add a point to the shape
///
/// \param X, Y : Position of the point
/// \param Col : Color of the point (white by default)
/// \param OutlineCol : Outline color of the point (black by default)
///
////////////////////////////////////////////////////////////
void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Add a point to the shape
///
/// \param Position : Position of the point
/// \param Col : Color of the point (white by default)
/// \param OutlineCol : Outline color of the point (black by default)
///
////////////////////////////////////////////////////////////
void AddPoint(const Vector2f& Position, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Get the number of points composing the shape
///
/// \param Total number of points
///
////////////////////////////////////////////////////////////
unsigned int GetNbPoints() const;
////////////////////////////////////////////////////////////
/// Enable or disable filling the shape.
/// Fill is enabled by default
///
/// \param Enable : True to enable, false to disable
///
////////////////////////////////////////////////////////////
void EnableFill(bool Enable);
////////////////////////////////////////////////////////////
/// Enable or disable drawing the shape outline.
/// Outline is enabled by default
///
/// \param Enable : True to enable, false to disable
///
////////////////////////////////////////////////////////////
void EnableOutline(bool Enable);
////////////////////////////////////////////////////////////
/// Set the position of a point
///
/// \param Index : Index of the point, in range [0, GetNbPoints() - 1]
/// \param Position : New position of the Index-th point
///
////////////////////////////////////////////////////////////
void SetPointPosition(unsigned int Index, const Vector2f& Position);
////////////////////////////////////////////////////////////
/// Set the position of a point
///
/// \param Index : Index of the point, in range [0, GetNbPoints() - 1]
/// \param X : New X coordinate of the Index-th point
/// \param Y : New Y coordinate of the Index-th point
///
////////////////////////////////////////////////////////////
void SetPointPosition(unsigned int Index, float X, float Y);
////////////////////////////////////////////////////////////
/// Set the color of a point
///
/// \param Index : Index of the point, in range [0, GetNbPoints() - 1]
/// \param Col : New color of the Index-th point
///
////////////////////////////////////////////////////////////
void SetPointColor(unsigned int Index, const Color& Col);
////////////////////////////////////////////////////////////
/// Set the outline color of a point
///
/// \param Index : Index of the point, in range [0, GetNbPoints() - 1]
/// \param OutlineCol : New outline color of the Index-th point
///
////////////////////////////////////////////////////////////
void SetPointOutlineColor(unsigned int Index, const Color& OutlineCol);
////////////////////////////////////////////////////////////
/// Change the width of the shape outline
///
/// \param Width : New width
///
////////////////////////////////////////////////////////////
void SetOutlineWidth(float Width);
////////////////////////////////////////////////////////////
/// Get the position of a point
///
/// \param Index : Index of the point, in range [0, GetNbPoints() - 1]
///
/// \return Position of the Index-th point
///
////////////////////////////////////////////////////////////
const Vector2f& GetPointPosition(unsigned int Index) const;
////////////////////////////////////////////////////////////
/// Get the color of a point
///
/// \param Index : Index of the point, in range [0, GetNbPoints() - 1]
///
/// \return Color of the Index-th point
///
////////////////////////////////////////////////////////////
const Color& GetPointColor(unsigned int Index) const;
////////////////////////////////////////////////////////////
/// Get the outline color of a point
///
/// \param Index : Index of the point, in range [0, GetNbPoints() - 1]
///
/// \return Outline color of the Index-th point
///
////////////////////////////////////////////////////////////
const Color& GetPointOutlineColor(unsigned int Index) const;
////////////////////////////////////////////////////////////
/// Get the width of the shape outline
///
/// \return Current outline width
///
////////////////////////////////////////////////////////////
float GetOutlineWidth() const;
////////////////////////////////////////////////////////////
/// Create a shape made of a single line (use floats)
///
/// \param P1X, P1Y : Position of the first point
/// \param P2X, P2Y : Position second point
/// \param Thickness : Line thickness
/// \param Col : Color used to draw the line
/// \param Outline : Outline width (0 by default)
/// \param OutlineCol : Color used to draw the outline (black by default)
///
////////////////////////////////////////////////////////////
static Shape Line(float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Create a shape made of a single line (use vectors)
///
/// \param P1X, P1Y : Position of the first point
/// \param P2X, P2Y : Position second point
/// \param Thickness : Line thickness
/// \param Col : Color used to draw the line
/// \param Outline : Outline width (0 by default)
/// \param OutlineCol : Color used to draw the outline (black by default)
///
////////////////////////////////////////////////////////////
static Shape Line(const Vector2f& P1, const Vector2f& P2, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Create a shape made of a single rectangle (use floats)
///
/// \param P1X, P1Y : Position of the first point
/// \param P2X, P2Y : Position second point
/// \param Col : Color used to fill the rectangle
/// \param Outline : Outline width (0 by default)
/// \param OutlineCol : Color used to draw the outline (black by default)
///
////////////////////////////////////////////////////////////
static Shape Rectangle(float P1X, float P1Y, float P2X, float P2Y, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Create a shape made of a single rectangle (use vectors)
///
/// \param P1 : Position of the first point
/// \param P2 : Position second point
/// \param Col : Color used to fill the rectangle
/// \param Outline : Outline width (0 by default)
/// \param OutlineCol : Color used to draw the outline (black by default)
///
////////////////////////////////////////////////////////////
static Shape Rectangle(const Vector2f& P1, const Vector2f& P2, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Create a shape made of a single circle (use floats)
///
/// \param X, Y : Position of the center
/// \param Radius : Radius
/// \param Col : Color used to fill the circle
/// \param Outline : Outline width (0 by default)
/// \param OutlineCol : Color used to draw the outline (black by default)
///
////////////////////////////////////////////////////////////
static Shape Circle(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
////////////////////////////////////////////////////////////
/// Create a shape made of a single circle (use vectors)
///
/// \param Center : Position of the center
/// \param Radius : Radius
/// \param Col : Color used to fill the circle
/// \param Outline : Outline width (0 by default)
/// \param OutlineCol : Color used to draw the outline (black by default)
///
////////////////////////////////////////////////////////////
static Shape Circle(const Vector2f& Center, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
protected :
////////////////////////////////////////////////////////////
/// /see Drawable::Render
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const;
private :
////////////////////////////////////////////////////////////
/// Compile the shape : compute its center and its outline
///
////////////////////////////////////////////////////////////
void Compile();
////////////////////////////////////////////////////////////
/// Compute the normal of a given 2D segment
///
/// \param P1 : First point of the segment
/// \param P2 : Second point of the segment
/// \param Normal : Calculated normal
///
/// \return False if the normal couldn't be calculated (segment is null)
///
////////////////////////////////////////////////////////////
static bool ComputeNormal(const Vector2f& P1, const Vector2f& P2, Vector2f& Normal);
////////////////////////////////////////////////////////////
/// Defines a simple 2D point
////////////////////////////////////////////////////////////
struct Point
{
Point(const Vector2f& Pos = Vector2f(0, 0), const Color& C = Color(255, 255, 255), const Color& OutlineC = Color(255, 255, 255));
Vector2f Position; ///< Position
Vector2f Normal; ///< Extruded normal
Color Col; ///< Color of the point
Color OutlineCol; ///< Outline color of the point
};
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
std::vector<Point> myPoints; ///< Points composing the shape
float myOutline; ///< Outline width
bool myIsFillEnabled; ///< Should we draw the inside if the shape ?
bool myIsOutlineEnabled; ///< Should we draw the outline if the shape ?
bool myIsCompiled; ///< Compiled state of the shape
};
} // namespace sf
#endif // SFML_SHAPE_HPP

View file

@ -0,0 +1,176 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_SPRITE_HPP
#define SFML_SPRITE_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Resource.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Rect.hpp>
namespace sf
{
class Image;
////////////////////////////////////////////////////////////
/// Sprite defines a sprite : texture, transformations,
/// color, and draw on screen
////////////////////////////////////////////////////////////
class SFML_API Sprite : public Drawable
{
public :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Sprite();
////////////////////////////////////////////////////////////
/// Construct the sprite from a source image
///
/// \param Img : Image of the sprite
/// \param Position : Position of the sprite (0, 0 by default)
/// \param Scale : Scale factor (1, 1 by default)
/// \param Rotation : Orientation, in degrees (0 by default)
/// \param Col : Color of the sprite (white by default)
///
////////////////////////////////////////////////////////////
Sprite(const Image& Img, const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));
////////////////////////////////////////////////////////////
/// Change the image of the sprite
///
/// \param Img : New image
///
////////////////////////////////////////////////////////////
void SetImage(const Image& Img);
////////////////////////////////////////////////////////////
/// Set the sub-rectangle of the sprite inside the source image.
/// By default, the subrect covers the entire source image
///
/// \param SubRect : New sub-rectangle
///
////////////////////////////////////////////////////////////
void SetSubRect(const IntRect& SubRect);
////////////////////////////////////////////////////////////
/// Resize the sprite (by changing its scale factors) (take 2 values).
/// The default size is defined by the subrect
///
/// \param Width : New width (must be strictly positive)
/// \param Height : New height (must be strictly positive)
///
////////////////////////////////////////////////////////////
void Resize(float Width, float Height);
////////////////////////////////////////////////////////////
/// Resize the sprite (by changing its scale factors) (take a 2D vector).
/// The default size is defined by the subrect
///
/// \param Size : New size (both coordinates must be strictly positive)
///
////////////////////////////////////////////////////////////
void Resize(const Vector2f& Size);
////////////////////////////////////////////////////////////
/// Flip the sprite horizontally
///
/// \param Flipped : True to flip the sprite
///
////////////////////////////////////////////////////////////
void FlipX(bool Flipped);
////////////////////////////////////////////////////////////
/// Flip the sprite vertically
///
/// \param Flipped : True to flip the sprite
///
////////////////////////////////////////////////////////////
void FlipY(bool Flipped);
////////////////////////////////////////////////////////////
/// Get the source image of the sprite
///
/// \return Pointer to the image (can be NULL)
///
////////////////////////////////////////////////////////////
const Image* GetImage() const;
////////////////////////////////////////////////////////////
/// Get the sub-rectangle of the sprite inside the source image
///
/// \return Sub-rectangle
///
////////////////////////////////////////////////////////////
const IntRect& GetSubRect() const;
////////////////////////////////////////////////////////////
/// Get the sprite size
///
/// \return Size of the sprite
///
////////////////////////////////////////////////////////////
Vector2f GetSize() const;
////////////////////////////////////////////////////////////
/// Get the color of a given pixel in the sprite
/// (point is in local coordinates)
///
/// \param X : X coordinate of the pixel to get
/// \param Y : Y coordinate of the pixel to get
///
/// \return Color of pixel (X, Y)
///
////////////////////////////////////////////////////////////
Color GetPixel(unsigned int X, unsigned int Y) const;
protected :
////////////////////////////////////////////////////////////
/// /see Drawable::Render
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const;
private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
ResourcePtr<Image> myImage; ///< Image used to draw the sprite
IntRect mySubRect; ///< Sub-rectangle of source image to assign to the sprite
bool myIsFlippedX; ///< Is the sprite flipped on the X axis ?
bool myIsFlippedY; ///< Is the sprite flipped on the Y axis ?
};
} // namespace sf
#endif // SFML_SPRITE_HPP

View file

@ -0,0 +1,191 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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/System/Resource.hpp>
#include <SFML/System/Unicode.hpp>
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <string>
namespace sf
{
////////////////////////////////////////////////////////////
/// String defines a graphical 2D text, that can be drawn on screen
////////////////////////////////////////////////////////////
class SFML_API String : public Drawable
{
public :
////////////////////////////////////////////////////////////
/// Enumerate the string drawing styles
////////////////////////////////////////////////////////////
enum Style
{
Regular = 0, ///< Regular characters, no style
Bold = 1 << 0, ///< Characters are bold
Italic = 1 << 1, ///< Characters are in italic
Underlined = 1 << 2 ///< Characters are underlined
};
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
String();
////////////////////////////////////////////////////////////
/// Construct the string from any kind of text
///
/// \param Text : Text assigned to the string
/// \param Font : Font used to draw the string (SFML built-in font by default)
/// \param Size : Characters size (30 by default)
///
////////////////////////////////////////////////////////////
explicit String(const Unicode::Text& Text, const Font& CharFont = Font::GetDefaultFont(), float Size = 30.f);
////////////////////////////////////////////////////////////
/// Set the text (from any kind of string)
///
/// \param Text : New text
///
////////////////////////////////////////////////////////////
void SetText(const Unicode::Text& Text);
////////////////////////////////////////////////////////////
/// Set the font of the string
///
/// \param Font : Font to use
///
////////////////////////////////////////////////////////////
void SetFont(const Font& CharFont);
////////////////////////////////////////////////////////////
/// Set the size of the string
/// The default size is 30
///
/// \param Size : New size, in pixels
///
////////////////////////////////////////////////////////////
void SetSize(float Size);
////////////////////////////////////////////////////////////
/// Set the style of the text
/// The default style is Regular
///
/// \param TextStyle : New text style, (combination of Style enum values)
///
////////////////////////////////////////////////////////////
void SetStyle(unsigned long TextStyle);
////////////////////////////////////////////////////////////
/// Get the text (the returned text can be converted implicitely to any kind of string)
///
/// \return String's text
///
////////////////////////////////////////////////////////////
const Unicode::Text& GetText() const;
////////////////////////////////////////////////////////////
/// Get the font used by the string
///
/// \return Font used
///
////////////////////////////////////////////////////////////
const Font& GetFont() const;
////////////////////////////////////////////////////////////
/// Get the size of the characters
///
/// \return Size of the characters
///
////////////////////////////////////////////////////////////
float GetSize() const;
////////////////////////////////////////////////////////////
/// Get the style of the text
///
/// \return Current string style (combination of Style enum values)
///
////////////////////////////////////////////////////////////
unsigned long GetStyle() const;
////////////////////////////////////////////////////////////
/// Return the visual position of the Index-th character of the string,
/// in coordinates relative to the string
/// (note : translation, center, rotation and scale are not applied)
///
/// \param Index : Index of the character
///
/// \return Position of the Index-th character (end of string if Index is out of range)
///
////////////////////////////////////////////////////////////
sf::Vector2f GetCharacterPos(std::size_t Index) const;
////////////////////////////////////////////////////////////
/// Get the string rectangle on screen
///
/// \return Rectangle contaning the string in screen coordinates
///
////////////////////////////////////////////////////////////
FloatRect GetRect() const;
protected :
////////////////////////////////////////////////////////////
/// /see Drawable::Render
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const;
private :
////////////////////////////////////////////////////////////
/// Recompute the bounding rectangle of the text
///
////////////////////////////////////////////////////////////
void RecomputeRect();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
Unicode::Text myText; ///< Text 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)
FloatRect myBaseRect; ///< Bounding rectangle of the text in object coordinates
bool myNeedRectUpdate; ///< Does the bounding rect need an update ?
};
} // namespace sf
#endif // SFML_STRING_HPP

View file

@ -0,0 +1,188 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 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_VIEW_HPP
#define SFML_VIEW_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Graphics/Matrix3.hpp>
#include <SFML/System/Vector2.hpp>
namespace sf
{
class RenderTarget;
////////////////////////////////////////////////////////////
/// This class defines a view (position, size, etc.) ;
/// you can consider it as a 2D camera
////////////////////////////////////////////////////////////
class SFML_API View
{
public :
////////////////////////////////////////////////////////////
/// Construct the view from a rectangle
///
/// \param ViewRect : Rectangle defining the position and size of the view (1000x1000 by default)
///
////////////////////////////////////////////////////////////
explicit View(const FloatRect& ViewRect = FloatRect(0, 0, 1000, 1000));
////////////////////////////////////////////////////////////
/// Construct the view from its center and half-size
///
/// \param Center : Center of the view
/// \param HalfSize : Half-size of the view (from center to corner)
///
////////////////////////////////////////////////////////////
View(const sf::Vector2f& Center, const sf::Vector2f& HalfSize);
////////////////////////////////////////////////////////////
/// Change the center of the view (take 2 values)
///
/// \param X : X coordinate of the new center
/// \param Y : Y coordinate of the new center
///
////////////////////////////////////////////////////////////
void SetCenter(float X, float Y);
////////////////////////////////////////////////////////////
/// Change the center of the view (take a vector)
///
/// \param Center : New center
///
////////////////////////////////////////////////////////////
void SetCenter(const sf::Vector2f& Center);
////////////////////////////////////////////////////////////
/// Change the half-size of the view (take 2 values)
///
/// \param HalfWidth : New half-width
/// \param HalfHeight : New half-height
///
////////////////////////////////////////////////////////////
void SetHalfSize(float HalfWidth, float HalfHeight);
////////////////////////////////////////////////////////////
/// Change the half-size of the view (take a vector)
///
/// \param HalfSize : New half-size
///
////////////////////////////////////////////////////////////
void SetHalfSize(const sf::Vector2f& HalfSize);
////////////////////////////////////////////////////////////
/// Rebuild the view from a rectangle
///
/// \param ViewRect : Rectangle defining the position and size of the view
///
////////////////////////////////////////////////////////////
void SetFromRect(const FloatRect& ViewRect);
////////////////////////////////////////////////////////////
/// Get the center of the view
///
/// \return Center of the view
///
////////////////////////////////////////////////////////////
const sf::Vector2f& GetCenter() const;
////////////////////////////////////////////////////////////
/// Get the half-size of the view
///
/// \return Half-size of the view
///
////////////////////////////////////////////////////////////
const sf::Vector2f& GetHalfSize() const;
////////////////////////////////////////////////////////////
/// Get the bounding rectangle of the view
///
/// \return Bounding rectangle of the view
///
////////////////////////////////////////////////////////////
const sf::FloatRect& GetRect() const;
////////////////////////////////////////////////////////////
/// Move the view (take 2 values)
///
/// \param OffsetX : Offset to move the view, on X axis
/// \param OffsetY : Offset to move the view, on Y axis
///
////////////////////////////////////////////////////////////
void Move(float OffsetX, float OffsetY);
////////////////////////////////////////////////////////////
/// Move the view (take a vector)
///
/// \param Offset : Offset to move the view
///
////////////////////////////////////////////////////////////
void Move(const sf::Vector2f& Offset);
////////////////////////////////////////////////////////////
/// Resize the view rectangle to simulate a zoom / unzoom effect
///
/// \param Factor : Zoom factor to apply, relative to the current zoom
///
////////////////////////////////////////////////////////////
void Zoom(float Factor);
private :
friend class RenderTarget;
////////////////////////////////////////////////////////////
/// Get the projection matrix of the view
///
/// \return Projection matrix containing the view settings
///
////////////////////////////////////////////////////////////
const Matrix3& GetMatrix() const;
////////////////////////////////////////////////////////////
/// Recompute the view rectangle and the projection matrix
///
////////////////////////////////////////////////////////////
void RecomputeMatrix();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
sf::Vector2f myCenter; ///< Center of the view
sf::Vector2f myHalfSize; ///< Half-size of the view
FloatRect myRect; ///< Rectangle defining the bounds of the view
Matrix3 myMatrix; ///< Precomputed projection matrix corresponding to the view
bool myNeedUpdate; ///< Internal state telling if the matrix needs to be updated
};
} // namespace sf
#endif // SFML_VIEW_HPP