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