mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +08:00
ac50bf8648
For futur references: List and inspect © to be updated $ egrep '2007-[0-9]{4}' -r examples/ tools/ src/ include/ license.txt Update all © $ egrep --null -l '2007-[0-9]{4}' -r examples/ tools/ src/ include/ license.txt | xargs -0 -P4 sed -i '' -E 's/^(.*)2007-[0-9]{4}(.*)$/\12007-2016\2/'
127 lines
3.7 KiB
C++
127 lines
3.7 KiB
C++
////////////////////////////////////////////////////////////
|
|
//
|
|
// SFML - Simple and Fast Multimedia Library
|
|
// Copyright (C) 2007-2016 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
|
|
///
|
|
////////////////////////////////////////////////////////////
|