Logo ROOT   master
Reference Guide
TGDimension.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 02/01/98
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 #ifndef ROOT_TGDimension
13 #define ROOT_TGDimension
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TGDimension, TGPosition, TGLongPosition, TGInsets and TGRectangle //
18 // //
19 // Several small geometry classes that implement dimensions //
20 // (width and height), positions (x and y), insets and rectangles. //
21 // They are trivial and their members are public. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TObject.h"
26 
27 class TGDimension {
28 public:
29  UInt_t fWidth; // width
30  UInt_t fHeight; // height
31 
32  TGDimension(): fWidth(0), fHeight(0) { }
33  TGDimension(UInt_t width, UInt_t height): fWidth(width), fHeight(height) { }
34  ~TGDimension() = default;
35 
37  { return ((fWidth == b.fWidth) && (fHeight == b.fHeight)); }
39  { return TGDimension(fWidth - b.fWidth, fHeight - b.fHeight); }
41  { return TGDimension(fWidth + b.fWidth, fHeight + b.fHeight); }
42 };
43 
44 
45 class TGPosition {
46 public:
47  Int_t fX; // x position
48  Int_t fY; // y position
49 
50  TGPosition(): fX(0), fY(0) { }
51  TGPosition(Int_t xc, Int_t yc): fX(xc), fY(yc) { }
52  ~TGPosition() = default;
53 
54  Bool_t operator==(const TGPosition &b) const
55  { return ((fX == b.fX) && (fY == b.fY)); }
57  { return TGPosition(fX - b.fX, fY - b.fY); }
59  { return TGPosition(fX + b.fX, fY + b.fY); }
60 };
61 
62 
64 public:
65  Long_t fX; // x position
66  Long_t fY; // y position
67 
68  TGLongPosition(): fX(0), fY(0) { }
69  TGLongPosition(Long_t xc, Long_t yc): fX(xc), fY(yc) { }
70  ~TGLongPosition() = default;
71 
73  { return ((fX == b.fX) && (fY == b.fY)); }
75  { return TGLongPosition(fX - b.fX, fY - b.fY); }
77  { return TGLongPosition(fX + b.fX, fY + b.fY); }
78 };
79 
80 
81 class TGInsets {
82 public:
83  Int_t fL; // left
84  Int_t fR; // right
85  Int_t fT; // top
86  Int_t fB; // bottom
87 
88  TGInsets(): fL(0), fR(0), fT(0), fB(0) { }
89  TGInsets(Int_t lf, Int_t rg, Int_t tp, Int_t bt):
90  fL(lf), fR(rg), fT(tp), fB(bt) { }
91  ~TGInsets() = default;
92 
93  Bool_t operator==(const TGInsets &in) const
94  { return ((fL == in.fL) && (fR == in.fR) && (fT == in.fT) && (fB == in.fB)); }
95 };
96 
97 
98 class TGRectangle {
99 public:
100  Int_t fX; // x position
101  Int_t fY; // y position
102  UInt_t fW; // width
103  UInt_t fH; // height
104 
105  // constructors
106  TGRectangle(): fX(0), fY(0), fW(0), fH(0) { Empty(); }
108  fX(rx), fY(ry), fW(rw), fH(rh) { }
109  TGRectangle(const TGPosition &p, const TGDimension &d):
110  fX(p.fX), fY(p.fY), fW(d.fWidth), fH(d.fHeight) { }
111  ~TGRectangle() = default;
112 
113  // methods
114  Bool_t Contains(Int_t px, Int_t py) const
115  { return ((px >= fX) && (px < fX + (Int_t) fW) &&
116  (py >= fY) && (py < fY + (Int_t) fH)); }
117  Bool_t Contains(const TGPosition &p) const
118  { return ((p.fX >= fX) && (p.fX < fX + (Int_t) fW) &&
119  (p.fY >= fY) && (p.fY < fY + (Int_t) fH)); }
121  { return ((fX <= r.fX + (Int_t) r.fW - 1) && (fX + (Int_t) fW - 1 >= r.fX) &&
122  (fY <= r.fY + (Int_t) r.fH - 1) && (fY + (Int_t) fH - 1 >= r.fY)); }
123  Int_t Area() const
124  { return (fW * fH); }
126  { return TGDimension(fW, fH); }
128  { return TGPosition(fX, fY); }
130  { return TGPosition(fX + (Int_t) fW - 1, fY + (Int_t) fH - 1); }
131  void Merge(const TGRectangle &r);
132  void Empty() { fX = fY = 0; fW = fH = 0; }
133  Bool_t IsEmpty() const { return ((fW == 0) && (fH == 0)); }
134 };
135 
136 #endif
TGDimension Size() const
Definition: TGDimension.h:125
~TGPosition()=default
Int_t fY
Definition: TGDimension.h:48
void Merge(const TGRectangle &r)
Definition: TGDimension.cxx:42
TGRectangle(Int_t rx, Int_t ry, UInt_t rw, UInt_t rh)
Definition: TGDimension.h:107
Bool_t Contains(Int_t px, Int_t py) const
Definition: TGDimension.h:114
Bool_t operator==(const TGLongPosition &b) const
Definition: TGDimension.h:72
TGLongPosition operator+(const TGLongPosition &b) const
Definition: TGDimension.h:76
TGPosition LeftTop() const
Definition: TGDimension.h:127
Bool_t operator==(const TGDimension &b) const
Definition: TGDimension.h:36
~TGLongPosition()=default
Bool_t IsEmpty() const
Definition: TGDimension.h:133
Bool_t operator==(const TGInsets &in) const
Definition: TGDimension.h:93
Bool_t Contains(const TGPosition &p) const
Definition: TGDimension.h:117
Int_t fT
Definition: TGDimension.h:85
Int_t fB
Definition: TGDimension.h:86
~TGDimension()=default
UInt_t fHeight
Definition: TGDimension.h:30
TGLongPosition operator-(const TGLongPosition &b) const
Definition: TGDimension.h:74
TGDimension operator+(const TGDimension &b) const
Definition: TGDimension.h:40
Bool_t operator==(const TGPosition &b) const
Definition: TGDimension.h:54
TGLongPosition(Long_t xc, Long_t yc)
Definition: TGDimension.h:69
UInt_t fWidth
Definition: TGDimension.h:29
ROOT::R::TRInterface & r
Definition: Object.C:4
Int_t Area() const
Definition: TGDimension.h:123
TGInsets(Int_t lf, Int_t rg, Int_t tp, Int_t bt)
Definition: TGDimension.h:89
unsigned int UInt_t
Definition: RtypesCore.h:42
~TGInsets()=default
Int_t fX
Definition: TGDimension.h:47
TGPosition operator+(const TGPosition &b) const
Definition: TGDimension.h:58
Int_t fR
Definition: TGDimension.h:84
TGRectangle(const TGPosition &p, const TGDimension &d)
Definition: TGDimension.h:109
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:120
TGDimension operator-(const TGDimension &b) const
Definition: TGDimension.h:38
Bool_t Intersects(const TGRectangle &r) const
Definition: TGDimension.h:120
long Long_t
Definition: RtypesCore.h:50
Int_t fL
Definition: TGDimension.h:83
#define d(i)
Definition: RSha256.hxx:102
~TGRectangle()=default
TGPosition RightBottom() const
Definition: TGDimension.h:129
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
TGPosition operator-(const TGPosition &b) const
Definition: TGDimension.h:56
void Empty()
Definition: TGDimension.h:132
TGPosition(Int_t xc, Int_t yc)
Definition: TGDimension.h:51
TGDimension(UInt_t width, UInt_t height)
Definition: TGDimension.h:33