Author: mordante
Date: Fri Jul 18 18:43:49 2008
New Revision: 28070

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28070&view=rev
Log:
Allow the label of the slider to be customized so it can display special values
it needed.

Modified:
    trunk/data/gui/default/widget/slider_default.cfg
    trunk/src/gui/widgets/slider.cpp
    trunk/src/gui/widgets/slider.hpp
    trunk/src/gui/widgets/window_builder.cpp

Modified: trunk/data/gui/default/widget/slider_default.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/widget/slider_default.cfg?rev=28070&r1=28069&r2=28070&view=diff
==============================================================================
--- trunk/data/gui/default/widget/slider_default.cfg (original)
+++ trunk/data/gui/default/widget/slider_default.cfg Fri Jul 18 18:43:49 2008
@@ -14,7 +14,7 @@
                [line]
                        x1 = 0
                        y1 = "(height / 2)"
-                       x2 = "(width - 36)"
+                       x2 = "(width - 136)"
                        y2 = "(height / 2)"
 
                        colour = {GROOVE_COLOUR}
@@ -26,7 +26,7 @@
                #
 
                [text]
-                       x = "(width - 30)"
+                       x = "(width - 130)"
                        y = {TEXT_V_CENTRE}
                        w = 30
                        h = "(height)"
@@ -54,10 +54,10 @@
        description = "A slider with it's value on the right hand side."
 
        [resolution]
-               min_width = 50
+               min_width = 150
                min_height = 22
 
-               default_width = 150
+               default_width = 250
                default_height = 22
 
                max_width = 0
@@ -69,7 +69,7 @@
                maximum_positioner_length = 16
 
                left_offset = 0
-               right_offset = 35
+               right_offset = 135
 
                [state_enabled]
                        {STATE "" "255, 255, 255, 255" "255, 255, 255, 255"}

Modified: trunk/src/gui/widgets/slider.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/slider.cpp?rev=28070&r1=28069&r2=28070&view=diff
==============================================================================
--- trunk/src/gui/widgets/slider.cpp (original)
+++ trunk/src/gui/widgets/slider.cpp Fri Jul 18 18:43:49 2008
@@ -114,6 +114,22 @@
        }
 }
 
+t_string tslider::get_value_label() const
+{
+       if(!value_labels_.empty()) {
+               assert(value_labels_.size() == get_item_count());
+               return value_labels_[get_item_position()];
+       } else if(!minimum_value_label_.empty() 
+                       && get_value() == get_minimum_value()) {
+               return minimum_value_label_;
+       } else if(!maximum_value_label_.empty() 
+                       && get_value() == get_maximum_value()) {
+               return maximum_value_label_;
+       } else {
+               return t_string((formatter() << get_value()).str());
+       }
+}
+
 unsigned tslider::minimum_positioner_length() const
 { 
        const tslider_definition::tresolution* conf = 
@@ -180,7 +196,7 @@
        tscrollbar_::update_canvas();
 
        foreach(tcanvas& tmp, canvas()) {
-               tmp.set_variable("text", variant((formatter() << 
get_value()).str()));
+               tmp.set_variable("text", variant(get_value_label()));
        }
 }
 

Modified: trunk/src/gui/widgets/slider.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/slider.hpp?rev=28070&r1=28069&r2=28070&view=diff
==============================================================================
--- trunk/src/gui/widgets/slider.hpp (original)
+++ trunk/src/gui/widgets/slider.hpp Fri Jul 18 18:43:49 2008
@@ -52,6 +52,26 @@
                // The number of items needs to include the begin and end so 
count - 1.
                { return minimum_value_ + get_item_count() - 1; }
 
+       /***** ***** ***** setters / getters for members ***** ****** *****/
+
+       void set_minimum_value_label(const t_string& minimum_value_label)
+               { minimum_value_label_ = minimum_value_label; }
+
+       void set_maximum_value_label(const t_string& maximum_value_label)
+               { maximum_value_label_ = maximum_value_label; }
+
+       void set_value_labels(const std::vector<t_string>& value_labels)
+               { value_labels_ = value_labels; }
+
+       /**
+        * Returns the label shown for the current value. 
+        *
+        * @returns                   The label for the current value, if no 
label
+        *                            for the current label is defined, it 
returns
+        *                            the result of get_value().
+        */
+       t_string get_value_label() const;
+
 private:
 
        /**
@@ -90,6 +110,11 @@
        /** Inherited from tscrollbar. */
        void update_canvas();
 
+       t_string minimum_value_label_;
+       t_string maximum_value_label_;
+
+       std::vector<t_string> value_labels_;
+
        /** Inherited from tcontrol. */
        const std::string& get_control_type() const 
                { static const std::string type = "slider"; return type; }

