Logo ROOT   6.08/07
Reference Guide
TGSlider.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 14/01/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_TGSlider
13 #define ROOT_TGSlider
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGSlider, TGVSlider and TGHSlider //
19 // //
20 // Slider widgets allow easy selection of a range. //
21 // Sliders can be either horizontal or vertical oriented and there is //
22 // a choice of two different slider types and three different types //
23 // of tick marks. //
24 // //
25 // TGSlider is an abstract base class. Use the concrete TGVSlider and //
26 // TGHSlider. //
27 // //
28 // Dragging the slider will generate the event: //
29 // kC_VSLIDER, kSL_POS, slider id, position (for vertical slider) //
30 // kC_HSLIDER, kSL_POS, slider id, position (for horizontal slider) //
31 // //
32 // Pressing the mouse will generate the event: //
33 // kC_VSLIDER, kSL_PRESS, slider id, 0 (for vertical slider) //
34 // kC_HSLIDER, kSL_PRESS, slider id, 0 (for horizontal slider) //
35 // //
36 // Releasing the mouse will generate the event: //
37 // kC_VSLIDER, kSL_RELEASE, slider id, 0 (for vertical slider) //
38 // kC_HSLIDER, kSL_RELEASE, slider id, 0 (for horizontal slider) //
39 // //
40 //////////////////////////////////////////////////////////////////////////
41 
42 #ifndef ROOT_TGFrame
43 #include "TGFrame.h"
44 #endif
45 #ifndef ROOT_TGWidget
46 #include "TGWidget.h"
47 #endif
48 
49 
50 //--- sizes for vert. and horz. sliders
51 
55 };
56 
57 
59  //--- slider types (type of slider picture)
60  kSlider1 = BIT(0),
61  kSlider2 = BIT(1),
62 
63  //--- scaling of slider
64  kScaleNo = BIT(2),
67 };
68 
69 
70 class TGSlider : public TGFrame, public TGWidget {
71 
72 protected:
73  Int_t fPos; // logical position between fVmin and fVmax
74  Int_t fRelPos; // slider position in pixel coordinates
75  Int_t fVmin; // logical lower limit of slider
76  Int_t fVmax; // logical upper limit of slider
77  Int_t fType; // slider type bits
78  Int_t fScale; // tick mark scale
79  Bool_t fDragging; // true if in dragging mode
80  const TGPicture *fSliderPic; // picture to draw slider
81  const TGPicture *fDisabledPic; // picture to draw disabled slider
82 
83  TString GetTypeString() const; // used in SavePrimitive
84  virtual void CreateDisabledPicture();
85 
86 private:
87  TGSlider(const TGSlider&); // not implemented
88  TGSlider& operator=(const TGSlider&); // not implemented
89 
90 public:
91  TGSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
92  UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
93  UInt_t options = kChildFrame,
95 
96  virtual ~TGSlider() { }
97 
98  virtual Bool_t HandleButton(Event_t *event) = 0;
99  virtual Bool_t HandleConfigureNotify(Event_t* event) = 0;
100  virtual Bool_t HandleMotion(Event_t *event) = 0;
101 
102  virtual void SetEnabled(Bool_t flag = kTRUE) { SetState( flag ); } //*TOGGLE* *GETTER=IsEnabled
103  virtual void SetState(Bool_t state);
104  virtual void SetScale(Int_t scale) { fScale = scale; } //*MENU*
105  virtual void SetRange(Int_t min, Int_t max) { fVmin = min; fVmax = max; } //*MENU*
106  virtual void SetPosition(Int_t pos) { fPos = pos; fClient->NeedRedraw(this); } //*MENU*
107  virtual Int_t GetPosition() const { return fPos; }
108  virtual Int_t GetMinPosition() const { return fVmin; }
109  virtual Int_t GetMaxPosition() const { return fVmax; }
110  virtual Int_t GetScale() const { return fScale; }
112  virtual void ChangeSliderPic(const char *name) {
113  if (fSliderPic) fClient->FreePicture(fSliderPic);
114  fSliderPic = fClient->GetPicture(name);
115  }
116 
117  virtual void PositionChanged(Int_t pos) { Emit("PositionChanged(Int_t)", pos); } // *SIGNAL*
118  virtual void Pressed() { Emit("Pressed()"); } // *SIGNAL*
119  virtual void Released() { Emit("Released()"); } // *SIGNAL*
120 
121  ClassDef(TGSlider,0) // Slider widget abstract base class
122 };
123 
124 
125 class TGVSlider : public TGSlider {
126 
127 protected:
128  Int_t fYp; // vertical slider y position in pixel coordinates
129 
130  virtual void DoRedraw();
131 
132 public:
133  TGVSlider(const TGWindow *p = 0, UInt_t h = 40,
134  UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
135  UInt_t options = kVerticalFrame,
137  virtual ~TGVSlider();
138 
139  virtual Bool_t HandleButton(Event_t *event);
140  virtual Bool_t HandleConfigureNotify(Event_t* event);
141  virtual Bool_t HandleMotion(Event_t *event);
142  virtual TGDimension GetDefaultSize() const
143  { return TGDimension(kSliderWidth, fHeight); }
144  virtual void Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w, h ? h+16 : fHeight + 16); }
145  virtual void Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
146  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
147 
148  ClassDef(TGVSlider,0) // Vertical slider widget
149 };
150 
151 
152 class TGHSlider : public TGSlider {
153 
154 protected:
155  Int_t fXp; // horizontal slider x position in pixel coordinates
156 
157  virtual void DoRedraw();
158 
159 public:
160  TGHSlider(const TGWindow *p = 0, UInt_t w = 40,
161  UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
162  UInt_t options = kHorizontalFrame,
164  virtual ~TGHSlider();
165 
166  virtual Bool_t HandleButton(Event_t *event);
167  virtual Bool_t HandleConfigureNotify(Event_t* event);
168  virtual Bool_t HandleMotion(Event_t *event);
169  virtual TGDimension GetDefaultSize() const
170  { return TGDimension(fWidth, kSliderHeight); }
171  virtual void Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w ? w+16 : fWidth + 16, h); }
172  virtual void Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
173  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
174 
175  ClassDef(TGHSlider,0) // Horizontal slider widget
176 };
177 
178 #endif
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:142
virtual void Pressed()
Definition: TGSlider.h:118
virtual Int_t GetPosition() const
Definition: TGSlider.h:107
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:105
const char Option_t
Definition: RtypesCore.h:62
TGSlider & operator=(const TGSlider &)
#define BIT(n)
Definition: Rtypes.h:120
TH1 * h
Definition: legend2.C:5
virtual void MapSubwindows()
Definition: TGWindow.h:91
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
Definition: TGSlider.cxx:112
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:172
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
TGSlider(const TGSlider &)
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t HandleConfigureNotify(Event_t *event)=0
This event is generated when the frame is resized.
Int_t fYp
Definition: TGSlider.h:128
virtual void DoRedraw()
Redraw the frame.
Definition: TGFrame.cxx:412
const TGPicture * fDisabledPic
Definition: TGSlider.h:81
#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
TString GetTypeString() const
Returns the slider type as a string - used in SavePrimitive().
Definition: TGSlider.cxx:510
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:306
virtual Bool_t HandleButton(Event_t *event)=0
UInt_t fHeight
Definition: TGDimension.h:32
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:561
virtual void ChangeSliderPic(const char *name)
Definition: TGSlider.h:112
UInt_t fWidth
Definition: TGDimension.h:31
Int_t fPos
Definition: TGSlider.h:73
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:145
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
Int_t fXp
Definition: TGSlider.h:155
virtual void Released()
Definition: TGSlider.h:119
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:169
virtual Int_t GetMaxPosition() const
Definition: TGSlider.h:109
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual ~TGSlider()
Definition: TGSlider.h:96
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:106
Int_t fType
Definition: TGSlider.h:77
UInt_t fWidth
Definition: TGFrame.h:150
virtual void SetScale(Int_t scale)
Definition: TGSlider.h:104
Int_t fRelPos
Definition: TGSlider.h:74
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:171
virtual void PositionChanged(Int_t pos)
Definition: TGSlider.h:117
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:287
int type
Definition: TGX11.cxx:120
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:102
virtual Int_t GetMinPosition() const
Definition: TGSlider.h:108
UInt_t fHeight
Definition: TGFrame.h:151
virtual Bool_t HandleMotion(Event_t *event)=0
Int_t fVmin
Definition: TGSlider.h:75
Bool_t fDragging
Definition: TGSlider.h:79
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:144
TGClient * fClient
Definition: TGObject.h:41
virtual void CreateDisabledPicture()
Creates disabled picture.
Definition: TGSlider.cxx:83
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:370
ESliderType
Definition: TGSlider.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual Int_t GetScale() const
Definition: TGSlider.h:110
Int_t fVmax
Definition: TGSlider.h:76
ESliderSize
Definition: TGSlider.h:52
virtual void MapSubwindows()
Definition: TGSlider.h:111
char name[80]
Definition: TGX11.cxx:109
Int_t fScale
Definition: TGSlider.h:78
const TGPicture * fSliderPic
Definition: TGSlider.h:80