Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4ConditionsBase/TGo4LabelPainter.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4LabelPainter.h"
00017 
00018 #include "TROOT.h"
00019 #include "TVirtualPad.h"
00020 
00021 TGo4LabelPainter::TGo4LabelPainter(const Text_t * name, const Text_t * title)
00022 : TNamed(name, title), fxLabel(0),fdX0(0),fdY0(0),fbIsLabStreamed(kFALSE)
00023 {
00024 InitAttributes();
00025 }
00026 
00027 TGo4LabelPainter::TGo4LabelPainter(const Text_t * name)
00028 : TNamed(name, "Go4 LabelPainter"), fxLabel(0),fdX0(0),fdY0(0),fbIsLabStreamed(kFALSE)
00029 {
00030 InitAttributes();
00031 }
00032 
00033 TGo4LabelPainter::TGo4LabelPainter()
00034 : TNamed(), fxLabel(0),fdX0(0),fdY0(0),fbIsLabStreamed(kTRUE)
00035 {
00036 InitAttributes();
00037 }
00038 
00039 void TGo4LabelPainter::InitAttributes()
00040 {
00041 fdWidth=0.25;
00042 fdHeight=0.22;
00043 SetCaption("Empty label");
00044 SetTextAlign(12); // left and central aligned
00045 //SetTextSize(0.03); // % of pad height
00046 SetTextSize(0); // this will let root scale fontsize depending on label frame
00047 SetTextFont(102); // proportional font for alignment of equations
00048 SetTextColor(GetLineColor());
00049 }
00050 
00051 TGo4LabelPainter::~TGo4LabelPainter()
00052 {
00053    gROOT->GetListOfCleanups()->Remove(fxLabel);
00054    delete fxLabel;
00055 }
00056 
00057 
00058 
00059 
00060 void TGo4LabelPainter::PaintLabel(Option_t* opt)
00061 {
00062 if(gPad==0) return;
00063 if(!CheckLabel())
00064    {
00065       // label was deleted by us or by root:
00066       if(fdX0==0)
00067         fdX0=(gPad->GetUxmax()-gPad->GetUxmin())/2; // default: place at x center
00068       if(fdY0==0)
00069         fdY0=(gPad->GetUymax()-gPad->GetUymin())/2; // default: place at y center
00070       fxLabel=CreateCurrentLabel(fdX0,fdY0);
00071       gROOT->GetListOfCleanups()->Add(fxLabel);
00072       fxLabel->AppendPad(opt); // only append to pad if not already there
00073    }
00074 else
00075    {
00076       // label is exisiting:
00077       if (gPad->GetListOfPrimitives()->FindObject(fxLabel)==0)
00078          fxLabel->AppendPad(opt); // label was cleared from pad, we redraw it
00079       fxLabel->SetLineColor(GetLineColor());
00080       fxLabel->Clear(); // remove old text lines
00081    }
00082 fxLabel->AddText(fxCaption.Data());
00083 fxLabel->AddText(" "); // dummy for automatic position of next line
00084 fxLabel->AddLine(0,0,0,0);
00085 }
00086 
00087 void TGo4LabelPainter::UnPaintLabel(Option_t* opt)
00088 {
00089    if(gPad==0) return;
00090    gPad->GetListOfPrimitives()->Remove(fxLabel);
00091    // we do not delete label, but restore graphics properties though invisible
00092    TString option=opt;
00093    if(option.Contains("reset"))
00094       {
00095          // case of reset option: discard old label geometry if
00096          if(CheckLabel())
00097             {
00098                gROOT->GetListOfCleanups()->Remove(fxLabel);
00099                delete fxLabel;
00100                fxLabel=0;
00101             }
00102       }
00103 }
00104 
00105 void TGo4LabelPainter::RePaintLabel(Option_t* opt)
00106 {
00107 if(fxLabel) fxLabel->Paint(opt);
00108 
00109 }
00110 TGo4Label* TGo4LabelPainter::CreateCurrentLabel(Double_t x, Double_t y)
00111 {
00112    if(gPad==0) return 0;
00113    Double_t x0=x;
00114    Double_t y0=y; // buffer external variables, since LabelCoords will change them
00115    Double_t xmax=0;
00116    Double_t ymax=0;
00117    LabelCoords(x0,y0,xmax,ymax);
00118    TGo4Label* label=new TGo4Label(x0,y0,xmax,ymax);
00119    label->SetOwner(this);
00120    TAttText::Copy(*label);
00121    TAttLine::Copy(*label);
00122    TAttFill::Copy(*label);
00123    return label;
00124 }
00125 
00126 Bool_t TGo4LabelPainter::CheckLabel()
00127 {
00128 if(fbIsLabStreamed && fxLabel!=0)
00129    {
00130     // case of label was streamed from file: not yet in cleanup list!
00131     gROOT->GetListOfCleanups()->Add(fxLabel);
00132     fxLabel->SetOwner(this);
00133     fbIsLabStreamed=kFALSE;
00134     return kTRUE;
00135    }
00136 
00137 if(fxLabel && gROOT->GetListOfCleanups()->FindObject(fxLabel))
00138    {
00139       return kTRUE;
00140    }
00141 
00142 else
00143    {
00144       fxLabel=0;
00145       return kFALSE;
00146    }
00147 }
00148 
00149 
00150 void TGo4LabelPainter::LabelCoords(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax)
00151 {
00152    Double_t xpmin =gPad->GetUxmin();
00153    Double_t xpmax =gPad->GetUxmax();
00154    Double_t ypmin =gPad->GetUymin();
00155    Double_t ypmax =gPad->GetUymax(); // this delivers pad coordinates
00156    Double_t dx=(xpmax-xpmin);
00157    Double_t dy=(ypmax-ypmin);
00158    Double_t width=fdWidth*dx;
00159    Double_t height=fdHeight*dy; // width is in pad coordinates
00160    xmax=gPad->XtoPad(xmin)+width;
00161    ymax=gPad->YtoPad(ymin)+height; // calculate label geometry in pad coordinates
00162    xmax=gPad->PadtoX(xmax);
00163    ymax=gPad->PadtoY(ymax); // back to axis coordinates for initial pavetext
00164 }
00165 
00166 Double_t TGo4LabelPainter::GetLabelXlo()
00167 {
00168 if(fxLabel)
00169       return fxLabel->GetX1();
00170 else
00171    return 0;
00172 }
00173 
00174 Double_t TGo4LabelPainter::GetLabelYlo()
00175 {
00176 if(fxLabel)
00177       return fxLabel->GetY1();
00178 else
00179    return 0;
00180 }
00181 
00182 Double_t TGo4LabelPainter::GetLabelXup()
00183 {
00184 if(fxLabel)
00185    return fxLabel->GetX2();
00186 else
00187    return 0;
00188 }
00189 
00190 Double_t TGo4LabelPainter::GetLabelYup()
00191 {
00192 if(fxLabel)
00193       return fxLabel->GetY2();
00194 else
00195    return 0;
00196 }
00197 
00199 void TGo4Label::Paint(Option_t* opt)
00200 {
00201 if(gPad==0) return;
00202 if(fxOwner) TPaveText::Paint(opt);
00203 // suppress painting of labels without owner. This case
00204 // happens after insert canvas in go4 (separate cloning
00205 // of lists of primitive members), thus leading to a
00206 // second "ghost label" for markers and conditions
00207 }
00209 
00211 void TGo4LabelConnector::Paint(Option_t* opt)
00212 {
00213 if(gPad==0) return;
00214 if(fxOwner) TLine::Paint(opt);
00215 // suppress painting of label connectors without owner. This case
00216 // happens after insert canvas in go4 (separate cloning
00217 // of lists of primitive members), thus leading to a
00218 // second "ghost label connector" for markers
00219 }
00221 
00222 ClassImp(TGo4LabelPainter)
00223 ClassImp(TGo4LabelConnector)
00224 ClassImp(TGo4Label)
00225 
00226 
00227 
00228 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:52 2005 for Go4-v2.10-5 by doxygen1.2.15