Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPaveText.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 20/10/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <cstring>
13#include <cstdlib>
14#include <cstdio>
15#include <iostream>
16#include <fstream>
17
18#include "TBufferFile.h"
19#include "TROOT.h"
20#include "TStyle.h"
21#include "TPaveText.h"
22#include "TPaveLabel.h"
23#include "TVirtualPad.h"
24#include "TMath.h"
25#include "TLatex.h"
26#include "TError.h"
27#include "TColor.h"
28#include "TLine.h"
29
31
32
33/** \class TPaveText
34\ingroup BasicGraphics
35
36A Pave (see TPave) with text, lines or/and boxes inside.
37
38Line (and boxes) are positioned in the pave using coordinates relative to
39the pave (%).
40
41The text lines are added in order using the AddText method. Also line separators
42can be added, in order too, using the AddLine method.
43
44AddText returns a TText corresponding to the line added to the pave. This
45return value can be used to modify the text attributes.
46
47Once the TPaveText is build the text of each line can be retrieved using
48GetLine or GetLineWith as a TText wich is useful to modify the text attributes
49of a line.
50
51Example:
52Begin_Macro(source)
53../../../tutorials/graphics/pavetext.C
54End_Macro
55
56GetListOfLines can also be used to retrieve all the lines in the TPaveText as
57a TList:
58
59Begin_Macro(source)
60{
61 TPaveText *t = new TPaveText(.05,.3,.95,.6);
62 t->AddText("This line is blue"); ((TText*)t->GetListOfLines()->Last())->SetTextColor(kBlue);
63 t->AddText("This line is red"); ((TText*)t->GetListOfLines()->Last())->SetTextColor(kRed);
64 t->Draw();
65}
66End_Macro
67
68*/
69
70////////////////////////////////////////////////////////////////////////////////
71/// pavetext default constructor.
72
74{
75 fLines = nullptr;
76 fMargin = 0.05;
77 fLongest = 0;
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// PaveText normal constructor.
82///
83/// A PaveText is a Pave with several lines of text
84///
85/// - option = "TR" Top and Right shadows are drawn.
86/// - option = "TL" Top and Left shadows are drawn.
87/// - option = "BR" Bottom and Right shadows are drawn.
88/// - option = "BL" Bottom and Left shadows are drawn.
89///
90/// If none of these four above options is specified the default the
91/// option "BR" will be used to draw the border. To produces a pave
92/// without any border it is enough to specify the option "NB" (no border).
93///
94/// - option = "NDC" x1,y1,x2,y2 are given in NDC
95/// - option = "ARC" corners are rounded
96///
97/// In case of option "ARC", the corner radius is specified
98/// via TPave::SetCornerRadius(rad) where rad is given in percent
99/// of the pave height (default value is 0.2).
100///
101/// The individual text items are entered via AddText
102/// By default, text items inherits from the default pavetext AttText.
103/// A title can be added later to this pavetext via TPaveText::SetLabel.
104
106 :TPave(x1,y1,x2,y2,4,option), TAttText(22,0,gStyle->GetTextColor(),gStyle->GetTextFont(),0)
107{
108 fLines = new TList;
109 fMargin = 0.05;
110 fLongest = 0;
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// pavetext default destructor.
115
117{
118 if (ROOT::Detail::HasBeenDeleted(this)) return;
119 if (fLines) fLines->Delete();
120 delete fLines;
121 fLines = nullptr;
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// pavetext copy constructor.
126
127TPaveText::TPaveText(const TPaveText &pavetext) : TPave(pavetext), TAttText(pavetext)
128{
129 fLabel = pavetext.fLabel;
130 fLongest = pavetext.fLongest;
131 fMargin = pavetext.fMargin;
132 if (pavetext.fLines)
133 fLines = (TList *) pavetext.fLines->Clone();
134}
135
136////////////////////////////////////////////////////////////////////////////////
137///assignment operator
138
140{
141 if(this != &pt) {
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;
182 fLines->Add(newline);
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;
200 fLines->Add(newtext);
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;
229 Double_t ymouse, yobj;
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;
265 Double_t ymouse, yobj;
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(Form("((TCanvas*)0x%zx)->SetSelected((TObject*)0x%zx)",
272 (size_t)gPad->GetCanvas(), (size_t)text));
273 gROOT->ProcessLine(Form("((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());
324 Double_t yspace = (fY2 - fY1)/Double_t(nlines);
325 Double_t y1,y,dy;
326 Double_t ytext = fY2 + 0.5*yspace;
327 Int_t valign;
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()) {
376 if (line->InheritsFrom(TText::Class())) nlines++;
377 }
378 return nlines;
379}
380
381////////////////////////////////////////////////////////////////////////////////
382/// Add a new line at the mouse position.
383
385{
386 if (!gPad->IsEditable()) return;
387 Double_t ymouse=0, yobj;
388 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
389 Double_t yline = (ymouse-fY1)/(fY2-fY1);
390 TLine *newline = AddLine(0,yline,0,yline);
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;
404 Double_t ymouse, yobj;
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
418{
419 // Draw the pave
423}
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;
443 Double_t yspace = dy/Double_t(nlines);
444 Double_t textsave = textsize;
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;
474 Int_t halign;
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
570 SetTextSize(textsave);
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;
580 title.SetFillColor(GetFillColor());
581 title.SetTextColor(GetTextColor());
582 title.SetTextFont(GetTextFont());
583 title.Paint();
584 }
585}
586
587////////////////////////////////////////////////////////////////////////////////
588/// Dump this pavetext with its attributes.
589
591{
593 if (fLines) fLines->Print();
594}
595
596////////////////////////////////////////////////////////////////////////////////
597/// Read lines of filename in this pavetext.
598///
599/// Read from line number fromline a total of nlines
600///
601/// Note that this function changes the default text alignment to left/center
602
603void TPaveText::ReadFile(const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
604{
605 Int_t ival;
606 Float_t val;
607 TString opt = option;
608 if (!opt.Contains("+")) {
609 Clear();
610 fLongest = 0;
611 }
612 SetTextAlign(12);
613 // Get file name
614 TString fname = filename;
615 if (fname.EndsWith(";"))
616 fname.Resize(fname.Length() - 1);
617 if (fname.Length() == 0)
618 return;
619
620 std::ifstream file(fname.Data(),std::ios::in);
621 if (!file.good()) {
622 Error("ReadFile", "illegal file name %s", fname.Data());
623 return;
624 }
625
626 const int linesize = 255;
627 char currentline[linesize];
628 char *ss, *sclose, *s = nullptr;
629
630 Int_t kline = 0;
631 while (1) {
632 file.getline(currentline,linesize);
633 if (file.eof())break;
634 if (kline >= fromline && kline < fromline+nlines) {
635 s = currentline;
636 if (strstr(s,"+SetText")) {
637 ss = s+8;
638 sclose = strstr(ss,")");
639 if (!sclose) continue;
640 *sclose = 0;
641 TText *lastline = (TText*)fLines->Last();
642 if (!lastline) continue;
643 if (strstr(ss,"Color(")) {
644 sscanf(ss+6,"%d",&ival);
645 lastline->SetTextColor(ival);
646 continue;
647 }
648 if (strstr(ss,"Align(")) {
649 sscanf(ss+6,"%d",&ival);
650 lastline->SetTextAlign(ival);
651 continue;
652 }
653 if (strstr(ss,"Font(")) {
654 sscanf(ss+5,"%d",&ival);
655 lastline->SetTextFont(ival);
656 continue;
657 }
658 if (strstr(ss,"Size(")) {
659 sscanf(ss+5,"%f",&val);
660 lastline->SetTextSize(val);
661 continue;
662 }
663 if (strstr(ss,"Angle(")) {
664 sscanf(ss+6,"%f",&val);
665 lastline->SetTextAngle(val);
666 continue;
667 }
668 }
669 AddText(s);
670 }
671 kline++;
672 }
673 file.close();
674}
675
676////////////////////////////////////////////////////////////////////////////////
677/// Save lines of this pavetext as C++ statements on output stream out
678
679void TPaveText::SaveLines(std::ostream &out, const char *name, Bool_t saved)
680{
681 if (!fLines) return;
682 Int_t nlines = GetSize();
683 if (nlines == 0) return;
684
685 if (!name || !*name)
686 name = "pt";
687
688 // Iterate over all lines
689 char quote = '"';
690 TIter next(fLines);
691
692 Bool_t savedlt = kFALSE, savedt = kFALSE, savedl = kFALSE, savedb = kFALSE;
693
694 while (auto line = next()) {
695 // Next primitive is a line
696 if (line->IsA() == TLine::Class()) {
697 auto linel = (TLine*)line;
698 if (saved || savedl) {
699 out<<" ";
700 } else {
701 out<<" TLine *";
702 savedl = kTRUE;
703 }
704
705 auto line_name = TString::Format("%s_Line", name);
706
707 out<<line_name<<" = "<<name<<"->AddLine("
708 <<linel->GetX1()<<","<<linel->GetY1()<<","<<linel->GetX2()<<","<<linel->GetY2()<<");"<<std::endl;
709
710 linel->SaveLineAttributes(out, line_name.Data(), 1, 1, 1);
711 continue;
712 }
713 // Next primitive is a box
714 if (line->IsA() == TBox::Class()) {
715 auto lineb = (TBox*)line;
716 if (saved || savedb) {
717 out<<" ";
718 } else {
719 out<<" TBox *";
720 savedb = kTRUE;
721 }
722
723 auto box_name = TString::Format("%s_Box", name);
724
725 out<<box_name<<" = "<<name<<"->AddBox("
726 <<lineb->GetX1()<<","<<lineb->GetY1()<<","<<lineb->GetX2()<<","<<lineb->GetY2()<<");"<<std::endl;
727
728 lineb->SaveFillAttributes(out, box_name.Data(), 18, 1001);
729 lineb->SaveLineAttributes(out, box_name.Data(), 1, 1, 1);
730 continue;
731 }
732 // Next primitive is a text
733 if (line->IsA() == TText::Class()) {
734 auto linet = (TText*)line;
735 if (saved || savedt) {
736 out<<" ";
737 } else {
738 out<<" TText *";
739 savedt = kTRUE;
740 }
741
742 auto text_name = TString::Format("%s_Text", name);
743
744 TString s = linet->GetTitle();
746
747 if (!linet->GetX() && !linet->GetY())
748 out<<text_name<<" = "<<name<<"->AddText(" <<quote<<s<<quote<<");"<<std::endl;
749 else
750 out<<text_name<<" = "<<name<<"->AddText("
751 <<linet->GetX()<<","<<linet->GetY()<<","<<quote<<s<<quote<<");"<<std::endl;
752
753 linet->SaveTextAttributes(out, text_name.Data(), 0, GetTextAngle(), 0, 0, 0);
754 continue;
755 }
756 // Next primitive is a Latex text
757 if (line->IsA() == TLatex::Class()) {
758 auto latex = (TLatex*)line;
759 if (saved || savedlt) {
760 out<<" ";
761 } else {
762 out<<" TText *";
763 savedlt = kTRUE;
764 }
765
766 auto latex_name = TString::Format("%s_LaTex", name);
767
768 TString sl = latex->GetTitle();
770
771 if (!latex->GetX() && !latex->GetY())
772 out<< latex_name << " = "<<name<<"->AddText(" <<quote<<sl<<quote<<");"<<std::endl;
773 else
774 out<< latex_name << " = "<<name<<"->AddText("
775 <<latex->GetX()<<","<<latex->GetY()<<","<<quote<<sl<<quote<<");"<<std::endl;
776
777 latex->SaveTextAttributes(out, latex_name.Data(), 0, GetTextAngle(), 0, 0, 0);
778 }
779 }
780}
781
782////////////////////////////////////////////////////////////////////////////////
783/// Save primitive as a C++ statement(s) on output stream out
784
785void TPaveText::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
786{
787 char quote = '"';
788 Bool_t saved = gROOT->ClassSaved(TPaveText::Class());
789 out<<" "<<std::endl;
790 if (saved) {
791 out<<" ";
792 } else {
793 out<<" "<<ClassName()<<" *";
794 }
795 if (fOption.Contains("NDC")) {
796 out<<"pt = new "<<ClassName()<<"("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
797 <<","<<quote<<fOption<<quote<<");"<<std::endl;
798 } else {
799 out<<"pt = new "<<ClassName()<<"("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
800 <<","<<quote<<fOption<<quote<<");"<<std::endl;
801 }
802 if (strcmp(GetName(),"TPave")) {
803 out<<" pt->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
804 }
805 if (fLabel.Length() > 0) {
806 out<<" pt->SetLabel("<<quote<<fLabel<<quote<<");"<<std::endl;
807 }
808 if (fBorderSize != 4) {
809 out<<" pt->SetBorderSize("<<fBorderSize<<");"<<std::endl;
810 }
811 SaveFillAttributes(out,"pt",19,1001);
812 SaveLineAttributes(out,"pt",1,1,1);
813 SaveTextAttributes(out,"pt",22,0,1,62,0);
814 SaveLines(out,"pt",saved);
815 out<<" pt->Draw();"<<std::endl;
816}
817
818////////////////////////////////////////////////////////////////////////////////
819/// Set attribute option for all lines containing string text.
820///
821/// Possible options are all the AttText attributes
822/// Align, Color, Font, Size and Angle
823
825{
826 TString opt=option;
827 opt.ToLower();
828 TText *line;
829 TIter next(fLines);
830 while ((line = (TText*) next())) {
831 if (strstr(line->GetTitle(),text)) {
832 if (opt == "align") line->SetTextAlign(Int_t(value));
833 if (opt == "color") line->SetTextColor(Int_t(value));
834 if (opt == "font") line->SetTextFont(Int_t(value));
835 if (opt == "size") line->SetTextSize(value);
836 if (opt == "angle") line->SetTextAngle(value);
837 }
838 }
839}
840
841////////////////////////////////////////////////////////////////////////////////
842/// Stream an object of class TPaveText.
843
845{
846 if (R__b.IsReading()) {
847 UInt_t R__s, R__c;
848 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
849 if (R__v > 1) {
850 R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
851 return;
852 }
853 //====process old versions before automatic schema evolution
854 TPave::Streamer(R__b);
855 TAttText::Streamer(R__b);
856 if (R__v > 1) fLabel.Streamer(R__b);
857 R__b >> fLongest;
858 R__b >> fMargin;
859 R__b >> fLines;
860 R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
861 //====end of old versions
862
863 } else {
865 }
866}
867
868////////////////////////////////////////////////////////////////////////////////
869/// Replace current attributes by current style.
870
872{
873 if (gStyle->IsReading()) {
877 } else {
881 }
882}
@ kDiamond
Definition Buttons.h:37
@ kPaveText
Definition Buttons.h:32
short Style_t
Definition RtypesCore.h:89
int Int_t
Definition RtypesCore.h:45
short Color_t
Definition RtypesCore.h:92
float Size_t
Definition RtypesCore.h:96
short Version_t
Definition RtypesCore.h:65
float Float_t
Definition RtypesCore.h:57
short Short_t
Definition RtypesCore.h:39
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
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:405
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
R__EXTERN TStyle * gStyle
Definition TStyle.h:414
#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:236
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:273
Text Attributes class.
Definition TAttText.h:18
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:36
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:42
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:32
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:35
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:34
virtual void Streamer(TBuffer &)
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:43
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:33
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:44
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:46
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition TAttText.cxx:375
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
Create a Box.
Definition TBox.h:22
Double_t GetX1() const
Definition TBox.h:51
virtual void PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option="")
Draw this box with new coordinates.
Definition TBox.cxx:677
static TClass * Class()
Double_t fX1
X of 1st point.
Definition TBox.h:28
Double_t GetX2() const
Definition TBox.h:52
Double_t GetY1() const
Definition TBox.h:53
Double_t GetY2() const
Definition TBox.h:54
TBox()
Box default constructor.
Definition TBox.cxx:42
Double_t fY2
Y of 2nd point.
Definition TBox.h:31
Double_t fX2
X of 2nd point.
Definition TBox.h:30
Double_t fY1
Y of 1st point.
Definition TBox.h:29
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
void Print(Option_t *option="") const override
Default print for collections, calls Print(option, 1).
TObject * Clone(const char *newname="") const override
Make a clone of an collection using the Streamer facility.
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:2502
static TClass * Class()
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition TLatex.cxx:2053
Use the TLine constructor to create a simple line.
Definition TLine.h:22
static TClass * Class()
virtual void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition TLine.cxx:397
Double_t GetY1() const
Definition TLine.h:52
Double_t GetX2() const
Definition TLine.h:51
TClass * IsA() const override
Definition TLine.h:79
Double_t GetX1() const
Definition TLine.h:50
Double_t GetY2() const
Definition TLine.h:53
A doubly linked list.
Definition TList.h:38
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
Definition TList.cxx:250
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:822
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:693
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
Definition TList.cxx:196
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:423
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:184
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:970
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:483
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)
void Streamer(TBuffer &) override
Stream an object of class TPaveText.
TList * fLines
List of labels.
Definition TPaveText.h:27
virtual void PaintPrimitives(Int_t mode)
Paint list of primitives in this pavetext.
TClass * IsA() const override
Definition TPaveText.h:65
void Print(Option_t *option="") const override
Dump this pavetext with its attributes.
TPaveText()
pavetext default constructor.
Definition TPaveText.cxx:73
virtual TLine * AddLine(Double_t x1=0, Double_t y1=0, Double_t x2=0, Double_t y2=0)
Add a new graphics line to this pavetext.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
virtual void InsertText(const char *label)
Add a new Text line at the mouse position.
virtual void ReadFile(const char *filename, Option_t *option="", Int_t nlines=50, Int_t fromline=0)
Read lines of filename in this pavetext.
virtual void DrawFile(const char *filename, Option_t *option="")
Draw lines in filename in this pavetext.
virtual void EditText()
Edit text at the mouse position.
virtual void SetAllWith(const char *text, Option_t *option, Double_t value)
Set attribute option for all lines containing string text.
virtual TObject * GetObject(Double_t &ymouse, Double_t &yobj) const
Get object pointed by the mouse in this pavetext.
virtual void SaveLines(std::ostream &out, const char *name, Bool_t saved)
Save lines of this pavetext as C++ statements on output stream out.
virtual void DeleteText()
Delete text at the mouse position.
void Clear(Option_t *option="") override
Clear all lines in this pavetext.
virtual ~TPaveText()
pavetext default destructor.
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:615
Int_t GetBorderSize() const
Definition TPave.h:54
TPave & operator=(const TPave &src)
Assignment operator.
Definition TPave.cxx:129
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Definition TPave.cxx:139
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:704
Int_t fBorderSize
window box bordersize in pixels
Definition TPave.h:26
Double_t fX2NDC
X2 point in NDC coordinates.
Definition TPave.h:24
TString fOption
Pave style.
Definition TPave.h:30
Double_t fY2NDC
Y2 point in NDC coordinates.
Definition TPave.h:25
Double_t fX1NDC
X1 point in NDC coordinates.
Definition TPave.h:22
Option_t * GetOption() const override
Definition TPave.h:57
Double_t fY1NDC
Y1 point in NDC coordinates.
Definition TPave.h:23
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:139
Ssiz_t Length() const
Definition TString.h:421
void ToLower()
Change string to lower-case.
Definition TString.cxx:1170
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2222
TString & ReplaceSpecialCppChars()
Find special characters which are typically used in printf() calls and replace them by appropriate es...
Definition TString.cxx:1102
const char * Data() const
Definition TString.h:380
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1140
virtual void Streamer(TBuffer &)
Stream a string object.
Definition TString.cxx:1390
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:2356
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:636
Bool_t IsReading() const
Definition TStyle.h:283
Base class for several text objects.
Definition TText.h:22
Double_t GetX() const
Definition TText.h:53
virtual void SetY(Double_t y)
Definition TText.h:77
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition TText.cxx:744
virtual void SetX(Double_t x)
Definition TText.h:76
Double_t GetY() const
Definition TText.h:61
static TClass * Class()
TPaveText * pt
TLine * line
Double_t y[n]
Definition legend1.C:17
R__ALWAYS_INLINE bool HasBeenDeleted(const TObject *obj)
Check if the TObject's memory has been deleted.
Definition TObject.h:404
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
Definition file.py:1