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
35namespace Pt {
36
37namespace Forms {
38
47class PT_FORMS_API PanelState
48{
49 public:
53
56 bool isEnabled() const;
57
60 void setEnabled(bool value);
61
64 bool isFocused() const;
65
68 void setFocused(bool value);
69
70 private:
71 bool _enabled;
72 bool _focused;
73};
74
92class PT_FORMS_API PanelRenderer : public Renderer
93{
94 public:
97 explicit PanelRenderer(std::size_t refs = 0);
98
101 virtual ~PanelRenderer();
102
106
107 public:
110 Gfx::SizeF measureFrame(PaintSurface& surface,
111 const Gfx::SizeF& contentSize);
112
115 Gfx::RectF layoutFrame(PaintSurface& surface,
116 const Gfx::RectF& frameRect);
117
121
125 const Gfx::RectF& rect,
126 const PanelState& state);
127
131 const Gfx::RectF& rect,
132 const PanelState& state);
133
137 const Gfx::RectF& rect,
138 const String& text,
139 const Gfx::PointF& pos,
140 const PanelState& state);
141
145 const Gfx::RectF& rect,
146 const Pixmap& picture,
147 const Gfx::PointF& pos,
148 const PanelState& state);
149
150 protected:
153 virtual PanelRenderer* onCreate() const = 0;
154
157 virtual void onReset(const StyleOptions& options) = 0;
158
161 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
162 const Gfx::SizeF& contentSize) = 0;
163
166 virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
167 const Gfx::RectF& frameRect) = 0;
168
171 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
172
175 virtual void onRenderBackground(PaintContext& context,
176 const Gfx::RectF& rect,
177 const PanelState& state) = 0;
178
181 virtual void onRenderFrame(PaintContext& context,
182 const Gfx::RectF& rect,
183 const PanelState& state) = 0;
184
187 virtual void onRenderText(PaintContext& context,
188 const Gfx::RectF& rect,
189 const String& text,
190 const Gfx::PointF& pos,
191 const PanelState& state) = 0;
192
195 virtual void onRenderIcon(PaintContext& context,
196 const Gfx::RectF& rect,
197 const Pixmap& picture,
198 const Gfx::PointF& pos,
199 const PanelState& state) = 0;
200};
201
217class PT_FORMS_API PanelStyler : public Styler
218{
219 public:
223
226 const Gfx::Brush& background() const;
227
230 void setBackground(const Gfx::Brush& brush);
231
234 const Gfx::Pen& contour() const;
235
238 void setContour(const Gfx::Pen& pen);
239
242 const Gfx::Color& textColor() const;
243
246 void setTextColor(const Gfx::Color& color);
247
251
254 void setFont(const Gfx::Font& font);
255
258 void setFontSize(std::size_t size);
259
263
267
270 Gfx::SizeF measureFrame(PaintSurface& surface,
271 const Gfx::SizeF& contentSize) const;
272
275 Gfx::RectF layoutFrame(PaintSurface& surface,
276 const Gfx::RectF& frameRect) const;
277
280 const Painter* textPainter(PaintSurface& surface) const;
281
285 const Gfx::RectF& rect,
286 const PanelState& state) const;
287
291 const Gfx::RectF& rect,
292 const PanelState& state) const;
293
297 const Gfx::RectF& rect,
298 const String& text,
299 const Gfx::PointF& pos,
300 const PanelState& state) const;
301
305 const Gfx::RectF& rect,
306 const Pixmap& picture,
307 const Gfx::PointF& pos,
308 const PanelState& state) const;
309
312 void setRenderer(PanelRenderer* renderer = 0);
313
319
322 const StyleOptions& options() const;
323
324 protected:
327 virtual StyleOptions& onBindOptions(const StyleOptions& styleOptions);
328
331 virtual Renderer* onStyleRenderer(const Style& style);
332
335 virtual Renderer* onCreateRenderer(const Style& style);
336
337 private:
338 FacetPtr<PanelRenderer> _renderer;
339 StyleOptions _options;
340};
341
342} // namespace
343
344} // namespace
345
346#endif
Manages a reference-counted Style::Facet.
Definition Style.h:79
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Forms render target for painting.
Definition PaintSurface.h:50
Draws on a Forms paint surface or paint context.
Definition Painter.h:53
Renders the look of a panel-like widget.
Definition PanelStyler.h:93
PanelRenderer * create() const
Creates a new default-constructed instance that the caller owns.
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for the given content size.
PanelRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
void renderFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the frame border within the outer frame rect.
virtual void onRenderBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)=0
Paints the background fill for state.
virtual void onRenderText(PaintContext &context, const Gfx::RectF &rect, const String &text, const Gfx::PointF &pos, const PanelState &state)=0
Paints text at pos for state.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)
Returns the inner content rectangle within the outer frame rect.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the frame enclosing contentSize.
virtual void onRenderIcon(PaintContext &context, const Gfx::RectF &rect, const Pixmap &picture, const Gfx::PointF &pos, const PanelState &state)=0
Paints picture at pos for state.
virtual Gfx::RectF onLayoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect)=0
Returns the content rectangle within frameRect.
virtual PanelRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color applied.
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 onRenderFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)=0
Paints the frame for state.
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.
virtual ~PanelRenderer()
Destroys the renderer.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state)
Paints the panel background within the widget rect.
Transient visual state of a panel-like widget.
Definition PanelStyler.h:48
bool isFocused() const
Returns true if the widget currently has focus.
void setFocused(bool value)
Sets whether the widget has focus.
PanelState()
Constructs an empty panel state.
bool isEnabled() const
Returns true if the widget is currently enabled.
void setEnabled(bool value)
Sets whether the widget is enabled.
StyleOptions & options()
Returns the bound effective panel options.
const Gfx::Color & textColor() const
Returns the effective text color.
void renderFrame(PaintContext &context, const Gfx::RectF &rect, const PanelState &state) const
Renders the panel frame within rect for state.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared panel renderer from style, or 0.
void setRenderer(PanelRenderer *renderer=0)
Assigns a specific panel renderer.
const Gfx::Brush & background() const
Returns the effective background brush.
Gfx::Font font() const
Returns the effective font.
PanelStyler()
Constructs an unbound panel styler.
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.
const Painter * textPainter(PaintSurface &surface) const
Returns the text painter for surface, or 0 when unavailable.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independent clone of the style renderer, or 0.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect) const
Returns the frame content rectangle within frameRect.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const PanelState &state) const
Renders the panel background within rect for state.
const StyleOptions & options() const
Returns the bound effective panel options.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
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.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
virtual StyleOptions & onBindOptions(const StyleOptions &styleOptions)
Binds the overlay to styleOptions and returns it.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Off-screen Forms paint surface.
Definition Pixmap.h:130
Provides cloneable drawing for one control family.
Definition Renderer.h:61
Renderer(const std::type_info &ti, std::size_t refs=0)
Constructor.
Definition Renderer.h:65
Stores named appearance options.
Definition StyleOptions.h:646
Stores renderer facets for the active theme.
Definition Style.h:203
Styler()
Constructor.
Fill color, gradient or texture.
Definition Brush.h:151
8-bit ARGB color.
Definition Color.h:65
Font family, size and style.
Definition Font.h:63
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Outline color, width and style.
Definition Pen.h:59
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33