GG

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 Cursor;
00042 class Font;
00043 class TextControl;
00044 
00052 class GG_API BrowseInfoWnd : public Wnd
00053 {
00054 public: 
00056 
00060     virtual bool WndHasBrowseInfo(const Wnd* wnd, std::size_t mode) const = 0;
00062  
00064     virtual void Render() = 0;
00065 
00072     void Update(std::size_t mode, const Wnd* target);
00073 
00075     void SetCursorPosition(const Pt& cursor_pos);
00077 
00083     mutable boost::function<
00084         Pt (const Pt&, const boost::shared_ptr<Cursor>&, const BrowseInfoWnd&, const Wnd&)
00085     > PositionWnd;
00086 
00087 protected: 
00089     BrowseInfoWnd(); 
00090     BrowseInfoWnd(X x, Y y, X w, Y h); 
00091 
00092 
00093 private:
00094     Pt m_cursor_pos;
00095 
00096     virtual void UpdateImpl(std::size_t mode, const Wnd* target);
00097 
00098     friend class boost::serialization::access;
00099     template <class Archive>
00100     void serialize(Archive& ar, const unsigned int version);
00101 };
00102 
00103 
00111 class GG_API TextBoxBrowseInfoWnd : public BrowseInfoWnd
00112 {
00113 public: 
00115 
00116     TextBoxBrowseInfoWnd(X w, const boost::shared_ptr<Font>& font, Clr color, Clr border_color, Clr text_color,
00117                          Flags<TextFormat> format = FORMAT_LEFT | FORMAT_WORDBREAK,
00118                          unsigned int border_width = 2, unsigned int text_margin = 4);
00120  
00122     virtual bool                   WndHasBrowseInfo(const Wnd* wnd, std::size_t mode) const;
00123 
00124     bool                           TextFromTarget() const; 
00125     const std::string&             Text () const;          
00126     const boost::shared_ptr<Font>& GetFont() const;        
00127     Clr                            Color() const;          
00128     Clr                            BorderColor() const;    
00129     Clr                            TextColor() const;      
00130     Flags<TextFormat>              GetTextFormat() const;  
00131     unsigned int                   BorderWidth() const;    
00132     unsigned int                   TextMargin() const;     
00133 
00134  
00136     void         SetText(const std::string& str);
00137     virtual void Render();
00138 
00139     void SetTextFromTarget(bool b);                    
00140     void SetFont(const boost::shared_ptr<Font>& font); 
00141     void SetColor(Clr color);                          
00142     void SetBorderColor(Clr border_color);             
00143     void SetTextColor(Clr text_color);                 
00144     void SetTextFormat(Flags<TextFormat> format);      
00145     void SetBorderWidth(unsigned int border_width);    
00146     void SetTextMargin(unsigned int text_margin);      
00147 
00148 
00149 protected: 
00151     TextBoxBrowseInfoWnd(); 
00152 
00153 
00154 private:
00155     virtual void UpdateImpl(std::size_t mode, const Wnd* target);
00156 
00157     bool                    m_text_from_target;
00158     boost::shared_ptr<Font> m_font;
00159     Clr                     m_color;
00160     Clr                     m_border_color;
00161     unsigned int            m_border_width;
00162     X                       m_preferred_width;
00163     TextControl*            m_text_control;
00164 
00165     friend class boost::serialization::access;
00166     template <class Archive>
00167     void serialize(Archive& ar, const unsigned int version);
00168 };
00169 
00170 } // namespace GG
00171 
00172 
00173 // template implementations
00174 template <class Archive>
00175 void GG::BrowseInfoWnd::serialize(Archive& ar, const unsigned int version)
00176 {
00177     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00178         & BOOST_SERIALIZATION_NVP(m_cursor_pos);
00179 }
00180 
00181 template <class Archive>
00182 void GG::TextBoxBrowseInfoWnd::serialize(Archive& ar, const unsigned int version)
00183 {
00184     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(BrowseInfoWnd)
00185         & BOOST_SERIALIZATION_NVP(m_text_from_target)
00186         & BOOST_SERIALIZATION_NVP(m_font)
00187         & BOOST_SERIALIZATION_NVP(m_color)
00188         & BOOST_SERIALIZATION_NVP(m_border_color)
00189         & BOOST_SERIALIZATION_NVP(m_border_width)
00190         & BOOST_SERIALIZATION_NVP(m_text_control)
00191         & BOOST_SERIALIZATION_NVP(m_preferred_width);
00192 }
00193 
00194 #endif // _GG_BrowseInfoWnd_h_