ManaPlus
slider.h
Go to the documentation of this file.
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"
74 
75 #include "gui/widgets/widget.h"
76 
77 #include "localconsts.h"
78 
79 class ImageCollection;
80 
86 class Slider final : public Widget,
87  public MouseListener,
88  public KeyListener
89 {
90  public:
94  Slider(Widget2 *const widget,
95  const double scaleEnd,
96  const double stepLength);
97 
101  Slider(Widget2 *const widget,
102  const double scaleStart,
103  const double scaleEnd,
104  const double stepLength);
105 
107 
108 
111  ~Slider() override final;
112 
116  void updateAlpha();
117 
121  void draw(Graphics *const graphics) override final A_NONNULL(2);
122 
123  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
124 
128  void mouseEntered(MouseEvent& event) override final;
129 
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 
152  void setScale(const double scaleStart, const double scaleEnd);
153 
160  double getScaleStart() const
161  { return mScaleStart; }
162 
169  void setScaleStart(const double scaleStart)
170  { mScaleStart = scaleStart; }
171 
178  double getScaleEnd() const
179  { return mScaleEnd; }
180 
187  void setScaleEnd(const double scaleEnd)
188  { mScaleEnd = scaleEnd; }
189 
196  void setValue(const double value);
197 
204  double getValue() const
205  { return mValue; }
206 
213  int getMarkerLength() const
214  { return mMarkerLength; }
215 
222  void setMarkerLength(const int length)
223  { mMarkerLength = length; }
224 
232  void setOrientation(const OrientationT orientation)
233  { mOrientation = orientation; }
234 
243  { return mOrientation; }
244 
252  void setStepLength(const double length)
253  { mStepLength = length; }
254 
262  double getStepLength() const
263  { return mStepLength; }
264 
265  private:
269  void init();
270 
278  double markerPositionToValue(const int position) const;
279 
287  int valueToMarkerPosition(const double value) const;
288 
294  int getMarkerPosition() const
295  { return valueToMarkerPosition(getValue()); }
296 
297  static ImageRect buttons[2];
298  static float mAlpha;
299  static int mInstances;
300 
304  double mValue;
305 
310  double mStepLength;
311 
315  double mScaleStart;
316 
320  double mScaleEnd;
321 
327 
329 
334 
335  bool mHasMouse;
336 };
337 
338 #endif // GUI_WIDGETS_SLIDER_H
Definition: slider.h:89
double markerPositionToValue(const int position) const
Definition: slider.cpp:487
int getMarkerPosition() const
Definition: slider.h:294
double mScaleEnd
Definition: slider.h:320
void setOrientation(const OrientationT orientation)
Definition: slider.h:232
double getValue() const
Definition: slider.h:204
void setStepLength(const double length)
Definition: slider.h:252
void setScale(const double scaleStart, const double scaleEnd)
Definition: slider.cpp:468
OrientationT mOrientation
Definition: slider.h:326
static ImageRect buttons[2]
Definition: slider.h:297
void mouseExited(MouseEvent &event)
Definition: slider.cpp:376
void init()
Definition: slider.cpp:148
void draw(Graphics *const graphics)
Definition: slider.cpp:195
double mStepLength
Definition: slider.h:310
void safeDraw(Graphics *const graphics)
Definition: slider.cpp:296
void setScaleStart(const double scaleStart)
Definition: slider.h:169
double getStepLength() const
Definition: slider.h:262
void setScaleEnd(const double scaleEnd)
Definition: slider.h:187
void setValue(const double value)
Definition: slider.cpp:474
ImageCollection * mVertexes
Definition: slider.h:328
void mouseEntered(MouseEvent &event)
Definition: slider.cpp:370
void setMarkerLength(const int length)
Definition: slider.h:222
static int mInstances
Definition: slider.h:299
void updateAlpha()
Definition: slider.cpp:176
OrientationT getOrientation() const
Definition: slider.h:242
static float mAlpha
Definition: slider.h:298
void mouseWheelMovedUp(MouseEvent &event)
Definition: slider.cpp:418
~Slider()
Definition: slider.cpp:134
bool mHasMouse
Definition: slider.h:335
void keyPressed(KeyEvent &event)
Definition: slider.cpp:432
void mouseDragged(MouseEvent &event)
Definition: slider.cpp:401
double getScaleStart() const
Definition: slider.h:160
double mScaleStart
Definition: slider.h:315
Slider(Widget2 *const widget, const double scaleEnd, const double stepLength)
Definition: slider.cpp:97
double getScaleEnd() const
Definition: slider.h:178
double mValue
Definition: slider.h:304
int getMarkerLength() const
Definition: slider.h:213
void mousePressed(MouseEvent &event)
Definition: slider.cpp:382
void mouseWheelMovedDown(MouseEvent &event)
Definition: slider.cpp:425
int valueToMarkerPosition(const double value) const
Definition: slider.cpp:499
int mMarkerLength
Definition: slider.h:333
Definition: widget.h:99
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
Orientation ::T OrientationT
Definition: orientation.h:77