Logo ROOT   6.16/01
Reference Guide
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 <string.h>
13#include <stdlib.h>
14#include <stdio.h>
15
16#include "Riostream.h"
17#include "TBufferFile.h"
18#include "TROOT.h"
19#include "TStyle.h"
20#include "TPaveText.h"
21#include "TPaveLabel.h"
22#include "TVirtualPad.h"
23#include "TMath.h"
24#include "TLatex.h"
25#include "TError.h"
26#include "TColor.h"
27#include "TClass.h"
28
30
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/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 = 0;
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///
93/// - option = "NDC" x1,y1,x2,y2 are given in NDC
94/// - option = "ARC" corners are rounded
95///
96/// In case of option "ARC", the corner radius is specified
97/// via TPave::SetCornerRadius(rad) where rad is given in percent
98/// of the pave height (default value is 0.2).
99///
100/// The individual text items are entered via AddText
101/// By default, text items inherits from the default pavetext AttText.
102/// A title can be added later to this pavetext via TPaveText::SetLabel.
103
105 :TPave(x1,y1,x2,y2,4,option), TAttText(22,0,gStyle->GetTextColor(),gStyle->GetTextFont(),0)
106{
107 fLines = new TList;
108 fMargin = 0.05;
109 fLongest = 0;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// pavetext default destructor.
114
116{
117 if (!TestBit(kNotDeleted)) return;
118 if (fLines) fLines->Delete();
119 delete fLines;
120 fLines = 0;
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// pavetext copy constructor.
125
127{
129 TPaveText *p = (TPaveText*)(&pavetext);
130 p->Streamer(b);
131 b.SetReadMode();
132 b.SetBufferOffset(0);
133 fLines = 0;
134 Streamer(b);
135}
136
137////////////////////////////////////////////////////////////////////////////////
138///assignment operator
139
141{
142 if(this!=&pt) {
149 }
150 return *this;
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Add a new graphics box to this pavetext.
155
157{
158 if (!gPad->IsEditable()) return 0;
159 TBox *newbox = new TBox(x1,y1,x2,y2);
160
161 if (!fLines) fLines = new TList;
162 fLines->Add(newbox);
163 return newbox;
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Add a new graphics line to this pavetext.
168
170{
171 if (!gPad->IsEditable()) return 0;
172 TLine *newline = new TLine(x1,y1,x2,y2);
173
174 if (!fLines) fLines = new TList;
175 fLines->Add(newline);
176 return newline;
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Add a new Text line to this pavetext at given coordinates.
181
183{
184 TLatex *newtext = new TLatex(x1,y1,text);
185 newtext->SetTextAlign(0);
186 newtext->SetTextColor(0);
187 newtext->SetTextFont(0);
188 newtext->SetTextSize(0);
189 Int_t nch = strlen(text);
190 if (nch > fLongest) fLongest = nch;
191
192 if (!fLines) fLines = new TList;
193 fLines->Add(newtext);
194 return newtext;
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Add a new Text line to this pavetext.
199
201{
202 return AddText(0,0,text);
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Clear all lines in this pavetext.
207
209{
210 if (!fLines) return;
211 fLines->Delete();
212 fLongest = 0;
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Delete text at the mouse position.
217
219{
220 if (!gPad->IsEditable()) return;
221 if (!fLines) return;
222 Double_t ymouse, yobj;
223 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
224 if (!obj) return;
225 if (!obj->InheritsFrom(TText::Class())) return;
226 fLines->Remove(obj);
227 delete obj;
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Draw this pavetext with its current attributes.
232
234{
235 Option_t *opt;
236 if (option && strlen(option)) opt = option;
237 else opt = GetOption();
238
239 AppendPad(opt);
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Draw lines in filename in this pavetext.
244
245void TPaveText::DrawFile(const char *filename, Option_t *option)
246{
247 ReadFile(filename);
248
249 AppendPad(option);
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Edit text at the mouse position.
254
256{
257 if (!gPad->IsEditable()) return;
258 Double_t ymouse, yobj;
259 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
260 if (!obj) return;
261 if (!obj->InheritsFrom(TText::Class())) return;
262 TText *text = (TText*)obj;
263 gROOT->SetSelectedPrimitive(text);
264 gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->SetSelected((TObject*)0x%lx)",
265 (ULong_t)gPad->GetCanvas(), (ULong_t)text));
266 gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->Selected((TVirtualPad*)0x%lx,(TObject*)0x%lx,1)",
267 (ULong_t)gPad->GetCanvas(), (ULong_t)gPad, (ULong_t)text));
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Get Pointer to line number in this pavetext.
273
275{
276 TText *line;
277 TIter next(fLines);
278 Int_t nlines = 0;
279 while ((line = (TText*) next())) {
280 if (nlines == number) return line;
281 nlines++;
282 }
283 return 0;
284}
285
286////////////////////////////////////////////////////////////////////////////////
287/// Get Pointer to first containing string text in this pavetext.
288
290{
291 TText *line;
292 TIter next(fLines);
293 while ((line = (TText*) next())) {
294 if (strstr(line->GetTitle(),text)) return line;
295 }
296 return 0;
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Get object pointed by the mouse in this pavetext.
301
303{
304 if (!fLines) return 0;
305 Int_t nlines = GetSize();
306 if (nlines == 0) return 0;
307
308 // Evaluate text size as a function of the number of lines
309
310 ymouse = gPad->AbsPixeltoY(gPad->GetEventY());
311 Double_t yspace = (fY2 - fY1)/Double_t(nlines);
312 Double_t y1,y,dy;
313 Double_t ytext = fY2 + 0.5*yspace;
314 Int_t valign;
315
316 // Iterate over all lines
317 // Copy pavetext attributes to line attributes if line attributes not set
318 dy = fY2 - fY1;
319 TObject *line;
320 TText *linet;
321 TLine *linel;
322 TBox *lineb;
323 TIter next(fLines);
324 while ((line = (TObject*) next())) {
325 // Next primitive is a line
326 if (line->IsA() == TLine::Class()) {
327 linel = (TLine*)line;
328 y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
329 if (TMath::Abs(y1-ymouse) < 0.2*yspace) {yobj = y1; return line;}
330 continue;
331 }
332 // Next primitive is a box
333 if (line->IsA() == TBox::Class()) {
334 lineb = (TBox*)line;
335 y1 = lineb->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
336 if (TMath::Abs(y1-ymouse) < 0.4*yspace) {yobj = y1; return line;}
337 continue;
338 }
339 // Next primitive is a text
341 linet = (TText*)line;
342 ytext -= yspace;
343 Double_t yl = linet->GetY();
344 Short_t talign = linet->GetTextAlign();
345 if (talign == 0) talign = GetTextAlign();
346 if (yl > 0 && yl <1) {
347 ytext = fY1 + yl*dy;
348 }
349 valign = linet->GetTextAlign()%10;
350 y = ytext;
351 if (valign == 1) y = ytext -0.5*yspace;
352 if (valign == 3) y = ytext +0.5*yspace;
353
354 if (TMath::Abs(y-ymouse) < 0.5*yspace) {yobj = y; return line;}
355 }
356 }
357 return 0;
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// return number of text lines (ignoring TLine, etc)
362
364{
365 Int_t nlines = 0;
366 TIter next(fLines);
367 TObject *line;
368 while ((line = (TObject*) next())) {
369 if (line->InheritsFrom(TText::Class())) nlines++;
370 }
371 return nlines;
372}
373
374////////////////////////////////////////////////////////////////////////////////
375/// Add a new line at the mouse position.
376
378{
379 if (!gPad->IsEditable()) return;
380 Double_t ymouse=0, yobj;
381 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
382 Double_t yline = (ymouse-fY1)/(fY2-fY1);
383 TLine *newline = AddLine(0,yline,0,yline);
384 if (obj) {
385 fLines->Remove(newline); //remove line from last position
386 if (yobj < ymouse) fLines->AddBefore(obj,newline);
387 else fLines->AddAfter(obj,newline);
388 }
389}
390
391////////////////////////////////////////////////////////////////////////////////
392/// Add a new Text line at the mouse position.
393
395{
396 if (!gPad->IsEditable()) return;
397 Double_t ymouse, yobj;
398 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
399 TText *newtext = AddText(0,0,text); //create new text object
400 if (obj) {
401 fLines->Remove(newtext); //remove text from last position
402 if (yobj < ymouse) fLines->AddBefore(obj,newtext); //insert new text at right position
403 else fLines->AddAfter(obj,newtext); //insert new text at right position
404 }
405}
406
407////////////////////////////////////////////////////////////////////////////////
408/// Paint this pavetext with its current attributes.
409
411{
412 // Draw the pave
416}
417
418////////////////////////////////////////////////////////////////////////////////
419/// Paint list of primitives in this pavetext.
420
422{
423 if (!fLines) return;
424 Double_t dx = fX2 - fX1;
425 Double_t dy = fY2 - fY1;
426 Double_t textsize = GetTextSize();
427 Int_t nlines = GetSize();
428 if (nlines == 0) nlines = 5;
429
430 // Evaluate text size as a function of the number of lines
431
432 Double_t x1,y1,x2,y2;
433 y1 = gPad->GetY1();
434 y2 = gPad->GetY2();
435 Float_t margin = fMargin*dx;
436 Double_t yspace = dy/Double_t(nlines);
437 Double_t textsave = textsize;
438 TObject *line;
439 TText *linet;
440 TLatex *latex;
441 TIter next(fLines);
442 Double_t longest = 0;
443 Double_t w;
444 if (textsize == 0) {
445 textsize = 0.85*yspace/(y2 - y1);
446 while ((line = (TObject*) next())) {
447 if (line->IsA() == TLatex::Class()) {
448 latex = (TLatex*)line;
449 Float_t tangle = latex->GetTextAngle();
450 if (latex->GetTextSize() != 0) continue;
451 Style_t tfont = latex->GetTextFont();
452 if (tfont == 0) latex->SetTextFont(GetTextFont());
453 latex->SetTextSize(textsize);
454 w = latex->GetXsize();
455 latex->SetTextSize(0);
456 latex->SetTextAngle(tangle); //text angle was redefined in GetXsize !
457 if (w > longest) longest = w;
458 latex->SetTextFont(tfont);
459 }
460 }
461 if (longest > 0.92*dx) textsize *= 0.92*dx/longest;
462 if (mode == kDiamond) textsize *= 0.66;
463 SetTextSize(textsize);
464 }
465 Double_t ytext = fY2 + 0.5*yspace;
466 Double_t xtext = 0;
467 Int_t halign;
468
469 // Iterate over all lines
470 // Copy pavetext attributes to line attributes if line attributes not set
471 TLine *linel;
472 TBox *lineb;
473 next.Reset();
474 while ((line = (TObject*) next())) {
475 // Next primitive is a line
476 if (line->IsA() == TLine::Class()) {
477 linel = (TLine*)line;
478 x1 = linel->GetX1(); if (x1 == 0) x1 = fX1; else x1 = fX1 + x1*dx;
479 x2 = linel->GetX2(); if (x2 == 0) x2 = fX2; else x2 = fX1 + x2*dx;
480 y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
481 y2 = linel->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
482 linel->PaintLine(x1,y1,x2,y2);
483 continue;
484 }
485 // Next primitive is a box
486 if (line->IsA() == TBox::Class()) {
487 lineb = (TBox*)line;
488 x1 = lineb->GetX1();
489 if (x1) x1 = fX1 + x1*dx;
490 else x1 = fX1 + gPad->PixeltoX(1) - gPad->PixeltoX(0);
491 x2 = lineb->GetX2();
492 if (x2) x2 = fX1 + x2*dx;
493 else x2 = fX2;
494 y1 = lineb->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
495 y2 = lineb->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
496 lineb->PaintBox(x1,y1,x2,y2);
497 continue;
498 }
499 // Next primitive is a text
500 if (line->IsA() == TText::Class()) {
501 linet = (TText*)line;
502 ytext -= yspace;
503 Double_t xl = linet->GetX();
504 Double_t yl = linet->GetY();
505 Short_t talign = linet->GetTextAlign();
506 Color_t tcolor = linet->GetTextColor();
507 Style_t tfont = linet->GetTextFont();
508 Size_t tsize = linet->GetTextSize();
509 if (talign == 0) linet->SetTextAlign(GetTextAlign());
510 if (tcolor == 0) linet->SetTextColor(GetTextColor());
511 if (tfont == 0) linet->SetTextFont(GetTextFont());
512 if (tsize == 0) linet->SetTextSize(GetTextSize());
513 if (xl > 0 && xl <1) {
514 xtext = fX1 + xl*dx;
515 } else {
516 halign = linet->GetTextAlign()/10;
517 if (halign == 1) xtext = fX1 + margin;
518 if (halign == 2) xtext = 0.5*(fX1+fX2);
519 if (halign == 3) xtext = fX2 - margin;
520 }
521 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
522 linet->PaintText(xtext,ytext,linet->GetTitle());
523 linet->SetTextAlign(talign);
524 linet->SetTextColor(tcolor);
525 linet->SetTextFont(tfont);
526 linet->SetTextSize(tsize);
527 }
528 // Next primitive is a Latex text
529 if (line->IsA() == TLatex::Class()) {
530 latex = (TLatex*)line;
531 ytext -= yspace;
532 Double_t xl = latex->GetX();
533 Double_t yl = latex->GetY();
534 Short_t talign = latex->GetTextAlign();
535 Color_t tcolor = latex->GetTextColor();
536 Style_t tfont = latex->GetTextFont();
537 Size_t tsize = latex->GetTextSize();
538 if (talign == 0) latex->SetTextAlign(GetTextAlign());
539 if (tcolor == 0) latex->SetTextColor(GetTextColor());
540 if (tfont == 0) latex->SetTextFont(GetTextFont());
541 if (tsize == 0) latex->SetTextSize(GetTextSize());
542 if (xl > 0 && xl <1) {
543 xtext = fX1 + xl*dx;
544 } else {
545 halign = latex->GetTextAlign()/10;
546 if (halign == 1) xtext = fX1 + margin;
547 if (halign == 2) xtext = 0.5*(fX1+fX2);
548 if (halign == 3) xtext = fX2 - margin;
549 }
550 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
551 latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
552 latex->GetTextSize(),
553 latex->GetTitle());
554 latex->SetTextAlign(talign);
555 latex->SetTextColor(tcolor);
556 latex->SetTextFont(tfont);
557 latex->SetTextSize(tsize);
558 latex->SetX(xl); // PaintLatex modifies fX and fY
559 latex->SetY(yl);
560 }
561 }
562
563 SetTextSize(textsave);
564
565 // if a label create & paint a pavetext title
566 if (fLabel.Length() > 0) {
567 dy = gPad->GetY2() - gPad->GetY1();
568 x1 = fX1 + 0.25*dx;
569 x2 = fX2 - 0.25*dx;
570 y1 = fY2 - 0.02*dy;
571 y2 = fY2 + 0.02*dy;
572 TPaveLabel *title = new TPaveLabel(x1,y1,x2,y2,fLabel.Data(),GetDrawOption());
573 title->SetFillColor(GetFillColor());
574 title->SetTextColor(GetTextColor());
575 title->SetTextFont(GetTextFont());
576 title->Paint();
577 delete title;
578 }
579}
580
581////////////////////////////////////////////////////////////////////////////////
582/// Dump this pavetext with its attributes.
583
584void TPaveText::Print(Option_t *option) const
585{
586 TPave::Print(option);
587 if (fLines) fLines->Print();
588}
589
590////////////////////////////////////////////////////////////////////////////////
591/// Read lines of filename in this pavetext.
592///
593/// Read from line number fromline a total of nlines
594///
595/// Note that this function changes the default text alignment to left/center
596
597void TPaveText::ReadFile(const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
598{
599 Int_t ival;
600 Float_t val;
601 TText *lastline = 0;
602 TString opt = option;
603 if (!opt.Contains("+")) {
604 Clear();
605 fLongest = 0;
606 }
607 SetTextAlign(12);
608 // Get file name
609 Int_t nch = strlen(filename);
610 if (nch == 0) return;
611
612 char *fname = StrDup(filename);
613 if (fname[nch-1] == ';') { nch--; fname[nch]=0;}
614
615 std::ifstream file(fname,std::ios::in);
616 if (!file.good()) {
617 Error("ReadFile", "illegal file name");
618 delete [] fname;
619 return;
620 }
621
622 const int linesize = 255;
623 char currentline[linesize];
624 char *ss, *sclose, *s= 0;
625
626 Int_t kline = 0;
627 while (1) {
628 file.getline(currentline,linesize);
629 if (file.eof())break;
630 if (kline >= fromline && kline < fromline+nlines) {
631 s = currentline;
632 if (strstr(s,"+SetText")) {
633 ss = s+8;
634 sclose = strstr(ss,")");
635 if (!sclose) continue;
636 *sclose = 0;
637 lastline = (TText*)fLines->Last();
638 if (!lastline) continue;
639 if (strstr(ss,"Color(")) {
640 sscanf(ss+6,"%d",&ival);
641 lastline->SetTextColor(ival);
642 continue;
643 }
644 if (strstr(ss,"Align(")) {
645 sscanf(ss+6,"%d",&ival);
646 lastline->SetTextAlign(ival);
647 continue;
648 }
649 if (strstr(ss,"Font(")) {
650 sscanf(ss+5,"%d",&ival);
651 lastline->SetTextFont(ival);
652 continue;
653 }
654 if (strstr(ss,"Size(")) {
655 sscanf(ss+5,"%f",&val);
656 lastline->SetTextSize(val);
657 continue;
658 }
659 if (strstr(ss,"Angle(")) {
660 sscanf(ss+6,"%f",&val);
661 lastline->SetTextAngle(val);
662 continue;
663 }
664 }
665 AddText(s);
666 }
667 kline++;
668 }
669 file.close();
670 delete [] fname;
671}
672
673////////////////////////////////////////////////////////////////////////////////
674/// Save lines of this pavetext as C++ statements on output stream out
675
676void TPaveText::SaveLines(std::ostream &out, const char *name, Bool_t saved)
677{
678 if (!fLines) return;
679 Int_t nlines = GetSize();
680 if (nlines == 0) return;
681
682 // Iterate over all lines
683 char quote = '"';
684 TObject *line;
685 TText *linet;
686 TLatex *latex;
687 TLine *linel;
688 TBox *lineb;
689 TIter next(fLines);
690 Bool_t savedlt = kFALSE;
691 Bool_t savedt = kFALSE;
692 Bool_t savedl = kFALSE;
693 Bool_t savedb = kFALSE;
694
695 while ((line = (TObject*) next())) {
696 // Next primitive is a line
697 if (line->IsA() == TLine::Class()) {
698 linel = (TLine*)line;
699 if (saved || savedl) {
700 out<<" ";
701 } else {
702 out<<" TLine *";
703 savedl = kTRUE;
704 }
705 out<<name<<"_Line = "<<name<<"->AddLine("
706 <<linel->GetX1()<<","<<linel->GetY1()<<","<<linel->GetX2()<<","<<linel->GetY2()<<");"<<std::endl;
707 if (linel->GetLineColor() != 1) {
708 if (linel->GetLineColor() > 228) {
709 TColor::SaveColor(out, linel->GetLineColor());
710 out<<" "<<name<<"_Line->SetLineColor(ci);" << std::endl;
711 } else
712 out<<" "<<name<<"_Line->SetLineColor("<<linel->GetLineColor()<<");"<<std::endl;
713 }
714 if (linel->GetLineStyle() != 1) {
715 out<<" "<<name<<"_Line->SetLineStyle("<<linel->GetLineStyle()<<");"<<std::endl;
716 }
717 if (linel->GetLineWidth() != 1) {
718 out<<" "<<name<<"_Line->SetLineWidth("<<linel->GetLineWidth()<<");"<<std::endl;
719 }
720 continue;
721 }
722 // Next primitive is a box
723 if (line->IsA() == TBox::Class()) {
724 lineb = (TBox*)line;
725 if (saved || savedb) {
726 out<<" ";
727 } else {
728 out<<" TBox *";
729 savedb = kTRUE;
730 }
731 out<<name<<"_Box = "<<name<<"->AddBox("
732 <<lineb->GetX1()<<","<<lineb->GetY1()<<","<<lineb->GetX2()<<","<<lineb->GetY2()<<");"<<std::endl;
733 if (lineb->GetFillColor() != 18) {
734 if (lineb->GetFillColor() > 228) {
735 TColor::SaveColor(out, lineb->GetFillColor());
736 out<<" "<<name<<"_Box->SetFillColor(ci);" << std::endl;
737 } else
738 out<<" "<<name<<"_Box->SetFillColor("<<lineb->GetFillColor()<<");"<<std::endl;
739 }
740 if (lineb->GetFillStyle() != 1001) {
741 out<<" "<<name<<"_Box->SetFillStyle("<<lineb->GetFillStyle()<<");"<<std::endl;
742 }
743 if (lineb->GetLineColor() != 1) {
744 if (lineb->GetLineColor() > 228) {
745 TColor::SaveColor(out, lineb->GetLineColor());
746 out<<" "<<name<<"_Box->SetLineColor(ci);" << std::endl;
747 } else
748 out<<" "<<name<<"_Box->SetLineColor("<<lineb->GetLineColor()<<");"<<std::endl;
749 }
750 if (lineb->GetLineStyle() != 1) {
751 out<<" "<<name<<"_Box->SetLineStyle("<<lineb->GetLineStyle()<<");"<<std::endl;
752 }
753 if (lineb->GetLineWidth() != 1) {
754 out<<" "<<name<<"_Box->SetLineWidth("<<lineb->GetLineWidth()<<");"<<std::endl;
755 }
756 continue;
757 }
758 // Next primitive is a text
759 if (line->IsA() == TText::Class()) {
760 linet = (TText*)line;
761 if (saved || savedt) {
762 out<<" ";
763 } else {
764 out<<" TText *";
765 savedt = kTRUE;
766 }
767 if (!linet->GetX() && !linet->GetY()) {
768 TString s = linet->GetTitle();
769 s.ReplaceAll("\"","\\\"");
770 out<<name<<"_Text = "<<name<<"->AddText("
771 <<quote<<s.Data()<<quote<<");"<<std::endl;
772 } else {
773 out<<name<<"_Text = "<<name<<"->AddText("
774 <<linet->GetX()<<","<<linet->GetY()<<","<<quote<<linet->GetTitle()<<quote<<");"<<std::endl;
775 }
776 if (linet->GetTextColor()) {
777 if (linet->GetTextColor() > 228) {
778 TColor::SaveColor(out, linet->GetTextColor());
779 out<<" "<<name<<"_Text->SetTextColor(ci);" << std::endl;
780 } else
781 out<<" "<<name<<"_Text->SetTextColor("<<linet->GetTextColor()<<");"<<std::endl;
782 }
783 if (linet->GetTextFont()) {
784 out<<" "<<name<<"_Text->SetTextFont("<<linet->GetTextFont()<<");"<<std::endl;
785 }
786 if (linet->GetTextSize()) {
787 out<<" "<<name<<"_Text->SetTextSize("<<linet->GetTextSize()<<");"<<std::endl;
788 }
789 if (linet->GetTextAngle() != GetTextAngle()) {
790 out<<" "<<name<<"_Text->SetTextAngle("<<linet->GetTextAngle()<<");"<<std::endl;
791 }
792 if (linet->GetTextAlign()) {
793 out<<" "<<name<<"_Text->SetTextAlign("<<linet->GetTextAlign()<<");"<<std::endl;
794 }
795 }
796 // Next primitive is a Latex text
797 if (line->IsA() == TLatex::Class()) {
798 latex = (TLatex*)line;
799 if (saved || savedlt) {
800 out<<" ";
801 } else {
802 out<<" TText *";
803 savedlt = kTRUE;
804 }
805 if (!latex->GetX() && !latex->GetY()) {
806 TString sl = latex->GetTitle();
807 sl.ReplaceAll("\"","\\\"");
808 out<<name<<"_LaTex = "<<name<<"->AddText("
809 <<quote<<sl.Data()<<quote<<");"<<std::endl;
810 } else {
811 out<<name<<"_LaTex = "<<name<<"->AddText("
812 <<latex->GetX()<<","<<latex->GetY()<<","<<quote<<latex->GetTitle()<<quote<<");"<<std::endl;
813 }
814 if (latex->GetTextColor()) {
815 if (latex->GetTextColor() > 228) {
816 TColor::SaveColor(out, latex->GetTextColor());
817 out<<" "<<name<<"_LaTex->SetTextColor(ci);" << std::endl;
818 } else
819 out<<" "<<name<<"_LaTex->SetTextColor("<<latex->GetTextColor()<<");"<<std::endl;
820 }
821 if (latex->GetTextFont()) {
822 out<<" "<<name<<"_LaTex->SetTextFont("<<latex->GetTextFont()<<");"<<std::endl;
823 }
824 if (latex->GetTextSize()) {
825 out<<" "<<name<<"_LaTex->SetTextSize("<<latex->GetTextSize()<<");"<<std::endl;
826 }
827 if (latex->GetTextAngle() != GetTextAngle()) {
828 out<<" "<<name<<"_LaTex->SetTextAngle("<<latex->GetTextAngle()<<");"<<std::endl;
829 }
830 if (latex->GetTextAlign()) {
831 out<<" "<<name<<"_LaTex->SetTextAlign("<<latex->GetTextAlign()<<");"<<std::endl;
832 }
833 }
834 }
835}
836
837////////////////////////////////////////////////////////////////////////////////
838/// Save primitive as a C++ statement(s) on output stream out
839
840void TPaveText::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
841{
842 char quote = '"';
843 Bool_t saved = gROOT->ClassSaved(TPaveText::Class());
844 out<<" "<<std::endl;
845 if (saved) {
846 out<<" ";
847 } else {
848 out<<" "<<ClassName()<<" *";
849 }
850 if (fOption.Contains("NDC")) {
851 out<<"pt = new "<<ClassName()<<"("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
852 <<","<<quote<<fOption<<quote<<");"<<std::endl;
853 } else {
854 out<<"pt = new "<<ClassName()<<"("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
855 <<","<<quote<<fOption<<quote<<");"<<std::endl;
856 }
857 if (strcmp(GetName(),"TPave")) {
858 out<<" pt->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
859 }
860 if (fLabel.Length() > 0) {
861 out<<" pt->SetLabel("<<quote<<fLabel<<quote<<");"<<std::endl;
862 }
863 if (fBorderSize != 4) {
864 out<<" pt->SetBorderSize("<<fBorderSize<<");"<<std::endl;
865 }
866 SaveFillAttributes(out,"pt",19,1001);
867 SaveLineAttributes(out,"pt",1,1,1);
868 SaveTextAttributes(out,"pt",22,0,1,62,0);
869 SaveLines(out,"pt",saved);
870 out<<" pt->Draw();"<<std::endl;
871}
872
873////////////////////////////////////////////////////////////////////////////////
874/// Set attribute option for all lines containing string text.
875///
876/// Possible options are all the AttText attributes
877/// Align, Color, Font, Size and Angle
878
879void TPaveText::SetAllWith(const char *text, Option_t *option, Double_t value)
880{
881 TString opt=option;
882 opt.ToLower();
883 TText *line;
884 TIter next(fLines);
885 while ((line = (TText*) next())) {
886 if (strstr(line->GetTitle(),text)) {
887 if (opt == "align") line->SetTextAlign(Int_t(value));
888 if (opt == "color") line->SetTextColor(Int_t(value));
889 if (opt == "font") line->SetTextFont(Int_t(value));
890 if (opt == "size") line->SetTextSize(value);
891 if (opt == "angle") line->SetTextAngle(value);
892 }
893 }
894}
895
896////////////////////////////////////////////////////////////////////////////////
897/// Stream an object of class TPaveText.
898
899void TPaveText::Streamer(TBuffer &R__b)
900{
901 if (R__b.IsReading()) {
902 UInt_t R__s, R__c;
903 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
904 if (R__v > 1) {
905 R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
906 return;
907 }
908 //====process old versions before automatic schema evolution
909 TPave::Streamer(R__b);
910 TAttText::Streamer(R__b);
911 if (R__v > 1) fLabel.Streamer(R__b);
912 R__b >> fLongest;
913 R__b >> fMargin;
914 R__b >> fLines;
915 R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
916 //====end of old versions
917
918 } else {
920 }
921}
922
923////////////////////////////////////////////////////////////////////////////////
924/// Replace current attributes by current style.
925
927{
928 if (gStyle->IsReading()) {
932 } else {
936 }
937}
@ kDiamond
Definition: Buttons.h:37
@ kPaveText
Definition: Buttons.h:32
void Class()
Definition: Class.C:29
#define b(i)
Definition: RSha256.hxx:100
static const double x2[5]
static const double x1[5]
int Int_t
Definition: RtypesCore.h:41
float Size_t
Definition: RtypesCore.h:83
short Version_t
Definition: RtypesCore.h:61
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
unsigned long ULong_t
Definition: RtypesCore.h:51
bool Bool_t
Definition: RtypesCore.h:59
short Short_t
Definition: RtypesCore.h:35
double Double_t
Definition: RtypesCore.h:55
short Color_t
Definition: RtypesCore.h:79
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:363
Binding & operator=(OUT(*fun)(void))
#define gROOT
Definition: TROOT.h:410
char * Form(const char *fmt,...)
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2465
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
#define gPad
Definition: TVirtualPad.h:286
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
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:233
virtual Color_t GetLineColor() const
Return the line color.
Definition: TAttLine.h:33
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual Style_t GetLineStyle() const
Return the line style.
Definition: TAttLine.h:34
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:262
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:41
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 SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition: TAttText.h:42
virtual Float_t GetTextAngle() const
Return the text angle.
Definition: TAttText.h:33
virtual void SetTextAttributes()
Invoke the DialogCanvas Text attributes.
Definition: TAttText.cxx:372
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
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:344
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
Create a Box.
Definition: TBox.h:24
Double_t GetX1() const
Definition: TBox.h:52
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:627
TBox & operator=(const TBox &)
Assignment operator.
Definition: TBox.cxx:92
Double_t fX1
X of 1st point.
Definition: TBox.h:30
Double_t GetX2() const
Definition: TBox.h:53
Double_t GetY1() const
Definition: TBox.h:54
Double_t GetY2() const
Definition: TBox.h:55
TBox()
Box default constructor.
Definition: TBox.cxx:41
Double_t fY2
Y of 2nd point.
Definition: TBox.h:33
Double_t fX2
X of 2nd point.
Definition: TBox.h:32
Double_t fY1
Y of 1st point.
Definition: TBox.h:31
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition: TBufferFile.h:46
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
@ kWrite
Definition: TBuffer.h:70
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2102
void Reset()
Definition: TCollection.h:252
To draw Mathematical Formula.
Definition: TLatex.h:18
Double_t GetXsize()
Return size of the formula along X in pad coordinates.
Definition: TLatex.cxx:2510
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition: TLatex.cxx:2038
A simple line.
Definition: TLine.h:23
virtual void PaintLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition: TLine.cxx:380
Double_t GetY1() const
Definition: TLine.h:51
Double_t GetX2() const
Definition: TLine.h:50
Double_t GetX1() const
Definition: TLine.h:49
Double_t GetY2() const
Definition: TLine.h:52
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:818
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:689
virtual void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
Definition: TList.cxx:247
virtual void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
Definition: TList.cxx:193
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
@ kNotDeleted
object has not been deleted
Definition: TObject.h:78
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:341
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:105
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:20
virtual void Paint(Option_t *option="")
Paint this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:99
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.
Definition: TPaveText.cxx:182
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:233
Int_t fLongest
Length of the longest line.
Definition: TPaveText.h:25
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TPaveText.cxx:840
virtual Int_t GetSize() const
return number of text lines (ignoring TLine, etc)
Definition: TPaveText.cxx:363
TList * fLines
List of labels.
Definition: TPaveText.h:27
virtual void PaintPrimitives(Int_t mode)
Paint list of primitives in this pavetext.
Definition: TPaveText.cxx:421
virtual void UseCurrentStyle()
Replace current attributes by current style.
Definition: TPaveText.cxx:926
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.
Definition: TPaveText.cxx:169
virtual void InsertText(const char *label)
Add a new Text line at the mouse position.
Definition: TPaveText.cxx:394
virtual void ReadFile(const char *filename, Option_t *option="", Int_t nlines=50, Int_t fromline=0)
Read lines of filename in this pavetext.
Definition: TPaveText.cxx:597
virtual void DrawFile(const char *filename, Option_t *option="")
Draw lines in filename in this pavetext.
Definition: TPaveText.cxx:245
virtual void EditText()
Edit text at the mouse position.
Definition: TPaveText.cxx:255
virtual void SetAllWith(const char *text, Option_t *option, Double_t value)
Set attribute option for all lines containing string text.
Definition: TPaveText.cxx:879
virtual TObject * GetObject(Double_t &ymouse, Double_t &yobj) const
Get object pointed by the mouse in this pavetext.
Definition: TPaveText.cxx:302
virtual void SaveLines(std::ostream &out, const char *name, Bool_t saved)
Save lines of this pavetext as C++ statements on output stream out.
Definition: TPaveText.cxx:676
virtual void DeleteText()
Delete text at the mouse position.
Definition: TPaveText.cxx:218
virtual ~TPaveText()
pavetext default destructor.
Definition: TPaveText.cxx:115
virtual void Paint(Option_t *option="")
Paint this pavetext with its current attributes.
Definition: TPaveText.cxx:410
TPaveText & operator=(const TPaveText &)
assignment operator
Definition: TPaveText.cxx:140
virtual TBox * AddBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Add a new graphics box to this pavetext.
Definition: TPaveText.cxx:156
virtual TText * GetLine(Int_t number) const
Get Pointer to line number in this pavetext.
Definition: TPaveText.cxx:274
virtual void Clear(Option_t *option="")
Clear all lines in this pavetext.
Definition: TPaveText.cxx:208
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.
Definition: TPaveText.cxx:377
virtual void Print(Option_t *option="") const
Dump this pavetext with its attributes.
Definition: TPaveText.cxx:584
virtual TText * GetLineWith(const char *text) const
Get Pointer to first containing string text in this pavetext.
Definition: TPaveText.cxx:289
Float_t fMargin
Text margin.
Definition: TPaveText.h:26
A TBox with a bordersize and a shadow option.
Definition: TPave.h:19
virtual void Print(Option_t *option="") const
Dump this pave with its attributes.
Definition: TPave.cxx:600
Int_t GetBorderSize() const
Definition: TPave.h:51
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Definition: TPave.cxx:128
Int_t fBorderSize
window box bordersize in pixels
Definition: TPave.h:26
Double_t fX2NDC
X2 point in NDC coordinates.
Definition: TPave.h:24
Option_t * GetOption() const
Definition: TPave.h:54
Option_t * GetName() const
Returns name of object.
Definition: TPave.h:53
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
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:301
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
void ToLower()
Change string to lower-case.
Definition: TString.cxx:1100
const char * Data() const
Definition: TString.h:364
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
Bool_t IsReading() const
Definition: TStyle.h:277
Base class for several text objects.
Definition: TText.h:23
Double_t GetX() const
Definition: TText.h:51
virtual void SetY(Double_t y)
Definition: TText.h:75
virtual void PaintText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition: TText.cxx:745
virtual void SetX(Double_t x)
Definition: TText.h:74
Double_t GetY() const
Definition: TText.h:59
TPaveText * pt
TText * text
TLine * line
Double_t y[n]
Definition: legend1.C:17
static constexpr double s
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
Definition: file.py:1