Skip to content

Commit f70b60a

Browse files
committed
[glpadpainter] use line and fill attributes for painting
Provide optional attribute args to TGLPadUtils to avoid any conflicts with external code
1 parent 3931434 commit f70b60a

3 files changed

Lines changed: 39 additions & 35 deletions

File tree

graf3d/gl/inc/TGLPadUtils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include "RtypesCore.h"
2121

2222
class TGLPadPainter;//For friend declarations.
23-
23+
class TAttFill;
24+
class TAttLine;
2425
/*
2526
2627
All code here and in corresponding *.cxx file is only
@@ -66,7 +67,7 @@ class FillAttribSet {
6667
UInt_t fStipple;
6768
Float_t fAlpha;
6869
public:
69-
FillAttribSet(const PolygonStippleSet & set, Bool_t ignoreStipple);
70+
FillAttribSet(const PolygonStippleSet & set, Bool_t ignoreStipple, const TAttFill *att = nullptr);
7071
~FillAttribSet();
7172
};
7273

@@ -87,7 +88,7 @@ class LineAttribSet {
8788
Bool_t fSetWidth;
8889
Float_t fAlpha;
8990
public:
90-
LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth);
91+
LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth, const TAttLine *att = nullptr);
9192
~LineAttribSet();
9293
};
9394

graf3d/gl/src/TGLPadPainter.cxx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,15 @@ void TGLPadPainter::DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
369369
return;
370370
}
371371

372-
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, gVirtualX->GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE);
372+
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, GetAttLine().GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE, &GetAttLine());
373373

374374
glBegin(GL_LINES);
375375
glVertex2d(x1, y1);
376376
glVertex2d(x2, y2);
377377
glEnd();
378378

379-
if (gVirtualX->GetLineWidth() > lineWidthTS) {
380-
Double_t pointSize = gVirtualX->GetLineWidth();
379+
if (GetAttLine().GetLineWidth() > lineWidthTS) {
380+
Double_t pointSize = GetAttLine().GetLineWidth();
381381
if (pointSize > fLimits.GetMaxPointSize())
382382
pointSize = fLimits.GetMaxPointSize();
383383
glPointSize((GLfloat)pointSize);
@@ -412,7 +412,7 @@ void TGLPadPainter::DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t
412412
return;
413413
}
414414

415-
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, gVirtualX->GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE);
415+
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, GetAttLine().GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE, &GetAttLine());
416416
const Double_t xRange = gPad->GetX2() - gPad->GetX1();
417417
const Double_t yRange = gPad->GetY2() - gPad->GetY1();
418418

@@ -429,22 +429,22 @@ void TGLPadPainter::DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
429429
{
430430
if (fLocked) return;
431431

432-
if (IsGradientFill(gVirtualX->GetFillColor())) {
432+
if (IsGradientFill(GetAttFill().GetFillColor())) {
433433
Double_t xs[] = {x1, x2, x2, x1};
434434
Double_t ys[] = {y1, y1, y2, y2};
435435
DrawPolygonWithGradient(4, xs, ys);
436436
return;
437437
}
438438

439439
if (mode == kHollow) {
440-
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, 0, fLimits.GetMaxLineWidth(), kTRUE);
440+
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, 0, fLimits.GetMaxLineWidth(), kTRUE, &GetAttLine());
441441
//
442442
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
443443
glRectd(x1, y1, x2, y2);
444444
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
445445
glLineWidth(1.f);
446446
} else {
447-
const Rgl::Pad::FillAttribSet fillAttribs(fSSet, kFALSE);//Set filling parameters.
447+
const Rgl::Pad::FillAttribSet fillAttribs(fSSet, kFALSE, &GetAttFill());//Set filling parameters.
448448
glRectd(x1, y1, x2, y2);
449449
}
450450
}
@@ -466,15 +466,15 @@ void TGLPadPainter::DrawFillArea(Int_t n, const Double_t *x, const Double_t *y)
466466
return;
467467
}
468468

469-
if (IsGradientFill(gVirtualX->GetFillColor()))
469+
if (IsGradientFill(GetAttFill().GetFillColor()))
470470
return DrawPolygonWithGradient(n, x, y);
471471

472-
if (!gVirtualX->GetFillStyle()) {
472+
if (!GetAttFill().GetFillStyle()) {
473473
fIsHollowArea = kTRUE;
474474
return DrawPolyLine(n, x, y);
475475
}
476476

477-
const Rgl::Pad::FillAttribSet fillAttribs(fSSet, kFALSE);
477+
const Rgl::Pad::FillAttribSet fillAttribs(fSSet, kFALSE, &GetAttFill());
478478
DrawTesselation(n, x, y);
479479
}
480480

@@ -486,7 +486,7 @@ void TGLPadPainter::DrawFillArea(Int_t n, const Float_t *x, const Float_t *y)
486486
{
487487
if (fLocked) return;
488488

489-
if (!gVirtualX->GetFillStyle()) {
489+
if (!GetAttFill().GetFillStyle()) {
490490
fIsHollowArea = kTRUE;
491491
return DrawPolyLine(n, x, y);
492492
}
@@ -498,7 +498,7 @@ void TGLPadPainter::DrawFillArea(Int_t n, const Float_t *x, const Float_t *y)
498498
fVs[i * 3 + 1] = y[i];
499499
}
500500

501-
const Rgl::Pad::FillAttribSet fillAttribs(fSSet, kFALSE);
501+
const Rgl::Pad::FillAttribSet fillAttribs(fSSet, kFALSE, &GetAttFill());
502502

503503
GLUtesselator *t = (GLUtesselator *)fTess.GetTess();
504504
gluBeginPolygon(t);
@@ -518,7 +518,7 @@ void TGLPadPainter::DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y)
518518
{
519519
if (fLocked) return;
520520

521-
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, gVirtualX->GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE);
521+
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, GetAttLine().GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE, &GetAttLine());
522522

523523
glBegin(GL_LINE_STRIP);
524524

@@ -531,8 +531,8 @@ void TGLPadPainter::DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y)
531531
}
532532
glEnd();
533533

534-
if (gVirtualX->GetLineWidth() > lineWidthTS) {
535-
Double_t pointSize = gVirtualX->GetLineWidth();
534+
if (GetAttLine().GetLineWidth() > lineWidthTS) {
535+
Double_t pointSize = GetAttLine().GetLineWidth();
536536
if (pointSize > fLimits.GetMaxPointSize())
537537
pointSize = fLimits.GetMaxPointSize();
538538
glPointSize((GLfloat)pointSize);
@@ -555,7 +555,7 @@ void TGLPadPainter::DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y)
555555
{
556556
if (fLocked) return;
557557

558-
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, gVirtualX->GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE);
558+
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, GetAttLine().GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE, &GetAttLine());
559559

560560
glBegin(GL_LINE_STRIP);
561561

@@ -577,7 +577,7 @@ void TGLPadPainter::DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *
577577
{
578578
if (fLocked) return;
579579

580-
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, gVirtualX->GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE);
580+
const Rgl::Pad::LineAttribSet lineAttribs(kTRUE, GetAttLine().GetLineStyle(), fLimits.GetMaxLineWidth(), kTRUE, &GetAttLine());
581581
const Double_t xRange = gPad->GetX2() - gPad->GetX1();
582582
const Double_t yRange = gPad->GetY2() - gPad->GetY1();
583583
const Double_t x1 = gPad->GetX1(), y1 = gPad->GetY1();
@@ -637,15 +637,15 @@ void TGLPadPainter::DrawPolyMarker()
637637
const TGLEnableGuard blendGuard(GL_BLEND);
638638

639639
Float_t rgba[4] = {};
640-
Rgl::Pad::ExtractRGBA(gVirtualX->GetMarkerColor(), rgba);
640+
Rgl::Pad::ExtractRGBA(GetAttMarker().GetMarkerColor(), rgba);
641641
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
642642
glColor4fv(rgba);
643643

644-
const Width_t w = TMath::Max(1, Int_t(TAttMarker::GetMarkerLineWidth(gVirtualX->GetMarkerStyle())));
644+
const Width_t w = TMath::Max(1, Int_t(TAttMarker::GetMarkerLineWidth(GetAttMarker().GetMarkerStyle())));
645645
glLineWidth(w > fLimits.GetMaxLineWidth() ? fLimits.GetMaxLineWidth() : !w ? 1.f : w);
646646

647647
const TPoint *xy = &fPoly[0];
648-
const Style_t markerStyle = TAttMarker::GetMarkerStyleBase(gVirtualX->GetMarkerStyle());
648+
const Style_t markerStyle = TAttMarker::GetMarkerStyleBase(GetAttMarker().GetMarkerStyle());
649649
const UInt_t n = UInt_t(fPoly.size());
650650
switch (markerStyle) {
651651
case kDot:
@@ -1069,10 +1069,8 @@ void TGLPadPainter::DrawPolygonWithGradient(Int_t n, const Double_t *x, const Do
10691069
assert(x != nullptr && "DrawPolygonWithGradient, parameter 'x' is null");
10701070
assert(y != nullptr && "DrawPolygonWithGradient, parameter 'y' is null");
10711071

1072-
assert(dynamic_cast<TColorGradient *>(gROOT->GetColor(gVirtualX->GetFillColor())) != nullptr &&
1073-
"DrawPolygonWithGradient, the current fill color is not a gradient fill");
1074-
const TColorGradient * const grad =
1075-
dynamic_cast<TColorGradient *>(gROOT->GetColor(gVirtualX->GetFillColor()));
1072+
auto grad = dynamic_cast<TColorGradient *>(gROOT->GetColor(GetAttFill().GetFillColor()));
1073+
assert(grad != nullptr && "DrawPolygonWithGradient, the current fill color is not a gradient fill");
10761074

10771075
if (fLocked)
10781076
return;

graf3d/gl/src/TGLPadUtils.cxx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,17 @@ Class to manipulate fill parameters.
118118
////////////////////////////////////////////////////////////////////////////////
119119
///Polygon stipple, if required.
120120

121-
FillAttribSet::FillAttribSet(const PolygonStippleSet &set, Bool_t ignoreStipple)
121+
FillAttribSet::FillAttribSet(const PolygonStippleSet &set, Bool_t ignoreStipple, const TAttFill *att)
122122
: fStipple(0), fAlpha(1.)
123123
{
124-
const UInt_t style = gVirtualX->GetFillStyle() / 1000;
124+
Style_t fillStyle = att ? att->GetFillStyle() : gVirtualX->GetFillStyle();
125+
Color_t fillColor = att ? att->GetFillColor() : gVirtualX->GetFillColor();
126+
127+
const UInt_t style = fillStyle / 1000;
125128

126129
if (!ignoreStipple) {
127130
if (style == 3) {
128-
const UInt_t fasi = gVirtualX->GetFillStyle() % 1000;
131+
const UInt_t fasi = fillStyle % 1000;
129132
fStipple = (fasi >= 1 && fasi <=25) ? fasi : 2;
130133
glPolygonStipple(&set.fStipples[fStipple * PolygonStippleSet::kStippleSize]);
131134
glEnable(GL_POLYGON_STIPPLE);
@@ -134,7 +137,7 @@ FillAttribSet::FillAttribSet(const PolygonStippleSet &set, Bool_t ignoreStipple)
134137

135138
// Color and transparency
136139
Float_t rgba[] = {0.f, 0.f, 0.f, 1.f};
137-
ExtractRGBA(gVirtualX->GetFillColor(), rgba);
140+
ExtractRGBA(fillColor, rgba);
138141
fAlpha = rgba[3];
139142
if (fAlpha<1.) {
140143
glEnable(GL_BLEND);
@@ -171,7 +174,7 @@ Set/unset line attributes.
171174
///Set up line parameters.
172175
///Smooth.
173176

174-
LineAttribSet::LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth)
177+
LineAttribSet::LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, Bool_t setWidth, const TAttLine *att)
175178
: fSmooth(smooth), fStipple(stipple), fSetWidth(setWidth), fAlpha(0.8)
176179
{
177180
if (fSmooth) {
@@ -181,6 +184,9 @@ LineAttribSet::LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, B
181184
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
182185
}
183186

187+
Color_t lineColor = att ? att->GetLineColor() : gVirtualX->GetLineColor();
188+
Width_t lineWidth = att ? att->GetLineWidth() : gVirtualX->GetLineWidth();
189+
184190
//Stipple.
185191
if (fStipple > 1) {
186192
if (fStipple >= gMaxStipple)
@@ -193,7 +199,7 @@ LineAttribSet::LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, B
193199

194200
//Color and transparency
195201
Float_t rgba[] = {0.f, 0.f, 0.f, 0.8f};
196-
ExtractRGBA(gVirtualX->GetLineColor(), rgba);
202+
ExtractRGBA(lineColor, rgba);
197203
fAlpha = rgba[3];
198204
if (fAlpha<0.8) {
199205
glEnable(GL_BLEND);
@@ -203,8 +209,7 @@ LineAttribSet::LineAttribSet(Bool_t smooth, UInt_t stipple, Double_t maxWidth, B
203209

204210
//Width.
205211
if (fSetWidth) {
206-
const Width_t w = gVirtualX->GetLineWidth();
207-
glLineWidth(w > maxWidth ? maxWidth : !w ? 1.f : w);
212+
glLineWidth(lineWidth > maxWidth ? maxWidth : !lineWidth ? 1.f : lineWidth);
208213
}
209214
}
210215

0 commit comments

Comments
 (0)