#include <string.h>
#include <stdlib.h>
#include "Riostream.h"
#include "TROOT.h"
#include "TError.h"
#include "TMath.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TH1.h"
#include "TClass.h"
#include "TBaseClass.h"
#include "TClassTable.h"
#include "TVirtualPS.h"
#include "TVirtualX.h"
#include "TVirtualViewer3D.h"
#include "TView.h"
#include "TPoint.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "THStack.h"
#include "TPaveText.h"
#include "TGroupButton.h"
#include "TBrowser.h"
#include "TVirtualGL.h"
#include "TString.h"
#include "TDataMember.h"
#include "TMethod.h"
#include "TDataType.h"
#include "TRealData.h"
#include "TFrame.h"
#include "TExec.h"
#include "TDatime.h"
#include "TColor.h"
#include "TCanvas.h"
#include "TPluginManager.h"
#include "TEnv.h"
#include "TImage.h"
#include "TViewer3DPad.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TCreatePrimitives.h"
#include "TLegend.h"
#include "TAtt3D.h"
#include "TObjString.h"
#include "TApplication.h"
const Int_t kPXY = 1002;
static TPoint gPXY[kPXY];
static Int_t gReadLevel = 0;
Int_t TPad::fgMaxPickDistance = 5;
ClassImpQ(TPad)
/*
<img src="gif/tpad_classtree.gif">
*/
//End_Html
/*
<img src="examples/gif/canvas.gif">
*/
//End_Html
TPad::TPad()
{
fModified = kTRUE;
fTip = 0;
fPadPointer = 0;
fPrimitives = 0;
fExecs = 0;
fCanvas = 0;
fMother = 0;
fPadPaint = 0;
fPixmapID = -1;
fGLDevice = -1;
fCopyGLDevice = kFALSE;
fEmbeddedGL = kFALSE;
fTheta = 30;
fPhi = 30;
fNumber = 0;
fAbsCoord = kFALSE;
fEditable = kTRUE;
fCrosshair = 0;
fCrosshairPos = 0;
fPadView3D = 0;
fMother = (TPad*)gPad;
fFixedAspectRatio = kFALSE;
fAspectRatio = 0.;
fLogx = 0;
fLogy = 0;
fLogz = 0;
fGridx = 0;
fGridy = 0;
fTickx = 0;
fTicky = 0;
fFrame = 0;
fView = 0;
fUxmin = fUymin = fUxmax = fUymax = 0;
fX1 = 0;
fX2 = 1;
fY1 = 0;
fY2 = 1;
fXlowNDC = 0;
fYlowNDC = 0;
fWNDC = 1;
fHNDC = 1;
fViewer3D = 0;
SetBit(kMustCleanup);
}
TPad::TPad(const char *name, const char *title, Double_t xlow,
Double_t ylow, Double_t xup, Double_t yup,
Color_t color, Short_t bordersize, Short_t bordermode)
: TVirtualPad(name,title,xlow,ylow,xup,yup,color,bordersize,bordermode)
{
fModified = kTRUE;
fTip = 0;
fBorderSize = bordersize;
fBorderMode = bordermode;
if (gPad) fCanvas = gPad->GetCanvas();
else fCanvas = (TCanvas*)this;
fMother = (TPad*)gPad;
fPrimitives = new TList;
fExecs = new TList;
fPadPointer = 0;
fTheta = 30;
fPhi = 30;
fGridx = gStyle->GetPadGridX();
fGridy = gStyle->GetPadGridY();
fTickx = gStyle->GetPadTickX();
fTicky = gStyle->GetPadTickY();
fFrame = 0;
fView = 0;
fPadPaint = 0;
fPadView3D = 0;
fPixmapID = -1;
fGLDevice = -1;
fCopyGLDevice = kFALSE;
fEmbeddedGL = kFALSE;
fNumber = 0;
fAbsCoord = kFALSE;
fEditable = kTRUE;
fCrosshair = 0;
fCrosshairPos = 0;
fFixedAspectRatio = kFALSE;
fAspectRatio = 0.;
fViewer3D = 0;
fX1 = 0;
fX2 = 1;
fY1 = 0;
fY2 = 1;
if (!gPad) {
Error("TPad", "You must create a TCanvas before creating a TPad");
MakeZombie();
return;
}
TPad *padsav = (TPad*)gPad;
if ((xlow < 0) || (xlow > 1) || (ylow < 0) || (ylow > 1)) {
Error("TPad", "illegal bottom left position: x=%f, y=%f", xlow, ylow);
goto zombie;
}
if ((xup < 0) || (xup > 1) || (yup < 0) || (yup > 1)) {
Error("TPad", "illegal top right position: x=%f, y=%f", xup, yup);
goto zombie;
}
fLogx = gStyle->GetOptLogx();
fLogy = gStyle->GetOptLogy();
fLogz = gStyle->GetOptLogz();
fUxmin = fUymin = fUxmax = fUymax = 0;
SetPad(name, title, xlow, ylow, xup, yup, color, bordersize, bordermode);
Range(0, 0, 1, 1);
SetBit(kMustCleanup);
SetBit(kCanDelete);
padsav->cd();
return;
zombie:
MakeZombie();
padsav->cd();
}
TPad::~TPad()
{
if (!TestBit(kNotDeleted)) return;
Close();
CloseToolTip(fTip);
DeleteToolTip(fTip);
SafeDelete(fPrimitives);
SafeDelete(fExecs);
delete fViewer3D;
if (fGLDevice != -1)
gGLManager->DeleteGLContext(fGLDevice);
}
void TPad::AddExec(const char *name, const char*command)
{
if (!fExecs) fExecs = new TList;
TExec *ex = new TExec(name,command);
fExecs->Add(ex);
}
void TPad::AutoExec()
{
if (GetCrosshair()) DrawCrosshair();
if (!fExecs) fExecs = new TList;
TIter next(fExecs);
TExec *exec;
while ((exec = (TExec*)next())) {
exec->Exec();
}
}
void TPad::Browse(TBrowser *b)
{
cd();
if (fPrimitives) fPrimitives->Browse(b);
}
TLegend *TPad::BuildLegend(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
const char* title)
{
TList *lop=GetListOfPrimitives();
if (!lop) return 0;
TLegend *leg=0;
TIter next(lop);
TString mes;
TObject *o=0;
while( (o=next()) ) {
if((o->InheritsFrom("TAttLine") || o->InheritsFrom("TAttMarker") ||
o->InheritsFrom("TAttFill")) &&
( !(o->InheritsFrom("TFrame")) && !(o->InheritsFrom("TPave")) )) {
if (!leg) leg = new TLegend(x1, y1, x2, y2, title);
if (o->InheritsFrom("TNamed") && strlen(((TNamed *)o)->GetTitle()))
mes = ((TNamed *)o)->GetTitle();
else if (strlen(o->GetName()))
mes = o->GetName();
else
mes = o->ClassName();
TString opt("");
if (o->InheritsFrom("TAttLine")) opt += "l";
if (o->InheritsFrom("TAttMarker")) opt += "p";
if (o->InheritsFrom("TAttFill")) opt += "f";
leg->AddEntry(o,mes.Data(),opt.Data());
} else if ( o->InheritsFrom("TMultiGraph" ) ) {
if (!leg) leg = new TLegend(x1, y1, x2, y2, title);
TList * grlist = ((TMultiGraph *)o)->GetListOfGraphs();
TIter nextgraph(grlist);
TGraph * gr;
TObject * obj;
while ((obj = nextgraph())) {
gr = (TGraph*) obj;
if (strlen(gr->GetTitle())) mes = gr->GetTitle();
else if (strlen(gr->GetName())) mes = gr->GetName();
else mes = gr->ClassName();
leg->AddEntry( obj, mes.Data(), "lpf" );
}
} else if ( o->InheritsFrom("THStack" ) ) {
if (!leg) leg = new TLegend(x1, y1, x2, y2, title);
TList * hlist = ((THStack *)o)->GetHists();
TIter nexthist(hlist);
TH1 * hist;
TObject * obj;
while ((obj = nexthist())) {
hist = (TH1*) obj;
if (strlen(hist->GetTitle())) mes = hist->GetTitle();
else if (strlen(hist->GetName())) mes = hist->GetName();
else mes = hist->ClassName();
leg->AddEntry( obj, mes.Data(), "lpf" );
}
}
}
if (leg) leg->Draw();
else Info("BuildLegend(void)","No object to build a TLegend.");
return leg;
}
TVirtualPad *TPad::cd(Int_t subpadnumber)
{
if (!subpadnumber) {
gPad = this;
if (!gPad->IsBatch()) gVirtualX->SelectWindow(fPixmapID);
return gPad;
}
TObject *obj;
if (!fPrimitives) fPrimitives = new TList;
TIter next(fPrimitives);
while ((obj = next())) {
if (obj->InheritsFrom(TPad::Class())) {
Int_t n = ((TPad*)obj)->GetNumber();
if (n == subpadnumber) {
return ((TPad*)obj)->cd();
}
}
}
return 0;
}
void TPad::Clear(Option_t *option)
{
if (!IsEditable()) return;
if (!fPadPaint) {
SafeDelete(fView);
if (fPrimitives) fPrimitives->Clear(option);
delete fFrame; fFrame = 0;
}
if (fCanvas) fCanvas->Cleared(this);
cd();
if (TestBit(kClearAfterCR)) getchar();
if (!gPad->IsBatch()) gVirtualX->ClearWindow();
if (gVirtualPS && gPad == gPad->GetCanvas()) gVirtualPS->NewPage();
PaintBorder(GetFillColor(), kTRUE);
fCrosshairPos = 0;
ResetBit(TGraph::kClipFrame);
}
Int_t TPad::Clip(Float_t *x, Float_t *y, Float_t xclipl, Float_t yclipb, Float_t xclipr, Float_t yclipt)
{
const Float_t kP=10000;
Int_t clip = 0;
for (Int_t i=0;i<2;i++) {
if (TMath::Abs(xclipl-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipl;
if (TMath::Abs(xclipr-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipr;
if (TMath::Abs(yclipb-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipb;
if (TMath::Abs(yclipt-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipt;
}
Int_t code1 = ClippingCode(x[0],y[0],xclipl,yclipb,xclipr,yclipt);
Int_t code2 = ClippingCode(x[1],y[1],xclipl,yclipb,xclipr,yclipt);
Double_t xt=0, yt=0;
Int_t clipped = 0;
while(code1 + code2) {
clipped = 1;
if (code1&code2) {
clip = 2;
return clip;
}
Int_t ic = code1;
if (ic == 0) ic = code2;
if (ic & 0x1) {
yt = y[0] + (y[1]-y[0])*(xclipl-x[0])/(x[1]-x[0]);
xt = xclipl;
}
if (ic & 0x2) {
yt = y[0] + (y[1]-y[0])*(xclipr-x[0])/(x[1]-x[0]);
xt = xclipr;
}
if (ic & 0x4) {
xt = x[0] + (x[1]-x[0])*(yclipb-y[0])/(y[1]-y[0]);
yt = yclipb;
}
if (ic & 0x8) {
xt = x[0] + (x[1]-x[0])*(yclipt-y[0])/(y[1]-y[0]);
yt = yclipt;
}
if (ic == code1) {
x[0] = xt;
y[0] = yt;
code1 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
} else {
x[1] = xt;
y[1] = yt;
code2 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
}
}
clip = clipped;
return clip;
}
Int_t TPad::Clip(Double_t *x, Double_t *y, Double_t xclipl, Double_t yclipb, Double_t xclipr, Double_t yclipt)
{
const Double_t kP=10000;
Int_t clip = 0;
for (Int_t i=0;i<2;i++) {
if (TMath::Abs(xclipl-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipl;
if (TMath::Abs(xclipr-x[i]) <= TMath::Abs(xclipr-xclipl)/kP) x[i] = xclipr;
if (TMath::Abs(yclipb-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipb;
if (TMath::Abs(yclipt-y[i]) <= TMath::Abs(yclipt-yclipb)/kP) y[i] = yclipt;
}
Int_t code1 = 0;
if (x[0] < xclipl) code1 = code1 | 0x1;
if (x[0] > xclipr) code1 = code1 | 0x2;
if (y[0] < yclipb) code1 = code1 | 0x4;
if (y[0] > yclipt) code1 = code1 | 0x8;
Int_t code2 = 0;
if (x[1] < xclipl) code2 = code2 | 0x1;
if (x[1] > xclipr) code2 = code2 | 0x2;
if (y[1] < yclipb) code2 = code2 | 0x4;
if (y[1] > yclipt) code2 = code2 | 0x8;
Double_t xt=0, yt=0;
Int_t clipped = 0;
while(code1 + code2) {
clipped = 1;
if (code1&code2) {
clip = 2;
return clip;
}
Int_t ic = code1;
if (ic == 0) ic = code2;
if (ic & 0x1) {
yt = y[0] + (y[1]-y[0])*(xclipl-x[0])/(x[1]-x[0]);
xt = xclipl;
}
if (ic & 0x2) {
yt = y[0] + (y[1]-y[0])*(xclipr-x[0])/(x[1]-x[0]);
xt = xclipr;
}
if (ic & 0x4) {
xt = x[0] + (x[1]-x[0])*(yclipb-y[0])/(y[1]-y[0]);
yt = yclipb;
}
if (ic & 0x8) {
xt = x[0] + (x[1]-x[0])*(yclipt-y[0])/(y[1]-y[0]);
yt = yclipt;
}
if (ic == code1) {
x[0] = xt;
y[0] = yt;
code1 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
} else {
x[1] = xt;
y[1] = yt;
code2 = ClippingCode(xt,yt,xclipl,yclipb,xclipr,yclipt);
}
}
clip = clipped;
return clip;
}
Int_t TPad::ClippingCode(Double_t x, Double_t y, Double_t xcl1, Double_t ycl1, Double_t xcl2, Double_t ycl2)
{
Int_t code = 0;
if (x < xcl1) code = code | 0x1;
if (x > xcl2) code = code | 0x2;
if (y < ycl1) code = code | 0x4;
if (y > ycl2) code = code | 0x8;
return code;
}
Int_t TPad::ClipPolygon(Int_t n, Double_t *x, Double_t *y, Int_t nn, Double_t *xc, Double_t *yc, Double_t xclipl, Double_t yclipb, Double_t xclipr, Double_t yclipt)
{
Int_t nc, nc2;
Double_t x1, y1, x2, y2, slope;
Double_t *xc2 = new Double_t[nn];
Double_t *yc2 = new Double_t[nn];
x1 = x[n-1]; y1 = y[n-1];
nc2 = 0;
Int_t i;
for (i=0; i<n; i++) {
x2 = x[i]; y2 = y[i];
if (x1 == x2) {
slope = 0;
} else {
slope = (y2-y1)/(x2-x1);
}
if (x1 >= xclipl) {
if (x2 < xclipl) {
xc2[nc2] = xclipl; yc2[nc2++] = slope*(xclipl-x1)+y1;
} else {
xc2[nc2] = x2; yc2[nc2++] = y2;
}
} else {
if (x2 >= xclipl) {
xc2[nc2] = xclipl; yc2[nc2++] = slope*(xclipl-x1)+y1;
xc2[nc2] = x2; yc2[nc2++] = y2;
}
}
x1 = x2; y1 = y2;
}
x1 = xc2[nc2-1]; y1 = yc2[nc2-1];
nc = 0;
for (i=0; i<nc2; i++) {
x2 = xc2[i]; y2 = yc2[i];
if (y1 == y2) {
slope = 0;
} else {
slope = (x2-x1)/(y2-y1);
}
if (y1 <= yclipt) {
if (y2 > yclipt) {
xc[nc] = x1+(yclipt-y1)*slope; yc[nc++] = yclipt;
} else {
xc[nc] = x2; yc[nc++] = y2;
}
} else {
if (y2 <= yclipt) {
xc[nc] = x1+(yclipt-y1)*slope; yc[nc++] = yclipt;
xc[nc] = x2; yc[nc++] = y2;
}
}
x1 = x2; y1 = y2;
}
x1 = xc[nc-1]; y1 = yc[nc-1];
nc2 = 0;
for (i=0; i<nc; i++) {
x2 = xc[i]; y2 = yc[i];
if (x1 == x2) {
slope = 0;
} else {
slope = (y2-y1)/(x2-x1);
}
if (x1 <= xclipr) {
if (x2 > xclipr) {
xc2[nc2] = xclipr; yc2[nc2++] = slope*(xclipr-x1)+y1;
} else {
xc2[nc2] = x2; yc2[nc2++] = y2;
}
} else {
if (x2 <= xclipr) {
xc2[nc2] = xclipr; yc2[nc2++] = slope*(xclipr-x1)+y1;
xc2[nc2] = x2; yc2[nc2++] = y2;
}
}
x1 = x2; y1 = y2;
}
x1 = xc2[nc2-1]; y1 = yc2[nc2-1];
nc = 0;
for (i=0; i<nc2; i++) {
x2 = xc2[i]; y2 = yc2[i];
if (y1 == y2) {
slope = 0;
} else {
slope = (x2-x1)/(y2-y1);
}
if (y1 >= yclipb) {
if (y2 < yclipb) {
xc[nc] = x1+(yclipb-y1)*slope; yc[nc++] = yclipb;
} else {
xc[nc] = x2; yc[nc++] = y2;
}
} else {
if (y2 >= yclipb) {
xc[nc] = x1+(yclipb-y1)*slope; yc[nc++] = yclipb;
xc[nc] = x2; yc[nc++] = y2;
}
}
x1 = x2; y1 = y2;
}
delete [] xc2;
delete [] yc2;
if (nc < 3) nc =0;
return nc;
}
void TPad::Close(Option_t *)
{
if (!TestBit(kNotDeleted)) return;
if (!fMother) return;
if (fPrimitives)
fPrimitives->Clear();
if (fView) {
if (fView->TestBit(kNotDeleted)) delete fView;
fView = 0;
}
if (fFrame) {
if (fFrame->TestBit(kNotDeleted)) delete fFrame;
fFrame = 0;
}
if (IsA() != TCanvas::Class())
Closed();
if (fPixmapID != -1) {
if (gPad) {
if (!gPad->IsBatch()) {
gVirtualX->SelectWindow(fPixmapID);
gVirtualX->ClosePixmap();
}
}
fPixmapID = -1;
if (!gROOT->GetListOfCanvases()) return;
if (fMother == this) {
gROOT->GetListOfCanvases()->Remove(this);
return;
}
if (fMother) {
if (fMother->GetListOfPrimitives())
fMother->GetListOfPrimitives()->Remove(this);
if (gPad == this) fMother->cd();
}
if (fCanvas->GetPadSave() == this)
fCanvas->ClearPadSave();
if (fCanvas->GetSelectedPad() == this)
fCanvas->SetSelectedPad(0);
if (fCanvas->GetClickSelectedPad() == this)
fCanvas->SetClickSelectedPad(0);
}
fMother = 0;
if (gROOT->GetSelectedPad() == this) gROOT->SetSelectedPad(0);
}
void TPad::CopyPixmap()
{
int px, py;
XYtoAbsPixel(fX1, fY2, px, py);
if (fPixmapID != -1)
gVirtualX->CopyPixmap(fPixmapID, px, py);
if (this == gPad) HighLight(gPad->GetHighLightColor());
if (fCopyGLDevice) {
Int_t borderSize = fBorderSize > 0 ? fBorderSize : 2;
Int_t realInd = gGLManager->GetVirtualXInd(fGLDevice);
gVirtualX->CopyPixmap(realInd, px + borderSize, py + borderSize);
}
}
void TPad::CopyPixmaps()
{
TObject *obj;
if (!fPrimitives) fPrimitives = new TList;
TIter next(GetListOfPrimitives());
while ((obj = next())) {
if (obj->InheritsFrom(TPad::Class())) {
((TPad*)obj)->CopyPixmap();
((TPad*)obj)->CopyPixmaps();
}
}
}
void TPad::DeleteExec(const char *name)
{
if (!fExecs) fExecs = new TList;
TExec *ex = (TExec*)fExecs->FindObject(name);
if (!ex) return;
fExecs->Remove(ex);
delete ex;
}
Int_t TPad::DistancetoPrimitive(Int_t px, Int_t py)
{
Int_t pxl, pyl, pxt, pyt;
Int_t px1 = gPad->XtoAbsPixel(fX1);
Int_t py1 = gPad->YtoAbsPixel(fY1);
Int_t px2 = gPad->XtoAbsPixel(fX2);
Int_t py2 = gPad->YtoAbsPixel(fY2);
if (px1 < px2) {pxl = px1; pxt = px2;}
else {pxl = px2; pxt = px1;}
if (py1 < py2) {pyl = py1; pyt = py2;}
else {pyl = py2; pyt = py1;}
if ( (px > pxl && px < pxt) && (py > pyl && py < pyt) ) {
if (GetFillStyle()) return 0;
}
Int_t dxl = TMath::Abs(px - pxl);
if (py < pyl) dxl += pyl - py; if (py > pyt) dxl += py - pyt;
Int_t dxt = TMath::Abs(px - pxt);
if (py < pyl) dxt += pyl - py; if (py > pyt) dxt += py - pyt;
Int_t dyl = TMath::Abs(py - pyl);
if (px < pxl) dyl += pxl - px; if (px > pxt) dyl += px - pxt;
Int_t dyt = TMath::Abs(py - pyt);
if (px < pxl) dyt += pxl - px; if (px > pxt) dyt += px - pxt;
Int_t distance = dxl;
if (dxt < distance) distance = dxt;
if (dyl < distance) distance = dyl;
if (dyt < distance) distance = dyt;
return distance - Int_t(0.5*fLineWidth);
}
void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color)
{
if (!IsEditable()) return;
if (gThreadXAR) {
void *arr[7];
arr[1] = this; arr[2] = (void*)&nx;arr[3] = (void*)& ny;
arr[4] = (void*)&xmargin; arr[5] = (void *)& ymargin; arr[6] = (void *)&color;
if ((*gThreadXAR)("PDCD", 7, arr, 0)) return;
}
TPad *padsav = (TPad*)gPad;
cd();
if (nx <= 0) nx = 1;
if (ny <= 0) ny = 1;
Int_t ix,iy;
Double_t x1,y1,x2,y2;
Double_t dx,dy;
TPad *pad;
char *name = new char [strlen(GetName())+6];
char *title = new char [strlen(GetTitle())+6];
Int_t n = 0;
if (color == 0) color = GetFillColor();
if (xmargin > 0 && ymargin > 0) {
dy = 1/Double_t(ny);
dx = 1/Double_t(nx);
for (iy=0;iy<ny;iy++) {
y2 = 1 - iy*dy - ymargin;
y1 = y2 - dy + 2*ymargin;
if (y1 < 0) y1 = 0;
if (y1 > y2) continue;
for (ix=0;ix<nx;ix++) {
x1 = ix*dx + xmargin;
x2 = x1 +dx -2*xmargin;
if (x1 > x2) continue;
n++;
sprintf(name,"%s_%d",GetName(),n);
pad = new TPad(name,name,x1,y1,x2,y2,color);
pad->SetNumber(n);
pad->Draw();
}
}
} else {
Double_t xl = GetLeftMargin();
Double_t xr = GetRightMargin();
Double_t yb = GetBottomMargin();
Double_t yt = GetTopMargin();
xl /= (1-xl+xr)*nx;
xr /= (1-xl+xr)*nx;
yb /= (1-xl+xr)*ny;
yt /= (1-xl+xr)*ny;
SetLeftMargin(xl);
SetRightMargin(xr);
SetBottomMargin(yb);
SetTopMargin(yt);
dx = (1-xl-xr)/nx;
dy = (1-yb-yt)/ny;
Int_t number = 0;
for (Int_t i=0;i<nx;i++) {
x1 = i*dx+xl;
x2 = x1 + dx;
if (i == 0) x1 = 0;
if (i == nx-1) x2 = 1-xr;
for (Int_t j=0;j<ny;j++) {
number = j*nx + i +1;
y2 = 1 -j*dy -yt;
y1 = y2 - dy;
if (j == 0) y2 = 1-yt;
if (j == ny-1) y1 = 0;
sprintf(name,"%s_%d",GetName(),number);
sprintf(title,"%s_%d",GetTitle(),number);
pad = new TPad(name,title,x1,y1,x2,y2);
pad->SetNumber(number);
pad->SetBorderMode(0);
if (i == 0) pad->SetLeftMargin(xl*nx);
else pad->SetLeftMargin(0);
pad->SetRightMargin(0);
pad->SetTopMargin(0);
if (j == ny-1) pad->SetBottomMargin(yb*ny);
else pad->SetBottomMargin(0);
pad->Draw();
}
}
}
delete [] name;
delete [] title;
Modified();
if (padsav) padsav->cd();
}
void TPad::Draw(Option_t *option)
{
if (!gPad) {
gROOT->MakeDefCanvas();
}
if (!fPrimitives) fPrimitives = new TList;
if (gPad != this) {
if (fMother) fMother->GetListOfPrimitives()->Remove(this);
TPad *oldMother = fMother;
fCanvas = gPad->GetCanvas();
fMother = (TPad*)gPad;
if (oldMother != fMother || fPixmapID == -1) ResizePad();
}
Paint();
if (gPad->IsRetained() && gPad != this && fMother)
fMother->GetListOfPrimitives()->Add(this, option);
}
void TPad::DrawClassObject(const TObject *classobj, Option_t *option)
{
/*
<img src="gif/drawclass.gif">
*/
//End_Html
char dname[256];
const Int_t kMAXLEVELS = 10;
TClass *clevel[kMAXLEVELS], *cl, *cll;
TBaseClass *base, *cinherit;
TText *ptext = 0;
TString opt=option;
Double_t x,y,dy,y1,v1,v2,dv;
Int_t nd,nf,nc,nkd,nkf,i,j;
TPaveText *pt;
Int_t maxlev = 4;
if (opt.Contains("2")) maxlev = 2;
if (opt.Contains("3")) maxlev = 3;
if (opt.Contains("5")) maxlev = 5;
if (opt.Contains("6")) maxlev = 6;
if (opt.Contains("7")) maxlev = 7;
Double_t xpad = 20.5;
Double_t ypad = 27.5;
Clear();
Range(0,0,xpad,ypad);
Int_t nlevel = 0;
TClass *obj = (TClass*)classobj;
clevel[nlevel] = obj;
TList *lbase = obj->GetListOfBases();
while(lbase) {
base = (TBaseClass*)lbase->First();
if (!base) break;
if ( base->GetClassPointer() == 0) break;
nlevel++;
clevel[nlevel] = base->GetClassPointer();
lbase = clevel[nlevel]->GetListOfBases();
if (nlevel >= maxlev-1) break;
}
Int_t maxelem = 0;
Int_t ncdraw = 0;
Int_t ilevel, nelem;
for (ilevel=nlevel;ilevel>=0;ilevel--) {
cl = clevel[ilevel];
nelem = cl->GetNdata() + cl->GetNmethods();
if (nelem > maxelem) maxelem = nelem;
nc = (nelem/50) + 1;
ncdraw += nc;
}
Double_t tsizcm = 0.40;
Double_t x1 = 0.25;
Double_t x2 = 0;
Double_t dx = 3.5;
if (ncdraw > 4) {
dx = dx - 0.42*Double_t(ncdraw-5);
if (dx < 1.3) dx = 1.3;
tsizcm = tsizcm - 0.03*Double_t(ncdraw-5);
if (tsizcm < 0.27) tsizcm = 0.27;
}
Double_t tsiz = 1.2*tsizcm/ypad;
for (ilevel=nlevel;ilevel>=0;ilevel--) {
cl = clevel[ilevel];
nelem = cl->GetNdata() + cl->GetNmethods();
if (nelem > maxelem) maxelem = nelem;
nc = (nelem/50) + 1;
dy = 0.45;
if (ilevel < nlevel) x1 = x2 + 0.5;
x2 = x1 + nc*dx;
v2 = ypad - 0.5;
lbase = cl->GetListOfBases();
cinherit = 0;
if (lbase) cinherit = (TBaseClass*)lbase->First();
do {
nd = cl->GetNdata();
nf = cl->GetNmethods() - 2;
if (cl->GetListOfMethods()->FindObject("Dictionary")) {
nf -= 6;
}
nkf= nf/nc +1;
nkd= nd/nc +1;
if (nd == 0) nkd=0;
if (nf == 0) nkf=0;
y1 = v2 - 0.7;
v1 = y1 - Double_t(nkf+nkd+nc-1)*dy;
dv = v2 - v1;
pt = new TPaveText(x1,v1,x2,v2);
pt->SetBit(kCanDelete);
pt->SetFillColor(19);
pt->Draw();
pt->SetTextColor(4);
pt->SetTextFont(61);
pt->SetTextAlign(12);
pt->SetTextSize(tsiz);
TBox *box = pt->AddBox(0,(y1+0.01-v1)/dv,0,(v2-0.01-v1)/dv);
box->SetFillColor(17);
pt->AddLine(0,(y1-v1)/dv,0,(y1-v1)/dv);
TText *title = pt->AddText(0.5,(0.5*(y1+v2)-v1)/dv,(char*)cl->GetName());
title->SetTextAlign(22);
title->SetTextSize(0.6*(v2-y1)/ypad);
i = 0;
x = 0.03;
y = y1 + 0.5*dy;
TDataMember *d;
TIter nextd(cl->GetListOfDataMembers());
while ((d = (TDataMember *) nextd())) {
if (i >= nkd) { i = 1; y = y1 - 0.5*dy; x += 1/Double_t(nc); }
else { i++; y -= dy; }
Int_t dim = d->GetArrayDim();
Int_t indx = 0;
sprintf(dname,"%s",obj->EscapeChars(d->GetName()));
Int_t ldname = 0;
while (indx < dim ){
ldname = strlen(dname);
sprintf(&dname[ldname],"[%d]",d->GetMaxIndex(indx));
indx++;
}
ptext = pt->AddText(x,(y-v1)/dv,dname);
}
Double_t ysep;
if (nd) {
ysep = y1 - Double_t(nkd)*dy;
pt->AddLine(0,(ysep-v1)/dv,0,(ysep-v1)/dv);
ysep -= 0.5*dy;
} else ysep = y1;
Int_t fcount = 0;
i = 0;
x = 0.03;
y = ysep + 0.5*dy;
TMethod *m;
TIter nextm(cl->GetListOfMethods());
while ((m = (TMethod *) nextm())) {
if (
!strcmp( m->GetName(), "Dictionary" ) ||
!strcmp( m->GetName(), "Class_Version" ) ||
!strcmp( m->GetName(), "DeclFileName" ) ||
!strcmp( m->GetName(), "DeclFileLine" ) ||
!strcmp( m->GetName(), "ImplFileName" ) ||
!strcmp( m->GetName(), "ImplFileLine" )
) continue;
fcount++;
if (fcount > nf) break;
if (i >= nkf) { i = 1; y = ysep - 0.5*dy; x += 1/Double_t(nc); }
else { i++; y -= dy; }
ptext = pt->AddText(x,(y-v1)/dv,obj->EscapeChars(m->GetName()));
for (j=ilevel-1;j>=0;j--) {
if (cl == clevel[ilevel]) {
if (clevel[j]->GetMethodAny((char*)m->GetName())) {
ptext->SetTextColor(15);
break;
}
}
}
}
cll = 0;
if (cinherit) {
cinherit = (TBaseClass*)lbase->After(cinherit);
if (cinherit) {
cl = cinherit->GetClassPointer();
cll = cl;
v2 = v1 -0.4;
dy = 0.35;
}
}
} while (cll);
}
Update();
}
void TPad::DrawCrosshair()
{
if (gPad->GetEvent() == kMouseEnter) return;
TPad *cpad = (TPad*)gPad;
TCanvas *canvas = cpad->GetCanvas();
canvas->FeedbackMode(kTRUE);
Int_t pxmin,pxmax,pymin,pymax,pxold,pyold,px,py;
pxold = fCrosshairPos%10000;
pyold = fCrosshairPos/10000;
px = cpad->GetEventX();
py = cpad->GetEventY()+1;
if (canvas->GetCrosshair() > 1) {
pxmin = cpad->XtoAbsPixel(fX1);
pxmax = cpad->XtoAbsPixel(fX2);
pymin = cpad->YtoAbsPixel(fY1);
pymax = cpad->YtoAbsPixel(fY2);
} else {
pxmin = 0;
pxmax = canvas->GetWw();
pymin = 0;
pymax = cpad->GetWh();
}
if(pxold) gVirtualX->DrawLine(pxold,pymin,pxold,pymax);
if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold);
if (cpad->GetEvent() == kButton1Down ||
cpad->GetEvent() == kButton1Up ||
cpad->GetEvent() == kMouseLeave) {
fCrosshairPos = 0;
return;
}
gVirtualX->DrawLine(px,pymin,px,pymax);
gVirtualX->DrawLine(pxmin,py,pxmax,py);
fCrosshairPos = px + 10000*py;
}
TH1F *TPad::DrawFrame(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax, const char *title)
{
if (!IsEditable()) return 0;
TPad *padsav = (TPad*)gPad;
if (this != padsav) {
Warning("DrawFrame","Drawframe must be called for the current pad only");
return padsav->DrawFrame(xmin,ymin,xmax,ymax,title);
}
cd();
TH1F *hframe = (TH1F*)FindObject("hframe");
if (hframe) delete hframe;
Int_t nbins = 1000;
if (fLogx && xmin > 0 && xmax > xmin) {
Double_t xminl = TMath::Log(xmin);
Double_t xmaxl = TMath::Log(xmax);
Double_t dx = (xmaxl-xminl)/nbins;
Double_t *xbins = new Double_t[nbins+1];
xbins[0] = xmin;
for (Int_t i=1;i<=nbins;i++) {
xbins[i] = TMath::Exp(xminl+i*dx);
}
hframe = new TH1F("hframe",title,nbins,xbins);
delete [] xbins;
} else {
hframe = new TH1F("hframe",title,nbins,xmin,xmax);
}
hframe->SetBit(TH1::kNoStats);
hframe->SetBit(kCanDelete);
hframe->SetMinimum(ymin);
hframe->SetMaximum(ymax);
hframe->GetYaxis()->SetLimits(ymin,ymax);
hframe->SetDirectory(0);
hframe->Draw(" ");
Update();
if (padsav) padsav->cd();
return hframe;
}
void TPad::DrawColorTable()
{
Int_t i, j;
Int_t color;
Double_t xlow, ylow, xup, yup, hs, ws;
Double_t x1, y1, x2, y2;
x1 = y1 = 0;
x2 = y2 = 20;
gPad->SetFillColor(0);
gPad->Clear();
gPad->Range(x1,y1,x2,y2);
TText *text = new TText(0,0,"");
text->SetTextFont(61);
text->SetTextSize(0.07);
text->SetTextAlign(22);
TBox *box = new TBox();
hs = (y2-y1)/Double_t(5);
ws = (x2-x1)/Double_t(10);
for (i=0;i<10;i++) {
xlow = x1 + ws*(Double_t(i)+0.1);
xup = x1 + ws*(Double_t(i)+0.9);
for (j=0;j<5;j++) {
ylow = y1 + hs*(Double_t(j)+0.1);
yup = y1 + hs*(Double_t(j)+0.9);
color = 10*j + i;
box->SetFillStyle(1001);
box->SetFillColor(color);
box->DrawBox(xlow, ylow, xup, yup);
box->SetFillStyle(0);
box->SetLineColor(1);
box->DrawBox(xlow, ylow, xup, yup);
if (color == 1) text->SetTextColor(0);
else text->SetTextColor(1);
text->DrawText(0.5*(xlow+xup), 0.5*(ylow+yup), Form("%d",color));
}
}
}
void TPad::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
static Double_t xmin;
static Double_t xmax;
static Double_t ymin;
static Double_t ymax;
const Int_t kMaxDiff = 5;
const Int_t kMinSize = 20;
static Int_t pxorg, pyorg;
static Int_t px1, px2, py1, py2, pxl, pyl, pxt, pyt, pxold, pyold;
static Int_t px1p, px2p, py1p, py2p, pxlp, pylp, pxtp, pytp;
static Bool_t pA, pB, pC, pD, pTop, pL, pR, pBot, pINSIDE;
Int_t wx, wy;
Bool_t opaque = OpaqueMoving();
Bool_t ropaque = OpaqueResizing();
Bool_t fixedr = HasFixedAspectRatio();
if (!IsEditable() && event != kMouseEnter) return;
TVirtualPad *parent = GetMother();
if (!parent->IsEditable()) return;
HideToolTip(event);
if (fXlowNDC < 0 && event != kButton1Down) return;
if (fYlowNDC < 0 && event != kButton1Down) return;
if (event == kButton1Down) {
xmin = fX1;
xmax = fX2;
ymin = fY1;
ymax = fY2;
pxorg = px;
pyorg = py;
}
Int_t newcode = gROOT->GetEditorMode();
if (newcode)
pA = pB = pC = pD = pTop = pL = pR = pBot = pINSIDE = kFALSE;
switch (newcode) {
case kPad:
TCreatePrimitives::Pad(event,px,py,0);
break;
case kMarker:
case kText:
TCreatePrimitives::Text(event,px,py,newcode);
break;
case kLine:
TCreatePrimitives::Line(event,px,py,kLine);
break;
case kArrow:
TCreatePrimitives::Line(event,px,py,kArrow);
break;
case kCurlyLine:
TCreatePrimitives::Line(event,px,py,kCurlyLine);
break;
case kCurlyArc:
TCreatePrimitives::Line(event,px,py,kCurlyArc);
break;
case kPolyLine:
TCreatePrimitives::PolyLine(event,px,py,kPolyLine);
break;
case kCutG:
TCreatePrimitives::PolyLine(event,px,py,kCutG);
break;
case kArc:
TCreatePrimitives::Ellipse(event,px,py,kArc);
break;
case kEllipse:
TCreatePrimitives::Ellipse(event,px,py,kEllipse);
break;
case kButton:
case kPave:
case kPaveLabel:
case kPaveText:
case kPavesText:
case kDiamond:
TCreatePrimitives::Pave(event,px,py,newcode);
return;
default:
break;
}
if (newcode) return;
Bool_t doing_again = kFALSE;
again:
switch (event) {
case kMouseEnter:
if (fTip)
ResetToolTip(fTip);
break;
case kButton1Down:
#ifdef WIN32
Pop();
#endif
gVirtualX->SetLineColor(-1);
TAttLine::Modify();
if (GetFillColor())
gVirtualX->SetLineColor(GetFillColor());
else
gVirtualX->SetLineColor(1);
gVirtualX->SetLineWidth(2);
case kMouseMotion:
px1 = XtoAbsPixel(fX1);
py1 = YtoAbsPixel(fY1);
px2 = XtoAbsPixel(fX2);
py2 = YtoAbsPixel(fY2);
if (px1 < px2) {
pxl = px1;
pxt = px2;
} else {
pxl = px2;
pxt = px1;
}
if (py1 < py2) {
pyl = py1;
pyt = py2;
} else {
pyl = py2;
pyt = py1;
}
px1p = parent->XtoAbsPixel(parent->GetX1()) + parent->GetBorderSize();
py1p = parent->YtoAbsPixel(parent->GetY1()) - parent->GetBorderSize();
px2p = parent->XtoAbsPixel(parent->GetX2()) - parent->GetBorderSize();
py2p = parent->YtoAbsPixel(parent->GetY2()) + parent->GetBorderSize();
if (px1p < px2p) {
pxlp = px1p;
pxtp = px2p;
} else {
pxlp = px2p;
pxtp = px1p;
}
if (py1p < py2p) {
pylp = py1p;
pytp = py2p;
} else {
pylp = py2p;
pytp = py1p;
}
pA = pB = pC = pD = pTop = pL = pR = pBot = pINSIDE = kFALSE;
if (TMath::Abs(px - pxl) <= kMaxDiff && TMath::Abs(py - pyl) <= kMaxDiff) {
pxold = pxl; pyold = pyl; pA = kTRUE;
SetCursor(kTopLeft);
}
if (TMath::Abs(px - pxt) <= kMaxDiff && TMath::Abs(py - pyl) <= kMaxDiff) {
pxold = pxt; pyold = pyl; pB = kTRUE;
SetCursor(kTopRight);
}
if (TMath::Abs(px - pxt) <= kMaxDiff && TMath::Abs(py - pyt) <= kMaxDiff) {
pxold = pxt; pyold = pyt; pC = kTRUE;
SetCursor(kBottomRight);
}
if (TMath::Abs(px - pxl) <= kMaxDiff && TMath::Abs(py - pyt) <= kMaxDiff) {
pxold = pxl; pyold = pyt; pD = kTRUE;
SetCursor(kBottomLeft);
}
if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
TMath::Abs(py - pyl) < kMaxDiff) {
pxold = pxl; pyold = pyl; pTop = kTRUE;
SetCursor(kTopSide);
}
if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
TMath::Abs(py - pyt) < kMaxDiff) {
pxold = pxt; pyold = pyt; pBot = kTRUE;
SetCursor(kBottomSide);
}
if ((py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
TMath::Abs(px - pxl) < kMaxDiff) {
pxold = pxl; pyold = pyl; pL = kTRUE;
SetCursor(kLeftSide);
}
if ((py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
TMath::Abs(px - pxt) < kMaxDiff) {
pxold = pxt; pyold = pyt; pR = kTRUE;
SetCursor(kRightSide);
}
if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
(py > pyl+kMaxDiff && py < pyt-kMaxDiff)) {
pxold = px; pyold = py; pINSIDE = kTRUE;
if (event == kButton1Down)
SetCursor(kMove);
else
SetCursor(kCross);
}
fResizing = kFALSE;
if (pA || pB || pC || pD || pTop || pL || pR || pBot)
fResizing = kTRUE;
if (!pA && !pB && !pC && !pD && !pTop && !pL && !pR && !pBot && !pINSIDE)
SetCursor(kCross);
break;
case kButton1Motion:
if (TestBit(kCannotMove)) break;
wx = wy = 0;
if (pA) {
if (!ropaque) gVirtualX->DrawBox(pxold, pyt, pxt, pyold, TVirtualX::kHollow);
if (px > pxt-kMinSize) { px = pxt-kMinSize; wx = px; }
if (py > pyt-kMinSize) { py = pyt-kMinSize; wy = py; }
if (px < pxlp) { px = pxlp; wx = px; }
if (py < pylp) { py = pylp; wy = py; }
if (fixedr) {
Double_t dy = Double_t(TMath::Abs(pxt-px))/parent->UtoPixel(1.) /
fAspectRatio;
Int_t npy2 = pyt - TMath::Abs(parent->VtoAbsPixel(dy) -
parent->VtoAbsPixel(0));
if (npy2 < pylp) {
px = pxold;
py = pyold;
} else
py = npy2;
wx = wy = 0;
}
if (!ropaque) gVirtualX->DrawBox(px , pyt, pxt, py, TVirtualX::kHollow);
}
if (pB) {
if (!ropaque) gVirtualX->DrawBox(pxl , pyt, pxold, pyold, TVirtualX::kHollow);
if (px < pxl+kMinSize) { px = pxl+kMinSize; wx = px; }
if (py > pyt-kMinSize) { py = pyt-kMinSize; wy = py; }
if (px > pxtp) { px = pxtp; wx = px; }
if (py < pylp) { py = pylp; wy = py; }
if (fixedr) {
Double_t dy = Double_t(TMath::Abs(pxl-px))/parent->UtoPixel(1.) /
fAspectRatio;
Int_t npy2 = pyt - TMath::Abs(parent->VtoAbsPixel(dy) -
parent->VtoAbsPixel(0));
if (npy2 < pylp) {
px = pxold;
py = pyold;
} else
py = npy2;
wx = wy = 0;
}
if (!ropaque) gVirtualX->DrawBox(pxl , pyt, px , py, TVirtualX::kHollow);
}
if (pC) {
if (!ropaque) gVirtualX->DrawBox(pxl , pyl, pxold, pyold, TVirtualX::kHollow);
if (px < pxl+kMinSize) { px = pxl+kMinSize; wx = px; }
if (py < pyl+kMinSize) { py = pyl+kMinSize; wy = py; }
if (px > pxtp) { px = pxtp; wx = px; }
if (py > pytp) { py = pytp; wy = py; }
if (fixedr) {
Double_t dy = Double_t(TMath::Abs(pxl-px))/parent->UtoPixel(1.) /
fAspectRatio;
Int_t npy2 = pyl + TMath::Abs(parent->VtoAbsPixel(dy) -
parent->VtoAbsPixel(0));
if (npy2 > pytp) {
px = pxold;
py = pyold;
} else
py = npy2;
wx = wy = 0;
}
if (!ropaque) gVirtualX->DrawBox(pxl , pyl, px , py, TVirtualX::kHollow);
}
if (pD) {
if (!ropaque) gVirtualX->DrawBox(pxold, pyold, pxt, pyl, TVirtualX::kHollow);
if (px > pxt-kMinSize) { px = pxt-kMinSize; wx = px; }
if (py < pyl+kMinSize) { py = pyl+kMinSize; wy = py; }
if (px < pxlp) { px = pxlp; wx = px; }
if (py > pytp) { py = pytp; wy = py; }
if (fixedr) {
Double_t dy = Double_t(TMath::Abs(pxt-px))/parent->UtoPixel(1.) /
fAspectRatio;
Int_t npy2 = pyl + TMath::Abs(parent->VtoAbsPixel(dy) -
parent->VtoAbsPixel(0));
if (npy2 > pytp) {
px = pxold;
py = pyold;
} else
py = npy2;
wx = wy = 0;
}
if (!ropaque) gVirtualX->DrawBox(px , py , pxt, pyl, TVirtualX::kHollow);
}
if (pTop) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
py2 += py - pyold;
if (py2 > py1-kMinSize) { py2 = py1-kMinSize; wy = py2; }
if (py2 < py2p) { py2 = py2p; wy = py2; }
if (fixedr) {
Double_t dx = Double_t(TMath::Abs(py2-py1))/parent->VtoPixel(0) *
fAspectRatio;
Int_t npx2 = px1 + parent->UtoPixel(dx);
if (npx2 > px2p)
py2 -= py - pyold;
else
px2 = npx2;
}
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pBot) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
py1 += py - pyold;
if (py1 < py2+kMinSize) { py1 = py2+kMinSize; wy = py1; }
if (py1 > py1p) { py1 = py1p; wy = py1; }
if (fixedr) {
Double_t dx = Double_t(TMath::Abs(py2-py1))/parent->VtoPixel(0) *
fAspectRatio;
Int_t npx2 = px1 + parent->UtoPixel(dx);
if (npx2 > px2p)
py1 -= py - pyold;
else
px2 = npx2;
}
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pL) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
px1 += px - pxold;
if (px1 > px2-kMinSize) { px1 = px2-kMinSize; wx = px1; }
if (px1 < px1p) { px1 = px1p; wx = px1; }
if (fixedr) {
Double_t dy = Double_t(TMath::Abs(px2-px1))/parent->UtoPixel(1.) /
fAspectRatio;
Int_t npy2 = py1 - TMath::Abs(parent->VtoAbsPixel(dy) -
parent->VtoAbsPixel(0));
if (npy2 < py2p)
px1 -= px - pxold;
else
py2 = npy2;
}
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pR) {
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
px2 += px - pxold;
if (px2 < px1+kMinSize) { px2 = px1+kMinSize; wx = px2; }
if (px2 > px2p) { px2 = px2p; wx = px2; }
if (fixedr) {
Double_t dy = Double_t(TMath::Abs(px2-px1))/parent->UtoPixel(1.) /
fAspectRatio;
Int_t npy2 = py1 - TMath::Abs(parent->VtoAbsPixel(dy) -
parent->VtoAbsPixel(0));
if (npy2 < py2p)
px2 -= px - pxold;
else
py2 = npy2;
}
if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (pINSIDE) {
if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
Int_t dx = px - pxold;
Int_t dy = py - pyold;
px1 += dx; py1 += dy; px2 += dx; py2 += dy;
if (px1 < px1p) { dx = px1p - px1; px1 += dx; px2 += dx; wx = px+dx; }
if (px2 > px2p) { dx = px2 - px2p; px1 -= dx; px2 -= dx; wx = px-dx; }
if (py1 > py1p) { dy = py1 - py1p; py1 -= dy; py2 -= dy; wy = py-dy; }
if (py2 < py2p) { dy = py2p - py2; py1 += dy; py2 += dy; wy = py+dy; }
if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
}
if (wx || wy) {
if (wx) px = wx;
if (wy) py = wy;
gVirtualX->Warp(px, py);
}
pxold = px;
pyold = py;
if ((!fResizing && opaque) || (fResizing && ropaque)) {
event = kButton1Up;
doing_again = kTRUE;
goto again;
}
break;
case kButton1Up:
if (gROOT->IsEscaped()) {
gROOT->SetEscape(kFALSE);
break;
}
if (pA) {
fX1 = AbsPixeltoX(pxold);
fY1 = AbsPixeltoY(pyt);
fX2 = AbsPixeltoX(pxt);
fY2 = AbsPixeltoY(pyold);
}
if (pB) {
fX1 = AbsPixeltoX(pxl);
fY1 = AbsPixeltoY(pyt);
fX2 = AbsPixeltoX(pxold);
fY2 = AbsPixeltoY(pyold);
}
if (pC) {
fX1 = AbsPixeltoX(pxl);
fY1 = AbsPixeltoY(pyold);
fX2 = AbsPixeltoX(pxold);
fY2 = AbsPixeltoY(pyl);
}
if (pD) {
fX1 = AbsPixeltoX(pxold);
fY1 = AbsPixeltoY(pyold);
fX2 = AbsPixeltoX(pxt);
fY2 = AbsPixeltoY(pyl);
}
if (pTop || pBot || pL || pR || pINSIDE) {
fX1 = AbsPixeltoX(px1);
fY1 = AbsPixeltoY(py1);
fX2 = AbsPixeltoX(px2);
fY2 = AbsPixeltoY(py2);
}
if (pINSIDE)
if (!doing_again) gPad->SetCursor(kCross);
if (pA || pB || pC || pD || pTop || pL || pR || pBot)
Modified(kTRUE);
gVirtualX->SetLineColor(-1);
gVirtualX->SetLineWidth(-1);
if (px != pxorg || py != pyorg) {
Int_t parentpx1 = fMother->XtoAbsPixel(parent->GetX1());
Int_t parentpx2 = fMother->XtoAbsPixel(parent->GetX2());
Int_t parentpy1 = fMother->YtoAbsPixel(parent->GetY1());
Int_t parentpy2 = fMother->YtoAbsPixel(parent->GetY2());
Int_t apx1 = XtoAbsPixel(fX1); if (apx1 < parentpx1) {apx1 = parentpx1; }
Int_t apx2 = XtoAbsPixel(fX2); if (apx2 > parentpx2) {apx2 = parentpx2; }
Int_t apy1 = YtoAbsPixel(fY1); if (apy1 > parentpy1) {apy1 = parentpy1; }
Int_t apy2 = YtoAbsPixel(fY2); if (apy2 < parentpy2) {apy2 = parentpy2; }
fXlowNDC = Double_t(apx1 - parentpx1)/Double_t(parentpx2 - parentpx1);
fYlowNDC = Double_t(apy1 - parentpy1)/Double_t(parentpy2 - parentpy1);
fWNDC = Double_t(apx2 - apx1)/Double_t(parentpx2 - parentpx1);
fHNDC = Double_t(apy2 - apy1)/Double_t(parentpy2 - parentpy1);
}
fX1 = xmin;
fX2 = xmax;
fY1 = ymin;
fY2 = ymax;
ResizePad();
RangeChanged();
break;
case kButton1Locate:
ExecuteEvent(kButton1Down, px, py);
while (1) {
px = py = 0;
event = gVirtualX->RequestLocator(1, 1, px, py);
ExecuteEvent(kButton1Motion, px, py);
if (event != -1) {
ExecuteEvent(kButton1Up, px, py);
return;
}
}
case kButton2Down:
Pop();
break;
}
}
void TPad::ExecuteEventAxis(Int_t event, Int_t px, Int_t py, TAxis *axis)
{
if (!IsEditable()) return;
SetCursor(kHand);
TView *view = GetView();
static Int_t axisNumber;
static Double_t ratio1, ratio2;
static Int_t px1old, py1old, px2old, py2old;
Int_t bin1, bin2, first, last;
Double_t temp, xmin,xmax;
TString opt = axis->GetParent()->GetDrawOption();
opt.ToLower();
Bool_t kCont4 = kFALSE;
if (strstr(opt,"cont4")) {
view = 0;
kCont4 = kTRUE;
}
switch (event) {
case kButton1Down:
axisNumber = 1;
if (!strcmp(axis->GetName(),"xaxis")) {
axisNumber = 1;
if (!IsVertical()) axisNumber = 2;
}
if (!strcmp(axis->GetName(),"yaxis")) {
axisNumber = 2;
if (!IsVertical()) axisNumber = 1;
}
if (!strcmp(axis->GetName(),"zaxis")) {
axisNumber = 3;
}
if (view) {
view->GetDistancetoAxis(axisNumber, px, py, ratio1);
} else {
if (axisNumber == 1) {
ratio1 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
px1old = XtoAbsPixel(GetUxmin()+ratio1*(GetUxmax() - GetUxmin()));
py1old = YtoAbsPixel(GetUymin());
px2old = px1old;
py2old = YtoAbsPixel(GetUymax());
} else if (axisNumber == 2) {
ratio1 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
py1old = YtoAbsPixel(GetUymin()+ratio1*(GetUymax() - GetUymin()));
px1old = XtoAbsPixel(GetUxmin());
px2old = XtoAbsPixel(GetUxmax());
py2old = py1old;
} else {
ratio1 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
py1old = YtoAbsPixel(GetUymin()+ratio1*(GetUymax() - GetUymin()));
px1old = XtoAbsPixel(GetUxmax());
px2old = XtoAbsPixel(GetX2());
py2old = py1old;
}
gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow);
}
gVirtualX->SetLineColor(-1);
case kButton1Motion:
if (view) {
view->GetDistancetoAxis(axisNumber, px, py, ratio2);
} else {
gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow);
if (axisNumber == 1) {
ratio2 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
px2old = XtoAbsPixel(GetUxmin()+ratio2*(GetUxmax() - GetUxmin()));
} else {
ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
py2old = YtoAbsPixel(GetUymin()+ratio2*(GetUymax() - GetUymin()));
}
gVirtualX->DrawBox(px1old, py1old, px2old, py2old, TVirtualX::kHollow);
}
break;
case kButton1Up:
if (gROOT->IsEscaped()) {
gROOT->SetEscape(kFALSE);
break;
}
if (view) {
view->GetDistancetoAxis(axisNumber, px, py, ratio2);
if (ratio1 > ratio2) {
temp = ratio1;
ratio1 = ratio2;
ratio2 = temp;
}
if (ratio2 - ratio1 > 0.05) {
TH1 *hobj = (TH1*)axis->GetParent();
if (axisNumber == 3 && hobj && hobj->GetDimension() != 3) {
Float_t zmin = hobj->GetMinimum();
Float_t zmax = hobj->GetMaximum();
if(GetLogz()){
if (zmin <= 0 && zmax > 0) zmin = TMath::Min((Double_t)1,
(Double_t)0.001*zmax);
zmin = TMath::Log10(zmin);
zmax = TMath::Log10(zmax);
}
Float_t newmin = zmin + (zmax-zmin)*ratio1;
Float_t newmax = zmin + (zmax-zmin)*ratio2;
if(newmin < zmin)newmin = hobj->GetBinContent(hobj->GetMinimumBin());
if(newmax > zmax)newmax = hobj->GetBinContent(hobj->GetMaximumBin());
if(GetLogz()){
newmin = TMath::Exp(2.302585092994*newmin);
newmax = TMath::Exp(2.302585092994*newmax);
}
hobj->SetMinimum(newmin);
hobj->SetMaximum(newmax);
hobj->SetBit(TH1::kIsZoomed);
} else {
first = axis->GetFirst();
last = axis->GetLast();
bin1 = first + Int_t((last-first+1)*ratio1);
bin2 = first + Int_t((last-first+1)*ratio2);
axis->SetRange(bin1, bin2);
}
delete view;
SetView(0);
Modified(kTRUE);
}
} else {
if (axisNumber == 1) {
ratio2 = (AbsPixeltoX(px) - GetUxmin())/(GetUxmax() - GetUxmin());
xmin = GetUxmin() +ratio1*(GetUxmax() - GetUxmin());
xmax = GetUxmin() +ratio2*(GetUxmax() - GetUxmin());
if (GetLogx() && !kCont4) {
xmin = PadtoX(xmin);
xmax = PadtoX(xmax);
}
} else if (axisNumber == 2) {
ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
xmin = GetUymin() +ratio1*(GetUymax() - GetUymin());
xmax = GetUymin() +ratio2*(GetUymax() - GetUymin());
if (GetLogy() && !kCont4) {
xmin = PadtoY(xmin);
xmax = PadtoY(xmax);
}
} else {
ratio2 = (AbsPixeltoY(py) - GetUymin())/(GetUymax() - GetUymin());
xmin = ratio1;
xmax = ratio2;
}
if (xmin > xmax) {
temp = xmin;
xmin = xmax;
xmax = temp;
temp = ratio1;
ratio1 = ratio2;
ratio2 = temp;
}
if (kCont4) {
Double_t low = axis->GetBinLowEdge(axis->GetFirst());
Double_t up = axis->GetBinUpEdge(axis->GetLast());
Double_t xmi = GetUxmin();
Double_t xma = GetUxmax();
xmin = ((xmin-xmi)/(xma-xmi))*(up-low)+low;
xmax = ((xmax-xmi)/(xma-xmi))*(up-low)+low;
}
if (!strcmp(axis->GetName(),"xaxis")) axisNumber = 1;
if (!strcmp(axis->GetName(),"yaxis")) axisNumber = 2;
if (ratio2 - ratio1 > 0.05) {
TH1 *hobj = (TH1*)axis->GetParent();
bin1 = axis->FindFixBin(xmin);
bin2 = axis->FindFixBin(xmax);
if (axisNumber == 1) axis->SetRange(bin1,bin2);
if (axisNumber == 2 && hobj) {
if (hobj->GetDimension() == 1) {
if (hobj->GetNormFactor() != 0) {
Double_t norm = hobj->GetSumOfWeights()/hobj->GetNormFactor();
xmin *= norm;
xmax *= norm;
}
hobj->SetMinimum(xmin);
hobj->SetMaximum(xmax);
hobj->SetBit(TH1::kIsZoomed);
} else {
axis->SetRange(bin1,bin2);
}
}
Modified(kTRUE);
}
}
gVirtualX->SetLineColor(-1);
break;
}
}
TObject *TPad::FindObject(const char *name) const
{
if (!fPrimitives) return 0;
TObject *found = fPrimitives->FindObject(name);
if (found) return found;
TObject *cur;
TIter next(GetListOfPrimitives());
while ((cur = next())) {
if (cur->InheritsFrom(TPad::Class())) {
found = ((TPad*)cur)->FindObject(name);
if (found) return found;
}
}
return 0;
}
TObject *TPad::FindObject(const TObject *obj) const
{
if (!fPrimitives) return 0;
TObject *found = fPrimitives->FindObject(obj);
if (found) return found;
TObject *cur;
TIter next(GetListOfPrimitives());
while ((cur = next())) {
if (cur->InheritsFrom(TPad::Class())) {
found = ((TPad*)cur)->FindObject(obj);
if (found) return found;
}
}
return 0;
}
Int_t TPad::GetCanvasID() const
{
return fCanvas->GetCanvasID();
}
Int_t TPad::GetEvent() const
{
return fCanvas->GetEvent();
}
Int_t TPad::GetEventX() const
{
return fCanvas->GetEventX();
}
Int_t TPad::GetEventY() const
{
return fCanvas->GetEventY();
}
TVirtualPad *TPad::GetVirtCanvas() const
{
return (TVirtualPad*) fCanvas;
}
Color_t TPad::GetHighLightColor() const
{
return fCanvas->GetHighLightColor();
}
Int_t TPad::GetMaxPickDistance()
{
return fgMaxPickDistance;
}
TObject *TPad::GetSelected() const
{
return fCanvas->GetSelected();
}
TVirtualPad *TPad::GetSelectedPad() const
{
return fCanvas->GetSelectedPad();
}
TVirtualPad *TPad::GetPadSave() const
{
return fCanvas->GetPadSave();
}
UInt_t TPad::GetWh() const
{
return fCanvas->GetWh();
}
UInt_t TPad::GetWw() const
{
return fCanvas->GetWw();
}
void TPad::HideToolTip(Int_t event)
{
if (event != kMouseEnter && event != kMouseMotion && fTip)
gPad->CloseToolTip(fTip);
}
Bool_t TPad::IsBatch() const
{
return fCanvas->IsBatch();
}
Bool_t TPad::IsRetained() const
{
return fCanvas->IsRetained();
}
Bool_t TPad::OpaqueMoving() const
{
return fCanvas->OpaqueMoving();
}
Bool_t TPad::OpaqueResizing() const
{
return fCanvas->OpaqueResizing();
}
void TPad::SetBatch(Bool_t batch)
{
fCanvas->SetBatch(batch);
}
void TPad::SetCanvasSize(UInt_t ww, UInt_t wh)
{
fCanvas->SetCanvasSize(ww,wh);
}
void TPad::SetCursor(ECursor cursor)
{
fCanvas->SetCursor(cursor);
}
void TPad::SetDoubleBuffer(Int_t mode)
{
fCanvas->SetDoubleBuffer(mode);
}
void TPad::SetSelected(TObject *obj)
{
fCanvas->SetSelected(obj);
}
void TPad::Update()
{
fCanvas->Update();
}
TFrame *TPad::GetFrame()
{
if (!fPrimitives) fPrimitives = new TList;
TFrame *frame = (TFrame*)GetListOfPrimitives()->FindObject(fFrame);
if (!frame) frame = (TFrame*)GetListOfPrimitives()->FindObject("TFrame");
fFrame = frame;
if (!fFrame) {
if (!frame) fFrame = new TFrame(0,0,1,1);
Int_t framecolor = GetFrameFillColor();
if (!framecolor) framecolor = GetFillColor();
fFrame->SetFillColor(framecolor);
fFrame->SetFillStyle(GetFrameFillStyle());
fFrame->SetLineColor(GetFrameLineColor());
fFrame->SetLineStyle(GetFrameLineStyle());
fFrame->SetLineWidth(GetFrameLineWidth());
fFrame->SetBorderSize(GetFrameBorderSize());
fFrame->SetBorderMode(GetFrameBorderMode());
}
return fFrame;
}
TObject *TPad::GetPrimitive(const char *name) const
{
if (!fPrimitives) return 0;
TIter next(fPrimitives);
TObject *found, *obj;
while ((obj=next())) {
if (!strcmp(name, obj->GetName())) return obj;
if (obj->InheritsFrom(TPad::Class())) continue;
found = obj->FindObject(name);
if (found) return found;
}
return 0;
}
TVirtualPad *TPad::GetPad(Int_t subpadnumber) const
{
if (!subpadnumber) {
return (TVirtualPad*)this;
}
TObject *obj;
if (!fPrimitives) return 0;
TIter next(GetListOfPrimitives());
while ((obj = next())) {
if (obj->InheritsFrom(TVirtualPad::Class())) {
TVirtualPad *pad = (TVirtualPad*)obj;
if (pad->GetNumber() == subpadnumber) return pad;
}
}
return 0;
}
void TPad::GetPadPar(Double_t &xlow, Double_t &ylow, Double_t &xup, Double_t &yup)
{
xlow = fXlowNDC;
ylow = fYlowNDC;
xup = fXlowNDC+fWNDC;
yup = fYlowNDC+fHNDC;
}
void TPad::GetRange(Double_t &x1, Double_t &y1, Double_t &x2, Double_t &y2)
{
x1 = fX1;
y1 = fY1;
x2 = fX2;
y2 = fY2;
}
void TPad::GetRangeAxis(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax)
{
xmin = fUxmin;
ymin = fUymin;
xmax = fUxmax;
ymax = fUymax;
}
void TPad::HighLight(Color_t color, Bool_t set)
{
if (gVirtualPS && gVirtualPS->TestBit(kPrintingPS)) return;
if (color <= 0) return;
AbsCoordinates(kTRUE);
if (GetMother()->IsEditable() && !InheritsFrom(TButton::Class())) {
gROOT->SetSelectedPad(this);
if (set)
PaintBorder(-color, kFALSE);
else
PaintBorder(-GetFillColor(), kFALSE);
}
AbsCoordinates(kFALSE);
}
void TPad::ls(Option_t *option) const
{
TROOT::IndentLevel();
cout <<IsA()->GetName()<<" fXlowNDC=" <<fXlowNDC<<" fYlowNDC="<<fYlowNDC<<" fWNDC="<<GetWNDC()<<" fHNDC="<<GetHNDC()
<<" Name= "<<GetName()<<" Title= "<<GetTitle()<<" Option="<<option<<endl;
TROOT::IncreaseDirLevel();
if (!fPrimitives) return;
fPrimitives->ls(option);
TROOT::DecreaseDirLevel();
}
Double_t TPad::PadtoX(Double_t x) const
{
if (fLogx && x < 50) return Double_t(TMath::Exp(2.302585092994*x));
return x;
}
Double_t TPad::PadtoY(Double_t y) const
{
if (fLogy && y < 50) return Double_t(TMath::Exp(2.302585092994*y));
return y;
}
Double_t TPad::XtoPad(Double_t x) const
{
if (fLogx) {
if (x > 0) x = TMath::Log10(x);
else x = fUxmin;
}
return x;
}
Double_t TPad::YtoPad(Double_t y) const
{
if (fLogy) {
if (y > 0) y = TMath::Log10(y);
else y = fUymin;
}
return y;
}
void TPad::Paint(Option_t * )
{
if (!fPrimitives) fPrimitives = new TList;
if (fViewer3D && fViewer3D->CanLoopOnPrimitives()) {
fViewer3D->PadPaint(this);
Modified(kFALSE);
if (GetGLDevice()!=-1 && gVirtualPS) {
TPad *padsav = (TPad*)gPad;
gPad = this;
gGLManager->PrintViewer(GetViewer3D());
gPad = padsav;
}
return;
}
if (fCanvas) TColor::SetGrayscale(fCanvas->IsGrayscale());
TPad *padsav = (TPad*)gPad;
fPadPaint = 1;
cd();
PaintBorder(GetFillColor(), kTRUE);
PaintDate();
TObjOptLink *lnk = (TObjOptLink*)GetListOfPrimitives()->FirstLink();
TObject *obj;
Bool_t began3DScene = kFALSE;
while (lnk) {
obj = lnk->GetObject();
if (!fViewer3D && obj->InheritsFrom("TAtt3D")) {
GetViewer3D("pad");
}
if (fViewer3D && !fViewer3D->BuildingScene()) {
fViewer3D->BeginScene();
began3DScene = kTRUE;
}
obj->Paint(lnk->GetOption());
lnk = (TObjOptLink*)lnk->Next();
}
if (padsav) padsav->cd();
fPadPaint = 0;
Modified(kFALSE);
if (began3DScene) {
fViewer3D->EndScene();
}
if (GetGLDevice()!=-1 && gVirtualPS) {
gPad = this;
gGLManager->PrintViewer(GetViewer3D());
gPad = padsav;
}
}
void TPad::PaintBorder(Color_t color, Bool_t tops)
{
if(color >= 0) {
TAttLine::Modify();
TAttFill::Modify();
PaintBox(fX1,fY1,fX2,fY2);
}
if (color < 0) color = -color;
if (IsTransparent()) return;
if (fBorderMode == 0) return;
Int_t bordersize = fBorderSize;
if (bordersize <= 0) bordersize = 2;
Short_t pxl,pyl,pxt,pyt,px1,py1,px2,py2;
Double_t xl, xt, yl, yt;
Color_t oldcolor = GetFillColor();
SetFillColor(color);
TAttFill::Modify();
Color_t light = 0, dark = 0;
if (color != 0) {
light = TColor::GetColorBright(color);
dark = TColor::GetColorDark(color);
}
px1 = XtoPixel(fX1); py1 = YtoPixel(fY1);
px2 = XtoPixel(fX2); py2 = YtoPixel(fY2);
if (px1 < px2) {pxl = px1; pxt = px2; xl = fX1; xt = fX2; }
else {pxl = px2; pxt = px1; xl = fX2; xt = fX1;}
if (py1 > py2) {pyl = py1; pyt = py2; yl = fY1; yt = fY2;}
else {pyl = py2; pyt = py1; yl = fY2; yt = fY1;}
if (!IsBatch()) {
TPoint frame[7];
frame[0].fX = pxl; frame[0].fY = pyl;
frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
frame[2].fX = frame[1].fX; frame[2].fY = pyt + bordersize;
frame[3].fX = pxt - bordersize; frame[3].fY = frame[2].fY;
frame[4].fX = pxt; frame[4].fY = pyt;
frame[5].fX = pxl; frame[5].fY = pyt;
frame[6].fX = pxl; frame[6].fY = pyl;
if (fBorderMode == -1) gVirtualX->SetFillColor(dark);
else gVirtualX->SetFillColor(light);
gVirtualX->DrawFillArea(7, frame);
frame[0].fX = pxl; frame[0].fY = pyl;
frame[1].fX = pxl + bordersize; frame[1].fY = pyl - bordersize;
frame[2].fX = pxt - bordersize; frame[2].fY = frame[1].fY;
frame[3].fX = frame[2].fX; frame[3].fY = pyt + bordersize;
frame[4].fX = pxt; frame[4].fY = pyt;
frame[5].fX = pxt; frame[5].fY = pyl;
frame[6].fX = pxl; frame[6].fY = pyl;
if (fBorderMode == -1) gVirtualX->SetFillColor(light);
else gVirtualX->SetFillColor(dark);
gVirtualX->DrawFillArea(7, frame);
if (InheritsFrom("TButton") && fBorderMode == -1) {
if (TestBit(kFraming)) {
if (GetFillColor() != 2) gVirtualX->SetLineColor(2);
else gVirtualX->SetLineColor(4);
gVirtualX->DrawBox(px1+2,py1-2,px2-2,py2+2, TVirtualX::kHollow);
}
}
gVirtualX->SetFillColor(-1);
SetFillColor(oldcolor);
}
if (!tops) return;
PaintBorderPS(xl, yl, xt, yt, fBorderMode, bordersize, dark, light);
}
void TPad::PaintBorderPS(Double_t xl,Double_t yl,Double_t xt,Double_t yt,Int_t bmode,Int_t bsize,Int_t dark,Int_t light)
{
if (!gVirtualPS) return;
gVirtualPS->DrawFrame(xl, yl, xt, yt, bmode,bsize,dark,light);
}
void TPad::PaintDate()
{
if (fCanvas == this && gStyle->GetOptDate()) {
TDatime dt;
const char *dates;
if (gStyle->GetOptDate() < 10) {
dates = dt.AsString();
} else if (gStyle->GetOptDate() < 20) {
char iso[16];
strncpy(iso,dt.AsSQLString(),10); iso[10] = 0;
dates = iso;
} else {
dates = dt.AsSQLString();
}
TText tdate(gStyle->GetDateX(),gStyle->GetDateY(),dates);
tdate.SetTextSize( gStyle->GetAttDate()->GetTextSize());
tdate.SetTextFont( gStyle->GetAttDate()->GetTextFont());
tdate.SetTextColor(gStyle->GetAttDate()->GetTextColor());
tdate.SetTextAlign(gStyle->GetAttDate()->GetTextAlign());
tdate.SetTextAngle(gStyle->GetAttDate()->GetTextAngle());
tdate.SetNDC();
tdate.Paint();
}
}
void TPad::PaintPadFrame(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax)
{
if (!fPrimitives) fPrimitives = new TList;
TList *glist = GetListOfPrimitives();
TFrame *frame = GetFrame();
frame->SetX1(xmin);
frame->SetX2(xmax);
frame->SetY1(ymin);
frame->SetY2(ymax);
if (!glist->FindObject(fFrame)) {
glist->AddFirst(frame);
fFrame->SetBit(kMustCleanup);
}
if (gROOT->GetForceStyle()) frame->UseCurrentStyle();
frame->Paint();
}
void TPad::PaintModified()
{
if (fViewer3D && fViewer3D->CanLoopOnPrimitives()) {
if (IsModified()) {
fViewer3D->PadPaint(this);
Modified(kFALSE);
}
TList *pList = GetListOfPrimitives();
TObjOptLink *lnk = 0;
if (pList) lnk = (TObjOptLink*)pList->FirstLink();
TObject *obj;
while (lnk) {
obj = lnk->GetObject();
if (obj->InheritsFrom(TPad::Class()))
((TPad*)obj)->PaintModified();
lnk = (TObjOptLink*)lnk->Next();
}
return;
}
if (fCanvas) TColor::SetGrayscale(fCanvas->IsGrayscale());
TPad *padsav = (TPad*)gPad;
TVirtualPS *saveps = gVirtualPS;
if (gVirtualPS) {
if (gVirtualPS->TestBit(kPrintingPS)) gVirtualPS = 0;
}
fPadPaint = 1;
cd();
if (IsModified() || IsTransparent()) {
if ((fFillStyle < 3026) && (fFillStyle > 3000)) {
if (!gPad->IsBatch()) gVirtualX->ClearWindow();
}
PaintBorder(GetFillColor(), kTRUE);
}
PaintDate();
TList *pList = GetListOfPrimitives();
TObjOptLink *lnk = 0;
if (pList) lnk = (TObjOptLink*)pList->FirstLink();
TObject *obj;
Bool_t began3DScene = kFALSE;
while (lnk) {
obj = lnk->GetObject();
if (obj->InheritsFrom(TPad::Class())) {
((TPad*)obj)->PaintModified();
} else if (IsModified() || IsTransparent()) {
if (!fViewer3D && obj->InheritsFrom("TAtt3D")) {
GetViewer3D("pad");
}
if (fViewer3D && !fViewer3D->BuildingScene()) {
fViewer3D->BeginScene();
began3DScene = kTRUE;
}
obj->Paint(lnk->GetOption());
}
lnk = (TObjOptLink*)lnk->Next();
}
if (padsav) padsav->cd();
fPadPaint = 0;
Modified(kFALSE);
if (began3DScene) {
fViewer3D->EndScene();
}
gVirtualPS = saveps;
}
void TPad::PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option)
{
if (!gPad->IsBatch()) {
Int_t px1 = XtoPixel(x1);
Int_t px2 = XtoPixel(x2);
Int_t py1 = YtoPixel(y1);
Int_t py2 = YtoPixel(y2);
if (TMath::Abs(px2-px1) < 1) px2 = px1+1;
if (TMath::Abs(py1-py2) < 1) py1 = py2+1;
Int_t style0 = gVirtualX->GetFillStyle();
Int_t style = style0;
if (option[0] == 's') {
gVirtualX->SetFillStyle(0);
style = 0;
}
if (style) {
if (style > 3000 && style < 4000) {
if (style < 3026) {
gVirtualX->DrawBox(px1,py1,px2,py2,TVirtualX::kFilled);
}
if (style >= 3100 && style < 4000) {
Double_t xb[4], yb[4];
xb[0] = x1; xb[1] = x1; xb[2] = x2; xb[3] = x2;
yb[0] = y1; yb[1] = y2; yb[2] = y2; yb[3] = y1;
PaintFillAreaHatches(4, xb, yb, style);
return;
}
if (gVirtualX->GetFillColor() == 10) {
gVirtualX->SetFillColor(1);
gVirtualX->DrawBox(px1,py1,px2,py2,TVirtualX::kFilled);
gVirtualX->SetFillColor(10);
}
} else if (style >= 4000 && style <= 4100) {
if (this == fMother)
gVirtualX->DrawBox(px1,py1,px2,py2,TVirtualX::kFilled);
else {
int px, py;
XYtoAbsPixel(fX1, fY2, px, py);
if (fMother) {
fMother->CopyBackgroundPixmap(px, py);
CopyBackgroundPixmaps(fMother, this, px, py);
}
gVirtualX->SetOpacity(style-4000);
}
} else {
gVirtualX->DrawBox(px1,py1,px2,py2,TVirtualX::kFilled);
}
if (option[0] == 'l') gVirtualX->DrawBox(px1,py1,px2,py2,TVirtualX::kHollow);
} else {
gVirtualX->DrawBox(px1,py1,px2,py2,TVirtualX::kHollow);
if (option[0] == 's') gVirtualX->SetFillStyle(style0);
}
}
if (gVirtualPS) {
Int_t style0 = gVirtualPS->GetFillStyle();
if (option[0] == 's') {
gVirtualPS->SetFillStyle(0);
} else {
if (style0 >= 3100 && style0 < 4000) {
Double_t xb[4], yb[4];
xb[0] = x1; xb[1] = x1; xb[2] = x2; xb[3] = x2;
yb[0] = y1; yb[1] = y2; yb[2] = y2; yb[3] = y1;
PaintFillAreaHatches(4, xb, yb, style0);
return;
}
}
gVirtualPS->DrawBox(x1, y1, x2, y2);
if (option[0] == 'l') {
gVirtualPS->SetFillStyle(0);
gVirtualPS->DrawBox(x1, y1, x2, y2);
}
if (option[0] == 's' || option[0] == 'l') gVirtualPS->SetFillStyle(style0);
}
Modified();
}
void TPad::CopyBackgroundPixmaps(TPad *start, TPad *stop, Int_t x, Int_t y)
{
TObject *obj;
if (!fPrimitives) fPrimitives = new TList;
TIter next(start->GetListOfPrimitives());
while ((obj = next())) {
if (obj->InheritsFrom(TPad::Class())) {
if (obj == stop) break;
((TPad*)obj)->CopyBackgroundPixmap(x, y);
((TPad*)obj)->CopyBackgroundPixmaps((TPad*)obj, stop, x, y);
}
}
}
void TPad::CopyBackgroundPixmap(Int_t x, Int_t y)
{
int px, py;
XYtoAbsPixel(fX1, fY2, px, py);
gVirtualX->CopyPixmap(GetPixmapID(), px-x, py-y);
}
void TPad::PaintFillArea(Int_t nn, Float_t *xx, Float_t *yy, Option_t *)
{
Warning("TPad::PaintFillArea", "Float_t signature is obsolete");
if (nn <3) return;
Int_t i,iclip,n=0;
Double_t xmin,xmax,ymin,ymax;
Double_t u1, v1, u[2],v[2];
if (TestBit(TGraph::kClipFrame)) {
xmin = fUxmin; ymin = fUymin; xmax = fUxmax; ymax = fUymax;
} else {
xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
}
Double_t *x = new Double_t[2*nn+1];
Double_t *y = new Double_t[2*nn+1];
for (i=0;i<nn;i++) {
u[0] = xx[i];
v[0] = yy[i];
if (i == nn-1) {
u[1] = xx[0];
v[1] = yy[0];
} else {
u[1] = xx[i+1];
v[1] = yy[i+1];
}
u1 = u[1];
v1 = v[1];
iclip = Clip(u,v,xmin,ymin,xmax,ymax);
if (iclip == 2) continue;
if (iclip == 1) {
if (u[0] == u[1] && v[0] == v[1]) continue;
}
x[n] = u[0];
y[n] = v[0];
n++;
if (iclip) {
if (u[1] != u1 || v[1] != v1) {
x[n] = u[1];
y[n] = v[1];
n++;
}
}
}
x[n] = x[0];
y[n] = y[0];
if (n < 3) {
delete [] x;
delete [] y;
return;
}
Int_t fillstyle = gVirtualX->GetFillStyle();
if (gPad->IsBatch() && gVirtualPS) fillstyle = gVirtualPS->GetFillStyle();
if (fillstyle >= 3100 && fillstyle < 4000) {
PaintFillAreaHatches(nn, x, y, fillstyle);
delete [] x;
delete [] y;
return;
}
TPoint *pxy;
if (!gPad->IsBatch()) {
if (n <kPXY) pxy = &gPXY[0];
else pxy = new TPoint[n+1];
for (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;
}
if (gVirtualPS) {
gVirtualPS->DrawPS(-n, x, y);
}
delete [] x;
delete [] y;
Modified();
}
void TPad::PaintFillArea(Int_t nn, Double_t *xx, Double_t *yy, Option_t *)
{
if (nn <3) return;
Int_t i,n=0;
Double_t xmin,xmax,ymin,ymax;
if (TestBit(TGraph::kClipFrame)) {
xmin = fUxmin; ymin = fUymin; xmax = fUxmax; ymax = fUymax;
} else {
xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
}
Int_t nc = 2*nn+1;
Double_t *x = new Double_t[nc];
Double_t *y = new Double_t[nc];
n = ClipPolygon(nn, xx, yy, nc, x, y,xmin,ymin,xmax,ymax);
if (!n) {
delete [] x;
delete [] y;
return;
}
Int_t fillstyle = gVirtualX->GetFillStyle();
if (gPad->IsBatch() && gVirtualPS) fillstyle = gVirtualPS->GetFillStyle();
if (fillstyle >= 3100 && fillstyle < 4000) {
PaintFillAreaHatches(nn, x, y, fillstyle);
delete [] x;
delete [] y;
return;
}
TPoint *pxy;
if (!gPad->IsBatch()) {
if (n <kPXY) pxy = &gPXY[0];
else pxy = new TPoint[n+1];
for (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;
}
if (gVirtualPS) {
gVirtualPS->DrawPS(-n, x, y);
}
delete [] x;
delete [] y;
Modified();
}
void TPad::PaintFillAreaHatches(Int_t nn, Double_t *xx, Double_t *yy, Int_t FillStyle)
{
static Double_t ang1[10] = {0., 10., 20., 30., 45.,5., 60., 70., 80., 90.};
static Double_t ang2[10] = {180.,170.,160.,150.,135.,5.,120.,110.,100., 90.};
Int_t fasi = FillStyle%1000;
Int_t idSPA = (Int_t)(fasi/100);
Int_t iAng2 = (Int_t)((fasi-100*idSPA)/10);
Int_t iAng1 = fasi%10;
Double_t dy = 0.003*(Double_t)(idSPA)*gStyle->GetHatchesSpacing();
Int_t lw = gStyle->GetHatchesLineWidth();
Short_t lws = 0;
Int_t lss = 0;
Int_t lcs = 0;
if (!gPad->IsBatch()) {
lws = gVirtualX->GetLineWidth();
lss = gVirtualX->GetLineStyle();
lcs = gVirtualX->GetLineColor();
} else {
if (gVirtualPS) {
lws = gVirtualPS->GetLineWidth();
lss = gVirtualPS->GetLineStyle();
lcs = gVirtualPS->GetLineColor();
}
}
if (!gPad->IsBatch()) {
gVirtualX->SetLineStyle(1);
gVirtualX->SetLineWidth(Short_t(lw));
gVirtualX->SetLineColor(gVirtualX->GetFillColor());
}
if (gVirtualPS) {
gVirtualPS->SetLineStyle(1);
gVirtualPS->SetLineWidth(Short_t(lw));
gVirtualPS->SetLineColor(gVirtualPS->GetFillColor());
}
if (ang1[iAng1] != 5.) PaintHatches(dy, ang1[iAng1], nn, xx, yy);
if (ang2[iAng2] != 5.) PaintHatches(dy, ang2[iAng2], nn, xx, yy);
if (!gPad->IsBatch()) {
gVirtualX->SetLineStyle(lss);
gVirtualX->SetLineWidth(lws);
gVirtualX->SetLineColor(lcs);
}
if (gVirtualPS) {
gVirtualPS->SetLineStyle(lss);
gVirtualPS->SetLineWidth(lws);
gVirtualPS->SetLineColor(lcs);
}
}
void TPad::PaintHatches(Double_t dy, Double_t angle,
Int_t nn, Double_t *xx, Double_t *yy)
{
Int_t i, i1, i2, nbi, m, inv;
Double_t ratiox, ratioy, ymin, ymax, yrot, ycur;
const Double_t angr = TMath::Pi()*(180-angle)/180.;
const Double_t epsil = 0.0001;
const Int_t maxnbi = 100;
Double_t xli[maxnbi], xlh[2], ylh[2], xt1, xt2, yt1, yt2;
Double_t ll, x, y, x1, x2, y1, y2, a, b, xi, xip, xin, yi, yip;
Double_t rwxmin = gPad->GetX1();
Double_t rwxmax = gPad->GetX2();
Double_t rwymin = gPad->GetY1();
Double_t rwymax = gPad->GetY2();
ratiox = 1/(rwxmax-rwxmin);
ratioy = 1/(rwymax-rwymin);
Double_t sina = TMath::Sin(angr), sinb;
Double_t cosa = TMath::Cos(angr), cosb;
if (TMath::Abs(cosa) <= epsil) cosa=0.;
if (TMath::Abs(sina) <= epsil) sina=0.;
sinb = -sina;
cosb = cosa;
Int_t iw = gPad->GetWw();
Int_t ih = gPad->GetWh();
Double_t x1p,y1p,x2p,y2p;
gPad->GetPadPar(x1p,y1p,x2p,y2p);
iw = (Int_t)(iw*x2p)-(Int_t)(iw*x1p);
ih = (Int_t)(ih*y2p)-(Int_t)(ih*y1p);
Double_t wndc = TMath::Min(1.,(Double_t)iw/(Double_t)ih);
Double_t hndc = TMath::Min(1.,(Double_t)ih/(Double_t)iw);
ymin = 1.;
ymax = 0.;
for (i=1; i<=nn; i++) {
x = wndc*ratiox*(xx[i-1]-rwxmin);
y = hndc*ratioy*(yy[i-1]-rwymin);
yrot = sina*x+cosa*y;
if (yrot > ymax) ymax = yrot;
if (yrot < ymin) ymin = yrot;
}
ymax = (Double_t)((Int_t)(ymax/dy))*dy;
for (ycur=ymax; ycur>=ymin; ycur=ycur-dy) {
nbi = 0;
for (i=2; i<=nn+1; i++) {
i2 = i;
i1 = i-1;
if (i == nn+1) i2=1;
x1 = wndc*ratiox*(xx[i1-1]-rwxmin);
y1 = hndc*ratioy*(yy[i1-1]-rwymin);
x2 = wndc*ratiox*(xx[i2-1]-rwxmin);
y2 = hndc*ratioy*(yy[i2-1]-rwymin);
xt1 = cosa*x1-sina*y1;
yt1 = sina*x1+cosa*y1;
xt2 = cosa*x2-sina*y2;
yt2 = sina*x2+cosa*y2;
if (xt1 == xt2) {
if (yt1 < yt2) {
yi = yt1;
yip = yt2;
} else {
yi = yt2;
yip = yt1;
}
if ((yi <= ycur) && (ycur < yip)) {
nbi++;
if (nbi >= maxnbi) return;
xli[nbi-1] = xt1;
}
continue;
}
if (yt1 == yt2) {
if (yt1 == ycur) {
nbi++;
if (nbi >= maxnbi) return;
xli[nbi-1] = xt1;
nbi++;
if (nbi >= maxnbi) return;
xli[nbi-1] = xt2;
}
continue;
}
a = (yt1-yt2)/(xt1-xt2);
b = (yt2*xt1-xt2*yt1)/(xt1-xt2);
if (xt1 < xt2) {
xi = xt1;
xip = xt2;
} else {
xi = xt2;
xip = xt1;
}
xin = (ycur-b)/a;
if ((xi <= xin) && (xin < xip) &&
(TMath::Min(yt1,yt2) <= ycur) &&
(ycur < TMath::Max(yt1,yt2))) {
nbi++;
if (nbi >= maxnbi) return;
xli[nbi-1] = xin;
}
}
inv = 0;
m = nbi-1;
L30:
for (i=1; i<=m; i++) {
if (xli[i] < xli[i-1]) {
inv++;
ll = xli[i-1];
xli[i-1] = xli[i];
xli[i] = ll;
}
}
m--;
if (inv == 0) goto L50;
inv = 0;
goto L30;
L50:
if (nbi%2 != 0) continue;
for (i=1; i<=nbi; i=i+2) {
xlh[0] = cosb*xli[i-1]-sinb*ycur;
ylh[0] = sinb*xli[i-1]+cosb*ycur;
xlh[1] = cosb*xli[i] -sinb*ycur;
ylh[1] = sinb*xli[i] +cosb*ycur;
xlh[0] = (xlh[0]/wndc)*(rwxmax-rwxmin)+rwxmin;
ylh[0] = (ylh[0]/hndc)*(rwymax-rwymin)+rwymin;
xlh[1] = (xlh[1]/wndc)*(rwxmax-rwxmin)+rwxmin;
ylh[1] = (ylh[1]/hndc)*(rwymax-rwymin)+rwymin;
gPad->PaintLine(xlh[0], ylh[0], xlh[1], ylh[1]);
}
}
}
void TPad::PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
{
Double_t x[2], y[2];
x[0] = x1; x[1] = x2; y[0] = y1; y[1] = y2;
if (TestBit(TGraph::kClipFrame)) {
if (Clip(x,y,fUxmin,fUymin,fUxmax,fUymax) == 2) return;
} else {
if (Clip(x,y,fX1,fY1,fX2,fY2) == 2) return;
}
if (!gPad->IsBatch()) {
Int_t px1 = XtoPixel(x[0]);
Int_t px2 = XtoPixel(x[1]);
Int_t py1 = YtoPixel(y[0]);
Int_t py2 = YtoPixel(y[1]);
gVirtualX->DrawLine(px1, py1, px2, py2);
}
if (gVirtualPS) {
gVirtualPS->DrawPS(2, x, y);
}
Modified();
}
void TPad::PaintLineNDC(Double_t u1, Double_t v1,Double_t u2, Double_t v2)
{
static Double_t xw[2], yw[2];
if (!gPad->IsBatch()) {
Int_t px1 = UtoPixel(u1);
Int_t py1 = VtoPixel(v1);
Int_t px2 = UtoPixel(u2);
Int_t py2 = VtoPixel(v2);
gVirtualX->DrawLine(px1, py1, px2, py2);
}
if (gVirtualPS) {
xw[0] = fX1 + u1*(fX2 - fX1);
xw[1] = fX1 + u2*(fX2 - fX1);
yw[0] = fY1 + v1*(fY2 - fY1);
yw[1] = fY1 + v2*(fY2 - fY1);
gVirtualPS->DrawPS(2, xw, yw);
}
Modified();
}
void TPad::PaintLine3D(Float_t *p1, Float_t *p2)
{
if (!fView) return;
Double_t xpad[6];
Double_t temp[3];
Int_t i;
for (i=0;i<3;i++) temp[i] = p1[i];
fView->WCtoNDC(temp, &xpad[0]);
for (i=0;i<3;i++) temp[i] = p2[i];
fView->WCtoNDC(temp, &xpad[3]);
PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
}
void TPad::PaintLine3D(Double_t *p1, Double_t *p2)
{
if (!fView) return;
Double_t xpad[6];
Double_t temp[3];
Int_t i;
for (i=0;i<3;i++) temp[i] = p1[i];
fView->WCtoNDC(temp, &xpad[0]);
for (i=0;i<3;i++) temp[i] = p2[i];
fView->WCtoNDC(temp, &xpad[3]);
PaintLine(xpad[0],xpad[1],xpad[3],xpad[4]);
}
void TPad::PaintPolyLine(Int_t n, Float_t *x, Float_t *y, Option_t *)
{
if (n < 2) return;
TPoint *pxy = &gPXY[0];
if (!gPad->IsBatch()) {
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
}
Double_t xmin,xmax,ymin,ymax;
if (TestBit(TGraph::kClipFrame)) {
xmin = fUxmin; ymin = fUymin; xmax = fUxmax; ymax = fUymax;
} else {
xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
}
Int_t i,j,i1=-1,np=1;
for (i=0; i<n-1; i++) {
Double_t x1=x[i];
Double_t y1=y[i];
Double_t x2=x[i+1];
Double_t y2=y[i+1];
Int_t iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
if (iclip == 2) {
i1 = -1;
continue;
}
np++;
if (i1 < 0) i1 = i;
if (iclip == 0 && i < n-2) continue;
if (!gPad->IsBatch()) {
for (j=0;j<np;j++) {
pxy[j].fX = XtoPixel(x[i1+j]);
pxy[j].fY = YtoPixel(y[i1+j]);
}
gVirtualX->DrawPolyLine(np,pxy);
}
if (gVirtualPS) {
gVirtualPS->DrawPS(np, &x[i1], &y[i1]);
}
if (iclip) {
x[i] = x1;
y[i] = y1;
x[i+1] = x2;
y[i+1] = y2;
}
i1 = -1;
np = 1;
}
if (!gPad->IsBatch()) {
if (n >= kPXY) delete [] pxy;
}
Modified();
}
void TPad::PaintPolyLine(Int_t n, Double_t *x, Double_t *y, Option_t *option)
{
if (n < 2) return;
TPoint *pxy = &gPXY[0];
if (!gPad->IsBatch()) {
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
}
Double_t xmin,xmax,ymin,ymax;
Bool_t mustClip = kTRUE;
if (TestBit(TGraph::kClipFrame)) {
xmin = fUxmin; ymin = fUymin; xmax = fUxmax; ymax = fUymax;
} else {
xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
if (option && (option[0] == 'C')) mustClip = kFALSE;
}
Int_t i,j,i1=-1,np=1,iclip=0;
for (i=0; i<n-1; i++) {
Double_t x1=x[i];
Double_t y1=y[i];
Double_t x2=x[i+1];
Double_t y2=y[i+1];
if (mustClip) {
iclip = Clip(&x[i],&y[i],xmin,ymin,xmax,ymax);
if (iclip == 2) {
i1 = -1;
continue;
}
}
np++;
if (i1 < 0) i1 = i;
if (iclip == 0 && i < n-2) continue;
if (!gPad->IsBatch()) {
for (j=0;j<np;j++) {
pxy[j].fX = XtoPixel(x[i1+j]);
pxy[j].fY = YtoPixel(y[i1+j]);
}
gVirtualX->DrawPolyLine(np,pxy);
}
if (gVirtualPS) {
gVirtualPS->DrawPS(np, &x[i1], &y[i1]);
}
if (iclip) {
x[i] = x1;
y[i] = y1;
x[i+1] = x2;
y[i+1] = y2;
}
i1 = -1;
np = 1;
}
if (!gPad->IsBatch()) {
if (n >= kPXY) delete [] pxy;
}
Modified();
}
void TPad::PaintPolyLineNDC(Int_t n, Double_t *x, Double_t *y, Option_t *)
{
TPoint *pxy;
Int_t i;
if (n <=0) return;
if (!gPad->IsBatch()) {
if (n <kPXY) pxy = &gPXY[0];
else pxy = new TPoint[n+1]; if (!pxy) return;
for (i=0; i<n; i++) {
pxy[i].fX = UtoPixel(x[i]);
pxy[i].fY = VtoPixel(y[i]);
}
gVirtualX->DrawPolyLine(n,pxy);
if (n >= kPXY) delete [] pxy;
}
if (gVirtualPS) {
Double_t *xw = new Double_t[n];
Double_t *yw = new Double_t[n];
for (i=0; i<n; i++) {
xw[i] = fX1 + x[i]*(fX2 - fX1);
yw[i] = fY1 + y[i]*(fY2 - fY1);
}
gVirtualPS->DrawPS(n, xw, yw);
delete [] xw;
delete [] yw;
}
Modified();
}
void TPad::PaintPolyLine3D(Int_t n, Double_t *p)
{
if (!fView) return;
for (Int_t i = 1; i < n; i++)
PaintLine3D(&p[3*i-3], &p[3*i]);
Modified();
}
void TPad::PaintPolyMarker(Int_t nn, Float_t *x, Float_t *y, Option_t *)
{
Int_t n = TMath::Abs(nn);
TPoint *pxy = &gPXY[0];
if (!gPad->IsBatch()) {
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
}
Double_t xmin,xmax,ymin,ymax;
if (nn > 0 || TestBit(TGraph::kClipFrame)) {
xmin = fUxmin; ymin = fUymin; xmax = fUxmax; ymax = fUymax;
} else {
xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
}
Int_t i,j,i1=-1,np=0;
for (i=0; i<n; i++) {
if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
np++;
if (i1 < 0) i1 = i;
if (i < n-1) continue;
}
if (np == 0) continue;
if (!gPad->IsBatch()) {
for (j=0;j<np;j++) {
pxy[j].fX = XtoPixel(x[i1+j]);
pxy[j].fY = YtoPixel(y[i1+j]);
}
gVirtualX->DrawPolyMarker(np,pxy);
}
if (gVirtualPS) {
gVirtualPS->DrawPolyMarker(np, &x[i1], &y[i1]);
}
i1 = -1;
np = 0;
}
if (!gPad->IsBatch()) {
if (n >= kPXY) delete [] pxy;
}
Modified();
}
void TPad::PaintPolyMarker(Int_t nn, Double_t *x, Double_t *y, Option_t *)
{
Int_t n = TMath::Abs(nn);
TPoint *pxy = &gPXY[0];
if (!gPad->IsBatch()) {
if (n >= kPXY) pxy = new TPoint[n+1]; if (!pxy) return;
}
Double_t xmin,xmax,ymin,ymax;
if (nn > 0 || TestBit(TGraph::kClipFrame)) {
xmin = fUxmin; ymin = fUymin; xmax = fUxmax; ymax = fUymax;
} else {
xmin = fX1; ymin = fY1; xmax = fX2; ymax = fY2;
}
Int_t i,j,i1=-1,np=0;
for (i=0; i<n; i++) {
if (x[i] >= xmin && x[i] <= xmax && y[i] >= ymin && y[i] <= ymax) {
np++;
if (i1 < 0) i1 = i;
if (i < n-1) continue;
}
if (np == 0) continue;
if (!gPad->IsBatch()) {
for (j=0;j<np;j++) {
pxy[j].fX = XtoPixel(x[i1+j]);
pxy[j].fY = YtoPixel(y[i1+j]);
}
gVirtualX->DrawPolyMarker(np,pxy);
}
if (gVirtualPS) {
gVirtualPS->DrawPolyMarker(np, &x[i1], &y[i1]);
}
i1 = -1;
np = 0;
}
if (!gPad->IsBatch()) {
if (n >= kPXY) delete [] pxy;
}
Modified();
}
void TPad::PaintText(Double_t x, Double_t y, const char *text)
{
Modified();
if (!gPad->IsBatch()) {
Int_t px = XtoPixel(x);
Int_t py = YtoPixel(y);
Float_t angle = gVirtualX->GetTextAngle();
gVirtualX->DrawText(px, py, angle, gVirtualX->GetTextMagnitude(), text, TVirtualX::kClear);
}
if (gVirtualPS) gVirtualPS->Text(x, y, text);
}
void TPad::PaintTextNDC(Double_t u, Double_t v, const char *text)
{
Modified();
if (!gPad->IsBatch()) {
Int_t px = UtoPixel(u);
Int_t py = VtoPixel(v);
Float_t angle = gVirtualX->GetTextAngle();
gVirtualX->DrawText(px, py, angle, gVirtualX->GetTextMagnitude(), text, TVirtualX::kClear);
}
if (gVirtualPS) {
Double_t x = fX1 + u*(fX2 - fX1);
Double_t y = fY1 + v*(fY2 - fY1);
gVirtualPS->Text(x, y, text);
}
}
TPad *TPad::Pick(Int_t px, Int_t py, TObjLink *&pickobj)
{
if (gPad == 0) return 0;
if (GetListOfPrimitives() == 0) return 0;
Int_t dist;
Double_t x = AbsPixeltoX(px);
Double_t y = AbsPixeltoY(py);
if (this != gPad->GetCanvas()) {
if (!((x >= fX1 && x <= fX2) && (y >= fY1 && y <= fY2))) return 0;
}
static TObjOptLink dummyLink(0,"");
TPad *padsav = (TPad*)gPad;
gPad = this;
TPad *pick = 0;
TPad *picked = this;
pickobj = 0;
if (DistancetoPrimitive(px,py) < fgMaxPickDistance) {
dummyLink.SetObject(this);
pickobj = &dummyLink;
}
Bool_t gotPrim = kFALSE;
TObjLink *lnk = GetListOfPrimitives()->LastLink();
while (lnk) {
TObject *obj = lnk->GetObject();
if (obj->InheritsFrom(TAtt3D::Class()) && fEmbeddedGL) {
lnk = lnk->Prev();
continue;
}
fPadPointer = obj;
if (obj->InheritsFrom(TPad::Class())) {
pick = ((TPad*)obj)->Pick(px, py, pickobj);
if (pick) {
picked = pick;
break;
}
} else if (!gROOT->GetEditorMode()) {
if (!gotPrim) {
if (!obj->TestBit(kCannotPick)) {
dist = obj->DistancetoPrimitive(px, py);
if (dist < fgMaxPickDistance) {
pickobj = lnk;
gotPrim = kTRUE;
if (dist == 0) break;
}
}
}
}
lnk = lnk->Prev();
}
if (fView && !gotPrim) {
Double_t dx = 0.05*(fUxmax-fUxmin);
if ((x > fUxmin + dx) && (x < fUxmax-dx)) {
if (fEmbeddedGL) {
py -= Int_t((1 - GetHNDC() - GetYlowNDC()) * GetWh());
px -= Int_t(GetXlowNDC() * GetWw());
fViewer3D->DistancetoPrimitive(px, py);
}
else
dummyLink.SetObject(fView);
}
}
if (picked->InheritsFrom(TButton::Class())) {
TButton *button = (TButton*)picked;
if (!button->IsEditable()) pickobj = 0;
}
gPad = padsav;
return picked;
}
void TPad::Pop()
{
if (!fMother) return;
if (!fPrimitives) fPrimitives = new TList;
if (this == fMother->GetListOfPrimitives()->Last()) return;
TListIter next(fMother->GetListOfPrimitives());
TObject *obj;
while ((obj = next()))
if (obj == this) {
char *opt = StrDup(next.GetOption());
fMother->GetListOfPrimitives()->Remove(this);
fMother->GetListOfPrimitives()->AddLast(this, opt);
delete [] opt;
return;
}
}
void TPad::Print(const char *filename) const
{
((TPad*)this)->SaveAs(filename);
}
static Bool_t ContainsTImage(TList *li)
{
TIter next(li);
TObject *obj;
while ((obj = next())) {
if (obj->InheritsFrom(TImage::Class())) {
return kTRUE;
} else if (obj->InheritsFrom(TPad::Class())) {
if (ContainsTImage(((TPad*)obj)->GetListOfPrimitives())) {
return kTRUE;
}
}
}
return kFALSE;
}
void TPad::Print(const char *filenam, Option_t *option)
{
TString psname, fs1, fs2;
char *filename;
fs1 = filenam;
if (fs1.EndsWith("[")) {
fs1.Replace((fs1.Length()-1),1," ");
fs2 = gSystem->ExpandPathName(fs1.Data());
fs2.Replace((fs2.Length()-1),1,"[");
} else if (fs1.EndsWith("]")) {
fs1.Replace((fs1.Length()-1),1," ");
fs2 = gSystem->ExpandPathName(fs1.Data());
fs2.Replace((fs2.Length()-1),1,"]");
} else {
char* exppath = gSystem->ExpandPathName(fs1.Data());
fs2 = exppath;
delete [] exppath;
}
filename = (char*)fs2.Data();
Int_t lenfil = filename ? strlen(filename) : 0;
const char *opt = option;
Bool_t image = kFALSE;
const char *opt_default="ps";
if( !opt ) opt = opt_default;
if ( !lenfil ) {
psname = GetName();
psname += opt;
} else {
psname = filename;
}
if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
psname = GetName();
psname.Append(filename);
psname.Prepend("/");
psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
}
if (!gPad->IsBatch() && fCanvas)
gVirtualX->SelectWindow(GetCanvasID());
TImage::EImageFileTypes gtype = TImage::kUnknown;
if (strstr(opt, "gif+")) {
gtype = TImage::kAnimGif;
image = kTRUE;
} else if (strstr(opt, "gif")) {
gtype = TImage::kGif;
image = kTRUE;
} else if (strstr(opt, "png")) {
gtype = TImage::kPng;
image = kTRUE;
} else if (strstr(opt, "jpg")) {
gtype = TImage::kJpeg;
image = kTRUE;
} else if (strstr(opt, "tiff")) {
gtype = TImage::kTiff;
image = kTRUE;
} else if (strstr(opt, "xpm")) {
gtype = TImage::kXpm;
image = kTRUE;
} else if (strstr(opt, "bmp")) {
gtype = TImage::kBmp;
image = kTRUE;
}
Int_t wid = 0;
if (!gROOT->IsBatch() && image) {
if ((gtype == TImage::kGif) && !ContainsTImage(fPrimitives)) {
wid = (this == GetCanvas()) ? GetCanvas()->GetCanvasID() : GetPixmapID();
Color_t hc = gPad->GetCanvas()->GetHighLightColor();
gPad->GetCanvas()->SetHighLightColor(-1);
gPad->Modified();
gPad->Update();
gVirtualX->SelectWindow(wid);
if (gVirtualX->WriteGIF((char*)psname.Data())) {
if (!gSystem->AccessPathName(psname.Data())) {
Info("Print", "GIF file %s has been created", psname.Data());
}
}
gPad->GetCanvas()->SetHighLightColor(hc);
return;
}
if (gtype != TImage::kUnknown) {
Color_t hc = gPad->GetCanvas()->GetHighLightColor();
gPad->GetCanvas()->SetHighLightColor(-1);
gPad->Modified();
gPad->Update();
if (gVirtualX->InheritsFrom("TGQt")) {
wid = (this == GetCanvas()) ? GetCanvas()->GetCanvasID() : GetPixmapID();
gVirtualX->WritePixmap(wid,UtoPixel(1.),VtoPixel(0.),(char *)psname.Data());
} else {
Int_t saver = gErrorIgnoreLevel;
gErrorIgnoreLevel = kFatal;
gVirtualX->Update(1);
gSystem->Sleep(30);
TImage *img = TImage::Create();
img->FromPad(this);
img->WriteImage(psname, gtype);
gErrorIgnoreLevel = saver;
delete img;
}
if (!gSystem->AccessPathName(psname)) {
Info("Print", "file %s has been created", psname.Data());
}
gPad->GetCanvas()->SetHighLightColor(hc);
} else {
Warning("Print", "Unsupported image format %s", psname.Data());
}
return;
}
if (strstr(opt,"cxx")) {
GetCanvas()->SaveSource(psname, "");
return;
}
if (strstr(opt,"root")) {
if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
return;
}
if (strstr(opt,"xml")) {
if (gDirectory) gDirectory->SaveObjectAs(this,psname.Data(),"");
return;
}
if (strstr(opt,"svg")) {
gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
Bool_t noScreen = kFALSE;
if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
noScreen = kTRUE;
GetCanvas()->SetBatch(kTRUE);
}
TPad *padsav = (TPad*)gPad;
cd();
TVirtualPS *psave = gVirtualPS;
if (!gVirtualPS) {
TPluginHandler *h;
if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "svg"))) {
if (h->LoadPlugin() == -1)
return;
h->ExecPlugin(0);
}
}
gVirtualPS->SetName(psname);
gVirtualPS->Open(psname);
gVirtualPS->SetBit(kPrintingPS);
gVirtualPS->NewPage();
Paint();
if (noScreen) GetCanvas()->SetBatch(kFALSE);
if (!gSystem->AccessPathName(psname)) Info("Print", "SVG file %s has been created", psname.Data());
delete gVirtualPS;
gVirtualPS = psave;
gVirtualPS = 0;
padsav->cd();
return;
}
Bool_t mustOpen = kTRUE;
Bool_t mustClose = kTRUE;
char *copen=0, *cclose=0, *copenb=0, *ccloseb=0;
if (!image) {
copen = (char*)strstr(psname.Data(),"("); if (copen) *copen = 0;
cclose = (char*)strstr(psname.Data(),")"); if (cclose) *cclose = 0;
copenb = (char*)strstr(psname.Data(),"["); if (copenb) *copenb = 0;
ccloseb = (char*)strstr(psname.Data(),"]"); if (ccloseb) *ccloseb = 0;
}
gVirtualPS = (TVirtualPS*)gROOT->GetListOfSpecials()->FindObject(psname);
if (gVirtualPS) {mustOpen = kFALSE; mustClose = kFALSE;}
if (copen || copenb) mustClose = kFALSE;
if (cclose || ccloseb) mustClose = kTRUE;
Bool_t noScreen = kFALSE;
if (!GetCanvas()->IsBatch() && GetCanvas()->GetCanvasID() == -1) {
noScreen = kTRUE;
GetCanvas()->SetBatch(kTRUE);
}
Int_t pstype = 111;
Double_t xcanvas = GetCanvas()->XtoPixel(GetCanvas()->GetX2());
Double_t ycanvas = GetCanvas()->YtoPixel(GetCanvas()->GetY1());
Double_t ratio = ycanvas/xcanvas;
if (ratio < 1) pstype = 112;
if (strstr(opt,"Portrait")) pstype = 111;
if (strstr(opt,"Landscape")) pstype = 112;
if (strstr(opt,"eps")) pstype = 113;
if (strstr(opt,"Preview")) pstype = 113;
TPad *padsav = (TPad*)gPad;
cd();
TVirtualPS *psave = gVirtualPS;
if (!gVirtualPS || mustOpen) {
TPluginHandler *h;
if (strstr(opt,"pdf")) {
if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "pdf"))) {
if (h->LoadPlugin() == -1) return;
h->ExecPlugin(0);
}
} else if (image) {
if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "image"))) {
if (h->LoadPlugin() == -1) return;
h->ExecPlugin(0);
}
} else {
if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualPS", "ps"))) {
if (h->LoadPlugin() == -1) return;
h->ExecPlugin(0);
}
}
gVirtualPS->SetName(psname);
gVirtualPS->Open(psname,pstype);
gVirtualPS->SetBit(kPrintingPS);
if (!copenb) {
if (!strstr(opt,"pdf") || image) gVirtualPS->NewPage();
Paint();
}
if (noScreen) GetCanvas()->SetBatch(kFALSE);
if (!gSystem->AccessPathName(psname)) Info("Print", "%s file %s has been created", opt, psname.Data());
if (mustClose) {
gROOT->GetListOfSpecials()->Remove(gVirtualPS);
delete gVirtualPS;
gVirtualPS = psave;
} else {
gROOT->GetListOfSpecials()->Add(gVirtualPS);
gVirtualPS = 0;
}
} else {
if (!ccloseb) {
gVirtualPS->NewPage();
Paint();
}
Info("Print", "Current canvas added to %s file %s", opt, psname.Data());
if (mustClose) {
gROOT->GetListOfSpecials()->Remove(gVirtualPS);
delete gVirtualPS;
gVirtualPS = 0;
} else {
gVirtualPS = 0;
}
}
if (strstr(opt,"Preview")) gSystem->Exec(Form("epstool --quiet -t6p %s %s",psname.Data(),psname.Data()));
padsav->cd();
}
void TPad::Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
{
if ((x1 >= x2) || (y1 >= y2)) {
Error("Range", "illegal world coordinates range: x1=%f, y1=%f, x2=%f, y2=%f",x1,y1,x2,y2);
return;
}
fUxmin = x1;
fUxmax = x2;
fUymin = y1;
fUymax = y2;
if (fX1 == x1 && fY1 == y1 && fX2 == x2 && fY2 == y2) return;
fX1 = x1;
fY1 = y1;
fX2 = x2;
fY2 = y2;
ResizePad();
RangeChanged();
}
void TPad::RangeAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax)
{
if ((xmin >= xmax) || (ymin >= ymax)) {
Error("RangeAxis", "illegal axis coordinates range: xmin=%f, ymin=%f, xmax=%f, ymax=%f",
xmin, ymin, xmax, ymax);
return;
}
fUxmin = xmin;
fUymin = ymin;
fUxmax = xmax;
fUymax = ymax;
RangeAxisChanged();
}
void TPad::RecursiveRemove(TObject *obj)
{
if (obj == fCanvas->GetSelected()) fCanvas->SetSelected(0);
if (obj == fCanvas->GetClickSelected()) fCanvas->SetClickSelected(0);
if (obj == fView) fView = 0;
if (!fPrimitives) return;
Int_t nold = fPrimitives->GetSize();
fPrimitives->RecursiveRemove(obj);
if (nold != fPrimitives->GetSize()) fModified = kTRUE;
}
void TPad::RedrawAxis(Option_t *option)
{
TString opt = option;
opt.ToLower();
TPad *padsav = (TPad*)gPad;
cd();
if (!fPrimitives) fPrimitives = new TList;
TIter next(fPrimitives);
TObject *obj;
while ((obj = next())) {
if (obj->InheritsFrom("TH1")) {
TH1 *hobj = (TH1*)obj;
if (opt.Contains("g")) hobj->DrawCopy("sameaxig");
else hobj->DrawCopy("sameaxis");
return;
}
if (obj->InheritsFrom("TMultiGraph")) {
TMultiGraph *mg = (TMultiGraph*)obj;
if (mg) mg->GetHistogram()->DrawCopy("sameaxis");
return;
}
if (obj->InheritsFrom("TGraph")) {
TGraph *g = (TGraph*)obj;
if (g) g->GetHistogram()->DrawCopy("sameaxis");
return;
}
}
if (padsav) padsav->cd();
}
void TPad::ResizePad(Option_t *option)
{
TPad *parent = fMother;
if (this == gPad->GetCanvas()) {
fAbsXlowNDC = fXlowNDC;
fAbsYlowNDC = fYlowNDC;
fAbsWNDC = fWNDC;
fAbsHNDC = fHNDC;
}
else {
fAbsXlowNDC = fXlowNDC*parent->GetAbsWNDC() + parent->GetAbsXlowNDC();
fAbsYlowNDC = fYlowNDC*parent->GetAbsHNDC() + parent->GetAbsYlowNDC();
fAbsWNDC = fWNDC*parent->GetAbsWNDC();
fAbsHNDC = fHNDC*parent->GetAbsHNDC();
}
Double_t ww = (Double_t)gPad->GetWw();
Double_t wh = (Double_t)gPad->GetWh();
Double_t pxlow = fAbsXlowNDC*ww;
Double_t pylow = (1-fAbsYlowNDC)*wh;
Double_t pxrange = fAbsWNDC*ww;
Double_t pyrange = -fAbsHNDC*wh;
Double_t rounding = 0.00005;
Double_t xrange = fX2 - fX1;
fXtoAbsPixelk = rounding + pxlow - pxrange*fX1/xrange;
fXtoPixelk = rounding + -pxrange*fX1/xrange;
fXtoPixel = pxrange/xrange;
fAbsPixeltoXk = fX1 - pxlow*xrange/pxrange;
fPixeltoXk = fX1;
fPixeltoX = xrange/pxrange;
Double_t yrange = fY2 - fY1;
fYtoAbsPixelk = rounding + pylow - pyrange*fY1/yrange;
fYtoPixelk = rounding + -pyrange - pyrange*fY1/yrange;
fYtoPixel = pyrange/yrange;
fAbsPixeltoYk = fY1 - pylow*yrange/pyrange;
fPixeltoYk = fY1;
fPixeltoY = yrange/pyrange;
fUtoAbsPixelk = rounding + pxlow;
fUtoPixelk = rounding;
fUtoPixel = pxrange;
fVtoAbsPixelk = rounding + pylow;
fVtoPixelk = -pyrange;
fVtoPixel = pyrange;
TObject *obj;
if (!fPrimitives) fPrimitives = new TList;
TIter next(GetListOfPrimitives());
while ((obj = next())) {
if (obj->InheritsFrom(TPad::Class()))
((TPad*)obj)->ResizePad(option);
}
if (gPad->IsBatch())
fPixmapID = 0;
else {
gVirtualX->SetLineWidth(-1);
gVirtualX->SetTextSize(-1);
if (fPixmapID) {
int w = TMath::Abs(XtoPixel(fX2) - XtoPixel(fX1));
int h = TMath::Abs(YtoPixel(fY2) - YtoPixel(fY1));
if (!(TMath::Finite(fX1)) || !(TMath::Finite(fX2))
|| !(TMath::Finite(fY1)) || !(TMath::Finite(fY2)))
Warning("ResizePad", "Inf/NaN propagated to the pad. Check drawn objects.");
if (w <= 0 || w > 10000) {
Warning("ResizePad", "%s width changed from %d to %d\n",GetName(),w,10);
w = 10;
}
if (h <= 0 || h > 10000) {
Warning("ResizePad", "%s height changed from %d to %d\n",GetName(),h,10);
h = 10;
}
if (fPixmapID == -1) {
fPixmapID = gVirtualX->OpenPixmap(w, h);
} else {
if (fGLDevice != -1) {
Int_t borderSize = fBorderSize > 0 ? fBorderSize : 2;
Int_t w2 = w - 2 * borderSize;
Int_t h2 = h - 2 * borderSize;
Int_t px = 0, py = 0;
XYtoAbsPixel(fX1, fY2, px, py);
if (w2 < 0) w2 = 1;
if (h2 < 0) h2 = 1;
if (gGLManager->ResizeOffScreenDevice(fGLDevice, px + borderSize, py + borderSize, w2, h2))
Modified(kTRUE);
}
if (gVirtualX->ResizePixmap(fPixmapID, w, h)) {
Modified(kTRUE);
}
}
}
}
if (fView) {
TPad *padsav = (TPad*)gPad;
if (padsav == this) {
fView->ResizePad();
} else {
cd();
fView->ResizePad();
padsav->cd();
}
}
}
void TPad::SaveAs(const char *filename, Option_t * ) const
{
TString psname;
Int_t lenfil = filename ? strlen(filename) : 0;
if (!lenfil) { psname = GetName(); psname.Append(".ps"); }
else psname = filename;
if (psname.BeginsWith('.') && (psname.Contains('/') == 0)) {
psname = GetName();
psname.Append(filename);
psname.Prepend("/");
psname.Prepend(gEnv->GetValue("Canvas.PrintDirectory","."));
}
if (psname.EndsWith(".gif"))
((TPad*)this)->Print(psname,"gif");
else if (psname.Contains(".gif+"))
((TPad*)this)->Print(psname,"gif+");
else if (psname.EndsWith(".C") || psname.EndsWith(".cxx") || psname.EndsWith(".cpp"))
((TPad*)this)->Print(psname,"cxx");
else if (psname.EndsWith(".root"))
((TPad*)this)->Print(psname,"root");
else if (psname.EndsWith(".xml"))
((TPad*)this)->Print(psname,"xml");
else if (psname.EndsWith(".eps"))
((TPad*)this)->Print(psname,"eps");
else if (psname.EndsWith(".pdf"))
((TPad*)this)->Print(psname,"pdf");
else if (psname.EndsWith(".svg"))
((TPad*)this)->Print(psname,"svg");
else if (psname.EndsWith(".xpm"))
((TPad*)this)->Print(psname,"xpm");
else if (psname.EndsWith(".png"))
((TPad*)this)->Print(psname,"png");
else if (psname.EndsWith(".jpg"))
((TPad*)this)->Print(psname,"jpg");
else if (psname.EndsWith(".jpeg"))
((TPad*)this)->Print(psname,"jpg");
else if (psname.EndsWith(".bmp"))
((TPad*)this)->Print(psname,"bmp");
else if (psname.EndsWith(".tiff"))
((TPad*)this)->Print(psname,"tiff");
else
((TPad*)this)->Print(psname,"ps");
}
void TPad::SavePrimitive(ostream &out, Option_t * )
{
TPad *padsav = (TPad*)gPad;
gPad = this;
char quote='"';
char lcname[10];
const char *cname = GetName();
Int_t nch = strlen(cname);
if (nch < 10) {
strcpy(lcname,cname);
for (Int_t k=1;k<=nch;k++) {if (lcname[nch-k] == ' ') lcname[nch-k] = 0;}
if (lcname[0] == 0) {
if (this == gPad->GetCanvas()) {strcpy(lcname,"c1"); nch = 2;}
else {strcpy(lcname,"pad"); nch = 3;}
}
cname = lcname;
}
if (this != gPad->GetCanvas()) {
out <<" "<<endl;
out <<"// ------------>Primitives in pad: "<<GetName()<<endl;
if (gROOT->ClassSaved(TPad::Class())) {
out<<" ";
} else {
out<<" TPad *";
}
out<<cname<<" = new TPad("<<quote<<GetName()<<quote<<", "<<quote<<GetTitle()
<<quote
<<","<<fXlowNDC
<<","<<fYlowNDC
<<","<<fXlowNDC+fWNDC
<<","<<fYlowNDC+fHNDC
<<");"<<endl;
out<<" "<<cname<<"->Draw();"<<endl;
out<<" "<<cname<<"->cd();"<<endl;
}
out<<" "<<cname<<"->Range("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2<<");"<<endl;
TView *view = GetView();
Double_t rmin[3], rmax[3];
if (view) {
view->GetRange(rmin, rmax);
out<<" TView *view = TView::CreateView(1);"<<endl;
out<<" view->SetRange("<<rmin[0]<<","<<rmin[1]<<","<<rmin[2]<<","
<<rmax[0]<<","<<rmax[1]<<","<<rmax[2]<<");"<<endl;
}
if (GetFillColor() != 19) {
if (GetFillColor() > 228) {
TColor::SaveColor(out, GetFillColor());
out<<" "<<cname<<"->SetFillColor(ci);" << endl;
} else
out<<" "<<cname<<"->SetFillColor("<<GetFillColor()<<");"<<endl;
}
if (GetFillStyle() != 1001) {
out<<" "<<cname<<"->SetFillStyle("<<GetFillStyle()<<");"<<endl;
}
if (GetBorderMode() != 1) {
out<<" "<<cname<<"->SetBorderMode("<<GetBorderMode()<<");"<<endl;
}
if (GetBorderSize() != 4) {
out<<" "<<cname<<"->SetBorderSize("<<GetBorderSize()<<");"<<endl;
}
if (GetLogx()) {
out<<" "<<cname<<"->SetLogx();"<<endl;
}
if (GetLogy()) {
out<<" "<<cname<<"->SetLogy();"<<endl;
}
if (GetLogz()) {
out<<" "<<cname<<"->SetLogz();"<<endl;
}
if (GetGridx()) {
out<<" "<<cname<<"->SetGridx();"<<endl;
}
if (GetGridy()) {
out<<" "<<cname<<"->SetGridy();"<<endl;
}
if (GetTickx()) {
out<<" "<<cname<<"->SetTickx("<<GetTickx()<<");"<<endl;
}
if (GetTicky()) {
out<<" "<<cname<<"->SetTicky("<<GetTicky()<<");"<<endl;
}
if (GetTheta() != 30) {
out<<" "<<cname<<"->SetTheta("<<GetTheta()<<");"<<endl;
}
if (GetPhi() != 30) {
out<<" "<<cname<<"->SetPhi("<<GetPhi()<<");"<<endl;
}
if (TMath::Abs(fLeftMargin-0.1) > 0.01) {
out<<" "<<cname<<"->SetLeftMargin("<<GetLeftMargin()<<");"<<endl;
}
if (TMath::Abs(fRightMargin-0.1) > 0.01) {
out<<" "<<cname<<"->SetRightMargin("<<GetRightMargin()<<");"<<endl;
}
if (TMath::Abs(fTopMargin-0.1) > 0.01) {
out<<" "<<cname<<"->SetTopMargin("<<GetTopMargin()<<");"<<endl;
}
if (TMath::Abs(fBottomMargin-0.1) > 0.01) {
out<<" "<<cname<<"->SetBottomMargin("<<GetBottomMargin()<<");"<<endl;
}
if (GetFrameFillColor() != GetFillColor()) {
if (GetFrameFillColor() > 228) {
TColor::SaveColor(out, GetFrameFillColor());
out<<" "<<cname<<"->SetFrameFillColor(ci);" << endl;
} else
out<<" "<<cname<<"->SetFrameFillColor("<<GetFrameFillColor()<<");"<<endl;
}
if (GetFrameFillStyle() != 1001) {
out<<" "<<cname<<"->SetFrameFillStyle("<<GetFrameFillStyle()<<");"<<endl;
}
if (GetFrameLineStyle() != 1) {
out<<" "<<cname<<"->SetFrameLineStyle("<<GetFrameLineStyle()<<");"<<endl;
}
if (GetFrameLineColor() != 1) {
if (GetFrameLineColor() > 228) {
TColor::SaveColor(out, GetFrameLineColor());
out<<" "<<cname<<"->SetFrameLineColor(ci);" << endl;
} else
out<<" "<<cname<<"->SetFrameLineColor("<<GetFrameLineColor()<<");"<<endl;
}
if (GetFrameLineWidth() != 1) {
out<<" "<<cname<<"->SetFrameLineWidth("<<GetFrameLineWidth()<<");"<<endl;
}
if (GetFrameBorderMode() != 1) {
out<<" "<<cname<<"->SetFrameBorderMode("<<GetFrameBorderMode()<<");"<<endl;
}
if (GetFrameBorderSize() != 1) {
out<<" "<<cname<<"->SetFrameBorderSize("<<GetFrameBorderSize()<<");"<<endl;
}
TFrame *frame = fFrame;
if (!frame) frame = (TFrame*)GetPrimitive("TFrame");
if (frame) {
if (frame->GetFillColor() != GetFillColor()) {
if (frame->GetFillColor() > 228) {
TColor::SaveColor(out, frame->GetFillColor());
out<<" "<<cname<<"->SetFrameFillColor(ci);" << endl;
} else
out<<" "<<cname<<"->SetFrameFillColor("<<frame->GetFillColor()<<");"<<endl;
}
if (frame->GetFillStyle() != 1001) {
out<<" "<<cname<<"->SetFrameFillStyle("<<frame->GetFillStyle()<<");"<<endl;
}
if (frame->GetLineStyle() != 1) {
out<<" "<<cname<<"->SetFrameLineStyle("<<frame->GetLineStyle()<<");"<<endl;
}
if (frame->GetLineColor() != 1) {
if (frame->GetLineColor() > 228) {
TColor::SaveColor(out, frame->GetLineColor());
out<<" "<<cname<<"->SetFrameLineColor(ci);" << endl;
} else
out<<" "<<cname<<"->SetFrameLineColor("<<frame->GetLineColor()<<");"<<endl;
}
if (frame->GetLineWidth() != 1) {
out<<" "<<cname<<"->SetFrameLineWidth("<<frame->GetLineWidth()<<");"<<endl;
}
if (frame->GetBorderMode() != 1) {
out<<" "<<cname<<"->SetFrameBorderMode("<<frame->GetBorderMode()<<");"<<endl;
}
if (frame->GetBorderSize() != 1) {
out<<" "<<cname<<"->SetFrameBorderSize("<<frame->GetBorderSize()<<");"<<endl;
}
}
TIter next(GetListOfPrimitives());
TObject *obj;
while ((obj = next()))
obj->SavePrimitive(out, (Option_t *)next.GetOption());
out<<" "<<cname<<"->Modified();"<<endl;
out<<" "<<GetMother()->GetName()<<"->cd();"<<endl;
if (padsav) padsav->cd();
}
void TPad::SetFixedAspectRatio(Bool_t fixed)
{
if (fixed) {
if (!fFixedAspectRatio) {
if (fHNDC != 0.)
fAspectRatio = fWNDC / fHNDC;
else {
Error("SetAspectRatio", "cannot fix aspect ratio, height of pad is 0");
return;
}
fFixedAspectRatio = kTRUE;
}
} else {
fFixedAspectRatio = kFALSE;
fAspectRatio = 0;
}
}
void TPad::SetEditable(Bool_t mode)
{
fEditable = mode;
TObject *obj;
if (!fPrimitives) fPrimitives = new TList;
TIter next(GetListOfPrimitives());
while ((obj = next())) {
if (obj->InheritsFrom(TPad::Class())) {
TPad *pad = (TPad*)obj;
pad->SetEditable(mode);
}
}
}
void TPad::SetFillStyle(Style_t fstyle)
{
if (fstyle == 0) fstyle = 4000;
TAttFill::SetFillStyle(fstyle);
}
void TPad::SetLogx(Int_t value)
{
fLogx = value;
delete fView; fView=0;
Modified();
}
void TPad::SetLogy(Int_t value)
{
fLogy = value;
delete fView; fView=0;
Modified();
}
void TPad::SetLogz(Int_t value)
{
fLogz = value;
delete fView; fView=0;
Modified();
}
void TPad::SetPad(Double_t xlow, Double_t ylow, Double_t xup, Double_t yup)
{
if (xup < xlow) {
Double_t x = xlow;
xlow = xup;
xup = x;
}
if (yup < ylow) {
Double_t y = ylow;
ylow = yup;
yup = y;
}
fXlowNDC = xlow;
fYlowNDC = ylow;
fWNDC = xup - xlow;
fHNDC = yup - ylow;
SetFixedAspectRatio(kFALSE);
ResizePad();
}
void TPad::SetPad(const char *name, const char *title,
Double_t xlow, Double_t ylow, Double_t xup, Double_t yup,
Color_t color, Short_t bordersize, Short_t bordermode)
{
fName = name;
fTitle = title;
SetFillStyle(1001);
SetBottomMargin(gStyle->GetPadBottomMargin());
SetTopMargin(gStyle->GetPadTopMargin());
SetLeftMargin(gStyle->GetPadLeftMargin());
SetRightMargin(gStyle->GetPadRightMargin());
if (color >= 0) SetFillColor(color);
else SetFillColor(gStyle->GetPadColor());
if (bordersize < 0) fBorderSize = gStyle->GetPadBorderSize();
else fBorderSize = bordersize;
if (bordermode < -1) fBorderMode = gStyle->GetPadBorderMode();
else fBorderMode = bordermode;
SetPad(xlow, ylow, xup, yup);
}
void TPad::SetView(TView *view)
{
if (!view) delete fView;
fView = view;
}
void TPad::SetAttFillPS(Color_t color, Style_t style)
{
if (gVirtualPS) {
gVirtualPS->SetFillColor(color);
gVirtualPS->SetFillStyle(style);
}
}
void TPad::SetAttLinePS(Color_t color, Style_t style, Width_t lwidth)
{
if (gVirtualPS) {
gVirtualPS->SetLineColor(color);
gVirtualPS->SetLineStyle(style);
gVirtualPS->SetLineWidth(lwidth);
}
}
void TPad::SetAttMarkerPS(Color_t color, Style_t style, Size_t msize)
{
if (gVirtualPS) {
gVirtualPS->SetMarkerColor(color);
gVirtualPS->SetMarkerStyle(style);
gVirtualPS->SetMarkerSize(msize);
}
}
void TPad::SetAttTextPS(Int_t align, Float_t angle, Color_t color, Style_t font, Float_t tsize)
{
if (gVirtualPS) {
gVirtualPS->SetTextAlign(align);
gVirtualPS->SetTextAngle(angle);
gVirtualPS->SetTextColor(color);
gVirtualPS->SetTextFont(font);
if (font%10 > 2) {
Float_t wh = (Float_t)gPad->XtoPixel(gPad->GetX2());
Float_t hh = (Float_t)gPad->YtoPixel(gPad->GetY1());
Float_t dy;
if (wh < hh) {
dy = AbsPixeltoX(Int_t(tsize)) - AbsPixeltoX(0);
tsize = dy/(fX2-fX1);
} else {
dy = AbsPixeltoY(0) - AbsPixeltoY(Int_t(tsize));
tsize = dy/(fY2-fY1);
}
}
gVirtualPS->SetTextSize(tsize);
}
}
Bool_t TPad::HasCrosshair() const
{
return (Bool_t)GetCrosshair();
}
Int_t TPad::GetCrosshair() const
{
if (this == (TPad*)fCanvas)
return fCrosshair;
return fCanvas ? fCanvas->GetCrosshair() : 0;
}
void TPad::SetCrosshair(Int_t crhair)
{
fCrosshair = crhair;
fCrosshairPos = 0;
if (this != (TPad*)fCanvas) fCanvas->SetCrosshair(crhair);
}
void TPad::SetMaxPickDistance(Int_t maxPick)
{
fgMaxPickDistance = maxPick;
}
void TPad::SetToolTipText(const char *text, Long_t delayms)
{
if (fTip) {
DeleteToolTip(fTip);
fTip = 0;
}
if (text && strlen(text))
fTip = CreateToolTip((TBox*)0, text, delayms);
}
void TPad::SetVertical(Bool_t vert)
{
if (vert) ResetBit(kHori);
else SetBit(kHori);
}
void TPad::Streamer(TBuffer &b)
{
UInt_t R__s, R__c;
Int_t nch, nobjects;
Float_t single;
TObject *obj;
if (b.IsReading()) {
Version_t v = b.ReadVersion(&R__s, &R__c);
if (v > 5) {
if (!gPad) gPad = new TCanvas(GetName());
TPad *padsave = (TPad*)gPad;
fMother = (TPad*)gPad;
if (fMother) fCanvas = fMother->GetCanvas();
gPad = this;
fPixmapID = -1;
gReadLevel++;
gROOT->SetReadingObject(kTRUE);
b.ReadClassBuffer(TPad::Class(), this, v, R__s, R__c);
fModified = kTRUE;
fPadPointer = 0;
gReadLevel--;
if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
gROOT->SetReadingObject(kFALSE);
gPad = padsave;
return;
}
if (v < 5) {
if (v < 3) {
b.ReadVersion();
b.ReadVersion();
b.ReadVersion();
TObject::Streamer(b);
TAttLine::Streamer(b);
TAttFill::Streamer(b);
b >> single; fX1 = single;
b >> single; fY1 = single;
b >> single; fX2 = single;
b >> single; fY2 = single;
b >> fBorderSize;
b >> fBorderMode;
TAttPad::Streamer(b);
} else {
TVirtualPad::Streamer(b);
TAttPad::Streamer(b);
b >> single; fX1 = single;
b >> single; fY1 = single;
b >> single; fX2 = single;
b >> single; fY2 = single;
b >> fBorderSize;
b >> fBorderMode;
}
b >> fLogx;
b >> fLogy;
b >> fLogz;
b >> single; fXtoAbsPixelk = single;
b >> single; fXtoPixelk = single;
b >> single; fXtoPixel = single;
b >> single; fYtoAbsPixelk = single;
b >> single; fYtoPixelk = single;
b >> single; fYtoPixel = single;
b >> single; fUtoAbsPixelk = single;
b >> single; fUtoPixelk = single;
b >> single; fUtoPixel = single;
b >> single; fVtoAbsPixelk = single;
b >> single; fVtoPixelk = single;
b >> single; fVtoPixel = single;
b >> single; fAbsPixeltoXk = single;
b >> single; fPixeltoXk = single;
b >> single; fPixeltoX = single;
b >> single; fAbsPixeltoYk = single;
b >> single; fPixeltoYk = single;
b >> single; fPixeltoY = single;
b >> single; fXlowNDC = single;
b >> single; fYlowNDC = single;
b >> single; fWNDC = single;
b >> single; fHNDC = single;
b >> single; fAbsXlowNDC = single;
b >> single; fAbsYlowNDC = single;
b >> single; fAbsWNDC = single;
b >> single; fAbsHNDC = single;
b >> single; fUxmin = single;
b >> single; fUymin = single;
b >> single; fUxmax = single;
b >> single; fUymax = single;
} else {
TVirtualPad::Streamer(b);
TAttPad::Streamer(b);
b >> fX1;
b >> fY1;
b >> fX2;
b >> fY2;
b >> fBorderSize;
b >> fBorderMode;
b >> fLogx;
b >> fLogy;
b >> fLogz;
b >> fXtoAbsPixelk;
b >> fXtoPixelk;
b >> fXtoPixel;
b >> fYtoAbsPixelk;
b >> fYtoPixelk;
b >> fYtoPixel;
b >> fUtoAbsPixelk;
b >> fUtoPixelk;
b >> fUtoPixel;
b >> fVtoAbsPixelk;
b >> fVtoPixelk;
b >> fVtoPixel;
b >> fAbsPixeltoXk;
b >> fPixeltoXk;
b >> fPixeltoX;
b >> fAbsPixeltoYk;
b >> fPixeltoYk;
b >> fPixeltoY;
b >> fXlowNDC;
b >> fYlowNDC;
b >> fWNDC;
b >> fHNDC;
b >> fAbsXlowNDC;
b >> fAbsYlowNDC;
b >> fAbsWNDC;
b >> fAbsHNDC;
b >> fUxmin;
b >> fUymin;
b >> fUxmax;
b >> fUymax;
}
if (!gPad) gPad = new TCanvas(GetName());
if (gReadLevel == 0) fMother = (TPad*)gROOT->GetSelectedPad();
else fMother = (TPad*)gPad;
if (!fMother) fMother = (TPad*)gPad;
if (fMother) fCanvas = fMother->GetCanvas();
gPad = fMother;
fPixmapID = -1;
gReadLevel++;
gROOT->SetReadingObject(kTRUE);
fPrimitives = new TList;
b >> nobjects;
if (nobjects > 0) {
TPad *padsav = (TPad*)gPad;
gPad = this;
char drawoption[64];
for (Int_t i = 0; i < nobjects; i++) {
b >> obj;
b >> nch;
b.ReadFastArray(drawoption,nch);
fPrimitives->AddLast(obj, drawoption);
gPad = this;
}
gPad = padsav;
}
gReadLevel--;
gROOT->SetReadingObject(kFALSE);
if (v > 3) {
b >> fExecs;
}
fName.Streamer(b);
fTitle.Streamer(b);
b >> fPadPaint;
fModified = kTRUE;
b >> fGridx;
b >> fGridy;
b >> fFrame;
b >> fView;
if (v < 5) {
b >> single; fTheta = single;
b >> single; fPhi = single;
} else {
b >> fTheta;
b >> fPhi;
}
fPadPointer = 0;
b >> fNumber;
b >> fAbsCoord;
if (v > 1) {
b >> fTickx;
b >> fTicky;
} else {
fTickx = fTicky = 0;
}
if (gReadLevel == 0 && IsA() == TPad::Class()) ResizePad();
b.CheckByteCount(R__s, R__c, TPad::IsA());
} else {
b.WriteClassBuffer(TPad::Class(),this);
}
}
void TPad::UseCurrentStyle()
{
if (gStyle->IsReading()) {
SetFillColor(gStyle->GetPadColor());
SetBottomMargin(gStyle->GetPadBottomMargin());
SetTopMargin(gStyle->GetPadTopMargin());
SetLeftMargin(gStyle->GetPadLeftMargin());
SetRightMargin(gStyle->GetPadRightMargin());
fBorderSize = gStyle->GetPadBorderSize();
fBorderMode = gStyle->GetPadBorderMode();
fGridx = gStyle->GetPadGridX();
fGridy = gStyle->GetPadGridY();
fTickx = gStyle->GetPadTickX();
fTicky = gStyle->GetPadTickY();
fLogx = gStyle->GetOptLogx();
fLogy = gStyle->GetOptLogy();
fLogz = gStyle->GetOptLogz();
} else {
gStyle->SetPadColor(GetFillColor());
gStyle->SetPadBottomMargin(GetBottomMargin());
gStyle->SetPadTopMargin(GetTopMargin());
gStyle->SetPadLeftMargin(GetLeftMargin());
gStyle->SetPadRightMargin(GetRightMargin());
gStyle->SetPadBorderSize(GetBorderSize());
gStyle->SetPadBorderMode(GetBorderMode());
gStyle->SetPadGridX(fGridx);
gStyle->SetPadGridY(fGridy);
gStyle->SetPadTickX(fTickx);
gStyle->SetPadTickY(fTicky);
gStyle->SetOptLogx (fLogx);
gStyle->SetOptLogy (fLogy);
gStyle->SetOptLogz (fLogz);
}
if (!fPrimitives) fPrimitives = new TList;
TIter next(GetListOfPrimitives());
TObject *obj;
while ((obj = next())) {
obj->UseCurrentStyle();
}
TPaveText *title = (TPaveText*)FindObject("title");
if (title) {
if (gStyle->IsReading()) {
title->SetFillColor(gStyle->GetTitleFillColor());
title->SetTextFont(gStyle->GetTitleFont(""));
title->SetTextColor(gStyle->GetTitleTextColor());
title->SetBorderSize(gStyle->GetTitleBorderSize());
if (!gStyle->GetOptTitle()) delete title;
} else {
gStyle->SetTitleFillColor(title->GetFillColor());
gStyle->SetTitleFont(title->GetTextFont());
gStyle->SetTitleTextColor(title->GetTextColor());
gStyle->SetTitleBorderSize(title->GetBorderSize());
}
}
if (fFrame) fFrame->UseCurrentStyle();
if (gStyle->IsReading()) Modified();
}
TObject *TPad::WaitPrimitive(const char *pname, const char *emode)
{
if (strlen(emode)) gROOT->SetEditorMode(emode);
if (gROOT->GetEditorMode() == 0 && strlen(pname) > 2) gROOT->SetEditorMode(&pname[1]);
if (!fPrimitives) fPrimitives = new TList;
gSystem->ProcessEvents();
TObject *oldlast = gPad->GetListOfPrimitives()->Last();
TObject *obj = 0;
Bool_t testlast = kFALSE;
Bool_t hasname = strlen(pname) > 0;
if (strlen(pname) == 0 && strlen(emode) == 0) testlast = kTRUE;
if (testlast) gROOT->SetEditorMode();
while (!gSystem->ProcessEvents() && gROOT->GetSelectedPad()) {
if (gROOT->GetEditorMode() == 0) {
if (hasname) {
obj = FindObject(pname);
if (obj) return obj;
}
if (testlast) {
obj = gPad->GetListOfPrimitives()->Last();
if (obj != oldlast) return obj;
Int_t event = GetEvent();
if (event == kButton1Double || event == kKeyPress) {
fCanvas->HandleInput((EEventType)-1,0,0);
return 0;
}
}
}
gSystem->Sleep(10);
}
return 0;
}
TObject *TPad::CreateToolTip(const TBox *box, const char *text, Long_t delayms)
{
if (gPad->IsBatch()) return 0;
return (TObject*)gROOT->ProcessLineFast(Form("new TGToolTip((TBox*)0x%lx,\"%s\",%d)",
(Long_t)box,text,(Int_t)delayms));
}
void TPad::DeleteToolTip(TObject *tip)
{
if (!tip) return;
gROOT->ProcessLineFast(Form("delete (TGToolTip*)0x%lx", (Long_t)tip));
}
void TPad::ResetToolTip(TObject *tip)
{
if (!tip) return;
gROOT->ProcessLineFast(Form("((TGToolTip*)0x%lx)->Reset((TPad*)0x%lx)",
(Long_t)tip,(Long_t)this));
}
void TPad::CloseToolTip(TObject *tip)
{
if (!tip) return;
gROOT->ProcessLineFast(Form("((TGToolTip*)0x%lx)->Hide()",(Long_t)tip));
}
void TPad::x3d(Option_t *type)
{
::Info("TPad::x3d()", "Fn is depreciated - use TPad::GetViewer3D() instead");
if (!type || !type[0]) {
type = "x3d";
}
GetViewer3D(type);
}
TVirtualViewer3D *TPad::GetViewer3D(Option_t *type)
{
Bool_t validType = kFALSE;
if ( (!type || !type[0] || (strstr(type, "gl") && !strstr(type, "ogl"))) && !fCanvas->UseGL())
type = "pad";
if (type && type[0]) {
TPluginHandler *h;
if ((h = gPluginMgr->FindHandler("TVirtualViewer3D", type)))
validType = kTRUE;
}
if (!validType) {
if (fViewer3D) {
return fViewer3D;
}
else {
type = "pad";
}
}
TVirtualViewer3D *newViewer = 0;
Bool_t createdExternal = kFALSE;
if (fGLDevice != -1) {
gGLManager->DeleteGLContext(fGLDevice);
fCanvas->SetSelected(this);
fGLDevice = -1;
fCopyGLDevice = kFALSE;
fEmbeddedGL = kFALSE;
}
if (!strstr(type,"pad")) {
newViewer = TVirtualViewer3D::Viewer3D(this,type);
if (!newViewer) {
Warning("TPad::CreateViewer3D", "Cannot create 3D viewer of type: %s", type);
return fViewer3D;
}
if (strstr(type, "gl") && !strstr(type, "ogl"))
fEmbeddedGL = kTRUE, fCopyGLDevice = kTRUE, Modified();
else
createdExternal = kTRUE;
} else
newViewer = new TViewer3DPad(*this);
delete fViewer3D;
fViewer3D = newViewer;
if (createdExternal) {
Modified();
Update();
}
return fViewer3D;
}
void TPad::ReleaseViewer3D(Option_t * )
{
fViewer3D = 0;
}
Int_t TPad::GetGLDevice()
{
if (fGLDevice == -1 && gGLManager && fCanvas->UseGL()) {
Int_t borderSize = fBorderSize > 0 ? fBorderSize : 2;
UInt_t w = TMath::Abs(XtoPixel(fX2) - XtoPixel(fX1)) - 2 * borderSize;
UInt_t h = TMath::Abs(YtoPixel(fY2) - YtoPixel(fY1)) - 2 * borderSize;
Int_t px = 0, py = 0;
XYtoAbsPixel(fX1, fY2, px, py);
px += borderSize, py += borderSize;
fGLDevice = gGLManager->CreateGLContext(fCanvas->GetCanvasID());
if (fGLDevice != -1 && !gGLManager->AttachOffScreenDevice(fGLDevice, px, py, w, h)) {
gGLManager->DeleteGLContext(fGLDevice);
fGLDevice = -1;
}
}
return fGLDevice;
}
Last change: Tue Oct 7 11:41:29 2008
Last generated: 2008-10-07 11:41
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.