CheckBoxStyle.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_CheckBoxStyle_h
31 #define Pt_Forms_CheckBoxStyle_h
32 
33 #include <Pt/Forms/Style.h>
34 
35 namespace Pt {
36 
37 namespace Forms {
38 
44 class PT_FORMS_API CheckBoxStyleOptions
45 {
46  public:
50 
53  bool hasOverrides() const;
54 
57  std::size_t generation() const;
58 
61  const Gfx::Brush* background() const;
62 
65  void setBackground(const Gfx::Brush& brush);
66 
69  const Gfx::Pen* contour() const;
70 
73  void setContour(const Gfx::Pen& pen);
74 
77  const Gfx::Color* textColor() const;
78 
81  void setTextColor(const Gfx::Color& color);
82 
85  const Gfx::Font* font() const;
86 
89  void setFont(const Gfx::Font& font);
90 
93  void setFontSize(std::size_t size);
94 
98 
102 
105  Gfx::Font getFont(const Gfx::Font& base) const;
106 
107  private:
108  enum StyleOverride
109  {
110  Background = 0x01,
111  Contour = 0x02,
112  TextColor = 0x04,
113  Font = 0x08
114  };
115 
116  bool hasOverride(StyleOverride mask) const;
117 
118  void setOverride(StyleOverride mask);
119 
120  private:
121  AutoPtr<Gfx::Brush> _background;
122  AutoPtr<Gfx::Pen> _contour;
123  AutoPtr<Gfx::Color> _textColor;
124  FontOption _font;
125  std::size_t _generation;
126  unsigned _overrides;
127 };
128 
133 class PT_FORMS_API CheckBoxState
134 {
135  public:
139 
142  bool isEnabled() const;
143 
146  void setEnabled(bool value);
147 
150  bool isHovered() const;
151 
154  void setHovered(bool value);
155 
158  bool isFocused() const;
159 
162  void setFocused(bool value);
163 
166  bool isChecked() const;
167 
170  void setChecked(bool value);
171 
172  private:
173  bool _enabled;
174  bool _hovered;
175  bool _focused;
176  bool _checked;
177 };
178 
184 class PT_FORMS_API CheckBoxRenderer : public Style::Facet
185 {
186  public:
187  explicit CheckBoxRenderer(std::size_t refs = 0);
188 
189  virtual ~CheckBoxRenderer();
190 
194 
199  void prepare(const StyleOptions& options,
200  const CheckBoxStyleOptions& checkBoxOptions);
201 
202  public:
206 
210  const Gfx::SizeF& indicatorSize,
211  const Gfx::SizeF& textSize);
212 
216  const Gfx::SizeF& contentSize);
217 
221  const Gfx::RectF& frameRect);
222 
226  const Gfx::RectF& contentRect,
227  const Gfx::SizeF& indicatorSize,
228  const Gfx::SizeF& textSize,
229  Gfx::RectF& indicatorRect,
230  Gfx::RectF& textRect);
231 
235  const String& text,
236  const Gfx::PointF& textPos,
237  const Gfx::FontMetrics& fontMetrics,
238  String::size_type mnemonicIndex);
239 
242  const Painter& textPainter(PaintSurface& surface);
243 
246  void renderChrome(PaintContext& context,
247  const Gfx::RectF& rect,
248  const Gfx::RectF& boxRect,
249  const CheckBoxState& state);
250 
253  void renderText(PaintContext& context,
254  const Gfx::RectF& textRect,
255  const String& text,
256  const Gfx::PointF& pos,
257  const CheckBoxState& state);
258 
262  const Gfx::RectF& rect,
263  const Gfx::RectF& mnemonic,
264  const CheckBoxState& state);
265 
266  protected:
269  virtual void onReset(const StyleOptions& options);
270 
271  virtual CheckBoxRenderer* onCreate() const = 0;
272 
273  virtual void onPrepare(const StyleOptions& options,
274  const CheckBoxStyleOptions& checkBoxOptions) = 0;
275 
276  virtual Gfx::SizeF onMeasureIndicator(PaintSurface& surface) = 0;
277 
278  virtual Gfx::SizeF onMeasureContent(PaintSurface& surface,
279  const Gfx::SizeF& indicatorSize,
280  const Gfx::SizeF& textSize) = 0;
281 
282  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
283  const Gfx::SizeF& contentSize) = 0;
284 
285  virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
286  const Gfx::RectF& frameRect) = 0;
287 
288  virtual void onLayoutContent(PaintSurface& surface,
289  const Gfx::RectF& contentRect,
290  const Gfx::SizeF& indicatorSize,
291  const Gfx::SizeF& textSize,
292  Gfx::RectF& indicatorRect,
293  Gfx::RectF& textRect) = 0;
294 
295  virtual Gfx::RectF onLayoutMnemonic(PaintSurface& surface,
296  const String& text,
297  const Gfx::PointF& textPos,
298  const Gfx::FontMetrics& fontMetrics,
299  String::size_type mnemonicIndex) = 0;
300 
301  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
302 
303  virtual void onRenderChrome(PaintContext& context,
304  const Gfx::RectF& rect,
305  const Gfx::RectF& boxRect,
306  const CheckBoxState& state) = 0;
307 
308  virtual void onRenderText(PaintContext& context,
309  const Gfx::RectF& textRect,
310  const String& text,
311  const Gfx::PointF& pos,
312  const CheckBoxState& state) = 0;
313 
314  virtual void onRenderMnemonic(PaintContext& context,
315  const Gfx::RectF& rect,
316  const Gfx::RectF& mnemonic,
317  const CheckBoxState& state) = 0;
318 };
319 
325 class PT_FORMS_API CheckBoxStyle : public StyleBinder<CheckBoxRenderer,
326  CheckBoxStyleOptions>
327 {
328  public:
332 };
333 
334 } // namespace
335 
336 } // namespace
337 
338 #endif
bool hasOverrides() const
Returns true if any local style override is present.
Core module.
Definition: Allocator.h:33
void setFontSize(std::size_t size)
Sets the local font size override.
void setChecked(bool value)
Sets whether the check box is checked.
Attributes for the drawing of outlines.
Definition: Pen.h:54
Common renderer-binding controller for Forms style slices.
Definition: Style.h:272
void setTextColor(const Gfx::Color &color)
Sets the local text color override.
Renders the visual appearance of a check box widget.
Definition: CheckBoxStyle.h:185
void setBackground(const Gfx::Brush &brush)
Sets the local background override.
Metrics that describe a font face at a given size.
Definition: FontMetrics.h:46
Paint surface.
Definition: PaintSurface.h:44
void setFont(const Gfx::Font &font)
Sets the complete local font override.
Slant
Describes the requested font slant.
Definition: Font.h:76
2D painter for Forms paint surfaces.
Definition: Painter.h:46
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.
CheckBoxStyle()
Constructs an unbound check box style controller.
void setFocused(bool value)
Sets whether the widget has focus.
const Gfx::Color * textColor() const
Returns the local text color override or 0 if none is set.
Stores widget-local style overrides for a check box.
Definition: CheckBoxStyle.h:45
void setFontSlant(Gfx::Font::Slant slant)
Sets the local font slant override.
Size with floating-point width and height.
Definition: Size.h:47
CheckBoxRenderer * create() const
Creates a new default-constructed instance that the caller owns.
Policy based Auto pointer.
Definition: SmartPtr.h:291
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.
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.
Binds a check box widget to the currently active renderer.
Definition: CheckBoxStyle.h:327
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color applied.
const Gfx::Brush * background() const
Returns the local background override or 0 if none is set.
Composable font override slice for widget-local style options.
Definition: StyleOptions.h:344
Weight
Describes the requested font weight.
Definition: Font.h:61
void setFontWeight(Gfx::Font::Weight weight)
Sets the local font weight override.
bool isChecked() const
Returns true if the check box is currently checked.
void prepare(const StyleOptions &options, const CheckBoxStyleOptions &checkBoxOptions)
Applies the widget-local check box style overrides to this renderer.
void setContour(const Gfx::Pen &pen)
Sets the local contour override.
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.
Font request used for text drawing and measurement.
Definition: Font.h:56
virtual void onReset(const StyleOptions &options)
Resets the shared check box renderer to global defaults.
Gfx::SizeF measureIndicator(PaintSurface &surface)
Returns the natural size of the check indicator on surface.
Stores the global theme option values shared across styles.
Definition: StyleOptions.h:186
const Gfx::Font * font() const
Returns the local font override data or 0 if none is set.
Standard color type.
Definition: Color.h:47
std::size_t generation() const
Returns the current local override generation.
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.
Fill description for shapes and text.
Definition: Brush.h:145
Stores the transient render state for a check box widget.
Definition: CheckBoxStyle.h:134
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
Gfx::Font getFont(const Gfx::Font &base) const
Resolves the effective font against the given base font.
const Gfx::Pen * contour() const
Returns the local contour override or 0 if none is set.
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.
CheckBoxStyleOptions()
Constructs empty local check box style options.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the content rectangle within the outer frame rect.