ScrollBarStyler.h
1 /* Copyright (C) 2016 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef PT_FORMS_SCROLLBARSTYLE_H
30 #define PT_FORMS_SCROLLBARSTYLE_H
31 
32 #include <Pt/Forms/Styler.h>
33 #include <Pt/Forms/Direction.h>
34 
35 namespace Pt {
36 
37 namespace Forms {
38 
39 class PT_FORMS_API ScrollBarState
40 {
41  public:
42  ScrollBarState();
43 
44  bool isEnabled() const;
45 
46  void setEnabled(bool value);
47 
48  bool isFocused() const;
49 
50  void setFocused(bool value);
51 
52  bool isHandleHovered() const;
53 
54  void setHandleHovered(bool value);
55 
56  bool isHandlePressed() const;
57 
58  void setHandlePressed(bool value);
59 
60  bool isDecreaseHovered() const;
61 
62  void setDecreaseHovered(bool value);
63 
64  bool isDecreasePressed() const;
65 
66  void setDecreasePressed(bool value);
67 
68  bool isIncreaseHovered() const;
69 
70  void setIncreaseHovered(bool value);
71 
72  bool isIncreasePressed() const;
73 
74  void setIncreasePressed(bool value);
75 
76  private:
77  bool _enabled;
78  bool _focused;
79  bool _handleHovered;
80  bool _handlePressed;
81  bool _decreaseHovered;
82  bool _decreasePressed;
83  bool _increaseHovered;
84  bool _increasePressed;
85 };
86 
87 
88 class PT_FORMS_API ScrollBarRenderer : public Renderer
89 {
90  public:
91  explicit ScrollBarRenderer(std::size_t refs = 0);
92 
93  virtual ~ScrollBarRenderer();
94 
97  ScrollBarRenderer* create() const;
98 
99  public:
100  Gfx::SizeF measureFrame(PaintSurface& surface,
101  const Gfx::SizeF& contentSize,
102  Direction direction);
103 
104  Gfx::SizeF measureTrack(PaintSurface& surface,
105  Direction direction);
106 
107  Gfx::SizeF measureHandle(PaintSurface& surface,
108  Direction direction);
109 
110  Gfx::SizeF measureButton(PaintSurface& surface,
111  Direction direction);
112 
113  void layoutChrome(PaintSurface& surface,
114  const Gfx::RectF& rect,
115  Direction direction,
116  const Gfx::SizeF& buttonSize,
117  Gfx::RectF& trackRect,
118  Gfx::RectF& decreaseRect,
119  Gfx::RectF& increaseRect);
120 
121  void layoutHandle(PaintSurface& surface,
122  const Gfx::RectF& trackRect,
123  Direction direction,
124  float fraction,
125  float viewProportion,
126  Gfx::RectF& handleRect);
127 
128  void renderChrome(PaintContext& context,
129  const Gfx::RectF& rect,
130  Direction direction,
131  const Gfx::RectF& trackRect,
132  const Gfx::RectF& handleRect,
133  const Gfx::RectF& decreaseRect,
134  const Gfx::RectF& increaseRect,
135  const ScrollBarState& state);
136 
137  void renderTrack(PaintContext& context,
138  const Gfx::RectF& trackRect,
139  Direction direction,
140  const ScrollBarState& state);
141 
142  void renderHandle(PaintContext& context,
143  const Gfx::RectF& handleRect,
144  Direction direction,
145  const ScrollBarState& state);
146 
147  void renderDecreaseButton(PaintContext& context,
148  const Gfx::RectF& buttonRect,
149  Direction direction,
150  const ScrollBarState& state);
151 
152  void renderIncreaseButton(PaintContext& context,
153  const Gfx::RectF& buttonRect,
154  Direction direction,
155  const ScrollBarState& state);
156 
157  protected:
158  virtual ScrollBarRenderer* onCreate() const = 0;
159 
162  virtual void onReset(const StyleOptions& options) = 0;
163 
164  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
165  const Gfx::SizeF& contentSize,
166  Direction direction) = 0;
167 
168  virtual Gfx::SizeF onMeasureTrack(PaintSurface& surface,
169  Direction direction) = 0;
170 
171  virtual Gfx::SizeF onMeasureHandle(PaintSurface& surface,
172  Direction direction) = 0;
173 
174  virtual Gfx::SizeF onMeasureButton(PaintSurface& surface,
175  Direction direction) = 0;
176 
177  virtual void onLayoutChrome(PaintSurface& surface,
178  const Gfx::RectF& rect,
179  Direction direction,
180  const Gfx::SizeF& buttonSize,
181  Gfx::RectF& trackRect,
182  Gfx::RectF& decreaseRect,
183  Gfx::RectF& increaseRect) = 0;
184 
185  virtual void onLayoutHandle(PaintSurface& surface,
186  const Gfx::RectF& trackRect,
187  Direction direction,
188  float fraction,
189  float viewProportion,
190  Gfx::RectF& handleRect) = 0;
191 
192  virtual void onRenderChrome(PaintContext& context,
193  const Gfx::RectF& rect,
194  Direction direction,
195  const Gfx::RectF& trackRect,
196  const Gfx::RectF& handleRect,
197  const Gfx::RectF& decreaseRect,
198  const Gfx::RectF& increaseRect,
199  const ScrollBarState& state);
200 
201  virtual void onRenderTrack(PaintContext& context,
202  const Gfx::RectF& trackRect,
203  Direction direction,
204  const ScrollBarState& state) = 0;
205 
206  virtual void onRenderHandle(PaintContext& context,
207  const Gfx::RectF& handleRect,
208  Direction direction,
209  const ScrollBarState& state) = 0;
210 
211  virtual void onRenderDecreaseButton(PaintContext& context,
212  const Gfx::RectF& buttonRect,
213  Direction direction,
214  const ScrollBarState& state) = 0;
215 
216  virtual void onRenderIncreaseButton(PaintContext& context,
217  const Gfx::RectF& buttonRect,
218  Direction direction,
219  const ScrollBarState& state) = 0;
220 };
221 
222 
225 class PT_FORMS_API ScrollBarStyler : public Styler
226 {
227  public:
231 
234  const Gfx::Brush& background() const;
235 
238  void setBackground(const Gfx::Brush& brush);
239 
242  const Gfx::Brush& foreground() const;
243 
246  void setForeground(const Gfx::Brush& brush);
247 
250  const Gfx::Pen& contour() const;
251 
254  void setContour(const Gfx::Pen& pen);
255 
259  const Gfx::SizeF& contentSize,
260  Direction direction) const;
261 
265  Direction direction) const;
266 
269  void layoutChrome(PaintSurface& surface,
270  const Gfx::RectF& rect,
271  Direction direction,
272  const Gfx::SizeF& buttonSize,
273  Gfx::RectF& trackRect,
274  Gfx::RectF& decreaseRect,
275  Gfx::RectF& increaseRect) const;
276 
279  void layoutHandle(PaintSurface& surface,
280  const Gfx::RectF& trackRect,
281  Direction direction,
282  float fraction,
283  float viewProportion,
284  Gfx::RectF& handleRect) const;
285 
288  void renderChrome(PaintContext& context,
289  const Gfx::RectF& rect,
290  Direction direction,
291  const Gfx::RectF& trackRect,
292  const Gfx::RectF& handleRect,
293  const Gfx::RectF& decreaseRect,
294  const Gfx::RectF& increaseRect,
295  const ScrollBarState& state) const;
296 
299  void setRenderer(ScrollBarRenderer* renderer = 0);
300 
301  protected:
302  virtual StyleOptions& onBindOptions(const StyleOptions& global);
303 
304  virtual Renderer* onStyleRenderer(const Style& style);
305 
306  virtual Renderer* onCreateRenderer(const Style& style);
307 
308  private:
309  FacetPtr<ScrollBarRenderer> _renderer;
310  StyleOptions _options;
311 };
312 
313 } // namespace
314 
315 } // namespace
316 
317 #endif
Core module.
Definition: Allocator.h:33
const Gfx::Pen & contour() const
Returns the effective contour pen.
Attributes for the drawing of outlines.
Definition: Pen.h:54
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Returns the specific style options.
Paint surface.
Definition: PaintSurface.h:44
Styler.
Definition: Styler.h:47
Paint context.
Definition: PaintContext.h:45
Size with floating-point width and height.
Definition: Size.h:47
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Direction direction, const Gfx::SizeF &buttonSize, Gfx::RectF &trackRect, Gfx::RectF &decreaseRect, Gfx::RectF &increaseRect) const
Lays out the track and decrease and increase buttons within rect.
void layoutHandle(PaintSurface &surface, const Gfx::RectF &trackRect, Direction direction, float fraction, float viewProportion, Gfx::RectF &handleRect) const
Lays out the handle within trackRect.
const Gfx::Brush & background() const
Returns the effective background brush.
Scroll bar styler.
Definition: ScrollBarStyler.h:226
Style for widgets.
Definition: Style.h:155
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush to brush.
void setRenderer(ScrollBarRenderer *renderer=0)
Assigns a specific scroll bar renderer.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize, Direction direction) const
Measures the frame enclosing contentSize.
Style options container.
Definition: StyleOptions.h:535
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
void renderChrome(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) const
Renders the scroll bar chrome within rect for state.
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
ScrollBarStyler()
Constructs an unbound scroll bar styler.
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
Gfx::SizeF measureButton(PaintSurface &surface, Direction direction) const
Measures a decrease or increase button for direction.