Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BlendBrush.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_BLENDBRUSH_H_
21 #define OMNI_BLENDBRUSH_H_
22 
23 #include <QVector2D>
24 #include <omni/Buffer.h>
25 
26 class QPointF;
27 class QDataStream;
28 
29 namespace omni {
30  /**@brief BlendBrush for drawing on the blendmask
31  * @detail Holds an internal pixel buffer
32  **/
33  class BlendBrush {
34  public:
35  /// Default constructor
36  BlendBrush();
37 
38  /**@brief Constructor with a size and feather value (1.0 by default)
39  @detail Updates internal pixel buffer
40  **/
41  BlendBrush(QVector2D const& _size,
42  float _feather = 1.0);
43 
44  /// Returns brush size
45  QVector2D const& size() const;
46 
47  /**@brief Sets size of the brush.
48  * @detail Minimum size is 2 pixels, maximum size is 512 pixels
49  **/
50  void setSize(QVector2D const& _size);
51 
52  /**@brief Increase/Decrease size of the brush with a certain delta value
53  * @detail Minimum size is 2 pixels, maximum size is 512 pixels
54  **/
55  void changeSize(QVector2D const& _delta);
56 
57  /// Return feather value
58  float feather() const;
59 
60  /// Return opacity value
61  float opacity() const;
62 
63  /**@brief Set opacity value
64  * @detail Value must be between 0.0 and 1.0 and is clamped if necessary.
65  * A value 0.0 means a hard brush, a value of 1.0 means soft
66  *brush.
67  **/
68  void setOpacity(float _opacity);
69 
70  /**@brief Set feather value
71  * @detail Value must be between 0.0 and 1.0 and is clamped if necessary.
72  * A value 0.0 means a hard brush, a value of 1.0 means soft
73  *brush.
74  **/
75  void setFeather(float _feather);
76 
77  /// Returns true if the brush is inverted (aka eraser mode)
78  bool invert() const;
79 
80  /// Sets inverted flag of the brush
81  void setInvert(bool _invert);
82 
83  /// Set brush settings and generate pixel buffer
84  void setBrush(QVector2D const& _size,
85  float _feather,
86  float _opacity,
87  bool _invert);
88 
89  /// Draws internal pixel buffer in given blend buffer
90  void stamp(const QPointF& _pos,
91  Buffer<uint8_t>& _buf) const;
92 
93  /**@brief Draws a lot from point _p0 to _p1 on given pixel buffer
94  *@param _p0 Start point
95  *@param _p1 End point
96  *@param _buf Buffer to be drawn
97  *@param _leftOver Left over value to compensate positioning errors from
98  *previous moves
99  *@returns New left over value
100  **/
101  float drawLine(const QPointF& _p0,
102  const QPointF& _p1,
103  Buffer<uint8_t>& _buf,
104  float _leftOver = 0.0);
105 
106  Buffer<float>const& buffer() const;
107 
108  /// Write blend brush to stream
109  void toStream(QDataStream&) const;
110 
111  /// Read blend brush from stream
112  void fromStream(QDataStream&);
113 
114  /// Test for equality, buffer is ignored
115  friend bool operator==(BlendBrush const&,
116  BlendBrush const&);
117 
118  private:
119  /// Generate internal pixel buffer with given size and feather parameters
120  void generate();
121 
122  /// Keep brush size within certain limits
123  static QVector2D clampBrushSize(QVector2D const&);
124 
125  /// Internal pixel buffer
127 
128  float opacity_ = 1.0;
129  QVector2D size_;
130  float feather_ = 1.0;
131  bool invert_ = false;
132  };
133 }
134 
136 
137 #endif /* OMNI_BLENDBRUSH_H_ */
QVector2D const & size() const
Returns brush size.
Definition: BlendBrush.cpp:41
BlendBrush for drawing on the blendmask Holds an internal pixel buffer.
Definition: BlendBrush.h:33
void setFeather(float _feather)
Set feather value Value must be between 0.0 and 1.0 and is clamped if necessary. A value 0...
Definition: BlendBrush.cpp:79
friend bool operator==(BlendBrush const &, BlendBrush const &)
Test for equality, buffer is ignored.
Definition: BlendBrush.cpp:266
void generate()
Generate internal pixel buffer with given size and feather parameters.
Definition: BlendBrush.cpp:210
bool invert_
Definition: BlendBrush.h:131
static QVector2D clampBrushSize(QVector2D const &)
Keep brush size within certain limits.
Definition: BlendBrush.cpp:237
#define OMNI_DECL_STREAM_OPERATORS(CLASS)
Definition: Interface.h:53
void stamp(const QPointF &_pos, Buffer< uint8_t > &_buf) const
Draws internal pixel buffer in given blend buffer.
Definition: BlendBrush.cpp:124
void setSize(QVector2D const &_size)
Sets size of the brush. Minimum size is 2 pixels, maximum size is 512 pixels.
Definition: BlendBrush.cpp:46
QVector2D size_
Definition: BlendBrush.h:129
float feather() const
Return feather value.
Definition: BlendBrush.cpp:74
Buffer< float > const & buffer() const
Definition: BlendBrush.cpp:205
float feather_
Definition: BlendBrush.h:130
float drawLine(const QPointF &_p0, const QPointF &_p1, Buffer< uint8_t > &_buf, float _leftOver=0.0)
Draws a lot from point _p0 to _p1 on given pixel buffer.
Definition: BlendBrush.cpp:160
void setOpacity(float _opacity)
Set opacity value Value must be between 0.0 and 1.0 and is clamped if necessary. A value 0...
Definition: BlendBrush.cpp:61
void toStream(QDataStream &) const
Write blend brush to stream.
Definition: BlendBrush.cpp:245
float opacity() const
Return opacity value.
Definition: BlendBrush.cpp:57
BlendBrush()
Default constructor.
Definition: BlendBrush.cpp:29
bool invert() const
Returns true if the brush is inverted (aka eraser mode)
Definition: BlendBrush.cpp:89
void setBrush(QVector2D const &_size, float _feather, float _opacity, bool _invert)
Set brush settings and generate pixel buffer.
Definition: BlendBrush.cpp:100
float opacity_
Definition: BlendBrush.h:128
void setInvert(bool _invert)
Sets inverted flag of the brush.
Definition: BlendBrush.cpp:94
void changeSize(QVector2D const &_delta)
Increase/Decrease size of the brush with a certain delta value Minimum size is 2 pixels...
Definition: BlendBrush.cpp:52
Buffer< float > buffer_
Internal pixel buffer.
Definition: BlendBrush.h:126
void fromStream(QDataStream &)
Read blend brush from stream.
Definition: BlendBrush.cpp:256