GG

Slider.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003-2008 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@gmail.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 
00051 class GG_API Slider : public Control
00052 {
00053 public: 
00055     typedef boost::signal<void (int, int, int)> SlidSignalType;           
00056     typedef boost::signal<void (int, int, int)> SlidAndStoppedSignalType; 
00057 
00058  
00060     Slider(X x, Y y, X w, Y h, int min, int max,
00061            Orientation orientation, SliderLineStyle style, Clr color,
00062            unsigned int tab_width, unsigned int line_width = 5, Flags<WndFlag> flags = INTERACTIVE); 
00063 
00064  
00066     virtual Pt           MinUsableSize() const;
00067 
00068     int                  Posn() const;           
00069     std::pair<int, int>  SliderRange() const;    
00070 
00074     unsigned int         PageSize() const;
00075 
00076     Orientation          GetOrientation() const; 
00077     unsigned int         TabWidth() const;       
00078     unsigned int         LineWidth() const;      
00079     SliderLineStyle      LineStyle() const;      
00080 
00081     mutable SlidSignalType           SlidSignal;           
00082     mutable SlidAndStoppedSignalType SlidAndStoppedSignal; 
00083 
00084  
00086     virtual void   Render();
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 
00100     void           SetPageSize(unsigned int size);
00101 
00102     void           SetLineStyle(SliderLineStyle style); 
00103 
00104     virtual void   DefineAttributes(WndEditor* editor);
00106 
00107     static const unsigned int INVALID_PAGE_SIZE;
00108 
00109 protected: 
00111     Slider(); 
00112 
00113  
00115     Button* Tab() const;                  
00116     int     PtToPosn(const Pt& pt) const; 
00117 
00118  
00120     virtual void LClick(const Pt& pt, Flags<ModKey> mod_keys);
00121     virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
00122 
00123     virtual bool EventFilter(Wnd* w, const WndEvent& event);
00124 
00125     void MoveTabToPosn(); 
00126 
00127 
00128 private:
00129     void SlideToImpl(int p, bool signal);
00130     void UpdatePosn();
00131 
00132     int                       m_posn;
00133     int                       m_range_min;
00134     int                       m_range_max;
00135     unsigned int              m_page_sz;
00136     Orientation               m_orientation;
00137     unsigned int              m_line_width;
00138     unsigned int              m_tab_width;
00139     SliderLineStyle           m_line_style;
00140     int                       m_tab_drag_offset;
00141     Button*                   m_tab;
00142     bool                      m_dragging_tab;
00143 
00144     friend class boost::serialization::access;
00145     template <class Archive>
00146     void serialize(Archive& ar, const unsigned int version);
00147 };
00148 
00149 } // namespace GG
00150 
00151 
00152 // template implementations
00153 template <class Archive>
00154 void GG::Slider::serialize(Archive& ar, const unsigned int version)
00155 {
00156     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control)
00157         & BOOST_SERIALIZATION_NVP(m_posn)
00158         & BOOST_SERIALIZATION_NVP(m_range_min)
00159         & BOOST_SERIALIZATION_NVP(m_range_max)
00160         & BOOST_SERIALIZATION_NVP(m_orientation)
00161         & BOOST_SERIALIZATION_NVP(m_line_width)
00162         & BOOST_SERIALIZATION_NVP(m_tab_width)
00163         & BOOST_SERIALIZATION_NVP(m_line_style)
00164         & BOOST_SERIALIZATION_NVP(m_tab_drag_offset)
00165         & BOOST_SERIALIZATION_NVP(m_tab)
00166         & BOOST_SERIALIZATION_NVP(m_page_sz);
00167 }
00168 
00169 #endif // _GG_Slider_h_