ScrollBar.h
1 /* Copyright (C) 2016 Marc Boris Duerner
2  Copyright (C) 2016 Laurentiu-Gheorghe Crisan
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_SCROLLBAR_H
31 #define Pt_Forms_SCROLLBAR_H
32 
33 #include <Pt/Forms/Api.h>
34 #include <Pt/Forms/Control.h>
35 #include <Pt/Forms/Direction.h>
36 #include <Pt/Forms/ScrollBarStyler.h>
37 
38 namespace Pt {
39 
40 namespace Forms {
41 
75 class PT_FORMS_API ScrollBar : public Control
76 {
77  typedef Control Base;
78 
79  public:
83  {
86  Horizontal = 0,
87 
90  Vertical = 1
91  };
92 
95  explicit ScrollBar(Orientation o);
96 
100 
103  void setRange(double minpos, double maxpos);
104 
107  void setStepping(double scroll, double page);
108 
111  double minimumPosition() const;
112 
115  double maximumPosition() const;
116 
119  double position() const;
120 
123  void setPosition(double pos);
124 
127  void scroll(double pos);
128 
132  { return _changed; }
133 
134  public:
137  const Gfx::Brush& background() const;
138 
141  void setBackground(const Gfx::Brush& b);
142 
145  const Gfx::Brush& foreground() const;
146 
149  void setForeground(const Gfx::Brush& b);
150 
153  const Gfx::Pen& contour() const;
154 
157  void setContour(const Gfx::Pen& p);
158 
164 
168 
169  protected:
172  virtual void onInvalidate();
173 
176  virtual void onLayout(const Gfx::RectF& rect);
177 
180  virtual void onPaint(PaintContext& context, const Gfx::RectF& rect);
181 
184  virtual void onPaintChrome(PaintContext& context,
185  const Gfx::RectF& rect,
186  Direction direction,
187  const Gfx::RectF& trackRect,
188  const Gfx::RectF& handleRect,
189  const Gfx::RectF& decreaseRect,
190  const Gfx::RectF& increaseRect,
191  const ScrollBarState& state);
192 
196 
199  virtual bool onMouseEvent(const MouseEvent& ev);
200 
203  virtual bool onTouchEvent(const TouchEvent& ev);
204 
207  virtual bool onEnterEvent(const EnterEvent& ev);
208 
211  virtual bool onLeaveEvent(const LeaveEvent& ev);
212 
213  private:
214  enum HotZone
215  {
216  NoZone = 0,
217  TrackZone,
218  HandleZone,
219  DecreaseZone,
220  IncreaseZone
221  };
222 
223  Direction direction() const;
224 
225  float fraction() const;
226 
227  float viewProportion() const;
228 
229  HotZone hitTest(const Gfx::PointF& pos);
230 
231  Gfx::RectF currentHandleRect();
232 
233  private:
234  Orientation _orientation;
235  double _minPos;
236  double _maxPos;
237  double _pageStep;
238  double _scrollStep;
239  double _position;
240  bool _dragging;
241  Signal<double> _changed;
242 
243  ScrollBarStyler _styler;
244  Gfx::RectF _trackRect;
245  Gfx::RectF _decreaseRect;
246  Gfx::RectF _increaseRect;
247  HotZone _hoveredZone;
248  HotZone _pressedZone;
249 };
250 
251 } // namespace
252 
253 } // namespace
254 
255 #endif
Core module.
Definition: Allocator.h:33
virtual void onPaint(PaintContext &context, const Gfx::RectF &rect)
Paints the track, handle, and buttons.
Touch press, move, or release.
Definition: TouchEvent.h:51
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
Pointer entered a widget.
Definition: EnterEvent.h:49
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Attributes for the drawing of outlines.
Definition: Pen.h:54
Transient visual state of a scroll bar.
Definition: ScrollBarStyler.h:49
double maximumPosition() const
Returns the upper bound of the range.
void scroll(double pos)
Sets the position to pos, clamped to the range, and emits changed().
virtual void onInvalidate()
Binds the styler.
virtual bool onTouchEvent(const TouchEvent &ev)
Updates the position from a touch press or drag.
virtual void onLayout(const Gfx::RectF &rect)
Places the track, handle, and buttons in rect.
Gfx::SizeF onMeasure(const SizePolicy &s)
Measures the track, handle, and buttons.
ScrollBarState scrollBarState() const
Returns the transient visual state for the current paint pass.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Clears the highlight when the pointer leaves.
virtual bool onMouseEvent(const MouseEvent &ev)
Updates the position from a pointer press or drag.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
ScrollBar(Orientation o)
Creates a scroll bar with o orientation.
void setForeground(const Gfx::Brush &b)
Sets the widget-local foreground brush to b.
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
virtual bool onEnterEvent(const EnterEvent &ev)
Highlights a hot zone when the pointer enters.
Reusable view used as application content.
Definition: Control.h:107
Renders the look of a scroll bar.
Definition: ScrollBarStyler.h:149
Orientation
Direction of the track.
Definition: ScrollBar.h:83
Binds a scroll bar to the current style renderer.
Definition: ScrollBarStyler.h:349
const Gfx::Pen & contour() const
Returns the effective contour pen.
const Gfx::Brush & background() const
Returns the effective background brush.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
void setRange(double minpos, double maxpos)
Sets the range to minpos through maxpos.
Names a flow direction.
Definition: Direction.h:52
void setRenderer(ScrollBarRenderer *renderer)
Assigns renderer as the family renderer.
void setStepping(double scroll, double page)
Sets the step to scroll and the page step to page.
virtual void onPaintChrome(PaintContext &context, const Gfx::RectF &rect, Direction direction, const Gfx::RectF &trackRect, const Gfx::RectF &handleRect, const Gfx::RectF &decreaseRect, const Gfx::RectF &increaseRect, const ScrollBarState &state)
Paints the scroll bar chrome for state.
Widget that hosts controls on a paint surface.
Definition: View.h:86
Position in a range shown by a handle on a track.
Definition: ScrollBar.h:76
~ScrollBar()
Destroys the scroll bar.
Pointer left a widget.
Definition: LeaveEvent.h:49
Constraint used when measuring a control.
Definition: SizePolicy.h:48
double position() const
Returns the current position.
double minimumPosition() const
Returns the lower bound of the range.
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
Signal< double > & changed()
Returns the signal emitted when scroll() changes the position.
Definition: ScrollBar.h:131
void setPosition(double pos)
Sets the position to pos, clamped to the range.
Pointer movement or button change.
Definition: MouseEvent.h:134