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