Skip to content

Commit 71d11a9

Browse files
committed
[x11] use EAlign for text align constant
While it is used both in TGX11 and TGX11TTF, put it into protected declaration space. Remove no longer used fTextAlign members
1 parent de932a7 commit 71d11a9

4 files changed

Lines changed: 29 additions & 50 deletions

File tree

graf2d/x11/inc/TGX11.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct XWindow_t;
6363

6464
class TGX11 : public TVirtualX {
6565

66+
friend struct XWindow_t;
67+
6668
private:
6769
std::unordered_map<Int_t,std::unique_ptr<XWindow_t>> fWindows; // map of windows
6870
TExMap *fColors; ///< Hash list of colors
@@ -108,9 +110,6 @@ class TGX11 : public TVirtualX {
108110
ULong_t fBlackPixel; ///< Value of black pixel in colormap
109111
ULong_t fWhitePixel; ///< Value of white pixel in colormap
110112
Int_t fScreenNumber; ///< Screen number
111-
Int_t fTextAlignH; ///< Text Alignment Horizontal
112-
Int_t fTextAlignV; ///< Text Alignment Vertical
113-
Int_t fTextAlign; ///< Text alignment (set in SetTextAlign) !!! conflict with TAttText
114113
Float_t fCharacterUpX; ///< Character Up vector along X
115114
Float_t fCharacterUpY; ///< Character Up vector along Y
116115
Float_t fTextMagnitude; ///< Text Magnitude
@@ -125,12 +124,17 @@ class TGX11 : public TVirtualX {
125124
Bool_t fHasXft; ///< True when XftFonts are used
126125

127126
// needed by TGX11TTF
127+
enum EAlign {
128+
kAlignNone,
129+
kTLeft, kTCenter, kTRight, kMLeft, kMCenter, kMRight,
130+
kBLeft, kBCenter, kBRight };
131+
128132
Bool_t AllocColor(Colormap cmap, RXColor *color);
129133
void QueryColors(Colormap cmap, RXColor *colors, Int_t ncolors);
130134
void *GetGC(Int_t which) const;
131135
Window_t GetWindow(WinContext_t wctxt) const;
132136
void *GetGCW(WinContext_t wctxt, Int_t which) const;
133-
Int_t GetTextAlignW(WinContext_t wctxt) const;
137+
EAlign GetTextAlignW(WinContext_t wctxt) const;
134138

135139
XColor_t &GetColor(Int_t cid);
136140

graf2d/x11/src/TGX11.cxx

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct XWindow_t {
124124
std::vector<XPoint> markerShape; ///< marker shape points
125125
Int_t markerLineWidth = 0; ///< line width used for marker
126126
TAttText fAttText; ///< current text attribute
127-
Int_t textAlign = 0; ///< selected text align
127+
TGX11::EAlign textAlign = TGX11::kAlignNone; ///< selected text align
128128
XFontStruct *textFont = nullptr; ///< selected text font
129129
};
130130

@@ -213,9 +213,6 @@ TGX11::TGX11()
213213
fDepth = 0;
214214
fHasTTFonts = kFALSE;
215215
fHasXft = kFALSE;
216-
fTextAlignH = 1;
217-
fTextAlignV = 1;
218-
fTextAlign = 7;
219216
fTextMagnitude = 1;
220217
for (i = 0; i < kNumCursors; i++) fCursors[i] = 0;
221218
}
@@ -247,9 +244,6 @@ TGX11::TGX11(const char *name, const char *title) : TVirtualX(name, title)
247244
fDepth = 0;
248245
fHasTTFonts = kFALSE;
249246
fHasXft = kFALSE;
250-
fTextAlignH = 1;
251-
fTextAlignV = 1;
252-
fTextAlign = 7;
253247
fTextMagnitude = 1;
254248
for (i = 0; i < kNumCursors; i++)
255249
fCursors[i] = 0;
@@ -272,9 +266,6 @@ TGX11::TGX11(TGX11 &&org) : TVirtualX(org)
272266
fWhitePixel = org.fWhitePixel;
273267
fHasTTFonts = org.fHasTTFonts;
274268
fHasXft = org.fHasXft;
275-
fTextAlignH = org.fTextAlignH;
276-
fTextAlignV = org.fTextAlignV;
277-
fTextAlign = org.fTextAlign;
278269
fTextMagnitude = org.fTextMagnitude;
279270
fCharacterUpX = org.fCharacterUpX;
280271
fCharacterUpY = org.fCharacterUpY;
@@ -862,12 +853,12 @@ void TGX11::DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Float
862853

863854
case kClear:
864855
XRotDrawAlignedString((Display*)fDisplay, ctxt->textFont, angle,
865-
ctxt->fDrawing, ctxt->fGClist[kGCtext], x, y, (char*)text, ctxt->textAlign);
856+
ctxt->fDrawing, ctxt->fGClist[kGCtext], x, y, (char*)text, (int) ctxt->textAlign);
866857
break;
867858

868859
case kOpaque:
869860
XRotDrawAlignedImageString((Display*)fDisplay, ctxt->textFont, angle,
870-
ctxt->fDrawing, ctxt->fGClist[kGCtext], x, y, (char*)text, ctxt->textAlign);
861+
ctxt->fDrawing, ctxt->fGClist[kGCtext], x, y, (char*)text, (int) ctxt->textAlign);
871862
break;
872863

