Skip to content

Commit 3931434

Browse files
committed
[glpadpainter] derive TGLPadPainter from Base class
So attributes for painting will be held in the painter Final idea is to avoid gVirtualX attributes when making GL painting
1 parent f17c502 commit 3931434

2 files changed

Lines changed: 51 additions & 246 deletions

File tree

graf3d/gl/inc/TGLPadPainter.h

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifndef ROOT_TGLPadPainter
1313
#define ROOT_TGLPadPainter
1414

15-
#include "TVirtualPadPainter.h"
15+
#include "TPadPainterBase.h"
1616
#include "TGLFontManager.h"
1717
#include "TGLPadUtils.h"
1818
#include "TPoint.h"
@@ -26,7 +26,7 @@ class TRadialGradient;
2626
The _main_ purpose of TGLPadPainter is to enable 2d gl raphics
2727
inside standard TPad/TCanvas.
2828
*/
29-
class TGLPadPainter : public TVirtualPadPainter {
29+
class TGLPadPainter : public TPadPainterBase {
3030
private:
3131
Rgl::Pad::PolygonStippleSet fSSet;
3232
Rgl::Pad::Tesselator fTess;
@@ -52,49 +52,17 @@ class TGLPadPainter : public TVirtualPadPainter {
5252
public:
5353
TGLPadPainter();
5454

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;
7355
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;
8156
Float_t GetTextMagnitude() const override;
8257

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;
58+
59+
void OnPad(TVirtualPad *) override;
60+
61+
// Overwrite only attributes setters
62+
void SetAttFill(const TAttFill &att) override;
63+
void SetAttLine(const TAttLine &att) override;
64+
void SetAttMarker(const TAttMarker &att) override;
65+
void SetAttText(const TAttText &att) override;
9866

9967
//2. "Off-screen management" part.
10068
Int_t CreateDrawable(UInt_t w, UInt_t h) override;

graf3d/gl/src/TGLPadPainter.cxx

Lines changed: 41 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -66,95 +66,6 @@ TGLPadPainter::TGLPadPainter()
6666
}
6767

6868

69-
////////////////////////////////////////////////////////////////////////////////
70-
///Delegate to gVirtualX.
71-
72-
Color_t TGLPadPainter::GetLineColor() const
73-
{
74-
return gVirtualX->GetLineColor();
75-
}
76-
77-
////////////////////////////////////////////////////////////////////////////////
78-
///Delegate to gVirtualX.
79-
80-
Style_t TGLPadPainter::GetLineStyle() const
81-
{
82-
return gVirtualX->GetLineStyle();
83-
}
84-
85-
////////////////////////////////////////////////////////////////////////////////
86-
///Delegate to gVirtualX.
87-
88-
Width_t TGLPadPainter::GetLineWidth() const
89-
{
90-
return gVirtualX->GetLineWidth();
91-
}
92-
93-
////////////////////////////////////////////////////////////////////////////////
94-
///Delegate to gVirtualX.
95-
96-
void TGLPadPainter::SetLineColor(Color_t lcolor)
97-
{
98-
gVirtualX->SetLineColor(lcolor);
99-
}
100-
101-
////////////////////////////////////////////////////////////////////////////////
102-
///Delegate to gVirtualX.
103-
104-
void TGLPadPainter::SetLineStyle(Style_t lstyle)
105-
{
106-
gVirtualX->SetLineStyle(lstyle);
107-
}
108-
109-
////////////////////////////////////////////////////////////////////////////////
110-
///Delegate to gVirtualX.
111-
112-
void TGLPadPainter::SetLineWidth(Width_t lwidth)
113-
{
114-
gVirtualX->SetLineWidth(lwidth);
115-
}
116-
117-
////////////////////////////////////////////////////////////////////////////////
118-
///Delegate to gVirtualX.
119-
120-
Color_t TGLPadPainter::GetFillColor() const
121-
{
122-
return gVirtualX->GetFillColor();
123-
}
124-
125-
////////////////////////////////////////////////////////////////////////////////
126-
///Delegate to gVirtualX.
127-
128-
Style_t TGLPadPainter::GetFillStyle() const
129-
{
130-
return gVirtualX->GetFillStyle();
131-
}
132-
133-
////////////////////////////////////////////////////////////////////////////////
134-
///Delegate to gVirtualX.
135-
///IsTransparent is implemented as inline function in TAttFill.
136-
137-
Bool_t TGLPadPainter::IsTransparent() const
138-
{
139-
return gVirtualX->IsTransparent();
140-
}
141-
142-
////////////////////////////////////////////////////////////////////////////////
143-
///Delegate to gVirtualX.
144-
145-
void TGLPadPainter::SetFillColor(Color_t fcolor)
146-
{
147-
gVirtualX->SetFillColor(fcolor);
148-
}
149-
150-
////////////////////////////////////////////////////////////////////////////////
151-
///Delegate to gVirtualX.
152-
153-
void TGLPadPainter::SetFillStyle(Style_t fstyle)
154-
{
155-
gVirtualX->SetFillStyle(fstyle);
156-
}
157-
15869
////////////////////////////////////////////////////////////////////////////////
15970
///Delegate to gVirtualX.
16071

@@ -166,151 +77,73 @@ void TGLPadPainter::SetOpacity(Int_t percent)
16677
////////////////////////////////////////////////////////////////////////////////
16778
///Delegate to gVirtualX.
16879

169-
Short_t TGLPadPainter::GetTextAlign() const
170-
{
171-
return gVirtualX->GetTextAlign();
172-
}
173-
174-
////////////////////////////////////////////////////////////////////////////////
175-
///Delegate to gVirtualX.
176-
177-
Float_t TGLPadPainter::GetTextAngle() const
178-
{
179-
return gVirtualX->GetTextAngle();
180-
}
181-
182-
////////////////////////////////////////////////////////////////////////////////
183-
///Delegate to gVirtualX.
184-
185-
Color_t TGLPadPainter::GetTextColor() const
186-
{
187-
return gVirtualX->GetTextColor();
188-
}
189-
190-
////////////////////////////////////////////////////////////////////////////////
191-
///Delegate to gVirtualX.
192-
193-
Font_t TGLPadPainter::GetTextFont() const
194-
{
195-
return gVirtualX->GetTextFont();
196-
}
197-
198-
////////////////////////////////////////////////////////////////////////////////
199-
///Delegate to gVirtualX.
200-
201-
Float_t TGLPadPainter::GetTextSize() const
202-
{
203-
return gVirtualX->GetTextSize();
204-
}
205-
206-
////////////////////////////////////////////////////////////////////////////////
207-
///Delegate to gVirtualX.
208-
20980
Float_t TGLPadPainter::GetTextMagnitude() const
21081
{
21182
return gVirtualX->GetTextMagnitude();
21283
}
21384

21485
////////////////////////////////////////////////////////////////////////////////
215-
///Delegate to gVirtualX.
216-
217-
void TGLPadPainter::SetTextAlign(Short_t align)
218-
{
219-
gVirtualX->SetTextAlign(align);
220-
}
221-
222-
////////////////////////////////////////////////////////////////////////////////
223-
///Delegate to gVirtualX.
224-
225-
void TGLPadPainter::SetTextAngle(Float_t tangle)
226-
{
227-
gVirtualX->SetTextAngle(tangle);
228-
}
229-
230-
////////////////////////////////////////////////////////////////////////////////
231-
///Delegate to gVirtualX.
86+
/// Select pad where current painting will be performed
23287

233-
void TGLPadPainter::SetTextColor(Color_t tcolor)
88+
void TGLPadPainter::OnPad(TVirtualPad *pad)
23489
{
235-
gVirtualX->SetTextColor(tcolor);
90+
// GL painter does not use proper id for sub-pads (see CreateDrawable)
91+
// so one always use canvas ID to execute TVirtualX-specific commands
92+
if (!fWinContext)
93+
fWinContext = gVirtualX->GetWindowContext(pad->GetCanvasID());
23694
}
23795

238-
////////////////////////////////////////////////////////////////////////////////
239-
///Delegate to gVirtualX.
240-
241-
void TGLPadPainter::SetTextFont(Font_t tfont)
242-
{
243-
gVirtualX->SetTextFont(tfont);
244-
}
24596

24697
////////////////////////////////////////////////////////////////////////////////
247-
///Delegate to gVirtualX.
98+
/// Set fill attributes
24899

249-
void TGLPadPainter::SetTextSize(Float_t tsize)
100+
void TGLPadPainter::SetAttFill(const TAttFill &att)
250101
{
251-
gVirtualX->SetTextSize(tsize);
252-
}
102+
if (&fAttFill != &att)
103+
att.Copy(fAttFill);
253104

254-
////////////////////////////////////////////////////////////////////////////////
255-
///Delegate to gVirtualX.
256-
257-
void TGLPadPainter::SetTextSizePixels(Int_t npixels)
258-
{
259-
gVirtualX->SetTextSizePixels(npixels);
105+
// TODO: dismiss in the future, gVirtualX attributes not needed in GL
106+
if (fWinContext && gVirtualX)
107+
gVirtualX->SetAttFill(fWinContext, att);
260108
}
261109

262-
263110
////////////////////////////////////////////////////////////////////////////////
264-
/// Delegate to gVirtualX.
111+
/// Set line attributes
265112

266-
Color_t TGLPadPainter::GetMarkerColor() const
113+
void TGLPadPainter::SetAttLine(const TAttLine &att)
267114
{
268-
return gVirtualX->GetMarkerColor();
269-
}
270-
271-
272-
////////////////////////////////////////////////////////////////////////////////
273-
/// Delegate to gVirtualX.
115+
if (&fAttLine != &att)
116+
att.Copy(fAttLine);
274117

275-
Style_t TGLPadPainter::GetMarkerStyle() const
276-
{
277-
return gVirtualX->GetMarkerStyle();
118+
// TODO: dismiss in the future, gVirtualX attributes not needed in GL
119+
if (fWinContext && gVirtualX)
120+
gVirtualX->SetAttLine(fWinContext, att);
278121
}
279122

280-
281123
////////////////////////////////////////////////////////////////////////////////
282-
/// Delegate to gVirtualX.
124+
/// Set marker attributes
283125

284-
Size_t TGLPadPainter::GetMarkerSize() const
126+
void TGLPadPainter::SetAttMarker(const TAttMarker &att)
285127
{
286-
return gVirtualX->GetMarkerSize();
287-
}
128+
if (&fAttMarker != &att)
129+
att.Copy(fAttMarker);
288130

289-
290-
////////////////////////////////////////////////////////////////////////////////
291-
/// Delegate to gVirtualX.
292-
293-
void TGLPadPainter::SetMarkerColor(Color_t mcolor)
294-
{
295-
gVirtualX->SetMarkerColor(mcolor);
131+
// TODO: dismiss in the future, gVirtualX attributes not needed in GL
132+
if (fWinContext && gVirtualX)
133+
gVirtualX->SetAttMarker(fWinContext, att);
296134
}
297135

298-
299136
////////////////////////////////////////////////////////////////////////////////
300-
/// Delegate to gVirtualX.
137+
/// Set text attributes
301138

302-
void TGLPadPainter::SetMarkerStyle(Style_t mstyle)
139+
void TGLPadPainter::SetAttText(const TAttText &att)
303140
{
304-
gVirtualX->SetMarkerStyle(mstyle);
305-
}
141+
if (&fAttText != &att)
142+
att.Copy(fAttText);
306143

307-
308-
////////////////////////////////////////////////////////////////////////////////
309-
/// Delegate to gVirtualX.
310-
311-
void TGLPadPainter::SetMarkerSize(Size_t msize)
312-
{
313-
gVirtualX->SetMarkerSize(msize);
144+
// TODO: dismiss in the future, gVirtualX attributes not needed in GL
145+
if (fWinContext && gVirtualX)
146+
gVirtualX->SetAttText(fWinContext, att);
314147
}
315148

316149
/*
@@ -376,14 +209,16 @@ void TGLPadPainter::DestroyDrawable(Int_t /* device */)
376209

377210
void TGLPadPainter::SelectDrawable(Int_t /* device */)
378211
{
212+
auto pad = dynamic_cast<TPad *>(gPad);
213+
if (!fWinContext && pad)
214+
fWinContext = gVirtualX->GetWindowContext(pad->GetCanvasID());
215+
379216
if (fLocked)
380217
return;
381218

382-
if (TPad *pad = dynamic_cast<TPad *>(gPad)) {
219+
if (pad) {
383220
// GL painter does not use proper id for sub-pads (see CreateDrawable)
384221
// so one always use canvas ID to execute TVirtualX-specific commands
385-
fWinContext = gVirtualX->GetWindowContext(pad->GetCanvasID());
386-
387222
Int_t px = 0, py = 0;
388223

389224
pad->XYtoAbsPixel(pad->GetX1(), pad->GetY1(), px, py);
@@ -524,6 +359,7 @@ void TGLPadPainter::DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
524359
//from TView3D::ExecuteRotateView. This means in fact,
525360
//that TView3D wants to draw itself in a XOR mode, via
526361
//gVirtualX.
362+
// TODO: only here set line attributes to virtual x
527363
if (fWinContext && (gVirtualX->GetDrawModeW(fWinContext) == TVirtualX::kInvert)) {
528364
gVirtualX->DrawLineW(fWinContext,
529365
gPad->XtoAbsPixel(x1), gPad->YtoAbsPixel(y1),
@@ -570,6 +406,7 @@ void TGLPadPainter::DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t
570406
const Int_t py1 = gPad->VtoPixel(v1);
571407
const Int_t px2 = gPad->UtoPixel(u2);
572408
const Int_t py2 = gPad->VtoPixel(v2);
409+
// TODO: only here set line attributes to virtual x
573410
gVirtualX->DrawLineW(fWinContext, px1, py1, px2, py2);
574411
}
575412
return;

0 commit comments

Comments
 (0)