Logo ROOT  
Reference Guide
TSliderBox.cxx
Go to the documentation of this file.
1// @(#)root/gpad:$Id$
2// Author: Rene Brun 23/11/96
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#include "Riostream.h"
13#include "TROOT.h"
14#include "TSlider.h"
15#include "TSliderBox.h"
16#include "TVirtualX.h"
17
18#include <string.h>
19
21
22
23/** \class TSliderBox
24\ingroup gpad
25
26The moving box in a TSlider
27*/
28
29////////////////////////////////////////////////////////////////////////////////
30/// SliderBox default constructor.
31
33{
34 fSlider = 0;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// SliderBox normal constructor.
39
41 :TWbox(x1,y1,x2,y2,color,bordersize,bordermode)
42{
43 fSlider = 0;
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// SliderBox default destructor.
48
50{
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Interaction with a slider.
55
57{
58 if (!gPad) return;
59
60 const Int_t kMaxDiff = 5;
61 const Int_t kMinSize = 20;
62
63 static Int_t px1, px2, py1, py2, pxl, pyl, pxt, pyt, pxold, pyold;
64 static Int_t px1p, px2p, py1p, py2p;
65 static Bool_t pL, pR, pTop, pBot, pINSIDE;
66 Int_t wx, wy;
67 Bool_t doing_again = kFALSE;
68 Bool_t opaque = gPad->OpaqueMoving();
69 Bool_t ropaque = gPad->OpaqueResizing();
70
71 TVirtualPad *parent = gPad;
72
73 Int_t border = parent->GetBorderSize();
74 Int_t pxpadmin = parent->XtoAbsPixel(parent->GetX1()) + border;
75 Int_t pxpadmax = parent->XtoAbsPixel(parent->GetX2()) - border;
76 Int_t pypadmin = parent->YtoAbsPixel(parent->GetY1()) - border;
77 Int_t pypadmax = parent->YtoAbsPixel(parent->GetY2()) + border;
78
79 Bool_t vertical = kTRUE;
80 if (pxpadmax-pxpadmin > pypadmin-pypadmax) vertical = kFALSE;
81
82again:
83
84 switch (event) {
85
86 case kButton1Down:
87
88 gVirtualX->SetLineColor(-1);
89 TAttLine::Modify(); //Change line attributes only if necessary
90 if (GetFillColor())
91 gVirtualX->SetLineColor(GetFillColor());
92 else
93 gVirtualX->SetLineColor(1);
94 gVirtualX->SetLineWidth(2);
95
96 // No break !!!
97
98 case kMouseMotion:
99
100 px1 = gPad->XtoAbsPixel(GetX1());
101 py1 = gPad->YtoAbsPixel(GetY1());
102 px2 = gPad->XtoAbsPixel(GetX2());
103 py2 = gPad->YtoAbsPixel(GetY2());
104
105 if (px1 < px2) {
106 pxl = px1;
107 pxt = px2;
108 } else {
109 pxl = px2;
110 pxt = px1;
111 }
112 if (py1 < py2) {
113 pyl = py1;
114 pyt = py2;
115 } else {
116 pyl = py2;
117 pyt = py1;
118 }
119
120 px1p = pxpadmin;
121 py1p = pypadmin;
122 px2p = pxpadmax;
123 py2p = pypadmax;
124
125 pL = pR = pTop = pBot = pINSIDE = kFALSE;
126
127 if (vertical && (px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
128 TMath::Abs(py - pyl) < kMaxDiff) { // top edge
129 pxold = pxl; pyold = pyl; pTop = kTRUE;
130 gPad->SetCursor(kTopSide);
131 }
132
133 if (vertical && (px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
134 TMath::Abs(py - pyt) < kMaxDiff) { // bottom edge
135 pxold = pxt; pyold = pyt; pBot = kTRUE;
136 gPad->SetCursor(kBottomSide);
137 }
138
139 if (!vertical && (py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
140 TMath::Abs(px - pxl) < kMaxDiff) { // left edge
141 pxold = pxl; pyold = pyl; pL = kTRUE;
142 gPad->SetCursor(kLeftSide);
143 }
144
145 if (!vertical && (py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
146 TMath::Abs(px - pxt) < kMaxDiff) { // right edge
147 pxold = pxt; pyold = pyt; pR = kTRUE;
148 gPad->SetCursor(kRightSide);
149 }
150
151 if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
152 (py > pyl+kMaxDiff && py < pyt-kMaxDiff)) { // inside box
153 pxold = px; pyold = py; pINSIDE = kTRUE;
154 if (event == kButton1Down)
155 gPad->SetCursor(kMove);
156 else
157 gPad->SetCursor(kCross);
158 }
159
161 if ( pL || pR || pTop || pBot)
163
164 if ( !pL && !pR && !pTop && !pBot && !pINSIDE)
165 gPad->SetCursor(kCross);
166
167 break;
168
169 case kButton1Motion:
170
171 wx = wy = 0;
172
173 if (pTop) {
174 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
175 py2 += py - pyold;
176 if (py2 > py1-kMinSize) { py2 = py1-kMinSize; wy = py2; }
177 if (py2 < py2p) { py2 = py2p; wy = py2; }
178 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
179 }
180 if (pBot) {
181 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
182 py1 += py - pyold;
183 if (py1 < py2+kMinSize) { py1 = py2+kMinSize; wy = py1; }
184 if (py1 > py1p) { py1 = py1p; wy = py1; }
185 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
186 }
187 if (pL) {
188 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
189 px1 += px - pxold;
190 if (px1 > px2-kMinSize) { px1 = px2-kMinSize; wx = px1; }
191 if (px1 < px1p) { px1 = px1p; wx = px1; }
192 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
193 }
194 if (pR) {
195 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
196 px2 += px - pxold;
197 if (px2 < px1+kMinSize) { px2 = px1+kMinSize; wx = px2; }
198 if (px2 > px2p) { px2 = px2p; wx = px2; }
199 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
200 }
201 if (pINSIDE) {
202 if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the old box
203 Int_t dx = px - pxold;
204 Int_t dy = py - pyold;
205 px1 += dx; py1 += dy; px2 += dx; py2 += dy;
206 if (px1 < px1p) { dx = px1p - px1; px1 += dx; px2 += dx; wx = px+dx; }
207 if (px2 > px2p) { dx = px2 - px2p; px1 -= dx; px2 -= dx; wx = px-dx; }
208 if (py1 > py1p) { dy = py1 - py1p; py1 -= dy; py2 -= dy; wy = py-dy; }
209 if (py2 < py2p) { dy = py2p - py2; py1 += dy; py2 += dy; wy = py+dy; }
210 if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the new box
211 }
212
213 if (wx || wy) {
214 if (wx) px = wx;
215 if (wy) py = wy;
216 gVirtualX->Warp(px, py);
217 }
218
219 pxold = px;
220 pyold = py;
221
222 if ((pINSIDE && opaque) || (fResizing && ropaque)) {
223 event = kButton1Up;
224 doing_again = kTRUE;
225 goto again;
226 }
227
228 break;
229
230 case kButton1Up:
231
232 if (pTop || pBot || pL || pR || pINSIDE) {
233 fX1 = gPad->AbsPixeltoX(px1);
234 fY1 = gPad->AbsPixeltoY(py1);
235 fX2 = gPad->AbsPixeltoX(px2);
236 fY2 = gPad->AbsPixeltoY(py2);
237 }
238
239 if (pINSIDE) {
240 // if it was not a pad that was moved then it must have been
241 // a box or something like that so we have to redraw the pad
242 if (parent == gPad) gPad->Modified(kTRUE);
243 if (!doing_again) gPad->SetCursor(kCross);
244 }
245
246 if (pTop || pBot || pL || pR )
247 gPad->Modified(kTRUE);
248
249 // Restore original event type
250 if (doing_again)
251 event = kButton1Motion;
252 else {
253 gVirtualX->SetLineColor(-1);
254 gVirtualX->SetLineWidth(-1);
255 }
256
257 break;
258 }
259
260
261 // Give control to object using the slider
262
263 Float_t xpmin,xpmax;
264 if (vertical) {
265 xpmin = Float_t(pypadmin-py1)/Float_t(pypadmin-pypadmax);
266 xpmax = Float_t(pypadmin-py2)/Float_t(pypadmin-pypadmax);
267 } else { //vertical slider
268 xpmin = Float_t(px1-pxpadmin)/Float_t(pxpadmax-pxpadmin);
269 xpmax = Float_t(px2-pxpadmin)/Float_t(pxpadmax-pxpadmin);
270 }
271 fSlider->SetMinimum(xpmin);
272 fSlider->SetMaximum(xpmax);
273
274 //A user method to execute?
275 Int_t lenMethod = strlen(fSlider->GetMethod());
276 if (event == kButton1Up && lenMethod > 0 ) {
277 gPad->SetCursor(kWatch);
278 gROOT->ProcessLine(fSlider->GetMethod());
279 return;
280 }
281
282 //An object connected to this slider?
283 TObject *obj = fSlider->GetObject();
284 if (obj) {
285 obj->ExecuteEvent(event,0,0);
286 }
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Save primitive as a C++ statement(s) on output stream out
291
292void TSliderBox::SavePrimitive(std::ostream &, Option_t * /*= ""*/)
293{
294}
@ kMouseMotion
Definition: Buttons.h:23
@ kButton1Motion
Definition: Buttons.h:20
@ kButton1Up
Definition: Buttons.h:19
@ kButton1Down
Definition: Buttons.h:17
@ kRightSide
Definition: GuiTypes.h:372
@ kBottomSide
Definition: GuiTypes.h:372
@ kTopSide
Definition: GuiTypes.h:372
@ kLeftSide
Definition: GuiTypes.h:372
@ kWatch
Definition: GuiTypes.h:374
@ kMove
Definition: GuiTypes.h:373
@ kCross
Definition: GuiTypes.h:373
static const double x2[5]
static const double x1[5]
const Bool_t kFALSE
Definition: RtypesCore.h:90
short Short_t
Definition: RtypesCore.h:37
double Double_t
Definition: RtypesCore.h:57
short Color_t
Definition: RtypesCore.h:81
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
#define gROOT
Definition: TROOT.h:406
#define gPad
Definition: TVirtualPad.h:287
#define gVirtualX
Definition: TVirtualX.h:338
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
virtual void Modify()
Change current line attributes if necessary.
Definition: TAttLine.cxx:242
Double_t GetX1() const
Definition: TBox.h:52
Double_t fX1
X of 1st point.
Definition: TBox.h:30
Double_t GetX2() const
Definition: TBox.h:53
Double_t GetY1() const
Definition: TBox.h:54
Double_t GetY2() const
Definition: TBox.h:55
Double_t fY2
Y of 2nd point.
Definition: TBox.h:33
Double_t fX2
X of 2nd point.
Definition: TBox.h:32
Double_t fY1
Y of 1st point.
Definition: TBox.h:31
Bool_t fResizing
! True if box is being resized
Definition: TBox.h:34
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to an event at (px,py).
Definition: TObject.cxx:311
The moving box in a TSlider.
Definition: TSliderBox.h:20
virtual ~TSliderBox()
SliderBox default destructor.
Definition: TSliderBox.cxx:49
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Interaction with a slider.
Definition: TSliderBox.cxx:56
TSlider * fSlider
Pointer to slider.
Definition: TSliderBox.h:23
TSliderBox()
SliderBox default constructor.
Definition: TSliderBox.cxx:32
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TSliderBox.cxx:292
virtual const char * GetMethod() const
Definition: TSlider.h:37
virtual void SetMaximum(Double_t max=1)
Definition: TSlider.h:43
TObject * GetObject() const
Definition: TSlider.h:34
virtual void SetMinimum(Double_t min=0)
Definition: TSlider.h:42
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:51
virtual Int_t YtoAbsPixel(Double_t y) const =0
virtual Double_t GetX2() const =0
virtual Int_t XtoAbsPixel(Double_t x) const =0
virtual Double_t GetY1() const =0
virtual Double_t GetY2() const =0
virtual Short_t GetBorderSize() const =0
virtual Double_t GetX1() const =0
A TBox with a bordersize and a bordermode.
Definition: TWbox.h:20
Short_t Abs(Short_t d)
Definition: TMathBase.h:120