BrowseInfoWnd.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_BrowseInfoWnd_h_
00031 #define _GG_BrowseInfoWnd_h_
00032 
00033 #include <GG/Wnd.h>
00034 #include <GG/Font.h>
00035 
00036 #include <boost/serialization/version.hpp>
00037 
00038 
00039 namespace GG {
00040 
00041 class Font;
00042 class TextControl;
00043 
00051 class GG_API BrowseInfoWnd : public Wnd
00052 {
00053 public: 
00055 
00059     virtual bool WndHasBrowseInfo(const Wnd* wnd, std::size_t mode) const = 0;
00061  
00063     virtual void Render() = 0;
00064 
00071     void Update(std::size_t mode, const Wnd* target);
00072 
00074     void SetCursorPosition(const Pt& cursor_pos);
00076 
00077 protected: 
00079     BrowseInfoWnd(); 
00080     BrowseInfoWnd(X x, Y y, X w, Y h); 
00081 
00082 
00083 private:
00084     Pt m_cursor_pos;
00085 
00086     virtual void UpdateImpl(std::size_t mode, const Wnd* target);
00087 
00088     friend class boost::serialization::access;
00089     template <class Archive>
00090     void serialize(Archive& ar, const unsigned int version);
00091 };
00092 
00093 
00101 class GG_API TextBoxBrowseInfoWnd : public BrowseInfoWnd
00102 {
00103 public: 
00105 
00106     TextBoxBrowseInfoWnd(X w, const boost::shared_ptr<Font>& font, Clr color, Clr border_color, Clr text_color,
00107                          Flags<TextFormat> format = FORMAT_LEFT | FORMAT_WORDBREAK,
00108                          unsigned int border_width = 2, unsigned int text_margin = 4);
00110  
00112     virtual bool                   WndHasBrowseInfo(const Wnd* wnd, std::size_t mode) const;
00113 
00114     bool                           TextFromTarget() const; 
00115     const std::string&             Text () const;          
00116     const boost::shared_ptr<Font>& GetFont() const;        
00117     Clr                            Color() const;          
00118     Clr                            BorderColor() const;    
00119     Clr                            TextColor() const;      
00120     Flags<TextFormat>              GetTextFormat() const;  
00121     unsigned int                   BorderWidth() const;    
00122     unsigned int                   TextMargin() const;     
00123 
00124  
00126     void         SetText (const std::string& str);
00127     virtual void Render();
00128 
00129     void SetTextFromTarget(bool b);                    
00130     void SetFont(const boost::shared_ptr<Font>& font); 
00131     void SetColor(Clr color);                          
00132     void SetBorderColor(Clr border_color);             
00133     void SetTextColor(Clr text_color);                 
00134     void SetTextFormat(Flags<TextFormat> format);      
00135     void SetBorderWidth(unsigned int border_width);    
00136     void SetTextMargin(unsigned int text_margin);      
00137 
00138 
00139 protected: 
00141     TextBoxBrowseInfoWnd(); 
00142 
00143 
00144 private:
00145     virtual void UpdateImpl(std::size_t mode, const Wnd* target);
00146 
00147     bool                    m_text_from_target;
00148     boost::shared_ptr<Font> m_font;
00149     Clr                     m_color;
00150     Clr                     m_border_color;
00151     unsigned int            m_border_width;
00152     X                       m_preferred_width;
00153     TextControl*            m_text_control;
00154 
00155     friend class boost::serialization::access;
00156     template <class Archive>
00157     void serialize(Archive& ar, const unsigned int version);
00158 };
00159 
00160 } // namespace GG
00161 
00162 
00163 // template implementations
00164 template <class Archive>
00165 void GG::BrowseInfoWnd::serialize(Archive& ar, const unsigned int version)
00166 {
00167     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00168         & BOOST_SERIALIZATION_NVP(m_cursor_pos);
00169 }
00170 
00171 template <class Archive>
00172 void GG::TextBoxBrowseInfoWnd::serialize(Archive& ar, const unsigned int version)
00173 {
00174     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BrowseInfoWnd)
00175         & BOOST_SERIALIZATION_NVP(m_text_from_target)
00176         & BOOST_SERIALIZATION_NVP(m_font)
00177         & BOOST_SERIALIZATION_NVP(m_color)
00178         & BOOST_SERIALIZATION_NVP(m_border_color)
00179         & BOOST_SERIALIZATION_NVP(m_border_width)
00180         & BOOST_SERIALIZATION_NVP(m_text_control)
00181         & BOOST_SERIALIZATION_NVP(m_preferred_width);
00182 }
00183 
00184 #endif // _GG_BrowseInfoWnd_h_

Generated on Sat Mar 26 07:08:37 2011 for GG by  doxygen 1.5.9