SpinBoxStyle.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_SpinBoxStyle_h
30 #define Pt_Forms_SpinBoxStyle_h
31 
32 #include <Pt/Forms/Style.h>
33 
34 namespace Pt {
35 
36 namespace Forms {
37 
43 class PT_FORMS_API SpinBoxStyleOptions
44 {
45  public:
47 
48  bool hasOverrides() const;
49 
50  std::size_t generation() const;
51 
52  const Gfx::Brush* background() const;
53 
54  void setBackground(const Gfx::Brush& brush);
55 
56  const Gfx::Pen* contour() const;
57 
58  void setContour(const Gfx::Pen& pen);
59 
60  const Gfx::Brush* foreground() const;
61 
62  void setForeground(const Gfx::Brush& brush);
63 
64  const Gfx::Color* textColor() const;
65 
66  void setTextColor(const Gfx::Color& color);
67 
68  const Gfx::Font* font() const;
69 
70  void setFont(const Gfx::Font& font);
71 
72  void setFontSize(std::size_t size);
73 
74  void setFontWeight(Gfx::Font::Weight weight);
75 
76  void setFontSlant(Gfx::Font::Slant slant);
77 
78  Gfx::Font getFont(const Gfx::Font& base) const;
79 
80  private:
81  enum StyleOverride
82  {
83  Background = 0x01,
84  Contour = 0x02,
85  Foreground = 0x04,
86  TextColor = 0x08,
87  Font = 0x10
88  };
89 
90  bool hasOverride(StyleOverride mask) const;
91 
92  void setOverride(StyleOverride mask);
93 
94  private:
95  AutoPtr<Gfx::Brush> _background;
96  AutoPtr<Gfx::Pen> _contour;
97  AutoPtr<Gfx::Brush> _foreground;
98  AutoPtr<Gfx::Color> _textColor;
99  FontOption _font;
100  std::size_t _generation;
101  unsigned _overrides;
102 };
103 
104 
109 class PT_FORMS_API SpinBoxState
110 {
111  public:
112  SpinBoxState();
113 
114  bool isEnabled() const;
115 
116  void setEnabled(bool value);
117 
118  bool isHovered() const;
119 
120  void setHovered(bool value);
121 
122  bool isFocused() const;
123 
124  void setFocused(bool value);
125 
126  bool isEditable() const;
127 
128  void setEditable(bool value);
129 
130  bool isUpPressed() const;
131 
132  void setUpPressed(bool value);
133 
134  bool isUpHovered() const;
135 
136  void setUpHovered(bool value);
137 
138  bool isDownPressed() const;
139 
140  void setDownPressed(bool value);
141 
142  bool isDownHovered() const;
143 
144  void setDownHovered(bool value);
145 
146  private:
147  bool _enabled;
148  bool _hovered;
149  bool _focused;
150  bool _editable;
151  bool _upPressed;
152  bool _upHovered;
153  bool _downPressed;
154  bool _downHovered;
155 };
156 
157 
163 class PT_FORMS_API SpinBoxRenderer : public Style::Facet
164 {
165  public:
166  explicit SpinBoxRenderer(std::size_t refs = 0);
167 
168  virtual ~SpinBoxRenderer();
169 
170  SpinBoxRenderer* create() const;
171 
172  void prepare(const StyleOptions& options,
173  const SpinBoxStyleOptions& spinBoxOptions);
174 
175  public:
176  Gfx::SizeF measureFrame(PaintSurface& surface,
177  const Gfx::SizeF& contentSize);
178 
179  Gfx::SizeF measureEntry(PaintSurface& surface,
180  const Gfx::SizeF& contentSize);
181 
182  Gfx::SizeF measureIndicator(PaintSurface& surface);
183 
184  void layoutChrome(PaintSurface& surface,
185  const Gfx::RectF& rect,
186  Gfx::RectF& entryRect,
187  Gfx::RectF& upButtonRect,
188  Gfx::RectF& downButtonRect,
189  Gfx::RectF& textRect);
190 
191  Gfx::RectF layoutEntry(PaintSurface& surface,
192  const Gfx::RectF& entryRect);
193 
194  const Painter& textPainter(PaintSurface& surface);
195 
196  void renderChrome(PaintContext& context,
197  const Gfx::RectF& rect,
198  const Gfx::RectF& entryRect,
199  const Gfx::RectF& upButtonRect,
200  const Gfx::RectF& downButtonRect,
201  const SpinBoxState& state);
202 
203  void renderText(PaintContext& context,
204  const Gfx::RectF& textRect,
205  const String& text,
206  const Gfx::PointF& textPos,
207  const Gfx::RectF& cursor,
208  const SpinBoxState& state);
209 
210  protected:
211  virtual void onReset(const StyleOptions& options);
212 
213  virtual SpinBoxRenderer* onCreate() const = 0;
214 
215  virtual void onPrepare(const StyleOptions& options,
216  const SpinBoxStyleOptions& spinBoxOptions) = 0;
217 
218  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
219  const Gfx::SizeF& contentSize) = 0;
220 
221  virtual Gfx::SizeF onMeasureEntry(PaintSurface& surface,
222  const Gfx::SizeF& contentSize) = 0;
223 
224  virtual Gfx::SizeF onMeasureIndicator(PaintSurface& surface) = 0;
225 
226  virtual void onLayoutChrome(PaintSurface& surface,
227  const Gfx::RectF& rect,
228  Gfx::RectF& entryRect,
229  Gfx::RectF& upButtonRect,
230  Gfx::RectF& downButtonRect,
231  Gfx::RectF& textRect) = 0;
232 
233  virtual Gfx::RectF onLayoutEntry(PaintSurface& surface,
234  const Gfx::RectF& entryRect) = 0;
235 
236  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
237 
238  virtual void onRenderChrome(PaintContext& context,
239  const Gfx::RectF& rect,
240  const Gfx::RectF& entryRect,
241  const Gfx::RectF& upButtonRect,
242  const Gfx::RectF& downButtonRect,
243  const SpinBoxState& state);
244 
245  virtual void onRenderEntry(PaintContext& context,
246  const Gfx::RectF& entryRect,
247  const SpinBoxState& state) = 0;
248 
249  virtual void onRenderUpButton(PaintContext& context,
250  const Gfx::RectF& buttonRect,
251  const SpinBoxState& state) = 0;
252 
253  virtual void onRenderDownButton(PaintContext& context,
254  const Gfx::RectF& buttonRect,
255  const SpinBoxState& state) = 0;
256 
257  virtual void onRenderText(PaintContext& context,
258  const Gfx::RectF& textRect,
259  const String& text,
260  const Gfx::PointF& textPos,
261  const Gfx::RectF& cursor,
262  const SpinBoxState& state) = 0;
263 };
264 
265 
268 class PT_FORMS_API SpinBoxStyle : public StyleBinder<SpinBoxRenderer,
269  SpinBoxStyleOptions>
270 {
271  public:
272  SpinBoxStyle();
273 };
274 
275 } // namespace
276 
277 } // namespace
278 
279 #endif
Core module.
Definition: Allocator.h:33
Attributes for the drawing of outlines.
Definition: Pen.h:54
Binds a spin box widget to the currently active renderer.
Definition: SpinBoxStyle.h:270
Common renderer-binding controller for Forms style slices.
Definition: Style.h:272
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
Size with floating-point width and height.
Definition: Size.h:47
Policy based Auto pointer.
Definition: SmartPtr.h:291
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Composable font override slice for widget-local style options.
Definition: StyleOptions.h:344
Weight
Describes the requested font weight.
Definition: Font.h:61
Stores widget-local style overrides for a spin box.
Definition: SpinBoxStyle.h:44
Font request used for text drawing and measurement.
Definition: Font.h:56
Stores the global theme option values shared across styles.
Definition: StyleOptions.h:186
Stores the transient render state for a spin box widget.
Definition: SpinBoxStyle.h:110
Standard color type.
Definition: Color.h:47
Unicode capable basic_string.
Definition: Api-String.h:44
Renders the visual appearance of a spin box widget.
Definition: SpinBoxStyle.h:164
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47