Drawable.hpp
00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 #ifndef SFML_DRAWABLE_HPP
00026 #define SFML_DRAWABLE_HPP
00027 
00029 // Headers
00031 #include <SFML/System/Vector2.hpp>
00032 #include <SFML/Graphics/Color.hpp>
00033 #include <SFML/Graphics/Matrix3.hpp>
00034 
00035 
00036 namespace sf
00037 {
00038 class Renderer;
00039 class RenderTarget;
00040 
00041 namespace Blend
00042 {
00048     enum Mode
00049     {
00050         Alpha,    
00051         Add,      
00052         Multiply, 
00053         None      
00054     };
00055 }
00056 
00062 class SFML_API Drawable
00063 {
00064 public :
00065 
00070     virtual ~Drawable();
00071 
00085     void SetPosition(float x, float y);
00086 
00099     void SetPosition(const Vector2f& position);
00100 
00109     void SetX(float x);
00110 
00119     void SetY(float y);
00120 
00136     void SetScale(float factorX, float factorY);
00137 
00152     void SetScale(const Vector2f& factors);
00153 
00164     void SetScaleX(float factor);
00165 
00176     void SetScaleY(float factor);
00177 
00194     void SetOrigin(float x, float y);
00195 
00211     void SetOrigin(const Vector2f& origin);
00212 
00225     void SetRotation(float angle);
00226 
00239     void SetColor(const Color& color);
00240 
00255     void SetBlendMode(Blend::Mode mode);
00256 
00265     const Vector2f& GetPosition() const;
00266 
00275     const Vector2f& GetScale() const;
00276 
00285     const Vector2f& GetOrigin() const;
00286 
00297     float GetRotation() const;
00298 
00307     const Color& GetColor() const;
00308 
00317     Blend::Mode GetBlendMode() const;
00318 
00336     void Move(float offsetX, float offsetY);
00337 
00353     void Move(const Vector2f& offset);
00354 
00372     void Scale(float factorX, float factorY);
00373 
00390     void Scale(const Vector2f& factor);
00391 
00405     void Rotate(float angle);
00406 
00423     Vector2f TransformToLocal(const Vector2f& point) const;
00424 
00440     Vector2f TransformToGlobal(const Vector2f& point) const;
00441 
00442 protected :
00443 
00448     Drawable();
00449 
00458     const Matrix3& GetMatrix() const;
00459 
00468     const Matrix3& GetInverseMatrix() const;
00469 
00470 private :
00471 
00472     friend class RenderTarget;
00473 
00485     void Draw(RenderTarget& target, Renderer& renderer) const;
00486 
00498     virtual void Render(RenderTarget& target, Renderer& renderer) const = 0;
00499 
00501     // Member data
00503     Vector2f        myPosition;         
00504     Vector2f        myScale;            
00505     Vector2f        myOrigin;           
00506     float           myRotation;         
00507     Color           myColor;            
00508     Blend::Mode     myBlendMode;        
00509     mutable Matrix3 myMatrix;           
00510     mutable Matrix3 myInvMatrix;        
00511     mutable bool    myMatrixUpdated;    
00512     mutable bool    myInvMatrixUpdated; 
00513 };
00514 
00515 } // namespace sf
00516 
00517 
00518 #endif // SFML_DRAWABLE_HPP
00519 
00520