Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPaveLabel.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 17/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 <iostream>
13#include "TROOT.h"
14#include "TStyle.h"
15#include "TPaveLabel.h"
16#include "TLatex.h"
17#include "TVirtualPad.h"
18
19
20/** \class TPaveLabel
21\ingroup BasicGraphics
22
23A Pave (see TPave) with a text centered in the Pave.
24
25\image html graf_pavelabel.png
26*/
27
28////////////////////////////////////////////////////////////////////////////////
29/// Pavelabel default constructor.
30
34
35////////////////////////////////////////////////////////////////////////////////
36/// Pavelabel normal constructor.
37///
38/// a PaveLabel is a Pave with a label centered in the Pave
39/// The Pave is by default defined with bordersize=3 and option ="br".
40/// The text size is automatically computed as a function of the pave size.
41/// To remove the shadow or border of a TPaveLabel, use the function TPave::SetBorderSize
42
44 :TPave(x1,y1,x2,y2,3,option), TAttText(22,0,1,gStyle->GetTextFont(),0.99)
45{
46 fLabel = label;
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// TPaveLabel default destructor.
51
55
56////////////////////////////////////////////////////////////////////////////////
57/// TPaveLabel copy constructor.
58
60{
61 pavelabel.TPaveLabel::Copy(*this);
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// TPaveLabel assign operator
66
68{
69 if (this != &pavelabel)
70 pavelabel.TPaveLabel::Copy(*this);
71 return *this;
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Copy this pavelabel to pavelabel.
76
77void TPaveLabel::Copy(TObject &obj) const
78{
79 TPave::Copy(obj);
81 ((TPaveLabel &)obj).fLabel = fLabel;
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Draw this pavelabel with its current attributes.
86
88{
89 Option_t *opt;
90 if (option && *option) opt = option;
91 else opt = GetOption();
92
93 AppendPad(opt);
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Draw this pavelabel with new coordinates.
98
100{
102 newpavelabel->SetBit(kCanDelete);
103 newpavelabel->AppendPad();
104 return newpavelabel;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Paint this pavelabel with its current attributes.
109
111{
112 // Convert from NDC to pad coordinates
114
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Draw this pavelabel with new coordinates.
120
122 const char *label ,Option_t *option)
123{
124 if (!gPad) return;
125 Int_t nch = label ? strlen(label) : 0;
126
127 // Draw the pave
129
130 Float_t nspecials = 0;
131 for (Int_t i=0;i<nch;i++) {
132 if (label[i] == '!') nspecials += 1;
133 if (label[i] == '?') nspecials += 1.5;
134 if (label[i] == '#') nspecials += 1;
135 if (label[i] == '`') nspecials += 1;
136 if (label[i] == '^') nspecials += 1.5;
137 if (label[i] == '~') nspecials += 1;
138 if (label[i] == '&') nspecials += 2;
139 if (label[i] == '\\') nspecials += 3; // octal characters very likely
140 }
141 nch -= Int_t(nspecials + 0.5);
142 if (nch <= 0) return;
143
144 // Draw label
145 Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
146 Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
147 if (wh==0||hh==0) return;
149 Int_t automat = 0;
150 if (GetTextFont()%10 > 2) { // fixed size font specified in pixels
152 } else {
153 if (std::abs(textsize -0.99) < 0.001) automat = 1;
154 if (textsize == 0) { textsize = 0.99; automat = 1;}
155 Int_t ypixel = std::abs(gPad->YtoPixel(y1) - gPad->YtoPixel(y2));
157 if (wh < hh) labelsize *= hh/wh;
158 }
160 latex.SetTextAngle(GetTextAngle());
161 latex.SetTextFont(GetTextFont());
162 latex.SetTextAlign(GetTextAlign());
163 latex.SetTextColor(GetTextColor());
164 latex.SetTextSize(labelsize);
165 if (automat) {
166 UInt_t w=0,h=0,w1=0;
167 latex.GetTextExtent(w,h,GetTitle());
168 if (!w) return;
169 labelsize = h/hh;
170 Double_t wxlabel = std::abs(gPad->XtoPixel(x2) - gPad->XtoPixel(x1));
171 latex.GetTextExtent(w1,h,GetTitle());
172 while (w > 0.99*wxlabel) {
173 labelsize *= 0.99*wxlabel/w;
174 latex.SetTextSize(labelsize);
175 latex.GetTextExtent(w,h,GetTitle());
176 if (w==w1) break;
177 else w1=w;
178 }
179 if (h < 1) h = 1;
180 if (h==1) {
182 if (wh < hh) labelsize *= hh/wh;
183 latex.SetTextSize(labelsize);
184 }
185 }
188 Double_t x = 0.5*(x1+x2);
189 if (halign == 1) x = x1 + 0.02*(x2-x1);
190 if (halign == 3) x = x2 - 0.02*(x2-x1);
191 Double_t y = 0.5*(y1+y2);
192 if (valign == 1) y = y1 + 0.02*(y2-y1);
193 if (valign == 3) y = y2 - 0.02*(y2-y1);
194 latex.PaintLatex(x, y, GetTextAngle(),labelsize,GetLabel());
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Save primitive as a C++ statement(s) on output stream out
199
201{
202 TString lbl_arg = TString::Format("\"%s\"", TString(fLabel).ReplaceSpecialCppChars().Data());
204 if (strcmp(GetName(), "TPave"))
205 out << " pavelabel->SetName(\"" << GetName() << "\");\n";
206 if (fBorderSize != 3)
207 out << " pavelabel->SetBorderSize(" << fBorderSize << ");\n";
208
209 SaveFillAttributes(out, "pavelabel", 19, 1001);
210 SaveLineAttributes(out, "pavelabel", 1, 1, 1);
211 SaveTextAttributes(out, "pavelabel", 22, 0, 1, 62, 0);
212
213 SavePrimitiveDraw(out, "pavelabel", option);
214}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t textsize
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:238
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:274
Text Attributes class.
Definition TAttText.h:20
virtual Float_t GetTextSize() const
Return the text size.
Definition TAttText.h:38
virtual Short_t GetTextAlign() const
Return the text alignment.
Definition TAttText.h:34
virtual Font_t GetTextFont() const
Return the text font.
Definition TAttText.h:37
virtual Color_t GetTextColor() const
Return the text color.
Definition TAttText.h:36
virtual Float_t GetTextAngle() const
Return the text angle.
Definition TAttText.h:35
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
Definition TAttText.cxx:372
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
Definition TAttText.cxx:293
Double_t fX1
X of 1st point.
Definition TBox.h:28
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
To draw Mathematical Formula.
Definition TLatex.h:18
Mother of all ROOT objects.
Definition TObject.h:41
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:203
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:822
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:771
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:68
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
void Copy(TObject &pavelabel) const override
Copy this pavelabel to pavelabel.
virtual void PaintPaveLabel(Double_t x1, Double_t y1, Double_t x2, Double_t y2, const char *label, Option_t *option="")
Draw this pavelabel with new coordinates.
~TPaveLabel() override
TPaveLabel default destructor.
static TClass * Class()
virtual TPaveLabel * DrawPaveLabel(Double_t x1, Double_t y1, Double_t x2, Double_t y2, const char *label, Option_t *option="")
Draw this pavelabel with new coordinates.
const char * GetLabel() const
Definition TPaveLabel.h:36
void Paint(Option_t *option="") override
Paint this pavelabel with its current attributes.
TPaveLabel()
Pavelabel default constructor.
TString fLabel
Label written at the center of Pave.
Definition TPaveLabel.h:23
TPaveLabel & operator=(const TPaveLabel &pavelabel)
TPaveLabel assign operator.
void Draw(Option_t *option="") override
Draw this pavelabel with its current attributes.
const char * GetTitle() const override
Returns title of object.
Definition TPaveLabel.h:37
A TBox with a bordersize and a shadow option.
Definition TPave.h:19
Int_t GetBorderSize() const
Definition TPave.h:56
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Definition TPave.cxx:138
const char * GetName() const override
Returns name of object.
Definition TPave.h:58
TString GetSavePaveArgs(const char *extra_arg=nullptr, Bool_t save_option=kTRUE)
Returns arguments which should be used when saving primitive constructor Check if coordinates are ini...
Definition TPave.cxx:617
void Copy(TObject &pave) const override
Copy this pave to pave.
Definition TPave.cxx:185
Int_t fBorderSize
window box bordersize in pixels
Definition TPave.h:26
Option_t * GetOption() const override
Definition TPave.h:59
virtual void PaintPave(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Int_t bordersize=4, Option_t *option="br")
Draw this pave with new coordinates.
Definition TPave.cxx:314
Basic string class.
Definition TString.h:138
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17