GUI/Gui.cxx

00001 // @(#)fROOT/GUI:$Name:  $:$Id: Gui.cxx,v 1.16 2007/10/01 08:03:29 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2006/05/26
00003 
00004 #include "Gui.h"
00005 #include <TROOT.h>
00006 #include <TH2F.h>
00007 #include <TThread.h>
00008 #include <TClass.h>
00009 
00010 //using namespace FROOT;
00011 
00012 //_______________________________
00013 Float_t Gui::GetTGadj(Int_t whichone)
00014 {
00015   // whichone = 0: x (width)
00016   // whichone = 1: y (height)
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   // independent on the screen resolution
00028   // (size must be expressed according to a 1024x768 resolution)
00029 
00030   if(!f) return;
00031   Int_t xsafe = (Int_t)(GetTGadj(0) * x);
00032   Int_t ysafe = (Int_t)(GetTGadj(1) * y);
00033   //  gROOT->Info("FROOT::Gui::MoveSafe","Moving: %d, %d",xsafe,ysafe);
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   // independent on the screen resolution
00044   // (size must be expressed according to a 1024x768 resolution)
00045 
00046   if(!f) return;
00047   UInt_t wsafe = (UInt_t)(GetTGadj(0) * w);
00048   UInt_t hsafe = (UInt_t)(GetTGadj(1) * h);
00049   //  gROOT->Info("FROOT::Gui::ResizeSafe","Resizing: %u, %u",wsafe,hsafe);
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   // independent on the screen resolution
00060   // (size must be expressed according to a 1024x768 resolution)
00061 
00062   if(!f) return;
00063   //  gROOT->Info("FROOT::Gui::MoveResizeSafe","Moving-Resizing: %d, %d - %u, %u",x,y,w,h);
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   //  gClient->NeedRedraw(combo);
00080   //  gClient->ProcessEventsFor(combo);
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   // pad_tit_h is: percent of canvas height
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   //   cout << "************* ori_w: " << ori_w << endl;
00098   //   cout << "************* ori_h: " << ori_h << endl;
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   // WRITE TITLE
00117   pt->cd();
00118   TLatex tit;//= new TLatex(.05,.95,title);
00119   tit.SetTextAlign(23);
00120   tit.SetTextSize(TitSize);
00121   tit.DrawLatex(0.5,0.65,title);
00122   //  tit->Draw();
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   // Now apply draw options
00142   pd->cd();
00143 
00144   // compute error-bars
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 }

Generated on Tue Oct 16 15:40:46 2007 by  doxygen 1.5.2