Logo ROOT  
Reference Guide
TPaveText.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 20/10/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <cstring>
13#include <cstdlib>
14#include <cstdio>
15#include <iostream>
16#include <fstream>
17
18#include "TBufferFile.h"
19#include "TROOT.h"
20#include "TStyle.h"
21#include "TPaveText.h"
22#include "TPaveLabel.h"
23#include "TVirtualPad.h"
24#include "TMath.h"
25#include "TLatex.h"
26#include "TError.h"
27#include "TColor.h"
28#include "TLine.h"
29
31
32
33/** \class TPaveText
34\ingroup BasicGraphics
35
36A Pave (see TPave) with text, lines or/and boxes inside.
37
38Line (and boxes) are positioned in the pave using coordinates relative to
39the pave (%).
40
41The text lines are added in order using the AddText method. Also line separators
42can be added, in order too, using the AddLine method.
43
44AddText returns a TText corresponding to the line added to the pave. This
45return value can be used to modify the text attributes.
46
47Once the TPaveText is build the text of each line can be retrieved using
48GetLine or GetLineWith as a TText wich is useful to modify the text attributes
49of a line.
50
51Example:
52Begin_Macro(source)
53../../../tutorials/graphics/pavetext.C
54End_Macro
55
56GetListOfLines can also be used to retrieve all the lines in the TPaveText as
57a TList:
58
59Begin_Macro(source)
60{
61 TPaveText *t = new TPaveText(.05,.3,.95,.6);
62 t->AddText("This line is blue"); ((TText*)t->GetListOfLines()->Last())->SetTextColor(kBlue);
63 t->AddText("This line is red"); ((TText*)t->GetListOfLines()->Last())->SetTextColor(kRed);
64 t->Draw();
65}
66End_Macro
67
68*/
69
70////////////////////////////////////////////////////////////////////////////////
71/// pavetext default constructor.
72
74{
75 fLines = 0;
76 fMargin = 0.05;
77 fLongest = 0;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// PaveText normal constructor.
82///
83/// A PaveText is a Pave with several lines of text
84///
85/// - option = "TR" Top and Right shadows are drawn.
86/// - option = "TL" Top and Left shadows are drawn.
87/// - option = "BR" Bottom and Right shadows are drawn.
88/// - option = "BL" Bottom and Left shadows are drawn.
89///
90/// If none of these four above options is specified the default the
91/// option "BR" will be used to draw the border. To produces a pave
92/// without any border it is enough to specify the option "NB" (no border).
93///
94/// - option = "NDC" x1,y1,x2,y2 are given in NDC
95/// - option = "ARC" corners are rounded
96///
97/// In case of option "ARC", the corner radius is specified
98/// via TPave::SetCornerRadius(rad) where rad is given in percent
99/// of the pave height (default value is 0.2).
100///
101/// The individual text items are entered via AddText
102/// By default, text items inherits from the default pavetext AttText.
103/// A title can be added later to this pavetext via TPaveText::SetLabel.
104
106 :TPave(x1,y1,x2,y2,4,option), TAttText(22,0,gStyle->GetTextColor(),gStyle->GetTextFont(),0)
107{
108 fLines = new TList;
109 fMargin = 0.05;
110 fLongest = 0;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// pavetext default destructor.
115
117{
118 if (ROOT::Detail::HasBeenDeleted(this)) return;
119 if (fLines) fLines->Delete();
120 delete fLines;
121 fLines = nullptr;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// pavetext copy constructor.
126
127TPaveText::TPaveText(const TPaveText &pavetext) : TPave(pavetext), TAttText(pavetext)
128{
129 fLabel = pavetext.fLabel;
130 fLongest = pavetext.fLongest;
131 fMargin = pavetext.fMargin;
132 if (pavetext.fLines)
133 fLines = (TList *) pavetext.fLines->Clone();
134}
135
136////////////////////////////////////////////////////////////////////////////////
137///assignment operator
138
140{
141 if(this != &pt) {
144 fLabel = pt.fLabel;
147 if (fLines) {
148 fLines->Delete();
149 delete fLines;
150 fLines = nullptr;
151 }
152 if (pt.fLines)
153 fLines = (TList *)pt.fLines->Clone();
154 }
155 return *this;
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Add a new graphics box to this pavetext.
160
162{
163 if (!gPad->IsEditable()) return 0;
164 TBox *newbox = new TBox(x1,y1,x2,y2);
165
166 if (!fLines) fLines = new TList;
167 fLines->Add(newbox);
168 return newbox;
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Add a new graphics line to this pavetext.
173
175{
176 if (!gPad->IsEditable()) return 0;
177 TLine *newline = new TLine(x1,y1,x2,y2);
178
179 if (!fLines) fLines = new TList;
180 fLines->Add(newline);
181 return newline;
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Add a new Text line to this pavetext at given coordinates.
186
188{
189 TLatex *newtext = new TLatex(x1,y1,text);
190 newtext->SetTextAlign(0);
191 newtext->SetTextColor(0);
192 newtext->SetTextFont(0);
193 newtext->SetTextSize(0);
194 Int_t nch = text ? strlen(text) : 0;
195 if (nch > fLongest) fLongest = nch;
196
197 if (!fLines) fLines = new TList;
198 fLines->Add(newtext);
199 return newtext;
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Add a new Text line to this pavetext.
204
206{
207 return AddText(0,0,text);
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Clear all lines in this pavetext.
212
214{
215 if (!fLines) return;
216 fLines->Delete();
217 fLongest = 0;
218}
219
220////////////////////////////////////////////////////////////////////////////////
221/// Delete text at the mouse position.
222
224{
225 if (!gPad->IsEditable()) return;
226 if (!fLines) return;
227 Double_t ymouse, yobj;
228 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
229 if (!obj) return;
230 if (!obj->InheritsFrom(TText::Class())) return;
231 fLines->Remove(obj);
232 delete obj;
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Draw this pavetext with its current attributes.
237
239{
240 Option_t *opt;
241 if (option && strlen(option)) opt = option;
242 else opt = GetOption();
243
244 AppendPad(opt);
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Draw lines in filename in this pavetext.
249
251{
253
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Edit text at the mouse position.
259
261{
262 if (!gPad->IsEditable()) return;
263 Double_t ymouse, yobj;
264 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
265 if (!obj) return;
266 if (!obj->InheritsFrom(TText::Class())) return;
267 TText *text = (TText*)obj;
268 gROOT->SetSelectedPrimitive(text);
269 gROOT->ProcessLine(Form("((TCanvas*)0x%zx)->SetSelected((TObject*)0x%zx)",
270 (size_t)gPad->GetCanvas(), (size_t)text));
271 gROOT->ProcessLine(Form("((TCanvas*)0x%zx)->Selected((TVirtualPad*)0x%zx,(TObject*)0x%zx,1)",
272 (size_t)gPad->GetCanvas(), (size_t)gPad, (size_t)text));
273 text->SetTextAttributes();
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Get Pointer to line number in this pavetext.
278/// Ignore any TLine or TBox, they are not accounted
279
281{
282 TIter next(fLines);
283 Int_t nlines = 0;
284 while (auto obj = next()) {
285 if (!obj->InheritsFrom(TText::Class()))
286 continue;
287
288 if (nlines++ == number)
289 return (TText *) obj;
290 }
291 return nullptr;
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Get Pointer to first containing string text in this pavetext.
296/// Ignore any TLine or TBox, they are not accounted
297
299{
300 if (!text)
301 return nullptr;
302 TIter next(fLines);
303 while (auto obj = next()) {
304 if (obj->InheritsFrom(TText::Class()) && strstr(obj->GetTitle(), text))
305 return (TText *) obj;
306 }
307 return nullptr;
308}
309
310////////////////////////////////////////////////////////////////////////////////
311/// Get object pointed by the mouse in this pavetext.
312
314{
315 if (!fLines) return nullptr;
316 Int_t nlines = GetSize();
317 if (nlines == 0) return nullptr;
318
319 // Evaluate text size as a function of the number of lines
320
321 ymouse = gPad->AbsPixeltoY(gPad->GetEventY());
322 Double_t yspace = (fY2 - fY1)/Double_t(nlines);
323 Double_t y1,y,dy;
324 Double_t ytext = fY2 + 0.5*yspace;
325 Int_t valign;
326
327 // Iterate over all lines
328 // Copy pavetext attributes to line attributes if line attributes not set
329 dy = fY2 - fY1;
330 TIter next(fLines);
331 while (auto line = next()) {
332 // Next primitive is a line
333 if (line->IsA() == TLine::Class()) {
334 auto linel = (TLine *)line;
335 y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
336 if (TMath::Abs(y1-ymouse) < 0.2*yspace) {yobj = y1; return line;}
337 continue;
338 }
339 // Next primitive is a box
340 if (line->IsA() == TBox::Class()) {
341 auto lineb = (TBox *)line;
342 y1 = lineb->GetY1();
343 if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
344 if (TMath::Abs(y1-ymouse) < 0.4*yspace) {yobj = y1; return line;}
345 continue;
346 }
347 // Next primitive is a text
349 auto linet = (TText *)line;
350 ytext -= yspace;
351 Double_t yl = linet->GetY();
352 if (yl > 0 && yl <1) {
353 ytext = fY1 + yl*dy;
354 }
355 valign = linet->GetTextAlign()%10;
356 y = ytext;
357 if (valign == 1) y = ytext -0.5*yspace;
358 if (valign == 3) y = ytext +0.5*yspace;
359
360 if (TMath::Abs(y-ymouse) < 0.5*yspace) {yobj = y; return line;}
361 }
362 }
363 return nullptr;
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// return number of text lines (ignoring TLine, etc)
368
370{
371 Int_t nlines = 0;
372 TIter next(fLines);
373 while (auto line = next()) {
374 if (line->InheritsFrom(TText::Class())) nlines++;
375 }
376 return nlines;
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Add a new line at the mouse position.
381
383{
384 if (!gPad->IsEditable()) return;
385 Double_t ymouse=0, yobj;
386 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
387 Double_t yline = (ymouse-fY1)/(fY2-fY1);
388 TLine *newline = AddLine(0,yline,0,yline);
389 if (obj) {
390 fLines->Remove(newline); //remove line from last position
391 if (yobj < ymouse) fLines->AddBefore(obj,newline);
392 else fLines->AddAfter(obj,newline);
393 }
394}
395
396////////////////////////////////////////////////////////////////////////////////
397/// Add a new Text line at the mouse position.
398
400{
401 if (!gPad->IsEditable()) return;
402 Double_t ymouse, yobj;
403 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
404 TText *newtext = AddText(0,0,text); //create new text object
405 if (obj) {
406 fLines->Remove(newtext); //remove text from last position
407 if (yobj < ymouse) fLines->AddBefore(obj,newtext); //insert new text at right position
408 else fLines->AddAfter(obj,newtext); //insert new text at right position
409 }
410}
411
412////////////////////////////////////////////////////////////////////////////////
413/// Paint this pavetext with its current attributes.
414
416{
417 // Draw the pave
421}
422
423////////////////////////////////////////////////////////////////////////////////
424/// Paint list of primitives in this pavetext.
425
427{
428 if (!fLines) return;
429 Double_t dx = fX2 - fX1;
430 Double_t dy = fY2 - fY1;
432 Int_t nlines = GetSize();
433 if (nlines == 0) nlines = 5;
434
435 // Evaluate text size as a function of the number of lines
436
438 y1 = gPad->GetY1();
439 y2 = gPad->GetY2();
440 Float_t margin = fMargin*dx;
441 Double_t yspace = dy/Double_t(nlines);
442 Double_t textsave = textsize;
443 TObject *line;
444 TText *linet;
445 TLatex *latex;
446 TIter next(fLines);
447 Double_t longest = 0;
448 Double_t w;
449 if (textsize == 0) {
450 textsize = 0.85*yspace/(y2 - y1);
451 while ((line = (TObject*) next())) {
452 if (line->IsA() == TLatex::Class()) {
453 latex = (TLatex*)line;
454 Float_t tangle = latex->GetTextAngle();
455 if (latex->GetTextSize() != 0) continue;
456 Style_t tfont = latex->GetTextFont();
457 if (tfont == 0) latex->SetTextFont(GetTextFont());
458 latex->SetTextSize(textsize);
459 w = latex->GetXsize();
460 latex->SetTextSize(0);
461 latex->SetTextAngle(tangle); //text angle was redefined in GetXsize !
462 if (w > longest) longest = w;
463 latex->SetTextFont(tfont);
464 }
465 }
466 if (longest > 0.92*dx) textsize *= 0.92*dx/longest;
467 if (mode == kDiamond) textsize *= 0.66;
469 }
470 Double_t ytext = fY2 + 0.5*yspace;
471 Double_t xtext = 0;
472 Int_t halign;
473
474 // Iterate over all lines
475 // Copy pavetext attributes to line attributes if line attributes not set
476 TLine *linel;
477 TBox *lineb;
478 next.Reset();
479 while ((line = (TObject*) next())) {
480 // Next primitive is a line
481 if (line->IsA() == TLine::Class()) {
482 linel = (TLine*)line;
483 x1 = linel->GetX1(); if (x1 == 0) x1 = fX1; else x1 = fX1 + x1*dx;
484 x2 = linel->GetX2(); if (x2 == 0) x2 = fX2; else x2 = fX1 + x2*dx;
485 y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
486 y2 = linel->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
487 linel->PaintLine(x1,y1,x2,y2);
488 continue;
489 }
490 // Next primitive is a box
491 if (line->IsA() == TBox::Class()) {
492 lineb = (TBox*)line;
493 x1 = lineb->GetX1();
494 if (x1) x1 = fX1 + x1*dx;
495 else x1 = fX1 + gPad->PixeltoX(1) - gPad->PixeltoX(0);
496 x2 = lineb->GetX2();
497 if (x2) x2 = fX1 + x2*dx;
498 else x2 = fX2;
499 y1 = lineb->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
500 y2 = lineb->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
501 lineb->PaintBox(x1,y1,x2,y2);
502 continue;
503 }
504 // Next primitive is a text
505 if (line->IsA() == TText::Class()) {
506 linet = (TText*)line;
507 ytext -= yspace;
508 Double_t xl = linet->GetX();
509 Double_t yl = linet->GetY();
510 Short_t talign = linet->GetTextAlign();
511 Color_t tcolor = linet->GetTextColor();
512 Style_t tfont = linet->GetTextFont();
513 Size_t tsize = linet->GetTextSize();
514 if (talign == 0) linet->SetTextAlign(GetTextAlign());
515 if (tcolor == 0) linet->SetTextColor(GetTextColor());
516 if (tfont == 0) linet->SetTextFont(GetTextFont());
517 if (tsize == 0) linet->SetTextSize(GetTextSize());
518 if (xl > 0 && xl <1) {
519 xtext = fX1 + xl*dx;
520 } else {
521 halign = linet->GetTextAlign()/10;
522 if (halign == 1) xtext = fX1 + margin;
523 if (halign == 2) xtext = 0.5*(fX1+fX2);
524 if (halign == 3) xtext = fX2 - margin;
525 }
526 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
527 linet->PaintText(xtext,ytext,linet->GetTitle());
528 linet->SetTextAlign(talign);
529 linet->SetTextColor(tcolor);
530 linet->SetTextFont(tfont);
531 linet->SetTextSize(tsize);
532 }
533 // Next primitive is a Latex text
534 if (line->IsA() == TLatex::Class()) {
535 latex = (TLatex*)line;
536 ytext -= yspace;
537 Double_t xl = latex->GetX();
538 Double_t yl = latex->GetY();
539 Short_t talign = latex->GetTextAlign();
540 Color_t tcolor = latex->GetTextColor();
541 Style_t tfont = latex->GetTextFont();
542 Size_t tsize = latex->GetTextSize();
543 if (talign == 0) latex->SetTextAlign(GetTextAlign());
544 if (tcolor == 0) latex->SetTextColor(GetTextColor());
545 if (tfont == 0) latex->SetTextFont(GetTextFont());
546 if (tsize == 0) latex->SetTextSize(GetTextSize());
547 if (xl > 0 && xl <1) {
548 xtext = fX1 + xl*dx;
549 } else {
550 halign = latex->GetTextAlign()/10;
551 if (halign == 1) xtext = fX1 + margin;
552 if (halign == 2) xtext = 0.5*(fX1+fX2);
553 if (halign == 3) xtext = fX2 - margin;
554 }
555 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
556 latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
557 latex->GetTextSize(),
558 latex->GetTitle());
559 latex->SetTextAlign(talign);
560 latex->SetTextColor(tcolor);
561 latex->SetTextFont(tfont);
562 latex->SetTextSize(tsize);
563 latex->SetX(xl); // PaintLatex modifies fX and fY
564 latex->SetY(yl);
565 }
566 }
567
568 SetTextSize(textsave);
569
570 // if a label create & paint a pavetext title
571 if (fLabel.Length() > 0) {
572 dy = gPad->GetY2() - gPad->GetY1();
573 x1 = fX1 + 0.25*dx;
574 x2 = fX2 - 0.25*dx;
575 y1 = fY2 - 0.02*dy;
576 y2 = fY2 + 0.02*dy;
578 title.SetFillColor(GetFillColor());
579 title.SetTextColor(GetTextColor());
580 title.SetTextFont(GetTextFont());
581 title.Paint();
582 }
583}
584
585////////////////////////////////////////////////////////////////////////////////
586/// Dump this pavetext with its attributes.
587
589{
591 if (fLines) fLines->Print();
592}
593
594////////////////////////////////////////////////////////////////////////////////
595/// Read lines of filename in this pavetext.
596///
597/// Read from line number fromline a total of nlines
598///
599/// Note that this function changes the default text alignment to left/center
600
601void TPaveText::ReadFile(const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
602{
603 Int_t ival;
604 Float_t val;
605 TString opt = option;
606 if (!opt.Contains("+")) {
607 Clear();
608 fLongest = 0;
609 }
610 SetTextAlign(12);
611 // Get file name
612 TString fname = filename;
613 if (fname.EndsWith(";"))
614 fname.Resize(fname.Length() - 1);
615 if (fname.Length() == 0)
616 return;
617
618 std::ifstream file(fname.Data(),std::ios::in);
619 if (!file.good()) {
620 Error("ReadFile", "illegal file name %s", fname.Data());
621 return;
622 }
623
624 const int linesize = 255;
625 char currentline[linesize];
626 char *ss, *sclose, *s = nullptr;
627
628 Int_t kline = 0;
629 while (1) {
630 file.getline(currentline,linesize);
631 if (file.eof())break;
632 if (kline >= fromline && kline < fromline+nlines) {
633 s = currentline;
634 if (strstr(s,"+SetText")) {
635 ss = s+8;
636 sclose = strstr(ss,")");
637 if (!sclose) continue;
638 *sclose = 0;
639 TText *lastline = (TText*)fLines->Last();
640 if (!lastline) continue;
641 if (strstr(ss,"Color(")) {
642 sscanf(ss+6,"%d",&ival);
643 lastline->SetTextColor(ival);
644 continue;
645 }
646 if (strstr(ss,"Align(")) {
647 sscanf(ss+6,"%d",&ival);
648 lastline->SetTextAlign(ival);
649 continue;
650 }
651 if (strstr(ss,"Font(")) {
652 sscanf(ss+5,"%d",&ival);
653 lastline->SetTextFont(ival);
654 continue;
655 }
656 if (strstr(ss,"Size(")) {
657 sscanf(ss+5,"%f",&val);
658 lastline->SetTextSize(val);
659 continue;
660 }
661 if (strstr(ss,"Angle(")) {
662 sscanf(ss+6,"%f",&val);
663 lastline->SetTextAngle(val);
664 continue;
665 }
666 }
667 AddText(s);
668 }
669 kline++;
670 }
671 file.close();
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Save lines of this pavetext as C++ statements on output stream out
676
677void TPaveText::SaveLines(std::ostream &out, const char *name, Bool_t saved)
678{
679 if (!fLines) return;
680 Int_t nlines = GetSize();
681 if (nlines == 0) return;
682
683 // Iterate over all lines
684 char quote = '"';
685 TObject *line;
686 TText *linet;
687 TLatex *latex;
688 TLine *linel;
689 TBox *lineb;
690 TIter next(fLines);
691 Bool_t savedlt = kFALSE;
692 Bool_t savedt = kFALSE;
693 Bool_t savedl = kFALSE;
694 Bool_t savedb = kFALSE;
695
696 while ((line = (TObject*) next())) {
697 // Next primitive is a line
698 if (line->IsA() == TLine::Class()) {
699 linel = (TLine*)line;
700 if (saved || savedl) {
701 out<<" ";
702 } else {
703 out<<" TLine *";
704 savedl = kTRUE;
705 }
706 out<<name<<"_Line = "<<name<<"->AddLine("
707 <<linel->GetX1()<<","<<linel->GetY1()<<","<<linel->GetX2()<<","<<linel->GetY2()<<");"<<std::endl;
708 if (linel->GetLineColor() != 1) {
709 if (linel->GetLineColor() > 228) {
710 TColor::SaveColor(out, linel->GetLineColor());
711 out<<" "<<name<<"_Line->SetLineColor(ci);" << std::endl;
712 } else
713 out<<" "<<name<<"_Line->SetLineColor("<<linel->GetLineColor()<<");"<<std::endl;
714 }
715 if (linel->GetLineStyle() != 1) {
716 out<<" "<<name<<"_Line->SetLineStyle("<<linel->GetLineStyle()<<");"<<std::endl;
717 }
718 if (linel->GetLineWidth() != 1) {
719 out<<" "<<name<<"_Line->SetLineWidth("<<linel->GetLineWidth()<<");"<<std::endl;
720 }
721 continue;
722 }
723 // Next primitive is a box
724 if (line->IsA() == TBox::Class()) {
725 lineb = (TBox*)line;
726 if (saved || savedb) {
727 out<<" ";
728 } else {
729 out<<" TBox *";
730 savedb = kTRUE;
731 }
732 out<<name<<"_Box = "<<name<<"->AddBox("
733 <<lineb->GetX1()<<","<<lineb->GetY1()<<","<<lineb->GetX2()<<","<<lineb->GetY2()<<");"<<std::endl;
734 if (lineb->GetFillColor() != 18) {
735 if (lineb->GetFillColor() > 228) {
736 TColor::SaveColor(out, lineb->GetFillColor());
737 out<<" "<<name<<"_Box->SetFillColor(ci);" << std::endl;
738 } else
739 out<<" "<<name<<"_Box->SetFillColor("<<lineb->GetFillColor()<<");"<<std::endl;
740 }
741 if (lineb->GetFillStyle() != 1001) {
742 out<<" "<<name<<"_Box->SetFillStyle("<<lineb->GetFillStyle()<<");"<<std::endl;
743 }
744 if (lineb->GetLineColor() != 1) {
745 if (lineb->GetLineColor() > 228) {
746 TColor::SaveColor(out, lineb->GetLineColor());
747 out<<" "<<name<<"_Box->SetLineColor(ci);" << std::endl;
748 } else
749 out<<" "<<name<<"_Box->SetLineColor("<<lineb->GetLineColor()<<");"<<std::endl;
750 }
751 if (lineb->GetLineStyle() != 1) {
752 out<<" "<<name<<"_Box->SetLineStyle("<<lineb->GetLineStyle()<<");"<<std::endl;
753 }
754 if (lineb->GetLineWidth() != 1) {
755 out<<" "<<name<<"_Box->SetLineWidth("<<lineb->GetLineWidth()<<");"<<std::endl;
756 }
757 continue;
758 }
759 // Next primitive is a text
760 if (line->IsA() == TText::Class()) {
761 linet = (TText*)line;
762 if (saved || savedt) {
763 out<<" ";
764 } else {
765 out<<" TText *";
766 savedt = kTRUE;
767 }
768 if (!linet->GetX() && !linet->GetY()) {
769 TString s = linet->GetTitle();
770 s.ReplaceAll("\"","\\\"");
771 out<<name<<"_Text = "<<name<<"->AddText("
772 <<quote<<s.Data()<<quote<<");"<<std::endl;
773 } else {
774 out<<name<<"_Text = "<<name<<"->AddText("
775 <<linet->GetX()<<","<<linet->GetY()<<","<<quote<<linet->GetTitle()<<quote<<");"<<std::endl;
776 }
777 if (linet->GetTextColor()) {
778 if (linet->GetTextColor() > 228) {
779 TColor::SaveColor(out, linet->GetTextColor());
780 out<<" "<<name<<"_Text->SetTextColor(ci);" << std::endl;
781 } else
782 out<<" "<<name<<"_Text->SetTextColor("<<linet->GetTextColor()<<");"<<std::endl;
783 }
784 if (linet->GetTextFont()) {
785 out<<" "<<name<<"_Text->SetTextFont("<<linet->GetTextFont()<<");"<<std::endl;
786 }
787 if (linet->GetTextSize()) {
788 out<<" "<<name<<"_Text->SetTextSize("<<linet->GetTextSize()<<");"<<std::endl;
789 }
790 if (linet->GetTextAngle() != GetTextAngle()) {
791 out<<" "<<name<<"_Text->SetTextAngle("<<linet->GetTextAngle()<<");"<<std::endl;
792 }
793 if (linet->GetTextAlign()) {
794 out<<" "<<name<<"_Text->SetTextAlign("<<linet->GetTextAlign()<<");"<<std::endl;
795 }
796 }
797 // Next primitive is a Latex text
798 if (line->IsA() == TLatex::Class()) {
799 latex = (TLatex*)line;
800 if (saved || savedlt) {
801 out<<" ";
802 } else {
803 out<<" TText *";
804 savedlt = kTRUE;
805 }
806 if (!latex->GetX() && !latex->GetY()) {
807 TString sl = latex->GetTitle();
808 sl.ReplaceAll("\"","\\\"");
809 out<<name<<"_LaTex = "<<name<<"->AddText("
810 <<quote<<sl.Data()<<quote<<");"<<std::endl;
811 } else {
812 out<<name<<"_LaTex = "<<name<<"->AddText("
813 <<latex->GetX()<<","<<latex->GetY()<<","<<quote<<latex->GetTitle()<<quote<<");"<<std::endl;
814 }
815 if (latex->GetTextColor()) {
816 if (latex->GetTextColor() > 228) {
817 TColor::SaveColor(out, latex->GetTextColor());
818 out<<" "<<name<<"_LaTex->SetTextColor(ci);" << std::endl;
819 } else
820 out<<" "<<name<<"_LaTex->SetTextColor("<<latex->GetTextColor()<<");"<<std::endl;
821 }
822 if (latex->GetTextFont()) {
823 out<<" "<<name<<"_LaTex->SetTextFont("<<latex->GetTextFont()<<");"<<std::endl;
824 }
825 if (latex->GetTextSize()) {
826 out<<" "<<name<<"_LaTex->SetTextSize("<<latex->GetTextSize()<<");"<<std::endl;
827 }
828 if (latex->GetTextAngle() != GetTextAngle()) {
829 out<<" "<<name<<"_LaTex->SetTextAngle("<<latex->GetTextAngle()<<");"<<std::endl;
830 }
831 if (latex->GetTextAlign()) {
832 out<<" "<<name<<"_LaTex->SetTextAlign("<<latex->GetTextAlign()<<");"<<std::endl;
833 }
834 }
835 }
836}
837
838////////////////////////////////////////////////////////////////////////////////
839/// Save primitive as a C++ statement(s) on output stream out
840
841void TPaveText::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
842{
843 char quote = '"';
844 Bool_t saved = gROOT->ClassSaved(TPaveText::Class());
845 out<<" "<<std::endl;
846 if (saved) {
847 out<<" ";
848 } else {
849 out<<" "<<ClassName()<<" *";
850 }
851 if (fOption.Contains("NDC")) {
852 out<<"pt = new "<<ClassName()<<"("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
853 <<","<<quote<<fOption<<quote<<");"<<std::endl;
854 } else {
855 out<<"pt = new "<<ClassName()<<"("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
856 <<","<<quote<<fOption<<quote<<");"<<std::endl;
857 }
858 if (strcmp(GetName(),"TPave")) {
859 out<<" pt->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
860 }
861 if (fLabel.Length() > 0) {
862 out<<" pt->SetLabel("<<quote<<fLabel<<quote<<");"<<std::endl;
863 }
864 if (fBorderSize != 4) {
865 out<<" pt->SetBorderSize("<<fBorderSize<<");"<<std::endl;
866 }
867 SaveFillAttributes(out,"pt",19,1001);
868 SaveLineAttributes(out,"pt",1,1,1);
869 SaveTextAttributes(out,"pt",22,0,1,62,0);
870 SaveLines(out,"pt",saved);
871 out<<" pt->Draw();"<<std::endl;
872}
873
874////////////////////////////////////////////////////////////////////////////////
875/// Set attribute option for all lines containing string text.
876///
877/// Possible options are all the AttText attributes
878/// Align, Color, Font, Size and Angle
879
881{
882 TString opt=option;
883 opt.ToLower();
884 TText *line;
885 TIter next(fLines);
886 while ((line = (TText*) next())) {
887 if (strstr(line->GetTitle(),text)) {
888 if (opt == "align") line->SetTextAlign(Int_t(value));
889 if (opt == "color") line->SetTextColor(Int_t(value));
890 if (opt == "font") line->SetTextFont(Int_t(value));
891 if (opt == "size") line->SetTextSize(value);
892 if (opt == "angle") line->SetTextAngle(value);
893 }
894 }
895}
896
897////////////////////////////////////////////////////////////////////////////////
898/// Stream an object of class TPaveText.
899
901{
902 if (R__b.IsReading()) {
903 UInt_t R__s, R__c;
904 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
905 if (R__v > 1) {
906 R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
907 return;
908 }
909 //====process old versions before automatic schema evolution
910 TPave::Streamer(R__b);
911 TAttText::Streamer(R__b);
912 if (R__v > 1) fLabel.Streamer(R__b);
913 R__b >> fLongest;
914 R__b >> fMargin;
915 R__b >> fLines;
916 R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
917 //====end of old versions
918
919 } else {
921 }
922}
923
924////////////////////////////////////////////////////////////////////////////////
925/// Replace current attributes by current style.
926
928{
929 if (gStyle->IsReading()) {
933 } else {
937 }
938}
@ kDiamond
Definition: Buttons.h:37
@ kPaveText
Definition: Buttons.h:32
short Style_t
Definition: RtypesCore.h:89
int Int_t
Definition: RtypesCore.h:45
short Color_t
Definition: RtypesCore.h:92
float Size_t
Definition: RtypesCore.h:96
short Version_t
Definition: RtypesCore.h:65
const Bool_t kFALSE
Definition: RtypesCore.h:101
float Float_t
Definition: RtypesCore.h:57
short Short_t
Definition: RtypesCore.h:39
double Double_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:100
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:375
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t textsize
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
char name[80]
Definition: TGX11.cxx:110
Binding & operator=(OUT(*fun)(void))
#define gROOT
Definition: TROOT.h:404
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2452
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
#define gPad
Definition: TVirtualPad.h:288
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition: TAttFill.cxx:236
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttLine.cxx:273
Text Attributes class.
Definition: TAttText.h:18
virtual Float_t GetTextSize() const
Return the text size.
Definition: TAttText.h:36
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:42
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition: TAttText.h:32
virtual Font_t GetTextFont() const
Return the text font.
Definition: TAttText.h:35
virtual Color_t GetTextColor() const
Return the text color.
Definition: TAttText.h:34
virtual void Streamer(TBuffer &)
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition: TAttText.h:43
virtual Float_t GetTextAngle() const
Return the text angle.
Definition: TAttText.h:33
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:44
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:46
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition: TAttText.cxx:375
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:47
Create a Box.
Definition: TBox.h:22
Double_t GetX1() const
Definition: TBox.h:51
virtual void PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option="")
Draw this box with new coordinates.
Definition: TBox.cxx:677
static TClass * Class()
Double_t fX1
X of 1st point.
Definition: TBox.h:28
Double_t GetX2() const
Definition: TBox.h:52
Double_t GetY1() const
Definition: TBox.h:53
Double_t GetY2() const
Definition: TBox.h:54
TBox()
Box default constructor.
Definition: TBox.cxx:42
Double_t fY2
Y of 2nd point.
Definition: TBox.h:31
Double_t fX2
X of 2nd point.
Definition: TBox.h:30
Double_t fY1
Y of 1st point.
Definition: TBox.h:29
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition: TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
void Print(Option_t *option="") const override
Default print for collections, calls Print(option, 1).
TObject * Clone(const char *newname="") const override
Make a clone of an collection using the Streamer facility.
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2187
void Reset()
Definition: TCollection.h:254
To draw Mathematical Formula.
Definition: TLatex.h:18
Double_t GetXsize()
Return size of the formula along X in pad coordinates when the text precision is smaller than 3.
Definition: TLatex.cxx:2502
static TClass * Class()
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition: TLatex.cxx:2053
Use the TLine constructor to create a simple line.
Definition: TLine.h:22
static TClass * Class()
virtual void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition: TLine.cxx:397
Double_t GetY1() const
Definition: TLine.h:52
Double_t GetX2() const
Definition: TLine.h:51
TClass * IsA() const override
Definition: TLine.h:79
Double_t GetX1() const
Definition: TLine.h:50
Double_t GetY2() const
Definition: TLine.h:53
A doubly linked list.
Definition: TList.h:38
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
Definition: TList.cxx:250
void Add(TObject *obj) override
Definition: TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition: TList.cxx:822
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:693
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
Definition: TList.cxx:196
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:41
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:200
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:417
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:177
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:519
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:963
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:477
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:20
void Paint(Option_t *option="") override
Paint this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:110
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:187
static TClass * Class()
Int_t fLongest
Length of the longest line.
Definition: TPaveText.h:25
virtual Int_t GetSize() const
return number of text lines (ignoring TLine, etc)
Definition: TPaveText.cxx:369
void Streamer(TBuffer &) override
Stream an object of class TPaveText.
Definition: TPaveText.cxx:900
TList * fLines
List of labels.
Definition: TPaveText.h:27
virtual void PaintPrimitives(Int_t mode)
Paint list of primitives in this pavetext.
Definition: TPaveText.cxx:426
TClass * IsA() const override
Definition: TPaveText.h:66
void Print(Option_t *option="") const override
Dump this pavetext with its attributes.
Definition: TPaveText.cxx:588
TPaveText()
pavetext default constructor.
Definition: TPaveText.cxx:73
virtual TLine * AddLine(Double_t x1=0, Double_t y1=0, Double_t x2=0, Double_t y2=0)
Add a new graphics line to this pavetext.
Definition: TPaveText.cxx:174
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition: TPaveText.cxx:841
virtual void InsertText(const char *label)
Add a new Text line at the mouse position.
Definition: TPaveText.cxx:399
virtual void ReadFile(const char *filename, Option_t *option="", Int_t nlines=50, Int_t fromline=0)
Read lines of filename in this pavetext.
Definition: TPaveText.cxx:601
virtual void DrawFile(const char *filename, Option_t *option="")
Draw lines in filename in this pavetext.
Definition: TPaveText.cxx:250
virtual void EditText()
Edit text at the mouse position.
Definition: TPaveText.cxx:260
virtual void SetAllWith(const char *text, Option_t *option, Double_t value)
Set attribute option for all lines containing string text.
Definition: TPaveText.cxx:880
virtual TObject * GetObject(Double_t &ymouse, Double_t &yobj) const
Get object pointed by the mouse in this pavetext.
Definition: TPaveText.cxx:313
virtual void SaveLines(std::ostream &out, const char *name, Bool_t saved)
Save lines of this pavetext as C++ statements on output stream out.
Definition: TPaveText.cxx:677
virtual void DeleteText()
Delete text at the mouse position.
Definition: TPaveText.cxx:223
void Clear(Option_t *option="") override
Clear all lines in this pavetext.
Definition: TPaveText.cxx:213
virtual ~TPaveText()
pavetext default destructor.
Definition: TPaveText.cxx:116
TPaveText & operator=(const TPaveText &)
assignment operator
Definition: TPaveText.cxx:139
virtual TBox * AddBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Add a new graphics box to this pavetext.
Definition: TPaveText.cxx:161
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:238
void Paint(Option_t *option="") override
Paint this pavetext with its current attributes.
Definition: TPaveText.cxx:415
virtual TText * GetLine(Int_t number) const
Get Pointer to line number in this pavetext.
Definition: TPaveText.cxx:280
TString fLabel
Label written at the top of the pavetext.
Definition: TPaveText.h:24
virtual void InsertLine()
Add a new line at the mouse position.
Definition: TPaveText.cxx:382
virtual TText * GetLineWith(const char *text) const
Get Pointer to first containing string text in this pavetext.
Definition: TPaveText.cxx:298
Float_t fMargin
Text margin.
Definition: TPaveText.h:26
void UseCurrentStyle() override
Replace current attributes by current style.
Definition: TPaveText.cxx:927
A TBox with a bordersize and a shadow option.
Definition: TPave.h:19
void Print(Option_t *option="") const override
Dump this pave with its attributes.
Definition: TPave.cxx:615
Int_t GetBorderSize() const
Definition: TPave.h:54
TPave & operator=(const TPave &src)
Assignment operator.
Definition: TPave.cxx:129
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Definition: TPave.cxx:139
void Streamer(TBuffer &) override
Stream an object of class TPave.
Definition: TPave.cxx:704
Int_t fBorderSize
window box bordersize in pixels
Definition: TPave.h:26
Double_t fX2NDC
X2 point in NDC coordinates.
Definition: TPave.h:24
TString fOption
Pave style.
Definition: TPave.h:30
Double_t fY2NDC
Y2 point in NDC coordinates.
Definition: TPave.h:25
Double_t fX1NDC
X1 point in NDC coordinates.
Definition: TPave.h:22
Option_t * GetOption() const override
Definition: TPave.h:57
Double_t fY1NDC
Y1 point in NDC coordinates.
Definition: TPave.h:23
Option_t * GetName() const override
Returns name of object.
Definition: TPave.h:56
virtual void PaintPave(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Int_t bordersize=4, Option_t *option="br")
Draw this pave with new coordinates.
Definition: TPave.cxx:314
Basic string class.
Definition: TString.h:136
Ssiz_t Length() const
Definition: TString.h:410
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1155
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2207
const char * Data() const
Definition: TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition: TString.cxx:1125
virtual void Streamer(TBuffer &)
Stream a string object.
Definition: TString.cxx:1375
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:624
Bool_t IsReading() const
Definition: TStyle.h:283
Base class for several text objects.
Definition: TText.h:22
Double_t GetX() const
Definition: TText.h:53
virtual void SetY(Double_t y)
Definition: TText.h:77
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition: TText.cxx:744
virtual void SetX(Double_t x)
Definition: TText.h:76
Double_t GetY() const
Definition: TText.h:61
static TClass * Class()
TPaveText * pt
TLine * line
Double_t y[n]
Definition: legend1.C:17
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
Definition: TObject.h:404
static constexpr double s
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition: TMathBase.h:123
Definition: file.py:1