Logo ROOT   6.08/07
Reference Guide
TGDoubleSlider.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Reiner Rohlfs 30/09/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGDoubleSlider
13 #define ROOT_TGDoubleSlider
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGDoubleSlider, TGDoubleVSlider and TGDoubleHSlider //
19 // //
20 // DoubleSlider widgets allow easy selection of a min and a max value //
21 // out of a range. //
22 // DoubleSliders can be either horizontal or vertical oriented and //
23 // there is a choice of three different types of tick marks. //
24 // //
25 // To change the min value press the mouse near to the left / bottom //
26 // edge of the slider. //
27 // To change the max value press the mouse near to the right / top //
28 // edge of the slider. //
29 // To change both values simultaneously press the mouse near to the //
30 // center of the slider. //
31 // //
32 // TGDoubleSlider is an abstract base class. Use the concrete //
33 // TGDoubleVSlider and TGDoubleHSlider. //
34 // //
35 // Dragging the slider will generate the event: //
36 // kC_VSLIDER, kSL_POS, slider id, 0 (for vertical slider) //
37 // kC_HSLIDER, kSL_POS, slider id, 0 (for horizontal slider) //
38 // //
39 // Pressing the mouse will generate the event: //
40 // kC_VSLIDER, kSL_PRESS, slider id, 0 (for vertical slider) //
41 // kC_HSLIDER, kSL_PRESS, slider id, 0 (for horizontal slider) //
42 // //
43 // Releasing the mouse will generate the event: //
44 // kC_VSLIDER, kSL_RELEASE, slider id, 0 (for vertical slider) //
45 // kC_HSLIDER, kSL_RELEASE, slider id, 0 (for horizontal slider) //
46 // //
47 // Use the functions GetMinPosition(), GetMaxPosition() and //
48 // GetPosition() to retrieve the position of the slider. //
49 // //
50 //////////////////////////////////////////////////////////////////////////
51 
52 #ifndef ROOT_TGFrame
53 #include "TGFrame.h"
54 #endif
55 #ifndef ROOT_TGWidget
56 #include "TGWidget.h"
57 #endif
58 
59 class TGPicture;
60 
62  //--- sizes for vert. and horz. sliders
65 };
66 
67 
69  //--- type of slider scale
73 };
74 
75 
76 class TGDoubleSlider : public TGFrame, public TGWidget {
77 
78 private:
79  TGDoubleSlider(const TGDoubleSlider&); // Not implemented
80  TGDoubleSlider& operator=(const TGDoubleSlider&); // Not implemented
81 
82 protected:
83  Float_t fPos; // logical position between fVmin and fVmax
84  Float_t fSmin; // logical position of min value of Slider
85  Float_t fSmax; // logical position of max value of Slider
86  Int_t fRelPos; // slider position in pixel coordinates
87  Float_t fVmin; // logical lower limit of slider
88  Float_t fVmax; // logical upper limit of slider
89  Int_t fScale; // tick mark scale
90  Int_t fScaleType; // tick mark scale type (no, downright, both)
91  Int_t fPressPoint; // mouse position at button press event
92  Float_t fPressSmin; // logical min position at button press event
93  Float_t fPressSmax; // logical max position at button press event
94  Int_t fMove; // 1: move min value
95  // 2: move max value
96  // 3: move min and max value
97  // 0: don't move any value
98  Bool_t fReversedScale; // reverse which end is min and max
99  Bool_t fMarkEnds; // lines marking where stretch zones begin
100  const TGPicture *fSliderPic; // picture to draw slider ends
101 
102  TString GetSString() const; // returns scaling type as string
103 
104  static void FixBounds(Float_t &min, Float_t &max);
105  void ChangeCursor(Event_t *event);
106 
107 public:
108  TGDoubleSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1, UInt_t type = 1, Int_t id = -1,
109  UInt_t options = kChildFrame,
111  Bool_t reversed = kFALSE,
112  Bool_t mark_ends = kFALSE);
113 
114  virtual ~TGDoubleSlider() { }
115 
116  virtual Bool_t HandleButton(Event_t *event) = 0;
117  virtual Bool_t HandleMotion(Event_t *event) = 0;
118 
119  virtual void SetScale(Int_t scale) { fScale = scale; }
120  virtual void SetRange(Float_t min, Float_t max) {
121  fVmin = min; fVmax = max;
122  FixBounds(fVmin, fVmax);
123  }
124 
125  virtual void SetPosition(Float_t min, Float_t max) {
126  if (fReversedScale) { fSmin = fVmin+fVmax-max; fSmax = fVmin+fVmax-min; }
127  else { fSmin = min; fSmax = max; }
128  fClient->NeedRedraw(this);
129  }
130 
131  virtual Float_t GetMinPosition() const {
132  if (fReversedScale) return fVmin+fVmax-fSmax;
133  else return fSmin;
134  }
135  virtual Float_t GetMaxPosition() const {
136  if (fReversedScale) return fVmin+fVmax-fSmin;
137  else return fSmax;
138  }
139  virtual void GetPosition(Float_t &min, Float_t &max) const {
140  if (fReversedScale) { min = fVmin+fVmax-fSmax; max = fVmin+fVmax-fSmin; }
141  else { min = fSmin; max = fSmax; }
142  }
143  virtual void GetPosition(Float_t *min, Float_t *max) const {
144  if (fReversedScale) { *min = fVmin+fVmax-fSmax; *max = fVmin+fVmax-fSmin; }
145  else { *min = fSmin; *max = fSmax; }
146  }
147 
149 
150  virtual void PositionChanged() { Emit("PositionChanged()"); } //*SIGNAL*
151  virtual void Pressed() { Emit("Pressed()"); } //*SIGNAL*
152  virtual void Released() { Emit("Released()"); } //*SIGNAL*
153 
154  ClassDef(TGDoubleSlider,0) // Double slider widget abstract base class
155 };
156 
157 
159 
160 protected:
161  Int_t fYp; // vertical slider y position in pixel coordinates
162 
163  virtual void DoRedraw();
164 
165 public:
166  TGDoubleVSlider(const TGWindow *p = 0, UInt_t h = 1, UInt_t type = 1, Int_t id = -1,
167  UInt_t options = kVerticalFrame,
169  Bool_t reversed = kFALSE,
170  Bool_t mark_ends = kFALSE);
171 
172  virtual ~TGDoubleVSlider();
173 
174  virtual Bool_t HandleButton(Event_t *event);
175  virtual Bool_t HandleMotion(Event_t *event);
176  virtual TGDimension GetDefaultSize() const
178  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
179 
180  ClassDef(TGDoubleVSlider,0) // Vertical double slider widget
181 };
182 
183 
185 
186 protected:
187  Int_t fXp; // horizontal slider x position in pixel coordinates
188 
189  virtual void DoRedraw();
190 
191 public:
192  TGDoubleHSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t type = 1, Int_t id = -1,
193  UInt_t options = kHorizontalFrame,
195  Bool_t reversed = kFALSE,
196  Bool_t mark_ends = kFALSE);
197 
198  virtual ~TGDoubleHSlider();
199 
200  virtual Bool_t HandleButton(Event_t *event);
201  virtual Bool_t HandleMotion(Event_t *event);
202  virtual TGDimension GetDefaultSize() const
204  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
205 
206  ClassDef(TGDoubleHSlider,0) // Horizontal double slider widget
207 };
208 
209 #endif
TString GetSString() const
Returns the slider type as a string - used in SavePrimitive()
virtual Float_t GetMinPosition() const
virtual Float_t GetMaxPosition() const
float Float_t
Definition: RtypesCore.h:53
const char Option_t
Definition: RtypesCore.h:62
#define BIT(n)
Definition: Rtypes.h:120
TH1 * h
Definition: legend2.C:5
EDoubleSliderSize
virtual void MapSubwindows()
Definition: TGWindow.h:91
Float_t fPressSmax
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
EDoubleSliderScale
virtual void SetRange(Float_t min, Float_t max)
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
virtual void Released()
TGDoubleSlider(const TGDoubleSlider &)
virtual Bool_t HandleButton(Event_t *event)=0
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:412
virtual void GetPosition(Float_t &min, Float_t &max) const
#define ClassDef(name, id)
Definition: Rtypes.h:254
ULong_t Pixel_t
Definition: GuiTypes.h:41
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
virtual void GetPosition(Float_t *min, Float_t *max) const
Float_t fPressSmin
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:561
const TGPicture * fSliderPic
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a frame widget as a C++ statement(s) on output stream out.
Definition: TGFrame.cxx:3188
virtual ~TGDoubleSlider()
static void FixBounds(Float_t &min, Float_t &max)
Avoid boundaries to be equal.
virtual void Pressed()
unsigned int UInt_t
Definition: RtypesCore.h:42
void ChangeCursor(Event_t *event)
Change the cursor shape depending on the slider area.
virtual Bool_t HandleMotion(Event_t *event)=0
UInt_t fWidth
Definition: TGFrame.h:150
int type
Definition: TGX11.cxx:120
virtual void MapSubwindows()
UInt_t fHeight
Definition: TGFrame.h:151
Bool_t fReversedScale
TGClient * fClient
Definition: TGObject.h:41
virtual void SetPosition(Float_t min, Float_t max)
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
virtual void SetScale(Int_t scale)
TGDoubleSlider & operator=(const TGDoubleSlider &)
virtual void PositionChanged()
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;