FastUIDraw
painter_gradient_brush_shader.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_gradient_brush_shader.hpp
3  * \brief file painter_gradient_brush_shader.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 
20 #ifndef FASTUIDRAW_PAINTER_GRADIENT_BRUSH_SHADER_HPP
21 #define FASTUIDRAW_PAINTER_GRADIENT_BRUSH_SHADER_HPP
22 
24 #include <fastuidraw/painter/painter_custom_brush.hpp>
26 
27 namespace fastuidraw
28 {
29 
30 /*!\addtogroup PainterShaders
31  * @{
32  */
33 
34  /*!
35  * \brief
36  * A \ref PainterGradientBrushShader represents a set of brush shaders to
37  * to perform a gradient. Internally it containts four generic parent shaders:
38  * - a parent shader able to handle any gradient and spread type
39  * - a parent shader only for linear gradients able to handle any spread type
40  * - a parent shader only for radial gradients able to handle any spread type
41  * - a parent shader only for sweep gradients able to handle any spread type
42  */
44  public reference_counted<PainterGradientBrushShader>::concurrent,
45  public PainterBrushEnums
46  {
47  public:
48  /*!
49  * \brief
50  * Enumeration describing the roles of the bits for
51  * the sub-shader ID's.
52  */
54  {
55  /*!
56  * Number of bits used to encode a \ref spread_type_t
57  */
59 
60  /*!
61  * Number of bits used to encode the gradient type,
62  * see \ref PainterBrushEnums::gradient_type_t
63  */
65 
66  /*!
67  * first bit used to encode the \ref spread_type_t
68  */
70 
71  /*!
72  * first bit used to encode the \ref PainterBrushEnums::gradient_type_t
73  */
75 
76  /*!
77  * The total number of bits needed to specify the sub-shader IDs.
78  */
80 
81  /*!
82  * the total number of sub-shaders that the generic parent
83  * shader has.
84  */
86 
87  /*!
88  * the total number of sub-shaders that a parent shader for
89  * a specific gradient type has.
90  */
91  number_sub_shaders_of_specific_gradient = 1u << spread_type_num_bits
92  };
93 
94  /*!
95  * Various bit-mask values derived from \ref sub_shader_bits
96  */
98  {
99  /*!
100  * mask generated from \ref spread_type_bit0 and \ref spread_type_num_bits
101  */
103 
104  /*!
105  * mask generated from \ref gradient_type_bit0 and \ref gradient_type_num_bits
106  */
108  };
109 
110  /*!
111  * Ctor.
112  * \param generic \ref PainterBrushShader that supports all gradient and
113  * sweep types via its sub-shaders which are indexed by \ref
114  * sub_shader_id(enum spread_type_t, enum gradient_type_t)
115  * \param linear \ref PainterBrushShader that performs linear gradient
116  * that supports all sweep types via its sub-shaders which
117  * are indexed by \ref sub_shader_id(enum spread_type_t)
118  * \param radial \ref PainterBrushShader that performs radial gradient
119  * that supports all sweep types via its sub-shaders which
120  * are indexed by \ref sub_shader_id(enum spread_type_t)
121  * \param sweep \ref PainterBrushShader that performs sweep gradient
122  * that supports all sweep types via its sub-shaders which
123  * are indexed by \ref sub_shader_id(enum spread_type_t)
124  * \param white \ref PainterBrushShader that applied solid white for the brush
125  */
131 
133 
134  /*!
135  * Returns the sub-shader of the generic parent shader for
136  * specified \ref gradient_type_t and \ref spread_type_t
137  * values.
138  */
140  sub_shader(enum spread_type_t, enum gradient_type_t) const;
141 
142  /*!
143  * Returns the sub-shader of the linear gradient parent shader
144  * for a specified \ref spread_type_t value.
145  */
147  linear_sub_shader(enum spread_type_t) const;
148 
149  /*!
150  * Returns the sub-shader of the radial gradient parent shader
151  * for a specified \ref spread_type_t value.
152  */
154  radial_sub_shader(enum spread_type_t) const;
155 
156  /*!
157  * Returns the sub-shader of the sweep gradient parent shader
158  * for a specified \ref spread_type_t value.
159  */
161  sweep_sub_shader(enum spread_type_t) const;
162 
163  /*!
164  * Returns the white shader, i.e. the shader that is
165  * solid white to the brush.
166  */
168  white_shader(void) const;
169 
170  /*!
171  * Create a \ref PainterCustomBrush from a \ref
172  * PainterGradientBrushShaderData
173  * \param pool \ref PainterPackedValuePool used to create the packed value
174  * \param brush_data \ref PainterGradientBrushShaderData specifing gradient
175  * \param spread spread pattern for gradient
176  */
179  const PainterGradientBrushShaderData &brush_data,
180  enum spread_type_t spread) const;
181 
182  /*!
183  * The sub-shader to take from the generic parent shader
184  * for specified \ref gradient_type_t and \ref spread_type_t
185  * values.
186  */
187  static
188  uint32_t
190 
191  /*!
192  * The sub-shader to take from the linear, radial or sweep
193  * parent shader for a specified \ref spread_type_t value.
194  */
195  static
196  uint32_t
198 
199  private:
200  void *m_d;
201  };
202 
203 /*! @} */
204 }
205 
206 #endif
static uint32_t sub_shader_id(enum spread_type_t, enum gradient_type_t)
#define FASTUIDRAW_MASK(BIT0, NUMBITS)
Definition: util.hpp:59
A PainterPackedValuePool can be used to create PainterPackedValue objects.
A PainterGradientBrushShaderData defines the PainterBrushShaderData that the shaders of a PainterGrad...
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A wrapper over a pointer to implement reference counting.
file painter_brush_shader.hpp
PainterGradientBrushShader(const reference_counted_ptr< PainterBrushShader > &generic, const reference_counted_ptr< PainterBrushShader > &linear, const reference_counted_ptr< PainterBrushShader > &radial, const reference_counted_ptr< PainterBrushShader > &sweep, const reference_counted_ptr< PainterBrushShader > &white)
const reference_counted_ptr< PainterBrushShader > & sweep_sub_shader(enum spread_type_t) const
A PainterCustomBrush is just a conveniance to wrap a pointer to a PainterBrushShader together with a ...
file painter_gradient_brush_shader_data.hpp
sub_shader_bits
Enumeration describing the roles of the bits for the sub-shader ID&#39;s.
Defines default reference counting base classes.
const reference_counted_ptr< PainterBrushShader > & linear_sub_shader(enum spread_type_t) const
const reference_counted_ptr< PainterBrushShader > & radial_sub_shader(enum spread_type_t) const
Class to contain various enumerations needed for describing a brush.
A PainterGradientBrushShader represents a set of brush shaders to to perform a gradient. Internally it containts four generic parent shaders:
const reference_counted_ptr< PainterBrushShader > & white_shader(void) const
PainterCustomBrush create_brush(PainterPackedValuePool &pool, const PainterGradientBrushShaderData &brush_data, enum spread_type_t spread) const
const reference_counted_ptr< PainterBrushShader > & sub_shader(enum spread_type_t, enum gradient_type_t) const