Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #include "TGFrame.h"
53 #include "TGWidget.h"
54 
55 class TGPicture;
56 
57 enum EDoubleSliderSize {
58  //--- sizes for vert. and horz. sliders
59  kDoubleSliderWidth = 24,
60  kDoubleSliderHeight = kDoubleSliderWidth
61 };
62 
63 
64 enum EDoubleSliderScale {
65  //--- type of slider scale
66  kDoubleScaleNo = BIT(0),
67  kDoubleScaleDownRight = BIT(1),
68  kDoubleScaleBoth = BIT(2)
69 };
70 
71 
72 class TGDoubleSlider : public TGFrame, public TGWidget {
73 
74 private:
75  TGDoubleSlider(const TGDoubleSlider&); // Not implemented
76  TGDoubleSlider& operator=(const TGDoubleSlider&); // Not implemented
77 
78 protected:
79  Float_t fPos; // logical position between fVmin and fVmax
80  Float_t fSmin; // logical position of min value of Slider
81  Float_t fSmax; // logical position of max value of Slider
82  Int_t fRelPos; // slider position in pixel coordinates
83  Float_t fVmin; // logical lower limit of slider
84  Float_t fVmax; // logical upper limit of slider
85  Int_t fScale; // tick mark scale
86  Int_t fScaleType; // tick mark scale type (no, downright, both)
87  Int_t fPressPoint; // mouse position at button press event
88  Float_t fPressSmin; // logical min position at button press event
89  Float_t fPressSmax; // logical max position at button press event
90  Int_t fMove; // 1: move min value
91  // 2: move max value
92  // 3: move min and max value
93  // 0: don't move any value
94  Bool_t fReversedScale; // reverse which end is min and max
95  Bool_t fMarkEnds; // lines marking where stretch zones begin
96  const TGPicture *fSliderPic; // picture to draw slider ends
97 
98  TString GetSString() const; // returns scaling type as string
99 
100  static void FixBounds(Float_t &min, Float_t &max);
101  void ChangeCursor(Event_t *event);
102 
103 public:
104  TGDoubleSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1, UInt_t type = 1, Int_t id = -1,
105  UInt_t options = kChildFrame,
106  Pixel_t back = GetDefaultFrameBackground(),
107  Bool_t reversed = kFALSE,
108  Bool_t mark_ends = kFALSE);
109 
110  virtual ~TGDoubleSlider() { }
111 
112  virtual Bool_t HandleButton(Event_t *event) = 0;
113  virtual Bool_t HandleMotion(Event_t *event) = 0;
114 
115  virtual void SetScale(Int_t scale) { fScale = scale; }
116  virtual void SetRange(Float_t min, Float_t max) {
117  fVmin = min; fVmax = max;
118  FixBounds(fVmin, fVmax);
119  }
120 
121  virtual void SetPosition(Float_t min, Float_t max) {
122  if (fReversedScale) { fSmin = fVmin+fVmax-max; fSmax = fVmin+fVmax-min; }
123  else { fSmin = min; fSmax = max; }
124  fClient->NeedRedraw(this);
125  }
126 
127  virtual Float_t GetMinPosition() const {
128  if (fReversedScale) return fVmin+fVmax-fSmax;
129  else return fSmin;
130  }
131  virtual Float_t GetMaxPosition() const {
132  if (fReversedScale) return fVmin+fVmax-fSmin;
133  else return fSmax;
134  }
135  virtual void GetPosition(Float_t &min, Float_t &max) const {
136  if (fReversedScale) { min = fVmin+fVmax-fSmax; max = fVmin+fVmax-fSmin; }
137  else { min = fSmin; max = 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 
144  virtual void MapSubwindows() { TGWindow::MapSubwindows(); }
145 
146  virtual void PositionChanged() { Emit("PositionChanged()"); } //*SIGNAL*
147  virtual void Pressed() { Emit("Pressed()"); } //*SIGNAL*
148  virtual void Released() { Emit("Released()"); } //*SIGNAL*
149 
150  ClassDef(TGDoubleSlider,0) // Double slider widget abstract base class
151 };
152 
153 
154 class TGDoubleVSlider : public TGDoubleSlider {
155 
156 protected:
157  Int_t fYp; // vertical slider y position in pixel coordinates
158 
159  virtual void DoRedraw();
160 
161 public:
162  TGDoubleVSlider(const TGWindow *p = 0, UInt_t h = 1, UInt_t type = 1, Int_t id = -1,
163  UInt_t options = kVerticalFrame,
164  Pixel_t back = GetDefaultFrameBackground(),
165  Bool_t reversed = kFALSE,
166  Bool_t mark_ends = kFALSE);
167 
168  virtual ~TGDoubleVSlider();
169 
170  virtual Bool_t HandleButton(Event_t *event);
171  virtual Bool_t HandleMotion(Event_t *event);
172  virtual TGDimension GetDefaultSize() const
173  { return TGDimension(kDoubleSliderWidth, fHeight); }
174  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
175 
176  ClassDef(TGDoubleVSlider,0) // Vertical double slider widget
177 };
178 
179 
180 class TGDoubleHSlider : public TGDoubleSlider {
181 
182 protected:
183  Int_t fXp; // horizontal slider x position in pixel coordinates
184 
185  virtual void DoRedraw();
186 
187 public:
188  TGDoubleHSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t type = 1, Int_t id = -1,
189  UInt_t options = kHorizontalFrame,
190  Pixel_t back = GetDefaultFrameBackground(),
191  Bool_t reversed = kFALSE,
192  Bool_t mark_ends = kFALSE);
193 
194  virtual ~TGDoubleHSlider();
195 
196  virtual Bool_t HandleButton(Event_t *event);
197  virtual Bool_t HandleMotion(Event_t *event);
198  virtual TGDimension GetDefaultSize() const
199  { return TGDimension(fWidth, kDoubleSliderHeight); }
200  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
201 
202  ClassDef(TGDoubleHSlider,0) // Horizontal double slider widget
203 };
204 
205 #endif