TGDoubleSlider.h

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGDoubleSlider.h 23115 2008-04-10 13:35:37Z rdm $
00002 // Author: Reiner Rohlfs   30/09/98
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 #ifndef ROOT_TGDoubleSlider
00013 #define ROOT_TGDoubleSlider
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TGDoubleSlider, TGDoubleVSlider and TGDoubleHSlider                  //
00019 //                                                                      //
00020 // DoubleSlider widgets allow easy selection of a min and a max value   //
00021 // out of a range.                                                      //
00022 // DoubleSliders can be either horizontal or vertical oriented and      //
00023 // there is a choice of three different types of tick marks.            //
00024 //                                                                      //
00025 // To change the min value press the mouse near to the left / bottom    //
00026 // edge of the slider.                                                  //
00027 // To change the max value press the mouse near to the right / top      //
00028 // edge of the slider.                                                  //
00029 // To change both values simultaneously press the mouse near to the     //
00030 // center of the slider.                                                //
00031 //                                                                      //
00032 // TGDoubleSlider is an abstract base class. Use the concrete           //
00033 // TGDoubleVSlider and TGDoubleHSlider.                                 //
00034 //                                                                      //
00035 // Dragging the slider will generate the event:                         //
00036 // kC_VSLIDER, kSL_POS, slider id, 0  (for vertical slider)             //
00037 // kC_HSLIDER, kSL_POS, slider id, 0  (for horizontal slider)           //
00038 //                                                                      //
00039 // Pressing the mouse will generate the event:                          //
00040 // kC_VSLIDER, kSL_PRESS, slider id, 0  (for vertical slider)           //
00041 // kC_HSLIDER, kSL_PRESS, slider id, 0  (for horizontal slider)         //
00042 //                                                                      //
00043 // Releasing the mouse will generate the event:                         //
00044 // kC_VSLIDER, kSL_RELEASE, slider id, 0  (for vertical slider)         //
00045 // kC_HSLIDER, kSL_RELEASE, slider id, 0  (for horizontal slider)       //
00046 //                                                                      //
00047 // Use the functions GetMinPosition(), GetMaxPosition() and             //
00048 // GetPosition() to retrieve the position of the slider.                //
00049 //                                                                      //
00050 //////////////////////////////////////////////////////////////////////////
00051 
00052 #ifndef ROOT_TGFrame
00053 #include "TGFrame.h"
00054 #endif
00055 #ifndef ROOT_TGWidget
00056 #include "TGWidget.h"
00057 #endif
00058 
00059 class TGPicture;
00060 
00061 enum EDoubleSliderSize {
00062    //--- sizes for vert. and horz. sliders
00063    kDoubleSliderWidth  = 24,
00064    kDoubleSliderHeight = kDoubleSliderWidth
00065 };
00066 
00067 
00068 enum EDoubleSliderScale {
00069    //--- type of slider scale
00070    kDoubleScaleNo        = BIT(0),
00071    kDoubleScaleDownRight = BIT(1),
00072    kDoubleScaleBoth      = BIT(2)
00073 };
00074 
00075 
00076 class TGDoubleSlider : public TGFrame, public TGWidget {
00077 
00078 private:
00079    TGDoubleSlider(const TGDoubleSlider&); // Not implemented
00080    TGDoubleSlider& operator=(const TGDoubleSlider&); // Not implemented
00081 
00082 protected:
00083    Float_t       fPos;           // logical position between fVmin and fVmax
00084    Float_t       fSmin;          // logical position of min value of Slider
00085    Float_t       fSmax;          // logical position of max value of Slider
00086    Int_t         fRelPos;        // slider position in pixel coordinates
00087    Float_t       fVmin;          // logical lower limit of slider
00088    Float_t       fVmax;          // logical upper limit of slider
00089    Int_t         fScale;         // tick mark scale
00090    Int_t         fScaleType;     // tick mark scale type (no, downright, both)
00091    Int_t         fPressPoint;    // mouse position at button press event
00092    Float_t       fPressSmin;     // logical min position at button press event
00093    Float_t       fPressSmax;     // logical max position at button press event
00094    Int_t         fMove;          // 1: move min value
00095                                  // 2: move max value
00096                                  // 3: move min and max value
00097                                  // 0: don't move any value
00098    Bool_t        fReversedScale; // reverse which end is min and max
00099    Bool_t        fMarkEnds;      // lines marking where stretch zones begin
00100    const TGPicture *fSliderPic;  // picture to draw slider ends
00101 
00102    TString       GetSString() const; // returns scaling type as string
00103 
00104    static void   FixBounds(Float_t &min, Float_t &max);
00105    void          ChangeCursor(Event_t *event);
00106 
00107 public:
00108    TGDoubleSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1, UInt_t type = 1, Int_t id = -1,
00109                   UInt_t options = kChildFrame,
00110                   Pixel_t back = GetDefaultFrameBackground(),
00111                   Bool_t reversed = kFALSE,
00112                   Bool_t mark_ends = kFALSE);
00113 
00114    virtual ~TGDoubleSlider() { }
00115 
00116    virtual Bool_t HandleButton(Event_t *event) = 0;
00117    virtual Bool_t HandleMotion(Event_t *event) = 0;
00118 
00119    virtual void  SetScale(Int_t scale) { fScale = scale; }
00120    virtual void  SetRange(Float_t min, Float_t max) { 
00121       fVmin = min; fVmax = max; 
00122       FixBounds(fVmin, fVmax);
00123    }
00124 
00125    virtual void SetPosition(Float_t min, Float_t max) {
00126       if (fReversedScale) { fSmin = fVmin+fVmax-max; fSmax = fVmin+fVmax-min; }
00127       else { fSmin = min; fSmax = max; }
00128       fClient->NeedRedraw(this);
00129    }
00130 
00131    virtual Float_t GetMinPosition() const {
00132       if (fReversedScale) return fVmin+fVmax-fSmax;
00133       else return fSmin;
00134    }
00135    virtual Float_t GetMaxPosition() const {
00136       if (fReversedScale) return fVmin+fVmax-fSmin;
00137       else return fSmax;
00138    }
00139    virtual void GetPosition(Float_t &min, Float_t &max) const {
00140       if (fReversedScale) { min = fVmin+fVmax-fSmax; max = fVmin+fVmax-fSmin; }
00141       else { min = fSmin; max = fSmax; }
00142    }
00143    virtual void GetPosition(Float_t *min, Float_t *max) const {
00144       if (fReversedScale) { *min = fVmin+fVmax-fSmax; *max = fVmin+fVmax-fSmin; }
00145       else { *min = fSmin; *max = fSmax; }
00146    }
00147 
00148    virtual void  MapSubwindows() { TGWindow::MapSubwindows(); }
00149 
00150    virtual void  PositionChanged() { Emit("PositionChanged()"); } //*SIGNAL*
00151    virtual void  Pressed() { Emit("Pressed()"); }                 //*SIGNAL*
00152    virtual void  Released() { Emit("Released()"); }               //*SIGNAL*
00153 
00154    ClassDef(TGDoubleSlider,0)  // Double slider widget abstract base class
00155 };
00156 
00157 
00158 class TGDoubleVSlider : public TGDoubleSlider {
00159 
00160 protected:
00161    Int_t   fYp;      // vertical slider y position in pixel coordinates
00162 
00163    virtual void DoRedraw();
00164 
00165 public:
00166    TGDoubleVSlider(const TGWindow *p = 0, UInt_t h = 1, UInt_t type = 1, Int_t id = -1,
00167                    UInt_t options = kVerticalFrame,
00168                    Pixel_t back = GetDefaultFrameBackground(),
00169                    Bool_t reversed = kFALSE,
00170                    Bool_t mark_ends = kFALSE);
00171 
00172    virtual ~TGDoubleVSlider();
00173 
00174    virtual Bool_t HandleButton(Event_t *event);
00175    virtual Bool_t HandleMotion(Event_t *event);
00176    virtual TGDimension GetDefaultSize() const
00177                      { return TGDimension(kDoubleSliderWidth, fHeight); }
00178    virtual void   SavePrimitive(ostream &out, Option_t *option = "");
00179 
00180    ClassDef(TGDoubleVSlider,0)  // Vertical double slider widget
00181 };
00182 
00183 
00184 class TGDoubleHSlider : public TGDoubleSlider {
00185 
00186 protected:
00187    Int_t       fXp;     // horizontal slider x position in pixel coordinates
00188 
00189    virtual void DoRedraw();
00190 
00191 public:
00192    TGDoubleHSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t type = 1, Int_t id = -1,
00193                    UInt_t options = kHorizontalFrame,
00194                    Pixel_t back = GetDefaultFrameBackground(),
00195                    Bool_t reversed = kFALSE,
00196                    Bool_t mark_ends = kFALSE);
00197 
00198    virtual ~TGDoubleHSlider();
00199 
00200    virtual Bool_t HandleButton(Event_t *event);
00201    virtual Bool_t HandleMotion(Event_t *event);
00202    virtual TGDimension GetDefaultSize() const
00203                      { return TGDimension(fWidth, kDoubleSliderHeight); }
00204    virtual void   SavePrimitive(ostream &out, Option_t *option = "");
00205 
00206    ClassDef(TGDoubleHSlider,0)  // Horizontal double slider widget
00207 };
00208 
00209 #endif

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