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 
37 namespace Pt {
38 
39 namespace Forms {
40 
71 class PT_FORMS_API Slider : public Control
72 {
73  public:
74  typedef Control Base;
75 
76  public:
79  Slider();
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 
148  Gfx::Font font() const;
149 
152  void setFont(const Gfx::Font& font);
153 
156  void setFontSize(std::size_t size);
157 
161 
165 
170  void setRenderer(SliderRenderer* renderer);
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
Core module.
Definition: Allocator.h:33
void setPosition(int pos)
Sets the position to pos, clamped to the range, and emits positionChanged() when it changes.
Slider()
Creates a slider.
Touch press, move, or release.
Definition: TouchEvent.h:51
Binds a slider to the current style renderer.
Definition: SliderStyler.h:244
Pointer entered a widget.
Definition: EnterEvent.h:49
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
Attributes for the drawing of outlines.
Definition: Pen.h:54
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Value chosen along a range by dragging a handle on a track.
Definition: Slider.h:72
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints the track and handle.
Slant
Describes the requested font slant.
Definition: Font.h:76
void setRange(int min, int max)
Sets the range to min through max.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
virtual bool onEnterEvent(const EnterEvent &ev)
Highlights the slider when the pointer enters.
virtual void onInvalidate()
Binds the styler.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
virtual bool onTouchEvent(const TouchEvent &ev)
Updates the position from a touch drag.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Clears the highlight when the pointer leaves.
const Gfx::Color & textColor() const
Returns the effective text color.
Size with floating-point width and height.
Definition: Size.h:47
Reusable view used as application content.
Definition: Control.h:107
int maximum() const
Returns the upper bound of the range.
virtual ~Slider()
Destroys the slider.
Weight
Describes the requested font weight.
Definition: Font.h:61
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the track, handle, and frame.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void setForeground(const Gfx::Brush &b)
Sets the widget-local foreground brush to b.
Signal< int > & positionChanged()
Returns the signal emitted when the position changes.
const Gfx::Brush & background() const
Returns the effective background brush.
Widget that hosts controls on a paint surface.
Definition: View.h:86
int position() const
Returns the current position.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
Font request used for text drawing and measurement.
Definition: Font.h:56
int minimum() const
Returns the lower bound of the range.
bool isHighlighted() const
Returns true if the pointer is over the slider.
Pointer left a widget.
Definition: LeaveEvent.h:49
Constraint used when measuring a control.
Definition: SizePolicy.h:48
Gfx::Font font() const
Returns the effective font.
Standard color type.
Definition: Color.h:47
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Transient visual state of a slider.
Definition: SliderStyler.h:47
Fill description for shapes and text.
Definition: Brush.h:145
SliderState sliderState() const
Returns the transient visual state for the current paint pass.
void setRenderer(SliderRenderer *renderer)
Assigns renderer as the family renderer.
virtual void onLayout(const Gfx::RectF &rect)
Places the track and handle in rect.
Rect with floating-point coordinates.
Definition: Rect.h:47
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
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 setFont(const Gfx::Font &font)
Sets the widget-local font to font.
Pointer movement or button change.
Definition: MouseEvent.h:134
Renders the look of a slider.
Definition: SliderStyler.h:104
virtual bool onMouseEvent(const MouseEvent &ev)
Updates the position from a pointer drag.