OpenWalnut  1.4.0
WOSGButtonLabel.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WOSGBUTTONLABEL_H
00026 #define WOSGBUTTONLABEL_H
00027 
00028 #include <osgWidget/Label>
00029 #include <osgWidget/Util>
00030 #include <osgWidget/WindowManager>
00031 
00032 /**
00033  * implements mouse interaction for a osgWidget label
00034  */
00035 class WOSGButtonLabel : public osgWidget::Label
00036 {
00037 public:
00038     /**
00039      * constructor
00040      * \param pushable denotes if the button is pushable, i.e. keeps a pushed state or not
00041      */
00042     explicit WOSGButtonLabel( bool pushable );
00043 
00044     /**
00045      * destructor
00046      */
00047     ~WOSGButtonLabel();
00048 
00049     /**
00050      * function handles mouse click on label, the function was copied from an osg example, as everything in
00051      * the osg it wasn't documented, so it's not entirely sure what the params are for and what they do
00052      *
00053      * \return bool
00054      */
00055     bool mousePush( double, double, osgWidget::WindowManager* );
00056 
00057     /**
00058      * getter for clicked flag, resets the flag to false
00059      *
00060      * \return true if the label has been clicked
00061      */
00062     bool clicked();
00063 
00064     /**
00065      * getter for pushed flag
00066      *
00067      * \return true if the button is pushed
00068      */
00069     bool pushed();
00070 
00071     /**
00072      * setter
00073      * \param pushed if true the button is pushed
00074      */
00075     void setPushed( bool pushed );
00076 
00077 protected:
00078 private:
00079     bool m_clicked; //!< if true the label has been clicked since it was last checked for
00080 
00081     bool m_pushable; //!< button is pushable or not
00082 
00083     bool m_pushed; //!< true if button is pushable and was clicked
00084 };
00085 
00086 inline bool WOSGButtonLabel::clicked()
00087 {
00088     bool tmp = m_clicked;
00089     m_clicked = false;
00090     return tmp;
00091 }
00092 
00093 inline bool WOSGButtonLabel::pushed()
00094 {
00095     return m_pushed;
00096 }
00097 
00098 inline void WOSGButtonLabel::setPushed( bool pushed )
00099 {
00100     m_pushed = pushed;
00101 }
00102 
00103 #endif  // WOSGBUTTONLABEL_H