SliderStyler.h
1 /* Copyright (C) 2017 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_SLIDERSTYLE_H
30 #define PT_FORMS_SLIDERSTYLE_H
31 
32 #include <Pt/Forms/Styler.h>
33 
34 namespace Pt {
35 
36 namespace Forms {
37 
38 class PT_FORMS_API SliderState
39 {
40  public:
41  SliderState();
42 
43  bool isEnabled() const;
44 
45  void setEnabled(bool value);
46 
47  bool isHovered() const;
48 
49  void setHovered(bool value);
50 
51  bool isFocused() const;
52 
53  void setFocused(bool value);
54 
55  private:
56  bool _enabled;
57  bool _hovered;
58  bool _focused;
59 };
60 
61 
64 class PT_FORMS_API SliderRenderer : public Renderer
65 {
66  public:
67  explicit SliderRenderer(std::size_t refs = 0);
68 
69  virtual ~SliderRenderer();
70 
74 
75  public:
76  Gfx::SizeF measureFrame(PaintSurface& surface,
77  const Gfx::SizeF& contentSize);
78 
79  Gfx::SizeF measureTrack(PaintSurface& surface);
80 
81  Gfx::SizeF measureHandle(PaintSurface& surface);
82 
83  void layoutChrome(PaintSurface& surface,
84  const Gfx::RectF& rect,
85  const Gfx::SizeF& trackSize,
86  const Gfx::SizeF& handleSize,
87  Gfx::RectF& trackRect,
88  Gfx::RectF& handleRect);
89 
90  void layoutHandle(PaintSurface& surface,
91  const Gfx::RectF& trackRect,
92  float fraction,
93  Gfx::RectF& handleRect);
94 
95  void renderChrome(PaintContext& context,
96  const Gfx::RectF& rect,
97  const Gfx::RectF& trackRect,
98  const Gfx::RectF& handleRect,
99  const SliderState& state);
100 
101  void renderTrack(PaintContext& context,
102  const Gfx::RectF& trackRect,
103  const SliderState& state);
104 
105  void renderHandle(PaintContext& context,
106  const Gfx::RectF& handleRect,
107  const SliderState& state);
108 
109  protected:
110  virtual SliderRenderer* onCreate() const = 0;
111 
114  virtual void onReset(const StyleOptions& options) = 0;
115 
116  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
117  const Gfx::SizeF& contentSize) = 0;
118 
119  virtual Gfx::SizeF onMeasureTrack(PaintSurface& surface) = 0;
120 
121  virtual Gfx::SizeF onMeasureHandle(PaintSurface& surface) = 0;
122 
123  virtual void onLayoutChrome(PaintSurface& surface,
124  const Gfx::RectF& rect,
125  const Gfx::SizeF& trackSize,
126  const Gfx::SizeF& handleSize,
127  Gfx::RectF& trackRect,
128  Gfx::RectF& handleRect) = 0;
129 
130  virtual void onLayoutHandle(PaintSurface& surface,
131  const Gfx::RectF& trackRect,
132  float fraction,
133  Gfx::RectF& handleRect) = 0;
134 
135  virtual void onRenderChrome(PaintContext& context,
136  const Gfx::RectF& rect,
137  const Gfx::RectF& trackRect,
138  const Gfx::RectF& handleRect,
139  const SliderState& state);
140 
141  virtual void onRenderTrack(PaintContext& context,
142  const Gfx::RectF& trackRect,
143  const SliderState& state) = 0;
144 
145  virtual void onRenderHandle(PaintContext& context,
146  const Gfx::RectF& handleRect,
147  const SliderState& state) = 0;
148 };
149 
150 
153 class PT_FORMS_API SliderStyler : public Styler
154 {
155  public:
159 
162  const Gfx::Brush& background() const;
163 
166  void setBackground(const Gfx::Brush& brush);
167 
170  const Gfx::Brush& foreground() const;
171 
174  void setForeground(const Gfx::Brush& brush);
175 
178  const Gfx::Pen& contour() const;
179 
182  void setContour(const Gfx::Pen& pen);
183 
186  const Gfx::Color& textColor() const;
187 
190  void setTextColor(const Gfx::Color& color);
191 
194  Gfx::Font font() const;
195 
198  void setFont(const Gfx::Font& font);
199 
202  void setFontSize(std::size_t size);
203 
207 
211 
215  const Gfx::SizeF& contentSize) const;
216 
220 
224 
227  void layoutChrome(PaintSurface& surface,
228  const Gfx::RectF& rect,
229  const Gfx::SizeF& trackSize,
230  const Gfx::SizeF& handleSize,
231  Gfx::RectF& trackRect,
232  Gfx::RectF& handleRect) const;
233 
236  void layoutHandle(PaintSurface& surface,
237  const Gfx::RectF& trackRect,
238  float fraction,
239  Gfx::RectF& handleRect) const;
240 
243  void renderChrome(PaintContext& context,
244  const Gfx::RectF& rect,
245  const Gfx::RectF& trackRect,
246  const Gfx::RectF& handleRect,
247  const SliderState& state) const;
248 
251  void setRenderer(SliderRenderer* renderer = 0);
252 
256 
259  const StyleOptions& options() const;
260 
261  protected:
264  virtual StyleOptions& onBindOptions(const StyleOptions& global);
265 
268  virtual Renderer* onStyleRenderer(const Style& style);
269 
272  virtual Renderer* onCreateRenderer(const Style& style);
273 
274  private:
275  FacetPtr<SliderRenderer> _renderer;
276  StyleOptions _options;
277 };
278 
279 } // namespace
280 
281 } // namespace
282 
283 #endif
Core module.
Definition: Allocator.h:33
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
Slider styler.
Definition: SliderStyler.h:154
const StyleOptions & options() const
Returns the bound effective slider options.
Attributes for the drawing of outlines.
Definition: Pen.h:54
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &trackRect, const Gfx::RectF &handleRect, const SliderState &state) const
Renders the slider chrome within rect for state.
SliderStyler()
Constructs an unbound slider styler.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setRenderer(SliderRenderer *renderer=0)
Assigns a specific slider renderer.
Gfx::Font font() const
Returns the effective font.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
Paint context.
Definition: PaintContext.h:45
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independent slider renderer from style.
Size with floating-point width and height.
Definition: Size.h:47
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
SliderRenderer * create() const
Creates a new default-constructed slider renderer.
Gfx::SizeF measureTrack(PaintSurface &surface) const
Measures the slider track.
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush to brush.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
const Gfx::Brush & background() const
Returns the effective background brush.
Weight
Describes the requested font weight.
Definition: Font.h:61
Style for widgets.
Definition: Style.h:155
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds local slider options to global and returns them.
Gfx::SizeF measureHandle(PaintSurface &surface) const
Measures the slider handle.
StyleOptions & options()
Returns the bound effective slider options.
const Gfx::Pen & contour() const
Returns the effective contour pen.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Font request used for text drawing and measurement.
Definition: Font.h:56
Style options container.
Definition: StyleOptions.h:535
virtual void onReset(const StyleOptions &options)=0
Standard color type.
Definition: Color.h:47
void layoutHandle(PaintSurface &surface, const Gfx::RectF &trackRect, float fraction, Gfx::RectF &handleRect) const
Lays out the handle for fraction along trackRect.
Fill description for shapes and text.
Definition: Brush.h:145
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, const Gfx::SizeF &trackSize, const Gfx::SizeF &handleSize, Gfx::RectF &trackRect, Gfx::RectF &handleRect) const
Lays out the slider track and handle rectangles.
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared slider renderer from style.
Rect with floating-point coordinates.
Definition: Rect.h:47
virtual SliderRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
const Gfx::Color & textColor() const
Returns the effective text color.
Renders the visual appearance of a slider.
Definition: SliderStyler.h:65