# TGDoubleSlider* ```cpp ////////////////////////////////////////////////////////////////////////// // // // TGDoubleSlider, TGDoubleVSlider and TGDoubleHSlider // // // // DoubleSlider widgets allow easy selection of a min and a max value // // out of a range. // // DoubleSliders can be either horizontal or vertical oriented and // // there is a choice of three different types of tick marks. // // // // To change the min value press the mouse near to the left / bottom // // edge of the slider. // // To change the max value press the mouse near to the right / top // // edge of the slider. // // To change both values simultaneously press the mouse near to the // // center of the slider. // // // // TGDoubleSlider is an abstract base class. Use the concrete // // TGDoubleVSlider and TGDoubleHSlider. // // // // Dragging the slider will generate the event: // // kC_VSLIDER, kSL_POS, slider id, 0 (for vertical slider) // // kC_HSLIDER, kSL_POS, slider id, 0 (for horizontal slider) // // // // Pressing the mouse will generate the event: // // kC_VSLIDER, kSL_PRESS, slider id, 0 (for vertical slider) // // kC_HSLIDER, kSL_PRESS, slider id, 0 (for horizontal slider) // // // // Releasing the mouse will generate the event: // // kC_VSLIDER, kSL_RELEASE, slider id, 0 (for vertical slider) // // kC_HSLIDER, kSL_RELEASE, slider id, 0 (for horizontal slider) // // // // Use the functions GetMinPosition(), GetMaxPosition() and // // GetPosition() to retrieve the position of the slider. // // // ////////////////////////////////////////////////////////////////////////// ``` TGDoubleSlider 继承 TGFrame, TGWidget TGDoubleVSlider 继承 TGDoubleSlider TGDoubleHSlider 继承 TGDoubleSlider ## class ```cpp enum EDoubleSliderSize { //--- sizes for vert. and horz. sliders kDoubleSliderWidth = 24, kDoubleSliderHeight = kDoubleSliderWidth }; enum EDoubleSliderScale { //--- type of slider scale kDoubleScaleNo = BIT(0), kDoubleScaleDownRight = BIT(1), kDoubleScaleBoth = BIT(2) }; ``` **TGDoubleSlider** ```cpp TGDoubleSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1, UInt_t type = 1, Int_t id = -1, UInt_t options = kChildFrame, Pixel_t back = GetDefaultFrameBackground(), Bool_t reversed = kFALSE, Bool_t mark_ends = kFALSE);/// Slider constructor. virtual ~TGDoubleSlider() { } virtual Bool_t HandleButton(Event_t *event) = 0; virtual Bool_t HandleMotion(Event_t *event) = 0; virtual void SetScale(Int_t scale) { fScale = scale; } virtual void SetRange(Float_t min, Float_t max) { fVmin = min; fVmax = max; FixBounds(fVmin, fVmax); } virtual void SetPosition(Float_t min, Float_t max) { if (fReversedScale) { fSmin = fVmin+fVmax-max; fSmax = fVmin+fVmax-min; } else { fSmin = min; fSmax = max; } fClient->NeedRedraw(this); } virtual Float_t GetMinPosition() const { if (fReversedScale) return fVmin+fVmax-fSmax; else return fSmin; } virtual Float_t GetMaxPosition() const { if (fReversedScale) return fVmin+fVmax-fSmin; else return fSmax; } virtual void GetPosition(Float_t &min, Float_t &max) const { if (fReversedScale) { min = fVmin+fVmax-fSmax; max = fVmin+fVmax-fSmin; } else { min = fSmin; max = fSmax; } } virtual void GetPosition(Float_t *min, Float_t *max) const { if (fReversedScale) { *min = fVmin+fVmax-fSmax; *max = fVmin+fVmax-fSmin; } else { *min = fSmin; *max = fSmax; } } virtual void MapSubwindows() { TGWindow::MapSubwindows(); } virtual void PositionChanged() { Emit("PositionChanged()"); } //*SIGNAL* virtual void Pressed() { Emit("Pressed()"); } //*SIGNAL* virtual void Released() { Emit("Released()"); } //*SIGNAL* ``` **TGDoubleVSlider** ```cpp TGDoubleVSlider(const TGWindow *p = 0, UInt_t h = 1, UInt_t type = 1, Int_t id = -1, UInt_t options = kVerticalFrame, Pixel_t back = GetDefaultFrameBackground(), Bool_t reversed = kFALSE, Bool_t mark_ends = kFALSE);/// Create a vertical slider widget. virtual ~TGDoubleVSlider();/// Delete vertical slider widget. virtual Bool_t HandleButton(Event_t *event);/// Handle mouse button event in vertical slider. virtual Bool_t HandleMotion(Event_t *event);/// Handle mouse motion event in vertical slider. virtual TGDimension GetDefaultSize() const { return TGDimension(kDoubleSliderWidth, fHeight); } virtual void SavePrimitive(std::ostream &out, Option_t *option = ""); /// Save an horizontal slider as a C++ statement(s) on output stream out. ``` **TGDoubleHSlider ** ```cpp TGDoubleHSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t type = 1, Int_t id = -1, UInt_t options = kHorizontalFrame, Pixel_t back = GetDefaultFrameBackground(), Bool_t reversed = kFALSE, Bool_t mark_ends = kFALSE);/// Create horizontal slider widget. virtual ~TGDoubleHSlider();/// Delete a horizontal slider widget. virtual Bool_t HandleButton(Event_t *event);/// Handle mouse button event in horizontal slider widget. virtual Bool_t HandleMotion(Event_t *event);/// Handle mouse motion event in horizontal slide widget. virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, kDoubleSliderHeight); } virtual void SavePrimitive(std::ostream &out, Option_t *option = ""); /// Save an horizontal slider as a C++ statement(s) on output stream out. ``` ## code ## example