ROOT  6.06/09
Reference Guide
TGLPadPainter.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov 06/05/2009
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2009, 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_TGLPadPainter
13 #define ROOT_TGLPadPainter
14 
15 #include <deque>
16 
17 #ifndef ROOT_TVirtualPadPainter
18 #include "TVirtualPadPainter.h"
19 #endif
20 #ifndef ROOT_TGLFontmanager
21 #include "TGLFontManager.h"
22 #endif
23 #ifndef ROOT_TGLPadUtils
24 #include "TGLPadUtils.h"
25 #endif
26 #ifndef ROOT_TPoint
27 #include "TPoint.h"
28 #endif
29 
30 class TLinearGradient;
31 class TRadialGradient;
32 /*
33 The _main_ purpose of TGLPadPainter is to enable 2d gl raphics
34 inside standard TPad/TCanvas.
35 */
37 private:
42 
43  std::vector<Double_t> fVs;//Vertex buffer for tesselator.
44 
47 
48  Int_t fVp[4];
49 
50  std::vector<TPoint> fPoly;
52 
54 
55  template<class Char_t>
56  void DrawTextHelper(Double_t x, Double_t y, const Char_t *text, ETextMode mode);
57 public:
58  TGLPadPainter();
59 
60  //Final overriders for TVirtualPadPainter pure virtual functions.
61  //1. Part, which simply delegates to TVirtualX.
62  //Line attributes.
63  Color_t GetLineColor() const;
64  Style_t GetLineStyle() const;
65  Width_t GetLineWidth() const;
66 
67  void SetLineColor(Color_t lcolor);
68  void SetLineStyle(Style_t lstyle);
69  void SetLineWidth(Width_t lwidth);
70  //Fill attributes.
71  Color_t GetFillColor() const;
72  Style_t GetFillStyle() const;
73  Bool_t IsTransparent() const;
74 
75  void SetFillColor(Color_t fcolor);
76  void SetFillStyle(Style_t fstyle);
77  void SetOpacity(Int_t percent);
78  //Text attributes.
79  Short_t GetTextAlign() const;
80  Float_t GetTextAngle() const;
81  Color_t GetTextColor() const;
82  Font_t GetTextFont() const;
83  Float_t GetTextSize() const;
84  Float_t GetTextMagnitude() const;
85 
86  void SetTextAlign(Short_t align);
87  void SetTextAngle(Float_t tangle);
88  void SetTextColor(Color_t tcolor);
89  void SetTextFont(Font_t tfont);
90  void SetTextSize(Float_t tsize);
91  void SetTextSizePixels(Int_t npixels);
92 
93  //2. "Off-screen management" part.
95  void ClearDrawable();
96  void CopyDrawable(Int_t id, Int_t px, Int_t py);
97  void DestroyDrawable();
98  void SelectDrawable(Int_t device);
99 
100  void InitPainter();
101  void InvalidateCS();
102  void LockPainter();
103 
105  void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2);
106 
107  void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode);
108  //TPad needs double and float versions.
109  void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y);
110  void DrawFillArea(Int_t n, const Float_t *x, const Float_t *y);
111 
112  //TPad needs both double and float versions of DrawPolyLine.
113  void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y);
114  void DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y);
115  void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v);
116 
117  //TPad needs both versions.
118  void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y);
119  void DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y);
120 
121  void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode);
122  void DrawText(Double_t, Double_t, const wchar_t *, ETextMode);
123  void DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode);
124  void DrawTextNDC(Double_t, Double_t, const wchar_t *, ETextMode);
125 
126  //jpg, png, gif and bmp output.
127  void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const;
128 
129  //TASImage support.
130  void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height,
131  Int_t dstX, Int_t dstY, Bool_t enableBlending);
132 
133 
134 private:
135 
136  //Attention! GL_PROJECTION will become
137  //the current matrix after these calls.
138  void SaveProjectionMatrix()const;
139  void RestoreProjectionMatrix()const;
140 
141  //Attention! GL_MODELVIEW will become the
142  //current matrix after these calls.
143  void SaveModelviewMatrix()const;
144  void RestoreModelviewMatrix()const;
145 
146  void SaveViewport();
147  void RestoreViewport();
148 
149  void DrawPolyMarker();
150 
151  //Aux. functions for a gradient and solid fill:
152  void DrawPolygonWithGradient(Int_t n, const Double_t *x, const Double_t *y);
153  //
154  void DrawGradient(const TLinearGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
155  void DrawGradient(const TRadialGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
156  //
157  void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y);
158 
159  TGLPadPainter(const TGLPadPainter &rhs);
161 
163 };
164 
165 #endif
166 
Color_t GetFillColor() const
Delegate to gVirtualX.
void SelectDrawable(Int_t device)
For gVirtualX this means select pixmap (or window) and all subsequent drawings will go into this pixm...
const Double_t * v1
Definition: TArcBall.cxx:33
short Style_t
Definition: RtypesCore.h:76
void SetTextColor(Color_t tcolor)
Delegate to gVirtualX.
Rgl::Pad::PolygonStippleSet fSSet
Definition: TGLPadPainter.h:38
void LockPainter()
Locked state of painter means, that GL context can be invalid, so no GL calls can be executed...
float Float_t
Definition: RtypesCore.h:53
void DrawPolygonWithGradient(Int_t n, const Double_t *x, const Double_t *y)
At the moment I assume both linear and radial gradients will work the same way - using a stencil buff...
Int_t CreateDrawable(UInt_t w, UInt_t h)
Not required at the moment.
TH1 * h
Definition: legend2.C:5
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y)
Draw poly-line in user coordinates.
void SetTextSize(Float_t tsize)
Delegate to gVirtualX.
void ClearDrawable()
Not required at the moment.
Rgl::Pad::Tesselator fTess
Definition: TGLPadPainter.h:39
void SetLineColor(Color_t lcolor)
Delegate to gVirtualX.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2)
Draw line segment in NDC coordinates.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode)
Draw text.
Width_t GetLineWidth() const
Delegate to gVirtualX.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t IsTransparent() const
Delegate to gVirtualX.
Define a radial color gradient.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v)
Poly line in NDC.
void DrawGradient(const TLinearGradient *gradient, Int_t n, const Double_t *x, const Double_t *y)
short Font_t
Definition: RtypesCore.h:75
void SetTextSizePixels(Int_t npixels)
Delegate to gVirtualX.
void InvalidateCS()
When TPad::Range for gPad is called, projection must be changed in OpenGL.
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode)
Draw filled or hollow box.
Rgl::Pad::MarkerPainter fMarker
Definition: TGLPadPainter.h:40
std::vector< TPoint > fPoly
Definition: TGLPadPainter.h:50
Short_t GetTextAlign() const
Delegate to gVirtualX.
void RestoreViewport()
Restore the saved viewport.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
void DrawPolyMarker()
Poly-marker.
short Color_t
Definition: RtypesCore.h:79
Int_t fVp[4]
Definition: TGLPadPainter.h:48
void CopyDrawable(Int_t id, Int_t px, Int_t py)
Not required at the moment.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableBlending)
Bool_t fIsHollowArea
Definition: TGLPadPainter.h:51
void RestoreProjectionMatrix() const
Restore the projection matrix.
SVector< double, 2 > v
Definition: Dict.h:5
Float_t GetTextSize() const
Delegate to gVirtualX.
"Delegating" part of TGLPadPainter.
Definition: TGLPadPainter.h:36
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y)
Draw tesselated polygon (probably, outline only).
unsigned int UInt_t
Definition: RtypesCore.h:42
void SaveViewport()
Extract and save the current viewport.
Color_t GetTextColor() const
Delegate to gVirtualX.
short Short_t
Definition: RtypesCore.h:35
Rgl::Pad::GLLimits fLimits
Definition: TGLPadPainter.h:41
void SetFillStyle(Style_t fstyle)
Delegate to gVirtualX.
void SaveModelviewMatrix() const
Save the modelview matrix.
void RestoreModelviewMatrix() const
Restore the modelview matrix.
void SetTextAlign(Short_t align)
Delegate to gVirtualX.
short Width_t
Definition: RtypesCore.h:78
std::vector< Double_t > fVs
Definition: TGLPadPainter.h:43
void DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode)
Draw text in NDC.
Define a linear color gradient.
void SetFillColor(Color_t fcolor)
Delegate to gVirtualX.
void SetTextAngle(Float_t tangle)
Delegate to gVirtualX.
static const double x1[5]
double Double_t
Definition: RtypesCore.h:55
void SaveProjectionMatrix() const
Save the projection matrix.
TText * text
int type
Definition: TGX11.cxx:120
Double_t y[n]
Definition: legend1.C:17
void InitPainter()
Init gl-pad painter:
TGLPadPainter & operator=(const TGLPadPainter &rhs)
void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const
Using TImage save frame-buffer contents as a picture.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw line segment.
char Char_t
Definition: RtypesCore.h:29
Style_t GetLineStyle() const
Delegate to gVirtualX.
Font_t GetTextFont() const
Delegate to gVirtualX.
TGLFontManager fFM
Definition: TGLPadPainter.h:45
void DrawTextHelper(Double_t x, Double_t y, const Char_t *text, ETextMode mode)
A FreeType GL font manager.
Float_t GetTextAngle() const
Delegate to gVirtualX.
void SetTextFont(Font_t tfont)
Delegate to gVirtualX.
void SetLineStyle(Style_t lstyle)
Delegate to gVirtualX.
void SetLineWidth(Width_t lwidth)
Delegate to gVirtualX.
Style_t GetFillStyle() const
Delegate to gVirtualX.
A wrapper class for FTFont.
void DestroyDrawable()
Not required at the moment.
Color_t GetLineColor() const
Delegate to gVirtualX.
void SetOpacity(Int_t percent)
Delegate to gVirtualX.
Float_t GetTextMagnitude() const
Delegate to gVirtualX.
const Int_t n
Definition: legend1.C:16
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y)