Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TVirtualPadPainter.h"
16#include "TGLFontManager.h"
17#include "TGLPadUtils.h"
18#include "TPoint.h"
19#include "GuiTypes.h"
20
21#include <vector>
22
23class TLinearGradient;
24class TRadialGradient;
25/*
26The _main_ purpose of TGLPadPainter is to enable 2d gl raphics
27inside standard TPad/TCanvas.
28*/
30private:
35
36 WinContext_t fWinContext; // context of selected drawable
37
38 std::vector<Double_t> fVs;//Vertex buffer for tesselator.
39
42
44
45 std::vector<TPoint> fPoly;
47
49
50 template<class Char_t>
52public:
54
55 //Final overriders for TVirtualPadPainter pure virtual functions.
56 //1. Part, which simply delegates to TVirtualX.
57 //Line attributes.
58 Color_t GetLineColor() const override;
59 Style_t GetLineStyle() const override;
60 Width_t GetLineWidth() const override;
61
62 void SetLineColor(Color_t lcolor) override;
63 void SetLineStyle(Style_t lstyle) override;
64 void SetLineWidth(Width_t lwidth) override;
65
66 //Fill attributes.
67 Color_t GetFillColor() const override;
68 Style_t GetFillStyle() const override;
69 Bool_t IsTransparent() const override;
70
71 void SetFillColor(Color_t fcolor) override;
72 void SetFillStyle(Style_t fstyle) override;
73 void SetOpacity(Int_t percent) override;
74
75 //Text attributes.
76 Short_t GetTextAlign() const override;
77 Float_t GetTextAngle() const override;
78 Color_t GetTextColor() const override;
79 Font_t GetTextFont() const override;
80 Float_t GetTextSize() const override;
81 Float_t GetTextMagnitude() const override;
82
83 void SetTextAlign(Short_t align) override;
84 void SetTextAngle(Float_t tangle) override;
85 void SetTextColor(Color_t tcolor) override;
86 void SetTextFont(Font_t tfont) override;
87 void SetTextSize(Float_t tsize) override;
88 void SetTextSizePixels(Int_t npixels) override;
89
90 //Marker attributes
91 Color_t GetMarkerColor() const override;
92 Style_t GetMarkerStyle() const override;
93 Size_t GetMarkerSize() const override;
94
95 void SetMarkerColor(Color_t mcolor) override;
96 void SetMarkerStyle(Style_t mstyle) override;
97 void SetMarkerSize(Size_t msize) override;
98
99 //2. "Off-screen management" part.
100 Int_t CreateDrawable(UInt_t w, UInt_t h) override;
101 void ClearDrawable() override;
103 void CopyDrawable(Int_t device, Int_t px, Int_t py) override;
104 void DestroyDrawable(Int_t device) override;
105 void SelectDrawable(Int_t device) override;
106 void UpdateDrawable(Int_t mode) override;
107 void SetDrawMode(Int_t device, Int_t mode) override;
108
109 void InitPainter() override;
110 void InvalidateCS() override;
111 void LockPainter() override;
112
113 void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override;
115
117 //TPad needs double and float versions.
118 void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override;
119 void DrawFillArea(Int_t n, const Float_t *x, const Float_t *y) override;
120
121 //TPad needs both double and float versions of DrawPolyLine.
122 void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override;
123 void DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y) override;
124 void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override;
125
126 //TPad needs both versions.
127 void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override;
128 void DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y) override;
129
130 void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override;
131 void DrawText(Double_t, Double_t, const wchar_t *, ETextMode) override;
132 void DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode) override;
133 void DrawTextNDC(Double_t, Double_t, const wchar_t *, ETextMode) override;
134
135 //jpg, png, gif and bmp output.
136 void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override;
137
138 //TASImage support.
139 void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height,
141
142 Bool_t IsNative() const override { return kTRUE; }
143
144 Bool_t IsCocoa() const override;
145
146 Bool_t IsSupportAlpha() const override { return kTRUE; }
147
148private:
149
150 //Attention! GL_PROJECTION will become
151 //the current matrix after these calls.
152 void SaveProjectionMatrix()const;
153 void RestoreProjectionMatrix()const;
154
155 //Attention! GL_MODELVIEW will become the
156 //current matrix after these calls.
157 void SaveModelviewMatrix()const;
158 void RestoreModelviewMatrix()const;
159
160 void SaveViewport();
161 void RestoreViewport();
162
163 void DrawPolyMarker();
164
165 //Aux. functions for a gradient and solid fill:
166 void DrawPolygonWithGradient(Int_t n, const Double_t *x, const Double_t *y);
167 //
168 void DrawGradient(const TLinearGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
169 void DrawGradient(const TRadialGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
170 //
171 void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y);
172
175
177};
178
179#endif
180
Handle_t WinContext_t
Window drawing context.
Definition GuiTypes.h:30
#define h(i)
Definition RSha256.hxx:106
short Style_t
Style number (short)
Definition RtypesCore.h:96
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
float Size_t
Attribute size (float)
Definition RtypesCore.h:103
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
short Width_t
Line width (short)
Definition RtypesCore.h:98
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
short Font_t
Font number (short)
Definition RtypesCore.h:95
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
Option_t Option_t SetLineWidth
Option_t Option_t SetFillStyle
Option_t Option_t SetTextSize
Option_t Option_t DrawFillArea
Option_t Option_t SetLineColor
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t SetTextFont
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t SetFillColor
Option_t Option_t TPoint TPoint const char DrawLine
Option_t Option_t SetMarkerStyle
Option_t Option_t width
Option_t Option_t TPoint TPoint percent
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint DrawText
Option_t Option_t TPoint TPoint SetOpacity
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
A FreeType GL font manager.
A wrapper class for FTFont.
"Delegating" part of TGLPadPainter.
void SetDrawMode(Int_t device, Int_t mode) override
Set drawing mode for specified device.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableBlending) override
Float_t GetTextSize() const override
Delegate to gVirtualX.
Int_t ResizeDrawable(Int_t device, UInt_t w, UInt_t h) override
Resize a gVirtualX Pixmap.
void DestroyDrawable(Int_t device) override
Not required at the moment.
Bool_t IsNative() const override
void DrawGradient(const TLinearGradient *gradient, Int_t n, const Double_t *x, const Double_t *y)
Rgl::Pad::Tesselator fTess
Float_t GetTextAngle() const override
Delegate to gVirtualX.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Draw line segment in NDC coordinates.
Style_t GetLineStyle() const override
Delegate to gVirtualX.
WinContext_t fWinContext
Color_t GetTextColor() const override
Delegate to gVirtualX.
std::vector< TPoint > fPoly
void DrawTextHelper(Double_t x, Double_t y, const Char_t *text, ETextMode mode)
TGLPadPainter(const TGLPadPainter &rhs)
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override
Draw filled or hollow box.
Color_t GetMarkerColor() const override
Delegate to gVirtualX.
void SetTextSizePixels(Int_t npixels) override
Delegate to gVirtualX.
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...
void InvalidateCS() override
When TPad::Range for gPad is called, projection must be changed in OpenGL.
void ClearDrawable() override
Call gVirtualX->ClearWindow()
Color_t GetLineColor() const override
Delegate to gVirtualX.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Poly line in NDC.
TGLPadPainter & operator=(const TGLPadPainter &rhs)
void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override
Draw poly-line in user coordinates.
void SetTextAlign(Short_t align) override
Delegate to gVirtualX.
Rgl::Pad::GLLimits fLimits
void SetTextAngle(Float_t tangle) override
Delegate to gVirtualX.
void DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode) override
Draw text in NDC.
void SetTextColor(Color_t tcolor) override
Delegate to gVirtualX.
void SetMarkerSize(Size_t msize) override
Delegate to gVirtualX.
void InitPainter() override
Init gl-pad painter:
void SelectDrawable(Int_t device) override
For gVirtualX this means select pixmap (or window) and all subsequent drawings will go into this pixm...
TGLFontManager fFM
Rgl::Pad::PolygonStippleSet fSSet
Rgl::Pad::MarkerPainter fMarker
void DrawPolyMarker()
Poly-marker.
void SaveViewport()
Extract and save the current viewport.
void CopyDrawable(Int_t device, Int_t px, Int_t py) override
Not required at the moment.
void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override
Using TImage save frame-buffer contents as a picture.
Style_t GetMarkerStyle() const override
Delegate to gVirtualX.
Short_t GetTextAlign() const override
Delegate to gVirtualX.
Style_t GetFillStyle() const override
Delegate to gVirtualX.
void UpdateDrawable(Int_t mode) override
Call low-level update of selected drawable, redirect to gVirtualX.
Font_t GetTextFont() const override
Delegate to gVirtualX.
void RestoreProjectionMatrix() const
Restore the projection matrix.
void SetLineStyle(Style_t lstyle) override
Delegate to gVirtualX.
Bool_t IsSupportAlpha() const override
void LockPainter() override
Locked state of painter means, that GL context can be invalid, so no GL calls can be executed.
Float_t GetTextMagnitude() const override
Delegate to gVirtualX.
Width_t GetLineWidth() const override
Delegate to gVirtualX.
void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y)
Color_t GetFillColor() const override
Delegate to gVirtualX.
Int_t CreateDrawable(UInt_t w, UInt_t h) override
Not required at the moment.
Bool_t IsTransparent() const override
Delegate to gVirtualX.
Size_t GetMarkerSize() const override
Delegate to gVirtualX.
void RestoreModelviewMatrix() const
Restore the modelview matrix.
std::vector< Double_t > fVs
Bool_t fIsHollowArea
void SaveProjectionMatrix() const
Save the projection matrix.
Bool_t IsCocoa() const override
Returns true when cocoa backend is used.
void SetMarkerColor(Color_t mcolor) override
Delegate to gVirtualX.
void SaveModelviewMatrix() const
Save the modelview matrix.
void RestoreViewport()
Restore the saved viewport.
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16