Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAttBBox2D.cxx
Go to the documentation of this file.
1// @(#)root/graf:$Id$
2// Author: Anna-Pia Lohfink 27.3.2014
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 "TAttBBox2D.h"
13
14#include "TPoint.h"
15#include "TVirtualPad.h"
16
17
18/** \class TAttBBox2D
19\ingroup Base
20\ingroup GraphicsAtt
21
22Abstract base class for elements drawn in the editor.
23Classes inheriting from TAttBBox2D implementing the TAttBBox2D
24virtual methods, and using TPad::ShowGuideLines in ExecuteEvent
25will automatically get the guide lines drawn when moved in the pad.
26All methods work with pixel coordinates.
27*/
28
29////////////////////////////////////////////////////////////////////////////////
30// TAttBBox2D destructor.
31
35
36////////////////////////////////////////////////////////////////////////////////
37// Returns BBox center
38// By default returns center of rectangle returned by GetBBox() method
39
41{
42 auto box = GetBBox();
43 return { (Short_t) (box.fX + box.fWidth/2), (Short_t) (box.fY + box.fHeight/2)};
44}
45
46////////////////////////////////////////////////////////////////////////////////
47// Set BBox center
48// By default calls SetBBoxCenterX and SetBBoxCenterY
49
51{
52 SetBBoxCenterX(p.GetX());
53 SetBBoxCenterY(p.GetY());
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Return user X coordinate for pixel X value
58/// Can return ndc or normal values
59/// Also one can specify to use absolute coordinates for input parameter x
60/// Used in derived classes to implement SetBBox... methods
61
63{
64 if (!gPad)
65 return 0.;
66
67 if (!is_ndc)
68 return gPad->PadtoX(is_absolute ? gPad->AbsPixeltoX(x) : gPad->PixeltoX(x));
69
70 if (is_absolute) {
71 Double_t ww = gPad->GetWw();
72 Double_t wndc = gPad->GetAbsWNDC();
73 return ww > 0 && wndc > 0 ? (x / ww - gPad->GetAbsXlowNDC()) / wndc : 0.;
74 }
75 Int_t pw = gPad->GetPadWidth();
76 return pw > 0 ? 1. * x / pw : 0.;
77}
78
79////////////////////////////////////////////////////////////////////////////////
80// Return user Y coordinate for pixel Y value
81/// Can return ndc or normal values
82/// Also one can specify to use absolute coordinates for input parameter x
83// Used in derived classes to implement SetBBox... methods
84
86{
87 if (!gPad)
88 return 0.;
89
90 if (!is_ndc)
91 return gPad->PadtoY(is_absolute ? gPad->AbsPixeltoY(y) : gPad->PixeltoY(y - gPad->VtoPixel(0)));
92
93 if (is_absolute) {
94 Double_t wh = gPad->GetWh();
95 Double_t hndc = gPad->GetAbsHNDC();
96 return wh > 0 && hndc > 0 ? ((1. - y / wh) - gPad->GetAbsYlowNDC()) / hndc : 0.;
97 }
98
99 Int_t ph = gPad->GetPadHeight();
100 return ph > 0 ? 1. - 1. * y / ph : 0.;
101}
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
#define gPad
Double_t GetYCoord(const Int_t y, Bool_t is_ndc=kFALSE, Bool_t is_absolute=kFALSE)
Can return ndc or normal values Also one can specify to use absolute coordinates for input parameter ...
virtual void SetBBoxCenterY(const Int_t y)=0
virtual void SetBBoxCenterX(const Int_t x)=0
virtual void SetBBoxCenter(const TPoint &p)
virtual ~TAttBBox2D()
virtual Rectangle_t GetBBox()=0
virtual TPoint GetBBoxCenter()
Double_t GetXCoord(const Int_t x, Bool_t is_ndc=kFALSE, Bool_t is_absolute=kFALSE)
Return user X coordinate for pixel X value Can return ndc or normal values Also one can specify to us...
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