Author: mordante
Date: Thu May 22 18:30:51 2008
New Revision: 26774

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26774&view=rev
Log:
Let tpanel inherit from tcontainer_ instead of tcontrol.

Modified:
    trunk/src/gui/widgets/container.cpp
    trunk/src/gui/widgets/container.hpp
    trunk/src/gui/widgets/panel.cpp
    trunk/src/gui/widgets/panel.hpp

Modified: trunk/src/gui/widgets/container.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/container.cpp?rev=26774&r1=26773&r2=26774&view=diff
==============================================================================
--- trunk/src/gui/widgets/container.cpp (original)
+++ trunk/src/gui/widgets/container.cpp Thu May 22 18:30:51 2008
@@ -47,5 +47,37 @@
        grid_.draw(surface);
 }
 
+tpoint tcontainer_::get_minimum_size() const
+{
+       tpoint size = grid_.get_maximum_size();
+       tpoint border_size = border_space();
+
+       if(size.x) {
+               size.x += border_size.x;
+       }
+
+       if(size.y) {
+               size.y += border_size.y;
+       }
+
+       return size;
+}
+
+tpoint tcontainer_::get_best_size() const
+{
+       tpoint size = grid_.get_best_size();
+       tpoint border_size = border_space();
+
+       if(size.x) {
+               size.x += border_size.x;
+       }
+
+       if(size.y) {
+               size.y += border_size.y;
+       }
+
+       return size;
+}
+
 } // namespace gui2
 

Modified: trunk/src/gui/widgets/container.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/container.hpp?rev=26774&r1=26773&r2=26774&view=diff
==============================================================================
--- trunk/src/gui/widgets/container.hpp (original)
+++ trunk/src/gui/widgets/container.hpp Thu May 22 18:30:51 2008
@@ -76,17 +76,20 @@
        bool has_vertical_scrollbar() const = 0;
 
        /** Inherited from tcontrol. */
-       tpoint get_minimum_size() const { return grid_.get_minimum_size(); }
+       tpoint get_minimum_size() const;
 
        /** Inherited from tcontrol. */
-       tpoint get_best_size() const { return grid_.get_best_size(); }
+       tpoint get_best_size() const;
 
        /** Inherited from tcontrol. */
        void set_size(const SDL_Rect& rect) 
        {       
                tcontrol::set_size(rect);
-               grid_.set_size(rect);
+               set_client_size(get_client_rect());
        }
+
+       /** FIXME see whether needed to be exported. */
+       void set_client_size(const SDL_Rect& rect) { grid_.set_size(rect); }
 
        /** Inherited from tcontrol. */
        void draw(surface& surface);
@@ -108,6 +111,17 @@
        void set_rows_cols(const unsigned rows, const unsigned cols)
                { grid_.set_rows_cols(rows, cols); }
 
+       void add_child(twidget* widget, const unsigned row, 
+               const unsigned col, const unsigned flags, const unsigned 
border_size)
+               { grid_.add_child(widget, row, col, flags, border_size); }
+
+       void set_row_grow_factor(const unsigned row, const unsigned factor) 
+               { grid_.set_row_grow_factor(row, factor); }
+
+       void set_col_grow_factor(const unsigned col, const unsigned factor)
+               { grid_.set_col_grow_factor(col, factor); }
+
+       virtual SDL_Rect get_client_rect() const { return get_rect(); }
 protected:
        const tgrid& grid() const { return grid_; }
        tgrid& grid() { return grid_; }
@@ -115,6 +129,9 @@
 private:
 
        tgrid grid_;
+
+       //! Returns the space used by the border.
+       virtual tpoint border_space() const { return tpoint(0, 0); }
 };
 
 } // namespace gui2

