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
34namespace Pt {
35
36namespace Forms {
37
46class PT_FORMS_API ProgressBarState
47{
48 public:
52
55 bool isEnabled() const;
56
59 void setEnabled(bool value);
60
63 bool isFocused() const;
64
67 void setFocused(bool value);
68
69 private:
70 bool _enabled;
71 bool _focused;
72};
73
87class PT_FORMS_API ProgressBarRenderer : public Renderer
88{
89 public:
92 explicit ProgressBarRenderer(std::size_t refs = 0);
93
97
101
102 public:
105 Gfx::SizeF measureFrame(PaintSurface& surface,
106 const Gfx::SizeF& contentSize);
107
110 Gfx::SizeF measureBar(PaintSurface& surface);
111
115 const Gfx::RectF& rect,
116 const Gfx::SizeF& barSize,
117 const Gfx::SizeF& textSize,
118 Gfx::RectF& barRect,
119 Gfx::RectF& textRect);
120
123 void layoutBar(PaintSurface& surface,
124 const Gfx::RectF& barRect,
125 float progressRatio,
126 Gfx::RectF& trackRect,
127 Gfx::RectF& chunkRect);
128
132
136 const Gfx::RectF& rect,
137 const Gfx::RectF& trackRect,
138 const Gfx::RectF& chunkRect,
139 const Gfx::RectF& textRect,
140 const String& text,
141 const Gfx::PointF& textPos,
142 const ProgressBarState& state);
143
146 void renderBar(PaintContext& context,
147 const Gfx::RectF& trackRect,
148 const Gfx::RectF& chunkRect,
149 const ProgressBarState& state);
150
154 const Gfx::RectF& trackRect,
155 const ProgressBarState& state);
156
160 const Gfx::RectF& chunkRect,
161 const ProgressBarState& state);
162
166 const Gfx::RectF& textRect,
167 const Gfx::RectF& chunkRect,
168 const String& text,
169 const Gfx::PointF& textPos,
170 const ProgressBarState& state);
171
172 protected:
175 virtual ProgressBarRenderer* onCreate() const = 0;
176
179 virtual void onReset(const StyleOptions& options) = 0;
180
183 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
184 const Gfx::SizeF& contentSize) = 0;
185
188 virtual Gfx::SizeF onMeasureBar(PaintSurface& surface) = 0;
189
192 virtual void onLayoutChrome(PaintSurface& surface,
193 const Gfx::RectF& rect,
194 const Gfx::SizeF& barSize,
195 const Gfx::SizeF& textSize,
196 Gfx::RectF& barRect,
197 Gfx::RectF& textRect) = 0;
198
201 virtual void onLayoutBar(PaintSurface& surface,
202 const Gfx::RectF& barRect,
203 float progressRatio,
204 Gfx::RectF& trackRect,
205 Gfx::RectF& chunkRect) = 0;
206
209 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
210
213 virtual void onRenderChrome(PaintContext& context,
214 const Gfx::RectF& rect,
215 const Gfx::RectF& trackRect,
216 const Gfx::RectF& chunkRect,
217 const Gfx::RectF& textRect,
218 const String& text,
219 const Gfx::PointF& textPos,
220 const ProgressBarState& state);
221
224 virtual void onRenderBar(PaintContext& context,
225 const Gfx::RectF& trackRect,
226 const Gfx::RectF& chunkRect,
227 const ProgressBarState& state);
228
231 virtual void onRenderTrack(PaintContext& context,
232 const Gfx::RectF& trackRect,
233 const ProgressBarState& state) = 0;
234
237 virtual void onRenderChunk(PaintContext& context,
238 const Gfx::RectF& chunkRect,
239 const ProgressBarState& state) = 0;
240
243 virtual void onRenderText(PaintContext& context,
244 const Gfx::RectF& textRect,
245 const Gfx::RectF& chunkRect,
246 const String& text,
247 const Gfx::PointF& textPos,
248 const ProgressBarState& state) = 0;
249};
250
266class PT_FORMS_API ProgressBarStyler : public Styler
267{
268 public:
272
275 const Gfx::Brush& background() const;
276
279 void setBackground(const Gfx::Brush& brush);
280
283 const Gfx::Brush& foreground() const;
284
287 void setForeground(const Gfx::Brush& brush);
288
291 const Gfx::Pen& contour() const;
292
295 void setContour(const Gfx::Pen& pen);
296
299 const Gfx::Color& textColor() const;
300
303 void setTextColor(const Gfx::Color& color);
304
308
311 void setFont(const Gfx::Font& font);
312
315 void setFontSize(std::size_t size);
316
320
324
327 Gfx::SizeF measureFrame(PaintSurface& surface,
328 const Gfx::SizeF& contentSize) const;
329
332 Gfx::SizeF measureBar(PaintSurface& surface) const;
333
337 const Gfx::RectF& rect,
338 const Gfx::SizeF& barSize,
339 const Gfx::SizeF& textSize,
340 Gfx::RectF& barRect,
341 Gfx::RectF& textRect) const;
342
345 void layoutBar(PaintSurface& surface,
346 const Gfx::RectF& barRect,
347 float progressRatio,
348 Gfx::RectF& trackRect,
349 Gfx::RectF& chunkRect) const;
350
353 const Painter* textPainter(PaintSurface& surface) const;
354
358 const Gfx::RectF& rect,
359 const Gfx::RectF& trackRect,
360 const Gfx::RectF& chunkRect,
361 const Gfx::RectF& textRect,
362 const String& text,
363 const Gfx::PointF& textPos,
364 const ProgressBarState& state) const;
365
368 void renderBar(PaintContext& context,
369 const Gfx::RectF& trackRect,
370 const Gfx::RectF& chunkRect,
371 const ProgressBarState& state) const;
372
376 const Gfx::RectF& trackRect,
377 const ProgressBarState& state) const;
378
382 const Gfx::RectF& chunkRect,
383 const ProgressBarState& state) const;
384
388 const Gfx::RectF& textRect,
389 const Gfx::RectF& chunkRect,
390 const String& text,
391 const Gfx::PointF& textPos,
392 const ProgressBarState& state) const;
393
396 void setRenderer(ProgressBarRenderer* renderer = 0);
397
403
406 const StyleOptions& options() const;
407
408 protected:
411 virtual StyleOptions& onBindOptions(const StyleOptions& styleOptions);
412
415 virtual Renderer* onStyleRenderer(const Style& style);
416
419 virtual Renderer* onCreateRenderer(const Style& style);
420
421 private:
423 StyleOptions _options;
424};
425
426} // namespace
427
428} // namespace
429
430#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
Draws on a Forms paint surface or paint context.
Definition Painter.h:53
Renders the look of a progress bar.
Definition ProgressBarStyler.h:88
ProgressBarRenderer * create() const
Creates a new default-constructed instance that the caller owns.
void renderChunk(PaintContext &context, const Gfx::RectF &chunkRect, const ProgressBarState &state)
Paints the filled portion for state.
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const Gfx::RectF &chunkRect, const String &text, const Gfx::PointF &textPos, const ProgressBarState &state)
Paints text at textPos for state.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
virtual void onLayoutChrome(PaintSurface &surface, const Gfx::RectF &rect, const Gfx::SizeF &barSize, const Gfx::SizeF &textSize, Gfx::RectF &barRect, Gfx::RectF &textRect)=0
Places the track and text rectangles in rect.
void layoutBar(PaintSurface &surface, const Gfx::RectF &barRect, float progressRatio, Gfx::RectF &trackRect, Gfx::RectF &chunkRect)
Places the track and filled portion for progressRatio.
void renderTrack(PaintContext &context, const Gfx::RectF &trackRect, const ProgressBarState &state)
Paints the track for state.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the frame enclosing contentSize.
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)
Paints track, filled portion, and text for state.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color.
virtual Gfx::SizeF onMeasureBar(PaintSurface &surface)=0
Returns the natural size of the track.
virtual ~ProgressBarRenderer()
Destroys the renderer.
Gfx::SizeF measureBar(PaintSurface &surface)
Returns the natural size of the track.
virtual void onRenderChunk(PaintContext &context, const Gfx::RectF &chunkRect, const ProgressBarState &state)=0
Paints the filled portion for state.
virtual void onRenderTrack(PaintContext &context, const Gfx::RectF &trackRect, const ProgressBarState &state)=0
Paints the track for state.
virtual void onRenderBar(PaintContext &context, const Gfx::RectF &trackRect, const Gfx::RectF &chunkRect, const ProgressBarState &state)
Paints the track and filled portion for state.
virtual void onRenderText(PaintContext &context, const Gfx::RectF &textRect, const Gfx::RectF &chunkRect, const String &text, const Gfx::PointF &textPos, const ProgressBarState &state)=0
Paints text at textPos for state.
virtual ProgressBarRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
void renderBar(PaintContext &context, const Gfx::RectF &trackRect, const Gfx::RectF &chunkRect, const ProgressBarState &state)
Paints the track and filled portion for state.
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, const Gfx::SizeF &barSize, const Gfx::SizeF &textSize, Gfx::RectF &barRect, Gfx::RectF &textRect)
Places the track and text rectangles in rect.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
ProgressBarRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
virtual void onLayoutBar(PaintSurface &surface, const Gfx::RectF &barRect, float progressRatio, Gfx::RectF &trackRect, Gfx::RectF &chunkRect)=0
Places the track and filled portion for progressRatio.
virtual void onRenderChrome(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)
Paints track, filled portion, and text for state.
Transient visual state of a progress bar.
Definition ProgressBarStyler.h:47
bool isFocused() const
Returns true if the widget currently has focus.
ProgressBarState()
Constructs an empty progress bar state.
void setFocused(bool value)
Sets whether the widget has focus.
bool isEnabled() const
Returns true if the widget is currently enabled.
void setEnabled(bool value)
Sets whether the widget is enabled.
StyleOptions & options()
Returns the bound effective progress bar options.
const Gfx::Color & textColor() const
Returns the effective text color.
Gfx::SizeF measureBar(PaintSurface &surface) const
Measures the bar's natural size.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared progress-bar renderer from style, or 0.
void renderTrack(PaintContext &context, const Gfx::RectF &trackRect, const ProgressBarState &state) const
Renders the track.
void setRenderer(ProgressBarRenderer *renderer=0)
Assigns a specific progress bar renderer.
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 &chunkRect, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const ProgressBarState &state) const
Renders the chrome within rect.
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.
const Painter * textPainter(PaintSurface &surface) const
Returns the text painter for surface, or 0 when unavailable.
ProgressBarStyler()
Constructs an unbound progress 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.
void renderBar(PaintContext &context, const Gfx::RectF &trackRect, const Gfx::RectF &chunkRect, const ProgressBarState &state) const
Renders the bar.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
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.
const StyleOptions & options() const
Returns the bound effective progress bar options.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
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.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
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.
virtual StyleOptions & onBindOptions(const StyleOptions &styleOptions)
Binds the overlay to styleOptions and returns it.
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.
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
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
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33