TSliderBox.cxx

Go to the documentation of this file.
00001 // @(#)root/gpad:$Id: TSliderBox.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Rene Brun   23/11/96
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "Riostream.h"
00013 #include "TROOT.h"
00014 #include "TSlider.h"
00015 #include "TSliderBox.h"
00016 
00017 #include <string.h>
00018 
00019 ClassImp(TSliderBox)
00020 
00021 //______________________________________________________________________________
00022 //////////////////////////////////////////////////////////////////////////
00023 //                                                                      //
00024 // TSliderBox                                                           //
00025 //                                                                      //
00026 //  The moving box in a TSlider                                         //
00027 //                                                                      //
00028 //////////////////////////////////////////////////////////////////////////
00029 
00030 
00031 //______________________________________________________________________________
00032 TSliderBox::TSliderBox(): TWbox()
00033 {
00034    // SliderBox default constructor.
00035 
00036    fSlider = 0;
00037 }
00038 
00039 
00040 //______________________________________________________________________________
00041 TSliderBox::TSliderBox(Double_t x1, Double_t y1,Double_t x2, Double_t  y2, Color_t color, Short_t bordersize, Short_t bordermode)
00042            :TWbox(x1,y1,x2,y2,color,bordersize,bordermode)
00043 {
00044    // SliderBox normal constructor.
00045 
00046    fSlider = 0;
00047 }
00048 
00049 
00050 //______________________________________________________________________________
00051 TSliderBox::~TSliderBox()
00052 {
00053    // SliderBox default destructor.
00054 }
00055 
00056 
00057 //______________________________________________________________________________
00058 void TSliderBox::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00059 {
00060    // Interaction with a slider.
00061 
00062    const Int_t kMaxDiff = 5;
00063    const Int_t kMinSize = 20;
00064 
00065    static Int_t px1, px2, py1, py2, pxl, pyl, pxt, pyt, pxold, pyold;
00066    static Int_t px1p, px2p, py1p, py2p;
00067    static Bool_t  pL, pR, pTop, pBot, pINSIDE;
00068    Int_t  wx, wy;
00069    Bool_t doing_again = kFALSE;
00070    Bool_t opaque  = gPad->OpaqueMoving();
00071    Bool_t ropaque = gPad->OpaqueResizing();
00072 
00073    TVirtualPad  *parent = gPad;
00074 
00075    Int_t border   = parent->GetBorderSize();
00076    Int_t pxpadmin = parent->XtoAbsPixel(parent->GetX1()) + border;
00077    Int_t pxpadmax = parent->XtoAbsPixel(parent->GetX2()) - border;
00078    Int_t pypadmin = parent->YtoAbsPixel(parent->GetY1()) - border;
00079    Int_t pypadmax = parent->YtoAbsPixel(parent->GetY2()) + border;
00080 
00081    Bool_t vertical = kTRUE;
00082    if (pxpadmax-pxpadmin > pypadmin-pypadmax) vertical = kFALSE;
00083 
00084 again:
00085 
00086    switch (event) {
00087 
00088    case kButton1Down:
00089 
00090       gVirtualX->SetLineColor(-1);
00091       TAttLine::Modify();  //Change line attributes only if necessary
00092       if (GetFillColor())
00093          gVirtualX->SetLineColor(GetFillColor());
00094       else
00095          gVirtualX->SetLineColor(1);
00096       gVirtualX->SetLineWidth(2);
00097 
00098       // No break !!!
00099 
00100    case kMouseMotion:
00101 
00102       px1 = gPad->XtoAbsPixel(GetX1());
00103       py1 = gPad->YtoAbsPixel(GetY1());
00104       px2 = gPad->XtoAbsPixel(GetX2());
00105       py2 = gPad->YtoAbsPixel(GetY2());
00106 
00107       if (px1 < px2) {
00108          pxl = px1;
00109          pxt = px2;
00110       } else {
00111          pxl = px2;
00112          pxt = px1;
00113       }
00114       if (py1 < py2) {
00115          pyl = py1;
00116          pyt = py2;
00117       } else {
00118          pyl = py2;
00119          pyt = py1;
00120       }
00121 
00122       px1p = pxpadmin;
00123       py1p = pypadmin;
00124       px2p = pxpadmax;
00125       py2p = pypadmax;
00126 
00127       pL = pR  = pTop = pBot = pINSIDE = kFALSE;
00128 
00129       if (vertical && (px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
00130           TMath::Abs(py - pyl) < kMaxDiff) {             // top edge
00131          pxold = pxl; pyold = pyl; pTop = kTRUE;
00132          gPad->SetCursor(kTopSide);
00133       }
00134 
00135       if (vertical && (px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
00136           TMath::Abs(py - pyt) < kMaxDiff) {             // bottom edge
00137          pxold = pxt; pyold = pyt; pBot = kTRUE;
00138          gPad->SetCursor(kBottomSide);
00139       }
00140 
00141       if (!vertical && (py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
00142           TMath::Abs(px - pxl) < kMaxDiff) {             // left edge
00143          pxold = pxl; pyold = pyl; pL = kTRUE;
00144          gPad->SetCursor(kLeftSide);
00145       }
00146 
00147       if (!vertical && (py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
00148           TMath::Abs(px - pxt) < kMaxDiff) {             // right edge
00149          pxold = pxt; pyold = pyt; pR = kTRUE;
00150          gPad->SetCursor(kRightSide);
00151       }
00152 
00153       if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
00154           (py > pyl+kMaxDiff && py < pyt-kMaxDiff)) {    // inside box
00155          pxold = px; pyold = py; pINSIDE = kTRUE;
00156          if (event == kButton1Down)
00157             gPad->SetCursor(kMove);
00158          else
00159             gPad->SetCursor(kCross);
00160       }
00161 
00162       fResizing = kFALSE;
00163       if ( pL || pR || pTop || pBot)
00164          fResizing = kTRUE;
00165 
00166       if ( !pL && !pR && !pTop && !pBot && !pINSIDE)
00167          gPad->SetCursor(kCross);
00168 
00169       break;
00170 
00171    case kButton1Motion:
00172 
00173       wx = wy = 0;
00174 
00175       if (pTop) {
00176          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00177          py2 += py - pyold;
00178          if (py2 > py1-kMinSize) { py2 = py1-kMinSize; wy = py2; }
00179          if (py2 < py2p) { py2 = py2p; wy = py2; }
00180          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00181       }
00182       if (pBot) {
00183          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00184          py1 += py - pyold;
00185          if (py1 < py2+kMinSize) { py1 = py2+kMinSize; wy = py1; }
00186          if (py1 > py1p) { py1 = py1p; wy = py1; }
00187          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00188       }
00189       if (pL) {
00190          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00191          px1 += px - pxold;
00192          if (px1 > px2-kMinSize) { px1 = px2-kMinSize; wx = px1; }
00193          if (px1 < px1p) { px1 = px1p; wx = px1; }
00194          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00195       }
00196       if (pR) {
00197          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00198          px2 += px - pxold;
00199          if (px2 < px1+kMinSize) { px2 = px1+kMinSize; wx = px2; }
00200          if (px2 > px2p) { px2 = px2p; wx = px2; }
00201          if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
00202       }
00203       if (pINSIDE) {
00204          if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);  // draw the old box
00205          Int_t dx = px - pxold;
00206          Int_t dy = py - pyold;
00207          px1 += dx; py1 += dy; px2 += dx; py2 += dy;
00208          if (px1 < px1p) { dx = px1p - px1; px1 += dx; px2 += dx; wx = px+dx; }
00209          if (px2 > px2p) { dx = px2 - px2p; px1 -= dx; px2 -= dx; wx = px-dx; }
00210          if (py1 > py1p) { dy = py1 - py1p; py1 -= dy; py2 -= dy; wy = py-dy; }
00211          if (py2 < py2p) { dy = py2p - py2; py1 += dy; py2 += dy; wy = py+dy; }
00212          if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);  // draw the new box
00213       }
00214 
00215       if (wx || wy) {
00216          if (wx) px = wx;
00217          if (wy) py = wy;
00218          gVirtualX->Warp(px, py);
00219       }
00220 
00221       pxold = px;
00222       pyold = py;
00223 
00224       if ((pINSIDE && opaque) || (fResizing && ropaque)) {
00225          event = kButton1Up;
00226          doing_again = kTRUE;
00227          goto again;
00228       }
00229 
00230       break;
00231 
00232    case kButton1Up:
00233 
00234       if (pTop || pBot || pL || pR || pINSIDE) {
00235          fX1 = gPad->AbsPixeltoX(px1);
00236          fY1 = gPad->AbsPixeltoY(py1);
00237          fX2 = gPad->AbsPixeltoX(px2);
00238          fY2 = gPad->AbsPixeltoY(py2);
00239       }
00240 
00241       if (pINSIDE) {
00242          // if it was not a pad that was moved then it must have been
00243          // a box or something like that so we have to redraw the pad
00244          if (parent == gPad) gPad->Modified(kTRUE);
00245          if (!doing_again) gPad->SetCursor(kCross);
00246       }
00247 
00248       if (pTop || pBot ||  pL || pR )
00249          gPad->Modified(kTRUE);
00250 
00251       // Restore original event type
00252       if (doing_again)
00253          event = kButton1Motion;
00254       else {
00255          gVirtualX->SetLineColor(-1);
00256          gVirtualX->SetLineWidth(-1);
00257       }
00258 
00259       break;
00260    }
00261 
00262 
00263    // Give control to object using the slider
00264 
00265    Float_t xpmin,xpmax;
00266    if (vertical) {
00267       xpmin = Float_t(pypadmin-py1)/Float_t(pypadmin-pypadmax);
00268       xpmax = Float_t(pypadmin-py2)/Float_t(pypadmin-pypadmax);
00269    } else {  //vertical slider
00270       xpmin = Float_t(px1-pxpadmin)/Float_t(pxpadmax-pxpadmin);
00271       xpmax = Float_t(px2-pxpadmin)/Float_t(pxpadmax-pxpadmin);
00272    }
00273    fSlider->SetMinimum(xpmin);
00274    fSlider->SetMaximum(xpmax);
00275 
00276    //A user method to execute?
00277    Int_t lenMethod = strlen(fSlider->GetMethod());
00278    if (event == kButton1Up && lenMethod > 0 ) {
00279       gPad->SetCursor(kWatch);
00280       gROOT->ProcessLine(fSlider->GetMethod());
00281       return;
00282    }
00283 
00284    //An object connected to this slider?
00285    TObject *obj = fSlider->GetObject();
00286    if (obj) {
00287       obj->ExecuteEvent(event,0,0);
00288    }
00289 }
00290 
00291 
00292 //______________________________________________________________________________
00293 void TSliderBox::SavePrimitive(ostream &, Option_t * /*= ""*/)
00294 {
00295     // Save primitive as a C++ statement(s) on output stream out
00296 }

Generated on Tue Jul 5 14:14:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1