72 TPaveText::TPaveText(): TPave(), TAttText()
104 TPaveText::TPaveText(Double_t x1, Double_t y1,Double_t x2, Double_t y2, Option_t *option)
105 :TPave(x1,y1,x2,y2,4,option), TAttText(22,0,gStyle->GetTextColor(),gStyle->GetTextFont(),0)
115 TPaveText::~TPaveText()
117 if (!TestBit(kNotDeleted))
return;
118 if (fLines) fLines->Delete();
126 TPaveText::TPaveText(
const TPaveText &pavetext) : TPave(), TAttText()
128 TBufferFile b(TBuffer::kWrite);
129 TPaveText *p = (TPaveText*)(&pavetext);
132 b.SetBufferOffset(0);
140 TPaveText& TPaveText::operator=(
const TPaveText& pt)
143 TPave::operator=(pt);
144 TAttText::operator=(pt);
146 fLongest=pt.fLongest;
156 TBox *TPaveText::AddBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
158 if (!gPad->IsEditable())
return 0;
159 TBox *newbox =
new TBox(x1,y1,x2,y2);
161 if (!fLines) fLines =
new TList;
169 TLine *TPaveText::AddLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
171 if (!gPad->IsEditable())
return 0;
172 TLine *newline =
new TLine(x1,y1,x2,y2);
174 if (!fLines) fLines =
new TList;
175 fLines->Add(newline);
182 TText *TPaveText::AddText(Double_t x1, Double_t y1,
const char *text)
184 TLatex *newtext =
new TLatex(x1,y1,text);
185 newtext->SetTextAlign(0);
186 newtext->SetTextColor(0);
187 newtext->SetTextFont(0);
188 newtext->SetTextSize(0);
189 Int_t nch = strlen(text);
190 if (nch > fLongest) fLongest = nch;
192 if (!fLines) fLines =
new TList;
193 fLines->Add(newtext);
200 TText *TPaveText::AddText(
const char *text)
202 return AddText(0,0,text);
208 void TPaveText::Clear(Option_t *)
218 void TPaveText::DeleteText()
220 if (!gPad->IsEditable())
return;
222 Double_t ymouse, yobj;
223 TObject *obj = GetObject(ymouse, yobj);
225 if (!obj->InheritsFrom(TText::Class()))
return;
233 void TPaveText::Draw(Option_t *option)
236 if (option && strlen(option)) opt = option;
237 else opt = GetOption();
245 void TPaveText::DrawFile(
const char *filename, Option_t *option)
255 void TPaveText::EditText()
257 if (!gPad->IsEditable())
return;
258 Double_t ymouse, yobj;
259 TObject *obj = GetObject(ymouse, yobj);
261 if (!obj->InheritsFrom(TText::Class()))
return;
262 TText *text = (TText*)obj;
263 gROOT->SetSelectedPrimitive(text);
264 gROOT->ProcessLine(Form(
"((TCanvas*)0x%lx)->SetSelected((TObject*)0x%lx)",
265 (ULong_t)gPad->GetCanvas(), (ULong_t)text));
266 gROOT->ProcessLine(Form(
"((TCanvas*)0x%lx)->Selected((TVirtualPad*)0x%lx,(TObject*)0x%lx,1)",
267 (ULong_t)gPad->GetCanvas(), (ULong_t)gPad, (ULong_t)text));
268 text->SetTextAttributes();
274 TText *TPaveText::GetLine(Int_t number)
const
279 while ((line = (TText*) next())) {
280 if (nlines == number)
return line;
289 TText *TPaveText::GetLineWith(
const char *text)
const
293 while ((line = (TText*) next())) {
294 if (strstr(line->GetTitle(),text))
return line;
302 TObject *TPaveText::GetObject(Double_t &ymouse, Double_t &yobj)
const
304 if (!fLines)
return 0;
305 Int_t nlines = GetSize();
306 if (nlines == 0)
return 0;
310 ymouse = gPad->AbsPixeltoY(gPad->GetEventY());
311 Double_t yspace = (fY2 - fY1)/Double_t(nlines);
313 Double_t ytext = fY2 + 0.5*yspace;
324 while ((line = (TObject*) next())) {
326 if (line->IsA() == TLine::Class()) {
327 linel = (TLine*)line;
328 y1 = linel->GetY1();
if (y1 == 0) y1 = ytext;
else y1 = fY1 + y1*dy;
329 if (TMath::Abs(y1-ymouse) < 0.2*yspace) {yobj = y1;
return line;}
333 if (line->IsA() == TBox::Class()) {
335 y1 = lineb->GetY1();
if (y1 == 0) y1 = ytext;
else y1 = fY1 + y1*dy;
336 if (TMath::Abs(y1-ymouse) < 0.4*yspace) {yobj = y1;
return line;}
340 if (line->InheritsFrom(TText::Class())) {
341 linet = (TText*)line;
343 Double_t yl = linet->GetY();
344 Short_t talign = linet->GetTextAlign();
345 if (talign == 0) talign = GetTextAlign();
346 if (yl > 0 && yl <1) {
349 valign = linet->GetTextAlign()%10;
351 if (valign == 1) y = ytext -0.5*yspace;
352 if (valign == 3) y = ytext +0.5*yspace;
354 if (TMath::Abs(y-ymouse) < 0.5*yspace) {yobj = y;
return line;}
363 Int_t TPaveText::GetSize()
const
368 while ((line = (TObject*) next())) {
369 if (line->InheritsFrom(TText::Class())) nlines++;
377 void TPaveText::InsertLine()
379 if (!gPad->IsEditable())
return;
380 Double_t ymouse=0, yobj;
381 TObject *obj = GetObject(ymouse, yobj);
382 Double_t yline = (ymouse-fY1)/(fY2-fY1);
383 TLine *newline = AddLine(0,yline,0,yline);
385 fLines->Remove(newline);
386 if (yobj < ymouse) fLines->AddBefore(obj,newline);
387 else fLines->AddAfter(obj,newline);
394 void TPaveText::InsertText(
const char *text)
396 if (!gPad->IsEditable())
return;
397 Double_t ymouse, yobj;
398 TObject *obj = GetObject(ymouse, yobj);
399 TText *newtext = AddText(0,0,text);
401 fLines->Remove(newtext);
402 if (yobj < ymouse) fLines->AddBefore(obj,newtext);
403 else fLines->AddAfter(obj,newtext);
410 void TPaveText::Paint(Option_t *option)
413 TPave::ConvertNDCtoPad();
414 TPave::PaintPave(fX1,fY1,fX2,fY2,GetBorderSize(),option);
415 PaintPrimitives(kPaveText);
421 void TPaveText::PaintPrimitives(Int_t mode)
424 Double_t dx = fX2 - fX1;
425 Double_t dy = fY2 - fY1;
426 Double_t textsize = GetTextSize();
427 Int_t nlines = GetSize();
428 if (nlines == 0) nlines = 5;
432 Double_t x1,y1,x2,y2;
435 Float_t margin = fMargin*dx;
436 Double_t yspace = dy/Double_t(nlines);
437 Double_t textsave = textsize;
442 Double_t longest = 0;
445 textsize = 0.85*yspace/(y2 - y1);
446 while ((line = (TObject*) next())) {
447 if (line->IsA() == TLatex::Class()) {
448 latex = (TLatex*)line;
449 Float_t tangle = latex->GetTextAngle();
450 if (latex->GetTextSize() != 0)
continue;
451 Style_t tfont = latex->GetTextFont();
452 if (tfont == 0) latex->SetTextFont(GetTextFont());
453 latex->SetTextSize(textsize);
454 w = latex->GetXsize();
455 latex->SetTextSize(0);
456 latex->SetTextAngle(tangle);
457 if (w > longest) longest = w;
458 latex->SetTextFont(tfont);
461 if (longest > 0.92*dx) textsize *= 0.92*dx/longest;
462 if (mode == kDiamond) textsize *= 0.66;
463 SetTextSize(textsize);
465 Double_t ytext = fY2 + 0.5*yspace;
474 while ((line = (TObject*) next())) {
476 if (line->IsA() == TLine::Class()) {
477 linel = (TLine*)line;
478 x1 = linel->GetX1();
if (x1 == 0) x1 = fX1;
else x1 = fX1 + x1*dx;
479 x2 = linel->GetX2();
if (x2 == 0) x2 = fX2;
else x2 = fX1 + x2*dx;
480 y1 = linel->GetY1();
if (y1 == 0) y1 = ytext;
else y1 = fY1 + y1*dy;
481 y2 = linel->GetY2();
if (y2 == 0) y2 = ytext;
else y2 = fY1 + y2*dy;
482 linel->PaintLine(x1,y1,x2,y2);
486 if (line->IsA() == TBox::Class()) {
489 if (x1) x1 = fX1 + x1*dx;
490 else x1 = fX1 + gPad->PixeltoX(1) - gPad->PixeltoX(0);
492 if (x2) x2 = fX1 + x2*dx;
494 y1 = lineb->GetY1();
if (y1 == 0) y1 = ytext;
else y1 = fY1 + y1*dy;
495 y2 = lineb->GetY2();
if (y2 == 0) y2 = ytext;
else y2 = fY1 + y2*dy;
496 lineb->PaintBox(x1,y1,x2,y2);
500 if (line->IsA() == TText::Class()) {
501 linet = (TText*)line;
503 Double_t xl = linet->GetX();
504 Double_t yl = linet->GetY();
505 Short_t talign = linet->GetTextAlign();
506 Color_t tcolor = linet->GetTextColor();
507 Style_t tfont = linet->GetTextFont();
508 Size_t tsize = linet->GetTextSize();
509 if (talign == 0) linet->SetTextAlign(GetTextAlign());
510 if (tcolor == 0) linet->SetTextColor(GetTextColor());
511 if (tfont == 0) linet->SetTextFont(GetTextFont());
512 if (tsize == 0) linet->SetTextSize(GetTextSize());
513 if (xl > 0 && xl <1) {
516 halign = linet->GetTextAlign()/10;
517 if (halign == 1) xtext = fX1 + margin;
518 if (halign == 2) xtext = 0.5*(fX1+fX2);
519 if (halign == 3) xtext = fX2 - margin;
521 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
522 linet->PaintText(xtext,ytext,linet->GetTitle());
523 linet->SetTextAlign(talign);
524 linet->SetTextColor(tcolor);
525 linet->SetTextFont(tfont);
526 linet->SetTextSize(tsize);
529 if (line->IsA() == TLatex::Class()) {
530 latex = (TLatex*)line;
532 Double_t xl = latex->GetX();
533 Double_t yl = latex->GetY();
534 Short_t talign = latex->GetTextAlign();
535 Color_t tcolor = latex->GetTextColor();
536 Style_t tfont = latex->GetTextFont();
537 Size_t tsize = latex->GetTextSize();
538 if (talign == 0) latex->SetTextAlign(GetTextAlign());
539 if (tcolor == 0) latex->SetTextColor(GetTextColor());
540 if (tfont == 0) latex->SetTextFont(GetTextFont());
541 if (tsize == 0) latex->SetTextSize(GetTextSize());
542 if (xl > 0 && xl <1) {
545 halign = latex->GetTextAlign()/10;
546 if (halign == 1) xtext = fX1 + margin;
547 if (halign == 2) xtext = 0.5*(fX1+fX2);
548 if (halign == 3) xtext = fX2 - margin;
550 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
551 latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
552 latex->GetTextSize(),
554 latex->SetTextAlign(talign);
555 latex->SetTextColor(tcolor);
556 latex->SetTextFont(tfont);
557 latex->SetTextSize(tsize);
563 SetTextSize(textsave);
566 if (fLabel.Length() > 0) {
567 dy = gPad->GetY2() - gPad->GetY1();
572 TPaveLabel *title =
new TPaveLabel(x1,y1,x2,y2,fLabel.Data(),GetDrawOption());
573 title->SetFillColor(GetFillColor());
574 title->SetTextColor(GetTextColor());
575 title->SetTextFont(GetTextFont());
584 void TPaveText::Print(Option_t *option)
const
586 TPave::Print(option);
587 if (fLines) fLines->Print();
597 void TPaveText::ReadFile(
const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
602 TString opt = option;
603 if (!opt.Contains(
"+")) {
609 Int_t nch = strlen(filename);
610 if (nch == 0)
return;
612 char *fname = StrDup(filename);
613 if (fname[nch-1] ==
';') { nch--; fname[nch]=0;}
615 std::ifstream file(fname,std::ios::in);
617 Error(
"ReadFile",
"illegal file name");
622 const int linesize = 255;
623 char currentline[linesize];
624 char *ss, *sclose, *s= 0;
628 file.getline(currentline,linesize);
629 if (file.eof())
break;
630 if (kline >= fromline && kline < fromline+nlines) {
632 if (strstr(s,
"+SetText")) {
634 sclose = strstr(ss,
")");
635 if (!sclose)
continue;
637 lastline = (TText*)fLines->Last();
638 if (!lastline)
continue;
639 if (strstr(ss,
"Color(")) {
640 sscanf(ss+6,
"%d",&ival);
641 lastline->SetTextColor(ival);
644 if (strstr(ss,
"Align(")) {
645 sscanf(ss+6,
"%d",&ival);
646 lastline->SetTextAlign(ival);
649 if (strstr(ss,
"Font(")) {
650 sscanf(ss+5,
"%d",&ival);
651 lastline->SetTextFont(ival);
654 if (strstr(ss,
"Size(")) {
655 sscanf(ss+5,
"%f",&val);
656 lastline->SetTextSize(val);
659 if (strstr(ss,
"Angle(")) {
660 sscanf(ss+6,
"%f",&val);
661 lastline->SetTextAngle(val);
676 void TPaveText::SaveLines(std::ostream &out,
const char *name, Bool_t saved)
679 Int_t nlines = GetSize();
680 if (nlines == 0)
return;
690 Bool_t savedlt = kFALSE;
691 Bool_t savedt = kFALSE;
692 Bool_t savedl = kFALSE;
693 Bool_t savedb = kFALSE;
695 while ((line = (TObject*) next())) {
697 if (line->IsA() == TLine::Class()) {
698 linel = (TLine*)line;
699 if (saved || savedl) {
705 out<<name<<
"_Line = "<<name<<
"->AddLine("
706 <<linel->GetX1()<<
","<<linel->GetY1()<<
","<<linel->GetX2()<<
","<<linel->GetY2()<<
");"<<std::endl;
707 if (linel->GetLineColor() != 1) {
708 if (linel->GetLineColor() > 228) {
709 TColor::SaveColor(out, linel->GetLineColor());
710 out<<
" "<<name<<
"_Line->SetLineColor(ci);" << std::endl;
712 out<<
" "<<name<<
"_Line->SetLineColor("<<linel->GetLineColor()<<
");"<<std::endl;
714 if (linel->GetLineStyle() != 1) {
715 out<<
" "<<name<<
"_Line->SetLineStyle("<<linel->GetLineStyle()<<
");"<<std::endl;
717 if (linel->GetLineWidth() != 1) {
718 out<<
" "<<name<<
"_Line->SetLineWidth("<<linel->GetLineWidth()<<
");"<<std::endl;
723 if (line->IsA() == TBox::Class()) {
725 if (saved || savedb) {
731 out<<name<<
"_Box = "<<name<<
"->AddBox("
732 <<lineb->GetX1()<<
","<<lineb->GetY1()<<
","<<lineb->GetX2()<<
","<<lineb->GetY2()<<
");"<<std::endl;
733 if (lineb->GetFillColor() != 18) {
734 if (lineb->GetFillColor() > 228) {
735 TColor::SaveColor(out, lineb->GetFillColor());
736 out<<
" "<<name<<
"_Box->SetFillColor(ci);" << std::endl;
738 out<<
" "<<name<<
"_Box->SetFillColor("<<lineb->GetFillColor()<<
");"<<std::endl;
740 if (lineb->GetFillStyle() != 1001) {
741 out<<
" "<<name<<
"_Box->SetFillStyle("<<lineb->GetFillStyle()<<
");"<<std::endl;
743 if (lineb->GetLineColor() != 1) {
744 if (lineb->GetLineColor() > 228) {
745 TColor::SaveColor(out, lineb->GetLineColor());
746 out<<
" "<<name<<
"_Box->SetLineColor(ci);" << std::endl;
748 out<<
" "<<name<<
"_Box->SetLineColor("<<lineb->GetLineColor()<<
");"<<std::endl;
750 if (lineb->GetLineStyle() != 1) {
751 out<<
" "<<name<<
"_Box->SetLineStyle("<<lineb->GetLineStyle()<<
");"<<std::endl;
753 if (lineb->GetLineWidth() != 1) {
754 out<<
" "<<name<<
"_Box->SetLineWidth("<<lineb->GetLineWidth()<<
");"<<std::endl;
759 if (line->IsA() == TText::Class()) {
760 linet = (TText*)line;
761 if (saved || savedt) {
767 if (!linet->GetX() && !linet->GetY()) {
768 TString s = linet->GetTitle();
769 s.ReplaceAll(
"\"",
"\\\"");
770 out<<name<<
"_Text = "<<name<<
"->AddText("
771 <<quote<<s.Data()<<quote<<
");"<<std::endl;
773 out<<name<<
"_Text = "<<name<<
"->AddText("
774 <<linet->GetX()<<
","<<linet->GetY()<<
","<<quote<<linet->GetTitle()<<quote<<
");"<<std::endl;
776 if (linet->GetTextColor()) {
777 if (linet->GetTextColor() > 228) {
778 TColor::SaveColor(out, linet->GetTextColor());
779 out<<
" "<<name<<
"_Text->SetTextColor(ci);" << std::endl;
781 out<<
" "<<name<<
"_Text->SetTextColor("<<linet->GetTextColor()<<
");"<<std::endl;
783 if (linet->GetTextFont()) {
784 out<<
" "<<name<<
"_Text->SetTextFont("<<linet->GetTextFont()<<
");"<<std::endl;
786 if (linet->GetTextSize()) {
787 out<<
" "<<name<<
"_Text->SetTextSize("<<linet->GetTextSize()<<
");"<<std::endl;
789 if (linet->GetTextAngle() != GetTextAngle()) {
790 out<<
" "<<name<<
"_Text->SetTextAngle("<<linet->GetTextAngle()<<
");"<<std::endl;
792 if (linet->GetTextAlign()) {
793 out<<
" "<<name<<
"_Text->SetTextAlign("<<linet->GetTextAlign()<<
");"<<std::endl;
797 if (line->IsA() == TLatex::Class()) {
798 latex = (TLatex*)line;
799 if (saved || savedlt) {
805 if (!latex->GetX() && !latex->GetY()) {
806 TString sl = latex->GetTitle();
807 sl.ReplaceAll(
"\"",
"\\\"");
808 out<<name<<
"_LaTex = "<<name<<
"->AddText("
809 <<quote<<sl.Data()<<quote<<
");"<<std::endl;
811 out<<name<<
"_LaTex = "<<name<<
"->AddText("
812 <<latex->GetX()<<
","<<latex->GetY()<<
","<<quote<<latex->GetTitle()<<quote<<
");"<<std::endl;
814 if (latex->GetTextColor()) {
815 if (latex->GetTextColor() > 228) {
816 TColor::SaveColor(out, latex->GetTextColor());
817 out<<
" "<<name<<
"_LaTex->SetTextColor(ci);" << std::endl;
819 out<<
" "<<name<<
"_LaTex->SetTextColor("<<latex->GetTextColor()<<
");"<<std::endl;
821 if (latex->GetTextFont()) {
822 out<<
" "<<name<<
"_LaTex->SetTextFont("<<latex->GetTextFont()<<
");"<<std::endl;
824 if (latex->GetTextSize()) {
825 out<<
" "<<name<<
"_LaTex->SetTextSize("<<latex->GetTextSize()<<
");"<<std::endl;
827 if (latex->GetTextAngle() != GetTextAngle()) {
828 out<<
" "<<name<<
"_LaTex->SetTextAngle("<<latex->GetTextAngle()<<
");"<<std::endl;
830 if (latex->GetTextAlign()) {
831 out<<
" "<<name<<
"_LaTex->SetTextAlign("<<latex->GetTextAlign()<<
");"<<std::endl;
840 void TPaveText::SavePrimitive(std::ostream &out, Option_t * )
843 Bool_t saved = gROOT->ClassSaved(TPaveText::Class());
848 out<<
" "<<ClassName()<<
" *";
850 if (fOption.Contains(
"NDC")) {
851 out<<
"pt = new "<<ClassName()<<
"("<<fX1NDC<<
","<<fY1NDC<<
","<<fX2NDC<<
","<<fY2NDC
852 <<
","<<quote<<fOption<<quote<<
");"<<std::endl;
854 out<<
"pt = new "<<ClassName()<<
"("<<gPad->PadtoX(fX1)<<
","<<gPad->PadtoY(fY1)<<
","<<gPad->PadtoX(fX2)<<
","<<gPad->PadtoY(fY2)
855 <<
","<<quote<<fOption<<quote<<
");"<<std::endl;
857 if (strcmp(GetName(),
"TPave")) {
858 out<<
" pt->SetName("<<quote<<GetName()<<quote<<
");"<<std::endl;
860 if (fLabel.Length() > 0) {
861 out<<
" pt->SetLabel("<<quote<<fLabel<<quote<<
");"<<std::endl;
863 if (fBorderSize != 4) {
864 out<<
" pt->SetBorderSize("<<fBorderSize<<
");"<<std::endl;
866 SaveFillAttributes(out,
"pt",19,1001);
867 SaveLineAttributes(out,
"pt",1,1,1);
868 SaveTextAttributes(out,
"pt",22,0,1,62,0);
869 SaveLines(out,
"pt",saved);
870 out<<
" pt->Draw();"<<std::endl;
879 void TPaveText::SetAllWith(
const char *text, Option_t *option, Double_t value)
885 while ((line = (TText*) next())) {
886 if (strstr(line->GetTitle(),text)) {
887 if (opt ==
"align") line->SetTextAlign(Int_t(value));
888 if (opt ==
"color") line->SetTextColor(Int_t(value));
889 if (opt ==
"font") line->SetTextFont(Int_t(value));
890 if (opt ==
"size") line->SetTextSize(value);
891 if (opt ==
"angle") line->SetTextAngle(value);
899 void TPaveText::Streamer(TBuffer &R__b)
901 if (R__b.IsReading()) {
903 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
905 R__b.ReadClassBuffer(TPaveText::Class(),
this, R__v, R__s, R__c);
909 TPave::Streamer(R__b);
910 TAttText::Streamer(R__b);
911 if (R__v > 1) fLabel.Streamer(R__b);
915 R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
919 R__b.WriteClassBuffer(TPaveText::Class(),
this);
926 void TPaveText::UseCurrentStyle()
928 if (gStyle->IsReading()) {
929 SetTextFont(gStyle->GetTextFont());
930 SetTextSize(gStyle->GetTextSize());
931 SetTextColor(gStyle->GetTextColor());
933 gStyle->SetTextColor(GetTextColor());
934 gStyle->SetTextFont(GetTextFont());
935 gStyle->SetTextSize(GetTextSize());