873864
default:
@@ -1077,10 +1068,10 @@ void *TGX11::GetGCW(WinContext_t wctxt, Int_t which) const
10771068
/// Return text align value for specified window context.
10781069
/// Protected method used by TGX11TTF.
10791070

1080-
Int_t TGX11::GetTextAlignW(WinContext_t wctxt) const
1071+
TGX11::EAlign TGX11::GetTextAlignW(WinContext_t wctxt) const
10811072
{
10821073
auto ctxt = (XWindow_t *) wctxt;
1083-
return ctxt ? ctxt->textAlign : 0;
1074+
return ctxt ? ctxt->textAlign : kAlignNone;
10841075
}
10851076

10861077
////////////////////////////////////////////////////////////////////////////////
@@ -2653,9 +2644,6 @@ void TGX11::SetTextAlign(Short_t talign)
26532644
arg.SetTextAlign(talign);
26542645

26552646
SetAttText((WinContext_t) gCws, arg);
2656-
2657-
// FIXME: member fTextAlign conflicts with TAttText::fTextAlign
2658-
fTextAlign = gCws->textAlign;
26592647
}
26602648

26612649
////////////////////////////////////////////////////////////////////////////////
@@ -3863,44 +3851,46 @@ void TGX11::SetAttText(WinContext_t wctxt, const TAttText &att)
38633851
Int_t txalh = att.GetTextAlign() / 10;
38643852
Int_t txalv = att.GetTextAlign() % 10;
38653853

