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