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
35namespace Pt {
36
37namespace Forms {
38
48class PT_FORMS_API ScrollBarState
49{
50 public:
54
57 bool isEnabled() const;
58
61 void setEnabled(bool value);
62
65 bool isFocused() const;
66
69 void setFocused(bool value);
70
73 bool isHandleHovered() const;
74
77 void setHandleHovered(bool value);
78
81 bool isHandlePressed() const;
82
85 void setHandlePressed(bool value);
86
89 bool isDecreaseHovered() const;
90
93 void setDecreaseHovered(bool value);
94
97 bool isDecreasePressed() const;
98
101 void setDecreasePressed(bool value);
102
105 bool isIncreaseHovered() const;
106
109 void setIncreaseHovered(bool value);
110
113 bool isIncreasePressed() const;
114
117 void setIncreasePressed(bool value);
118
119 private:
120 bool _enabled;
121 bool _focused;
122 bool _handleHovered;
123 bool _handlePressed;
124 bool _decreaseHovered;
125 bool _decreasePressed;
126 bool _increaseHovered;
127 bool _increasePressed;
128};
129
130
148class PT_FORMS_API ScrollBarRenderer : public Renderer
149{
150 public:
153 explicit ScrollBarRenderer(std::size_t refs = 0);
154
158
162
163 public:
166 Gfx::SizeF measureFrame(PaintSurface& surface,
167 const Gfx::SizeF& contentSize,
168 Direction direction);
169
172 Gfx::SizeF measureTrack(PaintSurface& surface,
173 Direction direction);
174
177 Gfx::SizeF measureHandle(PaintSurface& surface,
178 Direction direction);
179
182 Gfx::SizeF measureButton(PaintSurface& surface,
183 Direction direction);
184
188 const Gfx::RectF& rect,
189 Direction direction,
190 const Gfx::SizeF& buttonSize,
191 Gfx::RectF& trackRect,
192 Gfx::RectF& decreaseRect,
193 Gfx::RectF& increaseRect);
194
198 const Gfx::RectF& trackRect,
199 Direction direction,
200 float fraction,
201 float viewProportion,
202 Gfx::RectF& handleRect);
203
207 const Gfx::RectF& rect,
208 Direction direction,
209 const Gfx::RectF& trackRect,
210 const Gfx::RectF& handleRect,
211 const Gfx::RectF& decreaseRect,
212 const Gfx::RectF& increaseRect,
213 const ScrollBarState& state);
214
218 const Gfx::RectF& trackRect,
219 Direction direction,
220 const ScrollBarState& state);
221
225 const Gfx::RectF& handleRect,
226 Direction direction,
227 const ScrollBarState& state);
228
232 const Gfx::RectF& buttonRect,
233 Direction direction,
234 const ScrollBarState& state);
235
239 const Gfx::RectF& buttonRect,
240 Direction direction,
241 const ScrollBarState& state);
242
243 protected:
246 virtual ScrollBarRenderer* onCreate() const = 0;
247
250 virtual void onReset(const StyleOptions& options) = 0;
251
254 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
255 const Gfx::SizeF& contentSize,
256 Direction direction) = 0;
257
260 virtual Gfx::SizeF onMeasureTrack(PaintSurface& surface,
261 Direction direction) = 0;
262
265 virtual Gfx::SizeF onMeasureHandle(PaintSurface& surface,
266 Direction direction) = 0;
267
270 virtual Gfx::SizeF onMeasureButton(PaintSurface& surface,
271 Direction direction) = 0;
272
275 virtual void onLayoutChrome(PaintSurface& surface,
276 const Gfx::RectF& rect,
277 Direction direction,
278 const Gfx::SizeF& buttonSize,
279 Gfx::RectF& trackRect,
280 Gfx::RectF& decreaseRect,
281 Gfx::RectF& increaseRect) = 0;
282
285 virtual void onLayoutHandle(PaintSurface& surface,
286 const Gfx::RectF& trackRect,
287 Direction direction,
288 float fraction,
289 float viewProportion,
290 Gfx::RectF& handleRect) = 0;
291
294 virtual void onRenderChrome(PaintContext& context,
295 const Gfx::RectF& rect,
296 Direction direction,
297 const Gfx::RectF& trackRect,
298 const Gfx::RectF& handleRect,
299 const Gfx::RectF& decreaseRect,
300 const Gfx::RectF& increaseRect,
301 const ScrollBarState& state);
302
305 virtual void onRenderTrack(PaintContext& context,
306 const Gfx::RectF& trackRect,
307 Direction direction,
308 const ScrollBarState& state) = 0;
309
312 virtual void onRenderHandle(PaintContext& context,
313 const Gfx::RectF& handleRect,
314 Direction direction,
315 const ScrollBarState& state) = 0;
316
320 const Gfx::RectF& buttonRect,
321 Direction direction,
322 const ScrollBarState& state) = 0;
323
327 const Gfx::RectF& buttonRect,
328 Direction direction,
329 const ScrollBarState& state) = 0;
330};
331
332
348class PT_FORMS_API ScrollBarStyler : public Styler
349{
350 public:
354
357 const Gfx::Brush& background() const;
358
361 void setBackground(const Gfx::Brush& brush);
362
365 const Gfx::Brush& foreground() const;
366
369 void setForeground(const Gfx::Brush& brush);
370
373 const Gfx::Pen& contour() const;
374
377 void setContour(const Gfx::Pen& pen);
378
381 Gfx::SizeF measureFrame(PaintSurface& surface,
382 const Gfx::SizeF& contentSize,
383 Direction direction) const;
384
387 Gfx::SizeF measureButton(PaintSurface& surface,
388 Direction direction) const;
389
393 const Gfx::RectF& rect,
394 Direction direction,
395 const Gfx::SizeF& buttonSize,
396 Gfx::RectF& trackRect,
397 Gfx::RectF& decreaseRect,
398 Gfx::RectF& increaseRect) const;
399
403 const Gfx::RectF& trackRect,
404 Direction direction,
405 float fraction,
406 float viewProportion,
407 Gfx::RectF& handleRect) const;
408
412 const Gfx::RectF& rect,
413 Direction direction,
414 const Gfx::RectF& trackRect,
415 const Gfx::RectF& handleRect,
416 const Gfx::RectF& decreaseRect,
417 const Gfx::RectF& increaseRect,
418 const ScrollBarState& state) const;
419
424 void setRenderer(ScrollBarRenderer* renderer = 0);
425
426 protected:
429 virtual StyleOptions& onBindOptions(const StyleOptions& global);
430
433 virtual Renderer* onStyleRenderer(const Style& style);
434
437 virtual Renderer* onCreateRenderer(const Style& style);
438
439 private:
441 StyleOptions _options;
442};
443
444} // namespace
445
446} // namespace
447
448#endif
Names a flow direction.
Definition Direction.h:52
Manages a reference-counted Style::Facet.
Definition Style.h:79
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Forms render target for painting.
Definition PaintSurface.h:50
Provides cloneable drawing for one control family.
Definition Renderer.h:61
Renderer(const std::type_info &ti, std::size_t refs=0)
Constructor.
Definition Renderer.h:65
Renders the look of a scroll bar.
Definition ScrollBarStyler.h:149
virtual void onRenderDecreaseButton(PaintContext &context, const Gfx::RectF &buttonRect, Direction direction, const ScrollBarState &state)=0
Paints the decrease control for state.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize, Direction direction)=0
Measures the frame enclosing contentSize.
void layoutHandle(PaintSurface &surface, const Gfx::RectF &trackRect, Direction direction, float fraction, float viewProportion, Gfx::RectF &handleRect)
Places the handle in trackRect for fraction and viewProportion.
void renderDecreaseButton(PaintContext &context, const Gfx::RectF &buttonRect, Direction direction, const ScrollBarState &state)
Paints the decrease control for state.
virtual void onRenderHandle(PaintContext &context, const Gfx::RectF &handleRect, Direction direction, const ScrollBarState &state)=0
Paints the handle for state.
virtual void onRenderChrome(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 track, handle, and buttons for state.
virtual void onLayoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Direction direction, const Gfx::SizeF &buttonSize, Gfx::RectF &trackRect, Gfx::RectF &decreaseRect, Gfx::RectF &increaseRect)=0
Places the track and decrease and increase controls in rect.
virtual void onLayoutHandle(PaintSurface &surface, const Gfx::RectF &trackRect, Direction direction, float fraction, float viewProportion, Gfx::RectF &handleRect)=0
Places the handle in trackRect for fraction and viewProportion.
Gfx::SizeF measureButton(PaintSurface &surface, Direction direction)
Returns the natural size of a decrease or increase control for direction.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize, Direction direction)
Returns the outer size including the frame for contentSize.
virtual Gfx::SizeF onMeasureButton(PaintSurface &surface, Direction direction)=0
Returns the natural size of a decrease or increase control for direction.
virtual void onRenderIncreaseButton(PaintContext &context, const Gfx::RectF &buttonRect, Direction direction, const ScrollBarState &state)=0
Paints the increase control for state.
Gfx::SizeF measureTrack(PaintSurface &surface, Direction direction)
Returns the natural size of the track for direction.
void renderIncreaseButton(PaintContext &context, const Gfx::RectF &buttonRect, Direction direction, const ScrollBarState &state)
Paints the increase control for state.
void renderHandle(PaintContext &context, const Gfx::RectF &handleRect, Direction direction, const ScrollBarState &state)
Paints the handle for state.
Gfx::SizeF measureHandle(PaintSurface &surface, Direction direction)
Returns the natural size of the handle for direction.
void renderTrack(PaintContext &context, const Gfx::RectF &trackRect, Direction direction, const ScrollBarState &state)
Paints the track for state.
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Direction direction, const Gfx::SizeF &buttonSize, Gfx::RectF &trackRect, Gfx::RectF &decreaseRect, Gfx::RectF &increaseRect)
Places the track and decrease and increase controls in rect.
virtual ScrollBarRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
ScrollBarRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
virtual ~ScrollBarRenderer()
Destroys the renderer.
virtual Gfx::SizeF onMeasureHandle(PaintSurface &surface, Direction direction)=0
Returns the natural size of the handle for direction.
ScrollBarRenderer * create() const
Creates a new default-constructed instance that the caller owns.
virtual Gfx::SizeF onMeasureTrack(PaintSurface &surface, Direction direction)=0
Returns the natural size of the track for direction.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
virtual void onRenderTrack(PaintContext &context, const Gfx::RectF &trackRect, Direction direction, const ScrollBarState &state)=0
Paints the track for state.
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)
Paints track, handle, and buttons for state.
Transient visual state of a scroll bar.
Definition ScrollBarStyler.h:49
bool isHandleHovered() const
Returns true if the pointer is currently over the handle.
bool isIncreaseHovered() const
Returns true if the pointer is currently over the increase control.
bool isIncreasePressed() const
Returns true if the increase control is currently pressed.
void setIncreasePressed(bool value)
Sets whether the increase control is pressed.
bool isFocused() const
Returns true if the bar currently has focus.
bool isDecreasePressed() const
Returns true if the decrease control is currently pressed.
void setDecreaseHovered(bool value)
Sets whether the pointer is over the decrease control.
void setFocused(bool value)
Sets whether the bar has focus.
void setDecreasePressed(bool value)
Sets whether the decrease control is pressed.
ScrollBarState()
Constructs an empty scroll bar state.
bool isEnabled() const
Returns true if the bar is currently enabled.
void setEnabled(bool value)
Sets whether the bar is enabled.
void setIncreaseHovered(bool value)
Sets whether the pointer is over the increase control.
bool isDecreaseHovered() const
Returns true if the pointer is currently over the decrease control.
bool isHandlePressed() const
Returns true if the handle is currently pressed.
void setHandlePressed(bool value)
Sets whether the handle is pressed.
void setHandleHovered(bool value)
Sets whether the pointer is over the handle.
Gfx::SizeF measureButton(PaintSurface &surface, Direction direction) const
Measures a decrease or increase button for direction.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared scroll-bar renderer from style, or 0.
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.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the overlay to global and returns it.
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush to brush.
const Gfx::Brush & background() const
Returns the effective background brush.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
void setRenderer(ScrollBarRenderer *renderer=0)
Assigns a specific scroll bar renderer.
ScrollBarStyler()
Constructs an unbound scroll bar styler.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independent clone of the style renderer, or 0.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize, Direction direction) const
Measures the frame enclosing contentSize.
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::Pen & contour() const
Returns the effective contour pen.
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.
Stores named appearance options.
Definition StyleOptions.h:646
Stores renderer facets for the active theme.
Definition Style.h:203
Styler()
Constructor.
Fill color, gradient or texture.
Definition Brush.h:151
Outline color, width and style.
Definition Pen.h:59
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33