FastUIDraw
painter_effect_brush.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_effect_brush.hpp
3  * \brief file painter_effect_brush.hpp
4  *
5  * Copyright 2019 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_EFFECT_BRUSH_HPP
20 #define FASTUIDRAW_PAINTER_EFFECT_BRUSH_HPP
21 
22 #include <fastuidraw/util/vecN.hpp>
25 
26 namespace fastuidraw
27 {
28 /*!\addtogroup Painter
29  * @{
30  */
31 
32  /*!
33  * \brief
34  * A PainterEffectBrush represents applying a brush.
35  * The \ref PainterEffectParams derived object to use
36  * with a \ref PainterEffectBrush is \ref
37  * PainterEffectBrushParams
38  */
40  {
41  public:
42  virtual
43  unsigned int
44  number_passes(void) const override;
45 
46  virtual
48  brush(unsigned pass,
50  const Rect &brush_rect,
51  PainterEffectParams &params) const override;
52  };
53 
54  /*!
55  * The \ref PainterEffectParams derived object for
56  * \ref PainterEffectBrush
57  */
59  {
60  public:
61  /*!
62  * Set the modulate color, default value is
63  * (1, 1, 1, 1), i.e. no modulation.
64  */
66  color(const vec4 &v)
67  {
68  m_brush.color(v);
69  return *this;
70  }
71 
72  /*!
73  * Sets the brush to have a linear gradient.
74  * \param cs color stops for gradient. If handle is invalid,
75  * then sets brush to not have a gradient.
76  * \param start_p start position of gradient
77  * \param end_p end position of gradient.
78  * \param spread specifies the gradient spread type
79  */
82  const vec2 &start_p, const vec2 &end_p,
83  enum PainterBrush::spread_type_t spread)
84  {
85  m_brush.linear_gradient(cs, start_p, end_p, spread);
86  return *this;
87  }
88 
89  /*!
90  * Sets the brush to have a radial gradient.
91  * \param cs color stops for gradient. If handle is invalid,
92  * then sets brush to not have a gradient.
93  * \param start_p start position of gradient
94  * \param start_r starting radius of radial gradient
95  * \param end_p end position of gradient.
96  * \param end_r ending radius of radial gradient
97  * \param spread specifies the gradient spread type
98  */
101  const vec2 &start_p, float start_r,
102  const vec2 &end_p, float end_r,
103  enum PainterBrush::spread_type_t spread)
104  {
105  m_brush.radial_gradient(cs, start_p, start_r, end_p, end_r, spread);
106  return *this;
107  }
108 
109  /*!
110  * Sets the brush to have a radial gradient. Provided as
111  * a conveniance, equivalent to
112  * \code
113  * radial_gradient(cs, p, 0.0f, p, r, repeat);
114  * \endcode
115  * \param cs color stops for gradient. If handle is invalid,
116  * then sets brush to not have a gradient.
117  * \param p start and end position of gradient
118  * \param r ending radius of radial gradient
119  * \param spread specifies the gradient spread type
120  */
123  const vec2 &p, float r, enum PainterBrush::spread_type_t spread)
124  {
125  m_brush.radial_gradient(cs, p, r, spread);
126  return *this;
127  }
128 
129  /*!
130  * Sets the brush to have a sweep gradient (directly).
131  * \param cs color stops for gradient. If handle is invalid,
132  * then sets brush to not have a gradient.
133  * \param p position of gradient
134  * \param theta start angle of the sweep gradient, this value
135  * should be in the range [-PI, PI]
136  * \param F the repeat factor applied to the interpolate, the
137  * sign of F is used to determine the sign of the
138  * sweep gradient.
139  * \param spread specifies the gradient spread type
140  */
143  const vec2 &p, float theta, float F,
144  enum PainterBrush::spread_type_t spread)
145  {
146  m_brush.sweep_gradient(cs, p, theta, F, spread);
147  return *this;
148  }
149 
150  /*!
151  * Sets the brush to have a sweep gradient where the sign is
152  * determined by a PainterEnums::screen_orientation and a
153  * PainterEnums::rotation_orientation_t.
154  * \param cs color stops for gradient. If handle is invalid,
155  * then sets brush to not have a gradient.
156  * \param p position of gradient
157  * \param theta angle of the sweep gradient, this value
158  * should be in the range [-PI, PI]
159  * \param F the repeat factor applied to the interpolate,
160  * a negative reverses the orientation of the sweep.
161  * \param orientation orientation of the screen
162  * \param rotation_orientation orientation of the sweep
163  * \param spread specifies the gradient spread type
164  */
167  const vec2 &p, float theta,
168  enum PainterEnums::screen_orientation orientation,
169  enum PainterEnums::rotation_orientation_t rotation_orientation,
170  float F, enum PainterBrush::spread_type_t spread)
171  {
172  m_brush.sweep_gradient(cs, p, theta, orientation,
173  rotation_orientation, F, spread);
174  return *this;
175  }
176 
177  /*!
178  * Sets the brush to have a sweep gradient with a repeat factor
179  * of 1.0 and where the sign is determined by a
180  * PainterEnums::screen_orientation and a
181  * PainterEnums::rotation_orientation_t. Equivalent to
182  * \code
183  * sweep_gradient(cs, p, theta, orientation, rotation_orientation, 1.0f, repeat);
184  * \endcode
185  * \param cs color stops for gradient. If handle is invalid,
186  * then sets brush to not have a gradient.
187  * \param p position of gradient
188  * \param theta angle of the sweep gradient, this value
189  * should be in the range [-PI, PI]
190  * \param orientation orientation of the screen
191  * \param rotation_orientation orientation of the sweep
192  * \param spread specifies the gradient spread type
193  */
196  const vec2 &p, float theta,
197  enum PainterEnums::screen_orientation orientation,
198  enum PainterEnums::rotation_orientation_t rotation_orientation,
199  enum PainterBrush::spread_type_t spread)
200  {
201  m_brush.sweep_gradient(cs, p, theta, orientation,
202  rotation_orientation, spread);
203  return *this;
204  }
205 
206  /*!
207  * Sets the brush to not have a gradient.
208  */
211  {
212  m_brush.no_gradient();
213  return *this;
214  }
215 
216  /*!
217  * Sets the brush to have a translation in its transformation.
218  * \param p translation value for brush transformation
219  */
222  {
223  m_brush.transformation_translate(p);
224  return *this;
225  }
226 
227  /*!
228  * Sets the brush to have a matrix in its transformation.
229  * \param m matrix value for brush transformation
230  */
233  {
234  m_brush.transformation_matrix(m);
235  return *this;
236  }
237 
238  /*!
239  * Apply a shear to the transformation of the brush.
240  * \param m matrix to which to apply
241  */
244  {
245  m_brush.apply_matrix(m);
246  return *this;
247  }
248 
249  /*!
250  * Apply a shear to the transformation of the brush.
251  * \param sx scale factor in x-direction
252  * \param sy scale factor in y-direction
253  */
255  apply_shear(float sx, float sy)
256  {
257  m_brush.apply_shear(sx, sy);
258  return *this;
259  }
260 
261  /*!
262  * Apply a rotation to the transformation of the brush.
263  * \param angle in radians by which to rotate
264  */
266  apply_rotate(float angle)
267  {
268  m_brush.apply_rotate(angle);
269  return *this;
270  }
271 
272  /*!
273  * Apply a translation to the transformation of the brush.
274  */
277  {
278  m_brush.apply_translate(p);
279  return *this;
280  }
281 
282  /*!
283  * Sets the brush to have a matrix and translation in its
284  * transformation
285  * \param p translation value for brush transformation
286  * \param m matrix value for brush transformation
287  */
289  transformation(const vec2 &p, const float2x2 &m)
290  {
291  m_brush.transformation(p, m);
292  return *this;
293  }
294 
295  /*!
296  * Sets the brush to have no translation in its transformation.
297  */
300  {
302  return *this;
303  }
304 
305  /*!
306  * Sets the brush to have no matrix in its transformation.
307  */
310  {
311  m_brush.no_transformation_matrix();
312  return *this;
313  }
314 
315  /*!
316  * Sets the brush to have no transformation.
317  */
320  {
321  m_brush.no_transformation();
322  return *this;
323  }
324 
325  /*!
326  * Sets the brush to have a repeat window
327  * \param pos location of repeat window
328  * \param size of repeat window
329  * \param x_mode spread mode for x-coordinate
330  * \param y_mode spread mode for y-coordinate
331  */
333  repeat_window(const vec2 &pos, const vec2 &size,
336  {
337  m_brush.repeat_window(pos, size, x_mode, y_mode);
338  return *this;
339  }
340 
341  /*!
342  * Sets the brush to not have a repeat window
343  */
346  {
347  m_brush.no_repeat_window();
348  return *this;
349  }
350 
351  private:
352  friend class PainterEffectBrush;
353  PainterBrush m_brush;
354  };
355 
356 /*! @} */
357 };
358 
359 #endif
PainterEffectBrushParams & apply_matrix(const float2x2 &m)
PainterEffectBrushParams & radial_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &p, float r, enum PainterBrush::spread_type_t spread)
A PainterEffect represents the interface to define and effect to apply to image data. At its core, it is made up of a sequence of passes.
PainterEffectBrushParams & no_repeat_window(void)
screen_orientation
Enumeration to indicate in what direction the y-coordinate increases.
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
PainterEffectBrushParams & transformation_translate(const vec2 &p)
A wrapper over a pointer to implement reference counting.
PainterEffectBrushParams & radial_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &start_p, float start_r, const vec2 &end_p, float end_r, enum PainterBrush::spread_type_t spread)
PainterEffectBrushParams & no_transformation(void)
PainterEffectBrushParams & no_transformation_matrix(void)
PainterEffectBrushParams & no_gradient(void)
PainterEffectBrushParams & linear_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &start_p, const vec2 &end_p, enum PainterBrush::spread_type_t spread)
PainterEffectBrushParams & apply_rotate(float angle)
PainterEffectBrushParams & sweep_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &p, float theta, float F, enum PainterBrush::spread_type_t spread)
file painter_brush.hpp
PainterEffectBrushParams & apply_translate(const vec2 &p)
PainterEffectBrushParams & repeat_window(const vec2 &pos, const vec2 &size, enum PainterBrush::spread_type_t x_mode=PainterBrush::spread_repeat, enum PainterBrush::spread_type_t y_mode=PainterBrush::spread_repeat)
PainterEffectBrushParams & sweep_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &p, float theta, enum PainterEnums::screen_orientation orientation, enum PainterEnums::rotation_orientation_t rotation_orientation, enum PainterBrush::spread_type_t spread)
PainterEffectBrushParams & sweep_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &p, float theta, enum PainterEnums::screen_orientation orientation, enum PainterEnums::rotation_orientation_t rotation_orientation, float F, enum PainterBrush::spread_type_t spread)
PainterEffectBrushParams & transformation(const vec2 &p, const float2x2 &m)
virtual PainterData::brush_value brush(unsigned pass, const reference_counted_ptr< const Image > &image, const Rect &brush_rect, PainterEffectParams &params) const override
A brush_value stores the brush applied; it stores a pointer to a PainterBrushShader together with a P...
PainterEffectBrushParams & apply_shear(float sx, float sy)
virtual unsigned int number_passes(void) const override
PainterEffectBrushParams & no_transformation_translation(void)
rotation_orientation_t
Enumeration to specify orientation of a rotation.
A PainterBrush defines a brush for painting via Painter.
file vecN.hpp
PainterEffectBrushParams & color(const vec4 &v)
file painter_effect.hpp
A PainterEffectBrush represents applying a brush. The PainterEffectParams derived object to use with ...
PainterEffectBrushParams & transformation_matrix(const float2x2 &m)