Author: mordante
Date: Thu May 1 15:52:24 2008
New Revision: 26281
URL: http://svn.gna.org/viewcvs/wesnoth?rev=26281&view=rev
Log:
Add the settings section for the gui.
Modified:
trunk/data/gui/default.cfg
trunk/src/gui/widgets/control.cpp
trunk/src/gui/widgets/event_handler.cpp
trunk/src/gui/widgets/settings.cpp
trunk/src/gui/widgets/settings.hpp
trunk/src/gui/widgets/window.cpp
trunk/src/gui/widgets/window_builder.cpp
Modified: trunk/data/gui/default.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default.cfg?rev=26281&r1=26280&r2=26281&view=diff
==============================================================================
--- trunk/data/gui/default.cfg (original)
+++ trunk/data/gui/default.cfg Thu May 1 15:52:24 2008
@@ -6,6 +6,14 @@
[gui]
id = "default"
description = "Default"
+
+ [settings]
+ popup_show_delay = 1500
+ popup_show_time = 5000
+ help_show_time = 0
+
+ double_click_time = 500
+ [/settings]
{gui/default/macros.cfg}
{gui/default/window/}
Modified: trunk/src/gui/widgets/control.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.cpp?rev=26281&r1=26280&r2=26281&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.cpp (original)
+++ trunk/src/gui/widgets/control.cpp Thu May 1 15:52:24 2008
@@ -60,13 +60,13 @@
void tcontrol::mouse_hover(tevent_handler& event)
{
DBG_G_E << "Control: mouse hover.\n";
- event.show_tooltip(tooltip_, 5000); //FIXME timout should be a parameter
+ event.show_tooltip(tooltip_, settings::popup_show_time);
}
void tcontrol::help_key(tevent_handler& event)
{
DBG_G_E << "Control: help key.\n";
- event.show_help_popup(help_message_, 0); //FIXME timout should be a
parameter
+ event.show_help_popup(help_message_, settings::help_show_time);
}
void tcontrol::set_size(const SDL_Rect& rect)
Modified: trunk/src/gui/widgets/event_handler.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/event_handler.cpp?rev=26281&r1=26280&r2=26281&view=diff
==============================================================================
--- trunk/src/gui/widgets/event_handler.cpp (original)
+++ trunk/src/gui/widgets/event_handler.cpp Thu May 1 15:52:24 2008
@@ -443,7 +443,7 @@
{
if((widget->*button.wants_double_click)()) {
Uint32 stamp = SDL_GetTicks();
- if(button.last_click_stamp + 500 >= stamp) { // FIXME 500
should be variable
+ if(button.last_click_stamp + settings::double_click_time >=
stamp) {
(widget->*button.double_click)(*this);
button.last_click_stamp = 0;
@@ -497,8 +497,7 @@
*hover = hover_id;
hover_id_ = hover_id++;
- // Fixme delay show be a setting
- SDL_AddTimer(1500, hover_callback, hover);
+ SDL_AddTimer(settings::popup_show_delay, hover_callback, hover);
}
void tevent_handler::key_down(const SDL_Event& event)
Modified: trunk/src/gui/widgets/settings.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=26281&r1=26280&r2=26281&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Thu May 1 15:52:24 2008
@@ -57,8 +57,16 @@
namespace gui2 {
-unsigned screen_width = 0;
-unsigned screen_height = 0;
+namespace settings {
+ unsigned screen_width = 0;
+ unsigned screen_height = 0;
+
+ unsigned popup_show_delay = 0;
+ unsigned popup_show_time = 0;
+ unsigned help_show_time = 0;
+ unsigned double_click_time = 0;
+
+} // namespace settings
namespace {
@@ -92,12 +100,14 @@
{
LOG_G << "Setting: init gui.\n";
+ // Init.
fill_window_types();
const SDL_Rect rect = screen_area();
- screen_width = rect.w;
- screen_height = rect.h;
-
+ settings::screen_width = rect.w;
+ settings::screen_height = rect.h;
+
+ // Read file.
config cfg;
const std::string& filename = "data/gui/default.cfg";
try {
@@ -107,6 +117,7 @@
ERR_G_P << "Setting: could not read file '" << filename <<
"'.\n";
}
+ // Parse guis
const config::child_list& gui_cfgs = cfg.get_children("gui");
for(std::vector<config*>::const_iterator itor = gui_cfgs.begin();
itor != gui_cfgs.end(); ++itor) {
@@ -119,6 +130,7 @@
VALIDATE(guis.find("default") != guis.end(), _ ("No default gui
defined."));
current_gui = guis.find("default");
+ current_gui->second.activate();
}
const std::string& tgui_definition::read(const config& cfg)
@@ -156,6 +168,7 @@
* [[#widget_list|widgets]].
* window (section) The defintions of all
* [[#window_list|windows]].
+ * settings (section) The settings for the gui.
* @end_table
*
* <span id="widget_list"></span>List of available widgets:
@@ -213,11 +226,48 @@
}
}
+ /***** settings *****/
+/*WIKI
+ * @page = GUIToolkitWML
+ * @order = 1
+ *
+ * A setting section has the following variables:
+ * @start_table = config
+ * popup_show_delay (unsigned = 0) The time it take before the popup shows
+ * if the mouse moves over the widget. 0
+ * means show directly.
+ * popup_show_time (unsigned = 0) The time a shown popup remains visible.
+ * 0 means until the mouse leaves the
+ * widget.
+ * help_show_time (unsigned = 0) The time a shown help remains visible.
+ * 0 means until the mouse leaves the
+ * widget.
+ * double_click_time (unsigned) The time between two clicks to still be
a
+ * double click.
+ */
+ const config& settings = *cfg.child("settings");
+
+ popup_show_delay_ =
lexical_cast_default<unsigned>(settings["popup_show_delay"]);
+ popup_show_time_ =
lexical_cast_default<unsigned>(settings["popup_show_time"]);
+ help_show_time_ =
lexical_cast_default<unsigned>(settings["help_show_time"]);
+ double_click_time_ =
lexical_cast_default<unsigned>(settings["double_click_time"]);
+
+ VALIDATE(double_click_time_, missing_mandatory_wml_key("settings",
"double_click_time"));
+
return id;
}
+void tgui_definition::activate() const
+{
+ settings::popup_show_delay = popup_show_delay_;
+ settings::popup_show_time = popup_show_time_;
+ settings::help_show_time = help_show_time_;
+ settings::double_click_time = double_click_time_;
+}
+
template<class T>
-void tgui_definition::load_definitions(const std::string& definition_type,
const config::child_list& definition_list)
+void tgui_definition::load_definitions(
+ const std::string& definition_type, const config::child_list&
definition_list)
{
for(std::vector<config*>::const_iterator itor = definition_list.begin();
itor != definition_list.end(); ++itor) {
@@ -641,8 +691,8 @@
itor != end;
++itor) {
- if(screen_width <= (**itor).window_width &&
- screen_height <= (**itor).window_height) {
+ if(settings::screen_width <= (**itor).window_width &&
+ settings::screen_height <=
(**itor).window_height) {
return *itor;
} else if (itor == end - 1) {
@@ -670,8 +720,8 @@
itor != end;
++itor) {
- if(screen_width <= itor->window_width &&
- screen_height <= itor->window_height) {
+ if(settings::screen_width <= itor->window_width &&
+ settings::screen_height <= itor->window_height)
{
return itor;
} else if (itor == end - 1) {
Modified: trunk/src/gui/widgets/settings.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.hpp?rev=26281&r1=26280&r2=26281&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.hpp (original)
+++ trunk/src/gui/widgets/settings.hpp Thu May 1 15:52:24 2008
@@ -183,13 +183,27 @@
struct tgui_definition
{
+ tgui_definition() :
+ id(),
+ description(),
+ popup_show_delay_(0),
+ popup_show_time_(0),
+ help_show_time_(0),
+ double_click_time_(0)
+ {
+ }
+
std::string id;
t_string description;
const std::string& read(const config& cfg);
+ //! Activates a gui.
+ void activate() const;
- typedef std::map<std::string /*control type*/, std::map<std::string
/*id*/, tcontrol_definition*> > tcontrol_definition_map;
+ typedef std::map <std::string /*control type*/,
+ std::map<std::string /*id*/, tcontrol_definition*> >
+ tcontrol_definition_map;
tcontrol_definition_map control_definition;
@@ -198,20 +212,38 @@
std::map<std::string, twindow_builder> window_types;
private:
template<class T>
- void load_definitions(const std::string& definition_type, const
config::child_list& definition_list);
-};
-
- tresolution_definition_* get_control(const std::string& control_type,
const std::string& definition);
-
- std::vector<twindow_builder::tresolution>::const_iterator
get_window_builder(const std::string& type);
+ void load_definitions(const std::string& definition_type,
+ const config::child_list& definition_list);
+
+ unsigned popup_show_delay_;
+ unsigned popup_show_time_;
+ unsigned help_show_time_;
+ unsigned double_click_time_;
+};
+
+ tresolution_definition_* get_control(
+ const std::string& control_type, const std::string& definition);
+
+ std::vector<twindow_builder::tresolution>::const_iterator
+ get_window_builder(const std::string& type);
//! Loads the setting for the theme.
void load_settings();
- //! The screen resolution should be available for all widgets since
their
- //! drawing method will depend on it.
- extern unsigned screen_width;
- extern unsigned screen_height;
+
+ // This namespace contains the 'global' settings.
+ namespace settings {
+ //! The screen resolution should be available for all widgets
since their
+ //! drawing method will depend on it.
+ extern unsigned screen_width;
+ extern unsigned screen_height;
+
+ //! These are copied from the active gui.
+ extern unsigned popup_show_delay;
+ extern unsigned popup_show_time;
+ extern unsigned help_show_time;
+ extern unsigned double_click_time;
+ }
} // namespace gui2
Modified: trunk/src/gui/widgets/window.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window.cpp?rev=26281&r1=26280&r2=26281&view=diff
==============================================================================
--- trunk/src/gui/widgets/window.cpp (original)
+++ trunk/src/gui/widgets/window.cpp Thu May 1 15:52:24 2008
@@ -181,8 +181,8 @@
void twindow::window_resize(tevent_handler&,
const unsigned new_width, const unsigned new_height)
{
- screen_width = new_width;
- screen_height = new_height;
+ settings::screen_width = new_width;
+ settings::screen_height = new_height;
need_layout_ = true;
}
Modified: trunk/src/gui/widgets/window_builder.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=26281&r1=26280&r2=26281&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Thu May 1 15:52:24 2008
@@ -242,8 +242,8 @@
if(definition->automatic_placement) {
tpoint size = window.get_best_size();
- size.x = size.x < screen_width ? size.x : screen_width;
- size.y = size.y < screen_height ? size.y : screen_height;
+ size.x = size.x < settings::screen_width ? size.x :
settings::screen_width;
+ size.y = size.y < settings::screen_height ? size.y :
settings::screen_height;
tpoint position(0, 0);
switch(definition->horizontal_placement) {
@@ -251,10 +251,10 @@
// Do nothing
break;
case tgrid::HORIZONTAL_ALIGN_CENTER :
- position.x = (screen_width - size.x) / 2;
+ position.x = (settings::screen_width - size.x)
/ 2;
break;
case tgrid::HORIZONTAL_ALIGN_RIGHT :
- position.x = screen_width - size.x;
+ position.x = settings::screen_width - size.x;
break;
default :
assert(false);
@@ -264,10 +264,10 @@
// Do nothing
break;
case tgrid::VERTICAL_ALIGN_CENTER :
- position.y = (screen_height - size.y) / 2;
+ position.y = (settings::screen_height - size.y)
/ 2;
break;
case tgrid::VERTICAL_ALIGN_BOTTOM :
- position.y = screen_height - size.y;
+ position.y = settings::screen_height - size.y;
break;
default :
assert(false);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits