00001 /* $Id: slider.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #ifndef GUI_WIDGETS_SLIDER_HPP_INCLUDED 00017 #define GUI_WIDGETS_SLIDER_HPP_INCLUDED 00018 00019 #include "gui/widgets/integer_selector.hpp" 00020 #include "gui/widgets/scrollbar.hpp" 00021 00022 namespace gui2 { 00023 00024 /** A slider. */ 00025 class tslider : public tscrollbar_, public tinteger_selector_ 00026 { 00027 public: 00028 00029 tslider(); 00030 00031 /***** ***** ***** ***** layout functions ***** ***** ***** *****/ 00032 00033 private: 00034 /** Inherited from tcontrol. */ 00035 tpoint calculate_best_size() const; 00036 public: 00037 00038 /***** ***** ***** ***** Inherited ***** ***** ***** *****/ 00039 00040 /** Inherited from tinteger_selector_. */ 00041 void set_value(const int value); 00042 00043 /** Inherited from tinteger_selector_. */ 00044 int get_value() const 00045 { return minimum_value_ + get_item_position() * get_step_size(); } 00046 00047 /** Inherited from tinteger_selector_. */ 00048 void set_minimum_value(const int minimum_value); 00049 00050 /** Inherited from tinteger_selector_. */ 00051 int get_minimum_value() const { return minimum_value_; } 00052 00053 /** Inherited from tinteger_selector_. */ 00054 void set_maximum_value(const int maximum_value); 00055 00056 /** Inherited from tinteger_selector_. */ 00057 int get_maximum_value() const 00058 // The number of items needs to include the begin and end so count - 1. 00059 { return minimum_value_ + get_item_count() - 1; } 00060 00061 /***** ***** ***** setters / getters for members ***** ****** *****/ 00062 00063 void set_best_slider_length(const unsigned length) 00064 { best_slider_length_ = length; set_dirty(); } 00065 00066 void set_minimum_value_label(const t_string& minimum_value_label) 00067 { minimum_value_label_ = minimum_value_label; } 00068 00069 void set_maximum_value_label(const t_string& maximum_value_label) 00070 { maximum_value_label_ = maximum_value_label; } 00071 00072 void set_value_labels(const std::vector<t_string>& value_labels) 00073 { value_labels_ = value_labels; } 00074 00075 /** 00076 * Returns the label shown for the current value. 00077 * 00078 * @returns The label for the current value, if no label 00079 * for the current label is defined, it returns 00080 * the result of get_value(). 00081 */ 00082 t_string get_value_label() const; 00083 00084 protected: 00085 00086 /** Inherited from tscrollbar. */ 00087 void child_callback_positioner_moved(); 00088 00089 private: 00090 00091 /** The best size for the slider part itself, if 0 ignored. */ 00092 unsigned best_slider_length_; 00093 00094 /** 00095 * The minimum value the slider holds. 00096 * 00097 * The maximum value is minimum + item_count_. 00098 * The current value is minimum + item_position_. 00099 */ 00100 int minimum_value_; 00101 00102 /** Inherited from tscrollbar. */ 00103 unsigned get_length() const { return get_width(); } 00104 00105 /** Inherited from tscrollbar. */ 00106 unsigned minimum_positioner_length() const; 00107 00108 /** Inherited from tscrollbar. */ 00109 unsigned maximum_positioner_length() const; 00110 00111 /** Inherited from tscrollbar. */ 00112 unsigned offset_before() const; 00113 00114 /** Inherited from tscrollbar. */ 00115 unsigned offset_after() const; 00116 00117 /** Inherited from tscrollbar. */ 00118 bool on_positioner(const tpoint& coordinate) const; 00119 00120 /** Inherited from tscrollbar. */ 00121 int on_bar(const tpoint& coordinate) const; 00122 00123 /** Inherited from tscrollbar. */ 00124 int get_length_difference(const tpoint& original, const tpoint& current) const 00125 { return current.x - original.x; } 00126 00127 /** Inherited from tscrollbar. */ 00128 void update_canvas(); 00129 00130 /** 00131 * When the slider shows the minimum value can show a special text. 00132 * If this text is not empty this text is shown else the minimum value. 00133 */ 00134 t_string minimum_value_label_; 00135 00136 /** 00137 * When the slider shows the maximum value can show a special text. 00138 * If this text is not empty this text is shown else the maximum value. 00139 */ 00140 t_string maximum_value_label_; 00141 00142 /** 00143 * This allows the slider to show custom texts instead of the values. 00144 * This vector should have the same amount of items as options for the 00145 * sliders. When set these texts are shown instead of the values. It also 00146 * overrides minimum_value_label_ and maximum_value_label_. 00147 */ 00148 std::vector<t_string> value_labels_; 00149 00150 /** Inherited from tcontrol. */ 00151 const std::string& get_control_type() const; 00152 00153 /** 00154 * Handlers for keyboard input 00155 */ 00156 void handle_key_decrease(bool& handled); 00157 void handle_key_increase(bool& handled); 00158 00159 /** 00160 * Signal handlers: 00161 */ 00162 void signal_handler_sdl_key_down(const event::tevent event 00163 , bool& handled 00164 , const SDLKey key); 00165 00166 // In this subclass, only used to grab keyboard focus - 00167 // see tscrollbar class for more handling of this event. 00168 void signal_handler_left_button_up( 00169 const event::tevent event, bool& handled); 00170 }; 00171 00172 } // namespace gui2 00173 00174 #endif 00175
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:56 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |