Logo ROOT   6.14/05
Reference Guide
TColorGradient.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 //Author: Timur Pocheptsov 20/03/2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TColorGradient
13 #define ROOT_TColorGradient
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TColorGradient //
19 // //
20 // TColorGradient extends basic TColor. //
21 // Actually, this is not a simple color, but linear or radial gradient //
22 // for a filled area. By inheriting from TColor, gradients can be //
23 // placed inside gROOT's list of colors and use it in all TAttXXX //
24 // descendants without modifying any existing code. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include <vector>
29 
30 #include "Rtypes.h"
31 
32 #include "TColor.h"
33 
34 
35 class TColorGradient : public TColor {
36 public:
37  typedef std::vector<Color_t>::size_type SizeType_t;
38 
39  //TODO: Replace with enum class as soon as we have C++11 enabled by default.
40  //CoordinateMode: both linear and radial gradients require some points - the
41  //start and end points.
42  //We can use either pad's rectangle as a coordinate system
43  //or an object's bounding rect.
45  kPadMode,//NDC, in a pad's rectangle (pad is 0,0 - 1,1).
46  kObjectBoundingMode //NDC in an object's bounding rect (this rect is 0,0 - 1, 1).
47  };
48 
49  struct Point {
52 
54  : fX(0.), fY(0.)
55  {
56  }
57 
59  : fX(x), fY(y)
60  {
61  }
62  };
63 
64 private:
65  //Positions of color nodes in a gradient, in NDC.
66  std::vector<Double_t> fColorPositions;
67  std::vector<Double_t> fColors;//RGBA values.
68 
69  //'default value' is kObjectBoundingMode.
71 
72 protected:
74 
75  TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
76  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
77  TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
79 
80 public:
81  void ResetColor(UInt_t nPoints, const Double_t *points,
82  const Color_t *colorIndices);
83  void ResetColor(UInt_t nPoints, const Double_t *points,
84  const Double_t *colorIndices);
85 
88 
89  SizeType_t GetNumberOfSteps()const;
90  const Double_t *GetColorPositions()const;
91  const Double_t *GetColors()const;
92 
93 private:
94  void RegisterColor(Color_t colorIndex);
95 
96  ClassDef(TColorGradient, 0); //Gradient fill.
97 };
98 
100 public:
101  //With C++11 we'll use inherited constructors!!!
102  TLinearGradient();
103  TLinearGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
104  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
105  TLinearGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
107 
108  //points are always in NDC (and also affected by fCoordinateMode).
109  void SetStartEnd(const Point &p1, const Point &p2);
110  const Point &GetStart()const;
111  const Point &GetEnd()const;
112 
113 private:
116 
117  ClassDef(TLinearGradient, 0); //Linear gradient fill.
118 };
119 
120 //
121 //Radial gradient. Can be either "simple": you specify a center
122 //and radius in NDC coordinates (see comments about linear gradient
123 //and coordinate modes above), or "extended": you have two centers
124 //(start,end) and two radiuses (R1, R2) and interpolation between them;
125 //still start/end and radiuses are in NDC.
126 //
127 
129 public:
132  kExtended
133  };
134 
135 
136  //With C++11 we'll use inherited constructors!!!
137  TRadialGradient();
138  TRadialGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
139  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
140  TRadialGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
142 
143 
144  EGradientType GetGradientType()const;
145 
146 
147  //Extended gradient.
148  void SetStartEndR1R2(const Point &p1, Double_t r1,
149  const Point &p2, Double_t r2);
150  const Point &GetStart()const;
151  Double_t GetR1()const;
152  const Point &GetEnd()const;
153  Double_t GetR2()const;
154 
155  //Simple radial gradient: the same as extended with
156  //start == end, r1 = 0, r2 = radius.
157  void SetRadialGradient(const Point &center, Double_t radius);
158  const Point &GetCenter()const;
159  Double_t GetRadius()const;
160 
161 private:
163  Double_t fR1 = 0.;
165  Double_t fR2 = 0.;
166 
167  EGradientType fType = kSimple;
168 
169  ClassDef(TRadialGradient, 0); //Radial gradient fill.
170 };
171 
172 
173 #endif
const Double_t * GetColorPositions() const
Get color positions.
ECoordinateMode GetCoordinateMode() const
Get coordinate mode.
SizeType_t GetNumberOfSteps() const
Get number of steps.
std::vector< Double_t > fColorPositions
Define a radial color gradient.
TColorGradient()
Constructor.
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:320
static double p2(double t, double a, double b, double c)
void SetCoordinateMode(ECoordinateMode mode)
Set coordinate mode.
std::vector< Double_t > fColors
short Color_t
Definition: RtypesCore.h:79
void RegisterColor(Color_t colorIndex)
Register color.
std::vector< Color_t >::size_type SizeType_t
point * points
Definition: X3DBuffer.c:20
unsigned int UInt_t
Definition: RtypesCore.h:42
static double p1(double t, double a, double b)
PyObject * fType
Define a linear color gradient.
Color * colors
Definition: X3DBuffer.c:19
double Double_t
Definition: RtypesCore.h:55
Point(Double_t x, Double_t y)
Double_t y[n]
Definition: legend1.C:17
The color creation and management class.
Definition: TColor.h:19
void ResetColor(UInt_t nPoints, const Double_t *points, const Color_t *colorIndices)
Reset color.
const Double_t * GetColors() const
Get colors.
TColorGradient extends basic TColor.
ECoordinateMode fCoordinateMode