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
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;
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;
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;
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;
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());
326 Double_t y1,y,dy;
327 Double_t ytext = fY2 + 0.5*yspace;
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()) {
378 }
379 return nlines;
380}
381
382////////////////////////////////////////////////////////////////////////////////
383/// Add a new line at the mouse position.
384
386{
387 if (!gPad->IsEditable()) return;
389 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
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;
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
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;
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;
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
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
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
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;
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)
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 static int linecnt = 0;
691
692 // Iterate over all lines
693 TIter next(fLines);
694
695 while (auto line = next()) {
696 if (line->IsA() == TLine::Class()) {
697 // Next primitive is a line
698 auto linel = static_cast<TLine *>(line);
699 auto line_name = TString::Format("%s_line%d", name, linecnt++);
700 out << " TLine *" << line_name << " = " << name << "->AddLine(" << linel->GetX1() << "," << linel->GetY1()
701 << "," << linel->GetX2() << "," << linel->GetY2() << ");" << std::endl;
702 linel->SaveLineAttributes(out, line_name.Data(), 1, 1, 1);
703 } else if (line->IsA() == TBox::Class()) {
704 // Next primitive is a box
705 auto lineb = static_cast<TBox *>(line);
706 auto box_name = TString::Format("%s_box%d", name, linecnt++);
707 out << " TBox *" << box_name << " = " << name << "->AddBox(" << lineb->GetX1() << "," << lineb->GetY1()
708 << "," << lineb->GetX2() << "," << lineb->GetY2() << ");" << std::endl;
709 lineb->SaveFillAttributes(out, box_name.Data(), 18, 1001);
710 lineb->SaveLineAttributes(out, box_name.Data(), 1, 1, 1);
711 } else if (line->IsA() == TText::Class() || line->IsA() == TLatex::Class()) {
712 // Next primitive is a text
713 auto linet = static_cast<TText *>(line);
714 auto text_name = TString::Format("%s_text%d", name, linecnt++);
715
716 TString s = linet->GetTitle();
718
719 out << " TText *" << text_name << " = ";
720
721 if (!linet->GetX() && !linet->GetY())
722 out << name << "->AddText(\"" << s << "\");" << std::endl;
723 else
724 out << name << "->AddText(" << linet->GetX() << ", " << linet->GetY() << ", \"" << s << "\");" << std::endl;
725
726 linet->SaveTextAttributes(out, text_name.Data(), 0, GetTextAngle(), 0, 0, 0);
727 }
728 }
729}
730
731////////////////////////////////////////////////////////////////////////////////
732/// Save primitive as a C++ statement(s) on output stream out
733
734void TPaveText::SavePrimitive(std::ostream &out, Option_t *option)
735{
737
738 if (strcmp(GetName(), "TPave"))
739 out << " pt->SetName(\"" << GetName() << "\");\n";
740 if (fLabel.Length() > 0)
741 out << " pt->SetLabel(\"" << TString(fLabel).ReplaceSpecialCppChars() << "\");\n";
742 if (fBorderSize != 4)
743 out << " pt->SetBorderSize(" << fBorderSize << ");\n";
744 SaveFillAttributes(out, "pt", 19, 1001);
745 SaveLineAttributes(out, "pt", 1, 1, 1);
746 SaveTextAttributes(out, "pt", 22, 0, 1, 62, 0);
747 SaveLines(out, "pt", kTRUE);
748 SavePrimitiveDraw(out, "pt", option);
749}
750
751////////////////////////////////////////////////////////////////////////////////
752/// Set attribute option for all lines containing string text.
753///
754/// Possible options are all the AttText attributes
755/// Align, Color, Font, Size and Angle
756
758{
759 TString opt = option;
760 opt.ToLower();
761 TIter next(fLines);
762 while (auto obj = next()) {
763 auto line = dynamic_cast<TText *> (obj);
764 if (line && strstr(line->GetTitle(),text)) {
765 if (opt == "align") line->SetTextAlign(Int_t(value));
766 if (opt == "color") line->SetTextColor(Int_t(value));
767 if (opt == "font") line->SetTextFont(Int_t(value));
768 if (opt == "size") line->SetTextSize(value);
769 if (opt == "angle") line->SetTextAngle(value);
770 }
771 }
772}
773
774////////////////////////////////////////////////////////////////////////////////
775/// Stream an object of class TPaveText.
776
778{
779 if (R__b.IsReading()) {
781 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
782 if (R__v > 1) {
783 R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
784 return;
785 }
786 //====process old versions before automatic schema evolution
789 if (R__v > 1) fLabel.Streamer(R__b);
790 R__b >> fLongest;
791 R__b >> fMargin;
792 R__b >> fLines;
793 R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
794 //====end of old versions
795
796 } else {
797 R__b.WriteClassBuffer(TPaveText::Class(),this);
798 }
799}
800
801////////////////////////////////////////////////////////////////////////////////
802/// Replace current attributes by current style.
803
@ 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
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:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:442
#define gPad
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:31
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
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:20
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:38
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:44
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:34
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:37
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:36
virtual void Streamer(TBuffer &)
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:35
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:46
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:48
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:49
Create a Box.
Definition TBox.h:22
static TClass * Class()
Double_t fX1
X of 1st point.
Definition TBox.h:28
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
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
static TClass * Class()
Use the TLine constructor to create a simple line.
Definition TLine.h:22
static TClass * Class()
TClass * IsA() const override
Definition TLine.h:79
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
Mother of all ROOT objects.
Definition TObject.h:41
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:441
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:501
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:822
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:771
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.
virtual void SaveLines(std::ostream &out, const char *name, Bool_t)
Save lines of this pavetext as C++ statements on output stream out.
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 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:56
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:58
TString GetSavePaveArgs(const char *extra_arg=nullptr, Bool_t save_option=kTRUE)
Returns arguments which should be used when saving primitive constructor Check if coordinates are ini...
Definition TPave.cxx:618
void Streamer(TBuffer &) override
Stream an object of class TPave.
Definition TPave.cxx:717
Int_t fBorderSize
window box bordersize in pixels
Definition TPave.h:26
Option_t * GetOption() const override
Definition TPave.h:59
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
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
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:300
Base class for several text objects.
Definition TText.h:22
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:408
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123