OSGUIsh  0.3.1
FocusPolicy.hpp
Go to the documentation of this file.
00001 /******************************************************************************\
00002 * FocusPolicy.hpp                                                              *
00003 * Interface for policies used to change the focus from one node to another.    *
00004 *                                                                              *
00005 * Copyright (C) 2006-2010 by Leandro Motta Barros.                             *
00006 *                                                                              *
00007 * This program is distributed under the OpenSceneGraph Public License. You     *
00008 * should have received a copy of it with the source distribution, in a file    *
00009 * named 'COPYING.txt'.                                                         *
00010 \******************************************************************************/
00011 
00012 #ifndef _OSGUISH_FOCUS_POLICY_HPP_
00013 #define _OSGUISH_FOCUS_POLICY_HPP_
00014 
00015 #include <boost/shared_ptr.hpp>
00016 #include <osgGA/GUIEventAdapter>
00017 #include <OSGUIsh/Types.hpp>
00018 
00019 
00020 namespace OSGUIsh
00021 {
00026    class FocusPolicy
00027    {
00028       public:
00034          FocusPolicy(NodePtr& focusedNode);
00035 
00045          virtual void updateFocus(const osgGA::GUIEventAdapter& ea,
00046                                   const NodePtr nodeUnderMouse) = 0;
00047 
00048       protected:
00050          void setFocusedNode(NodePtr focusedNode)
00051          { focusedNode_ = focusedNode; }
00052 
00053       private:
00058          NodePtr& focusedNode_;
00059    };
00060 
00061 
00062 
00064    typedef boost::shared_ptr<FocusPolicy> FocusPolicyPtr;
00065 
00066 
00067 
00072    class FocusPolicyFactory
00073    {
00074       public:
00081          virtual FocusPolicyPtr create(NodePtr& focusedNode) const = 0;
00082    };
00083 
00084 
00085 
00092    template <class T>
00093    class FocusPolicyFactoryMason: public FocusPolicyFactory
00094    {
00095       public:
00096          // (inherits docs)
00097          virtual FocusPolicyPtr create(NodePtr& focusedNode) const
00098          {
00099             return FocusPolicyPtr(new T(focusedNode));
00100          }
00101    };
00102 
00103 } // namespace OSGUIsh
00104 
00105 #endif // _OSGUISH_FOCUS_POLICY_HPP_