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
38namespace Pt {
39
40namespace Forms {
41
75class PT_FORMS_API ScrollBar : public Control
76{
77 typedef Control Base;
78
79 public:
83 {
87
91 };
92
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
195 Gfx::SizeF onMeasure(const SizePolicy& s);
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
Control()
Creates an unparented control.
Names a flow direction.
Definition Direction.h:52
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
Renders the look of a scroll bar.
Definition ScrollBarStyler.h:149
Transient visual state of a scroll bar.
Definition ScrollBarStyler.h:49
Binds a scroll bar to the current style renderer.
Definition ScrollBarStyler.h:349
virtual bool onMouseEvent(const MouseEvent &ev)
Updates the position from a pointer press or drag.
void setPosition(double pos)
Sets the position to pos, clamped to the range.
virtual bool onTouchEvent(const TouchEvent &ev)
Updates the position from a touch press or drag.
ScrollBar(Orientation o)
Creates a scroll bar with o orientation.
ScrollBarState scrollBarState() const
Returns the transient visual state for the current paint pass.
double maximumPosition() const
Returns the upper bound of the range.
virtual void onPaint(PaintContext &context, const Gfx::RectF &rect)
Paints the track, handle, and buttons.
void setForeground(const Gfx::Brush &b)
Sets the widget-local foreground brush to b.
virtual bool onEnterEvent(const EnterEvent &ev)
Highlights a hot zone when the pointer enters.
Signal< double > & changed()
Returns the signal emitted when scroll() changes the position.
Definition ScrollBar.h:131
const Gfx::Brush & background() const
Returns the effective background brush.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Gfx::SizeF onMeasure(const SizePolicy &s)
Measures the track, handle, and buttons.
~ScrollBar()
Destroys the scroll bar.
virtual void onLayout(const Gfx::RectF &rect)
Places the track, handle, and buttons in rect.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
void setRange(double minpos, double maxpos)
Sets the range to minpos through maxpos.
Orientation
Direction of the track.
Definition ScrollBar.h:83
@ Vertical
Track runs top to bottom.
Definition ScrollBar.h:90
@ Horizontal
Track runs left to right.
Definition ScrollBar.h:86
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Clears the highlight when the pointer leaves.
void setStepping(double scroll, double page)
Sets the step to scroll and the page step to page.
void scroll(double pos)
Sets the position to pos, clamped to the range, and emits changed().
double minimumPosition() const
Returns the lower bound of the range.
const Gfx::Pen & contour() const
Returns the effective contour pen.
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.
void setRenderer(ScrollBarRenderer *renderer)
Assigns renderer as the family renderer.
virtual void onInvalidate()
Binds the styler.
double position() const
Returns the current position.
Constraint used when measuring a control.
Definition SizePolicy.h:48
Touch press, move, or release.
Definition TouchEvent.h:51
Fill color, gradient or texture.
Definition Brush.h:151
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