Logo ROOT  
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
35class TColorGradient : public TColor {
36public:
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
64private:
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
72protected:
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
80public:
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
90 const Double_t *GetColorPositions()const;
91 const Double_t *GetColors()const;
92
93private:
94 void RegisterColor(Color_t colorIndex);
95
96 ClassDef(TColorGradient, 0); //Gradient fill.
97};
98
100public:
101 //With C++11 we'll use inherited constructors!!!
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
113private:
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
129public:
133 };
134
135
136 //With C++11 we'll use inherited constructors!!!
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
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
161private:
166
168
169 ClassDef(TRadialGradient, 0); //Radial gradient fill.
170};
171
172
173#endif
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
short Color_t
Definition: RtypesCore.h:79
#define ClassDef(name, id)
Definition: Rtypes.h:326
point * points
Definition: X3DBuffer.c:22
Color * colors
Definition: X3DBuffer.c:21
TColorGradient extends basic TColor.
void RegisterColor(Color_t colorIndex)
Register color.
const Double_t * GetColors() const
Get colors.
std::vector< Double_t > fColorPositions
std::vector< Color_t >::size_type SizeType_t
TColorGradient()
Constructor.
void SetCoordinateMode(ECoordinateMode mode)
Set coordinate mode.
void ResetColor(UInt_t nPoints, const Double_t *points, const Color_t *colorIndices)
Reset color.
SizeType_t GetNumberOfSteps() const
Get number of steps.
ECoordinateMode fCoordinateMode
ECoordinateMode GetCoordinateMode() const
Get coordinate mode.
const Double_t * GetColorPositions() const
Get color positions.
std::vector< Double_t > fColors
The color creation and management class.
Definition: TColor.h:19
Define a linear color gradient.
void SetStartEnd(const Point &p1, const Point &p2)
Set end and start.
const Point & GetEnd() const
Get end.
const Point & GetStart() const
Get start.
Define a radial color gradient.
Double_t GetR1() const
Double_t GetRadius() const
Get radius.
void SetStartEndR1R2(const Point &p1, Double_t r1, const Point &p2, Double_t r2)
Set start and end R1 and R2.
const Point & GetStart() const
Get start.
Double_t GetR2() const
Get R2.
const Point & GetCenter() const
Get center.
EGradientType fType
EGradientType GetGradientType() const
Get gradient type.
const Point & GetEnd() const
Get end.
void SetRadialGradient(const Point &center, Double_t radius)
Set radial gradient.
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Point(Double_t x, Double_t y)