1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2004-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
/* _______ __ __ __ ______ __ __ _______ __ __ |
25 |
|
|
* / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ |
26 |
|
|
* / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / |
27 |
|
|
* / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / |
28 |
|
|
* / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / |
29 |
|
|
* /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / |
30 |
|
|
* \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ |
31 |
|
|
* |
32 |
|
|
* Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson |
33 |
|
|
* |
34 |
|
|
* |
35 |
|
|
* Per Larsson a.k.a finalman |
36 |
|
|
* Olof Naessén a.k.a jansem/yakslem |
37 |
|
|
* |
38 |
|
|
* Visit: http://guichan.sourceforge.net |
39 |
|
|
* |
40 |
|
|
* License: (BSD) |
41 |
|
|
* Redistribution and use in source and binary forms, with or without |
42 |
|
|
* modification, are permitted provided that the following conditions |
43 |
|
|
* are met: |
44 |
|
|
* 1. Redistributions of source code must retain the above copyright |
45 |
|
|
* notice, this list of conditions and the following disclaimer. |
46 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
47 |
|
|
* notice, this list of conditions and the following disclaimer in |
48 |
|
|
* the documentation and/or other materials provided with the |
49 |
|
|
* distribution. |
50 |
|
|
* 3. Neither the name of Guichan nor the names of its contributors may |
51 |
|
|
* be used to endorse or promote products derived from this software |
52 |
|
|
* without specific prior written permission. |
53 |
|
|
* |
54 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
55 |
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
56 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
57 |
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
58 |
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
59 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
60 |
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
61 |
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
62 |
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
63 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
64 |
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
65 |
|
|
*/ |
66 |
|
|
|
67 |
|
|
#ifndef GUI_WIDGETS_SLIDER_H |
68 |
|
|
#define GUI_WIDGETS_SLIDER_H |
69 |
|
|
|
70 |
|
|
#include "enums/gui/orientation.h" |
71 |
|
|
|
72 |
|
|
#include "listeners/keylistener.h" |
73 |
|
|
#include "listeners/mouselistener.h" |
74 |
|
|
|
75 |
|
|
#include "gui/widgets/widget.h" |
76 |
|
|
|
77 |
|
|
#include "localconsts.h" |
78 |
|
|
|
79 |
|
|
class ImageCollection; |
80 |
|
|
|
81 |
|
|
/** |
82 |
|
|
* Slider widget. Same as the Guichan slider but with custom look. |
83 |
|
|
* |
84 |
|
|
* \ingroup GUI |
85 |
|
|
*/ |
86 |
|
|
class Slider final : public Widget, |
87 |
|
|
public MouseListener, |
88 |
|
|
public KeyListener |
89 |
|
|
{ |
90 |
|
|
public: |
91 |
|
|
/** |
92 |
|
|
* Constructor with scale start equal to 0. |
93 |
|
|
*/ |
94 |
|
|
Slider(Widget2 *const widget, |
95 |
|
|
const double scaleEnd, |
96 |
|
|
const double stepLength); |
97 |
|
|
|
98 |
|
|
/** |
99 |
|
|
* Constructor. |
100 |
|
|
*/ |
101 |
|
|
Slider(Widget2 *const widget, |
102 |
|
|
const double scaleStart, |
103 |
|
|
const double scaleEnd, |
104 |
|
|
const double stepLength); |
105 |
|
|
|
106 |
|
|
A_DELETE_COPY(Slider) |
107 |
|
|
|
108 |
|
|
/** |
109 |
|
|
* Destructor. |
110 |
|
|
*/ |
111 |
|
|
~Slider() override final; |
112 |
|
|
|
113 |
|
|
/** |
114 |
|
|
* Update the alpha value to the graphic components. |
115 |
|
|
*/ |
116 |
|
|
void updateAlpha(); |
117 |
|
|
|
118 |
|
|
/** |
119 |
|
|
* Draws the slider. |
120 |
|
|
*/ |
121 |
|
|
void draw(Graphics *const graphics) override final A_NONNULL(2); |
122 |
|
|
|
123 |
|
|
void safeDraw(Graphics *const graphics) override final A_NONNULL(2); |
124 |
|
|
|
125 |
|
|
/** |
126 |
|
|
* Called when the mouse enteres the widget area. |
127 |
|
|
*/ |
128 |
|
|
void mouseEntered(MouseEvent& event) override final; |
129 |
|
|
|
130 |
|
|
/** |
131 |
|
|
* Called when the mouse leaves the widget area. |
132 |
|
|
*/ |
133 |
|
|
void mouseExited(MouseEvent& event) override final; |
134 |
|
|
|
135 |
|
|
void mousePressed(MouseEvent &event) override final; |
136 |
|
|
|
137 |
|
|
void mouseDragged(MouseEvent &event) override final; |
138 |
|
|
|
139 |
|
|
void mouseWheelMovedUp(MouseEvent &event) override final; |
140 |
|
|
|
141 |
|
|
void mouseWheelMovedDown(MouseEvent &event) override final; |
142 |
|
|
|
143 |
|
|
void keyPressed(KeyEvent& event) override final; |
144 |
|
|
|
145 |
|
|
/** |
146 |
|
|
* Sets the scale of the slider. |
147 |
|
|
* |
148 |
|
|
* @param scaleStart The start value of the scale. |
149 |
|
|
* @param scaleEnd tThe end of value the scale. |
150 |
|
|
* @see getScaleStart, getScaleEnd |
151 |
|
|
*/ |
152 |
|
|
void setScale(const double scaleStart, const double scaleEnd); |
153 |
|
|
|
154 |
|
|
/** |
155 |
|
|
* Gets the start value of the scale. |
156 |
|
|
* |
157 |
|
|
* @return The start value of the scale. |
158 |
|
|
* @see setScaleStart, setScale |
159 |
|
|
*/ |
160 |
|
|
double getScaleStart() const |
161 |
|
|
{ return mScaleStart; } |
162 |
|
|
|
163 |
|
|
/** |
164 |
|
|
* Sets the start value of the scale. |
165 |
|
|
* |
166 |
|
|
* @param scaleStart The start value of the scale. |
167 |
|
|
* @see getScaleStart |
168 |
|
|
*/ |
169 |
|
|
void setScaleStart(const double scaleStart) |
170 |
|
|
{ mScaleStart = scaleStart; } |
171 |
|
|
|
172 |
|
|
/** |
173 |
|
|
* Gets the end value of the scale. |
174 |
|
|
* |
175 |
|
|
* @return The end value of the scale. |
176 |
|
|
* @see setScaleEnd, setScale |
177 |
|
|
*/ |
178 |
|
|
double getScaleEnd() const |
179 |
|
|
{ return mScaleEnd; } |
180 |
|
|
|
181 |
|
|
/** |
182 |
|
|
* Sets the end value of the scale. |
183 |
|
|
* |
184 |
|
|
* @param scaleEnd The end value of the scale. |
185 |
|
|
* @see getScaleEnd |
186 |
|
|
*/ |
187 |
|
|
void setScaleEnd(const double scaleEnd) |
188 |
|
|
{ mScaleEnd = scaleEnd; } |
189 |
|
|
|
190 |
|
|
/** |
191 |
|
|
* Sets the current selected value. |
192 |
|
|
* |
193 |
|
|
* @param value The current selected value. |
194 |
|
|
* @see getValue |
195 |
|
|
*/ |
196 |
|
|
void setValue(const double value); |
197 |
|
|
|
198 |
|
|
/** |
199 |
|
|
* Gets the current selected value. |
200 |
|
|
* |
201 |
|
|
* @return The current selected value. |
202 |
|
|
* @see setValue |
203 |
|
|
*/ |
204 |
|
|
double getValue() const |
205 |
|
|
{ return mValue; } |
206 |
|
|
|
207 |
|
|
/** |
208 |
|
|
* Gets the length of the marker. |
209 |
|
|
* |
210 |
|
|
* @return The length of the marker. |
211 |
|
|
* @see setMarkerLength |
212 |
|
|
*/ |
213 |
|
|
int getMarkerLength() const |
214 |
|
|
{ return mMarkerLength; } |
215 |
|
|
|
216 |
|
|
/** |
217 |
|
|
* Sets the length of the marker. |
218 |
|
|
* |
219 |
|
|
* @param length The length for the marker. |
220 |
|
|
* @see getMarkerLength |
221 |
|
|
*/ |
222 |
|
|
void setMarkerLength(const int length) |
223 |
|
33 |
{ mMarkerLength = length; } |
224 |
|
|
|
225 |
|
|
/** |
226 |
|
|
* Sets the orientation of the slider. A slider can be drawn vertically |
227 |
|
|
* or horizontally. |
228 |
|
|
* |
229 |
|
|
* @param orientation The orientation of the slider. |
230 |
|
|
* @see getOrientation |
231 |
|
|
*/ |
232 |
|
|
void setOrientation(const OrientationT orientation) |
233 |
|
|
{ mOrientation = orientation; } |
234 |
|
|
|
235 |
|
|
/** |
236 |
|
|
* Gets the orientation of the slider. A slider can be drawn vertically |
237 |
|
|
* or horizontally. |
238 |
|
|
* |
239 |
|
|
* @return The orientation of the slider. |
240 |
|
|
* @see setOrientation |
241 |
|
|
*/ |
242 |
|
|
OrientationT getOrientation() const |
243 |
|
|
{ return mOrientation; } |
244 |
|
|
|
245 |
|
|
/** |
246 |
|
|
* Sets the step length. The step length is used when the keys LEFT |
247 |
|
|
* and RIGHT are pressed to step in the scale. |
248 |
|
|
* |
249 |
|
|
* @param length The step length. |
250 |
|
|
* @see getStepLength |
251 |
|
|
*/ |
252 |
|
|
void setStepLength(const double length) |
253 |
|
|
{ mStepLength = length; } |
254 |
|
|
|
255 |
|
|
/** |
256 |
|
|
* Gets the step length. The step length is used when the keys LEFT |
257 |
|
|
* and RIGHT are pressed to step in the scale. |
258 |
|
|
* |
259 |
|
|
* @return the step length. |
260 |
|
|
* @see setStepLength |
261 |
|
|
*/ |
262 |
|
|
double getStepLength() const |
263 |
|
|
{ return mStepLength; } |
264 |
|
|
|
265 |
|
|
private: |
266 |
|
|
/** |
267 |
|
|
* Used to initialize instances. |
268 |
|
|
*/ |
269 |
|
|
void init(); |
270 |
|
|
|
271 |
|
|
/** |
272 |
|
|
* Converts a marker position to a value in the scale. |
273 |
|
|
* |
274 |
|
|
* @param position The position to convert. |
275 |
|
|
* @return A scale value corresponding to the position. |
276 |
|
|
* @see valueToMarkerPosition |
277 |
|
|
*/ |
278 |
|
|
double markerPositionToValue(const int position) const; |
279 |
|
|
|
280 |
|
|
/** |
281 |
|
|
* Converts a value to a marker position. |
282 |
|
|
* |
283 |
|
|
* @param value The value to convert. |
284 |
|
|
* @return A marker position corresponding to the value. |
285 |
|
|
* @see markerPositionToValue |
286 |
|
|
*/ |
287 |
|
|
int valueToMarkerPosition(const double value) const; |
288 |
|
|
|
289 |
|
|
/** |
290 |
|
|
* Gets the marker position of the current selected value. |
291 |
|
|
* |
292 |
|
|
* @return The marker position of the current selected value. |
293 |
|
|
*/ |
294 |
|
|
int getMarkerPosition() const |
295 |
|
14 |
{ return valueToMarkerPosition(getValue()); } |
296 |
|
|
|
297 |
|
|
static ImageRect buttons[2]; |
298 |
|
|
static float mAlpha; |
299 |
|
|
static int mInstances; |
300 |
|
|
|
301 |
|
|
/** |
302 |
|
|
* Holds the current selected value. |
303 |
|
|
*/ |
304 |
|
|
double mValue; |
305 |
|
|
|
306 |
|
|
/** |
307 |
|
|
* Holds the step length. The step length is used when the keys LEFT |
308 |
|
|
* and RIGHT are pressed to step in the scale. |
309 |
|
|
*/ |
310 |
|
|
double mStepLength; |
311 |
|
|
|
312 |
|
|
/** |
313 |
|
|
* Holds the start value of the scale. |
314 |
|
|
*/ |
315 |
|
|
double mScaleStart; |
316 |
|
|
|
317 |
|
|
/** |
318 |
|
|
* Holds the end value of the scale. |
319 |
|
|
*/ |
320 |
|
|
double mScaleEnd; |
321 |
|
|
|
322 |
|
|
/** |
323 |
|
|
* Holds the orientation of the slider. A slider can be drawn |
324 |
|
|
* vertically or horizontally. |
325 |
|
|
*/ |
326 |
|
|
OrientationT mOrientation; |
327 |
|
|
|
328 |
|
|
ImageCollection *mVertexes A_NONNULLPOINTER; |
329 |
|
|
|
330 |
|
|
/** |
331 |
|
|
* Holds the length of the marker. |
332 |
|
|
*/ |
333 |
|
|
int mMarkerLength; |
334 |
|
|
|
335 |
|
|
bool mHasMouse; |
336 |
|
|
}; |
337 |
|
|
|
338 |
|
|
#endif // GUI_WIDGETS_SLIDER_H |