Slider.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@hotmail.com */
00025 
00030 #ifndef _GG_Slider_h_
00031 #define _GG_Slider_h_
00032 
00033 #include <GG/Control.h>
00034 
00035 #include <boost/serialization/version.hpp>
00036 
00037 
00038 namespace GG {
00039 
00040 class Button;
00041 class WndEvent;
00042 
00047 class GG_API Slider : public Control
00048 {
00049 public: 
00051     typedef boost::signal<void (int, int, int)> SlidSignalType;           
00052     typedef boost::signal<void (int, int, int)> SlidAndStoppedSignalType; 
00053 
00054  
00056     typedef SlidSignalType::slot_type SlidSlotType;           
00057     typedef SlidSignalType::slot_type SlidAndStoppedSlotType; 
00058 
00059  
00061     Slider(int x, int y, int w, int h, int min, int max, Orientation orientation, SliderLineStyle style, Clr color, int tab_width, int line_width = 5, Flags<WndFlag> flags = CLICKABLE); 
00062 
00063  
00065     virtual Pt           MinUsableSize() const;
00066 
00067     int                  Posn() const;           
00068     std::pair<int, int>  SliderRange() const;    
00069 
00072     int                  PageSize() const;
00073 
00074     Orientation          GetOrientation() const; 
00075     int                  TabWidth() const;       
00076     int                  LineWidth() const;      
00077     SliderLineStyle      LineStyle() const;      
00078 
00079     mutable SlidSignalType           SlidSignal;           
00080     mutable SlidAndStoppedSignalType SlidAndStoppedSignal; 
00081 
00082  
00084     virtual void   Render();
00085     virtual void   LClick(const Pt& pt, Flags<ModKey> mod_keys);
00086     virtual void   KeyPress(Key key, Flags<ModKey> mod_keys);
00087     virtual void   SizeMove(const Pt& ul, const Pt& lr);
00088     virtual void   Disable(bool b = true);
00089     virtual void   SetColor(Clr c);
00090 
00091     void           SizeSlider(int min, int max); 
00092     void           SetMax(int max);              
00093     void           SetMin(int min);              
00094     void           SlideTo(int p);               
00095 
00099     void           SetPageSize(int size);
00100 
00101     void           SetLineStyle(SliderLineStyle style); 
00102 
00103     virtual void   DefineAttributes(WndEditor* editor);
00105 
00106 protected: 
00108     Slider(); 
00109 
00110  
00112     Button* Tab() const;                  
00113     int     PtToPosn(const Pt& pt) const; 
00114 
00115  
00117     virtual bool EventFilter(Wnd* w, const WndEvent& event);
00118 
00119     void MoveTabToPosn(); 
00120 
00121 
00122 private:
00123     void UpdatePosn();
00124 
00125     int                       m_posn;
00126     int                       m_range_min;
00127     int                       m_range_max;
00128     int                       m_page_sz;
00129     Orientation               m_orientation;
00130     int                       m_line_width;
00131     int                       m_tab_width;
00132     SliderLineStyle           m_line_style;
00133     int                       m_tab_drag_offset;
00134     Button*                   m_tab;
00135 
00136     friend class boost::serialization::access;
00137     template <class Archive>
00138     void serialize(Archive& ar, const unsigned int version);
00139 };
00140 
00141 } // namespace GG
00142 
00143 BOOST_CLASS_VERSION(GG::Slider, 1)
00144 
00145 // template implementations
00146 template <class Archive>
00147 void GG::Slider::serialize(Archive& ar, const unsigned int version)
00148 {
00149     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control)
00150         & BOOST_SERIALIZATION_NVP(m_posn)
00151         & BOOST_SERIALIZATION_NVP(m_range_min)
00152         & BOOST_SERIALIZATION_NVP(m_range_max)
00153         & BOOST_SERIALIZATION_NVP(m_orientation)
00154         & BOOST_SERIALIZATION_NVP(m_line_width)
00155         & BOOST_SERIALIZATION_NVP(m_tab_width)
00156         & BOOST_SERIALIZATION_NVP(m_line_style)
00157         & BOOST_SERIALIZATION_NVP(m_tab_drag_offset)
00158         & BOOST_SERIALIZATION_NVP(m_tab);
00159 
00160     if (1 <= version)
00161         ar & BOOST_SERIALIZATION_NVP(m_page_sz);
00162 }
00163 
00164 #endif // _GG_Slider_h_

Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2