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 "TPadPainterBase.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 TAttFill fGlFillAtt; // fill attributes used for GL
38
39 std::vector<Double_t> fVs;//Vertex buffer for tesselator.
40
43
45
46 std::vector<TPoint> fPoly;
48
50
51 void SelectGLFont(Font_t font, Float_t size);
52
53 template<class Char_t>
55
56 template<class Char_t>
57 void TextExtentHelper(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const Char_t *text);
58
59 template<class Char_t>
61
62public:
64
65 void SetOpacity(Int_t percent) override;
66 Float_t GetTextMagnitude() const override;
67
68
69 void OnPad(TVirtualPad *) override;
70
71 // Overwrite only attributes setters
72 void SetAttFill(const TAttFill &att) override;
73 void SetAttLine(const TAttLine &att) override;
74 void SetAttMarker(const TAttMarker &att) override;
75
76 //2. "Off-screen management" part.
77 Int_t CreateDrawable(UInt_t w, UInt_t h) override;
78 void ClearDrawable() override;
79 void ClearWindow(Int_t device) override;
80 Int_t ResizeDrawable(Int_t device, UInt_t w, UInt_t h) override;
81 void CopyDrawable(Int_t device, Int_t px, Int_t py) override;
82 void DestroyDrawable(Int_t device) override;
83 void SelectDrawable(Int_t device) override;
84 void UpdateDrawable(Int_t mode) override;
85 void SetDrawMode(Int_t device, Int_t mode) override;
86
87 void InitPainter() override;
88 void InvalidateCS() override;
89 void LockPainter() override;
90
91 void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override;
92 void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override;
93
94 void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode) override;
95 //TPad needs double and float versions.
96 void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override;
97 void DrawFillArea(Int_t n, const Float_t *x, const Float_t *y) override;
98
99 //TPad needs both double and float versions of DrawPolyLine.
100 void DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y) override;
101 void DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y) override;
102 void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override;
103
104 //TPad needs both versions.
105 void DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y) override;
106 void DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y) override;
107
108 void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override;
109 void DrawText(Double_t, Double_t, const wchar_t *, ETextMode) override;
110 void DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode) override;
111 void DrawTextNDC(Double_t, Double_t, const wchar_t *, ETextMode) override;
112
113 void GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess) override;
114 void GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const wchar_t *mess) override;
115 void GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess) override;
116 void GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const wchar_t *mess) override;
117 UInt_t GetTextAdvance(Font_t font, Double_t size, const char *text, Bool_t kern) override;
118
119 //jpg, png, gif and bmp output.
120 void SaveImage(TVirtualPad *pad, const char *fileName, Int_t type) const override;
121
122 //TASImage support.
123 void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height,
124 Int_t dstX, Int_t dstY, Bool_t enableBlending) override;
125
126 Bool_t IsNative() const override { return kTRUE; }
127
128 Bool_t IsCocoa() const override;
129
130 Bool_t IsSupportAlpha() const override { return kTRUE; }
131
132private:
133
134 //Attention! GL_PROJECTION will become
135 //the current matrix after these calls.
136 void SaveProjectionMatrix()const;
137 void RestoreProjectionMatrix()const;
138
139 //Attention! GL_MODELVIEW will become the
140 //current matrix after these calls.
141 void SaveModelviewMatrix()const;
142 void RestoreModelviewMatrix()const;
143
144 void SaveViewport();
145 void RestoreViewport();
146
147 void DrawPolyMarker();
148
149 //Aux. functions for a gradient and solid fill:
150 void DrawPolygonWithGradient(Int_t n, const Double_t *x, const Double_t *y);
151 //
152 void DrawGradient(const TLinearGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
153 void DrawGradient(const TRadialGradient *gradient, Int_t n, const Double_t *x, const Double_t *y);
154 //
155 void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y);
156
159
161};
162
163#endif
164
Handle_t WinContext_t
Window drawing context.
Definition GuiTypes.h:30
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
char Char_t
Character 1 byte (char).
Definition RtypesCore.h:51
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
short Font_t
Font number (short).
Definition RtypesCore.h:95
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
A FreeType GL font manager.
A wrapper class for FTFont.
void DrawText(Double_t x, Double_t y, const char *text, ETextMode mode) override
Draw text.
void TextExtentHelper(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const Char_t *text)
Helper function to get text extent.
void SetDrawMode(Int_t device, Int_t mode) override
Set drawing mode for specified device.
void TextAscentDescentHelper(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const Char_t *text)
Helper function to get text ascent / descent.
void DrawPixels(const unsigned char *pixelData, UInt_t width, UInt_t height, Int_t dstX, Int_t dstY, Bool_t enableBlending) override
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
void SelectGLFont(Font_t font, Float_t size)
Select specified font/size.
void DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2) override
Draw line segment in NDC coordinates.
WinContext_t fWinContext
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.
void SetAttLine(const TAttLine &att) override
Set line attributes.
TAttFill fGlFillAtt
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 GetTextAscentDescent(Font_t font, Double_t size, UInt_t &a, UInt_t &d, const char *mess) override
Get text extent.
void InvalidateCS() override
When TPad::Range for gPad is called, projection must be changed in OpenGL.
void ClearDrawable() override
Do nothing, sub-pads not cleared in GL.
void ClearWindow(Int_t device) override
Clear specified window - calling gVirtualX->ClearWindowW.
void DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v) override
Poly line in NDC.
void OnPad(TVirtualPad *) override
Select pad where current painting will be performed.
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.
Rgl::Pad::GLLimits fLimits
void SetOpacity(Int_t percent) override
Delegate to gVirtualX.
void DrawTextNDC(Double_t x, Double_t y, const char *text, ETextMode mode) override
Draw text in NDC.
void SetAttFill(const TAttFill &att) override
Set fill attributes.
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.
void DrawFillArea(Int_t n, const Double_t *x, const Double_t *y) override
Draw tesselated polygon (probably, outline only).
void UpdateDrawable(Int_t mode) override
Call low-level update of selected drawable, redirect to gVirtualX.
void RestoreProjectionMatrix() const
Restore the projection matrix.
void SetAttMarker(const TAttMarker &att) override
Set marker attributes.
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.
void DrawTesselation(Int_t n, const Double_t *x, const Double_t *y)
Int_t CreateDrawable(UInt_t w, UInt_t h) override
Not required at the moment.
UInt_t GetTextAdvance(Font_t font, Double_t size, const char *text, Bool_t kern) override
Get text advance.
void RestoreModelviewMatrix() const
Restore the modelview matrix.
std::vector< Double_t > fVs
Bool_t fIsHollowArea
void SaveProjectionMatrix() const
Save the projection matrix.
void DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Draw line segment.
void GetTextExtent(Font_t font, Double_t size, UInt_t &w, UInt_t &h, const char *mess) override
Get text extent.
Bool_t IsCocoa() const override
Returns true when cocoa backend is used.
void SaveModelviewMatrix() const
Save the modelview matrix.
void RestoreViewport()
Restore the saved viewport.
Extends TVirtualPadPainter interface to simplify work with graphical attributes.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
TText * text
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16