Author: mordante
Date: Mon Apr 13 15:02:09 2009
New Revision: 34861
URL: http://svn.gna.org/viewcvs/wesnoth?rev=34861&view=rev
Log:
Add the basics of the new layout algorithm.
The resize functions are still a NOP.
Modified:
trunk/src/gui/widgets/container.cpp
trunk/src/gui/widgets/container.hpp
trunk/src/gui/widgets/grid.cpp
trunk/src/gui/widgets/grid.hpp
trunk/src/gui/widgets/widget.hpp
trunk/src/gui/widgets/window.cpp
Modified: trunk/src/gui/widgets/container.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/container.cpp?rev=34861&r1=34860&r2=34861&view=diff
==============================================================================
--- trunk/src/gui/widgets/container.cpp (original)
+++ trunk/src/gui/widgets/container.cpp Mon Apr 13 15:02:09 2009
@@ -42,6 +42,16 @@
grid_.NEW_layout_init(full_initialization);
}
+void tcontainer_::NEW_reduce_width(const unsigned maximum_width)
+{
+ grid_.NEW_reduce_width(maximum_width);
+}
+
+void tcontainer_::NEW_reduce_height(const unsigned maximum_height)
+{
+ grid_.NEW_reduce_height(maximum_height);
+}
+
void tcontainer_::layout_wrap(const unsigned maximum_width)
{
// Inherited.
Modified: trunk/src/gui/widgets/container.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/container.hpp?rev=34861&r1=34860&r2=34861&view=diff
==============================================================================
--- trunk/src/gui/widgets/container.hpp (original)
+++ trunk/src/gui/widgets/container.hpp Mon Apr 13 15:02:09 2009
@@ -52,6 +52,24 @@
void layout_init2(const bool full_initialization);
void NEW_layout_init(const bool full_initialization);
+ /**
+ * Tries to reduce the width of a container.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_width The wanted maximum width.
+ */
+ void NEW_reduce_width(const unsigned maximum_width);
+
+ /**
+ * Tries to reduce the height of a container.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_height The wanted maximum height.
+ */
+ void NEW_reduce_height(const unsigned maximum_height);
+
private:
/** Inherited from twidget. */
tpoint calculate_best_size() const;
Modified: trunk/src/gui/widgets/grid.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.cpp?rev=34861&r1=34860&r2=34861&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.cpp (original)
+++ trunk/src/gui/widgets/grid.cpp Mon Apr 13 15:02:09 2009
@@ -224,6 +224,16 @@
child.NEW_layout_init(full_initialization);
}
+}
+
+void tgrid::NEW_reduce_width(const unsigned /*maximum_width*/)
+{
+ /** @todo Implement. */
+}
+
+void tgrid::NEW_reduce_height(const unsigned /*maximum_height*/)
+{
+ /** @todo Implement. */
}
tpoint tgrid::calculate_best_size() const
Modified: trunk/src/gui/widgets/grid.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.hpp?rev=34861&r1=34860&r2=34861&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.hpp (original)
+++ trunk/src/gui/widgets/grid.hpp Mon Apr 13 15:02:09 2009
@@ -184,6 +184,25 @@
void layout_init2(const bool full_initialization);
void NEW_layout_init(const bool full_initialization);
+ /**
+ * Tries to reduce the width of a container.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_width The wanted maximum width.
+ */
+ void NEW_reduce_width(const unsigned maximum_width);
+
+ /**
+ * Tries to reduce the height of a container.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_height The wanted maximum height.
+ */
+ void NEW_reduce_height(const unsigned maximum_height);
+
+
private:
/** Inherited from twidget. */
Modified: trunk/src/gui/widgets/widget.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/widget.hpp?rev=34861&r1=34860&r2=34861&view=diff
==============================================================================
--- trunk/src/gui/widgets/widget.hpp (original)
+++ trunk/src/gui/widgets/widget.hpp Mon Apr 13 15:02:09 2009
@@ -179,6 +179,61 @@
virtual void NEW_layout_init(const bool full_initialization);
/**
+ * Tries to reduce the width of a widget.
+ *
+ * This function tries to do it 'friendly' and only use scrollbars or
+ * wrapping of the widget.
+ *
+ * @todo Make pure virtual.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_width The wanted maximum width.
+ */
+ virtual void NEW_request_reduce_width(const unsigned /*maximum_width*/)
{}
+
+ /**
+ * Tries to reduce the width of a widget.
+ *
+ * This function does it more agressive and should only be used when
+ * using scrollbars and wrapping failed.
+ *
+ * @todo Make pure virtual.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_width The wanted maximum width.
+ */
+ virtual void NEW_demand_reduce_width(const unsigned /*maximum_width*/)
{}
+
+ /**
+ * Tries to reduce the height of a widget.
+ *
+ * This function tries to do it 'friendly' and only use scrollbars.
+ *
+ * @todo Make pure virtual.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_height The wanted maximum height.
+ */
+ virtual void NEW_request_reduce_height(const unsigned
/*maximum_height*/) {}
+
+ /**
+ * Tries to reduce the height of a widget.
+ *
+ * This function does it more agressive and should only be used when
+ * using scrollbars failed.
+ *
+ * @todo Make pure virtual.
+ *
+ * @see @ref layout_algorihm for more information.
+ *
+ * @param maximum_height The wanted maximum height.
+ */
+ virtual void NEW_demand_reduce_height(const unsigned
/*maximum_height*/) {}
+
+ /**
* Gets the best size for the widget.
*
* During the layout phase a best size will be determined, several
stages
Modified: trunk/src/gui/widgets/window.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=34861&r1=34860&r2=34861&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Mon Apr 13 15:02:09 2009
@@ -739,6 +739,8 @@
const int maximum_height = automatic_placement_ ?
settings::screen_height : h_(variables);
+ /** @todo Handle linked widgets. */
+
if(!NEW_layout(maximum_width, maximum_height)) {
/** @todo implement the scrollbars on the window. */
assert(false);
@@ -799,9 +801,43 @@
}
bool twindow::NEW_layout(
- const unsigned /*maximum_width*/, const unsigned
/*maximum_height*/)
-{
- /** @todo Do something. */
+ const unsigned maximum_width, const unsigned maximum_height)
+{
+ /*
+ * For now we return the status, need to test later whether this can
+ * entirely be converted to an exception based system as in 'promised'
on
+ * the algorithm page.
+ */
+
+ tpoint size = get_best_size();
+
+ if(size.x <= static_cast<int>(maximum_width)
+ && size.y <= static_cast<int>(maximum_height)) {
+
+ return true;
+ }
+
+ if(size.x > static_cast<int>(maximum_width)) {
+ NEW_reduce_width(maximum_width);
+
+ tpoint size = get_best_size();
+ if(size.x > static_cast<int>(maximum_width)) {
+ return false;
+ }
+ }
+
+ if(size.y > static_cast<int>(maximum_height)) {
+ NEW_reduce_height(maximum_height);
+
+ tpoint size = get_best_size();
+ if(size.y > static_cast<int>(maximum_height)) {
+ return false;
+ }
+ }
+
+ assert(size.x <= static_cast<int>(maximum_width)
+ && size.y <= static_cast<int>(maximum_height));
+
return true;
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits