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 
35 namespace Pt {
36 
37 namespace Forms {
38 
43 class PT_FORMS_API CheckBoxState
44 {
45  public:
49 
52  bool isEnabled() const;
53 
56  void setEnabled(bool value);
57 
60  bool isHovered() const;
61 
64  void setHovered(bool value);
65 
68  bool isFocused() const;
69 
72  void setFocused(bool value);
73 
76  bool isChecked() const;
77 
80  void setChecked(bool value);
81 
82  private:
83  bool _enabled;
84  bool _hovered;
85  bool _focused;
86  bool _checked;
87 };
88 
94 class PT_FORMS_API CheckBoxRenderer : public Renderer
95 {
96  public:
97  explicit CheckBoxRenderer(std::size_t refs = 0);
98 
99  virtual ~CheckBoxRenderer();
100 
104 
105  public:
109 
113  const Gfx::SizeF& indicatorSize,
114  const Gfx::SizeF& textSize);
115 
119  const Gfx::SizeF& contentSize);
120 
124  const Gfx::RectF& frameRect);
125 
129  const Gfx::RectF& contentRect,
130  const Gfx::SizeF& indicatorSize,
131  const Gfx::SizeF& textSize,
132  Gfx::RectF& indicatorRect,
133  Gfx::RectF& textRect);
134 
138  const String& text,
139  const Gfx::PointF& textPos,
140  const Gfx::FontMetrics& fontMetrics,
141  String::size_type mnemonicIndex);
142 
145  const Painter& textPainter(PaintSurface& surface);
146 
149  void renderChrome(PaintContext& context,
150  const Gfx::RectF& rect,
151  const Gfx::RectF& boxRect,
152  const CheckBoxState& state);
153 
156  void renderText(PaintContext& context,
157  const Gfx::RectF& textRect,
158  const String& text,
159  const Gfx::PointF& pos,
160  const CheckBoxState& state);
161 
165  const Gfx::RectF& rect,
166  const Gfx::RectF& mnemonic,
167  const CheckBoxState& state);
168 
169  protected:
170  virtual CheckBoxRenderer* onCreate() const = 0;
171 
174  virtual void onReset(const StyleOptions& options) = 0;
175 
176  virtual Gfx::SizeF onMeasureIndicator(PaintSurface& surface) = 0;
177 
178  virtual Gfx::SizeF onMeasureContent(PaintSurface& surface,
179  const Gfx::SizeF& indicatorSize,
180  const Gfx::SizeF& textSize) = 0;
181 
182  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
183  const Gfx::SizeF& contentSize) = 0;
184 
185  virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
186  const Gfx::RectF& frameRect) = 0;
187 
188  virtual void onLayoutContent(PaintSurface& surface,
189  const Gfx::RectF& contentRect,
190  const Gfx::SizeF& indicatorSize,
191  const Gfx::SizeF& textSize,
192  Gfx::RectF& indicatorRect,
193  Gfx::RectF& textRect) = 0;
194 
195  virtual Gfx::RectF onLayoutMnemonic(PaintSurface& surface,
196  const String& text,
197  const Gfx::PointF& textPos,
198  const Gfx::FontMetrics& fontMetrics,
199  String::size_type mnemonicIndex) = 0;
200 
201  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
202 
203  virtual void onRenderChrome(PaintContext& context,
204  const Gfx::RectF& rect,
205  const Gfx::RectF& boxRect,
206  const CheckBoxState& state) = 0;
207 
208  virtual void onRenderText(PaintContext& context,
209  const Gfx::RectF& textRect,
210  const String& text,
211  const Gfx::PointF& pos,
212  const CheckBoxState& state) = 0;
213 
214  virtual void onRenderMnemonic(PaintContext& context,
215  const Gfx::RectF& rect,
216  const Gfx::RectF& mnemonic,
217  const CheckBoxState& state) = 0;
218 };
219 
225 class PT_FORMS_API CheckBoxStyler : public Styler
226 {
227  public:
231 
234  const Gfx::Brush& background() const;
235 
238  void setBackground(const Gfx::Brush& brush);
239 
242  const Gfx::Pen& contour() const;
243 
246  void setContour(const Gfx::Pen& pen);
247 
250  const Gfx::Color& textColor() const;
251 
254  void setTextColor(const Gfx::Color& color);
255 
258  Gfx::Font font() const;
259 
262  void setFont(const Gfx::Font& font);
263 
266  void setFontSize(std::size_t size);
267 
271 
275 
278  void setRenderer(CheckBoxRenderer* renderer = 0);
279 
282  const Painter* textPainter(PaintSurface& surface);
283 
287 
291  const Gfx::SizeF& indicatorSize,
292  const Gfx::SizeF& textSize);
293 
297  const Gfx::SizeF& contentSize);
298 
302  const Gfx::RectF& frameRect);
303 
307  const Gfx::RectF& contentRect,
308  const Gfx::SizeF& indicatorSize,
309  const Gfx::SizeF& textSize,
310  Gfx::RectF& indicatorRect,
311  Gfx::RectF& textRect);
312 
316  const String& text,
317  const Gfx::PointF& textPos,
318  const Gfx::FontMetrics& fontMetrics,
319  String::size_type mnemonicIndex);
320 
323  void renderChrome(PaintContext& context,
324  const Gfx::RectF& rect,
325  const Gfx::RectF& boxRect,
326  const CheckBoxState& state);
327 
330  void renderText(PaintContext& context,
331  const Gfx::RectF& textRect,
332  const String& text,
333  const Gfx::PointF& pos,
334  const CheckBoxState& state);
335 
339  const Gfx::RectF& rect,
340  const Gfx::RectF& mnemonic,
341  const CheckBoxState& state);
342 
346 
349  const StyleOptions& options() const;
350 
351  protected:
352  virtual StyleOptions& onBindOptions(const StyleOptions& global);
353 
354  virtual Renderer* onStyleRenderer(const Style& style);
355 
356  virtual Renderer* onCreateRenderer(const Style& style);
357 
358  private:
359  FacetPtr<CheckBoxRenderer> _renderer;
360  StyleOptions _options;
361 };
362 
363 } // namespace
364 
365 } // namespace
366 
367 #endif
Core module.
Definition: Allocator.h:33
void setChecked(bool value)
Sets whether the check box is checked.
Attributes for the drawing of outlines.
Definition: Pen.h:54
void setFont(const Gfx::Font &font)
Sets the widget-local check box font to font.
Renders the visual appearance of a check box widget.
Definition: CheckBoxStyler.h:95
Gfx::SizeF measureContent(PaintSurface &surface, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize)
Returns the combined content size for the indicator and text.
Metrics that describe a font face at a given size.
Definition: FontMetrics.h:46
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local check box font weight to weight.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
virtual void onReset(const StyleOptions &options)=0
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including frame for the given content size.
Paint context.
Definition: PaintContext.h:45
bool isFocused() const
Returns true if the widget currently has focus.
const Gfx::Color & textColor() const
Returns the effective check box text color.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the content rectangle within frameRect.
CheckBoxStyler()
Constructs an unbound check box style controller.
void setFocused(bool value)
Sets whether the widget has focus.
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
Size with floating-point width and height.
Definition: Size.h:47
CheckBoxRenderer * create() const
Creates a new default-constructed instance that the caller owns.
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.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &boxRect, const CheckBoxState &state)
Draws the check indicator chrome within the widget rect.
Gfx::Font font() const
Returns the effective check box font.
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.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
const Gfx::Pen & contour() const
Returns the effective check box contour pen.
void renderMnemonic(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const CheckBoxState &state)
Draws the mnemonic underline.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color applied.
Weight
Describes the requested font weight.
Definition: Font.h:61
const StyleOptions & options() const
Returns the effective check box options.
Style for widgets.
Definition: Style.h:155
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Returns the specific style options.
bool isChecked() const
Returns true if the check box is currently checked.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
const Gfx::Brush & background() const
Returns the effective check box background brush.
bool isEnabled() const
Returns true if the widget is currently enabled.
Gfx::SizeF measureContent(PaintSurface &surface, const Gfx::SizeF &indicatorSize, const Gfx::SizeF &textSize)
Returns the combined content size for indicator and text.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
Font request used for text drawing and measurement.
Definition: Font.h:56
Gfx::SizeF measureIndicator(PaintSurface &surface)
Returns the natural size of the check indicator on surface.
Style options container.
Definition: StyleOptions.h:535
void setContour(const Gfx::Pen &pen)
Sets the widget-local check box contour pen to 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.
const Painter * textPainter(PaintSurface &surface)
Returns the current text painter or 0 when no renderer is bound.
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 renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const CheckBoxState &state)
Draws text clipped to textRect.
Standard color type.
Definition: Color.h:47
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &boxRect, const CheckBoxState &state)
Draws check indicator chrome.
Unicode capable basic_string.
Definition: Api-String.h:44
void setEnabled(bool value)
Sets whether the widget is enabled.
CheckBoxState()
Constructs an empty check box state.
virtual CheckBoxRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
Fill description for shapes and text.
Definition: Brush.h:145
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local check box font slant to slant.
Stores the transient render state for a check box widget.
Definition: CheckBoxStyler.h:44
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.
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.
Rect with floating-point coordinates.
Definition: Rect.h:47
void setBackground(const Gfx::Brush &brush)
Sets the widget-local check box background brush to brush.
void setRenderer(CheckBoxRenderer *renderer=0)
Assigns a specific check box renderer.
bool isHovered() const
Returns true if the pointer is currently hovering the widget.
void setHovered(bool value)
Sets whether the pointer is hovering the widget.
StyleOptions & options()
Returns the effective check box options.
Binds a check box widget to the currently active renderer.
Definition: CheckBoxStyler.h:226
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the content rectangle within the outer frame rect.
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 setFontSize(std::size_t size)
Sets the widget-local check box font size to size.