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