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