Modified: trunk/src/gui/widgets/panel.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/panel.cpp?rev=26774&r1=26773&r2=26774&view=diff
==============================================================================
--- trunk/src/gui/widgets/panel.cpp (original)
+++ trunk/src/gui/widgets/panel.cpp Thu May 22 18:30:51 2008
@@ -38,49 +38,12 @@
 
 namespace gui2 {
 
-tpoint tpanel::get_minimum_size() const
-{
-       const tpoint max_size = get_maximum_size();
-       tpoint size = grid_.get_minimum_size() + border_space();
-
-       if(max_size.x) {
-               size.x = minimum(size.x, max_size.x);
-       }
-
-       if(max_size.y) {
-               size.y = minimum(size.y, max_size.y);
-       }
-
-       return size;
-}
-
-tpoint tpanel::get_best_size() const
-{
-       const tpoint max_size = get_maximum_size();
-       tpoint size = grid_.get_best_size() + border_space();
-
-       if(max_size.x) {
-               size.x = minimum(size.x, max_size.x);
-       }
-
-       if(max_size.y) {
-               size.y = minimum(size.y, max_size.y);
-       }
-
-       return size;
-}
-
 void tpanel::draw(surface& surface)
 {
        // Need to preserve the state and inherited draw clear the flag.
        const bool is_dirty = dirty();
-       // background.
-       if(is_dirty) {
-               tcontrol::draw(surface);
-       }
 
-       // children
-       grid_.draw(surface);
+       tcontainer_::draw(surface);
 
        // foreground
        if(is_dirty) {
@@ -105,13 +68,6 @@
        return result;
 }
 
-void tpanel::set_size(const SDL_Rect& rect) 
-{
-       tcontrol::set_size(rect);
-
-       grid_.set_size(get_client_rect());
-}
-
 tpoint tpanel::border_space() const
 {
        const tpanel_definition::tresolution* conf = 

Modified: trunk/src/gui/widgets/panel.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/panel.hpp?rev=26774&r1=26773&r2=26774&view=diff
==============================================================================
--- trunk/src/gui/widgets/panel.hpp (original)
+++ trunk/src/gui/widgets/panel.hpp Thu May 22 18:30:51 2008
@@ -15,12 +15,12 @@
 #ifndef __GUI_WIDGETS_PANEL_HPP_INCLUDED__
 #define __GUI_WIDGETS_PANEL_HPP_INCLUDED__
 
-#include "gui/widgets/grid.hpp"
+#include "gui/widgets/container.hpp"
 
 namespace gui2 {
 
 //! Visible container to hold children.
-class tpanel : public tcontrol 
+class tpanel : public tcontainer_ 
 {
 
 public:
@@ -28,38 +28,25 @@
        //!
        //! @param canvas_count  The canvas count for tcontrol.
        tpanel(const unsigned canvas_count = 2) : 
-               tcontrol(canvas_count),
-               grid_()
+               tcontainer_(canvas_count)
        {
-               grid_.set_parent(this);
        }
 
-       /** Inherited from tcontrol, copied from container.hpp. */
        twidget* find_widget(const tpoint& coordinate, const bool 
must_be_active) 
-               { return grid_.find_widget(coordinate, must_be_active); }
+               { return tcontainer_::find_widget(coordinate, must_be_active); }
 
-       /** Inherited from tcontrol, copied from container.hpp. */
        const twidget* find_widget(const tpoint& coordinate, 
                        const bool must_be_active) const
-               { return grid_.find_widget(coordinate, must_be_active); }
+               { return tcontainer_::find_widget(coordinate, must_be_active); }
 
-       /** Inherited from tcontrol, copied from container.hpp.*/
        twidget* find_widget(const std::string& id, const bool must_be_active)
-       { 
-               twidget* result = tcontrol::find_widget(id, must_be_active);
-               return result ? result : grid_.find_widget(id, must_be_active); 
-       }
+               { return tcontainer_::find_widget(id, must_be_active); }
 
-       /** Inherited from tcontrol, copied from container.hpp.*/
        const twidget* find_widget(const std::string& id, 
                        const bool must_be_active) const
-       { 
-               const twidget* result = tcontrol::find_widget(id, 
must_be_active);
-               return result ? result : grid_.find_widget(id, must_be_active); 
-       }
-       
-       // Inherited from twidget.
-       bool dirty() const { return twidget::dirty() || grid_.dirty(); }
+               { return tcontainer_::find_widget(id, must_be_active); }
+
+       bool has_vertical_scrollbar() const { return false; }
 
        //! A panel is always active atm so ignore the request.
        void set_active(const bool /*active*/) {}
@@ -67,52 +54,17 @@
        unsigned get_state() const { return 0; }
 
        //! Inherited from tcontrol.
-       tpoint get_minimum_size() const;
-       tpoint get_best_size() const;
-
-       // get_maximum_size is inherited from tcontrol.
-
-       //! Inherited from tcontrol.
        void draw(surface& surface);
-
-       //! Inherited from tcontrol.
-       void set_size(const SDL_Rect& rect);
-
-       //***** **** wrappers to the grid **** ****
-       tgrid::iterator begin() { return grid_.begin(); }
-       tgrid::iterator end() { return grid_.end(); }
 
        SDL_Rect get_client_rect() const;
 
-       void set_client_size(const SDL_Rect& rect) { grid_.set_size(rect); }
-
-       void set_rows(const unsigned rows) { grid_.set_rows(rows); }
-       unsigned int get_rows() const { return grid_.get_rows(); }
-
-       void set_cols(const unsigned cols) { grid_.set_cols(cols); }
-       unsigned int get_cols() const { return grid_.get_cols(); }
-
-       void set_rows_cols(const unsigned rows, const unsigned cols)
-               { grid_.set_rows_cols(rows, cols); }
-
-       void add_child(twidget* widget, const unsigned row, 
-               const unsigned col, const unsigned flags, const unsigned 
border_size)
-               { grid_.add_child(widget, row, col, flags, border_size); }
-       
-       void set_row_grow_factor(const unsigned row, const unsigned factor) 
-               { grid_.set_row_grow_factor(row, factor); }
-
-       void set_col_grow_factor(const unsigned col, const unsigned factor)
-               { grid_.set_col_grow_factor(col, factor); }
-
 private:
-       tgrid grid_;
 
        //! Inherited from tcontrol.
        const std::string& get_control_type() const 
                { static const std::string type = "panel"; return type; }
 
-       //! Returns the space used by the border.
+       /** Inherited from tcontainer_. */
        tpoint border_space() const;
 }; 
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to