Layout.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_Layout_h_
00030 #define _GG_Layout_h_
00031 
00032 #include <GG/AlignmentFlags.h>
00033 #include <GG/Wnd.h>
00034 
00035 #include <boost/serialization/version.hpp>
00036 
00037 
00038 namespace GG {
00039 
00040 struct SetMarginAction;
00041 
00084 class GG_API Layout : public Wnd
00085 {
00086 public: 
00088 
00089     Layout(int x, int y, int w, int h, int rows, int columns, int border_margin = 0, int cell_margin = -1);
00091  
00093     virtual Pt MinUsableSize() const;
00094 
00095     int    Rows() const;                             
00096     int    Columns() const;                          
00097     Flags<Alignment>
00098            ChildAlignment(Wnd* wnd) const;           
00099     int    BorderMargin() const;                     
00100     int    CellMargin() const;                       
00101     double RowStretch(int row) const;                
00102     double ColumnStretch(int column) const;          
00103     int    MinimumRowHeight(int row) const;          
00104     int    MinimumColumnWidth(int column) const;     
00105     std::vector<std::vector<const Wnd*> >
00106            Cells() const;                            
00107     std::vector<std::vector<Rect> >
00108            CellRects() const;                        
00109     std::vector<std::vector<Rect> >
00110            RelativeCellRects() const;                
00111 
00114     bool   RenderOutline() const;
00115 
00118     Clr    OutlineColor() const;
00120     
00122     virtual void StartingChildDragDrop(const Wnd* wnd, const Pt& offset);
00123     virtual void CancellingChildDragDrop(const std::list<Wnd*>& wnds);
00124     virtual void ChildrenDraggedAway(const std::list<Wnd*>& wnds, const Wnd* destination);
00125     virtual void SizeMove(const Pt& ul, const Pt& lr);
00126     virtual void Render();
00127     virtual void MouseWheel(const Pt& pt, int move, Flags<ModKey> mod_keys);
00128     virtual void KeyPress(Key key, Flags<ModKey> mod_keys);
00129     virtual void KeyRelease(Key key, Flags<ModKey> mod_keys);
00130 
00134     void Add(Wnd* wnd, int row, int column, Flags<Alignment> alignment = ALIGN_NONE);
00135 
00141     void Add(Wnd* wnd, int row, int column, int num_rows, int num_columns, Flags<Alignment> alignment = ALIGN_NONE);
00142 
00145     void Remove(Wnd* wnd);
00146 
00149     void DetachAndResetChildren();
00150 
00153     void ResizeLayout(int rows, int columns);
00154 
00156     void SetChildAlignment(Wnd* wnd, Flags<Alignment> alignment);
00157 
00159     void SetBorderMargin(int margin);
00160 
00162     void SetCellMargin(int margin);
00163 
00167     void SetRowStretch(int row, double stretch);
00168 
00172     void SetColumnStretch(int column, double stretch);
00173 
00175     void SetMinimumRowHeight(int row, int height);
00176 
00178     void SetMinimumColumnWidth(int column, int width);
00179 
00182     void RenderOutline(bool render_outline);
00183 
00186     void SetOutlineColor(Clr color);
00187 
00188     virtual void DefineAttributes(WndEditor* editor);
00190  
00192 
00193     GG_ABSTRACT_EXCEPTION(Exception);
00194 
00196     GG_CONCRETE_EXCEPTION(InvalidMargin, GG::Layout, Exception);
00197 
00199     GG_CONCRETE_EXCEPTION(NoSuchChild, GG::Layout, Exception);
00200 
00202     GG_CONCRETE_EXCEPTION(FailedCalculationCheck, GG::Layout, Exception);
00203 
00205     GG_CONCRETE_EXCEPTION(AttemptedOverwrite, GG::Layout, Exception);
00207 
00208 protected: 
00210     Layout(); 
00211 
00212 
00213 private:
00214     struct GG_API RowColParams
00215     {
00216         RowColParams();
00217 
00218         double stretch;
00219         int    min;
00220         int    effective_min;   
00221         int    current_origin;  
00222         int    current_width;   
00223 
00224     private:
00225         friend class boost::serialization::access;
00226         template <class Archive>
00227         void serialize(Archive& ar, const unsigned int version);
00228     };
00229 
00230     struct GG_API WndPosition
00231     {
00232         WndPosition();
00233         WndPosition(int first_row_, int first_column_, int last_row_, int last_column_, Flags<Alignment> alignment_, const Pt& original_ul_, const Pt& original_size_);
00234 
00235         int              first_row;
00236         int              first_column;
00237         int              last_row;
00238         int              last_column;
00239         Flags<Alignment> alignment;
00240         Pt               original_ul;
00241         Pt               original_size;
00242 
00243     private:
00244         friend class boost::serialization::access;
00245         template <class Archive>
00246         void serialize(Archive& ar, const unsigned int version);
00247     };
00248 
00249     double TotalStretch(const std::vector<RowColParams>& params_vec) const;
00250     int    TotalMinWidth() const;
00251     int    TotalMinHeight() const;
00252     void   ValidateAlignment(Flags<Alignment>& alignment);
00253     void   RedoLayout();
00254     void   ChildSizeOrMinSizeOrMaxSizeChanged();
00255 
00256     std::vector<std::vector<Wnd*> > m_cells;
00257     int                             m_border_margin;
00258     int                             m_cell_margin;
00259     std::vector<RowColParams>       m_row_params;
00260     std::vector<RowColParams>       m_column_params;
00261     std::map<Wnd*, WndPosition>     m_wnd_positions;
00262     Pt                              m_min_usable_size;
00263     bool                            m_ignore_child_resize;
00264     bool                            m_ignore_parent_resize;
00265     bool                            m_render_outline;
00266     Clr                             m_outline_color;
00267 
00268     friend class Wnd;
00269     friend struct SetMarginAction;
00270 
00271     friend class boost::serialization::access;
00272     template <class Archive>
00273     void serialize(Archive& ar, const unsigned int version);
00274 };
00275 
00276 } // namespace GG
00277 
00278 BOOST_CLASS_VERSION(GG::Layout, 1)
00279 
00280 // template implementations
00281 template <class Archive>
00282 void GG::Layout::RowColParams::serialize(Archive& ar, const unsigned int version)
00283 {
00284     ar  & BOOST_SERIALIZATION_NVP(stretch)
00285         & BOOST_SERIALIZATION_NVP(min)
00286         & BOOST_SERIALIZATION_NVP(effective_min)
00287         & BOOST_SERIALIZATION_NVP(current_origin)
00288         & BOOST_SERIALIZATION_NVP(current_width);
00289 }
00290 
00291 template <class Archive>
00292 void GG::Layout::WndPosition::serialize(Archive& ar, const unsigned int version)
00293 {
00294     ar  & BOOST_SERIALIZATION_NVP(first_row)
00295         & BOOST_SERIALIZATION_NVP(first_column)
00296         & BOOST_SERIALIZATION_NVP(last_row)
00297         & BOOST_SERIALIZATION_NVP(last_column)
00298         & BOOST_SERIALIZATION_NVP(alignment)
00299         & BOOST_SERIALIZATION_NVP(original_ul)
00300         & BOOST_SERIALIZATION_NVP(original_size);
00301 }
00302 
00303 template <class Archive>
00304 void GG::Layout::serialize(Archive& ar, const unsigned int version)
00305 {
00306     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00307         & BOOST_SERIALIZATION_NVP(m_cells)
00308         & BOOST_SERIALIZATION_NVP(m_border_margin)
00309         & BOOST_SERIALIZATION_NVP(m_cell_margin)
00310         & BOOST_SERIALIZATION_NVP(m_row_params)
00311         & BOOST_SERIALIZATION_NVP(m_column_params)
00312         & BOOST_SERIALIZATION_NVP(m_wnd_positions)
00313         & BOOST_SERIALIZATION_NVP(m_ignore_child_resize)
00314         & BOOST_SERIALIZATION_NVP(m_render_outline)
00315         & BOOST_SERIALIZATION_NVP(m_outline_color);
00316 
00317     if (1 <= version)
00318         ar & BOOST_SERIALIZATION_NVP(m_min_usable_size);
00319 }
00320 
00321 #endif // _GG_Layout_h_

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