Skip to content

Commit 1443fd3

Browse files
committed
[glpadpainter] use text and marker attributes
Avoid extensive gVirtualX usage in these places But keep full backward compatibility In the future one can remove gVirtualX completely
1 parent f70b60a commit 1443fd3

5 files changed

Lines changed: 119 additions & 107 deletions

File tree

graf3d/gl/inc/TGLFontManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TGLFont
4848
Int_t fSize; // free-type face size
4949
Int_t fFile; // free-type file name
5050
EMode fMode; // free-type FTGL class id
51+
UInt_t fTextAlign = 0; // set text align
5152

5253
mutable Int_t fTrashCount;
5354
public:
@@ -74,6 +75,8 @@ class TGLFont
7475
Float_t GetDepth() const { return fDepth; }
7576
void SetDepth(Float_t d) { fDepth = d; }
7677

78+
void SetTextAlign(UInt_t align) { fTextAlign = align; }
79+
7780
// FTGL wrapper functions
7881
Float_t GetAscent() const;
7982
Float_t GetDescent() const;

graf3d/gl/inc/TGLPadUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,20 @@ class MarkerPainter {
110110

111111
mutable std::vector<TPoint> fCircle;
112112

113+
Size_t fMarkerSize;
114+
Width_t fMarkerWidth;
115+
Bool_t fSetMarker = kFALSE;
116+
113117
enum {
114118
kSmallCirclePts = 80,
115119
kLargeCirclePts = 150
116120
};
117121

118122
public:
123+
void SetMarkerSizeWidth(Size_t size, Width_t width);
124+
Size_t GetMarkerSize() const;
125+
Width_t GetMarkerWidth() const;
126+
119127
//Each function draw n markers.
120128
void DrawDot(UInt_t n, const TPoint *xy)const;
121129
void DrawPlus(UInt_t n, const TPoint *xy)const;

graf3d/gl/src/TGLFontManager.cxx

Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -194,69 +194,37 @@ void TGLFont::RenderHelper(const Char *txt, Double_t x, Double_t y, Double_t ang
194194
*/
195195
const Double_t dx = urx - llx, dy = ury - lly;
196196
Double_t xc = 0., yc = 0.;
197-
const UInt_t align = gVirtualX->GetTextAlign();
198197

199-
//Here's the nice X11 bullshido: you call gVirtualX->SetTextAlign(11),
198+
// if align was not set before - use value from gVirtualX
199+
const UInt_t align = fTextAlign ? fTextAlign : gVirtualX->GetTextAlign();
200+
201+
//Timur: Here's the nice X11 bullshido: you call gVirtualX->SetTextAlign(11),
200202
//later gVirtualX->GetTextAling() will give you 7. Brilliant!
201203
//But with Cocoa you'll have 11. As it should be, of course.
204+
//Sergey: problem with gVirtualX solved, now all platforms works same way
205+
206+
const UInt_t hAlign = UInt_t(align / 10);
207+
const UInt_t vAlign = UInt_t(align % 10);
208+
switch (hAlign) {
209+
case 1:
210+
xc = 0.5 * dx;
211+
break;
212+
case 2:
213+
break;
214+
case 3:
215+
xc = -0.5 * dy;
216+
break;
217+
}
202218

203-
if (gVirtualX->InheritsFrom("TGCocoa") || true) {
204-
const UInt_t hAlign = UInt_t(align / 10);
205-
switch (hAlign) {
206-
case 1:
207-
xc = 0.5 * dx;
208-
break;
209-
case 2:
210-
break;
211-
case 3:
212-
xc = -0.5 * dy;
213-
break;
214-
}
215-
216-
const UInt_t vAlign = UInt_t(align % 10);
217-
switch (vAlign) {
218-
case 1:
219-
yc = 0.5 * dy;
220-
break;
221-
case 2:
222-
break;
223-
case 3:
224-
yc = -0.5 * dy;
225-
break;
226-
}
227-
} else {
228-
switch (align) {
229-
case 7:
230-
xc += 0.5 * dx;
231-
yc += 0.5 * dy;
232-
break;
233-
case 8:
234-
yc += 0.5 * dy;
235-
break;
236-
case 9:
237-
xc -= 0.5 * dx;
238-
yc += 0.5 * dy;
239-
break;
240-
case 4:
241-
xc += 0.5 * dx;
242-
break;
243-
case 5:
244-
break;
245-
case 6:
246-
xc = -0.5 * dx;
247-
break;
248-
case 1:
249-
xc += 0.5 * dx;
250-
yc -= 0.5 * dy;
251-
break;
252-
case 2:
253-
yc -= 0.5 * dy;
254-
break;
255-
case 3:
256-
xc -= 0.5 * dx;
257-
yc -= 0.5 * dy;
258-
break;
259-
}
219+
switch (vAlign) {
220+
case 1:
221+
yc = 0.5 * dy;
222+
break;
223+
case 2:
224+
break;
225+
case 3:
226+
yc = -0.5 * dy;
227+
break;
260228
}
261229

262230
glTranslated(x, y, 0.);

graf3d/gl/src/TGLPadPainter.cxx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,12 @@ void TGLPadPainter::DrawPolyMarker()
641641
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
642642
glColor4fv(rgba);
643643

644+
644645
const Width_t w = TMath::Max(1, Int_t(TAttMarker::GetMarkerLineWidth(GetAttMarker().GetMarkerStyle())));
645646
glLineWidth(w > fLimits.GetMaxLineWidth() ? fLimits.GetMaxLineWidth() : !w ? 1.f : w);
646647

648+
fMarker.SetMarkerSizeWidth(GetAttMarker().GetMarkerSize(), w);
649+
647650
const TPoint *xy = &fPoly[0];
648651
const Style_t markerStyle = TAttMarker::GetMarkerStyleBase(GetAttMarker().GetMarkerStyle());
649652
const UInt_t n = UInt_t(fPoly.size());
@@ -781,21 +784,23 @@ void TGLPadPainter::DrawTextHelper(Double_t x, Double_t y, const Char *text, ETe
781784
glMatrixMode(GL_MODELVIEW);
782785

783786
Float_t rgba[4] = {};
784-
Rgl::Pad::ExtractRGBA(gVirtualX->GetTextColor(), rgba);
787+
Rgl::Pad::ExtractRGBA(GetAttText().GetTextColor(), rgba);
785788
glColor4fv(rgba);
786789

787790
//10 is the first valid font index.
788791
//20 is FreeSerifBold, as in TTF.cxx and in TGLFontManager.cxx.
789792
//shift - is the shift to access "extended" fonts.
790793
const Int_t shift = TGLFontManager::GetExtendedFontStartIndex();
791794

792-
Int_t fontIndex = TMath::Max(Short_t(10), gVirtualX->GetTextFont());
795+
Int_t fontIndex = TMath::Max(Short_t(10), GetAttText().GetTextFont());
793796
if (fontIndex / 10 + shift > TGLFontManager::GetFontFileArray()->GetEntries())
794797
fontIndex = 20 + shift * 10;
795798
else
796799
fontIndex += shift * 10;
797800

798-
fFM.RegisterFont(TMath::Max(Int_t(gVirtualX->GetTextSize()) - 1, 10),//kTexture does not work if size < 10.
801+
fF.SetTextAlign(GetAttText().GetTextAlign());
802+
803+
fFM.RegisterFont(TMath::Max(Int_t(GetAttText().GetTextSize()) - 1, 10),//kTexture does not work if size < 10.
799804
TGLFontManager::GetFontNameFromId(fontIndex),
800805
TGLFont::kTexture, fF);
801806
fF.PreRender();
@@ -819,7 +824,7 @@ void TGLPadPainter::DrawText(Double_t x, Double_t y, const char *text, ETextMode
819824
{
820825
if (fLocked) return;
821826

822-
if (!gVirtualX->GetTextSize())
827+
if (!GetAttText().GetTextSize())
823828
return;
824829

825830
DrawTextHelper(x, y, text, mode);
@@ -835,7 +840,7 @@ void TGLPadPainter::DrawText(Double_t x, Double_t y, const wchar_t *text, ETextM
835840
{
836841
if (fLocked) return;
837842

838-
if (!gVirtualX->GetTextSize())
843+
if (!GetAttText().GetTextSize())
839844
return;
840845

841846
DrawTextHelper(x, y, text, mode);

0 commit comments

Comments
 (0)