FifeGUI 0.3.0
A C++ GUI library designed for games.
slider.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_SLIDER_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_SLIDER_HPP_
7
8// Standard library includes
9#include <memory>
10
11// Platform config include
12#include "fifechan/platform.hpp"
13
14// Project headers (subdirs before local)
15#include "fifechan/listeners/keylistener.hpp"
16#include "fifechan/listeners/mouselistener.hpp"
17#include "fifechan/widget.hpp"
18
19namespace fcn
20{
31 class FIFEGUI_API Slider : public Widget, public MouseListener, public KeyListener
32 {
33 public:
39 enum class Orientation : uint8_t
40 {
41 Horizontal = 0,
42 Vertical
43 };
44
52 explicit Slider(double scaleEnd = 1.0);
53
60 Slider(double scaleStart, double scaleEnd);
61
62 ~Slider() override = default;
63
64 Slider(Slider const &) = delete;
65 Slider& operator=(Slider const &) = delete;
66 Slider(Slider&&) = delete;
67 Slider& operator=(Slider&&) = delete;
68
76 void setScale(double scaleStart, double scaleEnd);
77
84 double getScaleStart() const;
85
92 void setScaleStart(double scaleStart);
93
100 double getScaleEnd() const;
101
108 void setScaleEnd(double scaleEnd);
109
116 double getValue() const;
117
124 void setValue(double value);
125
132 void setMarkerLength(int length);
133
140 int getMarkerLength() const;
141
150 void setOrientation(Orientation orientation);
151
160 Orientation getOrientation() const;
161
171 void setStepLength(double length);
172
182 double getStepLength() const;
183
184 // Inherited from Widget
185
186 void draw(Graphics* graphics) override;
187
188 // Inherited from MouseListener.
189
190 void mousePressed(MouseEvent& mouseEvent) override;
191 void mouseDragged(MouseEvent& mouseEvent) override;
192 void mouseWheelMovedUp(MouseEvent& mouseEvent) override;
193 void mouseWheelMovedDown(MouseEvent& mouseEvent) override;
194 void mouseWheelMovedRight(MouseEvent& mouseEvent) override;
195 void mouseWheelMovedLeft(MouseEvent& mouseEvent) override;
196
197 // Inherited from KeyListener
198
199 void keyPressed(KeyEvent& keyEvent) override;
200
201 protected:
207 virtual void drawMarker(Graphics* graphics);
208
216 virtual double markerPositionToValue(int position) const;
217
225 virtual int valueToMarkerPosition(double value) const;
226
232 virtual int getMarkerPosition() const;
233
237 bool mDragged{false};
238
242 double mValue{0.0};
243
250 double mStepLength{0.5};
251
256
260 double mScaleStart{0.0};
261
265 double mScaleEnd{1.0};
266
272 Orientation mOrientation{Orientation::Horizontal};
273 };
274} // namespace fcn
275
276#endif // INCLUDE_FIFECHAN_WIDGETS_SLIDER_HPP_
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
Represents a key event.
Definition keyevent.hpp:26
KeyListener(KeyListener const &)=default
Copy constructor.
Represents a mouse event.
MouseListener(MouseListener const &)=default
Copy constructor.
A control for selecting a numeric value by sliding along a scale.
Definition slider.hpp:32
double mValue
Holds the current selected value.
Definition slider.hpp:242
Slider(double scaleEnd=1.0)
Constructor.
Definition slider.cpp:18
double mStepLength
Holds the step length.
Definition slider.hpp:250
Orientation
Draw orientations for the slider.
Definition slider.hpp:40
double mScaleEnd
Holds the end value of the scale.
Definition slider.hpp:265
Orientation mOrientation
Holds the orientation of the slider.
Definition slider.hpp:272
double mScaleStart
Holds the start value of the scale.
Definition slider.hpp:260
bool mDragged
True if the slider is dragged, false otherwise.
Definition slider.hpp:237
int mMarkerLength
Holds the length of the marker.
Definition slider.hpp:255
Widget()
Constructor.
Definition widget.cpp:52
Used replacement tokens by configure_file():