GG

TabWnd.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2006 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    
00029 #ifndef _GG_TabWnd_h_
00030 #define _GG_TabWnd_h_
00031 
00032 #include <GG/Button.h>
00033 
00034 
00035 namespace GG {
00036 
00037 class TabBar;
00038 class WndEvent;
00039 
00042 class GG_API OverlayWnd : public Wnd
00043 {
00044 public: 
00046 
00049     typedef boost::signal<void (std::size_t)> WndChangedSignalType;
00051  
00053 
00054     OverlayWnd(X x, Y y, X w, Y h, Flags<WndFlag> flags = Flags<WndFlag>());
00055     ~OverlayWnd();
00057  
00059     virtual Pt MinUsableSize() const;
00060 
00062     bool Empty() const;
00063 
00065     std::size_t NumWnds() const;
00066 
00068     Wnd* CurrentWnd() const;
00069 
00073     std::size_t  CurrentWndIndex() const;
00074 
00076     const std::vector<Wnd*>& Wnds() const;
00078  
00080 
00083     std::size_t AddWnd(Wnd* wnd);
00084 
00089     void InsertWnd(std::size_t index, Wnd* wnd);
00090 
00093     Wnd* RemoveWnd(std::size_t index);
00094 
00097     Wnd* RemoveWnd(Wnd* wnd);
00098 
00101     void SetCurrentWnd(std::size_t index);
00103 
00106     static const std::size_t NO_WND;
00107 
00108 protected: 
00110     OverlayWnd(); 
00111 
00112 
00113 private:
00114     std::vector<Wnd*> m_wnds;
00115     std::size_t       m_current_wnd_index;
00116 
00117     friend class boost::serialization::access;
00118     template <class Archive>
00119     void serialize(Archive& ar, const unsigned int version);
00120 };
00121 
00122 
00125 class GG_API TabWnd : public Wnd
00126 {
00127 public: 
00129 
00132     typedef boost::signal<void (std::size_t)> WndChangedSignalType;
00134  
00136 
00137     TabWnd(X x, Y y, X w, Y h, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
00138            TabBarStyle style = TAB_BAR_ATTACHED, Flags<WndFlag> flags = INTERACTIVE);
00140  
00142     virtual Pt MinUsableSize() const;
00143 
00145     bool Empty() const;
00146 
00148     std::size_t NumWnds() const;
00149 
00151     Wnd* CurrentWnd() const;
00152 
00156     std::size_t  CurrentWndIndex() const;
00158  
00160 
00163     std::size_t AddWnd(Wnd* wnd, const std::string& name);
00164 
00169     void InsertWnd(std::size_t index, Wnd* wnd, const std::string& name);
00170 
00174     Wnd* RemoveWnd(const std::string& name);
00175 
00178     void SetCurrentWnd(std::size_t index);
00180 
00181     mutable WndChangedSignalType WndChangedSignal; 
00182 
00185     static const std::size_t NO_WND;
00186 
00187 protected: 
00189     TabWnd(); 
00190 
00191  
00193 
00194     const TabBar* GetTabBar() const;
00195 
00197     const OverlayWnd* GetOverlayWnd() const;
00198 
00201     const std::map<std::string, Wnd*>& WndNames() const;
00203 
00204 private:
00205     void TabChanged(std::size_t tab_index, bool signal);
00206 
00207     TabBar*                     m_tab_bar;
00208     OverlayWnd*                 m_overlay;
00209     std::map<std::string, Wnd*> m_named_wnds;
00210 
00211     friend class boost::serialization::access;
00212     template <class Archive>
00213     void serialize(Archive& ar, const unsigned int version);
00214 };
00215 
00216 
00222 class GG_API TabBar : public Control
00223 {
00224 public: 
00226 
00229     typedef boost::signal<void (std::size_t)> TabChangedSignalType;
00231  
00233 
00234     TabBar(X x, Y y, X w, const boost::shared_ptr<Font>& font, Clr color, Clr text_color = CLR_BLACK,
00235            TabBarStyle style = TAB_BAR_ATTACHED, Flags<WndFlag> flags = INTERACTIVE);
00237  
00239     virtual Pt MinUsableSize() const;
00240 
00242     bool Empty() const;
00243 
00245     std::size_t NumTabs() const;
00246 
00250     std::size_t CurrentTabIndex() const;
00251 
00253     Clr TextColor() const;
00255  
00257     virtual void SizeMove(const Pt& ul, const Pt& lr);
00258     virtual void Render();
00259 
00263     std::size_t AddTab(const std::string& name);
00264 
00269     void InsertTab(std::size_t index, const std::string& name);
00270 
00273     void RemoveTab(const std::string& name);
00274 
00277     void SetCurrentTab(std::size_t index);
00279 
00280     mutable TabChangedSignalType TabChangedSignal; 
00281 
00284     static const std::size_t NO_TAB;
00285 
00287     static const X BUTTON_WIDTH;
00288 
00289 protected: 
00291     TabBar(); 
00292 
00293  
00295     const Button* LeftButton() const;
00296     const Button* RightButton() const;
00298  
00300     virtual bool EventFilter(Wnd* w, const WndEvent& event);
00301 
00304     void RaiseCurrentTabButton();
00306 
00307 private:
00308     virtual void DistinguishCurrentTab(const std::vector<StateButton*>& tab_buttons);
00309 
00310     void TabChanged(std::size_t index, bool signal);
00311     void LeftClicked();
00312     void RightClicked();
00313     void BringTabIntoView(std::size_t index);
00314 
00315     RadioButtonGroup*         m_tabs;
00316     std::vector<StateButton*> m_tab_buttons;
00317     boost::shared_ptr<Font>   m_font;
00318     Button*                   m_left_button;
00319     Button*                   m_right_button;
00320     Layout*                   m_left_right_button_layout;
00321     Flags<TextFormat>         m_format;
00322     Clr                       m_text_color;
00323     TabBarStyle               m_style;
00324     std::size_t               m_first_tab_shown;
00325 
00326     friend class boost::serialization::access;
00327     template <class Archive>
00328     void serialize(Archive& ar, const unsigned int version);
00329 };
00330 
00331 } // namespace GG
00332 
00333 // template implementations
00334 template <class Archive>
00335 void GG::OverlayWnd::serialize(Archive& ar, const unsigned int version)
00336 {
00337     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00338         & BOOST_SERIALIZATION_NVP(m_wnds)
00339         & BOOST_SERIALIZATION_NVP(m_current_wnd_index);
00340 }
00341 
00342 template <class Archive>
00343 void GG::TabWnd::serialize(Archive& ar, const unsigned int version)
00344 {
00345     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00346         & BOOST_SERIALIZATION_NVP(m_tab_bar)
00347         & BOOST_SERIALIZATION_NVP(m_overlay)
00348         & BOOST_SERIALIZATION_NVP(m_named_wnds);
00349 }
00350 
00351 template <class Archive>
00352 void GG::TabBar::serialize(Archive& ar, const unsigned int version)
00353 {
00354     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Control)
00355         & BOOST_SERIALIZATION_NVP(m_tabs)
00356         & BOOST_SERIALIZATION_NVP(m_tab_buttons)
00357         & BOOST_SERIALIZATION_NVP(m_font)
00358         & BOOST_SERIALIZATION_NVP(m_left_button)
00359         & BOOST_SERIALIZATION_NVP(m_right_button)
00360         & BOOST_SERIALIZATION_NVP(m_left_right_button_layout)
00361         & BOOST_SERIALIZATION_NVP(m_format)
00362         & BOOST_SERIALIZATION_NVP(m_text_color)
00363         & BOOST_SERIALIZATION_NVP(m_style)
00364         & BOOST_SERIALIZATION_NVP(m_first_tab_shown);
00365 }
00366 
00367 #endif