Author: mordante
Date: Fri Oct 31 19:45:33 2008
New Revision: 30473
URL: http://svn.gna.org/viewcvs/wesnoth?rev=30473&view=rev
Log:
Add the easy close feature to the new widgets.
The easy close feature closes windows by a single mouse click, without
the need for a close button. Also converted the test dialog for the
remove addons to use this feature and commenting out the button in the
config (it will be needed later again).
Modified:
trunk/changelog
trunk/data/gui/default/window/message.cfg
trunk/src/gui/widgets/button.cpp
trunk/src/gui/widgets/button.hpp
trunk/src/gui/widgets/container.hpp
trunk/src/gui/widgets/control.cpp
trunk/src/gui/widgets/control.hpp
trunk/src/gui/widgets/grid.cpp
trunk/src/gui/widgets/image.hpp
trunk/src/gui/widgets/label.hpp
trunk/src/gui/widgets/minimap.hpp
trunk/src/gui/widgets/scrollbar.cpp
trunk/src/gui/widgets/scrollbar.hpp
trunk/src/gui/widgets/spacer.hpp
trunk/src/gui/widgets/text.cpp
trunk/src/gui/widgets/text.hpp
trunk/src/gui/widgets/toggle_button.cpp
trunk/src/gui/widgets/toggle_button.hpp
trunk/src/gui/widgets/tooltip.hpp
trunk/src/gui/widgets/vertical_scrollbar_container.cpp
Modified: trunk/changelog
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/changelog?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/changelog (original)
+++ trunk/changelog Fri Oct 31 19:45:33 2008
@@ -33,6 +33,9 @@
in addition to the playable map area. The used mask must have the same
border_size as the map (i.e. currently 1), else this will be ignored.
* Restore x1, y1, x2, and y2 after events fired from events.
+ * User interface:
+ * The new widget library now also supports closing a dialog with a mouse
+ click without a close button.
* Miscellaneous and bug fixes:
* fixed addon update version logic (patch #1110)
Modified: trunk/data/gui/default/window/message.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/message.cfg?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/data/gui/default/window/message.cfg (original)
+++ trunk/data/gui/default/window/message.cfg Fri Oct 31 19:45:33 2008
@@ -329,6 +329,8 @@
[resolution]
definition = "default"
+ easy_close = "true"
+
[grid]
[row]
@@ -401,7 +403,9 @@
[/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]
@@ -419,7 +423,7 @@
[/column]
[/row]
-
+#endif
[/grid]
[/resolution]
Modified: trunk/src/gui/widgets/button.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/button.cpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/button.cpp (original)
+++ trunk/src/gui/widgets/button.cpp Fri Oct 31 19:45:33 2008
@@ -71,6 +71,7 @@
{
if(state != state_) {
state_ = state;
+ set_block_easy_close(get_visible() && get_active());
set_dirty(true);
}
}
Modified: trunk/src/gui/widgets/button.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/button.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/button.hpp (original)
+++ trunk/src/gui/widgets/button.hpp Fri Oct 31 19:45:33 2008
@@ -65,6 +65,9 @@
/** Inherited from tcontrol. */
unsigned get_state() const { return state_; }
+ /** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return true; }
+
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_retval(const int retval) { retval_ = retval; }
Modified: trunk/src/gui/widgets/container.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/container.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/container.hpp (original)
+++ trunk/src/gui/widgets/container.hpp Fri Oct 31 19:45:33 2008
@@ -125,6 +125,15 @@
/** Inherited from tcontrol. */
void set_active(const bool active);
+ /**
+ * Inherited from tcontrol.
+ *
+ * NOTE normally containers don't block, but their children may. But
+ * normally the state for the children is set as well so we don't need
to
+ * delegate the request to our children.
+ */
+ bool does_block_easy_close() const { return false; }
+
/***** **** ***** ***** wrappers to the grid **** ********* *****/
tgrid::iterator begin() { return grid_.begin(); }
Modified: trunk/src/gui/widgets/control.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.cpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.cpp (original)
+++ trunk/src/gui/widgets/control.cpp Fri Oct 31 19:45:33 2008
@@ -53,6 +53,31 @@
}
}
+void tcontrol::set_block_easy_close(const bool block)
+{
+ twindow* window = get_window();
+ if(!window) {
+ /*
+ * This can happen in a listbox when the row data is
manipulated before
+ * the listbox is finalized. In that case that widget should do
set the
+ * state in its finalizer.
+ */
+ DBG_GUI << "tcontrol(" + get_control_type() + ") " + __func__ +
": "
+ "No window set, this might be a bug.\n";
+ return;
+ }
+
+ if(block) {
+ if(id().empty()) {
+ set_id(get_uid());
+ }
+ window->add_easy_close_blocker(id());
+ } else if(!id().empty()) {
+ // It might never have been enabled so the id might be empty.
+ window->remove_easy_close_blocker(id());
+ }
+}
+
void tcontrol::mouse_hover(tevent_handler& event)
{
DBG_G_E << "Control: mouse hover.\n";
@@ -252,6 +277,15 @@
update_canvas();
}
+void tcontrol::set_visible(const bool visible)
+{
+ if(visible_ != visible) {
+ visible_ = visible;
+ set_block_easy_close(visible_ && does_block_easy_close());
+ set_dirty();
+ }
+}
+
void tcontrol::set_label(const t_string& label)
{
if(label == label_) {
Modified: trunk/src/gui/widgets/control.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.hpp (original)
+++ trunk/src/gui/widgets/control.hpp Fri Oct 31 19:45:33 2008
@@ -72,6 +72,31 @@
virtual unsigned get_state() const = 0;
public:
+
+ /***** ***** ***** ***** Easy close handling ***** ***** ***** *****/
+
+ /**
+ * Adds or removes a widget to/from the easy close block list.
+ *
+ * For adding to the block list an id is required, if not set it will
get
+ * one.
+ *
+ * @param block If true it's added to the blocklist,
removed
+ * otherwise.
+ */
+ void set_block_easy_close(const bool block = true);
+
+ /**
+ * Does the widget block the easy close feature?
+ *
+ * NOTE widgets that return true here, probably also need to make
+ * modifications to their set_state() function. Easy close blocking
_must_
+ * be disabled when the widget is disabled or not visible. (The tcontrol
+ * class handles the visibility part.)
+ *
+ * @returns Whether or not it blocks.
+ */
+ virtual bool does_block_easy_close() const = 0;
/***** ***** ***** ***** Inherited ***** ***** ***** *****/
@@ -164,8 +189,7 @@
/***** ***** ***** setters / getters for members ***** ****** *****/
bool get_visible() const { return visible_; }
- void set_visible(const bool visible = true)
- { if(visible_ != visible) { visible_ = visible; set_dirty();} }
+ void set_visible(const bool visible = true);
bool get_use_tooltip_on_label_overflow() const { return
use_tooltip_on_label_overflow_; }
void set_use_tooltip_on_label_overflow(const bool use_tooltip = true)
Modified: trunk/src/gui/widgets/grid.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/grid.cpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/grid.cpp (original)
+++ trunk/src/gui/widgets/grid.cpp Fri Oct 31 19:45:33 2008
@@ -91,6 +91,16 @@
// make sure the new child is valid before deferring
cell.set_id(cell.widget()->id());
cell.widget()->set_parent(this);
+
+ // Init the easy close state here, normally when put in a grid
the grid
+ // does have a parent window.
+ tcontrol* control = dynamic_cast<tcontrol*>(cell.widget());
+ if(control) {
+ control->set_block_easy_close(
+ control->get_visible()
+ && control->get_active()
+ && control->does_block_easy_close());
+ }
} else {
cell.set_id("");
}
Modified: trunk/src/gui/widgets/image.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/image.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/image.hpp (original)
+++ trunk/src/gui/widgets/image.hpp Fri Oct 31 19:45:33 2008
@@ -50,6 +50,9 @@
/** Inherited from tcontrol. */
unsigned get_state() const { return ENABLED; }
+ /** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return false; }
+
private:
/**
Modified: trunk/src/gui/widgets/label.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/label.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/label.hpp (original)
+++ trunk/src/gui/widgets/label.hpp Fri Oct 31 19:45:33 2008
@@ -44,6 +44,9 @@
/** Inherited from tcontrol. */
unsigned get_state() const { return state_; }
+ /** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return false; }
+
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_can_wrap(const bool wrap) { can_wrap_ = wrap; }
Modified: trunk/src/gui/widgets/minimap.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/minimap.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/minimap.hpp (original)
+++ trunk/src/gui/widgets/minimap.hpp Fri Oct 31 19:45:33 2008
@@ -51,6 +51,9 @@
/** Inherited from tcontrol. */
unsigned get_state() const { return 0; }
+
+ /** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return false; }
/** Inherited from tcontrol. */
void draw(surface& surface, const bool force = false,
Modified: trunk/src/gui/widgets/scrollbar.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/scrollbar.cpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/scrollbar.cpp (original)
+++ trunk/src/gui/widgets/scrollbar.cpp Fri Oct 31 19:45:33 2008
@@ -199,6 +199,7 @@
{
if(state != state_) {
state_ = state;
+ set_block_easy_close(get_visible() && get_active());
set_dirty(true);
}
}
Modified: trunk/src/gui/widgets/scrollbar.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/scrollbar.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/scrollbar.hpp (original)
+++ trunk/src/gui/widgets/scrollbar.hpp Fri Oct 31 19:45:33 2008
@@ -122,6 +122,9 @@
unsigned get_state() const { return state_; }
/** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return true; }
+
+ /** Inherited from tcontrol. */
void set_size(const SDL_Rect& rect);
/***** ***** ***** setters / getters for members ***** ****** *****/
Modified: trunk/src/gui/widgets/spacer.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/spacer.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/spacer.hpp (original)
+++ trunk/src/gui/widgets/spacer.hpp Fri Oct 31 19:45:33 2008
@@ -47,6 +47,9 @@
unsigned get_state() const { return 0; }
/** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return false; }
+
+ /** Inherited from tcontrol. */
tpoint get_best_size() const
{ return best_size_ != tpoint(0, 0) ? best_size_ :
tcontrol::get_best_size(); }
Modified: trunk/src/gui/widgets/text.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/text.cpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/text.cpp (original)
+++ trunk/src/gui/widgets/text.cpp Fri Oct 31 19:45:33 2008
@@ -311,6 +311,7 @@
{
if(state != state_) {
state_ = state;
+ set_block_easy_close(get_visible() && get_active());
set_dirty(true);
}
}
Modified: trunk/src/gui/widgets/text.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/text.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/text.hpp (original)
+++ trunk/src/gui/widgets/text.hpp Fri Oct 31 19:45:33 2008
@@ -68,6 +68,9 @@
/** Inherited from tcontrol. */
unsigned get_state() const { return state_; }
+
+ /** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return true; }
/***** ***** ***** ***** expose some functions ***** ***** ***** *****/
Modified: trunk/src/gui/widgets/toggle_button.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/toggle_button.cpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/toggle_button.cpp (original)
+++ trunk/src/gui/widgets/toggle_button.cpp Fri Oct 31 19:45:33 2008
@@ -141,6 +141,7 @@
{
if(state != state_) {
state_ = state;
+ set_block_easy_close(get_visible() && get_active());
set_dirty(true);
}
}
Modified: trunk/src/gui/widgets/toggle_button.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/toggle_button.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/toggle_button.hpp (original)
+++ trunk/src/gui/widgets/toggle_button.hpp Fri Oct 31 19:45:33 2008
@@ -68,6 +68,9 @@
/** Inherited from tcontrol. */
unsigned get_state() const { return state_; }
+
+ /** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return true; }
/** Inherited from tcontrol. */
void update_canvas();
Modified: trunk/src/gui/widgets/tooltip.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/tooltip.hpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/tooltip.hpp (original)
+++ trunk/src/gui/widgets/tooltip.hpp Fri Oct 31 19:45:33 2008
@@ -45,6 +45,9 @@
/** Inherited from tcontrol. */
unsigned get_state() const { return 0; }
+ /** Inherited from tcontrol. */
+ bool does_block_easy_close() const { return false; }
+
private:
/** Inherited from tcontrol. */
const std::string& get_control_type() const
Modified: trunk/src/gui/widgets/vertical_scrollbar_container.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/vertical_scrollbar_container.cpp?rev=30473&r1=30472&r2=30473&view=diff
==============================================================================
--- trunk/src/gui/widgets/vertical_scrollbar_container.cpp (original)
+++ trunk/src/gui/widgets/vertical_scrollbar_container.cpp Fri Oct 31 19:45:33
2008
@@ -433,6 +433,10 @@
find_scrollbar_grid();
content_find_grid();
+ // Set the easy close status.
+ /** @todo needs more testing. */
+ set_block_easy_close(get_visible() && get_active() &&
does_block_easy_close());
+
// Call the virtual function to subclasses can do their finalization
part.
finalize();
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits