Scroll.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 
00029 #ifndef _GG_Scroll_h_
00030 #define _GG_Scroll_h_
00031 
00032 #include <GG/Control.h>
00033 
00034 
00035 namespace GG {
00036 
00037 class Button;
00038 
00049 class GG_API Scroll : public Control
00050 {
00051 public:
00053     enum ScrollRegion {
00054         SBR_NONE,
00055         SBR_PAGE_DN,
00056         SBR_PAGE_UP
00057     };
00058  
00060     typedef boost::signal<void (int, int, int, int)> ScrolledSignalType; 
00061     typedef boost::signal<void (int, int, int, int)> ScrolledAndStoppedSignalType; 
00062 
00063  
00065     typedef ScrolledSignalType::slot_type ScrolledSlotType; 
00066     typedef ScrolledAndStoppedSignalType::slot_type ScrolledAndStoppedSlotType; 
00067 
00068  
00070 
00071     Scroll(int x, int y, int w, int h, Orientation orientation, Clr color, Clr interior,
00072            Flags<WndFlag> flags = CLICKABLE | REPEAT_BUTTON_DOWN);
00074  
00076     virtual Pt           MinUsableSize() const;
00077 
00078     std::pair<int, int>  PosnRange() const;         
00079     std::pair<int, int>  ScrollRange() const;       
00080     int                  LineSize() const;          
00081     int                  PageSize() const;          
00082 
00083     Clr                  InteriorColor() const;     
00084     Orientation          ScrollOrientation() const; 
00085 
00086     mutable ScrolledSignalType           ScrolledSignal;           
00087     mutable ScrolledAndStoppedSignalType ScrolledAndStoppedSignal; 
00088 
00089  
00091     virtual void   Render();
00092     virtual void   LButtonDown(const Pt& pt, Flags<ModKey> mod_keys);
00093     virtual void   LButtonUp(const Pt& pt, Flags<ModKey> mod_keys);
00094     virtual void   LClick(const Pt& pt, Flags<ModKey> mod_keys);
00095     virtual void   MouseHere(const Pt& pt, Flags<ModKey> mod_keys);
00096 
00097     virtual void   SizeMove(const Pt& ul, const Pt& lr);
00098 
00099     virtual void   Disable(bool b = true);
00100     virtual void   SetColor(Clr c);
00101 
00102     void           SetInteriorColor(Clr c); 
00103     void           SizeScroll(int min, int max, int line, int page); 
00104     void           SetMax(int max);         
00105     void           SetMin(int min);         
00106     void           SetLineSize(int line);   
00107     void           SetPageSize(int page);   
00108 
00109     void           ScrollTo(int p);  
00110     void           ScrollLineIncr(); 
00111     void           ScrollLineDecr(); 
00112     void           ScrollPageIncr(); 
00113     void           ScrollPageDecr(); 
00114 
00115     virtual void   DefineAttributes(WndEditor* editor);
00117 
00118 protected: 
00120     Scroll(); 
00121 
00122  
00124     int           TabSpace() const;          
00125     int           TabWidth() const;          
00126     ScrollRegion  RegionUnder(const Pt& pt); 
00127 
00128     Button*       TabButton() const;     
00129     Button*       IncrButton() const;    
00130     Button*       DecrButton() const;    
00131 
00132  
00134     virtual bool  EventFilter(Wnd* w, const WndEvent& event);
00136 
00137 private:
00138     void              UpdatePosn();        
00139     void              MoveTabToPosn();     
00140 
00141     Clr               m_int_color;   
00142     const Orientation m_orientation; 
00143     int               m_posn;        
00144     int               m_range_min;   
00145     int               m_range_max;   
00146     int               m_line_sz;     
00147     int               m_page_sz;     
00148     Button*           m_tab;         
00149     Button*           m_incr;        
00150     Button*           m_decr;        
00151     ScrollRegion      m_initial_depressed_region; 
00152     ScrollRegion      m_depressed_region;         
00153 
00154     friend class boost::serialization::access;
00155     template <class Archive>
00156     void serialize(Archive& ar, const unsigned int version);
00157 };
00158 
00159 // define EnumMap and stream operators for Scroll::ScrollRegion
00160 GG_ENUM_MAP_BEGIN(Scroll::ScrollRegion)
00161     GG_ENUM_MAP_INSERT(Scroll::SBR_NONE)
00162     GG_ENUM_MAP_INSERT(Scroll::SBR_PAGE_DN)
00163     GG_ENUM_MAP_INSERT(Scroll::SBR_PAGE_UP)
00164 GG_ENUM_MAP_END
00165 
00166 GG_ENUM_STREAM_IN(Scroll::ScrollRegion)
00167 GG_ENUM_STREAM_OUT(Scroll::ScrollRegion)
00168 
00169 } // namespace GG
00170 
00171 // template implementations
00172 template <class Archive>
00173 void GG::Scroll::serialize(Archive& ar, const unsigned int version)
00174 {
00175     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control)
00176         & BOOST_SERIALIZATION_NVP(m_int_color)
00177         & boost::serialization::make_nvp("m_orientation", const_cast<Orientation&>(m_orientation))
00178         & BOOST_SERIALIZATION_NVP(m_posn)
00179         & BOOST_SERIALIZATION_NVP(m_range_min)
00180         & BOOST_SERIALIZATION_NVP(m_range_max)
00181         & BOOST_SERIALIZATION_NVP(m_line_sz)
00182         & BOOST_SERIALIZATION_NVP(m_page_sz)
00183         & BOOST_SERIALIZATION_NVP(m_tab)
00184         & BOOST_SERIALIZATION_NVP(m_incr)
00185         & BOOST_SERIALIZATION_NVP(m_decr);
00186 }
00187 
00188 #endif // _GG_Scroll_h_

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