PanelStyler.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_PanelStyler_h
31 #define Pt_Forms_PanelStyler_h
32 
33 #include <Pt/Forms/Styler.h>
34 
35 namespace Pt {
36 
37 namespace Forms {
38 
43 class PT_FORMS_API PanelState
44 {
45  public:
49 
52  bool isEnabled() const;
53 
56  void setEnabled(bool value);
57 
60  bool isFocused() const;
61 
64  void setFocused(bool value);
65 
66  private:
67  bool _enabled;
68  bool _focused;
69 };
70 
76 class PT_FORMS_API PanelRenderer : public Renderer
77 {
78  public:
79  explicit PanelRenderer(std::size_t refs = 0);
80 
81  virtual ~PanelRenderer();
82 
86 
87  public:
91  const Gfx::SizeF& contentSize);
92 
96  const Gfx::RectF& frameRect);
97 
100  const Painter& textPainter(PaintSurface& surface);
101 
105  const Gfx::RectF& rect,
106  const PanelState& state);
107 
110  void renderFrame(PaintContext& context,
111  const Gfx::RectF& rect,
112  const PanelState& state);
113 
116  void renderText(PaintContext& context,
117  const Gfx::RectF& rect,
118  const String& text,
119  const Gfx::PointF& pos,
120  const PanelState& state);
121 
124  void renderIcon(PaintContext& context,
125  const Gfx::RectF& rect,
126  const Pixmap& picture,
127  const Gfx::PointF& pos,
128  const PanelState& state);
129 
130  protected:
131  virtual PanelRenderer* onCreate() const = 0;
132 
135  virtual void onReset(const StyleOptions& options) = 0;
136 
137  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
138  const Gfx::SizeF& contentSize) = 0;
139 
140  virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
141  const Gfx::RectF& frameRect) = 0;
142 
143  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
144 
145  virtual void onRenderBackground(PaintContext& context,
146  const Gfx::RectF& rect,
147  const PanelState& state) = 0;
148 
149  virtual void onRenderFrame(PaintContext& context,
150  const Gfx::RectF& rect,
151  const PanelState& state) = 0;
152 
153  virtual void onRenderText(PaintContext& context,
154  const Gfx::RectF& rect,
155  const String& text,
156  const Gfx::PointF& pos,
157  const PanelState& state) = 0;
158 
159  virtual void onRenderIcon(PaintContext& context,
160  const Gfx::RectF& rect,
161  const Pixmap& picture,
162  const Gfx::PointF& pos,
163  const PanelState& state) = 0;
164 };
165 
168 class PT_FORMS_API PanelStyler : public Styler
169 {
170  public:
174 
177  const Gfx::Brush& background() const;
178 
181  void setBackground(const Gfx::Brush& brush);
182 
185  const Gfx::Pen& contour() const;
186 
189  void setContour(const Gfx::Pen& pen);
190 
193  const Gfx::Color& textColor() const;
194 
197  void setTextColor(const Gfx::Color& color);
198 
201  Gfx::Font font() const;
202 
205  void setFont(const Gfx::Font& font);
206 
209  void setFontSize(std::size_t size);
210 
214 
218 
222  const Gfx::SizeF& contentSize) const;
223 
227  const Gfx::RectF& frameRect) const;
228 
231  const Painter* textPainter(PaintSurface& surface) const;
232 
236  const Gfx::RectF& rect,
237  const PanelState& state) const;
238 
241  void renderFrame(PaintContext& context,
242  const Gfx::RectF& rect,
243  const PanelState& state) const;
244 
247  void renderText(PaintContext& context,
248  const Gfx::RectF& rect,
249  const String& text,
250  const Gfx::PointF& pos,
251  const PanelState& state) const;
252 
255  void renderIcon(PaintContext& context,
256  const Gfx::RectF& rect,
257  const Pixmap& picture,
258  const Gfx::PointF& pos,
259  const PanelState& state) const;
260 
263  void setRenderer(PanelRenderer* renderer = 0);
264 
270 
273  const StyleOptions& options() const;
274 
275  protected:
276  virtual StyleOptions& onBindOptions(const StyleOptions& styleOptions);
277 
278  virtual Renderer* onStyleRenderer(const Style& style);
279 
280  virtual Renderer* onCreateRenderer(const Style& style);
281 
282  private:
283  FacetPtr<PanelRenderer> _renderer;
284  StyleOptions _options;
285 };
286 
287 } // namespace
288 
289 } // namespace
290 
291 #endif
void setRenderer(PanelRenderer *renderer=0)
Assigns a specific panel renderer.
Core module.
Definition: Allocator.h:33
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
bool isEnabled() const
Returns true if the widget is currently enabled.
Attributes for the drawing of outlines.
Definition: Pen.h:54
bool isFocused() const
Returns true if the widget currently has focus.
StyleOptions & options()
Returns the bound effective panel options.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state) const
Renders the panel background within rect for state.
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.
const Painter * textPainter(PaintSurface &surface) const
Returns the text painter for surface, or 0 when unavailable.
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.
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
PanelRenderer * create() const
Creates a new default-constructed instance that the caller owns.
PanelState()
Constructs an empty panel state.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
const Gfx::Color & textColor() const
Returns the effective text color.
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.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Gfx::Font font() const
Returns the effective font.
void setEnabled(bool value)
Sets whether the widget is enabled.
Panel styler.
Definition: PanelStyler.h:169
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
const Gfx::Brush & background() const
Returns the effective background brush.
Weight
Describes the requested font weight.
Definition: Font.h:61
void setFocused(bool value)
Sets whether the widget has focus.
Style for widgets.
Definition: Style.h:155
PanelStyler()
Constructs an unbound panel styler.
void renderIcon(PaintContext &context, const Gfx::RectF &rect, const Pixmap &picture, const Gfx::PointF &pos, const PanelState &state) const
Renders picture at pos within rect for state.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the inner content rectangle within the outer frame rect.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for the given content size.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
Font request used for text drawing and measurement.
Definition: Font.h:56
Style options container.
Definition: StyleOptions.h:535
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void renderFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state) const
Renders the panel frame within rect for state.
const Gfx::Pen & contour() const
Returns the effective contour pen.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Standard color type.
Definition: Color.h:47
Renders the visual appearance of a panel-like widget.
Definition: PanelStyler.h:77
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect) const
Returns the frame content rectangle within frameRect.
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.
virtual void onReset(const StyleOptions &options)=0
Fill description for shapes and text.
Definition: Brush.h:145
Stores the transient render state for panel-like widgets.
Definition: PanelStyler.h:44
Rect with floating-point coordinates.
Definition: Rect.h:47
virtual PanelRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
Back buffer drawing surface.
Definition: Pixmap.h:77
const StyleOptions & options() const
Returns the bound effective panel options.
void renderText(PaintContext &context, const Gfx::RectF &rect, const String &text, const Gfx::PointF &pos, const PanelState &state) const
Renders text at pos within rect for state.
virtual StyleOptions & onBindOptions(const StyleOptions &styleOptions)
Returns the specific style options.