Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 = nullptr;
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/// If you want to remove the border or shadow of an already existing TPaveText,
94/// then use the function TPave::SetBorderSize.
95///
96/// - option = "NDC" x1,y1,x2,y2 are given in NDC
97/// - option = "ARC" corners are rounded
98///
99/// In case of option "ARC", the corner radius is specified
100/// via TPave::SetCornerRadius(rad) where rad is given in percent
101/// of the pave height (default value is 0.2).
102///
103/// The individual text items are entered via AddText
104/// By default, text items inherits from the default pavetext AttText.
105/// A title can be added later to this pavetext via TPaveText::SetLabel.
106
108 :TPave(x1,y1,x2,y2,4,option), TAttText(22,0,gStyle->GetTextColor(),gStyle->GetTextFont(),0)
109{
110 fLines = new TList;
111 fMargin = 0.05;
112 fLongest = 0;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// pavetext default destructor.
117
119{
120 if (ROOT::Detail::HasBeenDeleted(this)) return;
121 if (fLines) fLines->Delete();
122 delete fLines;
123 fLines = nullptr;
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// pavetext copy constructor.
128
129TPaveText::TPaveText(const TPaveText &pavetext) : TPave(pavetext), TAttText(pavetext)
130{
131 fLabel = pavetext.fLabel;
132 fLongest = pavetext.fLongest;
133 fMargin = pavetext.fMargin;
134 if (pavetext.fLines)
135 fLines = (TList *) pavetext.fLines->Clone();
136}
137
138////////////////////////////////////////////////////////////////////////////////
139///assignment operator
140
142{
143 if(this != &pt) {
145 TAttText::operator=(pt);
146 fLabel = pt.fLabel;
149 if (fLines) {
150 fLines->Delete();
151 delete fLines;
152 fLines = nullptr;
153 }
154 if (pt.fLines)
155 fLines = (TList *)pt.fLines->Clone();
156 }
157 return *this;
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Add a new graphics box to this pavetext.
162
164{
165 if (!gPad->IsEditable())
166 return nullptr;
167 TBox *newbox = new TBox(x1,y1,x2,y2);
168
169 if (!fLines) fLines = new TList;
170 fLines->Add(newbox);
171 return newbox;
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Add a new graphics line to this pavetext.
176
178{
179 if (!gPad->IsEditable())
180 return nullptr;
181 TLine *newline = new TLine(x1,y1,x2,y2);
182
183 if (!fLines) fLines = new TList;
184 fLines->Add(newline);
185 return newline;
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Add a new Text line to this pavetext at given coordinates.
190
192{
193 TLatex *newtext = new TLatex(x1,y1,text);
194 newtext->SetTextAlign(0);
195 newtext->SetTextColor(0);
196 newtext->SetTextFont(0);
197 newtext->SetTextSize(0);
198 Int_t nch = text ? strlen(text) : 0;
199 if (nch > fLongest) fLongest = nch;
200
201 if (!fLines) fLines = new TList;
202 fLines->Add(newtext);
203 return newtext;
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Add a new Text line to this pavetext.
208
210{
211 return AddText(0,0,text);
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// Clear all lines in this pavetext.
216
218{
219 if (!fLines) return;
220 fLines->Delete();
221 fLongest = 0;
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Delete text at the mouse position.
226
228{
229 if (!gPad->IsEditable()) return;
230 if (!fLines) return;
231 Double_t ymouse, yobj;
232 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
233 if (!obj) return;
234 if (!obj->InheritsFrom(TText::Class())) return;
235 fLines->Remove(obj);
236 delete obj;
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Draw this pavetext with its current attributes.
241
243{
244 Option_t *opt;
245 if (option && strlen(option)) opt = option;
246 else opt = GetOption();
247
248 AppendPad(opt);
249}
250
251////////////////////////////////////////////////////////////////////////////////
252/// Draw lines in filename in this pavetext.
253
255{
257
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Edit text at the mouse position.
263
265{
266 if (!gPad->IsEditable()) return;
267 Double_t ymouse, yobj;
268 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
269 if (!obj) return;
270 if (!obj->InheritsFrom(TText::Class())) return;
271 TText *text = (TText*)obj;
272 gROOT->SetSelectedPrimitive(text);
273 gROOT->ProcessLine(TString::Format("((TCanvas*)0x%zx)->SetSelected((TObject*)0x%zx)",
274 (size_t)gPad->GetCanvas(), (size_t)text));
275 gROOT->ProcessLine(TString::Format("((TCanvas*)0x%zx)->Selected((TVirtualPad*)0x%zx,(TObject*)0x%zx,1)",
276 (size_t)gPad->GetCanvas(), (size_t)gPad, (size_t)text));
277 text->SetTextAttributes();
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Get Pointer to line number in this pavetext.
282/// Ignore any TLine or TBox, they are not accounted
283
285{
286 TIter next(fLines);
287 Int_t nlines = 0;
288 while (auto obj = next()) {
289 if (!obj->InheritsFrom(TText::Class()))
290 continue;
291
292 if (nlines++ == number)
293 return (TText *) obj;
294 }
295 return nullptr;
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Get Pointer to first containing string text in this pavetext.
300/// Ignore any TLine or TBox, they are not accounted
301
303{
304 if (!text)
305 return nullptr;
306 TIter next(fLines);
307 while (auto obj = next()) {
308 if (obj->InheritsFrom(TText::Class()) && strstr(obj->GetTitle(), text))
309 return (TText *) obj;
310 }
311 return nullptr;
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Get object pointed by the mouse in this pavetext.
316
318{
319 if (!fLines) return nullptr;
320 Int_t nlines = GetSize();
321 if (nlines == 0) return nullptr;
322
323 // Evaluate text size as a function of the number of lines
324
325 ymouse = gPad->AbsPixeltoY(gPad->GetEventY());
326 Double_t yspace = (fY2 - fY1)/Double_t(nlines);
327 Double_t y1,y,dy;
328 Double_t ytext = fY2 + 0.5*yspace;
329 Int_t valign;
330
331 // Iterate over all lines
332 // Copy pavetext attributes to line attributes if line attributes not set
333 dy = fY2 - fY1;
334 TIter next(fLines);
335 while (auto line = next()) {
336 // Next primitive is a line
337 if (line->IsA() == TLine::Class()) {
338 auto linel = (TLine *)line;
339 y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
340 if (TMath::Abs(y1-ymouse) < 0.2*yspace) {yobj = y1; return line;}
341 continue;
342 }
343 // Next primitive is a box
344 if (line->IsA() == TBox::Class()) {
345 auto lineb = (TBox *)line;
346 y1 = lineb->GetY1();
347 if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
348 if (TMath::Abs(y1-ymouse) < 0.4*yspace) {yobj = y1; return line;}
349 continue;
350 }
351 // Next primitive is a text
353 auto linet = (TText *)line;
354 ytext -= yspace;
355 Double_t yl = linet->GetY();
356 if (yl > 0 && yl <1) {
357 ytext = fY1 + yl*dy;
358 }
359 valign = linet->GetTextAlign()%10;
360 y = ytext;
361 if (valign == 1) y = ytext -0.5*yspace;
362 if (valign == 3) y = ytext +0.5*yspace;
363
364 if (TMath::Abs(y-ymouse) < 0.5*yspace) {yobj = y; return line;}
365 }
366 }
367 return nullptr;
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// return number of text lines (ignoring TLine, etc)
372
374{
375 Int_t nlines = 0;
376 TIter next(fLines);
377 while (auto line = next()) {
378 if (line->InheritsFrom(TText::Class())) nlines++;
379 }
380 return nlines;
381}
382
383////////////////////////////////////////////////////////////////////////////////
384/// Add a new line at the mouse position.
385
387{
388 if (!gPad->IsEditable()) return;
389 Double_t ymouse=0, yobj;
390 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
391 Double_t yline = (ymouse-fY1)/(fY2-fY1);
392 TLine *newline = AddLine(0,yline,0,yline);
393 if (obj) {
394 fLines->Remove(newline); //remove line from last position
395 if (yobj < ymouse) fLines->AddBefore(obj,newline);
396 else fLines->AddAfter(obj,newline);
397 }
398}
399
400////////////////////////////////////////////////////////////////////////////////
401/// Add a new Text line at the mouse position.
402
404{
405 if (!gPad->IsEditable()) return;
406 Double_t ymouse, yobj;
407 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
408 TText *newtext = AddText(0,0,text); //create new text object
409 if (obj) {
410 fLines->Remove(newtext); //remove text from last position
411 if (yobj < ymouse) fLines->AddBefore(obj,newtext); //insert new text at right position
412 else fLines->AddAfter(obj,newtext); //insert new text at right position
413 }
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Paint this pavetext with its current attributes.
418
420{
421 // Draw the pave
425}
426
427////////////////////////////////////////////////////////////////////////////////
428/// Paint list of primitives in this pavetext.
429
431{
432 if (!fLines) return;
433 Double_t dx = fX2 - fX1;
434 Double_t dy = fY2 - fY1;
436 Int_t nlines = GetSize();
437 if (nlines == 0) nlines = 5;
438
439 // Evaluate text size as a function of the number of lines
440
442 y1 = gPad->GetY1();
443 y2 = gPad->GetY2();
444 Float_t margin = fMargin*dx;
445 Double_t yspace = dy/Double_t(nlines);
446 Double_t textsave = textsize;
447 TObject *line;
448 TText *linet;
449 TLatex *latex;
450 TIter next(fLines);
451 Double_t longest = 0;
452 Double_t w;
453 if (textsize == 0) {
454 textsize = 0.85*yspace/(y2 - y1);
455 while ((line = (TObject*) next())) {
456 if (line->IsA() == TLatex::Class()) {
457 latex = (TLatex*)line;
458 Float_t tangle = latex->GetTextAngle();
459 if (latex->GetTextSize() != 0) continue;
460 Style_t tfont = latex->GetTextFont();
461 if (tfont == 0) latex->SetTextFont(GetTextFont());
462 latex->SetTextSize(textsize);
463 w = latex->GetXsize();
464 latex->SetTextSize(0);
465 latex->SetTextAngle(tangle); //text angle was redefined in GetXsize !
466 if (w > longest) longest = w;
467 latex->SetTextFont(tfont);
468 }
469 }
470 if (longest > 0.92*dx) textsize *= 0.92*dx/longest;
471 if (mode == kDiamond) textsize *= 0.66;
473 }
474 Double_t ytext = fY2 + 0.5*yspace;
475 Double_t xtext = 0;
476 Int_t halign;
477
478 // Iterate over all lines
479 // Copy pavetext attributes to line attributes if line attributes not set
480 TLine *linel;
481 TBox *lineb;
482 next.Reset();
483 while ((line = (TObject*) next())) {
484 // Next primitive is a line
485 if (line->IsA() == TLine::Class()) {
486 linel = (TLine*)line;
487 x1 = linel->GetX1(); if (x1 == 0) x1 = fX1; else x1 = fX1 + x1*dx;
488 x2 = linel->GetX2(); if (x2 == 0) x2 = fX2; else x2 = fX1 + x2*dx;
489 y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
490 y2 = linel->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
491 linel->PaintLine(x1,y1,x2,y2);
492 continue;
493 }
494 // Next primitive is a box
495 if (line->IsA() == TBox::Class()) {
496 lineb = (TBox*)line;
497 x1 = lineb->GetX1();
498 if (x1) x1 = fX1 + x1*dx;
499 else x1 = fX1 + gPad->PixeltoX(1) - gPad->PixeltoX(0);
500 x2 = lineb->GetX2();
501 if (x2) x2 = fX1 + x2*dx;
502 else x2 = fX2;
503 y1 = lineb->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
504 y2 = lineb->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
505 lineb->PaintBox(x1,y1,x2,y2);
506 continue;
507 }
508 // Next primitive is a text
509 if (line->IsA() == TText::Class()) {
510 linet = (TText*)line;
511 ytext -= yspace;
512 Double_t xl = linet->GetX();
513 Double_t yl = linet->GetY();
514 Short_t talign = linet->GetTextAlign();
515 Color_t tcolor = linet->GetTextColor();
516 Style_t tfont = linet->GetTextFont();
517 Size_t tsize = linet->GetTextSize();
518 if (talign == 0) linet->SetTextAlign(GetTextAlign());
519 if (tcolor == 0) linet->SetTextColor(GetTextColor());
520 if (tfont == 0) linet->SetTextFont(GetTextFont());
521 if (tsize == 0) linet->SetTextSize(GetTextSize());
522 if (xl > 0 && xl <1) {
523 xtext = fX1 + xl*dx;
524 } else {
525 halign = linet->GetTextAlign()/10;
526 if (halign == 1) xtext = fX1 + margin;
527 if (halign == 2) xtext = 0.5*(fX1+fX2);
528 if (halign == 3) xtext = fX2 - margin;
529 }
530 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
531 linet->PaintText(xtext,ytext,linet->GetTitle());
532 linet->SetTextAlign(talign);
533 linet->SetTextColor(tcolor);
534 linet->SetTextFont(tfont);
535 linet->SetTextSize(tsize);
536 }
537 // Next primitive is a Latex text
538 if (line->IsA() == TLatex::Class()) {
539 latex = (TLatex*)line;
540 ytext -= yspace;
541 Double_t xl = latex->GetX();
542 Double_t yl = latex->GetY();
543 Short_t talign = latex->GetTextAlign();
544 Color_t tcolor = latex->GetTextColor();
545 Style_t tfont = latex->GetTextFont();
546 Size_t tsize = latex->GetTextSize();
547 if (talign == 0) latex->SetTextAlign(GetTextAlign());
548 if (tcolor == 0) latex->SetTextColor(GetTextColor());
549 if (tfont == 0) latex->SetTextFont(GetTextFont());
550 if (tsize == 0) latex->SetTextSize(GetTextSize());
551 if (xl > 0 && xl <1) {
552 xtext = fX1 + xl*dx;
553 } else {
554 halign = latex->GetTextAlign()/10;
555 if (halign == 1) xtext = fX1 + margin;
556 if (halign == 2) xtext = 0.5*(fX1+fX2);
557 if (halign == 3) xtext = fX2 - margin;
558 }
559 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
560 latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
561 latex->GetTextSize(),
562 latex->GetTitle());
563 latex->SetTextAlign(talign);
564 latex->SetTextColor(tcolor);
565 latex->SetTextFont(tfont);
566 latex->SetTextSize(tsize);
567 latex->SetX(xl); // PaintLatex modifies fX and fY
568 latex->SetY(yl);
569 }
570 }
571
572 SetTextSize(textsave);
573
574 // if a label create & paint a pavetext title
575 if (fLabel.Length() > 0) {
576 dy = gPad->GetY2() - gPad->GetY1();
577 x1 = fX1 + 0.25*dx;
578 x2 = fX2 - 0.25*dx;
579 y1 = fY2 - 0.02*dy;
580 y2 = fY2 + 0.02*dy;
581 TString opt = GetDrawOption(); opt.ReplaceAll("NDC", "");
582 TPaveLabel title(x1,y1,x2,y2,fLabel.Data(),opt.Data());
583 title.SetFillColor(GetFillColor());
584 title.SetTextColor(GetTextColor());
585 title.SetTextFont(GetTextFont());
586 title.Paint();
587 }
588}
589
590////////////////////////////////////////////////////////////////////////////////
591/// Dump this pavetext with its attributes.
592
594{
596 if (fLines) fLines->Print();
597}
598
599////////////////////////////////////////////////////////////////////////////////
600/// Read lines of filename in this pavetext.
601///
602/// Read from line number fromline a total of nlines
603///
604/// Note that this function changes the default text alignment to left/center
605
606void TPaveText::ReadFile(const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
607{
608 Int_t ival;
609 Float_t val;
610 TString opt = option;
611 if (!opt.Contains("+")) {
612 Clear();
613 fLongest = 0;
614 }
615 SetTextAlign(12);
616 // Get file name
617 TString fname = filename;
618 if (fname.EndsWith(";"))
619 fname.Resize(fname.Length() - 1);
620 if (fname.Length() == 0)
621 return;
622
623 std::ifstream file(fname.Data(),std::ios::in);
624 if (!file.good()) {
625 Error("ReadFile", "illegal file name %s", fname.Data());
626 return;
627 }
628
629 const int linesize = 255;
630 char currentline[linesize];
631 char *ss, *sclose, *s = nullptr;
632
633 Int_t kline = 0;
634 while (true) {
635 file.getline(currentline,linesize);
636 if (file.eof())break;
637 if (kline >= fromline && kline < fromline+nlines) {
638 s = currentline;
639 if (strstr(s,"+SetText")) {
640 ss = s+8;
641 sclose = strstr(ss,")");
642 if (!sclose) continue;
643 *sclose = 0;
644 TText *lastline = (TText*)fLines->Last();
645 if (!lastline) continue;
646 if (strstr(ss,"Color(")) {
647 sscanf(ss+6,"%d",&ival);
648 lastline->SetTextColor(ival);
649 continue;
650 }
651 if (strstr(ss,"Align(")) {
652 sscanf(ss+6,"%d",&ival);
653 lastline->SetTextAlign(ival);
654 continue;
655 }
656 if (strstr(ss,"Font(")) {
657 sscanf(ss+5,"%d",&ival);
658 lastline->SetTextFont(ival);
659 continue;
660 }
661 if (strstr(ss,"Size(")) {
662 sscanf(ss+5,"%f",&val);
663 lastline->SetTextSize(val);
664 continue;
665 }
666 if (strstr(ss,"Angle(")) {
667 sscanf(ss+6,"%f",&val);
668 lastline->SetTextAngle(val);
669 continue;
670 }
671 }
672 AddText(s);
673 }
674 kline++;
675 }
676 file.close();
677}
678
679////////////////////////////////////////////////////////////////////////////////
680/// Save lines of this pavetext as C++ statements on output stream out
681
682void TPaveText::SaveLines(std::ostream &out, const char *name, Bool_t saved)
683{
684 if (!fLines) return;
685 Int_t nlines = GetSize();
686 if (nlines == 0) return;
687
688 if (!name || !*name)
689 name = "pt";
690
691 // Iterate over all lines
692 char quote = '"';
693 TIter next(fLines);
694
695 Bool_t savedlt = kFALSE, savedt = kFALSE, savedl = kFALSE, savedb = kFALSE;
696
697 while (auto line = next()) {
698 // Next primitive is a line
699 if (line->IsA() == TLine::Class()) {
700 auto linel = (TLine*)line;
701 if (saved || savedl) {
702 out<<" ";
703 } else {
704 out<<" TLine *";
705 savedl = kTRUE;
706 }
707
708 auto line_name = TString::Format("%s_Line", name);
709
710 out<<line_name<<" = "<<name<<"->AddLine("
711 <<linel->GetX1()<<","<<linel->GetY1()<<","<<linel->GetX2()<<","<<linel->GetY2()<<");"<<std::endl;
712
713 linel->SaveLineAttributes(out, line_name.Data(), 1, 1, 1);
714 continue;
715 }
716 // Next primitive is a box
717 if (line->IsA() == TBox::Class()) {
718 auto lineb = (TBox*)line;
719 if (saved || savedb) {
720 out<<" ";
721 } else {
722 out<<" TBox *";
723 savedb = kTRUE;
724 }
725
726 auto box_name = TString::Format("%s_Box", name);
727
728 out<<box_name<<" = "<<name<<"->AddBox("
729 <<lineb->GetX1()<<","<<lineb->GetY1()<<","<<lineb->GetX2()<<","<<lineb->GetY2()<<");"<<std::endl;
730
731 lineb->SaveFillAttributes(out, box_name.Data(), 18, 1001);
732 lineb->SaveLineAttributes(out, box_name.Data(), 1, 1, 1);
733 continue;
734 }
735 // Next primitive is a text
736 if (line->IsA() == TText::Class()) {
737 auto linet = (TText*)line;
738 if (saved || savedt) {
739 out<<" ";
740 } else {
741 out<<" TText *";
742 savedt = kTRUE;
743 }
744
745 auto text_name = TString::Format("%s_Text", name);
746
747 TString s = linet->GetTitle();
749
750 if (!linet->GetX() && !linet->GetY())
751 out<<text_name<<" = "<<name<<"->AddText(" <<quote<<s<<quote<<");"<<std::endl;
752 else
753 out<<text_name<<" = "<<name<<"->AddText("
754 <<linet->GetX()<<","<<linet->GetY()<<","<<quote<<s<<quote<<");"<<std::endl;
755
756 linet->SaveTextAttributes(out, text_name.Data(), 0, GetTextAngle(), 0, 0, 0);
757 continue;
758 }
759 // Next primitive is a Latex text
760 if (line->IsA() == TLatex::Class()) {
761 auto latex = (TLatex*)line;
762 if (saved || savedlt) {
763 out<<" ";
764 } else {
765 out<<" TText *";
766 savedlt = kTRUE;
767 }
768
769 auto latex_name = TString::Format("%s_LaTex", name);
770
771 TString sl = latex->GetTitle();
773
774 if (!latex->GetX() && !latex->GetY())
775 out<< latex_name << " = "<<name<<"->AddText(" <<quote<<sl<<quote<<");"<<std::endl;
776 else
777 out<< latex_name << " = "<<name<<"->AddText("
778 <<latex->GetX()<<","<<latex->GetY()<<","<<quote<<sl<<quote<<");"<<std::endl;
779
780 latex->SaveTextAttributes(out, latex_name.Data(), 0, GetTextAngle(), 0, 0, 0);
781 }
782 }
783}
784
785////////////////////////////////////////////////////////////////////////////////
786/// Save primitive as a C++ statement(s) on output stream out
787
788void TPaveText::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
789{
790 char quote = '"';
791 Bool_t saved = gROOT->ClassSaved(TPaveText::Class());
792 out<<" "<<std::endl;
793 if (saved) {
794 out<<" ";
795 } else {
796 out<<" "<<ClassName()<<" *";
797 }
798 if (fOption.Contains("NDC")) {
799 out<<"pt = new "<<ClassName()<<"("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
800 <<","<<quote<<fOption<<quote<<");"<<std::endl;
801 } else {
802 out<<"pt = new "<<ClassName()<<"("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
803 <<","<<quote<<fOption<<quote<<");"<<std::endl;
804 }
805 if (strcmp(GetName(),"TPave")) {
806 out<<" pt->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
807 }
808 if (fLabel.Length() > 0) {
809 out<<" pt->SetLabel("<<quote<<fLabel<<quote<<");"<<std::endl;
810 }
811 if (fBorderSize != 4) {
812 out<<" pt->SetBorderSize("<<fBorderSize<<");"<<std::endl;
813 }
814 SaveFillAttributes(out,"pt",19,1001);
815 SaveLineAttributes(out,"pt",1,1,1);
816 SaveTextAttributes(out,"pt",22,0,1,62,0);
817 SaveLines(out,"pt",saved);
818 out<<" pt->Draw();"<<std::endl;
819}
820
821////////////////////////////////////////////////////////////////////////////////
822/// Set attribute option for all lines containing string text.
823///
824/// Possible options are all the AttText attributes
825/// Align, Color, Font, Size and Angle
826
828{
829 TString opt = option;
830 opt.ToLower();
831 TIter next(fLines);
832 while (auto obj = next()) {
833 auto line = dynamic_cast<TText *> (obj);
834 if (line && strstr(line->GetTitle(),text)) {
835 if (opt == "align") line->SetTextAlign(Int_t(value));
836 if (opt == "color") line->SetTextColor(Int_t(value));
837 if (opt == "font") line->SetTextFont(Int_t(value));
838 if (opt == "size") line->SetTextSize(value);
839 if (opt == "angle") line->SetTextAngle(value);
840 }
841 }
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Stream an object of class TPaveText.
846
848{
849 if (R__b.IsReading()) {
850 UInt_t R__s, R__c;
851 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
852 if (R__v > 1) {
853 R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
854 return;
855 }
856 //====process old versions before automatic schema evolution
857 TPave::Streamer(R__b);
858 TAttText::Streamer(R__b);
859 if (R__v > 1) fLabel.Streamer(R__b);
860 R__b >> fLongest;
861 R__b >> fMargin;
862 R__b >> fLines;
863 R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
864 //====end of old versions
865
866 } else {
868 }
869}
870
871////////////////////////////////////////////////////////////////////////////////
872/// Replace current attributes by current style.
873
875{
876 if (gStyle->IsReading()) {
880 } else {
884 }
885}
@ kDiamond
Definition Buttons.h:37
@ kPaveText
Definition Buttons.h:32
short Style_t
Definition RtypesCore.h:82
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:85
float Size_t
Definition RtypesCore.h:89
short Version_t
Definition RtypesCore.h:65
float Float_t
Definition RtypesCore.h:57
short Short_t
Definition RtypesCore.h:39
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
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 SetTextSize
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 SetTextFont
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
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
#define gPad
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
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:239
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:275
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:373
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:678
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.
void Reset()
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:2569
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:2114
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:399
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:248
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:691
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
Definition TList.cxx:194
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
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:225
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:440
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:202
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:542
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1005
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:500
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.
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.
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)
~TPaveText() override
pavetext default destructor.
void Streamer(TBuffer &) override
Stream an object of class TPaveText.
TList * fLines
List of labels.
Definition TPaveText.h:27
virtual void PaintPrimitives(Int_t mode)
Paint list of primitives in this pavetext.
TClass * IsA() const override
Definition TPaveText.h:65
void Print(Option_t *option="") const override
Dump this pavetext with its attributes.
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.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
virtual void InsertText(const char *label)
Add a new Text line at the mouse position.
virtual void ReadFile(const char *filename, Option_t *option="", Int_t nlines=50, Int_t fromline=0)
Read lines of filename in this pavetext.
virtual void DrawFile(const char *filename, Option_t *option="")
Draw lines in filename in this pavetext.
virtual void EditText()
Edit text at the mouse position.
virtual void SetAllWith(const char *text, Option_t *option, Double_t value)
Set attribute option for all lines containing string text.
virtual TObject * GetObject(Double_t &ymouse, Double_t &yobj) const
Get object pointed by the mouse in this pavetext.
virtual void SaveLines(std::ostream &out, const char *name, Bool_t saved)
Save lines of this pavetext as C++ statements on output stream out.
virtual void DeleteText()
Delete text at the mouse position.
void Clear(Option_t *option="") override
Clear all lines in this pavetext.
TPaveText & operator=(const TPaveText &)
assignment operator
virtual TBox * AddBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Add a new graphics box to this pavetext.
void Draw(Option_t *option="") override
Draw this pavetext with its current attributes.
void Paint(Option_t *option="") override
Paint this pavetext with its current attributes.
virtual TText * GetLine(Int_t number) const
Get Pointer to line number in this pavetext.
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.
virtual TText * GetLineWith(const char *text) const
Get Pointer to first containing string text in this pavetext.
Float_t fMargin
Text margin.
Definition TPaveText.h:26
void UseCurrentStyle() override
Replace current attributes by current style.
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:609
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
const char * GetName() const override
Returns name of object.
Definition TPave.h:56
void Streamer(TBuffer &) override
Stream an object of class TPave.
Definition TPave.cxx:698
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
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:315
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1114
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1152
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1412
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Bool_t IsReading() const
Definition TStyle.h:296
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:752
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:402
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123