FastUIDraw
painter_brush.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_brush.hpp
3  * \brief file painter_brush.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 
20 #ifndef FASTUIDRAW_PAINTER_BRUSH_HPP
21 #define FASTUIDRAW_PAINTER_BRUSH_HPP
22 
24 #include <fastuidraw/util/vecN.hpp>
27 #include <fastuidraw/util/math.hpp>
28 
29 #include <fastuidraw/image.hpp>
36 
37 namespace fastuidraw
38 {
39 /*!\addtogroup Painter
40  * @{
41  */
42 
43  /*!
44  * \brief
45  * A PainterBrush defines a brush for painting via Painter.
46  *
47  * The brush applies, in the following order:
48  * -# a constant color, specified by \ref color()
49  * -# optionally modulates by an image, specified by \ref
50  * image() or \ref sub_image() and \ref no_image()
51  * -# optionally modulates by a gradient, see \ref
52  * linear_gradient(), \ref radial_gradient(),
53  * sweep_gradient() and \ref no_gradient().
54  *
55  * An item shader's vertex stage provides the coordinate
56  * fed to the brush. That coordinate is procesed in the
57  * following order before it is fed to the image and gradient:
58  * -# an optional 2x2 matrix is applied, see \ref
59  * transformation_matrix(), \ref apply_matrix()
60  * \ref apply_shear(), \ref apply_rotate()
61  * and \ref no_transformation_matrix()
62  * -# an optional translation is applied specified, see
63  * \ref transformation_translate(), apply_matrix()
64  * \ref apply_translate() and \ref no_transformation_translation()
65  * -# an optional repeat window is applied, see \ref
66  * repeat_window() and \ref no_repeat_window().
67  */
68  class PainterBrush:
70  public PainterBrushEnums
71  {
72  public:
73  /*!
74  * \brief
75  * Enumeration describing the roles of the bits for
76  * \ref features().
77  */
79  {
80  /*!
81  * Number of bits needed to encode if and how
82  * an \ref Image is sourced from.
83  */
85 
86  /*!
87  * Number of bits used to encode the gradient type,
88  * see \ref PainterBrushEnums::gradient_type_t
89  */
91 
92  /*!
93  * First bit to encode if and how the brush sources
94  * from an \ref Image
95  */
97 
98  /*!
99  * first bit used to encode the \ref PainterBrushEnums::gradient_type_t
100  */
102 
103  /*!
104  * Bit up if the brush has a repeat window
105  */
107 
108  /* First bit used to encore the spread mode for the x-coordinate
109  * if a repeat window is active
110  */
111  repeat_window_x_spread_type_bit0,
112 
113  /* First bit used to encore the spread mode for the x-coordinate
114  * if a repeat window is active
115  */
116  repeat_window_y_spread_type_bit0 = repeat_window_x_spread_type_bit0 + PainterGradientBrushShader::spread_type_num_bits,
117 
118  /*!
119  * Bit up if transformation 2x2 matrix is present
120  */
122 
123  /*!
124  * Bit up is translation is present
125  */
127 
128  /*!
129  * Must be last enum, gives number of bits needed to hold feature bits
130  * of a PainterBrush.
131  */
133  };
134 
135  /*!
136  * \brief
137  * Masks generated from \ref feature_bits, use these masks on the
138  * return value of \ref features() to get what features
139  * are active on the brush.
140  */
142  {
143  /*!
144  * mask generated from \ref image_bit0 and \ref image_num_bits
145  */
147 
148  /*!
149  * mask generated from \ref gradient_bit0 and \ref gradient_num_bits
150  */
152 
153  /*!
154  * mask generated from \ref repeat_window_bit
155  */
157 
158  /*!
159  * mask generated from \ref repeat_window_x_spread_type
160  * and \ref PainterGradientBrushShader::spread_type_num_bits
161  */
162  repeat_window_x_spread_type_mask = FASTUIDRAW_MASK(repeat_window_x_spread_type_bit0,
164 
165  /*!
166  * mask generated from \ref repeat_window_y_spread_type
167  * and \ref PainterGradientBrushShader::spread_type_num_bits
168  */
169  repeat_window_y_spread_type_mask = FASTUIDRAW_MASK(repeat_window_y_spread_type_bit0,
171 
172  /*!
173  * mask of \ref repeat_window_x_spread_type_mask and \ref
174  * repeat_window_y_spread_type bitwise or'd together
175  */
177 
178  /*!
179  * mask generated from \ref transformation_translation_bit
180  */
182 
183  /*!
184  * mask generated from \ref transformation_matrix_bit
185  */
187  };
188 
189  /*!
190  * \brief
191  * Enumeration giving the packing order for data of a brush.
192  * Each enumeration is an entry and when data is packed each
193  * entry starts on a multiple of the 4.
194  */
196  {
197  /*!
198  * Color packed first, see \ref header_offset_t
199  * for the offsets for the individual fields
200  */
202 
203  /*!
204  * repeat window packing, see \ref
205  * repeat_window_offset_t for the offsets
206  * for the individual fields
207  */
209 
210  /*!
211  * transformation_translation, see \ref
212  * transformation_translation_offset_t for the
213  * offsets of the individual fields
214  */
216 
217  /*!
218  * transformation_matrix, see \ref
219  * transformation_matrix_offset_t for the
220  * offsets of the individual fields
221  */
223 
224  /*!
225  * image packing as packed by \ref PainterImageBrushShaderData
226  */
228 
229  /*!
230  * gradient packing, as packed by \ref
231  * PainterGradientBrushShaderData
232  */
234  };
235 
236  /*!
237  * \brief
238  * enumerations for offsets to color values
239  */
241  {
242  features_offset, /*!< offset to value of features() (packed as uint) */
243  header_red_green_offset, /*!< offset for color red and green value (packed as fp16 pair) */
244  header_blue_alpha_offset, /*!< offset for color blue and alpha value (packed as fp16 pair) */
245 
246  header_data_size /*!< number of elements to pack color */
247  };
248 
249  /*!
250  * \brief
251  * Enumeration that provides offset from the start of
252  * repeat window packing to data for repeat window data
253  */
255  {
256  repeat_window_x_offset, /*!< offset for the x-position of the repeat window (packed at float) */
257  repeat_window_y_offset, /*!< offset for the y-position of the repeat window (packed at float) */
258  repeat_window_width_offset, /*!< offset for the width of the repeat window (packed at float) */
259  repeat_window_height_offset, /*!< offset for the height of the repeat window (packed at float) */
260  repeat_window_data_size /*!< size of data for repeat window */
261  };
262 
263  /*!
264  * \brief
265  * Enumeration that provides offset from the start of
266  * repeat transformation matrix to data for the transformation
267  * matrix data
268  */
270  {
271  transformation_matrix_row0_col0_offset, /*!< offset for float2x2(0, 0) (packed at float) */
272  transformation_matrix_row0_col1_offset, /*!< offset for float2x2(0, 1) (packed at float) */
273  transformation_matrix_row1_col0_offset, /*!< offset for float2x2(1, 0) (packed at float) */
274  transformation_matrix_row1_col1_offset, /*!< offset for float2x2(1, 1) (packed at float) */
275  transformation_matrix_data_size, /*!< size of data for transformation matrix */
276 
277  transformation_matrix_col0_row0_offset = transformation_matrix_row0_col0_offset, /*!< alias of \ref transformation_matrix_row0_col0_offset */
278  transformation_matrix_col0_row1_offset = transformation_matrix_row1_col0_offset, /*!< alias of \ref transformation_matrix_row1_col0_offset */
279  transformation_matrix_col1_row0_offset = transformation_matrix_row0_col1_offset, /*!< alias of \ref transformation_matrix_row0_col1_offset */
280  transformation_matrix_col1_row1_offset = transformation_matrix_row1_col1_offset, /*!< alias of \ref transformation_matrix_row1_col1_offset */
281  };
282 
283  /*!
284  * \brief
285  * Enumeration that provides offset from the start of
286  * repeat transformation translation to data for the
287  * transformation translation data
288  */
290  {
291  transformation_translation_x_offset = 0, /*!< offset for x-coordinate of translation (packed at float) */
292  transformation_translation_y_offset, /*!< offset for y-coordinate of translation (packed at float) */
293  transformation_translation_data_size /*!< size of data for transformation translation (packed at float) */
294  };
295 
296  /*!
297  * Ctor. Initializes the brush to have no image, no gradient,
298  * no repeat window and no transformation with the color as
299  * (1.0, 1.0, 1.0, 1.0) which is solid white.
300  */
302  {}
303 
304  /*!
305  * Copy ctor.
306  */
308  m_data(obj.m_data)
309  {}
310 
311  /*!
312  * Ctor. Initializes the brush to have no image, no gradient,
313  * no repeat window and no transformation with the given
314  * color color.
315  * \param pcolor inital color
316  */
317  PainterBrush(const vec4 &pcolor)
318  {
319  m_data.m_color = pcolor;
320  }
321 
322  /*!
323  * Assignment operator.
324  * \param obj value from which to copy
325  */
326  PainterBrush&
328  {
329  m_data = obj.m_data;
330  return *this;
331  }
332 
333  /*!
334  * Reset the brush to initial conditions.
335  */
336  PainterBrush&
337  reset(void);
338 
339  /*!
340  * Set the color to the color, default value is (1.0, 1.0, 1.0, 1.0).
341  */
342  PainterBrush&
343  color(const vec4 &color)
344  {
345  m_data.m_color = color;
346  return *this;
347  }
348 
349  /*!
350  * Set the color to the color, default value is (1.0, 1.0, 1.0, 1.0).
351  */
352  PainterBrush&
353  color(float r, float g, float b, float a = 1.0f)
354  {
355  return color(vec4(r, g, b, a));
356  }
357 
358  /*!
359  * Returns the current color-color.
360  */
361  const vec4&
362  color(void) const
363  {
364  return m_data.m_color;
365  }
366 
367  /*!
368  * Sets the brush to have an image.
369  * \param im handle to image to use. If handle is invalid,
370  * then sets brush to not have an image.
371  * \param f filter to apply to image, only has effect if im
372  * is non-nullptr
373  * \param mipmap_filtering specifies if to apply mipmap filtering
374  */
375  PainterBrush&
377  enum filter_t f = filter_linear,
378  enum mipmap_t mipmap_filtering = apply_mipmapping);
379 
380  /*!
381  * Set the brush to source from a sub-rectangle of an image
382  * \param im handle to image to use
383  * \param xy min-corner of sub-rectangle of image to use
384  * \param wh width and height of sub-rectangle of image to use
385  * \param f filter to apply to image, only has effect if im
386  * is non-nullptr
387  * \param mipmap_filtering specifies if to apply mipmap filtering
388  */
389  PainterBrush&
391  enum filter_t f = filter_linear,
392  enum mipmap_t mipmap_filtering = apply_mipmapping);
393 
394  /*!
395  * Sets the brush to not have an image.
396  */
397  PainterBrush&
398  no_image(void)
399  {
401  }
402 
403  /*!
404  * Sets the brush to have a linear gradient.
405  * \param cs color stops for gradient. If handle is invalid,
406  * then sets brush to not have a gradient.
407  * \param start_p start position of gradient
408  * \param end_p end position of gradient.
409  * \param spread specifies the gradient spread type
410  */
411  PainterBrush&
413  const vec2 &start_p, const vec2 &end_p,
414  enum spread_type_t spread)
415  {
416  m_data.m_gradient.linear_gradient(cs, start_p, end_p);
417  update_gradient_bits(spread);
418  return *this;
419  }
420 
421  /*!
422  * Sets the brush to have a radial gradient.
423  * \param cs color stops for gradient. If handle is invalid,
424  * then sets brush to not have a gradient.
425  * \param start_p start position of gradient
426  * \param start_r starting radius of radial gradient
427  * \param end_p end position of gradient.
428  * \param end_r ending radius of radial gradient
429  * \param spread specifies the gradient spread type
430  */
431  PainterBrush&
433  const vec2 &start_p, float start_r,
434  const vec2 &end_p, float end_r,
435  enum spread_type_t spread)
436  {
437  m_data.m_gradient.radial_gradient(cs, start_p, start_r, end_p, end_r);
438  update_gradient_bits(spread);
439  return *this;
440  }
441 
442  /*!
443  * Sets the brush to have a radial gradient. Provided as
444  * a conveniance, equivalent to
445  * \code
446  * radial_gradient(cs, p, 0.0f, p, r, repeat);
447  * \endcode
448  * \param cs color stops for gradient. If handle is invalid,
449  * then sets brush to not have a gradient.
450  * \param p start and end position of gradient
451  * \param r ending radius of radial gradient
452  * \param spread specifies the gradient spread type
453  */
454  PainterBrush&
456  const vec2 &p, float r, enum spread_type_t spread)
457  {
458  m_data.m_gradient.radial_gradient(cs, p, 0.0f, p, r);
459  update_gradient_bits(spread);
460  return *this;
461  }
462 
463  /*!
464  * Sets the brush to have a sweep gradient (directly).
465  * \param cs color stops for gradient. If handle is invalid,
466  * then sets brush to not have a gradient.
467  * \param p position of gradient
468  * \param theta start angle of the sweep gradient, this value
469  * should be in the range [-PI, PI]
470  * \param F the repeat factor applied to the interpolate, the
471  * sign of F is used to determine the sign of the
472  * sweep gradient.
473  * \param spread specifies the gradient spread type
474  */
475  PainterBrush&
477  const vec2 &p, float theta, float F,
478  enum spread_type_t spread)
479  {
480  m_data.m_gradient.sweep_gradient(cs, p, theta, F);
481  update_gradient_bits(spread);
482  return *this;
483  }
484 
485  /*!
486  * Sets the brush to have a sweep gradient where the sign is
487  * determined by a PainterEnums::screen_orientation and a
488  * PainterEnums::rotation_orientation_t.
489  * \param cs color stops for gradient. If handle is invalid,
490  * then sets brush to not have a gradient.
491  * \param p position of gradient
492  * \param theta angle of the sweep gradient, this value
493  * should be in the range [-PI, PI]
494  * \param F the repeat factor applied to the interpolate,
495  * a negative reverses the orientation of the sweep.
496  * \param orientation orientation of the screen
497  * \param rotation_orientation orientation of the sweep
498  * \param spread specifies the gradient spread type
499  */
500  PainterBrush&
502  const vec2 &p, float theta,
503  enum PainterEnums::screen_orientation orientation,
504  enum PainterEnums::rotation_orientation_t rotation_orientation,
505  float F, enum spread_type_t spread)
506  {
507  m_data.m_gradient.sweep_gradient(cs, p, theta, orientation,
508  rotation_orientation, F);
509  update_gradient_bits(spread);
510  return *this;
511  }
512 
513  /*!
514  * Sets the brush to have a sweep gradient with a repeat factor
515  * of 1.0 and where the sign is determined by a
516  * PainterEnums::screen_orientation and a
517  * PainterEnums::rotation_orientation_t. Equivalent to
518  * \code
519  * sweep_gradient(cs, p, theta, orientation, rotation_orientation, 1.0f, repeat);
520  * \endcode
521  * \param cs color stops for gradient. If handle is invalid,
522  * then sets brush to not have a gradient.
523  * \param p position of gradient
524  * \param theta angle of the sweep gradient, this value
525  * should be in the range [-PI, PI]
526  * \param orientation orientation of the screen
527  * \param rotation_orientation orientation of the sweep
528  * \param spread specifies the gradient spread type
529  */
530  PainterBrush&
532  const vec2 &p, float theta,
533  enum PainterEnums::screen_orientation orientation,
534  enum PainterEnums::rotation_orientation_t rotation_orientation,
535  enum spread_type_t spread)
536  {
537  m_data.m_gradient.sweep_gradient(cs, p, theta, orientation,
538  rotation_orientation);
539  update_gradient_bits(spread);
540  return *this;
541  }
542 
543  /*!
544  * Sets the brush to not have a gradient.
545  */
546  PainterBrush&
548  {
549  m_data.m_gradient.reset();
550  update_gradient_bits(spread_clamp);
551  return *this;
552  }
553 
554  /*!
555  * Return the gradient_type_t that the brush applies.
556  */
557  enum gradient_type_t
558  gradient_type(void) const
559  {
560  return m_data.m_gradient.type();
561  }
562 
563  /*!
564  * Sets the brush to have a translation in its transformation.
565  * \param p translation value for brush transformation
566  */
567  PainterBrush&
569  {
570  m_data.m_transformation_p = p;
571  m_data.m_features_raw |= transformation_translation_mask;
572  return *this;
573  }
574 
575  /*!
576  * Returns the translation of the transformation of the brush.
577  */
578  const vec2&
580  {
581  return m_data.m_transformation_p;
582  }
583 
584  /*!
585  * Sets the brush to have a matrix in its transformation.
586  * \param m matrix value for brush transformation
587  */
588  PainterBrush&
590  {
591  m_data.m_transformation_matrix = m;
592  m_data.m_features_raw |= transformation_matrix_mask;
593  return *this;
594  }
595 
596  /*!
597  * Returns the matrix of the transformation of the brush.
598  */
599  const float2x2&
601  {
602  return m_data.m_transformation_matrix;
603  }
604 
605  /*!
606  * Apply a shear to the transformation of the brush.
607  * \param m matrix to which to apply
608  */
609  PainterBrush&
611  {
612  m_data.m_features_raw |= transformation_matrix_mask;
613  m_data.m_transformation_matrix = m_data.m_transformation_matrix * m;
614  return *this;
615  }
616 
617  /*!
618  * Apply a shear to the transformation of the brush.
619  * \param sx scale factor in x-direction
620  * \param sy scale factor in y-direction
621  */
622  PainterBrush&
623  apply_shear(float sx, float sy)
624  {
625  m_data.m_features_raw |= transformation_matrix_mask;
626  m_data.m_transformation_matrix(0, 0) *= sx;
627  m_data.m_transformation_matrix(1, 0) *= sx;
628  m_data.m_transformation_matrix(0, 1) *= sy;
629  m_data.m_transformation_matrix(1, 1) *= sy;
630  return *this;
631  }
632 
633  /*!
634  * Apply a rotation to the transformation of the brush.
635  * \param angle in radians by which to rotate
636  */
637  PainterBrush&
638  apply_rotate(float angle)
639  {
640  float s, c;
641  float2x2 tr;
642 
643  s = t_sin(angle);
644  c = t_cos(angle);
645  tr(0, 0) = c;
646  tr(1, 0) = s;
647  tr(0, 1) = -s;
648  tr(1, 1) = c;
649  apply_matrix(tr);
650  return *this;
651  }
652 
653  /*!
654  * Apply a translation to the transformation of the brush.
655  */
656  PainterBrush&
658  {
659  m_data.m_transformation_p += m_data.m_transformation_matrix * p;
660  m_data.m_features_raw |= transformation_translation_mask;
661  return *this;
662  }
663 
664  /*!
665  * Sets the brush to have a matrix and translation in its
666  * transformation
667  * \param p translation value for brush transformation
668  * \param m matrix value for brush transformation
669  */
670  PainterBrush&
671  transformation(const vec2 &p, const float2x2 &m)
672  {
675  return *this;
676  }
677 
678  /*!
679  * Sets the brush to have no translation in its transformation.
680  */
681  PainterBrush&
683  {
684  m_data.m_features_raw &= ~transformation_translation_mask;
685  m_data.m_transformation_p = vec2(0.0f, 0.0f);
686  return *this;
687  }
688 
689  /*!
690  * Sets the brush to have no matrix in its transformation.
691  */
692  PainterBrush&
694  {
695  m_data.m_features_raw &= ~transformation_matrix_mask;
696  m_data.m_transformation_matrix = float2x2();
697  return *this;
698  }
699 
700  /*!
701  * Sets the brush to have no transformation.
702  */
703  PainterBrush&
705  {
708  return *this;
709  }
710 
711  /*!
712  * Sets the brush to have a repeat window
713  * \param pos location of repeat window
714  * \param size of repeat window
715  * \param x_mode spread mode for x-coordinate
716  * \param y_mode spread mode for y-coordinate
717  */
718  PainterBrush&
719  repeat_window(const vec2 &pos, const vec2 &size,
720  enum spread_type_t x_mode = spread_repeat,
721  enum spread_type_t y_mode = spread_repeat)
722  {
723  m_data.m_window_position = pos;
724  m_data.m_window_size = size;
725  m_data.m_features_raw |= repeat_window_mask;
726  m_data.m_features_raw &= ~repeat_window_spread_type_mask;
727  m_data.m_features_raw |= pack_bits(repeat_window_x_spread_type_bit0,
729  x_mode);
730  m_data.m_features_raw |= pack_bits(repeat_window_y_spread_type_bit0,
732  y_mode);
733  return *this;
734  }
735 
736  /*!
737  * Returns true if a repeat window is applied to the
738  * brush and writes out the position and size of
739  * the repeat window as well.
740  */
741  bool
742  repeat_window(vec2 *pos, vec2 *size) const
743  {
744  *pos = m_data.m_window_position;
745  *size = m_data.m_window_size;
746  return m_data.m_features_raw & repeat_window_mask;
747  }
748 
749  /*!
750  * Returns the x-coordinate spread type. Return
751  * value is undefined if the repeat_window() is
752  * not active.
753  */
754  enum spread_type_t
756  {
757  uint32_t v;
758  v = unpack_bits(repeat_window_x_spread_type_bit0,
760  m_data.m_features_raw);
761  return static_cast<enum spread_type_t>(v);
762  }
763 
764  /*!
765  * Returns the y-coordinate spread type. Return
766  * value is undefined if the repeat_window() is
767  * not active.
768  */
769  enum spread_type_t
771  {
772  uint32_t v;
773  v = unpack_bits(repeat_window_y_spread_type_bit0,
775  m_data.m_features_raw);
776  return static_cast<enum spread_type_t>(v);
777  }
778 
779  /*!
780  * Sets the brush to not have a repeat window
781  */
782  PainterBrush&
784  {
785  m_data.m_features_raw &= ~(repeat_window_mask | repeat_window_spread_type_mask);
786  return *this;
787  }
788 
789  /*!
790  * Returns the brush features which when tested against the
791  * bit masks from \ref feature_masks tells what features are
792  * active in the brush; \ref features() is decoded as follows:
793  *
794  * - The value given by
795  * \code
796  * unpack_bits(image_filter_bit0, image_filter_num_bits, features())
797  * \endcode
798  * is non-zero if an image is present and meannig of the value
799  * is encoded by \ref PainterImageBrushShader::sub_shader_bits
800  * - The value given by
801  * \code
802  * unpack_bits(gradient_bit0, gradient_num_bits, features())
803  * \endcode
804  * gives what gradient (if any) and spread type the brush applies as
805  * encoded by \ref PainterGradientBrushShader::sub_shader_bits
806  * - If features() & \ref repeat_window_mask is non-zero, then a repeat
807  * window is applied to the brush.
808  * - If features() & \ref transformation_translation_mask is non-zero, then a
809  * translation is applied to the brush.
810  * - If features() & \ref transformation_matrix_mask is non-zero, then a
811  * 2x2 matrix is applied to the brush.
812  */
813  uint32_t
814  features(void) const;
815 
816  /*!
817  * Returns a reference to the Image that the brush is set
818  * to use; if there is no such image, returns nullptr.
819  */
821  image(void) const
822  {
823  return m_data.m_image.image();
824  }
825 
826  /*!
827  * Returns the value of the handle to the
828  * ColorStopSequence that the
829  * brush is set to use.
830  */
832  color_stops(void) const
833  {
834  return m_data.m_gradient.color_stops();
835  }
836 
837  unsigned int
838  data_size(void) const override;
839 
840  void
841  pack_data(c_array<uvec4> dst) const override;
842 
843  void
845  {
846  dst[0] = m_data.m_image.image();
847  dst[1] = m_data.m_gradient.color_stops();
848  }
849 
850  unsigned int
851  number_resources(void) const override
852  {
853  return 2;
854  }
855 
857  bind_images(void) const override
858  {
859  return m_data.m_image.bind_images();
860  }
861 
862  private:
863  class brush_data
864  {
865  public:
866  brush_data(void):
867  m_features_raw(0),
868  m_color(1.0f, 1.0f, 1.0f, 1.0f),
869  m_window_position(0.0f, 0.0f),
870  m_window_size(1.0f, 1.0f),
871  m_transformation_matrix(),
872  m_transformation_p(0.0f, 0.0f)
873  {}
874 
875  uint32_t m_features_raw;
876  vec4 m_color;
879  vec2 m_window_position, m_window_size;
880  float2x2 m_transformation_matrix;
881  vec2 m_transformation_p;
882  };
883 
884  void
885  update_gradient_bits(enum spread_type_t spread)
886  {
887  uint32_t gradient_bits;
888 
889  gradient_bits = (m_data.m_gradient.type() != gradient_non) ?
890  PainterGradientBrushShader::sub_shader_id(spread, m_data.m_gradient.type()) :
891  0u;
892  gradient_bits = pack_bits(gradient_bit0,
894  gradient_bits);
895 
896  m_data.m_features_raw &= ~gradient_mask;
897  m_data.m_features_raw |= gradient_bits;
898  }
899 
900  brush_data m_data;
901  };
902 /*! @} */
903 }
904 
905 #endif
file painter_image_brush_shader.hpp
static uint32_t sub_shader_id(enum spread_type_t, enum gradient_type_t)
#define FASTUIDRAW_MASK(BIT0, NUMBITS)
Definition: util.hpp:59
transformation_translation_offset_t
Enumeration that provides offset from the start of repeat transformation translation to data for the ...
uint32_t unpack_bits(uint32_t bit0, uint32_t num_bits, uint32_t value)
Definition: util.hpp:328
PainterBrush & transformation(const vec2 &p, const float2x2 &m)
PainterBrush & no_image(void)
const reference_counted_ptr< const Image > & image(void) const
PainterBrush & no_transformation(void)
unsigned int data_size(void) const override
PainterBrush & apply_shear(float sx, float sy)
float t_cos(float x)
Definition: math.hpp:82
A PainterGradientBrushShaderData defines the PainterBrushShaderData that the shaders of a PainterGrad...
screen_orientation
Enumeration to indicate in what direction the y-coordinate increases.
file matrix.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
uint32_t features(void) const
feature_bits
Enumeration describing the roles of the bits for features().
unsigned int number_resources(void) const override
A wrapper over a pointer to implement reference counting.
PainterBrush & apply_translate(const vec2 &p)
PainterBrush & transformation_matrix(const float2x2 &m)
PainterBrush & radial_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &p, float r, enum spread_type_t spread)
A PainterImageBrushShaderData defines the PainterBrushShaderData that the shaders of a PainterImageBr...
PainterBrush & linear_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &start_p, const vec2 &end_p, enum spread_type_t spread)
PainterBrush & no_transformation_translation(void)
PainterBrush & no_gradient(void)
PainterBrush & operator=(const PainterBrush &obj)
file painter_gradient_brush_shader.hpp
void pack_data(c_array< uvec4 > dst) const override
PainterBrush(const vec4 &pcolor)
PainterBrush & sub_image(const reference_counted_ptr< const Image > &im, uvec2 xy, uvec2 wh, enum filter_t f=filter_linear, enum mipmap_t mipmap_filtering=apply_mipmapping)
matrixNxM< 2, 2, float > float2x2
Convenience typedef to matrixNxM<2, float>
Definition: matrix.hpp:362
PainterBrush & 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 spread_type_t spread)
file painter_shader_data.hpp
file c_array.hpp
file painter_brush_shader_data.hpp
PainterBrush & reset(void)
PainterBrush & color(float r, float g, float b, float a=1.0f)
vecN< float, 2 > vec2
Definition: vecN.hpp:1231
transformation_matrix_offset_t
Enumeration that provides offset from the start of repeat transformation matrix to data for the trans...
PainterBrush & apply_rotate(float angle)
file math.hpp
PainterBrush & no_transformation_matrix(void)
const vec4 & color(void) const
PainterBrush(const PainterBrush &obj)
enum gradient_type_t gradient_type(void) const
Base class to hold custom data for custom brush shaders.
float t_sin(float x)
Definition: math.hpp:75
enum spread_type_t repeat_window_y_spread_type(void) const
A c_array is a wrapper over a C pointer with a size parameter to facilitate bounds checking and provi...
Definition: c_array.hpp:43
file painter_enums.hpp
PainterBrush & 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 spread_type_t spread)
rotation_orientation_t
Enumeration to specify orientation of a rotation.
A PainterBrush defines a brush for painting via Painter.
file vecN.hpp
PainterBrush & transformation_translate(const vec2 &p)
PainterBrush & color(const vec4 &color)
uint32_t pack_bits(uint32_t bit0, uint32_t num_bits, uint32_t value)
Definition: util.hpp:294
bool repeat_window(vec2 *pos, vec2 *size) const
packing_order_t
Enumeration giving the packing order for data of a brush. Each enumeration is an entry and when data ...
enum spread_type_t repeat_window_x_spread_type(void) const
PainterBrush & no_repeat_window(void)
filter_t
Enumeration specifying what filter to apply to an image.
file colorstop_atlas.hpp
const float2x2 & transformation_matrix(void) const
vecN< float, 4 > vec4
Definition: vecN.hpp:1239
void save_resources(c_array< reference_counted_ptr< const resource_base > > dst) const override
PainterBrush & apply_matrix(const float2x2 &m)
PainterBrush & sweep_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &p, float theta, float F, enum spread_type_t spread)
PainterBrush & repeat_window(const vec2 &pos, const vec2 &size, enum spread_type_t x_mode=spread_repeat, enum spread_type_t y_mode=spread_repeat)
const vec2 & transformation_translate(void) const
feature_masks
Masks generated from feature_bits, use these masks on the return value of features() to get what feat...
Class to contain various enumerations needed for describing a brush.
header_offset_t
enumerations for offsets to color values
repeat_window_offset_t
Enumeration that provides offset from the start of repeat window packing to data for repeat window da...
PainterBrush & radial_gradient(const reference_counted_ptr< const ColorStopSequence > &cs, const vec2 &start_p, float start_r, const vec2 &end_p, float end_r, enum spread_type_t spread)
c_array< const reference_counted_ptr< const Image > > bind_images(void) const override
const reference_counted_ptr< const ColorStopSequence > & color_stops(void) const
file image.hpp
file reference_counted.hpp