FastUIDraw
painter_data.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_data.hpp
3  * \brief file painter_data.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 #ifndef FASTUIDRAW_PAINTER_DATA_HPP
20 #define FASTUIDRAW_PAINTER_DATA_HPP
21 
26 #include <fastuidraw/painter/painter_custom_brush.hpp>
28 
29 namespace fastuidraw
30 {
31  class PainterPackedValuePool;
32 
33 /*!\addtogroup PainterShaderData
34  * @{
35  */
36 
37  /*!
38  * \brief
39  * A PainterData provides the data for how for a
40  * Painter to draw content.
41  */
43  {
44  public:
45  /*!
46  * \brief
47  * A brush_value stores the brush applied; it stores
48  * a pointer to a \ref PainterBrushShader together
49  * with a PainterDataValue<PainterBrushShaderData>.
50  * If the pointer to the \ref PainterBrushShader is null,
51  * then it indicates to use the standard brush shader,
52  * \ref PainterBrushShaderSet::standard_brush().
53  */
55  {
56  public:
57  /*!
58  * Empty ctor that initializes to not have a brush source
59  * (custom or \ref PainterBrush).
60  */
61  brush_value(void):
62  m_brush_shader(nullptr)
63  {}
64 
65  /*!
66  * Ctor to set the brush_value to source from a
67  * \ref PainterBrush.
68  */
70  {
71  set(v);
72  }
73 
74  /*!
75  * Ctor to set the brush_value to source from a
76  * custom brush.
77  */
79  {
80  set(br);
81  }
82 
83  /*!
84  * Ctor to set the brush_value to source from a
85  * \ref PainterBrush packed.
86  */
88  {
89  set(brush_data);
90  }
91 
92  /*!
93  * Set to source from a \ref PainterBrush
94  */
95  void
96  set(const PainterBrush *v)
97  {
99  m_brush_shader_data = v;
100  m_brush_shader = nullptr;
101  }
102 
103  /*!
104  * Set to source from a custom brush shader
105  */
106  void
107  set(const PainterCustomBrush &br)
108  {
109  m_brush_shader_data = br.m_data;
110  m_brush_shader = br.m_shader;
111  }
112 
113  /*!
114  * Set to source from a packed PainterBrush value.
115  */
116  void
118  {
119  m_brush_shader_data = brush_data;
120  m_brush_shader = nullptr;
121  }
122 
123  /*!
124  * Returns the \ref PainterBrushShader for the brush;
125  * a value of nullptr indicates to used the default
126  * brush that processes \ref PainterBrush data.
127  */
128  const PainterBrushShader*
129  brush_shader(void) const
130  {
131  return m_brush_shader;
132  }
133 
134  /*!
135  * Returns the PainterDataValue<PainterBrushShaderData> holding
136  * the brush data.
137  */
139  brush_shader_data(void) const
140  {
141  return m_brush_shader_data;
142  }
143 
144  /*!
145  * Packs the brush shader data.
146  */
147  void
149  {
150  m_brush_shader_data.make_packed(pool);
151  }
152 
153  /*!
154  * Provided as a conveniance, equivalent to
155  * \code
156  * brush_shader_data().packed().
157  * \endcode
158  */
159  bool
160  packed(void) const
161  {
162  return m_brush_shader_data.packed();
163  }
164 
165  private:
166  /*!
167  * The \ref value for the brush data
168  */
169  PainterDataValue<PainterBrushShaderData> m_brush_shader_data;
170 
171  /*!
172  * If non-null, indicates that the brush is a realized
173  * by a custom brush shader.
174  */
175  const PainterBrushShader *m_brush_shader;
176  };
177 
178  /*!
179  * Ctor. Intitializes all fields as default nothings.
180  */
182  {}
183 
184  /*!
185  * Ctor to initialize one field.
186  * \param r1 calls one of the set() functions relying on C++
187  * conversion and template logic to select the correct
188  * field to set.
189  */
190  template<typename T1>
191  PainterData(const T1 &r1)
192  {
193  set(r1);
194  }
195 
196  /*!
197  * Ctor to initialize two fields.
198  * \param r1 calls one of the set() functions relying on C++
199  * conversion and template logic to select the correct
200  * field to set.
201  * \param r2 calls one of the set() functions relying on C++
202  * conversion and template logic to select the correct
203  * field to set.
204  */
205  template<typename T1, typename T2>
206  PainterData(const T1 &r1, const T2 &r2)
207  {
208  set(r1);
209  set(r2);
210  }
211 
212  /*!
213  * Ctor to initialize three fields.
214  * \param r1 calls one of the set() functions relying on C++
215  * conversion and template logic to select the correct
216  * field to set.
217  * \param r2 calls one of the set() functions relying on C++
218  * conversion and template logic to select the correct
219  * field to set.
220  * \param r3 calls one of the set() functions relying on C++
221  * conversion and template logic to select the correct
222  * field to set.
223  */
224  template<typename T1, typename T2, typename T3>
225  PainterData(const T1 &r1, const T2 &r2, const T3 &r3)
226  {
227  set(r1);
228  set(r2);
229  set(r3);
230  }
231 
232  /*!
233  * value for brush (fixed-function or custom brush shading).
234  */
236 
237  /*!
238  * value for item shader data
239  */
241 
242  /*!
243  * value for blend shader data
244  */
246 
247  /*!
248  * Sets \ref m_brush
249  */
250  PainterData&
251  set(const brush_value &value)
252  {
253  m_brush = value;
254  return *this;
255  }
256 
257  /*!
258  * Sets \ref m_brush
259  */
260  PainterData&
261  set(const PainterBrush *value)
262  {
263  m_brush = value;
264  return *this;
265  }
266 
267  /*!
268  * Sets \ref m_brush
269  */
270  PainterData&
271  set(const PainterCustomBrush &value)
272  {
273  m_brush.set(value);
274  return *this;
275  }
276 
277  /*!
278  * Sets \ref m_brush
279  */
280  PainterData&
282  {
283  m_brush.set(value);
284  return *this;
285  }
286 
287  /*!
288  * Sets \ref m_item_shader_data
289  */
290  PainterData&
292  {
293  m_item_shader_data = value;
294  return *this;
295  }
296 
297  /*!
298  * Sets \ref m_blend_shader_data
299  */
300  PainterData&
302  {
303  m_blend_shader_data = value;
304  return *this;
305  }
306 
307  /*!
308  * Call value::make_packed() on \ref m_brush,
309  * \ref m_item_shader_data, and \ref
310  * m_blend_shader_data.
311  * \param pool \ref PainterPackedValuePool from
312  * which to create the packed value
313  */
314  void
316  {
317  m_brush.make_packed(pool);
318  m_item_shader_data.make_packed(pool);
319  m_blend_shader_data.make_packed(pool);
320  }
321  };
322 
323 /*! @} */
324 }
325 
326 #endif
brush_value(const PainterCustomBrush &br)
A PainterPackedValuePool can be used to create PainterPackedValue objects.
PainterData(const T1 &r1, const T2 &r2, const T3 &r3)
A PainterData provides the data for how for a Painter to draw content.
void make_packed(PainterPackedValuePool &pool)
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
brush_value(const PainterDataValue< PainterBrushShaderData > &brush_data)
void set(const PainterBrush *v)
file painter_data_value.hpp
void make_packed(PainterPackedValuePool &pool)
file painter_shader_data.hpp
file painter_brush_shader_data.hpp
A PainterCustomBrush is just a conveniance to wrap a pointer to a PainterBrushShader together with a ...
PainterData(const T1 &r1, const T2 &r2)
file painter_brush.hpp
void make_packed(PainterPackedValuePool &pool)
A brush_value stores the brush applied; it stores a pointer to a PainterBrushShader together with a P...
brush_value(const PainterBrush *v)
PainterDataValue< PainterBlendShaderData > m_blend_shader_data
A PainterBrush defines a brush for painting via Painter.
const PainterDataValue< PainterBrushShaderData > & brush_shader_data(void) const
A PainterBrushShader represents a shader for performing a custom brush coloring.
PainterDataValue< PainterItemShaderData > m_item_shader_data
Element of PainterData to hold shader data either reference directly to unpacked data or to reuseable...
const PainterBrushShader * brush_shader(void) const
#define FASTUIDRAWassert(X)
Definition: util.hpp:99
file reference_counted.hpp