Author: mordante
Date: Mon Nov 24 20:54:44 2008
New Revision: 31059
URL: http://svn.gna.org/viewcvs/wesnoth?rev=31059&view=rev
Log:
Make wrapping for dialogs work nicely.
As long as the text is shown without a scrollbar the window closes on a
mouse click. When the scrollbar is needed a button will also be shown
and a mouse click (expect on the button) won't close the window anymore.
Modified:
trunk/data/gui/default/window/message.cfg
trunk/src/gui/dialogs/message.cpp
trunk/src/gui/dialogs/message.hpp
trunk/src/gui/widgets/window.hpp
Modified: trunk/data/gui/default/window/message.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/message.cfg?rev=31059&r1=31058&r2=31059&view=diff
==============================================================================
--- trunk/data/gui/default/window/message.cfg (original)
+++ trunk/data/gui/default/window/message.cfg Mon Nov 24 20:54:44 2008
@@ -575,9 +575,7 @@
[/column]
[/row]
-# Comment out the button for now since it's no longer needed.
-# It will be reenabled later to show the buttons optionally.
-#ifdef GUI_NO_SUCH_DEFINITION
+
[row]
[column]
@@ -586,6 +584,9 @@
horizontal_alignment = "center"
[button]
+ # This button will be shown or
hidden depending on the
+ # whether or not a scrollbar is
needed to show the
+ # text.
id = "ok"
definition = "default"
@@ -595,7 +596,7 @@
[/column]
[/row]
-#endif
+
[/grid]
[/resolution]
Modified: trunk/src/gui/dialogs/message.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/message.cpp?rev=31059&r1=31058&r2=31059&view=diff
==============================================================================
--- trunk/src/gui/dialogs/message.cpp (original)
+++ trunk/src/gui/dialogs/message.cpp Mon Nov 24 20:54:44 2008
@@ -44,13 +44,38 @@
VALIDATE(label, missing_widget("label"));
label->set_label(message_);
+
+ if(auto_close_) {
+ /*
+ * Hide the buttton and do the layout, if
window.does_easy_close() is
+ * false the scroll_label has a scrollbar so we need to show the
+ * button. When the button is hidden the text for the label is
bigger
+ * and thus not need a scrollbar. Also when the button is
visible
+ * easy_close will always return false.
+ */
+ /** @todo The space for invisible items is always reserved.
Look about
+ * how to change that. (Maybe get_best_size() in twidget can do
that by
+ * returning 0,0 when called upon invisible items. Or the
tgrid::tchild
+ * should do that since an item with 0,0 might get a border.)
+ */
+ tcontrol* button =
+ dynamic_cast<tcontrol*>(window.find_widget("ok",
false));
+ button->set_visible(false);
+
+ window.layout();
+
+ if(! window.does_easy_close()) {
+ button->set_visible();
+ }
+ }
}
/** @todo the caption is ignored. */
void show_message(CVideo& video, const std::string& title,
- const std::string& message, const std::string& /*button_caption*/)
+ const std::string& message, const std::string& /*button_caption*/,
+ const bool auto_close)
{
- tmessage(title, message).show(video);
+ tmessage(title, message, auto_close).show(video);
}
} // namespace gui2
Modified: trunk/src/gui/dialogs/message.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/message.hpp?rev=31059&r1=31058&r2=31059&view=diff
==============================================================================
--- trunk/src/gui/dialogs/message.hpp (original)
+++ trunk/src/gui/dialogs/message.hpp Mon Nov 24 20:54:44 2008
@@ -28,10 +28,12 @@
class tmessage : public tdialog
{
public:
- tmessage(const std::string& title, const std::string& message)
+ tmessage(const std::string& title, const std::string& message,
+ const bool auto_close)
: title_(title)
, image_()
, message_(message)
+ , auto_close_(auto_close)
{}
/***** ***** ***** setters / getters for members ***** ****** *****/
@@ -56,6 +58,12 @@
/** The message to show to the user. */
std::string message_;
+ /**
+ * Does the window need to use easy_close when the dialog doesn't need a
+ * scrollbar.
+ */
+ bool auto_close_;
+
/** Inherited from tdialog. */
twindow build_window(CVideo& video);
@@ -76,9 +84,13 @@
* @param title The title of the dialog.
* @param message The message to show in the dialog.
* @param button_caption The caption of the close button.
+ * @param auto_close When true the window will hide the ok button
+ * when the message doesn't need a scrollbar to
+ * show itself.
*/
void show_message(CVideo& video, const std::string& title,
- const std::string& message, const std::string& button_caption = "");
+ const std::string& message, const std::string& button_caption = "",
+ const bool auto_close = true);
} // namespace gui2
Modified: trunk/src/gui/widgets/window.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.hpp?rev=31059&r1=31058&r2=31059&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.hpp (original)
+++ trunk/src/gui/widgets/window.hpp Mon Nov 24 20:54:44 2008
@@ -47,6 +47,9 @@
class twindow : public tpanel, public tevent_handler
{
friend class tdebug_layout_graph;
+
+ // Wants to use layout().
+ friend class tmessage;
public:
twindow(CVideo& video,
tformula<unsigned>x,
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits