widget.h

Go to the documentation of this file.
00001 
00007 /*
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2.1 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with this library; if not, write to the Free Software
00020     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021 */
00022 
00023 // intrusive_ptr<Panel> needs to know that Panel inherits from RefCountable so include its definition
00024 #include <omgui/panel.h>
00025 
00026 #ifndef OMGUI_INITIALIZER_WIDGET_H
00027 #define OMGUI_INITIALIZER_WIDGET_H
00028 
00029 #include <omgui/dllimpexp.h>
00030 #include <omgui/types.h>
00031 
00032 namespace omgui {
00033     class Panel;
00034     class Widget;
00035     namespace initializer {
00036 
00040 struct OMGUI_API WidgetData
00041 {
00042 protected:
00047     omgui::Size m_min_size;
00048 
00053     omgui::Size m_max_size;
00054 
00056     omgui::Size m_natural_size;
00057 
00059     Pointer<omgui::Panel> m_parent;
00060 
00062     bool m_show;
00063 
00065     bool m_activate;
00066 
00068     bool m_enable;
00069 
00070 public:
00071     WidgetData();
00072     virtual ~WidgetData();
00073 
00074     void set_min_size(const omgui::Size &s);
00075     omgui::Size get_min_size() const;
00076     void set_max_size(const omgui::Size &s);
00077     omgui::Size get_max_size() const;
00078     void set_natural_size(const omgui::Size &s);
00079     omgui::Size get_natural_size() const;
00080     void set_parent(const Pointer<omgui::Panel> &p);
00081     Pointer<omgui::Panel> get_parent() const;
00082     void set_show(bool b);
00083     bool get_show() const;
00084     void set_activate(bool b);
00085     bool get_activate() const;
00086     void set_enable(bool b);
00087     bool get_enable() const;
00088 };
00089 
00093 template<class T> class Widget
00094 {
00095 public:
00096     typedef WidgetData data_type;
00097 
00098 protected:
00099     data_type *m_data;
00100 
00101     Widget(data_type *data)
00102         : m_data(data)
00103     { }
00104 
00105     virtual ~Widget() { delete m_data; }
00106 
00107 public:
00108     T &parent(const Pointer<omgui::Panel> &p)
00109     {
00110         m_data->set_parent(p);
00111         return static_cast<T&>(*this);
00112     }
00113 
00114     T &show(bool s = true)
00115     {
00116         m_data->set_show(s);
00117         return static_cast<T&>(*this);
00118     }
00119 
00120     T &activate(bool a = true)
00121     {
00122         m_data->set_activate(a);
00123         return static_cast<T&>(*this);
00124     }
00125 
00126     T &hide()
00127     {
00128         m_data->set_show(false);
00129         return static_cast<T&>(*this);
00130     }
00131 
00132     T &enable(bool s = true)
00133     {
00134         m_data->set_enable(s);
00135         return static_cast<T&>(*this);
00136     }
00137 
00138     T &disable()
00139     {
00140         m_data->set_enable(false);
00141         return static_cast<T&>(*this);
00142     }
00143 
00144     T &min_size(const omgui::Size &s)
00145     {
00146         m_data->set_min_size(s);
00147         return static_cast<T&>(*this);
00148     }
00149 
00150     T &max_size(const omgui::Size &s)
00151     {
00152         m_data->set_max_size(s);
00153         return static_cast<T&>(*this);
00154     }
00155 
00156     T &natural_size(const omgui::Size &s)
00157     {
00158         m_data->set_natural_size(s);
00159         return static_cast<T&>(*this);
00160     }
00161 
00162     omgui::Size get_min_size() const { return m_data->get_min_size(); }
00163     omgui::Size get_max_size() const { return m_data->get_max_size(); }
00164     omgui::Size get_natural_size() const { return m_data->get_natural_size(); }
00165     Pointer<omgui::Panel> get_parent() const { return m_data->get_parent(); }
00166     bool get_show() const { return m_data->get_show(); }
00167     bool get_enable() const { return m_data->get_enable(); }
00168     bool get_activate() const { return m_data->get_activate(); }
00169 
00170 private:
00171     // non assignable
00172     Widget<T> &operator= (const Widget<T> &);
00173 };
00174 
00175     } // initializer
00176 } // omgui
00177 
00178 #endif // OMGUI_INITIALIZER_WIDGET_H

doxygen SourceForge.net Logo