Logo ROOT   6.18/05
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#include "TGFrame.h"
43#include "TGWidget.h"
44
45
46//--- sizes for vert. and horz. sliders
47
51};
52
53
55 //--- slider types (type of slider picture)
58
59 //--- scaling of slider
62 kScaleBoth = BIT(4)
63};
64
65
66class TGSlider : public TGFrame, public TGWidget {
67
68protected:
69 Int_t fPos; // logical position between fVmin and fVmax
70 Int_t fRelPos; // slider position in pixel coordinates
71 Int_t fVmin; // logical lower limit of slider
72 Int_t fVmax; // logical upper limit of slider
73 Int_t fType; // slider type bits
74 Int_t fScale; // tick mark scale
75 Bool_t fDragging; // true if in dragging mode
76 const TGPicture *fSliderPic; // picture to draw slider
77 const TGPicture *fDisabledPic; // picture to draw disabled slider
78
79 TString GetTypeString() const; // used in SavePrimitive
80 virtual void CreateDisabledPicture();
81
82private:
83 TGSlider(const TGSlider&); // not implemented
84 TGSlider& operator=(const TGSlider&); // not implemented
85
86public:
87 TGSlider(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
88 UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
89 UInt_t options = kChildFrame,
91
92 virtual ~TGSlider() { }
93
94 virtual Bool_t HandleButton(Event_t *event) = 0;
96 virtual Bool_t HandleMotion(Event_t *event) = 0;
97
98 virtual void SetEnabled(Bool_t flag = kTRUE) { SetState( flag ); } //*TOGGLE* *GETTER=IsEnabled
99 virtual void SetState(Bool_t state);
100 virtual void SetScale(Int_t scale) { fScale = scale; } //*MENU*
101 virtual void SetRange(Int_t min, Int_t max) {
102 if (max > min) { fVmin = min; fVmax = max; }
103 else Warning("SetRange", "Incorrect range boundaries [%d,%d]", min, max);
104 } //*MENU*
105 virtual void SetPosition(Int_t pos) {
106 if ((pos >= fVmin) && (pos <= fVmax)) { fPos = pos; fClient->NeedRedraw(this); }
107 else Warning("SetPosition", "The position (%d) is out of range [%d,%d]", pos, fVmin, fVmax);
108 } //*MENU*
109 virtual Int_t GetPosition() const { return fPos; }
110 virtual Int_t GetMinPosition() const { return fVmin; }
111 virtual Int_t GetMaxPosition() const { return fVmax; }
112 virtual Int_t GetScale() const { return fScale; }
114 virtual void ChangeSliderPic(const char *name) {
117 }
118
119 virtual void PositionChanged(Int_t pos) { Emit("PositionChanged(Int_t)", pos); } // *SIGNAL*
120 virtual void Pressed() { Emit("Pressed()"); } // *SIGNAL*
121 virtual void Released() { Emit("Released()"); } // *SIGNAL*
122
123 ClassDef(TGSlider,0) // Slider widget abstract base class
124};
125
126
127class TGVSlider : public TGSlider {
128
129protected:
130 Int_t fYp; // vertical slider y position in pixel coordinates
131
132 virtual void DoRedraw();
133
134public:
135 TGVSlider(const TGWindow *p = 0, UInt_t h = 40,
136 UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
137 UInt_t options = kVerticalFrame,
139 virtual ~TGVSlider();
140
141 virtual Bool_t HandleButton(Event_t *event);
142 virtual Bool_t HandleConfigureNotify(Event_t* event);
143 virtual Bool_t HandleMotion(Event_t *event);
145 { return TGDimension(kSliderWidth, fHeight); }
146 virtual void Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w, h ? h+16 : fHeight + 16); }
147 virtual void Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
148 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
149
150 ClassDef(TGVSlider,0) // Vertical slider widget
151};
152
153
154class TGHSlider : public TGSlider {
155
156protected:
157 Int_t fXp; // horizontal slider x position in pixel coordinates
158
159 virtual void DoRedraw();
160
161public:
162 TGHSlider(const TGWindow *p = 0, UInt_t w = 40,
163 UInt_t type = kSlider1 | kScaleBoth, Int_t id = -1,
164 UInt_t options = kHorizontalFrame,
166 virtual ~TGHSlider();
167
168 virtual Bool_t HandleButton(Event_t *event);
169 virtual Bool_t HandleConfigureNotify(Event_t* event);
170 virtual Bool_t HandleMotion(Event_t *event);
172 { return TGDimension(fWidth, kSliderHeight); }
173 virtual void Resize(UInt_t w, UInt_t h) { TGFrame::Resize(w ? w+16 : fWidth + 16, h); }
174 virtual void Resize(TGDimension size) { Resize(size.fWidth, size.fHeight); }
175 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
176
177 ClassDef(TGHSlider,0) // Horizontal slider widget
178};
179
180#endif
ULong_t Pixel_t
Definition: GuiTypes.h:39
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
#define BIT(n)
Definition: Rtypes.h:83
@ kChildFrame
Definition: TGFrame.h:57
@ kVerticalFrame
Definition: TGFrame.h:59
@ kHorizontalFrame
Definition: TGFrame.h:60
ESliderSize
Definition: TGSlider.h:48
@ kSliderWidth
Definition: TGSlider.h:49
@ kSliderHeight
Definition: TGSlider.h:50
ESliderType
Definition: TGSlider.h:54
@ kScaleNo
Definition: TGSlider.h:60
@ kScaleBoth
Definition: TGSlider.h:62
@ kSlider2
Definition: TGSlider.h:57
@ kSlider1
Definition: TGSlider.h:56
@ kScaleDownRight
Definition: TGSlider.h:61
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
const TGPicture * GetPicture(const char *name)
Get picture from the picture pool.
Definition: TGClient.cxx:289
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
void FreePicture(const TGPicture *pic)
Free picture resource.
Definition: TGClient.cxx:308
UInt_t fHeight
Definition: TGDimension.h:30
UInt_t fWidth
Definition: TGDimension.h:29
UInt_t fHeight
Definition: TGFrame.h:135
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition: TGFrame.cxx:665
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
UInt_t fWidth
Definition: TGFrame.h:134
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:171
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:174
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:173
virtual void DoRedraw()
Redraw horizontal slider widget.
Definition: TGSlider.cxx:360
TGHSlider(const TGWindow *p=0, UInt_t w=40, UInt_t type=kSlider1|kScaleBoth, Int_t id=-1, UInt_t options=kHorizontalFrame, Pixel_t back=GetDefaultFrameBackground())
Create horizontal slider widget.
Definition: TGSlider.cxx:320
virtual ~TGHSlider()
Delete a horizontal slider widget.
Definition: TGSlider.cxx:351
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save an horizontal slider as a C++ statement(s) on output stream out.
Definition: TGSlider.cxx:542
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in horizontal slide widget.
Definition: TGSlider.cxx:476
Int_t fXp
Definition: TGSlider.h:157
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in horizontal slider widget.
Definition: TGSlider.cxx:402
virtual Bool_t HandleConfigureNotify(Event_t *event)
Handles resize events for this widget.
Definition: TGSlider.cxx:500
TGClient * fClient
Definition: TGObject.h:37
Int_t fPos
Definition: TGSlider.h:69
Int_t fRelPos
Definition: TGSlider.h:70
virtual Int_t GetMaxPosition() const
Definition: TGSlider.h:111
virtual void CreateDisabledPicture()
Creates disabled picture.
Definition: TGSlider.cxx:83
virtual void Released()
Definition: TGSlider.h:121
TGSlider & operator=(const TGSlider &)
virtual void Pressed()
Definition: TGSlider.h:120
virtual void ChangeSliderPic(const char *name)
Definition: TGSlider.h:114
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
const TGPicture * fSliderPic
Definition: TGSlider.h:76
virtual void MapSubwindows()
Definition: TGSlider.h:113
virtual Int_t GetMinPosition() const
Definition: TGSlider.h:110
virtual Bool_t HandleButton(Event_t *event)=0
TGSlider(const TGSlider &)
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
Int_t fVmin
Definition: TGSlider.h:71
Int_t fType
Definition: TGSlider.h:73
TString GetTypeString() const
Returns the slider type as a string - used in SavePrimitive().
Definition: TGSlider.cxx:510
virtual ~TGSlider()
Definition: TGSlider.h:92
virtual Int_t GetScale() const
Definition: TGSlider.h:112
Bool_t fDragging
Definition: TGSlider.h:75
virtual Bool_t HandleMotion(Event_t *event)=0
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
Int_t fScale
Definition: TGSlider.h:74
virtual void SetEnabled(Bool_t flag=kTRUE)
Definition: TGSlider.h:98
const TGPicture * fDisabledPic
Definition: TGSlider.h:77
virtual void PositionChanged(Int_t pos)
Definition: TGSlider.h:119
virtual Bool_t HandleConfigureNotify(Event_t *event)=0
This event is generated when the frame is resized.
Int_t fVmax
Definition: TGSlider.h:72
virtual void SetState(Bool_t state)
Set state of widget. If kTRUE=enabled, kFALSE=disabled.
Definition: TGSlider.cxx:112
virtual void SetScale(Int_t scale)
Definition: TGSlider.h:100
virtual void Resize(UInt_t w, UInt_t h)
Resize the frame.
Definition: TGSlider.h:146
virtual Bool_t HandleConfigureNotify(Event_t *event)
Handles resize events for this widget.
Definition: TGSlider.cxx:310
TGVSlider(const TGWindow *p=0, UInt_t h=40, UInt_t type=kSlider1|kScaleBoth, Int_t id=-1, UInt_t options=kVerticalFrame, Pixel_t back=GetDefaultFrameBackground())
Create a vertical slider widget.
Definition: TGSlider.cxx:125
virtual ~TGVSlider()
Delete vertical slider widget.
Definition: TGSlider.cxx:156
virtual void DoRedraw()
Redraw vertical slider widget.
Definition: TGSlider.cxx:165
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save an horizontal slider as a C++ statement(s) on output stream out.
Definition: TGSlider.cxx:579
Int_t fYp
Definition: TGSlider.h:130
virtual void Resize(TGDimension size)
Resize the frame.
Definition: TGSlider.h:147
virtual Bool_t HandleMotion(Event_t *event)
Handle mouse motion event in vertical slider.
Definition: TGSlider.cxx:286
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button event in vertical slider.
Definition: TGSlider.cxx:208
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGSlider.h:144
virtual void MapSubwindows()
Definition: TGWindow.h:89
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
Basic string class.
Definition: TString.h:131