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