Logo ROOT   6.08/07
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 #ifndef ROOT_TObject
26 #include "TObject.h"
27 #endif
28 
29 class TGDimension {
30 public:
31  UInt_t fWidth; // width
32  UInt_t fHeight; // height
33 
34  TGDimension(): fWidth(0), fHeight(0) { }
35  TGDimension(UInt_t width, UInt_t height): fWidth(width), fHeight(height) { }
36  TGDimension(const TGDimension &d): fWidth(d.fWidth), fHeight(d.fHeight) { }
37  virtual ~TGDimension() { }
38 
40  { return ((fWidth == b.fWidth) && (fHeight == b.fHeight)); }
42  { return TGDimension(fWidth - b.fWidth, fHeight - b.fHeight); }
44  { return TGDimension(fWidth + b.fWidth, fHeight + b.fHeight); }
45 
46  ClassDef(TGDimension,0) // Dimension object (width, height)
47 };
48 
49 
50 class TGPosition {
51 public:
52  Int_t fX; // x position
53  Int_t fY; // y position
54 
55  TGPosition(): fX(0), fY(0) { }
56  TGPosition(Int_t xc, Int_t yc): fX(xc), fY(yc) { }
57  TGPosition(const TGPosition &p): fX(p.fX), fY(p.fY) { }
58  virtual ~TGPosition() { }
59 
60  Bool_t operator==(const TGPosition &b) const
61  { return ((fX == b.fX) && (fY == b.fY)); }
63  { return TGPosition(fX - b.fX, fY - b.fY); }
65  { return TGPosition(fX + b.fX, fY + b.fY); }
66 
67  ClassDef(TGPosition,0) // Position object (x and y are Int_t)
68 };
69 
70 
72 public:
73  Long_t fX; // x position
74  Long_t fY; // y position
75 
76  TGLongPosition(): fX(0), fY(0) { }
77  TGLongPosition(Long_t xc, Long_t yc): fX(xc), fY(yc) { }
78  TGLongPosition(const TGLongPosition &p): fX(p.fX), fY(p.fY) { }
79  virtual ~TGLongPosition() { }
80 
82  { return ((fX == b.fX) && (fY == b.fY)); }
84  { return TGLongPosition(fX - b.fX, fY - b.fY); }
86  { return TGLongPosition(fX + b.fX, fY + b.fY); }
87 
88  ClassDef(TGLongPosition,0) // Position object (x and y are Long_t)
89 };
90 
91 
92 class TGInsets {
93 public:
94  Int_t fL; // left
95  Int_t fR; // right
96  Int_t fT; // top
97  Int_t fB; // bottom
98 
99  TGInsets(): fL(0), fR(0), fT(0), fB(0) { }
100  TGInsets(Int_t lf, Int_t rg, Int_t tp, Int_t bt):
101  fL(lf), fR(rg), fT(tp), fB(bt) { }
102  TGInsets(const TGInsets &in):
103  fL(in.fL), fR(in.fR), fT(in.fT), fB(in.fB) { }
104  virtual ~TGInsets() { }
105 
106  Bool_t operator==(const TGInsets &in) const
107  { return ((fL == in.fL) && (fR == in.fR) && (fT == in.fT) && (fB == in.fB)); }
108 
109  ClassDef(TGInsets,0) // Inset (left, right, top, bottom)
110 };
111 
112 
113 class TGRectangle {
114 public:
115  Int_t fX; // x position
116  Int_t fY; // y position
117  UInt_t fW; // width
118  UInt_t fH; // height
119 
120  // constructors
121  TGRectangle(): fX(0), fY(0), fW(0), fH(0) { Empty(); }
123  fX(rx), fY(ry), fW(rw), fH(rh) { }
124  TGRectangle(const TGPosition &p, const TGDimension &d):
125  fX(p.fX), fY(p.fY), fW(d.fWidth), fH(d.fHeight) { }
127  fX(r.fX), fY(r.fY), fW(r.fW), fH(r.fH) { }
128  virtual ~TGRectangle() { }
129 
130  // methods
131  Bool_t Contains(Int_t px, Int_t py) const
132  { return ((px >= fX) && (px < fX + (Int_t) fW) &&
133  (py >= fY) && (py < fY + (Int_t) fH)); }
134  Bool_t Contains(const TGPosition &p) const
135  { return ((p.fX >= fX) && (p.fX < fX + (Int_t) fW) &&
136  (p.fY >= fY) && (p.fY < fY + (Int_t) fH)); }
138  { return ((fX <= r.fX + (Int_t) r.fW - 1) && (fX + (Int_t) fW - 1 >= r.fX) &&
139  (fY <= r.fY + (Int_t) r.fH - 1) && (fY + (Int_t) fH - 1 >= r.fY)); }
140  Int_t Area() const
141  { return (fW * fH); }
143  { return TGDimension(fW, fH); }
145  { return TGPosition(fX, fY); }
147  { return TGPosition(fX + (Int_t) fW - 1, fY + (Int_t) fH - 1); }
148  void Merge(const TGRectangle &r);
149  void Empty() { fX = fY = 0; fW = fH = 0; }
150  Bool_t IsEmpty() const { return ((fW == 0) && (fH == 0)); }
151 
152  ClassDef(TGRectangle, 0) // Rectangle object
153 };
154 
155 #endif
TGDimension Size() const
Definition: TGDimension.h:142
Int_t fY
Definition: TGDimension.h:53
virtual ~TGPosition()
Definition: TGDimension.h:58
TGPosition(const TGPosition &p)
Definition: TGDimension.h:57
TGRectangle(Int_t rx, Int_t ry, UInt_t rw, UInt_t rh)
Definition: TGDimension.h:122
Bool_t Contains(Int_t px, Int_t py) const
Definition: TGDimension.h:131
Bool_t operator==(const TGLongPosition &b) const
Definition: TGDimension.h:81
TGLongPosition operator+(const TGLongPosition &b) const
Definition: TGDimension.h:85
TGPosition LeftTop() const
Definition: TGDimension.h:144
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t operator==(const TGDimension &b) const
Definition: TGDimension.h:39
Bool_t IsEmpty() const
Definition: TGDimension.h:150
Bool_t operator==(const TGInsets &in) const
Definition: TGDimension.h:106
Bool_t Contains(const TGPosition &p) const
Definition: TGDimension.h:134
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t fT
Definition: TGDimension.h:96
Int_t fB
Definition: TGDimension.h:97
UInt_t fHeight
Definition: TGDimension.h:32
TGLongPosition operator-(const TGLongPosition &b) const
Definition: TGDimension.h:83
TGDimension operator+(const TGDimension &b) const
Definition: TGDimension.h:43
virtual ~TGDimension()
Definition: TGDimension.h:37
Bool_t operator==(const TGPosition &b) const
Definition: TGDimension.h:60
TGLongPosition(Long_t xc, Long_t yc)
Definition: TGDimension.h:77
UInt_t fWidth
Definition: TGDimension.h:31
TRandom2 r(17)
Int_t Area() const
Definition: TGDimension.h:140
virtual ~TGLongPosition()
Definition: TGDimension.h:79
TGDimension(const TGDimension &d)
Definition: TGDimension.h:36
TGInsets(Int_t lf, Int_t rg, Int_t tp, Int_t bt)
Definition: TGDimension.h:100
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t fX
Definition: TGDimension.h:52
TGPosition operator+(const TGPosition &b) const
Definition: TGDimension.h:64
Int_t fR
Definition: TGDimension.h:95
TGRectangle(const TGPosition &p, const TGDimension &d)
Definition: TGDimension.h:124
TGDimension operator-(const TGDimension &b) const
Definition: TGDimension.h:41
Bool_t Intersects(const TGRectangle &r) const
Definition: TGDimension.h:137
long Long_t
Definition: RtypesCore.h:50
Int_t fL
Definition: TGDimension.h:94
TGPosition RightBottom() const
Definition: TGDimension.h:146
virtual ~TGInsets()
Definition: TGDimension.h:104
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
TGInsets(const TGInsets &in)
Definition: TGDimension.h:102
TGPosition operator-(const TGPosition &b) const
Definition: TGDimension.h:62
virtual ~TGRectangle()
Definition: TGDimension.h:128
void Empty()
Definition: TGDimension.h:149
TGPosition(Int_t xc, Int_t yc)
Definition: TGDimension.h:56
TGRectangle(const TGRectangle &r)
Definition: TGDimension.h:126
TGLongPosition(const TGLongPosition &p)
Definition: TGDimension.h:78
TGDimension(UInt_t width, UInt_t height)
Definition: TGDimension.h:35