3854+
ctxt->textAlign = kAlignNone;
3855+
38663856
switch (txalh) {
38673857
case 0 :
38683858
case 1 :
38693859
switch (txalv) { //left
38703860
case 1 :
3871-
ctxt->textAlign = 7; //bottom
3861+
ctxt->textAlign = kBLeft; //bottom
38723862
break;
38733863
case 2 :
3874-
ctxt->textAlign = 4; //center
3864+
ctxt->textAlign = kMLeft; //middle
38753865
break;
38763866
case 3 :
3877-
ctxt->textAlign = 1; //top
3867+
ctxt->textAlign = kTLeft; //top
38783868
break;
38793869
}
38803870
break;
38813871
case 2 :
38823872
switch (txalv) { //center
38833873
case 1 :
3884-
ctxt->textAlign = 8; //bottom
3874+
ctxt->textAlign = kBCenter; //bottom
38853875
break;
38863876
case 2 :
3887-
ctxt->textAlign = 5; //center
3877+
ctxt->textAlign = kMCenter; //middle
38883878
break;
38893879
case 3 :
3890-
ctxt->textAlign = 2; //top
3880+
ctxt->textAlign = kTCenter; //top
38913881
break;
38923882
}
38933883
break;
38943884
case 3 :
38953885
switch (txalv) { //right
38963886
case 1 :
3897-
ctxt->textAlign = 9; //bottom
3887+
ctxt->textAlign = kBRight; //bottom
38983888
break;
38993889
case 2 :
3900-
ctxt->textAlign = 6; //center
3890+
ctxt->textAlign = kMRight; //center
39013891
break;
39023892
case 3 :
3903-
ctxt->textAlign = 3; //top
3893+
ctxt->textAlign = kTRight; //top
39043894
break;
39053895
}
39063896
break;

graf2d/x11ttf/inc/TGX11TTF.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,12 @@ class TXftFontHash;
2727
class TGX11TTF : public TGX11 {
2828

2929
private:
30-
enum EAlign {
31-
// clang++ <v20 (-Wshadow) complains about shadowing GuiTypes.h global variable kNone. Let's silence warning:
32-
#if defined(__clang__) && __clang_major__ < 20
33-
#pragma clang diagnostic push
34-
#pragma clang diagnostic ignored "-Wshadow"
35-
#endif
36-
kNone,
37-
#if defined(__clang__) && __clang_major__ < 20
38-
#pragma clang diagnostic pop
39-
#endif
40-
41-
kTLeft, kTCenter, kTRight, kMLeft, kMCenter, kMRight,
42-
kBLeft, kBCenter, kBRight };
43-
4430
FT_Vector fAlign; ///< alignment vector
4531
#ifdef R__HAS_XFT
4632
TXftFontHash *fXftFontHash; ///< hash table for Xft fonts
4733
#endif
4834

49-
void Align(Int_t value);
35+
void Align(WinContext_t wctxt);
5036
void DrawImage(FT_Bitmap *source, ULong_t fore, ULong_t back, RXImage *xim,
5137
Int_t bx, Int_t by);
5238
Bool_t IsVisible(WinContext_t wctxt, Int_t x, Int_t y, UInt_t w, UInt_t h);

graf2d/x11ttf/src/TGX11TTF.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ Bool_t TGX11TTF::Init(void *display)
208208
/// then the rotation is applied on the alignment variables.
209209
/// SetRotation and LayoutGlyphs should have been called before.
210210

211-
void TGX11TTF::Align(Int_t value)
211+
void TGX11TTF::Align(WinContext_t wctxt)
212212
{
213-
EAlign align = (EAlign) value;
213+
auto align = GetTextAlignW(wctxt);
214214

215215
// vertical alignment
216216
if (align == kTLeft || align == kTCenter || align == kTRight) {
@@ -372,7 +372,7 @@ void TGX11TTF::DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Fl
372372
TTF::SetRotationMatrix(angle);
373373
TTF::PrepareString(text);
374374
TTF::LayoutGlyphs();
375-
Align(GetTextAlignW(wctxt));
375+
Align(wctxt);
376376
RenderString(wctxt, x, y, mode);
377377
}
378378
}
@@ -391,7 +391,7 @@ void TGX11TTF::DrawTextW(WinContext_t wctxt, Int_t x, Int_t y, Float_t angle, Fl
391391
TTF::SetRotationMatrix(angle);
392392
TTF::PrepareString(text);
393393
TTF::LayoutGlyphs();
394-
Align(GetTextAlignW(wctxt));
394+
Align(wctxt);
395395
RenderString(wctxt, x, y, mode);
396396
}
397397
}
@@ -549,7 +549,6 @@ void TGX11TTF::RenderString(WinContext_t wctxt, Int_t x, Int_t y, ETextMode mode
549549
////////////////////////////////////////////////////////////////////////////////
550550
/// Set specified font.
551551

552-
553552
void TGX11TTF::SetAttText(WinContext_t wctxt, const TAttText &att)
554553
{
555554
// TODO: add to window context custom part for TTF,

0 commit comments

Comments
 (0)