comparison ext/guichan-0.8.2/include/guichan/widgets/slider.hpp @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 /* _______ __ __ __ ______ __ __ _______ __ __
2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8 *
9 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
10 *
11 *
12 * Per Larsson a.k.a finalman
13 * Olof Naessén a.k.a jansem/yakslem
14 *
15 * Visit: http://guichan.sourceforge.net
16 *
17 * License: (BSD)
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 * 3. Neither the name of Guichan nor the names of its contributors may
28 * be used to endorse or promote products derived from this software
29 * without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
37 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 #ifndef GCN_SLIDER_HPP
45 #define GCN_SLIDER_HPP
46
47 #include "guichan/keylistener.hpp"
48 #include "guichan/mouselistener.hpp"
49 #include "guichan/platform.hpp"
50 #include "guichan/widget.hpp"
51
52 namespace gcn
53 {
54 /**
55 * An implementation of a slider where a user can select different values by
56 * sliding between a start value and an end value of a scale.
57 *
58 * If the selected value is changed an action event will be sent to all
59 * action listeners of the slider.
60 */
61 class GCN_CORE_DECLSPEC Slider :
62 public Widget,
63 public MouseListener,
64 public KeyListener
65 {
66 public:
67
68 /**
69 * Draw orientations for the slider. A slider can be drawn vertically or
70 * horizontally.
71 */
72 enum Orientation
73 {
74 HORIZONTAL = 0,
75 VERTICAL
76 };
77
78 /**
79 * Constructor. The default start value of the slider scale is zero.
80 *
81 * @param scaleEnd The end value of the slider scale.
82 */
83 Slider(double scaleEnd = 1.0);
84
85 /**
86 * Constructor.
87 *
88 * @param scaleStart The start value of the slider scale.
89 * @param scaleEnd The end value of the slider scale.
90 */
91 Slider(double scaleStart, double scaleEnd);
92
93 /**
94 * Destructor.
95 */
96 virtual ~Slider() { }
97
98 /**
99 * Sets the scale of the slider.
100 *
101 * @param scaleStart The start value of the scale.
102 * @param scaleEnd tThe end of value the scale.
103 * @see getScaleStart, getScaleEnd
104 */
105 void setScale(double scaleStart, double scaleEnd);
106
107 /**
108 * Gets the start value of the scale.
109 *
110 * @return The start value of the scale.
111 * @see setScaleStart, setScale
112 */
113 double getScaleStart() const;
114
115 /**
116 * Sets the start value of the scale.
117 *
118 * @param scaleStart The start value of the scale.
119 * @see getScaleStart
120 */
121 void setScaleStart(double scaleStart);
122
123 /**
124 * Gets the end value of the scale.
125 *
126 * @return The end value of the scale.
127 * @see setScaleEnd, setScale
128 */
129 double getScaleEnd() const;
130
131 /**
132 * Sets the end value of the scale.
133 *
134 * @param scaleEnd The end value of the scale.
135 * @see getScaleEnd
136 */
137 void setScaleEnd(double scaleEnd);
138
139 /**
140 * Gets the current selected value.
141 *
142 * @return The current selected value.
143 * @see setValue
144 */
145 double getValue() const;
146
147 /**
148 * Sets the current selected value.
149 *
150 * @param value The current selected value.
151 * @see getValue
152 */
153 void setValue(double value);
154
155 /**
156 * Sets the length of the marker.
157 *
158 * @param length The length for the marker.
159 * @see getMarkerLength
160 */
161 void setMarkerLength(int length);
162
163 /**
164 * Gets the length of the marker.
165 *
166 * @return The length of the marker.
167 * @see setMarkerLength
168 */
169 int getMarkerLength() const;
170
171 /**
172 * Sets the orientation of the slider. A slider can be drawn vertically
173 * or horizontally.
174 *
175 * @param orientation The orientation of the slider.
176 * @see getOrientation
177 */
178 void setOrientation(Orientation orientation);
179
180 /**
181 * Gets the orientation of the slider. A slider can be drawn vertically
182 * or horizontally.
183 *
184 * @return The orientation of the slider.
185 * @see setOrientation
186 */
187 Orientation getOrientation() const;
188
189 /**
190 * Sets the step length. The step length is used when the keys LEFT
191 * and RIGHT are pressed to step in the scale.
192 *
193 * @param length The step length.
194 * @see getStepLength
195 */
196 void setStepLength(double length);
197
198 /**
199 * Gets the step length. The step length is used when the keys LEFT
200 * and RIGHT are pressed to step in the scale.
201 *
202 * @return the step length.
203 * @see setStepLength
204 */
205 double getStepLength() const;
206
207
208 // Inherited from Widget
209
210 virtual void draw(Graphics* graphics);
211
212
213 // Inherited from MouseListener.
214
215 virtual void mousePressed(MouseEvent& mouseEvent);
216
217 virtual void mouseDragged(MouseEvent& mouseEvent);
218
219 virtual void mouseWheelMovedUp(MouseEvent& mouseEvent);
220
221 virtual void mouseWheelMovedDown(MouseEvent& mouseEvent);
222
223
224 // Inherited from KeyListener
225
226 virtual void keyPressed(KeyEvent& keyEvent);
227
228 protected:
229 /**
230 * Draws the marker.
231 *
232 * @param graphics A graphics object to draw with.
233 */
234 virtual void drawMarker(gcn::Graphics* graphics);
235
236 /**
237 * Converts a marker position to a value in the scale.
238 *
239 * @param position The position to convert.
240 * @return A scale value corresponding to the position.
241 * @see valueToMarkerPosition
242 */
243 virtual double markerPositionToValue(int position) const;
244
245 /**
246 * Converts a value to a marker position.
247 *
248 * @param value The value to convert.
249 * @return A marker position corresponding to the value.
250 * @see markerPositionToValue
251 */
252 virtual int valueToMarkerPosition(double value) const;
253
254 /**
255 * Gets the marker position of the current selected value.
256 *
257 * @return The marker position of the current selected value.
258 */
259 virtual int getMarkerPosition() const;
260
261 /**
262 * True if the slider is dragged, false otherwise.
263 */
264 bool mDragged;
265
266 /**
267 * Holds the current selected value.
268 */
269 double mValue;
270
271 /**
272 * Holds the step length. The step length is used when the keys LEFT
273 * and RIGHT are pressed to step in the scale.
274 */
275 double mStepLength;
276
277 /**
278 * Holds the length of the marker.
279 */
280 int mMarkerLength;
281
282 /**
283 * Holds the start value of the scale.
284 */
285 double mScaleStart;
286
287 /**
288 * Holds the end value of the scale.
289 */
290 double mScaleEnd;
291
292 /**
293 * Holds the orientation of the slider. A slider can be drawn
294 * vertically or horizontally.
295 */
296 Orientation mOrientation;
297 };
298 }
299
300 #endif // end GCN_SLIDER_HPP