PanelStyle.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_PanelStyle_h
31 #define Pt_Forms_PanelStyle_h
32 
33 #include <Pt/Forms/Style.h>
34 
35 namespace Pt {
36 
37 namespace Forms {
38 
44 class PT_FORMS_API PanelStyleOptions
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 PanelState
134 {
135  public:
139 
142  bool isEnabled() const;
143 
146  void setEnabled(bool value);
147 
150  bool isFocused() const;
151 
154  void setFocused(bool value);
155 
156  private:
157  bool _enabled;
158  bool _focused;
159 };
160 
166 class PT_FORMS_API PanelRenderer : public Style::Facet
167 {
168  public:
169  explicit PanelRenderer(std::size_t refs = 0);
170 
171  virtual ~PanelRenderer();
172 
176 
181  void prepare(const StyleOptions& options,
182  const PanelStyleOptions& panelOptions);
183 
184  public:
188  const Gfx::SizeF& contentSize);
189 
193  const Gfx::RectF& frameRect);
194 
197  const Painter& textPainter(PaintSurface& surface);
198 
202  const Gfx::RectF& rect,
203  const PanelState& state);
204 
207  void renderFrame(PaintContext& context,
208  const Gfx::RectF& rect,
209  const PanelState& state);
210 
213  void renderText(PaintContext& context,
214  const Gfx::RectF& rect,
215  const String& text,
216  const Gfx::PointF& pos,
217  const PanelState& state);
218 
221  void renderIcon(PaintContext& context,
222  const Gfx::RectF& rect,
223  const Pixmap& picture,
224  const Gfx::PointF& pos,
225  const PanelState& state);
226 
227  protected:
230  virtual void onReset(const StyleOptions& options);
231 
232  virtual PanelRenderer* onCreate() const = 0;
233 
234  virtual void onPrepare(const StyleOptions& options,
235  const PanelStyleOptions& panelOptions) = 0;
236 
237  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
238  const Gfx::SizeF& contentSize) = 0;
239 
240  virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
241  const Gfx::RectF& frameRect) = 0;
242 
243  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
244 
245  virtual void onRenderBackground(PaintContext& context,
246  const Gfx::RectF& rect,
247  const PanelState& state) = 0;
248 
249  virtual void onRenderFrame(PaintContext& context,
250  const Gfx::RectF& rect,
251  const PanelState& state) = 0;
252 
253  virtual void onRenderText(PaintContext& context,
254  const Gfx::RectF& rect,
255  const String& text,
256  const Gfx::PointF& pos,
257  const PanelState& state) = 0;
258 
259  virtual void onRenderIcon(PaintContext& context,
260  const Gfx::RectF& rect,
261  const Pixmap& picture,
262  const Gfx::PointF& pos,
263  const PanelState& state) = 0;
264 };
265 
271 class PT_FORMS_API PanelStyle : public StyleBinder<PanelRenderer,
272  PanelStyleOptions>
273 {
274  public:
278 };
279 
280 } // namespace
281 
282 } // namespace
283 
284 #endif
Core module.
Definition: Allocator.h:33
void setBackground(const Gfx::Brush &brush)
Sets the local background override.
bool isEnabled() const
Returns true if the widget is currently enabled.
PanelStyleOptions()
Constructs empty local panel style options.
Attributes for the drawing of outlines.
Definition: Pen.h:54
bool isFocused() const
Returns true if the widget currently has focus.
Common renderer-binding controller for Forms style slices.
Definition: Style.h:272
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color applied.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the panel background within the widget rect.
void renderText(PaintContext &context, const Gfx::RectF &rect, const String &text, const Gfx::PointF &pos, const PanelState &state)
Draws text at pos, clipped to the widget rect.
void prepare(const StyleOptions &options, const PanelStyleOptions &panelOptions)
Applies the widget-local panel style overrides to this renderer.
Binds a panel-like widget to the currently active renderer.
Definition: PanelStyle.h:273
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
PanelRenderer * create() const
Creates a new default-constructed instance that the caller owns.
PanelState()
Constructs an empty panel state.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
std::size_t generation() const
Returns the current local override generation.
const Gfx::Brush * background() const
Returns the local background override or 0 if none is set.
Size with floating-point width and height.
Definition: Size.h:47
void renderFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the frame border within the outer frame rect.
Policy based Auto pointer.
Definition: SmartPtr.h:291
Point with floating-point X and Y coordinates.
Definition: Point.h:47
void setEnabled(bool value)
Sets whether the widget is enabled.
Gfx::Font getFont(const Gfx::Font &base) const
Resolves the effective font against the given base font.
Composable font override slice for widget-local style options.
Definition: StyleOptions.h:344
Weight
Describes the requested font weight.
Definition: Font.h:61
const Gfx::Pen * contour() const
Returns the local contour override or 0 if none is set.
void setFontSlant(Gfx::Font::Slant slant)
Sets the local font slant override.
void setFocused(bool value)
Sets whether the widget has focus.
void setFontWeight(Gfx::Font::Weight weight)
Sets the local font weight override.
const Gfx::Font * font() const
Returns the local font override data or 0 if none is set.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the inner content rectangle within the outer frame rect.
virtual void onReset(const StyleOptions &options)
Resets the shared panel renderer to global defaults.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for the given content size.
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
void setTextColor(const Gfx::Color &color)
Sets the local text color override.
Standard color type.
Definition: Color.h:47
Renders the visual appearance of a panel-like widget.
Definition: PanelStyle.h:167
const Gfx::Color * textColor() const
Returns the local text color override or 0 if none is set.
Unicode capable basic_string.
Definition: Api-String.h:44
void renderIcon(PaintContext &context, const Gfx::RectF &rect, const Pixmap &picture, const Gfx::PointF &pos, const PanelState &state)
Draws picture at pos, clipped to the widget rect.
Stores widget-local style overrides for panel-like widgets.
Definition: PanelStyle.h:45
Fill description for shapes and text.
Definition: Brush.h:145
Stores the transient render state for panel-like widgets.
Definition: PanelStyle.h:134
bool hasOverrides() const
Returns true if any local style override is present.
Rect with floating-point coordinates.
Definition: Rect.h:47
Back buffer drawing surface.
Definition: Pixmap.h:77
void setFontSize(std::size_t size)
Sets the local font size override.
void setFont(const Gfx::Font &font)
Sets the complete local font override.
void setContour(const Gfx::Pen &pen)
Sets the local contour override.
PanelStyle()
Constructs an unbound panel style controller.