#include "TPad.h"
#include "TPoint.h"
#include "TPadPainter.h"
#include "TVirtualX.h"
const Int_t kPXY = 1002;
static TPoint gPXY[kPXY];
ClassImp(TPadPainter)
TPadPainter::TPadPainter()
{
}
Color_t TPadPainter::GetLineColor() const
{
return gVirtualX->GetLineColor();
}
Style_t TPadPainter::GetLineStyle() const
{
return gVirtualX->GetLineStyle();
}
Width_t TPadPainter::GetLineWidth() const
{
return gVirtualX->GetLineWidth();
}
void TPadPainter::SetLineColor(Color_t lcolor)
{
gVirtualX->SetLineColor(lcolor);
}
void TPadPainter::SetLineStyle(Style_t lstyle)
{
gVirtualX->SetLineStyle(lstyle);
}
void TPadPainter::SetLineWidth(Width_t lwidth)
{
gVirtualX->SetLineWidth(lwidth);
}
Color_t TPadPainter::GetFillColor() const
{
return gVirtualX->GetFillColor();
}
Style_t TPadPainter::GetFillStyle() const
{
return gVirtualX->GetFillStyle();
}
Bool_t TPadPainter::IsTransparent() const
{
return gVirtualX->IsTransparent();
}
void TPadPainter::SetFillColor(Color_t fcolor)
{
gVirtualX->SetFillColor(fcolor);
}
void TPadPainter::SetFillStyle(Style_t fstyle)
{
gVirtualX->SetFillStyle(fstyle);
}
void TPadPainter::SetOpacity(Int_t percent)
{
gVirtualX->SetOpacity(percent);
}
Short_t TPadPainter::GetTextAlign() const
{
return gVirtualX->GetTextAlign();
}
Float_t TPadPainter::GetTextAngle() const
{
return gVirtualX->GetTextAngle();
}
Color_t TPadPainter::GetTextColor() const
{
return gVirtualX->GetTextColor();
}
Font_t TPadPainter::GetTextFont() const
{
return gVirtualX->GetTextFont();
}
Float_t TPadPainter::GetTextSize() const
{
return gVirtualX->GetTextSize();
}
Float_t TPadPainter::GetTextMagnitude() const
{
return gVirtualX->GetTextMagnitude();
}
void TPadPainter::SetTextAlign(Short_t align)
{
gVirtualX->SetTextAlign(align);
}
void TPadPainter::SetTextAngle(Float_t tangle)
{
gVirtualX->SetTextAngle(tangle);
}
void TPadPainter::SetTextColor(Color_t tcolor)
{
gVirtualX->SetTextColor(tcolor);
}
void TPadPainter::SetTextFont(Font_t tfont)
{
gVirtualX->SetTextFont(tfont);
}
void TPadPainter::SetTextSize(Float_t tsize)
{
gVirtualX->SetTextSize(tsize);
}
void TPadPainter::SetTextSizePixels(Int_t npixels)
{
gVirtualX->SetTextSizePixels(npixels);
}
Int_t TPadPainter::CreateDrawable(UInt_t w, UInt_t h)
{
return gVirtualX->OpenPixmap(Int_t(w), Int_t(h));
}
void TPadPainter::ClearDrawable()
{
gVirtualX->ClearWindow();
}
void TPadPainter::CopyDrawable(Int_t id, Int_t px, Int_t py)
{
gVirtualX->CopyPixmap(id, px, py);
}
void TPadPainter::DestroyDrawable()
{
gVirtualX->ClosePixmap();
}
void TPadPainter::SelectDrawable(Int_t device)
{
gVirtualX->SelectWindow(device);
}
void TPadPainter::DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
{
Int_t px1 = gPad->XtoPixel(x1);
Int_t px2 = gPad->XtoPixel(x2);
Int_t py1 = gPad->YtoPixel(y1);
Int_t py2 = gPad->YtoPixel(y2);
gVirtualX->DrawLine(px1, py1, px2, py2);
}
void TPadPainter::DrawLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2)
{
Int_t px1 = gPad->UtoPixel(u1);
Int_t py1 = gPad->VtoPixel(v1);
Int_t px2 = gPad->UtoPixel(u2);
Int_t py2 = gPad->VtoPixel(v2);
gVirtualX->DrawLine(px1, py1, px2, py2);
}
void TPadPainter::DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, EBoxMode mode)
{
Int_t px1 = gPad->XtoPixel(x1);
Int_t px2 = gPad->XtoPixel(x2);
Int_t py1 = gPad->YtoPixel(y1);
Int_t py2 = gPad->YtoPixel(y2);
if (TMath::Abs(px2-px1) < 1) px2 = px1+1;
if (TMath::Abs(py1-py2) < 1) py1 = py2+1;
gVirtualX->DrawBox(px1,py1,px2,py2,(TVirtualX::EBoxMode)mode);
}
void TPadPainter::DrawFillArea(Int_t n, const Double_t *x, const Double_t *y)
{
TPoint *pxy = &gPXY[0];
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
Int_t fillstyle = gVirtualX->GetFillStyle();
for (Int_t i=0; i<n; i++) {
pxy[i].fX = gPad->XtoPixel(x[i]);
pxy[i].fY = gPad->YtoPixel(y[i]);
}
if (fillstyle == 0) {
pxy[n].fX = pxy[0].fX;
pxy[n].fY = pxy[0].fY;
gVirtualX->DrawFillArea(n+1,pxy);
} else {
gVirtualX->DrawFillArea(n,pxy);
}
if (n >= kPXY) delete [] pxy;
}
void TPadPainter::DrawFillArea(Int_t n, const Float_t *x, const Float_t *y)
{
TPoint *pxy = &gPXY[0];
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
Int_t fillstyle = gVirtualX->GetFillStyle();
for (Int_t i=0; i<n; i++) {
pxy[i].fX = gPad->XtoPixel(x[i]);
pxy[i].fY = gPad->YtoPixel(y[i]);
}
if (fillstyle == 0) {
pxy[n].fX = pxy[0].fX;
pxy[n].fY = pxy[0].fY;
gVirtualX->DrawFillArea(n+1,pxy);
} else {
gVirtualX->DrawFillArea(n,pxy);
}
if (n >= kPXY) delete [] pxy;
}
void TPadPainter::DrawPolyLine(Int_t n, const Double_t *x, const Double_t *y)
{
TPoint *pxy = &gPXY[0];
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
for (Int_t i=0; i<n; i++) {
pxy[i].fX = gPad->XtoPixel(x[i]);
pxy[i].fY = gPad->YtoPixel(y[i]);
}
gVirtualX->DrawPolyLine(n,pxy);
if (n >= kPXY) delete [] pxy;
}
void TPadPainter::DrawPolyLine(Int_t n, const Float_t *x, const Float_t *y)
{
TPoint *pxy = &gPXY[0];
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
for (Int_t i=0; i<n; i++) {
pxy[i].fX = gPad->XtoPixel(x[i]);
pxy[i].fY = gPad->YtoPixel(y[i]);
}
gVirtualX->DrawPolyLine(n,pxy);
if (n >= kPXY) delete [] pxy;
}
void TPadPainter::DrawPolyLineNDC(Int_t n, const Double_t *u, const Double_t *v)
{
TPoint *pxy = &gPXY[0];
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
for (Int_t i=0; i<n; i++) {
pxy[i].fX = gPad->UtoPixel(u[i]);
pxy[i].fY = gPad->VtoPixel(v[i]);
}
gVirtualX->DrawPolyLine(n,pxy);
if (n >= kPXY) delete [] pxy;
}
void TPadPainter::DrawPolyMarker(Int_t n, const Double_t *x, const Double_t *y)
{
TPoint *pxy = &gPXY[0];
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
for (Int_t i=0; i<n; i++) {
pxy[i].fX = gPad->XtoPixel(x[i]);
pxy[i].fY = gPad->YtoPixel(y[i]);
}
gVirtualX->DrawPolyMarker(n,pxy);
if (n >= kPXY) delete [] pxy;
}
void TPadPainter::DrawPolyMarker(Int_t n, const Float_t *x, const Float_t *y)
{
TPoint *pxy = &gPXY[0];
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
for (Int_t i=0; i<n; i++) {
pxy[i].fX = gPad->XtoPixel(x[i]);
pxy[i].fY = gPad->YtoPixel(y[i]);
}
gVirtualX->DrawPolyMarker(n,pxy);
if (n >= kPXY) delete [] pxy;
}
void TPadPainter::DrawText(Double_t x, Double_t y, const char *text, ETextMode mode)
{
Int_t px = gPad->XtoPixel(x);
Int_t py = gPad->YtoPixel(y);
Double_t angle = GetTextAngle();
Double_t mgn = GetTextMagnitude();
gVirtualX->DrawText(px, py, angle, mgn, text, (TVirtualX::ETextMode)mode);
}
void TPadPainter::DrawTextNDC(Double_t u, Double_t v, const char *text, ETextMode mode)
{
Int_t px = gPad->UtoPixel(u);
Int_t py = gPad->VtoPixel(v);
Double_t angle = GetTextAngle();
Double_t mgn = GetTextMagnitude();
gVirtualX->DrawText(px, py, angle, mgn, text, (TVirtualX::ETextMode)mode);
}