ProgressBarStyler.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_PROGRESSBARSTYLE_H
30 #define PT_FORMS_PROGRESSBARSTYLE_H
31 
32 #include <Pt/Forms/Styler.h>
33 
34 namespace Pt {
35 
36 namespace Forms {
37 
38 class PT_FORMS_API ProgressBarState
39 {
40  public:
41  ProgressBarState();
42 
43  bool isEnabled() const;
44 
45  void setEnabled(bool value);
46 
47  bool isFocused() const;
48 
49  void setFocused(bool value);
50 
51  private:
52  bool _enabled;
53  bool _focused;
54 };
55 
58 class PT_FORMS_API ProgressBarRenderer : public Renderer
59 {
60  public:
61  explicit ProgressBarRenderer(std::size_t refs = 0);
62 
63  virtual ~ProgressBarRenderer();
64 
65  ProgressBarRenderer* create() const;
66 
67  public:
68  Gfx::SizeF measureFrame(PaintSurface& surface,
69  const Gfx::SizeF& contentSize);
70 
71  Gfx::SizeF measureBar(PaintSurface& surface);
72 
73  void layoutChrome(PaintSurface& surface,
74  const Gfx::RectF& rect,
75  const Gfx::SizeF& barSize,
76  const Gfx::SizeF& textSize,
77  Gfx::RectF& barRect,
78  Gfx::RectF& textRect);
79 
80  void layoutBar(PaintSurface& surface,
81  const Gfx::RectF& barRect,
82  float progressRatio,
83  Gfx::RectF& trackRect,
84  Gfx::RectF& chunkRect);
85 
86  const Painter& textPainter(PaintSurface& surface);
87 
88  void renderChrome(PaintContext& context,
89  const Gfx::RectF& rect,
90  const Gfx::RectF& trackRect,
91  const Gfx::RectF& chunkRect,
92  const Gfx::RectF& textRect,
93  const String& text,
94  const Gfx::PointF& textPos,
95  const ProgressBarState& state);
96 
97  void renderBar(PaintContext& context,
98  const Gfx::RectF& trackRect,
99  const Gfx::RectF& chunkRect,
100  const ProgressBarState& state);
101 
102  void renderTrack(PaintContext& context,
103  const Gfx::RectF& trackRect,
104  const ProgressBarState& state);
105 
106  void renderChunk(PaintContext& context,
107  const Gfx::RectF& chunkRect,
108  const ProgressBarState& state);
109 
110  void renderText(PaintContext& context,
111  const Gfx::RectF& textRect,
112  const Gfx::RectF& chunkRect,
113  const String& text,
114  const Gfx::PointF& textPos,
115  const ProgressBarState& state);
116 
117  protected:
118  virtual ProgressBarRenderer* onCreate() const = 0;
119 
122  virtual void onReset(const StyleOptions& options) = 0;
123 
124  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
125  const Gfx::SizeF& contentSize) = 0;
126 
127  virtual Gfx::SizeF onMeasureBar(PaintSurface& surface) = 0;
128 
129  virtual void onLayoutChrome(PaintSurface& surface,
130  const Gfx::RectF& rect,
131  const Gfx::SizeF& barSize,
132  const Gfx::SizeF& textSize,
133  Gfx::RectF& barRect,
134  Gfx::RectF& textRect) = 0;
135 
136  virtual void onLayoutBar(PaintSurface& surface,
137  const Gfx::RectF& barRect,
138  float progressRatio,
139  Gfx::RectF& trackRect,
140  Gfx::RectF& chunkRect) = 0;
141 
142  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
143 
144  virtual void onRenderChrome(PaintContext& context,
145  const Gfx::RectF& rect,
146  const Gfx::RectF& trackRect,
147  const Gfx::RectF& chunkRect,
148  const Gfx::RectF& textRect,
149  const String& text,
150  const Gfx::PointF& textPos,
151  const ProgressBarState& state);
152 
153  virtual void onRenderBar(PaintContext& context,
154  const Gfx::RectF& trackRect,
155  const Gfx::RectF& chunkRect,
156  const ProgressBarState& state);
157 
158  virtual void onRenderTrack(PaintContext& context,
159  const Gfx::RectF& trackRect,
160  const ProgressBarState& state) = 0;
161 
162  virtual void onRenderChunk(PaintContext& context,
163  const Gfx::RectF& chunkRect,
164  const ProgressBarState& state) = 0;
165 
166  virtual void onRenderText(PaintContext& context,
167  const Gfx::RectF& textRect,
168  const Gfx::RectF& chunkRect,
169  const String& text,
170  const Gfx::PointF& textPos,
171  const ProgressBarState& state) = 0;
172 };
173 
176 class PT_FORMS_API ProgressBarStyler : public Styler
177 {
178  public:
182 
185  const Gfx::Brush& background() const;
186 
189  void setBackground(const Gfx::Brush& brush);
190 
193  const Gfx::Brush& foreground() const;
194 
197  void setForeground(const Gfx::Brush& brush);
198 
201  const Gfx::Pen& contour() const;
202 
205  void setContour(const Gfx::Pen& pen);
206 
209  const Gfx::Color& textColor() const;
210 
213  void setTextColor(const Gfx::Color& color);
214 
217  Gfx::Font font() const;
218 
221  void setFont(const Gfx::Font& font);
222 
225  void setFontSize(std::size_t size);
226 
230 
234 
238  const Gfx::SizeF& contentSize) const;
239 
243 
246  void layoutChrome(PaintSurface& surface,
247  const Gfx::RectF& rect,
248  const Gfx::SizeF& barSize,
249  const Gfx::SizeF& textSize,
250  Gfx::RectF& barRect,
251  Gfx::RectF& textRect) const;
252 
255  void layoutBar(PaintSurface& surface,
256  const Gfx::RectF& barRect,
257  float progressRatio,
258  Gfx::RectF& trackRect,
259  Gfx::RectF& chunkRect) const;
260 
263  const Painter* textPainter(PaintSurface& surface) const;
264 
267  void renderChrome(PaintContext& context,
268  const Gfx::RectF& rect,
269  const Gfx::RectF& trackRect,
270  const Gfx::RectF& chunkRect,
271  const Gfx::RectF& textRect,
272  const String& text,
273  const Gfx::PointF& textPos,
274  const ProgressBarState& state) const;
275 
278  void renderBar(PaintContext& context,
279  const Gfx::RectF& trackRect,
280  const Gfx::RectF& chunkRect,
281  const ProgressBarState& state) const;
282 
285  void renderTrack(PaintContext& context,
286  const Gfx::RectF& trackRect,
287  const ProgressBarState& state) const;
288 
291  void renderChunk(PaintContext& context,
292  const Gfx::RectF& chunkRect,
293  const ProgressBarState& state) const;
294 
297  void renderText(PaintContext& context,
298  const Gfx::RectF& textRect,
299  const Gfx::RectF& chunkRect,
300  const String& text,
301  const Gfx::PointF& textPos,
302  const ProgressBarState& state) const;
303 
306  void setRenderer(ProgressBarRenderer* renderer = 0);
307 
313 
316  const StyleOptions& options() const;
317 
318  protected:
319  virtual StyleOptions& onBindOptions(const StyleOptions& styleOptions);
320 
321  virtual Renderer* onStyleRenderer(const Style& style);
322 
323  virtual Renderer* onCreateRenderer(const Style& style);
324 
325  private:
326  FacetPtr<ProgressBarRenderer> _renderer;
327  StyleOptions _options;
328 };
329 
330 } // namespace
331 
332 } // namespace
333 
334 #endif
Core module.
Definition: Allocator.h:33
Renders the visual appearance of a progress bar.
Definition: ProgressBarStyler.h:59
Progress bar styler.
Definition: ProgressBarStyler.h:177
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush to brush.
const Painter * textPainter(PaintSurface &surface) const
Returns the text painter for surface, or 0 when unavailable.
Attributes for the drawing of outlines.
Definition: Pen.h:54
StyleOptions & options()
Returns the bound effective progress bar options.
void layoutBar(PaintSurface &surface, const Gfx::RectF &barRect, float progressRatio, Gfx::RectF &trackRect, Gfx::RectF &chunkRect) const
Lays out the track and chunk rectangles.
void renderChunk(PaintContext &context, const Gfx::RectF &chunkRect, const ProgressBarState &state) const
Renders the chunk.
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, const Gfx::SizeF &barSize, const Gfx::SizeF &textSize, Gfx::RectF &barRect, Gfx::RectF &textRect) const
Lays out the bar and text rectangles.
void renderTrack(PaintContext &context, const Gfx::RectF &trackRect, const ProgressBarState &state) const
Renders the track.
virtual void onReset(const StyleOptions &options)=0
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
virtual ProgressBarRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
const Gfx::Pen & contour() const
Returns the effective contour pen.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &trackRect, const Gfx::RectF &chunkRect, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const ProgressBarState &state) const
Renders the chrome within rect.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Size with floating-point width and height.
Definition: Size.h:47
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
ProgressBarStyler()
Constructs an unbound progress bar styler.
const StyleOptions & options() const
Returns the bound effective progress bar options.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const Gfx::RectF &chunkRect, const String &text, const Gfx::PointF &textPos, const ProgressBarState &state) const
Renders the text.
Weight
Describes the requested font weight.
Definition: Font.h:61
Style for widgets.
Definition: Style.h:155
virtual StyleOptions & onBindOptions(const StyleOptions &styleOptions)
Returns the specific style options.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void setRenderer(ProgressBarRenderer *renderer=0)
Assigns a specific progress bar renderer.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
Gfx::Font font() const
Returns the effective font.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
Font request used for text drawing and measurement.
Definition: Font.h:56
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Style options container.
Definition: StyleOptions.h:535
const Gfx::Color & textColor() const
Returns the effective text color.
Standard color type.
Definition: Color.h:47
Unicode capable basic_string.
Definition: Api-String.h:44
Gfx::SizeF measureBar(PaintSurface &surface) const
Measures the bar's natural size.
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
void renderBar(PaintContext &context, const Gfx::RectF &trackRect, const Gfx::RectF &chunkRect, const ProgressBarState &state) const
Renders the bar.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
const Gfx::Brush & background() const
Returns the effective background brush.