Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4LabelPainter.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 //#include "iostream.h"
00021 
00022 TGo4LabelPainter::TGo4LabelPainter(const Text_t * name, const Text_t * title)
00023 : TNamed(name, title), fxLabel(0),fdX0(0),fdY0(0),fbIsLabStreamed(kFALSE)
00024 {
00025    InitAttributes();
00026 }
00027 
00028 TGo4LabelPainter::TGo4LabelPainter(const Text_t * name)
00029 : TNamed(name, "Go4 LabelPainter"), fxLabel(0),fdX0(0),fdY0(0),fbIsLabStreamed(kFALSE)
00030 {
00031    InitAttributes();
00032 }
00033 
00034 TGo4LabelPainter::TGo4LabelPainter()
00035 : TNamed(), fxLabel(0),fdX0(0),fdY0(0),fbIsLabStreamed(kTRUE)
00036 {
00037    InitAttributes();
00038 }
00039 
00040 void TGo4LabelPainter::InitAttributes()
00041 {
00042    SetBit(kMustCleanup);
00043    fdWidth=0.25;
00044    fdHeight=0.22;
00045    SetCaption("Empty label");
00046    SetTextAlign(12); // left and central aligned
00047    //SetTextSize(0.03); // % of pad height
00048    SetTextSize(0); // this will let root scale fontsize depending on label frame
00049    SetTextFont(102); // proportional font for alignment of equations
00050    SetTextColor(GetLineColor());
00051 }
00052 
00053 TGo4LabelPainter::~TGo4LabelPainter()
00054 {
00055    if (fxLabel!=0) {
00056       delete fxLabel;
00057       fxLabel = 0;
00058    }
00059 }
00060 
00061 void TGo4LabelPainter::PaintLabel(Option_t* opt)
00062 {
00063    if(gPad==0) return;
00064    if(!CheckLabel()) {
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       fxLabel->AppendPad(opt); // only append to pad if not already there
00072    } else {
00073       // label is exisiting:
00074       if (gPad->GetListOfPrimitives()->FindObject(fxLabel)==0)
00075          fxLabel->AppendPad(opt); // label was cleared from pad, we redraw it
00076       fxLabel->SetLineColor(GetLineColor());
00077       fxLabel->Clear(); // remove old text lines
00078    }
00079    fxLabel->AddText(fxCaption.Data());
00080    fxLabel->AddText(" "); // dummy for automatic position of next line
00081    fxLabel->AddLine(0,0,0,0);
00082 }
00083 
00084 void TGo4LabelPainter::UnPaintLabel(Option_t* opt)
00085 {
00086    gROOT->GetListOfCanvases()->RecursiveRemove(fxLabel);
00087 
00088    // we do not delete label, but restore graphics properties though invisible
00089    TString option=opt;
00090    if(option.Contains("reset")) {
00091       // case of reset option: discard old label geometry if
00092       if(CheckLabel()) {
00093          delete fxLabel;
00094          fxLabel=0;
00095       }
00096    }
00097 }
00098 
00099 void TGo4LabelPainter::RePaintLabel(Option_t* opt)
00100 {
00101 if(fxLabel)
00102       fxLabel->Paint(opt);
00103 
00104 }
00105 
00106 void TGo4LabelPainter::DisplayToFront(Option_t* opt)
00107 {
00108 if(fxLabel)
00109    fxLabel->Pop();
00110 
00111 }
00112 
00113 
00114 
00115 TGo4Label* TGo4LabelPainter::CreateCurrentLabel(Double_t x, Double_t y)
00116 {
00117    if(gPad==0) return 0;
00118    Double_t x0=x;
00119    Double_t y0=y; // buffer external variables, since LabelCoords will change them
00120    Double_t xmax=0;
00121    Double_t ymax=0;
00122    LabelCoords(x0,y0,xmax,ymax);
00123    TGo4Label* label=new TGo4Label(x0,y0,xmax,ymax);
00124    label->SetOwner(this);
00125    TAttText::Copy(*label);
00126    TAttLine::Copy(*label);
00127    TAttFill::Copy(*label);
00128    return label;
00129 }
00130 
00131 Bool_t TGo4LabelPainter::CheckLabel()
00132 {
00133    if(fbIsLabStreamed && fxLabel!=0) {
00134       // case of label was streamed from file: not yet in cleanup list!
00135       fxLabel->SetOwner(this);
00136       fbIsLabStreamed=kFALSE;
00137       //cout <<"CheckLabel with fbIsLabStreamed" << endl;
00138       return kTRUE;
00139    }
00140 
00141    if(TGo4Label::fxLastDeleted==(char*) fxLabel) 
00142       {
00143          // our label was deleted by user mouse menu just before
00144          TGo4Label::fxLastDeleted=0;
00145          fxLabel=0; // reset reference, will re-create label on next paint
00146          return kFALSE;
00147       }
00148    return fxLabel!=0;
00149 }
00150 
00151 
00152 void TGo4LabelPainter::LabelCoords(Double_t &xmin, Double_t &ymin, Double_t &xmax, Double_t &ymax)
00153 {
00154    Double_t xpmin =gPad->GetUxmin();
00155    Double_t xpmax =gPad->GetUxmax();
00156    Double_t ypmin =gPad->GetUymin();
00157    Double_t ypmax =gPad->GetUymax(); // this delivers pad coordinates
00158    Double_t dx=(xpmax-xpmin);
00159    Double_t dy=(ypmax-ypmin);
00160    Double_t width=fdWidth*dx;
00161    Double_t height=fdHeight*dy; // width is in pad coordinates
00162    xmax=gPad->XtoPad(xmin)+width;
00163    ymax=gPad->YtoPad(ymin)+height; // calculate label geometry in pad coordinates
00164    xmax=gPad->PadtoX(xmax);
00165    ymax=gPad->PadtoY(ymax); // back to axis coordinates for initial pavetext
00166 }
00167 
00168 Double_t TGo4LabelPainter::GetLabelXlo()
00169 {
00170 if(fxLabel)
00171       return fxLabel->GetX1();
00172 else
00173    return 0;
00174 }
00175 
00176 Double_t TGo4LabelPainter::GetLabelYlo()
00177 {
00178 if(fxLabel)
00179       return fxLabel->GetY1();
00180 else
00181    return 0;
00182 }
00183 
00184 Double_t TGo4LabelPainter::GetLabelXup()
00185 {
00186 if(fxLabel)
00187    return fxLabel->GetX2();
00188 else
00189    return 0;
00190 }
00191 
00192 Double_t TGo4LabelPainter::GetLabelYup()
00193 {
00194 if(fxLabel)
00195       return fxLabel->GetY2();
00196 else
00197    return 0;
00198 }
00199 
00201 
00202 char* TGo4Label::fxLastDeleted = 0;
00203 
00204 void TGo4Label::Paint(Option_t* opt)
00205 {
00206 if(gPad==0) return;
00207 if(fxOwner)
00208 {
00209   TPaveText::Paint(opt);
00210 }
00211 
00212 // suppress painting of labels without owner. This case
00213 // happens after insert canvas in go4 (separate cloning
00214 // of lists of primitive members), thus leading to a
00215 // second "ghost label" for markers and conditions
00216 }
00217 
00219 void TGo4Label::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00220 {
00221 if(gPad==0) return;
00222 TPaveText::ExecuteEvent(event,px,py);
00223 if(event==kButton1Up)
00224    {
00225       TGo4LabelPainter* painter=dynamic_cast<TGo4LabelPainter*>(fxOwner);
00226       if(painter)
00227          {
00228             painter->DisplayToFront();
00229             //cout <<"TGo4Label::ExecuteEvent with Display to front for "<<painter->GetName() << endl;
00230          }
00231    }
00232 }
00233 
00235 
00236 char* TGo4LabelConnector::fxLastDeleted = 0;
00237 
00239 void TGo4LabelConnector::Paint(Option_t* opt)
00240 {
00241 if(gPad==0) return;
00242 if(fxOwner) TLine::Paint(opt);
00243 // suppress painting of label connectors without owner. This case
00244 // happens after insert canvas in go4 (separate cloning
00245 // of lists of primitive members), thus leading to a
00246 // second "ghost label connector" for markers
00247 }
00249 
00250 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:06 2008 for Go4-v3.04-1 by  doxygen 1.4.2