Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBox.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 12/12/94
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 <stdlib.h>
13
14#include <iostream>
15#include "TROOT.h"
16#include "TBuffer.h"
17#include "TBox.h"
18#include "TVirtualPad.h"
19#include "TVirtualX.h"
20#include "TClass.h"
21#include "TMath.h"
22#include "TPoint.h"
23
25
26/** \class TBox
27\ingroup BasicGraphics
28
29Create a Box.
30
31A box is defined by :
32
33- Its bottom left coordinates x1,y1
34- Its top right coordinates x2,y2
35
36A box has line attributes (see TAttLine) and fill area attributes (see TAttFill).
37*/
38
39////////////////////////////////////////////////////////////////////////////////
40/// Box default constructor.
41
43{
44 fTip = 0;
45 fX1 = 0.;
46 fY1 = 0.;
47 fX2 = 0.;
48 fY2 = 0.;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Box standard constructor.
54
56 : TObject(), TAttLine(), TAttFill()
57{
58 if (x2 >= x1) {fX1 =x1; fX2 = x2;}
59 else {fX1 = x2; fX2 = x1;}
60 if (y2 >= y1) {fY1 =y1; fY2 = y2;}
61 else {fY1 = y2; fY2 = y1;}
63 fTip = 0;
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Box destructor.
68
70{
71 if (fTip && gPad) {
72 gPad->CloseToolTip(fTip);
73 gPad->DeleteToolTip(fTip);
74 }
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Box copy constructor.
79
81{
82 fX1 = 0.;
83 fY1 = 0.;
84 fX2 = 0.;
85 fY2 = 0.;
87 ((TBox&)box).TBox::Copy(*this);
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Assignment operator.
92
94{
95 if(this!=&b) {
97 TAttLine::operator=(b);
98 TAttFill::operator=(b);
99 fTip=b.fTip;
100 fX1=b.fX1;
101 fY1=b.fY1;
102 fX2=b.fX2;
103 fY2=b.fY2;
104 fResizing=b.fResizing;
105 }
106 return *this;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Copy a Box.
111
112void TBox::Copy(TObject &obj) const
113{
114 TObject::Copy(obj);
115 TAttLine::Copy(((TBox&)obj));
116 TAttFill::Copy(((TBox&)obj));
117 ((TBox&)obj).fX1 = fX1;
118 ((TBox&)obj).fY1 = fY1;
119 ((TBox&)obj).fX2 = fX2;
120 ((TBox&)obj).fY2 = fY2;
121 ((TBox&)obj).fResizing = fResizing;
122 ((TBox&)obj).fTip = 0; //FIXME
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Compute distance from point px,py to a box.
127///
128/// Compute the closest distance of approach from point px,py to the
129/// edges of this box.
130/// The distance is computed in pixels units.
131///
132/// In case of a filled box the distance returned is 0 if the point
133/// (px,py) is inside the box, and is huge if the point is outside.
134
136{
137 Int_t pxl, pyl, pxt, pyt;
138 Int_t px1 = gPad->XtoAbsPixel(fX1);
139 Int_t py1 = gPad->YtoAbsPixel(fY1);
140 Int_t px2 = gPad->XtoAbsPixel(fX2);
141 Int_t py2 = gPad->YtoAbsPixel(fY2);
142
143 Bool_t isBox = !(InheritsFrom("TPave") || InheritsFrom("TWbox"));
144
145 if (isBox) {
146 if (gPad->GetLogx()) {
147 if (fX1>0) px1 = gPad->XtoAbsPixel(TMath::Log10(fX1));
148 if (fX2>0) px2 = gPad->XtoAbsPixel(TMath::Log10(fX2));
149 }
150 if (gPad->GetLogy()) {
151 if (fY1>0) py1 = gPad->YtoAbsPixel(TMath::Log10(fY1));
152 if (fY2>0) py2 = gPad->YtoAbsPixel(TMath::Log10(fY2));
153 }
154 }
155
156 if (px1 < px2) {pxl = px1; pxt = px2;}
157 else {pxl = px2; pxt = px1;}
158 if (py1 < py2) {pyl = py1; pyt = py2;}
159 else {pyl = py2; pyt = py1;}
160
161 // Are we inside the box?
162 if (GetFillStyle()) {
163 if ( (px >= pxl && px <= pxt) && (py >= pyl && py <= pyt) ) return 0;
164 else return 9999;
165 }
166
167 // Are we on the edges?
168 Int_t dxl = TMath::Abs(px - pxl);
169 if (py < pyl) dxl += pyl - py;
170 if (py > pyt) dxl += py - pyt;
171 Int_t dxt = TMath::Abs(px - pxt);
172 if (py < pyl) dxt += pyl - py;
173 if (py > pyt) dxt += py - pyt;
174 Int_t dyl = TMath::Abs(py - pyl);
175 if (px < pxl) dyl += pxl - px;
176 if (px > pxt) dyl += px - pxt;
177 Int_t dyt = TMath::Abs(py - pyt);
178 if (px < pxl) dyt += pxl - px;
179 if (px > pxt) dyt += px - pxt;
180
181 Int_t distance = dxl;
182 if (dxt < distance) distance = dxt;
183 if (dyl < distance) distance = dyl;
184 if (dyt < distance) distance = dyt;
185
186 return distance - Int_t(0.5*fLineWidth);
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Draw this box with its current attributes.
191/// if the box has no fill style (ie fill style=0), the box contour is drawn
192/// if the box has a fill style, the box contour is not drawn by default.
193/// to force the contour to be drawn, specify option "l"
194
195void TBox::Draw(Option_t *option)
196{
197 AppendPad(option);
198
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Draw this box with new coordinates.
203
205{
206 TBox *newbox = new TBox(x1,y1,x2,y2);
207 TAttLine::Copy(*newbox);
208 TAttFill::Copy(*newbox);
209 newbox->SetBit(kCanDelete);
210 newbox->AppendPad();
211 return newbox;
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// Execute action corresponding to one event.
216///
217/// This member function is called when a BOX/WBOX/PAD object is clicked.
218///
219/// If the mouse is clicked in one of the 4 corners of the box (pA,pB,pC,pD)
220/// the box is resized with the rubber rectangle.
221///
222/// If the mouse is clicked inside the box, the box is moved.
223///
224/// If the mouse is clicked on the 4 edges (pL,pR,pTop,pBot), the box is
225/// rescaled parallel to this edge (same as Motif window manager).
226///
227/// Note that this function is duplicated on purpose by TPad::ExecuteEvent.
228/// If somebody modifies this function, may be similar changes should also
229/// be applied to TPad::ExecuteEvent.
230
232{
233 if (!gPad) return;
234 if (!gPad->IsEditable() && event != kMouseEnter) return;
235
236 if (TestBit(kCannotMove)) return;
237
238 Bool_t isBox = !(InheritsFrom("TPave") || InheritsFrom("TWbox"));
239
240 const Int_t kMaxDiff = 7;
241 const Int_t kMinSize = 20;
242
243 static Int_t px1, px2, py1, py2, pxl, pyl, pxt, pyt, pxold, pyold;
244 static Int_t px1p, px2p, py1p, py2p, pxlp, pylp, pxtp, pytp;
245 static Double_t oldX1, oldY1, oldX2, oldY2;
246 static Bool_t pA, pB, pC, pD, pTop, pL, pR, pBot, pINSIDE;
247 Int_t wx, wy;
248 TVirtualPad *parent = gPad;
249 Bool_t opaque = gPad->OpaqueMoving();
250 Bool_t ropaque = gPad->OpaqueResizing();
251
252 HideToolTip(event);
253
254 switch (event) {
255
256 case kMouseEnter:
257 if (fTip) gPad->ResetToolTip(fTip);
258 break;
259
260 case kButton1Double:
261 px1 = -1; //used by kButton1Up
262 break;
263
264 case kArrowKeyPress:
265 case kButton1Down:
266
267 oldX1 = fX1;
268 oldY1 = fY1;
269 oldX2 = fX2;
270 oldY2 = fY2;
271 gVirtualX->SetLineColor(-1);
272 TAttLine::Modify(); //Change line attributes only if necessary
273 if (GetFillColor())
274 gVirtualX->SetLineColor(GetFillColor());
275 else
276 gVirtualX->SetLineColor(1);
277 gVirtualX->SetLineWidth(2);
278
279 // No break !!!
280
281 case kMouseMotion:
282
283 px1 = gPad->XtoAbsPixel(GetX1());
284 py1 = gPad->YtoAbsPixel(GetY1());
285 px2 = gPad->XtoAbsPixel(GetX2());
286 py2 = gPad->YtoAbsPixel(GetY2());
287
288 if (isBox) {
289 if (gPad->GetLogx()) {
290 if (fX1>0) px1 = gPad->XtoAbsPixel(TMath::Log10(fX1));
291 if (fX2>0) px2 = gPad->XtoAbsPixel(TMath::Log10(fX2));
292 }
293 if (gPad->GetLogy()) {
294 if (fY1>0) py1 = gPad->YtoAbsPixel(TMath::Log10(fY1));
295 if (fY2>0) py2 = gPad->YtoAbsPixel(TMath::Log10(fY2));
296 }
297 }
298
299 if (px1 < px2) {
300 pxl = px1;
301 pxt = px2;
302 } else {
303 pxl = px2;
304 pxt = px1;
305 }
306 if (py1 < py2) {
307 pyl = py1;
308 pyt = py2;
309 } else {
310 pyl = py2;
311 pyt = py1;
312 }
313
314 px1p = parent->XtoAbsPixel(parent->GetX1()) + parent->GetBorderSize();
315 py1p = parent->YtoAbsPixel(parent->GetY1()) - parent->GetBorderSize();
316 px2p = parent->XtoAbsPixel(parent->GetX2()) - parent->GetBorderSize();
317 py2p = parent->YtoAbsPixel(parent->GetY2()) + parent->GetBorderSize();
318
319 if (px1p < px2p) {
320 pxlp = px1p;
321 pxtp = px2p;
322 } else {
323 pxlp = px2p;
324 pxtp = px1p;
325 }
326 if (py1p < py2p) {
327 pylp = py1p;
328 pytp = py2p;
329 } else {
330 pylp = py2p;
331 pytp = py1p;
332 }
333
334 pA = pB = pC = pD = pTop = pL = pR = pBot = pINSIDE = kFALSE;
335
336 // case pA
337 if (TMath::Abs(px - pxl) <= kMaxDiff && TMath::Abs(py - pyl) <= kMaxDiff) {
338 pxold = pxl; pyold = pyl; pA = kTRUE;
339 gPad->SetCursor(kTopLeft);
340 }
341 // case pB
342 if (TMath::Abs(px - pxt) <= kMaxDiff && TMath::Abs(py - pyl) <= kMaxDiff) {
343 pxold = pxt; pyold = pyl; pB = kTRUE;
344 gPad->SetCursor(kTopRight);
345 }
346 // case pC
347 if (TMath::Abs(px - pxt) <= kMaxDiff && TMath::Abs(py - pyt) <= kMaxDiff) {
348 pxold = pxt; pyold = pyt; pC = kTRUE;
349 gPad->SetCursor(kBottomRight);
350 }
351 // case pD
352 if (TMath::Abs(px - pxl) <= kMaxDiff && TMath::Abs(py - pyt) <= kMaxDiff) {
353 pxold = pxl; pyold = pyt; pD = kTRUE;
354 gPad->SetCursor(kBottomLeft);
355 }
356
357 if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
358 TMath::Abs(py - pyl) < kMaxDiff) { // top edge
359 pxold = pxl; pyold = pyl; pTop = kTRUE;
360 gPad->SetCursor(kTopSide);
361 }
362
363 if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
364 TMath::Abs(py - pyt) < kMaxDiff) { // bottom edge
365 pxold = pxt; pyold = pyt; pBot = kTRUE;
366 gPad->SetCursor(kBottomSide);
367 }
368
369 if ((py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
370 TMath::Abs(px - pxl) < kMaxDiff) { // left edge
371 pxold = pxl; pyold = pyl; pL = kTRUE;
372 gPad->SetCursor(kLeftSide);
373 }
374
375 if ((py > pyl+kMaxDiff && py < pyt-kMaxDiff) &&
376 TMath::Abs(px - pxt) < kMaxDiff) { // right edge
377 pxold = pxt; pyold = pyt; pR = kTRUE;
378 gPad->SetCursor(kRightSide);
379 }
380
381 if ((px > pxl+kMaxDiff && px < pxt-kMaxDiff) &&
382 (py > pyl+kMaxDiff && py < pyt-kMaxDiff)) { // inside box
383 pxold = px; pyold = py; pINSIDE = kTRUE;
384 if (event == kButton1Down)
385 gPad->SetCursor(kMove);
386 else
387 gPad->SetCursor(kCross);
388 }
389
391 if (pA || pB || pC || pD || pTop || pL || pR || pBot)
393
394 if (!pA && !pB && !pC && !pD && !pTop && !pL && !pR && !pBot && !pINSIDE)
395 gPad->SetCursor(kCross);
396
397 break;
398
399 case kArrowKeyRelease:
400 case kButton1Motion:
401
402 wx = wy = 0;
403
404 if (pA) {
405 if (!ropaque) gVirtualX->DrawBox(pxold, pyt, pxt, pyold, TVirtualX::kHollow); // draw the old box
406 if (px > pxt-kMinSize) { px = pxt-kMinSize; wx = px; }
407 if (py > pyt-kMinSize) { py = pyt-kMinSize; wy = py; }
408 if (px < pxlp) { px = pxlp; wx = px; }
409 if (py < pylp) { py = pylp; wy = py; }
410 if (!ropaque) gVirtualX->DrawBox(px , pyt, pxt, py, TVirtualX::kHollow); // draw the new box
411 }
412 if (pB) {
413 if (!ropaque) gVirtualX->DrawBox(pxl , pyt, pxold, pyold, TVirtualX::kHollow);
414 if (px < pxl+kMinSize) { px = pxl+kMinSize; wx = px; }
415 if (py > pyt-kMinSize) { py = pyt-kMinSize; wy = py; }
416 if (px > pxtp) { px = pxtp; wx = px; }
417 if (py < pylp) { py = pylp; wy = py; }
418 if (!ropaque) gVirtualX->DrawBox(pxl , pyt, px , py, TVirtualX::kHollow);
419 }
420 if (pC) {
421 if (!ropaque) gVirtualX->DrawBox(pxl , pyl, pxold, pyold, TVirtualX::kHollow);
422 if (px < pxl+kMinSize) { px = pxl+kMinSize; wx = px; }
423 if (py < pyl+kMinSize) { py = pyl+kMinSize; wy = py; }
424 if (px > pxtp) { px = pxtp; wx = px; }
425 if (py > pytp) { py = pytp; wy = py; }
426 if (!ropaque) gVirtualX->DrawBox(pxl , pyl, px , py, TVirtualX::kHollow);
427 }
428 if (pD) {
429 if (!ropaque) gVirtualX->DrawBox(pxold, pyold, pxt, pyl, TVirtualX::kHollow);
430 if (px > pxt-kMinSize) { px = pxt-kMinSize; wx = px; }
431 if (py < pyl+kMinSize) { py = pyl+kMinSize; wy = py; }
432 if (px < pxlp) { px = pxlp; wx = px; }
433 if (py > pytp) { py = pytp; wy = py; }
434 if (!ropaque) gVirtualX->DrawBox(px , py , pxt, pyl, TVirtualX::kHollow);
435 }
436 if (pTop) {
437 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
438 py2 += py - pyold;
439 if (py2 > py1-kMinSize) { py2 = py1-kMinSize; wy = py2; }
440 if (py2 < py2p) { py2 = py2p; wy = py2; }
441 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
442 }
443 if (pBot) {
444 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
445 py1 += py - pyold;
446 if (py1 < py2+kMinSize) { py1 = py2+kMinSize; wy = py1; }
447 if (py1 > py1p) { py1 = py1p; wy = py1; }
448 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
449 }
450 if (pL) {
451 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
452 px1 += px - pxold;
453 if (px1 > px2-kMinSize) { px1 = px2-kMinSize; wx = px1; }
454 if (px1 < px1p) { px1 = px1p; wx = px1; }
455 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
456 }
457 if (pR) {
458 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
459 px2 += px - pxold;
460 if (px2 < px1+kMinSize) { px2 = px1+kMinSize; wx = px2; }
461 if (px2 > px2p) { px2 = px2p; wx = px2; }
462 if (!ropaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
463 }
464 if (pINSIDE) {
465 if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the old box
466 Int_t dx = px - pxold;
467 Int_t dy = py - pyold;
468 px1 += dx; py1 += dy; px2 += dx; py2 += dy;
469 if (px1 < px1p) { dx = px1p - px1; px1 += dx; px2 += dx; wx = px+dx; }
470 if (px2 > px2p) { dx = px2 - px2p; px1 -= dx; px2 -= dx; wx = px-dx; }
471 if (py1 > py1p) { dy = py1 - py1p; py1 -= dy; py2 -= dy; wy = py-dy; }
472 if (py2 < py2p) { dy = py2p - py2; py1 += dy; py2 += dy; wy = py+dy; }
473 if (!opaque) gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow); // draw the new box
474 }
475
476 if (wx || wy) {
477 if (wx) px = wx;
478 if (wy) py = wy;
479 gVirtualX->Warp(px, py);
480 }
481
482 pxold = px;
483 pyold = py;
484
485
486 if ((pINSIDE && opaque) || (fResizing && ropaque)) {
487 if (pA) {
488 fX1 = gPad->AbsPixeltoX(pxold);
489 fY1 = gPad->AbsPixeltoY(pyt);
490 fX2 = gPad->AbsPixeltoX(pxt);
491 fY2 = gPad->AbsPixeltoY(pyold);
492 }
493 if (pB) {
494 fX1 = gPad->AbsPixeltoX(pxl);
495 fY1 = gPad->AbsPixeltoY(pyt);
496 fX2 = gPad->AbsPixeltoX(pxold);
497 fY2 = gPad->AbsPixeltoY(pyold);
498 }
499 if (pC) {
500 fX1 = gPad->AbsPixeltoX(pxl);
501 fY1 = gPad->AbsPixeltoY(pyold);
502 fX2 = gPad->AbsPixeltoX(pxold);
503 fY2 = gPad->AbsPixeltoY(pyl);
504 }
505 if (pD) {
506 fX1 = gPad->AbsPixeltoX(pxold);
507 fY1 = gPad->AbsPixeltoY(pyold);
508 fX2 = gPad->AbsPixeltoX(pxt);
509 fY2 = gPad->AbsPixeltoY(pyl);
510 }
511 if (pTop || pBot || pL || pR || pINSIDE) {
512 fX1 = gPad->AbsPixeltoX(px1);
513 fY1 = gPad->AbsPixeltoY(py1);
514 fX2 = gPad->AbsPixeltoX(px2);
515 fY2 = gPad->AbsPixeltoY(py2);
516 }
517
518 if (isBox) {
519 if (gPad->GetLogx()) {
520 fX1 = TMath::Power(10,fX1);
521 fX2 = TMath::Power(10,fX2);
522 }
523 if (gPad->GetLogy()) {
524 fY1 = TMath::Power(10,fY1);
525 fY2 = TMath::Power(10,fY2);
526 }
527 }
528
529 if (pINSIDE) gPad->ShowGuidelines(this, event, 'i', true);
530 if (pTop) gPad->ShowGuidelines(this, event, 't', true);
531 if (pBot) gPad->ShowGuidelines(this, event, 'b', true);
532 if (pL) gPad->ShowGuidelines(this, event, 'l', true);
533 if (pR) gPad->ShowGuidelines(this, event, 'r', true);
534 if (pA) gPad->ShowGuidelines(this, event, '1', true);
535 if (pB) gPad->ShowGuidelines(this, event, '2', true);
536 if (pC) gPad->ShowGuidelines(this, event, '3', true);
537 if (pD) gPad->ShowGuidelines(this, event, '4', true);
538 gPad->Modified(kTRUE);
539 }
540
541 break;
542
543 case kButton1Up:
544 if (gROOT->IsEscaped()) {
545 gROOT->SetEscape(kFALSE);
546 if (opaque) {
547 this->SetX1(oldX1);
548 this->SetY1(oldY1);
549 this->SetX2(oldX2);
550 this->SetY2(oldY2);
551 gPad->Modified(kTRUE);
552 gPad->Update();
553 }
554 break;
555 }
556
557 if (opaque || ropaque) {
558 gPad->ShowGuidelines(this, event);
559 } else {
560 if (px1 < 0 ) break;
561 if (pA) {
562 fX1 = gPad->AbsPixeltoX(pxold);
563 fY1 = gPad->AbsPixeltoY(pyt);
564 fX2 = gPad->AbsPixeltoX(pxt);
565 fY2 = gPad->AbsPixeltoY(pyold);
566 }
567 if (pB) {
568 fX1 = gPad->AbsPixeltoX(pxl);
569 fY1 = gPad->AbsPixeltoY(pyt);
570 fX2 = gPad->AbsPixeltoX(pxold);
571 fY2 = gPad->AbsPixeltoY(pyold);
572 }
573 if (pC) {
574 fX1 = gPad->AbsPixeltoX(pxl);
575 fY1 = gPad->AbsPixeltoY(pyold);
576 fX2 = gPad->AbsPixeltoX(pxold);
577 fY2 = gPad->AbsPixeltoY(pyl);
578 }
579 if (pD) {
580 fX1 = gPad->AbsPixeltoX(pxold);
581 fY1 = gPad->AbsPixeltoY(pyold);
582 fX2 = gPad->AbsPixeltoX(pxt);
583 fY2 = gPad->AbsPixeltoY(pyl);
584 }
585 if (pTop || pBot || pL || pR || pINSIDE) {
586 fX1 = gPad->AbsPixeltoX(px1);
587 fY1 = gPad->AbsPixeltoY(py1);
588 fX2 = gPad->AbsPixeltoX(px2);
589 fY2 = gPad->AbsPixeltoY(py2);
590 }
591
592 if (isBox) {
593 if (gPad->GetLogx()) {
594 fX1 = TMath::Power(10,fX1);
595 fX2 = TMath::Power(10,fX2);
596 }
597 if (gPad->GetLogy()) {
598 fY1 = TMath::Power(10,fY1);
599 fY2 = TMath::Power(10,fY2);
600 }
601 }
602 if (pINSIDE) {
603 // if it was not a pad that was moved then it must have been
604 // a box or something like that so we have to redraw the pad
605 if (parent == gPad) gPad->Modified(kTRUE);
606 }
607 }
608
609 if (pA || pB || pC || pD || pTop || pL || pR || pBot) gPad->Modified(kTRUE);
610
611 if (!opaque) {
612 gVirtualX->SetLineColor(-1);
613 gVirtualX->SetLineWidth(-1);
614 }
615
616 break;
617
618 case kButton1Locate:
619
620 ExecuteEvent(kButton1Down, px, py);
621
622 while (1) {
623 px = py = 0;
624 event = gVirtualX->RequestLocator(1, 1, px, py);
625
627
628 if (event != -1) { // button is released
629 ExecuteEvent(kButton1Up, px, py);
630 return;
631 }
632 }
633 }
634}
635
636////////////////////////////////////////////////////////////////////////////////
637/// Hide tool tip depending on the event type. Typically tool tips
638/// are hidden when event is not a kMouseEnter and not a kMouseMotion
639/// event.
640
642{
643 if (event != kMouseEnter && event != kMouseMotion && fTip && gPad)
644 gPad->CloseToolTip(fTip);
645}
646
647////////////////////////////////////////////////////////////////////////////////
648/// Function which returns 1 if point x,y lies inside the box, 0 otherwise.
649
651{
652 if (x < fX1 || x > fX2) return 0;
653 if (y < fY1 || y > fY2) return 0;
654 return 1;
655}
656
657////////////////////////////////////////////////////////////////////////////////
658/// List this box with its attributes.
659
660void TBox::ls(Option_t *) const
661{
663 printf("%s X1= %f Y1=%f X2=%f Y2=%f\n",IsA()->GetName(),fX1,fY1,fX2,fY2);
664}
665
666////////////////////////////////////////////////////////////////////////////////
667/// Paint this box with its current attributes.
668
670{
671 if(gPad) PaintBox(gPad->XtoPad(fX1),gPad->YtoPad(fY1),gPad->XtoPad(fX2),gPad->YtoPad(fY2),option);
672}
673
674////////////////////////////////////////////////////////////////////////////////
675/// Draw this box with new coordinates.
676
678{
679 TAttLine::Modify(); //Change line attributes only if necessary
680 TAttFill::Modify(); //Change fill area attributes only if necessary
681
682 if (option) {
683 TString opt = option;
684 opt.ToLower();
685 if (opt.Contains("l")) gPad->PaintBox(x1,y1,x2,y2,"l");
686 else gPad->PaintBox(x1,y1,x2,y2);
687 } else {
688 gPad->PaintBox(x1,y1,x2,y2);
689 }
690}
691
692////////////////////////////////////////////////////////////////////////////////
693/// Dump this box with its attributes.
694
696{
697 printf("%s X1=%f Y1=%f X2=%f Y2=%f",IsA()->GetName(),fX1,fY1,fX2,fY2);
698 if (GetLineColor() != 1) printf(" Color=%d",GetLineColor());
699 if (GetLineStyle() != 1) printf(" Style=%d",GetLineStyle());
700 if (GetLineWidth() != 1) printf(" Width=%d",GetLineWidth());
701 if (GetFillColor() != 0) printf(" FillColor=%d",GetFillColor());
702 if (GetFillStyle() != 0) printf(" FillStyle=%d",GetFillStyle());
703 printf("\n");
704}
705
706////////////////////////////////////////////////////////////////////////////////
707/// Save primitive as a C++ statement(s) on output stream out
708
709void TBox::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
710{
711 if (gROOT->ClassSaved(TBox::Class())) {
712 out<<" ";
713 } else {
714 out<<" TBox *";
715 }
716 out<<"box = new TBox("<<fX1<<","<<fY1<<","<<fX2<<","<<fY2<<");"<<std::endl;
717
718 SaveFillAttributes(out,"box",0,1001);
719 SaveLineAttributes(out,"box",1,1,1);
720
721 out<<" box->Draw();"<<std::endl;
722}
723
724////////////////////////////////////////////////////////////////////////////////
725/// Set tool tip text associated with this box. The delay is in
726/// milliseconds (minimum 250). To remove tool tip call method with
727/// text = 0.
728
729void TBox::SetToolTipText(const char *text, Long_t delayms)
730{
731 if (!gPad) {
732 Warning("SetToolTipText", "a canvas must exist before setting the tool tip text");
733 return;
734 }
735
736 if (fTip) {
737 gPad->DeleteToolTip(fTip);
738 fTip = 0;
739 }
740
741 if (text && strlen(text))
742 fTip = gPad->CreateToolTip(this, text, delayms);
743}
744
745////////////////////////////////////////////////////////////////////////////////
746/// Stream an object of class TBox.
747
748void TBox::Streamer(TBuffer &R__b)
749{
750 if (R__b.IsReading()) {
751 UInt_t R__s, R__c;
752 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
753 if (R__v > 1) {
754 R__b.ReadClassBuffer(TBox::Class(), this, R__v, R__s, R__c);
755 return;
756 }
757 //====process old versions before automatic schema evolution
758 TObject::Streamer(R__b);
759 TAttLine::Streamer(R__b);
760 TAttFill::Streamer(R__b);
761 Float_t x1,y1,x2,y2;
762 R__b >> x1; fX1 = x1;
763 R__b >> y1; fY1 = y1;
764 R__b >> x2; fX2 = x2;
765 R__b >> y2; fY2 = y2;
766 R__b.CheckByteCount(R__s, R__c, TBox::IsA());
767 //====end of old versions
768
769 } else {
770 R__b.WriteClassBuffer(TBox::Class(),this);
771 }
772}
773
774////////////////////////////////////////////////////////////////////////////////
775/// Return the "bounding Box" of the Box
776
778{
779 Rectangle_t BBox;
780 Int_t px1, py1, px2, py2;
781 px1 = gPad->XtoPixel(fX1);
782 px2 = gPad->XtoPixel(fX2);
783 py1 = gPad->YtoPixel(fY1);
784 py2 = gPad->YtoPixel(fY2);
785
786 Int_t tmp;
787 if (px1>px2) { tmp = px1; px1 = px2; px2 = tmp;}
788 if (py1>py2) { tmp = py1; py1 = py2; py2 = tmp;}
789
790 BBox.fX = px1;
791 BBox.fY = py1;
792 BBox.fWidth = px2-px1;
793 BBox.fHeight = py2-py1;
794
795 return (BBox);
796}
797
798////////////////////////////////////////////////////////////////////////////////
799/// Return the center of the Box as TPoint in pixels
800
802{
803 TPoint p;
804 if (!gPad) return (p);
805 p.SetX(gPad->XtoPixel(TMath::Min(fX1,fX2)+0.5*(TMath::Max(fX1, fX2)-TMath::Min(fX1, fX2))));
806 p.SetY(gPad->YtoPixel(TMath::Min(fY1,fY2)+0.5*(TMath::Max(fY1, fY2)-TMath::Min(fY1, fY2))));
807 return(p);
808}
809
810////////////////////////////////////////////////////////////////////////////////
811/// Set center of the Box
812
814{
815 if (!gPad) return;
818 if (fX2>fX1) {
819 this->SetX1(gPad->PixeltoX(p.GetX())-0.5*w);
820 this->SetX2(gPad->PixeltoX(p.GetX())+0.5*w);
821 }
822 else {
823 this->SetX2(gPad->PixeltoX(p.GetX())-0.5*w);
824 this->SetX1(gPad->PixeltoX(p.GetX())+0.5*w);
825 }
826 if (fY2>fY1) {
827 this->SetY1(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))-0.5*h);
828 this->SetY2(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))+0.5*h);
829 }
830 else {
831 this->SetY2(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))-0.5*h);
832 this->SetY1(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))+0.5*h);
833 }
834}
835
836////////////////////////////////////////////////////////////////////////////////
837/// Set X coordinate of the center of the Box
838
840{
841 if (!gPad) return;
842 if (x<0) return;
844 if (fX2>fX1) {
845 this->SetX1(gPad->PixeltoX(x)-0.5*w);
846 this->SetX2(gPad->PixeltoX(x)+0.5*w);
847 }
848 else {
849 this->SetX2(gPad->PixeltoX(x)-0.5*w);
850 this->SetX1(gPad->PixeltoX(x)+0.5*w);
851 }
852}
853
854////////////////////////////////////////////////////////////////////////////////
855/// Set Y coordinate of the center of the Box
856
858{
859 if (!gPad) return;
860 if (y<0) return;
862 if (fY2>fY1) {
863 this->SetY1(gPad->PixeltoY(y-gPad->VtoPixel(0))-0.5*h);
864 this->SetY2(gPad->PixeltoY(y-gPad->VtoPixel(0))+0.5*h);
865 }
866 else {
867 this->SetY2(gPad->PixeltoY(y-gPad->VtoPixel(0))-0.5*h);
868 this->SetY1(gPad->PixeltoY(y-gPad->VtoPixel(0))+0.5*h);
869 }
870}
871
872////////////////////////////////////////////////////////////////////////////////
873/// Set left hand side of BoundingBox to a value
874/// (resize in x direction on left)
875
877{
878 if (x<0) return;
879 if (!gPad) return;
880 fX1 = gPad->PixeltoX(x);
881}
882
883////////////////////////////////////////////////////////////////////////////////
884/// Set right hand side of BoundingBox to a value
885/// (resize in x direction on right)
886
888{
889 if (x<0) return;
890 if (!gPad) return;
891 fX2 = gPad->PixeltoX(x);
892}
893
894////////////////////////////////////////////////////////////////////////////////
895/// Set top of BoundingBox to a value (resize in y direction on top)
896
898{
899 if (y<0) return;
900 if (!gPad) return;
901 fY2 = gPad->PixeltoY(y - gPad->VtoPixel(0));
902}
903
904////////////////////////////////////////////////////////////////////////////////
905/// Set bottom of BoundingBox to a value
906/// (resize in y direction on bottom)
907
909{
910 if (y<0) return;
911 if (!gPad) return;
912 fY1 = gPad->PixeltoY(y - gPad->VtoPixel(0));
913}
@ kMouseMotion
Definition Buttons.h:23
@ kArrowKeyRelease
Definition Buttons.h:21
@ kButton1Double
Definition Buttons.h:24
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kArrowKeyPress
Definition Buttons.h:21
@ kButton1Down
Definition Buttons.h:17
@ kButton1Locate
Definition Buttons.h:22
@ kMouseEnter
Definition Buttons.h:23
@ kRightSide
Definition GuiTypes.h:373
@ kBottomSide
Definition GuiTypes.h:373
@ kTopLeft
Definition GuiTypes.h:372
@ kBottomRight
Definition GuiTypes.h:372
@ kTopSide
Definition GuiTypes.h:373
@ kLeftSide
Definition GuiTypes.h:373
@ kMove
Definition GuiTypes.h:374
@ kTopRight
Definition GuiTypes.h:372
@ kBottomLeft
Definition GuiTypes.h:372
@ kCross
Definition GuiTypes.h:374
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
static const double x2[5]
static const double x1[5]
int Int_t
Definition RtypesCore.h:45
short Version_t
Definition RtypesCore.h:65
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:92
long Long_t
Definition RtypesCore.h:54
double Double_t
Definition RtypesCore.h:59
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
Abstract base class for elements drawn in the editor.
Definition TAttBBox2D.h:19
Fill Area Attributes class.
Definition TAttFill.h:19
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:202
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:211
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:234
Line Attributes class.
Definition TAttLine.h:18
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:33
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:35
Width_t fLineWidth
Line width.
Definition TAttLine.h:23
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
virtual void Modify()
Change current line attributes if necessary.
Definition TAttLine.cxx:242
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:172
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition TAttLine.cxx:270
Create a Box.
Definition TBox.h:22
virtual Rectangle_t GetBBox()
Return the "bounding Box" of the Box.
Definition TBox.cxx:777
Double_t GetX1() const
Definition TBox.h:50
virtual void SetBBoxY1(const Int_t y)
Set top of BoundingBox to a value (resize in y direction on top)
Definition TBox.cxx:897
virtual void SetToolTipText(const char *text, Long_t delayms=1000)
Set tool tip text associated with this box.
Definition TBox.cxx:729
virtual void SetY2(Double_t y2)
Definition TBox.h:64
virtual void PaintBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Option_t *option="")
Draw this box with new coordinates.
Definition TBox.cxx:677
virtual void SetBBoxX2(const Int_t x)
Set right hand side of BoundingBox to a value (resize in x direction on right)
Definition TBox.cxx:887
TBox & operator=(const TBox &)
Assignment operator.
Definition TBox.cxx:93
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition TBox.cxx:231
Double_t fX1
X of 1st point.
Definition TBox.h:28
virtual void ls(Option_t *option="") const
List this box with its attributes.
Definition TBox.cxx:660
virtual void HideToolTip(Int_t event)
Hide tool tip depending on the event type.
Definition TBox.cxx:641
Double_t GetX2() const
Definition TBox.h:51
virtual void SetBBoxCenter(const TPoint &p)
Set center of the Box.
Definition TBox.cxx:813
Double_t GetY1() const
Definition TBox.h:52
@ kCannotMove
Definition TBox.h:37
virtual void SetX1(Double_t x1)
Definition TBox.h:61
Double_t GetY2() const
Definition TBox.h:53
virtual void Draw(Option_t *option="")
Draw this box with its current attributes.
Definition TBox.cxx:195
virtual Int_t IsInside(Double_t x, Double_t y) const
Function which returns 1 if point x,y lies inside the box, 0 otherwise.
Definition TBox.cxx:650
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a box.
Definition TBox.cxx:135
virtual void SetX2(Double_t x2)
Definition TBox.h:62
virtual ~TBox()
Box destructor.
Definition TBox.cxx:69
void Copy(TObject &box) const
Copy a Box.
Definition TBox.cxx:112
TBox()
Box default constructor.
Definition TBox.cxx:42
virtual TBox * DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this box with new coordinates.
Definition TBox.cxx:204
virtual void SetBBoxY2(const Int_t y)
Set bottom of BoundingBox to a value (resize in y direction on bottom)
Definition TBox.cxx:908
TObject * fTip
! tool tip associated with box
Definition TBox.h:25
virtual void SetBBoxX1(const Int_t x)
Set left hand side of BoundingBox to a value (resize in x direction on left)
Definition TBox.cxx:876
virtual void SetBBoxCenterY(const Int_t y)
Set Y coordinate of the center of the Box.
Definition TBox.cxx:857
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
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition TBox.cxx:709
Bool_t fResizing
! True if box is being resized
Definition TBox.h:32
virtual void SetY1(Double_t y1)
Definition TBox.h:63
virtual TPoint GetBBoxCenter()
Return the center of the Box as TPoint in pixels.
Definition TBox.cxx:801
virtual void Paint(Option_t *option="")
Paint this box with its current attributes.
Definition TBox.cxx:669
virtual void SetBBoxCenterX(const Int_t x)
Set X coordinate of the center of the Box.
Definition TBox.cxx:839
virtual void Print(Option_t *option="") const
Dump this box with its attributes.
Definition TBox.cxx:695
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Mother of all ROOT objects.
Definition TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:359
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition TObject.h:283
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:187
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:879
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:107
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:696
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:445
virtual void Copy(TObject &object) const
Copy this to obj.
Definition TObject.cxx:63
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:58
SCoord_t GetY() const
Definition TPoint.h:47
void SetX(SCoord_t x)
Definition TPoint.h:48
void SetY(SCoord_t y)
Definition TPoint.h:49
SCoord_t GetX() const
Definition TPoint.h:46
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2811
Basic string class.
Definition TString.h:136
void ToLower()
Change string to lower-case.
Definition TString.cxx:1145
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
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
TText * text
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Short_t Max(Short_t a, Short_t b)
Definition TMathBase.h:212
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition TMath.h:735
Short_t Min(Short_t a, Short_t b)
Definition TMathBase.h:180
Double_t Log10(Double_t x)
Definition TMath.h:764
Short_t Abs(Short_t d)
Definition TMathBase.h:120
Rectangle structure (maps to the X11 XRectangle structure)
Definition GuiTypes.h:361
Short_t fX
Definition GuiTypes.h:362
UShort_t fHeight
Definition GuiTypes.h:363
Short_t fY
Definition GuiTypes.h:362
UShort_t fWidth
Definition GuiTypes.h:363