00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Riostream.h"
00013 #include "TROOT.h"
00014 #include "TStyle.h"
00015 #include "TPaveLabel.h"
00016 #include "TLatex.h"
00017 #include "TVirtualPad.h"
00018
00019 ClassImp(TPaveLabel)
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 TPaveLabel::TPaveLabel(): TPave(), TAttText()
00034 {
00035
00036 }
00037
00038
00039
00040 TPaveLabel::TPaveLabel(Double_t x1, Double_t y1,Double_t x2, Double_t y2, const char *label, Option_t *option)
00041 :TPave(x1,y1,x2,y2,3,option), TAttText(22,0,1,gStyle->GetTextFont(),0.99)
00042 {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 fLabel = label;
00056 }
00057
00058
00059
00060 TPaveLabel::~TPaveLabel()
00061 {
00062
00063 }
00064
00065
00066
00067 TPaveLabel::TPaveLabel(const TPaveLabel &pavelabel) : TPave(pavelabel), TAttText(pavelabel)
00068 {
00069
00070
00071 ((TPaveLabel&)pavelabel).Copy(*this);
00072 }
00073
00074
00075
00076 void TPaveLabel::Copy(TObject &obj) const
00077 {
00078
00079
00080 TPave::Copy(obj);
00081 TAttText::Copy(((TPaveLabel&)obj));
00082 ((TPaveLabel&)obj).fLabel = fLabel;
00083 }
00084
00085
00086
00087 void TPaveLabel::Draw(Option_t *option)
00088 {
00089
00090
00091 Option_t *opt;
00092 if (option && strlen(option)) opt = option;
00093 else opt = GetOption();
00094
00095 AppendPad(opt);
00096 }
00097
00098
00099
00100 void TPaveLabel::DrawPaveLabel(Double_t x1, Double_t y1, Double_t x2, Double_t y2, const char *label, Option_t *option)
00101 {
00102
00103
00104 TPaveLabel *newpavelabel = new TPaveLabel(x1,y1,x2,y2,label,option);
00105 newpavelabel->SetBit(kCanDelete);
00106 newpavelabel->AppendPad();
00107 }
00108
00109
00110
00111 void TPaveLabel::Paint(Option_t *option)
00112 {
00113
00114
00115
00116 TPave::ConvertNDCtoPad();
00117
00118 PaintPaveLabel(fX1, fY1, fX2, fY2, GetLabel(), strlen(option)?option:GetOption());
00119 }
00120
00121
00122
00123 void TPaveLabel::PaintPaveLabel(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
00124 const char *label ,Option_t *option)
00125 {
00126
00127
00128 Int_t nch = strlen(label);
00129
00130
00131 TPave::PaintPave(x1,y1,x2,y2,GetBorderSize(),option);
00132
00133 Float_t nspecials = 0;
00134 for (Int_t i=0;i<nch;i++) {
00135 if (label[i] == '!') nspecials += 1;
00136 if (label[i] == '?') nspecials += 1.5;
00137 if (label[i] == '#') nspecials += 1;
00138 if (label[i] == '`') nspecials += 1;
00139 if (label[i] == '^') nspecials += 1.5;
00140 if (label[i] == '~') nspecials += 1;
00141 if (label[i] == '&') nspecials += 2;
00142 if (label[i] == '\\') nspecials += 3;
00143 }
00144 nch -= Int_t(nspecials + 0.5);
00145 if (nch <= 0) return;
00146
00147
00148 Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
00149 Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
00150 Double_t labelsize, textsize = GetTextSize();
00151 Int_t automat = 0;
00152 if (GetTextFont()%10 > 2) {
00153 labelsize = GetTextSize();
00154 } else {
00155 if (TMath::Abs(textsize -0.99) < 0.001) automat = 1;
00156 if (textsize == 0) { textsize = 0.99; automat = 1;}
00157 Int_t ypixel = TMath::Abs(gPad->YtoPixel(y1) - gPad->YtoPixel(y2));
00158 labelsize = textsize*ypixel/hh;
00159 if (wh < hh) labelsize *= hh/wh;
00160 }
00161 TLatex latex;
00162 latex.SetTextAngle(GetTextAngle());
00163 latex.SetTextFont(GetTextFont());
00164 latex.SetTextAlign(GetTextAlign());
00165 latex.SetTextColor(GetTextColor());
00166 latex.SetTextSize(labelsize);
00167 if (automat) {
00168 UInt_t w,h;
00169 latex.GetTextExtent(w,h,GetTitle());
00170 labelsize = h/hh;
00171 Double_t wxlabel = TMath::Abs(gPad->XtoPixel(x2) - gPad->XtoPixel(x1));
00172 while (w > 0.99*wxlabel) { labelsize *= 0.99*wxlabel/w;latex.SetTextSize(labelsize); latex.GetTextExtent(w,h,GetTitle());}
00173 if (h < 1) h = 1;
00174 if (h==1) {
00175 labelsize = Double_t(h)/hh;
00176 if (wh < hh) labelsize *= hh/wh;
00177 latex.SetTextSize(labelsize);
00178 }
00179 }
00180 Int_t halign = GetTextAlign()/10;
00181 Int_t valign = GetTextAlign()%10;
00182 Double_t x = 0.5*(x1+x2);
00183 if (halign == 1) x = x1 + 0.02*(x2-x1);
00184 if (halign == 3) x = x2 - 0.02*(x2-x1);
00185 Double_t y = 0.5*(y1+y2);
00186 if (valign == 1) y = y1 + 0.02*(y2-y1);
00187 if (valign == 3) y = y2 - 0.02*(y2-y1);
00188 latex.PaintLatex(x, y, GetTextAngle(),labelsize,GetLabel());
00189 }
00190
00191
00192
00193 void TPaveLabel::SavePrimitive(ostream &out, Option_t * )
00194 {
00195
00196
00197 char quote = '"';
00198 out<<" "<<endl;
00199 if (gROOT->ClassSaved(TPaveLabel::Class())) {
00200 out<<" ";
00201 } else {
00202 out<<" TPaveLabel *";
00203 }
00204 TString s = fLabel.Data();
00205 s.ReplaceAll("\"","\\\"");
00206 if (fOption.Contains("NDC")) {
00207 out<<"pl = new TPaveLabel("<<fX1NDC<<","<<fY1NDC<<","<<fX2NDC<<","<<fY2NDC
00208 <<","<<quote<<s.Data()<<quote<<","<<quote<<fOption<<quote<<");"<<endl;
00209 } else {
00210 out<<"pl = new TPaveLabel("<<gPad->PadtoX(fX1)<<","<<gPad->PadtoY(fY1)<<","<<gPad->PadtoX(fX2)<<","<<gPad->PadtoY(fY2)
00211 <<","<<quote<<s.Data()<<quote<<","<<quote<<fOption<<quote<<");"<<endl;
00212 }
00213 if (fBorderSize != 3) {
00214 out<<" pl->SetBorderSize("<<fBorderSize<<");"<<endl;
00215 }
00216 SaveFillAttributes(out,"pl",19,1001);
00217 SaveLineAttributes(out,"pl",1,1,1);
00218 SaveTextAttributes(out,"pl",22,0,1,62,0);
00219
00220 out<<" pl->Draw();"<<endl;
00221 }