Logo ROOT   6.10/09
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 #include "TGFrame.h"
53 #include "TGWidget.h"
54 
55 class TGPicture;
56 
58  //--- sizes for vert. and horz. sliders
61 };
62 
63 
65  //--- type of slider scale
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,
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 
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 
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,
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
174  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
175 
176  ClassDef(TGDoubleVSlider,0) // Vertical double slider widget
177 };
178 
179 
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,
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
200  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
201 
202  ClassDef(TGDoubleHSlider,0) // Horizontal double slider widget
203 };
204 
205 #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:75
TH1 * h
Definition: legend2.C:5
EDoubleSliderSize
virtual void MapSubwindows()
Definition: TGWindow.h:85
Float_t fPressSmax
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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:297
ULong_t Pixel_t
Definition: GuiTypes.h:39
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
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:3187
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:134
const Bool_t kFALSE
Definition: RtypesCore.h:92
int type
Definition: TGX11.cxx:120
virtual void MapSubwindows()
UInt_t fHeight
Definition: TGFrame.h:135
Bool_t fReversedScale
TGClient * fClient
Definition: TGObject.h:37
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 &)
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
virtual void PositionChanged()
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;