Modified: trunk/src/gui/widgets/window_builder.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/window_builder.cpp?rev=28070&r1=28069&r2=28070&view=diff
==============================================================================
--- trunk/src/gui/widgets/window_builder.cpp (original)
+++ trunk/src/gui/widgets/window_builder.cpp Fri Jul 18 18:43:49 2008
@@ -161,26 +161,7 @@
 private:
        tbuilder_slider();
 public:
-/*WIKI
- * @page = GUIToolkitWML
- * @order = 3_widget_slider
- *
- * == Slider ==
- *
- * @start_table = config
- *     minimum_value (unsigned = 0)   The width of the slider.
- *     maximum_value (unsigned = 0)   The height of the slider.
- *     step_size (unsigned = 0)       The height of the slider.
- *     value (unsigned = 0)           The height of the slider.
- * @end_table
- */
-       tbuilder_slider(const config& cfg) :
-               tbuilder_control(cfg),
-               
minimum_value_(lexical_cast_default<unsigned>(cfg["minimum_value"])),
-               
maximum_value_(lexical_cast_default<unsigned>(cfg["maximum_value"])),
-               step_size_(lexical_cast_default<unsigned>(cfg["step_size"])),
-               value_(lexical_cast_default<unsigned>(cfg["value"]))
-       {}
+       tbuilder_slider(const config& cfg);
 
        twidget* build () const;
 
@@ -189,6 +170,11 @@
        int maximum_value_;
        int step_size_;
        int value_;
+
+       t_string minimum_value_label_;
+       t_string maximum_value_label_;
+
+       std::vector<t_string> value_labels_;
 };
 
 struct tbuilder_spacer : public tbuilder_control
@@ -1050,6 +1036,61 @@
        return panel;
 }
 
+tbuilder_slider::tbuilder_slider(const config& cfg) :
+       tbuilder_control(cfg),
+       minimum_value_(lexical_cast_default<unsigned>(cfg["minimum_value"])),
+       maximum_value_(lexical_cast_default<unsigned>(cfg["maximum_value"])),
+       step_size_(lexical_cast_default<unsigned>(cfg["step_size"])),
+       value_(lexical_cast_default<unsigned>(cfg["value"])),
+       minimum_value_label_(cfg["minimum_value_label"]),
+       maximum_value_label_(cfg["maximum_value_label"]),
+       value_labels_()
+{
+/*WIKI
+ * @page = GUIToolkitWML
+ * @order = 3_widget_slider
+ *
+ * == Slider ==
+ *
+ * @start_table = config
+ *     minimum_value (unsigned = 0)   The width of the slider.
+ *     maximum_value (unsigned = 0)   The height of the slider.
+ *
+ *     step_size (unsigned = 0)       The height of the slider.
+ *     value (unsigned = 0)           The height of the slider.
+ *
+ *     minimum_value_label (t_string = "")
+ *                                    If the minimum value is choosen there
+ *                                    might be the need for a special value (eg
+ *                                    off). When this key has a value that 
value
+ *                                    will be shown if the minimum is selected.
+ *     maximum_value_label (t_string = "")
+ *                                    If the maximum value is choosen there
+ *                                    might be the need for a special value (eg
+ *                                    unlimited)). When this key has a value
+ *                                    that value will be shown if the maximum 
is
+ *                                    selected.
+ *     value_labels ([])              It might be the labels need to be shown
+ *                                    are not a lineair number sequence eg 
(0.5,
+ *                                    1, 2, 4) in that case for all items this
+ *                                    section can be filled with the values,
+ *                                    which should be the same number of items
+ *                                    as the items in the slider. NOTE if this
+ *                                    option is used, 'minimum_value_label' and
+ *                                    'maximum_value_label' are ignored.
+ * @end_table
+ */
+       const config* labels = cfg.child("value_labels");
+       if(labels) {
+
+               const config::child_list& value = labels->get_children("value");
+               foreach(const config* label, value) {
+
+                       value_labels_.push_back((*label)["label"]);
+               }
+       }
+}
+
 twidget* tbuilder_slider::build() const
 {
        tslider* slider = new tslider();
@@ -1060,6 +1101,17 @@
        slider->set_minimum_value(minimum_value_);
        slider->set_step_size(step_size_);
        slider->set_value(value_);
+
+       if(!value_labels_.empty()) {
+               VALIDATE(value_labels_.size() == slider->get_item_count(),
+                       _("The number of value_labels and values don't 
match."));
+
+               slider->set_value_labels(value_labels_);
+
+       } else {
+               slider->set_minimum_value_label(minimum_value_label_);
+               slider->set_maximum_value_label(maximum_value_label_);
+       }
 
        DBG_G << "Window builder: placed slider '" << id << "' with defintion 
'" 
                << definition << "'.\n";


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to