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