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