Slider.h
1/* Copyright (C) 2017 Marc Boris Duerner
2 Copyright (C) 2017 Ilja Maier
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 As a special exception, you may use this file as part of a free
10 software library without restriction. Specifically, if other files
11 instantiate templates or use macros or inline functions from this
12 file, or you compile this file and link it with other files to
13 produce an executable, this file does not by itself cause the
14 resulting executable to be covered by the GNU General Public
15 License. This exception does not however invalidate any other
16 reasons why the executable file might be covered by the GNU Library
17 General Public License.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 MA 02110-1301 USA
28*/
29
30#ifndef Pt_Forms_Slider_H
31#define Pt_Forms_Slider_H
32
33#include <Pt/Forms/Control.h>
34#include <Pt/Forms/SliderStyler.h>
35#include <Pt/Signal.h>
36
37namespace Pt {
38
39namespace Forms {
40
71class PT_FORMS_API Slider : public Control
72{
73 public:
74 typedef Control Base;
75
76 public:
80
83 virtual ~Slider();
84
87 int position() const;
88
91 void setPosition(int pos);
92
95 int minimum() const;
96
99 int maximum() const;
100
103 void setRange(int min, int max);
104
107 bool isHighlighted() const;
108
112
113 public:
116 const Gfx::Brush& background() const;
117
120 void setBackground(const Gfx::Brush& b);
121
124 const Gfx::Brush& foreground() const;
125
128 void setForeground(const Gfx::Brush& b);
129
132 const Gfx::Pen& contour() const;
133
136 void setContour(const Gfx::Pen& p);
137
140 const Gfx::Color& textColor() const;
141
144 void setTextColor(const Gfx::Color& color);
145
149
152 void setFont(const Gfx::Font& font);
153
156 void setFontSize(std::size_t size);
157
161
165
171
175
176 protected:
179 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
180
183 virtual void onInvalidate();
184
187 virtual void onLayout(const Gfx::RectF& rect);
188
191 virtual void onPaint(PaintContext& context, const Gfx::RectF& updateRect);
192
195 virtual void onPaintChrome(PaintContext& context,
196 const Gfx::RectF& rect,
197 const Gfx::RectF& trackRect,
198 const Gfx::RectF& handleRect,
199 const SliderState& state);
200
203 virtual bool onMouseEvent(const MouseEvent& ev);
204
207 virtual bool onTouchEvent(const TouchEvent& ev);
208
211 virtual bool onEnterEvent(const EnterEvent& ev);
212
215 virtual bool onLeaveEvent(const LeaveEvent& ev);
216
217 private:
218 float toFraction() const;
219
220 int toPosition(double x) const;
221
222 private:
223 Signal<int> _positionChanged;
224 SliderStyler _sliderStyler;
225 int _position;
226 int _min;
227 int _max;
228 bool _isHighlighted;
229 Gfx::RectF _trackRect;
230 Gfx::RectF _handleRect;
231};
232
233} // namespace
234
235} // namespace
236
237#endif
Control()
Creates an unparented control.
Pointer entered a widget.
Definition EnterEvent.h:49
Pointer left a widget.
Definition LeaveEvent.h:49
Pointer movement or button change.
Definition MouseEvent.h:134
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Constraint used when measuring a control.
Definition SizePolicy.h:48
Renders the look of a slider.
Definition SliderStyler.h:104
Transient visual state of a slider.
Definition SliderStyler.h:47
Binds a slider to the current style renderer.
Definition SliderStyler.h:244
virtual bool onMouseEvent(const MouseEvent &ev)
Updates the position from a pointer drag.
Signal< int > & positionChanged()
Returns the signal emitted when the position changes.
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints the track and handle.
int position() const
Returns the current position.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual bool onTouchEvent(const TouchEvent &ev)
Updates the position from a touch drag.
void setPosition(int pos)
Sets the position to pos, clamped to the range, and emits positionChanged() when it changes.
void setForeground(const Gfx::Brush &b)
Sets the widget-local foreground brush to b.
virtual bool onEnterEvent(const EnterEvent &ev)
Highlights the slider when the pointer enters.
const Gfx::Brush & background() const
Returns the effective background brush.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Gfx::Font font() const
Returns the effective font.
virtual void onLayout(const Gfx::RectF &rect)
Places the track and handle in rect.
void setRange(int min, int max)
Sets the range to min through max.
bool isHighlighted() const
Returns true if the pointer is over the slider.
virtual ~Slider()
Destroys the slider.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
int maximum() const
Returns the upper bound of the range.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the track, handle, and frame.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Clears the highlight when the pointer leaves.
virtual void onPaintChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &trackRect, const Gfx::RectF &handleRect, const SliderState &state)
Paints the slider chrome for state.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
int minimum() const
Returns the lower bound of the range.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
SliderState sliderState() const
Returns the transient visual state for the current paint pass.
Slider()
Creates a slider.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
virtual void onInvalidate()
Binds the styler.
void setRenderer(SliderRenderer *renderer)
Assigns renderer as the family renderer.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Touch press, move, or release.
Definition TouchEvent.h:51
const Gfx::SizeF & size() const
Returns the size in local logical coordinates.
Fill color, gradient or texture.
Definition Brush.h:151
8-bit ARGB color.
Definition Color.h:65
Font family, size and style.
Definition Font.h:63
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Outline color, width and style.
Definition Pen.h:59
Multicast Signal to call multiple slots.
Definition Signal.h:190
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33