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
34namespace Pt {
35
36namespace Forms {
37
46class PT_FORMS_API SliderState
47{
48 public:
52
55 bool isEnabled() const;
56
59 void setEnabled(bool value);
60
63 bool isHovered() const;
64
67 void setHovered(bool value);
68
71 bool isFocused() const;
72
75 void setFocused(bool value);
76
77 private:
78 bool _enabled;
79 bool _hovered;
80 bool _focused;
81};
82
83
103class PT_FORMS_API SliderRenderer : public Renderer
104{
105 public:
108 explicit SliderRenderer(std::size_t refs = 0);
109
113
117
118 public:
121 Gfx::SizeF measureFrame(PaintSurface& surface,
122 const Gfx::SizeF& contentSize);
123
126 Gfx::SizeF measureTrack(PaintSurface& surface);
127
130 Gfx::SizeF measureHandle(PaintSurface& surface);
131
135 const Gfx::RectF& rect,
136 const Gfx::SizeF& trackSize,
137 const Gfx::SizeF& handleSize,
138 Gfx::RectF& trackRect,
139 Gfx::RectF& handleRect);
140
144 const Gfx::RectF& trackRect,
145 float fraction,
146 Gfx::RectF& handleRect);
147
151 const Gfx::RectF& rect,
152 const Gfx::RectF& trackRect,
153 const Gfx::RectF& handleRect,
154 const SliderState& state);
155
159 const Gfx::RectF& trackRect,
160 const SliderState& state);
161
165 const Gfx::RectF& handleRect,
166 const SliderState& state);
167
168 protected:
171 virtual SliderRenderer* onCreate() const = 0;
172
175 virtual void onReset(const StyleOptions& options) = 0;
176
179 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
180 const Gfx::SizeF& contentSize) = 0;
181
184 virtual Gfx::SizeF onMeasureTrack(PaintSurface& surface) = 0;
185
188 virtual Gfx::SizeF onMeasureHandle(PaintSurface& surface) = 0;
189
192 virtual void onLayoutChrome(PaintSurface& surface,
193 const Gfx::RectF& rect,
194 const Gfx::SizeF& trackSize,
195 const Gfx::SizeF& handleSize,
196 Gfx::RectF& trackRect,
197 Gfx::RectF& handleRect) = 0;
198
201 virtual void onLayoutHandle(PaintSurface& surface,
202 const Gfx::RectF& trackRect,
203 float fraction,
204 Gfx::RectF& handleRect) = 0;
205
208 virtual void onRenderChrome(PaintContext& context,
209 const Gfx::RectF& rect,
210 const Gfx::RectF& trackRect,
211 const Gfx::RectF& handleRect,
212 const SliderState& state);
213
216 virtual void onRenderTrack(PaintContext& context,
217 const Gfx::RectF& trackRect,
218 const SliderState& state) = 0;
219
222 virtual void onRenderHandle(PaintContext& context,
223 const Gfx::RectF& handleRect,
224 const SliderState& state) = 0;
225};
226
227
243class PT_FORMS_API SliderStyler : public Styler
244{
245 public:
249
252 const Gfx::Brush& background() const;
253
256 void setBackground(const Gfx::Brush& brush);
257
260 const Gfx::Brush& foreground() const;
261
264 void setForeground(const Gfx::Brush& brush);
265
268 const Gfx::Pen& contour() const;
269
272 void setContour(const Gfx::Pen& pen);
273
276 const Gfx::Color& textColor() const;
277
280 void setTextColor(const Gfx::Color& color);
281
285
288 void setFont(const Gfx::Font& font);
289
292 void setFontSize(std::size_t size);
293
297
301
304 Gfx::SizeF measureFrame(PaintSurface& surface,
305 const Gfx::SizeF& contentSize) const;
306
309 Gfx::SizeF measureTrack(PaintSurface& surface) const;
310
313 Gfx::SizeF measureHandle(PaintSurface& surface) const;
314
318 const Gfx::RectF& rect,
319 const Gfx::SizeF& trackSize,
320 const Gfx::SizeF& handleSize,
321 Gfx::RectF& trackRect,
322 Gfx::RectF& handleRect) const;
323
327 const Gfx::RectF& trackRect,
328 float fraction,
329 Gfx::RectF& handleRect) const;
330
334 const Gfx::RectF& rect,
335 const Gfx::RectF& trackRect,
336 const Gfx::RectF& handleRect,
337 const SliderState& state) const;
338
343 void setRenderer(SliderRenderer* renderer = 0);
344
348
351 const StyleOptions& options() const;
352
353 protected:
356 virtual StyleOptions& onBindOptions(const StyleOptions& global);
357
360 virtual Renderer* onStyleRenderer(const Style& style);
361
364 virtual Renderer* onCreateRenderer(const Style& style);
365
366 private:
367 FacetPtr<SliderRenderer> _renderer;
368 StyleOptions _options;
369};
370
371} // namespace
372
373} // namespace
374
375#endif
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 slider.
Definition SliderStyler.h:104
void layoutHandle(PaintSurface &surface, const Gfx::RectF &trackRect, float fraction, Gfx::RectF &handleRect)
Places the handle for fraction along trackRect.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
SliderRenderer * create() const
Creates a new default-constructed instance that the caller owns.
Gfx::SizeF measureTrack(PaintSurface &surface)
Returns the natural size of the track.
Gfx::SizeF measureHandle(PaintSurface &surface)
Returns the natural size of the handle.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &trackRect, const Gfx::RectF &handleRect, const SliderState &state)
Paints track and handle for state.
virtual SliderRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the frame enclosing contentSize.
virtual void onRenderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &trackRect, const Gfx::RectF &handleRect, const SliderState &state)
Paints track and handle for state.
void renderHandle(PaintContext &context, const Gfx::RectF &handleRect, const SliderState &state)
Paints the handle for state.
virtual Gfx::SizeF onMeasureTrack(PaintSurface &surface)=0
Returns the natural size of the track.
virtual void onRenderHandle(PaintContext &context, const Gfx::RectF &handleRect, const SliderState &state)=0
Paints the handle for state.
virtual ~SliderRenderer()
Destroys the renderer.
SliderRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
virtual void onRenderTrack(PaintContext &context, const Gfx::RectF &trackRect, const SliderState &state)=0
Paints the track for state.
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, const Gfx::SizeF &trackSize, const Gfx::SizeF &handleSize, Gfx::RectF &trackRect, Gfx::RectF &handleRect)
Places the track and handle in rect.
virtual void onLayoutChrome(PaintSurface &surface, const Gfx::RectF &rect, const Gfx::SizeF &trackSize, const Gfx::SizeF &handleSize, Gfx::RectF &trackRect, Gfx::RectF &handleRect)=0
Places the track and handle in rect.
void renderTrack(PaintContext &context, const Gfx::RectF &trackRect, const SliderState &state)
Paints the track for state.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
virtual void onLayoutHandle(PaintSurface &surface, const Gfx::RectF &trackRect, float fraction, Gfx::RectF &handleRect)=0
Places the handle for fraction along trackRect.
virtual Gfx::SizeF onMeasureHandle(PaintSurface &surface)=0
Returns the natural size of the handle.
Transient visual state of a slider.
Definition SliderStyler.h:47
bool isFocused() const
Returns true if the slider currently has focus.
void setFocused(bool value)
Sets whether the slider has focus.
void setHovered(bool value)
Sets whether the pointer is over the slider.
SliderState()
Constructs an empty slider state.
bool isEnabled() const
Returns true if the slider is currently enabled.
void setEnabled(bool value)
Sets whether the slider is enabled.
bool isHovered() const
Returns true if the pointer is currently over the slider.
void setRenderer(SliderRenderer *renderer=0)
Assigns a specific slider renderer.
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.
StyleOptions & options()
Returns the bound effective slider options.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared slider renderer from style, or 0.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the overlay to global and returns it.
Gfx::SizeF measureHandle(PaintSurface &surface) const
Measures the slider handle.
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.
Gfx::Font font() const
Returns the effective font.
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.
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) const
Measures the frame enclosing contentSize.
const StyleOptions & options() const
Returns the bound effective slider options.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Gfx::SizeF measureTrack(PaintSurface &surface) const
Measures the slider track.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
SliderStyler()
Constructs an unbound slider styler.
void layoutHandle(PaintSurface &surface, const Gfx::RectF &trackRect, float fraction, Gfx::RectF &handleRect) const
Lays out the handle for fraction along trackRect.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
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
8-bit ARGB color.
Definition Color.h:65
Font family, size and style.
Definition Font.h:63
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Outline color, width and style.
Definition Pen.h:59
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33