Author: mordante
Date: Thu May 17 18:22:00 2012
New Revision: 54187
URL: http://svn.gna.org/viewcvs/wesnoth?rev=54187&view=rev
Log:
Add a second constructor to tcontrol.
This constructor sets its state based on the structure send to it
instead of using a second call that sets the fields later.
The code is used to experiment with a different approach of the
implementation of a listbox.
Modified:
trunk/src/gui/auxiliary/window_builder/control.hpp
trunk/src/gui/widgets/control.cpp
trunk/src/gui/widgets/control.hpp
Modified: trunk/src/gui/auxiliary/window_builder/control.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/auxiliary/window_builder/control.hpp?rev=54187&r1=54186&r2=54187&view=diff
==============================================================================
--- trunk/src/gui/auxiliary/window_builder/control.hpp (original)
+++ trunk/src/gui/auxiliary/window_builder/control.hpp Thu May 17 18:22:00 2012
@@ -31,6 +31,7 @@
tbuilder_control(const config& cfg);
+ /** @deprecated The control can initalise itself. */
void init_control(tcontrol* control) const;
/** Parameters for the control. */
Modified: trunk/src/gui/widgets/control.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.cpp?rev=54187&r1=54186&r2=54187&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.cpp (original)
+++ trunk/src/gui/widgets/control.cpp Thu May 17 18:22:00 2012
@@ -26,6 +26,7 @@
#include "gui/dialogs/tip.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
+#include "gui/auxiliary/window_builder/control.hpp"
#include "marked-up_text.hpp"
#include <boost/bind.hpp>
@@ -73,6 +74,52 @@
, _3));
}
+tcontrol::tcontrol(
+ const implementation::tbuilder_control& builder
+ , const unsigned canvas_count)
+ : definition_(builder.definition)
+ , label_(builder.label)
+ , use_markup_(false)
+ , use_tooltip_on_label_overflow_(builder.use_tooltip_on_label_overflow)
+ , tooltip_(builder.tooltip)
+ , help_message_(builder.help)
+ , canvas_(canvas_count)
+ , config_(NULL)
+ , renderer_()
+ , text_maximum_width_(0)
+ , text_alignment_(PANGO_ALIGN_LEFT)
+ , shrunken_(false)
+{
+ set_id(builder.id);
+ set_linked_group(builder.linked_group);
+#ifndef LOW_MEM
+ set_debug_border_mode(builder.debug_border_mode);
+ set_debug_border_color(builder.debug_border_color);
+#endif
+
+ definition_load_configuration();
+
+ connect_signal<event::SHOW_TOOLTIP>(boost::bind(
+ &tcontrol::signal_handler_show_tooltip
+ , this
+ , _2
+ , _3
+ , _5));
+
+ connect_signal<event::SHOW_HELPTIP>(boost::bind(
+ &tcontrol::signal_handler_show_helptip
+ , this
+ , _2
+ , _3
+ , _5));
+
+ connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(boost::bind(
+ &tcontrol::signal_handler_notify_remove_tooltip
+ , this
+ , _2
+ , _3));
+}
+
void tcontrol::set_members(const string_map& data)
{
/** @todo document this feature on the wiki. */
@@ -240,14 +287,8 @@
void tcontrol::load_config()
{
if(!config()) {
- set_config(get_control(get_control_type(), definition_));
-
- assert(canvas().size() == config()->state.size());
- for(size_t i = 0; i < canvas().size(); ++i) {
- canvas(i) = config()->state[i].canvas;
- }
-
- update_canvas();
+
+ definition_load_configuration();
load_config_extra();
}
@@ -361,6 +402,20 @@
, calculate_blitting_rectangle(x_offset, y_offset));
}
+void tcontrol::definition_load_configuration()
+{
+ assert(!config());
+
+ set_config(get_control(get_control_type(), definition_));
+
+ assert(canvas().size() == config()->state.size());
+ for(size_t i = 0; i < canvas().size(); ++i) {
+ canvas(i) = config()->state[i].canvas;
+ }
+
+ update_canvas();
+}
+
tpoint tcontrol::get_best_text_size(
const tpoint& minimum_size
, const tpoint& maximum_size) const
Modified: trunk/src/gui/widgets/control.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/control.hpp?rev=54187&r1=54186&r2=54187&view=diff
==============================================================================
--- trunk/src/gui/widgets/control.hpp (original)
+++ trunk/src/gui/widgets/control.hpp Thu May 17 18:22:00 2012
@@ -22,13 +22,30 @@
namespace gui2 {
+namespace implementation {
+ class tbuilder_control;
+} // namespace implementation
+
/** Base class for all visible items. */
class tcontrol : public virtual twidget
{
friend class tdebug_layout_graph;
public:
+ /** @deprecated Used the second overload. */
explicit tcontrol(const unsigned canvas_count);
+
+ /**
+ * Constructor.
+ *
+ * @param builder The builder object with the settings for
the
+ * object.
+ *
+ * @param canvas_count The number of canvasses in the control.
+ */
+ tcontrol(
+ const implementation::tbuilder_control& builder
+ , const unsigned canvas_count);
/**
* Sets the members of the control.
@@ -148,6 +165,8 @@
* determine sizes and drawing the widget this definition needs to be
* loaded. The member definition_ contains the name of the definition
and
* function load the proper configuration.
+ *
+ * @depreciated @ref definition_load_configuration() is the replacement.
*/
void load_config();
@@ -332,6 +351,17 @@
* does nothing but classes can override it to implement custom
behaviour.
*/
virtual void load_config_extra() {}
+
+ /**
+ * Loads the configuration of the widget.
+ *
+ * Controls have their definition stored in a definition object. In
order to
+ * determine sizes and drawing the widget this definition needs to be
+ * loaded. The member definition_ contains the name of the definition
and
+ * function load the proper configuration.
+ */
+ void definition_load_configuration();
+
public:
/**
* Returns the control_type of the control.
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits