CheckBoxStyler.h
1/* Copyright (C) 2016 Laurentiu-Gheorghe Crisan
2 Copyright (C) 2016 Marc Boris Duerner
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 As a special exception, you may use this file as part of a free
10 software library without restriction. Specifically, if other files
11 instantiate templates or use macros or inline functions from this
12 file, or you compile this file and link it with other files to
13 produce an executable, this file does not by itself cause the
14 resulting executable to be covered by the GNU General Public
15 License. This exception does not however invalidate any other
16 reasons why the executable file might be covered by the GNU Library
17 General Public License.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 MA 02110-1301 USA
28*/
29
30#ifndef Pt_Forms_CheckBoxStyler_h
31#define Pt_Forms_CheckBoxStyler_h
32
33#include <Pt/Forms/Styler.h>
34
35namespace Pt {
36
37namespace Forms {
38
47class PT_FORMS_API CheckBoxState
48{
49 public:
53
56 bool isEnabled() const;
57
60 void setEnabled(bool value);
61
64 bool isHovered() const;
65
68 void setHovered(bool value);
69
72 bool isFocused() const;
73
76 void setFocused(bool value);
77
80 bool isChecked() const;
81
84 void setChecked(bool value);
85
86 private:
87 bool _enabled;
88 bool _hovered;
89 bool _focused;
90 bool _checked;
91};
92
107class PT_FORMS_API CheckBoxRenderer : public Renderer
108{
109 public:
112 explicit CheckBoxRenderer(std::size_t refs = 0);
113
117
121
122 public:
125 Gfx::SizeF measureIndicator(PaintSurface& surface);
126
129 Gfx::SizeF measureContent(PaintSurface& surface,
130 const Gfx::SizeF& indicatorSize,
131 const Gfx::SizeF& textSize);
132
135 Gfx::SizeF measureFrame(PaintSurface& surface,
136 const Gfx::SizeF& contentSize);
137
140 Gfx::RectF layoutFrame(PaintSurface& surface,
141 const Gfx::RectF& frameRect);
142
146 const Gfx::RectF& contentRect,
147 const Gfx::SizeF& indicatorSize,
148 const Gfx::SizeF& textSize,
149 Gfx::RectF& indicatorRect,
150 Gfx::RectF& textRect);
151
154 Gfx::RectF layoutMnemonic(PaintSurface& surface,
155 const String& text,
156 const Gfx::PointF& textPos,
157 const Gfx::FontMetrics& fontMetrics,
158 String::size_type mnemonicIndex);
159
163
167 const Gfx::RectF& rect,
168 const Gfx::RectF& boxRect,
169 const CheckBoxState& state);
170
174 const Gfx::RectF& textRect,
175 const String& text,
176 const Gfx::PointF& pos,
177 const CheckBoxState& state);
178
182 const Gfx::RectF& rect,
183 const Gfx::RectF& mnemonic,
184 const CheckBoxState& state);
185
186 protected:
189 virtual CheckBoxRenderer* onCreate() const = 0;
190
193 virtual void onReset(const StyleOptions& options) = 0;
194
197 virtual Gfx::SizeF onMeasureIndicator(PaintSurface& surface) = 0;
198
201 virtual Gfx::SizeF onMeasureContent(PaintSurface& surface,
202 const Gfx::SizeF& indicatorSize,
203 const Gfx::SizeF& textSize) = 0;
204
207 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
208 const Gfx::SizeF& contentSize) = 0;
209
212 virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
213 const Gfx::RectF& frameRect) = 0;
214
217 virtual void onLayoutContent(PaintSurface& surface,
218 const Gfx::RectF& contentRect,
219 const Gfx::SizeF& indicatorSize,
220 const Gfx::SizeF& textSize,
221 Gfx::RectF& indicatorRect,
222 Gfx::RectF& textRect) = 0;
223
226 virtual Gfx::RectF onLayoutMnemonic(PaintSurface& surface,
227 const String& text,
228 const Gfx::PointF& textPos,
229 const Gfx::FontMetrics& fontMetrics,
230 String::size_type mnemonicIndex) = 0;
231
234 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
235
238 virtual void onRenderChrome(PaintContext& context,
239 const Gfx::RectF& rect,
240 const Gfx::RectF& boxRect,
241 const CheckBoxState& state) = 0;
242
245 virtual void onRenderText(PaintContext& context,
246 const Gfx::RectF& textRect,
247 const String& text,
248 const Gfx::PointF& pos,
249 const CheckBoxState& state) = 0;
250
253 virtual void onRenderMnemonic(PaintContext& context,
254 const Gfx::RectF& rect,
255 const Gfx::RectF& mnemonic,
256 const CheckBoxState& state) = 0;
257};
258
274class PT_FORMS_API CheckBoxStyler : public Styler
275{
276 public:
280
283 const Gfx::Brush& background() const;
284
287 void setBackground(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 void setRenderer(CheckBoxRenderer* renderer = 0);
328
332
335 Gfx::SizeF measureIndicator(PaintSurface& surface);
336
339 Gfx::SizeF measureContent(PaintSurface& surface,
340 const Gfx::SizeF& indicatorSize,
341 const Gfx::SizeF& textSize);
342
345 Gfx::SizeF measureFrame(PaintSurface& surface,
346 const Gfx::SizeF& contentSize);
347
350 Gfx::RectF layoutFrame(PaintSurface& surface,
351 const Gfx::RectF& frameRect);
352
356 const Gfx::RectF& contentRect,
357 const Gfx::SizeF& indicatorSize,
358 const Gfx::SizeF& textSize,
359 Gfx::RectF& indicatorRect,
360 Gfx::RectF& textRect);
361
364 Gfx::RectF layoutMnemonic(PaintSurface& surface,
365 const String& text,
366 const Gfx::PointF& textPos,
367 const Gfx::FontMetrics& fontMetrics,
368 String::size_type mnemonicIndex);
369
373 const Gfx::RectF& rect,
374 const Gfx::RectF& boxRect,
375 const CheckBoxState& state);
376
380 const Gfx::RectF& textRect,
381 const String& text,
382 const Gfx::PointF& pos,
383 const CheckBoxState& state);
384
388 const Gfx::RectF& rect,
389 const Gfx::RectF& mnemonic,
390 const CheckBoxState& state);
391
395
398 const StyleOptions& options() const;
399
400 protected:
403 virtual StyleOptions& onBindOptions(const StyleOptions& global);
404
407 virtual Renderer* onStyleRenderer(const Style& style);
408
411 virtual Renderer* onCreateRenderer(const Style& style);
412
413 private:
415 StyleOptions _options;
416};
417
418} // namespace
419
420} // namespace
421
422#endif
Renders the look of a check box.
Definition CheckBoxStyler.h:108
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
virtual Gfx::SizeF onMeasureIndicator(PaintSurface &surface)=0
Returns the natural size of the checkable area.
Gfx::SizeF measureContent(PaintSurface &surface, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize)
Returns the combined content size for indicator and text.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including frame for the given content size.
virtual void onRenderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &boxRect, const CheckBoxState &state)=0
Paints the checkable area for state.
virtual Gfx::RectF onLayoutMnemonic(PaintSurface &surface, const String &text, const Gfx::PointF &textPos, const Gfx::FontMetrics &fontMetrics, String::size_type mnemonicIndex)=0
Returns the mnemonic underline rectangle.
virtual void onLayoutContent(PaintSurface &surface, const Gfx::RectF &contentRect, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize, Gfx::RectF &indicatorRect, Gfx::RectF &textRect)=0
Partitions contentRect into checkable area and caption.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the content rectangle within the outer frame rect.
CheckBoxRenderer * create() const
Creates a new default-constructed instance that the caller owns.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the frame enclosing contentSize.
virtual void onRenderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const CheckBoxState &state)=0
Paints text at pos for state.
virtual Gfx::RectF onLayoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)=0
Returns the content rectangle within frameRect.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const CheckBoxState &state)
Draws text at pos, clipped to the text rect.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color applied.
CheckBoxRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
virtual void onRenderMnemonic(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const CheckBoxState &state)=0
Paints the mnemonic underline for state.
Gfx::SizeF measureIndicator(PaintSurface &surface)
Returns the natural size of the check indicator on surface.
virtual ~CheckBoxRenderer()
Destroys the renderer.
Gfx::RectF layoutMnemonic(PaintSurface &surface, const String &text, const Gfx::PointF &textPos, const Gfx::FontMetrics &fontMetrics, String::size_type mnemonicIndex)
Computes the underline rectangle for the mnemonic character.
void renderMnemonic(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const CheckBoxState &state)
Draws the mnemonic underline within mnemonic, clipped to the widget rect.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
void layoutContent(PaintSurface &surface, const Gfx::RectF &contentRect, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize, Gfx::RectF &indicatorRect, Gfx::RectF &textRect)
Partitions the content rect into indicator and text sub-rectangles.
virtual CheckBoxRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &boxRect, const CheckBoxState &state)
Draws the check indicator chrome within the widget rect.
virtual Gfx::SizeF onMeasureContent(PaintSurface &surface, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize)=0
Returns the combined size of the checkable area and caption.
Transient visual state of a check box.
Definition CheckBoxStyler.h:48
void setChecked(bool value)
Sets whether the check box is checked.
CheckBoxState()
Constructs an empty check box state.
bool isFocused() const
Returns true if the widget currently has focus.
void setFocused(bool value)
Sets whether the widget has focus.
void setHovered(bool value)
Sets whether the pointer is hovering the widget.
bool isEnabled() const
Returns true if the widget is currently enabled.
void setEnabled(bool value)
Sets whether the widget is enabled.
bool isChecked() const
Returns true if the check box is currently checked.
bool isHovered() const
Returns true if the pointer is currently hovering the widget.
CheckBoxStyler()
Constructs an unbound check box style controller.
StyleOptions & options()
Returns the effective check box options.
const Gfx::Color & textColor() const
Returns the effective check box text color.
Gfx::SizeF measureContent(PaintSurface &surface, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize)
Returns the combined content size for the indicator and text.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
void setRenderer(CheckBoxRenderer *renderer=0)
Assigns a specific check box renderer.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared check-box renderer from style, or 0.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the overlay to global and returns it.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the content rectangle within frameRect.
const Gfx::Brush & background() const
Returns the effective check box background brush.
Gfx::Font font() const
Returns the effective check box font.
const Painter * textPainter(PaintSurface &surface)
Returns the current text painter or 0 when no renderer is bound.
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 check box background brush to brush.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const CheckBoxState &state)
Draws text clipped to textRect.
const StyleOptions & options() const
Returns the effective check box options.
Gfx::SizeF measureIndicator(PaintSurface &surface)
Returns the natural size of the check indicator on surface.
void setTextColor(const Gfx::Color &color)
Sets the widget-local check box text color to color.
void setFont(const Gfx::Font &font)
Sets the widget-local check box font to font.
const Gfx::Pen & contour() const
Returns the effective check box contour pen.
Gfx::RectF layoutMnemonic(PaintSurface &surface, const String &text, const Gfx::PointF &textPos, const Gfx::FontMetrics &fontMetrics, String::size_type mnemonicIndex)
Returns the mnemonic underline rectangle.
void setContour(const Gfx::Pen &pen)
Sets the widget-local check box contour pen to pen.
void renderMnemonic(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const CheckBoxState &state)
Draws the mnemonic underline.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local check box font weight to weight.
void layoutContent(PaintSurface &surface, const Gfx::RectF &contentRect, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize, Gfx::RectF &indicatorRect, Gfx::RectF &textRect)
Partitions contentRect into indicator and text rectangles.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &boxRect, const CheckBoxState &state)
Draws check indicator chrome.
void setFontSize(std::size_t size)
Sets the widget-local check box font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local check box font slant to slant.
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
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
Ascent, descent and line height of a font.
Definition FontMetrics.h:50
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