mirror of
https://github.com/AntoineHX/LivingMachine.git
synced 2025-05-04 13:50:46 +02:00
Ajout de la bibli SFML (A)
This commit is contained in:
parent
73704e5139
commit
cca7498ca2
204 changed files with 26813 additions and 0 deletions
215
code/SFML-2.4.2/include/SFML/Graphics/BlendMode.hpp
Normal file
215
code/SFML-2.4.2/include/SFML/Graphics/BlendMode.hpp
Normal file
|
@ -0,0 +1,215 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_BLENDMODE_HPP
|
||||
#define SFML_BLENDMODE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Blending modes for drawing
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct SFML_GRAPHICS_API BlendMode
|
||||
{
|
||||
////////////////////////////////////////////////////////
|
||||
/// \brief Enumeration of the blending factors
|
||||
///
|
||||
/// The factors are mapped directly to their OpenGL equivalents,
|
||||
/// specified by glBlendFunc() or glBlendFuncSeparate().
|
||||
////////////////////////////////////////////////////////
|
||||
enum Factor
|
||||
{
|
||||
Zero, ///< (0, 0, 0, 0)
|
||||
One, ///< (1, 1, 1, 1)
|
||||
SrcColor, ///< (src.r, src.g, src.b, src.a)
|
||||
OneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
|
||||
DstColor, ///< (dst.r, dst.g, dst.b, dst.a)
|
||||
OneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
|
||||
SrcAlpha, ///< (src.a, src.a, src.a, src.a)
|
||||
OneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
|
||||
DstAlpha, ///< (dst.a, dst.a, dst.a, dst.a)
|
||||
OneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
/// \brief Enumeration of the blending equations
|
||||
///
|
||||
/// The equations are mapped directly to their OpenGL equivalents,
|
||||
/// specified by glBlendEquation() or glBlendEquationSeparate().
|
||||
////////////////////////////////////////////////////////
|
||||
enum Equation
|
||||
{
|
||||
Add, ///< Pixel = Src * SrcFactor + Dst * DstFactor
|
||||
Subtract, ///< Pixel = Src * SrcFactor - Dst * DstFactor
|
||||
ReverseSubtract ///< Pixel = Dst * DstFactor - Src * SrcFactor
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Constructs a blending mode that does alpha blending.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
BlendMode();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the blend mode given the factors and equation.
|
||||
///
|
||||
/// This constructor uses the same factors and equation for both
|
||||
/// color and alpha components. It also defaults to the Add equation.
|
||||
///
|
||||
/// \param sourceFactor Specifies how to compute the source factor for the color and alpha channels.
|
||||
/// \param destinationFactor Specifies how to compute the destination factor for the color and alpha channels.
|
||||
/// \param blendEquation Specifies how to combine the source and destination colors and alpha.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the blend mode given the factors and equation.
|
||||
///
|
||||
/// \param colorSourceFactor Specifies how to compute the source factor for the color channels.
|
||||
/// \param colorDestinationFactor Specifies how to compute the destination factor for the color channels.
|
||||
/// \param colorBlendEquation Specifies how to combine the source and destination colors.
|
||||
/// \param alphaSourceFactor Specifies how to compute the source factor.
|
||||
/// \param alphaDestinationFactor Specifies how to compute the destination factor.
|
||||
/// \param alphaBlendEquation Specifies how to combine the source and destination alphas.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor,
|
||||
Equation colorBlendEquation, Factor alphaSourceFactor,
|
||||
Factor alphaDestinationFactor, Equation alphaBlendEquation);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member Data
|
||||
////////////////////////////////////////////////////////////
|
||||
Factor colorSrcFactor; ///< Source blending factor for the color channels
|
||||
Factor colorDstFactor; ///< Destination blending factor for the color channels
|
||||
Equation colorEquation; ///< Blending equation for the color channels
|
||||
Factor alphaSrcFactor; ///< Source blending factor for the alpha channel
|
||||
Factor alphaDstFactor; ///< Destination blending factor for the alpha channel
|
||||
Equation alphaEquation; ///< Blending equation for the alpha channel
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates BlendMode
|
||||
/// \brief Overload of the == operator
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return True if blending modes are equal, false if they are different
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates BlendMode
|
||||
/// \brief Overload of the != operator
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return True if blending modes are different, false if they are equal
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Commonly used blending modes
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API extern const BlendMode BlendAlpha; ///< Blend source and dest according to dest alpha
|
||||
SFML_GRAPHICS_API extern const BlendMode BlendAdd; ///< Add source to dest
|
||||
SFML_GRAPHICS_API extern const BlendMode BlendMultiply; ///< Multiply source and dest
|
||||
SFML_GRAPHICS_API extern const BlendMode BlendNone; ///< Overwrite dest with source
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_BLENDMODE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::BlendMode
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::BlendMode is a class that represents a blend mode. A blend
|
||||
/// mode determines how the colors of an object you draw are
|
||||
/// mixed with the colors that are already in the buffer.
|
||||
///
|
||||
/// The class is composed of 6 components, each of which has its
|
||||
/// own public member variable:
|
||||
/// \li %Color Source Factor (@ref colorSrcFactor)
|
||||
/// \li %Color Destination Factor (@ref colorDstFactor)
|
||||
/// \li %Color Blend Equation (@ref colorEquation)
|
||||
/// \li Alpha Source Factor (@ref alphaSrcFactor)
|
||||
/// \li Alpha Destination Factor (@ref alphaDstFactor)
|
||||
/// \li Alpha Blend Equation (@ref alphaEquation)
|
||||
///
|
||||
/// The source factor specifies how the pixel you are drawing contributes
|
||||
/// to the final color. The destination factor specifies how the pixel
|
||||
/// already drawn in the buffer contributes to the final color.
|
||||
///
|
||||
/// The color channels RGB (red, green, blue; simply referred to as
|
||||
/// color) and A (alpha; the transparency) can be treated separately. This
|
||||
/// separation can be useful for specific blend modes, but most often you
|
||||
/// won't need it and will simply treat the color as a single unit.
|
||||
///
|
||||
/// The blend factors and equations correspond to their OpenGL equivalents.
|
||||
/// In general, the color of the resulting pixel is calculated according
|
||||
/// to the following formula (\a src is the color of the source pixel, \a dst
|
||||
/// the color of the destination pixel, the other variables correspond to the
|
||||
/// public members, with the equations being + or - operators):
|
||||
/// \code
|
||||
/// dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb
|
||||
/// dst.a = alphaSrcFactor * src.a (alphaEquation) alphaDstFactor * dst.a
|
||||
/// \endcode
|
||||
/// All factors and colors are represented as floating point numbers between
|
||||
/// 0 and 1. Where necessary, the result is clamped to fit in that range.
|
||||
///
|
||||
/// The most common blending modes are defined as constants
|
||||
/// in the sf namespace:
|
||||
///
|
||||
/// \code
|
||||
/// sf::BlendMode alphaBlending = sf::BlendAlpha;
|
||||
/// sf::BlendMode additiveBlending = sf::BlendAdd;
|
||||
/// sf::BlendMode multiplicativeBlending = sf::BlendMultiply;
|
||||
/// sf::BlendMode noBlending = sf::BlendNone;
|
||||
/// \endcode
|
||||
///
|
||||
/// In SFML, a blend mode can be specified every time you draw a sf::Drawable
|
||||
/// object to a render target. It is part of the sf::RenderStates compound
|
||||
/// that is passed to the member function sf::RenderTarget::draw().
|
||||
///
|
||||
/// \see sf::RenderStates, sf::RenderTarget
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
154
code/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp
Normal file
154
code/SFML-2.4.2/include/SFML/Graphics/CircleShape.hpp
Normal file
|
@ -0,0 +1,154 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_CIRCLESHAPE_HPP
|
||||
#define SFML_CIRCLESHAPE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialized shape representing a circle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API CircleShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// \param radius Radius of the circle
|
||||
/// \param pointCount Number of points composing the circle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit CircleShape(float radius = 0, std::size_t pointCount = 30);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the radius of the circle
|
||||
///
|
||||
/// \param radius New radius of the circle
|
||||
///
|
||||
/// \see getRadius
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setRadius(float radius);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the radius of the circle
|
||||
///
|
||||
/// \return Radius of the circle
|
||||
///
|
||||
/// \see setRadius
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getRadius() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the number of points of the circle
|
||||
///
|
||||
/// \param count New number of points of the circle
|
||||
///
|
||||
/// \see getPointCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setPointCount(std::size_t count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of points of the circle
|
||||
///
|
||||
/// \return Number of points of the circle
|
||||
///
|
||||
/// \see setPointCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual std::size_t getPointCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a point of the circle
|
||||
///
|
||||
/// The returned point is in local coordinates, that is,
|
||||
/// the shape's transforms (position, rotation, scale) are
|
||||
/// not taken into account.
|
||||
/// The result is undefined if \a index is out of the valid range.
|
||||
///
|
||||
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
||||
///
|
||||
/// \return index-th point of the shape
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2f getPoint(std::size_t index) const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
float m_radius; ///< Radius of the circle
|
||||
std::size_t m_pointCount; ///< Number of points composing the circle
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_CIRCLESHAPE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::CircleShape
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// This class inherits all the functions of sf::Transformable
|
||||
/// (position, rotation, scale, bounds, ...) as well as the
|
||||
/// functions of sf::Shape (outline, color, texture, ...).
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::CircleShape circle;
|
||||
/// circle.setRadius(150);
|
||||
/// circle.setOutlineColor(sf::Color::Red);
|
||||
/// circle.setOutlineThickness(5);
|
||||
/// circle.setPosition(10, 20);
|
||||
/// ...
|
||||
/// window.draw(circle);
|
||||
/// \endcode
|
||||
///
|
||||
/// Since the graphics card can't draw perfect circles, we have to
|
||||
/// fake them with multiple triangles connected to each other. The
|
||||
/// "points count" property of sf::CircleShape defines how many of these
|
||||
/// triangles to use, and therefore defines the quality of the circle.
|
||||
///
|
||||
/// The number of points can also be used for another purpose; with
|
||||
/// small numbers you can create any regular polygon shape:
|
||||
/// equilateral triangle, square, pentagon, hexagon, ...
|
||||
///
|
||||
/// \see sf::Shape, sf::RectangleShape, sf::ConvexShape
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
275
code/SFML-2.4.2/include/SFML/Graphics/Color.hpp
Normal file
275
code/SFML-2.4.2/include/SFML/Graphics/Color.hpp
Normal file
|
@ -0,0 +1,275 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Graphics/Export.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility class for manipulating RGBA colors
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Color
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Constructs an opaque black color. It is equivalent to
|
||||
/// sf::Color(0, 0, 0, 255).
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Color();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the color from its 4 RGBA components
|
||||
///
|
||||
/// \param red Red component (in the range [0, 255])
|
||||
/// \param green Green component (in the range [0, 255])
|
||||
/// \param blue Blue component (in the range [0, 255])
|
||||
/// \param alpha Alpha (opacity) component (in the range [0, 255])
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the color from 32-bit unsigned integer
|
||||
///
|
||||
/// \param color Number containing the RGBA components (in that order)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit Color(Uint32 color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve the color as a 32-bit unsigned integer
|
||||
///
|
||||
/// \return Color represented as a 32-bit unsigned integer
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 toInteger() 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
|
||||
static const Color Transparent; ///< Transparent (black) predefined color
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint8 r; ///< Red component
|
||||
Uint8 g; ///< Green component
|
||||
Uint8 b; ///< Blue component
|
||||
Uint8 a; ///< Alpha (opacity) component
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the == operator
|
||||
///
|
||||
/// This operator compares two colors and check if they are equal.
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return True if colors are equal, false if they are different
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the != operator
|
||||
///
|
||||
/// This operator compares two colors and check if they are different.
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return True if colors are different, false if they are equal
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the binary + operator
|
||||
///
|
||||
/// This operator returns the component-wise sum of two colors.
|
||||
/// Components that exceed 255 are clamped to 255.
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return Result of \a left + \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the binary - operator
|
||||
///
|
||||
/// This operator returns the component-wise subtraction of two colors.
|
||||
/// Components below 0 are clamped to 0.
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return Result of \a left - \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Color operator -(const Color& left, const Color& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the binary * operator
|
||||
///
|
||||
/// This operator returns the component-wise multiplication
|
||||
/// (also called "modulation") of two colors.
|
||||
/// Components are then divided by 255 so that the result is
|
||||
/// still in the range [0, 255].
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return Result of \a left * \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the binary += operator
|
||||
///
|
||||
/// This operator computes the component-wise sum of two colors,
|
||||
/// and assigns the result to the left operand.
|
||||
/// Components that exceed 255 are clamped to 255.
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the binary -= operator
|
||||
///
|
||||
/// This operator computes the component-wise subtraction of two colors,
|
||||
/// and assigns the result to the left operand.
|
||||
/// Components below 0 are clamped to 0.
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Color& operator -=(Color& left, const Color& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Color
|
||||
/// \brief Overload of the binary *= operator
|
||||
///
|
||||
/// This operator returns the component-wise multiplication
|
||||
/// (also called "modulation") of two colors, and assigns
|
||||
/// the result to the left operand.
|
||||
/// Components are then divided by 255 so that the result is
|
||||
/// still in the range [0, 255].
|
||||
///
|
||||
/// \param left Left operand
|
||||
/// \param right Right operand
|
||||
///
|
||||
/// \return Reference to \a left
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_COLOR_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Color
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::Color is a simple color class composed of 4 components:
|
||||
/// \li Red
|
||||
/// \li Green
|
||||
/// \li Blue
|
||||
/// \li Alpha (opacity)
|
||||
///
|
||||
/// Each component is a public member, an unsigned integer in
|
||||
/// the range [0, 255]. Thus, colors can be constructed and
|
||||
/// manipulated very easily:
|
||||
///
|
||||
/// \code
|
||||
/// sf::Color color(255, 0, 0); // red
|
||||
/// color.r = 0; // make it black
|
||||
/// color.b = 128; // make it dark blue
|
||||
/// \endcode
|
||||
///
|
||||
/// The fourth component of colors, named "alpha", represents
|
||||
/// the opacity of the color. A color with an alpha value of
|
||||
/// 255 will be fully opaque, while an alpha value of 0 will
|
||||
/// make a color fully transparent, whatever the value of the
|
||||
/// other components is.
|
||||
///
|
||||
/// The most common colors are already defined as static variables:
|
||||
/// \code
|
||||
/// sf::Color black = sf::Color::Black;
|
||||
/// sf::Color white = sf::Color::White;
|
||||
/// sf::Color red = sf::Color::Red;
|
||||
/// sf::Color green = sf::Color::Green;
|
||||
/// sf::Color blue = sf::Color::Blue;
|
||||
/// sf::Color yellow = sf::Color::Yellow;
|
||||
/// sf::Color magenta = sf::Color::Magenta;
|
||||
/// sf::Color cyan = sf::Color::Cyan;
|
||||
/// sf::Color transparent = sf::Color::Transparent;
|
||||
/// \endcode
|
||||
///
|
||||
/// Colors can also be added and modulated (multiplied) using the
|
||||
/// overloaded operators + and *.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
153
code/SFML-2.4.2/include/SFML/Graphics/ConvexShape.hpp
Normal file
153
code/SFML-2.4.2/include/SFML/Graphics/ConvexShape.hpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_CONVEXSHAPE_HPP
|
||||
#define SFML_CONVEXSHAPE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialized shape representing a convex polygon
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API ConvexShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// \param pointCount Number of points of the polygon
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit ConvexShape(std::size_t pointCount = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the number of points of the polygon
|
||||
///
|
||||
/// \a count must be greater than 2 to define a valid shape.
|
||||
///
|
||||
/// \param count New number of points of the polygon
|
||||
///
|
||||
/// \see getPointCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setPointCount(std::size_t count);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of points of the polygon
|
||||
///
|
||||
/// \return Number of points of the polygon
|
||||
///
|
||||
/// \see setPointCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual std::size_t getPointCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the position of a point
|
||||
///
|
||||
/// Don't forget that the polygon must remain convex, and
|
||||
/// the points need to stay ordered!
|
||||
/// setPointCount must be called first in order to set the total
|
||||
/// number of points. The result is undefined if \a index is out
|
||||
/// of the valid range.
|
||||
///
|
||||
/// \param index Index of the point to change, in range [0 .. getPointCount() - 1]
|
||||
/// \param point New position of the point
|
||||
///
|
||||
/// \see getPoint
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setPoint(std::size_t index, const Vector2f& point);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of a point
|
||||
///
|
||||
/// The returned point is in local coordinates, that is,
|
||||
/// the shape's transforms (position, rotation, scale) are
|
||||
/// not taken into account.
|
||||
/// The result is undefined if \a index is out of the valid range.
|
||||
///
|
||||
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
||||
///
|
||||
/// \return Position of the index-th point of the polygon
|
||||
///
|
||||
/// \see setPoint
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2f getPoint(std::size_t index) const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
std::vector<Vector2f> m_points; ///< Points composing the convex polygon
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_CONVEXSHAPE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::ConvexShape
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// This class inherits all the functions of sf::Transformable
|
||||
/// (position, rotation, scale, bounds, ...) as well as the
|
||||
/// functions of sf::Shape (outline, color, texture, ...).
|
||||
///
|
||||
/// It is important to keep in mind that a convex shape must
|
||||
/// always be... convex, otherwise it may not be drawn correctly.
|
||||
/// Moreover, the points must be defined in order; using a random
|
||||
/// order would result in an incorrect shape.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::ConvexShape polygon;
|
||||
/// polygon.setPointCount(3);
|
||||
/// polygon.setPoint(0, sf::Vector2f(0, 0));
|
||||
/// polygon.setPoint(1, sf::Vector2f(0, 10));
|
||||
/// polygon.setPoint(2, sf::Vector2f(25, 5));
|
||||
/// polygon.setOutlineColor(sf::Color::Red);
|
||||
/// polygon.setOutlineThickness(5);
|
||||
/// polygon.setPosition(10, 20);
|
||||
/// ...
|
||||
/// window.draw(polygon);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Shape, sf::RectangleShape, sf::CircleShape
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
126
code/SFML-2.4.2/include/SFML/Graphics/Drawable.hpp
Normal file
126
code/SFML-2.4.2/include/SFML/Graphics/Drawable.hpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/RenderStates.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class RenderTarget;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Abstract base class for objects that can be drawn
|
||||
/// to a render target
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Virtual destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~Drawable() {}
|
||||
|
||||
protected:
|
||||
|
||||
friend class RenderTarget;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw the object to a render target
|
||||
///
|
||||
/// This is a pure virtual function that has to be implemented
|
||||
/// by the derived class to define how the drawable should be
|
||||
/// drawn.
|
||||
///
|
||||
/// \param target Render target to draw to
|
||||
/// \param states Current render states
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void draw(RenderTarget& target, RenderStates states) const = 0;
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_DRAWABLE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Drawable
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::Drawable is a very simple base class that allows objects
|
||||
/// of derived classes to be drawn to a sf::RenderTarget.
|
||||
///
|
||||
/// All you have to do in your derived class is to override the
|
||||
/// draw virtual function.
|
||||
///
|
||||
/// Note that inheriting from sf::Drawable is not mandatory,
|
||||
/// but it allows this nice syntax "window.draw(object)" rather
|
||||
/// than "object.draw(window)", which is more consistent with other
|
||||
/// SFML classes.
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// class MyDrawable : public sf::Drawable
|
||||
/// {
|
||||
/// public:
|
||||
///
|
||||
/// ...
|
||||
///
|
||||
/// private:
|
||||
///
|
||||
/// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
/// {
|
||||
/// // You can draw other high-level objects
|
||||
/// target.draw(m_sprite, states);
|
||||
///
|
||||
/// // ... or use the low-level API
|
||||
/// states.texture = &m_texture;
|
||||
/// target.draw(m_vertices, states);
|
||||
///
|
||||
/// // ... or draw with OpenGL directly
|
||||
/// glBegin(GL_QUADS);
|
||||
/// ...
|
||||
/// glEnd();
|
||||
/// }
|
||||
///
|
||||
/// sf::Sprite m_sprite;
|
||||
/// sf::Texture m_texture;
|
||||
/// sf::VertexArray m_vertices;
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::RenderTarget
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
48
code/SFML-2.4.2/include/SFML/Graphics/Export.hpp
Normal file
48
code/SFML-2.4.2/include/SFML/Graphics/Export.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_GRAPHICS_EXPORT_HPP
|
||||
#define SFML_GRAPHICS_EXPORT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Define portable import / export macros
|
||||
////////////////////////////////////////////////////////////
|
||||
#if defined(SFML_GRAPHICS_EXPORTS)
|
||||
|
||||
#define SFML_GRAPHICS_API SFML_API_EXPORT
|
||||
|
||||
#else
|
||||
|
||||
#define SFML_GRAPHICS_API SFML_API_IMPORT
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SFML_GRAPHICS_EXPORT_HPP
|
439
code/SFML-2.4.2/include/SFML/Graphics/Font.hpp
Normal file
439
code/SFML-2.4.2/include/SFML/Graphics/Font.hpp
Normal file
|
@ -0,0 +1,439 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Glyph.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class InputStream;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Class for loading and manipulating character fonts
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Font
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Holds various information about a font
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct Info
|
||||
{
|
||||
std::string family; ///< The font family
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor defines an empty font
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Font();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
/// \param copy Instance to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Font(const Font& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
/// Cleans up all the internal resources used by the font
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Font();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the font from a file
|
||||
///
|
||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
||||
/// Note that this function know nothing about the standard
|
||||
/// fonts installed on the user's system, thus you can't
|
||||
/// load them directly.
|
||||
///
|
||||
/// \warning SFML cannot preload all the font data in this
|
||||
/// function, so the file has to remain accessible until
|
||||
/// the sf::Font object loads a new font or is destroyed.
|
||||
///
|
||||
/// \param filename Path of the font file to load
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromMemory, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromFile(const std::string& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the font from a file in memory
|
||||
///
|
||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
||||
///
|
||||
/// \warning SFML cannot preload all the font data in this
|
||||
/// function, so the buffer pointed by \a data has to remain
|
||||
/// valid until the sf::Font object loads a new font or
|
||||
/// is destroyed.
|
||||
///
|
||||
/// \param data Pointer to the file data in memory
|
||||
/// \param sizeInBytes Size of the data to load, in bytes
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the font from a custom stream
|
||||
///
|
||||
/// The supported font formats are: TrueType, Type 1, CFF,
|
||||
/// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42.
|
||||
/// Warning: SFML cannot preload all the font data in this
|
||||
/// function, so the contents of \a stream have to remain
|
||||
/// valid as long as the font is used.
|
||||
///
|
||||
/// \warning SFML cannot preload all the font data in this
|
||||
/// function, so the stream has to remain accessible until
|
||||
/// the sf::Font object loads a new font or is destroyed.
|
||||
///
|
||||
/// \param stream Source stream to read from
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromMemory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromStream(InputStream& stream);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the font information
|
||||
///
|
||||
/// \return A structure that holds the font information
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Info& getInfo() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve a glyph of the font
|
||||
///
|
||||
/// If the font is a bitmap font, not all character sizes
|
||||
/// might be available. If the glyph is not available at the
|
||||
/// requested size, an empty glyph is returned.
|
||||
///
|
||||
/// Be aware that using a negative value for the outline
|
||||
/// thickness will cause distorted rendering.
|
||||
///
|
||||
/// \param codePoint Unicode code point of the character to get
|
||||
/// \param characterSize Reference character size
|
||||
/// \param bold Retrieve the bold version or the regular one?
|
||||
/// \param outlineThickness Thickness of outline (when != 0 the glyph will not be filled)
|
||||
///
|
||||
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the kerning offset of two glyphs
|
||||
///
|
||||
/// The kerning is an extra offset (negative) to apply between two
|
||||
/// glyphs when rendering them, to make the pair look more "natural".
|
||||
/// For example, the pair "AV" have a special kerning to make them
|
||||
/// closer than other characters. Most of the glyphs pairs have a
|
||||
/// kerning offset of zero, though.
|
||||
///
|
||||
/// \param first Unicode code point of the first character
|
||||
/// \param second Unicode code point of the second character
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Kerning value for \a first and \a second, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the line spacing
|
||||
///
|
||||
/// Line spacing is the vertical offset to apply between two
|
||||
/// consecutive lines of text.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Line spacing, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getLineSpacing(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the underline
|
||||
///
|
||||
/// Underline position is the vertical offset to apply between the
|
||||
/// baseline and the underline.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Underline position, in pixels
|
||||
///
|
||||
/// \see getUnderlineThickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getUnderlinePosition(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the thickness of the underline
|
||||
///
|
||||
/// Underline thickness is the vertical size of the underline.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Underline thickness, in pixels
|
||||
///
|
||||
/// \see getUnderlinePosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getUnderlineThickness(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve the texture containing the loaded glyphs of a certain size
|
||||
///
|
||||
/// The contents of the returned texture changes as more glyphs
|
||||
/// are requested, thus it is not very relevant. It is mainly
|
||||
/// used internally by sf::Text.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Texture containing the glyphs of the requested size
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture& getTexture(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Font& operator =(const Font& right);
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Structure defining a row of glyphs
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct Row
|
||||
{
|
||||
Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(rowTop), height(rowHeight) {}
|
||||
|
||||
unsigned int width; ///< Current width of the row
|
||||
unsigned int top; ///< Y position of the row into the texture
|
||||
unsigned int height; ///< Height of the row
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Types
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::map<Uint64, Glyph> GlyphTable; ///< Table mapping a codepoint to its glyph
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Structure defining a page of glyphs
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct Page
|
||||
{
|
||||
Page();
|
||||
|
||||
GlyphTable glyphs; ///< Table mapping code points to their corresponding glyph
|
||||
Texture texture; ///< Texture containing the pixels of the glyphs
|
||||
unsigned int nextRow; ///< Y position of the next new row in the texture
|
||||
std::vector<Row> rows; ///< List containing the position of all the existing rows
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Free all the internal resources
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void cleanup();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load a new glyph and store it in the cache
|
||||
///
|
||||
/// \param codePoint Unicode code point of the character to load
|
||||
/// \param characterSize Reference character size
|
||||
/// \param bold Retrieve the bold version or the regular one?
|
||||
/// \param outlineThickness Thickness of outline (when != 0 the glyph will not be filled)
|
||||
///
|
||||
/// \return The glyph corresponding to \a codePoint and \a characterSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Find a suitable rectangle within the texture for a glyph
|
||||
///
|
||||
/// \param page Page of glyphs to search in
|
||||
/// \param width Width of the rectangle
|
||||
/// \param height Height of the rectangle
|
||||
///
|
||||
/// \return Found rectangle within the texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Make sure that the given size is the current one
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return True on success, false if any error happened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool setCurrentSize(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Types
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::map<unsigned int, Page> PageTable; ///< Table mapping a character size to its page (texture)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
void* m_library; ///< Pointer to the internal library interface (it is typeless to avoid exposing implementation details)
|
||||
void* m_face; ///< Pointer to the internal font face (it is typeless to avoid exposing implementation details)
|
||||
void* m_streamRec; ///< Pointer to the stream rec instance (it is typeless to avoid exposing implementation details)
|
||||
void* m_stroker; ///< Pointer to the stroker (it is typeless to avoid exposing implementation details)
|
||||
int* m_refCount; ///< Reference counter used by implicit sharing
|
||||
Info m_info; ///< Information about the font
|
||||
mutable PageTable m_pages; ///< Table containing the glyphs pages by character size
|
||||
mutable std::vector<Uint8> m_pixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
void* m_stream; ///< Asset file streamer (if loaded from file)
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_FONT_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Font
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// Fonts can be loaded from a file, from memory or from a custom
|
||||
/// stream, and supports the most common types of fonts. See
|
||||
/// the loadFromFile function for the complete list of supported formats.
|
||||
///
|
||||
/// Once it is loaded, a sf::Font instance provides three
|
||||
/// types of information about the font:
|
||||
/// \li Global metrics, such as the line spacing
|
||||
/// \li Per-glyph metrics, such as bounding box or kerning
|
||||
/// \li Pixel representation of glyphs
|
||||
///
|
||||
/// Fonts alone are not very useful: they hold the font data
|
||||
/// but cannot make anything useful of it. To do so you need to
|
||||
/// use the sf::Text class, which is able to properly output text
|
||||
/// with several options such as character size, style, color,
|
||||
/// position, rotation, etc.
|
||||
/// This separation allows more flexibility and better performances:
|
||||
/// indeed a sf::Font is a heavy resource, and any operation on it
|
||||
/// is slow (often too slow for real-time applications). On the other
|
||||
/// side, a sf::Text is a lightweight object which can combine the
|
||||
/// glyphs data and metrics of a sf::Font to display any text on a
|
||||
/// render target.
|
||||
/// Note that it is also possible to bind several sf::Text instances
|
||||
/// to the same sf::Font.
|
||||
///
|
||||
/// It is important to note that the sf::Text instance doesn't
|
||||
/// copy the font that it uses, it only keeps a reference to it.
|
||||
/// Thus, a sf::Font must not be destructed while it is
|
||||
/// used by a sf::Text (i.e. never write a function that
|
||||
/// uses a local sf::Font instance for creating a text).
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Declare a new font
|
||||
/// sf::Font font;
|
||||
///
|
||||
/// // Load it from a file
|
||||
/// if (!font.loadFromFile("arial.ttf"))
|
||||
/// {
|
||||
/// // error...
|
||||
/// }
|
||||
///
|
||||
/// // Create a text which uses our font
|
||||
/// sf::Text text1;
|
||||
/// text1.setFont(font);
|
||||
/// text1.setCharacterSize(30);
|
||||
/// text1.setStyle(sf::Text::Regular);
|
||||
///
|
||||
/// // Create another text using the same font, but with different parameters
|
||||
/// sf::Text text2;
|
||||
/// text2.setFont(font);
|
||||
/// text2.setCharacterSize(50);
|
||||
/// text2.setStyle(sf::Text::Italic);
|
||||
/// \endcode
|
||||
///
|
||||
/// Apart from loading font files, and passing them to instances
|
||||
/// of sf::Text, you should normally not have to deal directly
|
||||
/// with this class. However, it may be useful to access the
|
||||
/// font metrics or rasterized glyphs for advanced usage.
|
||||
///
|
||||
/// Note that if the font is a bitmap font, it is not scalable,
|
||||
/// thus not all requested sizes will be available to use. This
|
||||
/// needs to be taken into consideration when using sf::Text.
|
||||
/// If you need to display text of a certain size, make sure the
|
||||
/// corresponding bitmap font that supports that size is used.
|
||||
///
|
||||
/// \see sf::Text
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
227
code/SFML-2.4.2/include/SFML/Graphics/Glsl.hpp
Normal file
227
code/SFML-2.4.2/include/SFML/Graphics/Glsl.hpp
Normal file
|
@ -0,0 +1,227 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_GLSL_HPP
|
||||
#define SFML_GLSL_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Transform.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
// Forward declarations
|
||||
template <std::size_t Columns, std::size_t Rows>
|
||||
struct Matrix;
|
||||
|
||||
template <typename T>
|
||||
struct Vector4;
|
||||
|
||||
#include <SFML/Graphics/Glsl.inl>
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Namespace with GLSL types
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
namespace Glsl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 2D float vector (\p vec2 in GLSL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef Vector2<float> Vec2;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 2D int vector (\p ivec2 in GLSL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef Vector2<int> Ivec2;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 2D bool vector (\p bvec2 in GLSL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef Vector2<bool> Bvec2;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 3D float vector (\p vec3 in GLSL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef Vector3<float> Vec3;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 3D int vector (\p ivec3 in GLSL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef Vector3<int> Ivec3;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 3D bool vector (\p bvec3 in GLSL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef Vector3<bool> Bvec3;
|
||||
|
||||
#ifdef SFML_DOXYGEN
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 4D float vector (\p vec4 in GLSL)
|
||||
///
|
||||
/// 4D float vectors can be implicitly converted from sf::Color
|
||||
/// instances. Each color channel is normalized from integers
|
||||
/// in [0, 255] to floating point values in [0, 1].
|
||||
/// \code
|
||||
/// sf::Glsl::Vec4 zeroVector;
|
||||
/// sf::Glsl::Vec4 vector(1.f, 2.f, 3.f, 4.f);
|
||||
/// sf::Glsl::Vec4 color = sf::Color::Cyan;
|
||||
/// \endcode
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef implementation-defined Vec4;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 4D int vector (\p ivec4 in GLSL)
|
||||
///
|
||||
/// 4D int vectors can be implicitly converted from sf::Color
|
||||
/// instances. Each color channel remains unchanged inside
|
||||
/// the integer interval [0, 255].
|
||||
/// \code
|
||||
/// sf::Glsl::Ivec4 zeroVector;
|
||||
/// sf::Glsl::Ivec4 vector(1, 2, 3, 4);
|
||||
/// sf::Glsl::Ivec4 color = sf::Color::Cyan;
|
||||
/// \endcode
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef implementation-defined Ivec4;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 4D bool vector (\p bvec4 in GLSL)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef implementation-defined Bvec4;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 3x3 float matrix (\p mat3 in GLSL)
|
||||
///
|
||||
/// The matrix can be constructed from an array with 3x3
|
||||
/// elements, aligned in column-major order. For example,
|
||||
/// a translation by (x, y) looks as follows:
|
||||
/// \code
|
||||
/// float array[9] =
|
||||
/// {
|
||||
/// 1, 0, 0,
|
||||
/// 0, 1, 0,
|
||||
/// x, y, 1
|
||||
/// };
|
||||
///
|
||||
/// sf::Glsl::Mat3 matrix(array);
|
||||
/// \endcode
|
||||
///
|
||||
/// Mat3 can also be implicitly converted from sf::Transform:
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// sf::Glsl::Mat3 matrix = transform;
|
||||
/// \endcode
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef implementation-defined Mat3;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 4x4 float matrix (\p mat4 in GLSL)
|
||||
///
|
||||
/// The matrix can be constructed from an array with 4x4
|
||||
/// elements, aligned in column-major order. For example,
|
||||
/// a translation by (x, y, z) looks as follows:
|
||||
/// \code
|
||||
/// float array[16] =
|
||||
/// {
|
||||
/// 1, 0, 0, 0,
|
||||
/// 0, 1, 0, 0,
|
||||
/// 0, 0, 1, 0,
|
||||
/// x, y, z, 1
|
||||
/// };
|
||||
///
|
||||
/// sf::Glsl::Mat4 matrix(array);
|
||||
/// \endcode
|
||||
///
|
||||
/// Mat4 can also be implicitly converted from sf::Transform:
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// sf::Glsl::Mat4 matrix = transform;
|
||||
/// \endcode
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef implementation-defined Mat4;
|
||||
|
||||
#else // SFML_DOXYGEN
|
||||
|
||||
typedef priv::Vector4<float> Vec4;
|
||||
typedef priv::Vector4<int> Ivec4;
|
||||
typedef priv::Vector4<bool> Bvec4;
|
||||
typedef priv::Matrix<3, 3> Mat3;
|
||||
typedef priv::Matrix<4, 4> Mat4;
|
||||
|
||||
#endif // SFML_DOXYGEN
|
||||
|
||||
} // namespace Glsl
|
||||
} // namespace sf
|
||||
|
||||
#endif // SFML_GLSL_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \namespace sf::Glsl
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// \details The sf::Glsl namespace contains types that match
|
||||
/// their equivalents in GLSL, the OpenGL shading language.
|
||||
/// These types are exclusively used by the sf::Shader class.
|
||||
///
|
||||
/// Types that already exist in SFML, such as \ref sf::Vector2<T>
|
||||
/// and \ref sf::Vector3<T>, are reused as typedefs, so you can use
|
||||
/// the types in this namespace as well as the original ones.
|
||||
/// Others are newly defined, such as Glsl::Vec4 or Glsl::Mat3. Their
|
||||
/// actual type is an implementation detail and should not be used.
|
||||
///
|
||||
/// All vector types support a default constructor that
|
||||
/// initializes every component to zero, in addition to a
|
||||
/// constructor with one parameter for each component.
|
||||
/// The components are stored in member variables called
|
||||
/// x, y, z, and w.
|
||||
///
|
||||
/// All matrix types support a constructor with a float*
|
||||
/// parameter that points to a float array of the appropriate
|
||||
/// size (that is, 9 in a 3x3 matrix, 16 in a 4x4 matrix).
|
||||
/// Furthermore, they can be converted from sf::Transform
|
||||
/// objects.
|
||||
///
|
||||
/// \see sf::Shader
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
155
code/SFML-2.4.2/include/SFML/Graphics/Glsl.inl
Normal file
155
code/SFML-2.4.2/include/SFML/Graphics/Glsl.inl
Normal file
|
@ -0,0 +1,155 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Helper functions to copy sf::Transform to sf::Glsl::Mat3/4
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFML_GRAPHICS_API copyMatrix(const Transform& source, Matrix<3, 3>& dest);
|
||||
void SFML_GRAPHICS_API copyMatrix(const Transform& source, Matrix<4, 4>& dest);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy array-based matrix with given number of elements
|
||||
///
|
||||
/// Indirection to std::copy() to avoid inclusion of
|
||||
/// <algorithm> and MSVC's annoying 4996 warning in header
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFML_GRAPHICS_API copyMatrix(const float* source, std::size_t elements, float* dest);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Helper functions to copy sf::Color to sf::Glsl::Vec4/Ivec4
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void SFML_GRAPHICS_API copyVector(const Color& source, Vector4<float>& dest);
|
||||
void SFML_GRAPHICS_API copyVector(const Color& source, Vector4<int>& dest);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Matrix type, used to set uniforms in GLSL
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <std::size_t Columns, std::size_t Rows>
|
||||
struct Matrix
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from raw data
|
||||
///
|
||||
/// \param pointer Points to the beginning of an array that
|
||||
/// has the size of the matrix. The elements
|
||||
/// are copied to the instance.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit Matrix(const float* pointer)
|
||||
{
|
||||
copyMatrix(pointer, Columns * Rows, array);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct implicitly from SFML transform
|
||||
///
|
||||
/// This constructor is only supported for 3x3 and 4x4
|
||||
/// matrices.
|
||||
///
|
||||
/// \param transform Object containing a transform.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Matrix(const Transform& transform)
|
||||
{
|
||||
copyMatrix(transform, *this);
|
||||
}
|
||||
|
||||
float array[Columns * Rows]; ///< Array holding matrix data
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 4D vector type, used to set uniforms in GLSL
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
struct Vector4
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor, creates a zero vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector4() :
|
||||
x(0),
|
||||
y(0),
|
||||
z(0),
|
||||
w(0)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct from 4 vector components
|
||||
///
|
||||
/// \param X Component of the 4D vector
|
||||
/// \param Y Component of the 4D vector
|
||||
/// \param Z Component of the 4D vector
|
||||
/// \param W Component of the 4D vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector4(T X, T Y, T Z, T W) :
|
||||
x(X),
|
||||
y(Y),
|
||||
z(Z),
|
||||
w(W)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Conversion constructor
|
||||
///
|
||||
/// \param other 4D vector of different type
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename U>
|
||||
explicit Vector4(const Vector4<U>& other) :
|
||||
x(static_cast<T>(other.x)),
|
||||
y(static_cast<T>(other.y)),
|
||||
z(static_cast<T>(other.z)),
|
||||
w(static_cast<T>(other.w))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct float vector implicitly from color
|
||||
///
|
||||
/// \param color Color instance. Is normalized to [0, 1]
|
||||
/// for floats, and left as-is for ints.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector4(const Color& color)
|
||||
// uninitialized
|
||||
{
|
||||
copyVector(color, *this);
|
||||
}
|
||||
|
||||
T x; ///< 1st component (X) of the 4D vector
|
||||
T y; ///< 2nd component (Y) of the 4D vector
|
||||
T z; ///< 3rd component (Z) of the 4D vector
|
||||
T w; ///< 4th component (W) of the 4D vector
|
||||
};
|
79
code/SFML-2.4.2/include/SFML/Graphics/Glyph.hpp
Normal file
79
code/SFML-2.4.2/include/SFML/Graphics/Glyph.hpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Structure describing a glyph
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Glyph
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Glyph() : advance(0) {}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
float advance; ///< Offset to move horizontally to the next character
|
||||
FloatRect bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline
|
||||
IntRect textureRect; ///< Texture coordinates of the glyph inside the font's texture
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_GLYPH_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Glyph
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// A glyph is the visual representation of a character.
|
||||
///
|
||||
/// The sf::Glyph structure provides the information needed
|
||||
/// to handle the glyph:
|
||||
/// \li its coordinates in the font's texture
|
||||
/// \li its bounding rectangle
|
||||
/// \li the offset to apply to get the starting position of the next glyph
|
||||
///
|
||||
/// \see sf::Font
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
327
code/SFML-2.4.2/include/SFML/Graphics/Image.hpp
Normal file
327
code/SFML-2.4.2/include/SFML/Graphics/Image.hpp
Normal file
|
@ -0,0 +1,327 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class InputStream;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Class for loading, manipulating and saving images
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Image
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates an empty image.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Image();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Image();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the image and fill it with a unique color
|
||||
///
|
||||
/// \param width Width of the image
|
||||
/// \param height Height of the image
|
||||
/// \param color Fill color
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0));
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the image from an array of pixels
|
||||
///
|
||||
/// The \a pixel array is assumed to contain 32-bits RGBA pixels,
|
||||
/// and have the given \a width and \a height. If not, this is
|
||||
/// an undefined behavior.
|
||||
/// If \a pixels is null, an empty image is created.
|
||||
///
|
||||
/// \param width Width of the image
|
||||
/// \param height Height of the image
|
||||
/// \param pixels Array of pixels to copy to the image
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void create(unsigned int width, unsigned int height, const Uint8* pixels);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the image from a file on disk
|
||||
///
|
||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||
/// psd, hdr and pic. Some format options are not supported,
|
||||
/// like progressive jpeg.
|
||||
/// If this function fails, the image is left unchanged.
|
||||
///
|
||||
/// \param filename Path of the image file to load
|
||||
///
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
/// \see loadFromMemory, loadFromStream, saveToFile
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromFile(const std::string& filename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the image from a file in memory
|
||||
///
|
||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||
/// psd, hdr and pic. Some format options are not supported,
|
||||
/// like progressive jpeg.
|
||||
/// If this function fails, the image is left unchanged.
|
||||
///
|
||||
/// \param data Pointer to the file data in memory
|
||||
/// \param size Size of the data to load, in bytes
|
||||
///
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
/// \see loadFromFile, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromMemory(const void* data, std::size_t size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the image from a custom stream
|
||||
///
|
||||
/// The supported image formats are bmp, png, tga, jpg, gif,
|
||||
/// psd, hdr and pic. Some format options are not supported,
|
||||
/// like progressive jpeg.
|
||||
/// If this function fails, the image is left unchanged.
|
||||
///
|
||||
/// \param stream Source stream to read from
|
||||
///
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
/// \see loadFromFile, loadFromMemory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromStream(InputStream& stream);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Save the image to a file on disk
|
||||
///
|
||||
/// The format of the image is automatically deduced from
|
||||
/// the extension. The supported image formats are bmp, png,
|
||||
/// tga and jpg. The destination file is overwritten
|
||||
/// if it already exists. This function fails if the image is empty.
|
||||
///
|
||||
/// \param filename Path of the file to save
|
||||
///
|
||||
/// \return True if saving was successful
|
||||
///
|
||||
/// \see create, loadFromFile, loadFromMemory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool saveToFile(const std::string& filename) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size (width and height) of the image
|
||||
///
|
||||
/// \return Size of the image, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a transparency mask from a specified color-key
|
||||
///
|
||||
/// This function sets the alpha value of every pixel matching
|
||||
/// the given color to \a alpha (0 by default), so that they
|
||||
/// become transparent.
|
||||
///
|
||||
/// \param color Color to make transparent
|
||||
/// \param alpha Alpha value to assign to transparent pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void createMaskFromColor(const Color& color, Uint8 alpha = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy pixels from another image onto this one
|
||||
///
|
||||
/// This function does a slow pixel copy and should not be
|
||||
/// used intensively. It can be used to prepare a complex
|
||||
/// static image from several others, but if you need this
|
||||
/// kind of feature in real-time you'd better use sf::RenderTexture.
|
||||
///
|
||||
/// If \a sourceRect is empty, the whole image is copied.
|
||||
/// If \a applyAlpha is set to true, the transparency of
|
||||
/// source pixels is applied. If it is false, the pixels are
|
||||
/// copied unchanged with their alpha value.
|
||||
///
|
||||
/// \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
|
||||
/// \param applyAlpha Should the copy take into account the source transparency?
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the color of a pixel
|
||||
///
|
||||
/// This function doesn't check the validity of the pixel
|
||||
/// coordinates, using out-of-range values will result in
|
||||
/// an undefined behavior.
|
||||
///
|
||||
/// \param x X coordinate of pixel to change
|
||||
/// \param y Y coordinate of pixel to change
|
||||
/// \param color New color of the pixel
|
||||
///
|
||||
/// \see getPixel
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setPixel(unsigned int x, unsigned int y, const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the color of a pixel
|
||||
///
|
||||
/// This function doesn't check the validity of the pixel
|
||||
/// coordinates, using out-of-range values will result in
|
||||
/// an undefined behavior.
|
||||
///
|
||||
/// \param x X coordinate of pixel to get
|
||||
/// \param y Y coordinate of pixel to get
|
||||
///
|
||||
/// \return Color of the pixel at coordinates (x, y)
|
||||
///
|
||||
/// \see setPixel
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Color getPixel(unsigned int x, unsigned int y) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a read-only pointer to the array of pixels
|
||||
///
|
||||
/// The returned value points to an array of RGBA pixels made of
|
||||
/// 8 bits integers components. The size of the array is
|
||||
/// width * height * 4 (getSize().x * getSize().y * 4).
|
||||
/// Warning: the returned pointer may become invalid if you
|
||||
/// modify the image, so you should never store it for too long.
|
||||
/// If the image is empty, a null pointer is returned.
|
||||
///
|
||||
/// \return Read-only pointer to the array of pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Uint8* getPixelsPtr() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Flip the image horizontally (left <-> right)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void flipHorizontally();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Flip the image vertically (top <-> bottom)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void flipVertically();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u m_size; ///< Image size
|
||||
std::vector<Uint8> m_pixels; ///< Pixels of the image
|
||||
#ifdef SFML_SYSTEM_ANDROID
|
||||
void* m_stream; ///< Asset file streamer (if loaded from file)
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_IMAGE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Image
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::Image is an abstraction to manipulate images
|
||||
/// as bidimensional arrays of pixels. The class provides
|
||||
/// functions to load, read, write and save pixels, as well
|
||||
/// as many other useful functions.
|
||||
///
|
||||
/// sf::Image can handle a unique internal representation of
|
||||
/// pixels, which is RGBA 32 bits. This means that a pixel
|
||||
/// must be composed of 8 bits red, green, blue and alpha
|
||||
/// channels -- just like a sf::Color.
|
||||
/// All the functions that return an array of pixels follow
|
||||
/// this rule, and all parameters that you pass to sf::Image
|
||||
/// functions (such as loadFromMemory) must use this
|
||||
/// representation as well.
|
||||
///
|
||||
/// A sf::Image can be copied, but it is a heavy resource and
|
||||
/// if possible you should always use [const] references to
|
||||
/// pass or return them to avoid useless copies.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Load an image file from a file
|
||||
/// sf::Image background;
|
||||
/// if (!background.loadFromFile("background.jpg"))
|
||||
/// return -1;
|
||||
///
|
||||
/// // Create a 20x20 image filled with black color
|
||||
/// sf::Image image;
|
||||
/// image.create(20, 20, sf::Color::Black);
|
||||
///
|
||||
/// // Copy image1 on image2 at position (10, 10)
|
||||
/// image.copy(background, 10, 10);
|
||||
///
|
||||
/// // Make the top-left pixel transparent
|
||||
/// sf::Color color = image.getPixel(0, 0);
|
||||
/// color.a = 0;
|
||||
/// image.setPixel(0, 0, color);
|
||||
///
|
||||
/// // Save the image to a file
|
||||
/// if (!image.saveToFile("result.png"))
|
||||
/// return -1;
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
58
code/SFML-2.4.2/include/SFML/Graphics/PrimitiveType.hpp
Normal file
58
code/SFML-2.4.2/include/SFML/Graphics/PrimitiveType.hpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_PRIMITIVETYPE_HPP
|
||||
#define SFML_PRIMITIVETYPE_HPP
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \ingroup graphics
|
||||
/// \brief Types of primitives that a sf::VertexArray can render
|
||||
///
|
||||
/// Points and lines have no area, therefore their thickness
|
||||
/// will always be 1 pixel, regardless the current transform
|
||||
/// and view.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum PrimitiveType
|
||||
{
|
||||
Points, ///< List of individual points
|
||||
Lines, ///< List of individual lines
|
||||
LineStrip, ///< List of connected lines, a point uses the previous point to form a line
|
||||
Triangles, ///< List of individual triangles
|
||||
TriangleStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle
|
||||
TriangleFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle
|
||||
Quads, ///< List of individual quads (deprecated, don't work with OpenGL ES)
|
||||
|
||||
// Deprecated names
|
||||
LinesStrip = LineStrip, ///< \deprecated Use LineStrip instead
|
||||
TrianglesStrip = TriangleStrip, ///< \deprecated Use TriangleStrip instead
|
||||
TrianglesFan = TriangleFan ///< \deprecated Use TriangleFan instead
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_PRIMITIVETYPE_HPP
|
254
code/SFML-2.4.2/include/SFML/Graphics/Rect.hpp
Normal file
254
code/SFML-2.4.2/include/SFML/Graphics/Rect.hpp
Normal file
|
@ -0,0 +1,254 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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 <SFML/System/Vector2.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Utility class for manipulating 2D axis aligned rectangles
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
class Rect
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates an empty rectangle (it is equivalent to calling
|
||||
/// Rect(0, 0, 0, 0)).
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rectangle from its coordinates
|
||||
///
|
||||
/// Be careful, the last two parameters are the width
|
||||
/// and height, not the right and bottom coordinates!
|
||||
///
|
||||
/// \param rectLeft Left coordinate of the rectangle
|
||||
/// \param rectTop Top coordinate of the rectangle
|
||||
/// \param rectWidth Width of the rectangle
|
||||
/// \param rectHeight Height of the rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rectangle from position and size
|
||||
///
|
||||
/// Be careful, the last parameter is the size,
|
||||
/// not the bottom-right corner!
|
||||
///
|
||||
/// \param position Position of the top-left corner of the rectangle
|
||||
/// \param size Size of the rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect(const Vector2<T>& position, const Vector2<T>& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the rectangle from another type of rectangle
|
||||
///
|
||||
/// This constructor doesn't replace the copy constructor,
|
||||
/// it's called only when U != T.
|
||||
/// A call to this constructor will fail to compile if U
|
||||
/// is not convertible to T.
|
||||
///
|
||||
/// \param rectangle Rectangle to convert
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename U>
|
||||
explicit Rect(const Rect<U>& rectangle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a point is inside the rectangle's area
|
||||
///
|
||||
/// This check is non-inclusive. If the point lies on the
|
||||
/// edge of the rectangle, this function will return false.
|
||||
///
|
||||
/// \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, false otherwise
|
||||
///
|
||||
/// \see intersects
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool contains(T x, T y) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check if a point is inside the rectangle's area
|
||||
///
|
||||
/// This check is non-inclusive. If the point lies on the
|
||||
/// edge of the rectangle, this function will return false.
|
||||
///
|
||||
/// \param point Point to test
|
||||
///
|
||||
/// \return True if the point is inside, false otherwise
|
||||
///
|
||||
/// \see intersects
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool contains(const Vector2<T>& point) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check the intersection between two rectangles
|
||||
///
|
||||
/// \param rectangle Rectangle to test
|
||||
///
|
||||
/// \return True if rectangles overlap, false otherwise
|
||||
///
|
||||
/// \see contains
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool intersects(const Rect<T>& rectangle) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check the intersection between two rectangles
|
||||
///
|
||||
/// This overload returns the overlapped rectangle in the
|
||||
/// \a intersection parameter.
|
||||
///
|
||||
/// \param rectangle Rectangle to test
|
||||
/// \param intersection Rectangle to be filled with the intersection
|
||||
///
|
||||
/// \return True if rectangles overlap, false otherwise
|
||||
///
|
||||
/// \see contains
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool intersects(const Rect<T>& rectangle, Rect<T>& intersection) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
T left; ///< Left coordinate of the rectangle
|
||||
T top; ///< Top coordinate of the rectangle
|
||||
T width; ///< Width of the rectangle
|
||||
T height; ///< Height of the rectangle
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Rect
|
||||
/// \brief Overload of binary operator ==
|
||||
///
|
||||
/// This operator compares strict equality between two rectangles.
|
||||
///
|
||||
/// \param left Left operand (a rectangle)
|
||||
/// \param right Right operand (a rectangle)
|
||||
///
|
||||
/// \return True if \a left is equal to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator ==(const Rect<T>& left, const Rect<T>& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates Rect
|
||||
/// \brief Overload of binary operator !=
|
||||
///
|
||||
/// This operator compares strict difference between two rectangles.
|
||||
///
|
||||
/// \param left Left operand (a rectangle)
|
||||
/// \param right Right operand (a rectangle)
|
||||
///
|
||||
/// \return True if \a left is not equal to \a right
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool operator !=(const Rect<T>& left, const Rect<T>& right);
|
||||
|
||||
#include <SFML/Graphics/Rect.inl>
|
||||
|
||||
// Create typedefs for the most common types
|
||||
typedef Rect<int> IntRect;
|
||||
typedef Rect<float> FloatRect;
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_RECT_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Rect
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// A rectangle is defined by its top-left corner and its size.
|
||||
/// It is a very simple class defined for convenience, so
|
||||
/// its member variables (left, top, width and height) are public
|
||||
/// and can be accessed directly, just like the vector classes
|
||||
/// (Vector2 and Vector3).
|
||||
///
|
||||
/// To keep things simple, sf::Rect doesn't define
|
||||
/// functions to emulate the properties that are not directly
|
||||
/// members (such as right, bottom, center, etc.), it rather
|
||||
/// only provides intersection functions.
|
||||
///
|
||||
/// sf::Rect uses the usual rules for its boundaries:
|
||||
/// \li The left and top edges are included in the rectangle's area
|
||||
/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area
|
||||
///
|
||||
/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1)
|
||||
/// don't intersect.
|
||||
///
|
||||
/// sf::Rect is a template and may be used with any numeric type, but
|
||||
/// for simplicity the instantiations used by SFML are typedef'd:
|
||||
/// \li sf::Rect<int> is sf::IntRect
|
||||
/// \li sf::Rect<float> is sf::FloatRect
|
||||
///
|
||||
/// So that you don't have to care about the template syntax.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Define a rectangle, located at (0, 0) with a size of 20x5
|
||||
/// sf::IntRect r1(0, 0, 20, 5);
|
||||
///
|
||||
/// // Define another rectangle, located at (4, 2) with a size of 18x10
|
||||
/// sf::Vector2i position(4, 2);
|
||||
/// sf::Vector2i size(18, 10);
|
||||
/// sf::IntRect r2(position, size);
|
||||
///
|
||||
/// // Test intersections with the point (3, 1)
|
||||
/// bool b1 = r1.contains(3, 1); // true
|
||||
/// bool b2 = r2.contains(3, 1); // false
|
||||
///
|
||||
/// // Test the intersection between r1 and r2
|
||||
/// sf::IntRect result;
|
||||
/// bool b3 = r1.intersects(r2, result); // true
|
||||
/// // result == (4, 2, 16, 3)
|
||||
/// \endcode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
159
code/SFML-2.4.2/include/SFML/Graphics/Rect.inl
Normal file
159
code/SFML-2.4.2/include/SFML/Graphics/Rect.inl
Normal file
|
@ -0,0 +1,159 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Rect<T>::Rect() :
|
||||
left (0),
|
||||
top (0),
|
||||
width (0),
|
||||
height(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Rect<T>::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) :
|
||||
left (rectLeft),
|
||||
top (rectTop),
|
||||
width (rectWidth),
|
||||
height(rectHeight)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) :
|
||||
left (position.x),
|
||||
top (position.y),
|
||||
width (size.x),
|
||||
height(size.y)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
Rect<T>::Rect(const Rect<U>& rectangle) :
|
||||
left (static_cast<T>(rectangle.left)),
|
||||
top (static_cast<T>(rectangle.top)),
|
||||
width (static_cast<T>(rectangle.width)),
|
||||
height(static_cast<T>(rectangle.height))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool Rect<T>::contains(T x, T y) const
|
||||
{
|
||||
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
||||
|
||||
// Compute the real min and max of the rectangle on both axes
|
||||
T minX = std::min(left, static_cast<T>(left + width));
|
||||
T maxX = std::max(left, static_cast<T>(left + width));
|
||||
T minY = std::min(top, static_cast<T>(top + height));
|
||||
T maxY = std::max(top, static_cast<T>(top + height));
|
||||
|
||||
return (x >= minX) && (x < maxX) && (y >= minY) && (y < maxY);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool Rect<T>::contains(const Vector2<T>& point) const
|
||||
{
|
||||
return contains(point.x, point.y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool Rect<T>::intersects(const Rect<T>& rectangle) const
|
||||
{
|
||||
Rect<T> intersection;
|
||||
return intersects(rectangle, intersection);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
bool Rect<T>::intersects(const Rect<T>& rectangle, Rect<T>& intersection) const
|
||||
{
|
||||
// Rectangles with negative dimensions are allowed, so we must handle them correctly
|
||||
|
||||
// Compute the min and max of the first rectangle on both axes
|
||||
T r1MinX = std::min(left, static_cast<T>(left + width));
|
||||
T r1MaxX = std::max(left, static_cast<T>(left + width));
|
||||
T r1MinY = std::min(top, static_cast<T>(top + height));
|
||||
T r1MaxY = std::max(top, static_cast<T>(top + height));
|
||||
|
||||
// Compute the min and max of the second rectangle on both axes
|
||||
T r2MinX = std::min(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
||||
T r2MaxX = std::max(rectangle.left, static_cast<T>(rectangle.left + rectangle.width));
|
||||
T r2MinY = std::min(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
||||
T r2MaxY = std::max(rectangle.top, static_cast<T>(rectangle.top + rectangle.height));
|
||||
|
||||
// Compute the intersection boundaries
|
||||
T interLeft = std::max(r1MinX, r2MinX);
|
||||
T interTop = std::max(r1MinY, r2MinY);
|
||||
T interRight = std::min(r1MaxX, r2MaxX);
|
||||
T interBottom = std::min(r1MaxY, r2MaxY);
|
||||
|
||||
// If the intersection is valid (positive non zero area), then there is an intersection
|
||||
if ((interLeft < interRight) && (interTop < interBottom))
|
||||
{
|
||||
intersection = Rect<T>(interLeft, interTop, interRight - interLeft, interBottom - interTop);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
intersection = Rect<T>(0, 0, 0, 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline bool operator ==(const Rect<T>& left, const Rect<T>& right)
|
||||
{
|
||||
return (left.left == right.left) && (left.width == right.width) &&
|
||||
(left.top == right.top) && (left.height == right.height);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline bool operator !=(const Rect<T>& left, const Rect<T>& right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
132
code/SFML-2.4.2/include/SFML/Graphics/RectangleShape.hpp
Normal file
132
code/SFML-2.4.2/include/SFML/Graphics/RectangleShape.hpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_RECTANGLESHAPE_HPP
|
||||
#define SFML_RECTANGLESHAPE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specialized shape representing a rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API RectangleShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// \param size Size of the rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit RectangleShape(const Vector2f& size = Vector2f(0, 0));
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the size of the rectangle
|
||||
///
|
||||
/// \param size New size of the rectangle
|
||||
///
|
||||
/// \see getSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setSize(const Vector2f& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the size of the rectangle
|
||||
///
|
||||
/// \return Size of the rectangle
|
||||
///
|
||||
/// \see setSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the number of points defining the shape
|
||||
///
|
||||
/// \return Number of points of the shape. For rectangle
|
||||
/// shapes, this number is always 4.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual std::size_t getPointCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a point of the rectangle
|
||||
///
|
||||
/// The returned point is in local coordinates, that is,
|
||||
/// the shape's transforms (position, rotation, scale) are
|
||||
/// not taken into account.
|
||||
/// The result is undefined if \a index is out of the valid range.
|
||||
///
|
||||
/// \param index Index of the point to get, in range [0 .. 3]
|
||||
///
|
||||
/// \return index-th point of the shape
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2f getPoint(std::size_t index) const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f m_size; ///< Size of the rectangle
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_RECTANGLESHAPE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::RectangleShape
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// This class inherits all the functions of sf::Transformable
|
||||
/// (position, rotation, scale, bounds, ...) as well as the
|
||||
/// functions of sf::Shape (outline, color, texture, ...).
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::RectangleShape rectangle;
|
||||
/// rectangle.setSize(sf::Vector2f(100, 50));
|
||||
/// rectangle.setOutlineColor(sf::Color::Red);
|
||||
/// rectangle.setOutlineThickness(5);
|
||||
/// rectangle.setPosition(10, 20);
|
||||
/// ...
|
||||
/// window.draw(rectangle);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Shape, sf::CircleShape, sf::ConvexShape
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
174
code/SFML-2.4.2/include/SFML/Graphics/RenderStates.hpp
Normal file
174
code/SFML-2.4.2/include/SFML/Graphics/RenderStates.hpp
Normal file
|
@ -0,0 +1,174 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_RENDERSTATES_HPP
|
||||
#define SFML_RENDERSTATES_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/BlendMode.hpp>
|
||||
#include <SFML/Graphics/Transform.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Shader;
|
||||
class Texture;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Define the states used for drawing to a RenderTarget
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API RenderStates
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Constructing a default set of render states is equivalent
|
||||
/// to using sf::RenderStates::Default.
|
||||
/// The default set defines:
|
||||
/// \li the BlendAlpha blend mode
|
||||
/// \li the identity transform
|
||||
/// \li a null texture
|
||||
/// \li a null shader
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a default set of render states with a custom blend mode
|
||||
///
|
||||
/// \param theBlendMode Blend mode to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates(const BlendMode& theBlendMode);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a default set of render states with a custom transform
|
||||
///
|
||||
/// \param theTransform Transform to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates(const Transform& theTransform);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a default set of render states with a custom texture
|
||||
///
|
||||
/// \param theTexture Texture to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates(const Texture* theTexture);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a default set of render states with a custom shader
|
||||
///
|
||||
/// \param theShader Shader to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates(const Shader* theShader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a set of render states with all its attributes
|
||||
///
|
||||
/// \param theBlendMode Blend mode to use
|
||||
/// \param theTransform Transform to use
|
||||
/// \param theTexture Texture to use
|
||||
/// \param theShader Shader to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderStates(const BlendMode& theBlendMode, const Transform& theTransform,
|
||||
const Texture* theTexture, const Shader* theShader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const RenderStates Default; ///< Special instance holding the default render states
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
BlendMode blendMode; ///< Blending mode
|
||||
Transform transform; ///< Transform
|
||||
const Texture* texture; ///< Texture
|
||||
const Shader* shader; ///< Shader
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_RENDERSTATES_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::RenderStates
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// There are four global states that can be applied to
|
||||
/// the drawn objects:
|
||||
/// \li the blend mode: how pixels of the object are blended with the background
|
||||
/// \li the transform: how the object is positioned/rotated/scaled
|
||||
/// \li the texture: what image is mapped to the object
|
||||
/// \li the shader: what custom effect is applied to the object
|
||||
///
|
||||
/// High-level objects such as sprites or text force some of
|
||||
/// these states when they are drawn. For example, a sprite
|
||||
/// will set its own texture, so that you don't have to care
|
||||
/// about it when drawing the sprite.
|
||||
///
|
||||
/// The transform is a special case: sprites, texts and shapes
|
||||
/// (and it's a good idea to do it with your own drawable classes
|
||||
/// too) combine their transform with the one that is passed in the
|
||||
/// RenderStates structure. So that you can use a "global" transform
|
||||
/// on top of each object's transform.
|
||||
///
|
||||
/// Most objects, especially high-level drawables, can be drawn
|
||||
/// directly without defining render states explicitly -- the
|
||||
/// default set of states is ok in most cases.
|
||||
/// \code
|
||||
/// window.draw(sprite);
|
||||
/// \endcode
|
||||
///
|
||||
/// If you want to use a single specific render state,
|
||||
/// for example a shader, you can pass it directly to the Draw
|
||||
/// function: sf::RenderStates has an implicit one-argument
|
||||
/// constructor for each state.
|
||||
/// \code
|
||||
/// window.draw(sprite, shader);
|
||||
/// \endcode
|
||||
///
|
||||
/// When you're inside the Draw function of a drawable
|
||||
/// object (inherited from sf::Drawable), you can
|
||||
/// either pass the render states unmodified, or change
|
||||
/// some of them.
|
||||
/// For example, a transformable object will combine the
|
||||
/// current transform with its own transform. A sprite will
|
||||
/// set its texture. Etc.
|
||||
///
|
||||
/// \see sf::RenderTarget, sf::Drawable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
459
code/SFML-2.4.2/include/SFML/Graphics/RenderTarget.hpp
Normal file
459
code/SFML-2.4.2/include/SFML/Graphics/RenderTarget.hpp
Normal file
|
@ -0,0 +1,459 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Export.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/View.hpp>
|
||||
#include <SFML/Graphics/Transform.hpp>
|
||||
#include <SFML/Graphics/BlendMode.hpp>
|
||||
#include <SFML/Graphics/RenderStates.hpp>
|
||||
#include <SFML/Graphics/PrimitiveType.hpp>
|
||||
#include <SFML/Graphics/Vertex.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Drawable;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Base class for all render targets (window, texture, ...)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API RenderTarget : NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~RenderTarget();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Clear the entire target with a single color
|
||||
///
|
||||
/// This function is usually called once every frame,
|
||||
/// to clear the previous contents of the target.
|
||||
///
|
||||
/// \param color Fill color to use to clear the render target
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void clear(const Color& color = Color(0, 0, 0, 255));
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the current active view
|
||||
///
|
||||
/// The view is like a 2D camera, it controls which part of
|
||||
/// the 2D scene is visible, and how it is viewed in the
|
||||
/// render target.
|
||||
/// The new view will affect everything that is drawn, until
|
||||
/// another view is set.
|
||||
/// The render target keeps its own copy of the view object,
|
||||
/// so it is not necessary to keep the original one alive
|
||||
/// after calling this function.
|
||||
/// To restore the original view of the target, you can pass
|
||||
/// the result of getDefaultView() to this function.
|
||||
///
|
||||
/// \param view New view to use
|
||||
///
|
||||
/// \see getView, getDefaultView
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setView(const View& view);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the view currently in use in the render target
|
||||
///
|
||||
/// \return The view object that is currently used
|
||||
///
|
||||
/// \see setView, getDefaultView
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const View& getView() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the default view of the render target
|
||||
///
|
||||
/// The default view has the initial size of the render target,
|
||||
/// and never changes after the target has been created.
|
||||
///
|
||||
/// \return The default view of the render target
|
||||
///
|
||||
/// \see setView, getView
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const View& getDefaultView() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the viewport of a view, applied to this render target
|
||||
///
|
||||
/// The viewport is defined in the view as a ratio, this function
|
||||
/// simply applies this ratio to the current dimensions of the
|
||||
/// render target to calculate the pixels rectangle that the viewport
|
||||
/// actually covers in the target.
|
||||
///
|
||||
/// \param view The view for which we want to compute the viewport
|
||||
///
|
||||
/// \return Viewport rectangle, expressed in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
IntRect getViewport(const View& view) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a point from target coordinates to world
|
||||
/// coordinates, using the current view
|
||||
///
|
||||
/// This function is an overload of the mapPixelToCoords
|
||||
/// function that implicitly uses the current view.
|
||||
/// It is equivalent to:
|
||||
/// \code
|
||||
/// target.mapPixelToCoords(point, target.getView());
|
||||
/// \endcode
|
||||
///
|
||||
/// \param point Pixel to convert
|
||||
///
|
||||
/// \return The converted point, in "world" coordinates
|
||||
///
|
||||
/// \see mapCoordsToPixel
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f mapPixelToCoords(const Vector2i& point) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a point from target coordinates to world coordinates
|
||||
///
|
||||
/// This function finds the 2D position that matches the
|
||||
/// given pixel of the render target. In other words, it does
|
||||
/// the inverse of what the graphics card does, to find the
|
||||
/// initial position of a rendered pixel.
|
||||
///
|
||||
/// Initially, both coordinate systems (world units and target pixels)
|
||||
/// match perfectly. But if you define a custom view or resize your
|
||||
/// render target, this assertion is not true anymore, i.e. a point
|
||||
/// located at (10, 50) in your render target may map to the point
|
||||
/// (150, 75) in your 2D world -- if the view is translated by (140, 25).
|
||||
///
|
||||
/// For render-windows, this function is typically used to find
|
||||
/// which point (or object) is located below the mouse cursor.
|
||||
///
|
||||
/// This version uses a custom view for calculations, see the other
|
||||
/// overload of the function if you want to use the current view of the
|
||||
/// render target.
|
||||
///
|
||||
/// \param point Pixel to convert
|
||||
/// \param view The view to use for converting the point
|
||||
///
|
||||
/// \return The converted point, in "world" units
|
||||
///
|
||||
/// \see mapCoordsToPixel
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f mapPixelToCoords(const Vector2i& point, const View& view) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a point from world coordinates to target
|
||||
/// coordinates, using the current view
|
||||
///
|
||||
/// This function is an overload of the mapCoordsToPixel
|
||||
/// function that implicitly uses the current view.
|
||||
/// It is equivalent to:
|
||||
/// \code
|
||||
/// target.mapCoordsToPixel(point, target.getView());
|
||||
/// \endcode
|
||||
///
|
||||
/// \param point Point to convert
|
||||
///
|
||||
/// \return The converted point, in target coordinates (pixels)
|
||||
///
|
||||
/// \see mapPixelToCoords
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i mapCoordsToPixel(const Vector2f& point) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a point from world coordinates to target coordinates
|
||||
///
|
||||
/// This function finds the pixel of the render target that matches
|
||||
/// the given 2D point. In other words, it goes through the same process
|
||||
/// as the graphics card, to compute the final position of a rendered point.
|
||||
///
|
||||
/// Initially, both coordinate systems (world units and target pixels)
|
||||
/// match perfectly. But if you define a custom view or resize your
|
||||
/// render target, this assertion is not true anymore, i.e. a point
|
||||
/// located at (150, 75) in your 2D world may map to the pixel
|
||||
/// (10, 50) of your render target -- if the view is translated by (140, 25).
|
||||
///
|
||||
/// This version uses a custom view for calculations, see the other
|
||||
/// overload of the function if you want to use the current view of the
|
||||
/// render target.
|
||||
///
|
||||
/// \param point Point to convert
|
||||
/// \param view The view to use for converting the point
|
||||
///
|
||||
/// \return The converted point, in target coordinates (pixels)
|
||||
///
|
||||
/// \see mapPixelToCoords
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw a drawable object to the render target
|
||||
///
|
||||
/// \param drawable Object to draw
|
||||
/// \param states Render states to use for drawing
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void draw(const Drawable& drawable, const RenderStates& states = RenderStates::Default);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw primitives defined by an array of vertices
|
||||
///
|
||||
/// \param vertices Pointer to the vertices
|
||||
/// \param vertexCount Number of vertices in the array
|
||||
/// \param type Type of primitives to draw
|
||||
/// \param states Render states to use for drawing
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void draw(const Vertex* vertices, std::size_t vertexCount,
|
||||
PrimitiveType type, const RenderStates& states = RenderStates::Default);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size of the rendering region of the target
|
||||
///
|
||||
/// \return Size in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2u getSize() const = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the render target for rendering
|
||||
///
|
||||
/// This function makes the render target's context current for
|
||||
/// future OpenGL rendering operations (so you shouldn't care
|
||||
/// about it if you're not doing direct OpenGL stuff).
|
||||
/// A render target's context is active only on the current thread,
|
||||
/// if you want to make it active on another thread you have
|
||||
/// to deactivate it on the previous thread first if it was active.
|
||||
/// Only one context can be current in a thread, so if you
|
||||
/// want to draw OpenGL geometry to another render target
|
||||
/// don't forget to activate it again. Activating a render
|
||||
/// target will automatically deactivate the previously active
|
||||
/// context (if any).
|
||||
///
|
||||
/// \param active True to activate, false to deactivate
|
||||
///
|
||||
/// \return True if operation was successful, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual bool setActive(bool active = true) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Save the current OpenGL render states and matrices
|
||||
///
|
||||
/// This function can be used when you mix SFML drawing
|
||||
/// and direct OpenGL rendering. Combined with popGLStates,
|
||||
/// it ensures that:
|
||||
/// \li SFML's internal states are not messed up by your OpenGL code
|
||||
/// \li your OpenGL states are not modified by a call to a SFML function
|
||||
///
|
||||
/// More specifically, it must be used around code that
|
||||
/// calls Draw functions. Example:
|
||||
/// \code
|
||||
/// // OpenGL code here...
|
||||
/// window.pushGLStates();
|
||||
/// window.draw(...);
|
||||
/// window.draw(...);
|
||||
/// window.popGLStates();
|
||||
/// // OpenGL code here...
|
||||
/// \endcode
|
||||
///
|
||||
/// Note that this function is quite expensive: it saves all the
|
||||
/// possible OpenGL states and matrices, even the ones you
|
||||
/// don't care about. Therefore it should be used wisely.
|
||||
/// It is provided for convenience, but the best results will
|
||||
/// be achieved if you handle OpenGL states yourself (because
|
||||
/// you know which states have really changed, and need to be
|
||||
/// saved and restored). Take a look at the resetGLStates
|
||||
/// function if you do so.
|
||||
///
|
||||
/// \see popGLStates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void pushGLStates();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Restore the previously saved OpenGL render states and matrices
|
||||
///
|
||||
/// See the description of pushGLStates to get a detailed
|
||||
/// description of these functions.
|
||||
///
|
||||
/// \see pushGLStates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void popGLStates();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Reset the internal OpenGL states so that the target is ready for drawing
|
||||
///
|
||||
/// This function can be used when you mix SFML drawing
|
||||
/// and direct OpenGL rendering, if you choose not to use
|
||||
/// pushGLStates/popGLStates. It makes sure that all OpenGL
|
||||
/// states needed by SFML are set, so that subsequent draw()
|
||||
/// calls will work as expected.
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// // OpenGL code here...
|
||||
/// glPushAttrib(...);
|
||||
/// window.resetGLStates();
|
||||
/// window.draw(...);
|
||||
/// window.draw(...);
|
||||
/// glPopAttrib(...);
|
||||
/// // OpenGL code here...
|
||||
/// \endcode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void resetGLStates();
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderTarget();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Performs the common initialization step after creation
|
||||
///
|
||||
/// The derived classes must call this function after the
|
||||
/// target is created and ready for drawing.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Apply the current view
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void applyCurrentView();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Apply a new blending mode
|
||||
///
|
||||
/// \param mode Blending mode to apply
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void applyBlendMode(const BlendMode& mode);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Apply a new transform
|
||||
///
|
||||
/// \param transform Transform to apply
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void applyTransform(const Transform& transform);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Apply a new texture
|
||||
///
|
||||
/// \param texture Texture to apply
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void applyTexture(const Texture* texture);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Apply a new shader
|
||||
///
|
||||
/// \param shader Shader to apply
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void applyShader(const Shader* shader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Render states cache
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct StatesCache
|
||||
{
|
||||
enum {VertexCacheSize = 4};
|
||||
|
||||
bool glStatesSet; ///< Are our internal GL states set yet?
|
||||
bool viewChanged; ///< Has the current view changed since last draw?
|
||||
BlendMode lastBlendMode; ///< Cached blending mode
|
||||
Uint64 lastTextureId; ///< Cached texture
|
||||
bool useVertexCache; ///< Did we previously use the vertex cache?
|
||||
Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertices cache
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
View m_defaultView; ///< Default view
|
||||
View m_view; ///< Current view
|
||||
StatesCache m_cache; ///< Render states cache
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_RENDERTARGET_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::RenderTarget
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::RenderTarget defines the common behavior of all the
|
||||
/// 2D render targets usable in the graphics module. It makes
|
||||
/// it possible to draw 2D entities like sprites, shapes, text
|
||||
/// without using any OpenGL command directly.
|
||||
///
|
||||
/// A sf::RenderTarget is also able to use views (sf::View),
|
||||
/// which are a kind of 2D cameras. With views you can globally
|
||||
/// scroll, rotate or zoom everything that is drawn,
|
||||
/// without having to transform every single entity. See the
|
||||
/// documentation of sf::View for more details and sample pieces of
|
||||
/// code about this class.
|
||||
///
|
||||
/// On top of that, render targets are still able to render direct
|
||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
||||
/// and regular SFML drawing commands. When doing so, make sure that
|
||||
/// OpenGL states are not messed up by calling the
|
||||
/// pushGLStates/popGLStates functions.
|
||||
///
|
||||
/// \see sf::RenderWindow, sf::RenderTexture, sf::View
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
283
code/SFML-2.4.2/include/SFML/Graphics/RenderTexture.hpp
Normal file
283
code/SFML-2.4.2/include/SFML/Graphics/RenderTexture.hpp
Normal file
|
@ -0,0 +1,283 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_RENDERTEXTURE_HPP
|
||||
#define SFML_RENDERTEXTURE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
class RenderTextureImpl;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Target for off-screen 2D rendering into a texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API RenderTexture : public RenderTarget
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Constructs an empty, invalid render-texture. You must
|
||||
/// call create to have a valid render-texture.
|
||||
///
|
||||
/// \see create
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderTexture();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~RenderTexture();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the render-texture
|
||||
///
|
||||
/// Before calling this function, the render-texture is in
|
||||
/// an invalid state, thus it is mandatory to call it before
|
||||
/// doing anything with the render-texture.
|
||||
/// The last parameter, \a depthBuffer, is useful if you want
|
||||
/// to use the render-texture for 3D OpenGL rendering that requires
|
||||
/// a depth buffer. Otherwise it is unnecessary, and you should
|
||||
/// leave this parameter to false (which is its default value).
|
||||
///
|
||||
/// \param width Width of the render-texture
|
||||
/// \param height Height of the render-texture
|
||||
/// \param depthBuffer Do you want this render-texture to have a depth buffer?
|
||||
///
|
||||
/// \return True if creation has been successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool create(unsigned int width, unsigned int height, bool depthBuffer = false);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable texture smoothing
|
||||
///
|
||||
/// This function is similar to Texture::setSmooth.
|
||||
/// This parameter is disabled by default.
|
||||
///
|
||||
/// \param smooth True to enable smoothing, false to disable it
|
||||
///
|
||||
/// \see isSmooth
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setSmooth(bool smooth);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether the smooth filtering is enabled or not
|
||||
///
|
||||
/// \return True if texture smoothing is enabled
|
||||
///
|
||||
/// \see setSmooth
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isSmooth() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable texture repeating
|
||||
///
|
||||
/// This function is similar to Texture::setRepeated.
|
||||
/// This parameter is disabled by default.
|
||||
///
|
||||
/// \param repeated True to enable repeating, false to disable it
|
||||
///
|
||||
/// \see isRepeated
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setRepeated(bool repeated);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether the texture is repeated or not
|
||||
///
|
||||
/// \return True if texture is repeated
|
||||
///
|
||||
/// \see setRepeated
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isRepeated() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Generate a mipmap using the current texture data
|
||||
///
|
||||
/// This function is similar to Texture::generateMipmap and operates
|
||||
/// on the texture used as the target for drawing.
|
||||
/// Be aware that any draw operation may modify the base level image data.
|
||||
/// For this reason, calling this function only makes sense after all
|
||||
/// drawing is completed and display has been called. Not calling display
|
||||
/// after subsequent drawing will lead to undefined behavior if a mipmap
|
||||
/// had been previously generated.
|
||||
///
|
||||
/// \return True if mipmap generation was successful, false if unsuccessful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool generateMipmap();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the render-texture for rendering
|
||||
///
|
||||
/// This function makes the render-texture's context current for
|
||||
/// future OpenGL rendering operations (so you shouldn't care
|
||||
/// about it if you're not doing direct OpenGL stuff).
|
||||
/// Only one context can be current in a thread, so if you
|
||||
/// want to draw OpenGL geometry to another render target
|
||||
/// (like a RenderWindow) don't forget to activate it again.
|
||||
///
|
||||
/// \param active True to activate, false to deactivate
|
||||
///
|
||||
/// \return True if operation was successful, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool setActive(bool active = true);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the contents of the target texture
|
||||
///
|
||||
/// This function updates the target texture with what
|
||||
/// has been drawn so far. Like for windows, calling this
|
||||
/// function is mandatory at the end of rendering. Not calling
|
||||
/// it may leave the texture in an undefined state.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void display();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size of the rendering region of the texture
|
||||
///
|
||||
/// The returned value is the size that you passed to
|
||||
/// the create function.
|
||||
///
|
||||
/// \return Size in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2u getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a read-only reference to the target texture
|
||||
///
|
||||
/// After drawing to the render-texture and calling Display,
|
||||
/// you can retrieve the updated texture using this function,
|
||||
/// and draw it using a sprite (for example).
|
||||
/// The internal sf::Texture of a render-texture is always the
|
||||
/// same instance, so that it is possible to call this function
|
||||
/// once and keep a reference to the texture even after it is
|
||||
/// modified.
|
||||
///
|
||||
/// \return Const reference to the texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture& getTexture() const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
priv::RenderTextureImpl* m_impl; ///< Platform/hardware specific implementation
|
||||
Texture m_texture; ///< Target texture to draw on
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_RENDERTEXTURE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::RenderTexture
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::RenderTexture is the little brother of sf::RenderWindow.
|
||||
/// It implements the same 2D drawing and OpenGL-related functions
|
||||
/// (see their base class sf::RenderTarget for more details),
|
||||
/// the difference is that the result is stored in an off-screen
|
||||
/// texture rather than being show in a window.
|
||||
///
|
||||
/// Rendering to a texture can be useful in a variety of situations:
|
||||
/// \li precomputing a complex static texture (like a level's background from multiple tiles)
|
||||
/// \li applying post-effects to the whole scene with shaders
|
||||
/// \li creating a sprite from a 3D object rendered with OpenGL
|
||||
/// \li etc.
|
||||
///
|
||||
/// Usage example:
|
||||
///
|
||||
/// \code
|
||||
/// // Create a new render-window
|
||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
||||
///
|
||||
/// // Create a new render-texture
|
||||
/// sf::RenderTexture texture;
|
||||
/// if (!texture.create(500, 500))
|
||||
/// return -1;
|
||||
///
|
||||
/// // The main loop
|
||||
/// while (window.isOpen())
|
||||
/// {
|
||||
/// // Event processing
|
||||
/// // ...
|
||||
///
|
||||
/// // Clear the whole texture with red color
|
||||
/// texture.clear(sf::Color::Red);
|
||||
///
|
||||
/// // Draw stuff to the texture
|
||||
/// texture.draw(sprite); // sprite is a sf::Sprite
|
||||
/// texture.draw(shape); // shape is a sf::Shape
|
||||
/// texture.draw(text); // text is a sf::Text
|
||||
///
|
||||
/// // We're done drawing to the texture
|
||||
/// texture.display();
|
||||
///
|
||||
/// // Now we start rendering to the window, clear it first
|
||||
/// window.clear();
|
||||
///
|
||||
/// // Draw the texture
|
||||
/// sf::Sprite sprite(texture.getTexture());
|
||||
/// window.draw(sprite);
|
||||
///
|
||||
/// // End the current frame and display its contents on screen
|
||||
/// window.display();
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// Like sf::RenderWindow, sf::RenderTexture is still able to render direct
|
||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
||||
/// and regular SFML drawing commands. If you need a depth buffer for
|
||||
/// 3D rendering, don't forget to request it when calling RenderTexture::create.
|
||||
///
|
||||
/// \see sf::RenderTarget, sf::RenderWindow, sf::View, sf::Texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
284
code/SFML-2.4.2/include/SFML/Graphics/RenderWindow.hpp
Normal file
284
code/SFML-2.4.2/include/SFML/Graphics/RenderWindow.hpp
Normal file
|
@ -0,0 +1,284 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Export.hpp>
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Window that can serve as a target for 2D drawing
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor doesn't actually create the window,
|
||||
/// use the other constructors or call create() to do so.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderWindow();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a new window
|
||||
///
|
||||
/// This constructor creates the window with the size and pixel
|
||||
/// depth defined in \a mode. An optional style can be passed to
|
||||
/// customize the look and behavior of the window (borders,
|
||||
/// title bar, resizable, closable, ...).
|
||||
///
|
||||
/// The fourth parameter is an optional structure specifying
|
||||
/// advanced OpenGL context settings such as antialiasing,
|
||||
/// depth-buffer bits, etc. You shouldn't care about these
|
||||
/// parameters for a regular usage of the graphics module.
|
||||
///
|
||||
/// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window)
|
||||
/// \param title Title of the window
|
||||
/// \param style %Window style, a bitwise OR combination of sf::Style enumerators
|
||||
/// \param settings Additional settings for the underlying OpenGL context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
RenderWindow(VideoMode mode, const String& title, Uint32 style = Style::Default, const ContextSettings& settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the window from an existing control
|
||||
///
|
||||
/// Use this constructor if you want to create an SFML
|
||||
/// rendering area into an already existing control.
|
||||
///
|
||||
/// The second parameter is an optional structure specifying
|
||||
/// advanced OpenGL context settings such as antialiasing,
|
||||
/// depth-buffer bits, etc. You shouldn't care about these
|
||||
/// parameters for a regular usage of the graphics module.
|
||||
///
|
||||
/// \param handle Platform-specific handle of the control (\a HWND on
|
||||
/// Windows, \a %Window on Linux/FreeBSD, \a NSWindow on OS X)
|
||||
/// \param settings Additional settings for the underlying OpenGL context
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit RenderWindow(WindowHandle handle, const ContextSettings& settings = ContextSettings());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
/// Closes the window and frees all the resources attached to it.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~RenderWindow();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the size of the rendering region of the window
|
||||
///
|
||||
/// The size doesn't include the titlebar and borders
|
||||
/// of the window.
|
||||
///
|
||||
/// \return Size in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2u getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Activate or deactivate the window as the current target
|
||||
/// for OpenGL rendering
|
||||
///
|
||||
/// A window is active only on the current thread, if you want to
|
||||
/// make it active on another thread you have to deactivate it
|
||||
/// on the previous thread first if it was active.
|
||||
/// Only one window can be active on a thread at a time, thus
|
||||
/// the window previously active (if any) automatically gets deactivated.
|
||||
/// This is not to be confused with requestFocus().
|
||||
///
|
||||
/// \param active True to activate, false to deactivate
|
||||
///
|
||||
/// \return True if operation was successful, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool setActive(bool active = true);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy the current contents of the window to an image
|
||||
///
|
||||
/// \deprecated
|
||||
/// Use a sf::Texture and its sf::Texture::update(const Window&)
|
||||
/// function and copy its contents into an sf::Image instead.
|
||||
/// \code
|
||||
/// sf::Vector2u windowSize = window.getSize();
|
||||
/// sf::Texture texture;
|
||||
/// texture.create(windowSize.x, windowSize.y);
|
||||
/// texture.update(window);
|
||||
/// sf::Image screenshot = texture.copyToImage();
|
||||
/// \endcode
|
||||
///
|
||||
/// This is a slow operation, whose main purpose is to make
|
||||
/// screenshots of the application. If you want to update an
|
||||
/// image with the contents of the window and then use it for
|
||||
/// drawing, you should rather use a sf::Texture and its
|
||||
/// update(Window&) function.
|
||||
/// You can also draw things directly to a texture with the
|
||||
/// sf::RenderTexture class.
|
||||
///
|
||||
/// \return Image containing the captured contents
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED Image capture() const;
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Function called after the window has been created
|
||||
///
|
||||
/// This function is called so that derived classes can
|
||||
/// perform their own specific initialization as soon as
|
||||
/// the window is created.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void onCreate();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Function called after the window has been resized
|
||||
///
|
||||
/// This function is called so that derived classes can
|
||||
/// perform custom actions when the size of the window changes.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void onResize();
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_RENDERWINDOW_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::RenderWindow
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::RenderWindow is the main class of the Graphics module.
|
||||
/// It defines an OS window that can be painted using the other
|
||||
/// classes of the graphics module.
|
||||
///
|
||||
/// sf::RenderWindow is derived from sf::Window, thus it inherits
|
||||
/// all its features: events, window management, OpenGL rendering,
|
||||
/// etc. See the documentation of sf::Window for a more complete
|
||||
/// description of all these features, as well as code examples.
|
||||
///
|
||||
/// On top of that, sf::RenderWindow adds more features related to
|
||||
/// 2D drawing with the graphics module (see its base class
|
||||
/// sf::RenderTarget for more details).
|
||||
/// Here is a typical rendering and event loop with a sf::RenderWindow:
|
||||
///
|
||||
/// \code
|
||||
/// // Declare and create a new render-window
|
||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
|
||||
///
|
||||
/// // Limit the framerate to 60 frames per second (this step is optional)
|
||||
/// window.setFramerateLimit(60);
|
||||
///
|
||||
/// // The main loop - ends as soon as the window is closed
|
||||
/// while (window.isOpen())
|
||||
/// {
|
||||
/// // Event processing
|
||||
/// sf::Event event;
|
||||
/// while (window.pollEvent(event))
|
||||
/// {
|
||||
/// // Request for closing the window
|
||||
/// if (event.type == sf::Event::Closed)
|
||||
/// window.close();
|
||||
/// }
|
||||
///
|
||||
/// // Clear the whole window before rendering a new frame
|
||||
/// window.clear();
|
||||
///
|
||||
/// // Draw some graphical entities
|
||||
/// window.draw(sprite);
|
||||
/// window.draw(circle);
|
||||
/// window.draw(text);
|
||||
///
|
||||
/// // End the current frame and display its contents on screen
|
||||
/// window.display();
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// Like sf::Window, sf::RenderWindow is still able to render direct
|
||||
/// OpenGL stuff. It is even possible to mix together OpenGL calls
|
||||
/// and regular SFML drawing commands.
|
||||
///
|
||||
/// \code
|
||||
/// // Create the render window
|
||||
/// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL");
|
||||
///
|
||||
/// // Create a sprite and a text to display
|
||||
/// sf::Sprite sprite;
|
||||
/// sf::Text text;
|
||||
/// ...
|
||||
///
|
||||
/// // Perform OpenGL initializations
|
||||
/// glMatrixMode(GL_PROJECTION);
|
||||
/// ...
|
||||
///
|
||||
/// // Start the rendering loop
|
||||
/// while (window.isOpen())
|
||||
/// {
|
||||
/// // Process events
|
||||
/// ...
|
||||
///
|
||||
/// // Draw a background sprite
|
||||
/// window.pushGLStates();
|
||||
/// window.draw(sprite);
|
||||
/// window.popGLStates();
|
||||
///
|
||||
/// // Draw a 3D object using OpenGL
|
||||
/// glBegin(GL_QUADS);
|
||||
/// glVertex3f(...);
|
||||
/// ...
|
||||
/// glEnd();
|
||||
///
|
||||
/// // Draw text on top of the 3D object
|
||||
/// window.pushGLStates();
|
||||
/// window.draw(text);
|
||||
/// window.popGLStates();
|
||||
///
|
||||
/// // Finally, display the rendered frame on screen
|
||||
/// window.display();
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
875
code/SFML-2.4.2/include/SFML/Graphics/Shader.hpp
Normal file
875
code/SFML-2.4.2/include/SFML/Graphics/Shader.hpp
Normal file
|
@ -0,0 +1,875 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_SHADER_HPP
|
||||
#define SFML_SHADER_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Glsl.hpp>
|
||||
#include <SFML/Window/GlResource.hpp>
|
||||
#include <SFML/System/NonCopyable.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Color;
|
||||
class InputStream;
|
||||
class Texture;
|
||||
class Transform;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Shader class (vertex, geometry and fragment)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Shader : GlResource, NonCopyable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Types of shaders
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum Type
|
||||
{
|
||||
Vertex, ///< %Vertex shader
|
||||
Geometry, ///< Geometry shader
|
||||
Fragment ///< Fragment (pixel) shader
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Special type that can be passed to setUniform(),
|
||||
/// and that represents the texture of the object being drawn
|
||||
///
|
||||
/// \see setUniform(const std::string&, CurrentTextureType)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct CurrentTextureType {};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Represents the texture of the object being drawn
|
||||
///
|
||||
/// \see setUniform(const std::string&, CurrentTextureType)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static CurrentTextureType CurrentTexture;
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor creates an invalid shader.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Shader();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Shader();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the vertex, geometry or fragment shader from a file
|
||||
///
|
||||
/// This function loads a single shader, vertex, geometry or
|
||||
/// fragment, identified by the second argument.
|
||||
/// The source must be a text file containing a valid
|
||||
/// shader in GLSL language. GLSL is a C-like language
|
||||
/// dedicated to OpenGL shaders; you'll probably need to
|
||||
/// read a good documentation for it before writing your
|
||||
/// own shaders.
|
||||
///
|
||||
/// \param filename Path of the vertex, geometry or fragment shader file to load
|
||||
/// \param type Type of shader (vertex, geometry or fragment)
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromMemory, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromFile(const std::string& filename, Type type);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load both the vertex and fragment shaders from files
|
||||
///
|
||||
/// This function loads both the vertex and the fragment
|
||||
/// shaders. If one of them fails to load, the shader is left
|
||||
/// empty (the valid shader is unloaded).
|
||||
/// The sources must be text files containing valid shaders
|
||||
/// in GLSL language. GLSL is a C-like language dedicated to
|
||||
/// OpenGL shaders; you'll probably need to read a good documentation
|
||||
/// for it before writing your own shaders.
|
||||
///
|
||||
/// \param vertexShaderFilename Path of the vertex shader file to load
|
||||
/// \param fragmentShaderFilename Path of the fragment shader file to load
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromMemory, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromFile(const std::string& vertexShaderFilename, const std::string& fragmentShaderFilename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the vertex, geometry and fragment shaders from files
|
||||
///
|
||||
/// This function loads the vertex, geometry and fragment
|
||||
/// shaders. If one of them fails to load, the shader is left
|
||||
/// empty (the valid shader is unloaded).
|
||||
/// The sources must be text files containing valid shaders
|
||||
/// in GLSL language. GLSL is a C-like language dedicated to
|
||||
/// OpenGL shaders; you'll probably need to read a good documentation
|
||||
/// for it before writing your own shaders.
|
||||
///
|
||||
/// \param vertexShaderFilename Path of the vertex shader file to load
|
||||
/// \param geometryShaderFilename Path of the geometry shader file to load
|
||||
/// \param fragmentShaderFilename Path of the fragment shader file to load
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromMemory, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromFile(const std::string& vertexShaderFilename, const std::string& geometryShaderFilename, const std::string& fragmentShaderFilename);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the vertex, geometry or fragment shader from a source code in memory
|
||||
///
|
||||
/// This function loads a single shader, vertex, geometry
|
||||
/// or fragment, identified by the second argument.
|
||||
/// The source code must be a valid shader in GLSL language.
|
||||
/// GLSL is a C-like language dedicated to OpenGL shaders;
|
||||
/// you'll probably need to read a good documentation for
|
||||
/// it before writing your own shaders.
|
||||
///
|
||||
/// \param shader String containing the source code of the shader
|
||||
/// \param type Type of shader (vertex, geometry or fragment)
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromMemory(const std::string& shader, Type type);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load both the vertex and fragment shaders from source codes in memory
|
||||
///
|
||||
/// This function loads both the vertex and the fragment
|
||||
/// shaders. If one of them fails to load, the shader is left
|
||||
/// empty (the valid shader is unloaded).
|
||||
/// The sources must be valid shaders in GLSL language. GLSL is
|
||||
/// a C-like language dedicated to OpenGL shaders; you'll
|
||||
/// probably need to read a good documentation for it before
|
||||
/// writing your own shaders.
|
||||
///
|
||||
/// \param vertexShader String containing the source code of the vertex shader
|
||||
/// \param fragmentShader String containing the source code of the fragment shader
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromMemory(const std::string& vertexShader, const std::string& fragmentShader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the vertex, geometry and fragment shaders from source codes in memory
|
||||
///
|
||||
/// This function loads the vertex, geometry and fragment
|
||||
/// shaders. If one of them fails to load, the shader is left
|
||||
/// empty (the valid shader is unloaded).
|
||||
/// The sources must be valid shaders in GLSL language. GLSL is
|
||||
/// a C-like language dedicated to OpenGL shaders; you'll
|
||||
/// probably need to read a good documentation for it before
|
||||
/// writing your own shaders.
|
||||
///
|
||||
/// \param vertexShader String containing the source code of the vertex shader
|
||||
/// \param geometryShader String containing the source code of the geometry shader
|
||||
/// \param fragmentShader String containing the source code of the fragment shader
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromStream
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromMemory(const std::string& vertexShader, const std::string& geometryShader, const std::string& fragmentShader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the vertex, geometry or fragment shader from a custom stream
|
||||
///
|
||||
/// This function loads a single shader, vertex, geometry
|
||||
/// or fragment, identified by the second argument.
|
||||
/// The source code must be a valid shader in GLSL language.
|
||||
/// GLSL is a C-like language dedicated to OpenGL shaders;
|
||||
/// you'll probably need to read a good documentation for it
|
||||
/// before writing your own shaders.
|
||||
///
|
||||
/// \param stream Source stream to read from
|
||||
/// \param type Type of shader (vertex, geometry or fragment)
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromMemory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromStream(InputStream& stream, Type type);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load both the vertex and fragment shaders from custom streams
|
||||
///
|
||||
/// This function loads both the vertex and the fragment
|
||||
/// shaders. If one of them fails to load, the shader is left
|
||||
/// empty (the valid shader is unloaded).
|
||||
/// The source codes must be valid shaders in GLSL language.
|
||||
/// GLSL is a C-like language dedicated to OpenGL shaders;
|
||||
/// you'll probably need to read a good documentation for
|
||||
/// it before writing your own shaders.
|
||||
///
|
||||
/// \param vertexShaderStream Source stream to read the vertex shader from
|
||||
/// \param fragmentShaderStream Source stream to read the fragment shader from
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromMemory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromStream(InputStream& vertexShaderStream, InputStream& fragmentShaderStream);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the vertex, geometry and fragment shaders from custom streams
|
||||
///
|
||||
/// This function loads the vertex, geometry and fragment
|
||||
/// shaders. If one of them fails to load, the shader is left
|
||||
/// empty (the valid shader is unloaded).
|
||||
/// The source codes must be valid shaders in GLSL language.
|
||||
/// GLSL is a C-like language dedicated to OpenGL shaders;
|
||||
/// you'll probably need to read a good documentation for
|
||||
/// it before writing your own shaders.
|
||||
///
|
||||
/// \param vertexShaderStream Source stream to read the vertex shader from
|
||||
/// \param geometryShaderStream Source stream to read the geometry shader from
|
||||
/// \param fragmentShaderStream Source stream to read the fragment shader from
|
||||
///
|
||||
/// \return True if loading succeeded, false if it failed
|
||||
///
|
||||
/// \see loadFromFile, loadFromMemory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromStream(InputStream& vertexShaderStream, InputStream& geometryShaderStream, InputStream& fragmentShaderStream);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p float uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param x Value of the float scalar
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, float x);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p vec2 uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the vec2 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Vec2& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p vec3 uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the vec3 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Vec3& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p vec4 uniform
|
||||
///
|
||||
/// This overload can also be called with sf::Color objects
|
||||
/// that are converted to sf::Glsl::Vec4.
|
||||
///
|
||||
/// It is important to note that the components of the color are
|
||||
/// normalized before being passed to the shader. Therefore,
|
||||
/// they are converted from range [0 .. 255] to range [0 .. 1].
|
||||
/// For example, a sf::Color(255, 127, 0, 255) will be transformed
|
||||
/// to a vec4(1.0, 0.5, 0.0, 1.0) in the shader.
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the vec4 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Vec4& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p int uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param x Value of the int scalar
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, int x);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p ivec2 uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the ivec2 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Ivec2& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p ivec3 uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the ivec3 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Ivec3& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p ivec4 uniform
|
||||
///
|
||||
/// This overload can also be called with sf::Color objects
|
||||
/// that are converted to sf::Glsl::Ivec4.
|
||||
///
|
||||
/// If color conversions are used, the ivec4 uniform in GLSL
|
||||
/// will hold the same values as the original sf::Color
|
||||
/// instance. For example, sf::Color(255, 127, 0, 255) is
|
||||
/// mapped to ivec4(255, 127, 0, 255).
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the ivec4 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Ivec4& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p bool uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param x Value of the bool scalar
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, bool x);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p bvec2 uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the bvec2 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Bvec2& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p bvec3 uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the bvec3 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Bvec3& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p bvec4 uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vector Value of the bvec4 vector
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Bvec4& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p mat3 matrix
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param matrix Value of the mat3 matrix
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Mat3& matrix);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify value for \p mat4 matrix
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param matrix Value of the mat4 matrix
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Glsl::Mat4& matrix);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify a texture as \p sampler2D uniform
|
||||
///
|
||||
/// \a name is the name of the variable to change in the shader.
|
||||
/// The corresponding parameter in the shader must be a 2D texture
|
||||
/// (\p sampler2D GLSL type).
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// uniform sampler2D the_texture; // this is the variable in the shader
|
||||
/// \endcode
|
||||
/// \code
|
||||
/// sf::Texture texture;
|
||||
/// ...
|
||||
/// shader.setUniform("the_texture", texture);
|
||||
/// \endcode
|
||||
/// It is important to note that \a texture must remain alive as long
|
||||
/// as the shader uses it, no copy is made internally.
|
||||
///
|
||||
/// To use the texture of the object being drawn, which cannot be
|
||||
/// known in advance, you can pass the special value
|
||||
/// sf::Shader::CurrentTexture:
|
||||
/// \code
|
||||
/// shader.setUniform("the_texture", sf::Shader::CurrentTexture).
|
||||
/// \endcode
|
||||
///
|
||||
/// \param name Name of the texture in the shader
|
||||
/// \param texture Texture to assign
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, const Texture& texture);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify current texture as \p sampler2D uniform
|
||||
///
|
||||
/// This overload maps a shader texture variable to the
|
||||
/// texture of the object being drawn, which cannot be
|
||||
/// known in advance. The second argument must be
|
||||
/// sf::Shader::CurrentTexture.
|
||||
/// The corresponding parameter in the shader must be a 2D texture
|
||||
/// (\p sampler2D GLSL type).
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// uniform sampler2D current; // this is the variable in the shader
|
||||
/// \endcode
|
||||
/// \code
|
||||
/// shader.setUniform("current", sf::Shader::CurrentTexture);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param name Name of the texture in the shader
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniform(const std::string& name, CurrentTextureType);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify values for \p float[] array uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param scalarArray pointer to array of \p float values
|
||||
/// \param length Number of elements in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniformArray(const std::string& name, const float* scalarArray, std::size_t length);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify values for \p vec2[] array uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vectorArray pointer to array of \p vec2 values
|
||||
/// \param length Number of elements in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniformArray(const std::string& name, const Glsl::Vec2* vectorArray, std::size_t length);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify values for \p vec3[] array uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vectorArray pointer to array of \p vec3 values
|
||||
/// \param length Number of elements in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniformArray(const std::string& name, const Glsl::Vec3* vectorArray, std::size_t length);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify values for \p vec4[] array uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param vectorArray pointer to array of \p vec4 values
|
||||
/// \param length Number of elements in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniformArray(const std::string& name, const Glsl::Vec4* vectorArray, std::size_t length);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify values for \p mat3[] array uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param matrixArray pointer to array of \p mat3 values
|
||||
/// \param length Number of elements in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniformArray(const std::string& name, const Glsl::Mat3* matrixArray, std::size_t length);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Specify values for \p mat4[] array uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable in GLSL
|
||||
/// \param matrixArray pointer to array of \p mat4 values
|
||||
/// \param length Number of elements in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setUniformArray(const std::string& name, const Glsl::Mat4* matrixArray, std::size_t length);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a float parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, float) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, float x);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a 2-components vector parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Glsl::Vec2&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, float x, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a 3-components vector parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Glsl::Vec3&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, float x, float y, float z);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a 4-components vector parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Glsl::Vec4&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, float x, float y, float z, float w);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a 2-components vector parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Glsl::Vec2&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, const Vector2f& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a 3-components vector parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Glsl::Vec3&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, const Vector3f& vector);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a color parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Glsl::Vec4&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a matrix parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Glsl::Mat4&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, const Transform& transform);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a texture parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, const Texture&) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, const Texture& texture);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change a texture parameter of the shader
|
||||
///
|
||||
/// \deprecated Use setUniform(const std::string&, CurrentTextureType) instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setParameter(const std::string& name, CurrentTextureType);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the underlying OpenGL handle of the shader.
|
||||
///
|
||||
/// You shouldn't need to use this function, unless you have
|
||||
/// very specific stuff to implement that SFML doesn't support,
|
||||
/// or implement a temporary workaround until a bug is fixed.
|
||||
///
|
||||
/// \return OpenGL handle of the shader or 0 if not yet loaded
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int getNativeHandle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Bind a shader for rendering
|
||||
///
|
||||
/// This function is not part of the graphics API, it mustn't be
|
||||
/// used when drawing SFML entities. It must be used only if you
|
||||
/// mix sf::Shader with OpenGL code.
|
||||
///
|
||||
/// \code
|
||||
/// sf::Shader s1, s2;
|
||||
/// ...
|
||||
/// sf::Shader::bind(&s1);
|
||||
/// // draw OpenGL stuff that use s1...
|
||||
/// sf::Shader::bind(&s2);
|
||||
/// // draw OpenGL stuff that use s2...
|
||||
/// sf::Shader::bind(NULL);
|
||||
/// // draw OpenGL stuff that use no shader...
|
||||
/// \endcode
|
||||
///
|
||||
/// \param shader Shader to bind, can be null to use no shader
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void bind(const Shader* shader);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether or not the system supports shaders
|
||||
///
|
||||
/// This function should always be called before using
|
||||
/// the shader features. If it returns false, then
|
||||
/// any attempt to use sf::Shader will fail.
|
||||
///
|
||||
/// \return True if shaders are supported, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool isAvailable();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether or not the system supports geometry shaders
|
||||
///
|
||||
/// This function should always be called before using
|
||||
/// the geometry shader features. If it returns false, then
|
||||
/// any attempt to use sf::Shader geometry shader features will fail.
|
||||
///
|
||||
/// This function can only return true if isAvailable() would also
|
||||
/// return true, since shaders in general have to be supported in
|
||||
/// order for geometry shaders to be supported as well.
|
||||
///
|
||||
/// Note: The first call to this function, whether by your
|
||||
/// code or SFML will result in a context switch.
|
||||
///
|
||||
/// \return True if geometry shaders are supported, false otherwise
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static bool isGeometryAvailable();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Compile the shader(s) and create the program
|
||||
///
|
||||
/// If one of the arguments is NULL, the corresponding shader
|
||||
/// is not created.
|
||||
///
|
||||
/// \param vertexShaderCode Source code of the vertex shader
|
||||
/// \param geometryShaderCode Source code of the geometry shader
|
||||
/// \param fragmentShaderCode Source code of the fragment shader
|
||||
///
|
||||
/// \return True on success, false if any error happened
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool compile(const char* vertexShaderCode, const char* geometryShaderCode, const char* fragmentShaderCode);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Bind all the textures used by the shader
|
||||
///
|
||||
/// This function each texture to a different unit, and
|
||||
/// updates the corresponding variables in the shader accordingly.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void bindTextures() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the location ID of a shader uniform
|
||||
///
|
||||
/// \param name Name of the uniform variable to search
|
||||
///
|
||||
/// \return Location ID of the uniform, or -1 if not found
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int getUniformLocation(const std::string& name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief RAII object to save and restore the program
|
||||
/// binding while uniforms are being set
|
||||
///
|
||||
/// Implementation is private in the .cpp file.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
struct UniformBinder;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Types
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef std::map<int, const Texture*> TextureTable;
|
||||
typedef std::map<std::string, int> UniformTable;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int m_shaderProgram; ///< OpenGL identifier for the program
|
||||
int m_currentTexture; ///< Location of the current texture in the shader
|
||||
TextureTable m_textures; ///< Texture variables in the shader, mapped to their location
|
||||
UniformTable m_uniforms; ///< Parameters location cache
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SHADER_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Shader
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// Shaders are programs written using a specific language,
|
||||
/// executed directly by the graphics card and allowing
|
||||
/// to apply real-time operations to the rendered entities.
|
||||
///
|
||||
/// There are three kinds of shaders:
|
||||
/// \li %Vertex shaders, that process vertices
|
||||
/// \li Geometry shaders, that process primitives
|
||||
/// \li Fragment (pixel) shaders, that process pixels
|
||||
///
|
||||
/// A sf::Shader can be composed of either a vertex shader
|
||||
/// alone, a geometry shader alone, a fragment shader alone,
|
||||
/// or any combination of them. (see the variants of the
|
||||
/// load functions).
|
||||
///
|
||||
/// Shaders are written in GLSL, which is a C-like
|
||||
/// language dedicated to OpenGL shaders. You'll probably
|
||||
/// need to learn its basics before writing your own shaders
|
||||
/// for SFML.
|
||||
///
|
||||
/// Like any C/C++ program, a GLSL shader has its own variables
|
||||
/// called \a uniforms that you can set from your C++ application.
|
||||
/// sf::Shader handles different types of uniforms:
|
||||
/// \li scalars: \p float, \p int, \p bool
|
||||
/// \li vectors (2, 3 or 4 components)
|
||||
/// \li matrices (3x3 or 4x4)
|
||||
/// \li samplers (textures)
|
||||
///
|
||||
/// Some SFML-specific types can be converted:
|
||||
/// \li sf::Color as a 4D vector (\p vec4)
|
||||
/// \li sf::Transform as matrices (\p mat3 or \p mat4)
|
||||
///
|
||||
/// Every uniform variable in a shader can be set through one of the
|
||||
/// setUniform() or setUniformArray() overloads. For example, if you
|
||||
/// have a shader with the following uniforms:
|
||||
/// \code
|
||||
/// uniform float offset;
|
||||
/// uniform vec3 point;
|
||||
/// uniform vec4 color;
|
||||
/// uniform mat4 matrix;
|
||||
/// uniform sampler2D overlay;
|
||||
/// uniform sampler2D current;
|
||||
/// \endcode
|
||||
/// You can set their values from C++ code as follows, using the types
|
||||
/// defined in the sf::Glsl namespace:
|
||||
/// \code
|
||||
/// shader.setUniform("offset", 2.f);
|
||||
/// shader.setUniform("point", sf::Vector3f(0.5f, 0.8f, 0.3f));
|
||||
/// shader.setUniform("color", sf::Glsl::Vec4(color)); // color is a sf::Color
|
||||
/// shader.setUniform("matrix", sf::Glsl::Mat4(transform)); // transform is a sf::Transform
|
||||
/// shader.setUniform("overlay", texture); // texture is a sf::Texture
|
||||
/// shader.setUniform("current", sf::Shader::CurrentTexture);
|
||||
/// \endcode
|
||||
///
|
||||
/// The old setParameter() overloads are deprecated and will be removed in a
|
||||
/// future version. You should use their setUniform() equivalents instead.
|
||||
///
|
||||
/// The special Shader::CurrentTexture argument maps the
|
||||
/// given \p sampler2D uniform to the current texture of the
|
||||
/// object being drawn (which cannot be known in advance).
|
||||
///
|
||||
/// To apply a shader to a drawable, you must pass it as an
|
||||
/// additional parameter to the \ref Window::draw() draw() function:
|
||||
/// \code
|
||||
/// window.draw(sprite, &shader);
|
||||
/// \endcode
|
||||
///
|
||||
/// ... which is in fact just a shortcut for this:
|
||||
/// \code
|
||||
/// sf::RenderStates states;
|
||||
/// states.shader = &shader;
|
||||
/// window.draw(sprite, states);
|
||||
/// \endcode
|
||||
///
|
||||
/// In the code above we pass a pointer to the shader, because it may
|
||||
/// be null (which means "no shader").
|
||||
///
|
||||
/// Shaders can be used on any drawable, but some combinations are
|
||||
/// not interesting. For example, using a vertex shader on a sf::Sprite
|
||||
/// is limited because there are only 4 vertices, the sprite would
|
||||
/// have to be subdivided in order to apply wave effects.
|
||||
/// Another bad example is a fragment shader with sf::Text: the texture
|
||||
/// of the text is not the actual text that you see on screen, it is
|
||||
/// a big texture containing all the characters of the font in an
|
||||
/// arbitrary order; thus, texture lookups on pixels other than the
|
||||
/// current one may not give you the expected result.
|
||||
///
|
||||
/// Shaders can also be used to apply global post-effects to the
|
||||
/// current contents of the target (like the old sf::PostFx class
|
||||
/// in SFML 1). This can be done in two different ways:
|
||||
/// \li draw everything to a sf::RenderTexture, then draw it to
|
||||
/// the main target using the shader
|
||||
/// \li draw everything directly to the main target, then use
|
||||
/// sf::Texture::update(Window&) to copy its contents to a texture
|
||||
/// and draw it to the main target using the shader
|
||||
///
|
||||
/// The first technique is more optimized because it doesn't involve
|
||||
/// retrieving the target's pixels to system memory, but the
|
||||
/// second one doesn't impact the rendering process and can be
|
||||
/// easily inserted anywhere without impacting all the code.
|
||||
///
|
||||
/// Like sf::Texture that can be used as a raw OpenGL texture,
|
||||
/// sf::Shader can also be used directly as a raw shader for
|
||||
/// custom OpenGL geometry.
|
||||
/// \code
|
||||
/// sf::Shader::bind(&shader);
|
||||
/// ... render OpenGL geometry ...
|
||||
/// sf::Shader::bind(NULL);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Glsl
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
355
code/SFML-2.4.2/include/SFML/Graphics/Shape.hpp
Normal file
355
code/SFML-2.4.2/include/SFML/Graphics/Shape.hpp
Normal file
|
@ -0,0 +1,355 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Export.hpp>
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/Transformable.hpp>
|
||||
#include <SFML/Graphics/VertexArray.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Base class for textured shapes with outline
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Shape : public Drawable, public Transformable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Virtual destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~Shape();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the source texture of the shape
|
||||
///
|
||||
/// The \a texture argument refers to a texture that must
|
||||
/// exist as long as the shape uses it. Indeed, the shape
|
||||
/// doesn't store its own copy of the texture, but rather keeps
|
||||
/// a pointer to the one that you passed to this function.
|
||||
/// If the source texture is destroyed and the shape tries to
|
||||
/// use it, the behavior is undefined.
|
||||
/// \a texture can be NULL to disable texturing.
|
||||
/// If \a resetRect is true, the TextureRect property of
|
||||
/// the shape is automatically adjusted to the size of the new
|
||||
/// texture. If it is false, the texture rect is left unchanged.
|
||||
///
|
||||
/// \param texture New texture
|
||||
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
||||
///
|
||||
/// \see getTexture, setTextureRect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setTexture(const Texture* texture, bool resetRect = false);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the sub-rectangle of the texture that the shape will display
|
||||
///
|
||||
/// The texture rect is useful when you don't want to display
|
||||
/// the whole texture, but rather a part of it.
|
||||
/// By default, the texture rect covers the entire texture.
|
||||
///
|
||||
/// \param rect Rectangle defining the region of the texture to display
|
||||
///
|
||||
/// \see getTextureRect, setTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setTextureRect(const IntRect& rect);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the fill color of the shape
|
||||
///
|
||||
/// This color is modulated (multiplied) with the shape's
|
||||
/// texture if any. It can be used to colorize the shape,
|
||||
/// or change its global opacity.
|
||||
/// You can use sf::Color::Transparent to make the inside of
|
||||
/// the shape transparent, and have the outline alone.
|
||||
/// By default, the shape's fill color is opaque white.
|
||||
///
|
||||
/// \param color New color of the shape
|
||||
///
|
||||
/// \see getFillColor, setOutlineColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setFillColor(const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the outline color of the shape
|
||||
///
|
||||
/// By default, the shape's outline color is opaque white.
|
||||
///
|
||||
/// \param color New outline color of the shape
|
||||
///
|
||||
/// \see getOutlineColor, setFillColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setOutlineColor(const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the thickness of the shape's outline
|
||||
///
|
||||
/// Note that negative values are allowed (so that the outline
|
||||
/// expands towards the center of the shape), and using zero
|
||||
/// disables the outline.
|
||||
/// By default, the outline thickness is 0.
|
||||
///
|
||||
/// \param thickness New outline thickness
|
||||
///
|
||||
/// \see getOutlineThickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setOutlineThickness(float thickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the source texture of the shape
|
||||
///
|
||||
/// If the shape has no source texture, a NULL pointer is returned.
|
||||
/// The returned pointer is const, which means that you can't
|
||||
/// modify the texture when you retrieve it with this function.
|
||||
///
|
||||
/// \return Pointer to the shape's texture
|
||||
///
|
||||
/// \see setTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture* getTexture() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the sub-rectangle of the texture displayed by the shape
|
||||
///
|
||||
/// \return Texture rectangle of the shape
|
||||
///
|
||||
/// \see setTextureRect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const IntRect& getTextureRect() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the fill color of the shape
|
||||
///
|
||||
/// \return Fill color of the shape
|
||||
///
|
||||
/// \see setFillColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& getFillColor() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the outline color of the shape
|
||||
///
|
||||
/// \return Outline color of the shape
|
||||
///
|
||||
/// \see setOutlineColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& getOutlineColor() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the outline thickness of the shape
|
||||
///
|
||||
/// \return Outline thickness of the shape
|
||||
///
|
||||
/// \see setOutlineThickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getOutlineThickness() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the total number of points of the shape
|
||||
///
|
||||
/// \return Number of points of the shape
|
||||
///
|
||||
/// \see getPoint
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual std::size_t getPointCount() const = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a point of the shape
|
||||
///
|
||||
/// The returned point is in local coordinates, that is,
|
||||
/// the shape's transforms (position, rotation, scale) are
|
||||
/// not taken into account.
|
||||
/// The result is undefined if \a index is out of the valid range.
|
||||
///
|
||||
/// \param index Index of the point to get, in range [0 .. getPointCount() - 1]
|
||||
///
|
||||
/// \return index-th point of the shape
|
||||
///
|
||||
/// \see getPointCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual Vector2f getPoint(std::size_t index) const = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the local bounding rectangle of the entity
|
||||
///
|
||||
/// The returned rectangle is in local coordinates, which means
|
||||
/// that it ignores the transformations (translation, rotation,
|
||||
/// scale, ...) that are applied to the entity.
|
||||
/// In other words, this function returns the bounds of the
|
||||
/// entity in the entity's coordinate system.
|
||||
///
|
||||
/// \return Local bounding rectangle of the entity
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect getLocalBounds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the global (non-minimal) bounding rectangle of the entity
|
||||
///
|
||||
/// The returned rectangle is in global coordinates, which means
|
||||
/// that it takes into account the transformations (translation,
|
||||
/// rotation, scale, ...) that are applied to the entity.
|
||||
/// In other words, this function returns the bounds of the
|
||||
/// shape in the global 2D world's coordinate system.
|
||||
///
|
||||
/// This function does not necessarily return the \a minimal
|
||||
/// bounding rectangle. It merely ensures that the returned
|
||||
/// rectangle covers all the vertices (but possibly more).
|
||||
/// This allows for a fast approximation of the bounds as a
|
||||
/// first check; you may want to use more precise checks
|
||||
/// on top of that.
|
||||
///
|
||||
/// \return Global bounding rectangle of the entity
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect getGlobalBounds() const;
|
||||
|
||||
protected:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Shape();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Recompute the internal geometry of the shape
|
||||
///
|
||||
/// This function must be called by the derived class everytime
|
||||
/// the shape's points change (i.e. the result of either
|
||||
/// getPointCount or getPoint is different).
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw the shape to a render target
|
||||
///
|
||||
/// \param target Render target to draw to
|
||||
/// \param states Current render states
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the fill vertices' color
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void updateFillColors();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the fill vertices' texture coordinates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void updateTexCoords();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the outline vertices' position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void updateOutline();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the outline vertices' color
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void updateOutlineColors();
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture* m_texture; ///< Texture of the shape
|
||||
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
||||
Color m_fillColor; ///< Fill color
|
||||
Color m_outlineColor; ///< Outline color
|
||||
float m_outlineThickness; ///< Thickness of the shape's outline
|
||||
VertexArray m_vertices; ///< Vertex array containing the fill geometry
|
||||
VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
|
||||
FloatRect m_insideBounds; ///< Bounding rectangle of the inside (fill)
|
||||
FloatRect m_bounds; ///< Bounding rectangle of the whole shape (outline + fill)
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SHAPE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Shape
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::Shape is a drawable class that allows to define and
|
||||
/// display a custom convex shape on a render target.
|
||||
/// It's only an abstract base, it needs to be specialized for
|
||||
/// concrete types of shapes (circle, rectangle, convex polygon,
|
||||
/// star, ...).
|
||||
///
|
||||
/// In addition to the attributes provided by the specialized
|
||||
/// shape classes, a shape always has the following attributes:
|
||||
/// \li a texture
|
||||
/// \li a texture rectangle
|
||||
/// \li a fill color
|
||||
/// \li an outline color
|
||||
/// \li an outline thickness
|
||||
///
|
||||
/// Each feature is optional, and can be disabled easily:
|
||||
/// \li the texture can be null
|
||||
/// \li the fill/outline colors can be sf::Color::Transparent
|
||||
/// \li the outline thickness can be zero
|
||||
///
|
||||
/// You can write your own derived shape class, there are only
|
||||
/// two virtual functions to override:
|
||||
/// \li getPointCount must return the number of points of the shape
|
||||
/// \li getPoint must return the points of the shape
|
||||
///
|
||||
/// \see sf::RectangleShape, sf::CircleShape, sf::ConvexShape, sf::Transformable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
279
code/SFML-2.4.2/include/SFML/Graphics/Sprite.hpp
Normal file
279
code/SFML-2.4.2/include/SFML/Graphics/Sprite.hpp
Normal file
|
@ -0,0 +1,279 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/Transformable.hpp>
|
||||
#include <SFML/Graphics/Vertex.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Texture;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Drawable representation of a texture, with its
|
||||
/// own transformations, color, etc.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates an empty sprite with no source texture.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Sprite();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the sprite from a source texture
|
||||
///
|
||||
/// \param texture Source texture
|
||||
///
|
||||
/// \see setTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit Sprite(const Texture& texture);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the sprite from a sub-rectangle of a source texture
|
||||
///
|
||||
/// \param texture Source texture
|
||||
/// \param rectangle Sub-rectangle of the texture to assign to the sprite
|
||||
///
|
||||
/// \see setTexture, setTextureRect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Sprite(const Texture& texture, const IntRect& rectangle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Change the source texture of the sprite
|
||||
///
|
||||
/// The \a texture argument refers to a texture that must
|
||||
/// exist as long as the sprite uses it. Indeed, the sprite
|
||||
/// doesn't store its own copy of the texture, but rather keeps
|
||||
/// a pointer to the one that you passed to this function.
|
||||
/// If the source texture is destroyed and the sprite tries to
|
||||
/// use it, the behavior is undefined.
|
||||
/// If \a resetRect is true, the TextureRect property of
|
||||
/// the sprite is automatically adjusted to the size of the new
|
||||
/// texture. If it is false, the texture rect is left unchanged.
|
||||
///
|
||||
/// \param texture New texture
|
||||
/// \param resetRect Should the texture rect be reset to the size of the new texture?
|
||||
///
|
||||
/// \see getTexture, setTextureRect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setTexture(const Texture& texture, bool resetRect = false);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the sub-rectangle of the texture that the sprite will display
|
||||
///
|
||||
/// The texture rect is useful when you don't want to display
|
||||
/// the whole texture, but rather a part of it.
|
||||
/// By default, the texture rect covers the entire texture.
|
||||
///
|
||||
/// \param rectangle Rectangle defining the region of the texture to display
|
||||
///
|
||||
/// \see getTextureRect, setTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setTextureRect(const IntRect& rectangle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the global color of the sprite
|
||||
///
|
||||
/// This color is modulated (multiplied) with the sprite's
|
||||
/// texture. It can be used to colorize the sprite, or change
|
||||
/// its global opacity.
|
||||
/// By default, the sprite's color is opaque white.
|
||||
///
|
||||
/// \param color New color of the sprite
|
||||
///
|
||||
/// \see getColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setColor(const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the source texture of the sprite
|
||||
///
|
||||
/// If the sprite has no source texture, a NULL pointer is returned.
|
||||
/// The returned pointer is const, which means that you can't
|
||||
/// modify the texture when you retrieve it with this function.
|
||||
///
|
||||
/// \return Pointer to the sprite's texture
|
||||
///
|
||||
/// \see setTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture* getTexture() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the sub-rectangle of the texture displayed by the sprite
|
||||
///
|
||||
/// \return Texture rectangle of the sprite
|
||||
///
|
||||
/// \see setTextureRect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const IntRect& getTextureRect() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the global color of the sprite
|
||||
///
|
||||
/// \return Global color of the sprite
|
||||
///
|
||||
/// \see setColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& getColor() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the local bounding rectangle of the entity
|
||||
///
|
||||
/// The returned rectangle is in local coordinates, which means
|
||||
/// that it ignores the transformations (translation, rotation,
|
||||
/// scale, ...) that are applied to the entity.
|
||||
/// In other words, this function returns the bounds of the
|
||||
/// entity in the entity's coordinate system.
|
||||
///
|
||||
/// \return Local bounding rectangle of the entity
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect getLocalBounds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the global bounding rectangle of the entity
|
||||
///
|
||||
/// The returned rectangle is in global coordinates, which means
|
||||
/// that it takes into account the transformations (translation,
|
||||
/// rotation, scale, ...) that are applied to the entity.
|
||||
/// In other words, this function returns the bounds of the
|
||||
/// sprite in the global 2D world's coordinate system.
|
||||
///
|
||||
/// \return Global bounding rectangle of the entity
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect getGlobalBounds() const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw the sprite to a render target
|
||||
///
|
||||
/// \param target Render target to draw to
|
||||
/// \param states Current render states
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the vertices' positions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void updatePositions();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the vertices' texture coordinates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void updateTexCoords();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex m_vertices[4]; ///< Vertices defining the sprite's geometry
|
||||
const Texture* m_texture; ///< Texture of the sprite
|
||||
IntRect m_textureRect; ///< Rectangle defining the area of the source texture to display
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_SPRITE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Sprite
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::Sprite is a drawable class that allows to easily display
|
||||
/// a texture (or a part of it) on a render target.
|
||||
///
|
||||
/// It inherits all the functions from sf::Transformable:
|
||||
/// position, rotation, scale, origin. It also adds sprite-specific
|
||||
/// properties such as the texture to use, the part of it to display,
|
||||
/// and some convenience functions to change the overall color of the
|
||||
/// sprite, or to get its bounding rectangle.
|
||||
///
|
||||
/// sf::Sprite works in combination with the sf::Texture class, which
|
||||
/// loads and provides the pixel data of a given texture.
|
||||
///
|
||||
/// The separation of sf::Sprite and sf::Texture allows more flexibility
|
||||
/// and better performances: indeed a sf::Texture is a heavy resource,
|
||||
/// and any operation on it is slow (often too slow for real-time
|
||||
/// applications). On the other side, a sf::Sprite is a lightweight
|
||||
/// object which can use the pixel data of a sf::Texture and draw
|
||||
/// it with its own transformation/color/blending attributes.
|
||||
///
|
||||
/// It is important to note that the sf::Sprite instance doesn't
|
||||
/// copy the texture that it uses, it only keeps a reference to it.
|
||||
/// Thus, a sf::Texture must not be destroyed while it is
|
||||
/// used by a sf::Sprite (i.e. never write a function that
|
||||
/// uses a local sf::Texture instance for creating a sprite).
|
||||
///
|
||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Declare and load a texture
|
||||
/// sf::Texture texture;
|
||||
/// texture.loadFromFile("texture.png");
|
||||
///
|
||||
/// // Create a sprite
|
||||
/// sf::Sprite sprite;
|
||||
/// sprite.setTexture(texture);
|
||||
/// sprite.setTextureRect(sf::IntRect(10, 10, 50, 30));
|
||||
/// sprite.setColor(sf::Color(255, 255, 255, 200));
|
||||
/// sprite.setPosition(100, 25);
|
||||
///
|
||||
/// // Draw it
|
||||
/// window.draw(sprite);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Texture, sf::Transformable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
456
code/SFML-2.4.2/include/SFML/Graphics/Text.hpp
Normal file
456
code/SFML-2.4.2/include/SFML/Graphics/Text.hpp
Normal file
|
@ -0,0 +1,456 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_TEXT_HPP
|
||||
#define SFML_TEXT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/Transformable.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/VertexArray.hpp>
|
||||
#include <SFML/System/String.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Graphical text that can be drawn to a render target
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Text : public Drawable, public Transformable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enumeration of the string drawing styles
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum Style
|
||||
{
|
||||
Regular = 0, ///< Regular characters, no style
|
||||
Bold = 1 << 0, ///< Bold characters
|
||||
Italic = 1 << 1, ///< Italic characters
|
||||
Underlined = 1 << 2, ///< Underlined characters
|
||||
StrikeThrough = 1 << 3 ///< Strike through characters
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates an empty text.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Text();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the text from a string, font and size
|
||||
///
|
||||
/// Note that if the used font is a bitmap font, it is not
|
||||
/// scalable, thus not all requested sizes will be available
|
||||
/// to use. This needs to be taken into consideration when
|
||||
/// setting the character size. If you need to display text
|
||||
/// of a certain size, make sure the corresponding bitmap
|
||||
/// font that supports that size is used.
|
||||
///
|
||||
/// \param string Text assigned to the string
|
||||
/// \param font Font used to draw the string
|
||||
/// \param characterSize Base size of characters, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Text(const String& string, const Font& font, unsigned int characterSize = 30);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the text's string
|
||||
///
|
||||
/// The \a string argument is a sf::String, which can
|
||||
/// automatically be constructed from standard string types.
|
||||
/// So, the following calls are all valid:
|
||||
/// \code
|
||||
/// text.setString("hello");
|
||||
/// text.setString(L"hello");
|
||||
/// text.setString(std::string("hello"));
|
||||
/// text.setString(std::wstring(L"hello"));
|
||||
/// \endcode
|
||||
/// A text's string is empty by default.
|
||||
///
|
||||
/// \param string New string
|
||||
///
|
||||
/// \see getString
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setString(const String& string);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the text's font
|
||||
///
|
||||
/// The \a font argument refers to a font that must
|
||||
/// exist as long as the text uses it. Indeed, the text
|
||||
/// doesn't store its own copy of the font, but rather keeps
|
||||
/// a pointer to the one that you passed to this function.
|
||||
/// If the font is destroyed and the text tries to
|
||||
/// use it, the behavior is undefined.
|
||||
///
|
||||
/// \param font New font
|
||||
///
|
||||
/// \see getFont
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setFont(const Font& font);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the character size
|
||||
///
|
||||
/// The default size is 30.
|
||||
///
|
||||
/// Note that if the used font is a bitmap font, it is not
|
||||
/// scalable, thus not all requested sizes will be available
|
||||
/// to use. This needs to be taken into consideration when
|
||||
/// setting the character size. If you need to display text
|
||||
/// of a certain size, make sure the corresponding bitmap
|
||||
/// font that supports that size is used.
|
||||
///
|
||||
/// \param size New character size, in pixels
|
||||
///
|
||||
/// \see getCharacterSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setCharacterSize(unsigned int size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the text's style
|
||||
///
|
||||
/// You can pass a combination of one or more styles, for
|
||||
/// example sf::Text::Bold | sf::Text::Italic.
|
||||
/// The default style is sf::Text::Regular.
|
||||
///
|
||||
/// \param style New style
|
||||
///
|
||||
/// \see getStyle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setStyle(Uint32 style);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the fill color of the text
|
||||
///
|
||||
/// By default, the text's fill color is opaque white.
|
||||
/// Setting the fill color to a transparent color with an outline
|
||||
/// will cause the outline to be displayed in the fill area of the text.
|
||||
///
|
||||
/// \param color New fill color of the text
|
||||
///
|
||||
/// \see getFillColor
|
||||
///
|
||||
/// \deprecated There is now fill and outline colors instead
|
||||
/// of a single global color.
|
||||
/// Use setFillColor() or setOutlineColor() instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED void setColor(const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the fill color of the text
|
||||
///
|
||||
/// By default, the text's fill color is opaque white.
|
||||
/// Setting the fill color to a transparent color with an outline
|
||||
/// will cause the outline to be displayed in the fill area of the text.
|
||||
///
|
||||
/// \param color New fill color of the text
|
||||
///
|
||||
/// \see getFillColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setFillColor(const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the outline color of the text
|
||||
///
|
||||
/// By default, the text's outline color is opaque black.
|
||||
///
|
||||
/// \param color New outline color of the text
|
||||
///
|
||||
/// \see getOutlineColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setOutlineColor(const Color& color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the thickness of the text's outline
|
||||
///
|
||||
/// By default, the outline thickness is 0.
|
||||
///
|
||||
/// Be aware that using a negative value for the outline
|
||||
/// thickness will cause distorted rendering.
|
||||
///
|
||||
/// \param thickness New outline thickness, in pixels
|
||||
///
|
||||
/// \see getOutlineThickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setOutlineThickness(float thickness);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the text's string
|
||||
///
|
||||
/// The returned string is a sf::String, which can automatically
|
||||
/// be converted to standard string types. So, the following
|
||||
/// lines of code are all valid:
|
||||
/// \code
|
||||
/// sf::String s1 = text.getString();
|
||||
/// std::string s2 = text.getString();
|
||||
/// std::wstring s3 = text.getString();
|
||||
/// \endcode
|
||||
///
|
||||
/// \return Text's string
|
||||
///
|
||||
/// \see setString
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const String& getString() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the text's font
|
||||
///
|
||||
/// If the text has no font attached, a NULL pointer is returned.
|
||||
/// The returned pointer is const, which means that you
|
||||
/// cannot modify the font when you get it from this function.
|
||||
///
|
||||
/// \return Pointer to the text's font
|
||||
///
|
||||
/// \see setFont
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Font* getFont() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the character size
|
||||
///
|
||||
/// \return Size of the characters, in pixels
|
||||
///
|
||||
/// \see setCharacterSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int getCharacterSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the text's style
|
||||
///
|
||||
/// \return Text's style
|
||||
///
|
||||
/// \see setStyle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Uint32 getStyle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the fill color of the text
|
||||
///
|
||||
/// \return Fill color of the text
|
||||
///
|
||||
/// \see setFillColor
|
||||
///
|
||||
/// \deprecated There is now fill and outline colors instead
|
||||
/// of a single global color.
|
||||
/// Use getFillColor() or getOutlineColor() instead.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_DEPRECATED const Color& getColor() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the fill color of the text
|
||||
///
|
||||
/// \return Fill color of the text
|
||||
///
|
||||
/// \see setFillColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& getFillColor() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the outline color of the text
|
||||
///
|
||||
/// \return Outline color of the text
|
||||
///
|
||||
/// \see setOutlineColor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Color& getOutlineColor() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the outline thickness of the text
|
||||
///
|
||||
/// \return Outline thickness of the text, in pixels
|
||||
///
|
||||
/// \see setOutlineThickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getOutlineThickness() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the position of the \a index-th character
|
||||
///
|
||||
/// This function computes the visual position of a character
|
||||
/// from its index in the string. The returned position is
|
||||
/// in global coordinates (translation, rotation, scale and
|
||||
/// origin are applied).
|
||||
/// If \a index is out of range, the position of the end of
|
||||
/// the string is returned.
|
||||
///
|
||||
/// \param index Index of the character
|
||||
///
|
||||
/// \return Position of the character
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f findCharacterPos(std::size_t index) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the local bounding rectangle of the entity
|
||||
///
|
||||
/// The returned rectangle is in local coordinates, which means
|
||||
/// that it ignores the transformations (translation, rotation,
|
||||
/// scale, ...) that are applied to the entity.
|
||||
/// In other words, this function returns the bounds of the
|
||||
/// entity in the entity's coordinate system.
|
||||
///
|
||||
/// \return Local bounding rectangle of the entity
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect getLocalBounds() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the global bounding rectangle of the entity
|
||||
///
|
||||
/// The returned rectangle is in global coordinates, which means
|
||||
/// that it takes into account the transformations (translation,
|
||||
/// rotation, scale, ...) that are applied to the entity.
|
||||
/// In other words, this function returns the bounds of the
|
||||
/// text in the global 2D world's coordinate system.
|
||||
///
|
||||
/// \return Global bounding rectangle of the entity
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect getGlobalBounds() const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw the text to a render target
|
||||
///
|
||||
/// \param target Render target to draw to
|
||||
/// \param states Current render states
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Make sure the text's geometry is updated
|
||||
///
|
||||
/// All the attributes related to rendering are cached, such
|
||||
/// that the geometry is only updated when necessary.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void ensureGeometryUpdate() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
String m_string; ///< String to display
|
||||
const Font* m_font; ///< Font used to display the string
|
||||
unsigned int m_characterSize; ///< Base size of characters, in pixels
|
||||
Uint32 m_style; ///< Text style (see Style enum)
|
||||
Color m_fillColor; ///< Text fill color
|
||||
Color m_outlineColor; ///< Text outline color
|
||||
float m_outlineThickness; ///< Thickness of the text's outline
|
||||
mutable VertexArray m_vertices; ///< Vertex array containing the fill geometry
|
||||
mutable VertexArray m_outlineVertices; ///< Vertex array containing the outline geometry
|
||||
mutable FloatRect m_bounds; ///< Bounding rectangle of the text (in local coordinates)
|
||||
mutable bool m_geometryNeedUpdate; ///< Does the geometry need to be recomputed?
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TEXT_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Text
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::Text is a drawable class that allows to easily display
|
||||
/// some text with custom style and color on a render target.
|
||||
///
|
||||
/// It inherits all the functions from sf::Transformable:
|
||||
/// position, rotation, scale, origin. It also adds text-specific
|
||||
/// properties such as the font to use, the character size,
|
||||
/// the font style (bold, italic, underlined, strike through), the
|
||||
/// global color and the text to display of course.
|
||||
/// It also provides convenience functions to calculate the
|
||||
/// graphical size of the text, or to get the global position
|
||||
/// of a given character.
|
||||
///
|
||||
/// sf::Text works in combination with the sf::Font class, which
|
||||
/// loads and provides the glyphs (visual characters) of a given font.
|
||||
///
|
||||
/// The separation of sf::Font and sf::Text allows more flexibility
|
||||
/// and better performances: indeed a sf::Font is a heavy resource,
|
||||
/// and any operation on it is slow (often too slow for real-time
|
||||
/// applications). On the other side, a sf::Text is a lightweight
|
||||
/// object which can combine the glyphs data and metrics of a sf::Font
|
||||
/// to display any text on a render target.
|
||||
///
|
||||
/// It is important to note that the sf::Text instance doesn't
|
||||
/// copy the font that it uses, it only keeps a reference to it.
|
||||
/// Thus, a sf::Font must not be destructed while it is
|
||||
/// used by a sf::Text (i.e. never write a function that
|
||||
/// uses a local sf::Font instance for creating a text).
|
||||
///
|
||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // Declare and load a font
|
||||
/// sf::Font font;
|
||||
/// font.loadFromFile("arial.ttf");
|
||||
///
|
||||
/// // Create a text
|
||||
/// sf::Text text("hello", font);
|
||||
/// text.setCharacterSize(30);
|
||||
/// text.setStyle(sf::Text::Bold);
|
||||
/// text.setColor(sf::Color::Red);
|
||||
///
|
||||
/// // Draw it
|
||||
/// window.draw(text);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Font, sf::Transformable
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
686
code/SFML-2.4.2/include/SFML/Graphics/Texture.hpp
Normal file
686
code/SFML-2.4.2/include/SFML/Graphics/Texture.hpp
Normal file
|
@ -0,0 +1,686 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_TEXTURE_HPP
|
||||
#define SFML_TEXTURE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Window/GlResource.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Window;
|
||||
class RenderTarget;
|
||||
class RenderTexture;
|
||||
class InputStream;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Image living on the graphics card that can be used for drawing
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Texture : GlResource
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Types of texture coordinates that can be used for rendering
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
enum CoordinateType
|
||||
{
|
||||
Normalized, ///< Texture coordinates in range [0 .. 1]
|
||||
Pixels ///< Texture coordinates in range [0 .. size]
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates an empty texture.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy constructor
|
||||
///
|
||||
/// \param copy instance to copy
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture(const Texture& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
~Texture();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create the texture
|
||||
///
|
||||
/// If this function fails, the texture is left unchanged.
|
||||
///
|
||||
/// \param width Width of the texture
|
||||
/// \param height Height of the texture
|
||||
///
|
||||
/// \return True if creation was successful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool create(unsigned int width, unsigned int height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the texture from a file on disk
|
||||
///
|
||||
/// This function is a shortcut for the following code:
|
||||
/// \code
|
||||
/// sf::Image image;
|
||||
/// image.loadFromFile(filename);
|
||||
/// texture.loadFromImage(image, area);
|
||||
/// \endcode
|
||||
///
|
||||
/// The \a area argument can be used to load only a sub-rectangle
|
||||
/// of the whole image. If you want the entire image then leave
|
||||
/// the default value (which is an empty IntRect).
|
||||
/// If the \a area rectangle crosses the bounds of the image, it
|
||||
/// is adjusted to fit the image size.
|
||||
///
|
||||
/// The maximum size for a texture depends on the graphics
|
||||
/// driver and can be retrieved with the getMaximumSize function.
|
||||
///
|
||||
/// If this function fails, the texture is left unchanged.
|
||||
///
|
||||
/// \param filename Path of the image file to load
|
||||
/// \param area Area of the image to load
|
||||
///
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
/// \see loadFromMemory, loadFromStream, loadFromImage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromFile(const std::string& filename, const IntRect& area = IntRect());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the texture from a file in memory
|
||||
///
|
||||
/// This function is a shortcut for the following code:
|
||||
/// \code
|
||||
/// sf::Image image;
|
||||
/// image.loadFromMemory(data, size);
|
||||
/// texture.loadFromImage(image, area);
|
||||
/// \endcode
|
||||
///
|
||||
/// The \a area argument can be used to load only a sub-rectangle
|
||||
/// of the whole image. If you want the entire image then leave
|
||||
/// the default value (which is an empty IntRect).
|
||||
/// If the \a area rectangle crosses the bounds of the image, it
|
||||
/// is adjusted to fit the image size.
|
||||
///
|
||||
/// The maximum size for a texture depends on the graphics
|
||||
/// driver and can be retrieved with the getMaximumSize function.
|
||||
///
|
||||
/// If this function fails, the texture is left unchanged.
|
||||
///
|
||||
/// \param data Pointer to the file data in memory
|
||||
/// \param size Size of the data to load, in bytes
|
||||
/// \param area Area of the image to load
|
||||
///
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
/// \see loadFromFile, loadFromStream, loadFromImage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromMemory(const void* data, std::size_t size, const IntRect& area = IntRect());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the texture from a custom stream
|
||||
///
|
||||
/// This function is a shortcut for the following code:
|
||||
/// \code
|
||||
/// sf::Image image;
|
||||
/// image.loadFromStream(stream);
|
||||
/// texture.loadFromImage(image, area);
|
||||
/// \endcode
|
||||
///
|
||||
/// The \a area argument can be used to load only a sub-rectangle
|
||||
/// of the whole image. If you want the entire image then leave
|
||||
/// the default value (which is an empty IntRect).
|
||||
/// If the \a area rectangle crosses the bounds of the image, it
|
||||
/// is adjusted to fit the image size.
|
||||
///
|
||||
/// The maximum size for a texture depends on the graphics
|
||||
/// driver and can be retrieved with the getMaximumSize function.
|
||||
///
|
||||
/// If this function fails, the texture is left unchanged.
|
||||
///
|
||||
/// \param stream Source stream to read from
|
||||
/// \param area Area of the image to load
|
||||
///
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
/// \see loadFromFile, loadFromMemory, loadFromImage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromStream(InputStream& stream, const IntRect& area = IntRect());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Load the texture from an image
|
||||
///
|
||||
/// The \a area argument can be used to load only a sub-rectangle
|
||||
/// of the whole image. If you want the entire image then leave
|
||||
/// the default value (which is an empty IntRect).
|
||||
/// If the \a area rectangle crosses the bounds of the image, it
|
||||
/// is adjusted to fit the image size.
|
||||
///
|
||||
/// The maximum size for a texture depends on the graphics
|
||||
/// driver and can be retrieved with the getMaximumSize function.
|
||||
///
|
||||
/// If this function fails, the texture is left unchanged.
|
||||
///
|
||||
/// \param image Image to load into the texture
|
||||
/// \param area Area of the image to load
|
||||
///
|
||||
/// \return True if loading was successful
|
||||
///
|
||||
/// \see loadFromFile, loadFromMemory
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool loadFromImage(const Image& image, const IntRect& area = IntRect());
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the size of the texture
|
||||
///
|
||||
/// \return Size in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Copy the texture pixels to an image
|
||||
///
|
||||
/// This function performs a slow operation that downloads
|
||||
/// the texture's pixels from the graphics card and copies
|
||||
/// them to a new image, potentially applying transformations
|
||||
/// to pixels if necessary (texture may be padded or flipped).
|
||||
///
|
||||
/// \return Image containing the texture's pixels
|
||||
///
|
||||
/// \see loadFromImage
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Image copyToImage() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the whole texture from an array of pixels
|
||||
///
|
||||
/// The \a pixel array is assumed to have the same size as
|
||||
/// the \a area rectangle, and to contain 32-bits RGBA pixels.
|
||||
///
|
||||
/// No additional check is performed on the size of the pixel
|
||||
/// array, passing invalid arguments will lead to an undefined
|
||||
/// behavior.
|
||||
///
|
||||
/// This function does nothing if \a pixels is null or if the
|
||||
/// texture was not previously created.
|
||||
///
|
||||
/// \param pixels Array of pixels to copy to the texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update(const Uint8* pixels);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update a part of the texture from an array of pixels
|
||||
///
|
||||
/// The size of the \a pixel array must match the \a width and
|
||||
/// \a height arguments, and it must contain 32-bits RGBA pixels.
|
||||
///
|
||||
/// No additional check is performed on the size of the pixel
|
||||
/// array or the bounds of the area to update, passing invalid
|
||||
/// arguments will lead to an undefined behavior.
|
||||
///
|
||||
/// This function does nothing if \a pixels is null or if the
|
||||
/// texture was not previously created.
|
||||
///
|
||||
/// \param pixels Array of pixels to copy to the texture
|
||||
/// \param width Width of the pixel region contained in \a pixels
|
||||
/// \param height Height of the pixel region contained in \a pixels
|
||||
/// \param x X offset in the texture where to copy the source pixels
|
||||
/// \param y Y offset in the texture where to copy the source pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the texture from an image
|
||||
///
|
||||
/// Although the source image can be smaller than the texture,
|
||||
/// this function is usually used for updating the whole texture.
|
||||
/// The other overload, which has (x, y) additional arguments,
|
||||
/// is more convenient for updating a sub-area of the texture.
|
||||
///
|
||||
/// No additional check is performed on the size of the image,
|
||||
/// passing an image bigger than the texture will lead to an
|
||||
/// undefined behavior.
|
||||
///
|
||||
/// This function does nothing if the texture was not
|
||||
/// previously created.
|
||||
///
|
||||
/// \param image Image to copy to the texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update(const Image& image);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update a part of the texture from an image
|
||||
///
|
||||
/// No additional check is performed on the size of the image,
|
||||
/// passing an invalid combination of image size and offset
|
||||
/// will lead to an undefined behavior.
|
||||
///
|
||||
/// This function does nothing if the texture was not
|
||||
/// previously created.
|
||||
///
|
||||
/// \param image Image to copy to the texture
|
||||
/// \param x X offset in the texture where to copy the source image
|
||||
/// \param y Y offset in the texture where to copy the source image
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update(const Image& image, unsigned int x, unsigned int y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update the texture from the contents of a window
|
||||
///
|
||||
/// Although the source window can be smaller than the texture,
|
||||
/// this function is usually used for updating the whole texture.
|
||||
/// The other overload, which has (x, y) additional arguments,
|
||||
/// is more convenient for updating a sub-area of the texture.
|
||||
///
|
||||
/// No additional check is performed on the size of the window,
|
||||
/// passing a window bigger than the texture will lead to an
|
||||
/// undefined behavior.
|
||||
///
|
||||
/// This function does nothing if either the texture or the window
|
||||
/// was not previously created.
|
||||
///
|
||||
/// \param window Window to copy to the texture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update(const Window& window);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Update a part of the texture from the contents of a window
|
||||
///
|
||||
/// No additional check is performed on the size of the window,
|
||||
/// passing an invalid combination of window size and offset
|
||||
/// will lead to an undefined behavior.
|
||||
///
|
||||
/// This function does nothing if either the texture or the window
|
||||
/// was not previously created.
|
||||
///
|
||||
/// \param window Window to copy to the texture
|
||||
/// \param x X offset in the texture where to copy the source window
|
||||
/// \param y Y offset in the texture where to copy the source window
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void update(const Window& window, unsigned int x, unsigned int y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable the smooth filter
|
||||
///
|
||||
/// When the filter is activated, the texture appears smoother
|
||||
/// so that pixels are less noticeable. However if you want
|
||||
/// the texture to look exactly the same as its source file,
|
||||
/// you should leave it disabled.
|
||||
/// The smooth filter is disabled by default.
|
||||
///
|
||||
/// \param smooth True to enable smoothing, false to disable it
|
||||
///
|
||||
/// \see isSmooth
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setSmooth(bool smooth);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether the smooth filter is enabled or not
|
||||
///
|
||||
/// \return True if smoothing is enabled, false if it is disabled
|
||||
///
|
||||
/// \see setSmooth
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isSmooth() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable conversion from sRGB
|
||||
///
|
||||
/// When providing texture data from an image file or memory, it can
|
||||
/// either be stored in a linear color space or an sRGB color space.
|
||||
/// Most digital images account for gamma correction already, so they
|
||||
/// would need to be "uncorrected" back to linear color space before
|
||||
/// being processed by the hardware. The hardware can automatically
|
||||
/// convert it from the sRGB color space to a linear color space when
|
||||
/// it gets sampled. When the rendered image gets output to the final
|
||||
/// framebuffer, it gets converted back to sRGB.
|
||||
///
|
||||
/// After enabling or disabling sRGB conversion, make sure to reload
|
||||
/// the texture data in order for the setting to take effect.
|
||||
///
|
||||
/// This option is only useful in conjunction with an sRGB capable
|
||||
/// framebuffer. This can be requested during window creation.
|
||||
///
|
||||
/// \param sRgb True to enable sRGB conversion, false to disable it
|
||||
///
|
||||
/// \see isSrgb
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setSrgb(bool sRgb);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether the texture source is converted from sRGB or not
|
||||
///
|
||||
/// \return True if the texture source is converted from sRGB, false if not
|
||||
///
|
||||
/// \see setSrgb
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isSrgb() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Enable or disable repeating
|
||||
///
|
||||
/// Repeating is involved when using texture coordinates
|
||||
/// outside the texture rectangle [0, 0, width, height].
|
||||
/// In this case, if repeat mode is enabled, the whole texture
|
||||
/// will be repeated as many times as needed to reach the
|
||||
/// coordinate (for example, if the X texture coordinate is
|
||||
/// 3 * width, the texture will be repeated 3 times).
|
||||
/// If repeat mode is disabled, the "extra space" will instead
|
||||
/// be filled with border pixels.
|
||||
/// Warning: on very old graphics cards, white pixels may appear
|
||||
/// when the texture is repeated. With such cards, repeat mode
|
||||
/// can be used reliably only if the texture has power-of-two
|
||||
/// dimensions (such as 256x128).
|
||||
/// Repeating is disabled by default.
|
||||
///
|
||||
/// \param repeated True to repeat the texture, false to disable repeating
|
||||
///
|
||||
/// \see isRepeated
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setRepeated(bool repeated);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Tell whether the texture is repeated or not
|
||||
///
|
||||
/// \return True if repeat mode is enabled, false if it is disabled
|
||||
///
|
||||
/// \see setRepeated
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isRepeated() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Generate a mipmap using the current texture data
|
||||
///
|
||||
/// Mipmaps are pre-computed chains of optimized textures. Each
|
||||
/// level of texture in a mipmap is generated by halving each of
|
||||
/// the previous level's dimensions. This is done until the final
|
||||
/// level has the size of 1x1. The textures generated in this process may
|
||||
/// make use of more advanced filters which might improve the visual quality
|
||||
/// of textures when they are applied to objects much smaller than they are.
|
||||
/// This is known as minification. Because fewer texels (texture elements)
|
||||
/// have to be sampled from when heavily minified, usage of mipmaps
|
||||
/// can also improve rendering performance in certain scenarios.
|
||||
///
|
||||
/// Mipmap generation relies on the necessary OpenGL extension being
|
||||
/// available. If it is unavailable or generation fails due to another
|
||||
/// reason, this function will return false. Mipmap data is only valid from
|
||||
/// the time it is generated until the next time the base level image is
|
||||
/// modified, at which point this function will have to be called again to
|
||||
/// regenerate it.
|
||||
///
|
||||
/// \return True if mipmap generation was successful, false if unsuccessful
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool generateMipmap();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Overload of assignment operator
|
||||
///
|
||||
/// \param right Instance to assign
|
||||
///
|
||||
/// \return Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture& operator =(const Texture& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the underlying OpenGL handle of the texture.
|
||||
///
|
||||
/// You shouldn't need to use this function, unless you have
|
||||
/// very specific stuff to implement that SFML doesn't support,
|
||||
/// or implement a temporary workaround until a bug is fixed.
|
||||
///
|
||||
/// \return OpenGL handle of the texture or 0 if not yet created
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int getNativeHandle() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Bind a texture for rendering
|
||||
///
|
||||
/// This function is not part of the graphics API, it mustn't be
|
||||
/// used when drawing SFML entities. It must be used only if you
|
||||
/// mix sf::Texture with OpenGL code.
|
||||
///
|
||||
/// \code
|
||||
/// sf::Texture t1, t2;
|
||||
/// ...
|
||||
/// sf::Texture::bind(&t1);
|
||||
/// // draw OpenGL stuff that use t1...
|
||||
/// sf::Texture::bind(&t2);
|
||||
/// // draw OpenGL stuff that use t2...
|
||||
/// sf::Texture::bind(NULL);
|
||||
/// // draw OpenGL stuff that use no texture...
|
||||
/// \endcode
|
||||
///
|
||||
/// The \a coordinateType argument controls how texture
|
||||
/// coordinates will be interpreted. If Normalized (the default), they
|
||||
/// must be in range [0 .. 1], which is the default way of handling
|
||||
/// texture coordinates with OpenGL. If Pixels, they must be given
|
||||
/// in pixels (range [0 .. size]). This mode is used internally by
|
||||
/// the graphics classes of SFML, it makes the definition of texture
|
||||
/// coordinates more intuitive for the high-level API, users don't need
|
||||
/// to compute normalized values.
|
||||
///
|
||||
/// \param texture Pointer to the texture to bind, can be null to use no texture
|
||||
/// \param coordinateType Type of texture coordinates to use
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void bind(const Texture* texture, CoordinateType coordinateType = Normalized);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the maximum texture size allowed
|
||||
///
|
||||
/// This maximum size is defined by the graphics driver.
|
||||
/// You can expect a value of 512 pixels for low-end graphics
|
||||
/// card, and up to 8192 pixels or more for newer hardware.
|
||||
///
|
||||
/// \return Maximum size allowed for textures, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static unsigned int getMaximumSize();
|
||||
|
||||
private:
|
||||
|
||||
friend class RenderTexture;
|
||||
friend class RenderTarget;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a valid image size according to hardware support
|
||||
///
|
||||
/// This function checks whether the graphics driver supports
|
||||
/// non power of two sizes or not, and adjusts the size
|
||||
/// accordingly.
|
||||
/// The returned size is greater than or equal to the original size.
|
||||
///
|
||||
/// \param size size to convert
|
||||
///
|
||||
/// \return Valid nearest size (greater than or equal to specified size)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static unsigned int getValidSize(unsigned int size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Invalidate the mipmap if one exists
|
||||
///
|
||||
/// This also resets the texture's minifying function.
|
||||
/// This function is mainly for internal use by RenderTexture.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void invalidateMipmap();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2u m_size; ///< Public texture size
|
||||
Vector2u m_actualSize; ///< Actual texture size (can be greater than public size because of padding)
|
||||
unsigned int m_texture; ///< Internal texture identifier
|
||||
bool m_isSmooth; ///< Status of the smooth filter
|
||||
bool m_sRgb; ///< Should the texture source be converted from sRGB?
|
||||
bool m_isRepeated; ///< Is the texture in repeat mode?
|
||||
mutable bool m_pixelsFlipped; ///< To work around the inconsistency in Y orientation
|
||||
bool m_fboAttachment; ///< Is this texture owned by a framebuffer object?
|
||||
bool m_hasMipmap; ///< Has the mipmap been generated?
|
||||
Uint64 m_cacheId; ///< Unique number that identifies the texture to the render target's cache
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TEXTURE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Texture
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::Texture stores pixels that can be drawn, with a sprite
|
||||
/// for example. A texture lives in the graphics card memory,
|
||||
/// therefore it is very fast to draw a texture to a render target,
|
||||
/// or copy a render target to a texture (the graphics card can
|
||||
/// access both directly).
|
||||
///
|
||||
/// Being stored in the graphics card memory has some drawbacks.
|
||||
/// A texture cannot be manipulated as freely as a sf::Image,
|
||||
/// you need to prepare the pixels first and then upload them
|
||||
/// to the texture in a single operation (see Texture::update).
|
||||
///
|
||||
/// sf::Texture makes it easy to convert from/to sf::Image, but
|
||||
/// keep in mind that these calls require transfers between
|
||||
/// the graphics card and the central memory, therefore they are
|
||||
/// slow operations.
|
||||
///
|
||||
/// A texture can be loaded from an image, but also directly
|
||||
/// from a file/memory/stream. The necessary shortcuts are defined
|
||||
/// so that you don't need an image first for the most common cases.
|
||||
/// However, if you want to perform some modifications on the pixels
|
||||
/// before creating the final texture, you can load your file to a
|
||||
/// sf::Image, do whatever you need with the pixels, and then call
|
||||
/// Texture::loadFromImage.
|
||||
///
|
||||
/// Since they live in the graphics card memory, the pixels of a texture
|
||||
/// cannot be accessed without a slow copy first. And they cannot be
|
||||
/// accessed individually. Therefore, if you need to read the texture's
|
||||
/// pixels (like for pixel-perfect collisions), it is recommended to
|
||||
/// store the collision information separately, for example in an array
|
||||
/// of booleans.
|
||||
///
|
||||
/// Like sf::Image, sf::Texture can handle a unique internal
|
||||
/// representation of pixels, which is RGBA 32 bits. This means
|
||||
/// that a pixel must be composed of 8 bits red, green, blue and
|
||||
/// alpha channels -- just like a sf::Color.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// // This example shows the most common use of sf::Texture:
|
||||
/// // drawing a sprite
|
||||
///
|
||||
/// // Load a texture from a file
|
||||
/// sf::Texture texture;
|
||||
/// if (!texture.loadFromFile("texture.png"))
|
||||
/// return -1;
|
||||
///
|
||||
/// // Assign it to a sprite
|
||||
/// sf::Sprite sprite;
|
||||
/// sprite.setTexture(texture);
|
||||
///
|
||||
/// // Draw the textured sprite
|
||||
/// window.draw(sprite);
|
||||
/// \endcode
|
||||
///
|
||||
/// \code
|
||||
/// // This example shows another common use of sf::Texture:
|
||||
/// // streaming real-time data, like video frames
|
||||
///
|
||||
/// // Create an empty texture
|
||||
/// sf::Texture texture;
|
||||
/// if (!texture.create(640, 480))
|
||||
/// return -1;
|
||||
///
|
||||
/// // Create a sprite that will display the texture
|
||||
/// sf::Sprite sprite(texture);
|
||||
///
|
||||
/// while (...) // the main loop
|
||||
/// {
|
||||
/// ...
|
||||
///
|
||||
/// // update the texture
|
||||
/// sf::Uint8* pixels = ...; // get a fresh chunk of pixels (the next frame of a movie, for example)
|
||||
/// texture.update(pixels);
|
||||
///
|
||||
/// // draw it
|
||||
/// window.draw(sprite);
|
||||
///
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// \endcode
|
||||
///
|
||||
/// Like sf::Shader that can be used as a raw OpenGL shader,
|
||||
/// sf::Texture can also be used directly as a raw texture for
|
||||
/// custom OpenGL geometry.
|
||||
/// \code
|
||||
/// sf::Texture::bind(&texture);
|
||||
/// ... render OpenGL geometry ...
|
||||
/// sf::Texture::bind(NULL);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Sprite, sf::Image, sf::RenderTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
450
code/SFML-2.4.2/include/SFML/Graphics/Transform.hpp
Normal file
450
code/SFML-2.4.2/include/SFML/Graphics/Transform.hpp
Normal file
|
@ -0,0 +1,450 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_TRANSFORM_HPP
|
||||
#define SFML_TRANSFORM_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Define a 3x3 transform matrix
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Transform
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates an identity transform (a transform that does nothing).
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct a transform from a 3x3 matrix
|
||||
///
|
||||
/// \param a00 Element (0, 0) of the matrix
|
||||
/// \param a01 Element (0, 1) of the matrix
|
||||
/// \param a02 Element (0, 2) of the matrix
|
||||
/// \param a10 Element (1, 0) of the matrix
|
||||
/// \param a11 Element (1, 1) of the matrix
|
||||
/// \param a12 Element (1, 2) of the matrix
|
||||
/// \param a20 Element (2, 0) of the matrix
|
||||
/// \param a21 Element (2, 1) of the matrix
|
||||
/// \param a22 Element (2, 2) of the matrix
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform(float a00, float a01, float a02,
|
||||
float a10, float a11, float a12,
|
||||
float a20, float a21, float a22);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the transform as a 4x4 matrix
|
||||
///
|
||||
/// This function returns a pointer to an array of 16 floats
|
||||
/// containing the transform elements as a 4x4 matrix, which
|
||||
/// is directly compatible with OpenGL functions.
|
||||
///
|
||||
/// \code
|
||||
/// sf::Transform transform = ...;
|
||||
/// glLoadMatrixf(transform.getMatrix());
|
||||
/// \endcode
|
||||
///
|
||||
/// \return Pointer to a 4x4 matrix
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const float* getMatrix() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the inverse of the transform
|
||||
///
|
||||
/// If the inverse cannot be computed, an identity transform
|
||||
/// is returned.
|
||||
///
|
||||
/// \return A new transform which is the inverse of self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform getInverse() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Transform a 2D point
|
||||
///
|
||||
/// \param x X coordinate of the point to transform
|
||||
/// \param y Y coordinate of the point to transform
|
||||
///
|
||||
/// \return Transformed point
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f transformPoint(float x, float y) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Transform a 2D point
|
||||
///
|
||||
/// \param point Point to transform
|
||||
///
|
||||
/// \return Transformed point
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f transformPoint(const Vector2f& point) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Transform a rectangle
|
||||
///
|
||||
/// Since SFML doesn't provide support for oriented rectangles,
|
||||
/// the result of this function is always an axis-aligned
|
||||
/// rectangle. Which means that if the transform contains a
|
||||
/// rotation, the bounding rectangle of the transformed rectangle
|
||||
/// is returned.
|
||||
///
|
||||
/// \param rectangle Rectangle to transform
|
||||
///
|
||||
/// \return Transformed rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect transformRect(const FloatRect& rectangle) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with another one
|
||||
///
|
||||
/// The result is a transform that is equivalent to applying
|
||||
/// *this followed by \a transform. Mathematically, it is
|
||||
/// equivalent to a matrix multiplication.
|
||||
///
|
||||
/// \param transform Transform to combine with this transform
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& combine(const Transform& transform);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a translation
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.translate(100, 200).rotate(45);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param x Offset to apply on X axis
|
||||
/// \param y Offset to apply on Y axis
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see rotate, scale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& translate(float x, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a translation
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.translate(sf::Vector2f(100, 200)).rotate(45);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param offset Translation offset to apply
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see rotate, scale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& translate(const Vector2f& offset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a rotation
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.rotate(90).translate(50, 20);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param angle Rotation angle, in degrees
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see translate, scale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& rotate(float angle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a rotation
|
||||
///
|
||||
/// The center of rotation is provided for convenience as a second
|
||||
/// argument, so that you can build rotations around arbitrary points
|
||||
/// more easily (and efficiently) than the usual
|
||||
/// translate(-center).rotate(angle).translate(center).
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.rotate(90, 8, 3).translate(50, 20);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param angle Rotation angle, in degrees
|
||||
/// \param centerX X coordinate of the center of rotation
|
||||
/// \param centerY Y coordinate of the center of rotation
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see translate, scale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& rotate(float angle, float centerX, float centerY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a rotation
|
||||
///
|
||||
/// The center of rotation is provided for convenience as a second
|
||||
/// argument, so that you can build rotations around arbitrary points
|
||||
/// more easily (and efficiently) than the usual
|
||||
/// translate(-center).rotate(angle).translate(center).
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.rotate(90, sf::Vector2f(8, 3)).translate(sf::Vector2f(50, 20));
|
||||
/// \endcode
|
||||
///
|
||||
/// \param angle Rotation angle, in degrees
|
||||
/// \param center Center of rotation
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see translate, scale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& rotate(float angle, const Vector2f& center);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a scaling
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.scale(2, 1).rotate(45);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param scaleX Scaling factor on the X axis
|
||||
/// \param scaleY Scaling factor on the Y axis
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see translate, rotate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& scale(float scaleX, float scaleY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a scaling
|
||||
///
|
||||
/// The center of scaling is provided for convenience as a second
|
||||
/// argument, so that you can build scaling around arbitrary points
|
||||
/// more easily (and efficiently) than the usual
|
||||
/// translate(-center).scale(factors).translate(center).
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.scale(2, 1, 8, 3).rotate(45);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param scaleX Scaling factor on X axis
|
||||
/// \param scaleY Scaling factor on Y axis
|
||||
/// \param centerX X coordinate of the center of scaling
|
||||
/// \param centerY Y coordinate of the center of scaling
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see translate, rotate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& scale(float scaleX, float scaleY, float centerX, float centerY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a scaling
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.scale(sf::Vector2f(2, 1)).rotate(45);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param factors Scaling factors
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see translate, rotate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& scale(const Vector2f& factors);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Combine the current transform with a scaling
|
||||
///
|
||||
/// The center of scaling is provided for convenience as a second
|
||||
/// argument, so that you can build scaling around arbitrary points
|
||||
/// more easily (and efficiently) than the usual
|
||||
/// translate(-center).scale(factors).translate(center).
|
||||
///
|
||||
/// This function returns a reference to *this, so that calls
|
||||
/// can be chained.
|
||||
/// \code
|
||||
/// sf::Transform transform;
|
||||
/// transform.scale(sf::Vector2f(2, 1), sf::Vector2f(8, 3)).rotate(45);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param factors Scaling factors
|
||||
/// \param center Center of scaling
|
||||
///
|
||||
/// \return Reference to *this
|
||||
///
|
||||
/// \see translate, rotate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transform& scale(const Vector2f& factors, const Vector2f& center);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Static member data
|
||||
////////////////////////////////////////////////////////////
|
||||
static const Transform Identity; ///< The identity transform (does nothing)
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
float m_matrix[16]; ///< 4x4 matrix defining the transformation
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates sf::Transform
|
||||
/// \brief Overload of binary operator * to combine two transforms
|
||||
///
|
||||
/// This call is equivalent to calling Transform(left).combine(right).
|
||||
///
|
||||
/// \param left Left operand (the first transform)
|
||||
/// \param right Right operand (the second transform)
|
||||
///
|
||||
/// \return New combined transform
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Transform operator *(const Transform& left, const Transform& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates sf::Transform
|
||||
/// \brief Overload of binary operator *= to combine two transforms
|
||||
///
|
||||
/// This call is equivalent to calling left.combine(right).
|
||||
///
|
||||
/// \param left Left operand (the first transform)
|
||||
/// \param right Right operand (the second transform)
|
||||
///
|
||||
/// \return The combined transform
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Transform& operator *=(Transform& left, const Transform& right);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \relates sf::Transform
|
||||
/// \brief Overload of binary operator * to transform a point
|
||||
///
|
||||
/// This call is equivalent to calling left.transformPoint(right).
|
||||
///
|
||||
/// \param left Left operand (the transform)
|
||||
/// \param right Right operand (the point to transform)
|
||||
///
|
||||
/// \return New transformed point
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_GRAPHICS_API Vector2f operator *(const Transform& left, const Vector2f& right);
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TRANSFORM_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Transform
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// A sf::Transform specifies how to translate, rotate, scale,
|
||||
/// shear, project, whatever things. In mathematical terms, it defines
|
||||
/// how to transform a coordinate system into another.
|
||||
///
|
||||
/// For example, if you apply a rotation transform to a sprite, the
|
||||
/// result will be a rotated sprite. And anything that is transformed
|
||||
/// by this rotation transform will be rotated the same way, according
|
||||
/// to its initial position.
|
||||
///
|
||||
/// Transforms are typically used for drawing. But they can also be
|
||||
/// used for any computation that requires to transform points between
|
||||
/// the local and global coordinate systems of an entity (like collision
|
||||
/// detection).
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// // define a translation transform
|
||||
/// sf::Transform translation;
|
||||
/// translation.translate(20, 50);
|
||||
///
|
||||
/// // define a rotation transform
|
||||
/// sf::Transform rotation;
|
||||
/// rotation.rotate(45);
|
||||
///
|
||||
/// // combine them
|
||||
/// sf::Transform transform = translation * rotation;
|
||||
///
|
||||
/// // use the result to transform stuff...
|
||||
/// sf::Vector2f point = transform.transformPoint(10, 20);
|
||||
/// sf::FloatRect rect = transform.transformRect(sf::FloatRect(0, 0, 10, 100));
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Transformable, sf::RenderStates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
429
code/SFML-2.4.2/include/SFML/Graphics/Transformable.hpp
Normal file
429
code/SFML-2.4.2/include/SFML/Graphics/Transformable.hpp
Normal file
|
@ -0,0 +1,429 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_TRANSFORMABLE_HPP
|
||||
#define SFML_TRANSFORMABLE_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Transform.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Decomposed transform defined by a position, a rotation and a scale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Transformable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Transformable();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Virtual destructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual ~Transformable();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief set the position of the object
|
||||
///
|
||||
/// This function completely overwrites the previous position.
|
||||
/// See the move function to apply an offset based on the previous position instead.
|
||||
/// The default position of a transformable object is (0, 0).
|
||||
///
|
||||
/// \param x X coordinate of the new position
|
||||
/// \param y Y coordinate of the new position
|
||||
///
|
||||
/// \see move, getPosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setPosition(float x, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief set the position of the object
|
||||
///
|
||||
/// This function completely overwrites the previous position.
|
||||
/// See the move function to apply an offset based on the previous position instead.
|
||||
/// The default position of a transformable object is (0, 0).
|
||||
///
|
||||
/// \param position New position
|
||||
///
|
||||
/// \see move, getPosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setPosition(const Vector2f& position);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief set the orientation of the object
|
||||
///
|
||||
/// This function completely overwrites the previous rotation.
|
||||
/// See the rotate function to add an angle based on the previous rotation instead.
|
||||
/// The default rotation of a transformable object is 0.
|
||||
///
|
||||
/// \param angle New rotation, in degrees
|
||||
///
|
||||
/// \see rotate, getRotation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setRotation(float angle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief set the scale factors of the object
|
||||
///
|
||||
/// This function completely overwrites the previous scale.
|
||||
/// See the scale function to add a factor based on the previous scale instead.
|
||||
/// The default scale of a transformable object is (1, 1).
|
||||
///
|
||||
/// \param factorX New horizontal scale factor
|
||||
/// \param factorY New vertical scale factor
|
||||
///
|
||||
/// \see scale, getScale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setScale(float factorX, float factorY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief set the scale factors of the object
|
||||
///
|
||||
/// This function completely overwrites the previous scale.
|
||||
/// See the scale function to add a factor based on the previous scale instead.
|
||||
/// The default scale of a transformable object is (1, 1).
|
||||
///
|
||||
/// \param factors New scale factors
|
||||
///
|
||||
/// \see scale, getScale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setScale(const Vector2f& factors);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief set the local origin of the object
|
||||
///
|
||||
/// The origin of an object defines the center point for
|
||||
/// all transformations (position, scale, rotation).
|
||||
/// The coordinates of this point must be relative to the
|
||||
/// top-left corner of the object, and ignore all
|
||||
/// transformations (position, scale, rotation).
|
||||
/// The default origin of a transformable object is (0, 0).
|
||||
///
|
||||
/// \param x X coordinate of the new origin
|
||||
/// \param y Y coordinate of the new origin
|
||||
///
|
||||
/// \see getOrigin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setOrigin(float x, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief set the local origin of the object
|
||||
///
|
||||
/// The origin of an object defines the center point for
|
||||
/// all transformations (position, scale, rotation).
|
||||
/// The coordinates of this point must be relative to the
|
||||
/// top-left corner of the object, and ignore all
|
||||
/// transformations (position, scale, rotation).
|
||||
/// The default origin of a transformable object is (0, 0).
|
||||
///
|
||||
/// \param origin New origin
|
||||
///
|
||||
/// \see getOrigin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setOrigin(const Vector2f& origin);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief get the position of the object
|
||||
///
|
||||
/// \return Current position
|
||||
///
|
||||
/// \see setPosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& getPosition() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief get the orientation of the object
|
||||
///
|
||||
/// The rotation is always in the range [0, 360].
|
||||
///
|
||||
/// \return Current rotation, in degrees
|
||||
///
|
||||
/// \see setRotation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getRotation() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief get the current scale of the object
|
||||
///
|
||||
/// \return Current scale factors
|
||||
///
|
||||
/// \see setScale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& getScale() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief get the local origin of the object
|
||||
///
|
||||
/// \return Current origin
|
||||
///
|
||||
/// \see setOrigin
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& getOrigin() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move the object by a given offset
|
||||
///
|
||||
/// This function adds to the current position of the object,
|
||||
/// unlike setPosition which overwrites it.
|
||||
/// Thus, it is equivalent to the following code:
|
||||
/// \code
|
||||
/// sf::Vector2f pos = object.getPosition();
|
||||
/// object.setPosition(pos.x + offsetX, pos.y + offsetY);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param offsetX X offset
|
||||
/// \param offsetY Y offset
|
||||
///
|
||||
/// \see setPosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void move(float offsetX, float offsetY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move the object by a given offset
|
||||
///
|
||||
/// This function adds to the current position of the object,
|
||||
/// unlike setPosition which overwrites it.
|
||||
/// Thus, it is equivalent to the following code:
|
||||
/// \code
|
||||
/// object.setPosition(object.getPosition() + offset);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param offset Offset
|
||||
///
|
||||
/// \see setPosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void move(const Vector2f& offset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Rotate the object
|
||||
///
|
||||
/// This function adds to the current rotation of the object,
|
||||
/// unlike setRotation which overwrites it.
|
||||
/// Thus, it is equivalent to the following code:
|
||||
/// \code
|
||||
/// object.setRotation(object.getRotation() + angle);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param angle Angle of rotation, in degrees
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void rotate(float angle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Scale the object
|
||||
///
|
||||
/// This function multiplies the current scale of the object,
|
||||
/// unlike setScale which overwrites it.
|
||||
/// Thus, it is equivalent to the following code:
|
||||
/// \code
|
||||
/// sf::Vector2f scale = object.getScale();
|
||||
/// object.setScale(scale.x * factorX, scale.y * factorY);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param factorX Horizontal scale factor
|
||||
/// \param factorY Vertical scale factor
|
||||
///
|
||||
/// \see setScale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void scale(float factorX, float factorY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Scale the object
|
||||
///
|
||||
/// This function multiplies the current scale of the object,
|
||||
/// unlike setScale which overwrites it.
|
||||
/// Thus, it is equivalent to the following code:
|
||||
/// \code
|
||||
/// sf::Vector2f scale = object.getScale();
|
||||
/// object.setScale(scale.x * factor.x, scale.y * factor.y);
|
||||
/// \endcode
|
||||
///
|
||||
/// \param factor Scale factors
|
||||
///
|
||||
/// \see setScale
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void scale(const Vector2f& factor);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief get the combined transform of the object
|
||||
///
|
||||
/// \return Transform combining the position/rotation/scale/origin of the object
|
||||
///
|
||||
/// \see getInverseTransform
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& getTransform() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief get the inverse of the combined transform of the object
|
||||
///
|
||||
/// \return Inverse of the combined transformations applied to the object
|
||||
///
|
||||
/// \see getTransform
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& getInverseTransform() const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f m_origin; ///< Origin of translation/rotation/scaling of the object
|
||||
Vector2f m_position; ///< Position of the object in the 2D world
|
||||
float m_rotation; ///< Orientation of the object, in degrees
|
||||
Vector2f m_scale; ///< Scale of the object
|
||||
mutable Transform m_transform; ///< Combined transformation of the object
|
||||
mutable bool m_transformNeedUpdate; ///< Does the transform need to be recomputed?
|
||||
mutable Transform m_inverseTransform; ///< Combined transformation of the object
|
||||
mutable bool m_inverseTransformNeedUpdate; ///< Does the transform need to be recomputed?
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_TRANSFORMABLE_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Transformable
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// This class is provided for convenience, on top of sf::Transform.
|
||||
///
|
||||
/// sf::Transform, as a low-level class, offers a great level of
|
||||
/// flexibility but it is not always convenient to manage. Indeed,
|
||||
/// one can easily combine any kind of operation, such as a translation
|
||||
/// followed by a rotation followed by a scaling, but once the result
|
||||
/// transform is built, there's no way to go backward and, let's say,
|
||||
/// change only the rotation without modifying the translation and scaling.
|
||||
/// The entire transform must be recomputed, which means that you
|
||||
/// need to retrieve the initial translation and scale factors as
|
||||
/// well, and combine them the same way you did before updating the
|
||||
/// rotation. This is a tedious operation, and it requires to store
|
||||
/// all the individual components of the final transform.
|
||||
///
|
||||
/// That's exactly what sf::Transformable was written for: it hides
|
||||
/// these variables and the composed transform behind an easy to use
|
||||
/// interface. You can set or get any of the individual components
|
||||
/// without worrying about the others. It also provides the composed
|
||||
/// transform (as a sf::Transform), and keeps it up-to-date.
|
||||
///
|
||||
/// In addition to the position, rotation and scale, sf::Transformable
|
||||
/// provides an "origin" component, which represents the local origin
|
||||
/// of the three other components. Let's take an example with a 10x10
|
||||
/// pixels sprite. By default, the sprite is positioned/rotated/scaled
|
||||
/// relatively to its top-left corner, because it is the local point
|
||||
/// (0, 0). But if we change the origin to be (5, 5), the sprite will
|
||||
/// be positioned/rotated/scaled around its center instead. And if
|
||||
/// we set the origin to (10, 10), it will be transformed around its
|
||||
/// bottom-right corner.
|
||||
///
|
||||
/// To keep the sf::Transformable class simple, there's only one
|
||||
/// origin for all the components. You cannot position the sprite
|
||||
/// relatively to its top-left corner while rotating it around its
|
||||
/// center, for example. To do such things, use sf::Transform directly.
|
||||
///
|
||||
/// sf::Transformable can be used as a base class. It is often
|
||||
/// combined with sf::Drawable -- that's what SFML's sprites,
|
||||
/// texts and shapes do.
|
||||
/// \code
|
||||
/// class MyEntity : public sf::Transformable, public sf::Drawable
|
||||
/// {
|
||||
/// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
/// {
|
||||
/// states.transform *= getTransform();
|
||||
/// target.draw(..., states);
|
||||
/// }
|
||||
/// };
|
||||
///
|
||||
/// MyEntity entity;
|
||||
/// entity.setPosition(10, 20);
|
||||
/// entity.setRotation(45);
|
||||
/// window.draw(entity);
|
||||
/// \endcode
|
||||
///
|
||||
/// It can also be used as a member, if you don't want to use
|
||||
/// its API directly (because you don't need all its functions,
|
||||
/// or you have different naming conventions for example).
|
||||
/// \code
|
||||
/// class MyEntity
|
||||
/// {
|
||||
/// public:
|
||||
/// void SetPosition(const MyVector& v)
|
||||
/// {
|
||||
/// myTransform.setPosition(v.x(), v.y());
|
||||
/// }
|
||||
///
|
||||
/// void Draw(sf::RenderTarget& target) const
|
||||
/// {
|
||||
/// target.draw(..., myTransform.getTransform());
|
||||
/// }
|
||||
///
|
||||
/// private:
|
||||
/// sf::Transformable myTransform;
|
||||
/// };
|
||||
/// \endcode
|
||||
///
|
||||
/// A note on coordinates and undistorted rendering: \n
|
||||
/// By default, SFML (or more exactly, OpenGL) may interpolate drawable objects
|
||||
/// such as sprites or texts when rendering. While this allows transitions
|
||||
/// like slow movements or rotations to appear smoothly, it can lead to
|
||||
/// unwanted results in some cases, for example blurred or distorted objects.
|
||||
/// In order to render a sf::Drawable object pixel-perfectly, make sure
|
||||
/// the involved coordinates allow a 1:1 mapping of pixels in the window
|
||||
/// to texels (pixels in the texture). More specifically, this means:
|
||||
/// * The object's position, origin and scale have no fractional part
|
||||
/// * The object's and the view's rotation are a multiple of 90 degrees
|
||||
/// * The view's center and size have no fractional part
|
||||
///
|
||||
/// \see sf::Transform
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
148
code/SFML-2.4.2/include/SFML/Graphics/Vertex.hpp
Normal file
148
code/SFML-2.4.2/include/SFML/Graphics/Vertex.hpp
Normal file
|
@ -0,0 +1,148 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_VERTEX_HPP
|
||||
#define SFML_VERTEX_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Define a point with color and texture coordinates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API Vertex
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vertex from its position
|
||||
///
|
||||
/// The vertex color is white and texture coordinates are (0, 0).
|
||||
///
|
||||
/// \param thePosition Vertex position
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex(const Vector2f& thePosition);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vertex from its position and color
|
||||
///
|
||||
/// The texture coordinates are (0, 0).
|
||||
///
|
||||
/// \param thePosition Vertex position
|
||||
/// \param theColor Vertex color
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex(const Vector2f& thePosition, const Color& theColor);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vertex from its position and texture coordinates
|
||||
///
|
||||
/// The vertex color is white.
|
||||
///
|
||||
/// \param thePosition Vertex position
|
||||
/// \param theTexCoords Vertex texture coordinates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vertex from its position, color and texture coordinates
|
||||
///
|
||||
/// \param thePosition Vertex position
|
||||
/// \param theColor Vertex color
|
||||
/// \param theTexCoords Vertex texture coordinates
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f position; ///< 2D position of the vertex
|
||||
Color color; ///< Color of the vertex
|
||||
Vector2f texCoords; ///< Coordinates of the texture's pixel to map to the vertex
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VERTEX_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::Vertex
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// A vertex is an improved point. It has a position and other
|
||||
/// extra attributes that will be used for drawing: in SFML,
|
||||
/// vertices also have a color and a pair of texture coordinates.
|
||||
///
|
||||
/// The vertex is the building block of drawing. Everything which
|
||||
/// is visible on screen is made of vertices. They are grouped
|
||||
/// as 2D primitives (triangles, quads, ...), and these primitives
|
||||
/// are grouped to create even more complex 2D entities such as
|
||||
/// sprites, texts, etc.
|
||||
///
|
||||
/// If you use the graphical entities of SFML (sprite, text, shape)
|
||||
/// you won't have to deal with vertices directly. But if you want
|
||||
/// to define your own 2D entities, such as tiled maps or particle
|
||||
/// systems, using vertices will allow you to get maximum performances.
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// // define a 100x100 square, red, with a 10x10 texture mapped on it
|
||||
/// sf::Vertex vertices[] =
|
||||
/// {
|
||||
/// sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Red, sf::Vector2f( 0, 0)),
|
||||
/// sf::Vertex(sf::Vector2f( 0, 100), sf::Color::Red, sf::Vector2f( 0, 10)),
|
||||
/// sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2f(10, 10)),
|
||||
/// sf::Vertex(sf::Vector2f(100, 0), sf::Color::Red, sf::Vector2f(10, 0))
|
||||
/// };
|
||||
///
|
||||
/// // draw it
|
||||
/// window.draw(vertices, 4, sf::Quads);
|
||||
/// \endcode
|
||||
///
|
||||
/// Note: although texture coordinates are supposed to be an integer
|
||||
/// amount of pixels, their type is float because of some buggy graphics
|
||||
/// drivers that are not able to process integer coordinates correctly.
|
||||
///
|
||||
/// \see sf::VertexArray
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
223
code/SFML-2.4.2/include/SFML/Graphics/VertexArray.hpp
Normal file
223
code/SFML-2.4.2/include/SFML/Graphics/VertexArray.hpp
Normal file
|
@ -0,0 +1,223 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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_VERTEXARRAY_HPP
|
||||
#define SFML_VERTEXARRAY_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Vertex.hpp>
|
||||
#include <SFML/Graphics/PrimitiveType.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Define a set of one or more 2D primitives
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API VertexArray : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// Creates an empty vertex array.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
VertexArray();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the vertex array with a type and an initial number of vertices
|
||||
///
|
||||
/// \param type Type of primitives
|
||||
/// \param vertexCount Initial number of vertices in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit VertexArray(PrimitiveType type, std::size_t vertexCount = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Return the vertex count
|
||||
///
|
||||
/// \return Number of vertices in the array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t getVertexCount() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a read-write access to a vertex by its index
|
||||
///
|
||||
/// This function doesn't check \a index, it must be in range
|
||||
/// [0, getVertexCount() - 1]. The behavior is undefined
|
||||
/// otherwise.
|
||||
///
|
||||
/// \param index Index of the vertex to get
|
||||
///
|
||||
/// \return Reference to the index-th vertex
|
||||
///
|
||||
/// \see getVertexCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Vertex& operator [](std::size_t index);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a read-only access to a vertex by its index
|
||||
///
|
||||
/// This function doesn't check \a index, it must be in range
|
||||
/// [0, getVertexCount() - 1]. The behavior is undefined
|
||||
/// otherwise.
|
||||
///
|
||||
/// \param index Index of the vertex to get
|
||||
///
|
||||
/// \return Const reference to the index-th vertex
|
||||
///
|
||||
/// \see getVertexCount
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vertex& operator [](std::size_t index) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Clear the vertex array
|
||||
///
|
||||
/// This function removes all the vertices from the array.
|
||||
/// It doesn't deallocate the corresponding memory, so that
|
||||
/// adding new vertices after clearing doesn't involve
|
||||
/// reallocating all the memory.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void clear();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Resize the vertex array
|
||||
///
|
||||
/// If \a vertexCount is greater than the current size, the previous
|
||||
/// vertices are kept and new (default-constructed) vertices are
|
||||
/// added.
|
||||
/// If \a vertexCount is less than the current size, existing vertices
|
||||
/// are removed from the array.
|
||||
///
|
||||
/// \param vertexCount New size of the array (number of vertices)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void resize(std::size_t vertexCount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Add a vertex to the array
|
||||
///
|
||||
/// \param vertex Vertex to add
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void append(const Vertex& vertex);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the type of primitives to draw
|
||||
///
|
||||
/// This function defines how the vertices must be interpreted
|
||||
/// when it's time to draw them:
|
||||
/// \li As points
|
||||
/// \li As lines
|
||||
/// \li As triangles
|
||||
/// \li As quads
|
||||
/// The default primitive type is sf::Points.
|
||||
///
|
||||
/// \param type Type of primitive
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setPrimitiveType(PrimitiveType type);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the type of primitives drawn by the vertex array
|
||||
///
|
||||
/// \return Primitive type
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
PrimitiveType getPrimitiveType() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Compute the bounding rectangle of the vertex array
|
||||
///
|
||||
/// This function returns the minimal axis-aligned rectangle
|
||||
/// that contains all the vertices of the array.
|
||||
///
|
||||
/// \return Bounding rectangle of the vertex array
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect getBounds() const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Draw the vertex array to a render target
|
||||
///
|
||||
/// \param target Render target to draw to
|
||||
/// \param states Current render states
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
virtual void draw(RenderTarget& target, RenderStates states) const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
std::vector<Vertex> m_vertices; ///< Vertices contained in the array
|
||||
PrimitiveType m_primitiveType; ///< Type of primitives to draw
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VERTEXARRAY_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::VertexArray
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::VertexArray is a very simple wrapper around a dynamic
|
||||
/// array of vertices and a primitives type.
|
||||
///
|
||||
/// It inherits sf::Drawable, but unlike other drawables it
|
||||
/// is not transformable.
|
||||
///
|
||||
/// Example:
|
||||
/// \code
|
||||
/// sf::VertexArray lines(sf::LineStrip, 4);
|
||||
/// lines[0].position = sf::Vector2f(10, 0);
|
||||
/// lines[1].position = sf::Vector2f(20, 0);
|
||||
/// lines[2].position = sf::Vector2f(30, 5);
|
||||
/// lines[3].position = sf::Vector2f(40, 2);
|
||||
///
|
||||
/// window.draw(lines);
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Vertex
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
343
code/SFML-2.4.2/include/SFML/Graphics/View.hpp
Normal file
343
code/SFML-2.4.2/include/SFML/Graphics/View.hpp
Normal file
|
@ -0,0 +1,343 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2017 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// 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/Graphics/Export.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/Transform.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief 2D camera that defines what region is shown on screen
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class SFML_GRAPHICS_API View
|
||||
{
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
/// This constructor creates a default view of (0, 0, 1000, 1000)
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
View();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the view from a rectangle
|
||||
///
|
||||
/// \param rectangle Rectangle defining the zone to display
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
explicit View(const FloatRect& rectangle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the view from its center and size
|
||||
///
|
||||
/// \param center Center of the zone to display
|
||||
/// \param size Size of zone to display
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
View(const Vector2f& center, const Vector2f& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the center of the view
|
||||
///
|
||||
/// \param x X coordinate of the new center
|
||||
/// \param y Y coordinate of the new center
|
||||
///
|
||||
/// \see setSize, getCenter
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setCenter(float x, float y);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the center of the view
|
||||
///
|
||||
/// \param center New center
|
||||
///
|
||||
/// \see setSize, getCenter
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setCenter(const Vector2f& center);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the size of the view
|
||||
///
|
||||
/// \param width New width of the view
|
||||
/// \param height New height of the view
|
||||
///
|
||||
/// \see setCenter, getCenter
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setSize(float width, float height);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the size of the view
|
||||
///
|
||||
/// \param size New size
|
||||
///
|
||||
/// \see setCenter, getCenter
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setSize(const Vector2f& size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the orientation of the view
|
||||
///
|
||||
/// The default rotation of a view is 0 degree.
|
||||
///
|
||||
/// \param angle New angle, in degrees
|
||||
///
|
||||
/// \see getRotation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setRotation(float angle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Set the target viewport
|
||||
///
|
||||
/// The viewport is the rectangle into which the contents of the
|
||||
/// view are displayed, expressed as a factor (between 0 and 1)
|
||||
/// of the size of the RenderTarget to which the view is applied.
|
||||
/// For example, a view which takes the left side of the target would
|
||||
/// be defined with View.setViewport(sf::FloatRect(0, 0, 0.5, 1)).
|
||||
/// By default, a view has a viewport which covers the entire target.
|
||||
///
|
||||
/// \param viewport New viewport rectangle
|
||||
///
|
||||
/// \see getViewport
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void setViewport(const FloatRect& viewport);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Reset the view to the given rectangle
|
||||
///
|
||||
/// Note that this function resets the rotation angle to 0.
|
||||
///
|
||||
/// \param rectangle Rectangle defining the zone to display
|
||||
///
|
||||
/// \see setCenter, setSize, setRotation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void reset(const FloatRect& rectangle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the center of the view
|
||||
///
|
||||
/// \return Center of the view
|
||||
///
|
||||
/// \see getSize, setCenter
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& getCenter() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the size of the view
|
||||
///
|
||||
/// \return Size of the view
|
||||
///
|
||||
/// \see getCenter, setSize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Vector2f& getSize() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current orientation of the view
|
||||
///
|
||||
/// \return Rotation angle of the view, in degrees
|
||||
///
|
||||
/// \see setRotation
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getRotation() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the target viewport rectangle of the view
|
||||
///
|
||||
/// \return Viewport rectangle, expressed as a factor of the target size
|
||||
///
|
||||
/// \see setViewport
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const FloatRect& getViewport() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move the view relatively to its current position
|
||||
///
|
||||
/// \param offsetX X coordinate of the move offset
|
||||
/// \param offsetY Y coordinate of the move offset
|
||||
///
|
||||
/// \see setCenter, rotate, zoom
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void move(float offsetX, float offsetY);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Move the view relatively to its current position
|
||||
///
|
||||
/// \param offset Move offset
|
||||
///
|
||||
/// \see setCenter, rotate, zoom
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void move(const Vector2f& offset);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Rotate the view relatively to its current orientation
|
||||
///
|
||||
/// \param angle Angle to rotate, in degrees
|
||||
///
|
||||
/// \see setRotation, move, zoom
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void rotate(float angle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Resize the view rectangle relatively to its current size
|
||||
///
|
||||
/// Resizing the view simulates a zoom, as the zone displayed on
|
||||
/// screen grows or shrinks.
|
||||
/// \a factor is a multiplier:
|
||||
/// \li 1 keeps the size unchanged
|
||||
/// \li > 1 makes the view bigger (objects appear smaller)
|
||||
/// \li < 1 makes the view smaller (objects appear bigger)
|
||||
///
|
||||
/// \param factor Zoom factor to apply
|
||||
///
|
||||
/// \see setSize, move, rotate
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void zoom(float factor);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the projection transform of the view
|
||||
///
|
||||
/// This function is meant for internal use only.
|
||||
///
|
||||
/// \return Projection transform defining the view
|
||||
///
|
||||
/// \see getInverseTransform
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& getTransform() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the inverse projection transform of the view
|
||||
///
|
||||
/// This function is meant for internal use only.
|
||||
///
|
||||
/// \return Inverse of the projection transform defining the view
|
||||
///
|
||||
/// \see getTransform
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
const Transform& getInverseTransform() const;
|
||||
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2f m_center; ///< Center of the view, in scene coordinates
|
||||
Vector2f m_size; ///< Size of the view, in scene coordinates
|
||||
float m_rotation; ///< Angle of rotation of the view rectangle, in degrees
|
||||
FloatRect m_viewport; ///< Viewport rectangle, expressed as a factor of the render-target's size
|
||||
mutable Transform m_transform; ///< Precomputed projection transform corresponding to the view
|
||||
mutable Transform m_inverseTransform; ///< Precomputed inverse projection transform corresponding to the view
|
||||
mutable bool m_transformUpdated; ///< Internal state telling if the transform needs to be updated
|
||||
mutable bool m_invTransformUpdated; ///< Internal state telling if the inverse transform needs to be updated
|
||||
};
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VIEW_HPP
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \class sf::View
|
||||
/// \ingroup graphics
|
||||
///
|
||||
/// sf::View defines a camera in the 2D scene. This is a
|
||||
/// very powerful concept: you can scroll, rotate or zoom
|
||||
/// the entire scene without altering the way that your
|
||||
/// drawable objects are drawn.
|
||||
///
|
||||
/// A view is composed of a source rectangle, which defines
|
||||
/// what part of the 2D scene is shown, and a target viewport,
|
||||
/// which defines where the contents of the source rectangle
|
||||
/// will be displayed on the render target (window or texture).
|
||||
///
|
||||
/// The viewport allows to map the scene to a custom part
|
||||
/// of the render target, and can be used for split-screen
|
||||
/// or for displaying a minimap, for example. If the source
|
||||
/// rectangle doesn't have the same size as the viewport, its
|
||||
/// contents will be stretched to fit in.
|
||||
///
|
||||
/// To apply a view, you have to assign it to the render target.
|
||||
/// Then, objects drawn in this render target will be
|
||||
/// affected by the view until you use another view.
|
||||
///
|
||||
/// Usage example:
|
||||
/// \code
|
||||
/// sf::RenderWindow window;
|
||||
/// sf::View view;
|
||||
///
|
||||
/// // Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
|
||||
/// view.reset(sf::FloatRect(100, 100, 400, 200));
|
||||
///
|
||||
/// // Rotate it by 45 degrees
|
||||
/// view.rotate(45);
|
||||
///
|
||||
/// // Set its target viewport to be half of the window
|
||||
/// view.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));
|
||||
///
|
||||
/// // Apply it
|
||||
/// window.setView(view);
|
||||
///
|
||||
/// // Render stuff
|
||||
/// window.draw(someSprite);
|
||||
///
|
||||
/// // Set the default view back
|
||||
/// window.setView(window.getDefaultView());
|
||||
///
|
||||
/// // Render stuff not affected by the view
|
||||
/// window.draw(someText);
|
||||
/// \endcode
|
||||
///
|
||||
/// See also the note on coordinates and undistorted rendering in sf::Transformable.
|
||||
///
|
||||
/// \see sf::RenderWindow, sf::RenderTexture
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue