Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/base/inc/TVirtualPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class TVirtualPad : public TObject, public TAttLine, public TAttFill,
virtual Double_t GetHNDC() const = 0;
virtual UInt_t GetWw() const = 0;
virtual UInt_t GetWh() const = 0;
virtual UInt_t GetPadWidth() const = 0;
virtual UInt_t GetPadHeight() const = 0;
virtual Double_t GetAbsXlowNDC() const = 0;
virtual Double_t GetAbsYlowNDC() const = 0;
virtual Double_t GetAbsWNDC() const = 0;
Expand Down
19 changes: 9 additions & 10 deletions core/base/src/TAttText.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ sizes in two different pads.
The text size in pixels (`charheight`) computed in the following way:

~~~ {.cpp}
pad_width = gPad->XtoPixel(gPad->GetX2());
pad_height = gPad->YtoPixel(gPad->GetY1());
if (pad_width < pad_height) charheight = textsize*pad_width;
else charheight = textsize*pad_height;
UInt_t pad_width = gPad->GetPadWidth();
UInt_t pad_height = gPad->GetPadHeight();
Float_t charheight = textsize*TMath::Min(pad_width, pad_height);
~~~

This value can be obtained using GetTextSizePixels() method:
Expand Down Expand Up @@ -336,9 +335,9 @@ Float_t TAttText::GetTextSizeRelative(TVirtualPad &pad) const
{
Float_t rsize = GetTextSize();
if (GetTextFont() % 10 > 2) {
auto wh = pad.XtoPixel(pad.GetX2());
auto hh = pad.YtoPixel(pad.GetY1());
rsize = rsize / TMath::Max(1, TMath::Min(wh, hh));
UInt_t padw = pad.GetPadWidth();
UInt_t padh = pad.GetPadHeight();
rsize /= TMath::Max((UInt_t) 1, TMath::Min(padw, padh));
}
return rsize;
}
Expand All @@ -353,9 +352,9 @@ Float_t TAttText::GetTextSizePixels(TVirtualPad &pad) const
{
Float_t tsize = GetTextSize();
if (GetTextFont() % 10 <= 2) {
auto wh = pad.XtoPixel(pad.GetX2());
auto hh = pad.YtoPixel(pad.GetY1());
tsize *= TMath::Min(wh, hh);
UInt_t padw = pad.GetPadWidth();
UInt_t padh = pad.GetPadHeight();
tsize *= TMath::Min(padw, padh);
}
return tsize;
}
Expand Down
14 changes: 3 additions & 11 deletions graf2d/asimage/src/TASImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5729,19 +5729,11 @@ void TASImage::DrawTextOnPad(TText *text, Int_t x, Int_t y, TVirtualPad *pad, In
// set text font
TTF::SetTextFont(text->GetTextFont());

Int_t wh = 100, hh = 100;
if (pad) {
wh = pad->XtoPixel(pad->GetX2());
hh = pad->YtoPixel(pad->GetY1());
}
UInt_t padw = pad ? pad->GetPadWidth() : 100;
UInt_t padh = pad ? pad->GetPadHeight() : 100;

// set text size
Float_t ttfsize;
if (wh < hh) {
ttfsize = text->GetTextSize() * wh;
} else {
ttfsize = text->GetTextSize() * hh;
}
Float_t ttfsize = text->GetTextSize() * TMath::Min(padw, padh);
TTF::SetTextSize(ttfsize*kScale);

// set text angle
Expand Down
2 changes: 2 additions & 0 deletions graf2d/gpad/inc/TCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ friend class TInterpreter;
UInt_t GetWindowHeight() const { return fWindowHeight; }
UInt_t GetWw() const override { return fCw; }
UInt_t GetWh() const override { return fCh; }
UInt_t GetPadWidth() const override { return fCw; }
UInt_t GetPadHeight() const override { return fCh; }
virtual void GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
{wtopx=GetWindowTopX(); wtopy=fWindowTopY; ww=fWindowWidth; wh=fWindowHeight;}
virtual void HandleInput(EEventType button, Int_t x, Int_t y);
Expand Down
2 changes: 2 additions & 0 deletions graf2d/gpad/inc/TPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ friend class TWebCanvas;
Double_t GetHNDC() const override { return fHNDC; }
UInt_t GetWw() const override;
UInt_t GetWh() const override;
UInt_t GetPadWidth() const override;
UInt_t GetPadHeight() const override;
Double_t GetAbsXlowNDC() const override { return fAbsXlowNDC; }
Double_t GetAbsYlowNDC() const override { return fAbsYlowNDC; }
Double_t GetAbsWNDC() const override { return fAbsWNDC; }
Expand Down
39 changes: 37 additions & 2 deletions graf2d/gpad/src/TPad.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <iostream>
#include <locale>
#include <memory>
#include <cmath>

#include "TROOT.h"
#include "TBuffer.h"
Expand Down Expand Up @@ -2816,21 +2817,55 @@ TVirtualPad *TPad::GetPadSave() const
}

////////////////////////////////////////////////////////////////////////////////
/// Get Wh.
/// Get canvas height

UInt_t TPad::GetWh() const
{
return fCanvas ? fCanvas->GetWh() : 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Get Ww.
/// Get canvas width

UInt_t TPad::GetWw() const
{
return fCanvas ? fCanvas->GetWw() : 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Get pad width

UInt_t TPad::GetPadWidth() const
{
// Very often pad width was calculated as XtoPixel(GetX2());
// But if coordinate system broken such trnasformation fail.
// Therefore use canvas width multiplied by absolute NDC width value
// Keep fallback solution only when canvas width cannot be defined

auto cw = GetWw();
if (!cw)
return XtoPixel(GetX2());

return static_cast<UInt_t>(std::lround(cw * GetAbsWNDC()));
}

////////////////////////////////////////////////////////////////////////////////
/// Get pad height

UInt_t TPad::GetPadHeight() const
{
// Very often pad height was calculated as YtoPixel(GetY1())
// But if coordinate system broken such trnasformation fail.
// Therefore use canvas height multiplied by absolute NDC height value
// Keep fallback solution only when canvas height cannot be defined

auto ch = GetWh();
if (!ch)
return YtoPixel(GetY1());

return static_cast<UInt_t>(std::lround(GetWh() * GetAbsHNDC()));
}

////////////////////////////////////////////////////////////////////////////////
/// Hide tool tip depending on the event type. Typically tool tips
/// are hidden when event is not a kMouseEnter and not a kMouseMotion
Expand Down
4 changes: 2 additions & 2 deletions graf2d/graf/src/TPaveLabel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ void TPaveLabel::PaintPaveLabel(Double_t x1, Double_t y1,Double_t x2, Double_t
if (nch <= 0) return;

// Draw label
Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
Double_t wh = gPad->GetPadWidth();
Double_t hh = gPad->GetPadHeight();
if (wh==0||hh==0) return;
Double_t labelsize, textsize = GetTextSize();
Int_t automat = 0;
Expand Down
6 changes: 4 additions & 2 deletions graf2d/postscript/src/TPostScript.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2675,8 +2675,10 @@ void TPostScript::Text(Double_t xx, Double_t yy, const char *chars)
// Compute the font size. Exit if it is 0
// The font size is computed from the TTF size to get exactly the same
// size on the screen and in the PostScript file.
Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
Double_t wh = (Double_t) gPad->GetPadWidth();
Double_t hh = (Double_t) gPad->GetPadHeight();
if (wh <= 0 || hh <= 0)
return;
Float_t tsize, ftsize;

if (wh < hh) {
Expand Down
4 changes: 2 additions & 2 deletions graf2d/postscript/src/TSVG.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1361,8 +1361,8 @@ void TSVG::Text(Double_t xx, Double_t yy, const char *chars)
Double_t txalv = fTextAlign%10;
if (txalv <1) txalv = 1; else if (txalv > 3) txalv = 3;

Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
Double_t wh = (Double_t)gPad->GetPadWidth();
Double_t hh = (Double_t)gPad->GetPadHeight();
Float_t fontrap = 1.09; //scale down compared to X11
Float_t ftsize;

Expand Down
4 changes: 2 additions & 2 deletions graf2d/postscript/src/TTeXDump.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,8 @@ void TTeXDump::SetTextColor( Color_t cindex )

void TTeXDump::Text(Double_t x, Double_t y, const char *chars)
{
Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
Double_t wh = (Double_t)gPad->GetPadWidth();
Double_t hh = (Double_t)gPad->GetPadHeight();
Float_t tsize, ftsize;
if (wh < hh) {
tsize = fTextSize*wh;
Expand Down
6 changes: 3 additions & 3 deletions hist/histpainter/src/THistPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10360,9 +10360,9 @@ void THistPainter::PaintTitle()

if (ht <= 0) {
if (gStyle->GetTitleFont("")%10 == 3) {
Double_t hw = TMath::Max((Double_t)gPad->XtoPixel(gPad->GetX2()),
(Double_t)gPad->YtoPixel(gPad->GetY1()));
ht = 1.1*(gStyle->GetTitleSize("")/hw);
Double_t hw = (Double_t) TMath::Max(gPad->GetPadWidth(), gPad->GetPadHeight());
if (hw > 0)
ht = 1.1 * (gStyle->GetTitleSize("")/hw);
} else {
ht = 1.1*gStyle->GetTitleFontSize();
}
Expand Down
4 changes: 2 additions & 2 deletions test/Aclock.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ void ClockHand::Move(Float_t clock_angle)
// ClockPoints used to rotate,scale and shift initial points
static ClockPoints *points = new ClockPoints();

Float_t wh = (Float_t)fPad->XtoPixel(fPad->GetX2());
Float_t hh = (Float_t)fPad->YtoPixel(fPad->GetY1());
Float_t wh = (Float_t)fPad->GetPadWidth();
Float_t hh = (Float_t)fPad->GetPadHeight();

for (int i = 0; i < n; i++) {
points->SetXY(fX0[i],fY0[i]);
Expand Down
2 changes: 1 addition & 1 deletion test/Tetris.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void TetrisBox::SetY(Int_t y)
// Set Y measured in boxes units

// height in pixels of pad
Float_t height = (Float_t)fPad->YtoPixel(fPad->GetY1());
Float_t height = (Float_t)fPad->GetPadHeight();

Coord_t y1 = ((Float_t)y)*gBoxPixelSize/height;
Coord_t y2 = ((Float_t)y+1)*gBoxPixelSize/height;
Expand Down
30 changes: 25 additions & 5 deletions test/Tetris.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class TetrisBox : public TWbox {

void Erase();
void Paint(Option_t *option="") override;
void ExecuteEvent(Int_t, Int_t, Int_t) override { return; } // disable any actions on it
void ExecuteEvent(Int_t, Int_t, Int_t) override {} // disable any actions on it

ClassDefOverride(TetrisBox, 0)
};


Expand Down Expand Up @@ -174,7 +176,9 @@ friend class Tetris;

void PaintModified() override;
void PieceDropped(TetrisPiece *piece, Int_t height);
void ExecuteEvent(Int_t, Int_t, Int_t) override { return; } // disable any actions on it
void ExecuteEvent(Int_t, Int_t, Int_t) override {} // disable any actions on it

ClassDefOverride(TetrisBoard, 0)
};


Expand Down Expand Up @@ -205,7 +209,9 @@ class CurrentPiece : public TetrisPiece, public TTimer {
Bool_t Notify() override;
void SetSpeed();
void Paint(Option_t *option="") override;
void ExecuteEvent(Int_t, Int_t, Int_t) override { return; } // disable any actions on it
void ExecuteEvent(Int_t, Int_t, Int_t) override { } // disable any actions on it

ClassDefOverride(CurrentPiece, 0)
};


Expand All @@ -228,7 +234,9 @@ class NextPiecePad : public TPad {
void Show() { fPiece->Show(); Modified(kTRUE); }

TetrisPiece *GetPiece() { return fPiece; }
void ExecuteEvent(Int_t, Int_t, Int_t) override { return; } // disable any actions on it
void ExecuteEvent(Int_t, Int_t, Int_t) override { } // disable any actions on it

ClassDefOverride(NextPiecePad, 0)
};


Expand All @@ -244,6 +252,8 @@ class QuitButton : public TButton {
~QuitButton() override { }

void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;

ClassDefOverride(QuitButton, 0)
};


Expand All @@ -269,6 +279,8 @@ class PauseButton : public TButton {

Bool_t IsPressed() { return fPressed; }
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;

ClassDefOverride(PauseButton, 0)
};


Expand All @@ -294,6 +306,8 @@ class NewGameButton : public TButton {

Bool_t IsPressed() { return fPressed; }
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;

ClassDefOverride(NewGameButton, 0)
};


Expand All @@ -315,7 +329,9 @@ class InfoPad : public TPad, public TAttText {
virtual void AddValue(Int_t addValue=1) { fValue = fValue+addValue; Modified(kTRUE); }

void PaintModified() override;
void ExecuteEvent(Int_t, Int_t, Int_t) override { return; } // disable any actions on it
void ExecuteEvent(Int_t, Int_t, Int_t) override { } // disable any actions on it

ClassDefOverride(InfoPad, 0)
};


Expand All @@ -331,6 +347,8 @@ class KeyHandler : public TGFrame {
~KeyHandler() override;

Bool_t HandleKey(Event_t *event) override; // handler of the key events

ClassDefOverride(KeyHandler, 0)
};


Expand All @@ -344,6 +362,8 @@ class UpdateLevelTimer : public TTimer {
~UpdateLevelTimer() override { }

Bool_t Notify() override;

ClassDefOverride(UpdateLevelTimer, 0)
};


Expand Down
Loading