00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Riostream.h"
00013 #include "TROOT.h"
00014 #include "TPave.h"
00015 #include "TStyle.h"
00016 #include "TVirtualPad.h"
00017 #include "TClass.h"
00018 #include "TMath.h"
00019
00020
00021 ClassImp(TPave)
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 TPave::TPave(): TBox()
00040 {
00041
00042
00043 fBorderSize = 4;
00044 fOption = "brNDC";
00045 fName = "";
00046 fInit = 1;
00047 fCornerRadius = 0;
00048 fX1NDC = 0;
00049 fY1NDC = 0;
00050 fX2NDC = 0;
00051 fY2NDC = 0;
00052 SetFillColor(gStyle->GetFillColor());
00053 SetFillStyle(gStyle->GetFillStyle());
00054 SetLineColor(gStyle->GetLineColor());
00055 SetLineStyle(gStyle->GetLineStyle());
00056 fShadowColor = GetLineColor();
00057 }
00058
00059
00060
00061 TPave::TPave(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
00062 Int_t bordersize ,Option_t *option)
00063 :TBox(x1,y1,x2,y2)
00064 {
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 fBorderSize = bordersize;
00083 fOption = option;
00084 fName = "";
00085 fInit = 0;
00086 fCornerRadius = 0;
00087 if (fOption == "NDC" || fOption == "ndc") fOption = "brNDC";
00088
00089 SetFillColor(gStyle->GetFillColor());
00090 SetFillStyle(gStyle->GetFillStyle());
00091 SetLineColor(gStyle->GetLineColor());
00092 SetLineStyle(gStyle->GetLineStyle());
00093 SetName((char*)ClassName());
00094 fShadowColor = GetLineColor();
00095 }
00096
00097
00098
00099 TPave::~TPave()
00100 {
00101
00102 }
00103
00104
00105
00106 TPave::TPave(const TPave &pave) : TBox(pave)
00107 {
00108
00109
00110 fX1NDC = 0.;
00111 fY1NDC = 0.;
00112 fX2NDC = 0.;
00113 fY2NDC = 0.;
00114 fCornerRadius = 0.;
00115 fBorderSize = 0;
00116 fInit = 0;
00117 fShadowColor = 0;
00118
00119 ((TPave&)pave).TPave::Copy(*this);
00120 }
00121
00122
00123
00124 void TPave::ConvertNDCtoPad()
00125 {
00126
00127
00128 Double_t dpx = gPad->GetX2() - gPad->GetX1();
00129 Double_t dpy = gPad->GetY2() - gPad->GetY1();
00130 Double_t xp1 = gPad->GetX1();
00131 Double_t yp1 = gPad->GetY1();
00132
00133
00134
00135
00136 if (!fInit) {
00137 fInit = 1;
00138 if (fOption.Contains("NDC")) {
00139 fX1NDC = fX1;
00140 fY1NDC = fY1;
00141 fX2NDC = fX2;
00142 fY2NDC = fY2;
00143 fX1 = xp1 + fX1NDC*dpx;
00144 fY1 = yp1 + fY1NDC*dpy;
00145 fX2 = xp1 + fX2NDC*dpx;
00146 fY2 = yp1 + fY2NDC*dpy;
00147 } else {
00148 if (gPad->GetLogx()) {
00149 if (fX1 > 0) fX1 = TMath::Log10(fX1);
00150 if (fX2 > 0) fX2 = TMath::Log10(fX2);
00151 }
00152 if (gPad->GetLogy()) {
00153 if (fY1 > 0) fY1 = TMath::Log10(fY1);
00154 if (fY2 > 0) fY2 = TMath::Log10(fY2);
00155 }
00156 fX1NDC = (fX1-xp1)/dpx;
00157 fY1NDC = (fY1-yp1)/dpy;
00158 fX2NDC = (fX2-xp1)/dpx;
00159 fY2NDC = (fY2-yp1)/dpy;
00160 }
00161 } else {
00162 fX1 = xp1 + fX1NDC*dpx;
00163 fY1 = yp1 + fY1NDC*dpy;
00164 fX2 = xp1 + fX2NDC*dpx;
00165 fY2 = yp1 + fY2NDC*dpy;
00166 }
00167 }
00168
00169
00170
00171 void TPave::Copy(TObject &obj) const
00172 {
00173
00174
00175 TBox::Copy(obj);
00176 ((TPave&)obj).fX1NDC = fX1NDC;
00177 ((TPave&)obj).fY1NDC = fY1NDC;
00178 ((TPave&)obj).fX2NDC = fX2NDC;
00179 ((TPave&)obj).fY2NDC = fY2NDC;
00180 ((TPave&)obj).fBorderSize = fBorderSize;
00181 ((TPave&)obj).fInit = fInit;
00182 ((TPave&)obj).fOption = fOption;
00183 ((TPave&)obj).fName = fName;
00184 ((TPave&)obj).fCornerRadius= fCornerRadius;
00185 ((TPave&)obj).fShadowColor = fShadowColor;
00186 }
00187
00188
00189 Int_t TPave::DistancetoPrimitive(Int_t px, Int_t py)
00190 {
00191
00192
00193
00194
00195
00196
00197 Int_t pxl, pyl, pxt, pyt;
00198 Int_t px1 = gPad->XtoAbsPixel(fX1);
00199 Int_t py1 = gPad->YtoAbsPixel(fY1);
00200 Int_t px2 = gPad->XtoAbsPixel(fX2);
00201 Int_t py2 = gPad->YtoAbsPixel(fY2);
00202 if (px1 < px2) {pxl = px1; pxt = px2;}
00203 else {pxl = px2; pxt = px1;}
00204 if (py1 < py2) {pyl = py1; pyt = py2;}
00205 else {pyl = py2; pyt = py1;}
00206
00207
00208 if ( (px >= pxl && px <= pxt) && (py >= pyl && py <= pyt) ) return 0;
00209 else return 9999;
00210 }
00211
00212
00213
00214
00215 void TPave::Draw(Option_t *option)
00216 {
00217
00218
00219 Option_t *opt;
00220 if (option && strlen(option)) opt = option;
00221 else opt = GetOption();
00222
00223 AppendPad(opt);
00224 }
00225
00226
00227
00228 void TPave::DrawPave(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
00229 Int_t bordersize ,Option_t *option)
00230 {
00231
00232
00233 TPave *newpave = new TPave(x1,y1,x2,y2,bordersize,option);
00234 newpave->SetBit(kCanDelete);
00235 newpave->AppendPad(option);
00236 }
00237
00238
00239
00240 void TPave::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00241 {
00242
00243
00244
00245
00246 if (!gPad->IsEditable()) return;
00247
00248 TBox::ExecuteEvent(event, px, py);
00249
00250
00251 Double_t dpx = gPad->GetX2() - gPad->GetX1();
00252 Double_t dpy = gPad->GetY2() - gPad->GetY1();
00253 Double_t xp1 = gPad->GetX1();
00254 Double_t yp1 = gPad->GetY1();
00255 fX1NDC = (fX1-xp1)/dpx;
00256 fY1NDC = (fY1-yp1)/dpy;
00257 fX2NDC = (fX2-xp1)/dpx;
00258 fY2NDC = (fY2-yp1)/dpy;
00259
00260
00261
00262 if (event == kButton1Double) {
00263 if (TestBit(kNameIsAction)) gROOT->ProcessLine(GetName());
00264 }
00265 }
00266
00267
00268
00269 void TPave::ls(Option_t *) const
00270 {
00271
00272
00273 TROOT::IndentLevel();
00274 printf("OBJ: %s\t%s \tX1= %f Y1=%f X2=%f Y2=%f\n",IsA()->GetName(),GetName(),fX1,fY1,fX2,fY2);
00275 }
00276
00277
00278
00279 void TPave::Paint(Option_t *option)
00280 {
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 ConvertNDCtoPad();
00295
00296 PaintPave(fX1, fY1, fX2, fY2, fBorderSize, option);
00297 }
00298
00299
00300
00301 void TPave::PaintPave(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
00302 Int_t bordersize ,Option_t *option)
00303 {
00304
00305
00306 Double_t x[7],y[7];
00307 TString opt = option;
00308 opt.ToLower();
00309
00310 if (opt.Contains("arc")) {
00311 PaintPaveArc(x1,y1,x2,y2,bordersize,option);
00312 return;
00313 }
00314
00315
00316 if (opt.Length() == 0) opt ="br";
00317 Int_t fillstyle = GetFillStyle();
00318 Int_t fillcolor = GetFillColor();
00319 Int_t shadowcolor = GetShadowColor();
00320
00321
00322 if (fBorderSize <= 0 && fillstyle <= 0) return;
00323 TBox::PaintBox(x1,y1,x2,y2);
00324 if (fBorderSize <= 0) return;
00325 if (fBorderSize == 1) {
00326 gPad->PaintLine(x1,y1,x2,y1);
00327 gPad->PaintLine(x2,y1,x2,y2);
00328 gPad->PaintLine(x2,y2,x1,y2);
00329 gPad->PaintLine(x1,y2,x1,y1);
00330 return;
00331 }
00332
00333 Double_t wy = gPad->PixeltoY(0) - gPad->PixeltoY(fBorderSize);
00334 Double_t wx = gPad->PixeltoX(fBorderSize) - gPad->PixeltoX(0);
00335 Int_t mode = 0;
00336
00337 if (opt.Contains("t") && opt.Contains("r")) {
00338 mode = 1;
00339 x[0] = x1 + 1.5*wx; y[0] = y2;
00340 x[1] = x[0]; y[1] = y2 + wy;
00341 x[2] = x2 + wx; y[2] = y[1];
00342 x[3] = x[2]; y[3] = y1 + 1.5*wy;
00343 x[4] = x2; y[4] = y[3];
00344 x[5] = x[4]; y[5] = y2;
00345 }
00346
00347 if (opt.Contains("t") && opt.Contains("l")) {
00348 mode = 2;
00349 x[0] = x1 - wx; y[0] = y1 + 1.5*wy;
00350 x[1] = x[0]; y[1] = y2 + wy;
00351 x[2] = x2 - 1.5*wx; y[2] = y[1];
00352 x[3] = x[2]; y[3] = y2;
00353 x[4] = x1; y[4] = y[3];
00354 x[5] = x1; y[5] = y[0];
00355 }
00356
00357 if (opt.Contains("b") && opt.Contains("r")) {
00358 mode = 3;
00359 x[0] = x1 + 1.5*wx; y[0] = y1;
00360 x[1] = x[0]; y[1] = y1 - wy;
00361 x[2] = x2 + wx; y[2] = y[1];
00362 x[3] = x[2]; y[3] = y2 - 1.5*wy;
00363 x[4] = x2; y[4] = y[3];
00364 x[5] = x[4]; y[5] = y1;
00365 }
00366
00367 if (opt.Contains("b") && opt.Contains("l")) {
00368 mode = 4;
00369 x[0] = x1 - wx; y[0] = y2 - 1.5*wy;
00370 x[1] = x[0]; y[1] = y1 - wy;
00371 x[2] = x2 - 1.5*wx; y[2] = y[1];
00372 x[3] = x[2]; y[3] = y1;
00373 x[4] = x1; y[4] = y[3];
00374 x[5] = x[4]; y[5] = y[0];
00375 }
00376 if (!mode) return;
00377 for (Int_t i=0;i<6;i++) {
00378 if (x[i] < gPad->GetX1()) x[i] = gPad->GetX1();
00379 if (x[i] > gPad->GetX2()) x[i] = gPad->GetX2();
00380 if (y[i] < gPad->GetY1()) y[i] = gPad->GetY1();
00381 if (y[i] > gPad->GetY2()) y[i] = gPad->GetY2();
00382 }
00383 x[6] = x[0]; y[6] = y[0];
00384 SetFillStyle(1001);
00385 SetFillColor(shadowcolor);
00386 TAttFill::Modify();
00387 gPad->PaintFillArea(6,x,y);
00388 x[0] = x1; y[0] = y1;
00389 x[1] = x1; y[1] = y2;
00390 x[2] = x2; y[2] = y2;
00391 x[3] = x2; y[3] = y1;
00392 x[4] = x1; y[4] = y1;
00393 gPad->PaintPolyLine(5,x,y);
00394 SetFillStyle(fillstyle);
00395 SetFillColor(fillcolor);
00396 }
00397
00398
00399
00400 void TPave::PaintPaveArc(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
00401 Int_t, Option_t *option)
00402 {
00403
00404
00405 const Int_t kNPARC = 10;
00406 Double_t x[4*kNPARC+10], y[4*kNPARC+10];
00407 Double_t px[4*kNPARC+10], py[4*kNPARC+10];
00408 Int_t i;
00409 TString opt = option;
00410 opt.ToLower();
00411 if (opt.Length() == 0) opt ="br";
00412 Int_t fillstyle = GetFillStyle();
00413 Int_t fillcolor = GetFillColor();
00414 Int_t shadowcolor = GetShadowColor();
00415
00416 static Double_t cosa[kNPARC], sina[kNPARC];
00417 static Bool_t done = kFALSE;
00418 if (!done) {
00419 done = kTRUE;
00420 Double_t dtheta = 0.5*3.141592/(kNPARC+1);
00421 Double_t theta = 0;
00422 for (i=0;i<kNPARC;i++) {
00423 theta += dtheta;
00424 cosa[i] = TMath::Cos(theta);
00425 sina[i] = TMath::Sin(theta);
00426 }
00427 }
00428 Int_t px1 = gPad->XtoAbsPixel(x1);
00429 Int_t py1 = gPad->YtoAbsPixel(y1);
00430 Int_t px2 = gPad->XtoAbsPixel(x2);
00431 Int_t py2 = gPad->YtoAbsPixel(y2);
00432
00433 Double_t rad = fCornerRadius;
00434 if (rad > 0 && rad < 0.5) rad = fCornerRadius;
00435 else rad = 0.2;
00436 Double_t r = rad*TMath::Abs(py1-py2);
00437 if (r > 0.5*TMath::Abs(px2-px1)) r = 0.5*TMath::Abs(px2-px1);
00438 if (r == 0) r = 1;
00439
00440
00441 px[0] = px2; py[0] = py1 - r;
00442 px[1] = px2; py[1] = py2 + r;
00443 Int_t np = 2;
00444 for (i=0;i<kNPARC;i++) {
00445 px[np] = px2 - r + r*cosa[i];
00446 py[np] = py2 + r - r*sina[i];
00447 np++;
00448 }
00449 px[np] = px2 - r; py[np] = py2;
00450 px[np+1] = px1 + r; py[np+1] = py2;
00451 np += 2;
00452 for (i=kNPARC-1;i>=0;i--) {
00453 px[np] = px1 + r - r*cosa[i];
00454 py[np] = py2 + r - r*sina[i];
00455 np++;
00456 }
00457 px[np] = px1; py[np] = py2 + r;
00458 px[np+1] = px1; py[np+1] = py1 - r;
00459 np += 2;
00460 for (i=0;i<kNPARC;i++) {
00461 px[np] = px1 + r - r*cosa[i];
00462 py[np] = py1 - r + r*sina[i];
00463 np++;
00464 }
00465 px[np] = px1 + r; py[np] = py1;
00466 px[np+1] = px2 - r; py[np+1] = py1;
00467 np += 2;
00468 for (i=kNPARC-1;i>=0;i--) {
00469 px[np] = px2 - r + r*cosa[i];
00470 py[np] = py1 - r + r*sina[i];
00471 np++;
00472 }
00473 px[np] = px[0]; py[np] =py[0];
00474 TAttLine::Modify();
00475 TAttFill::Modify();
00476 for (i=0;i<=np;i++) {
00477 x[i] = gPad->AbsPixeltoX(Int_t(px[i]));
00478 y[i] = gPad->AbsPixeltoY(Int_t(py[i]));
00479 }
00480 gPad->PaintFillArea(np , x, y);
00481 gPad->PaintPolyLine(np+1, x, y);
00482
00483
00484 if (fBorderSize <= 0) return;
00485
00486 Double_t wy = fBorderSize;
00487 Double_t wx = fBorderSize;
00488
00489 if (opt.Contains("tr")) {
00490 px[0] = px2; py[0] = py1 - r;
00491 px[1] = px2; py[1] = py2 + r;
00492 np = 2;
00493 for (i=0;i<kNPARC;i++) {
00494 px[np] = px2 - r + r*cosa[i];
00495 py[np] = py2 + r - r*sina[i];
00496 np++;
00497 }
00498 px[np] = px2 - r; py[np] = py2;
00499 px[np+1] = px1 + r; py[np+1] = py2;
00500 px[np+2] = px1 + r; py[np+2] = py2 - wy;
00501 px[np+3] = px2 - r; py[np+3] = py2 - wy;
00502 np += 4;
00503 for (i=kNPARC-1;i>=0;i--) {
00504 px[np] = px2 - r + r*cosa[i]*(1+wx/r);
00505 py[np] = py2 + r - r*sina[i]*(1+wy/r);
00506 np++;
00507 }
00508 px[np] = px2 + wx; py[np] = py2 + r;
00509 px[np+1] = px2 + wx; py[np+1] = py1 - r;
00510 px[np+2] = px[0]; py[np+2] = py[0];
00511 np += 3;
00512 }
00513
00514 if (opt.Contains("tl")) {
00515 px[0] = px2 - r; py[0] = py2;
00516 px[1] = px1 + r; py[1] = py2;
00517 np = 2;
00518 for (i=kNPARC-1;i>=0;i--) {
00519 px[np] = px1 + r - r*cosa[i];
00520 py[np] = py2 + r - r*sina[i];
00521 np++;
00522 }
00523 px[np] = px1; py[np] = py2 + r;
00524 px[np+1] = px1; py[np+1] = py1 - r;
00525 px[np+2] = px1 - wx; py[np+2] = py1 - r;
00526 px[np+3] = px1 - wx; py[np+3] = py2 + r;
00527 np += 4;
00528 for (i=0;i<kNPARC;i++) {
00529 px[np] = px1 + r - r*cosa[i]*(1+wx/r);
00530 py[np] = py2 + r - r*sina[i]*(1+wy/r);
00531 np++;
00532 }
00533 px[np] = px1 + r; py[np] = py2 - wy;
00534 px[np+1] = px2 - r; py[np+1] = py2 - wy;
00535 px[np+2] = px[0]; py[np+2] = y[0];
00536 np += 3;
00537 }
00538
00539 if (opt.Contains("br")) {
00540 px[0] = px1 + r; py[0] = py1;
00541 px[1] = px2 - r; py[1] = py1;
00542 np = 2;
00543 for (i=kNPARC-1;i>=0;i--) {
00544 px[np] = px2 - r + r*cosa[i];
00545 py[np] = py1 - r + r*sina[i];
00546 np++;
00547 }
00548 px[np] = px2; py[np] = py1 - r;
00549 px[np+1] = px2; py[np+1] = py2 + r;
00550 px[np+2] = px2 + wx; py[np+2] = py2 + r;
00551 px[np+3] = px2 + wx; py[np+3] = py1 - r;
00552 np += 4;
00553 for (i=0;i<kNPARC;i++) {
00554 px[np] = px2 - r + r*cosa[i]*(1+wx/r);
00555 py[np] = py1 - r + r*sina[i]*(1+wy/r);
00556 np++;
00557 }
00558 px[np] = px2 - r; py[np] = py1 + wy;
00559 px[np+1] = px[0]; py[np+1] = py[0] + wy;
00560 px[np+2] = px[0]; py[np+2] = py[0];
00561 np += 3;
00562 }
00563
00564 if (opt.Contains("bl")) {
00565 px[0] = px1; py[0] = py2 + r;
00566 px[1] = px1; py[1] = py1 - r;
00567 np = 2;
00568 for (i=0;i<kNPARC;i++) {
00569 px[np] = px1 + r - r*cosa[i];
00570 py[np] = py1 + r - r*sina[i];
00571 np++;
00572 }
00573 px[np] = px1 + r; py[np] = py1;
00574 px[np+1] = px2 - r; py[np+1] = py1;
00575 px[np+2] = px2 - r; py[np+2] = py1 + wy;
00576 px[np+3] = px1 + r; py[np+3] = py1 + wy;
00577 np += 4;
00578 for (i=kNPARC-1;i>=0;i--) {
00579 px[np] = px1 + r - r*cosa[i]*(1+wx/r);
00580 py[np] = py1 - r + r*sina[i]*(1+wy/r);
00581 np++;
00582 }
00583 px[np] = px1 - wx; py[np] = py1 - r;
00584 px[np+1] = px1 - wx; py[np+1] = py[0];
00585 px[np+2] = px[0]; py[np+2] = py[0];
00586 np += 3;
00587 }
00588 SetFillStyle(1001);
00589 SetFillColor(shadowcolor);
00590 TAttFill::Modify();
00591 for (i=0;i<=np;i++) {
00592 x[i] = gPad->AbsPixeltoX(Int_t(px[i]));
00593 y[i] = gPad->AbsPixeltoY(Int_t(py[i]));
00594 }
00595 gPad->PaintFillArea(np,x,y);
00596 SetFillStyle(fillstyle);
00597 SetFillColor(fillcolor);
00598 }
00599
00600
00601
00602 void TPave::Print(Option_t *option) const
00603 {
00604
00605
00606 TBox::Print(option);
00607 }
00608
00609
00610
00611 void TPave::SavePrimitive(ostream &out, Option_t * )
00612 {
00613
00614
00615 char quote = '"';
00616 if (gROOT->ClassSaved(TPave::Class())) {
00617 out<<" ";
00618 } else {
00619 out<<" TPave *";
00620 }
00621 if (fOption.Contains("NDC")) {
00622 out<<"pave = new TPave("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
00623 <<","<<fBorderSize<<","<<quote<<fOption<<quote<<");"<<endl;
00624 } else {
00625 out<<"pave = new TPave("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2
00626 <<","<<fBorderSize<<","<<quote<<fOption<<quote<<");"<<endl;
00627 }
00628 if (strcmp(GetName(),"TPave")) {
00629 out<<" pave->SetName("<<quote<<GetName()<<quote<<");"<<endl;
00630 }
00631 if (fCornerRadius) {
00632 out<<" pave->SetCornerRadius("<<fCornerRadius<<");"<<endl;
00633 }
00634 SaveFillAttributes(out,"pave",19,1001);
00635 SaveLineAttributes(out,"pave",1,1,1);
00636 out<<" pave->Draw();"<<endl;
00637 }
00638
00639
00640
00641 void TPave::Streamer(TBuffer &R__b)
00642 {
00643
00644
00645 if (R__b.IsReading()) {
00646 UInt_t R__s, R__c;
00647 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00648 if (R__v > 1) {
00649 R__b.ReadClassBuffer(TPave::Class(), this, R__v, R__s, R__c);
00650 return;
00651 }
00652
00653 TBox::Streamer(R__b);
00654 Float_t x1ndc,y1ndc,x2ndc,y2ndc,rad;
00655 R__b >> x1ndc; fX1NDC = x1ndc;
00656 R__b >> y1ndc; fY1NDC = y1ndc;
00657 R__b >> x2ndc; fX2NDC = x2ndc;
00658 R__b >> y2ndc; fY2NDC = y2ndc;
00659 R__b >> fBorderSize;
00660 R__b >> fInit;
00661 R__b >> rad; fCornerRadius = rad;
00662 fOption.Streamer(R__b);
00663 fName.Streamer(R__b);
00664 R__b.CheckByteCount(R__s, R__c, TPave::IsA());
00665
00666
00667 } else {
00668 R__b.WriteClassBuffer(TPave::Class(),this);
00669 }
00670 }