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