Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TBox.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Rene Brun 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <cstdlib>
13
14#include <iostream>
15#include "TROOT.h"
16#include "TBuffer.h"
17#include "TBox.h"
18#include "TVirtualPad.h"
19#include "TVirtualPadPainter.h"
20#include "TCanvasImp.h"
21#include "TClass.h"
22#include "TMath.h"
23#include "TPoint.h"
24
25
26/** \class TBox
27\ingroup BasicGraphics
28
29Create a Box.
30
31A box is defined by :
32
33- Its bottom left coordinates x1,y1
34- Its top right coordinates x2,y2
35
36A box has line attributes (see TAttLine) and fill area attributes (see TAttFill).
37*/
38
39////////////////////////////////////////////////////////////////////////////////
40/// Box default constructor.
41
43{
44 fTip = nullptr;
45 fX1 = 0.;
46 fY1 = 0.;
47 fX2 = 0.;
48 fY2 = 0.;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Box standard constructor.
54
56 : TObject(), TAttLine(), TAttFill()
57{
58 if (x2 >= x1) {fX1 =x1; fX2 = x2;}
59 else {fX1 = x2; fX2 = x1;}
60 if (y2 >= y1) {fY1 =y1; fY2 = y2;}
61 else {fY1 = y2; fY2 = y1;}
63 fTip = nullptr;
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Box destructor.
68
70{
71 if (fTip && gPad) {
72 gPad->CloseToolTip(fTip);
73 gPad->DeleteToolTip(fTip);
74 }
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// Box copy constructor.
79
81{
82 fX1 = 0.;
83 fY1 = 0.;
84 fX2 = 0.;
85 fY2 = 0.;
87 ((TBox&)box).TBox::Copy(*this);
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Assignment operator.
92
94{
95 if(this!=&b) {
97 TAttLine::operator=(b);
98 TAttFill::operator=(b);
99 fTip=b.fTip;
100 fX1=b.fX1;
101 fY1=b.fY1;
102 fX2=b.fX2;
103 fY2=b.fY2;
104 fResizing=b.fResizing;
105 }
106 return *this;
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Copy a Box.
111
112void TBox::Copy(TObject &obj) const
113{
114 TObject::Copy(obj);
115 TAttLine::Copy(((TBox&)obj));
116 TAttFill::Copy(((TBox&)obj));
117 ((TBox&)obj).fX1 = fX1;
118 ((TBox&)obj).fY1 = fY1;
119 ((TBox&)obj).fX2 = fX2;
120 ((TBox&)obj).fY2 = fY2;
121 ((TBox&)obj).fResizing = fResizing;
122 ((TBox&)obj).fTip = nullptr; //FIXME
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Compute distance from point px,py to a box.
127///
128/// Compute the closest distance of approach from point px,py to the
129/// edges of this box.
130/// The distance is computed in pixels units.
131///
132/// In case of a filled box the distance returned is 0 if the point
133/// (px,py) is inside the box, and is huge if the point is outside.
134
136{
137 if (!gPad) return 9999;
138 Int_t pxl, pyl, pxt, pyt;
139 Int_t px1 = gPad->XtoAbsPixel(fX1);
140 Int_t py1 = gPad->YtoAbsPixel(fY1);
141 Int_t px2 = gPad->XtoAbsPixel(fX2);
142 Int_t py2 = gPad->YtoAbsPixel(fY2);
143
144 Bool_t isBox = !(InheritsFrom("TPave") || InheritsFrom("TWbox"));
145
146 if (isBox) {
147 if (gPad->GetLogx()) {
148 if (fX1>0) px1 = gPad->XtoAbsPixel(TMath::Log10(fX1));
149 if (fX2>0) px2 = gPad->XtoAbsPixel(TMath::Log10(fX2));
150 }
151 if (gPad->GetLogy()) {
152 if (fY1>0) py1 = gPad->YtoAbsPixel(TMath::Log10(fY1));
153 if (fY2>0) py2 = gPad->YtoAbsPixel(TMath::Log10(fY2));
154 }
155 }
156
157 if (px1 < px2) {pxl = px1; pxt = px2;}
158 else {pxl = px2; pxt = px1;}
159 if (py1 < py2) {pyl = py1; pyt = py2;}
160 else {pyl = py2; pyt = py1;}
161
162 // Are we inside the box?
163 if (GetFillStyle()) {
164 if ( (px >= pxl && px <= pxt) && (py >= pyl && py <= pyt) ) return 0;
165 else return 9999;
166 }
167
168 // Are we on the edges?
169 Int_t dxl = TMath::Abs(px - pxl);
170 if (py < pyl) dxl += pyl - py;
171 if (py > pyt) dxl += py - pyt;
172 Int_t dxt = TMath::Abs(px - pxt);
173 if (py < pyl) dxt += pyl - py;
174 if (py > pyt) dxt += py - pyt;
175 Int_t dyl = TMath::Abs(py - pyl);
176 if (px < pxl) dyl += pxl - px;
177 if (px > pxt) dyl += px - pxt;
178 Int_t dyt = TMath::Abs(py - pyt);
179 if (px < pxl) dyt += pxl - px;
180 if (px > pxt) dyt += px - pxt;
181
183 if (dxt < distance) distance = dxt;
184 if (dyl < distance) distance = dyl;
185 if (dyt < distance) distance = dyt;
186
187 return distance - Int_t(0.5*fLineWidth);
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Draw this box with its current attributes.
192/// if the box has no fill style (ie fill style=0), the box contour is drawn
193/// if the box has a fill style, the box contour is not drawn by default.
194/// to force the contour to be drawn, specify option "l"
195
197{
199
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Draw this box with new coordinates.
204
206{
207 TBox *newbox = new TBox(x1,y1,x2,y2);
210 newbox->SetBit(kCanDelete);
211 newbox->AppendPad();
212 return newbox;
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Execute action corresponding to one event.
217///
218/// This member function is called when a BOX/WBOX/PAD object is clicked.
219///
220/// If the mouse is clicked in one of the 4 corners of the box (pA,pB,pC,pD)
221/// the box is resized with the rubber rectangle.
222///
223/// If the mouse is clicked inside the box, the box is moved.
224///
225/// If the mouse is clicked on the 4 edges (pL,pR,pTop,pBot), the box is
226/// rescaled parallel to this edge (same as Motif window manager).
227///
228/// Note that this function is duplicated on purpose by TPad::ExecuteEvent.
229/// If somebody modifies this function, may be similar changes should also
230/// be applied to TPad::ExecuteEvent.
231
233{
234 if (TestBit(kCannotMove)) return;
235
236 if (!gPad) return;
237
238 auto &parent = *gPad;
239
240 if (!parent.IsEditable() && event != kMouseEnter) return;
241
242 Bool_t isBox = !(InheritsFrom("TPave") || InheritsFrom("TWbox"));
243
244 constexpr Int_t kMaxDiff = 7;
245 constexpr Int_t kMinSize = 20;
246
247 static Int_t px1, px2, py1, py2, dpx1, dpy2;
248 static Int_t px1p, px2p, py1p, py2p;
249 static Double_t oldX1, oldY1, oldX2, oldY2;
250 static Bool_t hasOld = kFALSE;
251 static enum { pNone, pA, pB, pC, pD, pTop, pL, pR, pBot, pINSIDE } mode = pNone;
252 static bool firstPaint = kFALSE;
253 Bool_t opaque = parent.OpaqueMoving();
254 Bool_t ropaque = parent.OpaqueResizing();
255
256 // convert to user coordinates and either paint ot set back
257 auto paint_or_set = [&parent,isBox,this](Bool_t paint)
258 {
259 auto x1 = parent.AbsPixeltoX(px1);
260 auto y1 = parent.AbsPixeltoY(py1);
261 auto x2 = parent.AbsPixeltoX(px2);
262 auto y2 = parent.AbsPixeltoY(py2);
263 if (!paint) {
264 if (isBox) {
265 if (parent.GetLogx()) {
266 x1 = TMath::Power(10, x1);
267 x2 = TMath::Power(10, x2);
268 }
269 if (parent.GetLogy()) {
270 y1 = TMath::Power(10, y1);
271 y2 = TMath::Power(10, y2);
272 }
273 }
274 SetX1(x1);
275 SetY1(y1);
276 SetX2(x2);
277 SetY2(y2);
278 } else if (firstPaint) {
280 } else {
281 auto pp = parent.GetPainter();
282 pp->SetAttLine({GetFillColor() > 0 ? GetFillColor() : (Color_t) 1, GetLineStyle(), 2});
283 pp->DrawBox(x1, y1, x2, y2, TVirtualPadPainter::kHollow);
284 }
285 };
286
287 HideToolTip(event);
288
289 switch (event) {
290
291 case kMouseEnter:
292 if (fTip) parent.ResetToolTip(fTip);
293 break;
294
295 case kArrowKeyPress:
296 case kButton1Down:
297
298 oldX1 = fX1;
299 oldY1 = fY1;
300 oldX2 = fX2;
301 oldY2 = fY2;
302 hasOld = kTRUE;
303
304 // No break !!!
305
306 case kMouseMotion:
307
308 px1 = parent.XtoAbsPixel(isBox ? parent.XtoPad(GetX1()) : GetX1());
309 py1 = parent.YtoAbsPixel(isBox ? parent.YtoPad(GetY1()) : GetY1());
310 px2 = parent.XtoAbsPixel(isBox ? parent.XtoPad(GetX2()) : GetX2());
311 py2 = parent.YtoAbsPixel(isBox ? parent.YtoPad(GetY2()) : GetY2());
312 if (px1 > px2)
313 std::swap(px1, px2);
314 if (py1 < py2)
315 std::swap(py1, py2);
316
317 px1p = parent.XtoAbsPixel(parent.GetX1()) + parent.GetBorderSize();
318 py1p = parent.YtoAbsPixel(parent.GetY1()) - parent.GetBorderSize();
319 px2p = parent.XtoAbsPixel(parent.GetX2()) - parent.GetBorderSize();
320 py2p = parent.YtoAbsPixel(parent.GetY2()) + parent.GetBorderSize();
321 if (px1p > px2p)
322 std::swap(px1p, px2p);
323 if (py1p < py2p)
324 std::swap(py1p, py2p);
325
326 mode = pNone;
327
328 if (TMath::Abs(px - px1) <= kMaxDiff && TMath::Abs(py - py2) <= kMaxDiff) {
329 mode = pA;
330 parent.SetCursor(kTopLeft);
331 } else if (TMath::Abs(px - px2) <= kMaxDiff && TMath::Abs(py - py2) <= kMaxDiff) {
332 mode = pB;
333 parent.SetCursor(kTopRight);
334 } else if (TMath::Abs(px - px2) <= kMaxDiff && TMath::Abs(py - py1) <= kMaxDiff) {
335 mode = pC;
336 parent.SetCursor(kBottomRight);
337 } else if (TMath::Abs(px - px1) <= kMaxDiff && TMath::Abs(py - py1) <= kMaxDiff) {
338 mode = pD;
339 parent.SetCursor(kBottomLeft);
340 } else if ((px > px1 + kMaxDiff && px < px2 - kMaxDiff) && TMath::Abs(py - py2) < kMaxDiff) {
341 mode = pTop;
342 parent.SetCursor(kTopSide);
343 } else if ((px > px1 + kMaxDiff && px < px2 - kMaxDiff) && TMath::Abs(py - py1) < kMaxDiff) {
344 mode = pBot;
345 parent.SetCursor(kBottomSide);
346 } else if ((py > py2 + kMaxDiff && py < py1 - kMaxDiff) && TMath::Abs(px - px1) < kMaxDiff) {
347 mode = pL;
348 parent.SetCursor(kLeftSide);
349 } else if ((py > py2 + kMaxDiff && py < py1 - kMaxDiff) && TMath::Abs(px - px2) < kMaxDiff) {
350 mode = pR;
351 parent.SetCursor(kRightSide);
352 } else if ((px > px1+kMaxDiff && px < px2-kMaxDiff) && (py > py2+kMaxDiff && py < py1-kMaxDiff)) {
353 dpx1 = px - px1; // cursor position relative to top-left corner
354 dpy2 = py - py2;
355 mode = pINSIDE;
356 if (event == kButton1Down)
357 parent.SetCursor(kMove);
358 else
359 parent.SetCursor(kCross);
360 }
361
362 fResizing = (mode != pNone) && (mode != pINSIDE);
364 if (mode == pNone)
365 parent.SetCursor(kCross);
366
367 break;
368
369 case kArrowKeyRelease:
370 case kButton1Motion:
371
372 switch (mode) {
373 case pNone:
374 return;
375 case pA:
377 px1 = TMath::Max(px1p, TMath::Min(px, px2 - kMinSize));
378 py2 = TMath::Max(py2p, TMath::Min(py, py1 - kMinSize));
380 break;
381 case pB:
383 px2 = TMath::Min(px2p, TMath::Max(px, px1 + kMinSize));
384 py2 = TMath::Max(py2p, TMath::Min(py, py1 - kMinSize));
386 break;
387 case pC:
389 px2 = TMath::Min(px2p, TMath::Max(px, px1 + kMinSize));
390 py1 = TMath::Min(py1p, TMath::Max(py, py2 + kMinSize));
392 break;
393 case pD:
395 px1 = TMath::Max(px1p, TMath::Min(px, px2 - kMinSize));
396 py1 = TMath::Min(py1p, TMath::Max(py, py2 + kMinSize));
398 break;
399 case pTop:
401 py2 = TMath::Max(py2p, TMath::Min(py, py1 - kMinSize));
403 break;
404 case pBot:
406 py1 = TMath::Min(py1p, TMath::Max(py, py2 + kMinSize));
408 break;
409 case pL:
411 px1 = TMath::Max(px1p, TMath::Min(px, px2 - kMinSize));
413 break;
414 case pR:
416 px2 = TMath::Min(px2p, TMath::Max(px, px1 + kMinSize));
418 break;
419 case pINSIDE:
421 px2 += px - dpx1 - px1;
422 px1 = px - dpx1;
423 py1 += py - dpy2 - py2;
424 py2 = py - dpy2;
425 if (px1 < px1p) { px2 += px1p - px1; px1 = px1p; }
426 if (px2 > px2p) { px1 -= px2 - px2p; px2 = px2p; }
427 if (py1 > py1p) { py2 -= py1 - py1p; py1 = py1p; }
428 if (py2 < py2p) { py1 += py2p - py2; py2 = py2p; }
430 break;
431 }
432
433 if ((mode == pINSIDE && opaque) || (fResizing && ropaque)) {
434 switch(mode) {
435 case pINSIDE: parent.ShowGuidelines(this, event, 'i', true); break;
436 case pTop: parent.ShowGuidelines(this, event, 't', true); break;
437 case pBot: parent.ShowGuidelines(this, event, 'b', true); break;
438 case pL: parent.ShowGuidelines(this, event, 'l', true); break;
439 case pR: parent.ShowGuidelines(this, event, 'r', true); break;
440 case pA: parent.ShowGuidelines(this, event, '1', true); break;
441 case pB: parent.ShowGuidelines(this, event, '2', true); break;
442 case pC: parent.ShowGuidelines(this, event, '3', true); break;
443 case pD: parent.ShowGuidelines(this, event, '4', true); break;
444 default: break; // not involved
445 }
446 parent.Modified(kTRUE);
447 }
448
449 break;
450
451 case kButton1Up:
452 if (opaque || ropaque)
453 parent.ShowGuidelines(this, event);
454
455 if (gROOT->IsEscaped()) {
456 gROOT->SetEscape(kFALSE);
457 if (opaque && (mode != pNone)) {
458 if (hasOld) {
459 SetX1(oldX1);
460 SetY1(oldY1);
461 SetX2(oldX2);
462 SetY2(oldY2);
463 }
464 hasOld = kFALSE;
465 mode = pNone;
467 parent.Modified(kTRUE);
468 parent.Update();
469 }
470 break;
471 }
472
473 if ((!opaque && mode == pINSIDE) || (!ropaque && fResizing))
475
476 if (mode != pNone)
477 parent.Modified(kTRUE);
478
479 mode = pNone;
481 hasOld = kFALSE;
482
483 break;
484
485 case kButton1Locate:
486 // Sergey: code is never used, has to be removed in ROOT7
487
488 ExecuteEvent(kButton1Down, px, py);
489
490 while (true) {
491 px = py = 0;
492 event = parent.GetCanvasImp()->RequestLocator(px, py);
493
495
496 if (event != -1) { // button is released
497 ExecuteEvent(kButton1Up, px, py);
498 return;
499 }
500 }
501 }
502}
503
504////////////////////////////////////////////////////////////////////////////////
505/// Hide tool tip depending on the event type. Typically tool tips
506/// are hidden when event is not a kMouseEnter and not a kMouseMotion
507/// event.
508
510{
511 if (event != kMouseEnter && event != kMouseMotion && fTip && gPad)
512 gPad->CloseToolTip(fTip);
513}
514
515////////////////////////////////////////////////////////////////////////////////
516/// Function which returns 1 if point x,y lies inside the box, 0 otherwise.
517
519{
520 if (x < fX1 || x > fX2) return 0;
521 if (y < fY1 || y > fY2) return 0;
522 return 1;
523}
524
525////////////////////////////////////////////////////////////////////////////////
526/// List this box with its attributes.
527
528void TBox::ls(Option_t *) const
529{
531 printf("%s X1= %f Y1=%f X2=%f Y2=%f\n",IsA()->GetName(),fX1,fY1,fX2,fY2);
532}
533
534////////////////////////////////////////////////////////////////////////////////
535/// Paint this box with its current attributes.
536
538{
539 if(gPad) PaintBox(gPad->XtoPad(fX1),gPad->YtoPad(fY1),gPad->XtoPad(fX2),gPad->YtoPad(fY2),option);
540}
541
542////////////////////////////////////////////////////////////////////////////////
543/// Draw this box with new coordinates.
544
546{
547 if (!gPad) return;
548
549 TAttLine::Modify(); //Change line attributes only if necessary
550 TAttFill::Modify(); //Change fill area attributes only if necessary
551
552 if (option) {
553 TString opt = option;
554 opt.ToLower();
555 if (opt.Contains("l")) gPad->PaintBox(x1,y1,x2,y2,"l");
556 else gPad->PaintBox(x1,y1,x2,y2);
557 } else {
558 gPad->PaintBox(x1,y1,x2,y2);
559 }
560}
561
562////////////////////////////////////////////////////////////////////////////////
563/// Dump this box with its attributes.
564
566{
567 printf("%s X1=%f Y1=%f X2=%f Y2=%f",IsA()->GetName(),fX1,fY1,fX2,fY2);
568 if (GetLineColor() != 1) printf(" Color=%d",GetLineColor());
569 if (GetLineStyle() != 1) printf(" Style=%d",GetLineStyle());
570 if (GetLineWidth() != 1) printf(" Width=%d",GetLineWidth());
571 if (GetFillColor() != 0) printf(" FillColor=%d",GetFillColor());
572 if (GetFillStyle() != 0) printf(" FillStyle=%d",GetFillStyle());
573 printf("\n");
574}
575
576////////////////////////////////////////////////////////////////////////////////
577/// Save primitive as a C++ statement(s) on output stream out
578
579void TBox::SavePrimitive(std::ostream &out, Option_t *option)
580{
581 SavePrimitiveConstructor(out, Class(), "box", TString::Format("%g, %g, %g, %g", fX1, fY1, fX2, fY2));
582
583 SaveFillAttributes(out, "box", -1, -1);
584 SaveLineAttributes(out, "box", 1, 1, 1);
585
586 SavePrimitiveDraw(out, "box", option);
587}
588
589////////////////////////////////////////////////////////////////////////////////
590/// Set tool tip text associated with this box. The delay is in
591/// milliseconds (minimum 250). To remove tool tip call method with
592/// text = 0.
593
595{
596 if (!gPad) {
597 Warning("SetToolTipText", "a canvas must exist before setting the tool tip text");
598 return;
599 }
600
601 if (fTip) {
602 gPad->DeleteToolTip(fTip);
603 fTip = nullptr;
604 }
605
606 if (text && strlen(text))
607 fTip = gPad->CreateToolTip(this, text, delayms);
608}
609
610////////////////////////////////////////////////////////////////////////////////
611/// Stream an object of class TBox.
612
614{
615 if (R__b.IsReading()) {
617 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
618 if (R__v > 1) {
619 R__b.ReadClassBuffer(TBox::Class(), this, R__v, R__s, R__c);
620 return;
621 }
622 //====process old versions before automatic schema evolution
626 Float_t x1,y1,x2,y2;
627 R__b >> x1; fX1 = x1;
628 R__b >> y1; fY1 = y1;
629 R__b >> x2; fX2 = x2;
630 R__b >> y2; fY2 = y2;
631 R__b.CheckByteCount(R__s, R__c, TBox::IsA());
632 //====end of old versions
633
634 } else {
635 R__b.WriteClassBuffer(TBox::Class(),this);
636 }
637}
638
639////////////////////////////////////////////////////////////////////////////////
640/// Return the "bounding Box" of the Box
641
643{
644 Rectangle_t BBox{0,0,0,0};
645 if (gPad) {
646 Int_t px1 = gPad->XtoPixel(fX1);
647 Int_t px2 = gPad->XtoPixel(fX2);
648 Int_t py1 = gPad->YtoPixel(fY1);
649 Int_t py2 = gPad->YtoPixel(fY2);
650
651 if (px1 > px2) {
652 Int_t tmp = px1;
653 px1 = px2;
654 px2 = tmp;
655 }
656 if (py1 > py2) {
657 Int_t tmp = py1;
658 py1 = py2;
659 py2 = tmp;
660 }
661
662 BBox.fX = px1;
663 BBox.fY = py1;
664 BBox.fWidth = px2 - px1;
665 BBox.fHeight = py2 - py1;
666 }
667
668 return BBox;
669}
670
671////////////////////////////////////////////////////////////////////////////////
672/// Return the center of the Box as TPoint in pixels
673
675{
676 TPoint p(0, 0);
677 if (gPad) {
678 p.SetX(gPad->XtoPixel(TMath::Min(fX1, fX2) + 0.5 * (TMath::Max(fX1, fX2) - TMath::Min(fX1, fX2))));
679 p.SetY(gPad->YtoPixel(TMath::Min(fY1, fY2) + 0.5 * (TMath::Max(fY1, fY2) - TMath::Min(fY1, fY2))));
680 }
681 return p;
682}
683
684////////////////////////////////////////////////////////////////////////////////
685/// Set center of the Box
686
688{
689 if (!gPad) return;
692 if (fX2>fX1) {
693 this->SetX1(gPad->PixeltoX(p.GetX())-0.5*w);
694 this->SetX2(gPad->PixeltoX(p.GetX())+0.5*w);
695 }
696 else {
697 this->SetX2(gPad->PixeltoX(p.GetX())-0.5*w);
698 this->SetX1(gPad->PixeltoX(p.GetX())+0.5*w);
699 }
700 if (fY2>fY1) {
701 this->SetY1(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))-0.5*h);
702 this->SetY2(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))+0.5*h);
703 }
704 else {
705 this->SetY2(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))-0.5*h);
706 this->SetY1(gPad->PixeltoY(p.GetY()-gPad->VtoPixel(0))+0.5*h);
707 }
708}
709
710////////////////////////////////////////////////////////////////////////////////
711/// Set X coordinate of the center of the Box
712
714{
715 if (!gPad) return;
716 if (x<0) return;
718 if (fX2>fX1) {
719 this->SetX1(gPad->PixeltoX(x)-0.5*w);
720 this->SetX2(gPad->PixeltoX(x)+0.5*w);
721 }
722 else {
723 this->SetX2(gPad->PixeltoX(x)-0.5*w);
724 this->SetX1(gPad->PixeltoX(x)+0.5*w);
725 }
726}
727
728////////////////////////////////////////////////////////////////////////////////
729/// Set Y coordinate of the center of the Box
730
732{
733 if (!gPad) return;
734 if (y<0) return;
736 if (fY2>fY1) {
737 this->SetY1(gPad->PixeltoY(y-gPad->VtoPixel(0))-0.5*h);
738 this->SetY2(gPad->PixeltoY(y-gPad->VtoPixel(0))+0.5*h);
739 }
740 else {
741 this->SetY2(gPad->PixeltoY(y-gPad->VtoPixel(0))-0.5*h);
742 this->SetY1(gPad->PixeltoY(y-gPad->VtoPixel(0))+0.5*h);
743 }
744}
745
746////////////////////////////////////////////////////////////////////////////////
747/// Set left hand side of BoundingBox to a value
748/// (resize in x direction on left)
749
751{
752 if (x<0) return;
753 if (!gPad) return;
754 fX1 = gPad->PixeltoX(x);
755}
756
757////////////////////////////////////////////////////////////////////////////////
758/// Set right hand side of BoundingBox to a value
759/// (resize in x direction on right)
760
762{
763 if (x<0) return;
764 if (!gPad) return;
765 fX2 = gPad->PixeltoX(x);
766}
767
768////////////////////////////////////////////////////////////////////////////////
769/// Set top of BoundingBox to a value (resize in y direction on top)
770
772{
773 if (y<0) return;
774 if (!gPad) return;
775 fY2 = gPad->PixeltoY(y - gPad->VtoPixel(0));
776}
777
778////////////////////////////////////////////////////////////////////////////////
779/// Set bottom of BoundingBox to a value
780/// (resize in y direction on bottom)
781
783{
784 if (y<0) return;
785 if (!gPad) return;
786 fY1 = gPad->PixeltoY(y - gPad->VtoPixel(0));
787}
@ kMouseMotion
Definition Buttons.h:23
@ kArrowKeyRelease
Definition Buttons.h:21
@ kButton1Motion
Definition Buttons.h:20
@ kButton1Up
Definition Buttons.h:19
@ kArrowKeyPress
Definition Buttons.h:21
@ kButton1Down
Definition Buttons.h:17
@ kButton1Locate
Definition Buttons.h:22
@ kMouseEnter
Definition Buttons.h:23
@ kRightSide
Definition GuiTypes.h:374
@ kBottomSide
Definition GuiTypes.h:374
@ kTopLeft
Definition GuiTypes.h:373
@ kBottomRight
Definition GuiTypes.h:373
@ kTopSide
Definition GuiTypes.h:374
@ kLeftSide
Definition GuiTypes.h:374
@ kMove
Definition GuiTypes.h:375
@ kTopRight
Definition GuiTypes.h:373
@ kBottomLeft
Definition GuiTypes.h:373
@ kCross
Definition GuiTypes.h:375
#define b(i)
Definition RSha256.hxx:100
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Color_t
Color number (short)
Definition RtypesCore.h:99
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char text
Option_t Option_t TPoint TPoint const char y1
#define gROOT
Definition TROOT.h:426
#define gPad
Abstract base class for elements drawn in the editor.
Definition TAttBBox2D.h:19
Fill Area Attributes class.
Definition TAttFill.h:21
virtual void Streamer(TBuffer &)
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:203
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:33
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:212
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:240
Line Attributes class.
Definition TAttLine.h:21
virtual void Streamer(TBuffer &)
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
virtual Width_t GetLineWidth() const
Return the line width.
Definition TAttLine.h:38
Width_t fLineWidth
Line width.
Definition TAttLine.h:26
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:37
virtual void Modify()
Change current line attributes if necessary.
Definition TAttLine.cxx:246
void Copy(TAttLine &attline) const
Copy this line attributes to a new TAttLine.
Definition TAttLine.cxx:176
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:289
Create a Box.
Definition TBox.h:22
void Draw(Option_t *option="") override
Draw this box with its current attributes.
Definition TBox.cxx:196
Double_t GetX1() const
Definition TBox.h:51
virtual void SetToolTipText(const char *text, Long_t delayms=1000)
Set tool tip text associated with this box.
Definition TBox.cxx:594
virtual void SetY2(Double_t y2)
Definition TBox.h:65
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:545
static TClass * Class()
void Streamer(TBuffer &) override
Stream an object of class TBox.
Definition TBox.cxx:613
void SetBBoxX1(const Int_t x) override
Set left hand side of BoundingBox to a value (resize in x direction on left)
Definition TBox.cxx:750
~TBox() override
Box destructor.
Definition TBox.cxx:69
TBox & operator=(const TBox &)
Assignment operator.
Definition TBox.cxx:93
void SetBBoxY2(const Int_t y) override
Set bottom of BoundingBox to a value (resize in y direction on bottom)
Definition TBox.cxx:782
void SetBBoxY1(const Int_t y) override
Set top of BoundingBox to a value (resize in y direction on top)
Definition TBox.cxx:771
Double_t fX1
X of 1st point.
Definition TBox.h:28
TClass * IsA() const override
Definition TBox.h:77
virtual void HideToolTip(Int_t event)
Hide tool tip depending on the event type.
Definition TBox.cxx:509
void SetBBoxCenterY(const Int_t y) override
Set Y coordinate of the center of the Box.
Definition TBox.cxx:731
Double_t GetX2() const
Definition TBox.h:52
void ls(Option_t *option="") const override
List this box with its attributes.
Definition TBox.cxx:528
Double_t GetY1() const
Definition TBox.h:53
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override
Execute action corresponding to one event.
Definition TBox.cxx:232
virtual void SetX1(Double_t x1)
Definition TBox.h:62
void Paint(Option_t *option="") override
Paint this box with its current attributes.
Definition TBox.cxx:537
Double_t GetY2() const
Definition TBox.h:54
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:518
TPoint GetBBoxCenter() override
Return the center of the Box as TPoint in pixels.
Definition TBox.cxx:674
virtual void SetX2(Double_t x2)
Definition TBox.h:63
TBox()
Box default constructor.
Definition TBox.cxx:42
virtual TBox * DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this box with new coordinates.
Definition TBox.cxx:205
Rectangle_t GetBBox() override
Return the "bounding Box" of the Box.
Definition TBox.cxx:642
void Print(Option_t *option="") const override
Dump this box with its attributes.
Definition TBox.cxx:565
TObject * fTip
! tool tip associated with box
Definition TBox.h:25
void SetBBoxCenter(const TPoint &p) override
Set center of the Box.
Definition TBox.cxx:687
@ kCannotMove
Definition TBox.h:37
Double_t fY2
Y of 2nd point.
Definition TBox.h:31
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save primitive as a C++ statement(s) on output stream out.
Definition TBox.cxx:579
Double_t fX2
X of 2nd point.
Definition TBox.h:30
Double_t fY1
Y of 1st point.
Definition TBox.h:29
void Copy(TObject &box) const override
Copy a Box.
Definition TBox.cxx:112
Int_t DistancetoPrimitive(Int_t px, Int_t py) override
Compute distance from point px,py to a box.
Definition TBox.cxx:135
Bool_t fResizing
! True if box is being resized
Definition TBox.h:32
void SetBBoxX2(const Int_t x) override
Set right hand side of BoundingBox to a value (resize in x direction on right)
Definition TBox.cxx:761
virtual void SetY1(Double_t y1)
Definition TBox.h:64
void SetBBoxCenterX(const Int_t x) override
Set X coordinate of the center of the Box.
Definition TBox.cxx:713
Buffer base class used for serializing objects.
Definition TBuffer.h:43
Mother of all ROOT objects.
Definition TObject.h:42
TObject & operator=(const TObject &rhs) noexcept
TObject assignment operator.
Definition TObject.h:305
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:459
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:994
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1081
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition TObject.cxx:201
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:546
virtual void Copy(TObject &object) const
Copy this to obj.
Definition TObject.cxx:156
static void SavePrimitiveDraw(std::ostream &out, const char *variable_name, Option_t *option=nullptr)
Save invocation of primitive Draw() method Skipped if option contains "nodraw" string.
Definition TObject.cxx:842
static void SavePrimitiveConstructor(std::ostream &out, TClass *cl, const char *variable_name, const char *constructor_agrs="", Bool_t empty_line=kTRUE)
Save object constructor in the output stream "out".
Definition TObject.cxx:774
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
SCoord_t GetY() const
Definition TPoint.h:47
SCoord_t GetX() const
Definition TPoint.h:46
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:3061
Basic string class.
Definition TString.h:138
void ToLower()
Change string to lower-case.
Definition TString.cxx:1189
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2384
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:641
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)
Returns the largest of a and b.
Definition TMathBase.h:249
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:732
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:197
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.
Definition TMath.h:773
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:122
Rectangle structure (maps to the X11 XRectangle structure)
Definition GuiTypes.h:362