Author: mordante
Date: Sun Feb 14 20:36:28 2010
New Revision: 41214

URL: http://svn.gna.org/viewcvs/wesnoth?rev=41214&view=rev
Log:
Add a new way for a client to request a resize.

This version will put the responsibility for the resizing at the widget
requesting it. This feels more natural especially since the widget can
delay the placement until really needed, which in case of several
resizes is more efficient.

Modified:
    trunk/src/gui/widgets/scrollbar_container.cpp
    trunk/src/gui/widgets/scrollbar_container.hpp

Modified: trunk/src/gui/widgets/scrollbar_container.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/scrollbar_container.cpp?rev=41214&r1=41213&r2=41214&view=diff
==============================================================================
--- trunk/src/gui/widgets/scrollbar_container.cpp (original)
+++ trunk/src/gui/widgets/scrollbar_container.cpp Sun Feb 14 20:36:28 2010
@@ -322,7 +322,6 @@
                tscrollbar_container::tscrollbar_mode& scrollbar_mode,
                const unsigned items, const unsigned visible_items)
 {
-
        assert(scrollbar_grid && scrollbar);
 
        if(scrollbar_mode == tscrollbar_container::always_invisible) {
@@ -525,6 +524,124 @@
        return true;
 }
 
+bool tscrollbar_container::content_resize_request(
+                 const int width_modification
+               , const int height_modification)
+{
+       DBG_GUI_L << LOG_HEADER
+                       << " wanted width modification " << width_modification
+                       << " wanted height modification " << height_modification
+                       << ".\n";
+
+       if(get_size() == tpoint(0, 0)) {
+               DBG_GUI_L << LOG_HEADER
+                               << " initial setup not done, bailing out.\n";
+               return false;
+       }
+
+       twindow* window = get_window();
+       assert(window);
+       if(window->get_need_layout()) {
+               DBG_GUI_L << LOG_HEADER
+                               << " window already needs a layout phase, 
bailing out.\n";
+               return false;
+       }
+
+       assert(content_ && content_grid_);
+
+       const bool result = content_resize_width(width_modification)
+                       && content_resize_height(height_modification);
+
+       DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
+       return result;
+}
+
+bool tscrollbar_container::content_resize_width(const int width_modification)
+{
+       if(width_modification == 0) {
+               return true;
+       }
+
+       const int new_width = content_grid_->get_width() + width_modification;
+       DBG_GUI_L << LOG_HEADER
+                       << " current width " << content_grid_->get_width()
+                       << " wanted width " << new_width;
+
+       assert(new_width > 0);
+
+       if(static_cast<unsigned>(new_width) <= content_->get_width()) {
+               DBG_GUI_L << " width fits in container, test height.\n";
+               return true;
+       }
+
+       assert(horizontal_scrollbar_ && horizontal_scrollbar_grid_);
+       if(horizontal_scrollbar_mode_ == always_invisible
+                       || (horizontal_scrollbar_mode_ == auto_visible_first_run
+                               && horizontal_scrollbar_grid_->get_visible()
+                                       == twidget::INVISIBLE)) {
+
+               DBG_GUI_L << " can't use horizontal scrollbar, ask window.\n";
+               twindow* window = get_window();
+               assert(window);
+               window->invalidate_layout();
+               return false;
+       }
+
+       DBG_GUI_L << " use the horizontal scrollbar, test height.\n";
+       set_scrollbar_mode(horizontal_scrollbar_grid_
+                       , horizontal_scrollbar_
+                       , horizontal_scrollbar_mode_
+                       , new_width
+                       , content_->get_width());
+
+       return true;
+}
+
+bool tscrollbar_container::content_resize_height(const int height_modification)
+{
+       if(height_modification == 0) {
+               return true;
+       }
+
+       const int new_height =
+                       content_grid_->get_height() + height_modification;
+
+       DBG_GUI_L << LOG_HEADER
+                       << " current height " << content_grid_->get_height()
+                       << " wanted height " << new_height;
+
+       assert(new_height > 0);
+
+       if(static_cast<unsigned>(new_height) <= content_->get_height()) {
+               DBG_GUI_L << " height in container, resize allowed.\n";
+               return true;
+       }
+
+       assert(vertical_scrollbar_ && vertical_scrollbar_grid_);
+       if(vertical_scrollbar_mode_ == always_invisible
+                       || (vertical_scrollbar_mode_ == auto_visible_first_run
+                               && vertical_scrollbar_grid_->get_visible()
+                                       == twidget::INVISIBLE)) {
+
+               DBG_GUI_L << " can't use vertical scrollbar, ask window.\n";
+               twindow* window = get_window();
+               assert(window);
+               window->invalidate_layout();
+               return false;
+       }
+
+       DBG_GUI_L << " use the vertical scrollbar, resize allowed.\n";
+       set_scrollbar_mode(vertical_scrollbar_grid_
+                       , vertical_scrollbar_
+                       , vertical_scrollbar_mode_
+                       , new_height
+                       , content_->get_height());
+
+       vertical_scrollbar_->set_dirty();
+
+       return true;
+}
+
 void tscrollbar_container::vertical_scrollbar_click(twidget* caller)
 {
        const std::map<std::string, tscrollbar_::tscroll>::const_iterator

Modified: trunk/src/gui/widgets/scrollbar_container.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/scrollbar_container.hpp?rev=41214&r1=41213&r2=41214&view=diff
==============================================================================
--- trunk/src/gui/widgets/scrollbar_container.hpp (original)
+++ trunk/src/gui/widgets/scrollbar_container.hpp Sun Feb 14 20:36:28 2010
@@ -240,6 +240,57 @@
         */
        bool content_resize_request(const bool force_sizing = false);
 
+       /**
+        * Request from the content to modify the size of the container.
+        *
+        * When the wanted resize fails the function will call @ref
+        * twindow::invalidate_layout().
+        *
+        *
+        * @note Calling this function on a widget with size == (0, 0) results
+        * false but doesn't call invalidate_layout, the engine expects to be in
+        * build up phase with the layout already invalidated.
+        *
+        * @note If @ref twindow::get_need_layout() is true the function returns
+        * false and doesn't try to fit the contents since a layout phase will 
be
+        * triggered anyway.
+        *
+        * @note This function might replace the @ref content_resize_request 
above.
+        *
+        * @param width_modification  The wanted modification to the width:
+        *                            * negative values reduce width.
+        *                            * zero leave width as is.
+        *                            * positive values increase width.
+        * @param height_modification The wanted modification to the height:
+        *                            * negative values reduce height.
+        *                            * zero leave height as is.
+        *                            * positive values increase height.
+        *
+        * @returns                   True is wanted modification is accepted 
false
+        *                            otherwise.
+        */
+       bool content_resize_request(
+                         const int width_modification
+                       , const int height_modification);
+
+private:
+
+       /**
+        * Helper for @ref content_resize_request.
+        *
+        * Handle the width modification.
+        */
+       bool content_resize_width(const int width_modification);
+
+       /**
+        * Helper for @ref content_resize_request.
+        *
+        * Handle the height modification.
+        */
+       bool content_resize_height(const int height_modification);
+
+protected:
+
        /***** ***** ***** ***** keyboard functions ***** ***** ***** *****/
 
        /**


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

Reply via email to