// Mainframe macro generated from application: root // By ROOT version 3.10/0102 on 2003-12-01 16:54:59 // Note: I stripped away a bunch of stuff thats irrelevant. to this // example: I added two slots: // DoSlider() TGDoubleHSlider::PositionChanged() signal this // is used to "pan" displayed 1D histo // UpdateSlider() responds to TPad::RangeAxisChanged() signal // this updates the slider to reflect change in x-axis // limits. ALSO - it clips the displayed y-axis to a minimum // value of 0 - except it does'nt quite work - the user must // click on the canvas.... #if !defined( __CINT__) || defined (__MAKECINT__) #ifndef ROOT_TGDoubleSlider #include "TGDoubleSlider.h" #endif #ifndef ROOT_TGCanvas #include "TGCanvas.h" #endif #ifndef ROOT_TRootEmbeddedCanvas #include "TRootEmbeddedCanvas.h" #endif #ifndef ROOT_TCanvas #include "TCanvas.h" #endif #include "TH1.h" #include "TSystem.h" #endif TGDoubleHSlider *fSlider; TH1F *ph; void ctrls() { // main frame TGMainFrame *frame2 = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame); // composite frame TGCompositeFrame *frame35 = new TGCompositeFrame(frame2,805,626,kHorizontalFrame); // composite frame TGCompositeFrame *frame110 = new TGCompositeFrame(frame35,698,624,kVerticalFrame); // embedded canvas TRootEmbeddedCanvas *frame111 = new TRootEmbeddedCanvas(0,frame110,696,596); Int_t wframe111 = frame111->GetCanvasWindowId(); TCanvas *ECanvas = new TCanvas("ECanvas", 10, 10, wframe111); frame111->AdoptCanvas(ECanvas); frame110->AddFrame(frame111, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,1,1,1,1)); ULong_t ucolor; // will reflect user color changes gClient->GetColorByName("#bfbfbf",ucolor); fSlider = new TGDoubleHSlider(frame110,696,kDoubleScaleNo,-1,kHorizontalFrame,ucolor); fSlider->SetRange(0,700); frame110->AddFrame(fSlider, new TGLayoutHints(kLHintsExpandX,1,1,1,1)); frame35->AddFrame(frame110, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,1,1,1,1)); frame2->AddFrame(frame35, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,10,10,10,10)); // This is the stuff I added to the SavePrimitive() stuff gPad->Connect("RangeAxisChanged()",0,0,"UpdateSlider()"); fSlider->Connect("PositionChanged()",0,0,"DoSlider()"); ph = new TH1F("ph","Test",100,-10.,10.); ph->FillRandom("gaus",100000); ph->Draw(); frame2->SetWMSize(825,732); frame2->MapSubwindows(); frame2->Resize(frame2->GetDefaultSize()); frame2->MapWindow(); frame2->Resize(825,732); } //_____________________________________________________________________________ void UpdateSlider() { // slot attached to gPad->RangeAxisChanged() signal: re-set slider to match // TH1-derived x-axis limits and user limits. Would be nice to add TF1-derived // object.. // Also, if displayed histo does not derive from TH2, limit y-axis display only // non-negative values (ECN 450) TIter next(gPad->GetListOfPrimitives()); TObject *obj; TAxis *paxis; while( obj = next()) { if (obj->InheritsFrom("TH1")) { // following updates x-axis slider if (paxis = ((TH1 *)obj)->GetXaxis()) { fSlider->SetRange(paxis->GetXmin(),paxis->GetXmax()); fSlider->SetPosition(paxis->GetBinLowEdge(paxis->GetFirst()), paxis->GetBinUpEdge(paxis->GetLast())); } // following clips y-axis at minimum=0 for TH1. Note: user must click // on canvas to trigger the repaint if (!obj->InheritsFrom("TH2")) { TH1 *ph = (TH1 *)obj; if (ph->GetMinimum()<0. && ph->GetMinimum()!=-1111.) { ph->SetMinimum(0.); gPad->Modified(); gPad->Update(); break; } } } } } //_____________________________________________________________________________ void DoSlider() { // Handler for slider: use to set user range of displayed TH1-derived object. // Note: Would be nice to add TF1-derived things if no TH1-derived displayed TIter next(gPad->GetListOfPrimitives()); TObject *obj; TAxis *paxis; while( obj = next()) { if (obj->InheritsFrom("TH1")) { if (paxis = ((TH1 *)obj)->GetXaxis()) { Float_t low,hi; fSlider->GetPosition(low,hi); paxis->SetRangeUser(low,hi); gSystem->ProcessEvents(); gPad->Modified(); gPad->Update(); } break; } } }