PCL
Brush.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Brush.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Brush_h
53 #define __PCL_Brush_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/Color.h>
62 #include <pcl/Rectangle.h>
63 #include <pcl/UIObject.h>
64 
65 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
66 
67 namespace pcl
68 {
69 
70 // ----------------------------------------------------------------------------
71 
94 namespace BrushStyle
95 {
96  enum value_type
97  {
98  Empty, // empty brush (transparent brush)
99  Solid, // solid brush
100  Dense, // dense pattern brush
101  HalfTone, // 50% pattern brush
102  Sparse, // sparse pattern brush
103  HorzizontalHatch, // -----
104  VerticalHatch, // |||||
105  CrossHatch, // +++++
106  ForwardDiagonalHatch, // /////
107  BackwardDiagonalHatch, // \\\\\. <--- why this dot? :)
108  CrossDiagonalHatch, // XXXXX
109  Stipple, // fill with a tiled Bitmap
110  LinearGradient, // fill with a linear gradient
111  RadialGradient, // fill with a radial gradient
112  ConicalGradient, // fill with a conical gradient
113 
114  NumberOfBrushStyles
115  };
116 }
117 
128 namespace GradientSpreadMode
129 {
130  enum value_type
131  {
132  Pad,
133  Reflect,
134  Repeat,
135 
136  NumberOfGradientSpreadModes
137  };
138 }
139 
140 // ----------------------------------------------------------------------------
141 
142 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
143 
144 class PCL_CLASS Bitmap;
145 
146 // ----------------------------------------------------------------------------
147 
157 class PCL_CLASS Brush : public UIObject
158 {
159 public:
160 
165  using style = BrushStyle::value_type;
166 
170  Brush( RGBA color = 0xff000000, style = BrushStyle::Solid );
171 
175  Brush( const Bitmap& bmp );
176 
181  Brush( const Brush& b )
182  : UIObject( b )
183  {
184  }
185 
189  Brush( Brush&& x )
190  : UIObject( std::move( x ) )
191  {
192  }
193 
199  ~Brush() override
200  {
201  }
202 
210  Brush& operator =( const Brush& b )
211  {
212  Assign( b );
213  return *this;
214  }
215 
219  Brush& operator =( Brush&& x )
220  {
221  Transfer( x );
222  return *this;
223  }
224 
230  static Brush& Null();
231 
235  RGBA Color() const;
236 
240  void SetColor( RGBA );
241 
245  style Style() const;
246 
251  bool IsSolid() const
252  {
253  return Style() == BrushStyle::Solid;
254  }
255 
260  bool IsEmpty() const
261  {
262  return Style() == BrushStyle::Empty;
263  }
264 
269  bool IsTransparent() const
270  {
271  return IsEmpty();
272  }
273 
279  bool IsStippled() const
280  {
281  return Style() == BrushStyle::Stipple;
282  }
283 
293  void SetStyle( style );
294 
300  Bitmap Stipple() const;
301 
306  void SetStipple( const Bitmap& );
307 
311  virtual bool IsGradient() const
312  {
313  return false;
314  }
315 
316 private:
317 
318  Brush( void* h ) : UIObject( h )
319  {
320  }
321 
322  void* CloneHandle() const override;
323 
324  friend class GraphicsContextBase;
325  friend class Graphics;
326  friend class VectorGraphics;
327  friend class GradientBrush;
328  friend class Pen;
329 };
330 
331 // ----------------------------------------------------------------------------
332 
341 class PCL_CLASS GradientBrush : public Brush
342 {
343 public:
344 
349  using spread_mode = GradientSpreadMode::value_type;
350 
358  struct Stop
359  {
360  double position = 0;
361  RGBA color = 0xff000000;
362 
366  Stop() = default;
367 
372  Stop( double p, RGBA c )
373  : position( Range( p, 0.0, 1.0 ) )
374  , color( c )
375  {
376  }
377 
381  Stop( const Stop& ) = default;
382 
386  bool operator ==( const Stop& x ) const
387  {
388  return position == x.position && color == x.color;
389  }
390 
398  bool operator <( const Stop& x ) const
399  {
400  return position < x.position; // color is irrelevant to ordering of gradient stops
401  }
402  };
403 
408 
412  stop_list Stops() const;
413 
417  spread_mode SpreadMode() const;
418 
421  bool IsGradient() const override
422  {
423  return true;
424  }
425 
426 protected:
427 
428  GradientBrush( void* h ) : Brush( h )
429  {
430  }
431 
432  GradientBrush( const GradientBrush& x ) : Brush( x )
433  {
434  }
435 
436  GradientBrush( GradientBrush&& x ) : Brush( std::move( x ) )
437  {
438  }
439 };
440 
449 class PCL_CLASS LinearGradientBrush : public GradientBrush
450 {
451 public:
452 
457  using spread_mode = GradientBrush::spread_mode;
458 
463 
479  LinearGradientBrush( double x1, double y1, double x2, double y2,
480  const stop_list& stops = stop_list(),
481  spread_mode spread = GradientSpreadMode::Pad );
482 
491  const stop_list& stops = stop_list(),
492  spread_mode spread = GradientSpreadMode::Pad );
493 
502  const stop_list& stops = stop_list(),
503  spread_mode spread = GradientSpreadMode::Pad );
504 
510  : GradientBrush( b )
511  {
512  }
513 
518  : GradientBrush( std::move( x ) )
519  {
520  }
521 
529  LinearGradientBrush& operator =( const LinearGradientBrush& b )
530  {
531  SetHandle( b.handle );
532  return *this;
533  }
534 
539  {
540  Transfer( x );
541  return *this;
542  }
543 
552  void GetParameters( double& x1, double& y1, double& x2, double& y2 ) const;
553 
561  {
562  DRect r;
563  GetParameters( r.x0, r.y0, r.x1, r.y1 );
564  return r;
565  }
566 };
567 
576 class PCL_CLASS RadialGradientBrush : public GradientBrush
577 {
578 public:
579 
584  using spread_mode = GradientBrush::spread_mode;
585 
590 
610  RadialGradientBrush( double cx, double cy, double r, double fx = uint32_max, double fy = uint32_max,
611  const stop_list& stops = stop_list(),
612  spread_mode spread = GradientSpreadMode::Pad );
613 
621  RadialGradientBrush( const DPoint& c, double r, const DPoint& f = DPoint( uint32_max ),
622  const stop_list& stops = stop_list(),
623  spread_mode spread = GradientSpreadMode::Pad );
624 
632  RadialGradientBrush( const Point& c, double r, const Point& f = Point( uint32_max ),
633  const stop_list& stops = stop_list(),
634  spread_mode spread = GradientSpreadMode::Pad );
635 
641  : GradientBrush( b )
642  {
643  }
644 
649  : GradientBrush( std::move( x ) )
650  {
651  }
652 
660  RadialGradientBrush& operator =( const RadialGradientBrush& b )
661  {
662  SetHandle( b.handle );
663  return *this;
664  }
665 
670  {
671  Transfer( x );
672  return *this;
673  }
674 
684  void GetParameters( double& cx, double& cy, double& r, double& fx, double& fy ) const;
685 
695  void GetParameters( DPoint& c, double& r, DPoint& f ) const
696  {
697  GetParameters( c.x, c.y, r, f.x, f.y );
698  }
699 };
700 
709 class PCL_CLASS ConicalGradientBrush : public GradientBrush
710 {
711 public:
712 
717 
729  ConicalGradientBrush( double cx, double cy, double a, const stop_list& stops = stop_list() );
730 
738  ConicalGradientBrush( const DPoint& c, double a, const stop_list& stops = stop_list() );
739 
747  ConicalGradientBrush( const Point& c, double a, const stop_list& stops = stop_list() );
748 
754  : GradientBrush( b )
755  {
756  }
757 
762  : GradientBrush( std::move( x ) )
763  {
764  }
765 
774  {
775  SetHandle( b.handle );
776  return *this;
777  }
778 
783  {
784  Transfer( x );
785  return *this;
786  }
787 
796  void GetParameters( double& cx, double& cy, double& a ) const;
797 
807  void GetParameters( DPoint& c, double& a ) const
808  {
809  GetParameters( c.x, c.y, a );
810  }
811 };
812 
813 // ----------------------------------------------------------------------------
814 
815 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
816 
817 } // pcl
818 
819 #endif // __PCL_Brush_h
820 
821 // ----------------------------------------------------------------------------
822 // EOF pcl/Brush.h - Released 2024-06-18T15:48:54Z
Generic dynamic array.
Definition: Array.h:100
Client-side interface to a PixInsight Bitmap object.
Definition: Bitmap.h:204
Client-side interface to a PixInsight Brush object.
Definition: Brush.h:158
bool IsEmpty() const
Definition: Brush.h:260
void SetColor(RGBA)
void SetStyle(style)
bool IsStippled() const
Definition: Brush.h:279
virtual bool IsGradient() const
Definition: Brush.h:311
Brush(Brush &&x)
Definition: Brush.h:189
Brush(const Bitmap &bmp)
style Style() const
static Brush & Null()
Brush(RGBA color=0xff000000, style=BrushStyle::Solid)
RGBA Color() const
Bitmap Stipple() const
void SetStipple(const Bitmap &)
~Brush() override
Definition: Brush.h:199
bool IsTransparent() const
Definition: Brush.h:269
bool IsSolid() const
Definition: Brush.h:251
Brush(const Brush &b)
Definition: Brush.h:181
Conical gradient brush.
Definition: Brush.h:710
void GetParameters(DPoint &c, double &a) const
Definition: Brush.h:807
ConicalGradientBrush(const DPoint &c, double a, const stop_list &stops=stop_list())
void GetParameters(double &cx, double &cy, double &a) const
ConicalGradientBrush(const Point &c, double a, const stop_list &stops=stop_list())
ConicalGradientBrush(ConicalGradientBrush &&x)
Definition: Brush.h:761
ConicalGradientBrush(double cx, double cy, double a, const stop_list &stops=stop_list())
ConicalGradientBrush(const ConicalGradientBrush &b)
Definition: Brush.h:753
A generic point in the two-dimensional space.
Definition: Point.h:100
component x
Abscissa (horizontal, or X-axis coordinate).
Definition: Point.h:111
component y
Ordinate (vertical, or Y-axis coordinate).
Definition: Point.h:112
A generic rectangle in the two-dimensional space.
Definition: Rectangle.h:314
component x1
Horizontal coordinate of the lower right corner.
Definition: Rectangle.h:334
component y1
Vertical coordinate of the lower right corner.
Definition: Rectangle.h:335
component y0
Vertical coordinate of the upper left corner.
Definition: Rectangle.h:333
component x0
Horizontal coordinate of the upper left corner.
Definition: Rectangle.h:332
Base class of PCL gradient brushes.
Definition: Brush.h:342
stop_list Stops() const
GradientSpreadMode::value_type spread_mode
Definition: Brush.h:349
Array< Stop > stop_list
Definition: Brush.h:407
bool IsGradient() const override
Definition: Brush.h:421
spread_mode SpreadMode() const
Linear gradient brush.
Definition: Brush.h:450
LinearGradientBrush(const Rect &r, const stop_list &stops=stop_list(), spread_mode spread=GradientSpreadMode::Pad)
LinearGradientBrush(const LinearGradientBrush &b)
Definition: Brush.h:509
LinearGradientBrush(LinearGradientBrush &&x)
Definition: Brush.h:517
DRect Parameters() const
Definition: Brush.h:560
void GetParameters(double &x1, double &y1, double &x2, double &y2) const
LinearGradientBrush(const DRect &r, const stop_list &stops=stop_list(), spread_mode spread=GradientSpreadMode::Pad)
LinearGradientBrush(double x1, double y1, double x2, double y2, const stop_list &stops=stop_list(), spread_mode spread=GradientSpreadMode::Pad)
Radial gradient brush.
Definition: Brush.h:577
RadialGradientBrush(RadialGradientBrush &&x)
Definition: Brush.h:648
RadialGradientBrush(const RadialGradientBrush &b)
Definition: Brush.h:640
RadialGradientBrush(double cx, double cy, double r, double fx=uint32_max, double fy=uint32_max, const stop_list &stops=stop_list(), spread_mode spread=GradientSpreadMode::Pad)
void GetParameters(DPoint &c, double &r, DPoint &f) const
Definition: Brush.h:695
RadialGradientBrush(const DPoint &c, double r, const DPoint &f=DPoint(uint32_max), const stop_list &stops=stop_list(), spread_mode spread=GradientSpreadMode::Pad)
void GetParameters(double &cx, double &cy, double &r, double &fx, double &fy) const
RadialGradientBrush(const Point &c, double r, const Point &f=Point(uint32_max), const stop_list &stops=stop_list(), spread_mode spread=GradientSpreadMode::Pad)
Root base class for all user interface objects.
Definition: UIObject.h:95
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2267
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2278
#define uint32_max
Definition: Defs.h:875
uint32 RGBA
Definition: Color.h:92
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
Definition: Utility.h:190
PCL root namespace.
Definition: AbstractImage.h:77
Gradient stop.
Definition: Brush.h:359
Stop(const Stop &)=default
RGBA color
Stop color encoded as a 32-bit AARRGGBB value.
Definition: Brush.h:361
Stop(double p, RGBA c)
Definition: Brush.h:372
double position
Stop position in the [0,1] range, where 0 and 1 correspond, respectively, to the starting and end loc...
Definition: Brush.h:360