FifeGUI 0.2.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#include <memory>
9
10#include "fifechan/keylistener.hpp"
11#include "fifechan/mouselistener.hpp"
12#include "fifechan/platform.hpp"
13#include "fifechan/widget.hpp"
14
15namespace fcn
16{
27 class FIFEGUI_API Slider : public Widget, public MouseListener, public KeyListener
28 {
29 public:
34 enum class Orientation : uint8_t
35 {
36 Horizontal = 0,
37 Vertical
38 };
39
45 explicit Slider(double scaleEnd = 1.0);
46
53 Slider(double scaleStart, double scaleEnd);
54
55 ~Slider() override = default;
56
57 Slider(Slider const &) = delete;
58 Slider& operator=(Slider const &) = delete;
59 Slider(Slider&&) = delete;
60 Slider& operator=(Slider&&) = delete;
61
69 void setScale(double scaleStart, double scaleEnd);
70
77 double getScaleStart() const;
78
85 void setScaleStart(double scaleStart);
86
93 double getScaleEnd() const;
94
101 void setScaleEnd(double scaleEnd);
102
109 double getValue() const;
110
117 void setValue(double value);
118
125 void setMarkerLength(int length);
126
133 int getMarkerLength() const;
134
142 void setOrientation(Orientation orientation);
143
151 Orientation getOrientation() const;
152
160 void setStepLength(double length);
161
169 double getStepLength() const;
170
171 // Inherited from Widget
172
173 void draw(Graphics* graphics) override;
174
175 // Inherited from MouseListener.
176
177 void mousePressed(MouseEvent& mouseEvent) override;
178 void mouseDragged(MouseEvent& mouseEvent) override;
179 void mouseWheelMovedUp(MouseEvent& mouseEvent) override;
180 void mouseWheelMovedDown(MouseEvent& mouseEvent) override;
181 void mouseWheelMovedRight(MouseEvent& mouseEvent) override;
182 void mouseWheelMovedLeft(MouseEvent& mouseEvent) override;
183
184 // Inherited from KeyListener
185
186 void keyPressed(KeyEvent& keyEvent) override;
187
188 protected:
194 virtual void drawMarker(Graphics* graphics);
195
203 virtual double markerPositionToValue(int position) const;
204
212 virtual int valueToMarkerPosition(double value) const;
213
219 virtual int getMarkerPosition() const;
220
224 bool mDragged{false};
225
229 double mValue{0.0};
230
235 double mStepLength{0.5};
236
241
245 double mScaleStart{0.0};
246
250 double mScaleEnd{1.0};
251
256 Orientation mOrientation{Orientation::Horizontal};
257 };
258} // namespace fcn
259
260#endif // INCLUDE_FIFECHAN_WIDGETS_SLIDER_HPP_
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
Represents a key event.
Definition keyevent.hpp:22
Represents a mouse event.
A control for selecting a numeric value by sliding along a scale.
Definition slider.hpp:28
double mValue
Holds the current selected value.
Definition slider.hpp:229
Slider(double scaleEnd=1.0)
Constructor.
Definition slider.cpp:15
double mStepLength
Holds the step length.
Definition slider.hpp:235
Orientation
Draw orientations for the slider.
Definition slider.hpp:35
double mScaleEnd
Holds the end value of the scale.
Definition slider.hpp:250
Orientation mOrientation
Holds the orientation of the slider.
Definition slider.hpp:256
double mScaleStart
Holds the start value of the scale.
Definition slider.hpp:245
bool mDragged
True if the slider is dragged, false otherwise.
Definition slider.hpp:224
int mMarkerLength
Holds the length of the marker.
Definition slider.hpp:240
Widget()
Constructor.
Definition widget.cpp:36