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 (!TestBit(kNotDeleted)) 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%lx)->SetSelected((TObject*)0x%lx)",
266 (ULong_t)gPad->GetCanvas(), (ULong_t)text));
267 gROOT->ProcessLine(Form("((TCanvas*)0x%lx)->Selected((TVirtualPad*)0x%lx,(TObject*)0x%lx,1)",
268 (ULong_t)gPad->GetCanvas(), (ULong_t)gPad, (ULong_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 Short_t talign = linet->GetTextAlign();
346 if (talign == 0) talign = GetTextAlign();
347 if (yl > 0 && yl <1) {
348 ytext = fY1 + yl*dy;
349 }
350 valign = linet->GetTextAlign()%10;
351 y = ytext;
352 if (valign == 1) y = ytext -0.5*yspace;
353 if (valign == 3) y = ytext +0.5*yspace;
354
355 if (TMath::Abs(y-ymouse) < 0.5*yspace) {yobj = y; return line;}
356 }
357 }
358 return 0;
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// return number of text lines (ignoring TLine, etc)
363
365{
366 Int_t nlines = 0;
367 TIter next(fLines);
368 TObject *line;
369 while ((line = (TObject*) next())) {
370 if (line->InheritsFrom(TText::Class())) nlines++;
371 }
372 return nlines;
373}
374
375////////////////////////////////////////////////////////////////////////////////
376/// Add a new line at the mouse position.
377
379{
380 if (!gPad->IsEditable()) return;
381 Double_t ymouse=0, yobj;
382 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
383 Double_t yline = (ymouse-fY1)/(fY2-fY1);
384 TLine *newline = AddLine(0,yline,0,yline);
385 if (obj) {
386 fLines->Remove(newline); //remove line from last position
387 if (yobj < ymouse) fLines->AddBefore(obj,newline);
388 else fLines->AddAfter(obj,newline);
389 }
390}
391
392////////////////////////////////////////////////////////////////////////////////
393/// Add a new Text line at the mouse position.
394
396{
397 if (!gPad->IsEditable()) return;
398 Double_t ymouse, yobj;
399 TObject *obj = GetObject(ymouse, yobj); //get object pointed by the mouse
400 TText *newtext = AddText(0,0,text); //create new text object
401 if (obj) {
402 fLines->Remove(newtext); //remove text from last position
403 if (yobj < ymouse) fLines->AddBefore(obj,newtext); //insert new text at right position
404 else fLines->AddAfter(obj,newtext); //insert new text at right position
405 }
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// Paint this pavetext with its current attributes.
410
412{
413 // Draw the pave
417}
418
419////////////////////////////////////////////////////////////////////////////////
420/// Paint list of primitives in this pavetext.
421
423{
424 if (!fLines) return;
425 Double_t dx = fX2 - fX1;
426 Double_t dy = fY2 - fY1;
427 Double_t textsize = GetTextSize();
428 Int_t nlines = GetSize();
429 if (nlines == 0) nlines = 5;
430
431 // Evaluate text size as a function of the number of lines
432
433 Double_t x1,y1,x2,y2;
434 y1 = gPad->GetY1();
435 y2 = gPad->GetY2();
436 Float_t margin = fMargin*dx;
437 Double_t yspace = dy/Double_t(nlines);
438 Double_t textsave = textsize;
439 TObject *line;
440 TText *linet;
441 TLatex *latex;
442 TIter next(fLines);
443 Double_t longest = 0;
444 Double_t w;
445 if (textsize == 0) {
446 textsize = 0.85*yspace/(y2 - y1);
447 while ((line = (TObject*) next())) {
448 if (line->IsA() == TLatex::Class()) {
449 latex = (TLatex*)line;
450 Float_t tangle = latex->GetTextAngle();
451 if (latex->GetTextSize() != 0) continue;
452 Style_t tfont = latex->GetTextFont();
453 if (tfont == 0) latex->SetTextFont(GetTextFont());
454 latex->SetTextSize(textsize);
455 w = latex->GetXsize();
456 latex->SetTextSize(0);
457 latex->SetTextAngle(tangle); //text angle was redefined in GetXsize !
458 if (w > longest) longest = w;
459 latex->SetTextFont(tfont);
460 }
461 }
462 if (longest > 0.92*dx) textsize *= 0.92*dx/longest;
463 if (mode == kDiamond) textsize *= 0.66;
464 SetTextSize(textsize);
465 }
466 Double_t ytext = fY2 + 0.5*yspace;
467 Double_t xtext = 0;
468 Int_t halign;
469
470 // Iterate over all lines
471 // Copy pavetext attributes to line attributes if line attributes not set
472 TLine *linel;
473 TBox *lineb;
474 next.Reset();
475 while ((line = (TObject*) next())) {
476 // Next primitive is a line
477 if (line->IsA() == TLine::Class()) {
478 linel = (TLine*)line;
479 x1 = linel->GetX1(); if (x1 == 0) x1 = fX1; else x1 = fX1 + x1*dx;
480 x2 = linel->GetX2(); if (x2 == 0) x2 = fX2; else x2 = fX1 + x2*dx;
481 y1 = linel->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
482 y2 = linel->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
483 linel->PaintLine(x1,y1,x2,y2);
484 continue;
485 }
486 // Next primitive is a box
487 if (line->IsA() == TBox::Class()) {
488 lineb = (TBox*)line;
489 x1 = lineb->GetX1();
490 if (x1) x1 = fX1 + x1*dx;
491 else x1 = fX1 + gPad->PixeltoX(1) - gPad->PixeltoX(0);
492 x2 = lineb->GetX2();
493 if (x2) x2 = fX1 + x2*dx;
494 else x2 = fX2;
495 y1 = lineb->GetY1(); if (y1 == 0) y1 = ytext; else y1 = fY1 + y1*dy;
496 y2 = lineb->GetY2(); if (y2 == 0) y2 = ytext; else y2 = fY1 + y2*dy;
497 lineb->PaintBox(x1,y1,x2,y2);
498 continue;
499 }
500 // Next primitive is a text
501 if (line->IsA() == TText::Class()) {
502 linet = (TText*)line;
503 ytext -= yspace;
504 Double_t xl = linet->GetX();
505 Double_t yl = linet->GetY();
506 Short_t talign = linet->GetTextAlign();
507 Color_t tcolor = linet->GetTextColor();
508 Style_t tfont = linet->GetTextFont();
509 Size_t tsize = linet->GetTextSize();
510 if (talign == 0) linet->SetTextAlign(GetTextAlign());
511 if (tcolor == 0) linet->SetTextColor(GetTextColor());
512 if (tfont == 0) linet->SetTextFont(GetTextFont());
513 if (tsize == 0) linet->SetTextSize(GetTextSize());
514 if (xl > 0 && xl <1) {
515 xtext = fX1 + xl*dx;
516 } else {
517 halign = linet->GetTextAlign()/10;
518 if (halign == 1) xtext = fX1 + margin;
519 if (halign == 2) xtext = 0.5*(fX1+fX2);
520 if (halign == 3) xtext = fX2 - margin;
521 }
522 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
523 linet->PaintText(xtext,ytext,linet->GetTitle());
524 linet->SetTextAlign(talign);
525 linet->SetTextColor(tcolor);
526 linet->SetTextFont(tfont);
527 linet->SetTextSize(tsize);
528 }
529 // Next primitive is a Latex text
530 if (line->IsA() == TLatex::Class()) {
531 latex = (TLatex*)line;
532 ytext -= yspace;
533 Double_t xl = latex->GetX();
534 Double_t yl = latex->GetY();
535 Short_t talign = latex->GetTextAlign();
536 Color_t tcolor = latex->GetTextColor();
537 Style_t tfont = latex->GetTextFont();
538 Size_t tsize = latex->GetTextSize();
539 if (talign == 0) latex->SetTextAlign(GetTextAlign());
540 if (tcolor == 0) latex->SetTextColor(GetTextColor());
541 if (tfont == 0) latex->SetTextFont(GetTextFont());
542 if (tsize == 0) latex->SetTextSize(GetTextSize());
543 if (xl > 0 && xl <1) {
544 xtext = fX1 + xl*dx;
545 } else {
546 halign = latex->GetTextAlign()/10;
547 if (halign == 1) xtext = fX1 + margin;
548 if (halign == 2) xtext = 0.5*(fX1+fX2);
549 if (halign == 3) xtext = fX2 - margin;
550 }
551 if (yl > 0 && yl <1) ytext = fY1 + yl*dy;
552 latex->PaintLatex(xtext,ytext,latex->GetTextAngle(),
553 latex->GetTextSize(),
554 latex->GetTitle());
555 latex->SetTextAlign(talign);
556 latex->SetTextColor(tcolor);
557 latex->SetTextFont(tfont);
558 latex->SetTextSize(tsize);
559 latex->SetX(xl); // PaintLatex modifies fX and fY
560 latex->SetY(yl);
561 }
562 }
563
564 SetTextSize(textsave);
565
566 // if a label create & paint a pavetext title
567 if (fLabel.Length() > 0) {
568 dy = gPad->GetY2() - gPad->GetY1();
569 x1 = fX1 + 0.25*dx;
570 x2 = fX2 - 0.25*dx;
571 y1 = fY2 - 0.02*dy;
572 y2 = fY2 + 0.02*dy;
573 TPaveLabel *title = new TPaveLabel(x1,y1,x2,y2,fLabel.Data(),GetDrawOption());
574 title->SetFillColor(GetFillColor());
575 title->SetTextColor(GetTextColor());
576 title->SetTextFont(GetTextFont());
577 title->Paint();
578 delete title;
579 }
580}
581
582////////////////////////////////////////////////////////////////////////////////
583/// Dump this pavetext with its attributes.
584
585void TPaveText::Print(Option_t *option) const
586{
587 TPave::Print(option);
588 if (fLines) fLines->Print();
589}
590
591////////////////////////////////////////////////////////////////////////////////
592/// Read lines of filename in this pavetext.
593///
594/// Read from line number fromline a total of nlines
595///
596/// Note that this function changes the default text alignment to left/center
597
598void TPaveText::ReadFile(const char *filename, Option_t *option, Int_t nlines, Int_t fromline)
599{
600 Int_t ival;
601 Float_t val;
602 TText *lastline = 0;
603 TString opt = option;
604 if (!opt.Contains("+")) {
605 Clear();
606 fLongest = 0;
607 }
608 SetTextAlign(12);
609 // Get file name
610 Int_t nch = strlen(filename);
611 if (nch == 0) return;
612
613 char *fname = StrDup(filename);
614 if (fname[nch-1] == ';') { nch--; fname[nch]=0;}
615
616 std::ifstream file(fname,std::ios::in);
617 if (!file.good()) {
618 Error("ReadFile", "illegal file name");
619 delete [] fname;
620 return;
621 }
622
623 const int linesize = 255;
624 char currentline[linesize];
625 char *ss, *sclose, *s= 0;
626
627 Int_t kline = 0;
628 while (1) {
629 file.getline(currentline,linesize);
630 if (file.eof())break;
631 if (kline >= fromline && kline < fromline+nlines) {
632 s = currentline;
633 if (strstr(s,"+SetText")) {
634 ss = s+8;
635 sclose = strstr(ss,")");
636 if (!sclose) continue;
637 *sclose = 0;
638 lastline = (TText*)fLines->Last();
639 if (!lastline) continue;
640 if (strstr(ss,"Color(")) {
641 sscanf(ss+6,"%d",&ival);
642 lastline->SetTextColor(ival);
643 continue;
644 }
645 if (strstr(ss,"Align(")) {
646 sscanf(ss+6,"%d",&ival);
647 lastline->SetTextAlign(ival);
648 continue;
649 }
650 if (strstr(ss,"Font(")) {
651 sscanf(ss+5,"%d",&ival);
652 lastline->SetTextFont(ival);
653 continue;
654 }
655 if (strstr(ss,"Size(")) {
656 sscanf(ss+5,"%f",&val);
657 lastline->SetTextSize(val);
658 continue;
659 }
660 if (strstr(ss,"Angle(")) {
661 sscanf(ss+6,"%f",&val);
662 lastline->SetTextAngle(val);
663 continue;
664 }
665 }
666 AddText(s);
667 }
668 kline++;
669 }
670 file.close();
671 delete [] fname;
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Save lines of this pavetext as C++ statements on output stream out
676
677void TPaveText::SaveLines(std::ostream &out, const char *name, Bool_t saved)
678{
679 if (!fLines) return;
680 Int_t nlines = GetSize();
681 if (nlines == 0) return;
682
683 // Iterate over all lines
684 char quote = '"';
685 TObject *line;
686 TText *linet;
687 TLatex *latex;
688 TLine *linel;
689 TBox *lineb;
690 TIter next(fLines);
691 Bool_t savedlt = kFALSE;
692 Bool_t savedt = kFALSE;
693 Bool_t savedl = kFALSE;
694 Bool_t savedb = kFALSE;
695
696 while ((line = (TObject*) next())) {
697 // Next primitive is a line
698 if (line->IsA() == TLine::Class()) {
699 linel = (TLine*)line;
700 if (saved || savedl) {
701 out<<" ";
702 } else {
703 out<<" TLine *";
704 savedl = kTRUE;
705 }
706 out<<name<<"_Line = "<<name<<"->AddLine("
707 <<linel->GetX1()<<","<<linel->GetY1()<<","<<linel->GetX2()<<","<<linel->GetY2()<<");"<<std::endl;
708 if (linel->GetLineColor() != 1) {
709 if (linel->GetLineColor() > 228) {
710 TColor::SaveColor(out, linel->GetLineColor());
711 out<<" "<<name<<"_Line->SetLineColor(ci);" << std::endl;
712 } else
713 out<<" "<<name<<"_Line->SetLineColor("<<linel->GetLineColor()<<");"<<std::endl;
714 }
715 if (linel->GetLineStyle() != 1) {
716 out<<" "<<name<<"_Line->SetLineStyle("<<linel->GetLineStyle()<<");"<<std::endl;
717 }
718 if (linel->GetLineWidth() != 1) {
719 out<<" "<<name<<"_Line->SetLineWidth("<<linel->GetLineWidth()<<");"<<std::endl;
720 }
721 continue;
722 }
723 // Next primitive is a box
724 if (line->IsA() == TBox::Class()) {
725 lineb = (TBox*)line;
726 if (saved || savedb) {
727 out<<" ";
728 } else {
729 out<<" TBox *";
730 savedb = kTRUE;
731 }
732 out<<name<<"_Box = "<<name<<"->AddBox("
733 <<lineb->GetX1()<<","<<lineb->GetY1()<<","<<lineb->GetX2()<<","<<lineb->GetY2()<<");"<<std::endl;
734 if (lineb->GetFillColor() != 18) {
735 if (lineb->GetFillColor() > 228) {
736 TColor::SaveColor(out, lineb->GetFillColor());
737 out<<" "<<name<<"_Box->SetFillColor(ci);" << std::endl;
738 } else
739 out<<" "<<name<<"_Box->SetFillColor("<<lineb->GetFillColor()<<");"<<std::endl;
740 }
741 if (lineb->GetFillStyle() != 1001) {
742 out<<" "<<name<<"_Box->SetFillStyle("<<lineb->GetFillStyle()<<");"<<std::endl;
743 }
744 if (lineb->GetLineColor() != 1) {
745 if (lineb->GetLineColor() > 228) {
746 TColor::SaveColor(out, lineb->GetLineColor());
747 out<<" "<<name<<"_Box->SetLineColor(ci);" << std::endl;
748 } else
749 out<<" "<<name<<"_Box->SetLineColor("<<lineb->GetLineColor()<<");"<<std::endl;
750 }
751 if (lineb->GetLineStyle() != 1) {
752 out<<" "<<name<<"_Box->SetLineStyle("<<lineb->GetLineStyle()<<");"<<std::endl;
753 }
754 if (lineb->GetLineWidth() != 1) {
755 out<<" "<<name<<"_Box->SetLineWidth("<<lineb->GetLineWidth()<<");"<<std::endl;
756 }
757 continue;
758 }
759 // Next primitive is a text
760 if (line->IsA() == TText::Class()) {
761 linet = (TText*)line;
762 if (saved || savedt) {
763 out<<" ";
764 } else {
765 out<<" TText *";
766 savedt = kTRUE;
767 }
768 if (!linet->GetX() && !linet->GetY()) {
769 TString s = linet->GetTitle();
770 s.ReplaceAll("\"","\\\"");
771 out<<name<<"_Text = "<<name<<"->AddText("
772 <<quote<<s.Data()<<quote<<");"<<std::endl;
773 } else {
774 out<<name<<"_Text = "<<name<<"->AddText("
775 <<linet->GetX()<<","<<linet->GetY()<<","<<quote<<linet->GetTitle()<<quote<<");"<<std::endl;
776 }
777 if (linet->GetTextColor()) {
778 if (linet->GetTextColor() > 228) {
779 TColor::SaveColor(out, linet->GetTextColor());
780 out<<" "<<name<<"_Text->SetTextColor(ci);" << std::endl;
781 } else
782 out<<" "<<name<<"_Text->SetTextColor("<<linet->GetTextColor()<<");"<<std::endl;
783 }
784 if (linet->GetTextFont()) {
785 out<<" "<<name<<"_Text->SetTextFont("<<linet->GetTextFont()<<");"<<std::endl;
786 }
787 if (linet->GetTextSize()) {
788 out<<" "<<name<<"_Text->SetTextSize("<<linet->GetTextSize()<<");"<<std::endl;
789 }
790 if (linet->GetTextAngle() != GetTextAngle()) {
791 out<<" "<<name<<"_Text->SetTextAngle("<<linet->GetTextAngle()<<");"<<std::endl;
792 }
793 if (linet->GetTextAlign()) {
794 out<<" "<<name<<"_Text->SetTextAlign("<<linet->GetTextAlign()<<");"<<std::endl;
795 }
796 }
797 // Next primitive is a Latex text
798 if (line->IsA() == TLatex::Class()) {
799 latex = (TLatex*)line;
800 if (saved || savedlt) {
801 out<<" ";
802 } else {
803 out<<" TText *";
804 savedlt = kTRUE;
805 }
806 if (!latex->GetX() && !latex->GetY()) {
807 TString sl = latex->GetTitle();
808 sl.ReplaceAll("\"","\\\"");
809 out<<name<<"_LaTex = "<<name<<"->AddText("
810 <<quote<<sl.Data()<<quote<<");"<<std::endl;
811 } else {
812 out<<name<<"_LaTex = "<<name<<"->AddText("
813 <<latex->GetX()<<","<<latex->GetY()<<","<<quote<<latex->GetTitle()<<quote<<");"<<std::endl;
814 }
815 if (latex->GetTextColor()) {
816 if (latex->GetTextColor() > 228) {
817 TColor::SaveColor(out, latex->GetTextColor());
818 out<<" "<<name<<"_LaTex->SetTextColor(ci);" << std::endl;
819 } else
820 out<<" "<<name<<"_LaTex->SetTextColor("<<latex->GetTextColor()<<");"<<std::endl;
821 }
822 if (latex->GetTextFont()) {
823 out<<" "<<name<<"_LaTex->SetTextFont("<<latex->GetTextFont()<<");"<<std::endl;
824 }
825 if (latex->GetTextSize()) {
826 out<<" "<<name<<"_LaTex->SetTextSize("<<latex->GetTextSize()<<");"<<std::endl;
827 }
828 if (latex->GetTextAngle() != GetTextAngle()) {
829 out<<" "<<name<<"_LaTex->SetTextAngle("<<latex->GetTextAngle()<<");"<<std::endl;
830 }
831 if (latex->GetTextAlign()) {
832 out<<" "<<name<<"_LaTex->SetTextAlign("<<latex->GetTextAlign()<<");"<<std::endl;
833 }
834 }
835 }
836}
837
838////////////////////////////////////////////////////////////////////////////////
839/// Save primitive as a C++ statement(s) on output stream out
840
841void TPaveText::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
842{
843 char quote = '"';
844 Bool_t saved = gROOT->ClassSaved(TPaveText::Class());
845 out<<" "<<std::endl;
846 if (saved) {
847 out<<" ";
848 } else {
849 out<<" "<<ClassName()<<" *";
850 }
851 if (fOption.Contains("NDC")) {
852 out<<"pt = new "<<ClassName()<<"("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
853 <<","<<quote<<fOption<<quote<<");"<<std::endl;
854 } else {
855 out<<"pt = new "<<ClassName()<<"("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
856 <<","<<quote<<fOption<<quote<<");"<<std::endl;
857 }
858 if (strcmp(GetName(),"TPave")) {
859 out<<" pt->SetName("<<quote<<GetName()<<quote<<");"<<std::endl;
860 }
861 if (fLabel.Length() > 0) {
862 out<<" pt->SetLabel("<<quote<<fLabel<<quote<<");"<<std::endl;
863 }
864 if (fBorderSize != 4) {
865 out<<" pt->SetBorderSize("<<fBorderSize<<");"<<std::endl;
866 }
867 SaveFillAttributes(out,"pt",19,1001);
868 SaveLineAttributes(out,"pt",1,1,1);
869 SaveTextAttributes(out,"pt",22,0,1,62,0);
870 SaveLines(out,"pt",saved);
871 out<<" pt->Draw();"<<std::endl;
872}
873
874////////////////////////////////////////////////////////////////////////////////
875/// Set attribute option for all lines containing string text.
876///
877/// Possible options are all the AttText attributes
878/// Align, Color, Font, Size and Angle
879
880void TPaveText::SetAllWith(const char *text, Option_t *option, Double_t value)
881{
882 TString opt=option;
883 opt.ToLower();
884 TText *line;
885 TIter next(fLines);
886 while ((line = (TText*) next())) {
887 if (strstr(line->GetTitle(),text)) {
888 if (opt == "align") line->SetTextAlign(Int_t(value));
889 if (opt == "color") line->SetTextColor(Int_t(value));
890 if (opt == "font") line->SetTextFont(Int_t(value));
891 if (opt == "size") line->SetTextSize(value);
892 if (opt == "angle") line->SetTextAngle(value);
893 }
894 }
895}
896
897////////////////////////////////////////////////////////////////////////////////
898/// Stream an object of class TPaveText.
899
900void TPaveText::Streamer(TBuffer &R__b)
901{
902 if (R__b.IsReading()) {
903 UInt_t R__s, R__c;
904 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
905 if (R__v > 1) {
906 R__b.ReadClassBuffer(TPaveText::Class(), this, R__v, R__s, R__c);
907 return;
908 }
909 //====process old versions before automatic schema evolution
910 TPave::Streamer(R__b);
911 TAttText::Streamer(R__b);
912 if (R__v > 1) fLabel.Streamer(R__b);
913 R__b >> fLongest;
914 R__b >> fMargin;
915 R__b >> fLines;
916 R__b.CheckByteCount(R__s, R__c, TPaveText::IsA());
917 //====end of old versions
918
919 } else {
920 R__b.WriteClassBuffer(TPaveText::Class(),this);
921 }
922}
923
924////////////////////////////////////////////////////////////////////////////////
925/// Replace current attributes by current style.
926
928{
929 if (gStyle->IsReading()) {
933 } else {
937 }
938}
@ 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:87
short Version_t
Definition RtypesCore.h:65
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:92
unsigned long ULong_t
Definition RtypesCore.h:55
short Short_t
Definition RtypesCore.h:39
double Double_t
Definition RtypesCore.h:59
short Color_t
Definition RtypesCore.h:83
short Style_t
Definition RtypesCore.h:80
float Float_t
Definition RtypesCore.h:57
const Bool_t kTRUE
Definition RtypesCore.h:91
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:406
char * Form(const char *fmt,...)
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2510
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
#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:234
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:270
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: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:2121
void Reset()
To draw Mathematical Formula.
Definition TLatex.h:18
Double_t GetXsize()
Return size of the formula along X in pad coordinates.
Definition TLatex.cxx:2522
virtual void PaintLatex(Double_t x, Double_t y, Double_t angle, Double_t size, const char *text)
Main drawing function.
Definition TLatex.cxx:2051
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:384
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:44
virtual void Add(TObject *obj)
Definition TList.h:87
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:37
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:187
@ kNotDeleted
object has not been deleted
Definition TObject.h:78
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:343
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:107
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:403
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:1145
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
Short_t Abs(Short_t d)
Definition TMathBase.h:120
Definition file.py:1