00001
00002
00003
00004 #include "Gui.h"
00005 #include <TROOT.h>
00006 #include <TH2F.h>
00007 #include <TThread.h>
00008 #include <TClass.h>
00009
00010
00011
00012
00013 Float_t Gui::GetTGadj(Int_t whichone)
00014 {
00015
00016
00017 switch(whichone){
00018 case 0:return (Float_t)((gClient->GetDisplayWidth()) / 1024.);
00019 case 1:return (Float_t)((gClient->GetDisplayHeight()) / 768.);
00020 default: return 0;
00021 }
00022 }
00023
00024
00025
00026 void Gui::MoveSafe(Double_t x, Double_t y, TGFrame* f,Bool_t redraw){
00027
00028
00029
00030 if(!f) return;
00031 Int_t xsafe = (Int_t)(GetTGadj(0) * x);
00032 Int_t ysafe = (Int_t)(GetTGadj(1) * y);
00033
00034 f->Move(xsafe,ysafe);
00035 if(redraw){
00036 gClient->NeedRedraw(f);
00037 gClient->ProcessEventsFor(f);
00038 }
00039 }
00040
00041
00042 void Gui::ResizeSafe(Double_t w, Double_t h, TGFrame* f,Bool_t redraw){
00043
00044
00045
00046 if(!f) return;
00047 UInt_t wsafe = (UInt_t)(GetTGadj(0) * w);
00048 UInt_t hsafe = (UInt_t)(GetTGadj(1) * h);
00049
00050 f->Resize(wsafe,hsafe);
00051 if(redraw){
00052 gClient->NeedRedraw(f);
00053 gClient->ProcessEventsFor(f);
00054 }
00055 }
00056
00057
00058 void Gui::MoveResizeSafe(Double_t x, Double_t y, Double_t w, Double_t h, TGFrame* f,Bool_t redraw){
00059
00060
00061
00062 if(!f) return;
00063
00064 MoveSafe(x,y,f,kFALSE);
00065 ResizeSafe(w,h,f,kFALSE);
00066 if(redraw){
00067 gClient->NeedRedraw(f);
00068 gClient->ProcessEventsFor(f);
00069 }
00070 }
00071
00072
00073 void Gui::SelectComboEntry(TGComboBox *combo,Int_t entry_id){
00074
00075 Printf("Selecting entry %d",entry_id);
00076 combo->Select(entry_id);
00077 combo->Selected(combo->WidgetId(),entry_id);
00078 combo->Selected(entry_id);
00079
00080
00081 }
00082
00083
00084 void Gui::SaveCanvasWithTitle(TCanvas *canv,const TString &title,const TString &filename,TString draw_1D_opt,TString draw_2D_opt,Int_t TitColor,Double_t pad_tit_h,Double_t TitSize){
00085
00086
00087 Printf("saving canvas \"%s\"",canv->GetTitle());
00088
00089 Double_t sep = 0.005;
00090
00091 Double_t ori_w = (Double_t) ( canv->GetWindowWidth() );
00092 Double_t ori_h = (Double_t) ( canv->GetWindowHeight() );
00093
00094 if(ori_w == 0 || ori_w == 32000) ori_w = 800;
00095 if(ori_h == 0 || ori_h == 32000) ori_h = 600;
00096
00097
00098
00099
00100 Double_t w_h_ratio = ori_w / ori_h;
00101
00102 UInt_t displ_h = (UInt_t) ( ori_h - ( ori_h * pad_tit_h + sep) );
00103 UInt_t displ_w = (UInt_t) ( displ_h * w_h_ratio );
00104
00105 TCanvas *save_canvas = new TCanvas("save_canvas","Save Canvas",300,300,(UInt_t)ori_w,(UInt_t)ori_h);
00106
00107
00108 TPad *pt = new TPad("pt","ptit",
00109 .01 , (1.- (pad_tit_h - sep) ) ,
00110 .99 , .999);
00111
00112 if(TitColor != -1)pt->SetFillColor(TitColor);
00113
00114 save_canvas->cd();
00115 pt->Draw();
00116
00117 pt->cd();
00118 TLatex tit;
00119 tit.SetTextAlign(23);
00120 tit.SetTextSize(TitSize);
00121 tit.DrawLatex(0.5,0.65,title);
00122
00123
00124
00125 Double_t dis_perc_w = (Double_t) (displ_w) / ori_w;
00126 Double_t dis_perc_h = (Double_t) (displ_h) / ori_h;
00127
00128 Double_t half_p = (1. - dis_perc_w)/2;
00129
00130 TPad *pd = new TPad("pd","pdis",
00131 half_p , .0001,
00132 1 - half_p , dis_perc_h,3,1,1);
00133
00134 save_canvas->cd();
00135 pd->Draw();
00136
00137 pd->cd();
00138 canv->DrawClonePad();
00139
00140
00141
00142 pd->cd();
00143
00144
00145 TIter next(gDirectory->GetList());
00146 TObject *obj;
00147 while ((obj = next())) {
00148 TString clnam = obj->IsA()->GetName();
00149 clnam.Resize(3);
00150 if ( clnam.CompareTo("TH1") == 0 ) ( (TH1 *)obj )->SetOption(draw_1D_opt);
00151 else if ( clnam.CompareTo("TH2") == 0 ) ( (TH2 *)obj )->SetOption(draw_2D_opt);
00152 }
00153
00154
00155 pd->Modified();
00156 pd->Update();
00157
00158 save_canvas->SaveAs(filename);
00159 delete save_canvas;
00160
00161 }