|
|
|||
File indexing completed on 2026-06-02 08:58:13
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_DRAWABLE_HPP 0026 #define SFML_DRAWABLE_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Graphics/Export.hpp> 0032 #include <SFML/Graphics/RenderStates.hpp> 0033 0034 0035 namespace sf 0036 { 0037 class RenderTarget; 0038 0039 //////////////////////////////////////////////////////////// 0040 /// \brief Abstract base class for objects that can be drawn 0041 /// to a render target 0042 /// 0043 //////////////////////////////////////////////////////////// 0044 class SFML_GRAPHICS_API Drawable 0045 { 0046 public: 0047 0048 //////////////////////////////////////////////////////////// 0049 /// \brief Virtual destructor 0050 /// 0051 //////////////////////////////////////////////////////////// 0052 virtual ~Drawable() {} 0053 0054 protected: 0055 0056 friend class RenderTarget; 0057 0058 //////////////////////////////////////////////////////////// 0059 /// \brief Draw the object to a render target 0060 /// 0061 /// This is a pure virtual function that has to be implemented 0062 /// by the derived class to define how the drawable should be 0063 /// drawn. 0064 /// 0065 /// \param target Render target to draw to 0066 /// \param states Current render states 0067 /// 0068 //////////////////////////////////////////////////////////// 0069 virtual void draw(RenderTarget& target, RenderStates states) const = 0; 0070 }; 0071 0072 } // namespace sf 0073 0074 0075 #endif // SFML_DRAWABLE_HPP 0076 0077 0078 //////////////////////////////////////////////////////////// 0079 /// \class sf::Drawable 0080 /// \ingroup graphics 0081 /// 0082 /// sf::Drawable is a very simple base class that allows objects 0083 /// of derived classes to be drawn to a sf::RenderTarget. 0084 /// 0085 /// All you have to do in your derived class is to override the 0086 /// draw virtual function. 0087 /// 0088 /// Note that inheriting from sf::Drawable is not mandatory, 0089 /// but it allows this nice syntax "window.draw(object)" rather 0090 /// than "object.draw(window)", which is more consistent with other 0091 /// SFML classes. 0092 /// 0093 /// Example: 0094 /// \code 0095 /// class MyDrawable : public sf::Drawable 0096 /// { 0097 /// public: 0098 /// 0099 /// ... 0100 /// 0101 /// private: 0102 /// 0103 /// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const 0104 /// { 0105 /// // You can draw other high-level objects 0106 /// target.draw(m_sprite, states); 0107 /// 0108 /// // ... or use the low-level API 0109 /// states.texture = &m_texture; 0110 /// target.draw(m_vertices, states); 0111 /// 0112 /// // ... or draw with OpenGL directly 0113 /// glBegin(GL_QUADS); 0114 /// ... 0115 /// glEnd(); 0116 /// } 0117 /// 0118 /// sf::Sprite m_sprite; 0119 /// sf::Texture m_texture; 0120 /// sf::VertexArray m_vertices; 0121 /// }; 0122 /// \endcode 0123 /// 0124 /// \see sf::RenderTarget 0125 /// 0126 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|